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

Make Element#innerText to not collapse white space around inline-block

This patch makes |Element#innerText| not to collapse white space around inline-
block for improving interop.

Note: The spec doesn't explicitly mention about this.

Changes of AX test expectations added missing space after <input>.

TBR=dmazzoni@chromium.org

Bug: 890020
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I74a47fd5ba3a22ff17d9c36838a81b4277ac47cc
Reviewed-on: https://chromium-review.googlesource.com/c/1250825Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596485}
parent eccc6f0f
rootWebArea
++genericContainer editable multiline richlyEditable value='A contenteditable with a link and an and a.<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' editableRoot=true
++genericContainer editable multiline richlyEditable value='A contenteditable with a link and an and a .<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' editableRoot=true
++++paragraph editable richlyEditable
++++++staticText editable richlyEditable name='A contenteditable with a '
++++++++inlineTextBox name='A contenteditable with a '
......
AXWebArea
++AXTextArea AXValue='A contenteditable with a link and an and a.
++AXTextArea AXValue='A contenteditable with a link and an and a .
Always expose editable tables as tables.
Editable list item.
'
......
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE ia2_hypertext='<obj0><obj1><obj2>' n_selections=0
++IA2_ROLE_SECTION value='A contenteditable with a link and an and a.<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' FOCUSABLE IA2_STATE_EDITABLE IA2_STATE_MULTI_LINE ia2_hypertext='<obj0><obj1><obj2>' n_selections=0
++IA2_ROLE_SECTION value='A contenteditable with a link and an and a .<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' FOCUSABLE IA2_STATE_EDITABLE IA2_STATE_MULTI_LINE ia2_hypertext='<obj0><obj1><obj2>' n_selections=0
++++IA2_ROLE_PARAGRAPH IA2_STATE_EDITABLE ia2_hypertext='A contenteditable with a <obj1> and an <obj3> and a <obj5>.' n_selections=0
++++++ROLE_SYSTEM_STATICTEXT name='A contenteditable with a ' IA2_STATE_EDITABLE ia2_hypertext='A contenteditable with a ' n_selections=0
++++++ROLE_SYSTEM_LINK name='link' LINKED IA2_STATE_EDITABLE ia2_hypertext='link' n_selections=0
......
rootWebArea
++genericContainer editable multiline richlyEditable value='A contenteditable with a link and an and a.<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' editableRoot=true
++genericContainer editable multiline richlyEditable value='A contenteditable with a link and an and a .<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' editableRoot=true
++++paragraph editable richlyEditable
++++++staticText editable richlyEditable name='A contenteditable with a ' TreeData.textSelStartOffset=0
++++++++inlineTextBox name='A contenteditable with a '
......
AXWebArea
++AXTextArea AXValue='A contenteditable with a link and an and a.
++AXTextArea AXValue='A contenteditable with a link and an and a .
Always expose editable tables as tables.
Editable list item.'
++++AXGroup
......
ROLE_SYSTEM_DOCUMENT READONLY FOCUSABLE ia2_hypertext='<obj0>' caret_offset=1 n_selections=1 selection_start=0 selection_end=1
++IA2_ROLE_SECTION value='A contenteditable with a link and an and a.<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' FOCUSABLE IA2_STATE_EDITABLE IA2_STATE_MULTI_LINE ia2_hypertext='<obj0><obj1><obj2>' caret_offset=3 n_selections=1 selection_start=0 selection_end=3
++IA2_ROLE_SECTION value='A contenteditable with a link and an and a .<newline><newline>Always expose editable tables as tables.<newline>Editable list item.' FOCUSABLE IA2_STATE_EDITABLE IA2_STATE_MULTI_LINE ia2_hypertext='<obj0><obj1><obj2>' caret_offset=3 n_selections=1 selection_start=0 selection_end=3
++++IA2_ROLE_PARAGRAPH IA2_STATE_EDITABLE ia2_hypertext='A contenteditable with a <obj1> and an <obj3> and a <obj5>.' n_selections=1 selection_start=0 selection_end=44
++++++ROLE_SYSTEM_STATICTEXT name='A contenteditable with a ' IA2_STATE_EDITABLE ia2_hypertext='A contenteditable with a ' n_selections=1 selection_start=0 selection_end=25
++++++ROLE_SYSTEM_LINK name='link' LINKED IA2_STATE_EDITABLE ia2_hypertext='link' n_selections=1 selection_start=0 selection_end=4
......
This is a testharness.js-based test.
Found 214 tests; 211 PASS, 3 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 217 tests; 214 PASS, 3 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Simplest possible test ("<div>abc")
PASS Leading whitespace removed ("<div> abc")
PASS Trailing whitespace removed ("<div>abc ")
......@@ -36,6 +36,9 @@ PASS \t converted to space ("<div style='white-space:pre-line'>abc\tdef")
PASS Whitespace collapses across element boundaries ("<div><span>abc </span> def")
PASS Whitespace collapses across element boundaries ("<div><span>abc </span><span></span> def")
PASS Whitespace collapses across element boundaries ("<div><span>abc </span><span style='white-space:pre'></span> def")
PASS Whitespace around <input> should not be collapsed ("<div>abc <input> def")
PASS Whitespace around inline-block should not be collapsed ("<div>abc <span style='display:inline-block'></span> def")
PASS Trailing space at end of inline-block should be collapsed ("<div>abc <span style='display:inline-block'> def </span> ghi")
PASS Soft line breaks ignored ("<div style='width:0'>abc def")
PASS Whitespace text node preserved ("<div style='width:0'><span>abc</span> <span>def</span>")
FAIL ::first-line styles applied ("<div class='first-line-uppercase' style='width:0'>abc def") assert_equals: expected "ABC def" but got "abc def"
......
......@@ -52,6 +52,9 @@ testText("<div style='white-space:pre-line'>abc\tdef", "abc def", "\\t converted
testText("<div><span>abc </span> def", "abc def", "Whitespace collapses across element boundaries");
testText("<div><span>abc </span><span></span> def", "abc def", "Whitespace collapses across element boundaries");
testText("<div><span>abc </span><span style='white-space:pre'></span> def", "abc def", "Whitespace collapses across element boundaries");
testText("<div>abc <input> def", "abc def", "Whitespace around <input> should not be collapsed");
testText("<div>abc <span style='display:inline-block'></span> def", "abc def", "Whitespace around inline-block should not be collapsed");
testText("<div>abc <span style='display:inline-block'> def </span> ghi", "abc def ghi", "Trailing space at end of inline-block should be collapsed");
/**** Soft line breaks ****/
......
This is a testharness.js-based test.
Found 214 tests; 212 PASS, 2 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 217 tests; 215 PASS, 2 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS Simplest possible test ("<div>abc")
PASS Leading whitespace removed ("<div> abc")
PASS Trailing whitespace removed ("<div>abc ")
......@@ -36,6 +36,9 @@ PASS \t converted to space ("<div style='white-space:pre-line'>abc\tdef")
PASS Whitespace collapses across element boundaries ("<div><span>abc </span> def")
PASS Whitespace collapses across element boundaries ("<div><span>abc </span><span></span> def")
PASS Whitespace collapses across element boundaries ("<div><span>abc </span><span style='white-space:pre'></span> def")
PASS Whitespace around <input> should not be collapsed ("<div>abc <input> def")
PASS Whitespace around inline-block should not be collapsed ("<div>abc <span style='display:inline-block'></span> def")
PASS Trailing space at end of inline-block should be collapsed ("<div>abc <span style='display:inline-block'> def </span> ghi")
PASS Soft line breaks ignored ("<div style='width:0'>abc def")
PASS Whitespace text node preserved ("<div style='width:0'><span>abc</span> <span>def</span>")
PASS ::first-line styles applied ("<div class='first-line-uppercase' style='width:0'>abc def")
......
......@@ -56,15 +56,19 @@ class ElementInnerTextCollector final {
void EmitTab();
void EmitText(const StringView& text);
String Finish();
void FlushCollapsibleSpace();
bool HasCollapsibleSpace() const { return has_collapsible_space_; }
void SetShouldCollapseWhitespace(bool value) { at_start_of_block_ = value; }
private:
void FlushCollapsibleSpace();
void FlushRequiredLineBreak();
StringBuilder builder_;
int required_line_break_count_ = 0;
// TODO(yosin): We should rename |at_of_block_| to
// |should_collapse_white_space_|.
bool at_start_of_block_ = false;
bool has_collapsible_space_ = false;
......@@ -507,8 +511,15 @@ void ElementInnerTextCollector::ProcessNode(const Node& node) {
if (IsDisplayBlockLevel(node))
return ProcessChildrenWithRequiredLineBreaks(node, 1);
if (layout_object.IsLayoutBlock())
return ProcessChildrenWithRequiredLineBreaks(node, 0);
if (layout_object.IsLayoutBlock()) {
result_.FlushCollapsibleSpace();
ProcessChildrenWithRequiredLineBreaks(node, 0);
// We should not collapse white space after inline-block.
// e.g. abc <span style="display:inline-block"></span> def => "abc def".
// See http://crbug.com/890020
result_.SetShouldCollapseWhitespace(false);
return;
}
ProcessChildren(node);
}
......@@ -585,8 +596,6 @@ void ElementInnerTextCollector::ProcessTextNode(const Text& node) {
// ----
void ElementInnerTextCollector::Result::EmitBeginBlock() {
if (has_collapsible_space_)
return;
at_start_of_block_ = true;
}
......
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