mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Change AttrValue::Url to AttrValue::ResolvedUrl
There is actually only one attribute that can use that, the one for <body background>.
This commit is contained in:
parent
8b366a7441
commit
c7b1d3054f
9 changed files with 48 additions and 72 deletions
|
@ -46,7 +46,12 @@ pub enum AttrValue {
|
|||
Length(String, Option<Length>),
|
||||
Color(String, Option<RGBA>),
|
||||
Dimension(String, LengthOrPercentageOrAuto),
|
||||
Url(String, Option<ServoUrl>),
|
||||
|
||||
/// Stores a URL, computed from the input string and a document's base URL.
|
||||
///
|
||||
/// The URL is resolved at setting-time, so this kind of attribute value is
|
||||
/// not actually suitable for most URL-reflecting IDL attributes.
|
||||
ResolvedUrl(String, Option<ServoUrl>),
|
||||
|
||||
/// Note that this variant is only used transitively as a fast path to set
|
||||
/// the property declaration block relevant to the style of an element when
|
||||
|
@ -227,9 +232,9 @@ impl AttrValue {
|
|||
AttrValue::Atom(value)
|
||||
}
|
||||
|
||||
pub fn from_url(base: ServoUrl, url: String) -> AttrValue {
|
||||
pub fn from_resolved_url(base: &ServoUrl, url: String) -> AttrValue {
|
||||
let joined = base.join(&url).ok();
|
||||
AttrValue::Url(url, joined)
|
||||
AttrValue::ResolvedUrl(url, joined)
|
||||
}
|
||||
|
||||
pub fn from_legacy_color(string: String) -> AttrValue {
|
||||
|
@ -307,14 +312,14 @@ impl AttrValue {
|
|||
}
|
||||
}
|
||||
|
||||
/// Assumes the `AttrValue` is a `Url` and returns its value
|
||||
/// Assumes the `AttrValue` is a `ResolvedUrl` and returns its value.
|
||||
///
|
||||
/// ## Panics
|
||||
///
|
||||
/// Panics if the `AttrValue` is not a `Url`
|
||||
pub fn as_url(&self) -> Option<&ServoUrl> {
|
||||
/// Panics if the `AttrValue` is not a `ResolvedUrl`
|
||||
pub fn as_resolved_url(&self) -> Option<&ServoUrl> {
|
||||
match *self {
|
||||
AttrValue::Url(_, ref url) => url.as_ref(),
|
||||
AttrValue::ResolvedUrl(_, ref url) => url.as_ref(),
|
||||
_ => panic!("Url not found"),
|
||||
}
|
||||
}
|
||||
|
@ -365,15 +370,15 @@ impl ::std::ops::Deref for AttrValue {
|
|||
fn deref(&self) -> &str {
|
||||
match *self {
|
||||
AttrValue::String(ref value) |
|
||||
AttrValue::TokenList(ref value, _) |
|
||||
AttrValue::UInt(ref value, _) |
|
||||
AttrValue::Double(ref value, _) |
|
||||
AttrValue::Length(ref value, _) |
|
||||
AttrValue::Color(ref value, _) |
|
||||
AttrValue::Int(ref value, _) |
|
||||
AttrValue::Url(ref value, _) |
|
||||
AttrValue::Declaration(ref value, _) |
|
||||
AttrValue::Dimension(ref value, _) => &value,
|
||||
AttrValue::TokenList(ref value, _) |
|
||||
AttrValue::UInt(ref value, _) |
|
||||
AttrValue::Double(ref value, _) |
|
||||
AttrValue::Length(ref value, _) |
|
||||
AttrValue::Color(ref value, _) |
|
||||
AttrValue::Int(ref value, _) |
|
||||
AttrValue::ResolvedUrl(ref value, _) |
|
||||
AttrValue::Declaration(ref value, _) |
|
||||
AttrValue::Dimension(ref value, _) => &value,
|
||||
AttrValue::Atom(ref value) => &value,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue