Commit 01d0468d authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Enable DCHECK inside of NGConstraintSpace::CreateFromLayoutObject.

This also makes the function accept a LayoutBlock instead as well.

Unittests which call NGConstraintSpace::CreateFromLayoutObject on a LayoutObject
are updated to ensure that the LayoutObject is a new formatting context.

Should have no behaviour change.

Change-Id: Ibaeffaecd47b37474fc426f80b006592a3257de8
Reviewed-on: https://chromium-review.googlesource.com/c/1473393
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632815}
parent f1ee3203
...@@ -253,6 +253,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, MAYBE_VerticalAlignBottomReplaced) { ...@@ -253,6 +253,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, MAYBE_VerticalAlignBottomReplaced) {
<style> <style>
html { font-size: 10px; } html { font-size: 10px; }
img { vertical-align: bottom; } img { vertical-align: bottom; }
#container { display: flow-root; }
</style> </style>
<div id=container><img src="#" width="96" height="96"></div> <div id=container><img src="#" width="96" height="96"></div>
)HTML"); )HTML");
......
...@@ -34,11 +34,6 @@ bool LayoutNGBlockFlow::IsOfType(LayoutObjectType type) const { ...@@ -34,11 +34,6 @@ bool LayoutNGBlockFlow::IsOfType(LayoutObjectType type) const {
void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) { void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) {
LayoutAnalyzer::BlockScope analyzer(*this); LayoutAnalyzer::BlockScope analyzer(*this);
// This block is an entry-point from the legacy engine to LayoutNG. This means
// that we need to be at a formatting context boundary, since NG and legacy
// don't cooperate on e.g. margin collapsing.
DCHECK(CreatesNewFormattingContext());
if (IsOutOfFlowPositioned()) { if (IsOutOfFlowPositioned()) {
UpdateOutOfFlowBlockLayout(); UpdateOutOfFlowBlockLayout();
return; return;
......
...@@ -34,58 +34,52 @@ static_assert(sizeof(NGConstraintSpace) == sizeof(SameSizeAsNGConstraintSpace), ...@@ -34,58 +34,52 @@ static_assert(sizeof(NGConstraintSpace) == sizeof(SameSizeAsNGConstraintSpace),
} // namespace } // namespace
NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject( NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject(
const LayoutBox& box) { const LayoutBlock& block) {
const LayoutBlock* cb = box.ContainingBlock(); // We should only ever create a constraint space from legacy layout if the
// object is a new formatting context.
DCHECK(block.CreatesNewFormattingContext());
const LayoutBlock* cb = block.ContainingBlock();
LayoutUnit available_logical_width = LayoutUnit available_logical_width =
LayoutBoxUtils::AvailableLogicalWidth(box, cb); LayoutBoxUtils::AvailableLogicalWidth(block, cb);
LayoutUnit available_logical_height = LayoutUnit available_logical_height =
LayoutBoxUtils::AvailableLogicalHeight(box, cb); LayoutBoxUtils::AvailableLogicalHeight(block, cb);
NGLogicalSize percentage_size = {available_logical_width, NGLogicalSize percentage_size = {available_logical_width,
available_logical_height}; available_logical_height};
NGLogicalSize available_size = percentage_size; NGLogicalSize available_size = percentage_size;
bool fixed_inline = false, fixed_block = false; bool fixed_inline = false, fixed_block = false;
bool fixed_block_is_definite = true; bool fixed_block_is_definite = true;
if (box.HasOverrideLogicalWidth()) { if (block.HasOverrideLogicalWidth()) {
available_size.inline_size = box.OverrideLogicalWidth(); available_size.inline_size = block.OverrideLogicalWidth();
fixed_inline = true; fixed_inline = true;
} }
if (box.HasOverrideLogicalHeight()) { if (block.HasOverrideLogicalHeight()) {
available_size.block_size = box.OverrideLogicalHeight(); available_size.block_size = block.OverrideLogicalHeight();
fixed_block = true; fixed_block = true;
} }
if (box.IsFlexItem() && fixed_block) { if (block.IsFlexItem() && fixed_block) {
// The flexbox-specific behavior is in addition to regular definite-ness, so // The flexbox-specific behavior is in addition to regular definite-ness, so
// if the flex item would normally have a definite height it should keep it. // if the flex item would normally have a definite height it should keep it.
fixed_block_is_definite = fixed_block_is_definite =
ToLayoutFlexibleBox(box.Parent()) ToLayoutFlexibleBox(block.Parent())
->UseOverrideLogicalHeightForPerentageResolution(box) || ->UseOverrideLogicalHeightForPerentageResolution(block) ||
(box.IsLayoutBlock() && ToLayoutBlock(box).HasDefiniteLogicalHeight()); block.HasDefiniteLogicalHeight();
} }
bool is_new_fc = true; const ComputedStyle& style = block.StyleRef();
// TODO(ikilpatrick): This DCHECK needs to be enabled once we've switched auto writing_mode = style.GetWritingMode();
// LayoutTableCell, etc over to LayoutNG.
//
// We currently need to "force" LayoutNG roots to be formatting contexts so
// that floats have layout performed on them.
//
// DCHECK(is_new_fc,
// box.IsLayoutBlock() && ToLayoutBlock(box).CreatesNewFormattingContext());
auto writing_mode = box.StyleRef().GetWritingMode();
bool parallel_containing_block = IsParallelWritingMode( bool parallel_containing_block = IsParallelWritingMode(
cb ? cb->StyleRef().GetWritingMode() : writing_mode, writing_mode); cb ? cb->StyleRef().GetWritingMode() : writing_mode, writing_mode);
NGConstraintSpaceBuilder builder(writing_mode, writing_mode, is_new_fc, NGConstraintSpaceBuilder builder(writing_mode, writing_mode,
/* is_new_fc */ true,
!parallel_containing_block); !parallel_containing_block);
if (!box.IsWritingModeRoot() || box.IsGridItem()) { if (!block.IsWritingModeRoot() || block.IsGridItem()) {
// Add all types because we don't know which baselines will be requested. // Add all types because we don't know which baselines will be requested.
FontBaseline baseline_type = box.StyleRef().GetFontBaseline(); FontBaseline baseline_type = style.GetFontBaseline();
bool synthesize_inline_block_baseline = bool synthesize_inline_block_baseline =
box.IsLayoutBlock() && block.UseLogicalBottomMarginEdgeForInlineBlockBaseline();
ToLayoutBlock(box).UseLogicalBottomMarginEdgeForInlineBlockBaseline();
if (!synthesize_inline_block_baseline) { if (!synthesize_inline_block_baseline) {
builder.AddBaselineRequest( builder.AddBaselineRequest(
{NGBaselineAlgorithmType::kAtomicInline, baseline_type}); {NGBaselineAlgorithmType::kAtomicInline, baseline_type});
...@@ -100,8 +94,8 @@ NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject( ...@@ -100,8 +94,8 @@ NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject(
.SetIsFixedSizeBlock(fixed_block) .SetIsFixedSizeBlock(fixed_block)
.SetFixedSizeBlockIsDefinite(fixed_block_is_definite) .SetFixedSizeBlockIsDefinite(fixed_block_is_definite)
.SetIsShrinkToFit( .SetIsShrinkToFit(
box.SizesLogicalWidthToFitContent(box.StyleRef().LogicalWidth())) block.SizesLogicalWidthToFitContent(style.LogicalWidth()))
.SetTextDirection(box.StyleRef().Direction()) .SetTextDirection(style.Direction())
.ToConstraintSpace(); .ToConstraintSpace();
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace blink { namespace blink {
class LayoutBox; class LayoutBlock;
class NGConstraintSpaceBuilder; class NGConstraintSpaceBuilder;
enum NGFragmentationType { enum NGFragmentationType {
...@@ -136,7 +136,7 @@ class CORE_EXPORT NGConstraintSpace final { ...@@ -136,7 +136,7 @@ class CORE_EXPORT NGConstraintSpace final {
// Creates NGConstraintSpace representing LayoutObject's containing block. // Creates NGConstraintSpace representing LayoutObject's containing block.
// This should live on NGBlockNode or another layout bridge and probably take // This should live on NGBlockNode or another layout bridge and probably take
// a root NGConstraintSpace. // a root NGConstraintSpace.
static NGConstraintSpace CreateFromLayoutObject(const LayoutBox&); static NGConstraintSpace CreateFromLayoutObject(const LayoutBlock&);
const NGExclusionSpace& ExclusionSpace() const { return exclusion_space_; } const NGExclusionSpace& ExclusionSpace() const { return exclusion_space_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment