servo: Merge #7823 - Implement HTMLTableRowElement::Cells (from frewsxcv:htmltablerowelement-cells); r=Ms2ger

Extracted from #6936

Source-Repo: https://github.com/servo/servo
Source-Revision: 8865410ffc7998b1c74b5acda24507a07289fd1a
This commit is contained in:
David Zbarsky 2015-10-02 02:54:55 -06:00
Родитель 5eef9ab963
Коммит 9a218a0467
2 изменённых файлов: 32 добавлений и 5 удалений

Просмотреть файл

@ -5,20 +5,37 @@
use cssparser::RGBA;
use dom::attr::Attr;
use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableRowElementDerived};
use dom::bindings::js::Root;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived;
use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived;
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
use dom::document::Document;
use dom::element::{AttributeMutation, ElementTypeId};
use dom::element::{AttributeMutation, Element, ElementTypeId};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId};
use dom::node::{Node, NodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods;
use std::cell::Cell;
use util::str::{self, DOMString};
#[derive(JSTraceable)]
struct CellsFilter;
impl CollectionFilter for CellsFilter {
fn filter(&self, elem: &Element, root: &Node) -> bool {
(elem.is_htmltableheadercellelement() || elem.is_htmltabledatacellelement())
&& NodeCast::from_ref(elem).GetParentNode().r() == Some(root)
}
}
#[dom_struct]
pub struct HTMLTableRowElement {
htmlelement: HTMLElement,
cells: MutNullableHeap<JS<HTMLCollection>>,
background_color: Cell<Option<RGBA>>,
}
@ -38,6 +55,7 @@ impl HTMLTableRowElement {
localName,
prefix,
document),
cells: Default::default(),
background_color: Cell::new(None),
}
}
@ -61,6 +79,15 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
// https://html.spec.whatwg.org/multipage/#dom-tr-bgcolor
make_setter!(SetBgColor, "bgcolor");
// https://html.spec.whatwg.org/multipage/#dom-tr-cells
fn Cells(&self) -> Root<HTMLCollection> {
self.cells.or_init(|| {
let window = window_from_node(self);
let filter = box CellsFilter;
HTMLCollection::create(window.r(), NodeCast::from_ref(self), filter)
})
}
}
impl VirtualMethods for HTMLTableRowElement {

Просмотреть файл

@ -7,7 +7,7 @@
interface HTMLTableRowElement : HTMLElement {
//readonly attribute long rowIndex;
//readonly attribute long sectionRowIndex;
//readonly attribute HTMLCollection cells;
readonly attribute HTMLCollection cells;
//HTMLElement insertCell(optional long index = -1);
//void deleteCell(long index);