From ef541c8a2c52109b5f6881479e09704d8787bd13 Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Wed, 26 Oct 2016 02:27:13 -0500 Subject: [PATCH] servo: Merge #13902 - Prefer auto-generation for some keyword props (from Wafflespeanut:keyword); r=emilio --- - [x] `./mach build-geckolib` does not report any errors - [x] These changes do not require tests because it's a refactor r? @Manishearth or @emilio Source-Repo: https://github.com/servo/servo Source-Revision: 3c16dde1f268ffab3e2b220fda7e5be299d005b4 --- servo/components/gfx/paint_context.rs | 2 +- servo/components/layout/webrender_helpers.rs | 2 +- servo/components/style/properties/data.py | 13 +++- .../components/style/properties/gecko.mako.rs | 62 +++++---------- .../style/properties/helpers.mako.rs | 1 + .../style/properties/longhand/font.mako.rs | 7 ++ .../properties/longhand/inherited_box.mako.rs | 76 +++---------------- 7 files changed, 49 insertions(+), 114 deletions(-) diff --git a/servo/components/gfx/paint_context.rs b/servo/components/gfx/paint_context.rs index 51a1bf2795f0..8379b1f8df37 100644 --- a/servo/components/gfx/paint_context.rs +++ b/servo/components/gfx/paint_context.rs @@ -223,7 +223,7 @@ impl<'a> PaintContext<'a> { // Something like Scale2x would be ideal. let draw_surface_filter = match image_rendering { image_rendering::T::auto => Filter::Linear, - image_rendering::T::crispedges | image_rendering::T::pixelated => Filter::Point, + image_rendering::T::crisp_edges | image_rendering::T::pixelated => Filter::Point, }; let draw_surface_options = DrawSurfaceOptions::new(draw_surface_filter, true); diff --git a/servo/components/layout/webrender_helpers.rs b/servo/components/layout/webrender_helpers.rs index 369fab813d7a..91402a315e50 100644 --- a/servo/components/layout/webrender_helpers.rs +++ b/servo/components/layout/webrender_helpers.rs @@ -214,7 +214,7 @@ trait ToImageRendering { impl ToImageRendering for image_rendering::T { fn to_image_rendering(&self) -> webrender_traits::ImageRendering { match *self { - image_rendering::T::crispedges => webrender_traits::ImageRendering::CrispEdges, + image_rendering::T::crisp_edges => webrender_traits::ImageRendering::CrispEdges, image_rendering::T::auto => webrender_traits::ImageRendering::Auto, image_rendering::T::pixelated => webrender_traits::ImageRendering::Pixelated, } diff --git a/servo/components/style/properties/data.py b/servo/components/style/properties/data.py index 2b11109bbc41..e5c7778bfec5 100644 --- a/servo/components/style/properties/data.py +++ b/servo/components/style/properties/data.py @@ -18,7 +18,7 @@ def to_camel_case(ident): class Keyword(object): def __init__(self, name, values, gecko_constant_prefix=None, - gecko_enum_prefix=None, + gecko_enum_prefix=None, custom_consts=None, extra_gecko_values=None, extra_servo_values=None): self.name = name self.values = values.split() @@ -29,6 +29,7 @@ class Keyword(object): self.gecko_enum_prefix = gecko_enum_prefix self.extra_gecko_values = (extra_gecko_values or "").split() self.extra_servo_values = (extra_servo_values or "").split() + self.consts_map = {} if custom_consts is None else custom_consts def gecko_values(self): return self.values + self.extra_gecko_values @@ -45,12 +46,15 @@ class Keyword(object): raise Exception("Bad product: " + product) def gecko_constant(self, value): + moz_stripped = value.replace("-moz-", '') + parts = moz_stripped.split('-') if self.gecko_enum_prefix: - parts = value.replace("-moz-", "").split("-") parts = [p.title() for p in parts] return self.gecko_enum_prefix + "::" + "".join(parts) else: - return self.gecko_constant_prefix + "_" + value.replace("-moz-", "").replace("-", "_").upper() + mapped = self.consts_map.get(value) + suffix = mapped if mapped else moz_stripped.replace("-", "_") + return self.gecko_constant_prefix + "_" + suffix.upper() def needs_cast(self): return self.gecko_enum_prefix is None @@ -63,7 +67,7 @@ class Longhand(object): def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None, predefined_type=None, custom_cascade=False, experimental=False, internal=False, need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, - allowed_in_keyframe_block=True, complex_color=False): + allowed_in_keyframe_block=True, complex_color=False, cast_type='u8'): self.name = name self.keyword = keyword self.predefined_type = predefined_type @@ -78,6 +82,7 @@ class Longhand(object): self.depend_on_viewport_size = depend_on_viewport_size self.derived_from = (derived_from or "").split() self.complex_color = complex_color + self.cast_type = cast_type # https://drafts.csswg.org/css-animations/#keyframes # > The inside of accepts any CSS property diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 85ebdfdaaabf..7774c599e933 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -490,21 +490,29 @@ impl Debug for ${style_struct.gecko_struct_name} { "CSSColor": impl_color, } - def predefined_type_method(longhand): + def longhand_method(longhand): args = dict(ident=longhand.ident, gecko_ffi_name=longhand.gecko_ffi_name, need_clone=longhand.need_clone) - method = predefined_types[longhand.predefined_type] - # additional type-specific arguments - if longhand.predefined_type in ["CSSColor"]: - args.update(complex_color=longhand.complex_color) + # get the method and pass additional keyword or type-specific arguments + if longhand.keyword: + method = impl_keyword + args.update(keyword=longhand.keyword) + if "font" in longhand.ident: + args.update(cast_type=longhand.cast_type) + else: + method = predefined_types[longhand.predefined_type] + if longhand.predefined_type in ["CSSColor"]: + args.update(complex_color=longhand.complex_color) method(**args) - keyword_longhands = [x for x in longhands if x.keyword and x.name not in force_stub] - predefined_longhands = [x for x in longhands - if x.predefined_type in predefined_types and x.name not in force_stub] - stub_longhands = [x for x in longhands if x not in keyword_longhands + predefined_longhands] + picked_longhands, stub_longhands = [], [] + for x in longhands: + if (x.keyword or x.predefined_type in predefined_types) and x.name not in force_stub: + picked_longhands.append(x) + else: + stub_longhands.append(x) # If one of the longhands is not handled # by either: @@ -518,6 +526,7 @@ impl Debug for ${style_struct.gecko_struct_name} { # If you hit this error, please add `product="servo"` to the longhand. # In case the longhand is used in a shorthand, add it to the force_stub # list above. + for stub in stub_longhands: if stub.name not in force_stub: raise Exception("Don't know what to do with longhand %s in style struct %s" @@ -533,10 +542,8 @@ impl ${style_struct.gecko_struct_name} { * Auto-Generated Methods. */ <% - for longhand in keyword_longhands: - impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone) - for longhand in predefined_longhands: - predefined_type_method(longhand) + for longhand in picked_longhands: + longhand_method(longhand) %> /* @@ -758,7 +765,7 @@ fn static_assert() { <%self:impl_trait style_struct_name="Font" - skip_longhands="font-family font-kerning font-stretch font-style font-size font-weight" + skip_longhands="font-family font-size font-weight" skip_additionals="*"> pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) { @@ -791,9 +798,6 @@ fn static_assert() { unsafe { Gecko_CopyFontFamilyFrom(&mut self.gecko.mFont, &other.gecko.mFont); } } - <%call expr="impl_keyword('font_style', 'mFont.style', - data.longhands_by_name['font-style'].keyword, need_clone=False)"> - // FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the // actual computed size, and the other of which (mFont.size) is the 'display // size' which takes font zooming into account. We don't handle font zooming yet. @@ -809,19 +813,6 @@ fn static_assert() { Au(self.gecko.mSize) } - <% kerning_keyword = Keyword("font-kerning", "auto normal none", - gecko_constant_prefix='NS_FONT_KERNING') %> - - ${impl_keyword('font_kerning', 'mFont.kerning', kerning_keyword, need_clone=False)} - - <% stretch_keyword = Keyword("font-stretch", - "normal ultra-condensed extra-condensed condensed " + - "semi-condensed semi-expanded expanded " + - "extra-expanded ultra-expanded", - gecko_constant_prefix='NS_FONT_STRETCH') %> - - ${impl_keyword('font_stretch', 'mFont.stretch', stretch_keyword, need_clone=False, cast_type='i16')} - pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) { self.gecko.mFont.weight = v as u16; } @@ -1634,17 +1625,6 @@ fn static_assert() { -<%self:impl_trait style_struct_name="InheritedBox" - skip_longhands="image-rendering"> - - <% render_keyword = Keyword("image-rendering", - "auto optimizequality optimizespeed crispedges") %> - - ${impl_keyword('image_rendering', 'mImageRendering', render_keyword, need_clone=False)} - - - - <%self:impl_trait style_struct_name="InheritedText" skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing"> diff --git a/servo/components/style/properties/helpers.mako.rs b/servo/components/style/properties/helpers.mako.rs index b34175bcebe7..292f8fc66b69 100644 --- a/servo/components/style/properties/helpers.mako.rs +++ b/servo/components/style/properties/helpers.mako.rs @@ -312,6 +312,7 @@ keyword_kwargs = {a: kwargs.pop(a, None) for a in [ 'gecko_constant_prefix', 'gecko_enum_prefix', 'extra_gecko_values', 'extra_servo_values', + 'custom_consts', ]} %> diff --git a/servo/components/style/properties/longhand/font.mako.rs b/servo/components/style/properties/longhand/font.mako.rs index 28594f8fe39c..0733e83d82e9 100644 --- a/servo/components/style/properties/longhand/font.mako.rs +++ b/servo/components/style/properties/longhand/font.mako.rs @@ -123,7 +123,9 @@ ${helpers.single_keyword("font-style", "normal italic oblique", gecko_constant_prefix="NS_FONT_STYLE", + gecko_ffi_name="mFont.style", animatable=False)} + ${helpers.single_keyword("font-variant", "normal small-caps", animatable=False)} @@ -347,11 +349,16 @@ ${helpers.single_keyword("font-stretch", "normal ultra-condensed extra-condensed condensed \ semi-condensed semi-expanded expanded extra-expanded \ ultra-expanded", + gecko_ffi_name="mFont.stretch", + gecko_constant_prefix="NS_FONT_STRETCH", + cast_type='i16', animatable=False)} ${helpers.single_keyword("font-kerning", "auto none normal", products="gecko", + gecko_ffi_name="mFont.kerning", + gecko_constant_prefix="NS_FONT_KERNING", animatable=False)} ${helpers.single_keyword("font-variant-position", diff --git a/servo/components/style/properties/longhand/inherited_box.mako.rs b/servo/components/style/properties/longhand/inherited_box.mako.rs index 4a5368ddbc61..d03b38cf6f0a 100644 --- a/servo/components/style/properties/longhand/inherited_box.mako.rs +++ b/servo/components/style/properties/longhand/inherited_box.mako.rs @@ -40,73 +40,15 @@ ${helpers.single_keyword("color-adjust", "economy exact", products="gecko", animatable=False)} -<%helpers:longhand name="image-rendering" animatable="False"> - pub mod computed_value { - use cssparser::ToCss; - use std::fmt; - - #[allow(non_camel_case_types)] - #[derive(Copy, Clone, Debug, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))] - pub enum T { - auto, - crispedges, - % if product == "gecko": - optimizequality, - optimizespeed, - % else: - pixelated, // firefox doesn't support it (https://bugzilla.mozilla.org/show_bug.cgi?id=856337) - % endif - } - - impl ToCss for T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - T::auto => dest.write_str("auto"), - T::crispedges => dest.write_str("crisp-edges"), - % if product == "gecko": - T::optimizequality => dest.write_str("optimizeQuality"), - T::optimizespeed => dest.write_str("optimizeSpeed"), - % else: - T::pixelated => dest.write_str("pixelated"), - % endif - } - } - } - } - - use values::NoViewportPercentage; - impl NoViewportPercentage for SpecifiedValue {} - - pub type SpecifiedValue = computed_value::T; - - #[inline] - pub fn get_initial_value() -> computed_value::T { - computed_value::T::auto - } - - pub fn parse(_: &ParserContext, input: &mut Parser) -> Result { - // According to to CSS-IMAGES-3, `optimizespeed` and `optimizequality` are synonyms for - // `auto`. - match_ignore_ascii_case! { - try!(input.expect_ident()), - "auto" => Ok(computed_value::T::auto), - "crisp-edges" => Ok(computed_value::T::crispedges), - % if product == "gecko": - "optimizequality" => Ok(computed_value::T::optimizequality), - "optimizespeed" => Ok(computed_value::T::optimizespeed), - % else: - "optimizequality" => Ok(computed_value::T::auto), - "optimizespeed" => Ok(computed_value::T::auto), - "pixelated" => Ok(computed_value::T::pixelated), - % endif - _ => Err(()) - } - } - - use values::computed::ComputedValueAsSpecified; - impl ComputedValueAsSpecified for SpecifiedValue { } - +<% image_rendering_custom_consts = { "crisp-edges": "CRISPEDGES" } %> +// According to to CSS-IMAGES-3, `optimizespeed` and `optimizequality` are synonyms for `auto` +// And, firefox doesn't support `pixelated` yet (https://bugzilla.mozilla.org/show_bug.cgi?id=856337) +${helpers.single_keyword("image-rendering", + "auto crisp-edges", + extra_gecko_values="optimizespeed optimizequality", + extra_servo_values="pixelated", + custom_consts=image_rendering_custom_consts, + animatable=False)} // Used in the bottom-up flow construction traversal to avoid constructing flows for // descendants of nodes with `display: none`.