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::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))

View file

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

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