Skip to content

Commit

Permalink
style: Use consistent naming and shared code for out-of-flow stuff.
Browse files Browse the repository at this point in the history
Use the functions introduced in ee17eed.
  • Loading branch information
emilio committed Oct 7, 2019
1 parent 0b5aaef commit 6b674a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
5 changes: 1 addition & 4 deletions components/style/properties/longhands/box.mako.rs
Expand Up @@ -53,10 +53,7 @@ ${helpers.single_keyword(
>
impl computed_value::T {
pub fn is_absolutely_positioned(self) -> bool {
match self {
Self::Absolute | Self::Fixed => true,
_ => false,
}
matches!(self, Self::Absolute | Self::Fixed)
}
}
</%helpers:single_keyword>
Expand Down
12 changes: 5 additions & 7 deletions components/style/properties/properties.mako.rs
Expand Up @@ -3694,16 +3694,14 @@ impl<'a> StyleBuilder<'a> {
<% del style_struct %>

/// Returns whether this computed style represents a floated object.
pub fn floated(&self) -> bool {
self.get_box().clone_float() != longhands::float::computed_value::T::None
pub fn is_floating(&self) -> bool {
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.
pub fn out_of_flow_positioned(&self) -> bool {
use crate::properties::longhands::position::computed_value::T as Position;
matches!(self.get_box().clone_position(),
Position::Absolute | Position::Fixed)
pub fn is_absolutely_positioned(&self) -> bool {
self.get_box().clone_position().is_absolutely_positioned()
}

/// Whether this style has a top-layer style.
Expand Down
12 changes: 6 additions & 6 deletions components/style/style_adjuster.rs
Expand Up @@ -145,7 +145,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// computed to 'absolute' if the element is in a top layer.
///
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);
}
}
Expand All @@ -156,7 +156,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// value of 'float' is 'none'.
///
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);
}
}
Expand Down Expand Up @@ -205,8 +205,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {

let is_item_or_root = blockify;

blockify_if!(self.style.floated());
blockify_if!(self.style.out_of_flow_positioned());
blockify_if!(self.style.is_floating());
blockify_if!(self.style.is_absolutely_positioned());
#[cfg(any(feature = "servo-layout-2013", feature = "gecko"))]
blockify_if!(
self.style.pseudo.map_or(false, |p| p.is_marker()) &&
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
use crate::computed_values::align_self::T as AlignSelf;

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() {
AlignItems::Stretch => AlignSelf::Stretch,
Expand Down Expand Up @@ -556,7 +556,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
#[cfg(feature = "gecko")]
fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool {
// 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;
}
let parent_display = layout_parent_style.get_box().clone_display();
Expand Down

0 comments on commit 6b674a6

Please sign in to comment.