Commit cd477bac authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Implement LayoutText::AbsoluteRects

Another round to port InlineTextBox code to LayoutNG.

This function is used by Slider and testing/internals.

Bug: 636993
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: Iac2bbb59f49b02aeb0fd2e95cda5477a9160c444
Reviewed-on: https://chromium-review.googlesource.com/981574Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546244}
parent 4b486f54
...@@ -325,6 +325,31 @@ String LayoutText::PlainText() const { ...@@ -325,6 +325,31 @@ String LayoutText::PlainText() const {
void LayoutText::AbsoluteRects(Vector<IntRect>& rects, void LayoutText::AbsoluteRects(Vector<IntRect>& rects,
const LayoutPoint& accumulated_offset) const { const LayoutPoint& accumulated_offset) const {
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
auto fragments = NGPaintFragment::InlineFragmentsFor(this);
if (fragments.IsInLayoutNGInlineFormattingContext()) {
Vector<LayoutRect, 32> layout_rects;
for (const NGPaintFragment* fragment : fragments) {
layout_rects.push_back(
LayoutRect(fragment->InlineOffsetToContainerBox().ToLayoutPoint(),
fragment->Size().ToLayoutSize()));
}
// |rect| is in flipped block physical coordinate, but LayoutNG is in
// physical coordinate. Flip if needed.
if (UNLIKELY(HasFlippedBlocksWritingMode())) {
LayoutBlock* block = ContainingBlock();
DCHECK(block);
for (LayoutRect& rect : layout_rects)
block->FlipForWritingMode(rect);
}
for (LayoutRect& rect : layout_rects) {
rect.MoveBy(accumulated_offset);
rects.push_back(EnclosingIntRect(rect));
}
return;
}
}
for (InlineTextBox* box : TextBoxes()) { for (InlineTextBox* box : TextBoxes()) {
rects.push_back(EnclosingIntRect(LayoutRect( rects.push_back(EnclosingIntRect(LayoutRect(
LayoutPoint(accumulated_offset) + box->Location(), box->Size()))); LayoutPoint(accumulated_offset) + box->Location(), box->Size())));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "core/testing/CoreUnitTestHelper.h" #include "core/testing/CoreUnitTestHelper.h"
#include "platform/runtime_enabled_features.h" #include "platform/runtime_enabled_features.h"
#include "platform/testing/runtime_enabled_features_test_helpers.h" #include "platform/testing/runtime_enabled_features_test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace blink { namespace blink {
...@@ -428,6 +429,44 @@ TEST_P(ParameterizedLayoutTextTest, GetUpperLeftCornerVLR) { ...@@ -428,6 +429,44 @@ TEST_P(ParameterizedLayoutTextTest, GetUpperLeftCornerVLR) {
EXPECT_EQ(FloatPoint(10, 30), upper_left.value()); EXPECT_EQ(FloatPoint(10, 30), upper_left.value());
} }
TEST_P(ParameterizedLayoutTextTest, AbsoluteRects) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<style>
div {
font: 10px/1 Ahem;
width: 5em;
}
</style>
<div>012<span id=target>345 67</span></div>
)HTML");
LayoutText* layout_text = GetLayoutTextById("target");
Vector<IntRect> rects;
layout_text->AbsoluteRects(rects, {LayoutUnit(100), LayoutUnit(200)});
EXPECT_THAT(rects, testing::ElementsAre(IntRect(130, 200, 30, 10),
IntRect(100, 210, 20, 10)));
}
TEST_P(ParameterizedLayoutTextTest, AbsoluteRectsVRL) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<style>
div {
font: 10px/1 Ahem;
width: 10em;
height: 5em;
writing-mode: vertical-rl;
}
</style>
<div>012<span id=target>345 67</span></div>
)HTML");
LayoutText* layout_text = GetLayoutTextById("target");
Vector<IntRect> rects;
layout_text->AbsoluteRects(rects, {LayoutUnit(100), LayoutUnit(200)});
EXPECT_THAT(rects, testing::ElementsAre(IntRect(100, 230, 10, 30),
IntRect(110, 200, 10, 20)));
}
TEST_P(ParameterizedLayoutTextTest, LinesBoundingBox) { TEST_P(ParameterizedLayoutTextTest, LinesBoundingBox) {
LoadAhem(); LoadAhem();
SetBasicBody( SetBasicBody(
......
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