mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Auto merge of #10510 - frewsxcv:rowindex, r=KiChjang
Implement `rowIndex` property on `<tr>`. Part of 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/10510) <!-- Reviewable:end -->
This commit is contained in:
commit
9fb5703c6d
5 changed files with 31 additions and 45 deletions
|
@ -118,6 +118,13 @@ 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 {
|
||||
|
|
|
@ -14,7 +14,9 @@ use dom::element::{Element, RawLayoutElementHelpers};
|
|||
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::htmltabledatacellelement::HTMLTableDataCellElement;
|
||||
use dom::htmltableelement::HTMLTableElement;
|
||||
use dom::htmltableheadercellelement::HTMLTableHeaderCellElement;
|
||||
use dom::htmltablesectionelement::HTMLTableSectionElement;
|
||||
use dom::node::{Node, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use string_cache::Atom;
|
||||
|
@ -87,6 +89,27 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
|||
|| self.Cells(),
|
||||
|n| n.is::<HTMLTableDataCellElement>())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tr-rowindex
|
||||
fn RowIndex(&self) -> i32 {
|
||||
let parent = match self.upcast::<Node>().GetParentNode() {
|
||||
Some(parent) => parent,
|
||||
None => return -1,
|
||||
};
|
||||
if let Some(table) = parent.downcast::<HTMLTableElement>() {
|
||||
return table.row_index(self).map_or(-1, |i| i as i32);
|
||||
}
|
||||
if !parent.is::<HTMLTableSectionElement>() {
|
||||
return -1;
|
||||
}
|
||||
let grandparent = match parent.upcast::<Node>().GetParentNode() {
|
||||
Some(parent) => parent,
|
||||
None => return -1,
|
||||
};
|
||||
grandparent.downcast::<HTMLTableElement>()
|
||||
.and_then(|table| table.row_index(self))
|
||||
.map_or(-1, |i| i as i32)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HTMLTableRowElementLayoutHelpers {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#htmltablerowelement
|
||||
interface HTMLTableRowElement : HTMLElement {
|
||||
//readonly attribute long rowIndex;
|
||||
readonly attribute long rowIndex;
|
||||
//readonly attribute long sectionRowIndex;
|
||||
readonly attribute HTMLCollection cells;
|
||||
[Throws]
|
||||
|
|
|
@ -4311,9 +4311,6 @@
|
|||
[HTMLTableSectionElement interface: document.createElement("tfoot") must inherit property "vAlign" with the proper type (6)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: attribute rowIndex]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: attribute sectionRowIndex]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -4329,9 +4326,6 @@
|
|||
[HTMLTableRowElement interface: attribute vAlign]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "rowIndex" with the proper type (0)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement interface: document.createElement("tr") must inherit property "sectionRowIndex" with the proper type (1)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
[rowIndex.html]
|
||||
type: testharness
|
||||
[HTMLTableRowElement.rowIndex]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 1]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 2]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 3]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 4]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 5]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 6]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 7]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 8]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 9]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 10]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableRowElement.rowIndex 11]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue