diff options
author | Corey Farwell <coreyf@rwell.org> | 2016-01-02 16:32:09 -0800 |
---|---|---|
committer | Corey Farwell <coreyf@rwell.org> | 2016-01-02 16:54:38 -0800 |
commit | 1a808219a8e51b8cac8c32a2361a930f24041557 (patch) | |
tree | 80c3895ba76e8451f17c79d8ce73715ca608bc84 /components/style/attr.rs | |
parent | 9a1fd472ab7b136112bb8668d32ba5b324d35220 (diff) | |
download | servo-1a808219a8e51b8cac8c32a2361a930f24041557.tar.gz servo-1a808219a8e51b8cac8c32a2361a930f24041557.zip |
Remove parsed attribute 'background' field on HTMLBodyElement
https://github.com/servo/servo/issues/7863
Diffstat (limited to 'components/style/attr.rs')
-rw-r--r-- | components/style/attr.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/components/style/attr.rs b/components/style/attr.rs index aa7eb621839..dadc07eac29 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -5,6 +5,7 @@ use cssparser::RGBA; use std::ops::Deref; use string_cache::{Atom, Namespace}; +use url::Url; use util::str::{DOMString, LengthOrPercentageOrAuto, parse_unsigned_integer, parse_legacy_color, parse_length}; use util::str::{parse_nonzero_length, split_html_space_chars, str_join, parse_integer}; use values::specified::{Length}; @@ -22,6 +23,7 @@ pub enum AttrValue { Length(DOMString, Option<Length>), Color(DOMString, Option<RGBA>), Dimension(DOMString, LengthOrPercentageOrAuto), + Url(DOMString, Option<Url>), } impl AttrValue { @@ -86,6 +88,11 @@ impl AttrValue { AttrValue::Atom(value) } + pub fn from_url(base: &Url, url: DOMString) -> AttrValue { + let joined = base.join(&url).ok(); + AttrValue::Url(url, joined) + } + pub fn from_legacy_color(string: DOMString) -> AttrValue { let parsed = parse_legacy_color(&string).ok(); AttrValue::Color(string, parsed) @@ -161,6 +168,18 @@ impl AttrValue { } } + /// Assumes the `AttrValue` is a `Url` and returns its value + /// + /// ## Panics + /// + /// Panics if the `AttrValue` is not a `Url` + pub fn as_url(&self) -> Option<&Url> { + match *self { + AttrValue::Url(_, ref url) => url.as_ref(), + _ => panic!("Url not found"), + } + } + /// Return the AttrValue as its integer representation, if any. /// This corresponds to attribute values returned as `AttrValue::UInt(_)` /// by `VirtualMethods::parse_plain_attribute()`. @@ -188,6 +207,7 @@ impl Deref for AttrValue { AttrValue::Length(ref value, _) | AttrValue::Color(ref value, _) | AttrValue::Int(ref value, _) | + AttrValue::Url(ref value, _) | AttrValue::Dimension(ref value, _) => &value, AttrValue::Atom(ref value) => &value, } |