aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlelement.rs
diff options
context:
space:
mode:
authorVijay Hebbar <vijayhebbar91@gmail.com>2017-10-21 23:46:55 +0000
committerChirag Jain <csjain@ncsu.edu>2017-11-06 15:11:50 -0500
commit4a43dba8d7ee1ed8247a97cd00120cbde106b28a (patch)
tree590244029135081fd0d2feaeb16c1e5c24d848b8 /components/script/dom/htmlelement.rs
parent88505dc2ffc31efa614e1a5070a9bc23feded30a (diff)
downloadservo-4a43dba8d7ee1ed8247a97cd00120cbde106b28a.tar.gz
servo-4a43dba8d7ee1ed8247a97cd00120cbde106b28a.zip
Add implementation for itemprop and itemtype
Created test file Added the stub methods for itemprop and itemscope Resolved html5ever dependency, added ItemScope and ItemProp attr Resolving dependency Added pref override on metadata attributes Resetting to original state due to change in requirement Reverted adding attributes 1. add a customized implementation of parse_plain_attribute 2. add the following methods to HTMLElement.webidl added itemprop and itemtype, enabled pref in test Added initial implementation for getting itemprop property values Adding the wireframe for testing Implemented function to handle itemType Corrected typo Fixed typo bug in code Handling duplicates for itemtype attribute values Added the test suite structure Added test for extra space Added test for regular test values Added test cases for Single property values Test cases to check absence of itemtype and itemprop attributes Added code to handle absence of itemtype or itemprop attributes Added shell script to run all test cases cleared up Cargo file Tidying up Removed the local test file Removed new line for test-tidy Ordered key in prefs.json Fixes for test-tidy Enabled test preferences Created test using wpt Creating WPT Tests for Regular and Single Prop Types Fixed the Regular type test Fixed tests Removed old test case metadata Incorporate review changes from PR Updated MANIFEST to sync test cases Making changed suggested in review Removed editor folding Removed unnecessary code Resolving cargo conflicts Updated PropertyNames and itemtypes implementation Trying different data in test case Updated manifest Updated code based on reviews
Diffstat (limited to 'components/script/dom/htmlelement.rs')
-rw-r--r--components/script/dom/htmlelement.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index 616b69ebb95..d29251cb597 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -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,
+ )
+ },
+ }
+ }
}