summaryrefslogtreecommitdiff
path: root/Source/WebCore/editing/InsertLineBreakCommand.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/editing/InsertLineBreakCommand.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/editing/InsertLineBreakCommand.cpp')
-rw-r--r--Source/WebCore/editing/InsertLineBreakCommand.cpp80
1 files changed, 40 insertions, 40 deletions
diff --git a/Source/WebCore/editing/InsertLineBreakCommand.cpp b/Source/WebCore/editing/InsertLineBreakCommand.cpp
index 3cc8996d0..812c0b46f 100644
--- a/Source/WebCore/editing/InsertLineBreakCommand.cpp
+++ b/Source/WebCore/editing/InsertLineBreakCommand.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
@@ -29,7 +29,8 @@
#include "Document.h"
#include "Frame.h"
#include "FrameSelection.h"
-#include "HTMLElement.h"
+#include "HTMLBRElement.h"
+#include "HTMLHRElement.h"
#include "HTMLNames.h"
#include "HTMLTableElement.h"
#include "RenderElement.h"
@@ -52,45 +53,45 @@ bool InsertLineBreakCommand::preservesTypingStyle() const
return true;
}
-void InsertLineBreakCommand::insertNodeAfterPosition(Node* node, const Position& pos)
+void InsertLineBreakCommand::insertNodeAfterPosition(Node* node, const Position& position)
{
// Insert the BR after the caret position. In the case the
// position is a block, do an append. We don't want to insert
// the BR *after* the block.
- Element* cb = deprecatedEnclosingBlockFlowElement(pos.deprecatedNode());
- if (cb == pos.deprecatedNode())
- appendNode(node, cb);
+ auto* element = deprecatedEnclosingBlockFlowElement(position.deprecatedNode());
+ if (element == position.deprecatedNode())
+ appendNode(node, element);
else
- insertNodeAfter(node, pos.deprecatedNode());
+ insertNodeAfter(node, position.deprecatedNode());
}
-void InsertLineBreakCommand::insertNodeBeforePosition(Node* node, const Position& pos)
+void InsertLineBreakCommand::insertNodeBeforePosition(Node* node, const Position& position)
{
// Insert the BR after the caret position. In the case the
// position is a block, do an append. We don't want to insert
// the BR *before* the block.
- Element* cb = deprecatedEnclosingBlockFlowElement(pos.deprecatedNode());
- if (cb == pos.deprecatedNode())
- appendNode(node, cb);
+ auto* element = deprecatedEnclosingBlockFlowElement(position.deprecatedNode());
+ if (element == position.deprecatedNode())
+ appendNode(node, element);
else
- insertNodeBefore(node, pos.deprecatedNode());
+ insertNodeBefore(node, position.deprecatedNode());
}
// Whether we should insert a break element or a '\n'.
-bool InsertLineBreakCommand::shouldUseBreakElement(const Position& insertionPos)
+bool InsertLineBreakCommand::shouldUseBreakElement(const Position& position)
{
// An editing position like [input, 0] actually refers to the position before
// the input element, and in that case we need to check the input element's
// parent's renderer.
- Position p(insertionPos.parentAnchoredEquivalent());
- return p.deprecatedNode()->renderer() && !p.deprecatedNode()->renderer()->style().preserveNewline();
+ auto* node = position.parentAnchoredEquivalent().deprecatedNode();
+ return node->renderer() && !node->renderer()->style().preserveNewline();
}
void InsertLineBreakCommand::doApply()
{
deleteSelection();
VisibleSelection selection = endingSelection();
- if (!selection.isNonOrphanedCaretOrRange())
+ if (selection.isNoneOrOrphaned())
return;
VisiblePosition caret(selection.visibleStart());
@@ -99,60 +100,59 @@ void InsertLineBreakCommand::doApply()
if (caret.isNull())
return;
- Position pos(caret.deepEquivalent());
+ Position position(caret.deepEquivalent());
- pos = positionAvoidingSpecialElementBoundary(pos);
-
- pos = positionOutsideTabSpan(pos);
+ position = positionAvoidingSpecialElementBoundary(position);
+ position = positionOutsideTabSpan(position);
RefPtr<Node> nodeToInsert;
- if (shouldUseBreakElement(pos))
- nodeToInsert = createBreakElement(document());
+ if (shouldUseBreakElement(position))
+ nodeToInsert = HTMLBRElement::create(document());
else
nodeToInsert = document().createTextNode("\n");
// FIXME: Need to merge text nodes when inserting just after or before text.
if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) {
- bool needExtraLineBreak = !pos.deprecatedNode()->hasTagName(hrTag) && !isHTMLTableElement(pos.deprecatedNode());
+ bool needExtraLineBreak = !is<HTMLHRElement>(*position.deprecatedNode()) && !is<HTMLTableElement>(*position.deprecatedNode());
- insertNodeAt(nodeToInsert.get(), pos);
+ insertNodeAt(nodeToInsert.get(), position);
if (needExtraLineBreak)
insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert);
VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get()));
setEndingSelection(VisibleSelection(endingPosition, endingSelection().isDirectional()));
- } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNode())) {
- insertNodeAt(nodeToInsert.get(), pos);
+ } else if (position.deprecatedEditingOffset() <= caretMinOffset(*position.deprecatedNode())) {
+ insertNodeAt(nodeToInsert.get(), position);
// Insert an extra br or '\n' if the just inserted one collapsed.
if (!isStartOfParagraph(positionBeforeNode(nodeToInsert.get())))
- insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.get());
+ insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert.get());
setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInsert.get()), DOWNSTREAM, endingSelection().isDirectional()));
// If we're inserting after all of the rendered text in a text node, or into a non-text node,
// a simple insertion is sufficient.
- } else if (pos.deprecatedEditingOffset() >= caretMaxOffset(pos.deprecatedNode()) || !pos.deprecatedNode()->isTextNode()) {
- insertNodeAt(nodeToInsert.get(), pos);
+ } else if (position.deprecatedEditingOffset() >= caretMaxOffset(*position.deprecatedNode()) || !is<Text>(*position.deprecatedNode())) {
+ insertNodeAt(nodeToInsert.get(), position);
setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInsert.get()), DOWNSTREAM, endingSelection().isDirectional()));
- } else if (pos.deprecatedNode()->isTextNode()) {
+ } else if (is<Text>(*position.deprecatedNode())) {
// Split a text node
- Text* textNode = toText(pos.deprecatedNode());
- splitTextNode(textNode, pos.deprecatedEditingOffset());
- insertNodeBefore(nodeToInsert, textNode);
- Position endingPosition = firstPositionInNode(textNode);
+ Text& textNode = downcast<Text>(*position.deprecatedNode());
+ splitTextNode(&textNode, position.deprecatedEditingOffset());
+ insertNodeBefore(nodeToInsert, &textNode);
+ Position endingPosition = firstPositionInNode(&textNode);
// Handle whitespace that occurs after the split
document().updateLayoutIgnorePendingStylesheets();
if (!endingPosition.isRenderedCharacter()) {
- Position positionBeforeTextNode(positionInParentBeforeNode(textNode));
+ Position positionBeforeTextNode(positionInParentBeforeNode(&textNode));
// Clear out all whitespace and insert one non-breaking space
deleteInsignificantTextDownstream(endingPosition);
- ASSERT(!textNode->renderer() || textNode->renderer()->style().collapseWhiteSpace());
+ ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace());
// Deleting insignificant whitespace will remove textNode if it contains nothing but insignificant whitespace.
- if (textNode->inDocument())
- insertTextIntoNode(textNode, 0, nonBreakingSpaceString());
+ if (textNode.isConnected())
+ insertTextIntoNode(&textNode, 0, nonBreakingSpaceString());
else {
RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpaceString());
insertNodeAt(nbspNode.get(), positionBeforeTextNode);