Use the is_absolute_containing_block method everywhere

This is a better approach than relying on
contains_positioned_fragments, because in the future other properties
will create absolute containing blocks.
This commit is contained in:
Martin Robinson 2017-08-16 13:32:48 +02:00
parent ee73cb618a
commit 0a24c2f03c
4 changed files with 17 additions and 28 deletions

View file

@ -1989,12 +1989,12 @@ impl Flow for BlockFlow {
// For relatively-positioned descendants, the containing block formed by a block is just // For relatively-positioned descendants, the containing block formed by a block is just
// the content box. The containing block for absolutely-positioned descendants, on the // the content box. The containing block for absolutely-positioned descendants, on the
// other hand, is only established if we are positioned. // other hand, is established in other circumstances (see `is_absolute_containing_block').
let relative_offset = let relative_offset =
self.fragment.relative_position(&self.base self.fragment.relative_position(&self.base
.early_absolute_position_info .early_absolute_position_info
.relative_containing_block_size); .relative_containing_block_size);
if self.contains_positioned_fragments() { if self.is_absolute_containing_block() {
let border_box_origin = (self.fragment.border_box - let border_box_origin = (self.fragment.border_box -
self.fragment.style.logical_border_width()).start; self.fragment.style.logical_border_width()).start;
self.base self.base
@ -2013,14 +2013,15 @@ impl Flow for BlockFlow {
logical_border_width.inline_start, logical_border_width.inline_start,
logical_border_width.block_start); logical_border_width.block_start);
let position = position.to_physical(self.base.writing_mode, container_size); let position = position.to_physical(self.base.writing_mode, container_size);
if self.contains_positioned_fragments() {
// Some blocks establish a stacking context, but not a containing block for
// absolutely positioned elements. An example of this might be a block that has
// `position: static` and `opacity` set. In these cases, absolutely-positioned
// children will not be positioned relative to us but will instead be positioned
// relative to our containing block.
if self.is_absolute_containing_block() {
position position
} else { } else {
// We establish a stacking context but are not positioned. (This will happen
// if, for example, the element has `position: static` but has `opacity` or
// `transform` set.) In this case, absolutely-positioned children will not be
// positioned relative to us but will instead be positioned relative to our
// containing block.
position - self.base.stacking_relative_position position - self.base.stacking_relative_position
} }
} else { } else {
@ -2105,10 +2106,6 @@ impl Flow for BlockFlow {
(self.fragment.border_box - self.fragment.style().logical_border_width()).size (self.fragment.border_box - self.fragment.style().logical_border_width()).size
} }
fn is_absolute_containing_block(&self) -> bool {
self.contains_positioned_fragments()
}
fn update_late_computed_inline_position_if_necessary(&mut self, inline_position: Au) { fn update_late_computed_inline_position_if_necessary(&mut self, inline_position: Au) {
if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) &&
self.fragment.style().logical_position().inline_start == self.fragment.style().logical_position().inline_start ==

View file

@ -616,14 +616,12 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
flow.finish(); flow.finish();
// Set up the absolute descendants. // Set up the absolute descendants.
let contains_positioned_fragments = flow.contains_positioned_fragments(); if flow.is_absolute_containing_block() {
let is_absolutely_positioned = flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED);
if contains_positioned_fragments {
// This is the containing block for all the absolute descendants. // This is the containing block for all the absolute descendants.
flow.set_absolute_descendants(abs_descendants); flow.set_absolute_descendants(abs_descendants);
abs_descendants = AbsoluteDescendants::new(); abs_descendants = AbsoluteDescendants::new();
if is_absolutely_positioned { if flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED) {
// This is now the only absolute flow in the subtree which hasn't yet // This is now the only absolute flow in the subtree which hasn't yet
// reached its CB. // reached its CB.
abs_descendants.push(flow.clone()); abs_descendants.push(flow.clone());
@ -1060,16 +1058,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
// The flow is done. // The flow is done.
flow.finish(); flow.finish();
let contains_positioned_fragments = flow.contains_positioned_fragments(); if flow.is_absolute_containing_block() {
if contains_positioned_fragments {
// This is the containing block for all the absolute descendants. // This is the containing block for all the absolute descendants.
flow.set_absolute_descendants(abs_descendants); flow.set_absolute_descendants(abs_descendants);
abs_descendants = AbsoluteDescendants::new(); abs_descendants = AbsoluteDescendants::new();
let is_absolutely_positioned = if flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED) {
flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED);
if is_absolutely_positioned {
// This is now the only absolute flow in the subtree which hasn't yet // This is now the only absolute flow in the subtree which hasn't yet
// reached its containing block. // reached its containing block.
abs_descendants.push(flow.clone()); abs_descendants.push(flow.clone());
@ -1134,16 +1129,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
legalizer.finish(&mut wrapper_flow); legalizer.finish(&mut wrapper_flow);
wrapper_flow.finish(); wrapper_flow.finish();
let contains_positioned_fragments = wrapper_flow.contains_positioned_fragments(); if wrapper_flow.is_absolute_containing_block() {
if contains_positioned_fragments {
// This is the containing block for all the absolute descendants. // This is the containing block for all the absolute descendants.
wrapper_flow.set_absolute_descendants(abs_descendants); wrapper_flow.set_absolute_descendants(abs_descendants);
abs_descendants = AbsoluteDescendants::new(); abs_descendants = AbsoluteDescendants::new();
let is_absolutely_positioned = if flow::base(&*wrapper_flow).flags.contains(IS_ABSOLUTELY_POSITIONED) {
flow::base(&*wrapper_flow).flags.contains(IS_ABSOLUTELY_POSITIONED);
if is_absolutely_positioned {
// This is now the only absolute flow in the subtree which hasn't yet // This is now the only absolute flow in the subtree which hasn't yet
// reached its containing block. // reached its containing block.
abs_descendants.push(wrapper_flow.clone()); abs_descendants.push(wrapper_flow.clone());

View file

@ -404,7 +404,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
/// Returns true if this is an absolute containing block. /// Returns true if this is an absolute containing block.
fn is_absolute_containing_block(&self) -> bool { fn is_absolute_containing_block(&self) -> bool {
false self.contains_positioned_fragments()
} }
/// Updates the inline position of a child flow during the assign-height traversal. At present, /// Updates the inline position of a child flow during the assign-height traversal. At present,

View file

@ -1486,7 +1486,7 @@ impl Flow for InlineFlow {
indentation = Au(0) indentation = Au(0)
} }
if self.contains_positioned_fragments() { if self.is_absolute_containing_block() {
// Assign block-sizes for all flows in this absolute flow tree. // Assign block-sizes for all flows in this absolute flow tree.
// This is preorder because the block-size of an absolute flow may depend on // This is preorder because the block-size of an absolute flow may depend on
// the block-size of its containing block, which may also be an absolute flow. // the block-size of its containing block, which may also be an absolute flow.