mirror of
https://github.com/servo/servo.git
synced 2025-07-30 10:40:27 +01:00
Stub in some uses of getPropertyValue and sketch out its implementation.
This commit is contained in:
parent
4da0ca8ace
commit
2cfa8e85a6
3 changed files with 114 additions and 27 deletions
|
@ -15,41 +15,54 @@ pub struct CSS2Properties {
|
|||
declaration: CSSStyleDeclaration,
|
||||
}
|
||||
|
||||
macro_rules! css_getter(
|
||||
( $idlattr:ident, $cssprop:expr ) => (
|
||||
fn $idlattr(self) -> DOMString {
|
||||
let decl: JSRef<CSSStyleDeclaration> = CSSStyleDeclarationCast::from_ref(self);
|
||||
decl.GetPropertyValue($cssprop.to_string())
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
macro_rules! css_setter(
|
||||
( $fnname:ident, $cssprop:expr ) => (
|
||||
fn $fnname(self, value: DOMString) {
|
||||
let decl: JSRef<CSSStyleDeclaration> = CSSStyleDeclarationCast::from_ref(self);
|
||||
decl.SetPropertyValue($cssprop.to_string(), value).unwrap();
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
impl<'a> CSS2PropertiesMethods for JSRef<'a, CSS2Properties> {
|
||||
fn Color(self) -> DOMString {
|
||||
"".to_string()
|
||||
}
|
||||
css_getter!(Color, "color")
|
||||
css_setter!(SetColor, "color")
|
||||
|
||||
fn SetColor(self, _value: DOMString) {
|
||||
}
|
||||
css_getter!(Background, "background")
|
||||
css_setter!(SetBackground, "background")
|
||||
|
||||
fn Background(self) -> DOMString {
|
||||
"".to_string()
|
||||
}
|
||||
css_getter!(BackgroundColor, "background-color")
|
||||
css_setter!(SetBackgroundColor, "background-color")
|
||||
|
||||
fn SetBackground(self, _value: DOMString) {
|
||||
}
|
||||
css_getter!(BackgroundPosition, "background-position")
|
||||
css_setter!(SetBackgroundPosition, "background-position")
|
||||
|
||||
fn Display(self) -> DOMString {
|
||||
"".to_string()
|
||||
}
|
||||
css_getter!(BackgroundImage, "background-image")
|
||||
css_setter!(SetBackgroundImage, "background-image")
|
||||
|
||||
fn SetDisplay(self, _value: DOMString) {
|
||||
}
|
||||
css_getter!(BackgroundRepeat, "background-repeat")
|
||||
css_setter!(SetBackgroundRepeat, "background-repeat")
|
||||
|
||||
fn Width(self) -> DOMString {
|
||||
"".to_string()
|
||||
}
|
||||
css_getter!(BackgroundAttachment, "background-attachment")
|
||||
css_setter!(SetBackgroundAttachment, "background-attachment")
|
||||
|
||||
fn SetWidth(self, _value: DOMString) {
|
||||
}
|
||||
css_getter!(Display, "display")
|
||||
css_setter!(SetDisplay, "display")
|
||||
|
||||
fn Height(self) -> DOMString {
|
||||
"".to_string()
|
||||
}
|
||||
css_getter!(Width, "width")
|
||||
css_setter!(SetWidth, "width")
|
||||
|
||||
fn SetHeight(self, _value: DOMString) {
|
||||
}
|
||||
css_getter!(Height, "height")
|
||||
css_setter!(SetHeight, "height")
|
||||
|
||||
fn IndexedGetter(self, index: u32, found: &mut bool) -> DOMString {
|
||||
let decl: JSRef<CSSStyleDeclaration> = CSSStyleDeclarationCast::from_ref(self);
|
||||
|
|
|
@ -7,12 +7,43 @@ use dom::bindings::error::{ErrorResult, Fallible};
|
|||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::bindings::js::JSRef;
|
||||
use servo_util::str::DOMString;
|
||||
use string_cache::atom::Atom;
|
||||
use std::ascii::AsciiExt;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSStyleDeclaration {
|
||||
reflector_: Reflector,
|
||||
}
|
||||
|
||||
fn get_longhands_from_shorthand(shorthand: &Atom) -> Vec<Atom> {
|
||||
match shorthand.as_slice() {
|
||||
"background" =>
|
||||
vec!(Atom::from_slice("background-color"), Atom::from_slice("background-position"),
|
||||
Atom::from_slice("background-attachment"), Atom::from_slice("background-image"),
|
||||
Atom::from_slice("background-repeat")),
|
||||
_ => vec!(),
|
||||
}
|
||||
}
|
||||
|
||||
type Declaration = int;
|
||||
|
||||
fn serialize_list(property: String, list: Vec<Declaration>) -> DOMString {
|
||||
let mut result = property;
|
||||
result.push_str(": ");
|
||||
for declaration in list.iter() {
|
||||
result.push_str(serialize_declaration(declaration).as_slice());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn serialize_declaration(_declaration: &Declaration) -> DOMString {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
fn get_declaration(_property: &Atom) -> Option<Declaration> {
|
||||
None
|
||||
}
|
||||
|
||||
impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
||||
fn CssText(self) -> DOMString {
|
||||
"".to_string()
|
||||
|
@ -30,8 +61,46 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
|
|||
"".to_string()
|
||||
}
|
||||
|
||||
fn GetPropertyValue(self, _property: DOMString) -> DOMString {
|
||||
"".to_string()
|
||||
//http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||
fn GetPropertyValue(self, property: DOMString) -> DOMString {
|
||||
// 1. Let property be property converted to ASCII lowercase.
|
||||
let property = Atom::from_slice(property.as_slice().to_ascii_lower().as_slice());
|
||||
|
||||
// 2. If property is a shorthand property, then follow these substeps:
|
||||
let longhand_properties = get_longhands_from_shorthand(&property);
|
||||
if !longhand_properties.is_empty() {
|
||||
// 1. Let list be a new empty array.
|
||||
let mut list = vec!();
|
||||
|
||||
// 2. For each longhand property longhand that property maps to, in canonical order,
|
||||
// follow these substeps:
|
||||
for longhand in longhand_properties.iter() {
|
||||
// 1. If longhand is a case-sensitive match for a property name of a
|
||||
// CSS declaration in the declarations, let declaration be that CSS
|
||||
// declaration, or null otherwise.
|
||||
let declaration = get_declaration(longhand);
|
||||
|
||||
// 2. If declaration is null, return the empty string and terminate these
|
||||
// steps.
|
||||
if declaration.is_none() {
|
||||
return "".to_string();
|
||||
}
|
||||
|
||||
// 3. Append the declaration to list.
|
||||
list.push(declaration.unwrap());
|
||||
}
|
||||
|
||||
// 3. Return the serialization of list and terminate these steps.
|
||||
return serialize_list(property.as_slice().to_string(), list);
|
||||
}
|
||||
|
||||
// 3. If property is a case-sensitive match for a property name of a CSS declaration
|
||||
// in the declarations, return the result of invoking serialize a CSS value of that
|
||||
// declaration and terminate these steps.
|
||||
// 4. Return the empty string.
|
||||
let declaration = get_declaration(&property);
|
||||
declaration.as_ref().map(|declaration| serialize_declaration(declaration))
|
||||
.unwrap_or("".to_string())
|
||||
}
|
||||
|
||||
fn GetPropertyPriority(self, _property: DOMString) -> DOMString {
|
||||
|
|
|
@ -12,6 +12,11 @@ interface CSS2Properties : CSSStyleDeclaration {
|
|||
[TreatNullAs=EmptyString] attribute DOMString color;
|
||||
[TreatNullAs=EmptyString] attribute DOMString display;
|
||||
[TreatNullAs=EmptyString] attribute DOMString background;
|
||||
[TreatNullAs=EmptyString] attribute DOMString backgroundColor;
|
||||
[TreatNullAs=EmptyString] attribute DOMString backgroundPosition;
|
||||
[TreatNullAs=EmptyString] attribute DOMString backgroundRepeat;
|
||||
[TreatNullAs=EmptyString] attribute DOMString backgroundImage;
|
||||
[TreatNullAs=EmptyString] attribute DOMString backgroundAttachment;
|
||||
[TreatNullAs=EmptyString] attribute DOMString width;
|
||||
[TreatNullAs=EmptyString] attribute DOMString height;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue