Changeset 154943 in webkit


Ignore:
Timestamp:
Sep 1, 2013 7:57:23 AM (11 years ago)
Author:
akling@apple.com
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.

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154940 r154943  
     12013-09-01  Andreas Kling  <akling@apple.com>
     2
     3        Give EditCommand a protected Frame& getter.
     4        <https://webkit.org/b/120574>
     5
     6        Reviewed by Darin Adler.
     7
     8        EditCommand is only created for documents that are attached to a Frame,
     9        we already ASSERTed as much in the EditCommand constructor.
     10
     11        This patch adds a "Frame& EditCommand::frame()" helper, so EditCommand
     12        and its subclasses don't have to fumble around with pointers.
     13
    1142013-08-31  Antti Koivisto  <antti@apple.com>
    215
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r154938 r154943  
    206206    document().updateLayoutIgnorePendingStylesheets();
    207207
    208     Frame* frame = document().frame();
    209     ASSERT(frame);
    210208    {
    211209        EventQueueScope scope;
    212210#if ENABLE(DELETION_UI)
    213         DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(frame);
     211        DeleteButtonControllerDisableScope deleteButtonControllerDisableScope(&frame());
    214212#endif
    215213        doApply();
     
    219217    // and TypingCommands do it on their own (see TypingCommand::typingAddedToOpenCommand).
    220218    if (!isTypingCommand())
    221         frame->editor().appliedEditing(this);
     219        frame().editor().appliedEditing(this);
    222220    setShouldRetainAutocorrectionIndicator(false);
    223221}
     
    12171215   
    12181216    setEndingSelection(VisibleSelection(start, end, DOWNSTREAM));
    1219     document().frame()->editor().clearMisspellingsAndBadGrammar(endingSelection());
     1217    frame().editor().clearMisspellingsAndBadGrammar(endingSelection());
    12201218    deleteSelection(false, false, false, false);
    12211219
     
    12501248    applyCommandToComposite(ReplaceSelectionCommand::create(document(), fragment, options));
    12511249
    1252     document().frame()->editor().markMisspellingsAndBadGrammar(endingSelection());
     1250    frame().editor().markMisspellingsAndBadGrammar(endingSelection());
    12531251
    12541252    // If the selection is in an empty paragraph, restore styles from the old empty paragraph to the new empty paragraph.
  • trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp

    r154938 r154943  
    656656    RefPtr<Range> range = Range::create(&document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
    657657    RefPtr<Range> rangeToBeReplaced = Range::create(&document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
    658     if (!document().frame()->editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
     658    if (!frame().editor().client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
    659659        return;
    660660   
     
    729729    // but, if we change the selection, come back and start typing that style should be lost.  Also see
    730730    // preserveTypingStyle() below.
    731     document().frame()->selection().setTypingStyle(m_typingStyle);
     731    frame().selection().setTypingStyle(m_typingStyle);
    732732}
    733733
     
    802802        Element* textControl = enclosingTextFormControl(m_selectionToDelete.start());
    803803        if (textControl && textControl->focused())
    804             document().frame()->editor().textWillBeDeletedInTextField(textControl);
     804            frame().editor().textWillBeDeletedInTextField(textControl);
    805805    }
    806806
     
    860860    calculateTypingStyleAfterDelete();
    861861
    862     if (!originalString.isEmpty()) {
    863         if (Frame* frame = document().frame())
    864             frame->editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
    865     }
     862    if (!originalString.isEmpty())
     863        frame().editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
    866864
    867865    setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSelection().isDirectional()));
  • trunk/Source/WebCore/editing/EditCommand.cpp

    r154938 r154943  
    6262}
    6363
     64Frame& EditCommand::frame() const
     65{
     66    ASSERT(document().frame());
     67    return *document().frame();
     68}
     69
    6470EditAction EditCommand::editingAction() const
    6571{
  • trunk/Source/WebCore/editing/EditCommand.h

    r154938 r154943  
    3939class Document;
    4040class Element;
     41class Frame;
    4142
    4243class EditCommand : public RefCounted<EditCommand> {
     
    6263    EditCommand(Document&, const VisibleSelection&, const VisibleSelection&);
    6364
     65    Frame& frame() const;
    6466    Document& document() const { return *m_document; }
    6567    CompositeEditCommand* parent() const { return m_parent; }
  • trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp

    r154938 r154943  
    168168    // Handle the case where there is a typing style.
    169169
    170     RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingStyle();
     170    RefPtr<EditingStyle> typingStyle = frame().selection().typingStyle();
    171171
    172172    if (typingStyle && !typingStyle->isEmpty()) {
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r154938 r154943  
    147147        if (endingSelection().isNone())
    148148            return;
    149     } else if (document().frame()->editor().isOverwriteModeEnabled()) {
     149    } else if (frame().editor().isOverwriteModeEnabled()) {
    150150        if (performOverwrite(m_text, m_selectInsertedText))
    151151            return;
     
    223223
    224224    // Handle the case where there is a typing style.
    225     if (RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingStyle()) {
     225    if (RefPtr<EditingStyle> typingStyle = frame().selection().typingStyle()) {
    226226        typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection);
    227227        if (!typingStyle->isEmpty())
  • trunk/Source/WebCore/editing/RemoveFormatCommand.cpp

    r154938 r154943  
    8080void RemoveFormatCommand::doApply()
    8181{
    82     Frame* frame = document().frame();
    83 
    84     if (!frame->selection().selection().isNonOrphanedCaretOrRange())
     82    if (!frame().selection().selection().isNonOrphanedCaretOrRange())
    8583        return;
    8684
    8785    // Get the default style for this editable root, it's the style that we'll give the
    8886    // content that we're operating on.
    89     Node* root = frame->selection().rootEditableElement();
     87    Node* root = frame().selection().rootEditableElement();
    9088    RefPtr<EditingStyle> defaultStyle = EditingStyle::create(root);
    9189
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r154938 r154943  
    10131013    // FIXME: Can this wait until after the operation has been performed?  There doesn't seem to be
    10141014    // any work performed after this that queries or uses the typing style.
    1015     if (Frame* frame = document().frame())
    1016         frame->selection().clearTypingStyle();
     1015    frame().selection().clearTypingStyle();
    10171016
    10181017    removeHeadContents(fragment);
  • trunk/Source/WebCore/editing/SetSelectionCommand.cpp

    r154938 r154943  
    4141void SetSelectionCommand::doApply()
    4242{
    43     FrameSelection& selection = document().frame()->selection();
     43    FrameSelection& selection = frame().selection();
    4444
    4545    if (selection.shouldChangeSelection(m_selectionToSet) && m_selectionToSet.isNonOrphanedCaretOrRange()) {
     
    5151void SetSelectionCommand::doUnapply()
    5252{
    53     FrameSelection& selection = document().frame()->selection();
     53    FrameSelection& selection = frame().selection();
    5454
    5555    if (selection.shouldChangeSelection(startingSelection()) && startingSelection().isNonOrphanedCaretOrRange())
  • trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp

    r154938 r154943  
    6464    {
    6565        if (!m_hasBeenUndone) {
    66             document().frame()->editor().unappliedSpellCorrection(startingSelection(), m_corrected, m_correction);
     66            frame().editor().unappliedSpellCorrection(startingSelection(), m_corrected, m_correction);
    6767            m_hasBeenUndone = true;
    6868        }
     
    9696        return;
    9797
    98     if (!document().frame()->selection().shouldChangeSelection(m_selectionToBeCorrected))
     98    if (!frame().selection().shouldChangeSelection(m_selectionToBeCorrected))
    9999        return;
    100100
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r154938 r154943  
    294294void TypingCommand::markMisspellingsAfterTyping(ETypingCommand commandType)
    295295{
    296     Frame* frame = document().frame();
    297     if (!frame)
    298         return;
     296    Frame& frame = this->frame();
    299297
    300298#if PLATFORM(MAC)
    301     if (!frame->editor().isContinuousSpellCheckingEnabled()
    302         && !frame->editor().isAutomaticQuoteSubstitutionEnabled()
    303         && !frame->editor().isAutomaticLinkDetectionEnabled()
    304         && !frame->editor().isAutomaticDashSubstitutionEnabled()
    305         && !frame->editor().isAutomaticTextReplacementEnabled())
     299    if (!frame.editor().isContinuousSpellCheckingEnabled()
     300        && !frame.editor().isAutomaticQuoteSubstitutionEnabled()
     301        && !frame.editor().isAutomaticLinkDetectionEnabled()
     302        && !frame.editor().isAutomaticDashSubstitutionEnabled()
     303        && !frame.editor().isAutomaticTextReplacementEnabled())
    306304            return;
    307305#else
    308     if (!frame->editor().isContinuousSpellCheckingEnabled())
     306    if (!frame.editor().isContinuousSpellCheckingEnabled())
    309307        return;
    310308#endif
     
    323321            if (range && (commandType == TypingCommand::InsertText || commandType == TypingCommand::InsertLineBreak || commandType == TypingCommand::InsertParagraphSeparator || commandType == TypingCommand::InsertParagraphSeparatorInQuotedContent))
    324322                strippedPreviousWord = plainText(range.get()).stripWhiteSpace();
    325             frame->editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
     323            frame.editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
    326324        } else if (commandType == TypingCommand::InsertText)
    327             frame->editor().startAlternativeTextUITimer();
     325            frame.editor().startAlternativeTextUITimer();
    328326    }
    329327}
     
    331329void TypingCommand::typingAddedToOpenCommand(ETypingCommand commandTypeForAddedTyping)
    332330{
    333     Frame* frame = document().frame();
    334     if (!frame)
    335         return;
     331    Frame& frame = this->frame();
    336332
    337333    updatePreservesTypingStyle(commandTypeForAddedTyping);
    338334
    339335#if PLATFORM(MAC)
    340     frame->editor().appliedEditing(this);
     336    frame.editor().appliedEditing(this);
    341337    // Since the spellchecking code may also perform corrections and other replacements, it should happen after the typing changes.
    342338    if (!m_shouldPreventSpellChecking)
     
    345341    // The old spellchecking code requires that checking be done first, to prevent issues like that in 6864072, where <doesn't> is marked as misspelled.
    346342    markMisspellingsAfterTyping(commandTypeForAddedTyping);
    347     frame->editor().appliedEditing(this);
     343    frame.editor().appliedEditing(this);
    348344#endif
    349345}
     
    424420void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
    425421{
    426     Frame* frame = document().frame();
    427     if (!frame)
    428         return;
    429 
    430     frame->editor().updateMarkersForWordsAffectedByEditing(false);
     422    Frame& frame = this->frame();
     423
     424    frame.editor().updateMarkersForWordsAffectedByEditing(false);
    431425
    432426    VisibleSelection selectionToDelete;
     
    511505        return;
    512506   
    513     if (selectionToDelete.isCaret() || !frame->selection().shouldDeleteSelection(selectionToDelete))
     507    if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
    514508        return;
    515509   
    516510    if (killRing)
    517         frame->editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
     511        frame.editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
    518512    // Make undo select everything that has been deleted, unless an undo will undo more than just this deletion.
    519513    // FIXME: This behaves like TextEdit except for the case where you open with text insertion and then delete
     
    528522void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool killRing)
    529523{
    530     Frame* frame = document().frame();
    531     if (!frame)
    532         return;
    533 
    534     frame->editor().updateMarkersForWordsAffectedByEditing(false);
     524    Frame& frame = this->frame();
     525
     526    frame.editor().updateMarkersForWordsAffectedByEditing(false);
    535527
    536528    VisibleSelection selectionToDelete;
     
    604596        return;
    605597   
    606     if (selectionToDelete.isCaret() || !frame->selection().shouldDeleteSelection(selectionToDelete))
     598    if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
    607599        return;
    608600       
    609601    if (killRing)
    610         frame->editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
     602        frame.editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
    611603    // make undo select what was deleted
    612604    setStartingSelection(selectionAfterUndo);
Note: See TracChangeset for help on using the changeset viewer.