Commit 310ca88e authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make NGAbstractInlineTextBox::GetText() to include a collapsed space at soft line wrap

This patch changes |NGAbstractInlineTextBox::GetText()| to include a collapsed
space when it is collapsed by soft line wrap.

This patch fixes unit test failure of
DumpAccessibilityTreeTest.AccessibilityInputTypes.

Change-Id: Ic17caddde97295adf3dd8c56826dd37c8c194371
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1609003
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658986}
parent 7da20dc3
...@@ -1974,6 +1974,7 @@ jumbo_source_set("unit_tests") { ...@@ -1974,6 +1974,7 @@ jumbo_source_set("unit_tests") {
"layout/layout_text_test.cc", "layout/layout_text_test.cc",
"layout/layout_theme_test.cc", "layout/layout_theme_test.cc",
"layout/layout_view_test.cc", "layout/layout_view_test.cc",
"layout/line/abstract_inline_text_box_test.cc",
"layout/line/inline_text_box_test.cc", "layout/line/inline_text_box_test.cc",
"layout/line/line_orientation_utils_test.cc", "layout/line/line_orientation_utils_test.cc",
"layout/map_coordinates_test.cc", "layout/map_coordinates_test.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/layout/line/abstract_inline_text_box.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
namespace blink {
class AbstractInlineTextBoxTest : public testing::WithParamInterface<bool>,
private ScopedLayoutNGForTest,
public RenderingTest {
public:
AbstractInlineTextBoxTest() : ScopedLayoutNGForTest(GetParam()) {}
protected:
bool LayoutNGEnabled() const { return GetParam(); }
};
INSTANTIATE_TEST_SUITE_P(All, AbstractInlineTextBoxTest, testing::Bool());
TEST_P(AbstractInlineTextBoxTest, GetTextWithTrailingWhiteSpace) {
SetBodyInnerHTML(R"HTML(
<style>* { font-size: 10px; }</style>
<div style="width: 10ch"><label id=label>abc: <input></label></div>)HTML");
const Element& label = *GetDocument().getElementById("label");
LayoutText& layout_text =
*ToLayoutText(label.firstChild()->GetLayoutObject());
scoped_refptr<AbstractInlineTextBox> inline_text_box =
layout_text.FirstAbstractInlineTextBox();
EXPECT_EQ("abc: ", inline_text_box->GetText());
}
} // namespace blink
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_abstract_inline_text_box.h"
#include "third_party/blink/renderer/core/accessibility/ax_object_cache.h" #include "third_party/blink/renderer/core/accessibility/ax_object_cache.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h" #include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
...@@ -68,12 +69,6 @@ void NGAbstractInlineTextBox::Detach() { ...@@ -68,12 +69,6 @@ void NGAbstractInlineTextBox::Detach() {
fragment_ = nullptr; fragment_ = nullptr;
} }
bool NGAbstractInlineTextBox::HasSoftWrapToNextLine() const {
return To<NGPhysicalLineBoxFragment>(
fragment_->ContainerLineBox()->PhysicalFragment())
.HasSoftWrapToNextLine();
}
const NGPhysicalTextFragment& NGAbstractInlineTextBox::PhysicalTextFragment() const NGPhysicalTextFragment& NGAbstractInlineTextBox::PhysicalTextFragment()
const { const {
return To<NGPhysicalTextFragment>(fragment_->PhysicalFragment()); return To<NGPhysicalTextFragment>(fragment_->PhysicalFragment());
...@@ -84,13 +79,22 @@ bool NGAbstractInlineTextBox::NeedsLayout() const { ...@@ -84,13 +79,22 @@ bool NGAbstractInlineTextBox::NeedsLayout() const {
} }
bool NGAbstractInlineTextBox::NeedsTrailingSpace() const { bool NGAbstractInlineTextBox::NeedsTrailingSpace() const {
if (!HasSoftWrapToNextLine()) if (!fragment_->Style().CollapseWhiteSpace())
return false; return false;
const NGPaintFragment* next_fragment = NextTextFragmentForSameLayoutObject(); const NGPaintFragment& line_box = *fragment_->ContainerLineBox();
if (!next_fragment) if (!To<NGPhysicalLineBoxFragment>(line_box.PhysicalFragment())
.HasSoftWrapToNextLine())
return false;
const NGPhysicalTextFragment& text_fragment = PhysicalTextFragment();
if (text_fragment.EndOffset() >= text_fragment.TextContent().length())
return false;
if (text_fragment.TextContent()[text_fragment.EndOffset()] != ' ')
return false; return false;
return To<NGPhysicalTextFragment>(next_fragment->PhysicalFragment()) const NGInlineBreakToken& break_token =
.StartOffset() != PhysicalTextFragment().EndOffset(); *To<NGInlineBreakToken>(line_box.PhysicalFragment().BreakToken());
// TODO(yosin): We should support OOF fragments between |fragment_| and
// break token.
return break_token.TextOffset() == text_fragment.EndOffset() + 1;
} }
const NGPaintFragment* const NGPaintFragment*
......
...@@ -32,7 +32,6 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox { ...@@ -32,7 +32,6 @@ class CORE_EXPORT NGAbstractInlineTextBox final : public AbstractInlineTextBox {
NGAbstractInlineTextBox(LineLayoutText line_layout_item, NGAbstractInlineTextBox(LineLayoutText line_layout_item,
const NGPaintFragment& fragment); const NGPaintFragment& fragment);
bool HasSoftWrapToNextLine() const;
const NGPhysicalTextFragment& PhysicalTextFragment() const; const NGPhysicalTextFragment& PhysicalTextFragment() const;
bool NeedsLayout() const; bool NeedsLayout() const;
bool NeedsTrailingSpace() const; bool NeedsTrailingSpace() const;
......
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