Skip to content

Commit

Permalink
style: Move overflow to use cbindgen.
Browse files Browse the repository at this point in the history
It's one of the most annoying / hacky mako bits we have.

Differential Revision: https://phabricator.services.mozilla.com/D14084
  • Loading branch information
emilio committed Dec 16, 2018
1 parent 3f58e0b commit 901c055
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
1 change: 1 addition & 0 deletions components/style/cbindgen.toml
Expand Up @@ -64,5 +64,6 @@ include = [
"ScrollSnapType",
"OverflowClipBox",
"Resize",
"Overflow",
]
item_types = ["enums", "structs", "typedefs"]
1 change: 1 addition & 0 deletions components/style/properties/data.py
Expand Up @@ -325,6 +325,7 @@ def specified_is_copy(self):
"NonNegativeNumber",
"Opacity",
"OutlineStyle",
"Overflow",
"OverflowClipBox",
"OverflowWrap",
"OverscrollBehavior",
Expand Down
25 changes: 2 additions & 23 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1394,6 +1394,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
"OverflowClipBox": impl_simple,
"ScrollSnapType": impl_simple,
"Float": impl_simple,
"Overflow": impl_simple,
"BreakBetween": impl_simple,
"BreakWithin": impl_simple,
"Resize": impl_simple,
Expand Down Expand Up @@ -3011,7 +3012,7 @@ fn static_assert() {
}
</%def>

<% skip_box_longhands= """display overflow-y vertical-align
<% skip_box_longhands= """display vertical-align
animation-name animation-delay animation-duration
animation-direction animation-fill-mode animation-play-state
animation-iteration-count animation-timing-function
Expand Down Expand Up @@ -3063,28 +3064,6 @@ fn static_assert() {
) %>
${impl_keyword('clear', 'mBreakType', clear_keyword)}

<% overflow_x = data.longhands_by_name["overflow-x"] %>
pub fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) {
use crate::properties::longhands::overflow_x::computed_value::T as BaseType;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
self.gecko.mOverflowY = match v {
% for value in overflow_x.keyword.values_for('gecko'):
BaseType::${to_camel_case(value)} => structs::${overflow_x.keyword.gecko_constant(value)} as u8,
% endfor
};
}
${impl_simple_copy('overflow_y', 'mOverflowY')}
pub fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T {
use crate::properties::longhands::overflow_x::computed_value::T as BaseType;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match self.gecko.mOverflowY as u32 {
% for value in overflow_x.keyword.values_for('gecko'):
structs::${overflow_x.keyword.gecko_constant(value)} => BaseType::${to_camel_case(value)},
% endfor
x => panic!("Found unexpected value in style struct for overflow_y property: {}", x),
}
}

pub fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) {
use crate::values::generics::box_::VerticalAlign;
let value = match v {
Expand Down
32 changes: 14 additions & 18 deletions components/style/properties/longhands/box.mako.rs
Expand Up @@ -100,34 +100,30 @@ ${helpers.single_keyword("-servo-overflow-clip-box", "padding-box content-box",
)}
% endfor

<%
overflow_custom_consts = { "-moz-hidden-unscrollable": "CLIP" }
%>

// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
//
// We allow it to apply to placeholders for UA sheets, which set it !important.
${helpers.single_keyword(
${helpers.predefined_type(
"overflow-x",
"visible hidden scroll auto",
"Overflow",
"computed::Overflow::Visible",
animation_value_type="discrete",
extra_gecko_values="-moz-hidden-unscrollable",
custom_consts=overflow_custom_consts,
gecko_constant_prefix="NS_STYLE_OVERFLOW",
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-x",
needs_context=False,
servo_restyle_damage = "reflow",
)}

// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
//
// We allow it to apply to placeholders for UA sheets, which set it !important.
<%helpers:longhand name="overflow-y" animation_value_type="discrete"
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y"
servo_restyle_damage = "reflow">
pub use super::overflow_x::{SpecifiedValue, parse, get_initial_value, computed_value};
</%helpers:longhand>
${helpers.predefined_type(
"overflow-y",
"Overflow",
"computed::Overflow::Visible",
animation_value_type="discrete",
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y",
needs_context=False,
servo_restyle_damage = "reflow",
)}

<% transition_extra_prefixes = "moz:layout.css.prefixes.transitions webkit" %>

Expand Down
2 changes: 1 addition & 1 deletion components/style/values/computed/box.rs
Expand Up @@ -13,7 +13,7 @@ use crate::values::specified::box_ as specified;

pub use crate::values::specified::box_::{AnimationName, Appearance, BreakBetween, BreakWithin};
pub use crate::values::specified::box_::{Clear as SpecifiedClear, Float as SpecifiedFloat};
pub use crate::values::specified::box_::{Contain, Display, OverflowClipBox};
pub use crate::values::specified::box_::{Contain, Display, Overflow, OverflowClipBox};
pub use crate::values::specified::box_::{OverscrollBehavior, ScrollSnapType};
pub use crate::values::specified::box_::{TouchAction, TransitionProperty, WillChange};

Expand Down
2 changes: 1 addition & 1 deletion components/style/values/computed/mod.rs
Expand Up @@ -43,7 +43,7 @@ pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
pub use self::border::{BorderImageSlice, BorderImageWidth};
pub use self::box_::{AnimationIterationCount, AnimationName, Contain};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, Float};
pub use self::box_::{Display, TransitionProperty};
pub use self::box_::{Display, TransitionProperty, Overflow};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize};
pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
Expand Down
25 changes: 25 additions & 0 deletions components/style/values/specified/box.rs
Expand Up @@ -1363,3 +1363,28 @@ pub enum BreakWithin {
Auto,
Avoid,
}

/// The value for the `overflow-x` / `overflow-y` properties.
#[allow(missing_docs)]
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToComputedValue,
)]
#[repr(u8)]
pub enum Overflow {
Visible,
Hidden,
Scroll,
Auto,
#[cfg(feature = "gecko")]
MozHiddenUnscrollable,
}
2 changes: 1 addition & 1 deletion components/style/values/specified/mod.rs
Expand Up @@ -36,7 +36,7 @@ pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing, BorderStyle};
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, Float};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, Float, Overflow};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize};
pub use self::box_::{ScrollSnapType, TouchAction, TransitionProperty, VerticalAlign, WillChange};
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
Expand Down

0 comments on commit 901c055

Please sign in to comment.