style: Use consistent naming and shared code for out-of-flow stuff.

Use the functions introduced in ee17eedf3a.
This commit is contained in:
Emilio Cobos Álvarez 2019-10-07 15:45:43 +02:00
parent 0b5aaeff5d
commit 6b674a670b
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
3 changed files with 12 additions and 17 deletions

View file

@ -53,10 +53,7 @@ ${helpers.single_keyword(
> >
impl computed_value::T { impl computed_value::T {
pub fn is_absolutely_positioned(self) -> bool { pub fn is_absolutely_positioned(self) -> bool {
match self { matches!(self, Self::Absolute | Self::Fixed)
Self::Absolute | Self::Fixed => true,
_ => false,
}
} }
} }
</%helpers:single_keyword> </%helpers:single_keyword>

View file

@ -3694,16 +3694,14 @@ impl<'a> StyleBuilder<'a> {
<% del style_struct %> <% del style_struct %>
/// Returns whether this computed style represents a floated object. /// Returns whether this computed style represents a floated object.
pub fn floated(&self) -> bool { pub fn is_floating(&self) -> bool {
self.get_box().clone_float() != longhands::float::computed_value::T::None self.get_box().clone_float().is_floating()
} }
/// Returns whether this computed style represents an out of flow-positioned /// Returns whether this computed style represents an absolutely-positioned
/// object. /// object.
pub fn out_of_flow_positioned(&self) -> bool { pub fn is_absolutely_positioned(&self) -> bool {
use crate::properties::longhands::position::computed_value::T as Position; self.get_box().clone_position().is_absolutely_positioned()
matches!(self.get_box().clone_position(),
Position::Absolute | Position::Fixed)
} }
/// Whether this style has a top-layer style. /// Whether this style has a top-layer style.

View file

@ -145,7 +145,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// computed to 'absolute' if the element is in a top layer. /// computed to 'absolute' if the element is in a top layer.
/// ///
fn adjust_for_top_layer(&mut self) { fn adjust_for_top_layer(&mut self) {
if !self.style.out_of_flow_positioned() && self.style.in_top_layer() { if !self.style.is_absolutely_positioned() && self.style.in_top_layer() {
self.style.mutate_box().set_position(Position::Absolute); self.style.mutate_box().set_position(Position::Absolute);
} }
} }
@ -156,7 +156,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// value of 'float' is 'none'. /// value of 'float' is 'none'.
/// ///
fn adjust_for_position(&mut self) { fn adjust_for_position(&mut self) {
if self.style.out_of_flow_positioned() && self.style.floated() { if self.style.is_absolutely_positioned() && self.style.is_floating() {
self.style.mutate_box().set_float(Float::None); self.style.mutate_box().set_float(Float::None);
} }
} }
@ -205,8 +205,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
let is_item_or_root = blockify; let is_item_or_root = blockify;
blockify_if!(self.style.floated()); blockify_if!(self.style.is_floating());
blockify_if!(self.style.out_of_flow_positioned()); blockify_if!(self.style.is_absolutely_positioned());
#[cfg(any(feature = "servo-layout-2013", feature = "gecko"))] #[cfg(any(feature = "servo-layout-2013", feature = "gecko"))]
blockify_if!( blockify_if!(
self.style.pseudo.map_or(false, |p| p.is_marker()) && self.style.pseudo.map_or(false, |p| p.is_marker()) &&
@ -375,7 +375,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
use crate::computed_values::align_self::T as AlignSelf; use crate::computed_values::align_self::T as AlignSelf;
if self.style.get_position().clone_align_self() == AlignSelf::Auto && if self.style.get_position().clone_align_self() == AlignSelf::Auto &&
!self.style.out_of_flow_positioned() !self.style.is_absolutely_positioned()
{ {
let self_align = match layout_parent_style.get_position().clone_align_items() { let self_align = match layout_parent_style.get_position().clone_align_items() {
AlignItems::Stretch => AlignSelf::Stretch, AlignItems::Stretch => AlignSelf::Stretch,
@ -556,7 +556,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool { fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool {
// Line break suppression should only be propagated to in-flow children. // Line break suppression should only be propagated to in-flow children.
if self.style.floated() || self.style.out_of_flow_positioned() { if self.style.is_floating() || self.style.is_absolutely_positioned() {
return false; return false;
} }
let parent_display = layout_parent_style.get_box().clone_display(); let parent_display = layout_parent_style.get_box().clone_display();