mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement cached Document.Links
This commit is contained in:
parent
984ec0e0c3
commit
330f72fba5
1 changed files with 15 additions and 10 deletions
|
@ -78,6 +78,7 @@ pub struct Document {
|
|||
pub is_html_document: bool,
|
||||
url: Untraceable<Url>,
|
||||
quirks_mode: Untraceable<Cell<QuirksMode>>,
|
||||
links: Cell<Option<JS<HTMLCollection>>>,
|
||||
}
|
||||
|
||||
impl DocumentDerived for EventTarget {
|
||||
|
@ -86,6 +87,13 @@ impl DocumentDerived for EventTarget {
|
|||
}
|
||||
}
|
||||
|
||||
struct LinksFilter;
|
||||
impl CollectionFilter for LinksFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
(elem.is_htmlanchorelement() || elem.is_htmlareaelement()) && elem.has_attribute("href")
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DocumentHelpers {
|
||||
fn url<'a>(&'a self) -> &'a Url;
|
||||
fn quirks_mode(&self) -> QuirksMode;
|
||||
|
@ -228,6 +236,7 @@ impl Document {
|
|||
// http://dom.spec.whatwg.org/#concept-document-encoding
|
||||
encoding_name: Traceable::new(RefCell::new("utf-8".to_string())),
|
||||
is_html_document: is_html_document == HTMLDocument,
|
||||
links: Cell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -689,18 +698,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Links(&self) -> Temporary<HTMLCollection> {
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct LinksFilter;
|
||||
impl CollectionFilter for LinksFilter {
|
||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||
(elem.is_htmlanchorelement() || elem.is_htmlareaelement()) &&
|
||||
elem.get_attribute(Null, "href").is_some()
|
||||
}
|
||||
}
|
||||
if self.links.get().is_none() {
|
||||
let window = self.window.root();
|
||||
let root = NodeCast::from_ref(self);
|
||||
let filter = box LinksFilter;
|
||||
HTMLCollection::create(&*window, NodeCast::from_ref(self), filter)
|
||||
self.links.assign(Some(HTMLCollection::create(&*window, root, filter)));
|
||||
}
|
||||
Temporary::new(self.links.get().get_ref().clone())
|
||||
}
|
||||
|
||||
fn Forms(&self) -> Temporary<HTMLCollection> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue