Title: [154943] trunk/Source/WebCore
Revision
154943
Author
akl...@apple.com
Date
2013-09-01 07:57:23 -0700 (Sun, 01 Sep 2013)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (154942 => 154943)


--- trunk/Source/WebCore/ChangeLog	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/ChangeLog	2013-09-01 14:57:23 UTC (rev 154943)
@@ -1,3 +1,16 @@
+2013-09-01  Andreas Kling  <akl...@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  <an...@apple.com>
 
         Add element ancestor iterator

Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -205,12 +205,10 @@
     // 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 @@
     // 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 @@
     // 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 @@
         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());

Modified: trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -655,7 +655,7 @@
     
     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 @@
     // 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 @@
     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 @@
 
     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();

Modified: trunk/Source/WebCore/editing/EditCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/EditCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/EditCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -61,6 +61,12 @@
 {
 }
 
+Frame& EditCommand::frame() const
+{
+    ASSERT(document().frame());
+    return *document().frame();
+}
+
 EditAction EditCommand::editingAction() const
 {
     return EditActionUnspecified;

Modified: trunk/Source/WebCore/editing/EditCommand.h (154942 => 154943)


--- trunk/Source/WebCore/editing/EditCommand.h	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/EditCommand.h	2013-09-01 14:57:23 UTC (rev 154943)
@@ -38,6 +38,7 @@
 class CompositeEditCommand;
 class Document;
 class Element;
+class Frame;
 
 class EditCommand : public RefCounted<EditCommand> {
 public:
@@ -61,6 +62,7 @@
     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&);

Modified: trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -167,7 +167,7 @@
 
     // 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

Modified: trunk/Source/WebCore/editing/InsertTextCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/InsertTextCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/InsertTextCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -146,7 +146,7 @@
         // 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 @@
     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());

Modified: trunk/Source/WebCore/editing/RemoveFormatCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/RemoveFormatCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/RemoveFormatCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -79,14 +79,12 @@
 
 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.

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -1012,8 +1012,7 @@
     
     // 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);
 

Modified: trunk/Source/WebCore/editing/SetSelectionCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/SetSelectionCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/SetSelectionCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -40,7 +40,7 @@
 
 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::doUnapply()
 {
-    FrameSelection& selection = document().frame()->selection();
+    FrameSelection& selection = frame().selection();
 
     if (selection.shouldChangeSelection(startingSelection()) && startingSelection().isNonOrphanedCaretOrRange())
         selection.setSelection(startingSelection(), m_options);

Modified: trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -63,7 +63,7 @@
     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 @@
     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);

Modified: trunk/Source/WebCore/editing/TypingCommand.cpp (154942 => 154943)


--- trunk/Source/WebCore/editing/TypingCommand.cpp	2013-09-01 13:53:30 UTC (rev 154942)
+++ trunk/Source/WebCore/editing/TypingCommand.cpp	2013-09-01 14:57:23 UTC (rev 154943)
@@ -293,19 +293,17 @@
 
 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 @@
             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 @@
 
 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 @@
     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::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 @@
     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);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to