Move ComputedUrl into their impl mods. r?emilio
draft
Move ComputedUrl into their impl mods. r?emilio
MozReview-Commit-ID: FM0cA4RqrKK
--- a/servo/components/style/gecko/url.rs
+++ b/servo/components/style/gecko/url.rs
@@ -191,8 +191,13 @@ impl MallocSizeOf for SpecifiedImageUrl
let mut n = self.url.size_of(ops);
// Although this is a RefPtr, this is the primary reference because
// SpecifiedUrl is responsible for creating the image_value. So we
// measure unconditionally here.
n += unsafe { bindings::Gecko_ImageValue_SizeOfIncludingThis(self.image_value.get()) };
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;
--- a/servo/components/style/servo/url.rs
+++ b/servo/components/style/servo/url.rs
@@ -1,23 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! 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
// nonzero optimization is important in keeping the size of SpecifiedUrl below
// 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.
///
/// Servo eagerly resolves SpecifiedUrls, which it can then take advantage of
/// when computing values. In contrast, Gecko uses a different URL backend, so
/// eagerly resolving with rust-url would be duplicated work.
///
/// However, this approach is still not necessarily optimal: See
@@ -169,8 +170,46 @@ impl ToComputedValue for SpecifiedUrl {
resolved: None,
}
}
}
}
/// 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;
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -10,24 +10,20 @@ use Prefix;
use context::QuirksMode;
use euclid::Size2D;
use font_metrics::{FontMetricsProvider, get_metrics_provider_for_product};
use media_queries::Device;
#[cfg(feature = "gecko")]
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};
use super::animated::ToAnimatedValue;
use super::generics::{GreaterThanOrEqualToOne, NonNegative};
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackSize as GenericTrackSize, TrackList as GenericTrackList};
use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
@@ -79,16 +75,17 @@ pub use self::svg::{SVGPaintOrder, SVGSt
pub use self::svg::MozContextProperties;
pub use self::table::XSpan;
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize};
pub use self::text::{TextAlign, TextOverflow, WordSpacing};
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;
pub mod angle;
pub mod background;
pub mod basic_shape;
pub mod border;
#[path = "box.rs"]
@@ -112,16 +109,24 @@ pub mod position;
pub mod rect;
pub mod svg;
pub mod table;
pub mod text;
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> {
/// Whether the current element is the root element.
pub is_root_element: bool,
/// Values accessed through this need to be in the properties "computed
/// early": color, text-decoration, font-size, display, position, float,
@@ -631,63 +636,13 @@ impl ClipRectOrAuto {
pub fn is_auto(&self) -> bool {
match *self {
Either::Second(_) => true,
_ => false
}
}
}
-/// 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_>;
/// <url> | <none> for image
pub type ImageUrlOrNone = Either<ComputedImageUrl, None_>;
--- a/servo/components/style/values/specified/mod.rs
+++ b/servo/components/style/values/specified/mod.rs
@@ -112,19 +112,19 @@ pub mod table;
pub mod text;
pub mod time;
pub mod transform;
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.
fn parse_number_with_clamping_mode<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType,
) -> Result<Number, ParseError<'i>> {