aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-01-29 10:41:59 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-01-29 10:45:13 +0100
commitb7238c43cd6899cb1530f8ece8d6d3f3c17e154d (patch)
tree3f66862db196ab2b85af214fb2fcd33692f3ba89 /components
parent8d7a3f4f3d4a93830d7c5b3010a35e5fc5455375 (diff)
downloadservo-b7238c43cd6899cb1530f8ece8d6d3f3c17e154d.tar.gz
servo-b7238c43cd6899cb1530f8ece8d6d3f3c17e154d.zip
style: Properly compare the value of the alignment flags.
What this did before happens to be ok for these constants, but it's not great, because it depends on their particular value.
Diffstat (limited to 'components')
-rw-r--r--components/style/values/specified/align.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/components/style/values/specified/align.rs b/components/style/values/specified/align.rs
index 8223928046e..9e8d49dfe00 100644
--- a/components/style/values/specified/align.rs
+++ b/components/style/values/specified/align.rs
@@ -69,6 +69,14 @@ bitflags! {
}
}
+impl AlignFlags {
+ /// Returns the enumeration value stored in the lower 5 bits.
+ #[inline]
+ fn value(&self) -> Self {
+ *self & !AlignFlags::FLAG_BITS
+ }
+}
+
impl ToCss for AlignFlags {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
@@ -81,7 +89,7 @@ impl ToCss for AlignFlags {
_ => {}
}
- dest.write_str(match *self & !AlignFlags::FLAG_BITS {
+ dest.write_str(match self.value() {
AlignFlags::AUTO => "auto",
AlignFlags::NORMAL => "normal",
AlignFlags::START => "start",
@@ -150,21 +158,17 @@ impl ContentDistribution {
/// Returns whether this value is valid for both axis directions.
pub fn is_valid_on_both_axes(&self) -> bool {
- if self.primary.contains(AlignFlags::BASELINE) ||
- self.primary.contains(AlignFlags::LAST_BASELINE)
- {
+ match self.primary.value() {
// <baseline-position> is only allowed on the block axis.
- return false;
- }
+ AlignFlags::BASELINE |
+ AlignFlags::LAST_BASELINE => false,
- if self.primary.contains(AlignFlags::LEFT) ||
- self.primary.contains(AlignFlags::RIGHT)
- {
// left | right are only allowed on the inline axis.
- return false;
- }
+ AlignFlags::LEFT |
+ AlignFlags::RIGHT => false,
- true
+ _ => true,
+ }
}
/// The primary alignment
@@ -297,21 +301,17 @@ impl SelfAlignment {
/// Returns whether this value is valid for both axis directions.
pub fn is_valid_on_both_axes(&self) -> bool {
- if self.0.contains(AlignFlags::BASELINE) ||
- self.0.contains(AlignFlags::LAST_BASELINE)
- {
+ match self.0.value() {
// <baseline-position> is only allowed on the block axis.
- return false;
- }
+ AlignFlags::BASELINE |
+ AlignFlags::LAST_BASELINE => false,
- if self.0.contains(AlignFlags::LEFT) ||
- self.0.contains(AlignFlags::RIGHT)
- {
// left | right are only allowed on the inline axis.
- return false;
- }
+ AlignFlags::LEFT |
+ AlignFlags::RIGHT => false,
- true
+ _ => true,
+ }
}
/// Whether this value has extra flags.