mirror of
https://github.com/servo/servo.git
synced 2025-06-12 18:34:39 +00:00
Initial steps for CSSOM API
This commit is contained in:
parent
e551ea7322
commit
b7a57ef487
15 changed files with 159 additions and 77 deletions
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
|
|
60
components/script/dom/stylesheet.rs
Normal file
60
components/script/dom/stylesheet.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
|
54
components/script/dom/stylesheetlist.rs
Normal file
54
components/script/dom/stylesheetlist.rs
Normal 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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
|
17
components/script/dom/webidls/StyleSheet.webidl
Normal file
17
components/script/dom/webidls/StyleSheet.webidl
Normal 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;
|
||||
};
|
11
components/script/dom/webidls/StyleSheetList.webidl
Normal file
11
components/script/dom/webidls/StyleSheetList.webidl
Normal 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;
|
||||
};
|
|
@ -475,6 +475,7 @@ def check_webidl_spec(file_name, contents):
|
|||
"//dvcs.w3.org/hg",
|
||||
"//dom.spec.whatwg.org",
|
||||
"//domparsing.spec.whatwg.org",
|
||||
"//drafts.csswg.org/cssom",
|
||||
"//drafts.fxtf.org",
|
||||
"//encoding.spec.whatwg.org",
|
||||
"//html.spec.whatwg.org",
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
[interfaces.htm]
|
||||
type: testharness
|
||||
[Document interface: attribute styleSheets]
|
||||
expected: FAIL
|
||||
|
||||
[Document interface: attribute selectedStyleSheetSet]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -18,9 +15,6 @@
|
|||
[Document interface: operation enableStyleSheetsForSet(DOMString)]
|
||||
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)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -39,9 +33,6 @@
|
|||
[Document interface: calling enableStyleSheetsForSet(DOMString) on document with too few arguments must throw TypeError]
|
||||
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)]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -114,33 +105,15 @@
|
|||
[MediaList interface: operation deleteMedium(DOMString)]
|
||||
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]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute href]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute ownerNode]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute parentStyleSheet]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute title]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute media]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -216,39 +189,9 @@
|
|||
[StyleSheet interface: style_element.sheet must inherit property "disabled" with the proper type (6)]
|
||||
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]
|
||||
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]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
[ttwf-cssom-doc-ext-load-count.htm]
|
||||
type: testharness
|
||||
[stylesheet.css should be loaded and styleSheets.length === 1]
|
||||
expected: FAIL
|
||||
|
||||
[stylesheet.css should be unloaded and styleSheets.length === 0]
|
||||
expected: FAIL
|
||||
|
||||
[stylesheet-1.css should be loaded and styleSheets.length === 1]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
[ttwf-cssom-doc-ext-load-tree-order.htm]
|
||||
type: testharness
|
||||
[styleSheets.length must be 5]
|
||||
expected: FAIL
|
||||
|
||||
[styleSheets item 0 title must be aaa]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
[ttwf-cssom-document-extension.htm]
|
||||
type: testharness
|
||||
[CSSOM - Extensions to the Document Interface: StyleSheetList length is 0 when no sheets loaded]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -35,7 +35,3 @@
|
|||
|
||||
[lastModified set according to HTTP header]
|
||||
expected: FAIL
|
||||
|
||||
[styleSheets]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -8448,9 +8448,6 @@
|
|||
[Document interface: iframe.contentDocument must inherit property "onwaiting" with the proper type (156)]
|
||||
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)]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -208,6 +208,8 @@ var interfaceNamesInGlobalScope = [
|
|||
"Screen",
|
||||
"Storage",
|
||||
"StorageEvent",
|
||||
"StyleSheet",
|
||||
"StyleSheetList",
|
||||
"TestBinding", // XXX
|
||||
"TestBindingProxy", // XXX
|
||||
"Text",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue