mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #10558 - frewsxcv:tr-SectionRowIndex, r=KiChjang
Implement `sectionRowIndex` property on `<tr>`. Fixes https://github.com/servo/servo/issues/10509. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10558) <!-- Reviewable:end -->
This commit is contained in:
commit
9053721a32
5 changed files with 29 additions and 76 deletions
|
@ -118,13 +118,6 @@ impl HTMLTableElement {
|
|||
thead.upcast::<Node>().remove_self();
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the row index for the given `HTMLTableRowElement`.
|
||||
pub fn row_index(&self, row_elem: &HTMLTableRowElement) -> Option<usize> {
|
||||
self.Rows()
|
||||
.elements_iter()
|
||||
.position(|elem| (&elem as &Element) == row_elem.upcast::<Element>())
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLTableElementMethods for HTMLTableElement {
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
use cssparser::RGBA;
|
||||
use dom::attr::AttrValue;
|
||||
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods};
|
||||
use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::HTMLTableSectionElementMethods;
|
||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
|
@ -54,6 +56,14 @@ impl HTMLTableRowElement {
|
|||
document,
|
||||
HTMLTableRowElementBinding::Wrap)
|
||||
}
|
||||
|
||||
/// Determine the index for this `HTMLTableRowElement` within the given
|
||||
/// `HTMLCollection`. Returns `-1` if not found within collection.
|
||||
fn row_index(&self, collection: Root<HTMLCollection>) -> i32 {
|
||||
collection.elements_iter()
|
||||
.position(|elem| (&elem as &Element) == self.upcast())
|
||||
.map_or(-1, |i| i as i32)
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
||||
|
@ -97,7 +107,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
|||
None => return -1,
|
||||
};
|
||||
if let Some(table) = parent.downcast::<HTMLTableElement>() {
|
||||
return table.row_index(self).map_or(-1, |i| i as i32);
|
||||
return self.row_index(table.Rows());
|
||||
}
|
||||
if !parent.is::<HTMLTableSectionElement>() {
|
||||
return -1;
|
||||
|
@ -107,8 +117,23 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
|||
None => return -1,
|
||||
};
|
||||
grandparent.downcast::<HTMLTableElement>()
|
||||
.and_then(|table| table.row_index(self))
|
||||
.map_or(-1, |i| i as i32)
|
||||
.map_or(-1, |table| self.row_index(table.Rows()))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tr-sectionrowindex
|
||||
fn SectionRowIndex(&self) -> i32 {
|
||||
let parent = match self.upcast::<Node>().GetParentNode() {
|
||||
Some(parent) => parent,
|
||||
None => return -1,
|
||||
};
|
||||
let collection = if let Some(table) = parent.downcast::<HTMLTableElement>() {
|
||||
table.Rows()
|
||||
} else if let Some(table_section) = parent.downcast::<HTMLTableSectionElement>() {
|
||||
table_section.Rows()
|
||||
} else {
|
||||
return -1;
|
||||
};
|
||||
self.row_index(collection)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// https://html.spec.whatwg.org/multipage/#htmltablerowelement
|
||||
interface HTMLTableRowElement : HTMLElement {
|
||||
readonly attribute long rowIndex;
|
||||
//readonly attribute long sectionRowIndex;
|
||||
readonly attribute long sectionRowIndex;
|
||||
readonly attribute HTMLCollection cells;
|
||||
[Throws]
|
||||
HTMLElement insertCell(optional long index = -1);
|
||||
|
|
|
@ -4308,9 +4308,6 @@
|
|||
[HTMLTableSectionElement interface: document.createElement("tfoot") must inherit property "vAlign" with the proper type (6)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: attribute sectionRowIndex]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: attribute align]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -4323,9 +4320,6 @@
|
|||
[HTMLTableRowElement interface: attribute vAlign]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "sectionRowIndex" with the proper type (1)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "align" with the proper type (5)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
[sectionRowIndex.html]
|
||||
type: testharness
|
||||
[Row in thead in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in implicit tbody in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Other row in implicit tbody in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in explicit tbody in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in tfoot in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in thead in nested table in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in implicit tbody in nested table in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in explicit tbody in nested table in HTML]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created div in table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created thead in table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created tbody in table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created tfoot in table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created tr in tbody in table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created td in tr in tbody in table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created nested table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created thead in nested table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created tbody in nested table]
|
||||
expected: FAIL
|
||||
|
||||
[Row in script-created tfoot in nested table]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue