#include "core/editing/Editor.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
-#include "core/frame/Frame.h"
+#include "core/frame/LocalFrame.h"
+#include "core/html/HTMLSpanElement.h"
-namespace WebCore {
+namespace blink {
InsertTextCommand::InsertTextCommand(Document& document, const String& text, bool selectInsertedText, RebalanceType rebalanceType)
: CompositeEditCommand(document)
Position InsertTextCommand::positionInsideTextNode(const Position& p)
{
Position pos = p;
- if (isTabSpanTextNode(pos.anchorNode())) {
- RefPtr<Node> textNode = document().createEditingTextNode("");
+ if (isTabHTMLSpanElementTextNode(pos.anchorNode())) {
+ RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("");
insertNodeAtTabSpanPosition(textNode.get(), pos);
return firstPositionInNode(textNode.get());
}
// 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("");
+ RefPtrWillBeRawPtr<Text> textNode = document().createEditingTextNode("");
insertNodeAt(textNode.get(), pos);
return firstPositionInNode(textNode.get());
}
bool InsertTextCommand::performOverwrite(const String& text, bool selectInsertedText)
{
Position start = endingSelection().start();
- RefPtr<Text> textNode = start.containerText();
+ RefPtrWillBeRawPtr<Text> textNode = start.containerText();
if (!textNode)
return false;
if (endingSelection().isRange()) {
if (performTrivialReplace(m_text, m_selectInsertedText))
return;
+ bool endOfSelectionWasAtStartOfBlock = isStartOfBlock(endingSelection().visibleEnd());
deleteSelection(false, true, false, false);
// deleteSelection eventually makes a new endingSelection out of a Position. If that Position doesn't have
// a renderer (e.g. it is on a <frameset> in the DOM), the VisibleSelection cannot be canonicalized to
// anything other than NoSelection. The rest of this function requires a real endingSelection, so bail out.
if (endingSelection().isNone())
return;
+ if (endOfSelectionWasAtStartOfBlock) {
+ if (EditingStyle* typingStyle = document().frame()->selection().typingStyle())
+ typingStyle->removeBlockProperties();
+ }
} else if (document().frame()->editor().isOverwriteModeEnabled()) {
if (performOverwrite(m_text, m_selectInsertedText))
return;
// It is possible for the node that contains startPosition to contain only unrendered whitespace,
// and so deleteInsignificantText could remove it. Save the position before the node in case that happens.
- Position positionBeforeStartNode(positionInParentBeforeNode(startPosition.containerNode()));
+ ASSERT(startPosition.containerNode());
+ Position positionBeforeStartNode(positionInParentBeforeNode(*startPosition.containerNode()));
deleteInsignificantText(startPosition, startPosition.downstream());
if (!startPosition.inDocument())
startPosition = positionBeforeStartNode;
ASSERT(startPosition.containerNode()->isTextNode());
if (placeholder.isNotNull())
removePlaceholderAt(placeholder);
- RefPtr<Text> textNode = startPosition.containerText();
+ RefPtrWillBeRawPtr<Text> textNode = startPosition.containerText();
const unsigned offset = startPosition.offsetInContainerNode();
insertTextIntoNode(textNode, offset, m_text);
setEndingSelectionWithoutValidation(startPosition, endPosition);
// Handle the case where there is a typing style.
- if (RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingStyle()) {
+ if (RefPtrWillBeRawPtr<EditingStyle> typingStyle = document().frame()->selection().typingStyle()) {
typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection);
if (!typingStyle->isEmpty())
applyStyle(typingStyle.get());
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;
+ unsigned offset = node->isTextNode() ? insertPos.offsetInContainerNode() : 0;
// keep tabs coalesced in tab span
- if (isTabSpanTextNode(node)) {
- RefPtr<Text> textNode = toText(node);
+ if (isTabHTMLSpanElementTextNode(node)) {
+ RefPtrWillBeRawPtr<Text> textNode = toText(node);
insertTextIntoNode(textNode, offset, "\t");
return Position(textNode.release(), offset + 1);
}
// create new tab span
- RefPtr<Element> spanNode = createTabSpanElement(document());
+ RefPtrWillBeRawPtr<HTMLSpanElement> spanElement = createTabSpanElement(document());
// place it
if (!node->isTextNode()) {
- insertNodeAt(spanNode.get(), insertPos);
+ insertNodeAt(spanElement.get(), insertPos);
} else {
- RefPtr<Text> textNode = toText(node);
+ RefPtrWillBeRawPtr<Text> textNode = toText(node);
if (offset >= textNode->length())
- insertNodeAfter(spanNode, textNode.release());
+ insertNodeAfter(spanElement, textNode.release());
else {
// split node to make room for the span
// NOTE: splitTextNode uses textNode for the
// insert the span before it.
if (offset > 0)
splitTextNode(textNode, offset);
- insertNodeBefore(spanNode, textNode.release());
+ insertNodeBefore(spanElement, textNode.release());
}
}
// return the position following the new tab
- return lastPositionInNode(spanNode.get());
+ return lastPositionInNode(spanElement.get());
}
}