New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ComputedUrl #17812
Merged
bors-servo
merged 1 commit into
servo:master
from
fnune:use-resolved-url-instead-of-original
Aug 10, 2017
+197
−46
Merged
Introduce ComputedUrl #17812
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Introduce ComputedUrl
Add web platform tests for computed URL styles Mark url with no original or resolved unreachable Update the WPT manifest for new url tests
- Loading branch information
commit 14c5a1b8d3dee7cfc8dfeb9314a0178c33197145
| @@ -12,10 +12,14 @@ use media_queries::Device; | ||
| #[cfg(feature = "gecko")] | ||
| use properties; | ||
| use properties::{ComputedValues, StyleBuilder}; | ||
| #[cfg(feature = "servo")] | ||
| use servo_url::ServoUrl; | ||
| use std::f32; | ||
| use std::f64; | ||
| use std::f64::consts::PI; | ||
| use std::fmt; | ||
| #[cfg(feature = "servo")] | ||
| use std::sync::Arc; | ||
| use style_traits::ToCss; | ||
| use super::{CSSFloat, CSSInteger}; | ||
| use super::generics::{GreaterThanOrEqualToOne, NonNegative}; | ||
| @@ -39,9 +43,8 @@ pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, | ||
| pub use self::gecko::ScrollSnapPoint; | ||
| pub use self::rect::LengthOrNumberRect; | ||
| pub use super::{Auto, Either, None_}; | ||
| pub use super::specified::{BorderStyle, UrlOrNone}; | ||
| pub use super::specified::BorderStyle; | ||
| pub use super::generics::grid::GridLine; | ||
| pub use super::specified::url::SpecifiedUrl; | ||
| pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage}; | ||
| pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength}; | ||
| pub use self::length::NonNegativeLengthOrPercentage; | ||
| @@ -684,3 +687,45 @@ impl ToComputedValue for specified::Percentage { | ||
| specified::Percentage::new(computed.0) | ||
| } | ||
| } | ||
|
|
||
| /// The computed value of a CSS `url()`, resolved relative to the stylesheet URL. | ||
| #[cfg(feature = "servo")] | ||
| #[derive(Clone, Debug, HeapSizeOf, Serialize, Deserialize, PartialEq)] | ||
| pub enum ComputedUrl { | ||
fnune
Author
Contributor
|
||
| /// The `url()` was invalid or it wasn't specified by the user. | ||
| Invalid(Arc<String>), | ||
| /// The resolved `url()` relative to the stylesheet URL. | ||
| Valid(ServoUrl), | ||
| } | ||
|
|
||
| /// TODO: Properly build ComputedUrl for gecko | ||
| #[cfg(feature = "gecko")] | ||
| pub type ComputedUrl = specified::url::SpecifiedUrl; | ||
|
|
||
| #[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 W) -> fmt::Result where W: fmt::Write { | ||
| let string = match *self { | ||
| ComputedUrl::Valid(ref url) => url.as_str(), | ||
| ComputedUrl::Invalid(ref invalid_string) => invalid_string, | ||
fnune
Author
Contributor
|
||
| }; | ||
|
|
||
| dest.write_str("url(")?; | ||
| string.to_css(dest)?; | ||
| dest.write_str(")") | ||
| } | ||
| } | ||
|
|
||
| /// <url> | <none> | ||
| pub type UrlOrNone = Either<ComputedUrl, None_>; | ||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
We could move this to another module to avoid the
cfg's, but that's probably doable as a followup.