Commit e59817eb authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

[LayoutNG] Adapt LayoutInline::LinesBoundingBox() to work with fragments

This patch makes |LayoutInline::LinesBoundingBox()| to work with LayoutNG by
utilizing |NGInlineFragmentIterator| to collect box fragments associated to
|LayoutInline|.

This patch also changes |ShouldCreateBoxFragment()| to return |true| for
producing box fragements for plain SPAN to avoid using "culled inline box",
which is collected by traversing descendants of layout tree.

Note: Exclude master.tryserver.chromium.linux:linux_layout_tests_layout_ng

Bug: 591099
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: Ia71db55d551a8ee8e5e36019ab94e7fb18479198
Reviewed-on: https://chromium-review.googlesource.com/768599
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521017}
parent 036d62e6
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "core/layout/LayoutView.h" #include "core/layout/LayoutView.h"
#include "core/layout/api/LineLayoutBoxModel.h" #include "core/layout/api/LineLayoutBoxModel.h"
#include "core/layout/line/InlineTextBox.h" #include "core/layout/line/InlineTextBox.h"
#include "core/layout/ng/inline/ng_inline_fragment_iterator.h"
#include "core/layout/ng/layout_ng_block_flow.h" #include "core/layout/ng/layout_ng_block_flow.h"
#include "core/paint/BoxPainter.h" #include "core/paint/BoxPainter.h"
#include "core/paint/InlinePainter.h" #include "core/paint/InlinePainter.h"
...@@ -45,6 +46,19 @@ ...@@ -45,6 +46,19 @@
namespace blink { namespace blink {
namespace {
// TODO(layout-dev): Once we generate fragment for all inline element, we should
// use |LayoutObject::EnclosingBlockFlowFragment()|.
const NGPhysicalBoxFragment* EnclosingBlockFlowFragmentOf(
const LayoutInline& node) {
if (!RuntimeEnabledFeatures::LayoutNGPaintFragmentsEnabled())
return nullptr;
return node.EnclosingBlockFlowFragment();
}
} // anonymous namespace
struct SameSizeAsLayoutInline : public LayoutBoxModelObject { struct SameSizeAsLayoutInline : public LayoutBoxModelObject {
~SameSizeAsLayoutInline() override {} ~SameSizeAsLayoutInline() override {}
LayoutObjectChildList children_; LayoutObjectChildList children_;
...@@ -953,6 +967,19 @@ class LinesBoundingBoxGeneratorContext { ...@@ -953,6 +967,19 @@ class LinesBoundingBoxGeneratorContext {
} // unnamed namespace } // unnamed namespace
LayoutRect LayoutInline::LinesBoundingBox() const { LayoutRect LayoutInline::LinesBoundingBox() const {
if (const NGPhysicalBoxFragment* box_fragment =
EnclosingBlockFlowFragmentOf(*this)) {
LayoutRect result;
NGInlineFragmentIterator children(*box_fragment, this);
for (const auto& child : children) {
NGPhysicalOffset left_top =
child.fragment->Offset() + child.offset_to_container_box;
result.Unite(LayoutRect(LayoutPoint(left_top.left, left_top.top),
child.fragment->Size().ToLayoutSize()));
}
return result;
}
if (!AlwaysCreateLineBoxes()) { if (!AlwaysCreateLineBoxes()) {
DCHECK(!FirstLineBox()); DCHECK(!FirstLineBox());
FloatRect float_result; FloatRect float_result;
......
...@@ -6,12 +6,63 @@ ...@@ -6,12 +6,63 @@
#include "core/layout/LayoutBlockFlow.h" #include "core/layout/LayoutBlockFlow.h"
#include "core/layout/LayoutTestHelper.h" #include "core/layout/LayoutTestHelper.h"
#include "platform/runtime_enabled_features.h"
#include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace blink { namespace blink {
class LayoutInlineTest : public RenderingTest {}; class LayoutInlineTest : public RenderingTest {};
// Helper class to run the same test code with and without LayoutNG
class ParameterizedLayoutInlineTest
: public ::testing::WithParamInterface<bool>,
private ScopedLayoutNGForTest,
private ScopedLayoutNGPaintFragmentsForTest,
public LayoutInlineTest {
public:
ParameterizedLayoutInlineTest()
: ScopedLayoutNGForTest(GetParam()),
ScopedLayoutNGPaintFragmentsForTest(GetParam()) {}
protected:
bool LayoutNGEnabled() const { return GetParam(); }
};
INSTANTIATE_TEST_CASE_P(All, ParameterizedLayoutInlineTest, ::testing::Bool());
TEST_P(ParameterizedLayoutInlineTest, LinesBoundingBox) {
LoadAhem();
SetBodyInnerHTML(
"<style>"
"* { font-family: Ahem; font-size: 13px; }"
".vertical { writing-mode: vertical-rl; }"
"</style>"
"<p><span id=ltr1>abc<br>xyz</span></p>"
"<p><span id=ltr2>12 345 6789</span></p>"
"<p dir=rtl><span id=rtl1>abc<br>xyz</span></p>"
"<p dir=rtl><span id=rtl2>12 345 6789</span></p>"
"<p class=vertical><span id=vertical>abc<br>xyz</span></p>");
EXPECT_EQ(
LayoutRect(LayoutPoint(0, 0), LayoutSize(39, 26)),
ToLayoutInline(GetLayoutObjectByElementId("ltr1"))->LinesBoundingBox());
EXPECT_EQ(
LayoutRect(LayoutPoint(0, 0), LayoutSize(143, 13)),
ToLayoutInline(GetLayoutObjectByElementId("ltr2"))->LinesBoundingBox());
EXPECT_EQ(
LayoutRect(LayoutPoint(745, 0), LayoutSize(39, 26)),
ToLayoutInline(GetLayoutObjectByElementId("rtl1"))->LinesBoundingBox());
// TODO(layout-dev): LayoutNG should have same LayoutRect of legacy.
// See http://crbug.com/785687
EXPECT_EQ(
LayoutNGEnabled() ? LayoutRect(LayoutPoint(745, 0), LayoutSize(65, 13))
: LayoutRect(LayoutPoint(641, 0), LayoutSize(143, 13)),
ToLayoutInline(GetLayoutObjectByElementId("rtl2"))->LinesBoundingBox());
EXPECT_EQ(LayoutRect(LayoutPoint(0, 0), LayoutSize(26, 39)),
ToLayoutInline(GetLayoutObjectByElementId("vertical"))
->LinesBoundingBox());
}
TEST_F(LayoutInlineTest, SimpleContinuation) { TEST_F(LayoutInlineTest, SimpleContinuation) {
SetBodyInnerHTML( SetBodyInnerHTML(
"<span id='splitInline'><i id='before'></i><h1 id='blockChild'></h1><i " "<span id='splitInline'><i id='before'></i><h1 id='blockChild'></h1><i "
......
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