From 14fffc9cae4ca4e6245c1b3121569a3df667d73a Mon Sep 17 00:00:00 2001 From: Elliott Sprehn Date: Tue, 2 Dec 2014 11:24:46 -0800 Subject: [PATCH] Delete a bunch of rich text editing code. R=ojan@chromium.org Review URL: https://codereview.chromium.org/767623004 --- engine/core/core.gni | 2 - engine/core/editing/CompositeEditCommand.cpp | 210 ------------------ engine/core/editing/CompositeEditCommand.h | 10 - .../InsertParagraphSeparatorCommand.cpp | 5 - .../SplitTextNodeContainingElementCommand.cpp | 51 ----- .../SplitTextNodeContainingElementCommand.h | 51 ----- engine/core/editing/TypingCommand.cpp | 10 - 7 files changed, 339 deletions(-) delete mode 100644 engine/core/editing/SplitTextNodeContainingElementCommand.cpp delete mode 100644 engine/core/editing/SplitTextNodeContainingElementCommand.h diff --git a/engine/core/core.gni b/engine/core/core.gni index df65764e1f5..2a3b18a6b90 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -649,8 +649,6 @@ sky_core_files = [ "editing/SplitElementCommand.h", "editing/SplitTextNodeCommand.cpp", "editing/SplitTextNodeCommand.h", - "editing/SplitTextNodeContainingElementCommand.cpp", - "editing/SplitTextNodeContainingElementCommand.h", "editing/SurroundingText.cpp", "editing/SurroundingText.h", "editing/TextAffinity.h", diff --git a/engine/core/editing/CompositeEditCommand.cpp b/engine/core/editing/CompositeEditCommand.cpp index 79da40174ab..d4b8b59a209 100644 --- a/engine/core/editing/CompositeEditCommand.cpp +++ b/engine/core/editing/CompositeEditCommand.cpp @@ -49,7 +49,6 @@ #include "sky/engine/core/editing/SpellChecker.h" #include "sky/engine/core/editing/SplitElementCommand.h" #include "sky/engine/core/editing/SplitTextNodeCommand.h" -#include "sky/engine/core/editing/SplitTextNodeContainingElementCommand.h" #include "sky/engine/core/editing/TextIterator.h" #include "sky/engine/core/editing/VisibleUnits.h" #include "sky/engine/core/editing/htmlediting.h" @@ -374,11 +373,6 @@ void CompositeEditCommand::splitElement(PassRefPtr element, PassRefPtr< applyCommandToComposite(SplitElementCommand::create(element, atChild)); } -void CompositeEditCommand::splitTextNodeContainingElement(PassRefPtr text, unsigned offset) -{ - applyCommandToComposite(SplitTextNodeContainingElementCommand::create(text, offset)); -} - void CompositeEditCommand::insertTextIntoNode(PassRefPtr node, unsigned offset, const String& text) { if (!text.isEmpty()) @@ -706,75 +700,6 @@ void CompositeEditCommand::removePlaceholderAt(const Position& p) deleteTextFromNode(toText(p.anchorNode()), p.offsetInContainerNode(), 1); } -PassRefPtr CompositeEditCommand::insertNewDefaultParagraphElementAt(const Position& position) -{ - RefPtr paragraphElement = createDefaultParagraphElement(document()); - insertNodeAt(paragraphElement, position); - return paragraphElement.release(); -} - -// If the paragraph is not entirely within it's own block, create one and move the paragraph into -// it, and return that block. Otherwise return 0. -PassRefPtr CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary(const Position& pos) -{ - ASSERT(isEditablePosition(pos, ContentIsEditable, DoNotUpdateStyle)); - - // It's strange that this function is responsible for verifying that pos has not been invalidated - // by an earlier call to this function. The caller, applyBlockStyle, should do this. - VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY); - VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos)); - VisiblePosition visibleParagraphEnd = endOfParagraph(visiblePos); - VisiblePosition next = visibleParagraphEnd.next(); - VisiblePosition visibleEnd = next.isNotNull() ? next : visibleParagraphEnd; - - Position upstreamStart = visibleParagraphStart.deepEquivalent().upstream(); - Position upstreamEnd = visibleEnd.deepEquivalent().upstream(); - - // If there are no VisiblePositions in the same block as pos then - // upstreamStart will be outside the paragraph - if (comparePositions(pos, upstreamStart) < 0) - return nullptr; - - // Perform some checks to see if we need to perform work in this function. - if (isBlock(upstreamStart.deprecatedNode())) { - // If the block is the root editable element, always move content to a new block, - // since it is illegal to modify attributes on the root editable element for editing. - if (upstreamStart.deprecatedNode() == editableRootForPosition(upstreamStart)) { - // If the block is the root editable element and it contains no visible content, create a new - // block but don't try and move content into it, since there's nothing for moveParagraphs to move. - if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(upstreamStart.deprecatedNode()->renderer())) - return insertNewDefaultParagraphElementAt(upstreamStart); - } else if (isBlock(upstreamEnd.deprecatedNode())) { - if (!upstreamEnd.deprecatedNode()->isDescendantOf(upstreamStart.deprecatedNode())) { - // If the paragraph end is a descendant of paragraph start, then we need to run - // the rest of this function. If not, we can bail here. - return nullptr; - } - } else if (enclosingBlock(upstreamEnd.deprecatedNode()) != upstreamStart.deprecatedNode()) { - // It should be an ancestor of the paragraph start. - // We can bail as we have a full block to work with. - return nullptr; - } else if (isEndOfEditableOrNonEditableContent(visibleEnd)) { - // At the end of the editable region. We can bail here as well. - return nullptr; - } - } - - if (visibleParagraphEnd.isNull()) - return nullptr; - - RefPtr newBlock = insertNewDefaultParagraphElementAt(upstreamStart); - - // Inserting default paragraph element can change visible position. We - // should update visible positions before use them. - visiblePos = VisiblePosition(pos, VP_DEFAULT_AFFINITY); - visibleParagraphStart = VisiblePosition(startOfParagraph(visiblePos)); - visibleParagraphEnd = VisiblePosition(endOfParagraph(visiblePos)); - moveParagraphs(visibleParagraphStart, visibleParagraphEnd, VisiblePosition(firstPositionInNode(newBlock.get()))); - - return newBlock.release(); -} - void CompositeEditCommand::pushAnchorElementDown(Element* anchorNode) { if (!anchorNode) @@ -788,85 +713,6 @@ void CompositeEditCommand::pushAnchorElementDown(Element* anchorNode) removeNodePreservingChildren(anchorNode); } -// Clone the paragraph between start and end under blockElement, -// preserving the hierarchy up to outerNode. - -void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start, const Position& end, Node* passedOuterNode, Element* blockElement) -{ - ASSERT(comparePositions(start, end) <= 0); - ASSERT(passedOuterNode); - ASSERT(blockElement); - - // First we clone the outerNode - RefPtr lastNode = nullptr; - RefPtr outerNode = passedOuterNode; - - if (outerNode->isRootEditableElement()) { - lastNode = blockElement; - } else { - lastNode = outerNode->cloneNode(false); - appendNode(lastNode, blockElement); - } - - if (start.anchorNode() != outerNode && lastNode->isElementNode() && start.anchorNode()->isDescendantOf(outerNode.get())) { - Vector > ancestors; - - // Insert each node from innerNode to outerNode (excluded) in a list. - for (Node* n = start.deprecatedNode(); n && n != outerNode; n = n->parentNode()) - ancestors.append(n); - - // Clone every node between start.deprecatedNode() and outerBlock. - - for (size_t i = ancestors.size(); i != 0; --i) { - Node* item = ancestors[i - 1].get(); - RefPtr child = item->cloneNode(false); - appendNode(child, toElement(lastNode)); - lastNode = child.release(); - } - } - - // Scripts specified in javascript protocol may remove |outerNode| - // during insertion, e.g.