Bug 1362897 - Add function which convert from URLValueData to SpecifiedUrl. r?heycam draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Mon, 12 Jun 2017 13:11:29 +0900
changeset 592388 e0578ebb853e31f05427ba172a6426f02ca8e744
parent 592387 292cc8dbe54dcf0feeb5a4cdc32a0a30c0945018
child 592389 1b1ba5e6f3caa241417f1d23d718c150a501a79c
push id63367
push usermantaroh@gmail.com
push dateMon, 12 Jun 2017 06:59:45 +0000
reviewersheycam
bugs1362897, 1368610
milestone55.0a1
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
servo/components/style/gecko/url.rs
--- 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.
     ///