mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #9136 - frewsxcv:htmlbodyelement-background, r=nox
HTMLBodyElement 'background' attribute improvements <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9136) <!-- Reviewable:end -->
This commit is contained in:
commit
1b0053f8b1
6 changed files with 46 additions and 148 deletions
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue