From b7238c43cd6899cb1530f8ece8d6d3f3c17e154d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 Jan 2018 10:41:59 +0100 Subject: [PATCH] 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. --- components/style/values/specified/align.rs | 46 +++++++++++----------- 1 file 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(&self, dest: &mut CssWriter) -> 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() { // 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() { // 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.