Initial steps for CSSOM API

This commit is contained in:
Mohamed Albashir 2016-03-18 17:32:48 -04:00 committed by Josh Matthews
parent e551ea7322
commit b7a57ef487
15 changed files with 159 additions and 77 deletions

View file

@ -69,6 +69,7 @@ use dom::nodelist::NodeList;
use dom::processinginstruction::ProcessingInstruction; use dom::processinginstruction::ProcessingInstruction;
use dom::range::Range; use dom::range::Range;
use dom::servohtmlparser::{ParserRoot, ParserRef, MutNullableParserField}; use dom::servohtmlparser::{ParserRoot, ParserRef, MutNullableParserField};
use dom::stylesheetlist::StyleSheetList;
use dom::text::Text; use dom::text::Text;
use dom::touch::Touch; use dom::touch::Touch;
use dom::touchevent::TouchEvent; use dom::touchevent::TouchEvent;
@ -1750,6 +1751,11 @@ impl Element {
} }
impl DocumentMethods for Document { 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 // https://dom.spec.whatwg.org/#dom-document-implementation
fn Implementation(&self) -> Root<DOMImplementation> { fn Implementation(&self) -> Root<DOMImplementation> {
self.implementation.or_init(|| DOMImplementation::new(self)) self.implementation.or_init(|| DOMImplementation::new(self))

View file

@ -359,6 +359,8 @@ pub mod servohtmlparser;
pub mod servoxmlparser; pub mod servoxmlparser;
pub mod storage; pub mod storage;
pub mod storageevent; pub mod storageevent;
pub mod stylesheet;
pub mod stylesheetlist;
pub mod testbinding; pub mod testbinding;
pub mod testbindingproxy; pub mod testbindingproxy;
pub mod text; pub mod text;

View file

@ -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()
}
}

View file

@ -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
}
}

View file

@ -185,3 +185,8 @@ partial interface Document {
partial interface Document { partial interface Document {
Element? elementFromPoint(double x, double y); Element? elementFromPoint(double x, double y);
}; };
// https://drafts.csswg.org/cssom/#extensions-to-the-document-interface
partial interface Document {
[SameObject] readonly attribute StyleSheetList styleSheets;
};

View file

@ -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;
};

View file

@ -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;
};

View file

@ -475,6 +475,7 @@ def check_webidl_spec(file_name, contents):
"//dvcs.w3.org/hg", "//dvcs.w3.org/hg",
"//dom.spec.whatwg.org", "//dom.spec.whatwg.org",
"//domparsing.spec.whatwg.org", "//domparsing.spec.whatwg.org",
"//drafts.csswg.org/cssom",
"//drafts.fxtf.org", "//drafts.fxtf.org",
"//encoding.spec.whatwg.org", "//encoding.spec.whatwg.org",
"//html.spec.whatwg.org", "//html.spec.whatwg.org",

View file

@ -1,8 +1,5 @@
[interfaces.htm] [interfaces.htm]
type: testharness type: testharness
[Document interface: attribute styleSheets]
expected: FAIL
[Document interface: attribute selectedStyleSheetSet] [Document interface: attribute selectedStyleSheetSet]
expected: FAIL expected: FAIL
@ -18,9 +15,6 @@
[Document interface: operation enableStyleSheetsForSet(DOMString)] [Document interface: operation enableStyleSheetsForSet(DOMString)]
expected: FAIL expected: FAIL
[Document interface: document must inherit property "styleSheets" with the proper type (0)]
expected: FAIL
[Document interface: document must inherit property "selectedStyleSheetSet" with the proper type (1)] [Document interface: document must inherit property "selectedStyleSheetSet" with the proper type (1)]
expected: FAIL expected: FAIL
@ -39,9 +33,6 @@
[Document interface: calling enableStyleSheetsForSet(DOMString) on document with too few arguments must throw TypeError] [Document interface: calling enableStyleSheetsForSet(DOMString) on document with too few arguments must throw TypeError]
expected: FAIL expected: FAIL
[Document interface: new Document() must inherit property "styleSheets" with the proper type (0)]
expected: FAIL
[Document interface: new Document() must inherit property "selectedStyleSheetSet" with the proper type (1)] [Document interface: new Document() must inherit property "selectedStyleSheetSet" with the proper type (1)]
expected: FAIL expected: FAIL
@ -114,33 +105,15 @@
[MediaList interface: operation deleteMedium(DOMString)] [MediaList interface: operation deleteMedium(DOMString)]
expected: FAIL expected: FAIL
[StyleSheet interface: existence and properties of interface object]
expected: FAIL
[StyleSheet interface object length]
expected: FAIL
[StyleSheet interface: existence and properties of interface prototype object]
expected: FAIL
[StyleSheet interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[StyleSheet interface: attribute type] [StyleSheet interface: attribute type]
expected: FAIL expected: FAIL
[StyleSheet interface: attribute href]
expected: FAIL
[StyleSheet interface: attribute ownerNode] [StyleSheet interface: attribute ownerNode]
expected: FAIL expected: FAIL
[StyleSheet interface: attribute parentStyleSheet] [StyleSheet interface: attribute parentStyleSheet]
expected: FAIL expected: FAIL
[StyleSheet interface: attribute title]
expected: FAIL
[StyleSheet interface: attribute media] [StyleSheet interface: attribute media]
expected: FAIL expected: FAIL
@ -216,39 +189,9 @@
[StyleSheet interface: style_element.sheet must inherit property "disabled" with the proper type (6)] [StyleSheet interface: style_element.sheet must inherit property "disabled" with the proper type (6)]
expected: FAIL expected: FAIL
[StyleSheetList interface: existence and properties of interface object]
expected: FAIL
[StyleSheetList interface object length]
expected: FAIL
[StyleSheetList interface: existence and properties of interface prototype object] [StyleSheetList interface: existence and properties of interface prototype object]
expected: FAIL expected: FAIL
[StyleSheetList interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[StyleSheetList interface: operation item(unsigned long)]
expected: FAIL
[StyleSheetList interface: attribute length]
expected: FAIL
[StyleSheetList must be primary interface of document.styleSheets]
expected: FAIL
[Stringification of document.styleSheets]
expected: FAIL
[StyleSheetList interface: document.styleSheets must inherit property "item" with the proper type (0)]
expected: FAIL
[StyleSheetList interface: calling item(unsigned long) on document.styleSheets with too few arguments must throw TypeError]
expected: FAIL
[StyleSheetList interface: document.styleSheets must inherit property "length" with the proper type (1)]
expected: FAIL
[CSSRuleList interface: existence and properties of interface object] [CSSRuleList interface: existence and properties of interface object]
expected: FAIL expected: FAIL

View file

@ -1,11 +1,4 @@
[ttwf-cssom-doc-ext-load-count.htm] [ttwf-cssom-doc-ext-load-count.htm]
type: testharness type: testharness
[stylesheet.css should be loaded and styleSheets.length === 1]
expected: FAIL
[stylesheet.css should be unloaded and styleSheets.length === 0] [stylesheet.css should be unloaded and styleSheets.length === 0]
expected: FAIL expected: FAIL
[stylesheet-1.css should be loaded and styleSheets.length === 1]
expected: FAIL

View file

@ -1,8 +1,5 @@
[ttwf-cssom-doc-ext-load-tree-order.htm] [ttwf-cssom-doc-ext-load-tree-order.htm]
type: testharness type: testharness
[styleSheets.length must be 5]
expected: FAIL
[styleSheets item 0 title must be aaa] [styleSheets item 0 title must be aaa]
expected: FAIL expected: FAIL

View file

@ -1,5 +1,3 @@
[ttwf-cssom-document-extension.htm] [ttwf-cssom-document-extension.htm]
type: testharness type: testharness
[CSSOM - Extensions to the Document Interface: StyleSheetList length is 0 when no sheets loaded]
expected: FAIL

View file

@ -35,7 +35,3 @@
[lastModified set according to HTTP header] [lastModified set according to HTTP header]
expected: FAIL expected: FAIL
[styleSheets]
expected: FAIL

View file

@ -8069,7 +8069,7 @@
[Document interface: iframe.contentDocument must inherit property "createTreeWalker" with the proper type (27)] [Document interface: iframe.contentDocument must inherit property "createTreeWalker" with the proper type (27)]
expected: FAIL expected: FAIL
[Document interface: iframe.contentDocument must inherit property "styleSheets" with the proper type (28)] [Document interface: iframe.contentDocument must inherit property "styleSheets" with the proper type (28)]
expected: FAIL expected: FAIL
@ -8448,9 +8448,6 @@
[Document interface: iframe.contentDocument must inherit property "onwaiting" with the proper type (156)] [Document interface: iframe.contentDocument must inherit property "onwaiting" with the proper type (156)]
expected: FAIL expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "styleSheets" with the proper type (28)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "selectedStyleSheetSet" with the proper type (29)] [Document interface: document.implementation.createDocument(null, "", null) must inherit property "selectedStyleSheetSet" with the proper type (29)]
expected: FAIL expected: FAIL

View file

@ -208,6 +208,8 @@ var interfaceNamesInGlobalScope = [
"Screen", "Screen",
"Storage", "Storage",
"StorageEvent", "StorageEvent",
"StyleSheet",
"StyleSheetList",
"TestBinding", // XXX "TestBinding", // XXX
"TestBindingProxy", // XXX "TestBindingProxy", // XXX
"Text", "Text",