Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 'listed element' logic for HTMLFieldSetElement::Elements #9214

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Refactor 'listed element' logic for HTMLFieldSetElement::Elements

`HTMLElement::is_listed_element` method was added, which matches the
`HTMLElement::is_labelable_element` method directly above
  • Loading branch information
frewsxcv committed Jan 9, 2016
commit e3728f616747325201bac468d5ddbd8973d02b74
@@ -354,6 +354,30 @@ impl HTMLElement {
}
}

// https://html.spec.whatwg.org/multipage/#category-listed
pub fn is_listed_element(&self) -> bool {
// Servo does not implement HTMLKeygenElement
// https://github.com/servo/servo/issues/2782
if self.upcast::<Element>().local_name() == &atom!("keygen") {
return true;
}

match self.upcast::<Node>().type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(type_id)) =>
match type_id {
HTMLElementTypeId::HTMLButtonElement |
HTMLElementTypeId::HTMLFieldSetElement |
HTMLElementTypeId::HTMLInputElement |
HTMLElementTypeId::HTMLObjectElement |
HTMLElementTypeId::HTMLOutputElement |
HTMLElementTypeId::HTMLSelectElement |
HTMLElementTypeId::HTMLTextAreaElement => true,
_ => false,
},
_ => false,
}
}

pub fn supported_prop_names_custom_attr(&self) -> Vec<DOMString> {
let element = self.upcast::<Element>();
element.attrs().iter().filter_map(|attr| {
@@ -18,7 +18,7 @@ use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;
use selectors::states::*;
use string_cache::Atom;
use util::str::{DOMString, StaticStringVec};
use util::str::DOMString;

#[dom_struct]
pub struct HTMLFieldSetElement {
@@ -52,9 +52,8 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
struct ElementsFilter;
impl CollectionFilter for ElementsFilter {
fn filter<'a>(&self, elem: &'a Element, _root: &'a Node) -> bool {
static TAG_NAMES: StaticStringVec = &["button", "fieldset", "input",
"keygen", "object", "output", "select", "textarea"];
TAG_NAMES.iter().any(|&tag_name| tag_name == &**elem.local_name())
elem.downcast::<HTMLElement>()

This comment has been minimized.

@KiChjang

KiChjang Jan 9, 2016

Member

Is this supposed to be an .upcast::<HTMLElement>() instead?

This comment has been minimized.

@frewsxcv

frewsxcv Jan 9, 2016

Author Member

Element is the parent of HTMLElement, so we need to downcast.

https://html.spec.whatwg.org/multipage/dom.html#htmlelement

.map_or(false, HTMLElement::is_listed_element)
}
}
let filter = box ElementsFilter;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.