Give EditCommand a protected Frame& getter.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Sep 2013 14:57:23 +0000 (14:57 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Sep 2013 14:57:23 +0000 (14:57 +0000)
<https://webkit.org/b/120574>

Reviewed by Darin Adler.

EditCommand is only created for documents that are attached to a Frame,
we already ASSERTed as much in the EditCommand constructor.

This patch adds a "Frame& EditCommand::frame()" helper, so EditCommand
and its subclasses don't have to fumble around with pointers.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154943 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/DeleteSelectionCommand.cpp
Source/WebCore/editing/EditCommand.cpp
Source/WebCore/editing/EditCommand.h
Source/WebCore/editing/InsertLineBreakCommand.cpp
Source/WebCore/editing/InsertTextCommand.cpp
Source/WebCore/editing/RemoveFormatCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/SetSelectionCommand.cpp
Source/WebCore/editing/SpellingCorrectionCommand.cpp
Source/WebCore/editing/TypingCommand.cpp

index c5b23be..f070308 100644 (file)
@@ -1,3 +1,16 @@
+2013-09-01  Andreas Kling  <akling@apple.com>
+
+        Give EditCommand a protected Frame& getter.
+        <https://webkit.org/b/120574>
+
+        Reviewed by Darin Adler.
+
+        EditCommand is only created for documents that are attached to a Frame,
+        we already ASSERTed as much in the EditCommand constructor.
+
+        This patch adds a "Frame& EditCommand::frame()" helper, so EditCommand
+        and its subclasses don't have to fumble around with pointers.
+
 2013-08-31  Antti Koivisto  <antti@apple.com>
 
         Add element ancestor iterator
index 9a4eddc..486920d 100644 (file)
@@ -205,12 +205,10 @@ void CompositeEditCommand::apply()
     // if one is necessary (like for the creation of VisiblePositions).
     document().updateLayoutIgnorePendingStylesheets();
 
-    Frame* frame = document().frame();
-    ASSERT(frame);
     {
         EventQueueScope scope;
 #if ENABLE(DELETION_UI)
-        DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(frame);
+        DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(&frame());
 #endif
         doApply();
     }
@@ -218,7 +216,7 @@ void CompositeEditCommand::apply()
     // Only need to call appliedEditing for top-level commands,
     // and TypingCommands do it on their own (see TypingCommand::typingAddedToOpenCommand).
     if (!isTypingCommand())
-        frame->editor().appliedEditing(this);
+        frame().editor().appliedEditing(this);
     setShouldRetainAutocorrectionIndicator(false);
 }
 
@@ -1216,7 +1214,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
     // FIXME (5098931): We should add a new insert action "WebViewInsertActionMoved" and call shouldInsertFragment here.
     
     setEndingSelection(VisibleSelection(start, end, DOWNSTREAM));
-    document().frame()->editor().clearMisspellingsAndBadGrammar(endingSelection());
+    frame().editor().clearMisspellingsAndBadGrammar(endingSelection());
     deleteSelection(false, false, false, false);
 
     ASSERT(destination.deepEquivalent().anchorNode()->inDocument());
@@ -1249,7 +1247,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
         options |= ReplaceSelectionCommand::MatchStyle;
     applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment, options));
 
-    document().frame()->editor().markMisspellingsAndBadGrammar(endingSelection());
+    frame().editor().markMisspellingsAndBadGrammar(endingSelection());
 
     // If the selection is in an empty paragraph, restore styles from the old empty paragraph to the new empty paragraph.
     bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfParagraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().visibleStart());
index c6f7170..1e6e770 100644 (file)
@@ -655,7 +655,7 @@ void DeleteSelectionCommand::mergeParagraphs()
     
     RefPtr<Range> range = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
     RefPtr<Range> rangeToBeReplaced = Range::create(&document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
-    if (!document().frame()->editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
+    if (!frame().editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
         return;
     
     // moveParagraphs will insert placeholders if it removes blocks that would require their use, don't let block
@@ -728,7 +728,7 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete()
     // In this case if we start typing, the new characters should have the same style as the just deleted ones,
     // but, if we change the selection, come back and start typing that style should be lost.  Also see 
     // preserveTypingStyle() below.
-    document().frame()->selection().setTypingStyle(m_typingStyle);
+    frame().selection().setTypingStyle(m_typingStyle);
 }
 
 void DeleteSelectionCommand::clearTransientState()
@@ -801,7 +801,7 @@ void DeleteSelectionCommand::doApply()
     if (!m_replace) {
         Element* textControl = enclosingTextFormControl(m_selectionToDelete.start());
         if (textControl && textControl->focused())
-            document().frame()->editor().textWillBeDeletedInTextField(textControl);
+            frame().editor().textWillBeDeletedInTextField(textControl);
     }
 
     // save this to later make the selection with
@@ -859,10 +859,8 @@ void DeleteSelectionCommand::doApply()
 
     calculateTypingStyleAfterDelete();
 
-    if (!originalString.isEmpty()) {
-        if (Frame* frame = document().frame())
-            frame->editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
-    }
+    if (!originalString.isEmpty())
+        frame().editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
 
     setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSelection().isDirectional()));
     clearTransientState();
index 6f0ec54..4a4db3e 100644 (file)
@@ -61,6 +61,12 @@ EditCommand::~EditCommand()
 {
 }
 
+Frame& EditCommand::frame() const
+{
+    ASSERT(document().frame());
+    return *document().frame();
+}
+
 EditAction EditCommand::editingAction() const
 {
     return EditActionUnspecified;
index 8e9cbe4..7f232dd 100644 (file)
@@ -38,6 +38,7 @@ namespace WebCore {
 class CompositeEditCommand;
 class Document;
 class Element;
+class Frame;
 
 class EditCommand : public RefCounted<EditCommand> {
 public:
@@ -61,6 +62,7 @@ protected:
     explicit EditCommand(Document&);
     EditCommand(Document&, const VisibleSelection&, const VisibleSelection&);
 
+    Frame& frame() const;
     Document& document() const { return *m_document; }
     CompositeEditCommand* parent() const { return m_parent; }
     void setStartingSelection(const VisibleSelection&);
index 1a33888..a770409 100644 (file)
@@ -167,7 +167,7 @@ void InsertLineBreakCommand::doApply()
 
     // Handle the case where there is a typing style.
 
-    RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingStyle();
+    RefPtr<EditingStyle> typingStyle = frame().selection().typingStyle();
 
     if (typingStyle && !typingStyle->isEmpty()) {
         // Apply the typing style to the inserted line break, so that if the selection
index 09e4f87..7615cf0 100644 (file)
@@ -146,7 +146,7 @@ void InsertTextCommand::doApply()
         // anything other than NoSelection. The rest of this function requires a real endingSelection, so bail out.
         if (endingSelection().isNone())
             return;
-    } else if (document().frame()->editor().isOverwriteModeEnabled()) {
+    } else if (frame().editor().isOverwriteModeEnabled()) {
         if (performOverwrite(m_text, m_selectInsertedText))
             return;
     }
@@ -222,7 +222,7 @@ void InsertTextCommand::doApply()
     setEndingSelectionWithoutValidation(startPosition, endPosition);
 
     // Handle the case where there is a typing style.
-    if (RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingStyle()) {
+    if (RefPtr<EditingStyle> typingStyle = frame().selection().typingStyle()) {
         typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection);
         if (!typingStyle->isEmpty())
             applyStyle(typingStyle.get());
index eaa7550..5e50f8a 100644 (file)
@@ -79,14 +79,12 @@ static bool isElementForRemoveFormatCommand(const Element* element)
 
 void RemoveFormatCommand::doApply()
 {
-    Frame* frame = document().frame();
-
-    if (!frame->selection().selection().isNonOrphanedCaretOrRange())
+    if (!frame().selection().selection().isNonOrphanedCaretOrRange())
         return;
 
     // Get the default style for this editable root, it's the style that we'll give the
     // content that we're operating on.
-    Node* root = frame->selection().rootEditableElement();
+    Node* root = frame().selection().rootEditableElement();
     RefPtr<EditingStyle> defaultStyle = EditingStyle::create(root);
 
     // We want to remove everything but transparent background.
index ed41526..7a68676 100644 (file)
@@ -1012,8 +1012,7 @@ void ReplaceSelectionCommand::doApply()
     
     // FIXME: Can this wait until after the operation has been performed?  There doesn't seem to be
     // any work performed after this that queries or uses the typing style.
-    if (Frame* frame = document().frame())
-        frame->selection().clearTypingStyle();
+    frame().selection().clearTypingStyle();
 
     removeHeadContents(fragment);
 
index 88ddcec..f153a8d 100644 (file)
@@ -40,7 +40,7 @@ SetSelectionCommand::SetSelectionCommand(const VisibleSelection& selection, Fram
 
 void SetSelectionCommand::doApply()
 {
-    FrameSelection& selection = document().frame()->selection();
+    FrameSelection& selection = frame().selection();
 
     if (selection.shouldChangeSelection(m_selectionToSet) && m_selectionToSet.isNonOrphanedCaretOrRange()) {
         selection.setSelection(m_selectionToSet, m_options);
@@ -50,7 +50,7 @@ void SetSelectionCommand::doApply()
 
 void SetSelectionCommand::doUnapply()
 {
-    FrameSelection& selection = document().frame()->selection();
+    FrameSelection& selection = frame().selection();
 
     if (selection.shouldChangeSelection(startingSelection()) && startingSelection().isNonOrphanedCaretOrRange())
         selection.setSelection(startingSelection(), m_options);
index cd73ff8..2d966d1 100644 (file)
@@ -63,7 +63,7 @@ private:
     virtual void doUnapply() OVERRIDE
     {
         if (!m_hasBeenUndone) {
-            document().frame()->editor().unappliedSpellCorrection(startingSelection(), m_corrected, m_correction);
+            frame().editor().unappliedSpellCorrection(startingSelection(), m_corrected, m_correction);
             m_hasBeenUndone = true;
         }
         
@@ -95,7 +95,7 @@ void SpellingCorrectionCommand::doApply()
     if (!m_corrected.length())
         return;
 
-    if (!document().frame()->selection().shouldChangeSelection(m_selectionToBeCorrected))
+    if (!frame().selection().shouldChangeSelection(m_selectionToBeCorrected))
         return;
 
     RefPtr<DocumentFragment> fragment = createFragmentFromText(m_rangeToBeCorrected.get(), m_correction);
index a39fe18..01b2f8d 100644 (file)
@@ -293,19 +293,17 @@ EditAction TypingCommand::editingAction() const
 
 void TypingCommand::markMisspellingsAfterTyping(ETypingCommand commandType)
 {
-    Frame* frame = document().frame();
-    if (!frame)
-        return;
+    Frame& frame = this->frame();
 
 #if PLATFORM(MAC)
-    if (!frame->editor().isContinuousSpellCheckingEnabled()
-        && !frame->editor().isAutomaticQuoteSubstitutionEnabled()
-        && !frame->editor().isAutomaticLinkDetectionEnabled()
-        && !frame->editor().isAutomaticDashSubstitutionEnabled()
-        && !frame->editor().isAutomaticTextReplacementEnabled())
+    if (!frame.editor().isContinuousSpellCheckingEnabled()
+        && !frame.editor().isAutomaticQuoteSubstitutionEnabled()
+        && !frame.editor().isAutomaticLinkDetectionEnabled()
+        && !frame.editor().isAutomaticDashSubstitutionEnabled()
+        && !frame.editor().isAutomaticTextReplacementEnabled())
             return;
 #else
-    if (!frame->editor().isContinuousSpellCheckingEnabled())
+    if (!frame.editor().isContinuousSpellCheckingEnabled())
         return;
 #endif
     // Take a look at the selection that results after typing and determine whether we need to spellcheck. 
@@ -322,29 +320,27 @@ void TypingCommand::markMisspellingsAfterTyping(ETypingCommand commandType)
             String strippedPreviousWord;
             if (range && (commandType == TypingCommand::InsertText || commandType == TypingCommand::InsertLineBreak || commandType == TypingCommand::InsertParagraphSeparator || commandType == TypingCommand::InsertParagraphSeparatorInQuotedContent))
                 strippedPreviousWord = plainText(range.get()).stripWhiteSpace();
-            frame->editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
+            frame.editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
         } else if (commandType == TypingCommand::InsertText)
-            frame->editor().startAlternativeTextUITimer();
+            frame.editor().startAlternativeTextUITimer();
     }
 }
 
 void TypingCommand::typingAddedToOpenCommand(ETypingCommand commandTypeForAddedTyping)
 {
-    Frame* frame = document().frame();
-    if (!frame)
-        return;
+    Frame& frame = this->frame();
 
     updatePreservesTypingStyle(commandTypeForAddedTyping);
 
 #if PLATFORM(MAC)
-    frame->editor().appliedEditing(this);
+    frame.editor().appliedEditing(this);
     // Since the spellchecking code may also perform corrections and other replacements, it should happen after the typing changes.
     if (!m_shouldPreventSpellChecking)
         markMisspellingsAfterTyping(commandTypeForAddedTyping);
 #else
     // The old spellchecking code requires that checking be done first, to prevent issues like that in 6864072, where <doesn't> is marked as misspelled.
     markMisspellingsAfterTyping(commandTypeForAddedTyping);
-    frame->editor().appliedEditing(this);
+    frame.editor().appliedEditing(this);
 #endif
 }
 
@@ -423,11 +419,9 @@ bool TypingCommand::makeEditableRootEmpty()
 
 void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
 {
-    Frame* frame = document().frame();
-    if (!frame)
-        return;
+    Frame& frame = this->frame();
 
-    frame->editor().updateMarkersForWordsAffectedByEditing(false);
+    frame.editor().updateMarkersForWordsAffectedByEditing(false);
 
     VisibleSelection selectionToDelete;
     VisibleSelection selectionAfterUndo;
@@ -510,11 +504,11 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
     if (selectionToDelete.isNone())
         return;
     
-    if (selectionToDelete.isCaret() || !frame->selection().shouldDeleteSelection(selectionToDelete))
+    if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
         return;
     
     if (killRing)
-        frame->editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
+        frame.editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
     // Make undo select everything that has been deleted, unless an undo will undo more than just this deletion.
     // FIXME: This behaves like TextEdit except for the case where you open with text insertion and then delete
     // more text than you insert.  In that case all of the text that was around originally should be selected.
@@ -527,11 +521,9 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
 
 void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool killRing)
 {
-    Frame* frame = document().frame();
-    if (!frame)
-        return;
+    Frame& frame = this->frame();
 
-    frame->editor().updateMarkersForWordsAffectedByEditing(false);
+    frame.editor().updateMarkersForWordsAffectedByEditing(false);
 
     VisibleSelection selectionToDelete;
     VisibleSelection selectionAfterUndo;
@@ -603,11 +595,11 @@ void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool ki
     if (selectionToDelete.isNone())
         return;
     
-    if (selectionToDelete.isCaret() || !frame->selection().shouldDeleteSelection(selectionToDelete))
+    if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
         return;
         
     if (killRing)
-        frame->editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
+        frame.editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
     // make undo select what was deleted
     setStartingSelection(selectionAfterUndo);
     CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete);