aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/css2properties.rs25
-rw-r--r--components/script/dom/cssstyledeclaration.rs10
-rw-r--r--components/script/dom/htmlelement.rs24
-rw-r--r--components/script/dom/webidls/ElementCSSInlineStyle.webidl11
-rw-r--r--components/script/dom/webidls/HTMLElement.webidl1
5 files changed, 62 insertions, 9 deletions
diff --git a/components/script/dom/css2properties.rs b/components/script/dom/css2properties.rs
index db1787f42a3..cafb721e6ac 100644
--- a/components/script/dom/css2properties.rs
+++ b/components/script/dom/css2properties.rs
@@ -2,17 +2,20 @@
* 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::CSS2PropertiesBinding;
use dom::bindings::codegen::Bindings::CSS2PropertiesBinding::CSS2PropertiesMethods;
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
use dom::bindings::codegen::InheritTypes::CSSStyleDeclarationCast;
-use dom::bindings::utils::{Reflectable, Reflector};
-use dom::bindings::js::JSRef;
+use dom::bindings::global;
+use dom::bindings::js::{JSRef, Temporary};
+use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::cssstyledeclaration::CSSStyleDeclaration;
+use dom::window::Window;
use servo_util::str::DOMString;
#[dom_struct]
pub struct CSS2Properties {
- declaration: CSSStyleDeclaration,
+ cssstyledeclaration: CSSStyleDeclaration,
}
macro_rules! css_getter(
@@ -33,6 +36,20 @@ macro_rules! css_setter(
);
)
+impl CSS2Properties {
+ fn new_inherited() -> CSS2Properties {
+ CSS2Properties {
+ cssstyledeclaration: CSSStyleDeclaration::new_inherited(),
+ }
+ }
+
+ pub fn new(global: &JSRef<Window>) -> Temporary<CSS2Properties> {
+ reflect_dom_object(box CSS2Properties::new_inherited(),
+ global::Window(*global),
+ CSS2PropertiesBinding::Wrap)
+ }
+}
+
impl<'a> CSS2PropertiesMethods for JSRef<'a, CSS2Properties> {
css_getter!(Color, "color")
css_setter!(SetColor, "color")
@@ -72,6 +89,6 @@ impl<'a> CSS2PropertiesMethods for JSRef<'a, CSS2Properties> {
impl Reflectable for CSS2Properties {
fn reflector<'a>(&'a self) -> &'a Reflector {
- self.declaration.reflector()
+ self.cssstyledeclaration.reflector()
}
}
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index f2865a5aced..58b6de0ed33 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -4,8 +4,8 @@
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods;
use dom::bindings::error::{ErrorResult, Fallible};
-use dom::bindings::utils::{Reflectable, Reflector};
use dom::bindings::js::JSRef;
+use dom::bindings::utils::{Reflectable, Reflector};
use servo_util::str::DOMString;
use string_cache::atom::Atom;
use std::ascii::AsciiExt;
@@ -44,6 +44,14 @@ fn get_declaration(_property: &Atom) -> Option<Declaration> {
None
}
+impl CSSStyleDeclaration {
+ pub fn new_inherited() -> CSSStyleDeclaration {
+ CSSStyleDeclaration {
+ reflector_: Reflector::new()
+ }
+ }
+}
+
impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
fn CssText(self) -> DOMString {
"".to_string()
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index f8a8ea7ce5c..cf7915f3269 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -10,10 +10,12 @@ use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFrameSetElementDerived};
-use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLInputElementCast};
+use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLInputElementCast, CSSStyleDeclarationCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementDerived, HTMLBodyElementDerived};
-use dom::bindings::js::{JSRef, Temporary};
+use dom::bindings::js::{JSRef, Temporary, MutNullableJS};
use dom::bindings::utils::{Reflectable, Reflector};
+use dom::cssstyledeclaration::CSSStyleDeclaration;
+use dom::css2properties::CSS2Properties;
use dom::document::Document;
use dom::element::{Element, ElementTypeId, ActivationElementHelpers};
use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId};
@@ -24,9 +26,12 @@ use servo_util::str::DOMString;
use string_cache::Atom;
+use std::default::Default;
+
#[dom_struct]
pub struct HTMLElement {
- element: Element
+ element: Element,
+ style_decl: MutNullableJS<CSSStyleDeclaration>,
}
impl HTMLElementDerived for EventTarget {
@@ -42,7 +47,8 @@ impl HTMLElementDerived for EventTarget {
impl HTMLElement {
pub fn new_inherited(type_id: ElementTypeId, tag_name: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLElement {
HTMLElement {
- element: Element::new_inherited(type_id, tag_name, ns!(HTML), prefix, document)
+ element: Element::new_inherited(type_id, tag_name, ns!(HTML), prefix, document),
+ style_decl: Default::default(),
}
}
@@ -65,6 +71,16 @@ impl<'a> PrivateHTMLElementHelpers for JSRef<'a, HTMLElement> {
}
impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> {
+ fn Style(self) -> Temporary<CSSStyleDeclaration> {
+ if self.style_decl.get().is_none() {
+ let global = window_from_node(self);
+ let style_props = CSS2Properties::new(&*global.root()).root();
+ let style_decl: JSRef<CSSStyleDeclaration> = CSSStyleDeclarationCast::from_ref(*style_props);
+ self.style_decl.assign(Some(style_decl));
+ }
+ self.style_decl.get().unwrap()
+ }
+
make_getter!(Title)
make_setter!(SetTitle, "title")
diff --git a/components/script/dom/webidls/ElementCSSInlineStyle.webidl b/components/script/dom/webidls/ElementCSSInlineStyle.webidl
new file mode 100644
index 00000000000..85e14fab10e
--- /dev/null
+++ b/components/script/dom/webidls/ElementCSSInlineStyle.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/. */
+
+//http://dev.w3.org/csswg/cssom/#elementcssinlinestyle
+
+[NoInterfaceObject]
+interface ElementCSSInlineStyle {
+ [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
+};
diff --git a/components/script/dom/webidls/HTMLElement.webidl b/components/script/dom/webidls/HTMLElement.webidl
index 359ef11f0a7..39c7699900d 100644
--- a/components/script/dom/webidls/HTMLElement.webidl
+++ b/components/script/dom/webidls/HTMLElement.webidl
@@ -46,3 +46,4 @@ interface HTMLElement : Element {
//readonly attribute boolean? commandChecked;
};
HTMLElement implements GlobalEventHandlers;
+HTMLElement implements ElementCSSInlineStyle;