mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Upgrade to SM 39
This commit is contained in:
parent
a256f39796
commit
675267b782
205 changed files with 6546 additions and 5340 deletions
|
@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::HTMLCollectionBinding;
|
|||
use dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, JSRef, Rootable, Temporary};
|
||||
use dom::bindings::js::{JS, Root};
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::element::{Element, AttributeHandlers, ElementHelpers};
|
||||
|
@ -20,7 +20,7 @@ use std::iter::{FilterMap, Skip};
|
|||
use string_cache::{Atom, Namespace};
|
||||
|
||||
pub trait CollectionFilter : JSTraceable {
|
||||
fn filter<'a>(&self, elem: JSRef<'a, Element>, root: JSRef<'a, Node>) -> bool;
|
||||
fn filter<'a>(&self, elem: &'a Element, root: &'a Node) -> bool;
|
||||
}
|
||||
|
||||
#[jstraceable]
|
||||
|
@ -44,26 +44,26 @@ impl HTMLCollection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: JSRef<Window>, collection: CollectionTypeId) -> Temporary<HTMLCollection> {
|
||||
pub fn new(window: &Window, collection: CollectionTypeId) -> Root<HTMLCollection> {
|
||||
reflect_dom_object(box HTMLCollection::new_inherited(collection),
|
||||
GlobalRef::Window(window), HTMLCollectionBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl HTMLCollection {
|
||||
pub fn create(window: JSRef<Window>, root: JSRef<Node>,
|
||||
filter: Box<CollectionFilter+'static>) -> Temporary<HTMLCollection> {
|
||||
HTMLCollection::new(window, CollectionTypeId::Live(JS::from_rooted(root), filter))
|
||||
pub fn create(window: &Window, root: &Node,
|
||||
filter: Box<CollectionFilter+'static>) -> Root<HTMLCollection> {
|
||||
HTMLCollection::new(window, CollectionTypeId::Live(JS::from_ref(root), filter))
|
||||
}
|
||||
|
||||
fn all_elements(window: JSRef<Window>, root: JSRef<Node>,
|
||||
namespace_filter: Option<Namespace>) -> Temporary<HTMLCollection> {
|
||||
fn all_elements(window: &Window, root: &Node,
|
||||
namespace_filter: Option<Namespace>) -> Root<HTMLCollection> {
|
||||
#[jstraceable]
|
||||
struct AllElementFilter {
|
||||
namespace_filter: Option<Namespace>
|
||||
}
|
||||
impl CollectionFilter for AllElementFilter {
|
||||
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
match self.namespace_filter {
|
||||
None => true,
|
||||
Some(ref namespace) => *elem.namespace() == *namespace
|
||||
|
@ -74,8 +74,8 @@ impl HTMLCollection {
|
|||
HTMLCollection::create(window, root, box filter)
|
||||
}
|
||||
|
||||
pub fn by_tag_name(window: JSRef<Window>, root: JSRef<Node>, tag: DOMString)
|
||||
-> Temporary<HTMLCollection> {
|
||||
pub fn by_tag_name(window: &Window, root: &Node, tag: DOMString)
|
||||
-> Root<HTMLCollection> {
|
||||
if tag == "*" {
|
||||
return HTMLCollection::all_elements(window, root, None);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ impl HTMLCollection {
|
|||
ascii_lower_tag: Atom,
|
||||
}
|
||||
impl CollectionFilter for TagNameFilter {
|
||||
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
if elem.html_element_in_html_document() {
|
||||
*elem.local_name() == self.ascii_lower_tag
|
||||
} else {
|
||||
|
@ -101,8 +101,8 @@ impl HTMLCollection {
|
|||
HTMLCollection::create(window, root, box filter)
|
||||
}
|
||||
|
||||
pub fn by_tag_name_ns(window: JSRef<Window>, root: JSRef<Node>, tag: DOMString,
|
||||
maybe_ns: Option<DOMString>) -> Temporary<HTMLCollection> {
|
||||
pub fn by_tag_name_ns(window: &Window, root: &Node, tag: DOMString,
|
||||
maybe_ns: Option<DOMString>) -> Root<HTMLCollection> {
|
||||
let namespace_filter = match maybe_ns {
|
||||
Some(ref namespace) if namespace == &"*" => None,
|
||||
ns => Some(namespace::from_domstring(ns)),
|
||||
|
@ -117,7 +117,7 @@ impl HTMLCollection {
|
|||
namespace_filter: Option<Namespace>
|
||||
}
|
||||
impl CollectionFilter for TagNameNSFilter {
|
||||
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
let ns_match = match self.namespace_filter {
|
||||
Some(ref namespace) => {
|
||||
*elem.namespace() == *namespace
|
||||
|
@ -134,14 +134,14 @@ impl HTMLCollection {
|
|||
HTMLCollection::create(window, root, box filter)
|
||||
}
|
||||
|
||||
pub fn by_class_name(window: JSRef<Window>, root: JSRef<Node>, classes: DOMString)
|
||||
-> Temporary<HTMLCollection> {
|
||||
pub fn by_class_name(window: &Window, root: &Node, classes: DOMString)
|
||||
-> Root<HTMLCollection> {
|
||||
#[jstraceable]
|
||||
struct ClassNameFilter {
|
||||
classes: Vec<Atom>
|
||||
}
|
||||
impl CollectionFilter for ClassNameFilter {
|
||||
fn filter(&self, elem: JSRef<Element>, _root: JSRef<Node>) -> bool {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
self.classes.iter().all(|class| elem.has_class(class))
|
||||
}
|
||||
}
|
||||
|
@ -153,30 +153,30 @@ impl HTMLCollection {
|
|||
HTMLCollection::create(window, root, box filter)
|
||||
}
|
||||
|
||||
pub fn children(window: JSRef<Window>, root: JSRef<Node>) -> Temporary<HTMLCollection> {
|
||||
pub fn children(window: &Window, root: &Node) -> Root<HTMLCollection> {
|
||||
#[jstraceable]
|
||||
struct ElementChildFilter;
|
||||
impl CollectionFilter for ElementChildFilter {
|
||||
fn filter(&self, elem: JSRef<Element>, root: JSRef<Node>) -> bool {
|
||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||
root.is_parent_of(NodeCast::from_ref(elem))
|
||||
}
|
||||
}
|
||||
HTMLCollection::create(window, root, box ElementChildFilter)
|
||||
}
|
||||
|
||||
fn traverse(root: JSRef<Node>)
|
||||
fn traverse(root: &Node)
|
||||
-> FilterMap<Skip<TreeIterator>,
|
||||
fn(Temporary<Node>) -> Option<Temporary<Element>>> {
|
||||
fn to_temporary(node: Temporary<Node>) -> Option<Temporary<Element>> {
|
||||
ElementCast::to_temporary(node)
|
||||
fn(Root<Node>) -> Option<Root<Element>>> {
|
||||
fn to_temporary(node: Root<Node>) -> Option<Root<Element>> {
|
||||
ElementCast::to_root(node)
|
||||
}
|
||||
root.traverse_preorder()
|
||||
.skip(1)
|
||||
.filter_map(to_temporary as fn(Temporary<Node>) -> Option<Temporary<Element>>)
|
||||
.filter_map(to_temporary)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
||||
impl<'a> HTMLCollectionMethods for &'a HTMLCollection {
|
||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-length
|
||||
fn Length(self) -> u32 {
|
||||
match self.collection {
|
||||
|
@ -184,30 +184,29 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
CollectionTypeId::Live(ref root, ref filter) => {
|
||||
let root = root.root();
|
||||
HTMLCollection::traverse(root.r())
|
||||
.filter(|element| filter.filter(element.root().r(), root.r()))
|
||||
.filter(|element| filter.filter(element.r(), root.r()))
|
||||
.count() as u32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-item
|
||||
fn Item(self, index: u32) -> Option<Temporary<Element>> {
|
||||
fn Item(self, index: u32) -> Option<Root<Element>> {
|
||||
let index = index as usize;
|
||||
match self.collection {
|
||||
CollectionTypeId::Static(ref elems) => elems
|
||||
.get(index)
|
||||
.map(|elem| Temporary::from_rooted(elem.clone())),
|
||||
.get(index).map(|t| t.root()),
|
||||
CollectionTypeId::Live(ref root, ref filter) => {
|
||||
let root = root.root();
|
||||
HTMLCollection::traverse(root.r())
|
||||
.filter(|element| filter.filter(element.root().r(), root.r()))
|
||||
.filter(|element| filter.filter(element.r(), root.r()))
|
||||
.nth(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
||||
fn NamedItem(self, key: DOMString) -> Option<Temporary<Element>> {
|
||||
fn NamedItem(self, key: DOMString) -> Option<Root<Element>> {
|
||||
// Step 1.
|
||||
if key.is_empty() {
|
||||
return None;
|
||||
|
@ -219,28 +218,25 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
.map(|elem| elem.root())
|
||||
.find(|elem| {
|
||||
elem.r().get_string_attribute(&atom!("name")) == key ||
|
||||
elem.r().get_string_attribute(&atom!("id")) == key })
|
||||
.map(|maybe_elem| Temporary::from_rooted(maybe_elem.r())),
|
||||
elem.r().get_string_attribute(&atom!("id")) == key }),
|
||||
CollectionTypeId::Live(ref root, ref filter) => {
|
||||
let root = root.root();
|
||||
HTMLCollection::traverse(root.r())
|
||||
.map(|element| element.root())
|
||||
.filter(|element| filter.filter(element.r(), root.r()))
|
||||
.find(|elem| {
|
||||
elem.r().get_string_attribute(&atom!("name")) == key ||
|
||||
elem.r().get_string_attribute(&atom!("id")) == key })
|
||||
.map(|elem| Temporary::from_rooted(elem.r()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Element>> {
|
||||
fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Root<Element>> {
|
||||
let maybe_elem = self.Item(index);
|
||||
*found = maybe_elem.is_some();
|
||||
maybe_elem
|
||||
}
|
||||
|
||||
fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option<Temporary<Element>> {
|
||||
fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option<Root<Element>> {
|
||||
let maybe_elem = self.NamedItem(name);
|
||||
*found = maybe_elem.is_some();
|
||||
maybe_elem
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue