From c77ecd698472f733ee3461f5daa2615f88e6b3db Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 8 Aug 2018 23:40:06 +0000 Subject: [PATCH] style: Implement flow-relative values for resize property. Differential Revision: https://phabricator.services.mozilla.com/D2908 --- components/style/properties/data.py | 1 + components/style/properties/gecko.mako.rs | 3 + .../style/properties/longhands/box.mako.rs | 18 +++--- components/style/values/computed/box.rs | 55 +++++++++++++++++++ components/style/values/computed/mod.rs | 2 +- components/style/values/specified/box.rs | 15 +++++ components/style/values/specified/mod.rs | 2 +- 7 files changed, 87 insertions(+), 9 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 5e7567562cf..4d3e4ad2177 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -325,6 +325,7 @@ class Longhand(object): "OverflowClipBox", "OverscrollBehavior", "Percentage", + "Resize", "SVGOpacity", "SVGPaintOrder", "ScrollSnapType", diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index bb4e02ab4d2..81f9b2ec769 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -3106,6 +3106,9 @@ fn static_assert() { ) %> ${impl_keyword('clear', 'mBreakType', clear_keyword)} + <% resize_keyword = Keyword("resize", "None Both Horizontal Vertical") %> + ${impl_keyword('resize', 'mResize', resize_keyword)} + <% overflow_x = data.longhands_by_name["overflow-x"] %> pub fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) { use properties::longhands::overflow_x::computed_value::T as BaseType; diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index 09866c8b692..6b6bcf9cbe3 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -422,17 +422,21 @@ ${helpers.single_keyword("page-break-inside", // CSS Basic User Interface Module Level 3 // http://dev.w3.org/csswg/css-ui -// FIXME support logical values `block` and `inline` (https://drafts.csswg.org/css-logical-props/#resize) // // This is APPLIES_TO_PLACEHOLDER so we can override, in the UA sheet, the // 'resize' property we'd inherit from textarea otherwise. Basically, just // makes the UA rules easier to write. -${helpers.single_keyword("resize", - "none both horizontal vertical", - products="gecko", - spec="https://drafts.csswg.org/css-ui/#propdef-resize", - flags="APPLIES_TO_PLACEHOLDER", - animation_value_type="discrete")} +${helpers.predefined_type( + "resize", + "Resize", + "computed::Resize::None", + products="gecko", + animation_value_type="discrete", + needs_context=False, + gecko_ffi_name="mResize", + flags="APPLIES_TO_PLACEHOLDER", + spec="https://drafts.csswg.org/css-ui/#propdef-resize", +)} ${helpers.predefined_type( "perspective", diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs index b0db8337608..15e447ea415 100644 --- a/components/style/values/computed/box.rs +++ b/components/style/values/computed/box.rs @@ -9,6 +9,7 @@ use values::computed::length::{LengthOrPercentage, NonNegativeLength}; use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use values::generics::box_::Perspective as GenericPerspective; use values::generics::box_::VerticalAlign as GenericVerticalAlign; +use values::specified::box_ as specified; pub use values::specified::box_::{AnimationName, Appearance, Contain, Display, OverflowClipBox}; pub use values::specified::box_::{Clear as SpecifiedClear, Float as SpecifiedFloat}; @@ -139,3 +140,57 @@ impl ToComputedValue for SpecifiedClear { } } } + +/// A computed value for the `resize` property. +#[allow(missing_docs)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] +#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToCss)] +pub enum Resize { + None, + Both, + Horizontal, + Vertical, +} + +impl ToComputedValue for specified::Resize { + type ComputedValue = Resize; + + #[inline] + fn to_computed_value(&self, context: &Context) -> Resize { + let is_vertical = context.style().writing_mode.is_vertical(); + match self { + specified::Resize::Inline => { + context.rule_cache_conditions.borrow_mut() + .set_writing_mode_dependency(context.builder.writing_mode); + if is_vertical { + Resize::Vertical + } else { + Resize::Horizontal + } + } + specified::Resize::Block => { + context.rule_cache_conditions.borrow_mut() + .set_writing_mode_dependency(context.builder.writing_mode); + if is_vertical { + Resize::Horizontal + } else { + Resize::Vertical + } + } + specified::Resize::None => Resize::None, + specified::Resize::Both => Resize::Both, + specified::Resize::Horizontal => Resize::Horizontal, + specified::Resize::Vertical => Resize::Vertical, + } + } + + #[inline] + fn from_computed_value(computed: &Resize) -> specified::Resize { + match computed { + Resize::None => specified::Resize::None, + Resize::Both => specified::Resize::Both, + Resize::Horizontal => specified::Resize::Horizontal, + Resize::Vertical => specified::Resize::Vertical, + } + } +} diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index fa2a9cdcf0d..9a6b5fd76b5 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -44,7 +44,7 @@ pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumer pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display, TransitionProperty}; pub use self::box_::{Appearance, Clear, Float}; -pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective}; +pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize}; pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::column::ColumnCount; diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 11084ce7d44..6b474689df3 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -884,6 +884,21 @@ pub enum Clear { InlineEnd } +/// https://drafts.csswg.org/css-ui/#propdef-resize +#[allow(missing_docs)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] +#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, + SpecifiedValueInfo, ToCss)] +pub enum Resize { + None, + Both, + Horizontal, + Vertical, + // https://drafts.csswg.org/css-logical-1/#resize + Inline, + Block, +} + /// The value for the `appearance` property. /// /// https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-appearance diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 1eb59617008..2da4c7e93d3 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -39,7 +39,7 @@ pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumer pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display}; pub use self::box_::{Appearance, Clear, Float}; -pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective}; +pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize}; pub use self::box_::{ScrollSnapType, TouchAction, TransitionProperty, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};