From 34de342864125d18dd3da49c869b5359d0039da0 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 8 Aug 2018 23:40:06 +0000 Subject: [PATCH] Bug 1464786 - Implement flow-relative values for resize property. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D2908 --HG-- extra : moz-landing-system : lando --- .../shared/css/generated/properties-db.js | 2 + layout/style/ServoCSSPropList.mako.py | 1 + layout/style/test/property_database.js | 2 +- servo/components/style/properties/data.py | 1 + .../components/style/properties/gecko.mako.rs | 3 + .../style/properties/longhands/box.mako.rs | 18 +++--- servo/components/style/values/computed/box.rs | 55 +++++++++++++++++++ servo/components/style/values/computed/mod.rs | 2 +- .../components/style/values/specified/box.rs | 15 +++++ .../components/style/values/specified/mod.rs | 2 +- 10 files changed, 91 insertions(+), 10 deletions(-) diff --git a/devtools/shared/css/generated/properties-db.js b/devtools/shared/css/generated/properties-db.js index 9fd01b66b7c7..16a43c1a7e20 100644 --- a/devtools/shared/css/generated/properties-db.js +++ b/devtools/shared/css/generated/properties-db.js @@ -7868,10 +7868,12 @@ exports.CSS_PROPERTIES = { ], "supports": [], "values": [ + "block", "both", "horizontal", "inherit", "initial", + "inline", "none", "unset", "vertical" diff --git a/layout/style/ServoCSSPropList.mako.py b/layout/style/ServoCSSPropList.mako.py index 0d13ca74681c..6de1fe1dbe01 100644 --- a/layout/style/ServoCSSPropList.mako.py +++ b/layout/style/ServoCSSPropList.mako.py @@ -95,6 +95,7 @@ SERIALIZED_PREDEFINED_TYPES = [ "NonNegativeLengthOrPercentage", "ListStyleType", "Opacity", + "Resize", "url::ImageUrlOrNone", ] diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index b8dbc2fcdc5e..d314721cd58a 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -2401,7 +2401,7 @@ var gCSSProperties = { // No applies_to_placeholder because we have a !important rule in forms.css. prerequisites: { "display": "block", "overflow": "auto" }, initial_values: [ "none" ], - other_values: [ "both", "horizontal", "vertical" ], + other_values: [ "both", "horizontal", "vertical", "inline", "block" ], invalid_values: [] }, "-moz-stack-sizing": { diff --git a/servo/components/style/properties/data.py b/servo/components/style/properties/data.py index 5e7567562cfa..4d3e4ad2177a 100644 --- a/servo/components/style/properties/data.py +++ b/servo/components/style/properties/data.py @@ -325,6 +325,7 @@ class Longhand(object): "OverflowClipBox", "OverscrollBehavior", "Percentage", + "Resize", "SVGOpacity", "SVGPaintOrder", "ScrollSnapType", diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index bb4e02ab4d2a..81f9b2ec7692 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/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/servo/components/style/properties/longhands/box.mako.rs b/servo/components/style/properties/longhands/box.mako.rs index 09866c8b692b..6b6bcf9cbe3f 100644 --- a/servo/components/style/properties/longhands/box.mako.rs +++ b/servo/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/servo/components/style/values/computed/box.rs b/servo/components/style/values/computed/box.rs index b0db83376081..15e447ea4156 100644 --- a/servo/components/style/values/computed/box.rs +++ b/servo/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/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index fa2a9cdcf0de..9a6b5fd76b58 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/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/servo/components/style/values/specified/box.rs b/servo/components/style/values/specified/box.rs index 11084ce7d446..6b474689df37 100644 --- a/servo/components/style/values/specified/box.rs +++ b/servo/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/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 1eb59617008b..2da4c7e93d3e 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/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};