mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implements bitflags properties animatable
This commit is contained in:
parent
969047bb7c
commit
21b7b256c2
6 changed files with 97 additions and 92 deletions
|
@ -680,6 +680,20 @@ impl Debug for ${style_struct.gecko_struct_name} {
|
|||
%endif
|
||||
</%def>
|
||||
|
||||
<%def name="impl_simple_type_with_conversion(ident)">
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
self.gecko.m${to_camel_case(ident)} = From::from(v)
|
||||
}
|
||||
|
||||
<% impl_simple_copy(ident, "m" + to_camel_case(ident)) %>
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||
From::from(self.gecko.m${to_camel_case(ident)})
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
|
||||
<%
|
||||
longhands = [x for x in style_struct.longhands
|
||||
|
@ -1134,53 +1148,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;
|
||||
|
@ -2855,11 +2827,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)">
|
||||
|
@ -3843,28 +3811,7 @@ fn static_assert() {
|
|||
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;
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -156,10 +156,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;
|
||||
|
@ -172,8 +171,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":
|
||||
|
@ -269,6 +268,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",
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue