mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Added readonly flag for CSSStyleDeclaration
This commit is contained in:
parent
c4b93d30e4
commit
18d8ee6ce0
5 changed files with 35 additions and 14 deletions
|
@ -35,7 +35,8 @@ pub enum Error {
|
|||
Network,
|
||||
Abort,
|
||||
Timeout,
|
||||
DataClone
|
||||
DataClone,
|
||||
NoModificationAllowedError
|
||||
}
|
||||
|
||||
/// The return type for IDL operations that can throw DOM exceptions.
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::{mod, CSSStyleDeclarationMethods};
|
||||
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast};
|
||||
use dom::bindings::error::Error;
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, JSRef, OptionalRootedRootable, Temporary};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
|
@ -24,6 +26,13 @@ use std::ascii::AsciiExt;
|
|||
pub struct CSSStyleDeclaration {
|
||||
reflector_: Reflector,
|
||||
owner: JS<HTMLElement>,
|
||||
readonly: bool,
|
||||
}
|
||||
|
||||
#[deriving(PartialEq)]
|
||||
pub enum CSSModificationAccess {
|
||||
ReadWrite,
|
||||
Readonly
|
||||
}
|
||||
|
||||
macro_rules! css_properties(
|
||||
|
@ -53,15 +62,16 @@ fn serialize_value(declaration: &PropertyDeclaration) -> DOMString {
|
|||
}
|
||||
|
||||
impl CSSStyleDeclaration {
|
||||
pub fn new_inherited(owner: JSRef<HTMLElement>) -> CSSStyleDeclaration {
|
||||
pub fn new_inherited(owner: JSRef<HTMLElement>, modification_access: CSSModificationAccess) -> CSSStyleDeclaration {
|
||||
CSSStyleDeclaration {
|
||||
reflector_: Reflector::new(),
|
||||
owner: JS::from_rooted(owner),
|
||||
readonly: modification_access == CSSModificationAccess::Readonly,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: JSRef<Window>, owner: JSRef<HTMLElement>) -> Temporary<CSSStyleDeclaration> {
|
||||
reflect_dom_object(box CSSStyleDeclaration::new_inherited(owner),
|
||||
pub fn new(global: JSRef<Window>, owner: JSRef<HTMLElement>, modification_access: CSSModificationAccess) -> Temporary<CSSStyleDeclaration> {
|
||||
reflect_dom_object(box CSSStyleDeclaration::new_inherited(owner, modification_access),
|
||||
GlobalRef::Window(global),
|
||||
CSSStyleDeclarationBinding::Wrap)
|
||||
}
|
||||
|
@ -178,7 +188,10 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setproperty
|
||||
fn SetProperty(self, property: DOMString, value: DOMString,
|
||||
priority: DOMString) -> ErrorResult {
|
||||
//TODO: disallow modifications if readonly flag is set
|
||||
// Step 1
|
||||
if self.readonly {
|
||||
return Err(Error::NoModificationAllowedError);
|
||||
}
|
||||
|
||||
// Step 2
|
||||
let property = property.as_slice().to_ascii_lower();
|
||||
|
@ -190,8 +203,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
|
||||
// Step 4
|
||||
if value.is_empty() {
|
||||
self.RemoveProperty(property);
|
||||
return Ok(());
|
||||
return self.RemoveProperty(property).map(|_| ());
|
||||
}
|
||||
|
||||
// Step 5
|
||||
|
@ -234,7 +246,10 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
|
||||
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setpropertypriority
|
||||
fn SetPropertyPriority(self, property: DOMString, priority: DOMString) -> ErrorResult {
|
||||
//TODO: disallow modifications if readonly flag is set
|
||||
// Step 1
|
||||
if self.readonly {
|
||||
return Err(Error::NoModificationAllowedError);
|
||||
}
|
||||
|
||||
// Step 2
|
||||
let property = property.as_slice().to_ascii_lower();
|
||||
|
@ -276,8 +291,11 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
}
|
||||
|
||||
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-removeproperty
|
||||
fn RemoveProperty(self, property: DOMString) -> DOMString {
|
||||
//TODO: disallow modifications if readonly flag is set
|
||||
fn RemoveProperty(self, property: DOMString) -> Fallible<DOMString> {
|
||||
// Step 1
|
||||
if self.readonly {
|
||||
return Err(Error::NoModificationAllowedError);
|
||||
}
|
||||
|
||||
// Step 2
|
||||
let property = property.as_slice().to_ascii_lower();
|
||||
|
@ -290,7 +308,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
Some(longhands) => {
|
||||
// Step 4
|
||||
for longhand in longhands.iter() {
|
||||
self.RemoveProperty(longhand.clone());
|
||||
try!(self.RemoveProperty(longhand.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +321,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
}
|
||||
|
||||
// Step 6
|
||||
value
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
|
||||
|
|
|
@ -55,6 +55,7 @@ impl DOMErrorName {
|
|||
Error::Abort => DOMErrorName::AbortError,
|
||||
Error::Timeout => DOMErrorName::TimeoutError,
|
||||
Error::DataClone => DOMErrorName::DataCloneError,
|
||||
Error::NoModificationAllowedError => DOMErrorName::NoModificationAllowedError,
|
||||
Error::FailureUnknown => panic!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use dom::bindings::js::{JSRef, Temporary, MutNullableJS};
|
|||
use dom::bindings::error::ErrorResult;
|
||||
use dom::bindings::error::Error::Syntax;
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use dom::cssstyledeclaration::CSSStyleDeclaration;
|
||||
use dom::cssstyledeclaration::{CSSStyleDeclaration, CSSModificationAccess};
|
||||
use dom::document::Document;
|
||||
use dom::domstringmap::DOMStringMap;
|
||||
use dom::element::{Element, ElementTypeId, ActivationElementHelpers, AttributeHandlers};
|
||||
|
@ -78,7 +78,7 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> {
|
|||
fn Style(self) -> Temporary<CSSStyleDeclaration> {
|
||||
self.style_decl.or_init(|| {
|
||||
let global = window_from_node(self).root();
|
||||
CSSStyleDeclaration::new(*global, self)
|
||||
CSSStyleDeclaration::new(*global, self, CSSModificationAccess::ReadWrite)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ interface CSSStyleDeclaration {
|
|||
[Throws]
|
||||
void setPropertyPriority(DOMString property, [TreatNullAs=EmptyString] DOMString priority);
|
||||
|
||||
[Throws]
|
||||
DOMString removeProperty(DOMString property);
|
||||
//readonly attribute CSSRule? parentRule;
|
||||
[SetterThrows]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue