Commit 73a59b84 authored by tkent's avatar tkent Committed by Commit bot

Don't collapse whitespace in contenteditable=plaintext-only.

Rewrite white-space property for contenteditable=plaintext-only elements as:
    normal   -> pre-wrap
    nowrap   -> pre
    pre-line -> pre-wrap
because whitespace collapsing doesn't make sense in plain-text editing.
The new behavior matches to Microsoft Edge for TEXTAREA.

BUG=595491

Review URL: https://codereview.chromium.org/1813663002

Cr-Commit-Position: refs/heads/master@{#381668}
parent 73bd7ce8
...@@ -438,7 +438,8 @@ crbug.com/580355 virtual/spv2/fast/block/positioning/height-change.html [ Pass ] ...@@ -438,7 +438,8 @@ crbug.com/580355 virtual/spv2/fast/block/positioning/height-change.html [ Pass ]
crbug.com/580355 virtual/spv2/fast/block/positioning/relayout-on-position-change.html [ Pass ] crbug.com/580355 virtual/spv2/fast/block/positioning/relayout-on-position-change.html [ Pass ]
crbug.com/563667 virtual/spv2/fast/overflow/007.html [ Failure ] crbug.com/563667 virtual/spv2/fast/overflow/007.html [ Failure ]
crbug.com/595491 editing/pasteboard/8145-1.html [ NeedsRebaseline ]
crbug.com/595491 fast/forms/textarea/basic-textareas.html [ NeedsRebaseline ]
crbug.com/537409 virtual/spv2/fast/overflow [ Pass ] crbug.com/537409 virtual/spv2/fast/overflow [ Pass ]
# Sub-pixel differences in layout tests for SPv2 # Sub-pixel differences in layout tests for SPv2
crbug.com/589265 virtual/spv2/fast/block/float/002.html [ Failure ] crbug.com/589265 virtual/spv2/fast/block/float/002.html [ Failure ]
......
...@@ -24,8 +24,11 @@ Some text. ...@@ -24,8 +24,11 @@ Some text.
Some text. Some text.
Some text. Some text.
Some text. Some text.
Some text. Some text.
......
<!DOCTYPE html>
<textarea style="white-space:pre-wrap">a b </textarea>
<script>
var textarea = document.querySelector('textarea');
textarea.focus();
textarea.selectionStart = 4;
textarea.selectionEnd = 4;
</script>
<!DOCTYPE html>
<textarea style="white-space:normal"></textarea>
<script>
// We should be able to type ' ' into a TEXTAREA with white-space:normal,
// and the result should be identical to another TEXTAREA with
// white-space:pre-wrap.
document.querySelector('textarea').focus();
eventSender.keyDown('a')
eventSender.keyDown(' ')
eventSender.keyDown('b')
eventSender.keyDown(' ')
</script>
XThe test checks that we don't leave stale pointers into the internal grid representation. XThe test checks that we don't leave stale pointers into the internal grid representation.
This test has PASSED if it didn't crash under ASAN. This test has PASSED if it didn't crash under ASAN.
...@@ -9,7 +9,11 @@ layer at (0,0) size 800x600 ...@@ -9,7 +9,11 @@ layer at (0,0) size 800x600
LayoutBlockFlow {P} at (0,0) size 784x18 LayoutBlockFlow {P} at (0,0) size 784x18
LayoutText {#text} at (0,0) size 431x18 LayoutText {#text} at (0,0) size 431x18
text run at (0,0) width 431: "This is a replica of the paste that caused the crash covered by 8145." text run at (0,0) width 431: "This is a replica of the paste that caused the crash covered by 8145."
LayoutBlockFlow {DIV} at (0,34) size 784x20 [border: (1px solid #000000)] LayoutBlockFlow {DIV} at (0,34) size 784x38 [border: (1px solid #000000)]
LayoutText {#text} at (1,1) size 72x18 LayoutBlockFlow (anonymous) at (1,1) size 782x18
text run at (1,1) width 72: "foo bar baz" LayoutText {#text} at (0,0) size 72x18
caret: position 11 of child 0 {#text} of child 2 {DIV} of body text run at (0,0) width 72: "foo bar baz"
text run at (71,0) width 1: " "
LayoutBlockFlow {DIV} at (1,19) size 782x18
LayoutBR {BR} at (0,0) size 0x18
caret: position 0 of child 0 {BR} of child 1 {DIV} of child 2 {DIV} of body
...@@ -611,10 +611,11 @@ layer at (0,0) size 785x644 backgroundClip at (0,0) size 785x600 clip at (0,0) s ...@@ -611,10 +611,11 @@ layer at (0,0) size 785x644 backgroundClip at (0,0) size 785x600 clip at (0,0) s
LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)] LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
LayoutBlockFlow {DIV} at (3,3) size 120x65 LayoutBlockFlow {DIV} at (3,3) size 120x65
LayoutText {#text} at (0,0) size 120x65 LayoutText {#text} at (0,0) size 120x65
text run at (0,0) width 70: "Lorem ipsum " text run at (0,0) width 100: "Lorem ipsum dolor"
text run at (69,0) width 28: "dolor" text run at (99,0) width 4: " "
text run at (0,13) width 116: "ABCDEFGHIJKLMNOP" text run at (0,13) width 116: "ABCDEFGHIJKLMNOP"
text run at (0,26) width 78: "QRSTUVWXYZ" text run at (0,26) width 78: "QRSTUVWXYZ"
text run at (77,26) width 4: " "
text run at (0,39) width 120: "abcdefghijklmnopqrstu" text run at (0,39) width 120: "abcdefghijklmnopqrstu"
text run at (0,52) width 6: "v" text run at (0,52) width 6: "v"
layer at (144,500) size 141x32 clip at (145,501) size 124x15 scrollWidth 426 scrollHeight 17 layer at (144,500) size 141x32 clip at (145,501) size 124x15 scrollWidth 426 scrollHeight 17
...@@ -633,20 +634,20 @@ layer at (0,0) size 785x644 backgroundClip at (0,0) size 785x600 clip at (0,0) s ...@@ -633,20 +634,20 @@ layer at (0,0) size 785x644 backgroundClip at (0,0) size 785x600 clip at (0,0) s
text run at (77,26) width 4: " " text run at (77,26) width 4: " "
text run at (0,39) width 120: "abcdefghijklmnopqrstu" text run at (0,39) width 120: "abcdefghijklmnopqrstu"
text run at (0,52) width 6: "v" text run at (0,52) width 6: "v"
layer at (430,500) size 141x32 clip at (431,501) size 124x15 scrollWidth 423 scrollHeight 17 layer at (430,500) size 141x32 clip at (431,501) size 124x15 scrollWidth 426 scrollHeight 17
LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)] LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
LayoutBlockFlow {DIV} at (3,3) size 135x13 LayoutBlockFlow {DIV} at (3,3) size 135x13
LayoutText {#text} at (0,0) size 422x13 LayoutText {#text} at (0,0) size 425x13
text run at (0,0) width 70: "Lorem ipsum " text run at (0,0) width 425: "Lorem ipsum dolor ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuv"
text run at (69,0) width 353: "dolor ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuv"
layer at (573,500) size 141x32 clip at (574,501) size 124x30 scrollHeight 69 layer at (573,500) size 141x32 clip at (574,501) size 124x30 scrollHeight 69
LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)] LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
LayoutBlockFlow {DIV} at (3,3) size 120x65 LayoutBlockFlow {DIV} at (3,3) size 120x65
LayoutText {#text} at (0,0) size 120x65 LayoutText {#text} at (0,0) size 120x65
text run at (0,0) width 70: "Lorem ipsum " text run at (0,0) width 100: "Lorem ipsum dolor"
text run at (69,0) width 28: "dolor" text run at (99,0) width 4: " "
text run at (0,13) width 116: "ABCDEFGHIJKLMNOP" text run at (0,13) width 116: "ABCDEFGHIJKLMNOP"
text run at (0,26) width 78: "QRSTUVWXYZ" text run at (0,26) width 78: "QRSTUVWXYZ"
text run at (77,26) width 4: " "
text run at (0,39) width 120: "abcdefghijklmnopqrstu" text run at (0,39) width 120: "abcdefghijklmnopqrstu"
text run at (0,52) width 6: "v" text run at (0,52) width 6: "v"
layer at (1,593) size 141x47 clip at (2,594) size 124x30 scrollWidth 195 scrollHeight 43 layer at (1,593) size 141x47 clip at (2,594) size 124x30 scrollWidth 195 scrollHeight 43
...@@ -1338,10 +1339,11 @@ layer at (0,644) size 785x620 backgroundClip at (0,0) size 785x600 clip at (0,0) ...@@ -1338,10 +1339,11 @@ layer at (0,644) size 785x620 backgroundClip at (0,0) size 785x600 clip at (0,0)
LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)] LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
LayoutBlockFlow {DIV} at (3,3) size 120x65 LayoutBlockFlow {DIV} at (3,3) size 120x65
LayoutText {#text} at (0,0) size 120x65 LayoutText {#text} at (0,0) size 120x65
text run at (0,0) width 70: "Lorem ipsum " text run at (0,0) width 100: "Lorem ipsum dolor"
text run at (69,0) width 28: "dolor" text run at (99,0) width 4: " "
text run at (0,13) width 116: "ABCDEFGHIJKLMNOP" text run at (0,13) width 116: "ABCDEFGHIJKLMNOP"
text run at (0,26) width 78: "QRSTUVWXYZ" text run at (0,26) width 78: "QRSTUVWXYZ"
text run at (77,26) width 4: " "
text run at (0,39) width 120: "abcdefghijklmnopqrstu" text run at (0,39) width 120: "abcdefghijklmnopqrstu"
text run at (0,52) width 6: "v" text run at (0,52) width 6: "v"
layer at (144,482) size 141x32 clip at (145,483) size 124x15 scrollWidth 426 scrollHeight 17 layer at (144,482) size 141x32 clip at (145,483) size 124x15 scrollWidth 426 scrollHeight 17
...@@ -1360,20 +1362,20 @@ layer at (0,644) size 785x620 backgroundClip at (0,0) size 785x600 clip at (0,0) ...@@ -1360,20 +1362,20 @@ layer at (0,644) size 785x620 backgroundClip at (0,0) size 785x600 clip at (0,0)
text run at (77,26) width 4: " " text run at (77,26) width 4: " "
text run at (0,39) width 120: "abcdefghijklmnopqrstu" text run at (0,39) width 120: "abcdefghijklmnopqrstu"
text run at (0,52) width 6: "v" text run at (0,52) width 6: "v"
layer at (430,482) size 141x32 clip at (431,483) size 124x15 scrollWidth 423 scrollHeight 17 layer at (430,482) size 141x32 clip at (431,483) size 124x15 scrollWidth 426 scrollHeight 17
LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)] LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
LayoutBlockFlow {DIV} at (3,3) size 135x13 LayoutBlockFlow {DIV} at (3,3) size 135x13
LayoutText {#text} at (0,0) size 422x13 LayoutText {#text} at (0,0) size 425x13
text run at (0,0) width 70: "Lorem ipsum " text run at (0,0) width 425: "Lorem ipsum dolor ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuv"
text run at (69,0) width 353: "dolor ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuv"
layer at (573,482) size 141x32 clip at (574,483) size 124x30 scrollHeight 69 layer at (573,482) size 141x32 clip at (574,483) size 124x30 scrollHeight 69
LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)] LayoutTextControl {TEXTAREA} at (1,29) size 141x32 [bgcolor=#FFFFFF] [border: (1px solid #000000)]
LayoutBlockFlow {DIV} at (3,3) size 120x65 LayoutBlockFlow {DIV} at (3,3) size 120x65
LayoutText {#text} at (0,0) size 120x65 LayoutText {#text} at (0,0) size 120x65
text run at (0,0) width 70: "Lorem ipsum " text run at (0,0) width 100: "Lorem ipsum dolor"
text run at (69,0) width 28: "dolor" text run at (99,0) width 4: " "
text run at (0,13) width 116: "ABCDEFGHIJKLMNOP" text run at (0,13) width 116: "ABCDEFGHIJKLMNOP"
text run at (0,26) width 78: "QRSTUVWXYZ" text run at (0,26) width 78: "QRSTUVWXYZ"
text run at (77,26) width 4: " "
text run at (0,39) width 120: "abcdefghijklmnopqrstu" text run at (0,39) width 120: "abcdefghijklmnopqrstu"
text run at (0,52) width 6: "v" text run at (0,52) width 6: "v"
layer at (1,572) size 141x47 clip at (2,573) size 124x30 scrollWidth 195 scrollHeight 43 layer at (1,572) size 141x47 clip at (2,573) size 124x30 scrollWidth 195 scrollHeight 43
......
...@@ -231,6 +231,8 @@ void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, const ComputedStyl ...@@ -231,6 +231,8 @@ void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, const ComputedStyl
|| style.hasFilter())) || style.hasFilter()))
style.setTransformStyle3D(TransformStyle3DFlat); style.setTransformStyle3D(TransformStyle3DFlat);
adjustStyleForEditing(style);
bool isSVGElement = element && element->isSVGElement(); bool isSVGElement = element && element->isSVGElement();
if (isSVGElement) { if (isSVGElement) {
// Only the root <svg> element in an SVG document fragment tree honors css position // Only the root <svg> element in an SVG document fragment tree honors css position
...@@ -248,6 +250,19 @@ void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, const ComputedStyl ...@@ -248,6 +250,19 @@ void StyleAdjuster::adjustComputedStyle(ComputedStyle& style, const ComputedStyl
adjustStyleForAlignment(style, parentStyle); adjustStyleForAlignment(style, parentStyle);
} }
void StyleAdjuster::adjustStyleForEditing(ComputedStyle& style)
{
if (style.userModify() != READ_WRITE_PLAINTEXT_ONLY)
return;
// Collapsing whitespace is harmful in plain-text editing.
if (style.whiteSpace() == NORMAL)
style.setWhiteSpace(PRE_WRAP);
else if (style.whiteSpace() == NOWRAP)
style.setWhiteSpace(PRE);
else if (style.whiteSpace() == PRE_LINE)
style.setWhiteSpace(PRE_WRAP);
}
void StyleAdjuster::adjustStyleForFirstLetter(ComputedStyle& style) void StyleAdjuster::adjustStyleForFirstLetter(ComputedStyle& style)
{ {
if (style.styleType() != PseudoIdFirstLetter) if (style.styleType() != PseudoIdFirstLetter)
......
...@@ -41,6 +41,7 @@ public: ...@@ -41,6 +41,7 @@ public:
{ } { }
void adjustComputedStyle(ComputedStyle& styleToAdjust, const ComputedStyle& parentStyle, Element*); void adjustComputedStyle(ComputedStyle& styleToAdjust, const ComputedStyle& parentStyle, Element*);
static void adjustStyleForEditing(ComputedStyle&);
private: private:
void adjustStyleForFirstLetter(ComputedStyle&); void adjustStyleForFirstLetter(ComputedStyle&);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "core/html/shadow/TextControlInnerElements.h" #include "core/html/shadow/TextControlInnerElements.h"
#include "core/HTMLNames.h" #include "core/HTMLNames.h"
#include "core/css/resolver/StyleAdjuster.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/dom/NodeComputedStyle.h" #include "core/dom/NodeComputedStyle.h"
#include "core/events/MouseEvent.h" #include "core/events/MouseEvent.h"
...@@ -142,7 +143,11 @@ PassRefPtr<ComputedStyle> TextControlInnerEditorElement::customStyleForLayoutObj ...@@ -142,7 +143,11 @@ PassRefPtr<ComputedStyle> TextControlInnerEditorElement::customStyleForLayoutObj
if (!parentLayoutObject || !parentLayoutObject->isTextControl()) if (!parentLayoutObject || !parentLayoutObject->isTextControl())
return originalStyleForLayoutObject(); return originalStyleForLayoutObject();
LayoutTextControlItem textControlLayoutItem = LayoutTextControlItem(toLayoutTextControl(parentLayoutObject)); LayoutTextControlItem textControlLayoutItem = LayoutTextControlItem(toLayoutTextControl(parentLayoutObject));
return textControlLayoutItem.createInnerEditorStyle(textControlLayoutItem.styleRef()); RefPtr<ComputedStyle> innerEditorStyle = textControlLayoutItem.createInnerEditorStyle(textControlLayoutItem.styleRef());
// Using StyleAdjuster::adjustComputedStyle updates unwanted style. We'd like
// to apply only editing-related.
StyleAdjuster::adjustStyleForEditing(*innerEditorStyle);
return innerEditorStyle.release();
} }
// ---------------------------- // ----------------------------
......
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