зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #13902 - Prefer auto-generation for some keyword props (from Wafflespeanut:keyword); r=emilio
<!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build-geckolib` does not report any errors <!-- Either: --> - [x] These changes do not require tests because it's a refactor <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> r? @Manishearth or @emilio Source-Repo: https://github.com/servo/servo Source-Revision: 3c16dde1f268ffab3e2b220fda7e5be299d005b4
This commit is contained in:
Родитель
0291b6ce45
Коммит
ef541c8a2c
|
@ -223,7 +223,7 @@ impl<'a> PaintContext<'a> {
|
||||||
// Something like Scale2x would be ideal.
|
// Something like Scale2x would be ideal.
|
||||||
let draw_surface_filter = match image_rendering {
|
let draw_surface_filter = match image_rendering {
|
||||||
image_rendering::T::auto => Filter::Linear,
|
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);
|
let draw_surface_options = DrawSurfaceOptions::new(draw_surface_filter, true);
|
||||||
|
|
|
@ -214,7 +214,7 @@ trait ToImageRendering {
|
||||||
impl ToImageRendering for image_rendering::T {
|
impl ToImageRendering for image_rendering::T {
|
||||||
fn to_image_rendering(&self) -> webrender_traits::ImageRendering {
|
fn to_image_rendering(&self) -> webrender_traits::ImageRendering {
|
||||||
match *self {
|
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::auto => webrender_traits::ImageRendering::Auto,
|
||||||
image_rendering::T::pixelated => webrender_traits::ImageRendering::Pixelated,
|
image_rendering::T::pixelated => webrender_traits::ImageRendering::Pixelated,
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ def to_camel_case(ident):
|
||||||
|
|
||||||
class Keyword(object):
|
class Keyword(object):
|
||||||
def __init__(self, name, values, gecko_constant_prefix=None,
|
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):
|
extra_gecko_values=None, extra_servo_values=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.values = values.split()
|
self.values = values.split()
|
||||||
|
@ -29,6 +29,7 @@ class Keyword(object):
|
||||||
self.gecko_enum_prefix = gecko_enum_prefix
|
self.gecko_enum_prefix = gecko_enum_prefix
|
||||||
self.extra_gecko_values = (extra_gecko_values or "").split()
|
self.extra_gecko_values = (extra_gecko_values or "").split()
|
||||||
self.extra_servo_values = (extra_servo_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):
|
def gecko_values(self):
|
||||||
return self.values + self.extra_gecko_values
|
return self.values + self.extra_gecko_values
|
||||||
|
@ -45,12 +46,15 @@ class Keyword(object):
|
||||||
raise Exception("Bad product: " + product)
|
raise Exception("Bad product: " + product)
|
||||||
|
|
||||||
def gecko_constant(self, value):
|
def gecko_constant(self, value):
|
||||||
|
moz_stripped = value.replace("-moz-", '')
|
||||||
|
parts = moz_stripped.split('-')
|
||||||
if self.gecko_enum_prefix:
|
if self.gecko_enum_prefix:
|
||||||
parts = value.replace("-moz-", "").split("-")
|
|
||||||
parts = [p.title() for p in parts]
|
parts = [p.title() for p in parts]
|
||||||
return self.gecko_enum_prefix + "::" + "".join(parts)
|
return self.gecko_enum_prefix + "::" + "".join(parts)
|
||||||
else:
|
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):
|
def needs_cast(self):
|
||||||
return self.gecko_enum_prefix is None
|
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,
|
def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None,
|
||||||
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
|
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,
|
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.name = name
|
||||||
self.keyword = keyword
|
self.keyword = keyword
|
||||||
self.predefined_type = predefined_type
|
self.predefined_type = predefined_type
|
||||||
|
@ -78,6 +82,7 @@ class Longhand(object):
|
||||||
self.depend_on_viewport_size = depend_on_viewport_size
|
self.depend_on_viewport_size = depend_on_viewport_size
|
||||||
self.derived_from = (derived_from or "").split()
|
self.derived_from = (derived_from or "").split()
|
||||||
self.complex_color = complex_color
|
self.complex_color = complex_color
|
||||||
|
self.cast_type = cast_type
|
||||||
|
|
||||||
# https://drafts.csswg.org/css-animations/#keyframes
|
# https://drafts.csswg.org/css-animations/#keyframes
|
||||||
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property
|
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property
|
||||||
|
|
|
@ -490,21 +490,29 @@ impl Debug for ${style_struct.gecko_struct_name} {
|
||||||
"CSSColor": impl_color,
|
"CSSColor": impl_color,
|
||||||
}
|
}
|
||||||
|
|
||||||
def predefined_type_method(longhand):
|
def longhand_method(longhand):
|
||||||
args = dict(ident=longhand.ident, gecko_ffi_name=longhand.gecko_ffi_name,
|
args = dict(ident=longhand.ident, gecko_ffi_name=longhand.gecko_ffi_name,
|
||||||
need_clone=longhand.need_clone)
|
need_clone=longhand.need_clone)
|
||||||
method = predefined_types[longhand.predefined_type]
|
|
||||||
|
|
||||||
# additional type-specific arguments
|
# get the method and pass additional keyword or type-specific arguments
|
||||||
if longhand.predefined_type in ["CSSColor"]:
|
if longhand.keyword:
|
||||||
args.update(complex_color=longhand.complex_color)
|
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)
|
method(**args)
|
||||||
|
|
||||||
keyword_longhands = [x for x in longhands if x.keyword and x.name not in force_stub]
|
picked_longhands, stub_longhands = [], []
|
||||||
predefined_longhands = [x for x in longhands
|
for x in longhands:
|
||||||
if x.predefined_type in predefined_types and x.name not in force_stub]
|
if (x.keyword or 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.append(x)
|
||||||
|
else:
|
||||||
|
stub_longhands.append(x)
|
||||||
|
|
||||||
# If one of the longhands is not handled
|
# If one of the longhands is not handled
|
||||||
# by either:
|
# 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.
|
# 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
|
# In case the longhand is used in a shorthand, add it to the force_stub
|
||||||
# list above.
|
# list above.
|
||||||
|
|
||||||
for stub in stub_longhands:
|
for stub in stub_longhands:
|
||||||
if stub.name not in force_stub:
|
if stub.name not in force_stub:
|
||||||
raise Exception("Don't know what to do with longhand %s in style struct %s"
|
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.
|
* Auto-Generated Methods.
|
||||||
*/
|
*/
|
||||||
<%
|
<%
|
||||||
for longhand in keyword_longhands:
|
for longhand in picked_longhands:
|
||||||
impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)
|
longhand_method(longhand)
|
||||||
for longhand in predefined_longhands:
|
|
||||||
predefined_type_method(longhand)
|
|
||||||
%>
|
%>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -758,7 +765,7 @@ fn static_assert() {
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Font"
|
<%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="*">
|
skip_additionals="*">
|
||||||
|
|
||||||
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
|
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); }
|
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)"></%call>
|
|
||||||
|
|
||||||
// FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the
|
// 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
|
// 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.
|
// 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)
|
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) {
|
pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
|
||||||
self.gecko.mFont.weight = v as u16;
|
self.gecko.mFont.weight = v as u16;
|
||||||
}
|
}
|
||||||
|
@ -1634,17 +1625,6 @@ fn static_assert() {
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
|
|
||||||
<%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>
|
|
||||||
|
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="InheritedText"
|
<%self:impl_trait style_struct_name="InheritedText"
|
||||||
skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing">
|
skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing">
|
||||||
|
|
||||||
|
|
|
@ -312,6 +312,7 @@
|
||||||
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
||||||
'gecko_constant_prefix', 'gecko_enum_prefix',
|
'gecko_constant_prefix', 'gecko_enum_prefix',
|
||||||
'extra_gecko_values', 'extra_servo_values',
|
'extra_gecko_values', 'extra_servo_values',
|
||||||
|
'custom_consts',
|
||||||
]}
|
]}
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,9 @@
|
||||||
${helpers.single_keyword("font-style",
|
${helpers.single_keyword("font-style",
|
||||||
"normal italic oblique",
|
"normal italic oblique",
|
||||||
gecko_constant_prefix="NS_FONT_STYLE",
|
gecko_constant_prefix="NS_FONT_STYLE",
|
||||||
|
gecko_ffi_name="mFont.style",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.single_keyword("font-variant",
|
${helpers.single_keyword("font-variant",
|
||||||
"normal small-caps",
|
"normal small-caps",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
@ -347,11 +349,16 @@ ${helpers.single_keyword("font-stretch",
|
||||||
"normal ultra-condensed extra-condensed condensed \
|
"normal ultra-condensed extra-condensed condensed \
|
||||||
semi-condensed semi-expanded expanded extra-expanded \
|
semi-condensed semi-expanded expanded extra-expanded \
|
||||||
ultra-expanded",
|
ultra-expanded",
|
||||||
|
gecko_ffi_name="mFont.stretch",
|
||||||
|
gecko_constant_prefix="NS_FONT_STRETCH",
|
||||||
|
cast_type='i16',
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.single_keyword("font-kerning",
|
${helpers.single_keyword("font-kerning",
|
||||||
"auto none normal",
|
"auto none normal",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
|
gecko_ffi_name="mFont.kerning",
|
||||||
|
gecko_constant_prefix="NS_FONT_KERNING",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.single_keyword("font-variant-position",
|
${helpers.single_keyword("font-variant-position",
|
||||||
|
|
|
@ -40,73 +40,15 @@ ${helpers.single_keyword("color-adjust",
|
||||||
"economy exact", products="gecko",
|
"economy exact", products="gecko",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
<%helpers:longhand name="image-rendering" animatable="False">
|
<% image_rendering_custom_consts = { "crisp-edges": "CRISPEDGES" } %>
|
||||||
pub mod computed_value {
|
// According to to CSS-IMAGES-3, `optimizespeed` and `optimizequality` are synonyms for `auto`
|
||||||
use cssparser::ToCss;
|
// And, firefox doesn't support `pixelated` yet (https://bugzilla.mozilla.org/show_bug.cgi?id=856337)
|
||||||
use std::fmt;
|
${helpers.single_keyword("image-rendering",
|
||||||
|
"auto crisp-edges",
|
||||||
#[allow(non_camel_case_types)]
|
extra_gecko_values="optimizespeed optimizequality",
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
extra_servo_values="pixelated",
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
custom_consts=image_rendering_custom_consts,
|
||||||
pub enum T {
|
animatable=False)}
|
||||||
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<W>(&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<SpecifiedValue,()> {
|
|
||||||
// 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 { }
|
|
||||||
</%helpers:longhand>
|
|
||||||
|
|
||||||
// Used in the bottom-up flow construction traversal to avoid constructing flows for
|
// Used in the bottom-up flow construction traversal to avoid constructing flows for
|
||||||
// descendants of nodes with `display: none`.
|
// descendants of nodes with `display: none`.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче