servo: Merge #17253 - Bug1368610 - stylo: implement primitive (bit, uXX) type of discrete animatable properties (from dadaa:bug1368610); r=hiikezoe,nox,emilio

<!-- Please describe your changes on the following line: -->
This PR is to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1368610

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [X] There are tests for these changes. The tests will land in dom/animation/test of m-c. Test code is patch 6 of https://bugzilla.mozilla.org/show_bug.cgi?id=1368610

Source-Repo: https://github.com/servo/servo
Source-Revision: 88b47b0154e1897947904d926ad5af320e8bc607

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 8ee489c2b3348d6059cf051ebf6597097d12f78d
This commit is contained in:
Daisuke Akatsuka 2017-06-09 10:01:35 -07:00
Родитель cacf8fbbd8
Коммит eb243938ea
12 изменённых файлов: 326 добавлений и 211 удалений

Просмотреть файл

@ -680,6 +680,25 @@ impl Debug for ${style_struct.gecko_struct_name} {
%endif
</%def>
<%def name="impl_simple_type_with_conversion(ident, gecko_ffi_name=None)">
<%
if gecko_ffi_name is None:
gecko_ffi_name = "m" + to_camel_case(ident)
%>
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
self.gecko.${gecko_ffi_name} = From::from(v)
}
<% impl_simple_copy(ident, gecko_ffi_name) %>
#[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
From::from(self.gecko.${gecko_ffi_name})
}
</%def>
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
<%
longhands = [x for x in style_struct.longhands
@ -998,17 +1017,19 @@ fn static_assert() {
% endfor
}
<%
border_image_repeat_keywords = ["Stretch", "Repeat", "Round", "Space"]
%>
pub fn set_border_image_repeat(&mut self, v: longhands::border_image_repeat::computed_value::T) {
use properties::longhands::border_image_repeat::computed_value::RepeatKeyword;
use gecko_bindings::structs::{NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH, NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT};
use gecko_bindings::structs::{NS_STYLE_BORDER_IMAGE_REPEAT_ROUND, NS_STYLE_BORDER_IMAGE_REPEAT_SPACE};
use gecko_bindings::structs;
% for i, side in enumerate(["H", "V"]):
let k = match v.${i} {
RepeatKeyword::Stretch => NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH,
RepeatKeyword::Repeat => NS_STYLE_BORDER_IMAGE_REPEAT_REPEAT,
RepeatKeyword::Round => NS_STYLE_BORDER_IMAGE_REPEAT_ROUND,
RepeatKeyword::Space => NS_STYLE_BORDER_IMAGE_REPEAT_SPACE,
% for keyword in border_image_repeat_keywords:
RepeatKeyword::${keyword} => structs::NS_STYLE_BORDER_IMAGE_REPEAT_${keyword.upper()},
% endfor
};
self.gecko.mBorderImageRepeat${side} = k as u8;
@ -1020,6 +1041,21 @@ fn static_assert() {
self.gecko.mBorderImageRepeatV = other.gecko.mBorderImageRepeatV;
}
pub fn clone_border_image_repeat(&self) -> longhands::border_image_repeat::computed_value::T {
use properties::longhands::border_image_repeat::computed_value::RepeatKeyword;
use gecko_bindings::structs;
% for side in ["H", "V"]:
let servo_${side.lower()} = match self.gecko.mBorderImageRepeat${side} as u32 {
% for keyword in border_image_repeat_keywords:
structs::NS_STYLE_BORDER_IMAGE_REPEAT_${keyword.upper()} => RepeatKeyword::${keyword},
% endfor
x => panic!("Found unexpected value in mBorderImageRepeat${side}: {:?}", x),
};
% endfor
longhands::border_image_repeat::computed_value::T(servo_h, servo_v)
}
pub fn set_border_image_width(&mut self, v: longhands::border_image_width::computed_value::T) {
use values::generics::border::BorderImageSideWidth;
@ -1134,53 +1170,11 @@ fn static_assert() {
}
}
pub fn set_align_content(&mut self, v: longhands::align_content::computed_value::T) {
self.gecko.mAlignContent = v.bits()
}
${impl_simple_copy('align_content', 'mAlignContent')}
pub fn set_justify_content(&mut self, v: longhands::justify_content::computed_value::T) {
self.gecko.mJustifyContent = v.bits()
}
${impl_simple_copy('justify_content', 'mJustifyContent')}
pub fn set_align_self(&mut self, v: longhands::align_self::computed_value::T) {
self.gecko.mAlignSelf = v.0.bits()
}
${impl_simple_copy('align_self', 'mAlignSelf')}
pub fn set_justify_self(&mut self, v: longhands::justify_self::computed_value::T) {
self.gecko.mJustifySelf = v.0.bits()
}
${impl_simple_copy('justify_self', 'mJustifySelf')}
pub fn set_align_items(&mut self, v: longhands::align_items::computed_value::T) {
self.gecko.mAlignItems = v.0.bits()
}
${impl_simple_copy('align_items', 'mAlignItems')}
pub fn clone_align_items(&self) -> longhands::align_items::computed_value::T {
use values::specified::align::{AlignFlags, AlignItems};
AlignItems(AlignFlags::from_bits(self.gecko.mAlignItems)
.expect("mAlignItems contains valid flags"))
}
pub fn set_justify_items(&mut self, v: longhands::justify_items::computed_value::T) {
self.gecko.mJustifyItems = v.0.bits()
}
${impl_simple_copy('justify_items', 'mJustifyItems')}
pub fn clone_justify_items(&self) -> longhands::justify_items::computed_value::T {
use values::specified::align::{AlignFlags, JustifyItems};
JustifyItems(AlignFlags::from_bits(self.gecko.mJustifyItems)
.expect("mJustifyItems contains valid flags"))
}
% for kind in ["align", "justify"]:
${impl_simple_type_with_conversion(kind + "_content")}
${impl_simple_type_with_conversion(kind + "_self")}
${impl_simple_type_with_conversion(kind + "_items")}
% endfor
pub fn set_order(&mut self, v: longhands::order::computed_value::T) {
self.gecko.mOrder = v;
@ -1372,27 +1366,7 @@ fn static_assert() {
}
% endfor
pub fn set_grid_auto_flow(&mut self, v: longhands::grid_auto_flow::computed_value::T) {
use gecko_bindings::structs::NS_STYLE_GRID_AUTO_FLOW_ROW;
use gecko_bindings::structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN;
use gecko_bindings::structs::NS_STYLE_GRID_AUTO_FLOW_DENSE;
use properties::longhands::grid_auto_flow::computed_value::AutoFlow::{Row, Column};
self.gecko.mGridAutoFlow = 0;
let value = match v.autoflow {
Row => NS_STYLE_GRID_AUTO_FLOW_ROW,
Column => NS_STYLE_GRID_AUTO_FLOW_COLUMN,
};
self.gecko.mGridAutoFlow |= value as u8;
if v.dense {
self.gecko.mGridAutoFlow |= NS_STYLE_GRID_AUTO_FLOW_DENSE as u8;
}
}
${impl_simple_copy('grid_auto_flow', 'mGridAutoFlow')}
${impl_simple_type_with_conversion("grid_auto_flow")}
pub fn set_grid_template_areas(&mut self, v: longhands::grid_template_areas::computed_value::T) {
use gecko_bindings::bindings::Gecko_NewGridTemplateAreasValue;
@ -1814,21 +1788,7 @@ fn static_assert() {
unsafe { transmute(self.gecko.mFont.weight) }
}
pub fn set_font_synthesis(&mut self, v: longhands::font_synthesis::computed_value::T) {
use gecko_bindings::structs::{NS_FONT_SYNTHESIS_WEIGHT, NS_FONT_SYNTHESIS_STYLE};
self.gecko.mFont.synthesis = 0;
if v.weight {
self.gecko.mFont.synthesis |= NS_FONT_SYNTHESIS_WEIGHT as u8;
}
if v.style {
self.gecko.mFont.synthesis |= NS_FONT_SYNTHESIS_STYLE as u8;
}
}
pub fn copy_font_synthesis_from(&mut self, other: &Self) {
self.gecko.mFont.synthesis = other.gecko.mFont.synthesis;
}
${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}
pub fn set_font_size_adjust(&mut self, v: longhands::font_size_adjust::computed_value::T) {
use properties::longhands::font_size_adjust::computed_value::T;
@ -1863,10 +1823,7 @@ fn static_assert() {
}
}
pub fn set_font_language_override(&mut self, v: longhands::font_language_override::computed_value::T) {
self.gecko.mFont.languageOverride = v.0;
}
${impl_simple_copy('font_language_override', 'mFont.languageOverride')}
<% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %>
pub fn set_font_variant_alternates(&mut self, v: longhands::font_variant_alternates::computed_value::T) {
self.gecko.mFont.variantAlternates = v.to_gecko_keyword()
@ -1879,23 +1836,9 @@ fn static_assert() {
// self.gecko.mFont.alternateValues = other.gecko.mFont.alternateValues;
}
pub fn set_font_variant_ligatures(&mut self, v: longhands::font_variant_ligatures::computed_value::T) {
self.gecko.mFont.variantLigatures = v.to_gecko_keyword()
}
${impl_simple_copy('font_variant_ligatures', 'mFont.variantLigatures')}
pub fn set_font_variant_east_asian(&mut self, v: longhands::font_variant_east_asian::computed_value::T) {
self.gecko.mFont.variantEastAsian = v.to_gecko_keyword()
}
${impl_simple_copy('font_variant_east_asian', 'mFont.variantEastAsian')}
pub fn set_font_variant_numeric(&mut self, v: longhands::font_variant_numeric::computed_value::T) {
self.gecko.mFont.variantNumeric = v.to_gecko_keyword()
}
${impl_simple_copy('font_variant_numeric', 'mFont.variantNumeric')}
${impl_simple_type_with_conversion("font_variant_ligatures", "mFont.variantLigatures")}
${impl_simple_type_with_conversion("font_variant_east_asian", "mFont.variantEastAsian")}
${impl_simple_type_with_conversion("font_variant_numeric", "mFont.variantNumeric")}
#[allow(non_snake_case)]
pub fn set__moz_min_font_size_ratio(&mut self, v: longhands::_moz_min_font_size_ratio::computed_value::T) {
@ -2654,7 +2597,7 @@ fn static_assert() {
<% scroll_snap_type_keyword = Keyword("scroll-snap-type", "none mandatory proximity") %>
${impl_keyword('scroll_snap_type_y', 'mScrollSnapTypeY', scroll_snap_type_keyword, need_clone=False)}
${impl_keyword('scroll_snap_type_y', 'mScrollSnapTypeY', scroll_snap_type_keyword, need_clone=True)}
pub fn set_perspective_origin(&mut self, v: longhands::perspective_origin::computed_value::T) {
self.gecko.mPerspectiveOrigin[0].set(v.horizontal);
@ -2855,11 +2798,7 @@ fn static_assert() {
${impl_simple_copy("contain", "mContain")}
pub fn set_touch_action(&mut self, v: longhands::touch_action::computed_value::T) {
self.gecko.mTouchAction = v.bits();
}
${impl_simple_copy("touch_action", "mTouchAction")}
${impl_simple_type_with_conversion("touch_action")}
</%self:impl_trait>
<%def name="simple_image_array_property(name, shorthand, field_name)">
@ -3637,7 +3576,7 @@ fn static_assert() {
<%self:impl_trait style_struct_name="InheritedText"
skip_longhands="text-align text-emphasis-style text-shadow line-height letter-spacing word-spacing
-webkit-text-stroke-width text-emphasis-position -moz-tab-size -moz-text-size-adjust">
-webkit-text-stroke-width text-emphasis-position -moz-tab-size">
<% text_align_keyword = Keyword("text-align",
"start end left right center justify -moz-center -moz-left -moz-right char",
@ -3744,25 +3683,7 @@ fn static_assert() {
}
}
pub fn set_text_emphasis_position(&mut self, v: longhands::text_emphasis_position::computed_value::T) {
use properties::longhands::text_emphasis_position::*;
let mut result = match v.0 {
HorizontalWritingModeValue::Over => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER as u8,
HorizontalWritingModeValue::Under => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER as u8,
};
match v.1 {
VerticalWritingModeValue::Right => {
result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT as u8;
}
VerticalWritingModeValue::Left => {
result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT as u8;
}
}
self.gecko.mTextEmphasisPosition = result;
}
<%call expr="impl_simple_copy('text_emphasis_position', 'mTextEmphasisPosition')"></%call>
${impl_simple_type_with_conversion("text_emphasis_position")}
pub fn set_text_emphasis_style(&mut self, v: longhands::text_emphasis_style::computed_value::T) {
use properties::longhands::text_emphasis_style::computed_value::T;
@ -3804,7 +3725,7 @@ fn static_assert() {
self.gecko.mTextEmphasisStyle = other.gecko.mTextEmphasisStyle;
}
<%call expr="impl_app_units('_webkit_text_stroke_width', 'mWebkitTextStrokeWidth', need_clone=False)"></%call>
<%call expr="impl_app_units('_webkit_text_stroke_width', 'mWebkitTextStrokeWidth', need_clone=True)"></%call>
#[allow(non_snake_case)]
pub fn set__moz_tab_size(&mut self, v: longhands::_moz_tab_size::computed_value::T) {
@ -3832,39 +3753,13 @@ fn static_assert() {
}
<%call expr="impl_coord_copy('_moz_tab_size', 'mTabSize')"></%call>
<% text_size_adjust_keyword = Keyword("text-size-adjust", "auto none") %>
${impl_keyword('_moz_text_size_adjust', 'mTextSizeAdjust', text_size_adjust_keyword, need_clone=False)}
</%self:impl_trait>
<%self:impl_trait style_struct_name="Text"
skip_longhands="text-decoration-line text-overflow initial-letter"
skip_additionals="*">
pub fn set_text_decoration_line(&mut self, v: longhands::text_decoration_line::computed_value::T) {
let mut bits: u8 = 0;
if v.contains(longhands::text_decoration_line::UNDERLINE) {
bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8;
}
if v.contains(longhands::text_decoration_line::OVERLINE) {
bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8;
}
if v.contains(longhands::text_decoration_line::LINE_THROUGH) {
bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8;
}
if v.contains(longhands::text_decoration_line::BLINK) {
bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_BLINK as u8;
}
if v.contains(longhands::text_decoration_line::COLOR_OVERRIDE) {
bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL as u8;
}
self.gecko.mTextDecorationLine = bits;
}
${impl_simple_copy('text_decoration_line', 'mTextDecorationLine')}
${impl_simple_type_with_conversion("text_decoration_line")}
fn clear_overflow_sides_if_string(&mut self) {
use gecko_bindings::structs::nsStyleTextOverflowSide;
@ -3938,6 +3833,18 @@ fn static_assert() {
self.gecko.mInitialLetterSink = other.gecko.mInitialLetterSink;
}
pub fn clone_initial_letter(&self) -> longhands::initial_letter::computed_value::T {
use values::generics::text::InitialLetter;
if self.gecko.mInitialLetterSize == 0. && self.gecko.mInitialLetterSink == 0 {
InitialLetter::Normal
} else if self.gecko.mInitialLetterSize.floor() as i32 == self.gecko.mInitialLetterSink {
InitialLetter::Specified(self.gecko.mInitialLetterSize, None)
} else {
InitialLetter::Specified(self.gecko.mInitialLetterSize, Some(self.gecko.mInitialLetterSink))
}
}
#[inline]
pub fn has_underline(&self) -> bool {
(self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8)) != 0
@ -4491,12 +4398,7 @@ clip-path
</%self:impl_trait>
<%self:impl_trait style_struct_name="UI" skip_longhands="-moz-force-broken-image-icon">
#[allow(non_snake_case)]
pub fn set__moz_force_broken_image_icon(&mut self, v: longhands::_moz_force_broken_image_icon::computed_value::T) {
self.gecko.mForceBrokenImageIcon = v.0 as u8;
}
${impl_simple_copy("_moz_force_broken_image_icon", "mForceBrokenImageIcon")}
${impl_simple_type_with_conversion("_moz_force_broken_image_icon", "mForceBrokenImageIcon")}
</%self:impl_trait>
<%self:impl_trait style_struct_name="XUL"
@ -4507,6 +4409,11 @@ clip-path
}
${impl_simple_copy("_moz_box_ordinal_group", "mBoxOrdinal")}
#[allow(non_snake_case)]
pub fn clone__moz_box_ordinal_group(&self) -> i32{
self.gecko.mBoxOrdinal as i32
}
</%self:impl_trait>
<%def name="define_ffi_struct_accessor(style_struct)">

Просмотреть файл

@ -212,7 +212,7 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
animation_value_type="none",
boxed=True)}
<%helpers:longhand name="border-image-repeat" animation_value_type="none"
<%helpers:longhand name="border-image-repeat" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat">
use std::fmt;
use style_traits::ToCss;

Просмотреть файл

@ -1612,7 +1612,7 @@ ${helpers.single_keyword("scroll-snap-type-x",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type-x)",
animation_value_type="discrete")}
<%helpers:longhand products="gecko" name="scroll-snap-type-y" animation_value_type="none"
<%helpers:longhand products="gecko" name="scroll-snap-type-y" animation_value_type="discrete"
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type-x)">
pub use super::scroll_snap_type_x::SpecifiedValue;
pub use super::scroll_snap_type_x::computed_value;
@ -1710,7 +1710,7 @@ ${helpers.predefined_type("transform-origin",
// FIXME: `size` and `content` values are not implemented and `strict` is implemented
// like `content`(layout style paint) in gecko. We should implement `size` and `content`,
// also update the glue once they are implemented in gecko.
<%helpers:longhand name="contain" animation_value_type="none" products="gecko" need_clone="True"
<%helpers:longhand name="contain" animation_value_type="discrete" products="gecko" need_clone="True"
flags="FIXPOS_CB"
spec="https://drafts.csswg.org/css-contain/#contain-property">
use std::fmt;
@ -1925,7 +1925,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape",
<%helpers:longhand name="touch-action"
products="gecko"
animation_value_type="none"
animation_value_type="discrete"
disable_when_testing="True"
spec="https://compat.spec.whatwg.org/#touch-action">
use gecko_bindings::structs;
@ -1999,4 +1999,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape",
_ => Err(()),
}
}
#[cfg(feature = "gecko")]
impl_bitflags_conversions!(SpecifiedValue);
</%helpers:longhand>

Просмотреть файл

@ -16,6 +16,23 @@
%endif
</%def>
#[cfg(feature = "gecko")]
macro_rules! impl_gecko_keyword_from_trait {
($name: ident, $utype: ty) => {
impl From<$utype> for $name {
fn from(bits: $utype) -> $name {
$name::from_gecko_keyword(bits)
}
}
impl From<$name> for $utype {
fn from(v: $name) -> $utype {
v.to_gecko_keyword()
}
}
};
}
// Define ToComputedValue, ToCss, and other boilerplate for a specified value
// which is of the form `enum SpecifiedValue {Value(..), System(SystemFont)}`
<%def name="simple_system_boilerplate(name)">
@ -1144,7 +1161,7 @@ ${helpers.single_keyword_system("font-variant-caps",
}
</%helpers:longhand>
<%helpers:longhand products="gecko" name="font-synthesis" animation_value_type="none"
<%helpers:longhand products="gecko" name="font-synthesis" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-synthesis">
use std::fmt;
use style_traits::ToCss;
@ -1204,6 +1221,34 @@ ${helpers.single_keyword_system("font-variant-caps",
_ => Err(())
}
}
#[cfg(feature = "gecko")]
impl From<u8> for SpecifiedValue {
fn from(bits: u8) -> SpecifiedValue {
use gecko_bindings::structs;
SpecifiedValue {
weight: bits & structs::NS_FONT_SYNTHESIS_WEIGHT as u8 != 0,
style: bits & structs::NS_FONT_SYNTHESIS_STYLE as u8 != 0
}
}
}
#[cfg(feature = "gecko")]
impl From<SpecifiedValue> for u8 {
fn from(v: SpecifiedValue) -> u8 {
use gecko_bindings::structs;
let mut bits: u8 = 0;
if v.weight {
bits |= structs::NS_FONT_SYNTHESIS_WEIGHT as u8;
}
if v.style {
bits |= structs::NS_FONT_SYNTHESIS_STYLE as u8;
}
bits
}
}
</%helpers:longhand>
${helpers.single_keyword_system("font-stretch",
@ -1362,7 +1407,7 @@ macro_rules! exclusive_value {
}
}
<%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="none"
<%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-east-asian">
use properties::longhands::system_font::SystemFont;
use std::fmt;
@ -1500,9 +1545,12 @@ macro_rules! exclusive_value {
Err(())
}
}
#[cfg(feature = "gecko")]
impl_gecko_keyword_from_trait!(VariantEastAsian, u16);
</%helpers:longhand>
<%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="none"
<%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-ligatures">
use properties::longhands::system_font::SystemFont;
use std::fmt;
@ -1650,9 +1698,12 @@ macro_rules! exclusive_value {
Err(())
}
}
#[cfg(feature = "gecko")]
impl_gecko_keyword_from_trait!(VariantLigatures, u16);
</%helpers:longhand>
<%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="none"
<%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric">
use properties::longhands::system_font::SystemFont;
use std::fmt;
@ -1793,6 +1844,9 @@ macro_rules! exclusive_value {
Err(())
}
}
#[cfg(feature = "gecko")]
impl_gecko_keyword_from_trait!(VariantNumeric, u8);
</%helpers:longhand>
${helpers.single_keyword_system("font-variant-position",
@ -1875,7 +1929,7 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
}
</%helpers:longhand>
<%helpers:longhand name="font-language-override" products="gecko" animation_value_type="none"
<%helpers:longhand name="font-language-override" products="gecko" animation_value_type="discrete"
extra_prefixes="moz" boxed="True"
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override">
use properties::longhands::system_font::SystemFont;
@ -2009,6 +2063,20 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control-
})
}
}
#[cfg(feature = "gecko")]
impl From<u32> for computed_value::T {
fn from(bits: u32) -> computed_value::T {
computed_value::T(bits)
}
}
#[cfg(feature = "gecko")]
impl From<computed_value::T> for u32 {
fn from(v: computed_value::T) -> u32 {
v.0
}
}
</%helpers:longhand>
<%helpers:longhand name="-x-lang" products="gecko" animation_value_type="none" internal="True"

Просмотреть файл

@ -18,18 +18,20 @@ ${helpers.predefined_type("line-height",
${helpers.single_keyword("text-transform",
"none capitalize uppercase lowercase",
extra_gecko_values="full-width",
animation_value_type="none",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text/#propdef-text-transform")}
${helpers.single_keyword("hyphens", "manual none auto",
gecko_enum_prefix="StyleHyphens",
products="gecko", animation_value_type="none", extra_prefixes="moz",
gecko_inexhaustive=True,
products="gecko", animation_value_type="discrete", extra_prefixes="moz",
spec="https://drafts.csswg.org/css-text/#propdef-hyphens")}
// TODO: Support <percentage>
${helpers.single_keyword("-moz-text-size-adjust", "auto none",
gecko_constant_prefix="NS_STYLE_TEXT_SIZE_ADJUST",
products="gecko", animation_value_type="none",
gecko_ffi_name="mTextSizeAdjust",
products="gecko", animation_value_type="discrete",
spec="https://drafts.csswg.org/css-size-adjust/#adjustment-control",
alias="-webkit-text-size-adjust")}
@ -45,7 +47,7 @@ ${helpers.predefined_type("text-indent",
${helpers.single_keyword("overflow-wrap",
"normal break-word",
gecko_constant_prefix="NS_STYLE_OVERFLOWWRAP",
animation_value_type="none",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text/#propdef-overflow-wrap",
alias="word-wrap")}
@ -53,7 +55,7 @@ ${helpers.single_keyword("overflow-wrap",
${helpers.single_keyword("word-break",
"normal break-all keep-all",
gecko_constant_prefix="NS_STYLE_WORDBREAK",
animation_value_type="none",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text/#propdef-word-break")}
// TODO(pcwalton): Support `text-justify: distribute`.
@ -62,7 +64,8 @@ ${helpers.single_keyword("word-break",
extra_gecko_values="inter-character"
extra_specified="${'distribute' if product == 'gecko' else ''}"
gecko_enum_prefix="StyleTextJustify"
animation_value_type="none"
gecko_inexhaustive="True"
animation_value_type="discrete"
spec="https://drafts.csswg.org/css-text/#propdef-text-justify">
no_viewport_percentage!(SpecifiedValue);
@ -101,11 +104,11 @@ ${helpers.single_keyword("text-align-last",
"auto start end left right center justify",
products="gecko",
gecko_constant_prefix="NS_STYLE_TEXT_ALIGN",
animation_value_type="none",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-text/#propdef-text-align-last")}
// TODO make this a shorthand and implement text-align-last/text-align-all
<%helpers:longhand name="text-align" animation_value_type="none" need_clone="True"
<%helpers:longhand name="text-align" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-text/#propdef-text-align">
no_viewport_percentage!(SpecifiedValue);
pub mod computed_value {
@ -360,7 +363,8 @@ ${helpers.predefined_type("word-spacing",
extra_gecko_values="-moz-pre-space"
gecko_enum_prefix="StyleWhiteSpace"
needs_conversion="True"
animation_value_type="none"
gecko_inexhaustive="True"
animation_value_type="discrete"
spec="https://drafts.csswg.org/css-text/#propdef-white-space">
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
@ -605,7 +609,7 @@ ${helpers.predefined_type("word-spacing",
}
</%helpers:longhand>
<%helpers:longhand name="text-emphasis-position" animation_value_type="none" products="gecko"
<%helpers:longhand name="text-emphasis-position" animation_value_type="discrete" products="gecko"
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-position">
use values::computed::ComputedValueAsSpecified;
use style_traits::ToCss;
@ -663,6 +667,32 @@ ${helpers.predefined_type("word-spacing",
SpecifiedValue(horiz, vert)
}
}
impl From<u8> for SpecifiedValue {
fn from(bits: u8) -> SpecifiedValue {
SpecifiedValue::from_gecko_keyword(bits as u32)
}
}
impl From<SpecifiedValue> for u8 {
fn from(v: SpecifiedValue) -> u8 {
use gecko_bindings::structs;
let mut result = match v.0 {
HorizontalWritingModeValue::Over => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_OVER,
HorizontalWritingModeValue::Under => structs::NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER,
};
match v.1 {
VerticalWritingModeValue::Right => {
result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT;
}
VerticalWritingModeValue::Left => {
result |= structs::NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT;
}
};
result as u8
}
}
% endif
</%helpers:longhand>

Просмотреть файл

@ -16,7 +16,7 @@ ${helpers.predefined_type("outline-color", "Color", "computed_value::T::currentc
ignored_when_colors_disabled=True,
spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")}
<%helpers:longhand name="outline-style" need_clone="True" animation_value_type="none"
<%helpers:longhand name="outline-style" animation_value_type="discrete"
spec="https://drafts.csswg.org/css-ui/#propdef-outline-style">
use values::specified::BorderStyle;

Просмотреть файл

@ -24,6 +24,24 @@
animation_value_type="ComputedValue", logical=True)}
% endfor
#[cfg(feature = "gecko")]
macro_rules! impl_align_conversions {
($name: path) => {
impl From<u8> for $name {
fn from(bits: u8) -> $name {
$name(::values::specified::align::AlignFlags::from_bits(bits)
.expect("bits contain valid flag"))
}
}
impl From<$name> for u8 {
fn from(v: $name) -> u8 {
v.0.bits()
}
}
};
}
${helpers.predefined_type("z-index", "IntegerOrAuto",
"Either::Second(Auto)",
spec="https://www.w3.org/TR/CSS2/visuren.html#z-index",
@ -48,14 +66,14 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse",
${helpers.single_keyword("justify-content", "flex-start stretch flex-end center space-between space-around",
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-align/#propdef-justify-content",
animation_value_type="none")}
animation_value_type="discrete")}
% else:
${helpers.predefined_type(name="justify-content",
type="AlignJustifyContent",
initial_value="specified::AlignJustifyContent::normal()",
spec="https://drafts.csswg.org/css-align/#propdef-justify-content",
extra_prefixes="webkit",
animation_value_type="none")}
animation_value_type="discrete")}
% endif
% if product == "servo":
@ -63,7 +81,7 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse",
${helpers.single_keyword("align-content", "stretch flex-start flex-end center space-between space-around",
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-align/#propdef-align-content",
animation_value_type="none")}
animation_value_type="discrete")}
${helpers.single_keyword("align-items",
"stretch flex-start flex-end center baseline",
@ -76,7 +94,7 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse",
initial_value="specified::AlignJustifyContent::normal()",
spec="https://drafts.csswg.org/css-align/#propdef-align-content",
extra_prefixes="webkit",
animation_value_type="none")}
animation_value_type="discrete")}
${helpers.predefined_type(name="align-items",
type="AlignItems",
@ -85,11 +103,17 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse",
extra_prefixes="webkit",
animation_value_type="discrete")}
#[cfg(feature = "gecko")]
impl_align_conversions!(::values::specified::align::AlignItems);
${helpers.predefined_type(name="justify-items",
type="JustifyItems",
initial_value="specified::JustifyItems::auto()",
spec="https://drafts.csswg.org/css-align/#propdef-justify-items",
animation_value_type="none")}
animation_value_type="discrete")}
#[cfg(feature = "gecko")]
impl_align_conversions!(::values::specified::align::JustifyItems);
% endif
// Flex item properties
@ -109,23 +133,25 @@ ${helpers.predefined_type("flex-shrink", "Number",
% if product == "servo":
// FIXME: Update Servo to support the same syntax as Gecko.
${helpers.single_keyword("align-self", "auto stretch flex-start flex-end center baseline",
need_clone=True,
extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self",
animation_value_type="none")}
animation_value_type="discrete")}
% else:
${helpers.predefined_type(name="align-self",
type="AlignJustifySelf",
initial_value="specified::AlignJustifySelf::auto()",
spec="https://drafts.csswg.org/css-align/#align-self-property",
extra_prefixes="webkit",
animation_value_type="none")}
animation_value_type="discrete")}
${helpers.predefined_type(name="justify-self",
type="AlignJustifySelf",
initial_value="specified::AlignJustifySelf::auto()",
spec="https://drafts.csswg.org/css-align/#justify-self-property",
animation_value_type="none")}
animation_value_type="discrete")}
#[cfg(feature = "gecko")]
impl_align_conversions!(::values::specified::align::AlignJustifySelf);
% endif
// https://drafts.csswg.org/css-flexbox/#propdef-order
@ -266,7 +292,7 @@ ${helpers.predefined_type("object-position",
<%helpers:longhand name="grid-auto-flow"
spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-flow"
products="gecko"
animation_value_type="none">
animation_value_type="discrete">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
@ -346,6 +372,43 @@ ${helpers.predefined_type("object-position",
Err(())
}
}
#[cfg(feature = "gecko")]
impl From<u8> for SpecifiedValue {
fn from(bits: u8) -> SpecifiedValue {
use gecko_bindings::structs;
use self::computed_value::AutoFlow;
SpecifiedValue {
autoflow:
if bits & structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8 != 0 {
AutoFlow::Row
} else {
AutoFlow::Column
},
dense:
bits & structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8 != 0,
}
}
}
#[cfg(feature = "gecko")]
impl From<SpecifiedValue> for u8 {
fn from(v: SpecifiedValue) -> u8 {
use gecko_bindings::structs;
use self::computed_value::AutoFlow;
let mut result: u8 = match v.autoflow {
AutoFlow::Row => structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8,
AutoFlow::Column => structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN as u8,
};
if v.dense {
result |= structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8;
}
result
}
}
</%helpers:longhand>
<%helpers:longhand name="grid-template-areas"

Просмотреть файл

@ -143,10 +143,9 @@ ${helpers.single_keyword("unicode-bidi",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-writing-modes/#propdef-unicode-bidi")}
// FIXME: This prop should be animatable.
<%helpers:longhand name="text-decoration-line"
custom_cascade="${product == 'servo'}"
animation_value_type="none"
animation_value_type="discrete"
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-line">
use std::fmt;
use style_traits::ToCss;
@ -159,8 +158,8 @@ ${helpers.single_keyword("unicode-bidi",
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub flags SpecifiedValue: u8 {
const NONE = 0,
const OVERLINE = 0x01,
const UNDERLINE = 0x02,
const UNDERLINE = 0x01,
const OVERLINE = 0x02,
const LINE_THROUGH = 0x04,
const BLINK = 0x08,
% if product == "gecko":
@ -256,6 +255,9 @@ ${helpers.single_keyword("unicode-bidi",
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context);
}
% endif
#[cfg(feature = "gecko")]
impl_bitflags_conversions!(SpecifiedValue);
</%helpers:longhand>
${helpers.single_keyword("text-decoration-style",
@ -278,6 +280,6 @@ ${helpers.predefined_type(
"InitialLetter",
"computed::InitialLetter::normal()",
initial_specified_value="specified::InitialLetter::normal()",
animation_value_type="none",
animation_value_type="discrete",
products="gecko",
spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials")}

Просмотреть файл

@ -42,7 +42,7 @@ ${helpers.single_keyword("-moz-window-shadow", "none default menu tooltip sheet"
<%helpers:longhand name="-moz-force-broken-image-icon"
products="gecko"
animation_value_type="none"
animation_value_type="discrete"
spec="None (Nonstandard Firefox-only property)">
use std::fmt;
use style_traits::ToCss;
@ -83,4 +83,19 @@ ${helpers.single_keyword("-moz-window-shadow", "none default menu tooltip sheet"
_ => Err(()),
}
}
impl From<u8> for SpecifiedValue {
fn from(bits: u8) -> SpecifiedValue {
SpecifiedValue(bits == 1)
}
}
impl From<SpecifiedValue> for u8 {
fn from(v: SpecifiedValue) -> u8 {
match v.0 {
true => 1u8,
false => 0u8,
}
}
}
</%helpers:longhand>

Просмотреть файл

@ -59,5 +59,5 @@ ${helpers.predefined_type("-moz-box-ordinal-group", "Integer", "0",
products="gecko",
alias="-webkit-box-ordinal-group",
gecko_ffi_name="mBoxOrdinal",
animation_value_type="none",
animation_value_type="discrete",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-box-ordinal-group)")}

Просмотреть файл

@ -53,6 +53,23 @@ macro_rules! property_name {
($s: tt) => { atom!($s) }
}
#[cfg(feature = "gecko")]
macro_rules! impl_bitflags_conversions {
($name: ident) => {
impl From<u8> for $name {
fn from(bits: u8) -> $name {
$name::from_bits(bits).expect("bits contain valid flag")
}
}
impl From<$name> for u8 {
fn from(v: $name) -> u8 {
v.bits()
}
}
};
}
<%!
from data import Method, Keyword, to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS
import os.path

Просмотреть файл

@ -137,10 +137,6 @@ impl AlignJustifyContent {
AlignJustifyContent(flags.bits() as u16 | ((fallback.bits() as u16) << ALIGN_ALL_SHIFT))
}
/// The combined 16-bit flags, for copying into a Gecko style struct.
#[inline]
pub fn bits(self) -> u16 { self.0 }
/// The primary alignment
#[inline]
pub fn primary(self) -> AlignFlags {
@ -325,6 +321,20 @@ impl Parse for JustifyItems {
}
}
#[cfg(feature = "gecko")]
impl From<u16> for AlignJustifyContent {
fn from(bits: u16) -> AlignJustifyContent {
AlignJustifyContent(bits)
}
}
#[cfg(feature = "gecko")]
impl From<AlignJustifyContent> for u16 {
fn from(v: AlignJustifyContent) -> u16 {
v.0
}
}
// auto | normal | stretch | <baseline-position>
fn parse_auto_normal_stretch_baseline(input: &mut Parser) -> Result<AlignFlags, ()> {
if let Ok(baseline) = input.try(parse_baseline) {