Commit 5c161d39 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Add BoxType to distinguish different box fragments

Bug: 591099
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: I2f6d01a6351b07d8bc93ad016858f49f549cf89c
Reviewed-on: https://chromium-review.googlesource.com/722383
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509687}
parent 7df0afaf
......@@ -41,6 +41,23 @@ bool AppendFragmentOffsetAndSize(const NGPhysicalFragment* fragment,
return has_content;
}
String StringForBoxType(NGPhysicalFragment::NGBoxType box_type) {
switch (box_type) {
case NGPhysicalFragment::NGBoxType::kNormalBox:
return String();
case NGPhysicalFragment::NGBoxType::kInlineBlock:
return "inline-block";
case NGPhysicalFragment::NGBoxType::kFloating:
return "floating";
case NGPhysicalFragment::NGBoxType::kOutOfFlowPositioned:
return "out-of-flow-positioned";
case NGPhysicalFragment::NGBoxType::kAnonymousBox:
return "anonymous";
}
NOTREACHED();
return String();
}
void AppendFragmentToString(const NGPhysicalFragment* fragment,
StringBuilder* builder,
NGPhysicalFragment::DumpFlags flags,
......@@ -54,6 +71,12 @@ void AppendFragmentToString(const NGPhysicalFragment* fragment,
if (fragment->IsBox()) {
if (flags & NGPhysicalFragment::DumpType) {
builder->Append("Box");
String box_type = StringForBoxType(fragment->BoxType());
if (!box_type.IsEmpty()) {
builder->Append(" (");
builder->Append(box_type);
builder->Append(")");
}
has_content = true;
}
has_content =
......@@ -170,6 +193,43 @@ Node* NGPhysicalFragment::GetNode() const {
return layout_object_ ? layout_object_->GetNode() : nullptr;
}
// TODO(kojii): This series of Is*() functions rely on LayoutObject for now, but
// should be set by fragment builder.
bool NGPhysicalFragment::IsInlineBlock() const {
return layout_object_ && layout_object_->IsAtomicInlineLevel();
}
bool NGPhysicalFragment::IsFloating() const {
return layout_object_ && layout_object_->IsFloating();
}
bool NGPhysicalFragment::IsOutOfFlowPositioned() const {
return layout_object_ && layout_object_->IsOutOfFlowPositioned();
}
bool NGPhysicalFragment::IsAnonymousBox() const {
return !layout_object_ || layout_object_->Style() != style_.get();
}
bool NGPhysicalFragment::IsBlockLayoutRoot() const {
if (IsAnonymousBox())
return false;
return layout_object_->IsAtomicInlineLevel() ||
layout_object_->IsFloatingOrOutOfFlowPositioned();
}
NGPhysicalFragment::NGBoxType NGPhysicalFragment::BoxType() const {
if (IsInlineBlock())
return NGPhysicalFragment::NGBoxType::kInlineBlock;
if (IsFloating())
return NGPhysicalFragment::NGBoxType::kFloating;
if (IsOutOfFlowPositioned())
return NGPhysicalFragment::NGBoxType::kOutOfFlowPositioned;
if (IsAnonymousBox())
return NGPhysicalFragment::NGBoxType::kAnonymousBox;
return NGPhysicalFragment::NGBoxType::kNormalBox;
}
NGPixelSnappedPhysicalBoxStrut NGPhysicalFragment::BorderWidths() const {
unsigned edges = BorderEdges();
NGPhysicalBoxStrut box_strut(
......@@ -232,9 +292,10 @@ RefPtr<NGPhysicalFragment> NGPhysicalFragment::CloneWithoutOffset() const {
}
String NGPhysicalFragment::ToString() const {
return String::Format("Type: '%d' Size: '%s' Offset: '%s' Placed: '%d'",
Type(), Size().ToString().Ascii().data(),
Offset().ToString().Ascii().data(), IsPlaced());
return String::Format(
"Type: '%d' Size: '%s' Offset: '%s' Placed: '%d', BoxType: '%s'", Type(),
Size().ToString().Ascii().data(), Offset().ToString().Ascii().data(),
IsPlaced(), StringForBoxType(BoxType()).Ascii().data());
}
String NGPhysicalFragment::DumpFragmentTree(DumpFlags flags) const {
......
......@@ -47,6 +47,13 @@ class CORE_EXPORT NGPhysicalFragment
// When adding new values, make sure the bit size of |type_| is large
// enough to store.
};
enum NGBoxType {
kNormalBox,
kInlineBlock,
kFloating,
kOutOfFlowPositioned,
kAnonymousBox
};
~NGPhysicalFragment();
......@@ -59,6 +66,21 @@ class CORE_EXPORT NGPhysicalFragment
bool IsText() const { return Type() == NGFragmentType::kFragmentText; }
bool IsLineBox() const { return Type() == NGFragmentType::kFragmentLineBox; }
// Returns the box type of this fragment.
NGBoxType BoxType() const;
// An inline block is represented as a kFragmentBox.
// TODO(eae): This isn't true for replaces elements at the moment.
bool IsInlineBlock() const;
bool IsFloating() const;
bool IsOutOfFlowPositioned() const;
// A box fragment that do not exist in LayoutObject tree. Its LayoutObject is
// co-owned by other fragments.
bool IsAnonymousBox() const;
// A block sub-layout starts on this fragment. Inline blocks, floats, out of
// flow positioned objects are such examples. This may be false on NG/legacy
// boundary.
bool IsBlockLayoutRoot() const;
// The accessors in this class shouldn't be used by layout code directly,
// instead should be accessed by the NGFragmentBase classes. These accessors
// exist for paint, hit-testing, etc.
......
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