summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp b/chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp
index 7049dacad0c..abc857bdd64 100644
--- a/chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp
+++ b/chromium/third_party/WebKit/Source/core/editing/ApplyBlockElementCommand.cpp
@@ -27,8 +27,8 @@
#include "config.h"
#include "core/editing/ApplyBlockElementCommand.h"
-#include "HTMLNames.h"
#include "bindings/v8/ExceptionState.h"
+#include "core/HTMLNames.h"
#include "core/dom/NodeRenderStyle.h"
#include "core/dom/Text.h"
#include "core/editing/VisiblePosition.h"
@@ -73,17 +73,21 @@ void ApplyBlockElementCommand::doApply()
// FIXME: We paint the gap before some paragraphs that are indented with left
// margin/padding, but not others. We should make the gap painting more consistent and
// then use a left margin/padding rule here.
- if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd))
- setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(CannotCrossEditingBoundary), endingSelection().isDirectional()));
+ if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd)) {
+ VisibleSelection newSelection(visibleStart, visibleEnd.previous(CannotCrossEditingBoundary), endingSelection().isDirectional());
+ if (newSelection.isNone())
+ return;
+ setEndingSelection(newSelection);
+ }
VisibleSelection selection = selectionForParagraphIteration(endingSelection());
VisiblePosition startOfSelection = selection.visibleStart();
VisiblePosition endOfSelection = selection.visibleEnd();
ASSERT(!startOfSelection.isNull());
ASSERT(!endOfSelection.isNull());
- RefPtr<ContainerNode> startScope;
+ RefPtrWillBeRawPtr<ContainerNode> startScope = nullptr;
int startIndex = indexForVisiblePosition(startOfSelection, startScope);
- RefPtr<ContainerNode> endScope;
+ RefPtrWillBeRawPtr<ContainerNode> endScope = nullptr;
int endIndex = indexForVisiblePosition(endOfSelection, endScope);
formatSelection(startOfSelection, endOfSelection);
@@ -107,15 +111,15 @@ void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
// and there's nothing to move.
Position start = startOfSelection.deepEquivalent().downstream();
if (isAtUnsplittableElement(start)) {
- RefPtr<Element> blockquote = createBlockElement();
+ RefPtrWillBeRawPtr<Element> blockquote = createBlockElement();
insertNodeAt(blockquote, start);
- RefPtr<Element> placeholder = createBreakElement(document());
+ RefPtrWillBeRawPtr<Element> placeholder = createBreakElement(document());
appendNode(placeholder, blockquote);
setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get()), DOWNSTREAM, endingSelection().isDirectional()));
return;
}
- RefPtr<Element> blockquoteForNextIndent;
+ RefPtrWillBeRawPtr<Element> blockquoteForNextIndent = nullptr;
VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection);
VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection);
VisiblePosition endAfterSelection = endOfParagraph(endOfLastParagraph.next());
@@ -128,7 +132,7 @@ void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
atEnd = true;
rangeForParagraphSplittingTextNodesIfNeeded(endOfCurrentParagraph, start, end);
- endOfCurrentParagraph = end;
+ endOfCurrentParagraph = VisiblePosition(end);
Node* enclosingCell = enclosingNodeOfType(start, &isTableCell);
VisiblePosition endOfNextParagraph = endOfNextParagrahSplittingTextNodesIfNeeded(endOfCurrentParagraph, start, end);
@@ -138,7 +142,7 @@ void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
// Don't put the next paragraph in the blockquote we just created for this paragraph unless
// the next paragraph is in the same cell.
if (enclosingCell && enclosingCell != enclosingNodeOfType(endOfNextParagraph.deepEquivalent(), &isTableCell))
- blockquoteForNextIndent = 0;
+ blockquoteForNextIndent = nullptr;
// indentIntoBlockquote could move more than one paragraph if the paragraph
// is in a list item or a table. As a result, endAfterSelection could refer to a position
@@ -180,7 +184,7 @@ void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const
start = startOfParagraph(endOfCurrentParagraph).deepEquivalent();
end = endOfCurrentParagraph.deepEquivalent();
- document().updateStyleIfNeeded();
+ document().updateRenderTreeIfNeeded();
bool isStartAndEndOnSameNode = false;
if (RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start)) {
@@ -189,7 +193,7 @@ void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const
// Avoid obtanining the start of next paragraph for start
if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNewLineAtPosition(start.previous()) && start.offsetInContainerNode() > 0)
- start = startOfParagraph(end.previous()).deepEquivalent();
+ start = startOfParagraph(VisiblePosition(end.previous())).deepEquivalent();
// If start is in the middle of a text node, split.
if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) {
@@ -208,7 +212,7 @@ void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const
}
}
- document().updateStyleIfNeeded();
+ document().updateRenderTreeIfNeeded();
if (RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end)) {
bool isEndAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNode(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.deprecatedNode();
@@ -223,7 +227,7 @@ void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const
// If end is in the middle of a text node, split.
if (!endStyle->collapseWhiteSpace() && end.offsetInContainerNode() && end.offsetInContainerNode() < end.containerNode()->maxCharacterOffset()) {
- RefPtr<Text> endContainer = end.containerText();
+ RefPtrWillBeRawPtr<Text> endContainer = end.containerText();
splitTextNode(endContainer, end.offsetInContainerNode());
if (isStartAndEndOnSameNode)
start = firstPositionInOrBeforeNode(endContainer->previousSibling());
@@ -246,7 +250,7 @@ VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN
if (!style)
return endOfNextParagraph;
- RefPtr<Text> text = position.containerText();
+ RefPtrWillBeRawPtr<Text> text = position.containerText();
if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNewLineAtPosition(firstPositionInNode(text.get())))
return endOfNextParagraph;
@@ -273,15 +277,21 @@ VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN
m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.offsetInContainerNode() - 1);
}
- return Position(text.get(), position.offsetInContainerNode() - 1);
+ return VisiblePosition(Position(text.get(), position.offsetInContainerNode() - 1));
}
-PassRefPtr<Element> ApplyBlockElementCommand::createBlockElement() const
+PassRefPtrWillBeRawPtr<Element> ApplyBlockElementCommand::createBlockElement() const
{
- RefPtr<Element> element = createHTMLElement(document(), m_tagName);
+ RefPtrWillBeRawPtr<Element> element = createHTMLElement(document(), m_tagName);
if (m_inlineStyle.length())
element->setAttribute(styleAttr, m_inlineStyle);
return element.release();
}
+void ApplyBlockElementCommand::trace(Visitor* visitor)
+{
+ visitor->trace(m_endOfLastParagraph);
+ CompositeEditCommand::trace(visitor);
+}
+
}