aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-16 15:05:59 -0600
committerGitHub <noreply@github.com>2016-11-16 15:05:59 -0600
commitafc60bee2809059b8b754a1c6d6d10c1d36326fb (patch)
tree8813d15dd9a140bc612a181b1120fe739ede355a /components/script/dom/node.rs
parent17bf6aed21cb966c52382e7cef23d2bd66144874 (diff)
parent7fcad8afde9a4e70643e85499ca9a262b5dd474c (diff)
downloadservo-afc60bee2809059b8b754a1c6d6d10c1d36326fb.tar.gz
servo-afc60bee2809059b8b754a1c6d6d10c1d36326fb.zip
Auto merge of #14190 - Manishearth:cssom, r=SimonSapin
Immutable CSSOM This PR is intended to add basic support for all CSSOM interfaces, with the ability to index `document.styleSheets` and css rule lists, and serializing individual css rules. Handling individual interface methods for CSSRule subclasses can probably be done with easy/medium bugs. Mutation safety isn't dealt with here; if the css rule list is mutated the CSSOM will be in an inconsistent state. I intend to deal with this via zero sized tokens, see https://groups.google.com/forum/#!topic/mozilla.dev.servo/AnxJoVmtMXQ . I'll handle that when I start making the CSSOM mutable. (Getting the immutable bit landed first opens this up for easy bugs) This doesn't really change style aside from adding an extra arc in the CSS rule list as discussed in the linked thread. So far this same design can be used by stylo as well when the time comes. f? @SimonSapin @emilio cc @upsuper part of #11420 Todo: - [x] Stubs for rest of the CSSRule subclasses - [x] <s>ToCSS impls for CSSRules.</s> May make into easy bugs and stub out in this PR https://github.com/servo/servo/issues/14195 - [x] Cache CSSStyleSheet on the relevant node <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14190) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 0f510719640..37e0548fa13 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -30,6 +30,7 @@ use dom::bindings::reflector::{Reflectable, reflect_dom_object};
use dom::bindings::str::{DOMString, USVString};
use dom::bindings::xmlname::namespace_from_domstring;
use dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
+use dom::cssstylesheet::CSSStyleSheet;
use dom::document::{Document, DocumentSource, IsHTMLDocument};
use dom::documentfragment::DocumentFragment;
use dom::documenttype::DocumentType;
@@ -43,6 +44,9 @@ use dom::htmlelement::HTMLElement;
use dom::htmliframeelement::{HTMLIFrameElement, HTMLIFrameElementLayoutMethods};
use dom::htmlimageelement::{HTMLImageElement, LayoutHTMLImageElementHelpers};
use dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
+use dom::htmllinkelement::HTMLLinkElement;
+use dom::htmlmetaelement::HTMLMetaElement;
+use dom::htmlstyleelement::HTMLStyleElement;
use dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
@@ -76,8 +80,10 @@ use std::default::Default;
use std::iter;
use std::mem;
use std::ops::Range;
+use std::sync::Arc;
use style::dom::OpaqueNode;
use style::selector_impl::ServoSelectorImpl;
+use style::stylesheets::Stylesheet;
use style::thread_state;
use url::Url;
use uuid::Uuid;
@@ -901,6 +907,30 @@ impl Node {
element.upcast::<Node>().remove_self();
Ok(())
}
+
+ pub fn get_stylesheet(&self) -> Option<Arc<Stylesheet>> {
+ if let Some(node) = self.downcast::<HTMLStyleElement>() {
+ node.get_stylesheet()
+ } else if let Some(node) = self.downcast::<HTMLLinkElement>() {
+ node.get_stylesheet()
+ } else if let Some(node) = self.downcast::<HTMLMetaElement>() {
+ node.get_stylesheet()
+ } else {
+ None
+ }
+ }
+
+ pub fn get_cssom_stylesheet(&self) -> Option<Root<CSSStyleSheet>> {
+ if let Some(node) = self.downcast::<HTMLStyleElement>() {
+ node.get_cssom_stylesheet()
+ } else if let Some(node) = self.downcast::<HTMLLinkElement>() {
+ node.get_cssom_stylesheet()
+ } else if let Some(node) = self.downcast::<HTMLMetaElement>() {
+ node.get_cssom_stylesheet()
+ } else {
+ None
+ }
+ }
}