diff options
author | Ravi Shankar <wafflespeanut@gmail.com> | 2017-04-15 22:04:13 +0530 |
---|---|---|
committer | Ravi Shankar <wafflespeanut@gmail.com> | 2017-04-25 17:32:45 +0530 |
commit | 61a17993ebab00d8802bb60f431752791935d521 (patch) | |
tree | 2686989f371032259ba26f9f08686eaa57cb92ef /components/style/values/generics/position.rs | |
parent | 3f53fb148db3d4891e30ea2de71388b1ef9f42d2 (diff) | |
download | servo-61a17993ebab00d8802bb60f431752791935d521.tar.gz servo-61a17993ebab00d8802bb60f431752791935d521.zip |
Cleanup position and make use of generic Position for its users
Diffstat (limited to 'components/style/values/generics/position.rs')
-rw-r--r-- | components/style/values/generics/position.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/components/style/values/generics/position.rs b/components/style/values/generics/position.rs index 7ecfafdf356..d15198b638e 100644 --- a/components/style/values/generics/position.rs +++ b/components/style/values/generics/position.rs @@ -25,6 +25,52 @@ define_css_keyword_enum!{ Keyword: "y-end" => YEnd } +add_impls_for_keyword_enum!(Keyword); + +impl Keyword { + #[inline] + /// The defaults for position keywords are `left` and `top` (`x-start` and `y-start` for logical). + /// This method checks whether this keyword indicates their opposite sides. See the + /// `ToComputedValue` impl on `HorizontalPosition` and `VerticalPosition` for its use case. + pub fn is_other_side(&self) -> bool { + if self.is_horizontal() || self.is_logical_x() { + matches!(*self, Keyword::Right | Keyword::XEnd) + } else { + matches!(*self, Keyword::Bottom | Keyword::YEnd) + } + } + + #[inline] + /// Check whether this is a keyword for horizontal position. + pub fn is_horizontal(&self) -> bool { + matches!(*self, Keyword::Left | Keyword::Right) + } + + #[inline] + /// Check whether this is a keyword for vertical position. + pub fn is_vertical(&self) -> bool { + matches!(*self, Keyword::Top | Keyword::Bottom) + } + + #[inline] + /// Check whether this is a horizontal logical keyword. + pub fn is_logical_x(&self) -> bool { + matches!(*self, Keyword::XStart | Keyword::XEnd) + } + + #[inline] + /// Check whether this is a vertical logical keyword. + pub fn is_logical_y(&self) -> bool { + matches!(*self, Keyword::YStart | Keyword::YEnd) + } + + #[inline] + /// Check whether this is a logical keyword. + pub fn is_logical(&self) -> bool { + self.is_logical_x() || self.is_logical_y() + } +} + impl From<Keyword> for LengthOrPercentage { fn from(val: Keyword) -> LengthOrPercentage { match val { |