diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-10-14 07:39:24 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-10-14 07:39:24 -0600 |
commit | 55769b2fbf24ed84ee0f8ea5fe856e5fd29d8e60 (patch) | |
tree | 288312924cba7055d01242d95e860cd5ec121562 | |
parent | dd2f8b6891f963a6c0cf42be9212e85a86a77df7 (diff) | |
parent | 899f1cab587c92104ef9c4165786c2a04a92e24b (diff) | |
download | servo-55769b2fbf24ed84ee0f8ea5fe856e5fd29d8e60.tar.gz servo-55769b2fbf24ed84ee0f8ea5fe856e5fd29d8e60.zip |
Auto merge of #7829 - frewsxcv:htmltablecellelement-cellindex, r=Ms2ger
Implement HTMLTableCellElement::CellIndex
Extracted from #6936
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7829)
<!-- Reviewable:end -->
5 files changed, 29 insertions, 28 deletions
diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 7be54174eae..d377d1cee3d 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -5,7 +5,11 @@ use cssparser::RGBA; use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods; -use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableCellElementDerived}; +use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; +use dom::bindings::codegen::InheritTypes::HTMLElementCast; +use dom::bindings::codegen::InheritTypes::HTMLTableCellElementDerived; +use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived; +use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::js::LayoutJS; use dom::document::Document; use dom::element::{AttributeMutation, ElementTypeId}; @@ -78,6 +82,20 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement { // https://html.spec.whatwg.org/multipage/#dom-tdth-colspan make_uint_setter!(SetColSpan, "colspan"); + + // https://html.spec.whatwg.org/multipage/#dom-tdth-cellindex + fn CellIndex(&self) -> i32 { + let self_node = NodeCast::from_ref(self); + + let parent_children = match self_node.GetParentNode() { + Some(ref parent_node) if parent_node.is_htmltablerowelement() => parent_node.children(), + _ => return -1, + }; + + parent_children.filter(|c| c.is_htmltablecellelement()) + .position(|c| c.r() == self_node) + .map(|p| p as i32).unwrap_or(-1) + } } diff --git a/components/script/dom/webidls/HTMLTableCellElement.webidl b/components/script/dom/webidls/HTMLTableCellElement.webidl index 0f3a2a6a14f..7db825376c4 100644 --- a/components/script/dom/webidls/HTMLTableCellElement.webidl +++ b/components/script/dom/webidls/HTMLTableCellElement.webidl @@ -9,7 +9,7 @@ interface HTMLTableCellElement : HTMLElement { attribute unsigned long colSpan; // attribute unsigned long rowSpan; //[PutForwards=value] readonly attribute DOMSettableTokenList headers; - //readonly attribute long cellIndex; + readonly attribute long cellIndex; // also has obsolete members }; diff --git a/tests/wpt/metadata/html/dom/interfaces.html.ini b/tests/wpt/metadata/html/dom/interfaces.html.ini index 123d9c48d66..4f62c39b96a 100644 --- a/tests/wpt/metadata/html/dom/interfaces.html.ini +++ b/tests/wpt/metadata/html/dom/interfaces.html.ini @@ -4770,9 +4770,6 @@ [HTMLTableCellElement interface: document.createElement("td") must inherit property "headers" with the proper type (2)] expected: FAIL - [HTMLTableCellElement interface: document.createElement("td") must inherit property "cellIndex" with the proper type (3)] - expected: FAIL - [HTMLTableCellElement interface: document.createElement("td") must inherit property "align" with the proper type (4)] expected: FAIL @@ -4833,9 +4830,6 @@ [HTMLTableCellElement interface: document.createElement("th") must inherit property "headers" with the proper type (2)] expected: FAIL - [HTMLTableCellElement interface: document.createElement("th") must inherit property "cellIndex" with the proper type (3)] - expected: FAIL - [HTMLTableCellElement interface: document.createElement("th") must inherit property "align" with the proper type (4)] expected: FAIL @@ -4872,9 +4866,6 @@ [HTMLTableCellElement interface: attribute headers] expected: FAIL - [HTMLTableCellElement interface: attribute cellIndex] - expected: FAIL - [HTMLTableCellElement interface: attribute align] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html.ini b/tests/wpt/metadata/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html.ini deleted file mode 100644 index 516b739b45a..00000000000 --- a/tests/wpt/metadata/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html.ini +++ /dev/null @@ -1,17 +0,0 @@ -[cellIndex.html] - type: testharness - [cellIndex should exist.] - expected: FAIL - - [For cells without a parent, cellIndex should be -1.] - expected: FAIL - - [For cells whose parent is not a tr, cellIndex should be -1.] - expected: FAIL - - [For cells whose parent is not a HTML tr, cellIndex should be -1.] - expected: FAIL - - [For cells whose parent is a tr, cellIndex should be the index.] - expected: FAIL - diff --git a/tests/wpt/web-platform-tests/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html b/tests/wpt/web-platform-tests/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html index b9e523334f3..b8449229d5b 100644 --- a/tests/wpt/web-platform-tests/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html +++ b/tests/wpt/web-platform-tests/html/semantics/tabular-data/attributes-common-to-td-and-th-elements/cellIndex.html @@ -38,4 +38,13 @@ test(function() { var td = tr.appendChild(document.createElement("td")); assert_equals(td.cellIndex, 1); }, "For cells whose parent is a tr, cellIndex should be the index.") +test(function() { + var tr = document.createElement("tr"); + var th = tr.appendChild(document.createElement("th")); + assert_equals(th.cellIndex, 0); + tr.appendChild(document.createElement("div")); + tr.appendChild(document.createTextNode("Hello World")); + var td = tr.appendChild(document.createElement("td")); + assert_equals(td.cellIndex, 1) +}, "For cells whose parent is a tr with non td/th sibling, cellIndex should skip those non td/th siblings.") </script> |