aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorMohamed Albashir <mohamedalbashir@localhost.localdomain>2016-03-18 17:32:48 -0400
committerJosh Matthews <josh@joshmatthews.net>2016-03-31 18:17:30 -0400
commitb7a57ef4875a205254be64ae092eeedf6680d2b9 (patch)
tree03100c61e9b3aaef888bb7d1826543ac42822efc /components/script/dom
parente551ea73226404152e02c3445f4f91e639bf66ce (diff)
downloadservo-b7a57ef4875a205254be64ae092eeedf6680d2b9.tar.gz
servo-b7a57ef4875a205254be64ae092eeedf6680d2b9.zip
Initial steps for CSSOM API
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/document.rs6
-rw-r--r--components/script/dom/mod.rs2
-rw-r--r--components/script/dom/stylesheet.rs60
-rw-r--r--components/script/dom/stylesheetlist.rs54
-rw-r--r--components/script/dom/webidls/Document.webidl5
-rw-r--r--components/script/dom/webidls/StyleSheet.webidl17
-rw-r--r--components/script/dom/webidls/StyleSheetList.webidl11
7 files changed, 155 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index db565414ce1..0a148f0cb69 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -69,6 +69,7 @@ use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction;
use dom::range::Range;
use dom::servohtmlparser::{ParserRoot, ParserRef, MutNullableParserField};
+use dom::stylesheetlist::StyleSheetList;
use dom::text::Text;
use dom::touch::Touch;
use dom::touchevent::TouchEvent;
@@ -1750,6 +1751,11 @@ impl Element {
}
impl DocumentMethods for Document {
+ // https://drafts.csswg.org/cssom/#dom-document-stylesheets
+ fn StyleSheets(&self) -> Root<StyleSheetList> {
+ StyleSheetList::new(&self.window, JS::from_ref(&self))
+ }
+
// https://dom.spec.whatwg.org/#dom-document-implementation
fn Implementation(&self) -> Root<DOMImplementation> {
self.implementation.or_init(|| DOMImplementation::new(self))
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 15c57d04e60..e75c717b154 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -359,6 +359,8 @@ pub mod servohtmlparser;
pub mod servoxmlparser;
pub mod storage;
pub mod storageevent;
+pub mod stylesheet;
+pub mod stylesheetlist;
pub mod testbinding;
pub mod testbindingproxy;
pub mod text;
diff --git a/components/script/dom/stylesheet.rs b/components/script/dom/stylesheet.rs
new file mode 100644
index 00000000000..490acd997ed
--- /dev/null
+++ b/components/script/dom/stylesheet.rs
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use dom::bindings::codegen::Bindings::StyleSheetBinding;
+use dom::bindings::codegen::Bindings::StyleSheetBinding::StyleSheetMethods;
+use dom::bindings::global::GlobalRef;
+use dom::bindings::js::{Root};
+use dom::bindings::reflector::{Reflector, reflect_dom_object};
+use dom::window::Window;
+use util::str::DOMString;
+
+
+#[dom_struct]
+pub struct StyleSheet {
+ reflector_: Reflector,
+ type_: DOMString,
+ href: Option<DOMString>,
+ title: Option<DOMString>,
+}
+
+impl StyleSheet {
+ #[allow(unrooted_must_root)]
+ fn new_inherited(type_: DOMString, href: Option<DOMString>, title: Option<DOMString>) -> StyleSheet {
+ StyleSheet {
+ reflector_: Reflector::new(),
+ type_: type_,
+ href: href,
+ title: title
+ }
+ }
+
+ #[allow(unrooted_must_root)]
+ pub fn new(window: &Window, type_: DOMString,
+ href: Option<DOMString>,
+ title: Option<DOMString>) -> Root<StyleSheet> {
+ reflect_dom_object(box StyleSheet::new_inherited(type_, href, title),
+ GlobalRef::Window(window),
+ StyleSheetBinding::Wrap)
+ }
+}
+
+
+impl StyleSheetMethods for StyleSheet {
+ // https://drafts.csswg.org/cssom/#dom-stylesheet-type
+ fn Type_(&self) -> DOMString {
+ self.type_.clone()
+ }
+
+ // https://drafts.csswg.org/cssom/#dom-stylesheet-href
+ fn GetHref(&self) -> Option<DOMString> {
+ self.href.clone()
+ }
+
+ // https://drafts.csswg.org/cssom/#dom-stylesheet-title
+ fn GetTitle(&self) -> Option<DOMString> {
+ self.title.clone()
+ }
+}
+
diff --git a/components/script/dom/stylesheetlist.rs b/components/script/dom/stylesheetlist.rs
new file mode 100644
index 00000000000..d6c58256dc2
--- /dev/null
+++ b/components/script/dom/stylesheetlist.rs
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use dom::bindings::codegen::Bindings::StyleSheetListBinding;
+use dom::bindings::codegen::Bindings::StyleSheetListBinding::StyleSheetListMethods;
+use dom::bindings::global::GlobalRef;
+use dom::bindings::js::{JS, Root};
+use dom::bindings::reflector::{Reflector, reflect_dom_object};
+use dom::document::Document;
+use dom::stylesheet::StyleSheet;
+use dom::window::Window;
+
+#[dom_struct]
+pub struct StyleSheetList {
+ reflector_: Reflector,
+ document: JS<Document>,
+}
+
+impl StyleSheetList {
+ #[allow(unrooted_must_root)]
+ fn new_inherited(doc: JS<Document>) -> StyleSheetList {
+ StyleSheetList {
+ reflector_: Reflector::new(),
+ document: doc
+ }
+ }
+
+ #[allow(unrooted_must_root)]
+ pub fn new(window: &Window, document: JS<Document>) -> Root<StyleSheetList> {
+ reflect_dom_object(box StyleSheetList::new_inherited(document),
+ GlobalRef::Window(window), StyleSheetListBinding::Wrap)
+ }
+}
+
+impl StyleSheetListMethods for StyleSheetList {
+ // https://drafts.csswg.org/cssom/#dom-stylesheetlist-length
+ fn Length(&self) -> u32 {
+ self.document.stylesheets().len() as u32
+ }
+
+ // https://drafts.csswg.org/cssom/#dom-stylesheetlist-item
+ fn Item(&self, index: u32) -> Option<Root<StyleSheet>> {
+ None
+ //TODO Create a new StyleSheet object and return it
+ }
+
+ // check-tidy: no specs after this line
+ fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Root<StyleSheet>>{
+ let item = self.Item(index);
+ *found = item.is_some();
+ item
+ }
+}
diff --git a/components/script/dom/webidls/Document.webidl b/components/script/dom/webidls/Document.webidl
index 6c1814fa43b..845037e430c 100644
--- a/components/script/dom/webidls/Document.webidl
+++ b/components/script/dom/webidls/Document.webidl
@@ -185,3 +185,8 @@ partial interface Document {
partial interface Document {
Element? elementFromPoint(double x, double y);
};
+
+// https://drafts.csswg.org/cssom/#extensions-to-the-document-interface
+partial interface Document {
+ [SameObject] readonly attribute StyleSheetList styleSheets;
+};
diff --git a/components/script/dom/webidls/StyleSheet.webidl b/components/script/dom/webidls/StyleSheet.webidl
new file mode 100644
index 00000000000..fdb4e875ce2
--- /dev/null
+++ b/components/script/dom/webidls/StyleSheet.webidl
@@ -0,0 +1,17 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// https://drafts.csswg.org/cssom/#the-stylesheet-interface
+interface StyleSheet {
+ readonly attribute DOMString type_;
+ readonly attribute DOMString? href;
+
+ // readonly attribute (Element or ProcessingInstruction)? ownerNode;
+ // readonly attribute StyleSheet? parentStyleSheet;
+ readonly attribute DOMString? title;
+
+ // [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
+ // attribute boolean disabled;
+};
diff --git a/components/script/dom/webidls/StyleSheetList.webidl b/components/script/dom/webidls/StyleSheetList.webidl
new file mode 100644
index 00000000000..e743653fde3
--- /dev/null
+++ b/components/script/dom/webidls/StyleSheetList.webidl
@@ -0,0 +1,11 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// https://drafts.csswg.org/cssom/#the-stylesheetlist-interface
+// [ArrayClass]
+interface StyleSheetList {
+ getter StyleSheet? item(unsigned long index);
+ readonly attribute unsigned long length;
+};