Commit 1e0cb518 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Implement LayoutText::GetUpperLeftCorner

This patch implements LayoutText::GetUpperLeftCorner for LayoutNG.

Spartial navigation, scroll to anchor, Inspector, and some others
use this function.

The existing code for legacy was incorrect for vertical flow as
callers expect physical with flipped block, and the code uses
LineTop (logical top) as physical Y. This patch includes the fix
and a unit test.

This is another step to port InlineBox code to LayoutNG, started
when Aleks hit a bug by unported code.

Bug: 636993
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_layout_ng;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I658a58fd8bd5582d51e973bf97e3a4e97107603e
Reviewed-on: https://chromium-review.googlesource.com/981332Reviewed-by: default avatarAleks Totic <atotic@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546129}
parent c1c039e4
......@@ -1240,13 +1240,11 @@ crbug.com/714962 fast/dom/Range/getBoundingClientRect-linebreak-character.html [
crbug.com/591099 fast/dom/Window/property-access-on-cached-window-after-frame-navigated.html [ Timeout ]
crbug.com/591099 fast/dom/Window/window-lookup-precedence.html [ Timeout ]
crbug.com/591099 fast/dom/Window/window-postmessage-clone-deep-array.html [ Failure ]
crbug.com/714962 fast/dom/anchor-without-content.html [ Failure ]
crbug.com/591099 fast/dom/clone-node-dynamic-style.html [ Failure ]
crbug.com/591099 fast/dom/domstring-attribute-reflection.html [ Timeout ]
crbug.com/591099 fast/dom/element-attribute-js-null.html [ Timeout ]
crbug.com/714962 fast/dom/elementFromPoint-relative-to-viewport.html [ Failure ]
crbug.com/714962 fast/dom/elementsFromPoint/elementsFromPoint-inline.html [ Failure ]
crbug.com/714962 fast/dom/empty-anchor-in-overflow-scroller.html [ Failure ]
crbug.com/714962 fast/dom/inert/inert-inlines.html [ Failure ]
crbug.com/591099 fast/dom/inner-text-first-letter.html [ Failure ]
crbug.com/591099 fast/dom/nodesFromRect/nodesFromRect-basic.html [ Failure ]
......@@ -1530,25 +1528,9 @@ crbug.com/591099 fast/shapes/shape-outside-floats/shape-outside-relative-size-sv
crbug.com/591099 fast/shapes/shape-outside-floats/shape-outside-rounded-boxes-001.html [ Failure ]
crbug.com/591099 fast/shapes/shape-outside-floats/shape-outside-rounded-boxes-002.html [ Failure ]
crbug.com/591099 fast/shapes/shape-outside-floats/shape-outside-rounded-inset.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-date.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-fully-aligned-horizontally.html [ Failure ]
crbug.com/591099 fast/spatial-navigation/snav-fully-aligned-vertically.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-iframe-nested.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-iframe-no-focusable-content.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-iframe-no-scrollable-content.html [ Failure ]
crbug.com/591099 fast/spatial-navigation/snav-iframe-with-offscreen-focusable-element.html [ Failure ]
crbug.com/591099 fast/spatial-navigation/snav-iframe-with-outside-focusable-element.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-input.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-multiple-select.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-radio-group.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-radio.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-single-select-list.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-single-select.html [ Timeout ]
crbug.com/591099 fast/spatial-navigation/snav-stay-in-overflow-div.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-table-traversal.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-textarea.html [ Failure ]
crbug.com/714962 fast/spatial-navigation/snav-tiny-table-traversal.html [ Failure ]
crbug.com/591099 fast/spatial-navigation/snav-use-visual-viewport.html [ Failure ]
crbug.com/591099 fast/sub-pixel/computedstylemargin.html [ Failure ]
crbug.com/591099 fast/sub-pixel/inline-block-with-padding.html [ Failure ]
crbug.com/591099 fast/sub-pixel/sub-pixel-border-2.html [ Failure ]
......
......@@ -265,11 +265,26 @@ void LayoutText::DeleteTextBoxes() {
Optional<FloatPoint> LayoutText::GetUpperLeftCorner() const {
DCHECK(!IsBR());
// TODO(layoutng) Implement GetUpperLeftCorner for layoutng
if (!HasLegacyTextBoxes())
return WTF::nullopt;
return FloatPoint(LinesBoundingBox().X(),
FirstTextBox()->Root().LineTop().ToFloat());
if (HasLegacyTextBoxes()) {
if (StyleRef().IsHorizontalWritingMode()) {
return FloatPoint(LinesBoundingBox().X(),
FirstTextBox()->Root().LineTop().ToFloat());
}
return FloatPoint(FirstTextBox()->Root().LineTop().ToFloat(),
LinesBoundingBox().Y());
}
auto fragments = NGPaintFragment::InlineFragmentsFor(this);
if (!fragments.IsEmpty()) {
const NGPaintFragment* line_box = fragments.begin()->ContainerLineBox();
DCHECK(line_box);
if (StyleRef().IsHorizontalWritingMode()) {
return FloatPoint(LinesBoundingBox().X(),
line_box->InlineOffsetToContainerBox().top.ToFloat());
}
return FloatPoint(line_box->InlineOffsetToContainerBox().left.ToFloat(),
LinesBoundingBox().Y());
}
return WTF::nullopt;
}
bool LayoutText::HasTextBoxes() const {
......
......@@ -198,8 +198,8 @@ class CORE_EXPORT LayoutText : public LayoutObject {
InlineTextBox* FirstTextBox() const { return text_boxes_.First(); }
InlineTextBox* LastTextBox() const { return text_boxes_.Last(); }
// Returns upper left corner point in local coordinate if this object has
// rendered text.
// Returns upper left corner point in local physical coordinates with flipped
// block-flow direction if this object has rendered text.
Optional<FloatPoint> GetUpperLeftCorner() const;
// True if we have inline text box children which implies rendered text (or
......
......@@ -393,6 +393,41 @@ TEST_P(ParameterizedLayoutTextTest, IsBeforeAfterNonCollapsedCharacterBR) {
EXPECT_TRUE(GetBasicText()->IsAfterNonCollapsedCharacter(1));
}
TEST_P(ParameterizedLayoutTextTest, GetUpperLeftCorner) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<style>
div {
font: 10px/1 Ahem;
width: 5em;
}
</style>
<div>12345 123<span id="target">45</span></div>
)HTML");
LayoutText* layout_text = GetLayoutTextById("target");
Optional<FloatPoint> upper_left = layout_text->GetUpperLeftCorner();
EXPECT_TRUE(upper_left.has_value());
EXPECT_EQ(FloatPoint(30, 10), upper_left.value());
}
TEST_P(ParameterizedLayoutTextTest, GetUpperLeftCornerVLR) {
LoadAhem();
SetBodyInnerHTML(R"HTML(
<style>
div {
font: 10px/1 Ahem;
height: 5em;
writing-mode: vertical-lr;
}
</style>
<div>12345 123<span id="target">45</span></div>
)HTML");
LayoutText* layout_text = GetLayoutTextById("target");
Optional<FloatPoint> upper_left = layout_text->GetUpperLeftCorner();
EXPECT_TRUE(upper_left.has_value());
EXPECT_EQ(FloatPoint(10, 30), upper_left.value());
}
TEST_P(ParameterizedLayoutTextTest, LinesBoundingBox) {
LoadAhem();
SetBasicBody(
......
......@@ -113,6 +113,8 @@ class CORE_EXPORT NGPaintFragment : public DisplayItemClient,
return is_in_layout_ng_inline_formatting_context_;
}
bool IsEmpty() const { return !first_; }
class iterator {
public:
explicit iterator(NGPaintFragment* first) : current_(first) {}
......
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