Commit 62b19a80 authored by akling@apple.com's avatar akling@apple.com

TypingCommand helpers should take Document&.

<https://webkit.org/b/122370>

Reviewed by Anders Carlsson.

Instead of taking a Document* and immediately asserting that it's
non-null, just take Document&.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156941 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 01ebac50
2013-10-04 Andreas Kling <akling@apple.com>
TypingCommand helpers should take Document&.
<https://webkit.org/b/122370>
Reviewed by Anders Carlsson.
Instead of taking a Document* and immediately asserting that it's
non-null, just take Document&.
2013-10-04 Ryosuke Niwa <rniwa@webkit.org>
Use more references instead of pointers in DocumentOrderedMap
......@@ -348,7 +348,7 @@ bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g
if (m_frame.selection().isRange()) {
if (isTypingAction) {
TypingCommand::deleteKeyPressed(&document(), canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity);
TypingCommand::deleteKeyPressed(document(), canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity);
revealSelectionAfterEditingOperation();
} else {
if (killRing)
......@@ -365,11 +365,11 @@ bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity g
switch (direction) {
case DirectionForward:
case DirectionRight:
TypingCommand::forwardDeleteKeyPressed(&document(), options, granularity);
TypingCommand::forwardDeleteKeyPressed(document(), options, granularity);
break;
case DirectionBackward:
case DirectionLeft:
TypingCommand::deleteKeyPressed(&document(), options, granularity);
TypingCommand::deleteKeyPressed(document(), options, granularity);
break;
}
revealSelectionAfterEditingOperation();
......@@ -990,7 +990,7 @@ bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn
options |= TypingCommand::SelectInsertedText;
if (autocorrectionWasApplied)
options |= TypingCommand::RetainAutocorrectionIndicator;
TypingCommand::insertText(&document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionConfirm : TypingCommand::TextCompositionNone);
TypingCommand::insertText(document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionConfirm : TypingCommand::TextCompositionNone);
}
// Reveal the current selection
......@@ -1014,7 +1014,7 @@ bool Editor::insertLineBreak()
VisiblePosition caret = m_frame.selection().selection().visibleStart();
bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate();
TypingCommand::insertLineBreak(&document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0);
TypingCommand::insertLineBreak(document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0);
revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded : ScrollAlignment::alignCenterIfNeeded);
return true;
......@@ -1034,7 +1034,7 @@ bool Editor::insertParagraphSeparator()
VisiblePosition caret = m_frame.selection().selection().visibleStart();
bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate();
TypingCommand::insertParagraphSeparator(&document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0);
TypingCommand::insertParagraphSeparator(document(), autocorrectionIsApplied ? TypingCommand::RetainAutocorrectionIndicator : 0);
revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded : ScrollAlignment::alignCenterIfNeeded);
return true;
......@@ -1528,7 +1528,7 @@ void Editor::setComposition(const String& text, SetCompositionMode mode)
// If text is empty, then delete the old composition here. If text is non-empty, InsertTextCommand::input
// will delete the old composition with an optimized replace operation.
if (text.isEmpty() && mode != CancelComposition)
TypingCommand::deleteSelection(&document(), 0);
TypingCommand::deleteSelection(document(), 0);
m_compositionNode = 0;
m_customCompositionUnderlines.clear();
......@@ -1599,13 +1599,13 @@ void Editor::setComposition(const String& text, const Vector<CompositionUnderlin
// If text is empty, then delete the old composition here. If text is non-empty, InsertTextCommand::input
// will delete the old composition with an optimized replace operation.
if (text.isEmpty())
TypingCommand::deleteSelection(&document(), TypingCommand::PreventSpellChecking);
TypingCommand::deleteSelection(document(), TypingCommand::PreventSpellChecking);
m_compositionNode = 0;
m_customCompositionUnderlines.clear();
if (!text.isEmpty()) {
TypingCommand::insertText(&document(), text, TypingCommand::SelectInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextCompositionUpdate);
TypingCommand::insertText(document(), text, TypingCommand::SelectInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextCompositionUpdate);
// Find out what node has the composition now.
Position base = m_frame.selection().base().downstream();
......
......@@ -329,7 +329,7 @@ static bool executeDelete(Frame& frame, Event*, EditorCommandSource source, cons
case CommandFromDOMWithUserInterface:
// If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
// Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
TypingCommand::deleteKeyPressed(frame.document(), frame.selection().granularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
TypingCommand::deleteKeyPressed(*frame.document(), frame.selection().granularity() == WordGranularity ? TypingCommand::SmartDelete : 0);
return true;
}
ASSERT_NOT_REACHED();
......@@ -466,7 +466,7 @@ static bool executeForwardDelete(Frame& frame, Event*, EditorCommandSource sourc
// Doesn't scroll to make the selection visible, or modify the kill ring.
// ForwardDelete is not implemented in IE or Firefox, so this behavior is only needed for
// backward compatibility with ourselves, and for consistency with Delete.
TypingCommand::forwardDeleteKeyPressed(frame.document());
TypingCommand::forwardDeleteKeyPressed(*frame.document());
return true;
}
ASSERT_NOT_REACHED();
......@@ -522,7 +522,7 @@ static bool executeInsertLineBreak(Frame& frame, Event* event, EditorCommandSour
// Doesn't scroll to make the selection visible, or modify the kill ring.
// InsertLineBreak is not implemented in IE or Firefox, so this behavior is only needed for
// backward compatibility with ourselves, and for consistency with other commands.
TypingCommand::insertLineBreak(frame.document(), 0);
TypingCommand::insertLineBreak(*frame.document(), 0);
return true;
}
ASSERT_NOT_REACHED();
......@@ -537,7 +537,7 @@ static bool executeInsertNewline(Frame& frame, Event* event, EditorCommandSource
static bool executeInsertNewlineInQuotedContent(Frame& frame, Event*, EditorCommandSource, const String&)
{
TypingCommand::insertParagraphSeparatorInQuotedContent(frame.document());
TypingCommand::insertParagraphSeparatorInQuotedContent(*frame.document());
return true;
}
......@@ -550,7 +550,7 @@ static bool executeInsertOrderedList(Frame& frame, Event*, EditorCommandSource,
static bool executeInsertParagraph(Frame& frame, Event*, EditorCommandSource, const String&)
{
TypingCommand::insertParagraphSeparator(frame.document(), 0);
TypingCommand::insertParagraphSeparator(*frame.document(), 0);
return true;
}
......@@ -561,7 +561,7 @@ static bool executeInsertTab(Frame& frame, Event* event, EditorCommandSource, co
static bool executeInsertText(Frame& frame, Event*, EditorCommandSource, const String& value)
{
TypingCommand::insertText(frame.document(), value, 0);
TypingCommand::insertText(*frame.document(), value, 0);
return true;
}
......
......@@ -91,11 +91,9 @@ TypingCommand::TypingCommand(Document& document, ETypingCommand commandType, con
updatePreservesTypingStyle(m_commandType);
}
void TypingCommand::deleteSelection(Document* document, Options options)
void TypingCommand::deleteSelection(Document& document, Options options)
{
ASSERT(document);
Frame* frame = document->frame();
Frame* frame = document.frame();
ASSERT(frame);
if (!frame->selection().isRange())
......@@ -107,29 +105,27 @@ void TypingCommand::deleteSelection(Document* document, Options options)
return;
}
TypingCommand::create(*document, DeleteSelection, "", options)->apply();
TypingCommand::create(document, DeleteSelection, "", options)->apply();
}
void TypingCommand::deleteKeyPressed(Document *document, Options options, TextGranularity granularity)
void TypingCommand::deleteKeyPressed(Document& document, Options options, TextGranularity granularity)
{
ASSERT(document);
if (granularity == CharacterGranularity) {
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document->frame())) {
updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document->frame());
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document.frame());
lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
lastTypingCommand->deleteKeyPressed(granularity, options & KillRing);
return;
}
}
TypingCommand::create(*document, DeleteKey, "", options, granularity)->apply();
TypingCommand::create(document, DeleteKey, "", options, granularity)->apply();
}
void TypingCommand::forwardDeleteKeyPressed(Document *document, Options options, TextGranularity granularity)
void TypingCommand::forwardDeleteKeyPressed(Document& document, Options options, TextGranularity granularity)
{
// FIXME: Forward delete in TextEdit appears to open and close a new typing command.
ASSERT(document);
Frame* frame = document->frame();
Frame* frame = document.frame();
if (granularity == CharacterGranularity) {
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(frame)) {
updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), frame);
......@@ -139,7 +135,7 @@ void TypingCommand::forwardDeleteKeyPressed(Document *document, Options options,
}
}
TypingCommand::create(*document, ForwardDeleteKey, "", options, granularity)->apply();
TypingCommand::create(document, ForwardDeleteKey, "", options, granularity)->apply();
}
void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand* typingCommand, Frame* frame)
......@@ -153,25 +149,21 @@ void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand
typingCommand->setEndingSelection(currentSelection);
}
void TypingCommand::insertText(Document* document, const String& text, Options options, TextCompositionType composition)
void TypingCommand::insertText(Document& document, const String& text, Options options, TextCompositionType composition)
{
ASSERT(document);
Frame* frame = document->frame();
Frame* frame = document.frame();
ASSERT(frame);
if (!text.isEmpty())
document->frame()->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text.characters()[0]));
frame->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text.characters()[0]));
insertText(document, text, frame->selection().selection(), options, composition);
}
// FIXME: We shouldn't need to take selectionForInsertion. It should be identical to FrameSelection's current selection.
void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType)
void TypingCommand::insertText(Document& document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType)
{
ASSERT(document);
RefPtr<Frame> frame = document->frame();
RefPtr<Frame> frame = document.frame();
ASSERT(frame);
VisibleSelection currentSelection = frame->selection().selection();
......@@ -194,43 +186,40 @@ void TypingCommand::insertText(Document* document, const String& text, const Vis
return;
}
RefPtr<TypingCommand> cmd = TypingCommand::create(*document, InsertText, newText, options, compositionType);
RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSelection);
}
void TypingCommand::insertLineBreak(Document *document, Options options)
void TypingCommand::insertLineBreak(Document& document, Options options)
{
ASSERT(document);
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document->frame())) {
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
lastTypingCommand->insertLineBreak();
return;
}
applyCommand(TypingCommand::create(*document, InsertLineBreak, "", options));
applyCommand(TypingCommand::create(document, InsertLineBreak, "", options));
}
void TypingCommand::insertParagraphSeparatorInQuotedContent(Document *document)
void TypingCommand::insertParagraphSeparatorInQuotedContent(Document& document)
{
ASSERT(document);
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document->frame())) {
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
lastTypingCommand->insertParagraphSeparatorInQuotedContent();
return;
}
applyCommand(TypingCommand::create(*document, InsertParagraphSeparatorInQuotedContent));
applyCommand(TypingCommand::create(document, InsertParagraphSeparatorInQuotedContent));
}
void TypingCommand::insertParagraphSeparator(Document *document, Options options)
void TypingCommand::insertParagraphSeparator(Document& document, Options options)
{
ASSERT(document);
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document->frame())) {
if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document.frame())) {
lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
lastTypingCommand->insertParagraphSeparator();
return;
}
applyCommand(TypingCommand::create(*document, InsertParagraphSeparator, "", options));
applyCommand(TypingCommand::create(document, InsertParagraphSeparator, "", options));
}
PassRefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(Frame* frame)
......
......@@ -57,14 +57,14 @@ public:
};
typedef unsigned Options;
static void deleteSelection(Document*, Options = 0);
static void deleteKeyPressed(Document*, Options = 0, TextGranularity = CharacterGranularity);
static void forwardDeleteKeyPressed(Document*, Options = 0, TextGranularity = CharacterGranularity);
static void insertText(Document*, const String&, Options, TextCompositionType = TextCompositionNone);
static void insertText(Document*, const String&, const VisibleSelection&, Options, TextCompositionType = TextCompositionNone);
static void insertLineBreak(Document*, Options);
static void insertParagraphSeparator(Document*, Options);
static void insertParagraphSeparatorInQuotedContent(Document*);
static void deleteSelection(Document&, Options = 0);
static void deleteKeyPressed(Document&, Options = 0, TextGranularity = CharacterGranularity);
static void forwardDeleteKeyPressed(Document&, Options = 0, TextGranularity = CharacterGranularity);
static void insertText(Document&, const String&, Options, TextCompositionType = TextCompositionNone);
static void insertText(Document&, const String&, const VisibleSelection&, Options, TextCompositionType = TextCompositionNone);
static void insertLineBreak(Document&, Options);
static void insertParagraphSeparator(Document&, Options);
static void insertParagraphSeparatorInQuotedContent(Document&);
static void closeTyping(Frame*);
void insertText(const String &text, bool selectInsertedText);
......
......@@ -100,7 +100,7 @@ void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText)
bool Editor::insertParagraphSeparatorInQuotedContent()
{
// FIXME: Why is this missing calls to canEdit, canEditRichly, etc.?
TypingCommand::insertParagraphSeparatorInQuotedContent(&document());
TypingCommand::insertParagraphSeparatorInQuotedContent(document());
revealSelectionAfterEditingOperation();
return true;
}
......
......@@ -192,7 +192,8 @@ static void insertUnicodeCharacter(UChar character, Frame* frame)
if (!frame->editor().shouldInsertText(text, frame->selection().toNormalizedRange().get(), EditorInsertActionTyped))
return;
TypingCommand::insertText(frame->document(), text, 0, TypingCommand::TextCompositionNone);
ASSERT(frame->document());
TypingCommand::insertText(*frame->document(), text, 0, TypingCommand::TextCompositionNone);
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment