Commit ed669ecd authored by eae's avatar eae Committed by Commit bot

[LayoutNG] Replace use of NGPhysicalFragment top/left/width/height

Replace uses of the individual Top, Left, Width, and Height accessors in
NGPhysicalFragment with Offset and Size respectively to reduce API size,
improve compiler enforcement of logical & physical, and reduce code size.

R=ikilpatrick@chromium.org

Review-Url: https://codereview.chromium.org/2885053003
Cr-Commit-Position: refs/heads/master@{#472235}
parent 885a5dea
......@@ -99,9 +99,9 @@ TEST_F(NGInlineLayoutAlgorithmTest, VerticalAlignBottomReplaced) {
ToNGPhysicalBoxFragment(layout_result->PhysicalFragment().Get());
EXPECT_EQ(1u, wrapper->Children().size());
auto* line = ToNGPhysicalLineBoxFragment(wrapper->Children()[0].Get());
EXPECT_EQ(LayoutUnit(96), line->Height());
EXPECT_EQ(LayoutUnit(96), line->Size().height);
auto* img = line->Children()[0].Get();
EXPECT_EQ(LayoutUnit(0), img->TopOffset());
EXPECT_EQ(LayoutUnit(0), img->Offset().top);
}
// Verifies that text can flow correctly around floats that were positioned
......@@ -167,18 +167,18 @@ TEST_F(NGInlineLayoutAlgorithmTest, TextFloatsAroundFloatsBefore) {
auto* text_fragment1 = text_fragments[0];
// 40 = #left-float1' width 30 + #left-float2 10
EXPECT_EQ(LayoutUnit(40), text_fragment1->LeftOffset());
EXPECT_EQ(LayoutUnit(40), text_fragment1->Offset().left);
InlineTextBox* inline_text_box1 = layout_text->FirstTextBox();
EXPECT_EQ(LayoutUnit(40), inline_text_box1->X());
auto* text_fragment2 = text_fragments[1];
// 40 = #left-float1' width 30
EXPECT_EQ(LayoutUnit(30), text_fragment2->LeftOffset());
EXPECT_EQ(LayoutUnit(30), text_fragment2->Offset().left);
InlineTextBox* inline_text_box2 = inline_text_box1->NextTextBox();
EXPECT_EQ(LayoutUnit(30), inline_text_box2->X());
auto* text_fragment3 = text_fragments[2];
EXPECT_EQ(LayoutUnit(), text_fragment3->LeftOffset());
EXPECT_EQ(LayoutUnit(), text_fragment3->Offset().left);
InlineTextBox* inline_text_box3 = inline_text_box2->NextTextBox();
EXPECT_EQ(LayoutUnit(), inline_text_box3->X());
}
......
......@@ -54,12 +54,12 @@ void FragmentPositionUpdated(const NGPhysicalFragment& fragment) {
LayoutBlock* containing_block = layout_box->ContainingBlock();
if (containing_block->StyleRef().IsFlippedBlocksWritingMode()) {
LayoutUnit container_width = containing_block->Size().Width();
layout_box->SetX(container_width - fragment.LeftOffset() -
fragment.Width());
layout_box->SetX(container_width - fragment.Offset().left -
fragment.Size().width);
} else {
layout_box->SetX(fragment.LeftOffset());
layout_box->SetX(fragment.Offset().left);
}
layout_box->SetY(fragment.TopOffset());
layout_box->SetY(fragment.Offset().top);
}
// Similar to FragmentPositionUpdated but for floats.
......@@ -92,20 +92,20 @@ void UpdateLegacyMultiColumnFlowThread(LayoutBox* layout_box,
if (!flow_thread)
return;
if (LayoutMultiColumnSet* column_set = flow_thread->FirstMultiColumnSet()) {
column_set->SetWidth(fragment->Width());
column_set->SetHeight(fragment->Height());
column_set->SetWidth(fragment->Size().width);
column_set->SetHeight(fragment->Size().height);
// TODO(mstensho): This value has next to nothing to do with the flow thread
// portion size, but at least it's usually better than zero.
column_set->EndFlow(fragment->Height());
column_set->EndFlow(fragment->Size().height);
column_set->ClearNeedsLayout();
}
// TODO(mstensho): Fix the relatively nonsensical values here (the content box
// size of the multicol container has very little to do with the price of
// eggs).
flow_thread->SetWidth(fragment->Width());
flow_thread->SetHeight(fragment->Height());
flow_thread->SetWidth(fragment->Size().width);
flow_thread->SetHeight(fragment->Size().height);
flow_thread->ValidateColumnSets();
flow_thread->ClearNeedsLayout();
......@@ -268,8 +268,8 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
if (layout_box_->Style()->SpecifiesColumns())
UpdateLegacyMultiColumnFlowThread(layout_box_, fragment);
layout_box_->SetWidth(fragment->Width());
layout_box_->SetHeight(fragment->Height());
layout_box_->SetWidth(fragment->Size().width);
layout_box_->SetHeight(fragment->Size().height);
NGBoxStrut border_and_padding = ComputeBorders(constraint_space, Style()) +
ComputePadding(constraint_space, Style());
LayoutUnit intrinsic_logical_height =
......
......@@ -7,25 +7,27 @@
namespace blink {
LayoutUnit NGFragment::InlineSize() const {
return writing_mode_ == kHorizontalTopBottom ? physical_fragment_->Width()
: physical_fragment_->Height();
return writing_mode_ == kHorizontalTopBottom
? physical_fragment_->Size().width
: physical_fragment_->Size().height;
}
LayoutUnit NGFragment::BlockSize() const {
return writing_mode_ == kHorizontalTopBottom ? physical_fragment_->Height()
: physical_fragment_->Width();
return writing_mode_ == kHorizontalTopBottom
? physical_fragment_->Size().height
: physical_fragment_->Size().width;
}
LayoutUnit NGFragment::InlineOffset() const {
return writing_mode_ == kHorizontalTopBottom
? physical_fragment_->LeftOffset()
: physical_fragment_->TopOffset();
? physical_fragment_->Offset().left
: physical_fragment_->Offset().top;
}
LayoutUnit NGFragment::BlockOffset() const {
return writing_mode_ == kHorizontalTopBottom
? physical_fragment_->TopOffset()
: physical_fragment_->LeftOffset();
? physical_fragment_->Offset().top
: physical_fragment_->Offset().left;
}
NGPhysicalFragment::NGFragmentType NGFragment::Type() const {
......
......@@ -58,40 +58,27 @@ class CORE_EXPORT NGPhysicalFragment : public RefCounted<NGPhysicalFragment> {
// Returns the border-box size.
NGPhysicalSize Size() const { return size_; }
LayoutUnit Width() const { return size_.width; }
LayoutUnit Height() const { return size_.height; }
// Returns the offset relative to the parent fragment's content-box.
LayoutUnit LeftOffset() const {
DCHECK(is_placed_);
return offset_.left;
}
LayoutUnit TopOffset() const {
DCHECK(is_placed_);
return offset_.top;
}
NGPhysicalOffset Offset() const {
DCHECK(is_placed_);
return offset_;
}
// Should only be used by the parent fragment's layout.
void SetOffset(NGPhysicalOffset offset) {
DCHECK(!is_placed_);
offset_ = offset;
is_placed_ = true;
}
NGBreakToken* BreakToken() const { return break_token_.Get(); }
const ComputedStyle& Style() const;
// GetLayoutObject should only be used when necessary for compatibility
// with LegacyLayout.
LayoutObject* GetLayoutObject() const { return layout_object_; }
// Should only be used by the parent fragment's layout.
void SetOffset(NGPhysicalOffset offset) {
DCHECK(!is_placed_);
offset_ = offset;
is_placed_ = true;
}
bool IsPlaced() const { return is_placed_; }
String ToString() const;
......
......@@ -24,7 +24,7 @@ struct CORE_EXPORT NGPositionedFloat {
// In the case where a legacy FloatingObject is attached to not its own
// parent, e.g. a float surrounded by a bunch of nested empty divs,
// NG float fragment's LeftOffset() cannot be used as legacy FloatingObject's
// NG float fragment's left offset cannot be used as legacy FloatingObject's
// left offset because that offset should be relative to the original float
// parent.
// {@code paint_offset} is calculated when we know to which parent this float
......
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