From d5270427ff2561367b1ce63378201bc4e997a82c Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 4 May 2016 11:06:42 +1000 Subject: [PATCH 1/5] Move width and height from Box to Position. This helps with style struct alignment between Servo and Gecko. --- components/layout/block.rs | 2 +- components/layout/flex.rs | 8 ++++---- components/layout/incremental.rs | 2 +- components/style/animation.rs | 8 ++++---- components/style/properties/longhand/box.mako.rs | 10 ---------- components/style/properties/longhand/position.mako.rs | 10 ++++++++++ components/style/properties/properties.mako.rs | 10 +++++----- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/components/layout/block.rs b/components/layout/block.rs index 53094ffd311..fa5790306b5 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -1695,7 +1695,7 @@ impl Flow for BlockFlow { fn bubble_inline_sizes(&mut self) { // If this block has a fixed width, just use that for the minimum and preferred width, // rather than bubbling up children inline width. - let consult_children = match self.fragment.style().get_box().width { + let consult_children = match self.fragment.style().get_position().width { LengthOrPercentageOrAuto::Length(_) => false, _ => true, }; diff --git a/components/layout/flex.rs b/components/layout/flex.rs index eed7ec8aae3..789018e4121 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -125,7 +125,7 @@ impl FlexFlow { // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // stripped out, and max replaced with union_nonbreaking_inline. fn inline_mode_bubble_inline_sizes(&mut self) { - let fixed_width = match self.block_flow.fragment.style().get_box().width { + let fixed_width = match self.block_flow.fragment.style().get_position().width { LengthOrPercentageOrAuto::Length(_) => true, _ => false, }; @@ -151,7 +151,7 @@ impl FlexFlow { // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // stripped out. fn block_mode_bubble_inline_sizes(&mut self) { - let fixed_width = match self.block_flow.fragment.style().get_box().width { + let fixed_width = match self.block_flow.fragment.style().get_position().width { LengthOrPercentageOrAuto::Length(_) => true, _ => false, }; @@ -398,9 +398,9 @@ impl Flow for FlexFlow { let (available_block_size, available_inline_size) = { let style = &self.block_flow.fragment.style; let (specified_block_size, specified_inline_size) = if style.writing_mode.is_vertical() { - (style.get_box().width, style.get_box().height) + (style.get_position().width, style.get_position().height) } else { - (style.get_box().height, style.get_box().width) + (style.get_position().height, style.get_position().width) }; let available_inline_size = AxisSize::new(specified_inline_size, diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index a743afd1555..e8cf8e4c500 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -211,7 +211,7 @@ pub fn compute_damage(old: Option<&Arc>, new: &ServoCompute get_margin.margin_bottom, get_margin.margin_left, get_padding.padding_top, get_padding.padding_right, get_padding.padding_bottom, get_padding.padding_left, - get_box.width, get_box.height, + get_position.width, get_position.height, get_inheritedtext.line_height, get_inheritedtext.text_align, get_inheritedtext.text_indent, get_table.table_layout, diff --git a/components/style/animation.rs b/components/style/animation.rs index 9c0242aa971..08ae32baf0c 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -158,7 +158,7 @@ impl PropertyAnimation { [Color; get_color; color], [FontSize; get_font; font_size], [FontWeight; get_font; font_weight], - [Height; get_box; height], + [Height; get_position; height], [Left; get_position; left], [LineHeight; get_inheritedtext; line_height], [MarginBottom; get_margin; margin_bottom], @@ -181,7 +181,7 @@ impl PropertyAnimation { [Top; get_position; top], [VerticalAlign; get_box; vertical_align], [Visibility; get_inheritedbox; visibility], - [Width; get_box; width], + [Width; get_position; width], [ZIndex; get_position; z_index]); let property_animation = PropertyAnimation { @@ -256,7 +256,7 @@ impl PropertyAnimation { [Color; mutate_color; color], [FontSize; mutate_font; font_size], [FontWeight; mutate_font; font_weight], - [Height; mutate_box; height], + [Height; mutate_position; height], [Left; mutate_position; left], [LineHeight; mutate_inheritedtext; line_height], [MarginBottom; mutate_margin; margin_bottom], @@ -281,7 +281,7 @@ impl PropertyAnimation { [Transform; mutate_effects; transform], [VerticalAlign; mutate_box; vertical_align], [Visibility; mutate_inheritedbox; visibility], - [Width; mutate_box; width], + [Width; mutate_position; width], [ZIndex; mutate_position; z_index]); } diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index f1e3cfb5be5..a88db8bf03e 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -122,16 +122,6 @@ ${helpers.single_keyword("clear", "none left right both", gecko_ffi_name="mBreak -${helpers.predefined_type("width", - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", - "parse_non_negative")} - -${helpers.predefined_type("height", - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", - "parse_non_negative")} - <%helpers:longhand name="vertical-align"> use cssparser::ToCss; use std::fmt; diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index 41dc76ee3b6..c4ea596758d 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -96,6 +96,16 @@ ${helpers.predefined_type("flex-basis", ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", products="gecko")} +${helpers.predefined_type("width", + "LengthOrPercentageOrAuto", + "computed::LengthOrPercentageOrAuto::Auto", + "parse_non_negative")} + +${helpers.predefined_type("height", + "LengthOrPercentageOrAuto", + "computed::LengthOrPercentageOrAuto::Auto", + "parse_non_negative")} + ${helpers.predefined_type("min-width", "LengthOrPercentage", "computed::LengthOrPercentage::Length(Au(0))", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 6582d5a6020..0299b3a4276 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -972,18 +972,18 @@ impl ServoComputedValues { #[inline] pub fn content_inline_size(&self) -> computed::LengthOrPercentageOrAuto { - let box_style = self.get_box(); + let position_style = self.get_position(); if self.writing_mode.is_vertical() { - box_style.height + position_style.height } else { - box_style.width + position_style.width } } #[inline] pub fn content_block_size(&self) -> computed::LengthOrPercentageOrAuto { - let box_style = self.get_box(); - if self.writing_mode.is_vertical() { box_style.width } else { box_style.height } + let position_style = self.get_position(); + if self.writing_mode.is_vertical() { position_style.width } else { position_style.height } } #[inline] From 580f58c1467f5953e722a974191fb94c535f7b8e Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 4 May 2016 13:13:22 +1000 Subject: [PATCH 2/5] Support top, right, bottom and left in geckolib. --- ports/geckolib/properties.mako.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index dfb483ab86a..42e127ed791 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -476,6 +476,16 @@ fn static_assert() { % endfor +<% skip_position_longhands = " ".join(x.ident for x in SIDES) %> +<%self:impl_trait style_struct_name="Position" + skip_longhands="${skip_position_longhands}"> + + % for side in SIDES: + <% impl_style_coord("%s" % side.ident, + "mOffset.mUnits[%s]" % side.index, "mOffset.mValues[%s]" % side.index) %> + % endfor + + <%self:impl_trait style_struct_name="Outline" skip_longhands="outline-color outline-style" skip_additionals="*"> From 8d6a99b46e6e6a5981224142716f26f77b2d6cac Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 4 May 2016 14:34:53 +1000 Subject: [PATCH 3/5] Support width and height in geckolib. --- ports/geckolib/properties.mako.rs | 49 +++++++++++++++++++------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 42e127ed791..0257ba9e8d6 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -267,7 +267,7 @@ def set_gecko_property(ffi_name, expr): % endif -<%def name="impl_style_coord(ident, unit_ffi_name, union_ffi_name)"> +<%def name="impl_split_style_coord(ident, unit_ffi_name, union_ffi_name)"> fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { v.to_gecko_style_coord(&mut self.gecko.${unit_ffi_name}, &mut self.gecko.${union_ffi_name}); @@ -281,6 +281,10 @@ def set_gecko_property(ffi_name, expr): } +<%def name="impl_style_coord(ident, gecko_ffi_name)"> +<%call expr="impl_split_style_coord(ident, '%s.mUnit' % gecko_ffi_name, '%s.mValue' % gecko_ffi_name)"> + + <%def name="impl_style_struct(style_struct)"> impl ${style_struct.gecko_struct_name} { #[allow(dead_code, unused_variables)] @@ -354,14 +358,17 @@ impl Debug for ${style_struct.gecko_ffi_name} { # These are booleans. force_stub += ["page-break-after", "page-break-before"] - simple_types = ["Number", "Opacity"] + # Types used with predefined_type()-defined properties that we can auto-generate. + predefined_types = { + "LengthOrPercentageOrAuto": impl_style_coord, + "Number": impl_simple, + "Opacity": impl_simple, + } keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub] - simple_longhands = [x for x in longhands - if x.predefined_type in simple_types and not x.name in force_stub] - - autogenerated_longhands = keyword_longhands + simple_longhands - stub_longhands = [x for x in longhands if x not in autogenerated_longhands] + predefined_longhands = [x for x in longhands + if x.predefined_type in predefined_types and not x.name in force_stub] + stub_longhands = [x for x in longhands if x not in keyword_longhands + predefined_longhands] %> impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} { /* @@ -372,12 +379,13 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} { /* * Auto-Generated Methods. */ - % for longhand in keyword_longhands: - <%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"> - % endfor - % for longhand in simple_longhands: - <%call expr="impl_simple(longhand.ident, longhand.gecko_ffi_name)"> - % endfor + <% + for longhand in keyword_longhands: + impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone) + for longhand in predefined_longhands: + impl_fn = predefined_types[longhand.predefined_type] + impl_fn(longhand.ident, longhand.gecko_ffi_name) + %> /* * Stubs. @@ -461,8 +469,9 @@ fn static_assert() { skip_longhands="${skip_margin_longhands}"> % for side in SIDES: - <% impl_style_coord("margin_%s" % side.ident, - "mMargin.mUnits[%s]" % side.index, "mMargin.mValues[%s]" % side.index) %> + <% impl_split_style_coord("margin_%s" % side.ident, + "mMargin.mUnits[%s]" % side.index, + "mMargin.mValues[%s]" % side.index) %> % endfor @@ -471,8 +480,9 @@ fn static_assert() { skip_longhands="${skip_padding_longhands}"> % for side in SIDES: - <% impl_style_coord("padding_%s" % side.ident, - "mPadding.mUnits[%s]" % side.index, "mPadding.mValues[%s]" % side.index) %> + <% impl_split_style_coord("padding_%s" % side.ident, + "mPadding.mUnits[%s]" % side.index, + "mPadding.mValues[%s]" % side.index) %> % endfor @@ -481,8 +491,9 @@ fn static_assert() { skip_longhands="${skip_position_longhands}"> % for side in SIDES: - <% impl_style_coord("%s" % side.ident, - "mOffset.mUnits[%s]" % side.index, "mOffset.mValues[%s]" % side.index) %> + <% impl_split_style_coord("%s" % side.ident, + "mOffset.mUnits[%s]" % side.index, + "mOffset.mValues[%s]" % side.index) %> % endfor From 04f976bfb2861e135ec2c20a710c233a9bf30b5f Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 4 May 2016 14:47:49 +1000 Subject: [PATCH 4/5] Support min-{width,height} and text-indent in geckolib. --- ports/geckolib/properties.mako.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 0257ba9e8d6..2d291dd9618 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -360,6 +360,7 @@ impl Debug for ${style_struct.gecko_ffi_name} { # Types used with predefined_type()-defined properties that we can auto-generate. predefined_types = { + "LengthOrPercentage": impl_style_coord, "LengthOrPercentageOrAuto": impl_style_coord, "Number": impl_simple, "Opacity": impl_simple, From 84ef0de1600458f43c58eb3e259c7ac4f690fd59 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 4 May 2016 14:51:42 +1000 Subject: [PATCH 5/5] Support max-{width,height} in geckolib. --- ports/geckolib/properties.mako.rs | 1 + ports/geckolib/values.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 2d291dd9618..9faf4233f61 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -362,6 +362,7 @@ impl Debug for ${style_struct.gecko_ffi_name} { predefined_types = { "LengthOrPercentage": impl_style_coord, "LengthOrPercentageOrAuto": impl_style_coord, + "LengthOrPercentageOrNone": impl_style_coord, "Number": impl_simple, "Opacity": impl_simple, } diff --git a/ports/geckolib/values.rs b/ports/geckolib/values.rs index 99bf5f6fc40..172ce193b8a 100644 --- a/ports/geckolib/values.rs +++ b/ports/geckolib/values.rs @@ -4,7 +4,7 @@ use cssparser::RGBA; use gecko_style_structs::{nsStyleUnion, nsStyleUnit}; -use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; pub trait ToGeckoStyleCoord { fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion); @@ -46,6 +46,26 @@ impl ToGeckoStyleCoord for LengthOrPercentageOrAuto { } } +impl ToGeckoStyleCoord for LengthOrPercentageOrNone { + fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) { + match *self { + LengthOrPercentageOrNone::Length(au) => { + *unit = nsStyleUnit::eStyleUnit_Coord; + unsafe { *union.mInt.as_mut() = au.0; } + }, + LengthOrPercentageOrNone::Percentage(p) => { + *unit = nsStyleUnit::eStyleUnit_Percent; + unsafe { *union.mFloat.as_mut() = p; } + }, + LengthOrPercentageOrNone::None => { + *unit = nsStyleUnit::eStyleUnit_None; + unsafe { *union.mInt.as_mut() = 0; } + }, + LengthOrPercentageOrNone::Calc(_) => unimplemented!(), + }; + } +} + pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 { (((rgba.alpha * 255.0).round() as u32) << 24) | (((rgba.blue * 255.0).round() as u32) << 16) |