Indenting an indented image element resulted in an extra indentation
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Feb 2014 02:23:43 +0000 (02:23 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Feb 2014 02:23:43 +0000 (02:23 +0000)
commitca32000e905f7896db2df48ab624b81304b6cba9
treed35c4d6e6d73a79a16b3c652731b6b78e9eb3a1f
parent72f38570521c26b429d7144ead2fe369d3bdb541
Indenting an indented image element resulted in an extra indentation
https://bugs.webkit.org/show_bug.cgi?id=129201

Reviewed by Enrica Casucci.

Source/WebCore:

The bug was caused by endOfParagraph returning a position at the beginning of a block when the position
passed into the function was at the beginning of the block. Consider the following DOM:
<blockquote><img></blockquote>

When endOfParagraph is called on (blockquote, 0), the condition r->isBR() || isBlock(n) in endOfParagraph
matches immediately on startNode and it returns (blockquote, 0) again.

This resulted in moveParagraphWithClones invoked by indentIntoBlockquote to erroneously clone the inner
blockquote. Worked around this bug in ApplyBlockElementCommand::formatSelection by checking this specific
condition and moving the position to the end of the block. Unfortunately, a lot of existing code depends
on the current behavior of endOfParagraph so fixing the function itself was not possible.

There was another bug in indentIntoBlockquote to incorrectly insert a new blockquote into the existing
blockquote due to the code introduced in r99594 to avoid inserting before the root editable element.
Since this happens only if outerBlock is the root editable element, which is nodeToSplitTo or an ancestor
of nodeToSplitTo, explicitly look for this condition.

Test: editing/execCommand/indent-img-twice.html

* editing/ApplyBlockElementCommand.cpp:
(WebCore::ApplyBlockElementCommand::formatSelection):
(WebCore::isNewLineAtPosition):
* editing/IndentOutdentCommand.cpp:
(WebCore::IndentOutdentCommand::indentIntoBlockquote):
* editing/VisibleUnits.cpp:
(WebCore::endOfParagraph): Added a FIXME.

LayoutTests:

Added a regression test.

* editing/execCommand/indent-img-twice-expected.txt: Added.
* editing/execCommand/indent-img-twice.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164770 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/indent-img-twice-expected.txt [new file with mode: 0644]
LayoutTests/editing/execCommand/indent-img-twice.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/editing/ApplyBlockElementCommand.cpp
Source/WebCore/editing/IndentOutdentCommand.cpp
Source/WebCore/editing/VisibleUnits.cpp