Diff
Modified: trunk/LayoutTests/ChangeLog (99593 => 99594)
--- trunk/LayoutTests/ChangeLog 2011-11-08 18:29:54 UTC (rev 99593)
+++ trunk/LayoutTests/ChangeLog 2011-11-08 18:39:49 UTC (rev 99594)
@@ -1,3 +1,19 @@
+2011-11-07 Ryosuke Niwa <[email protected]>
+
+ Indent command can insert block quote in non editable content
+ https://bugs.webkit.org/show_bug.cgi?id=71754
+
+ Reviewed by Enrica Casucci.
+
+ Add tests to indent two images in a document.
+
+ * editing/execCommand/indent-images-expected.txt: Added.
+ * editing/execCommand/indent-images.html: Added.
+ * editing/execCommand/indent-images-2-expected.txt: Added.
+ * editing/execCommand/indent-images-2.html: Added.
+ * editing/execCommand/indent-images-3-expected.txt: Added.
+ * editing/execCommand/indent-images-3.html: Added.
+
2011-11-08 Adam Klein <[email protected]>
Only walk up the tree in search of MutationObservers if one has been added
Added: trunk/LayoutTests/editing/execCommand/indent-images-2-expected.txt (0 => 99594)
--- trunk/LayoutTests/editing/execCommand/indent-images-2-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/execCommand/indent-images-2-expected.txt 2011-11-08 18:39:49 UTC (rev 99594)
@@ -0,0 +1,12 @@
+This test indents insides a document with exactly two image elements.
+| <div>
+| contenteditable=""
+| <blockquote>
+| style="margin: 0 0 0 40px; border: none; padding: 0px;"
+| <img>
+| <img>
+| <#selection-caret>
+| "
+"
+| "
+"
Added: trunk/LayoutTests/editing/execCommand/indent-images-2.html (0 => 99594)
--- trunk/LayoutTests/editing/execCommand/indent-images-2.html (rev 0)
+++ trunk/LayoutTests/editing/execCommand/indent-images-2.html 2011-11-08 18:39:49 UTC (rev 99594)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<body><div contenteditable><img><img></div>
+<script src=""
+<script>
+
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+while (script = document.querySelector('script'))
+ script.parentNode.removeChild(script);
+
+getSelection().setPosition(document.getElementsByTagName('div')[0], 2);
+document.execCommand('indent');
+
+Markup.description('This test indents insides a document with exactly two image elements.');
+Markup.dump(document.body);
+
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/editing/execCommand/indent-images-3-expected.txt (0 => 99594)
--- trunk/LayoutTests/editing/execCommand/indent-images-3-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/execCommand/indent-images-3-expected.txt 2011-11-08 18:39:49 UTC (rev 99594)
@@ -0,0 +1,10 @@
+This test indents insides a document with exactly two image elements.
+Indentation should fail because the root editable element is inline.
+| <span>
+| contenteditable=""
+| <img>
+| <img>
+| "
+"
+| "
+"
Added: trunk/LayoutTests/editing/execCommand/indent-images-3.html (0 => 99594)
--- trunk/LayoutTests/editing/execCommand/indent-images-3.html (rev 0)
+++ trunk/LayoutTests/editing/execCommand/indent-images-3.html 2011-11-08 18:39:49 UTC (rev 99594)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<body><span contenteditable><img><img></span>
+<script src=""
+<script>
+
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+while (script = document.querySelector('script'))
+ script.parentNode.removeChild(script);
+
+getSelection().setPosition(document.getElementsByTagName('div')[0], 2);
+document.execCommand('indent');
+
+Markup.description('This test indents insides a document with exactly two image elements.\n'
++ 'Indentation should fail because the root editable element is inline.');
+Markup.dump(document.body);
+
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/editing/execCommand/indent-images-expected.txt (0 => 99594)
--- trunk/LayoutTests/editing/execCommand/indent-images-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/execCommand/indent-images-expected.txt 2011-11-08 18:39:49 UTC (rev 99594)
@@ -0,0 +1,6 @@
+This test indents insides a document with exactly two image elements.
+| <blockquote>
+| style="margin: 0 0 0 40px; border: none; padding: 0px;"
+| <img>
+| <img>
+| <#selection-caret>
Added: trunk/LayoutTests/editing/execCommand/indent-images.html (0 => 99594)
--- trunk/LayoutTests/editing/execCommand/indent-images.html (rev 0)
+++ trunk/LayoutTests/editing/execCommand/indent-images.html 2011-11-08 18:39:49 UTC (rev 99594)
@@ -0,0 +1,15 @@
+<body contenteditable><img><img><script src=""
+
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+while (script = document.querySelector('script'))
+ script.parentNode.removeChild(script);
+
+getSelection().setPosition(document.body, 2);
+document.execCommand('indent');
+
+Markup.description('This test indents insides a document with exactly two image elements.');
+Markup.dump(document.body);
+
+</script></body>
Modified: trunk/Source/WebCore/ChangeLog (99593 => 99594)
--- trunk/Source/WebCore/ChangeLog 2011-11-08 18:29:54 UTC (rev 99593)
+++ trunk/Source/WebCore/ChangeLog 2011-11-08 18:39:49 UTC (rev 99594)
@@ -1,3 +1,23 @@
+2011-11-07 Ryosuke Niwa <[email protected]>
+
+ Indent command can insert block quote in non editable content
+ https://bugs.webkit.org/show_bug.cgi?id=71754
+
+ Reviewed by Enrica Casucci.
+
+ The bug was caused by IndentOutdentCommand's incorrectly using deprecatedNode to determine the outer block,
+ not updating the start after inserting the targetBlockquote, and cloneParagraphUnderNewElement's cloning
+ outerNode even if it was body. Fixed those bugs.
+
+ Test: editing/execCommand/indent-images.html
+ editing/execCommand/indent-images-2.html
+ editing/execCommand/indent-images-3.html
+
+ * editing/CompositeEditCommand.cpp:
+ (WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
+ * editing/IndentOutdentCommand.cpp:
+ (WebCore::IndentOutdentCommand::indentIntoBlockquote):
+
2011-11-08 Adam Klein <[email protected]>
Only walk up the tree in search of MutationObservers if one has been added
Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (99593 => 99594)
--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp 2011-11-08 18:29:54 UTC (rev 99593)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp 2011-11-08 18:39:49 UTC (rev 99594)
@@ -779,14 +779,22 @@
// Clone the paragraph between start and end under blockElement,
// preserving the hierarchy up to outerNode.
-void CompositeEditCommand::cloneParagraphUnderNewElement(Position& start, Position& end, Node* outerNode, Element* blockElement)
+void CompositeEditCommand::cloneParagraphUnderNewElement(Position& start, Position& end, Node* passedOuterNode, Element* blockElement)
{
// First we clone the outerNode
-
- RefPtr<Node> topNode = outerNode->cloneNode(isTableElement(outerNode));
- appendNode(topNode, blockElement);
- RefPtr<Node> lastNode = topNode;
+ RefPtr<Node> topNode;
+ RefPtr<Node> lastNode;
+ RefPtr<Node> outerNode = passedOuterNode;
+ if (outerNode == outerNode->rootEditableElement()) {
+ topNode = blockElement;
+ lastNode = blockElement;
+ } else {
+ topNode = outerNode->cloneNode(isTableElement(outerNode.get()));
+ appendNode(topNode, blockElement);
+ lastNode = topNode;
+ }
+
if (start.deprecatedNode() != outerNode && lastNode->isElementNode()) {
Vector<RefPtr<Node> > ancestors;
@@ -811,12 +819,12 @@
// If end is not a descendant of outerNode we need to
// find the first common ancestor and adjust the insertion
// point accordingly.
- while (!end.deprecatedNode()->isDescendantOf(outerNode)) {
+ while (!end.deprecatedNode()->isDescendantOf(outerNode.get())) {
outerNode = outerNode->parentNode();
topNode = topNode->parentNode();
}
- for (Node* n = start.deprecatedNode()->traverseNextSibling(outerNode); n; n = n->traverseNextSibling(outerNode)) {
+ for (Node* n = start.deprecatedNode()->traverseNextSibling(outerNode.get()); n; n = n->traverseNextSibling(outerNode.get())) {
if (n->parentNode() != start.deprecatedNode()->parentNode())
lastNode = topNode->lastChild();
Modified: trunk/Source/WebCore/editing/IndentOutdentCommand.cpp (99593 => 99594)
--- trunk/Source/WebCore/editing/IndentOutdentCommand.cpp 2011-11-08 18:29:54 UTC (rev 99593)
+++ trunk/Source/WebCore/editing/IndentOutdentCommand.cpp 2011-11-08 18:39:49 UTC (rev 99594)
@@ -94,24 +94,30 @@
Node* nodeToSplitTo;
if (enclosingCell)
nodeToSplitTo = enclosingCell;
- else if (enclosingList(start.deprecatedNode()))
- nodeToSplitTo = enclosingBlock(start.deprecatedNode());
+ else if (enclosingList(start.containerNode()))
+ nodeToSplitTo = enclosingBlock(start.containerNode());
else
nodeToSplitTo = editableRootForPosition(start);
if (!nodeToSplitTo)
return;
- RefPtr<Node> outerBlock = (start.deprecatedNode() == nodeToSplitTo) ? start.deprecatedNode() : splitTreeToNode(start.deprecatedNode(), nodeToSplitTo);
+ RefPtr<Node> nodeAfterStart = start.computeNodeAfterPosition();
+ RefPtr<Node> outerBlock = (start.containerNode() == nodeToSplitTo) ? start.containerNode() : splitTreeToNode(start.containerNode(), nodeToSplitTo);
+ VisiblePosition startOfContents = start;
if (!targetBlockquote) {
// Create a new blockquote and insert it as a child of the root editable element. We accomplish
// this by splitting all parents of the current paragraph up to that point.
targetBlockquote = createBlockElement();
- insertNodeBefore(targetBlockquote, outerBlock);
+ if (outerBlock == start.containerNode())
+ insertNodeAt(targetBlockquote, start);
+ else
+ insertNodeBefore(targetBlockquote, outerBlock);
+ startOfContents = positionAfterNode(targetBlockquote.get());
}
- moveParagraphWithClones(start, end, targetBlockquote.get(), outerBlock.get());
+ moveParagraphWithClones(startOfContents, end, targetBlockquote.get(), outerBlock.get());
}
void IndentOutdentCommand::outdentParagraph()