| Index: Source/core/editing/commands/ReplaceSelectionCommand.cpp
|
| diff --git a/Source/core/editing/ReplaceSelectionCommand.cpp b/Source/core/editing/commands/ReplaceSelectionCommand.cpp
|
| similarity index 98%
|
| rename from Source/core/editing/ReplaceSelectionCommand.cpp
|
| rename to Source/core/editing/commands/ReplaceSelectionCommand.cpp
|
| index b0320f10f2131e55d8c50bc15e6d3abd63423c5a..e944b238bcc3e74c0b9bfa9ecf85c05ba70aaca5 100644
|
| --- a/Source/core/editing/ReplaceSelectionCommand.cpp
|
| +++ b/Source/core/editing/commands/ReplaceSelectionCommand.cpp
|
| @@ -25,7 +25,7 @@
|
| */
|
|
|
| #include "config.h"
|
| -#include "core/editing/ReplaceSelectionCommand.h"
|
| +#include "core/editing/commands/ReplaceSelectionCommand.h"
|
|
|
| #include "bindings/core/v8/ExceptionStatePlaceholder.h"
|
| #include "core/CSSPropertyNames.h"
|
| @@ -37,13 +37,13 @@
|
| #include "core/dom/DocumentFragment.h"
|
| #include "core/dom/Element.h"
|
| #include "core/dom/Text.h"
|
| -#include "core/editing/ApplyStyleCommand.h"
|
| -#include "core/editing/BreakBlockquoteCommand.h"
|
| #include "core/editing/EditingUtilities.h"
|
| #include "core/editing/FrameSelection.h"
|
| -#include "core/editing/SimplifyMarkupCommand.h"
|
| -#include "core/editing/SmartReplace.h"
|
| #include "core/editing/VisibleUnits.h"
|
| +#include "core/editing/commands/ApplyStyleCommand.h"
|
| +#include "core/editing/commands/BreakBlockquoteCommand.h"
|
| +#include "core/editing/commands/SimplifyMarkupCommand.h"
|
| +#include "core/editing/commands/SmartReplace.h"
|
| #include "core/editing/iterators/TextIterator.h"
|
| #include "core/editing/serializers/HTMLInterchange.h"
|
| #include "core/editing/serializers/Serialization.h"
|
| @@ -146,10 +146,10 @@ static Position positionAvoidingPrecedingNodes(Position pos)
|
| }
|
|
|
| ReplacementFragment::ReplacementFragment(Document* document, DocumentFragment* fragment, const VisibleSelection& selection)
|
| - : m_document(document),
|
| - m_fragment(fragment),
|
| - m_hasInterchangeNewlineAtStart(false),
|
| - m_hasInterchangeNewlineAtEnd(false)
|
| + : m_document(document)
|
| + , m_fragment(fragment)
|
| + , m_hasInterchangeNewlineAtStart(false)
|
| + , m_hasInterchangeNewlineAtEnd(false)
|
| {
|
| if (!m_document)
|
| return;
|
| @@ -859,7 +859,7 @@ void ReplaceSelectionCommand::mergeEndIfNeeded()
|
| if (mergeForward) {
|
| if (m_startOfInsertedContent.isOrphan())
|
| m_startOfInsertedContent = endingSelection().visibleStart().deepEquivalent();
|
| - m_endOfInsertedContent = endingSelection().visibleEnd().deepEquivalent();
|
| + m_endOfInsertedContent = endingSelection().visibleEnd().deepEquivalent();
|
| // If we merged text nodes, m_endOfInsertedContent could be null. If this is the case, we use m_startOfInsertedContent.
|
| if (m_endOfInsertedContent.isNull())
|
| m_endOfInsertedContent = m_startOfInsertedContent;
|
| @@ -954,9 +954,12 @@ void ReplaceSelectionCommand::doApply()
|
| bool selectionIsPlainText = !selection.isContentRichlyEditable();
|
| Element* currentRoot = selection.rootEditableElement();
|
|
|
| - if ((selectionStartWasStartOfParagraph && selectionEndWasEndOfParagraph && !startIsInsideMailBlockquote) ||
|
| - enclosingBlockOfVisibleStart == currentRoot || isListItem(enclosingBlockOfVisibleStart) || selectionIsPlainText)
|
| + if ((selectionStartWasStartOfParagraph && selectionEndWasEndOfParagraph && !startIsInsideMailBlockquote)
|
| + || enclosingBlockOfVisibleStart == currentRoot
|
| + || isListItem(enclosingBlockOfVisibleStart)
|
| + || selectionIsPlainText) {
|
| m_preventNesting = false;
|
| + }
|
|
|
| if (selection.isRange()) {
|
| // When the end of the selection being pasted into is at the end of a paragraph, and that selection
|
| @@ -974,17 +977,18 @@ void ReplaceSelectionCommand::doApply()
|
| if (isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart)) {
|
| if (!isEndOfEditableOrNonEditableContent(visibleStart))
|
| setEndingSelection(visibleStart.next());
|
| - } else
|
| + } else {
|
| insertParagraphSeparator();
|
| + }
|
| }
|
| insertionPos = endingSelection().start();
|
| } else {
|
| ASSERT(selection.isCaret());
|
| if (fragment.hasInterchangeNewlineAtStart()) {
|
| VisiblePosition next = visibleStart.next(CannotCrossEditingBoundary);
|
| - if (isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart) && next.isNotNull())
|
| + if (isEndOfParagraph(visibleStart) && !isStartOfParagraph(visibleStart) && next.isNotNull()) {
|
| setEndingSelection(next);
|
| - else {
|
| + } else {
|
| insertParagraphSeparator();
|
| visibleStart = endingSelection().visibleStart();
|
| }
|
| @@ -1019,7 +1023,7 @@ void ReplaceSelectionCommand::doApply()
|
|
|
| // If the downstream node has been removed there's no point in continuing.
|
| if (!insertionPos.downstream().anchorNode())
|
| - return;
|
| + return;
|
|
|
| // NOTE: This would be an incorrect usage of downstream() if downstream() were changed to mean the last position after
|
| // p that maps to the same visible position as p (since in the case where a br is at the end of a block and collapsed
|
| @@ -1111,9 +1115,9 @@ void ReplaceSelectionCommand::doApply()
|
|
|
| Element* blockStart = enclosingBlock(insertionPos.anchorNode());
|
| if ((isHTMLListElement(refNode.get()) || (isLegacyAppleHTMLSpanElement(refNode.get()) && isHTMLListElement(refNode->firstChild())))
|
| - && blockStart && blockStart->layoutObject()->isListItem())
|
| + && blockStart && blockStart->layoutObject()->isListItem()) {
|
| refNode = insertAsListItems(toHTMLElement(refNode), blockStart, insertionPos, insertedNodes);
|
| - else {
|
| + } else {
|
| insertNodeAt(refNode, insertionPos);
|
| insertedNodes.respondToNodeInsertion(*refNode);
|
| }
|
| @@ -1376,10 +1380,11 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi
|
| end = lastPositionToSelect;
|
|
|
| mergeTextNodesAroundPosition(start, end);
|
| - } else if (lastPositionToSelect.isNotNull())
|
| + } else if (lastPositionToSelect.isNotNull()) {
|
| start = end = lastPositionToSelect;
|
| - else
|
| + } else {
|
| return;
|
| + }
|
|
|
| if (m_selectReplacement)
|
| setEndingSelection(VisibleSelection(start, end, SEL_DEFAULT_AFFINITY, endingSelection().isDirectional()));
|
| @@ -1392,13 +1397,13 @@ void ReplaceSelectionCommand::mergeTextNodesAroundPosition(Position& position, P
|
| bool positionIsOffsetInAnchor = position.isOffsetInAnchor();
|
| bool positionOnlyToBeUpdatedIsOffsetInAnchor = positionOnlyToBeUpdated.isOffsetInAnchor();
|
| RefPtrWillBeRawPtr<Text> text = nullptr;
|
| - if (positionIsOffsetInAnchor && position.computeContainerNode() && position.computeContainerNode()->isTextNode())
|
| + if (positionIsOffsetInAnchor && position.computeContainerNode() && position.computeContainerNode()->isTextNode()) {
|
| text = toText(position.computeContainerNode());
|
| - else {
|
| + } else {
|
| Node* before = position.computeNodeBeforePosition();
|
| - if (before && before->isTextNode())
|
| + if (before && before->isTextNode()) {
|
| text = toText(before);
|
| - else {
|
| + } else {
|
| Node* after = position.computeNodeAfterPosition();
|
| if (after && after->isTextNode())
|
| text = toText(after);
|
| @@ -1481,8 +1486,9 @@ Node* ReplaceSelectionCommand::insertAsListItems(PassRefPtrWillBeRawPtr<HTMLElem
|
| insertNodeAfter(listItem, lastNode);
|
| insertedNodes.respondToNodeInsertion(*listItem);
|
| lastNode = listItem.get();
|
| - } else
|
| + } else {
|
| ASSERT_NOT_REACHED();
|
| + }
|
| }
|
| if (isStart || isMiddle) {
|
| if (Node* node = lastNode->previousSibling())
|
|
|