Stylo: Pass style list's image_value to gecko.

This commit is contained in:
cku 2017-05-15 10:42:07 +08:00
parent ff5043c8b5
commit f9b370719d
5 changed files with 68 additions and 15 deletions

View file

@ -53,6 +53,7 @@ use style::computed_values::position;
use style::context::SharedStyleContext; use style::context::SharedStyleContext;
use style::logical_geometry::Direction; use style::logical_geometry::Direction;
use style::properties::ServoComputedValues; use style::properties::ServoComputedValues;
use style::properties::longhands::list_style_image;
use style::selector_parser::{PseudoElement, RestyleDamage}; use style::selector_parser::{PseudoElement, RestyleDamage};
use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW}; use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW};
use style::values::Either; use style::values::Either;
@ -1206,13 +1207,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
-> ConstructionResult { -> ConstructionResult {
let flotation = FloatKind::from_property(flotation); let flotation = FloatKind::from_property(flotation);
let marker_fragments = match node.style(self.style_context()).get_list().list_style_image { let marker_fragments = match node.style(self.style_context()).get_list().list_style_image {
Either::First(ref url_value) => { list_style_image::computed_value::T(Either::First(ref url_value)) => {
let image_info = box ImageFragmentInfo::new(url_value.url().map(|u| u.clone()), let image_info = box ImageFragmentInfo::new(url_value.url().map(|u| u.clone()),
node, node,
&self.layout_context); &self.layout_context);
vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)] vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)]
} }
Either::Second(_none) => { list_style_image::computed_value::T(Either::Second(_none)) => {
match ListStyleTypeContent::from_list_style_type(node.style(self.style_context()) match ListStyleTypeContent::from_list_style_type(node.style(self.style_context())
.get_list() .get_list()
.list_style_type) { .list_style_type) {

View file

@ -37,8 +37,8 @@ use gecko_bindings::bindings::Gecko_StyleTransition_SetUnsupportedProperty;
use gecko_bindings::bindings::Gecko_NewCSSShadowArray; use gecko_bindings::bindings::Gecko_NewCSSShadowArray;
use gecko_bindings::bindings::Gecko_nsStyleFont_SetLang; use gecko_bindings::bindings::Gecko_nsStyleFont_SetLang;
use gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom; use gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom;
use gecko_bindings::bindings::Gecko_SetListStyleImage;
use gecko_bindings::bindings::Gecko_SetListStyleImageNone; use gecko_bindings::bindings::Gecko_SetListStyleImageNone;
use gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
use gecko_bindings::bindings::Gecko_SetListStyleType; use gecko_bindings::bindings::Gecko_SetListStyleType;
use gecko_bindings::bindings::Gecko_SetNullImageValue; use gecko_bindings::bindings::Gecko_SetNullImageValue;
use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
@ -2964,15 +2964,15 @@ fn static_assert() {
pub fn set_list_style_image(&mut self, image: longhands::list_style_image::computed_value::T) { pub fn set_list_style_image(&mut self, image: longhands::list_style_image::computed_value::T) {
use values::Either; use values::Either;
match image { match image {
Either::Second(_none) => { longhands::list_style_image::computed_value::T(Either::Second(_none)) => {
unsafe { unsafe {
Gecko_SetListStyleImageNone(&mut self.gecko); Gecko_SetListStyleImageNone(&mut self.gecko);
} }
} }
Either::First(ref url) => { longhands::list_style_image::computed_value::T(Either::First(ref url)) => {
unsafe { unsafe {
Gecko_SetListStyleImage(&mut self.gecko, Gecko_SetListStyleImageImageValue(&mut self.gecko,
url.for_ffi()); url.image_value.clone().unwrap().get());
} }
// We don't need to record this struct as uncacheable, like when setting // We don't need to record this struct as uncacheable, like when setting
// background-image to a url() value, since only properties in reset structs // background-image to a url() value, since only properties in reset structs

View file

@ -37,9 +37,55 @@ ${helpers.single_keyword("list-style-type", """
animation_value_type="none", animation_value_type="none",
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")} spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}
${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)", <%helpers:longhand name="list-style-image" animation_value_type="none"
initial_specified_value="Either::Second(None_)", animation_value_type="none", boxed="${product == 'gecko'}"
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")} spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image">
use std::fmt;
use values::HasViewportPercentage;
use values::computed::ComputedValueAsSpecified;
use values::specified::UrlOrNone;
pub use self::computed_value::T as SpecifiedValue;
use style_traits::ToCss;
pub mod computed_value {
use values::specified::UrlOrNone;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub UrlOrNone);
}
impl ComputedValueAsSpecified for SpecifiedValue {}
no_viewport_percentage!(SpecifiedValue);
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(Either::Second(None_))
}
#[inline]
pub fn get_initial_specified_value() -> SpecifiedValue {
SpecifiedValue(Either::Second(None_))
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
% if product == "gecko":
let mut value = input.try(|input| UrlOrNone::parse(context, input))?;
if let Either::First(ref mut url) = value {
url.build_image_value();
}
% else :
let value = input.try(|input| UrlOrNone::parse(context, input))?;
% endif
return Ok(SpecifiedValue(value));
}
</%helpers:longhand>
<%helpers:longhand name="quotes" animation_value_type="none" <%helpers:longhand name="quotes" animation_value_type="none"
spec="https://drafts.csswg.org/css-content/#propdef-quotes"> spec="https://drafts.csswg.org/css-content/#propdef-quotes">

View file

@ -60,7 +60,7 @@
(true, 2, None, None) => { (true, 2, None, None) => {
Ok(Longhands { Ok(Longhands {
list_style_position: position, list_style_position: position,
list_style_image: Either::Second(None_), list_style_image: list_style_image::SpecifiedValue(Either::Second(None_)),
list_style_type: list_style_type::SpecifiedValue::none, list_style_type: list_style_type::SpecifiedValue::none,
}) })
} }
@ -74,14 +74,14 @@
(true, 1, Some(list_style_type), None) => { (true, 1, Some(list_style_type), None) => {
Ok(Longhands { Ok(Longhands {
list_style_position: position, list_style_position: position,
list_style_image: Either::Second(None_), list_style_image: list_style_image::SpecifiedValue(Either::Second(None_)),
list_style_type: list_style_type, list_style_type: list_style_type,
}) })
} }
(true, 1, None, None) => { (true, 1, None, None) => {
Ok(Longhands { Ok(Longhands {
list_style_position: position, list_style_position: position,
list_style_image: Either::Second(None_), list_style_image: list_style_image::SpecifiedValue(Either::Second(None_)),
list_style_type: list_style_type::SpecifiedValue::none, list_style_type: list_style_type::SpecifiedValue::none,
}) })
} }

View file

@ -493,6 +493,7 @@ mod shorthand_serialization {
} }
mod list_style { mod list_style {
use style::properties::longhands::list_style_image::SpecifiedValue as ListStyleImage;
use style::properties::longhands::list_style_position::SpecifiedValue as ListStylePosition; use style::properties::longhands::list_style_position::SpecifiedValue as ListStylePosition;
use style::properties::longhands::list_style_type::SpecifiedValue as ListStyleType; use style::properties::longhands::list_style_type::SpecifiedValue as ListStyleType;
use style::values::Either; use style::values::Either;
@ -503,12 +504,17 @@ mod shorthand_serialization {
let mut properties = Vec::new(); let mut properties = Vec::new();
let position = ListStylePosition::inside; let position = ListStylePosition::inside;
let image = Either::First( let image =
SpecifiedUrl::new_for_testing("http://servo/test.png")); ListStyleImage(Either::First(SpecifiedUrl::new_for_testing("http://servo/test.png")));
let style_type = ListStyleType::disc; let style_type = ListStyleType::disc;
properties.push(PropertyDeclaration::ListStylePosition(position)); properties.push(PropertyDeclaration::ListStylePosition(position));
#[cfg(feature = "gecko")]
properties.push(PropertyDeclaration::ListStyleImage(Box::new(image)));
#[cfg(not(feature = "gecko"))]
properties.push(PropertyDeclaration::ListStyleImage(image)); properties.push(PropertyDeclaration::ListStyleImage(image));
properties.push(PropertyDeclaration::ListStyleType(style_type)); properties.push(PropertyDeclaration::ListStyleType(style_type));
let serialization = shorthand_properties_to_string(properties); let serialization = shorthand_properties_to_string(properties);