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/InsertParagraphSeparatorCommand.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp')
-rw-r--r-- | Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp index 2e32b69b4..4d1916009 100644 --- a/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp +++ b/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2005, 2006 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 @@ -28,7 +28,7 @@ #include "Document.h" #include "EditingStyle.h" -#include "HTMLElement.h" +#include "HTMLBRElement.h" #include "HTMLFormElement.h" #include "HTMLNames.h" #include "InsertLineBreakCommand.h" @@ -59,8 +59,8 @@ static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock) return curBlock; } -InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document& document, bool mustUseDefaultParagraphElement, bool pasteBlockqutoeIntoUnquotedArea) - : CompositeEditCommand(document) +InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(Document& document, bool mustUseDefaultParagraphElement, bool pasteBlockqutoeIntoUnquotedArea, EditAction editingAction) + : CompositeEditCommand(document, editingAction) , m_mustUseDefaultParagraphElement(mustUseDefaultParagraphElement) , m_pasteBlockqutoeIntoUnquotedArea(pasteBlockqutoeIntoUnquotedArea) { @@ -131,24 +131,24 @@ void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert } } -PassRefPtr<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock(const Vector<RefPtr<Element>>& ancestors, PassRefPtr<Element> blockToInsert) +RefPtr<Element> InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock(const Vector<RefPtr<Element>>& ancestors, PassRefPtr<Element> blockToInsert) { // Make clones of ancestors in between the start node and the start block. RefPtr<Element> parent = blockToInsert; for (size_t i = ancestors.size(); i != 0; --i) { - RefPtr<Element> child = ancestors[i - 1]->cloneElementWithoutChildren(); + auto child = ancestors[i - 1]->cloneElementWithoutChildren(document()); // It should always be okay to remove id from the cloned elements, since the originals are not deleted. child->removeAttribute(idAttr); - appendNode(child, parent); - parent = child.release(); + appendNode(child.ptr(), parent); + parent = WTFMove(child); } - return parent.release(); + return parent; } void InsertParagraphSeparatorCommand::doApply() { - if (!endingSelection().isNonOrphanedCaretOrRange()) + if (endingSelection().isNoneOrOrphaned()) return; Position insertionPosition = endingSelection().start(); @@ -169,7 +169,7 @@ void InsertParagraphSeparatorCommand::doApply() if (!startBlock || !startBlock->nonShadowBoundaryParentNode() || isTableCell(startBlock.get()) - || isHTMLFormElement(startBlock.get()) + || is<HTMLFormElement>(*startBlock) // FIXME: If the node is hidden, we don't have a canonical position so we will do the wrong thing for tables and <hr>. https://bugs.webkit.org/show_bug.cgi?id=40342 || (!canonicalPos.isNull() && canonicalPos.deprecatedNode()->renderer() && canonicalPos.deprecatedNode()->renderer()->isTable()) || (!canonicalPos.isNull() && canonicalPos.deprecatedNode()->hasTagName(hrTag))) { @@ -185,6 +185,9 @@ void InsertParagraphSeparatorCommand::doApply() // Adjust the insertion position after the delete insertionPosition = positionAvoidingSpecialElementBoundary(insertionPosition); VisiblePosition visiblePos(insertionPosition, affinity); + if (visiblePos.isNull()) + return; + calculateStyleBeforeInsertion(insertionPosition); //--------------------------------------------------------------------- @@ -207,7 +210,7 @@ void InsertParagraphSeparatorCommand::doApply() } else if (shouldUseDefaultParagraphElement(startBlock.get())) blockToInsert = createDefaultParagraphElement(document()); else - blockToInsert = startBlock->cloneElementWithoutChildren(); + blockToInsert = startBlock->cloneElementWithoutChildren(document()); //--------------------------------------------------------------------- // Handle case when position is in the last visible position in its block, @@ -227,7 +230,7 @@ void InsertParagraphSeparatorCommand::doApply() // into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted. if (m_pasteBlockqutoeIntoUnquotedArea) { if (Node* highestBlockquote = highestEnclosingNodeOfType(canonicalPos, &isMailBlockquote)) - startBlock = toElement(highestBlockquote); + startBlock = downcast<Element>(highestBlockquote); } // Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists). However, @@ -265,9 +268,8 @@ void InsertParagraphSeparatorCommand::doApply() // startBlock should always have children, otherwise isLastInBlock would be true and it's handled above. ASSERT(startBlock->firstChild()); refNode = startBlock->firstChild(); - } - else if (insertionPosition.deprecatedNode() == startBlock && nestNewBlock) { - refNode = startBlock->childNode(insertionPosition.deprecatedEditingOffset()); + } else if (insertionPosition.containerNode() == startBlock && nestNewBlock) { + refNode = startBlock->traverseToChildAt(insertionPosition.computeOffsetInContainerNode()); ASSERT(refNode); // must be true or we'd be in the end of block case } else refNode = insertionPosition.deprecatedNode(); @@ -297,7 +299,7 @@ void InsertParagraphSeparatorCommand::doApply() // it if visiblePos is at the start of a paragraph so that the // content will move down a line. if (isStartOfParagraph(visiblePos)) { - RefPtr<Element> br = createBreakElement(document()); + RefPtr<Element> br = HTMLBRElement::create(document()); insertNodeAt(br.get(), insertionPosition); insertionPosition = positionInParentAfterNode(br.get()); // If the insertion point is a break element, there is nothing else @@ -319,7 +321,7 @@ void InsertParagraphSeparatorCommand::doApply() // If the returned position lies either at the end or at the start of an element that is ignored by editing // we should move to its upstream or downstream position. - if (editingIgnoresContent(insertionPosition.deprecatedNode())) { + if (editingIgnoresContent(*insertionPosition.deprecatedNode())) { if (insertionPosition.atLastEditingPositionForNode()) insertionPosition = insertionPosition.downstream(); else if (insertionPosition.atFirstEditingPositionForNode()) @@ -331,16 +333,16 @@ void InsertParagraphSeparatorCommand::doApply() Position leadingWhitespace = insertionPosition.leadingWhitespacePosition(VP_DEFAULT_AFFINITY); // FIXME: leadingWhitespacePosition is returning the position before preserved newlines for positions // after the preserved newline, causing the newline to be turned into a nbsp. - if (leadingWhitespace.isNotNull() && leadingWhitespace.deprecatedNode()->isTextNode()) { - Text* textNode = toText(leadingWhitespace.deprecatedNode()); - ASSERT(!textNode->renderer() || textNode->renderer()->style().collapseWhiteSpace()); - replaceTextInNodePreservingMarkers(textNode, leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString()); + if (is<Text>(leadingWhitespace.deprecatedNode())) { + Text& textNode = downcast<Text>(*leadingWhitespace.deprecatedNode()); + ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace()); + replaceTextInNodePreservingMarkers(&textNode, leadingWhitespace.deprecatedEditingOffset(), 1, nonBreakingSpaceString()); } // Split at pos if in the middle of a text node. Position positionAfterSplit; - if (insertionPosition.anchorType() == Position::PositionIsOffsetInAnchor && insertionPosition.containerNode()->isTextNode()) { - RefPtr<Text> textNode = toText(insertionPosition.containerNode()); + if (insertionPosition.anchorType() == Position::PositionIsOffsetInAnchor && is<Text>(*insertionPosition.containerNode())) { + RefPtr<Text> textNode = downcast<Text>(insertionPosition.containerNode()); bool atEnd = static_cast<unsigned>(insertionPosition.offsetInContainerNode()) >= textNode->length(); if (insertionPosition.deprecatedEditingOffset() > 0 && !atEnd) { splitTextNode(textNode, insertionPosition.offsetInContainerNode()); @@ -368,7 +370,7 @@ void InsertParagraphSeparatorCommand::doApply() // created. All of the nodes, starting at visiblePos, are about to be added to the new paragraph // element. If the first node to be inserted won't be one that will hold an empty line open, add a br. if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visiblePos)) - appendNode(createBreakElement(document()).get(), blockToInsert.get()); + appendNode(HTMLBRElement::create(document()), blockToInsert.get()); // Move the start node and the siblings of the start node. if (VisiblePosition(insertionPosition) != VisiblePosition(positionBeforeNode(blockToInsert.get()))) { @@ -377,8 +379,8 @@ void InsertParagraphSeparatorCommand::doApply() n = insertionPosition.computeNodeAfterPosition(); else { Node* splitTo = insertionPosition.containerNode(); - if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode() >= caretMaxOffset(splitTo)) - splitTo = NodeTraversal::next(splitTo, startBlock.get()); + if (is<Text>(*splitTo) && insertionPosition.offsetInContainerNode() >= caretMaxOffset(*splitTo)) + splitTo = NodeTraversal::next(*splitTo, startBlock.get()); ASSERT(splitTo); splitTreeToNode(splitTo, startBlock.get()); @@ -399,8 +401,8 @@ void InsertParagraphSeparatorCommand::doApply() // Clear out all whitespace and insert one non-breaking space ASSERT(!positionAfterSplit.containerNode()->renderer() || positionAfterSplit.containerNode()->renderer()->style().collapseWhiteSpace()); deleteInsignificantTextDownstream(positionAfterSplit); - if (positionAfterSplit.deprecatedNode()->isTextNode()) - insertTextIntoNode(toText(positionAfterSplit.containerNode()), 0, nonBreakingSpaceString()); + if (is<Text>(*positionAfterSplit.deprecatedNode())) + insertTextIntoNode(downcast<Text>(positionAfterSplit.containerNode()), 0, nonBreakingSpaceString()); } } |