aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/block.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout/block.rs')
-rw-r--r--components/layout/block.rs58
1 files changed, 23 insertions, 35 deletions
diff --git a/components/layout/block.rs b/components/layout/block.rs
index 45de8786778..f7370e00a4e 100644
--- a/components/layout/block.rs
+++ b/components/layout/block.rs
@@ -42,12 +42,11 @@ use flow::IS_ABSOLUTELY_POSITIONED;
use flow_list::FlowList;
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow};
use fragment::{IS_INLINE_FLEX_ITEM, IS_BLOCK_FLEX_ITEM};
-use fragment::SpecificFragmentInfo;
use gfx::display_list::{ClippingRegion, StackingContext};
use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree;
use layout_debug;
-use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
+use model::{AdjoiningMargins, CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
use model::{specified, specified_or_none};
use sequential;
use serde::{Serialize, Serializer};
@@ -56,13 +55,12 @@ use std::fmt;
use std::sync::Arc;
use style::computed_values::{border_collapse, box_sizing, display, float, overflow_x, overflow_y};
use style::computed_values::{position, text_align};
-use style::context::{SharedStyleContext, StyleContext};
+use style::context::SharedStyleContext;
use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::ServoComputedValues;
use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPOSITION};
use style::values::computed::{LengthOrPercentageOrNone, LengthOrPercentage};
use style::values::computed::LengthOrPercentageOrAuto;
-use util::clamp;
/// Information specific to floated blocks.
#[derive(Clone, Serialize)]
@@ -555,7 +553,7 @@ impl BlockFlow {
/// relevant margins for this Block.
pub fn block_type(&self) -> BlockType {
if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) {
- if self.is_replaced_content() {
+ if self.fragment.is_replaced() {
BlockType::AbsoluteReplaced
} else {
BlockType::AbsoluteNonReplaced
@@ -563,19 +561,19 @@ impl BlockFlow {
} else if self.is_inline_flex_item() {
BlockType::InlineFlexItem
} else if self.base.flags.is_float() {
- if self.is_replaced_content() {
+ if self.fragment.is_replaced() {
BlockType::FloatReplaced
} else {
BlockType::FloatNonReplaced
}
} else if self.is_inline_block() {
- if self.is_replaced_content() {
+ if self.fragment.is_replaced() {
BlockType::InlineBlockReplaced
} else {
BlockType::InlineBlockNonReplaced
}
} else {
- if self.is_replaced_content() {
+ if self.fragment.is_replaced() {
BlockType::Replaced
} else {
BlockType::NonReplaced
@@ -668,22 +666,6 @@ impl BlockFlow {
}
}
- /// Return true if this has a replaced fragment.
- ///
- /// Text, Images, Inline Block and Canvas
- /// (https://html.spec.whatwg.org/multipage/#replaced-elements) fragments are considered as
- /// replaced fragments.
- fn is_replaced_content(&self) -> bool {
- match self.fragment.specific {
- SpecificFragmentInfo::ScannedText(_) |
- SpecificFragmentInfo::Svg(_) |
- SpecificFragmentInfo::Image(_) |
- SpecificFragmentInfo::Canvas(_) |
- SpecificFragmentInfo::InlineBlock(_) => true,
- _ => false,
- }
- }
-
/// Return shrink-to-fit inline-size.
///
/// This is where we use the preferred inline-sizes and minimum inline-sizes
@@ -1267,11 +1249,11 @@ impl BlockFlow {
let available_block_size = containing_block_block_size -
self.fragment.border_padding.block_start_end();
- if self.is_replaced_content() {
+ if self.fragment.is_replaced() {
// Calculate used value of block-size just like we do for inline replaced elements.
// TODO: Pass in the containing block block-size when Fragment's
// assign-block-size can handle it correctly.
- self.fragment.assign_replaced_block_size_if_necessary(Some(containing_block_block_size));
+ self.fragment.assign_replaced_block_size_if_necessary();
// TODO: Right now, this content block-size value includes the
// margin because of erroneous block-size calculation in fragment.
// Check this when that has been fixed.
@@ -1551,7 +1533,7 @@ impl BlockFlow {
size + self.fragment.border_padding.inline_start_end(),
}
} else {
- clamp(min_inline_size, available_inline_size, max_inline_size)
+ max(min_inline_size, min(available_inline_size, max_inline_size))
};
self.base.position.size.inline = inline_size + self.fragment.margin.inline_start_end();
@@ -1896,16 +1878,22 @@ impl Flow for BlockFlow {
fn fragment(&mut self, layout_context: &LayoutContext,
fragmentation_context: Option<FragmentationContext>)
-> Option<Arc<Flow>> {
- if self.is_replaced_content() {
+ if self.fragment.is_replaced() {
let _scope = layout_debug_scope!("assign_replaced_block_size_if_necessary {:x}",
self.base.debug_id());
// Assign block-size for fragment if it is an image fragment.
- let containing_block_block_size =
- self.base.block_container_explicit_block_size;
- self.fragment.assign_replaced_block_size_if_necessary(containing_block_block_size);
+ self.fragment.assign_replaced_block_size_if_necessary();
if !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) {
self.base.position.size.block = self.fragment.border_box.size.block;
+ let mut block_start = AdjoiningMargins::from_margin(self.fragment.margin.block_start);
+ let block_end = AdjoiningMargins::from_margin(self.fragment.margin.block_end);
+ if self.fragment.border_box.size.block == Au(0) {
+ block_start.union(block_end);
+ self.base.collapsible_margins = CollapsibleMargins::CollapseThrough(block_start);
+ } else {
+ self.base.collapsible_margins = CollapsibleMargins::Collapse(block_start, block_end);
+ }
self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW);
self.fragment.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW);
}
@@ -2870,7 +2858,7 @@ impl ISizeAndMarginsComputer for AbsoluteReplaced {
fragment.assign_replaced_inline_size_if_necessary(containing_block_inline_size, container_block_size);
// For replaced absolute flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
- MaybeAuto::Specified(fragment.content_inline_size())
+ MaybeAuto::Specified(fragment.content_box().size.inline)
}
fn containing_block_inline_size(&self,
@@ -2929,7 +2917,7 @@ impl ISizeAndMarginsComputer for BlockReplaced {
fragment.assign_replaced_inline_size_if_necessary(parent_flow_inline_size, container_block_size);
// For replaced block flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
- MaybeAuto::Specified(fragment.content_inline_size())
+ MaybeAuto::Specified(fragment.content_box().size.inline)
}
}
@@ -2987,7 +2975,7 @@ impl ISizeAndMarginsComputer for FloatReplaced {
fragment.assign_replaced_inline_size_if_necessary(parent_flow_inline_size, container_block_size);
// For replaced block flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
- MaybeAuto::Specified(fragment.content_inline_size())
+ MaybeAuto::Specified(fragment.content_box().size.inline)
}
}
@@ -3075,7 +3063,7 @@ impl ISizeAndMarginsComputer for InlineBlockReplaced {
fragment.assign_replaced_inline_size_if_necessary(parent_flow_inline_size, container_block_size);
// For replaced block flow, the rest of the constraint solving will
// take inline-size to be specified as the value computed here.
- MaybeAuto::Specified(fragment.content_inline_size())
+ MaybeAuto::Specified(fragment.content_box().size.inline)
}
}