Bug 1371115 - Part 13: implements nsStyleImageRequest type properties animatable. r?hiro
In this patch, implements following properties:
* list-style-image
MozReview-Commit-ID: 2EINwiRt2nk
--- a/servo/components/style/gecko/url.rs
+++ b/servo/components/style/gecko/url.rs
@@ -2,16 +2,17 @@
* 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 gecko_bindings::structs::{ServoBundledURI, URLExtraData};
use gecko_bindings::structs::mozilla::css::URLValueData;
use gecko_bindings::structs::root::mozilla::css::ImageValue;
+use gecko_bindings::structs::root::nsStyleImageRequest;
use gecko_bindings::sugar::refptr::RefPtr;
use parser::ParserContext;
use std::fmt;
use style_traits::{ToCss, ParseError};
use stylearc::Arc;
/// A specified url() value for gecko. Gecko does not eagerly resolve SpecifiedUrls.
#[derive(Clone, Debug, PartialEq)]
@@ -57,16 +58,29 @@ impl SpecifiedUrl {
-> Result<SpecifiedUrl, ()> {
Ok(SpecifiedUrl {
serialization: Arc::new(url.mString.to_string()),
extra_data: url.mExtraData.to_safe(),
image_value: None,
})
}
+ /// Convert from nsStyleImageRequest to SpecifiedUrl.
+ pub unsafe fn from_image_request(image_request: &nsStyleImageRequest) -> Result<SpecifiedUrl, ()> {
+ if image_request.mImageValue.mRawPtr.is_null() {
+ return Err(());
+ }
+
+ let image_value = image_request.mImageValue.mRawPtr.as_ref().unwrap();
+ let ref url_value_data = image_value._base;
+ let mut result = try!(Self::from_url_value_data(url_value_data));
+ result.build_image_value();
+ Ok(result)
+ }
+
/// 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.
///
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -3343,16 +3343,34 @@ fn static_assert() {
}
}
}
pub fn copy_list_style_image_from(&mut self, other: &Self) {
unsafe { Gecko_CopyListStyleImageFrom(&mut self.gecko, &other.gecko); }
}
+ pub fn clone_list_style_image(&self) -> longhands::list_style_image::computed_value::T {
+ use values::specified::url::SpecifiedUrl;
+ use values::{Either, None_};
+
+ longhands::list_style_image::computed_value::T(
+ match self.gecko.mListStyleImage.mRawPtr.is_null() {
+ true => Either::Second(None_),
+ false => {
+ unsafe {
+ let ref gecko_image_request = *self.gecko.mListStyleImage.mRawPtr;
+ Either::First(SpecifiedUrl::from_image_request(gecko_image_request)
+ .expect("mListStyleImage has valid data"))
+ }
+ }
+ }
+ )
+ }
+
pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T, device: &Device) {
use gecko_bindings::bindings::Gecko_SetCounterStyleToString;
use nsstring::{nsACString, nsCString};
use self::longhands::list_style_type::computed_value::T;
match v {
T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle, device),
T::String(s) => unsafe {
Gecko_SetCounterStyleToString(&mut self.gecko.mCounterStyle,
--- a/servo/components/style/properties/longhand/list.mako.rs
+++ b/servo/components/style/properties/longhand/list.mako.rs
@@ -95,17 +95,17 @@
SpecifiedValue::CounterStyle(style)
} else {
SpecifiedValue::String(input.expect_string()?.into_owned())
})
}
</%helpers:longhand>
% endif
-<%helpers:longhand name="list-style-image" animation_value_type="none"
+<%helpers:longhand name="list-style-image" animation_value_type="discrete"
boxed="${product == 'gecko'}"
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image">
use values::computed::ComputedValueAsSpecified;
use values::specified::UrlOrNone;
pub use self::computed_value::T as SpecifiedValue;
pub mod computed_value {
use values::specified::UrlOrNone;