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