Bug 1362897 - Add function which convert from URLValueData to SpecifiedUrl. r?heycam
We will need to convert from URLValueData to SpecifiedUrl when cloning the
stylo's data from gecko's data. Because the filter structure on gecko has url as
URLValue type. We will use this convert function when interpolating as
discrete also(
Bug 1368610).
MozReview-Commit-ID: 1axD4pcNV5S
--- a/servo/components/style/gecko/url.rs
+++ b/servo/components/style/gecko/url.rs
@@ -3,16 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! Common handling for the specified value CSS url() values.
use cssparser::CssStringWriter;
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
use gecko_bindings::structs::root::mozilla::css::ImageValue;
use gecko_bindings::sugar::refptr::RefPtr;
+use gecko_bindings::structs::mozilla::css::URLValueData;
use parser::ParserContext;
use std::borrow::Cow;
use std::fmt::{self, Write};
use style_traits::{ToCss, ParseError};
use stylearc::Arc;
/// A specified url() value for gecko. Gecko does not eagerly resolve SpecifiedUrls.
#[derive(Clone, Debug, PartialEq)]
@@ -48,16 +49,26 @@ impl SpecifiedUrl {
/// Returns true if the URL is definitely invalid. We don't eagerly resolve
/// URLs in gecko, so we just return false here.
/// use its |resolved| status.
pub fn is_invalid(&self) -> bool {
false
}
+ /// Convert from URLValueData to SpecifiedUrl.
+ pub unsafe fn from_url_value_data(url: &URLValueData)
+ -> Result<SpecifiedUrl, ()> {
+ Ok(SpecifiedUrl {
+ serialization: Arc::new(url.mString.to_string()),
+ extra_data: url.mExtraData.to_safe(),
+ image_value: None,
+ })
+ }
+
/// Returns true if this URL looks like a fragment.
/// See https://drafts.csswg.org/css-values/#local-urls
pub fn is_fragment(&self) -> bool {
self.as_str().chars().next().map_or(false, |c| c == '#')
}
/// Return the resolved url as string, or the empty string if it's invalid.
///