Commit 713375e0 authored by ossy@webkit.org's avatar ossy@webkit.org

Unreviewed. Roll-out r55263 because it broke fast/forms/textarea-type-spaces-pretty-diff.html.

https://bugs.webkit.org/show_bug.cgi?id=30946

WebCore: 

* editing/CompositeEditCommand.cpp:
(WebCore::isWhitespace):
(WebCore::CompositeEditCommand::rebalanceWhitespaceAt):
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::input):
* editing/InsertTextCommand.h:
* editing/htmlediting.cpp:
* editing/htmlediting.h:

LayoutTests: 

* editing/execCommand/5142012-3-expected.txt:
* editing/inserting/rebalance-whitespace-1-expected.txt: Removed.
* editing/inserting/rebalance-whitespace-1.html: Removed.
* editing/pasteboard/5521237-expected.txt:
* platform/mac/editing/execCommand/5482023-expected.checksum:
* platform/mac/editing/execCommand/5482023-expected.png: Added.
* platform/mac/editing/execCommand/5482023-expected.txt:
* platform/mac/editing/execCommand/remove-formatting-2-expected.checksum:
* platform/mac/editing/execCommand/remove-formatting-2-expected.png: Added.
* platform/mac/editing/execCommand/remove-formatting-expected.checksum:
* platform/mac/editing/execCommand/remove-formatting-expected.png: Added.
* platform/mac/editing/execCommand/remove-formatting-expected.txt:
* platform/mac/editing/inserting/editable-html-element-expected.checksum:
* platform/mac/editing/inserting/editable-html-element-expected.png: Added.
* platform/mac/editing/inserting/editable-html-element-expected.txt:
* platform/mac/editing/pasteboard/4989774-expected.checksum:
* platform/mac/editing/pasteboard/4989774-expected.png: Added.
* platform/mac/editing/pasteboard/4989774-expected.txt:
* platform/mac/editing/selection/4983858-expected.checksum:
* platform/mac/editing/selection/4983858-expected.png: Added.
* platform/mac/editing/selection/4983858-expected.txt:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55271 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 67018916
2010-02-26 Csaba Osztrogonác <ossy@webkit.org>
Unreviewed. Roll-out r55263 because it broke fast/forms/textarea-type-spaces-pretty-diff.html.
https://bugs.webkit.org/show_bug.cgi?id=30946
* editing/execCommand/5142012-3-expected.txt:
* editing/inserting/rebalance-whitespace-1-expected.txt: Removed.
* editing/inserting/rebalance-whitespace-1.html: Removed.
* editing/pasteboard/5521237-expected.txt:
* platform/mac/editing/execCommand/5482023-expected.checksum:
* platform/mac/editing/execCommand/5482023-expected.png: Added.
* platform/mac/editing/execCommand/5482023-expected.txt:
* platform/mac/editing/execCommand/remove-formatting-2-expected.checksum:
* platform/mac/editing/execCommand/remove-formatting-2-expected.png: Added.
* platform/mac/editing/execCommand/remove-formatting-expected.checksum:
* platform/mac/editing/execCommand/remove-formatting-expected.png: Added.
* platform/mac/editing/execCommand/remove-formatting-expected.txt:
* platform/mac/editing/inserting/editable-html-element-expected.checksum:
* platform/mac/editing/inserting/editable-html-element-expected.png: Added.
* platform/mac/editing/inserting/editable-html-element-expected.txt:
* platform/mac/editing/pasteboard/4989774-expected.checksum:
* platform/mac/editing/pasteboard/4989774-expected.png: Added.
* platform/mac/editing/pasteboard/4989774-expected.txt:
* platform/mac/editing/selection/4983858-expected.checksum:
* platform/mac/editing/selection/4983858-expected.png: Added.
* platform/mac/editing/selection/4983858-expected.txt:
2010-02-25 Dirk Pranke <dpranke@chromium.org>
Reviewed by Eric Seidel.
......
This tests for a bug when inserting after a link at the end of the document. Like TextEdit, we insert content outside of the link, but inserting outside of the link shouldn't cause the content to be inserted in the wrong paragraph.
This paragraph should not contains links.
This sentence should be a link. This sentence should not.
<a href="#">This sentence should be a link.</a> This sentence should not.
This sentence should be a link. This sentence should not.
<a href="#">This sentence should be a link.</a>&nbsp;This sentence should not.
This tests whitespace rebalancing when inserting characters in and around already balanced sequences. In each div below, 2 or more adjacent whitespace characters should be alternate between regular whitespace and non-breaking spaces (note that editable regions use -webkit-nbsp-mode:space).
hellox world
hellox  world
hellox   world
hello x world
hello  x world
hello  x  world
hello  x   world
hello   x  world
hello   x   world
<script>
if (window.layoutTestController)
window.layoutTestController.dumpAsText();
</script>
<div contentEditable="true" id="test1">hello world</div>
<script>
// Test rebalancing a single space on one side.
test = document.getElementById("test1");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test2">hello world</div>
<script>
// Test rebalancing two spaces on one side.
test = document.getElementById("test2");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test3">hello world</div>
<script>
// Test rebalancing three spaces on one side.
test = document.getElementById("test3");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test4">hello world</div>
<script>
// Test rebalancing one space on either side of the insertion.
test = document.getElementById("test4");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 6);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test5">hello world</div>
<script>
// Test rebalancing two spaces on one side and one space on the other side of the insertion.
test = document.getElementById("test5");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 7);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test6">hello world</div>
<script>
// Test rebalancing two spaces on either side of the insertion.
test = document.getElementById("test6");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 7);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test7">hello world</div>
<script>
// Test rebalancing two spaces on either side of the insertion.
test = document.getElementById("test7");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 7);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test8">hello world</div>
<script>
// Test rebalancing three spaces on one side and two on the other side of the insertion.
test = document.getElementById("test8");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 8);
document.execCommand("InsertText", false, "x");
</script>
<div contentEditable="true" id="test9">hello world</div>
<script>
// Test rebalancing three spaces on either side of the insertion.
test = document.getElementById("test9");
text = test.firstChild;
window.getSelection().setPosition(text, 5);
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
document.execCommand("InsertText", false, " ");
window.getSelection().setPosition(text, 8);
document.execCommand("InsertText", false, "x");
</script>
<script>
divs = document.getElementsByTagName("div");
var output = "This tests whitespace rebalancing when inserting characters in and around already balanced sequences. In each div below, 2 or more adjacent whitespace characters should be alternate between regular whitespace and non-breaking spaces (note that editable regions use -webkit-nbsp-mode:space).\n\n";
for (i = 0; i < divs.length; i++)
output += divs[i].innerText + "\n";
document.body.innerText = output;
</script>
This tests for a bug when pasting a word copied from TextEdit after a regular, breaking space.
Everything in this editable region should be in one paragraph.
Everything in this editable region should be in one paragraph.
72752236297a99482053d1bf0732fbfe
\ No newline at end of file
e67357e5552e5cf2f062416e2f357fa7
\ No newline at end of file
......@@ -4,10 +4,11 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x571
RenderBlock {H1} at (0,0) size 784x111
RenderText {#text} at (0,0) size 784x111
RenderText {#text} at (0,0) size 779x111
text run at (0,0) width 721: "This tests for a bug when performing a FormatBlock"
text run at (721,0) width 8: " "
text run at (0,37) width 779: "inside a body with no visible content. This text should be"
text run at (779,37) width 5: " "
text run at (0,37) width 512: "inside a body with no visible content. "
text run at (512,37) width 259: "This text should be"
text run at (771,37) width 8: " "
text run at (0,74) width 287: "inside an h1 element."
caret: position 132 of child 0 {#text} of child 0 {H1} of child 1 {BODY} of child 0 {HTML} of document
1f30e9cf361c234b16900a0459474544
\ No newline at end of file
13c97dae5ae20ea4fbf38b5855f386b0
\ No newline at end of file
cd6a356e264bbdbc23d6826d314ae259
\ No newline at end of file
a0e53bd03cecb9392c13f0f16e18cb15
\ No newline at end of file
......@@ -24,7 +24,7 @@ layer at (0,0) size 800x600
text run at (0,0) width 63: "foobarbaz"
RenderBR {BR} at (63,14) size 0x0
RenderText {#text} at (0,18) size 71x18
text run at (0,18) width 71: "foo bar baz"
text run at (0,18) width 71: "foo\x{9}bar\x{9}baz"
RenderBR {BR} at (71,32) size 0x0
RenderText {#text} at (0,36) size 63x18
text run at (0,36) width 63: "foobarbaz"
......
68690c967f7f6a8300ff78621ef29e5f
\ No newline at end of file
f17d800334a5794072abbfc30916a28c
\ No newline at end of file
......@@ -17,9 +17,10 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock (anonymous) at (0,0) size 784x54
RenderText {#text} at (0,0) size 784x54
text run at (0,0) width 783: "This tests to make sure that when the enclosing block is the body element, and when the html element is editable, inserting a"
text run at (783,0) width 1: " "
RenderText {#text} at (0,0) size 783x54
text run at (0,0) width 714: "This tests to make sure that when the enclosing block is the body element, and when the html element is editable, "
text run at (714,0) width 65: "inserting a"
text run at (779,0) width 4: " "
text run at (0,18) width 751: "paragraph separator doesn't split the body (inserting a paragraph separator usually splits/clones the enclosing block flow"
text run at (751,18) width 4: " "
text run at (0,36) width 58: "element)."
......
2af51840dfd0e575314da7c6befff2d6
\ No newline at end of file
2b8203352f8754425ebf04afdf9fc1dd
\ No newline at end of file
......@@ -7,10 +7,11 @@ layer at (0,0) size 800x600
RenderImage {IMG} at (76,0) size 76x103
RenderImage {IMG} at (152,0) size 76x103
RenderBR {BR} at (228,103) size 0x0
RenderText {#text} at (0,103) size 739x36
text run at (0,103) width 735: "This tests for a bug where an images pasted on the same line would appear on different lines. You should see"
text run at (735,103) width 4: " "
text run at (0,121) width 358: "several pictures above all in the same line/paragraph."
RenderText {#text} at (0,103) size 784x36
text run at (0,103) width 629: "This tests for a bug where an images pasted on the same line would appear on different lines. "
text run at (629,103) width 153: "You should see several"
text run at (782,103) width 2: " "
text run at (0,121) width 307: "pictures above all in the same line/paragraph."
RenderText {#text} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
caret: position 164 of child 4 {#text} of child 1 {BODY} of child 0 {HTML} of document
e23b4757a2355938acae1fffcfb07362
\ No newline at end of file
1ea76bed3d177e7dea634dc0a3658c6f
\ No newline at end of file
......@@ -4,9 +4,11 @@ layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock (anonymous) at (0,0) size 784x36
RenderText {#text} at (0,0) size 780x36
text run at (0,0) width 776: "This tests for a bug where selecting a word would select the line break and word before it. Only the word in the paragraph"
text run at (776,0) width 4: " "
RenderText {#text} at (0,0) size 772x36
text run at (0,0) width 570: "This tests for a bug where selecting a word would select the line break and word before it. "
text run at (570,0) width 135: "Only the word in the "
text run at (705,0) width 63: "paragraph"
text run at (768,0) width 4: " "
text run at (0,18) width 162: "below should be selected:"
RenderText {#text} at (0,0) size 0x0
RenderBlock {DIV} at (0,36) size 784x18
......
2010-02-26 Csaba Osztrogonác <ossy@webkit.org>
Unreviewed. Roll-out r55263 because it broke fast/forms/textarea-type-spaces-pretty-diff.html.
https://bugs.webkit.org/show_bug.cgi?id=30946
* editing/CompositeEditCommand.cpp:
(WebCore::isWhitespace):
(WebCore::CompositeEditCommand::rebalanceWhitespaceAt):
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::input):
* editing/InsertTextCommand.h:
* editing/htmlediting.cpp:
* editing/htmlediting.h:
2010-02-25 Mark Rowe <mrowe@apple.com>
Reviewed by Brady Eidson.
......
......@@ -385,6 +385,11 @@ void CompositeEditCommand::setNodeAttribute(PassRefPtr<Element> element, const Q
applyCommandToComposite(SetNodeAttributeCommand::create(element, attribute, value));
}
static inline bool isWhitespace(UChar c)
{
return c == noBreakSpace || c == ' ' || c == '\n' || c == '\t';
}
// FIXME: Doesn't go into text nodes that contribute adjacent text (siblings, cousins, etc).
void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position)
{
......@@ -393,14 +398,34 @@ void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position)
return;
Text* textNode = static_cast<Text*>(node);
if (textNode->length() == 0)
return;
RenderObject* renderer = textNode->renderer();
if (renderer && !renderer->style()->collapseWhiteSpace())
return;
String text = textNode->data();
ASSERT(!text.isEmpty());
int offset = position.deprecatedEditingOffset();
// If neither text[offset] nor text[offset - 1] are some form of whitespace, do nothing.
if (!isWhitespace(text[offset])) {
offset--;
if (offset < 0 || !isWhitespace(text[offset]))
return;
}
unsigned upstream, downstream;
if (!extentOfWhitespaceForRebalancingAt(textNode, position.deprecatedEditingOffset(), upstream, downstream))
return;
// Set upstream and downstream to define the extent of the whitespace surrounding text[offset].
int upstream = offset;
while (upstream > 0 && isWhitespace(text[upstream - 1]))
upstream--;
int downstream = offset;
while ((unsigned)downstream + 1 < text.length() && isWhitespace(text[downstream + 1]))
downstream++;
ASSERT(downstream > upstream);
int length = downstream - upstream;
int length = downstream - upstream + 1;
ASSERT(length > 0);
VisiblePosition visibleUpstreamPos(Position(position.node(), upstream));
VisiblePosition visibleDownstreamPos(Position(position.node(), downstream + 1));
......
......@@ -106,33 +106,9 @@ bool InsertTextCommand::performTrivialReplace(const String& text, bool selectIns
return true;
}
void InsertTextCommand::insertTextIntoNodeAndRebalanceWhitespace(const String& textToInsert, Text* node, unsigned offset)
{
unsigned whitespaceStart, whitespaceEnd;
if (!extentOfWhitespaceForRebalancingAt(node, offset, whitespaceStart, whitespaceEnd)) {
VisiblePosition visiblePosition(Position(node, offset));
String rebalancedText = stringWithRebalancedWhitespace(textToInsert, isStartOfParagraph(visiblePosition), isEndOfParagraph(visiblePosition));
insertTextIntoNode(node, offset, rebalancedText);
return;
}
ASSERT(whitespaceEnd > whitespaceStart);
unsigned length = whitespaceEnd - whitespaceStart;
String string = node->data().substring(whitespaceStart, length);
// Insert textToInsert into the whitespace we found.
string.insert(textToInsert, offset - whitespaceStart);
VisiblePosition visibleStart(Position(node, whitespaceStart));
VisiblePosition visibleEnd(Position(node, whitespaceEnd + textToInsert.length()));
String rebalancedString = stringWithRebalancedWhitespace(string, isStartOfParagraph(visibleStart), isEndOfParagraph(visibleEnd));
replaceTextInNode(node, whitespaceStart, length, rebalancedString);
}
void InsertTextCommand::input(const String& text, bool selectInsertedText)
{
ASSERT(text.find('\n') == -1);
if (endingSelection().isNone())
......@@ -194,9 +170,14 @@ void InsertTextCommand::input(const String& text, bool selectInsertedText)
Text *textNode = static_cast<Text *>(startPosition.node());
int offset = startPosition.deprecatedEditingOffset();
insertTextIntoNodeAndRebalanceWhitespace(text, textNode, offset);
insertTextIntoNode(textNode, offset, text);
endPosition = Position(textNode, offset + text.length());
// The insertion may require adjusting adjacent whitespace, if it is present.
rebalanceWhitespaceAt(endPosition);
// Rebalancing on both sides isn't necessary if we've inserted a space.
if (text != " ")
rebalanceWhitespaceAt(startPosition);
m_charactersAdded += text.length();
}
......
......@@ -52,8 +52,6 @@ private:
Position insertTab(const Position&);
bool performTrivialReplace(const String&, bool selectInsertedText);
void insertTextIntoNodeAndRebalanceWhitespace(const String& text, Text* node, unsigned offset);
unsigned m_charactersAdded;
};
......
......@@ -425,43 +425,6 @@ String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfP
return rebalancedString;
}
// FIXME: Move this into PlatformString.h or StringImpl.h and rename it to distinguish it from similar functions.
static inline bool isWhitespace(UChar c)
{
return c == noBreakSpace || c == ' ' || c == '\n' || c == '\t';
}
// Find the extent of whitespace around a particular offset. If whitespace characters (' ') are preserved, then we don't
// do whitespace rebalancing and this function returns false.
bool extentOfWhitespaceForRebalancingAt(PassRefPtr<Text> node, unsigned offset, unsigned& start, unsigned& end)
{
RenderObject* renderer = node->renderer();
if (renderer && !renderer->style()->collapseWhiteSpace())
return false;
String text = node->data();
start = offset;
end = offset;
if (offset == text.length() || !isWhitespace(text[offset])) {
if (!offset || !isWhitespace(text[offset - 1]))
// If neither text[offset] nor text[offset - 1] are some form of whitespace, no rebalancing is necessary.
return false;
// text[offset] is not whitespace, but text[offset - 1] is, adjust start and end offsets.
start = offset - 1;
end = offset;
}
while (start > 0 && isWhitespace(text[start - 1]))
start--;
while (end < text.length() && isWhitespace(text[end]))
end++;
return true;
}
bool isTableStructureNode(const Node *node)
{
RenderObject *r = node->renderer();
......
......@@ -40,7 +40,6 @@ class Node;
class Position;
class Range;
class String;
class Text;
class VisiblePosition;
class VisibleSelection;
......@@ -230,7 +229,6 @@ VisibleSelection selectionForParagraphIteration(const VisibleSelection&);
// Miscellaneous functions on String
String stringWithRebalancedWhitespace(const String&, bool, bool);
bool extentOfWhitespaceForRebalancingAt(PassRefPtr<Text> node, unsigned offset, unsigned& start, unsigned& end);
const String& nonBreakingSpaceString();
bool validBlockTag(const AtomicString&);
......
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