diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/editing/InsertTextCommand.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/editing/InsertTextCommand.cpp')
-rw-r--r-- | Source/WebCore/editing/InsertTextCommand.cpp | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/Source/WebCore/editing/InsertTextCommand.cpp b/Source/WebCore/editing/InsertTextCommand.cpp index 6e645d88d..36c9f3892 100644 --- a/Source/WebCore/editing/InsertTextCommand.cpp +++ b/Source/WebCore/editing/InsertTextCommand.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2005 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -27,9 +27,9 @@ #include "InsertTextCommand.h" #include "Document.h" -#include "Element.h" #include "Editor.h" #include "Frame.h" +#include "HTMLElement.h" #include "HTMLInterchange.h" #include "Text.h" #include "VisibleUnits.h" @@ -37,16 +37,16 @@ namespace WebCore { -InsertTextCommand::InsertTextCommand(Document& document, const String& text, bool selectInsertedText, RebalanceType rebalanceType) - : CompositeEditCommand(document) +InsertTextCommand::InsertTextCommand(Document& document, const String& text, bool selectInsertedText, RebalanceType rebalanceType, EditAction editingAction) + : CompositeEditCommand(document, editingAction) , m_text(text) , m_selectInsertedText(selectInsertedText) , m_rebalanceType(rebalanceType) { } -InsertTextCommand::InsertTextCommand(Document& document, const String& text, PassRefPtr<TextInsertionMarkerSupplier> markerSupplier) - : CompositeEditCommand(document) +InsertTextCommand::InsertTextCommand(Document& document, const String& text, PassRefPtr<TextInsertionMarkerSupplier> markerSupplier, EditAction editingAction) + : CompositeEditCommand(document, editingAction) , m_text(text) , m_selectInsertedText(false) , m_rebalanceType(RebalanceLeadingAndTrailingWhitespaces) @@ -58,7 +58,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p) { Position pos = p; if (isTabSpanTextNode(pos.anchorNode())) { - RefPtr<Node> textNode = document().createEditingTextNode(""); + RefPtr<Node> textNode = document().createEditingTextNode(emptyString()); insertNodeAtTabSpanPosition(textNode.get(), pos); return firstPositionInNode(textNode.get()); } @@ -66,7 +66,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p) // Prepare for text input by looking at the specified position. // It may be necessary to insert a text node to receive characters. if (!pos.containerNode()->isTextNode()) { - RefPtr<Node> textNode = document().createEditingTextNode(""); + RefPtr<Node> textNode = document().createEditingTextNode(emptyString()); insertNodeAt(textNode.get(), pos); return firstPositionInNode(textNode.get()); } @@ -120,7 +120,7 @@ bool InsertTextCommand::performOverwrite(const String& text, bool selectInserted replaceTextInNode(textNode, start.offsetInContainerNode(), count, text); - Position endPosition = Position(textNode.release(), start.offsetInContainerNode() + text.length()); + Position endPosition = Position(textNode.get(), start.offsetInContainerNode() + text.length()); setEndingSelectionWithoutValidation(start, endPosition); if (!selectInsertedText) setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional())); @@ -132,7 +132,7 @@ void InsertTextCommand::doApply() { ASSERT(m_text.find('\n') == notFound); - if (!endingSelection().isNonOrphanedCaretOrRange()) + if (endingSelection().isNoneOrOrphaned()) return; // Delete the current selection. @@ -176,7 +176,7 @@ void InsertTextCommand::doApply() // and so deleteInsignificantText could remove it. Save the position before the node in case that happens. Position positionBeforeStartNode(positionInParentBeforeNode(startPosition.containerNode())); deleteInsignificantText(startPosition.upstream(), startPosition.downstream()); - if (!startPosition.anchorNode()->inDocument()) + if (!startPosition.anchorNode()->isConnected()) startPosition = positionBeforeStartNode; if (!startPosition.isCandidate()) startPosition = startPosition.downstream(); @@ -202,7 +202,7 @@ void InsertTextCommand::doApply() const unsigned offset = startPosition.offsetInContainerNode(); insertTextIntoNode(textNode, offset, m_text); - endPosition = Position(textNode, offset + m_text.length()); + endPosition = Position(textNode.get(), offset + m_text.length()); if (m_markerSupplier) m_markerSupplier->addMarkersToTextNode(textNode.get(), offset, m_text); @@ -235,27 +235,29 @@ void InsertTextCommand::doApply() Position InsertTextCommand::insertTab(const Position& pos) { Position insertPos = VisiblePosition(pos, DOWNSTREAM).deepEquivalent(); + if (insertPos.isNull()) + return pos; Node* node = insertPos.containerNode(); unsigned int offset = node->isTextNode() ? insertPos.offsetInContainerNode() : 0; // keep tabs coalesced in tab span if (isTabSpanTextNode(node)) { - RefPtr<Text> textNode = toText(node); + RefPtr<Text> textNode = downcast<Text>(node); insertTextIntoNode(textNode, offset, "\t"); - return Position(textNode.release(), offset + 1); + return Position(textNode.get(), offset + 1); } // create new tab span - RefPtr<Element> spanNode = createTabSpanElement(document()); + auto spanNode = createTabSpanElement(document()); // place it - if (!node->isTextNode()) { - insertNodeAt(spanNode.get(), insertPos); - } else { - RefPtr<Text> textNode = toText(node); + if (!is<Text>(*node)) + insertNodeAt(spanNode.ptr(), insertPos); + else { + RefPtr<Text> textNode = downcast<Text>(node); if (offset >= textNode->length()) - insertNodeAfter(spanNode, textNode.release()); + insertNodeAfter(spanNode.copyRef(), WTFMove(textNode)); else { // split node to make room for the span // NOTE: splitTextNode uses textNode for the @@ -263,12 +265,12 @@ Position InsertTextCommand::insertTab(const Position& pos) // insert the span before it. if (offset > 0) splitTextNode(textNode, offset); - insertNodeBefore(spanNode, textNode.release()); + insertNodeBefore(spanNode.copyRef(), WTFMove(textNode)); } } // return the position following the new tab - return lastPositionInNode(spanNode.get()); + return lastPositionInNode(spanNode.ptr()); } } |