blob: 9c25b24660c515ad6fc3fa4562aa5892f717d2ba [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"
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);
// TODO(layout-dev): This should be created in the constructor once instead.
// There is some internal state which needs to be cleared between layout
// passes (probably FirstChild(), etc).
box_ = new NGBlockNode(this);
RefPtr<NGLayoutResult> result = box_->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_);
}
for (auto& descendant : result->OutOfFlowDescendants())
descendant->UseOldOutOfFlowPositioning();
UpdateAfterLayout();
ClearNeedsLayout();
}
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>();
}
} // namespace blink