From 330f72fba5e1d0e41556e848bc20af49b08bfd27 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 14 Aug 2014 10:06:52 -0400 Subject: [PATCH 1/3] Implement cached Document.Links --- src/components/script/dom/document.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index eb9eb3d3929..f7ce4c317cd 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -78,6 +78,7 @@ pub struct Document { pub is_html_document: bool, url: Untraceable, quirks_mode: Untraceable>, + links: Cell>>, } impl DocumentDerived for EventTarget { @@ -86,6 +87,13 @@ impl DocumentDerived for EventTarget { } } +struct LinksFilter; +impl CollectionFilter for LinksFilter { + fn filter(&self, elem: &JSRef, _root: &JSRef) -> 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 { - let window = self.window.root(); - // FIXME: https://github.com/mozilla/servo/issues/1847 - struct LinksFilter; - impl CollectionFilter for LinksFilter { - fn filter(&self, elem: &JSRef, _root: &JSRef) -> 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; + self.links.assign(Some(HTMLCollection::create(&*window, root, filter))); } - let filter = box LinksFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) + Temporary::new(self.links.get().get_ref().clone()) } fn Forms(&self) -> Temporary { From 66eb73ca444a535e8ac584f3faf0615b501c708a Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 7 Aug 2014 13:37:45 -0400 Subject: [PATCH 2/3] Added tests for Document's Link cache --- .../content/test_document_links_cache.html | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/content/test_document_links_cache.html diff --git a/src/test/content/test_document_links_cache.html b/src/test/content/test_document_links_cache.html new file mode 100644 index 00000000000..ec6525510dc --- /dev/null +++ b/src/test/content/test_document_links_cache.html @@ -0,0 +1,37 @@ + + + + + + + From 3b916d4e303c0cadaf0342b66dade8eb33a3a508 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 14 Aug 2014 10:27:04 -0400 Subject: [PATCH 3/3] Removed comment as issue #1847 is now fixed. --- src/components/script/dom/document.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index f7ce4c317cd..69d8abaf75f 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -666,8 +666,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Images(&self) -> Temporary { let window = self.window.root(); - - // FIXME: https://github.com/mozilla/servo/issues/1847 struct ImagesFilter; impl CollectionFilter for ImagesFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -680,8 +678,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Embeds(&self) -> Temporary { let window = self.window.root(); - - // FIXME: https://github.com/mozilla/servo/issues/1847 struct EmbedsFilter; impl CollectionFilter for EmbedsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -693,12 +689,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } fn Plugins(&self) -> Temporary { - // FIXME: https://github.com/mozilla/servo/issues/1847 self.Embeds() } fn Links(&self) -> Temporary { - // FIXME: https://github.com/mozilla/servo/issues/1847 if self.links.get().is_none() { let window = self.window.root(); let root = NodeCast::from_ref(self); @@ -710,8 +704,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Forms(&self) -> Temporary { let window = self.window.root(); - - // FIXME: https://github.com/mozilla/servo/issues/1847 struct FormsFilter; impl CollectionFilter for FormsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -724,8 +716,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Scripts(&self) -> Temporary { let window = self.window.root(); - - // FIXME: https://github.com/mozilla/servo/issues/1847 struct ScriptsFilter; impl CollectionFilter for ScriptsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -738,8 +728,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Anchors(&self) -> Temporary { let window = self.window.root(); - - // FIXME: https://github.com/mozilla/servo/issues/1847 struct AnchorsFilter; impl CollectionFilter for AnchorsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool {