mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Add DeleteRow method
This commit is contained in:
parent
2de3b119a9
commit
cf9fd7eb46
8 changed files with 106 additions and 37 deletions
|
@ -34,6 +34,20 @@ pub struct HTMLTableElement {
|
|||
tbodies: MutNullableHeap<JS<HTMLCollection>>,
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
struct TableRowFilter {
|
||||
sections: Vec<JS<Node>>,
|
||||
}
|
||||
|
||||
impl CollectionFilter for TableRowFilter {
|
||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||
elem.is::<HTMLTableRowElement>() &&
|
||||
(root.is_parent_of(elem.upcast())
|
||||
|| self.sections.iter().any(|ref section| section.is_parent_of(elem.upcast())))
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLTableElement {
|
||||
fn new_inherited(localName: Atom, prefix: Option<DOMString>, document: &Document)
|
||||
-> HTMLTableElement {
|
||||
|
@ -120,32 +134,22 @@ impl HTMLTableElement {
|
|||
thead.upcast::<Node>().remove_self();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLTableElementMethods for HTMLTableElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-rows
|
||||
fn Rows(&self) -> Root<HTMLCollection> {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
struct TableRowFilter {
|
||||
sections: Vec<JS<Node>>
|
||||
}
|
||||
|
||||
impl CollectionFilter for TableRowFilter {
|
||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||
elem.is::<HTMLTableRowElement>() &&
|
||||
(root.is_parent_of(elem.upcast())
|
||||
|| self.sections.iter().any(|ref section| section.is_parent_of(elem.upcast())))
|
||||
}
|
||||
}
|
||||
|
||||
let filter = TableRowFilter {
|
||||
fn get_rows(&self) -> TableRowFilter {
|
||||
TableRowFilter {
|
||||
sections: self.upcast::<Node>()
|
||||
.children()
|
||||
.filter_map(|ref node|
|
||||
node.downcast::<HTMLTableSectionElement>().map(|_| JS::from_ref(&**node)))
|
||||
.collect()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLTableElementMethods for HTMLTableElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-rows
|
||||
fn Rows(&self) -> Root<HTMLCollection> {
|
||||
let filter = self.get_rows();
|
||||
HTMLCollection::new(window_from_node(self).r(), self.upcast(), box filter)
|
||||
}
|
||||
|
||||
|
@ -338,6 +342,22 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
|||
Ok(new_row)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-deleterow
|
||||
fn DeleteRow(&self, mut index: i32) -> Fallible<()> {
|
||||
let rows = self.Rows();
|
||||
// Step 1.
|
||||
if index == -1 {
|
||||
index = rows.Length() as i32 - 1;
|
||||
}
|
||||
// Step 2.
|
||||
if index < 0 || index as u32 >= rows.Length() {
|
||||
return Err(Error::IndexSize);
|
||||
}
|
||||
// Step 3.
|
||||
Root::upcast::<Node>(rows.Item(index as u32).unwrap()).remove_self();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-bgcolor
|
||||
make_getter!(BgColor, "bgcolor");
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ interface HTMLTableElement : HTMLElement {
|
|||
HTMLTableSectionElement createTBody();
|
||||
readonly attribute HTMLCollection rows;
|
||||
[Throws] HTMLTableRowElement insertRow(optional long index = -1);
|
||||
//void deleteRow(long index);
|
||||
[Throws] void deleteRow(long index);
|
||||
|
||||
// also has obsolete members
|
||||
};
|
||||
|
|
|
@ -11,3 +11,4 @@
|
|||
[Various fileBits]
|
||||
expected: FAIL
|
||||
bug: https://github.com/servo/servo/issues/10911
|
||||
|
||||
|
|
|
@ -15225,6 +15225,10 @@
|
|||
"path": "dom/nodes/prepend-on-Document.html",
|
||||
"url": "/dom/nodes/prepend-on-Document.html"
|
||||
},
|
||||
{
|
||||
"path": "dom/nodes/remove-row.html",
|
||||
"url": "/dom/nodes/remove-row.html"
|
||||
},
|
||||
{
|
||||
"path": "dom/nodes/remove-unscopable.html",
|
||||
"url": "/dom/nodes/remove-unscopable.html"
|
||||
|
@ -37201,7 +37205,9 @@
|
|||
]
|
||||
},
|
||||
"local_changes": {
|
||||
"deleted": [],
|
||||
"deleted": [
|
||||
"dom/nodes/remove-row.html"
|
||||
],
|
||||
"deleted_reftests": {},
|
||||
"items": {
|
||||
"testharness": {
|
||||
|
@ -37210,6 +37216,12 @@
|
|||
"path": "html/semantics/scripting-1/the-script-element/script-charset-03.html",
|
||||
"url": "/html/semantics/scripting-1/the-script-element/script-charset-03.html"
|
||||
}
|
||||
],
|
||||
"html/semantics/tabular-data/the-table-element/remove-row.html": [
|
||||
{
|
||||
"path": "html/semantics/tabular-data/the-table-element/remove-row.html",
|
||||
"url": "/html/semantics/tabular-data/the-table-element/remove-row.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[getElementsByClassName-21.htm]
|
||||
type: testharness
|
||||
[delete element from collection]
|
||||
expected: FAIL
|
||||
|
|
@ -3237,9 +3237,6 @@
|
|||
[HTMLAreaElement interface: document.createElement("area") must inherit property "noHref" with the proper type (10)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableElement interface: operation deleteRow(long)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableElement interface: attribute sortable]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -3267,12 +3264,6 @@
|
|||
[HTMLTableElement interface: attribute cellSpacing]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableElement interface: document.createElement("table") must inherit property "deleteRow" with the proper type (13)]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableElement interface: calling deleteRow(long) on document.createElement("table") with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLTableElement interface: document.createElement("table") must inherit property "sortable" with the proper type (14)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Delete Row tests</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
<table id="element">
|
||||
<thead>
|
||||
<th>First column</th>
|
||||
<th>Second column</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>1.1</td>
|
||||
<td>1.2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2.1</td>
|
||||
<td>2.2</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
var el = document.getElementById('element');
|
||||
|
||||
test(function() {
|
||||
assert_throws("IndexSizeError", function() {
|
||||
el.deleteRow(-2)
|
||||
})
|
||||
}, 'deleteRow function invalid argument');
|
||||
test(function() {
|
||||
assert_throws("IndexSizeError", function() {
|
||||
el.deleteRow(el.rows.length)
|
||||
})
|
||||
}, 'deleteRow function invalid argument bis');
|
||||
|
||||
test(function() {
|
||||
var old_length = el.rows.length;
|
||||
el.insertRow(-1);
|
||||
el.deleteRow(-1);
|
||||
assert_equals(old_length, el.rows.length);
|
||||
}, "check normal deleteRow");
|
||||
test(function() {
|
||||
while (el.rows.length > 1) {
|
||||
el.deleteRow(-1);
|
||||
}
|
||||
assert_equals(1, el.rows.length);
|
||||
}, "check normal deleteRow bis");
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue