aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-05-01 13:08:34 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-05-07 12:55:41 +0200
commitc990c9623d8f204594e9fa12777fd595e1559bbc (patch)
tree706a527bae99ad0840f494b7d57d38ab8b44e308
parent8123007717a60e57ee13d98ae5df23e42d47aa53 (diff)
downloadservo-c990c9623d8f204594e9fa12777fd595e1559bbc.tar.gz
servo-c990c9623d8f204594e9fa12777fd595e1559bbc.zip
style: Use rust types for vertical-align.
The previous commit removed the dependence on the discriminant value, so we don't need to keep discriminants different from text-align anymore. Differential Revision: https://phabricator.services.mozilla.com/D29361
-rw-r--r--components/style/gecko/conversions.rs21
-rw-r--r--components/style/properties/gecko.mako.rs45
-rw-r--r--components/style/values/generics/box.rs41
-rw-r--r--components/style/values/specified/box.rs17
-rw-r--r--components/style/values/specified/text.rs3
5 files changed, 34 insertions, 93 deletions
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs
index 7b73f00e73e..4cd5722bdb0 100644
--- a/components/style/gecko/conversions.rs
+++ b/components/style/gecko/conversions.rs
@@ -22,7 +22,6 @@ use crate::values::computed::url::ComputedImageUrl;
use crate::values::computed::{Angle, Gradient, Image};
use crate::values::computed::{Integer, LengthPercentage};
use crate::values::computed::{Length, Percentage, TextAlign};
-use crate::values::generics::box_::VerticalAlign;
use crate::values::generics::grid::{TrackListValue, TrackSize};
use crate::values::generics::image::{CompatMode, Image as GenericImage};
use crate::values::generics::rect::Rect;
@@ -875,26 +874,6 @@ where
}
}
-impl<L> VerticalAlign<L> {
- /// Converts an enumerated value coming from Gecko to a `VerticalAlign<L>`.
- pub fn from_gecko_keyword(value: u32) -> Self {
- match value {
- structs::NS_STYLE_VERTICAL_ALIGN_BASELINE => VerticalAlign::Baseline,
- structs::NS_STYLE_VERTICAL_ALIGN_SUB => VerticalAlign::Sub,
- structs::NS_STYLE_VERTICAL_ALIGN_SUPER => VerticalAlign::Super,
- structs::NS_STYLE_VERTICAL_ALIGN_TOP => VerticalAlign::Top,
- structs::NS_STYLE_VERTICAL_ALIGN_TEXT_TOP => VerticalAlign::TextTop,
- structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE => VerticalAlign::Middle,
- structs::NS_STYLE_VERTICAL_ALIGN_BOTTOM => VerticalAlign::Bottom,
- structs::NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM => VerticalAlign::TextBottom,
- structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE => {
- VerticalAlign::MozMiddleWithBaseline
- },
- _ => panic!("unexpected enumerated value for vertical-align"),
- }
- }
-}
-
impl TextAlign {
/// Obtain a specified value from a Gecko keyword value
///
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 2dde6af2a57..b73bb073fa6 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -38,7 +38,7 @@ use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}
use crate::gecko_bindings::structs;
use crate::gecko_bindings::structs::nsCSSPropertyID;
use crate::gecko_bindings::structs::mozilla::PseudoStyleType;
-use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
+use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
use crate::gecko_bindings::sugar::refptr::RefPtr;
use crate::gecko::values::GeckoStyleCoordConvertible;
use crate::gecko::values::round_border_to_device_pixels;
@@ -2505,7 +2505,7 @@ fn static_assert() {
}
</%def>
-<% skip_box_longhands= """display vertical-align
+<% skip_box_longhands= """display
animation-name animation-delay animation-duration
animation-direction animation-fill-mode animation-play-state
animation-iteration-count animation-timing-function
@@ -2561,47 +2561,6 @@ fn static_assert() {
) %>
${impl_keyword('clear', 'mBreakType', clear_keyword)}
- pub fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) {
- use crate::values::generics::box_::VerticalAlign;
- let value = match v {
- VerticalAlign::Baseline => structs::NS_STYLE_VERTICAL_ALIGN_BASELINE,
- VerticalAlign::Sub => structs::NS_STYLE_VERTICAL_ALIGN_SUB,
- VerticalAlign::Super => structs::NS_STYLE_VERTICAL_ALIGN_SUPER,
- VerticalAlign::Top => structs::NS_STYLE_VERTICAL_ALIGN_TOP,
- VerticalAlign::TextTop => structs::NS_STYLE_VERTICAL_ALIGN_TEXT_TOP,
- VerticalAlign::Middle => structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE,
- VerticalAlign::Bottom => structs::NS_STYLE_VERTICAL_ALIGN_BOTTOM,
- VerticalAlign::TextBottom => structs::NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM,
- VerticalAlign::MozMiddleWithBaseline => {
- structs::NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE
- },
- VerticalAlign::Length(length) => {
- self.gecko.mVerticalAlign.set(length);
- return;
- },
- };
- self.gecko.mVerticalAlign.set_value(CoordDataValue::Enumerated(value));
- }
-
- pub fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T {
- use crate::values::computed::LengthPercentage;
- use crate::values::generics::box_::VerticalAlign;
-
- let gecko = &self.gecko.mVerticalAlign;
- match gecko.as_value() {
- CoordDataValue::Enumerated(value) => VerticalAlign::from_gecko_keyword(value),
- _ => {
- VerticalAlign::Length(
- LengthPercentage::from_gecko_style_coord(gecko).expect(
- "expected <length-percentage> for vertical-align",
- ),
- )
- },
- }
- }
-
- <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call>
-
${impl_style_coord("scroll_snap_points_x", "mScrollSnapPointsX")}
${impl_style_coord("scroll_snap_points_y", "mScrollSnapPointsY")}
diff --git a/components/style/values/generics/box.rs b/components/style/values/generics/box.rs
index 3e8f959f456..5d6e8e25031 100644
--- a/components/style/values/generics/box.rs
+++ b/components/style/values/generics/box.rs
@@ -6,14 +6,15 @@
use crate::values::animated::ToAnimatedZero;
-/// A generic value for the `vertical-align` property.
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
+ FromPrimitive,
MallocSizeOf,
+ Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
@@ -21,35 +22,51 @@ use crate::values::animated::ToAnimatedZero;
ToResolvedValue,
ToShmem,
)]
-pub enum VerticalAlign<LengthPercentage> {
- /// `baseline`
+#[repr(u8)]
+#[allow(missing_docs)]
+pub enum VerticalAlignKeyword {
Baseline,
- /// `sub`
Sub,
- /// `super`
Super,
- /// `top`
Top,
- /// `text-top`
TextTop,
- /// `middle`
Middle,
- /// `bottom`
Bottom,
- /// `text-bottom`
TextBottom,
- /// `-moz-middle-with-baseline`
#[cfg(feature = "gecko")]
MozMiddleWithBaseline,
+}
+
+/// A generic value for the `vertical-align` property.
+#[derive(
+ Animate,
+ Clone,
+ ComputeSquaredDistance,
+ Copy,
+ Debug,
+ MallocSizeOf,
+ PartialEq,
+ SpecifiedValueInfo,
+ ToComputedValue,
+ ToCss,
+ ToResolvedValue,
+ ToShmem,
+)]
+#[repr(C, u8)]
+pub enum GenericVerticalAlign<LengthPercentage> {
+ /// One of the vertical-align keywords.
+ Keyword(VerticalAlignKeyword),
/// `<length-percentage>`
Length(LengthPercentage),
}
+pub use self::GenericVerticalAlign as VerticalAlign;
+
impl<L> VerticalAlign<L> {
/// Returns `baseline`.
#[inline]
pub fn baseline() -> Self {
- VerticalAlign::Baseline
+ VerticalAlign::Keyword(VerticalAlignKeyword::Baseline)
}
}
diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs
index c90c270c59f..7b2c5a34648 100644
--- a/components/style/values/specified/box.rs
+++ b/components/style/values/specified/box.rs
@@ -10,7 +10,7 @@ use crate::properties::{LonghandId, PropertyDeclarationId, PropertyFlags};
use crate::properties::{PropertyId, ShorthandId};
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use crate::values::generics::box_::Perspective as GenericPerspective;
-use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign;
+use crate::values::generics::box_::{GenericVerticalAlign, VerticalAlignKeyword};
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
use crate::values::specified::{AllowQuirks, Number};
use crate::values::{CustomIdent, KeyframesName};
@@ -280,20 +280,7 @@ impl Parse for VerticalAlign {
return Ok(GenericVerticalAlign::Length(lp));
}
- try_match_ident_ignore_ascii_case! { input,
- "baseline" => Ok(GenericVerticalAlign::Baseline),
- "sub" => Ok(GenericVerticalAlign::Sub),
- "super" => Ok(GenericVerticalAlign::Super),
- "top" => Ok(GenericVerticalAlign::Top),
- "text-top" => Ok(GenericVerticalAlign::TextTop),
- "middle" => Ok(GenericVerticalAlign::Middle),
- "bottom" => Ok(GenericVerticalAlign::Bottom),
- "text-bottom" => Ok(GenericVerticalAlign::TextBottom),
- #[cfg(feature = "gecko")]
- "-moz-middle-with-baseline" => {
- Ok(GenericVerticalAlign::MozMiddleWithBaseline)
- },
- }
+ Ok(GenericVerticalAlign::Keyword(VerticalAlignKeyword::parse(input)?))
}
}
diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs
index bf4c5b288e1..7f1b438ea24 100644
--- a/components/style/values/specified/text.rs
+++ b/components/style/values/specified/text.rs
@@ -563,8 +563,7 @@ pub enum TextAlignKeyword {
}
/// Specified value of text-align property.
-#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
-#[derive(Clone, Copy, Debug, Eq, Hash, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
+#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
pub enum TextAlign {
/// Keyword value of text-align property.
Keyword(TextAlignKeyword),