Auto merge of #19038 - CJ8664:master, r=jdm

Added implementation for itemprop and itemtype along with test files

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19038)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-06 14:17:11 -06:00 committed by GitHub
commit 5227df260c
11 changed files with 345 additions and 0 deletions

View file

@ -31,6 +31,7 @@ use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use std::ascii::AsciiExt;
use std::collections::HashSet;
use std::default::Default;
use std::rc::Rc;
use style::attr::AttrValue;
@ -277,6 +278,38 @@ impl HTMLElementMethods for HTMLElement {
}
}
// https://html.spec.whatwg.org/multipage/#attr-itemtype
fn Itemtypes(&self) -> Option<Vec<DOMString>> {
let atoms = self.element.get_tokenlist_attribute(&local_name!("itemtype"), );
if atoms.is_empty() {
return None;
}
let mut item_attr_values = HashSet::new();
for attr_value in &atoms {
item_attr_values.insert(DOMString::from(String::from(attr_value.trim())));
}
Some(item_attr_values.into_iter().collect())
}
// https://html.spec.whatwg.org/multipage/#names:-the-itemprop-attribute
fn PropertyNames(&self) -> Option<Vec<DOMString>> {
let atoms = self.element.get_tokenlist_attribute(&local_name!("itemprop"), );
if atoms.is_empty() {
return None;
}
let mut item_attr_values = HashSet::new();
for attr_value in &atoms {
item_attr_values.insert(DOMString::from(String::from(attr_value.trim())));
}
Some(item_attr_values.into_iter().collect())
}
// https://html.spec.whatwg.org/multipage/#dom-click
fn Click(&self) {
if !self.upcast::<Element>().disabled_state() {
@ -577,4 +610,17 @@ impl VirtualMethods for HTMLElement {
}
self.update_sequentially_focusable_status();
}
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&local_name!("itemprop") => AttrValue::from_serialized_tokenlist(value.into()),
&local_name!("itemtype") => AttrValue::from_serialized_tokenlist(value.into()),
_ => {
self.super_type().unwrap().parse_plain_attribute(
name,
value,
)
},
}
}
}

View file

@ -18,9 +18,14 @@ interface HTMLElement : Element {
// microdata
// attribute boolean itemScope;
// attribute DOMString itemId;
//readonly attribute HTMLPropertiesCollection properties;
// attribute any itemValue; // acts as DOMString on setting
[Pref="dom.microdata.testing.enabled"]
sequence<DOMString>? propertyNames();
[Pref="dom.microdata.testing.enabled"]
sequence<DOMString>? itemtypes();
// user interaction
[CEReactions]