#include "config.h"
#include "core/editing/TypingCommand.h"
-#include "HTMLNames.h"
+#include "core/HTMLNames.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/ElementTraversal.h"
#include "core/html/HTMLBRElement.h"
#include "core/rendering/RenderObject.h"
-namespace WebCore {
+namespace blink {
using namespace HTMLNames;
if (!frame->selection().isRange())
return;
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
lastTypingCommand->deleteSelection(options & SmartDelete);
return;
{
if (granularity == CharacterGranularity) {
LocalFrame* frame = document.frame();
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
// If the last typing command is not Delete, open a new typing command.
// We need to group continuous delete commands alone in a single typing command.
if (lastTypingCommand->commandTypeOfOpenCommand() == DeleteKey) {
// FIXME: Forward delete in TextEdit appears to open and close a new typing command.
if (granularity == CharacterGranularity) {
LocalFrame* frame = document.frame();
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), frame);
lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
lastTypingCommand->forwardDeleteKeyPressed(granularity, options & KillRing);
// Set the starting and ending selection appropriately if we are using a selection
// that is different from the current selection. In the future, we should change EditCommand
// to deal with custom selections in a general way that can be used by all of the commands.
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame.get())) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame.get())) {
if (lastTypingCommand->endingSelection() != selectionForInsertion) {
lastTypingCommand->setStartingSelection(selectionForInsertion);
lastTypingCommand->setEndingSelection(selectionForInsertion);
return;
}
- RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
+ RefPtrWillBeRawPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSelection);
}
void TypingCommand::insertLineBreak(Document& document, Options options)
{
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
lastTypingCommand->insertLineBreak();
return;
void TypingCommand::insertParagraphSeparatorInQuotedContent(Document& document)
{
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
lastTypingCommand->insertParagraphSeparatorInQuotedContent();
return;
}
void TypingCommand::insertParagraphSeparator(Document& document, Options options)
{
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
lastTypingCommand->insertParagraphSeparator();
return;
TypingCommand::create(document, InsertParagraphSeparator, "", options)->apply();
}
-PassRefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(LocalFrame* frame)
+PassRefPtrWillBeRawPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(LocalFrame* frame)
{
ASSERT(frame);
- RefPtr<CompositeEditCommand> lastEditCommand = frame->editor().lastEditCommand();
+ RefPtrWillBeRawPtr<CompositeEditCommand> lastEditCommand = frame->editor().lastEditCommand();
if (!lastEditCommand || !lastEditCommand->isTypingCommand() || !static_cast<TypingCommand*>(lastEditCommand.get())->isOpenForMoreTyping())
return nullptr;
void TypingCommand::closeTyping(LocalFrame* frame)
{
- if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame))
+ if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame))
lastTypingCommand->closeTyping();
}
// get this by being at the end of a word and typing a space.
VisiblePosition start(endingSelection().start(), endingSelection().affinity());
VisiblePosition previous = start.previous();
- if (previous.isNotNull()) {
- VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary);
+
+ VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary);
+
+ if (commandType == InsertParagraphSeparator) {
+ VisiblePosition p2 = nextWordPosition(start);
+ VisibleSelection words(p1, endOfWord(p2));
+ frame->spellChecker().markMisspellingsAfterLineBreak(words);
+ } else if (previous.isNotNull()) {
VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary);
if (p1 != p2)
frame->spellChecker().markMisspellingsAfterTypingToWord(p1, endingSelection());
void TypingCommand::insertTextRunWithoutNewlines(const String &text, bool selectInsertedText)
{
- RefPtr<InsertTextCommand> command = InsertTextCommand::create(document(), text, selectInsertedText,
+ RefPtrWillBeRawPtr<InsertTextCommand> command = InsertTextCommand::create(document(), text, selectInsertedText,
m_compositionType == TextCompositionNone ? InsertTextCommand::RebalanceLeadingAndTrailingWhitespaces : InsertTextCommand::RebalanceAllWhitespaces);
applyCommandToComposite(command, endingSelection());
bool TypingCommand::makeEditableRootEmpty()
{
Element* root = endingSelection().rootEditableElement();
- if (!root || !root->firstChild())
+ if (!root || !root->hasChildren())
return false;
if (root->firstChild() == root->lastChild()) {
m_smartDelete = false;
- FrameSelection selection;
- selection.setSelection(endingSelection());
- selection.modify(FrameSelection::AlterationExtend, DirectionBackward, granularity);
- if (killRing && selection.isCaret() && granularity != CharacterGranularity)
- selection.modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity);
+ OwnPtrWillBeRawPtr<FrameSelection> selection = FrameSelection::create();
+ selection->setSelection(endingSelection());
+ selection->modify(FrameSelection::AlterationExtend, DirectionBackward, granularity);
+ if (killRing && selection->isCaret() && granularity != CharacterGranularity)
+ selection->modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity);
VisiblePosition visibleStart(endingSelection().visibleStart());
if (visibleStart.previous(CannotCrossEditingBoundary).isNull()) {
if (isLastPositionBeforeTable(visibleStart))
return;
// Extend the selection backward into the last cell, then deletion will handle the move.
- selection.modify(FrameSelection::AlterationExtend, DirectionBackward, granularity);
+ selection->modify(FrameSelection::AlterationExtend, DirectionBackward, granularity);
// If the caret is just after a table, select the table and don't delete anything.
- } else if (Node* table = isFirstPositionAfterTable(visibleStart)) {
+ } else if (Element* table = isFirstPositionAfterTable(visibleStart)) {
setEndingSelection(VisibleSelection(positionBeforeNode(table), endingSelection().start(), DOWNSTREAM, endingSelection().isDirectional()));
typingAddedToOpenCommand(DeleteKey);
return;
}
- selectionToDelete = selection.selection();
+ selectionToDelete = selection->selection();
if (granularity == CharacterGranularity && selectionToDelete.end().containerNode() == selectionToDelete.start().containerNode()
&& selectionToDelete.end().computeOffsetInContainerNode() - selectionToDelete.start().computeOffsetInContainerNode() > 1) {
// Handle delete at beginning-of-block case.
// Do nothing in the case that the caret is at the start of a
// root editable element or at the start of a document.
- FrameSelection selection;
- selection.setSelection(endingSelection());
- selection.modify(FrameSelection::AlterationExtend, DirectionForward, granularity);
- if (killRing && selection.isCaret() && granularity != CharacterGranularity)
- selection.modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
+ OwnPtrWillBeRawPtr<FrameSelection> selection = FrameSelection::create();
+ selection->setSelection(endingSelection());
+ selection->modify(FrameSelection::AlterationExtend, DirectionForward, granularity);
+ if (killRing && selection->isCaret() && granularity != CharacterGranularity)
+ selection->modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
Position downstreamEnd = endingSelection().end().downstream();
VisiblePosition visibleEnd = endingSelection().visibleEnd();
if (visibleEnd == endOfParagraph(visibleEnd))
downstreamEnd = visibleEnd.next(CannotCrossEditingBoundary).deepEquivalent().downstream();
// When deleting tables: Select the table first, then perform the deletion
- if (isRenderedTable(downstreamEnd.containerNode()) && downstreamEnd.computeOffsetInContainerNode() <= caretMinOffset(downstreamEnd.containerNode())) {
+ if (isRenderedTableElement(downstreamEnd.containerNode()) && downstreamEnd.computeOffsetInContainerNode() <= caretMinOffset(downstreamEnd.containerNode())) {
setEndingSelection(VisibleSelection(endingSelection().end(), positionAfterNode(downstreamEnd.containerNode()), DOWNSTREAM, endingSelection().isDirectional()));
typingAddedToOpenCommand(ForwardDeleteKey);
return;
}
// deleting to end of paragraph when at end of paragraph needs to merge the next paragraph (if any)
- if (granularity == ParagraphBoundary && selection.selection().isCaret() && isEndOfParagraph(selection.selection().visibleEnd()))
- selection.modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
+ if (granularity == ParagraphBoundary && selection->selection().isCaret() && isEndOfParagraph(selection->selection().visibleEnd()))
+ selection->modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
- selectionToDelete = selection.selection();
+ selectionToDelete = selection->selection();
if (!startingSelection().isRange() || selectionToDelete.base() != startingSelection().start())
selectionAfterUndo = selectionToDelete;
else {
return true;
}
-} // namespace WebCore
+} // namespace blink