blob: fbad7e71257fdb107558daabd582aeb59c34050d [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/layout/ng/layout_ng_block_flow.h"
#include "core/layout/LayoutAnalyzer.h"
#include "core/layout/ng/ng_constraint_space.h"
#include "core/layout/ng/ng_fragment.h"
#include "core/layout/ng/ng_layout_result.h"
#include "core/layout/ng/ng_length_utils.h"
namespace blink {
LayoutNGBlockFlow::LayoutNGBlockFlow(Element* element)
: LayoutBlockFlow(element) {}
bool LayoutNGBlockFlow::IsOfType(LayoutObjectType type) const {
return type == kLayoutObjectNGBlockFlow || LayoutBlockFlow::IsOfType(type);
}
void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) {
LayoutAnalyzer::BlockScope analyzer(*this);
RefPtr<NGConstraintSpace> constraint_space =
NGConstraintSpace::CreateFromLayoutObject(*this);
RefPtr<NGLayoutResult> result =
NGBlockNode(this).Layout(constraint_space.Get());
if (IsOutOfFlowPositioned()) {
// In legacy layout, abspos differs from regular blocks in that abspos
// blocks position themselves in their own layout, instead of getting
// positioned by their parent. So it we are a positioned block in a legacy-
// layout containing block, we have to emulate this positioning.
// Additionally, until we natively support abspos in LayoutNG, this code
// will also be reached though the layoutPositionedObjects call in
// NGBlockNode::CopyFragmentDataToLayoutBox.
LogicalExtentComputedValues computed_values;
ComputeLogicalWidth(computed_values);
SetLogicalLeft(computed_values.position_);
ComputeLogicalHeight(LogicalHeight(), LogicalTop(), computed_values);
SetLogicalTop(computed_values.position_);
}
// We need to update our margins as these are calculated once and stored in
// LayoutBox::margin_box_outsets_. Typically this happens within
// UpdateLogicalWidth and UpdateLogicalHeight.
//
// This primarily fixes cases where we are embedded inside another layout,
// for example LayoutView, LayoutFlexibleBox, etc.
UpdateMargins(*constraint_space);
for (NGOutOfFlowPositionedDescendant descendant :
result->OutOfFlowPositionedDescendants())
descendant.node.UseOldOutOfFlowPositioning();
}
void LayoutNGBlockFlow::UpdateMargins(
const NGConstraintSpace& constraint_space) {
NGBoxStrut margins =
ComputeMargins(constraint_space, StyleRef(),
constraint_space.WritingMode(), StyleRef().Direction());
SetMarginBefore(margins.block_start);
SetMarginAfter(margins.block_end);
SetMarginStart(margins.inline_start);
SetMarginEnd(margins.inline_end);
}
NGInlineNodeData& LayoutNGBlockFlow::GetNGInlineNodeData() const {
DCHECK(ng_inline_node_data_);
return *ng_inline_node_data_.get();
}
void LayoutNGBlockFlow::ResetNGInlineNodeData() {
ng_inline_node_data_ = WTF::MakeUnique<NGInlineNodeData>();
}
int LayoutNGBlockFlow::FirstLineBoxBaseline() const {
// TODO(kojii): Implement. This will stop working once we stop creating line
// boxes.
return LayoutBlockFlow::FirstLineBoxBaseline();
}
int LayoutNGBlockFlow::InlineBlockBaseline(
LineDirectionMode line_direction) const {
// TODO(kojii): Implement. This will stop working once we stop creating line
// boxes.
return LayoutBlockFlow::InlineBlockBaseline(line_direction);
}
} // namespace blink