mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move ComputedUrl into their impl mods.
This commit is contained in:
parent
d001fd9a0a
commit
0090fbb3c8
4 changed files with 57 additions and 58 deletions
|
@ -196,3 +196,8 @@ impl MallocSizeOf for SpecifiedImageUrl {
|
|||
n
|
||||
}
|
||||
}
|
||||
|
||||
/// The computed value of a CSS `url()`.
|
||||
pub type ComputedUrl = SpecifiedUrl;
|
||||
/// The computed value of a CSS `url()` for image.
|
||||
pub type ComputedImageUrl = SpecifiedImageUrl;
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
//! Common handling for the specified value CSS url() values.
|
||||
|
||||
use parser::ParserContext;
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use servo_url::ServoUrl;
|
||||
use std::fmt::{self, Write};
|
||||
// Note: We use std::sync::Arc rather than servo_arc::Arc here because the
|
||||
|
@ -12,7 +13,7 @@ use std::fmt::{self, Write};
|
|||
// the threshold.
|
||||
use std::sync::Arc;
|
||||
use style_traits::{CssWriter, ParseError, ToCss};
|
||||
use values::computed::{Context, ToComputedValue, ComputedUrl};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
|
||||
/// A specified url() value for servo.
|
||||
///
|
||||
|
@ -174,3 +175,41 @@ impl ToComputedValue for SpecifiedUrl {
|
|||
|
||||
/// A specified image url() value for servo.
|
||||
pub type SpecifiedImageUrl = SpecifiedUrl;
|
||||
|
||||
/// The computed value of a CSS `url()`, resolved relative to the stylesheet URL.
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub enum ComputedUrl {
|
||||
/// The `url()` was invalid or it wasn't specified by the user.
|
||||
Invalid(#[ignore_malloc_size_of = "Arc"] Arc<String>),
|
||||
/// The resolved `url()` relative to the stylesheet URL.
|
||||
Valid(ServoUrl),
|
||||
}
|
||||
|
||||
impl ComputedUrl {
|
||||
/// Returns the resolved url if it was valid.
|
||||
pub fn url(&self) -> Option<&ServoUrl> {
|
||||
match *self {
|
||||
ComputedUrl::Valid(ref url) => Some(url),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for ComputedUrl {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let string = match *self {
|
||||
ComputedUrl::Valid(ref url) => url.as_str(),
|
||||
ComputedUrl::Invalid(ref invalid_string) => invalid_string,
|
||||
};
|
||||
|
||||
dest.write_str("url(")?;
|
||||
string.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
/// The computed value of a CSS `url()` for image.
|
||||
pub type ComputedImageUrl = ComputedUrl;
|
||||
|
|
|
@ -15,14 +15,10 @@ use media_queries::Device;
|
|||
use properties;
|
||||
use properties::{ComputedValues, LonghandId, StyleBuilder};
|
||||
use rule_cache::RuleCacheConditions;
|
||||
#[cfg(feature = "servo")]
|
||||
use servo_url::ServoUrl;
|
||||
use std::cell::RefCell;
|
||||
use std::cmp;
|
||||
use std::f32;
|
||||
use std::fmt::{self, Write};
|
||||
#[cfg(feature = "servo")]
|
||||
use std::sync::Arc;
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use style_traits::cursor::CursorKind;
|
||||
use super::{CSSFloat, CSSInteger};
|
||||
|
@ -84,6 +80,7 @@ pub use self::time::Time;
|
|||
pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation};
|
||||
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
|
||||
pub use self::ui::MozForceBrokenImageIcon;
|
||||
pub use self::url::{ComputedUrl, ComputedImageUrl};
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub mod align;
|
||||
|
@ -117,6 +114,14 @@ pub mod time;
|
|||
pub mod transform;
|
||||
pub mod ui;
|
||||
|
||||
/// Common handling for the computed value CSS url() values.
|
||||
pub mod url {
|
||||
#[cfg(feature = "servo")]
|
||||
pub use ::servo::url::{ComputedUrl, ComputedImageUrl};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use ::gecko::url::{ComputedUrl, ComputedImageUrl};
|
||||
}
|
||||
|
||||
/// A `Context` is all the data a specified value could ever need to compute
|
||||
/// itself and be transformed to a computed value.
|
||||
pub struct Context<'a> {
|
||||
|
@ -636,56 +641,6 @@ impl ClipRectOrAuto {
|
|||
}
|
||||
}
|
||||
|
||||
/// The computed value of a CSS `url()`, resolved relative to the stylesheet URL.
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub enum ComputedUrl {
|
||||
/// The `url()` was invalid or it wasn't specified by the user.
|
||||
Invalid(#[ignore_malloc_size_of = "Arc"] Arc<String>),
|
||||
/// The resolved `url()` relative to the stylesheet URL.
|
||||
Valid(ServoUrl),
|
||||
}
|
||||
|
||||
/// The computed value of a CSS `url()` for image.
|
||||
#[cfg(feature = "servo")]
|
||||
pub type ComputedImageUrl = ComputedUrl;
|
||||
|
||||
// TODO: Properly build ComputedUrl for gecko
|
||||
/// The computed value of a CSS `url()`.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type ComputedUrl = specified::url::SpecifiedUrl;
|
||||
/// The computed value of a CSS `url()` for image.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub type ComputedImageUrl = specified::url::SpecifiedImageUrl;
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ComputedUrl {
|
||||
/// Returns the resolved url if it was valid.
|
||||
pub fn url(&self) -> Option<&ServoUrl> {
|
||||
match *self {
|
||||
ComputedUrl::Valid(ref url) => Some(url),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ToCss for ComputedUrl {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
let string = match *self {
|
||||
ComputedUrl::Valid(ref url) => url.as_str(),
|
||||
ComputedUrl::Invalid(ref invalid_string) => invalid_string,
|
||||
};
|
||||
|
||||
dest.write_str("url(")?;
|
||||
string.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
}
|
||||
|
||||
/// <url> | <none>
|
||||
pub type UrlOrNone = Either<ComputedUrl, None_>;
|
||||
|
||||
|
|
|
@ -117,9 +117,9 @@ pub mod ui;
|
|||
/// Common handling for the specified value CSS url() values.
|
||||
pub mod url {
|
||||
#[cfg(feature = "servo")]
|
||||
pub use ::servo::url::*;
|
||||
pub use ::servo::url::{SpecifiedUrl, SpecifiedImageUrl};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use ::gecko::url::*;
|
||||
pub use ::gecko::url::{SpecifiedUrl, SpecifiedImageUrl};
|
||||
}
|
||||
|
||||
/// Parse a `<number>` value, with a given clamping mode.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue