Changeset 260831 in webkit


Ignore:
Timestamp:
Apr 28, 2020 9:36:38 AM (4 years ago)
Author:
Jack Lee
Message:

Nullptr crash in EditCommand::EditCommand via CompositeEditCommand::removeNode
https://bugs.webkit.org/show_bug.cgi?id=207600
<rdar://problem/56969450>

Reviewed by Geoffrey Garen.

Source/WebCore:

Move FrameSelection and Editor objects from Frame to Document so when a document is detached
in nested command executions, the next EditCommand would not fail in constructor.

Test: editing/inserting/insert-list-then-edit-command-crash.html

  • dom/Document.cpp:

(WebCore::m_selection):
(WebCore::Document::prepareForDestruction):
(WebCore::m_undoManager): Deleted.

  • dom/Document.h:

(WebCore::Document::editor):
(WebCore::Document::editor const):
(WebCore::Document::selection):
(WebCore::Document::selection const):

  • dom/PositionIterator.cpp:

(WebCore::PositionIterator::isCandidate const):

  • editing/AlternativeTextController.cpp:

(WebCore::AlternativeTextController::AlternativeTextController):
(WebCore::AlternativeTextController::stopPendingCorrection):
(WebCore::AlternativeTextController::isSpellingMarkerAllowed const):
(WebCore::AlternativeTextController::applyAutocorrectionBeforeTypingIfAppropriate):
(WebCore::AlternativeTextController::respondToUnappliedSpellCorrection):
(WebCore::AlternativeTextController::timerFired):
(WebCore::AlternativeTextController::handleAlternativeTextUIResult):
(WebCore::AlternativeTextController::rootViewRectForRange const):
(WebCore::AlternativeTextController::respondToChangedSelection):
(WebCore::AlternativeTextController::respondToAppliedEditing):
(WebCore::AlternativeTextController::respondToUnappliedEditing):
(WebCore::AlternativeTextController::editorClient):
(WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
(WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
(WebCore::AlternativeTextController::respondToMarkerAtEndOfWord):
(WebCore::AlternativeTextController::alternativeTextClient):
(WebCore::AlternativeTextController::applyAlternativeTextToRange):
(WebCore::AlternativeTextController::insertDictatedText):
(WebCore::AlternativeTextController::applyDictationAlternative):

  • editing/AlternativeTextController.h:

(WebCore::AlternativeTextController::UNLESS_ENABLED):

  • editing/CompositeEditCommand.cpp:

(WebCore::EditCommandComposition::unapply):
(WebCore::EditCommandComposition::reapply):
(WebCore::CompositeEditCommand::willApplyCommand):
(WebCore::CompositeEditCommand::didApplyCommand):
(WebCore::CompositeEditCommand::targetRanges const):
(WebCore::CompositeEditCommand::moveParagraphs):

  • editing/DeleteSelectionCommand.cpp:

(WebCore::DeleteSelectionCommand::saveTypingStyleState):
(WebCore::DeleteSelectionCommand::mergeParagraphs):
(WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete):
(WebCore::DeleteSelectionCommand::doApply):

  • editing/EditCommand.cpp:

(WebCore::EditCommand::EditCommand):
(WebCore::EditCommand::isEditingTextAreaOrTextInput const):
(WebCore::EditCommand::postTextStateChangeNotification):
(WebCore::EditCommand::frame): Deleted.
(WebCore::EditCommand::frame const): Deleted.

  • editing/EditCommand.h:
  • editing/Editing.cpp:

(WebCore::createDefaultParagraphElement):

  • editing/EditingStyle.cpp:

(WebCore::StyleChange::StyleChange):

  • editing/Editor.cpp:

(WebCore::ClearTextCommand::CreateAndApply):
(WebCore::TemporarySelectionChange::TemporarySelectionChange):
(WebCore::TemporarySelectionChange::~TemporarySelectionChange):
(WebCore::TemporarySelectionChange::setSelection):
(WebCore::Editor::selectionForCommand):
(WebCore::Editor::behavior const):
(WebCore::Editor::client const):
(WebCore::Editor::canEdit const):
(WebCore::Editor::canEditRichly const):
(WebCore::Editor::canDHTMLCut):
(WebCore::Editor::canDHTMLCopy):
(WebCore::Editor::canCopy const):
(WebCore::Editor::canPaste const):
(WebCore::Editor::canDelete const):
(WebCore::Editor::shouldSmartDelete):
(WebCore::Editor::deleteWithDirection):
(WebCore::Editor::deleteSelectionWithSmartDelete):
(WebCore::Editor::clearText):
(WebCore::Editor::replaceSelectionWithFragment):
(WebCore::Editor::selectedRange):
(WebCore::Editor::tryDHTMLCopy):
(WebCore::Editor::tryDHTMLCut):
(WebCore::Editor::shouldInsertText const):
(WebCore::Editor::hasBidiSelection const):
(WebCore::Editor::selectionUnorderedListState const):
(WebCore::Editor::selectionOrderedListState const):
(WebCore::Editor::increaseSelectionListLevel):
(WebCore::Editor::increaseSelectionListLevelOrdered):
(WebCore::Editor::increaseSelectionListLevelUnordered):
(WebCore::Editor::decreaseSelectionListLevel):
(WebCore::Editor::findEventTargetFromSelection const):
(WebCore::Editor::applyStyle):
(WebCore::Editor::applyParagraphStyle):
(WebCore::Editor::applyStyleToSelection):
(WebCore::Editor::applyParagraphStyleToSelection):
(WebCore::Editor::selectionStartHasStyle const):
(WebCore::Editor::selectionHasStyle const):
(WebCore::Editor::selectionStartCSSPropertyValue):
(WebCore::Editor::appliedEditing):
(WebCore::Editor::Editor):
(WebCore::Editor::clear):
(WebCore::Editor::insertText):
(WebCore::Editor::insertTextForConfirmedComposition):
(WebCore::Editor::insertTextWithoutSendingTextEvent):
(WebCore::Editor::insertLineBreak):
(WebCore::Editor::insertParagraphSeparator):
(WebCore::Editor::performCutOrCopy):
(WebCore::Editor::paste):
(WebCore::Editor::pasteAsQuotation):
(WebCore::Editor::renderLayerDidScroll):
(WebCore::Editor::setBaseWritingDirection):
(WebCore::Editor::baseWritingDirectionForSelectionStart const):
(WebCore::Editor::selectComposition):
(WebCore::SetCompositionScope::SetCompositionScope):
(WebCore::SetCompositionScope::~SetCompositionScope):
(WebCore::Editor::setComposition):
(WebCore::Editor::ignoreSpelling):
(WebCore::Editor::learnSpelling):
(WebCore::Editor::advanceToNextMisspelling):
(WebCore::Editor::misspelledWordAtCaretOrRange const):
(WebCore::Editor::isSelectionUngrammatical):
(WebCore::Editor::guessesForMisspelledWord const):
(WebCore::Editor::guessesForMisspelledOrUngrammatical):
(WebCore::Editor::markMisspellingsAfterTypingToWord):
(WebCore::Editor::isSpellCheckingEnabledInFocusedNode const):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::markAndReplaceFor):
(WebCore::Editor::updateMarkersForWordsAffectedByEditing):
(WebCore::Editor::rangeForPoint):
(WebCore::Editor::revealSelectionAfterEditingOperation):
(WebCore::Editor::setIgnoreSelectionChanges):
(WebCore::Editor::getCompositionSelection const):
(WebCore::Editor::transpose):
(WebCore::Editor::changeSelectionAfterCommand):
(WebCore::Editor::selectedText const):
(WebCore::Editor::selectedTextForDataTransfer const):
(WebCore::Editor::insertTextPlaceholder):
(WebCore::Editor::removeTextPlaceholder):
(WebCore::Editor::shouldChangeSelection const):
(WebCore::Editor::computeAndSetTypingStyle):
(WebCore::Editor::findString):
(WebCore::Editor::countMatchesForText):
(WebCore::Editor::respondToChangedSelection):
(WebCore::Editor::shouldDetectTelephoneNumbers):
(WebCore::Editor::scanSelectionForTelephoneNumbers):
(WebCore::Editor::editorUIUpdateTimerFired):
(WebCore::Editor::selectionStartHasMarkerFor const):
(WebCore::candidateRangeForSelection):
(WebCore::Editor::stringForCandidateRequest const):
(WebCore::Editor::contextRangeForCandidateRequest const):
(WebCore::Editor::fontAttributesAtSelectionStart const):
(WebCore::Editor::notifyClientOfAttachmentUpdates):
(WebCore::Editor::handleAcceptedCandidate):
(WebCore::Editor::unifiedTextCheckerEnabled const):
(WebCore::Editor::toggleOverwriteModeEnabled):
(WebCore::Editor::fontForSelection const):
(WebCore::Editor::canCopyExcludingStandaloneImages const):
(WebCore::Editor::document const): Deleted.

  • editing/Editor.h:

(WebCore::TemporarySelectionChange::TemporarySelectionChange):
(WebCore::IgnoreSelectionChangeForScope::IgnoreSelectionChangeForScope):
(WebCore::Editor::document const):

  • editing/EditorCommand.cpp:

(WebCore::executeSwapWithMark):
(WebCore::Editor::command):
(WebCore::Editor::Command::Command):
(WebCore::Editor::Command::execute const):

  • editing/FrameSelection.cpp:

(WebCore::shouldAlwaysUseDirectionalSelection):
(WebCore::FrameSelection::FrameSelection):
(WebCore::FrameSelection::rootEditableElementOrDocumentElement const):
(WebCore::FrameSelection::setSelectionByMouseIfDifferent):
(WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance):
(WebCore::FrameSelection::setSelection):
(WebCore::updateSelectionByUpdatingLayoutOrStyle):
(WebCore::FrameSelection::setNeedsSelectionUpdate):
(WebCore::FrameSelection::updateAndRevealSelection):
(WebCore::FrameSelection::updateDataDetectorsForSelection):
(WebCore::FrameSelection::positionForPlatform const):
(WebCore::FrameSelection::nextWordPositionForPlatform):
(WebCore::FrameSelection::modifyMovingRight):
(WebCore::FrameSelection::modifyMovingLeft):
(WebCore::FrameSelection::modify):
(WebCore::FrameSelection::prepareForDestruction):
(WebCore::FrameSelection::absoluteCaretBounds):
(WebCore::FrameSelection::recomputeCaretRect):
(WebCore::FrameSelection::contains const):
(WebCore::FrameSelection::selectAll):
(WebCore::FrameSelection::focusedOrActiveStateChanged):
(WebCore::FrameSelection::isFocusedAndActive const):
(WebCore::shouldStopBlinkingDueToTypingCommand):
(WebCore::FrameSelection::updateAppearance):
(WebCore::FrameSelection::setCaretVisibility):
(WebCore::FrameSelection::setFocusedElementIfNeeded):
(WebCore::FrameSelection::shouldDeleteSelection const):
(WebCore::FrameSelection::selectionBounds const):
(WebCore::FrameSelection::getClippedVisibleTextRectangles const):
(WebCore::FrameSelection::currentForm const):
(WebCore::FrameSelection::revealSelection):
(WebCore::FrameSelection::setSelectionFromNone):
(WebCore::FrameSelection::shouldChangeSelection const):
(WebCore::FrameSelection::setShouldShowBlockCursor):
(WebCore::FrameSelection::appearanceUpdateTimerFired):
(WebCore::FrameSelection::updateAppearanceAfterLayoutOrStyleChange):
(WebCore::FrameSelection::selectRangeOnElement):
(WebCore::FrameSelection::setCaretBlinks):

  • editing/FrameSelection.h:
  • editing/InsertIntoTextNodeCommand.cpp:

(WebCore::InsertIntoTextNodeCommand::doApply):

  • editing/InsertLineBreakCommand.cpp:

(WebCore::InsertLineBreakCommand::doApply):

  • editing/InsertTextCommand.cpp:

(WebCore::InsertTextCommand::doApply):

  • editing/ReplaceRangeWithTextCommand.cpp:

(WebCore::ReplaceRangeWithTextCommand::doApply):

  • editing/ReplaceSelectionCommand.cpp:

(WebCore::ReplaceSelectionCommand::doApply):

  • editing/SetSelectionCommand.cpp:

(WebCore::SetSelectionCommand::doApply):
(WebCore::SetSelectionCommand::doUnapply):

  • editing/SpellChecker.cpp:

(WebCore::SpellChecker::SpellChecker):
(WebCore::SpellChecker::client const):
(WebCore::SpellChecker::isAsynchronousEnabled const):
(WebCore::SpellChecker::invokeRequest):
(WebCore::SpellChecker::didCheck):
(WebCore::SpellChecker::didCheckSucceed):

  • editing/SpellChecker.h:
  • editing/SpellingCorrectionCommand.cpp:

(WebCore::SpellingCorrectionCommand::doApply):

  • editing/TypingCommand.cpp:

(WebCore::TypingCommand::deleteSelection):
(WebCore::TypingCommand::deleteKeyPressed):
(WebCore::TypingCommand::forwardDeleteKeyPressed):
(WebCore::TypingCommand::updateSelectionIfDifferentFromCurrentSelection):
(WebCore::TypingCommand::insertText):
(WebCore::TypingCommand::insertLineBreak):
(WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent):
(WebCore::TypingCommand::insertParagraphSeparator):
(WebCore::TypingCommand::lastTypingCommandIfStillOpenForTyping):
(WebCore::TypingCommand::closeTyping):
(WebCore::TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping):
(WebCore::TypingCommand::markMisspellingsAfterTyping):
(WebCore::TypingCommand::willAddTypingToOpenCommand):
(WebCore::TypingCommand::typingAddedToOpenCommand):
(WebCore::TypingCommand::insertTextAndNotifyAccessibility):
(WebCore::TypingCommand::insertTextRunWithoutNewlines):
(WebCore::TypingCommand::insertLineBreakAndNotifyAccessibility):
(WebCore::TypingCommand::insertParagraphSeparatorAndNotifyAccessibility):
(WebCore::TypingCommand::insertParagraphSeparatorInQuotedContentAndNotifyAccessibility):

  • editing/TypingCommand.h:
  • editing/cocoa/EditorCocoa.mm:

(WebCore::Editor::selectionInHTMLFormat):
(WebCore::Editor::writeSelectionToPasteboard):
(WebCore::Editor::writeSelection):
(WebCore::Editor::selectionInWebArchiveFormat):
(WebCore::Editor::replaceSelectionWithAttributedString):
(WebCore::Editor::webContentFromPasteboard):
(WebCore::Editor::takeFindStringFromSelection):

  • editing/gtk/EditorGtk.cpp:

(WebCore::Editor::pasteWithPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):
(WebCore::Editor::webContentFromPasteboard):

  • editing/ios/EditorIOS.mm:

(WebCore::Editor::setTextAlignmentForChangedBaseWritingDirection):
(WebCore::Editor::removeUnchangeableStyles):
(WebCore::Editor::pasteWithPasteboard):
(WebCore::Editor::insertDictationPhrases):
(WebCore::Editor::setDictationPhrasesAsChildOfElement):
(WebCore::Editor::setTextAsChildOfElement):
(WebCore::Editor::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping):

  • editing/libwpe/EditorLibWPE.cpp:

(WebCore::Editor::writeSelectionToPasteboard):
(WebCore::Editor::pasteWithPasteboard):

  • editing/mac/EditorMac.mm:

(WebCore::Editor::readSelectionFromPasteboard):
(WebCore::Editor::replaceNodeFromPasteboard):
(WebCore::Editor::selectionWillChange):

  • editing/win/EditorWin.cpp:

(WebCore::Editor::pasteWithPasteboard):
(WebCore::Editor::webContentFromPasteboard):

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::willTransitionToCommitted):
(WebCore::FrameLoader::closeURL):
(WebCore::FrameLoader::didOpenURL):
(WebCore::FrameLoader::clear):

  • page/Frame.cpp:

(WebCore::Frame::Frame):
(WebCore::Frame::requestDOMPasteAccess):
(WebCore::Frame::setPageAndTextZoomFactors):

  • page/Frame.h:
  • page/TextIndicator.cpp:

(WebCore::TextIndicator::createWithRange):

LayoutTests:

Added a regression test for the crash.

  • editing/inserting/insert-list-then-edit-command-crash-expected.txt: Added.
  • editing/inserting/insert-list-then-edit-command-crash.html: Added.

Modify the test result. FrameSelection is being destructed along with
document so an additional selection change notification is expected.

  • platform/mac/editing/pasteboard/drag-drop-dead-frame-expected.txt:
Location:
trunk
Files:
2 added
40 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r260830 r260831  
     12020-04-28  Jack Lee  <shihchieh_lee@apple.com>
     2
     3        Nullptr crash in EditCommand::EditCommand via CompositeEditCommand::removeNode
     4        https://bugs.webkit.org/show_bug.cgi?id=207600
     5        <rdar://problem/56969450>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Added a regression test for the crash.
     10
     11        * editing/inserting/insert-list-then-edit-command-crash-expected.txt: Added.
     12        * editing/inserting/insert-list-then-edit-command-crash.html: Added.
     13
     14        Modify the test result. FrameSelection is being destructed along with
     15        document so an additional selection change notification is expected.
     16
     17        * platform/mac/editing/pasteboard/drag-drop-dead-frame-expected.txt:
     18
    1192020-04-28  Alejandro G. Castro  <alex@igalia.com>
    220
  • trunk/LayoutTests/platform/mac/editing/pasteboard/drag-drop-dead-frame-expected.txt

    r177774 r260831  
    55EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    66EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
     7EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
    78layer at (0,0) size 800x600
    89  RenderView at (0,0) size 800x600
  • trunk/Source/WebCore/ChangeLog

    r260828 r260831  
     12020-04-28  Jack Lee  <shihchieh_lee@apple.com>
     2
     3        Nullptr crash in EditCommand::EditCommand via CompositeEditCommand::removeNode
     4        https://bugs.webkit.org/show_bug.cgi?id=207600
     5        <rdar://problem/56969450>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Move FrameSelection and Editor objects from Frame to Document so when a document is detached
     10        in nested command executions, the next EditCommand would not fail in constructor.
     11
     12        Test: editing/inserting/insert-list-then-edit-command-crash.html
     13
     14        * dom/Document.cpp:
     15        (WebCore::m_selection):
     16        (WebCore::Document::prepareForDestruction):
     17        (WebCore::m_undoManager): Deleted.
     18        * dom/Document.h:
     19        (WebCore::Document::editor):
     20        (WebCore::Document::editor const):
     21        (WebCore::Document::selection):
     22        (WebCore::Document::selection const):
     23        * dom/PositionIterator.cpp:
     24        (WebCore::PositionIterator::isCandidate const):
     25        * editing/AlternativeTextController.cpp:
     26        (WebCore::AlternativeTextController::AlternativeTextController):
     27        (WebCore::AlternativeTextController::stopPendingCorrection):
     28        (WebCore::AlternativeTextController::isSpellingMarkerAllowed const):
     29        (WebCore::AlternativeTextController::applyAutocorrectionBeforeTypingIfAppropriate):
     30        (WebCore::AlternativeTextController::respondToUnappliedSpellCorrection):
     31        (WebCore::AlternativeTextController::timerFired):
     32        (WebCore::AlternativeTextController::handleAlternativeTextUIResult):
     33        (WebCore::AlternativeTextController::rootViewRectForRange const):
     34        (WebCore::AlternativeTextController::respondToChangedSelection):
     35        (WebCore::AlternativeTextController::respondToAppliedEditing):
     36        (WebCore::AlternativeTextController::respondToUnappliedEditing):
     37        (WebCore::AlternativeTextController::editorClient):
     38        (WebCore::AlternativeTextController::markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand):
     39        (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
     40        (WebCore::AlternativeTextController::respondToMarkerAtEndOfWord):
     41        (WebCore::AlternativeTextController::alternativeTextClient):
     42        (WebCore::AlternativeTextController::applyAlternativeTextToRange):
     43        (WebCore::AlternativeTextController::insertDictatedText):
     44        (WebCore::AlternativeTextController::applyDictationAlternative):
     45        * editing/AlternativeTextController.h:
     46        (WebCore::AlternativeTextController::UNLESS_ENABLED):
     47        * editing/CompositeEditCommand.cpp:
     48        (WebCore::EditCommandComposition::unapply):
     49        (WebCore::EditCommandComposition::reapply):
     50        (WebCore::CompositeEditCommand::willApplyCommand):
     51        (WebCore::CompositeEditCommand::didApplyCommand):
     52        (WebCore::CompositeEditCommand::targetRanges const):
     53        (WebCore::CompositeEditCommand::moveParagraphs):
     54        * editing/DeleteSelectionCommand.cpp:
     55        (WebCore::DeleteSelectionCommand::saveTypingStyleState):
     56        (WebCore::DeleteSelectionCommand::mergeParagraphs):
     57        (WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete):
     58        (WebCore::DeleteSelectionCommand::doApply):
     59        * editing/EditCommand.cpp:
     60        (WebCore::EditCommand::EditCommand):
     61        (WebCore::EditCommand::isEditingTextAreaOrTextInput const):
     62        (WebCore::EditCommand::postTextStateChangeNotification):
     63        (WebCore::EditCommand::frame): Deleted.
     64        (WebCore::EditCommand::frame const): Deleted.
     65        * editing/EditCommand.h:
     66        * editing/Editing.cpp:
     67        (WebCore::createDefaultParagraphElement):
     68        * editing/EditingStyle.cpp:
     69        (WebCore::StyleChange::StyleChange):
     70        * editing/Editor.cpp:
     71        (WebCore::ClearTextCommand::CreateAndApply):
     72        (WebCore::TemporarySelectionChange::TemporarySelectionChange):
     73        (WebCore::TemporarySelectionChange::~TemporarySelectionChange):
     74        (WebCore::TemporarySelectionChange::setSelection):
     75        (WebCore::Editor::selectionForCommand):
     76        (WebCore::Editor::behavior const):
     77        (WebCore::Editor::client const):
     78        (WebCore::Editor::canEdit const):
     79        (WebCore::Editor::canEditRichly const):
     80        (WebCore::Editor::canDHTMLCut):
     81        (WebCore::Editor::canDHTMLCopy):
     82        (WebCore::Editor::canCopy const):
     83        (WebCore::Editor::canPaste const):
     84        (WebCore::Editor::canDelete const):
     85        (WebCore::Editor::shouldSmartDelete):
     86        (WebCore::Editor::deleteWithDirection):
     87        (WebCore::Editor::deleteSelectionWithSmartDelete):
     88        (WebCore::Editor::clearText):
     89        (WebCore::Editor::replaceSelectionWithFragment):
     90        (WebCore::Editor::selectedRange):
     91        (WebCore::Editor::tryDHTMLCopy):
     92        (WebCore::Editor::tryDHTMLCut):
     93        (WebCore::Editor::shouldInsertText const):
     94        (WebCore::Editor::hasBidiSelection const):
     95        (WebCore::Editor::selectionUnorderedListState const):
     96        (WebCore::Editor::selectionOrderedListState const):
     97        (WebCore::Editor::increaseSelectionListLevel):
     98        (WebCore::Editor::increaseSelectionListLevelOrdered):
     99        (WebCore::Editor::increaseSelectionListLevelUnordered):
     100        (WebCore::Editor::decreaseSelectionListLevel):
     101        (WebCore::Editor::findEventTargetFromSelection const):
     102        (WebCore::Editor::applyStyle):
     103        (WebCore::Editor::applyParagraphStyle):
     104        (WebCore::Editor::applyStyleToSelection):
     105        (WebCore::Editor::applyParagraphStyleToSelection):
     106        (WebCore::Editor::selectionStartHasStyle const):
     107        (WebCore::Editor::selectionHasStyle const):
     108        (WebCore::Editor::selectionStartCSSPropertyValue):
     109        (WebCore::Editor::appliedEditing):
     110        (WebCore::Editor::Editor):
     111        (WebCore::Editor::clear):
     112        (WebCore::Editor::insertText):
     113        (WebCore::Editor::insertTextForConfirmedComposition):
     114        (WebCore::Editor::insertTextWithoutSendingTextEvent):
     115        (WebCore::Editor::insertLineBreak):
     116        (WebCore::Editor::insertParagraphSeparator):
     117        (WebCore::Editor::performCutOrCopy):
     118        (WebCore::Editor::paste):
     119        (WebCore::Editor::pasteAsQuotation):
     120        (WebCore::Editor::renderLayerDidScroll):
     121        (WebCore::Editor::setBaseWritingDirection):
     122        (WebCore::Editor::baseWritingDirectionForSelectionStart const):
     123        (WebCore::Editor::selectComposition):
     124        (WebCore::SetCompositionScope::SetCompositionScope):
     125        (WebCore::SetCompositionScope::~SetCompositionScope):
     126        (WebCore::Editor::setComposition):
     127        (WebCore::Editor::ignoreSpelling):
     128        (WebCore::Editor::learnSpelling):
     129        (WebCore::Editor::advanceToNextMisspelling):
     130        (WebCore::Editor::misspelledWordAtCaretOrRange const):
     131        (WebCore::Editor::isSelectionUngrammatical):
     132        (WebCore::Editor::guessesForMisspelledWord const):
     133        (WebCore::Editor::guessesForMisspelledOrUngrammatical):
     134        (WebCore::Editor::markMisspellingsAfterTypingToWord):
     135        (WebCore::Editor::isSpellCheckingEnabledInFocusedNode const):
     136        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
     137        (WebCore::Editor::markAndReplaceFor):
     138        (WebCore::Editor::updateMarkersForWordsAffectedByEditing):
     139        (WebCore::Editor::rangeForPoint):
     140        (WebCore::Editor::revealSelectionAfterEditingOperation):
     141        (WebCore::Editor::setIgnoreSelectionChanges):
     142        (WebCore::Editor::getCompositionSelection const):
     143        (WebCore::Editor::transpose):
     144        (WebCore::Editor::changeSelectionAfterCommand):
     145        (WebCore::Editor::selectedText const):
     146        (WebCore::Editor::selectedTextForDataTransfer const):
     147        (WebCore::Editor::insertTextPlaceholder):
     148        (WebCore::Editor::removeTextPlaceholder):
     149        (WebCore::Editor::shouldChangeSelection const):
     150        (WebCore::Editor::computeAndSetTypingStyle):
     151        (WebCore::Editor::findString):
     152        (WebCore::Editor::countMatchesForText):
     153        (WebCore::Editor::respondToChangedSelection):
     154        (WebCore::Editor::shouldDetectTelephoneNumbers):
     155        (WebCore::Editor::scanSelectionForTelephoneNumbers):
     156        (WebCore::Editor::editorUIUpdateTimerFired):
     157        (WebCore::Editor::selectionStartHasMarkerFor const):
     158        (WebCore::candidateRangeForSelection):
     159        (WebCore::Editor::stringForCandidateRequest const):
     160        (WebCore::Editor::contextRangeForCandidateRequest const):
     161        (WebCore::Editor::fontAttributesAtSelectionStart const):
     162        (WebCore::Editor::notifyClientOfAttachmentUpdates):
     163        (WebCore::Editor::handleAcceptedCandidate):
     164        (WebCore::Editor::unifiedTextCheckerEnabled const):
     165        (WebCore::Editor::toggleOverwriteModeEnabled):
     166        (WebCore::Editor::fontForSelection const):
     167        (WebCore::Editor::canCopyExcludingStandaloneImages const):
     168        (WebCore::Editor::document const): Deleted.
     169        * editing/Editor.h:
     170        (WebCore::TemporarySelectionChange::TemporarySelectionChange):
     171        (WebCore::IgnoreSelectionChangeForScope::IgnoreSelectionChangeForScope):
     172        (WebCore::Editor::document const):
     173        * editing/EditorCommand.cpp:
     174        (WebCore::executeSwapWithMark):
     175        (WebCore::Editor::command):
     176        (WebCore::Editor::Command::Command):
     177        (WebCore::Editor::Command::execute const):
     178        * editing/FrameSelection.cpp:
     179        (WebCore::shouldAlwaysUseDirectionalSelection):
     180        (WebCore::FrameSelection::FrameSelection):
     181        (WebCore::FrameSelection::rootEditableElementOrDocumentElement const):
     182        (WebCore::FrameSelection::setSelectionByMouseIfDifferent):
     183        (WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance):
     184        (WebCore::FrameSelection::setSelection):
     185        (WebCore::updateSelectionByUpdatingLayoutOrStyle):
     186        (WebCore::FrameSelection::setNeedsSelectionUpdate):
     187        (WebCore::FrameSelection::updateAndRevealSelection):
     188        (WebCore::FrameSelection::updateDataDetectorsForSelection):
     189        (WebCore::FrameSelection::positionForPlatform const):
     190        (WebCore::FrameSelection::nextWordPositionForPlatform):
     191        (WebCore::FrameSelection::modifyMovingRight):
     192        (WebCore::FrameSelection::modifyMovingLeft):
     193        (WebCore::FrameSelection::modify):
     194        (WebCore::FrameSelection::prepareForDestruction):
     195        (WebCore::FrameSelection::absoluteCaretBounds):
     196        (WebCore::FrameSelection::recomputeCaretRect):
     197        (WebCore::FrameSelection::contains const):
     198        (WebCore::FrameSelection::selectAll):
     199        (WebCore::FrameSelection::focusedOrActiveStateChanged):
     200        (WebCore::FrameSelection::isFocusedAndActive const):
     201        (WebCore::shouldStopBlinkingDueToTypingCommand):
     202        (WebCore::FrameSelection::updateAppearance):
     203        (WebCore::FrameSelection::setCaretVisibility):
     204        (WebCore::FrameSelection::setFocusedElementIfNeeded):
     205        (WebCore::FrameSelection::shouldDeleteSelection const):
     206        (WebCore::FrameSelection::selectionBounds const):
     207        (WebCore::FrameSelection::getClippedVisibleTextRectangles const):
     208        (WebCore::FrameSelection::currentForm const):
     209        (WebCore::FrameSelection::revealSelection):
     210        (WebCore::FrameSelection::setSelectionFromNone):
     211        (WebCore::FrameSelection::shouldChangeSelection const):
     212        (WebCore::FrameSelection::setShouldShowBlockCursor):
     213        (WebCore::FrameSelection::appearanceUpdateTimerFired):
     214        (WebCore::FrameSelection::updateAppearanceAfterLayoutOrStyleChange):
     215        (WebCore::FrameSelection::selectRangeOnElement):
     216        (WebCore::FrameSelection::setCaretBlinks):
     217        * editing/FrameSelection.h:
     218        * editing/InsertIntoTextNodeCommand.cpp:
     219        (WebCore::InsertIntoTextNodeCommand::doApply):
     220        * editing/InsertLineBreakCommand.cpp:
     221        (WebCore::InsertLineBreakCommand::doApply):
     222        * editing/InsertTextCommand.cpp:
     223        (WebCore::InsertTextCommand::doApply):
     224        * editing/ReplaceRangeWithTextCommand.cpp:
     225        (WebCore::ReplaceRangeWithTextCommand::doApply):
     226        * editing/ReplaceSelectionCommand.cpp:
     227        (WebCore::ReplaceSelectionCommand::doApply):
     228        * editing/SetSelectionCommand.cpp:
     229        (WebCore::SetSelectionCommand::doApply):
     230        (WebCore::SetSelectionCommand::doUnapply):
     231        * editing/SpellChecker.cpp:
     232        (WebCore::SpellChecker::SpellChecker):
     233        (WebCore::SpellChecker::client const):
     234        (WebCore::SpellChecker::isAsynchronousEnabled const):
     235        (WebCore::SpellChecker::invokeRequest):
     236        (WebCore::SpellChecker::didCheck):
     237        (WebCore::SpellChecker::didCheckSucceed):
     238        * editing/SpellChecker.h:
     239        * editing/SpellingCorrectionCommand.cpp:
     240        (WebCore::SpellingCorrectionCommand::doApply):
     241        * editing/TypingCommand.cpp:
     242        (WebCore::TypingCommand::deleteSelection):
     243        (WebCore::TypingCommand::deleteKeyPressed):
     244        (WebCore::TypingCommand::forwardDeleteKeyPressed):
     245        (WebCore::TypingCommand::updateSelectionIfDifferentFromCurrentSelection):
     246        (WebCore::TypingCommand::insertText):
     247        (WebCore::TypingCommand::insertLineBreak):
     248        (WebCore::TypingCommand::insertParagraphSeparatorInQuotedContent):
     249        (WebCore::TypingCommand::insertParagraphSeparator):
     250        (WebCore::TypingCommand::lastTypingCommandIfStillOpenForTyping):
     251        (WebCore::TypingCommand::closeTyping):
     252        (WebCore::TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping):
     253        (WebCore::TypingCommand::markMisspellingsAfterTyping):
     254        (WebCore::TypingCommand::willAddTypingToOpenCommand):
     255        (WebCore::TypingCommand::typingAddedToOpenCommand):
     256        (WebCore::TypingCommand::insertTextAndNotifyAccessibility):
     257        (WebCore::TypingCommand::insertTextRunWithoutNewlines):
     258        (WebCore::TypingCommand::insertLineBreakAndNotifyAccessibility):
     259        (WebCore::TypingCommand::insertParagraphSeparatorAndNotifyAccessibility):
     260        (WebCore::TypingCommand::insertParagraphSeparatorInQuotedContentAndNotifyAccessibility):
     261        * editing/TypingCommand.h:
     262        * editing/cocoa/EditorCocoa.mm:
     263        (WebCore::Editor::selectionInHTMLFormat):
     264        (WebCore::Editor::writeSelectionToPasteboard):
     265        (WebCore::Editor::writeSelection):
     266        (WebCore::Editor::selectionInWebArchiveFormat):
     267        (WebCore::Editor::replaceSelectionWithAttributedString):
     268        (WebCore::Editor::webContentFromPasteboard):
     269        (WebCore::Editor::takeFindStringFromSelection):
     270        * editing/gtk/EditorGtk.cpp:
     271        (WebCore::Editor::pasteWithPasteboard):
     272        (WebCore::Editor::writeSelectionToPasteboard):
     273        (WebCore::Editor::webContentFromPasteboard):
     274        * editing/ios/EditorIOS.mm:
     275        (WebCore::Editor::setTextAlignmentForChangedBaseWritingDirection):
     276        (WebCore::Editor::removeUnchangeableStyles):
     277        (WebCore::Editor::pasteWithPasteboard):
     278        (WebCore::Editor::insertDictationPhrases):
     279        (WebCore::Editor::setDictationPhrasesAsChildOfElement):
     280        (WebCore::Editor::setTextAsChildOfElement):
     281        (WebCore::Editor::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping):
     282        * editing/libwpe/EditorLibWPE.cpp:
     283        (WebCore::Editor::writeSelectionToPasteboard):
     284        (WebCore::Editor::pasteWithPasteboard):
     285        * editing/mac/EditorMac.mm:
     286        (WebCore::Editor::readSelectionFromPasteboard):
     287        (WebCore::Editor::replaceNodeFromPasteboard):
     288        (WebCore::Editor::selectionWillChange):
     289        * editing/win/EditorWin.cpp:
     290        (WebCore::Editor::pasteWithPasteboard):
     291        (WebCore::Editor::webContentFromPasteboard):
     292        * loader/FrameLoader.cpp:
     293        (WebCore::FrameLoader::willTransitionToCommitted):
     294        (WebCore::FrameLoader::closeURL):
     295        (WebCore::FrameLoader::didOpenURL):
     296        (WebCore::FrameLoader::clear):
     297        * page/Frame.cpp:
     298        (WebCore::Frame::Frame):
     299        (WebCore::Frame::requestDOMPasteAccess):
     300        (WebCore::Frame::setPageAndTextZoomFactors):
     301        * page/Frame.h:
     302        * page/TextIndicator.cpp:
     303        (WebCore::TextIndicator::createWithRange):
     304
    13052020-04-28  Antti Koivisto  <antti@apple.com>
    2306
  • trunk/Source/WebCore/dom/Document.cpp

    r260800 r260831  
    583583    , m_identifier(DocumentIdentifier::generate())
    584584    , m_undoManager(UndoManager::create(*this))
     585    , m_editor(makeUniqueRef<Editor>(*this))
     586    , m_selection(makeUniqueRef<FrameSelection>(this))
    585587{
    586588    auto addResult = allDocumentsMap().add(m_identifier, this);
     
    25002502}
    25012503
    2502 void Document::prepareForDestruction()
     2504void Document::willBeRemovedFromFrame()
    25032505{
    25042506    if (m_hasPreparedForDestruction)
     
    25932595    }
    25942596
     2597    editor().clear();
     2598    selection().willBeRemovedFromFrame();
    25952599    detachFromFrame();
    25962600
  • trunk/Source/WebCore/dom/Document.h

    r260800 r260831  
    121121class DocumentType;
    122122class EditingBehavior;
     123class Editor;
    123124class EventLoop;
    124125class EventLoopTaskGroup;
     
    129130class FormController;
    130131class Frame;
     132class FrameSelection;
    131133class FrameView;
    132134class FullscreenManager;
     
    627629    void didBecomeCurrentDocumentInFrame();
    628630    void destroyRenderTree();
    629     void prepareForDestruction();
     631    void willBeRemovedFromFrame();
    630632
    631633    // Override ScriptExecutionContext methods to do additional work
     
    15791581    bool hasVisuallyNonEmptyCustomContent() const { return m_hasVisuallyNonEmptyCustomContent; }
    15801582
     1583    Editor& editor() { return m_editor; }
     1584    const Editor& editor() const { return m_editor; }
     1585    FrameSelection& selection() { return m_selection; }
     1586    const FrameSelection& selection() const { return m_selection; }
     1587
    15811588protected:
    15821589    enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     
    21142121
    21152122    HashMap<Element*, ElementIdentifier> m_identifiedElementsMap;
     2123
     2124    UniqueRef<Editor> m_editor;
     2125    UniqueRef<FrameSelection> m_selection;
    21162126};
    21172127
  • trunk/Source/WebCore/editing/AlternativeTextController.cpp

    r260753 r260831  
    8383}
    8484
    85 AlternativeTextController::AlternativeTextController(Frame& frame)
     85AlternativeTextController::AlternativeTextController(Document& document)
    8686    : m_timer(*this, &AlternativeTextController::timerFired)
    87     , m_frame(frame)
     87    , m_document(document)
    8888{
    8989}
     
    116116{
    117117    // Make sure there's no pending autocorrection before we call markMisspellingsAndBadGrammar() below.
    118     VisibleSelection currentSelection(m_frame.selection().selection());
     118    VisibleSelection currentSelection(m_document.selection().selection());
    119119    if (currentSelection == oldSelection)
    120120        return;
     
    150150bool AlternativeTextController::isSpellingMarkerAllowed(Range& misspellingRange) const
    151151{
    152     return !m_frame.document()->markers().hasMarkers(misspellingRange, DocumentMarker::SpellCheckingExemption);
     152    return !m_document.markers().hasMarkers(misspellingRange, DocumentMarker::SpellCheckingExemption);
    153153}
    154154
     
    203203        return false;
    204204
    205     Position caretPosition = m_frame.selection().selection().start();
     205    Position caretPosition = m_document.selection().selection().start();
    206206
    207207    if (m_rangeWithAlternative->endPosition() == caretPosition) {
     
    221221        client->recordAutocorrectionResponse(AutocorrectionResponse::Reverted, corrected, correction);
    222222
    223     Ref<Frame> protector(m_frame);
    224     m_frame.document()->updateLayout();
    225 
    226     m_frame.selection().setSelection(selectionOfCorrected, FrameSelection::defaultSetSelectionOptions() | FrameSelection::SpellCorrectionTriggered);
    227     auto range = m_frame.selection().selection().firstRange();
     223    RefPtr<Frame> protector(m_document.frame());
     224    m_document.updateLayout();
     225
     226    m_document.selection().setSelection(selectionOfCorrected, FrameSelection::defaultSetSelectionOptions() | FrameSelection::SpellCorrectionTriggered);
     227    auto range = m_document.selection().selection().firstRange();
    228228    if (!range)
    229229        return;
    230     auto& markers = m_frame.document()->markers();
     230    auto& markers = m_document.markers();
    231231    markers.removeMarkers(*range, OptionSet<DocumentMarker::MarkerType> { DocumentMarker::Spelling, DocumentMarker::Autocorrected }, DocumentMarkerController::RemovePartiallyOverlappingMarker);
    232232    markers.addMarker(*range, DocumentMarker::Replacement);
     
    239239    switch (m_type) {
    240240    case AlternativeTextTypeCorrection: {
    241         VisibleSelection selection(m_frame.selection().selection());
     241        VisibleSelection selection(m_document.selection().selection());
    242242        VisiblePosition start(selection.start(), selection.affinity());
    243243        VisiblePosition p = startOfWord(start, LeftWordIfOnBoundary);
    244244        VisibleSelection adjacentWords = VisibleSelection(p, start);
    245245        auto adjacentWordRange = adjacentWords.toNormalizedRange();
    246         m_frame.editor().markAllMisspellingsAndBadGrammarInRanges({ TextCheckingType::Spelling, TextCheckingType::Replacement, TextCheckingType::ShowCorrectionPanel }, createLiveRange(adjacentWordRange), createLiveRange(adjacentWordRange), nullptr);
     246        m_document.editor().markAllMisspellingsAndBadGrammarInRanges({ TextCheckingType::Spelling, TextCheckingType::Replacement, TextCheckingType::ShowCorrectionPanel }, createLiveRange(adjacentWordRange), createLiveRange(adjacentWordRange), nullptr);
    247247    }
    248248        break;
     
    267267        String paragraphText = plainText(TextCheckingParagraph(*m_rangeWithAlternative).paragraphRange());
    268268        Vector<String> suggestions;
    269         textChecker()->getGuessesForWord(m_originalText, paragraphText, m_frame.selection().selection(), suggestions);
     269        textChecker()->getGuessesForWord(m_originalText, paragraphText, m_document.selection().selection(), suggestions);
    270270        if (suggestions.isEmpty()) {
    271271            m_rangeWithAlternative = nullptr;
     
    305305{
    306306    Range* rangeWithAlternative = m_rangeWithAlternative.get();
    307     if (!rangeWithAlternative || m_frame.document() != &rangeWithAlternative->ownerDocument())
     307    if (!rangeWithAlternative || m_document != rangeWithAlternative->ownerDocument())
    308308        return;
    309309
     
    343343FloatRect AlternativeTextController::rootViewRectForRange(const SimpleRange& range) const
    344344{
    345     auto* view = m_frame.view();
     345    auto* view = m_document.frame()->view();
    346346    if (!view)
    347347        return { };
     
    351351void AlternativeTextController::respondToChangedSelection(const VisibleSelection& oldSelection)
    352352{
    353     VisibleSelection currentSelection(m_frame.selection().selection());
     353    VisibleSelection currentSelection(m_document.selection().selection());
    354354    // When user moves caret to the end of autocorrected word and pauses, we show the panel
    355355    // containing the original pre-correction word so that user can quickly revert the
     
    386386{
    387387    if (command->isTopLevelCommand() && !command->shouldRetainAutocorrectionIndicator())
    388         m_frame.document()->markers().removeMarkers(DocumentMarker::CorrectionIndicator);
     388        m_document.markers().removeMarkers(DocumentMarker::CorrectionIndicator);
    389389
    390390    markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(command);
     
    401401    if (!range)
    402402        return;
    403     auto& markers = m_frame.document()->markers();
     403    auto& markers = m_document.markers();
    404404    markers.addMarker(*range, DocumentMarker::Replacement);
    405405    markers.addMarker(*range, DocumentMarker::SpellCheckingExemption);
     
    408408EditorClient* AlternativeTextController::editorClient()
    409409{
    410     return m_frame.page() ? &m_frame.page()->editorClient() : nullptr;
     410    return m_document.page() ? &m_document.page()->editorClient() : nullptr;
    411411}
    412412
     
    484484    // whitespace. So if the user types the same original word again at this position, we
    485485    // won't autocorrect it again.
    486     m_frame.document()->markers().addMarker(precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
     486    m_document.markers().addMarker(precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
    487487}
    488488
    489489bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult& result, Range& rangeWithAlternative, const String& stringToBeReplaced)
    490490{
    491     auto& markers = m_frame.document()->markers();
     491    auto& markers = m_document.markers();
    492492    if (markers.hasMarkers(rangeWithAlternative, DocumentMarker::Replacement)) {
    493493        if (result.type == TextCheckingType::Correction)
     
    525525        return false;
    526526    Node* node = endOfWordPosition.containerNode();
    527     auto wordRange = Range::create(*m_frame.document(), node, marker.startOffset(), node, marker.endOffset());
     527    auto wordRange = Range::create(m_document, node, marker.startOffset(), node, marker.endOffset());
    528528    String currentWord = plainText(wordRange);
    529529    if (!currentWord.length())
     
    563563AlternativeTextClient* AlternativeTextController::alternativeTextClient()
    564564{
    565     return m_frame.page() ? m_frame.page()->alternativeTextClient() : nullptr;
     565    return m_document.frame() && m_document.page() ? m_document.page()->alternativeTextClient() : nullptr;
    566566}
    567567
     
    600600    // Recalculate pragraphRangeContainingCorrection, since SpellingCorrectionCommand modified the DOM, such that the original paragraphRangeContainingCorrection is no longer valid. Radar: 10305315 Bugzilla: 89526
    601601    auto updatedParagraphStartContainingCorrection = resolveCharacterLocation(makeRangeSelectingNodeContents(treeScopeRoot), paragraphOffsetInTreeScope);
    602     auto updatedParagraphEndContainingCorrection = makeBoundaryPoint(m_frame.selection().selection().start());
     602    auto updatedParagraphEndContainingCorrection = makeBoundaryPoint(m_document.selection().selection().start());
    603603    if (!updatedParagraphEndContainingCorrection)
    604604        return;
     
    622622        target = triggeringEvent->target();
    623623    else
    624         target = eventTargetElementForDocument(m_frame.document());
     624        target = eventTargetElementForDocument(&m_document);
    625625    if (!target)
    626626        return false;
    627627
    628     auto event = TextEvent::createForDictation(&m_frame.windowProxy(), text, dictationAlternatives);
     628    auto event = TextEvent::createForDictation(&m_document.frame()->windowProxy(), text, dictationAlternatives);
    629629    event->setUnderlyingEvent(triggeringEvent);
    630630
     
    658658{
    659659#if USE(DICTATION_ALTERNATIVES)
    660     auto& editor = m_frame.editor();
     660    auto& editor = m_document.editor();
    661661    auto selection = editor.selectedRange();
    662662    if (!selection || !editor.shouldInsertText(alternativeString, selection.get(), EditorInsertAction::Pasted))
  • trunk/Source/WebCore/editing/AlternativeTextController.h

    r259575 r260831  
    3636
    3737class CompositeEditCommand;
     38class Document;
    3839class EditCommand;
    3940class EditCommandComposition;
    4041class EditorClient;
    4142class Event;
    42 class Frame;
    4343class Range;
    4444class TextCheckerClient;
     
    6262    WTF_MAKE_FAST_ALLOCATED;
    6363public:
    64     explicit AlternativeTextController(Frame& frame) UNLESS_ENABLED( : m_frame(frame) { })
     64    explicit AlternativeTextController(Document& document) UNLESS_ENABLED(: m_document(document) { })
    6565    ~AlternativeTextController() UNLESS_ENABLED({ })
    6666
     
    146146#endif
    147147
    148     Frame& m_frame;
     148    Document& m_document;
    149149};
    150150
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r260725 r260831  
    229229    // Desktop handles this in -[WebHTMLView _updateSelectionForInputManager], but the phone
    230230    // goes another route.
    231     frame->editor().cancelComposition();
     231    m_document->editor().cancelComposition();
    232232#endif
    233233
    234     if (!frame->editor().willUnapplyEditing(*this))
     234    if (!m_document->editor().willUnapplyEditing(*this))
    235235        return;
    236236
     
    239239        m_commands[i - 1]->doUnapply();
    240240
    241     frame->editor().unappliedEditing(*this);
     241    m_document->editor().unappliedEditing(*this);
    242242
    243243    if (AXObjectCache::accessibilityEnabled())
     
    259259    m_document->updateLayoutIgnorePendingStylesheets();
    260260
    261     if (!frame->editor().willReapplyEditing(*this))
     261    if (!m_document->editor().willReapplyEditing(*this))
    262262        return;
    263263
     
    265265        command->doReapply();
    266266
    267     frame->editor().reappliedEditing(*this);
     267    m_document->editor().reappliedEditing(*this);
    268268
    269269    if (AXObjectCache::accessibilityEnabled())
     
    320320bool CompositeEditCommand::willApplyCommand()
    321321{
    322     return frame().editor().willApplyEditing(*this, targetRangesForBindings());
     322    return document().editor().willApplyEditing(*this, targetRangesForBindings());
    323323}
    324324
     
    379379void CompositeEditCommand::didApplyCommand()
    380380{
    381     frame().editor().appliedEditing(*this);
     381    document().editor().appliedEditing(*this);
    382382}
    383383
     
    385385{
    386386    ASSERT(!isEditingTextAreaOrTextInput());
    387     auto firstRange = frame().selection().selection().firstRange();
     387    auto firstRange = document().selection().selection().firstRange();
    388388    if (!firstRange)
    389389        return { };
     
    14691469
    14701470    setEndingSelection(VisibleSelection(start, end, DOWNSTREAM));
    1471     frame().editor().clearMisspellingsAndBadGrammar(endingSelection());
     1471    document().editor().clearMisspellingsAndBadGrammar(endingSelection());
    14721472    deleteSelection(false, false, false, false);
    14731473
     
    15051505    applyCommandToComposite(ReplaceSelectionCommand::create(document(), WTFMove(fragment), options));
    15061506
    1507     frame().editor().markMisspellingsAndBadGrammar(endingSelection());
     1507    document().editor().markMisspellingsAndBadGrammar(endingSelection());
    15081508
    15091509    // 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

    r260725 r260831  
    335335    // position (now deleted), we need to clear that style as well.
    336336    if (m_upstreamStart.deprecatedNode() == m_downstreamEnd.deprecatedNode() && m_upstreamStart.deprecatedNode()->isTextNode()) {
    337         frame().selection().clearTypingStyle();
     337        document().selection().clearTypingStyle();
    338338        return;
    339339    }
     
    745745    auto range = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
    746746    auto rangeToBeReplaced = Range::create(document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
    747     if (!frame().editor().client()->shouldMoveRangeAfterDelete(range.ptr(), rangeToBeReplaced.ptr()))
     747    if (!document().editor().client()->shouldMoveRangeAfterDelete(range.ptr(), rangeToBeReplaced.ptr()))
    748748        return;
    749749   
     
    819819    // but, if we change the selection, come back and start typing that style should be lost.  Also see
    820820    // preserveTypingStyle() below.
    821     frame().selection().setTypingStyle(m_typingStyle.copyRef());
     821    document().selection().setTypingStyle(m_typingStyle.copyRef());
    822822}
    823823
     
    890890        Element* textControl = enclosingTextFormControl(m_selectionToDelete.start());
    891891        if (textControl && textControl->focused())
    892             frame().editor().textWillBeDeletedInTextField(textControl);
     892            document().editor().textWillBeDeletedInTextField(textControl);
    893893    }
    894894
     
    945945
    946946    bool shouldRebalaceWhiteSpace = true;
    947     if (!frame().editor().behavior().shouldRebalanceWhiteSpacesInSecureField()) {
     947    if (!document().editor().behavior().shouldRebalanceWhiteSpacesInSecureField()) {
    948948        Node* node = m_endingPosition.deprecatedNode();
    949949        if (is<Text>(node)) {
     
    959959
    960960    if (!originalString.isEmpty())
    961         frame().editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
     961        document().editor().deletedAutocorrectionAtPosition(m_endingPosition, originalString);
    962962
    963963    setEndingSelection(VisibleSelection(m_endingPosition, affinity, endingSelection().isDirectional()));
  • trunk/Source/WebCore/editing/EditCommand.cpp

    r254945 r260831  
    3333#include "Editor.h"
    3434#include "Element.h"
    35 #include "Frame.h"
    3635#include "HTMLInputElement.h"
    3736#include "HTMLTextAreaElement.h"
     
    128127    , m_editingAction(editingAction)
    129128{
    130     ASSERT(document.frame());
    131     setStartingSelection(m_document->frame()->selection().selection());
     129    setStartingSelection(m_document->selection().selection());
    132130    setEndingSelection(m_startingSelection);
    133131}
     
    136134    : m_document(document)
    137135{
    138     ASSERT(document.frame());
    139136    setStartingSelection(startingSelection);
    140137    setEndingSelection(endingSelection);
     
    142139
    143140EditCommand::~EditCommand() = default;
    144 
    145 Frame& EditCommand::frame()
    146 {
    147     ASSERT(document().frame());
    148     return *document().frame();
    149 }
    150 
    151 const Frame& EditCommand::frame() const
    152 {
    153     ASSERT(document().frame());
    154     return *document().frame();
    155 }
    156141
    157142EditAction EditCommand::editingAction() const
     
    169154bool EditCommand::isEditingTextAreaOrTextInput() const
    170155{
    171     auto* frame = m_document->frame();
    172     if (!frame)
    173         return false;
    174 
    175     auto* container = frame->selection().selection().start().containerNode();
     156    auto* container = m_document->selection().selection().start().containerNode();
    176157    if (!container)
    177158        return false;
     
    218199    if (!AXObjectCache::accessibilityEnabled())
    219200        return;
    220     postTextStateChangeNotification(type, text, frame().selection().selection().start());
     201    postTextStateChangeNotification(type, text, m_document->selection().selection().start());
    221202}
    222203
  • trunk/Source/WebCore/editing/EditCommand.h

    r235775 r260831  
    3939class Document;
    4040class Element;
    41 class Frame;
    4241
    4342String inputTypeNameForEditingAction(EditAction);
     
    6564    EditCommand(Document&, const VisibleSelection&, const VisibleSelection&);
    6665
    67     const Frame& frame() const;
    68     Frame& frame();
    6966    const Document& document() const { return m_document; }
    7067    Document& document() { return m_document; }
  • trunk/Source/WebCore/editing/Editing.cpp

    r260759 r260831  
    899899Ref<HTMLElement> createDefaultParagraphElement(Document& document)
    900900{
    901     switch (document.frame()->editor().defaultParagraphSeparator()) {
     901    switch (document.editor().defaultParagraphSeparator()) {
    902902    case EditorParagraphSeparatorIsDiv:
    903903        return HTMLDivElement::create(document);
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r260725 r260831  
    16871687
    16881688    reconcileTextDecorationProperties(mutableStyle.get());
    1689     bool shouldStyleWithCSS = document->frame()->editor().shouldStyleWithCSS();
     1689    bool shouldStyleWithCSS = document->editor().shouldStyleWithCSS();
    16901690    if (!shouldStyleWithCSS)
    16911691        extractTextStyles(*document, *mutableStyle, computedStyle.useFixedFontDefaultSize());
  • trunk/Source/WebCore/editing/Editor.cpp

    r260753 r260831  
    174174public:
    175175    ClearTextCommand(Document& document);
    176     static void CreateAndApply(const RefPtr<Frame> frame);
    177    
     176    static void CreateAndApply(Document&);
     177
    178178private:
    179179    EditAction editingAction() const override;
     
    190190}
    191191
    192 void ClearTextCommand::CreateAndApply(const RefPtr<Frame> frame)
    193 {
    194     if (frame->selection().isNone())
     192void ClearTextCommand::CreateAndApply(Document& document)
     193{
     194    if (document.selection().isNone())
    195195        return;
    196196
    197197    // Don't leave around stale composition state.
    198     frame->editor().clear();
     198    document.editor().clear();
    199199   
    200     const VisibleSelection oldSelection = frame->selection().selection();
    201     frame->selection().selectAll();
    202     auto clearCommand = adoptRef(*new ClearTextCommand(*frame->document()));
     200    const VisibleSelection oldSelection = document.selection().selection();
     201    document.selection().selectAll();
     202    auto clearCommand = adoptRef(*new ClearTextCommand(document));
    203203    clearCommand->setStartingSelection(oldSelection);
    204204    clearCommand->apply();
     
    208208using namespace WTF::Unicode;
    209209
    210 TemporarySelectionChange::TemporarySelectionChange(Frame& frame, Optional<VisibleSelection> temporarySelection, OptionSet<TemporarySelectionOption> options)
    211     : m_frame(frame)
     210TemporarySelectionChange::TemporarySelectionChange(Document& document, Optional<VisibleSelection> temporarySelection, OptionSet<TemporarySelectionOption> options)
     211    : m_document(RefPtr(&document))
    212212    , m_options(options)
    213     , m_wasIgnoringSelectionChanges(frame.editor().ignoreSelectionChanges())
     213    , m_wasIgnoringSelectionChanges(document.editor().ignoreSelectionChanges())
    214214#if PLATFORM(IOS_FAMILY)
    215     , m_appearanceUpdatesWereEnabled(frame.selection().isUpdateAppearanceEnabled())
     215    , m_appearanceUpdatesWereEnabled(document.selection().isUpdateAppearanceEnabled())
    216216#endif
    217217{
    218218#if PLATFORM(IOS_FAMILY)
    219219    if (options & TemporarySelectionOption::EnableAppearanceUpdates)
    220         frame.selection().setUpdateAppearanceEnabled(true);
     220        document.selection().setUpdateAppearanceEnabled(true);
    221221#endif
    222222
    223223    if (options & TemporarySelectionOption::IgnoreSelectionChanges)
    224         frame.editor().setIgnoreSelectionChanges(true);
     224        document.editor().setIgnoreSelectionChanges(true);
    225225
    226226    if (temporarySelection) {
    227         m_selectionToRestore = frame.selection().selection();
     227        m_selectionToRestore = document.selection().selection();
    228228        setSelection(temporarySelection.value());
    229229    }
     
    237237    if (m_options & TemporarySelectionOption::IgnoreSelectionChanges) {
    238238        auto revealSelection = m_options & TemporarySelectionOption::RevealSelection ? Editor::RevealSelection::Yes : Editor::RevealSelection::No;
    239         m_frame->editor().setIgnoreSelectionChanges(m_wasIgnoringSelectionChanges, revealSelection);
     239        m_document->editor().setIgnoreSelectionChanges(m_wasIgnoringSelectionChanges, revealSelection);
    240240    }
    241241
    242242#if PLATFORM(IOS_FAMILY)
    243243    if (m_options & TemporarySelectionOption::EnableAppearanceUpdates)
    244         m_frame->selection().setUpdateAppearanceEnabled(m_appearanceUpdatesWereEnabled);
     244        m_document->selection().setUpdateAppearanceEnabled(m_appearanceUpdatesWereEnabled);
    245245#endif
    246246}
     
    251251    if (m_options & TemporarySelectionOption::DoNotSetFocus)
    252252        options.add(FrameSelection::DoNotSetFocus);
    253     m_frame->selection().setSelection(selection, options);
     253    m_document->selection().setSelection(selection, options);
    254254}
    255255
     
    258258VisibleSelection Editor::selectionForCommand(Event* event)
    259259{
    260     auto selection = m_frame.selection().selection();
     260    auto selection = m_document.selection().selection();
    261261    if (!event)
    262262        return selection;
     
    277277EditingBehavior Editor::behavior() const
    278278{
    279     return EditingBehavior(m_frame.settings().editingBehaviorType());
     279    return EditingBehavior(m_document.settings().editingBehaviorType());
    280280}
    281281
    282282EditorClient* Editor::client() const
    283283{
    284     if (Page* page = m_frame.page())
     284    if (Page* page = m_document.page())
    285285        return &page->editorClient();
    286286    return nullptr;
     
    345345bool Editor::canEdit() const
    346346{
    347     return m_frame.selection().selection().rootEditableElement();
     347    return m_document.selection().selection().rootEditableElement();
    348348}
    349349
    350350bool Editor::canEditRichly() const
    351351{
    352     return m_frame.selection().selection().isContentRichlyEditable();
     352    return m_document.selection().selection().isContentRichlyEditable();
    353353}
    354354
     
    443443bool Editor::canDHTMLCut()
    444444{
    445     if (m_frame.selection().selection().isInPasswordField())
     445    if (m_document.selection().selection().isInPasswordField())
    446446        return false;
    447447
     
    451451bool Editor::canDHTMLCopy()
    452452{
    453     if (m_frame.selection().selection().isInPasswordField())
     453    if (m_document.selection().selection().isInPasswordField())
    454454        return false;
    455455    return !dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::BeforeCopy);
     
    485485    if (imageElementFromImageDocument(document()))
    486486        return true;
    487     const VisibleSelection& selection = m_frame.selection().selection();
     487    const VisibleSelection& selection = m_document.selection().selection();
    488488    return selection.isRange() && !selection.isInPasswordField();
    489489}
     
    491491bool Editor::canPaste() const
    492492{
    493     if (m_frame.mainFrame().loader().shouldSuppressTextInputFromEditing())
     493    if (m_document.frame()->mainFrame().loader().shouldSuppressTextInputFromEditing())
    494494        return false;
    495495
     
    499499bool Editor::canDelete() const
    500500{
    501     const VisibleSelection& selection = m_frame.selection().selection();
     501    const VisibleSelection& selection = m_document.selection().selection();
    502502    return selection.isRange() && selection.rootEditableElement();
    503503}
     
    525525    if (behavior().shouldAlwaysSmartDelete())
    526526        return true;
    527     return m_frame.selection().granularity() == WordGranularity;
     527    return m_document.selection().granularity() == WordGranularity;
    528528}
    529529
     
    548548        return false;
    549549
    550     if (m_frame.selection().isRange()) {
     550    if (m_document.selection().isRange()) {
    551551        if (isTypingAction) {
    552552            TypingCommand::deleteKeyPressed(document(), canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity);
     
    588588void Editor::deleteSelectionWithSmartDelete(bool smartDelete, EditAction editingAction)
    589589{
    590     if (m_frame.selection().isNone())
     590    if (m_document.selection().isNone())
    591591        return;
    592592
     
    596596void Editor::clearText()
    597597{
    598     ClearTextCommand::CreateAndApply(&m_frame);
     598    ClearTextCommand::CreateAndApply(m_document);
    599599}
    600600
     
    662662void Editor::replaceSelectionWithFragment(DocumentFragment& fragment, SelectReplacement selectReplacement, SmartReplace smartReplace, MatchStyle matchStyle, EditAction editingAction, MailBlockquoteHandling mailBlockquoteHandling)
    663663{
    664     VisibleSelection selection = m_frame.selection().selection();
     664    VisibleSelection selection = m_document.selection().selection();
    665665    if (selection.isNone() || !selection.isContentEditable())
    666666        return;
     
    690690        revealSelectionAfterEditingOperation();
    691691
    692     selection = m_frame.selection().selection();
     692    selection = m_document.selection().selection();
    693693    if (selection.isInPasswordField())
    694694        return;
     
    696696    if (AXObjectCache::accessibilityEnabled() && editingAction == EditAction::Paste) {
    697697        String text = AccessibilityObject::stringForVisiblePositionRange(command->visibleSelectionForInsertedText());
    698         replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypePaste, text, m_frame.selection().selection());
     698        replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypePaste, text, m_document.selection().selection());
    699699        command->composition()->setRangeDeletedByUnapply(replacedText.replacedRange());
    700700    }
     
    702702    if (AXObjectCache::accessibilityEnabled() && editingAction == EditAction::Insert) {
    703703        String text = command->documentFragmentPlainText();
    704         replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeInsert, text, m_frame.selection().selection());
     704        replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeInsert, text, m_document.selection().selection());
    705705        command->composition()->setRangeDeletedByUnapply(replacedText.replacedRange());
    706706    }
     
    729729RefPtr<Range> Editor::selectedRange()
    730730{
    731     return createLiveRange(m_frame.selection().selection().toNormalizedRange());
     731    return createLiveRange(m_document.selection().selection().toNormalizedRange());
    732732}
    733733
     
    745745bool Editor::tryDHTMLCopy()
    746746{   
    747     if (m_frame.selection().selection().isInPasswordField())
     747    if (m_document.selection().selection().isInPasswordField())
    748748        return false;
    749749
     
    753753bool Editor::tryDHTMLCut()
    754754{
    755     if (m_frame.selection().selection().isInPasswordField())
     755    if (m_document.selection().selection().isInPasswordField())
    756756        return false;
    757757   
     
    761761bool Editor::shouldInsertText(const String& text, Range* range, EditorInsertAction action) const
    762762{
    763     if (m_frame.mainFrame().loader().shouldSuppressTextInputFromEditing() && action == EditorInsertAction::Typed)
     763    if (m_document.frame()->mainFrame().loader().shouldSuppressTextInputFromEditing() && action == EditorInsertAction::Typed)
    764764        return false;
    765765
     
    783783bool Editor::hasBidiSelection() const
    784784{
    785     if (m_frame.selection().isNone())
     785    if (m_document.selection().isNone())
    786786        return false;
    787787
    788788    Node* startNode;
    789     if (m_frame.selection().isRange()) {
    790         startNode = m_frame.selection().selection().start().downstream().deprecatedNode();
    791         Node* endNode = m_frame.selection().selection().end().upstream().deprecatedNode();
     789    if (m_document.selection().isRange()) {
     790        startNode = m_document.selection().selection().start().downstream().deprecatedNode();
     791        Node* endNode = m_document.selection().selection().end().upstream().deprecatedNode();
    792792        if (enclosingBlock(startNode) != enclosingBlock(endNode))
    793793            return false;
    794794    } else
    795         startNode = m_frame.selection().selection().visibleStart().deepEquivalent().deprecatedNode();
     795        startNode = m_document.selection().selection().visibleStart().deepEquivalent().deprecatedNode();
    796796
    797797    if (!startNode)
     
    813813TriState Editor::selectionUnorderedListState() const
    814814{
    815     if (m_frame.selection().isCaret()) {
    816         if (enclosingElementWithTag(m_frame.selection().selection().start(), ulTag))
     815    if (m_document.selection().isCaret()) {
     816        if (enclosingElementWithTag(m_document.selection().selection().start(), ulTag))
    817817            return TrueTriState;
    818     } else if (m_frame.selection().isRange()) {
    819         auto* startNode = enclosingElementWithTag(m_frame.selection().selection().start(), ulTag);
    820         auto* endNode = enclosingElementWithTag(m_frame.selection().selection().end(), ulTag);
     818    } else if (m_document.selection().isRange()) {
     819        auto* startNode = enclosingElementWithTag(m_document.selection().selection().start(), ulTag);
     820        auto* endNode = enclosingElementWithTag(m_document.selection().selection().end(), ulTag);
    821821        if (startNode && endNode && startNode == endNode)
    822822            return TrueTriState;
     
    828828TriState Editor::selectionOrderedListState() const
    829829{
    830     if (m_frame.selection().isCaret()) {
    831         if (enclosingElementWithTag(m_frame.selection().selection().start(), olTag))
     830    if (m_document.selection().isCaret()) {
     831        if (enclosingElementWithTag(m_document.selection().selection().start(), olTag))
    832832            return TrueTriState;
    833     } else if (m_frame.selection().isRange()) {
    834         auto* startNode = enclosingElementWithTag(m_frame.selection().selection().start(), olTag);
    835         auto* endNode = enclosingElementWithTag(m_frame.selection().selection().end(), olTag);
     833    } else if (m_document.selection().isRange()) {
     834        auto* startNode = enclosingElementWithTag(m_document.selection().selection().start(), olTag);
     835        auto* endNode = enclosingElementWithTag(m_document.selection().selection().end(), olTag);
    836836        if (startNode && endNode && startNode == endNode)
    837837            return TrueTriState;
     
    873873RefPtr<Node> Editor::increaseSelectionListLevel()
    874874{
    875     if (!canEditRichly() || m_frame.selection().isNone())
     875    if (!canEditRichly() || m_document.selection().isNone())
    876876        return nullptr;
    877877   
     
    883883RefPtr<Node> Editor::increaseSelectionListLevelOrdered()
    884884{
    885     if (!canEditRichly() || m_frame.selection().isNone())
     885    if (!canEditRichly() || m_document.selection().isNone())
    886886        return nullptr;
    887887   
     
    893893RefPtr<Node> Editor::increaseSelectionListLevelUnordered()
    894894{
    895     if (!canEditRichly() || m_frame.selection().isNone())
     895    if (!canEditRichly() || m_document.selection().isNone())
    896896        return nullptr;
    897897   
     
    903903void Editor::decreaseSelectionListLevel()
    904904{
    905     if (!canEditRichly() || m_frame.selection().isNone())
     905    if (!canEditRichly() || m_document.selection().isNone())
    906906        return;
    907907   
     
    933933Element* Editor::findEventTargetFromSelection() const
    934934{
    935     return findEventTargetFrom(m_frame.selection().selection());
     935    return findEventTargetFrom(m_document.selection().selection());
    936936}
    937937
     
    947947        return;
    948948
    949     auto selectionType = m_frame.selection().selection().selectionType();
     949    auto selectionType = m_document.selection().selection().selectionType();
    950950    if (selectionType == VisibleSelection::NoSelection)
    951951        return;
     
    953953    String inputTypeName = inputTypeNameForEditingAction(editingAction);
    954954    String inputEventData = inputEventDataForEditingStyleAndAction(*style, editingAction);
    955     RefPtr<Element> element = m_frame.selection().selection().rootEditableElement();
     955    RefPtr<Element> element = m_document.selection().selection().rootEditableElement();
    956956    if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData))
    957957        return;
     
    970970    }
    971971
    972     client()->didApplyStyle();
     972    if (client())
     973        client()->didApplyStyle();
    973974    if (element)
    974975        dispatchInputEvent(*element, inputTypeName, inputEventData);
     
    985986        return;
    986987
    987     auto selectionType = m_frame.selection().selection().selectionType();
     988    auto selectionType = m_document.selection().selection().selectionType();
    988989    if (selectionType == VisibleSelection::NoSelection)
    989990        return;
     
    991992    String inputTypeName = inputTypeNameForEditingAction(editingAction);
    992993    String inputEventData = inputEventDataForEditingStyleAndAction(style, editingAction);
    993     RefPtr<Element> element = m_frame.selection().selection().rootEditableElement();
     994    RefPtr<Element> element = m_document.selection().selection().rootEditableElement();
    994995    if (element && !dispatchBeforeInputEvent(*element, inputTypeName, inputEventData))
    995996        return;
     
    10061007        return;
    10071008
    1008     if (!client() || !client()->shouldApplyStyle(style, createLiveRange(m_frame.selection().selection().toNormalizedRange()).get()))
     1009    if (!client() || !client()->shouldApplyStyle(style, createLiveRange(m_document.selection().selection().toNormalizedRange()).get()))
    10091010        return;
    10101011    applyStyle(style, editingAction);
     
    10171018
    10181019    // FIXME: This is wrong for text decorations since m_mutableStyle is empty.
    1019     if (!client() || !client()->shouldApplyStyle(style->styleWithResolvedTextDecorations().ptr(), createLiveRange(m_frame.selection().selection().toNormalizedRange()).get()))
     1020    if (!client() || !client()->shouldApplyStyle(style->styleWithResolvedTextDecorations().ptr(), createLiveRange(m_document.selection().selection().toNormalizedRange()).get()))
    10201021        return;
    10211022
     
    10281029        return;
    10291030   
    1030     if (client() && client()->shouldApplyStyle(style, createLiveRange(m_frame.selection().selection().toNormalizedRange()).get()))
     1031    if (client() && client()->shouldApplyStyle(style, createLiveRange(m_document.selection().selection().toNormalizedRange()).get()))
    10311032        applyParagraphStyle(style, editingAction);
    10321033}
     
    10341035bool Editor::selectionStartHasStyle(CSSPropertyID propertyID, const String& value) const
    10351036{
    1036     if (auto editingStyle = EditingStyle::styleAtSelectionStart(m_frame.selection().selection(), propertyID == CSSPropertyBackgroundColor))
     1037    if (auto editingStyle = EditingStyle::styleAtSelectionStart(m_document.selection().selection(), propertyID == CSSPropertyBackgroundColor))
    10371038        return editingStyle->hasStyle(propertyID, value);
    10381039    return false;
     
    10411042TriState Editor::selectionHasStyle(CSSPropertyID propertyID, const String& value) const
    10421043{
    1043     return EditingStyle::create(propertyID, value)->triStateOfStyle(m_frame.selection().selection());
     1044    return EditingStyle::create(propertyID, value)->triStateOfStyle(m_document.selection().selection());
    10441045}
    10451046
    10461047String Editor::selectionStartCSSPropertyValue(CSSPropertyID propertyID)
    10471048{
    1048     RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(m_frame.selection().selection(),
     1049    RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(m_document.selection().selection(),
    10491050        propertyID == CSSPropertyBackgroundColor);
    10501051    if (!selectionStyle || !selectionStyle->style())
     
    11371138
    11381139        if (!command.preservesTypingStyle())
    1139             m_frame.selection().clearTypingStyle();
     1140            m_document.selection().clearTypingStyle();
    11401141
    11411142        // Command will be equal to last edit command only in the case of typing
     
    12011202}
    12021203
    1203 Editor::Editor(Frame& frame)
    1204     : m_frame(frame)
     1204Editor::Editor(Document& document)
     1205    : m_document(document)
    12051206    , m_killRing(makeUnique<PAL::KillRing>())
    1206     , m_spellChecker(makeUnique<SpellChecker>(frame))
    1207     , m_alternativeTextController(makeUnique<AlternativeTextController>(frame))
     1207    , m_spellChecker(makeUnique<SpellChecker>(document))
     1208    , m_alternativeTextController(makeUnique<AlternativeTextController>(document))
    12081209    , m_editorUIUpdateTimer(*this, &Editor::editorUIUpdateTimerFired)
    12091210#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS_FAMILY)
     
    12211222        m_compositionNode = nullptr;
    12221223        if (EditorClient* client = this->client())
    1223             client->discardedComposition(&m_frame);
     1224            client->discardedComposition(m_document.frame());
    12241225    }
    12251226    m_customCompositionUnderlines.clear();
     
    12301231    m_oldSelectionForEditorUIUpdate = { };
    12311232    m_editorUIUpdateTimer.stop();
     1233    m_alternativeTextController->stopAlternativeTextUITimer();
    12321234
    12331235#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS_FAMILY)
     
    12391241bool Editor::insertText(const String& text, Event* triggeringEvent, TextEventInputType inputType)
    12401242{
    1241     return m_frame.eventHandler().handleTextInputEvent(text, triggeringEvent, inputType);
     1243    return m_document.frame()->eventHandler().handleTextInputEvent(text, triggeringEvent, inputType);
    12421244}
    12431245
    12441246bool Editor::insertTextForConfirmedComposition(const String& text)
    12451247{
    1246     return m_frame.eventHandler().handleTextInputEvent(text, 0, TextEventInputComposition);
     1248    return m_document.frame()->eventHandler().handleTextInputEvent(text, 0, TextEventInputComposition);
    12471249}
    12481250
     
    13031305            // is set for the newly focused frame.
    13041306            if (client() && client()->shouldRevealCurrentSelectionAfterInsertion()) {
    1305                 if (auto* editedFrame = document->frame()) {
    1306                     if (auto* page = editedFrame->page())
    1307                         page->revealCurrentSelection();
    1308                 }
     1307                if (auto* page = document->page())
     1308                    page->revealCurrentSelection();
    13091309            }
    13101310        }
     
    13191319        return false;
    13201320
    1321     if (!shouldInsertText("\n", createLiveRange(m_frame.selection().selection().toNormalizedRange()).get(), EditorInsertAction::Typed))
     1321    if (!shouldInsertText("\n", createLiveRange(m_document.selection().selection().toNormalizedRange()).get(), EditorInsertAction::Typed))
    13221322        return true;
    13231323
    1324     VisiblePosition caret = m_frame.selection().selection().visibleStart();
     1324    VisiblePosition caret = m_document.selection().selection().visibleStart();
    13251325    bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
    13261326    bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate();
     
    13381338    if (!canEditRichly())
    13391339        return insertLineBreak();
    1340 
    1341     if (!shouldInsertText("\n", createLiveRange(m_frame.selection().selection().toNormalizedRange()).get(), EditorInsertAction::Typed))
     1340   
     1341    if (!shouldInsertText("\n", createLiveRange(m_document.selection().selection().toNormalizedRange()).get(), EditorInsertAction::Typed))
    13421342        return true;
    13431343
    1344     VisiblePosition caret = m_frame.selection().selection().visibleStart();
     1344    VisiblePosition caret = m_document.selection().selection().visibleStart();
    13451345    bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
    13461346    bool autocorrectionIsApplied = m_alternativeTextController->applyAutocorrectionBeforeTypingIfAppropriate();
     
    14061406    }
    14071407
    1408     if (enclosingTextFormControl(m_frame.selection().selection().start()))
     1408    if (enclosingTextFormControl(m_document.selection().selection().start()))
    14091409        Pasteboard::createForCopyAndPaste()->writePlainText(selectedTextForDataTransfer(), canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
    14101410    else {
     
    14251425#else
    14261426            // FIXME: Delete after <http://webkit.org/b/177618> lands.
    1427             Pasteboard::createForCopyAndPaste()->writeSelection(*selection, canSmartCopyOrDelete(), m_frame, IncludeImageAltTextForDataTransfer);
     1427            Pasteboard::createForCopyAndPaste()->writeSelection(*selection, canSmartCopyOrDelete(), *m_document.frame(), IncludeImageAltTextForDataTransfer);
    14281428#endif
    14291429        }
     
    14341434        String text;
    14351435        if (AXObjectCache::accessibilityEnabled())
    1436             text = AccessibilityObject::stringForVisiblePositionRange(m_frame.selection().selection());
     1436            text = AccessibilityObject::stringForVisiblePositionRange(m_document.selection().selection());
    14371437        deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), EditAction::Cut);
    14381438        if (AXObjectCache::accessibilityEnabled())
    1439             postTextStateChangeNotificationForCut(text, m_frame.selection().selection());
     1439            postTextStateChangeNotificationForCut(text, m_document.selection().selection());
    14401440    }
    14411441}
     
    14541454    updateMarkersForWordsAffectedByEditing(false);
    14551455    ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader());
    1456     if (m_frame.selection().selection().isContentRichlyEditable())
     1456    if (m_document.selection().selection().isContentRichlyEditable())
    14571457        pasteWithPasteboard(&pasteboard, { PasteOption::AllowPlainText });
    14581458    else
     
    14791479    ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader());
    14801480    auto pasteboard = Pasteboard::createForCopyAndPaste();
    1481     if (m_frame.selection().selection().isContentRichlyEditable())
     1481    if (m_document.selection().selection().isContentRichlyEditable())
    14821482        pasteWithPasteboard(pasteboard.get(), { PasteOption::AllowPlainText, PasteOption::AsQuotation });
    14831483    else
     
    16171617        return;
    16181618
    1619     auto startContainer = makeRefPtr(m_frame.selection().selection().start().containerNode());
     1619    auto startContainer = makeRefPtr(m_document.selection().selection().start().containerNode());
    16201620    if (!startContainer)
    16211621        return;
     
    18511851{
    18521852#if PLATFORM(IOS_FAMILY)
    1853     if (inSameParagraph(m_frame.selection().selection().visibleStart(), m_frame.selection().selection().visibleEnd()) &&
    1854         baseWritingDirectionForSelectionStart() == direction)
     1853    if (inSameParagraph(m_document.selection().selection().visibleStart(), m_document.selection().selection().visibleEnd())
     1854        && baseWritingDirectionForSelectionStart() == direction)
    18551855        return;
    18561856#endif
     
    18821882    auto result = WritingDirection::LeftToRight;
    18831883
    1884     Position pos = m_frame.selection().selection().visibleStart().deepEquivalent();
     1884    Position pos = m_document.selection().selection().visibleStart().deepEquivalent();
    18851885    Node* node = pos.deprecatedNode();
    18861886    if (!node)
     
    19171917    VisibleSelection selection;
    19181918    selection.setWithoutValidation(range->startPosition(), range->endPosition());
    1919     m_frame.selection().setSelection(selection, { });
     1919    m_document.selection().setSelection(selection, { });
    19201920}
    19211921
     
    19521952class SetCompositionScope {
    19531953public:
    1954     SetCompositionScope(Frame& frame)
    1955         : m_frame(frame)
    1956         , m_typingGestureIndicator(frame)
     1954    SetCompositionScope(Document& document)
     1955        : m_document(RefPtr(&document))
     1956        , m_typingGestureIndicator(*document.frame())
    19571957    {
    1958         m_frame->editor().setIgnoreSelectionChanges(true);
     1958        m_document->editor().setIgnoreSelectionChanges(true);
    19591959    }
    19601960
    19611961    ~SetCompositionScope()
    19621962    {
    1963         m_frame->editor().setIgnoreSelectionChanges(false);
    1964         if (auto* editorClient = m_frame->editor().client())
     1963        m_document->editor().setIgnoreSelectionChanges(false);
     1964        if (auto* editorClient = m_document->editor().client())
    19651965            editorClient->didUpdateComposition();
    19661966    }
    19671967
    1968     Ref<Frame> m_frame;
     1968    RefPtr<Document> m_document;
    19691969    UserTypingGestureIndicator m_typingGestureIndicator;
    19701970};
     
    19731973{
    19741974    ASSERT(mode == ConfirmComposition || mode == CancelComposition);
    1975     SetCompositionScope setCompositionScope(m_frame);
     1975    SetCompositionScope setCompositionScope(m_document);
    19761976
    19771977    if (mode == CancelComposition)
     
    19841984    m_customCompositionHighlights.clear();
    19851985
    1986     if (m_frame.selection().isNone())
     1986    if (m_document.selection().isNone())
    19871987        return;
    19881988
     
    20002000    if (mode == CancelComposition) {
    20012001        // An open typing command that disagrees about current selection would cause issues with typing later on.
    2002         TypingCommand::closeTyping(&m_frame);
     2002        TypingCommand::closeTyping(m_document);
    20032003    }
    20042004}
     
    20062006void Editor::setComposition(const String& text, const Vector<CompositionUnderline>& underlines, const Vector<CompositionHighlight>& highlights, unsigned selectionStart, unsigned selectionEnd)
    20072007{
    2008     SetCompositionScope setCompositionScope(m_frame);
     2008    SetCompositionScope setCompositionScope(m_document);
    20092009
    20102010    // Updates styles before setting selection for composition to prevent
     
    20152015    selectComposition();
    20162016
    2017     if (m_frame.selection().isNone())
     2017    if (m_document.selection().isNone())
    20182018        return;
    20192019
     
    20232023        // We pass TypingCommand::TextCompositionFinal here to indicate that we are removing composition text that has been finalized.
    20242024        TypingCommand::deleteSelection(document(), 0, TypingCommand::TextCompositionFinal);
    2025         const VisibleSelection& currentSelection = m_frame.selection().selection();
     2025        const VisibleSelection& currentSelection = m_document.selection().selection();
    20262026        if (currentSelection.isRange()) {
    20272027            // If deletion was prevented, then we need to collapse the selection to the end so that the original text will not be recomposed.
    2028             m_frame.selection().setSelection({ currentSelection.end(), currentSelection.end() });
     2028            m_document.selection().setSelection({ currentSelection.end(), currentSelection.end() });
    20292029        }
    20302030    }
     
    20822082
    20832083        // Find out what node has the composition now.
    2084         Position base = m_frame.selection().selection().base().downstream();
    2085         Position extent = m_frame.selection().selection().extent();
     2084        Position base = m_document.selection().selection().base().downstream();
     2085        Position extent = m_document.selection().selection().extent();
    20862086        Node* baseNode = base.deprecatedNode();
    20872087        unsigned baseOffset = base.deprecatedEditingOffset();
     
    21092109            unsigned end = std::min(std::max(start, baseOffset + selectionEnd), extentOffset);
    21102110            auto selectedRange = Range::create(baseNode->document(), baseNode, start, baseNode, end);
    2111             m_frame.selection().setSelectedRange(selectedRange.ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::No);
     2111            m_document.selection().setSelectedRange(selectedRange.ptr(), DOWNSTREAM, FrameSelection::ShouldCloseTyping::No);
    21122112        }
    21132113    }
     
    21232123        return;
    21242124       
    2125     if (auto selectedRange = m_frame.selection().selection().toNormalizedRange())
     2125    if (auto selectedRange = m_document.selection().selection().toNormalizedRange())
    21262126        document().markers().removeMarkers(*selectedRange, DocumentMarker::Spelling);
    21272127
     
    21382138    // FIXME: On Mac OS X, when use "learn" button on "Spelling and Grammar" panel, we don't call this function. It should remove misspelling markers around the learned word, see <rdar://problem/5396072>.
    21392139
    2140     if (auto selectedRange = m_frame.selection().selection().toNormalizedRange())
     2140    if (auto selectedRange = m_document.selection().selection().toNormalizedRange())
    21412141        document().markers().removeMarkers(*selectedRange, DocumentMarker::Spelling);
    21422142
     
    21502150void Editor::advanceToNextMisspelling(bool startBeforeSelection)
    21512151{
    2152     Ref<Frame> protection(m_frame);
     2152    Ref<Document> protectedDocument(m_document);
    21532153
    21542154    // The basic approach is to search in two phases - from the selection end to the end of the doc, and
     
    21572157    // Start at the end of the selection, search to edge of document.  Starting at the selection end makes
    21582158    // repeated "check spelling" commands work.
    2159     VisibleSelection selection(m_frame.selection().selection());
     2159    VisibleSelection selection(m_document.selection().selection());
    21602160    Ref<Range> spellingSearchRange = rangeOfContents(document());
    21612161
     
    23062306        // FIXME 4859190: This gets confused with doubled punctuation at the end of a paragraph
    23072307        auto badGrammarRange = resolveCharacterRange(*grammarSearchRange, { grammarPhraseOffset + grammarDetail.range.location, grammarDetail.range.length });
    2308         m_frame.selection().setSelection(VisibleSelection(badGrammarRange, SEL_DEFAULT_AFFINITY));
    2309         m_frame.selection().revealSelection();
     2308        m_document.selection().setSelection(VisibleSelection(badGrammarRange, SEL_DEFAULT_AFFINITY));
     2309        m_document.selection().revealSelection();
    23102310       
    23112311        client()->updateSpellingUIWithGrammarString(badGrammarPhrase, grammarDetail);
     
    23182318       
    23192319        auto misspellingRange = resolveCharacterRange(spellingSearchRange, { misspellingOffset, misspelledWord.length() });
    2320         m_frame.selection().setSelection(VisibleSelection(misspellingRange, DOWNSTREAM));
    2321         m_frame.selection().revealSelection();
     2320        m_document.selection().setSelection(VisibleSelection(misspellingRange, DOWNSTREAM));
     2321        m_document.selection().revealSelection();
    23222322       
    23232323        client()->updateSpellingUIWithMisspelledWord(misspelledWord);
     
    23332333        return String();
    23342334
    2335     VisibleSelection selection = m_frame.selection().selection();
     2335    VisibleSelection selection = m_document.selection().selection();
    23362336    if (!selection.isContentEditable() || selection.isNone())
    23372337        return String();
     
    23872387{
    23882388#if USE(GRAMMAR_CHECKING)
    2389     auto range = m_frame.selection().selection().toNormalizedRange();
     2389    auto range = m_document.selection().selection().toNormalizedRange();
    23902390    if (!range || !client())
    23912391        return false;
     
    24022402    Vector<String> guesses;
    24032403    if (client())
    2404         textChecker()->getGuessesForWord(word, String(), m_frame.selection().selection(), guesses);
     2404        textChecker()->getGuessesForWord(word, String(), m_document.selection().selection(), guesses);
    24052405    return guesses;
    24062406}
     
    24102410    if (unifiedTextCheckerEnabled()) {
    24112411        Optional<SimpleRange> range;
    2412         VisibleSelection selection = m_frame.selection().selection();
     2412        VisibleSelection selection = m_document.selection().selection();
    24132413        if (selection.isCaret() && behavior().shouldAllowSpellingSuggestionsWithoutSelection()) {
    24142414            VisibleSelection wordSelection = VisibleSelection(selection.base());
     
    24702470void Editor::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping, bool doReplacement)
    24712471{
    2472     Ref<Frame> protection(m_frame);
     2472    Ref<Document> protectedDocument(m_document);
    24732473
    24742474    if (platformDrivenTextCheckerEnabled())
     
    25922592    if (!autocorrectedString.isEmpty()) {
    25932593        VisibleSelection newSelection(*misspellingRange, DOWNSTREAM);
    2594         if (newSelection != m_frame.selection().selection()) {
    2595             if (!m_frame.selection().shouldChangeSelection(newSelection))
     2594        if (newSelection != m_document.selection().selection()) {
     2595            if (!m_document.selection().shouldChangeSelection(newSelection))
    25962596                return;
    2597             m_frame.selection().setSelection(newSelection);
     2597            m_document.selection().setSelection(newSelection);
    25982598        }
    25992599
    2600         if (!m_frame.editor().shouldInsertText(autocorrectedString, misspellingRange.get(), EditorInsertAction::Typed))
     2600        if (!m_document.editor().shouldInsertText(autocorrectedString, misspellingRange.get(), EditorInsertAction::Typed))
    26012601            return;
    2602         m_frame.editor().replaceSelectionWithText(autocorrectedString, SelectReplacement::No, SmartReplace::No, EditAction::Insert);
     2602        m_document.editor().replaceSelectionWithText(autocorrectedString, SelectReplacement::No, SmartReplace::No, EditAction::Insert);
    26032603
    26042604        // Reset the charet one character further.
    2605         m_frame.selection().moveTo(m_frame.selection().selection().end());
    2606         m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
     2605        m_document.selection().moveTo(m_document.selection().selection().end());
     2606        m_document.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
    26072607    }
    26082608
     
    26762676bool Editor::isSpellCheckingEnabledInFocusedNode() const
    26772677{
    2678     return isSpellCheckingEnabledFor(m_frame.selection().selection().start().deprecatedNode());
     2678    return isSpellCheckingEnabledFor(m_document.selection().selection().start().deprecatedNode());
    26792679}
    26802680
     
    27242724        return;
    27252725
    2726     bool asynchronous = m_frame.settings().asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel;
     2726    bool asynchronous = m_document.settings().asynchronousSpellCheckingEnabled() && !shouldShowCorrectionPanel;
    27272727
    27282728    // In asynchronous mode, we intentionally check paragraph-wide sentence.
     
    27392739
    27402740    Vector<TextCheckingResult> results;
    2741     checkTextOfParagraph(*textChecker(), paragraphToCheck.text(), resolvedOptions, results, m_frame.selection().selection());
     2741    checkTextOfParagraph(*textChecker(), paragraphToCheck.text(), resolvedOptions, results, m_document.selection().selection());
    27422742    markAndReplaceFor(request.releaseNonNull(), results);
    27432743}
     
    27852785void Editor::markAndReplaceFor(const SpellCheckRequest& request, const Vector<TextCheckingResult>& results)
    27862786{
    2787     Ref<Frame> protection(m_frame);
     2787    Ref<Document> protectedDocument(m_document);
    27882788
    27892789    auto textCheckingOptions = request.data().checkingTypes();
     
    28092809
    28102810    if (shouldPerformReplacement || shouldMarkSpelling || shouldCheckForCorrection) {
    2811         if (m_frame.selection().selection().selectionType() == VisibleSelection::CaretSelection) {
     2811        if (m_document.selection().selection().selectionType() == VisibleSelection::CaretSelection) {
    28122812            // Attempt to save the caret position so we can restore it later if needed
    2813             Position caretPosition = m_frame.selection().selection().end();
     2813            Position caretPosition = m_document.selection().selection().end();
    28142814            selectionOffset = paragraph.offsetTo(caretPosition).releaseReturnValue();
    28152815            restoreSelectionAfterChange = true;
     
    28932893
    28942894            VisibleSelection selectionToReplace(rangeToReplace, DOWNSTREAM);
    2895             if (selectionToReplace != m_frame.selection().selection()) {
    2896                 if (!m_frame.selection().shouldChangeSelection(selectionToReplace))
     2895            if (selectionToReplace != m_document.selection().selection()) {
     2896                if (!m_document.selection().shouldChangeSelection(selectionToReplace))
    28972897                    continue;
    28982898            }
    28992899
    29002900            if (resultType == TextCheckingType::Link) {
    2901                 m_frame.selection().setSelection(selectionToReplace);
     2901                m_document.selection().setSelection(selectionToReplace);
    29022902                selectionChanged = true;
    29032903                restoreSelectionAfterChange = false;
     
    29082908
    29092909                if (AXObjectCache* cache = document().existingAXObjectCache()) {
    2910                     if (Element* root = m_frame.selection().selection().rootEditableElement())
     2910                    if (Element* root = m_document.selection().selection().rootEditableElement())
    29112911                        cache->postNotification(root, AXObjectCache::AXAutocorrectionOccured);
    29122912                }
     
    29382938        if (restoreSelectionAfterChange && selectionOffset <= extendedParagraph.rangeLength()) {
    29392939            auto selectionRange = extendedParagraph.subrange({ 0, selectionOffset });
    2940             m_frame.selection().moveTo(selectionRange->endPosition(), DOWNSTREAM);
     2940            m_document.selection().moveTo(selectionRange->endPosition(), DOWNSTREAM);
    29412941            if (adjustSelectionForParagraphBoundaries)
    2942                 m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
     2942                m_document.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
    29432943        } else {
    29442944            // If this fails for any reason, the fallback is to go one position beyond the last replacement
    2945             m_frame.selection().moveTo(m_frame.selection().selection().end());
    2946             m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
     2945            m_document.selection().moveTo(m_document.selection().selection().end());
     2946            m_document.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
    29472947        }
    29482948    }
     
    30213021    // selection, and remove words between the selection boundaries.
    30223022    //
    3023     VisiblePosition startOfSelection = m_frame.selection().selection().start();
    3024     VisiblePosition endOfSelection = m_frame.selection().selection().end();
     3023    VisiblePosition startOfSelection = m_document.selection().selection().start();
     3024    VisiblePosition endOfSelection = m_document.selection().selection().end();
    30253025    if (startOfSelection.isNull())
    30263026        return;
     
    30943094RefPtr<Range> Editor::rangeForPoint(const IntPoint& windowPoint)
    30953095{
    3096     auto document = m_frame.documentAtPoint(windowPoint);
     3096    auto document = m_document.frame()->documentAtPoint(windowPoint);
    30973097    if (!document)
    30983098        return nullptr;
    3099 
     3099   
    31003100    auto frame = document->frame();
    31013101    if (!frame)
    31023102        return nullptr;
    3103 
     3103   
    31043104    auto frameView = frame->view();
    31053105    if (!frameView)
     
    31173117
    31183118    SelectionRevealMode revealMode = SelectionRevealMode::Reveal;
    3119     m_frame.selection().revealSelection(revealMode, alignment, revealExtentOption);
     3119    m_document.selection().revealSelection(revealMode, alignment, revealExtentOption);
    31203120}
    31213121
     
    31293129    // FIXME: Should suppress selection change notifications during a composition change <https://webkit.org/b/38830>
    31303130    if (!ignore)
    3131         respondToChangedSelection(m_frame.selection().selection(), { });
     3131        respondToChangedSelection(m_document.selection().selection(), { });
    31323132#endif
    31333133    if (!ignore && shouldRevealExistingSelection == RevealSelection::Yes)
     
    31523152    if (!m_compositionNode)
    31533153        return false;
    3154     const VisibleSelection& selection = m_frame.selection().selection();
     3154    const VisibleSelection& selection = m_document.selection().selection();
    31553155    Position start = selection.start();
    31563156    if (start.deprecatedNode() != m_compositionNode)
     
    31753175        return;
    31763176
    3177     VisibleSelection selection = m_frame.selection().selection();
     3177    VisibleSelection selection = m_document.selection().selection();
    31783178    if (!selection.isCaret())
    31793179        return;
     
    32003200
    32013201    // Select the two characters.
    3202     if (newSelection != m_frame.selection().selection()) {
    3203         if (!m_frame.selection().shouldChangeSelection(newSelection))
     3202    if (newSelection != m_document.selection().selection()) {
     3203        if (!m_document.selection().shouldChangeSelection(newSelection))
    32043204            return;
    3205         m_frame.selection().setSelection(newSelection);
     3205        m_document.selection().setSelection(newSelection);
    32063206    }
    32073207
     
    32553255void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection, OptionSet<FrameSelection::SetSelectionOption> options)
    32563256{
    3257     Ref<Frame> protection(m_frame);
     3257    Ref<Document> protectedDocument(m_document);
    32583258
    32593259    // If the new selection is orphaned, then don't update the selection.
     
    32653265    // The old selection can be invalid here and calling shouldChangeSelection can produce some strange calls.
    32663266    // See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
    3267     bool selectionDidNotChangeDOMPosition = newSelection == m_frame.selection().selection();
    3268     if (selectionDidNotChangeDOMPosition || m_frame.selection().shouldChangeSelection(newSelection))
    3269         m_frame.selection().setSelection(newSelection, options);
     3267    bool selectionDidNotChangeDOMPosition = newSelection == m_document.selection().selection();
     3268    if (selectionDidNotChangeDOMPosition || m_document.selection().shouldChangeSelection(newSelection))
     3269        m_document.selection().setSelection(newSelection, options);
    32703270
    32713271    // Some editing operations change the selection visually without affecting its position within the DOM.
     
    32823282#endif
    32833283    if (selectionDidNotChangeDOMPosition && client())
    3284         client()->respondToChangedSelection(&m_frame);
     3284        client()->respondToChangedSelection(m_document.frame());
    32853285}
    32863286
     
    32883288{
    32893289    TextIteratorBehavior behavior = TextIteratorDefaultBehavior;
    3290     if (m_frame.settings().selectionAcrossShadowBoundariesEnabled())
     3290    if (m_document.settings().selectionAcrossShadowBoundariesEnabled())
    32913291        behavior |= TextIteratorTraversesFlatTree;
    32923292    return selectedText(behavior);
     
    32963296{
    32973297    TextIteratorBehavior behavior = TextIteratorEmitsImageAltText;
    3298     if (m_frame.settings().selectionAcrossShadowBoundariesEnabled())
     3298    if (m_document.settings().selectionAcrossShadowBoundariesEnabled())
    32993299        behavior |= TextIteratorTraversesFlatTree;
    33003300    return selectedText(behavior);
     
    33043304{
    33053305    // We remove '\0' characters because they are not visibly rendered to the user.
    3306     auto& selection = m_frame.selection().selection();
     3306    auto& selection = m_document.selection().selection();
    33073307    auto start = selection.start();
    33083308    auto end = selection.end();
     
    33143314RefPtr<TextPlaceholderElement> Editor::insertTextPlaceholder(const IntSize& size)
    33153315{
    3316     if (m_frame.selection().isNone() || !m_frame.selection().selection().isContentEditable())
     3316    if (m_document.selection().isNone() || !m_document.selection().selection().isContentEditable())
    33173317        return nullptr;
    33183318
     
    33223322    deleteSelectionWithSmartDelete(false);
    33233323
    3324     auto range = m_frame.selection().selection().toNormalizedRange();
     3324    auto range = m_document.selection().selection().toNormalizedRange();
    33253325    if (!range)
    33263326        return nullptr;
     
    33303330
    33313331    VisibleSelection newSelection { positionBeforeNode(placeholder.ptr()), positionAfterNode(placeholder.ptr()) };
    3332     m_frame.selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions(UserTriggered));
     3332    m_document.selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions(UserTriggered));
    33333333
    33343334    return placeholder;
     
    33503350
    33513351    // To match the Legacy WebKit implementation, set the text insertion point to be before where the placeholder use to be.
    3352     if (m_frame.selection().isFocusedAndActive() && document->focusedElement() == savedRootEditableElement)
    3353         m_frame.selection().setSelection(VisibleSelection { savedPositionBeforePlaceholder, SEL_DEFAULT_AFFINITY }, FrameSelection::defaultSetSelectionOptions(UserTriggered));
     3352    if (m_document.selection().isFocusedAndActive() && document->focusedElement() == savedRootEditableElement)
     3353        m_document.selection().setSelection(VisibleSelection { savedPositionBeforePlaceholder, SEL_DEFAULT_AFFINITY }, FrameSelection::defaultSetSelectionOptions(UserTriggered));
    33543354}
    33553355
     
    34033403{
    34043404#if PLATFORM(IOS_FAMILY)
    3405     if (m_frame.selectionChangeCallbacksDisabled())
     3405    if (m_document.frame() && m_document.frame()->selectionChangeCallbacksDisabled())
    34063406        return true;
    34073407#endif
     
    34123412{
    34133413    if (style.isEmpty()) {
    3414         m_frame.selection().clearTypingStyle();
     3414        m_document.selection().clearTypingStyle();
    34153415        return;
    34163416    }
     
    34183418    // Calculate the current typing style.
    34193419    RefPtr<EditingStyle> typingStyle;
    3420     if (auto existingTypingStyle = m_frame.selection().typingStyle())
     3420    if (auto existingTypingStyle = m_document.selection().typingStyle())
    34213421        typingStyle = existingTypingStyle->copy();
    34223422    else
    34233423        typingStyle = EditingStyle::create();
    3424     typingStyle->overrideTypingStyleAt(style, m_frame.selection().selection().visibleStart().deepEquivalent());
     3424    typingStyle->overrideTypingStyleAt(style, m_document.selection().selection().visibleStart().deepEquivalent());
    34253425
    34263426    // Handle block styles, substracting these from the typing style.
     
    34303430
    34313431    // Set the remaining style as the typing style.
    3432     m_frame.selection().setTypingStyle(WTFMove(typingStyle));
     3432    m_document.selection().setTypingStyle(WTFMove(typingStyle));
    34333433}
    34343434
     
    34893489bool Editor::findString(const String& target, FindOptions options)
    34903490{
    3491     Ref<Frame> protection(m_frame);
    3492 
    3493     VisibleSelection selection = m_frame.selection().selection();
     3491    Ref<Document> protectedDocument(m_document);
     3492
     3493    VisibleSelection selection = m_document.selection().selection();
    34943494
    34953495    auto resultRange = rangeOfString(target, createLiveRange(selection.firstRange()).get(), options);
     
    34973497        return false;
    34983498
    3499     m_frame.selection().setSelection(VisibleSelection(*resultRange, DOWNSTREAM));
     3499    m_document.selection().setSelection(VisibleSelection(*resultRange, DOWNSTREAM));
    35003500
    35013501    if (!(options.contains(DoNotRevealSelection)))
    3502         m_frame.selection().revealSelection();
     3502        m_document.selection().revealSelection();
    35033503
    35043504    return true;
     
    35973597        if (&range->ownerDocument() == &document())
    35983598            searchRange = range;
    3599         else if (!isFrameInRange(m_frame, *range))
     3599        else if (!isFrameInRange(*m_document.frame(), *range))
    36003600            return 0;
    36013601    }
     
    36673667
    36683668    if (client())
    3669         client()->respondToChangedSelection(&m_frame);
     3669        client()->respondToChangedSelection(m_document.frame());
    36703670
    36713671#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS_FAMILY)
     
    36903690bool Editor::shouldDetectTelephoneNumbers() const
    36913691{
    3692     return m_frame.document() && document().isTelephoneNumberParsingEnabled() && TelephoneNumberDetector::isSupported();
     3692    return m_document.isTelephoneNumberParsingEnabled() && TelephoneNumberDetector::isSupported();
    36933693}
    36943694
     
    37333733    m_detectedTelephoneNumberRanges.clear();
    37343734
    3735     auto& selection = m_frame.selection();
     3735    auto& selection = m_document.selection();
    37363736    if (selection.isRange()) {
    37373737        if (auto selectedRange = selection.selection().firstRange()) {
     
    37503750    }
    37513751
    3752     if (auto* page = m_frame.page())
     3752    if (auto* page = m_document.page())
    37533753        page->servicesOverlayController().selectedTelephoneNumberRangesChanged();
    37543754}
     
    37753775        VisibleSelection newAdjacentWords;
    37763776        VisibleSelection newSelectedSentence;
    3777         bool caretBrowsing = m_frame.settings().caretBrowsingEnabled();
    3778         if (m_frame.selection().selection().isContentEditable() || caretBrowsing) {
    3779             VisiblePosition newStart(m_frame.selection().selection().visibleStart());
     3777        bool caretBrowsing = m_document.settings().caretBrowsingEnabled();
     3778        if (m_document.selection().selection().isContentEditable() || caretBrowsing) {
     3779            VisiblePosition newStart(m_document.selection().selection().visibleStart());
    37803780#if !PLATFORM(IOS_FAMILY)
    37813781            newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
     
    38303830        m_alternativeTextController->respondToChangedSelection(oldSelection);
    38313831
    3832     m_oldSelectionForEditorUIUpdate = m_frame.selection().selection();
     3832    m_oldSelectionForEditorUIUpdate = m_document.selection().selection();
    38333833
    38343834#if ENABLE(ATTACHMENT_ELEMENT)
     
    38573857bool Editor::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const
    38583858{
    3859     Node* node = findFirstMarkable(m_frame.selection().selection().start().deprecatedNode());
     3859    Node* node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode());
    38603860    if (!node)
    38613861        return false;
     
    39353935String Editor::stringForCandidateRequest() const
    39363936{
    3937     auto& selection = m_frame.selection().selection();
     3937    auto& selection = m_document.selection().selection();
    39383938    auto range = selection.isCaret()
    3939         ? wordRangeFromPosition(selection.start())
    3940         : createLiveRange(selection.toNormalizedRange());
     3939    ? wordRangeFromPosition(selection.start())
     3940    : createLiveRange(selection.toNormalizedRange());
    39413941    if (!range)
    39423942        return { };
     
    39483948RefPtr<Range> Editor::contextRangeForCandidateRequest() const
    39493949{
    3950     const VisibleSelection& selection = m_frame.selection().selection();
     3950    const VisibleSelection& selection = m_document.selection().selection();
    39513951    return makeRange(startOfParagraph(selection.visibleStart()), endOfParagraph(selection.visibleEnd()));
    39523952}
     
    40154015    FontAttributes attributes;
    40164016    Node* nodeToRemove = nullptr;
    4017     auto* style = styleForSelectionStart(&m_frame, nodeToRemove);
     4017    auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove);
    40184018    if (!style) {
    40194019        if (nodeToRemove)
     
    40564056    }
    40574057
    4058     attributes.textLists = editableTextListsAtPositionInDescendingOrder(m_frame.selection().selection().start());
     4058    attributes.textLists = editableTextListsAtPositionInDescendingOrder(m_document.selection().selection().start());
    40594059
    40604060    switch (style->textAlign()) {
     
    40824082    }
    40834083
    4084     auto typingStyle = makeRefPtr(m_frame.selection().typingStyle());
     4084    auto typingStyle = makeRefPtr(m_document.selection().typingStyle());
    40854085    if (typingStyle && typingStyle->style()) {
    40864086        auto value = typingStyle->style()->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
     
    41704170        client()->didRemoveAttachmentWithIdentifier(identifier);
    41714171
    4172     auto* document = m_frame.document();
    4173     if (!document)
    4174         return;
    4175 
    41764172    for (auto& identifier : insertedAttachmentIdentifiers) {
    4177         if (auto attachment = document->attachmentForIdentifier(identifier))
     4173        if (auto attachment = m_document.attachmentForIdentifier(identifier))
    41784174            client()->didInsertAttachmentWithIdentifier(identifier, attachment->attributeWithoutSynchronization(HTMLNames::srcAttr), attachment->hasEnclosingImage());
    41794175        else
     
    41984194void Editor::handleAcceptedCandidate(TextCheckingResult acceptedCandidate)
    41994195{
    4200     const VisibleSelection& selection = m_frame.selection().selection();
     4196    const VisibleSelection& selection = m_document.selection().selection();
    42014197
    42024198    m_isHandlingAcceptedCandidate = true;
     
    42174213bool Editor::unifiedTextCheckerEnabled() const
    42184214{
    4219     return WebCore::unifiedTextCheckerEnabled(&m_frame);
     4215    return WebCore::unifiedTextCheckerEnabled(m_document.frame());
    42204216}
    42214217
     
    42334229{
    42344230    m_overwriteModeEnabled = !m_overwriteModeEnabled;
    4235     m_frame.selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
    4236 }
    4237 
    4238 Document& Editor::document() const
    4239 {
    4240     ASSERT(m_frame.document());
    4241     return *m_frame.document();
     4231    m_document.selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
    42424232}
    42434233
     
    42924282    hasMultipleFonts = false;
    42934283
    4294     if (!m_frame.selection().isRange()) {
     4284    if (!m_document.selection().isRange()) {
    42954285        Node* nodeToRemove;
    4296         auto* style = styleForSelectionStart(&m_frame, nodeToRemove); // sets nodeToRemove
     4286        auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove); // sets nodeToRemove
    42974287
    42984288        const Font* font = nullptr;
     
    43064296    }
    43074297
    4308     auto range = m_frame.selection().selection().toNormalizedRange();
     4298    auto range = m_document.selection().selection().toNormalizedRange();
    43094299    if (!range)
    43104300        return nullptr;
    43114301
    43124302    // FIXME: Adjusting the start may move it past the end. In that case the iterator below will go on to the end of the document.
    4313     auto adjustedStart = makeBoundaryPoint(adjustedSelectionStartForStyleComputation(m_frame.selection().selection()));
     4303    auto adjustedStart = makeBoundaryPoint(adjustedSelectionStartForStyleComputation(m_document.selection().selection()));
    43144304    if (!adjustedStart)
    43154305        return nullptr;
     
    43404330bool Editor::canCopyExcludingStandaloneImages() const
    43414331{
    4342     auto& selection = m_frame.selection().selection();
     4332    auto& selection = m_document.selection().selection();
    43434333    return selection.isRange() && !selection.isInPasswordField();
    43444334}
  • trunk/Source/WebCore/editing/Editor.h

    r260753 r260831  
    3434#include "EditorInsertAction.h"
    3535#include "FindOptions.h"
     36#include "Frame.h"
    3637#include "FrameSelection.h"
    3738#include "PasteboardWriterData.h"
     
    120121class TemporarySelectionChange {
    121122public:
    122     WEBCORE_EXPORT TemporarySelectionChange(Frame&, Optional<VisibleSelection> = WTF::nullopt, OptionSet<TemporarySelectionOption> = { });
     123    WEBCORE_EXPORT TemporarySelectionChange(Document&, Optional<VisibleSelection> = WTF::nullopt, OptionSet<TemporarySelectionOption> = { });
    123124    WEBCORE_EXPORT ~TemporarySelectionChange();
    124125
     
    126127    void setSelection(const VisibleSelection&);
    127128
    128     Ref<Frame> m_frame;
     129    RefPtr<Document> m_document;
    129130    OptionSet<TemporarySelectionOption> m_options;
    130131    bool m_wasIgnoringSelectionChanges;
     
    138139public:
    139140    IgnoreSelectionChangeForScope(Frame& frame)
    140         : m_selectionChange(frame, WTF::nullopt, TemporarySelectionOption::IgnoreSelectionChanges)
     141        : m_selectionChange(*frame.document(), WTF::nullopt, TemporarySelectionOption::IgnoreSelectionChanges)
    141142    {
    142143    }
     
    151152    WTF_MAKE_FAST_ALLOCATED;
    152153public:
    153     explicit Editor(Frame&);
     154    explicit Editor(Document&);
    154155    ~Editor();
    155156
     
    272273    public:
    273274        WEBCORE_EXPORT Command();
    274         Command(const EditorInternalCommand*, EditorCommandSource, Frame&);
     275        Command(const EditorInternalCommand*, EditorCommandSource, Document&);
    275276
    276277        WEBCORE_EXPORT bool execute(const String& parameter = String(), Event* triggeringEvent = nullptr) const;
     
    289290        const EditorInternalCommand* m_command { nullptr };
    290291        EditorCommandSource m_source;
     292        RefPtr<Document> m_document;
    291293        RefPtr<Frame> m_frame;
    292294    };
     
    569571
    570572private:
    571     Document& document() const;
     573    Document& document() const { return m_document; }
    572574
    573575    bool canDeleteRange(Range*) const;
     
    620622    void postTextStateChangeNotificationForCut(const String&, const VisibleSelection&);
    621623
    622     Frame& m_frame;
     624    Document& m_document;
    623625    RefPtr<CompositeEditCommand> m_lastEditCommand;
    624626    RefPtr<Text> m_compositionNode;
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r260725 r260831  
    11081108static bool executeSwapWithMark(Frame& frame, Event*, EditorCommandSource, const String&)
    11091109{
     1110    RefPtr<Document> protection(frame.document());
    11101111    Ref<Frame> protector(frame);
    11111112    const VisibleSelection& mark = frame.editor().mark();
     
    18351836Editor::Command Editor::command(const String& commandName)
    18361837{
    1837     return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, m_frame);
     1838    return Command(internalCommand(commandName), CommandFromMenuOrKeyBinding, m_document);
    18381839}
    18391840
    18401841Editor::Command Editor::command(const String& commandName, EditorCommandSource source)
    18411842{
    1842     return Command(internalCommand(commandName), source, m_frame);
     1843    return Command(internalCommand(commandName), source, m_document);
    18431844}
    18441845
     
    18521853}
    18531854
    1854 Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, Frame& frame)
     1855Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSource source, Document& document)
    18551856    : m_command(command)
    18561857    , m_source(source)
    1857     , m_frame(command ? &frame : nullptr)
    1858 {
    1859     ASSERT(command || !m_frame);
     1858    , m_document(command ? &document : nullptr)
     1859    , m_frame(command ? document.frame() : nullptr)
     1860{
     1861    ASSERT(command || !m_document);
    18601862}
    18611863
     
    18671869            return false;
    18681870    }
    1869     auto document = m_frame->document();
    1870     document->updateLayoutIgnorePendingStylesheets();
    1871     if (m_frame->document() != document)
     1871
     1872    m_document->updateLayoutIgnorePendingStylesheets();
     1873    if (m_document->frame() != m_frame)
    18721874        return false;
    18731875
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r260725 r260831  
    140140}
    141141
    142 static inline bool shouldAlwaysUseDirectionalSelection(Frame* frame)
    143 {
    144     return !frame || frame->editor().behavior().shouldConsiderSelectionAsDirectional();
    145 }
    146 
    147 FrameSelection::FrameSelection(Frame* frame)
    148     : m_frame(frame)
     142static inline bool shouldAlwaysUseDirectionalSelection(Document* document)
     143{
     144    return !document || document->editor().behavior().shouldConsiderSelectionAsDirectional();
     145}
     146
     147FrameSelection::FrameSelection(Document* document)
     148    : m_document(document)
     149    , m_frame(document? document->frame() : nullptr)
    149150    , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation())
    150151    , m_granularity(CharacterGranularity)
     
    157158    , m_caretPaint(true)
    158159    , m_isCaretBlinkingSuspended(false)
    159     , m_focused(frame && frame->page() && frame->page()->focusController().focusedFrame() == frame)
     160    , m_focused(m_frame && m_frame->page() && m_frame->page()->focusController().focusedFrame() == m_frame)
    160161    , m_shouldShowBlockCursor(false)
    161162    , m_pendingSelectionUpdate(false)
     
    166167#endif
    167168{
    168     if (shouldAlwaysUseDirectionalSelection(m_frame))
     169    if (shouldAlwaysUseDirectionalSelection(m_document))
    169170        m_selection.setIsDirectional(true);
     171
     172    bool activeAndFocused = isFocusedAndActive();
     173    if (activeAndFocused)
     174        setSelectionFromNone();
     175#if USE(UIKIT_EDITING)
     176    // Caret blinking (blinks | does not blink)
     177    setCaretVisible(activeAndFocused);
     178#else
     179    setCaretVisibility(activeAndFocused ? Visible : Hidden);
     180#endif
    170181}
    171182
     
    173184{
    174185    Element* selectionRoot = m_selection.rootEditableElement();
    175     return selectionRoot ? selectionRoot : m_frame->document()->documentElement();
     186    return selectionRoot ? selectionRoot : m_document->documentElement();
    176187}
    177188
     
    285296{
    286297    VisibleSelection newSelection = passedNewSelection;
    287     bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSelection.isDirectional();
     298    bool isDirectional = shouldAlwaysUseDirectionalSelection(m_document) || newSelection.isDirectional();
    288299
    289300    VisiblePosition base = m_originalBase.isNotNull() ? m_originalBase : newSelection.visibleBase();
     
    323334
    324335    VisibleSelection newSelection = newSelectionPossiblyWithoutDirection;
    325     if (shouldAlwaysUseDirectionalSelection(m_frame))
     336    if (shouldAlwaysUseDirectionalSelection(m_document))
    326337        newSelection.setIsDirectional(true);
    327338
     
    335346    if (Document* newSelectionDocument = newSelection.base().document()) {
    336347        if (RefPtr<Frame> newSelectionFrame = newSelectionDocument->frame()) {
    337             if (newSelectionFrame != m_frame && newSelectionDocument != m_frame->document()) {
     348            if (newSelectionFrame != m_frame && newSelectionDocument != m_document) {
    338349                newSelectionFrame->selection().setSelection(newSelection, options, AXTextStateChangeIntent(), align, granularity);
    339350                // It's possible that during the above set selection, this FrameSelection has been modified by
     
    350361
    351362    if (closeTyping)
    352         TypingCommand::closeTyping(m_frame);
     363        TypingCommand::closeTyping(*m_document);
    353364
    354365    if (shouldClearTypingStyle)
     
    358369    bool didMutateSelection = oldSelection != newSelection;
    359370    if (didMutateSelection)
    360         m_frame->editor().selectionWillChange();
     371        m_document->editor().selectionWillChange();
    361372
    362373    m_selection = newSelection;
     
    372383
    373384    if (!newSelection.isNone() && !(options & DoNotSetFocus)) {
    374         auto* oldFocusedElement = m_frame->document()->focusedElement();
     385        auto* oldFocusedElement = m_document->focusedElement();
    375386        setFocusedElementIfNeeded();
    376387        // FIXME: Should not be needed.
    377         if (m_frame->document()->focusedElement() != oldFocusedElement)
    378             m_frame->document()->updateStyleIfNeeded();
     388        if (m_document->focusedElement() != oldFocusedElement)
     389            m_document->updateStyleIfNeeded();
    379390    }
    380391
     
    383394    m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation();
    384395    selectFrameElementInParentIfFullySelected();
    385     m_frame->editor().respondToChangedSelection(oldSelection, options);
     396    m_document->editor().respondToChangedSelection(oldSelection, options);
    386397    // https://www.w3.org/TR/selection-api/#selectionchange-event
    387398    // FIXME: Spec doesn't specify which task source to use.
    388     m_frame->document()->queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().selectionchangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
     399    m_document->queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().selectionchangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
    389400
    390401    return true;
     
    393404void FrameSelection::setSelection(const VisibleSelection& selection, OptionSet<SetSelectionOption> options, AXTextStateChangeIntent intent, CursorAlignOnScroll align, TextGranularity granularity)
    394405{
    395     RefPtr<Frame> protectedFrame(m_frame);
     406    RefPtr<Document> protector(m_document);
    396407    if (!setSelectionWithoutUpdatingAppearance(selection, options, align, granularity))
    397         return;
    398 
    399     Document* document = m_frame->document();
    400     if (!document)
    401408        return;
    402409
     
    412419    m_pendingSelectionUpdate = true;
    413420
    414     if (document->hasPendingStyleRecalc())
    415         return;
    416 
    417     FrameView* frameView = document->view();
     421    if (m_document->hasPendingStyleRecalc())
     422        return;
     423
     424    FrameView* frameView = m_document->view();
    418425    if (frameView && frameView->layoutContext().isLayoutPending())
    419426        return;
     
    422429
    423430    if (options & IsUserTriggered) {
    424         if (auto* client = m_frame->editor().client())
     431        if (auto* client = m_document->editor().client())
    425432            client->didEndUserTriggeredSelectionChanges();
    426433    }
    427434}
    428435
    429 static void updateSelectionByUpdatingLayoutOrStyle(Frame& frame)
     436static void updateSelectionByUpdatingLayoutOrStyle(Document& document)
    430437{
    431438#if ENABLE(TEXT_CARET)
    432     frame.document()->updateLayoutIgnorePendingStylesheets();
     439    document.updateLayoutIgnorePendingStylesheets();
    433440#else
    434     frame.document()->updateStyleIfNeeded();
     441    document.updateStyleIfNeeded();
    435442#endif
    436443}
     
    442449        m_selectionRevealMode = SelectionRevealMode::Reveal;
    443450    m_pendingSelectionUpdate = true;
    444     if (RenderView* view = m_frame->contentRenderer())
     451    if (RenderView* view = m_document->renderView())
    445452        view->selection().clearSelection();
    446453}
     
    458465        ScrollAlignment alignment;
    459466
    460         if (m_frame->editor().behavior().shouldCenterAlignWhenSelectionIsRevealed())
     467        if (m_document->editor().behavior().shouldCenterAlignWhenSelectionIsRevealed())
    461468            alignment = m_alwaysAlignCursorOnScrollWhenRevealingSelection ? ScrollAlignment::alignCenterAlways : ScrollAlignment::alignCenterIfNeeded;
    462469        else
     
    472479{
    473480#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS_FAMILY)
    474     m_frame->editor().scanSelectionForTelephoneNumbers();
     481    m_document->editor().scanSelectionForTelephoneNumbers();
    475482#endif
    476483}
     
    704711    // to which depends on the value of isBaseFirst. Then this can be changed
    705712    // to just return m_sel.extent().
    706     if (m_frame && m_frame->editor().behavior().shouldAlwaysExtendSelectionFromExtentEndpoint())
     713    if (m_document && m_document->editor().behavior().shouldAlwaysExtendSelectionFromExtentEndpoint())
    707714        return m_selection.isBaseFirst() ? m_selection.visibleEnd() : m_selection.visibleStart();
    708715
     
    724731    VisiblePosition positionAfterCurrentWord = nextWordPosition(originalPosition);
    725732
    726     if (m_frame && m_frame->editor().behavior().shouldSkipSpaceWhenMovingRight()) {
     733    if (m_document && m_document->editor().behavior().shouldSkipSpaceWhenMovingRight()) {
    727734        // In order to skip spaces when moving right, we advance one
    728735        // word further and then move one word back. Given the
     
    856863        break;
    857864    case WordGranularity: {
    858         bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor().behavior().shouldSkipSpaceWhenMovingRight();
     865        bool skipsSpaceWhenMovingRight = m_document && m_document->editor().behavior().shouldSkipSpaceWhenMovingRight();
    859866        VisiblePosition currentPosition(m_selection.extent(), m_selection.affinity());
    860867        pos = rightWordPosition(currentPosition, skipsSpaceWhenMovingRight);
     
    10771084        break;
    10781085    case WordGranularity: {
    1079         bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor().behavior().shouldSkipSpaceWhenMovingRight();
     1086        bool skipsSpaceWhenMovingRight = m_document && m_document->editor().behavior().shouldSkipSpaceWhenMovingRight();
    10801087        VisiblePosition currentPosition(m_selection.extent(), m_selection.affinity());
    10811088        pos = leftWordPosition(currentPosition, skipsSpaceWhenMovingRight);
     
    13631370    }
    13641371
    1365     if (reachedBoundary && !isRange() && userTriggered == UserTriggered && m_frame && AXObjectCache::accessibilityEnabled()) {
     1372    if (reachedBoundary && !isRange() && userTriggered == UserTriggered && m_document && AXObjectCache::accessibilityEnabled()) {
    13661373        notifyAccessibilityForSelectionChange({ AXTextStateChangeTypeSelectionBoundary, textSelectionWithDirectionAndGranularity(direction, granularity) });
    13671374        return true;
     
    13751382            return false;
    13761383
    1377     if (m_frame && AXObjectCache::accessibilityEnabled()) {
    1378         if (AXObjectCache* cache = m_frame->document()->existingAXObjectCache())
     1384    if (m_document && AXObjectCache::accessibilityEnabled()) {
     1385        if (AXObjectCache* cache = m_document->existingAXObjectCache())
    13791386            cache->setTextSelectionIntent(textSelectionIntent(alter, direction, granularity));
    13801387    }
     
    13851392    // the requested position type if there were no xPosForVerticalArrowNavigation set.
    13861393    LayoutUnit x = lineDirectionPointForBlockDirectionNavigation(START);
    1387     m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(m_frame) || alter == AlterationExtend);
     1394    m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(m_document) || alter == AlterationExtend);
    13881395
    13891396    switch (alter) {
     
    13951402        if (!m_selection.isCaret()
    13961403            && (granularity == WordGranularity || granularity == ParagraphGranularity || granularity == LineGranularity)
    1397             && m_frame && !m_frame->editor().behavior().shouldExtendSelectionByWordOrLineAcrossCaret()) {
     1404            && m_document && !m_document->editor().behavior().shouldExtendSelectionByWordOrLineAcrossCaret()) {
    13981405            // Don't let the selection go across the base position directly. Needed to match mac
    13991406            // behavior when, for instance, word-selecting backwards starting with the caret in
     
    14081415        // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the
    14091416        // base in place and moving the extent. Matches NSTextView.
    1410         if (!m_frame || !m_frame->editor().behavior().shouldAlwaysGrowSelectionWhenExtendingToBoundary() || m_selection.isCaret() || !isBoundary(granularity))
     1417        if (!m_document || !m_document->editor().behavior().shouldAlwaysGrowSelectionWhenExtendingToBoundary() || m_selection.isCaret() || !isBoundary(granularity))
    14111418            setExtent(position, userTriggered);
    14121419        else {
     
    15181525        m_granularity = CharacterGranularity;
    15191526
    1520     m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(m_frame) || alter == AlterationExtend);
     1527    m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(m_document) || alter == AlterationExtend);
    15211528
    15221529    return true;
     
    15681575}
    15691576
    1570 void FrameSelection::prepareForDestruction()
     1577void FrameSelection::willBeRemovedFromFrame()
    15711578{
    15721579    m_granularity = CharacterGranularity;
     
    15761583#endif
    15771584
    1578     if (auto* view = m_frame->contentRenderer())
     1585    if (auto* view = m_document->renderView())
    15791586        view->selection().clearSelection();
    15801587
     
    16561663IntRect FrameSelection::absoluteCaretBounds(bool* insideFixed)
    16571664{
    1658     if (!m_frame)
     1665    if (!m_document)
    16591666        return IntRect();
    1660     updateSelectionByUpdatingLayoutOrStyle(*m_frame);
     1667    updateSelectionByUpdatingLayoutOrStyle(*m_document);
    16611668    recomputeCaretRect();
    16621669    if (insideFixed)
     
    16761683        return false;
    16771684
    1678     if (!m_frame)
     1685    if (!m_document)
    16791686        return false;
    16801687
    1681     FrameView* v = m_frame->document()->view();
     1688    FrameView* v = m_document->view();
    16821689    if (!v)
    16831690        return false;
     
    16911698        else {
    16921699            VisiblePosition visibleStart = m_selection.visibleStart();
    1693             if (updateCaretRect(m_frame->document(), visibleStart)) {
     1700            if (updateCaretRect(m_document, visibleStart)) {
    16941701                caretNode = visibleStart.deepEquivalent().deprecatedNode();
    16951702                m_absCaretBoundsDirty = true;
     
    17161723
    17171724#if ENABLE(TEXT_CARET)
    1718     if (RenderView* view = m_frame->document()->renderView()) {
     1725    if (RenderView* view = m_document->renderView()) {
    17191726        bool previousOrNewCaretNodeIsContentEditable = m_selection.isContentEditable() || (m_previousCaretNode && m_previousCaretNode->isContentEditable());
    17201727        if (shouldRepaintCaret(view, previousOrNewCaretNodeIsContentEditable)) {
     
    18951902        return false;
    18961903   
    1897     auto* document = m_frame->document();
    1898     if (!document)
     1904    if (!m_document)
    18991905        return false;
    19001906   
    19011907    HitTestResult result(point);
    1902     document->hitTest(HitTestRequest(), result);
     1908    m_document->hitTest(HitTestRequest(), result);
    19031909    Node* innerNode = result.innerNode();
    19041910    if (!innerNode || !innerNode->renderer())
     
    19691975void FrameSelection::selectAll()
    19701976{
    1971     Document* document = m_frame->document();
    1972 
    1973     Element* focusedElement = document->focusedElement();
     1977    Element* focusedElement = m_document->focusedElement();
    19741978    if (is<HTMLSelectElement>(focusedElement)) {
    19751979        HTMLSelectElement& selectElement = downcast<HTMLSelectElement>(*focusedElement);
     
    20012005            selectStartTarget = root->shadowHost();
    20022006        else {
    2003             root = document->documentElement();
    2004             selectStartTarget = document->bodyOrFrameset();
     2007            root = m_document->documentElement();
     2008            selectStartTarget = m_document->bodyOrFrameset();
    20052009        }
    20062010    }
     
    20592063{
    20602064    bool activeAndFocused = isFocusedAndActive();
    2061     Ref<Document> document(*m_frame->document());
    2062 
    2063     document->updateStyleIfNeeded();
     2065
     2066    m_document->updateStyleIfNeeded();
    20642067
    20652068#if USE(UIKIT_EDITING)
     
    20722075    // RenderObject::selectionForegroundColor() check if the frame is active,
    20732076    // we have to update places those colors were painted.
    2074     if (RenderView* view = document->renderView())
     2077    if (RenderView* view = m_document->renderView())
    20752078        view->selection().repaint();
    20762079
     
    20832086    // RenderTheme::isFocused() check if the frame is active, we have to
    20842087    // update style and theme state that depended on those.
    2085     if (Element* element = document->focusedElement()) {
     2088    if (Element* element = m_document->focusedElement()) {
    20862089        element->invalidateStyleForSubtree();
    20872090        if (RenderObject* renderer = element->renderer())
     
    21082111bool FrameSelection::isFocusedAndActive() const
    21092112{
    2110     return m_focused && m_frame->page() && m_frame->page()->focusController().isActive();
     2113    return m_focused && m_document->page() && m_document->page()->focusController().isActive();
    21112114}
    21122115
    21132116#if ENABLE(TEXT_CARET)
    2114 inline static bool shouldStopBlinkingDueToTypingCommand(Frame* frame)
    2115 {
    2116     return frame->editor().lastEditCommand() && frame->editor().lastEditCommand()->shouldStopCaretBlinking();
     2117inline static bool shouldStopBlinkingDueToTypingCommand(Document* document)
     2118{
     2119    return document->editor().lastEditCommand() && document->editor().lastEditCommand()->shouldStopCaretBlinking();
    21172120}
    21182121#endif
     
    21332136    bool caretRectChangedOrCleared = recomputeCaretRect();
    21342137
    2135     bool caretBrowsing = m_frame->settings().caretBrowsingEnabled();
     2138    bool caretBrowsing = m_document->settings().caretBrowsingEnabled();
    21362139    bool shouldBlink = !paintBlockCursor && caretIsVisible() && isCaret() && (oldSelection.isContentEditable() || caretBrowsing);
    21372140
    21382141    // If the caret moved, stop the blink timer so we can restart with a
    21392142    // black caret in the new location.
    2140     if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypingCommand(m_frame))
     2143    if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypingCommand(m_document))
    21412144        m_caretBlinkTimer.stop();
    21422145
     
    21542157#endif
    21552158
    2156     RenderView* view = m_frame->contentRenderer();
     2159    RenderView* view = m_document->renderView();
    21572160    if (!view)
    21582161        return;
     
    22032206
    22042207    // FIXME: We shouldn't trigger a synchronous layout here.
    2205     if (m_frame)
    2206         updateSelectionByUpdatingLayoutOrStyle(*m_frame);
     2208    if (m_document)
     2209        updateSelectionByUpdatingLayoutOrStyle(*m_document);
    22072210
    22082211#if ENABLE(TEXT_CARET)
     
    22482251        return;
    22492252
    2250     bool caretBrowsing = m_frame->settings().caretBrowsingEnabled();
     2253    bool caretBrowsing = m_document->settings().caretBrowsingEnabled();
    22512254    if (caretBrowsing) {
    22522255        if (Element* anchor = enclosingAnchorElement(m_selection.base())) {
    2253             m_frame->page()->focusController().setFocusedElement(anchor, *m_frame);
     2256            m_document->page()->focusController().setFocusedElement(anchor, *m_frame);
    22542257            return;
    22552258        }
     
    22632266            // work in the long term, but this is the safest fix at this time.
    22642267            if (target->isMouseFocusable() && !isFrameElement(target)) {
    2265                 m_frame->page()->focusController().setFocusedElement(target, *m_frame);
     2268                m_document->page()->focusController().setFocusedElement(target, *m_frame);
    22662269                return;
    22672270            }
    22682271            target = target->parentOrShadowHostElement();
    22692272        }
    2270         m_frame->document()->setFocusedElement(nullptr);
     2273        m_document->setFocusedElement(nullptr);
    22712274    }
    22722275
    22732276    if (caretBrowsing)
    2274         m_frame->page()->focusController().setFocusedElement(nullptr, *m_frame);
     2277        m_document->page()->focusController().setFocusedElement(nullptr, *m_frame);
    22752278}
    22762279
     
    23012304        return true;
    23022305#endif
    2303     return m_frame->editor().client()->shouldDeleteRange(createLiveRange(selection.toNormalizedRange()).get());
     2306    return m_document->editor().client()->shouldDeleteRange(createLiveRange(selection.toNormalizedRange()).get());
    23042307}
    23052308
    23062309FloatRect FrameSelection::selectionBounds(ClipToVisibleContent clipToVisibleContent) const
    23072310{
    2308     if (!m_frame->document())
     2311    if (!m_document)
    23092312        return LayoutRect();
    23102313
    2311     updateSelectionByUpdatingLayoutOrStyle(*m_frame);
    2312     auto* renderView = m_frame->contentRenderer();
     2314    updateSelectionByUpdatingLayoutOrStyle(*m_document);
     2315    auto* renderView = m_document->renderView();
    23132316    if (!renderView)
    23142317        return LayoutRect();
     
    23262329void FrameSelection::getClippedVisibleTextRectangles(Vector<FloatRect>& rectangles, TextRectangleHeight textRectHeight) const
    23272330{
    2328     if (!m_frame->contentRenderer())
     2331    if (!m_document->renderView())
    23292332        return;
    23302333
     
    23332336        return;
    23342337
    2335     auto visibleContentRect = m_frame->view()->visibleContentRect(ScrollableArea::LegacyIOSDocumentVisibleRect);
     2338    auto visibleContentRect = m_document->view()->visibleContentRect(ScrollableArea::LegacyIOSDocumentVisibleRect);
    23362339    for (auto& rect : boundingBoxes(RenderObject::absoluteTextQuads(*range, textRectHeight == TextRectangleHeight::SelectionHeight))) {
    23372340        auto intersectionRect = intersection(rect, visibleContentRect);
     
    23652368{
    23662369    // Start looking either at the active (first responder) node, or where the selection is.
    2367     Element* start = m_frame->document()->focusedElement();
     2370    Element* start = m_document->focusedElement();
    23682371    if (!start)
    23692372        start = m_selection.start().element();
     
    24082411                layer->setAdjustForIOSCaretWhenScrolling(false);
    24092412                updateAppearance();
    2410                 if (m_frame->page())
    2411                     m_frame->page()->chrome().client().notifyRevealedSelectionByScrollingFrame(*m_frame);
     2413                if (m_document->page())
     2414                    m_document->page()->chrome().client().notifyRevealedSelectionByScrollingFrame(*m_frame);
    24122415            }
    24132416        }
     
    24272430    // entire WebView is editable or designMode is on for this document).
    24282431
    2429     Document* document = m_frame->document();
    24302432#if !PLATFORM(IOS_FAMILY)
    2431     bool caretBrowsing = m_frame->settings().caretBrowsingEnabled();
    2432     if (!isNone() || !(document->hasEditableStyle() || caretBrowsing))
     2433    bool caretBrowsing = m_document->settings().caretBrowsingEnabled();
     2434    if (!isNone() || !(m_document->hasEditableStyle() || caretBrowsing))
    24332435        return;
    24342436#else
    2435     if (!document || !(isNone() || isStartOfDocument(VisiblePosition(m_selection.start(), m_selection.affinity()))) || !document->hasEditableStyle())
    2436         return;
    2437 #endif
    2438 
    2439     if (auto* body = document->body())
     2437    if (!m_document || !(isNone() || isStartOfDocument(VisiblePosition(m_selection.start(), m_selection.affinity()))) || !m_document->hasEditableStyle())
     2438        return;
     2439#endif
     2440
     2441    if (auto* body = m_document->body())
    24402442        setSelection(VisibleSelection(firstPositionInOrBeforeNode(body), DOWNSTREAM));
    24412443}
     
    24472449        return true;
    24482450#endif
    2449     return m_frame->editor().shouldChangeSelection(selection(), newSelection, newSelection.affinity(), false);
     2451    return m_document->editor().shouldChangeSelection(selection(), newSelection, newSelection.affinity(), false);
    24502452}
    24512453
     
    24652467    m_shouldShowBlockCursor = shouldShowBlockCursor;
    24662468
    2467     m_frame->document()->updateLayoutIgnorePendingStylesheets();
     2469    m_document->updateLayoutIgnorePendingStylesheets();
    24682470
    24692471    updateAppearance();
     
    24832485void FrameSelection::appearanceUpdateTimerFired()
    24842486{
    2485     Ref<Frame> protectedFrame(*m_frame);
     2487    Ref<Document> protector(*m_document);
    24862488    updateAppearanceAfterLayoutOrStyleChange();
    24872489}
     
    24892491void FrameSelection::updateAppearanceAfterLayoutOrStyleChange()
    24902492{
    2491     if (auto* client = m_frame->editor().client())
     2493    if (auto* client = m_document->editor().client())
    24922494        client->updateEditorStateAfterLayoutIfEditabilityChanged();
    24932495
     
    27092711void FrameSelection::selectRangeOnElement(unsigned location, unsigned length, Node& node)
    27102712{
    2711     RefPtr<Range> resultRange = m_frame->document()->createRange();
     2713    RefPtr<Range> resultRange = m_document->createRange();
    27122714    resultRange->setStart(node, location);
    27132715    resultRange->setEnd(node, location + length);
     
    28902892        return;
    28912893#if ENABLE(TEXT_CARET)
    2892     m_frame->document()->updateLayoutIgnorePendingStylesheets();
     2894    m_document->updateLayoutIgnorePendingStylesheets();
    28932895    if (m_caretPaint) {
    28942896        m_caretPaint = false;
  • trunk/Source/WebCore/editing/FrameSelection.h

    r260725 r260831  
    141141    }
    142142
    143     WEBCORE_EXPORT explicit FrameSelection(Frame* = nullptr);
     143    WEBCORE_EXPORT explicit FrameSelection(Document* = nullptr);
    144144
    145145    WEBCORE_EXPORT Element* rootEditableElementOrDocumentElement() const;
     
    159159    WEBCORE_EXPORT void selectAll();
    160160    WEBCORE_EXPORT void clear();
    161     void prepareForDestruction();
     161    void willBeRemovedFromFrame();
    162162
    163163    void updateAppearanceAfterLayout();
     
    337337#endif
    338338
     339    Document* m_document;
    339340    Frame* m_frame;
    340341
  • trunk/Source/WebCore/editing/InsertIntoTextNodeCommand.cpp

    r242117 r260831  
    5151void InsertIntoTextNodeCommand::doApply()
    5252{
    53     bool passwordEchoEnabled = frame().settings().passwordEchoEnabled();
     53    bool passwordEchoEnabled = document().settings().passwordEchoEnabled();
    5454    if (passwordEchoEnabled)
    5555        document().updateLayoutIgnorePendingStylesheets();
  • trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp

    r216233 r260831  
    143143    // Handle the case where there is a typing style.
    144144
    145     RefPtr<EditingStyle> typingStyle = frame().selection().typingStyle();
     145    RefPtr<EditingStyle> typingStyle = document().selection().typingStyle();
    146146
    147147    if (typingStyle && !typingStyle->isEmpty()) {
  • trunk/Source/WebCore/editing/InsertTextCommand.cpp

    r249854 r260831  
    147147        if (endingSelection().isNone())
    148148            return;
    149     } else if (frame().editor().isOverwriteModeEnabled()) {
     149    } else if (document().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 = frame().selection().typingStyle()) {
     225    if (RefPtr<EditingStyle> typingStyle = document().selection().typingStyle()) {
    226226        typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection);
    227227        if (!typingStyle->isEmpty())
  • trunk/Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp

    r259401 r260831  
    6161        return;
    6262
    63     if (!frame().selection().shouldChangeSelection(selection))
     63    if (!document().selection().shouldChangeSelection(selection))
    6464        return;
    6565
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r260725 r260831  
    11821182    // FIXME: Can this wait until after the operation has been performed?  There doesn't seem to be
    11831183    // any work performed after this that queries or uses the typing style.
    1184     frame().selection().clearTypingStyle();
     1184    document().selection().clearTypingStyle();
    11851185
    11861186    // We don't want the destination to end up inside nodes that weren't selected.  To avoid that, we move the
  • trunk/Source/WebCore/editing/SetSelectionCommand.cpp

    r234801 r260831  
    4141void SetSelectionCommand::doApply()
    4242{
    43     FrameSelection& selection = frame().selection();
     43    FrameSelection& selection = document().selection();
    4444
    4545    if (selection.shouldChangeSelection(m_selectionToSet) && !m_selectionToSet.isNoneOrOrphaned()) {
     
    5151void SetSelectionCommand::doUnapply()
    5252{
    53     FrameSelection& selection = frame().selection();
     53    FrameSelection& selection = document().selection();
    5454
    5555    if (selection.shouldChangeSelection(startingSelection()) && !startingSelection().isNoneOrOrphaned())
  • trunk/Source/WebCore/editing/SpellChecker.cpp

    r258182 r260831  
    9999}
    100100
    101 SpellChecker::SpellChecker(Frame& frame)
    102     : m_frame(frame)
     101SpellChecker::SpellChecker(Document& document)
     102    : m_document(document)
    103103    , m_timerToProcessQueuedRequest(*this, &SpellChecker::timerFiredToProcessQueuedRequest)
    104104{
     
    115115TextCheckerClient* SpellChecker::client() const
    116116{
    117     Page* page = m_frame.page();
     117    Page* page = m_document.page();
    118118    if (!page)
    119119        return nullptr;
     
    132132bool SpellChecker::isAsynchronousEnabled() const
    133133{
    134     return m_frame.settings().asynchronousSpellCheckingEnabled();
     134    return m_document.settings().asynchronousSpellCheckingEnabled();
    135135}
    136136
     
    175175        return;
    176176    m_processingRequest = WTFMove(request);
    177     client()->requestCheckingOfString(*m_processingRequest, m_frame.selection().selection());
     177    client()->requestCheckingOfString(*m_processingRequest, m_document.selection().selection());
    178178}
    179179
     
    200200    }
    201201
    202     m_frame.editor().markAndReplaceFor(*m_processingRequest, results);
     202    m_document.editor().markAndReplaceFor(*m_processingRequest, results);
    203203
    204204    if (m_lastProcessedIdentifier.toUInt64() < identifier.toUInt64())
     
    220220            markerTypes.add(DocumentMarker::Grammar);
    221221        if (!markerTypes.isEmpty())
    222             m_frame.document()->markers().removeMarkers(m_processingRequest->checkingRange(), markerTypes);
     222            m_document.markers().removeMarkers(m_processingRequest->checkingRange(), markerTypes);
    223223    }
    224224    didCheck(identifier, results);
  • trunk/Source/WebCore/editing/SpellChecker.h

    r258182 r260831  
    7777    friend class SpellCheckRequest;
    7878
    79     explicit SpellChecker(Frame&);
     79    explicit SpellChecker(Document&);
    8080    ~SpellChecker();
    8181
     
    107107    void didCheck(TextCheckingRequestIdentifier, const Vector<TextCheckingResult>&);
    108108
    109     Frame& m_frame;
     109    Document& m_document;
    110110    TextCheckingRequestIdentifier m_lastRequestIdentifier;
    111111    TextCheckingRequestIdentifier m_lastProcessedIdentifier;
  • trunk/Source/WebCore/editing/SpellingCorrectionCommand.cpp

    r259401 r260831  
    6666    {
    6767        if (!m_hasBeenUndone) {
    68             frame().editor().unappliedSpellCorrection(startingSelection(), m_corrected, m_correction);
     68            document().editor().unappliedSpellCorrection(startingSelection(), m_corrected, m_correction);
    6969            m_hasBeenUndone = true;
    7070        }
     
    104104        return;
    105105
    106     if (!frame().selection().shouldChangeSelection(m_selectionToBeCorrected))
     106    if (!document().selection().shouldChangeSelection(m_selectionToBeCorrected))
    107107        return;
    108108
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r260725 r260831  
    164164void TypingCommand::deleteSelection(Document& document, Options options, TextCompositionType compositionType)
    165165{
    166     Frame* frame = document.frame();
    167     ASSERT(frame);
    168 
    169     if (!frame->selection().isRange())
    170         return;
    171 
    172     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
     166    if (!document.selection().isRange())
     167        return;
     168
     169    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
    173170        lastTypingCommand->setIsAutocompletion(options & IsAutocompletion);
    174171        lastTypingCommand->setCompositionType(compositionType);
     
    184181{
    185182    if (granularity == CharacterGranularity) {
    186         if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
    187             updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document.frame());
     183        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
     184            updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document);
    188185            lastTypingCommand->setIsAutocompletion(options & IsAutocompletion);
    189186            lastTypingCommand->setCompositionType(TextCompositionNone);
     
    200197{
    201198    // FIXME: Forward delete in TextEdit appears to open and close a new typing command.
    202     Frame* frame = document.frame();
    203199    if (granularity == CharacterGranularity) {
    204         if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
    205             updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), frame);
     200        if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
     201            updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document);
    206202            lastTypingCommand->setIsAutocompletion(options & IsAutocompletion);
    207203            lastTypingCommand->setCompositionType(TextCompositionNone);
     
    215211}
    216212
    217 void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand* typingCommand, Frame* frame)
    218 {
    219     ASSERT(frame);
    220     VisibleSelection currentSelection = frame->selection().selection();
     213void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand* typingCommand, Document& document)
     214{
     215    VisibleSelection currentSelection = document.selection().selection();
    221216    if (currentSelection == typingCommand->endingSelection())
    222217        return;
     
    228223void TypingCommand::insertText(Document& document, const String& text, Options options, TextCompositionType composition)
    229224{
    230     Frame* frame = document.frame();
    231     ASSERT(frame);
    232 
    233225    if (!text.isEmpty())
    234         frame->editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0]));
     226        document.editor().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0]));
    235227   
    236     insertText(document, text, frame->selection().selection(), options, composition);
     228    insertText(document, text, document.selection().selection(), options, composition);
    237229}
    238230
     
    240232void TypingCommand::insertText(Document& document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType)
    241233{
    242     RefPtr<Frame> frame = document.frame();
    243     ASSERT(frame);
    244 
    245234    LOG(Editing, "TypingCommand::insertText (text %s)", text.utf8().data());
    246235
    247     VisibleSelection currentSelection = frame->selection().selection();
     236    VisibleSelection currentSelection = document.selection().selection();
    248237
    249238    String newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion, compositionType == TextCompositionPending);
     
    252241    // that is different from the current selection.  In the future, we should change EditCommand
    253242    // to deal with custom selections in a general way that can be used by all of the commands.
    254     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
     243    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
    255244        if (lastTypingCommand->endingSelection() != selectionForInsertion) {
    256245            lastTypingCommand->setStartingSelection(selectionForInsertion);
     
    267256
    268257    auto cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
    269     applyTextInsertionCommand(frame.get(), cmd.get(), selectionForInsertion, currentSelection);
     258    applyTextInsertionCommand(document.frame(), cmd.get(), selectionForInsertion, currentSelection);
    270259}
    271260
    272261void TypingCommand::insertLineBreak(Document& document, Options options)
    273262{
    274     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
     263    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
    275264        lastTypingCommand->setIsAutocompletion(options & IsAutocompletion);
    276265        lastTypingCommand->setCompositionType(TextCompositionNone);
     
    285274void TypingCommand::insertParagraphSeparatorInQuotedContent(Document& document)
    286275{
    287     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
     276    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
    288277        lastTypingCommand->setIsAutocompletion(false);
    289278        lastTypingCommand->setCompositionType(TextCompositionNone);
     
    297286void TypingCommand::insertParagraphSeparator(Document& document, Options options)
    298287{
    299     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*document.frame())) {
     288    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
    300289        lastTypingCommand->setIsAutocompletion(options & IsAutocompletion);
    301290        lastTypingCommand->setCompositionType(TextCompositionNone);
     
    308297}
    309298
    310 RefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(Frame& frame)
    311 {
    312     RefPtr<CompositeEditCommand> lastEditCommand = frame.editor().lastEditCommand();
     299RefPtr<TypingCommand> TypingCommand::lastTypingCommandIfStillOpenForTyping(Document& document)
     300{
     301    RefPtr<CompositeEditCommand> lastEditCommand = document.editor().lastEditCommand();
    313302    if (!lastEditCommand || !lastEditCommand->isTypingCommand() || !static_cast<TypingCommand*>(lastEditCommand.get())->isOpenForMoreTyping())
    314303        return nullptr;
     
    322311}
    323312
    324 void TypingCommand::closeTyping(Frame* frame)
    325 {
    326     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame))
     313void TypingCommand::closeTyping(Document& document)
     314{
     315    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document))
    327316        lastTypingCommand->closeTyping();
    328317}
    329318
    330319#if PLATFORM(IOS_FAMILY)
    331 void TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(Frame* frame, const VisibleSelection& newSelection)
    332 {
    333     if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(*frame)) {
     320void TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(Document& document, const VisibleSelection& newSelection)
     321{
     322    if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenForTyping(document)) {
    334323        lastTypingCommand->setEndingSelection(newSelection);
    335324        lastTypingCommand->setEndingSelectionOnLastInsertCommand(newSelection);
     
    437426void TypingCommand::markMisspellingsAfterTyping(ETypingCommand commandType)
    438427{
    439     Frame& frame = this->frame();
    440 
    441428#if PLATFORM(MAC)
    442     if (!frame.editor().isContinuousSpellCheckingEnabled()
    443         && !frame.editor().isAutomaticQuoteSubstitutionEnabled()
    444         && !frame.editor().isAutomaticLinkDetectionEnabled()
    445         && !frame.editor().isAutomaticDashSubstitutionEnabled()
    446         && !frame.editor().isAutomaticTextReplacementEnabled())
     429    if (!document().editor().isContinuousSpellCheckingEnabled()
     430        && !document().editor().isAutomaticQuoteSubstitutionEnabled()
     431        && !document().editor().isAutomaticLinkDetectionEnabled()
     432        && !document().editor().isAutomaticDashSubstitutionEnabled()
     433        && !document().editor().isAutomaticTextReplacementEnabled())
    447434            return;
    448     if (frame.editor().isHandlingAcceptedCandidate())
     435    if (document().editor().isHandlingAcceptedCandidate())
    449436        return;
    450437#else
    451     if (!frame.editor().isContinuousSpellCheckingEnabled())
     438    if (!document().editor().isContinuousSpellCheckingEnabled())
    452439        return;
    453440#endif
     
    467454            if (range && (commandType == TypingCommand::InsertText || commandType == TypingCommand::InsertLineBreak || commandType == TypingCommand::InsertParagraphSeparator || commandType == TypingCommand::InsertParagraphSeparatorInQuotedContent))
    468455                strippedPreviousWord = plainText(*range).stripWhiteSpace();
    469             frame.editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
     456            document().editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), !strippedPreviousWord.isEmpty());
    470457        } else if (commandType == TypingCommand::InsertText)
    471             frame.editor().startAlternativeTextUITimer();
     458            document().editor().startAlternativeTextUITimer();
    472459#else
    473460        UNUSED_PARAM(commandType);
     
    484471        VisiblePosition p2 = startOfWord(start, startWordSide);
    485472        if (p1 != p2)
    486             frame.editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), false);
     473            document().editor().markMisspellingsAfterTypingToWord(p1, endingSelection(), false);
    487474#endif // !PLATFORM(IOS_FAMILY)
    488475    }
     
    498485
    499486    if (!range || isEditingTextAreaOrTextInput())
    500         return frame().editor().willApplyEditing(*this, CompositeEditCommand::targetRangesForBindings());
    501 
    502     return frame().editor().willApplyEditing(*this, { 1, StaticRange::create(*range) });
     487        return document().editor().willApplyEditing(*this, CompositeEditCommand::targetRangesForBindings());
     488
     489    return document().editor().willApplyEditing(*this, { 1, StaticRange::create(*range) });
    503490}
    504491
    505492void TypingCommand::typingAddedToOpenCommand(ETypingCommand commandTypeForAddedTyping)
    506493{
    507     Frame& frame = this->frame();
     494    RefPtr<Frame> protector(document().frame());
    508495
    509496    updatePreservesTypingStyle(commandTypeForAddedTyping);
    510497
    511498#if PLATFORM(COCOA)
    512     frame.editor().appliedEditing(*this);
     499    document().editor().appliedEditing(*this);
    513500    // Since the spellchecking code may also perform corrections and other replacements, it should happen after the typing changes.
    514501    if (!m_shouldPreventSpellChecking)
     
    517504    // The old spellchecking code requires that checking be done first, to prevent issues like that in 6864072, where <doesn't> is marked as misspelled.
    518505    markMisspellingsAfterTyping(commandTypeForAddedTyping);
    519     frame.editor().appliedEditing(*this);
     506    document().editor().appliedEditing(*this);
    520507#endif
    521508}
     
    536523    LOG(Editing, "TypingCommand %p insertTextAndNotifyAccessibility (text %s, selectInsertedText %d)", this, text.utf8().data(), selectInsertedText);
    537524
    538     AccessibilityReplacedText replacedText(frame().selection().selection());
     525    AccessibilityReplacedText replacedText(document().selection().selection());
    539526    insertText(text, selectInsertedText);
    540     replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, text, frame().selection().selection());
     527    replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, text, document().selection().selection());
    541528    composition()->setRangeDeletedByUnapply(replacedText.replacedRange());
    542529}
     
    551538
    552539    applyCommandToComposite(WTFMove(command), endingSelection());
    553 
    554     Frame& frame = this->frame();
    555     Ref<Frame> protector(frame);
    556540    typingAddedToOpenCommand(InsertText);
    557541}
     
    566550
    567551    applyCommandToComposite(InsertLineBreakCommand::create(document()));
    568 
    569     Frame& frame = this->frame();
    570     Ref<Frame> protector(frame);
    571552    typingAddedToOpenCommand(InsertLineBreak);
    572553}
     
    574555void TypingCommand::insertLineBreakAndNotifyAccessibility()
    575556{
    576     AccessibilityReplacedText replacedText(frame().selection().selection());
     557    AccessibilityReplacedText replacedText(document().selection().selection());
    577558    insertLineBreak();
    578     replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, "\n", frame().selection().selection());
     559    replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, "\n", document().selection().selection());
    579560    composition()->setRangeDeletedByUnapply(replacedText.replacedRange());
    580561}
     
    589570
    590571    applyCommandToComposite(InsertParagraphSeparatorCommand::create(document(), false, false, EditAction::TypingInsertParagraph));
    591 
    592     Frame& frame = this->frame();
    593     Ref<Frame> protector(frame);
    594572    typingAddedToOpenCommand(InsertParagraphSeparator);
    595573}
     
    597575void TypingCommand::insertParagraphSeparatorAndNotifyAccessibility()
    598576{
    599     AccessibilityReplacedText replacedText(frame().selection().selection());
     577    AccessibilityReplacedText replacedText(document().selection().selection());
    600578    insertParagraphSeparator();
    601     replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, "\n", frame().selection().selection());
     579    replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, "\n", document().selection().selection());
    602580    composition()->setRangeDeletedByUnapply(replacedText.replacedRange());
    603581}
     
    616594       
    617595    applyCommandToComposite(BreakBlockquoteCommand::create(document()));
    618 
    619     Frame& frame = this->frame();
    620     Ref<Frame> protector(frame);
    621596    typingAddedToOpenCommand(InsertParagraphSeparatorInQuotedContent);
    622597}
     
    624599void TypingCommand::insertParagraphSeparatorInQuotedContentAndNotifyAccessibility()
    625600{
    626     AccessibilityReplacedText replacedText(frame().selection().selection());
     601    AccessibilityReplacedText replacedText(document().selection().selection());
    627602    insertParagraphSeparatorInQuotedContent();
    628     replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, "\n", frame().selection().selection());
     603    replacedText.postTextStateChangeNotification(document().existingAXObjectCache(), AXTextEditTypeTyping, "\n", document().selection().selection());
    629604    composition()->setRangeDeletedByUnapply(replacedText.replacedRange());
    630605}
     
    653628void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing)
    654629{
    655     Frame& frame = this->frame();
    656     Ref<Frame> protector(frame);
    657 
    658     frame.editor().updateMarkersForWordsAffectedByEditing(false);
     630    RefPtr<Frame> protector(document().frame());
     631
     632    document().editor().updateMarkersForWordsAffectedByEditing(false);
    659633
    660634    VisibleSelection selectionToDelete;
     
    749723        // Workaround for this bug:
    750724        // <rdar://problem/4653755> UIKit text widgets should use WebKit editing API to manipulate text
    751         setEndingSelection(frame.selection().selection());
    752         closeTyping(&frame);
     725        setEndingSelection(document().selection().selection());
     726        closeTyping(document());
    753727#endif
    754728        return;
    755729    }
    756730   
    757     if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
     731    if (selectionToDelete.isCaret() || !document().selection().shouldDeleteSelection(selectionToDelete))
    758732        return;
    759733   
     
    762736
    763737    if (shouldAddToKillRing)
    764         frame.editor().addRangeToKillRing(createLiveRange(*selectionToDelete.toNormalizedRange()), Editor::KillRingInsertionMode::PrependText);
     738        document().editor().addRangeToKillRing(createLiveRange(*selectionToDelete.toNormalizedRange()), Editor::KillRingInsertionMode::PrependText);
    765739
    766740    // Post the accessibility notification before actually deleting the content while selectionToDelete is still valid
     
    779753void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing)
    780754{
    781     Frame& frame = this->frame();
    782     Ref<Frame> protector(frame);
    783 
    784     frame.editor().updateMarkersForWordsAffectedByEditing(false);
     755    RefPtr<Frame> protector(document().frame());
     756
     757    document().editor().updateMarkersForWordsAffectedByEditing(false);
    785758
    786759    VisibleSelection selectionToDelete;
     
    858831        // Workaround for this bug:
    859832        // <rdar://problem/4653755> UIKit text widgets should use WebKit editing API to manipulate text
    860         setEndingSelection(frame.selection().selection());
    861         closeTyping(&frame);
     833        setEndingSelection(document().selection().selection());
     834        closeTyping(document());
    862835#endif
    863836        return;
    864837    }
    865838   
    866     if (selectionToDelete.isCaret() || !frame.selection().shouldDeleteSelection(selectionToDelete))
     839    if (selectionToDelete.isCaret() || !document().selection().shouldDeleteSelection(selectionToDelete))
    867840        return;
    868841
     
    874847
    875848    if (shouldAddToKillRing)
    876         frame.editor().addRangeToKillRing(createLiveRange(*selectionToDelete.toNormalizedRange()), Editor::KillRingInsertionMode::AppendText);
     849        document().editor().addRangeToKillRing(createLiveRange(*selectionToDelete.toNormalizedRange()), Editor::KillRingInsertionMode::AppendText);
    877850    // make undo select what was deleted
    878851    setStartingSelection(selectionAfterUndo);
  • trunk/Source/WebCore/editing/TypingCommand.h

    r237266 r260831  
    6666    static void insertParagraphSeparator(Document&, Options);
    6767    static void insertParagraphSeparatorInQuotedContent(Document&);
    68     static void closeTyping(Frame*);
     68    static void closeTyping(Document&);
    6969#if PLATFORM(IOS_FAMILY)
    70     static void ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(Frame*, const VisibleSelection&);
     70    static void ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(Document&, const VisibleSelection&);
    7171#endif
    7272
     
    104104    void closeTyping() { m_openForMoreTyping = false; }
    105105
    106     static RefPtr<TypingCommand> lastTypingCommandIfStillOpenForTyping(Frame&);
     106    static RefPtr<TypingCommand> lastTypingCommandIfStillOpenForTyping(Document&);
    107107
    108108    void doApply() final;
     
    123123    bool isBeforeInputEventCancelable() const final;
    124124
    125     static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Frame*);
     125    static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Document&);
    126126
    127127    void updatePreservesTypingStyle(ETypingCommand);
  • trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm

    r260753 r260831  
    8181String Editor::selectionInHTMLFormat()
    8282{
    83     return serializePreservingVisualAppearance(m_frame.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
    84         m_frame.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
     83    return serializePreservingVisualAppearance(m_document.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
     84        m_document.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
    8585}
    8686
     
    106106#endif
    107107
    108 static RetainPtr<NSAttributedString> selectionAsAttributedString(const Frame& frame)
    109 {
    110     auto range = frame.selection().selection().firstRange();
     108static RetainPtr<NSAttributedString> selectionAsAttributedString(const Document& document)
     109{
     110    auto range = document.selection().selection().firstRange();
    111111    return range ? attributedString(*range).string : adoptNS([[NSAttributedString alloc] init]);
    112112}
     
    114114void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
    115115{
    116     auto string = selectionAsAttributedString(m_frame);
     116    auto string = selectionAsAttributedString(m_document);
    117117
    118118    PasteboardWebContent content;
    119     content.contentOrigin = m_frame.document()->originIdentifierForPasteboard();
     119    content.contentOrigin = m_document.originIdentifierForPasteboard();
    120120    content.canSmartCopyOrDelete = canSmartCopyOrDelete();
    121121    content.dataInWebArchiveFormat = selectionInWebArchiveFormat();
     
    132132void Editor::writeSelection(PasteboardWriterData& pasteboardWriterData)
    133133{
    134     auto string = selectionAsAttributedString(m_frame);
     134    auto string = selectionAsAttributedString(m_document);
    135135
    136136    PasteboardWriterData::WebContent webContent;
    137     webContent.contentOrigin = m_frame.document()->originIdentifierForPasteboard();
     137    webContent.contentOrigin = m_document.originIdentifierForPasteboard();
    138138    webContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
    139139    webContent.dataInWebArchiveFormat = selectionInWebArchiveFormat();
     
    150150RefPtr<SharedBuffer> Editor::selectionInWebArchiveFormat()
    151151{
    152     auto archive = LegacyWebArchive::createFromSelection(&m_frame);
     152    auto archive = LegacyWebArchive::createFromSelection(m_document.frame());
    153153    if (!archive)
    154154        return nullptr;
     
    178178void Editor::replaceSelectionWithAttributedString(NSAttributedString *attributedString, MailBlockquoteHandling mailBlockquoteHandling)
    179179{
    180     if (m_frame.selection().isNone())
     180    if (m_document.selection().isNone())
    181181        return;
    182182
    183     if (m_frame.selection().selection().isContentRichlyEditable()) {
    184         if (auto fragment = createFragmentAndAddResources(m_frame, attributedString)) {
     183    if (m_document.selection().selection().isContentRichlyEditable()) {
     184        if (auto fragment = createFragmentAndAddResources(*m_document.frame(), attributedString)) {
    185185            if (shouldInsertFragment(*fragment, selectedRange().get(), EditorInsertAction::Pasted))
    186186                pasteAsFragment(fragment.releaseNonNull(), false, false, mailBlockquoteHandling);
     
    228228RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, const SimpleRange& context, bool allowPlainText, bool& chosePlainText)
    229229{
    230     WebContentReader reader(m_frame, context, allowPlainText);
     230    WebContentReader reader(*m_document.frame(), context, allowPlainText);
    231231    pasteboard.read(reader);
    232232    chosePlainText = reader.madeFragmentFromPlainText;
     
    241241    }
    242242
    243     auto stringFromSelection = m_frame.displayStringModifiedByEncoding(selectedTextForDataTransfer());
     243    auto stringFromSelection = m_document.frame()->displayStringModifiedByEncoding(selectedTextForDataTransfer());
    244244#if PLATFORM(MAC)
    245245    Vector<String> types;
  • trunk/Source/WebCore/editing/gtk/EditorGtk.cpp

    r260753 r260831  
    9595
    9696    bool chosePlainText;
    97     RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     97    RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, *m_document.frame(), *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
    9898
    9999    if (fragment && options.contains(PasteOption::AsQuotation))
     
    148148    pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
    149149    pasteboardContent.text = selectedTextForDataTransfer();
    150     pasteboardContent.markup = serializePreservingVisualAppearance(m_frame.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
    151         m_frame.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
     150    pasteboardContent.markup = serializePreservingVisualAppearance(m_document.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
     151        m_document.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
    152152    pasteboard.write(pasteboardContent);
    153153}
     
    155155RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, const SimpleRange& context, bool allowPlainText, bool& chosePlainText)
    156156{
    157     return createFragmentFromPasteboardData(pasteboard, m_frame, context, allowPlainText, chosePlainText);
     157    return createFragmentFromPasteboardData(pasteboard, *m_document.frame(), context, allowPlainText, chosePlainText);
    158158}
    159159
  • trunk/Source/WebCore/editing/ios/EditorIOS.mm

    r260739 r260831  
    8383    // Otherwise, do nothing.
    8484
    85     auto selectionStyle = EditingStyle::styleAtSelectionStart(m_frame.selection().selection());
     85    auto selectionStyle = EditingStyle::styleAtSelectionStart(m_document.selection().selection());
    8686    if (!selectionStyle || !selectionStyle->style())
    8787         return;
     
    127127        return;
    128128
    129     Element* focusedElement = m_frame.document()->focusedElement();
     129    Element* focusedElement = m_document.focusedElement();
    130130    if (focusedElement && (is<HTMLTextAreaElement>(*focusedElement) || (is<HTMLInputElement>(*focusedElement)
    131131        && (downcast<HTMLInputElement>(*focusedElement).isTextField()
     
    134134            return;
    135135        downcast<HTMLElement>(*focusedElement).setAttributeWithoutSynchronization(alignAttr, newValue);
    136         m_frame.document()->updateStyleIfNeeded();
     136        m_document.updateStyleIfNeeded();
    137137        return;
    138138    }
     
    147147    // This function removes styles that the user cannot modify by applying their default values.
    148148   
    149     auto editingStyle = EditingStyle::create(m_frame.document()->bodyOrFrameset());
     149    auto editingStyle = EditingStyle::create(m_document.bodyOrFrameset());
    150150    auto defaultStyle = editingStyle->style()->mutableCopy();
    151151   
     
    219219    RefPtr<Range> range = selectedRange();
    220220    bool allowPlainText = options.contains(PasteOption::AllowPlainText);
    221     WebContentReader reader(m_frame, *range, allowPlainText);
     221    WebContentReader reader(*m_document.frame(), *range, allowPlainText);
    222222    int numberOfPasteboardItems = client()->getPasteboardItemsCount();
    223223    for (int i = 0; i < numberOfPasteboardItems; ++i) {
     
    243243void Editor::insertDictationPhrases(Vector<Vector<String>>&& dictationPhrases, id metadata)
    244244{
    245     if (m_frame.selection().isNone())
     245    if (m_document.selection().isNone())
    246246        return;
    247247
     
    261261    clearUndoRedoOperations();
    262262
    263     m_frame.selection().clear();
     263    m_document.selection().clear();
    264264
    265265    element.removeChildren();
     
    339339    // As a side effect this function sets a caret selection after the inserted content. Much of what
    340340    // follows is more expensive if there is a selection, so clear it since it's going to change anyway.
    341     m_frame.selection().clear();
     341    m_document.selection().clear();
    342342
    343343    // clear out all current children of element
     
    380380    selection.setExtent(visiblePos);
    381381
    382     m_frame.selection().setSelection(selection);
     382    m_document.selection().setSelection(selection);
    383383
    384384    client()->respondToChangedContents();
     
    389389void Editor::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping()
    390390{
    391     TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(&m_frame, m_frame.selection().selection());
     391    TypingCommand::ensureLastEditCommandHasCurrentSelectionIfOpenForMoreTyping(m_document, m_document.selection().selection());
    392392}
    393393
  • trunk/Source/WebCore/editing/libwpe/EditorLibWPE.cpp

    r238317 r260831  
    6868    PasteboardWebContent pasteboardContent;
    6969    pasteboardContent.text = selectedTextForDataTransfer();
    70     pasteboardContent.markup = serializePreservingVisualAppearance(m_frame.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
    71         m_frame.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
     70    pasteboardContent.markup = serializePreservingVisualAppearance(m_document.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
     71        m_document.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
    7272    pasteboard.write(pasteboardContent);
    7373}
     
    8585
    8686    bool chosePlainText;
    87     RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     87    RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, *m_document.frame(), *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
    8888
    8989    if (fragment && options.contains(PasteOption::AsQuotation))
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r260753 r260831  
    103103{
    104104    Pasteboard pasteboard(pasteboardName);
    105     if (m_frame.selection().selection().isContentRichlyEditable())
     105    if (m_document.selection().selection().isContentRichlyEditable())
    106106        pasteWithPasteboard(&pasteboard, { PasteOption::AllowPlainText });
    107107    else
     
    137137    ASSERT(node);
    138138
    139     if (&node->document() != m_frame.document())
    140         return;
    141 
    142     Ref<Frame> protector(m_frame);
     139    if (node->document() != m_document)
     140        return;
     141
     142    Ref<Document> protector(m_document);
    143143
    144144    auto range = makeRangeSelectingNodeContents(*node);
    145     m_frame.selection().setSelection(VisibleSelection(range), FrameSelection::DoNotSetFocus);
     145    m_document.selection().setSelection(VisibleSelection(range), FrameSelection::DoNotSetFocus);
    146146
    147147    Pasteboard pasteboard(pasteboardName);
    148148
    149     if (!m_frame.selection().selection().isContentRichlyEditable()) {
     149    if (!m_document.selection().selection().isContentRichlyEditable()) {
    150150        pasteAsPlainTextWithPasteboard(pasteboard);
    151151        return;
     
    221221void Editor::selectionWillChange()
    222222{
    223     if (!hasComposition() || ignoreSelectionChanges() || m_frame.selection().isNone())
     223    if (!hasComposition() || ignoreSelectionChanges() || m_document.selection().isNone())
    224224        return;
    225225
  • trunk/Source/WebCore/editing/win/EditorWin.cpp

    r260753 r260831  
    4343
    4444    bool chosePlainText;
    45     RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
     45    RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(*m_document.frame(), *range, options.contains(PasteOption::AllowPlainText), chosePlainText);
    4646
    4747    if (fragment && options.contains(PasteOption::AsQuotation))
     
    7070{
    7171    if (COMPtr<IDataObject> platformDragData = pasteboard.dataObject())
    72         return createFragmentFromPlatformData(*platformDragData, m_frame);
     72        return createFragmentFromPlatformData(*platformDragData, *m_document.frame());
    7373
    74     return createFragmentFromPlatformData(pasteboard.dragDataMap(), m_frame);
     74    return createFragmentFromPlatformData(pasteboard.dragDataMap(), *m_document.frame());
    7575}
    7676
  • trunk/Source/WebCore/history/CachedFrame.cpp

    r260774 r260831  
    287287
    288288    m_document->setBackForwardCacheState(Document::NotInBackForwardCache);
    289     m_document->prepareForDestruction();
     289    m_document->willBeRemovedFromFrame();
    290290
    291291    clear();
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r260753 r260831  
    549549{
    550550    // This function is called when a frame is still fully in place (not cached, not detached), but will be replaced.
    551 
    552     if (m_frame.editor().hasComposition()) {
     551    Document* document = m_frame.document();
     552    if (!document)
     553        return;
     554
     555    if (document->editor().hasComposition()) {
    553556        // The text was already present in DOM, so it's better to confirm than to cancel the composition.
    554         m_frame.editor().confirmComposition();
    555         if (EditorClient* editorClient = m_frame.editor().client()) {
     557        document->editor().confirmComposition();
     558        if (EditorClient* editorClient = document->editor().client()) {
    556559            editorClient->respondToChangedSelection(&m_frame);
    557560            editorClient->discardedComposition(&m_frame);
     
    564567    history().saveDocumentState();
    565568
    566     Document* currentDocument = m_frame.document();
     569    RefPtr<Document> currentDocument = m_frame.document();
    567570    UnloadEventPolicy unloadEventPolicy;
    568571    if (m_frame.page() && m_frame.page()->chrome().client().isSVGImageChromeClient()) {
     
    576579    stopLoading(unloadEventPolicy);
    577580   
    578     m_frame.editor().clearUndoRedoOperations();
     581    if (currentDocument)
     582        currentDocument->editor().clearUndoRedoOperations();
    579583}
    580584
     
    588592
    589593    m_frame.navigationScheduler().cancel();
    590     m_frame.editor().clearLastEditCommand();
    591594
    592595    m_isComplete = false;
     
    651654void FrameLoader::clear(Document* newDocument, bool clearWindowProperties, bool clearScriptObjects, bool clearFrameView, WTF::Function<void()>&& handleDOMWindowCreation)
    652655{
    653     m_frame.editor().clear();
    654 
    655656    bool neededClear = m_needsClear;
    656657    m_needsClear = false;
     
    660661        m_frame.document()->stopActiveDOMObjects();
    661662        bool hadLivingRenderTree = m_frame.document()->hasLivingRenderTree();
    662         m_frame.document()->prepareForDestruction();
     663        m_frame.document()->willBeRemovedFromFrame();
    663664        if (hadLivingRenderTree)
    664665            m_frame.document()->adjustFocusedNodeOnNodeRemoval(*m_frame.document());
     
    681682    }
    682683
    683     m_frame.selection().prepareForDestruction();
    684684    m_frame.eventHandler().clear();
    685685
  • trunk/Source/WebCore/page/Frame.cpp

    r260774 r260831  
    157157    , m_ownerElement(ownerElement)
    158158    , m_script(makeUniqueRef<ScriptController>(*this))
    159     , m_editor(makeUniqueRef<Editor>(*this))
    160     , m_selection(makeUniqueRef<FrameSelection>(this))
    161159    , m_animationController(makeUniqueRef<CSSAnimationController>(*this))
    162160    , m_pageZoomFactor(parentPageZoomFactor(this))
     
    235233    // these calls to work.
    236234    if (!view && m_doc && m_doc->backForwardCacheState() != Document::InBackForwardCache)
    237         m_doc->prepareForDestruction();
     235        m_doc->willBeRemovedFromFrame();
    238236   
    239237    if (m_view)
     
    280278
    281279    if (m_doc && m_doc->backForwardCacheState() != Document::InBackForwardCache)
    282         m_doc->prepareForDestruction();
     280        m_doc->willBeRemovedFromFrame();
    283281
    284282    m_doc = newDocument.copyRef();
     
    555553        return false;
    556554    case DOMPasteAccessPolicy::NotRequestedYet: {
    557         auto* client = m_editor->client();
     555        auto* client = editor().client();
    558556        if (!client)
    559557            return false;
     
    938936        return;
    939937
    940     m_editor->dismissCorrectionPanelAsIgnored();
     938    editor().dismissCorrectionPanelAsIgnored();
    941939
    942940    // Respect SVGs zoomAndPan="disabled" property in standalone SVG documents.
  • trunk/Source/WebCore/page/Frame.h

    r260774 r260831  
    3030#include "AbstractFrame.h"
    3131#include "AdjustViewSizeOrNot.h"
     32#include "Document.h"
    3233#include "FrameIdentifier.h"
    3334#include "FrameTree.h"
     
    164165    FrameView* view() const;
    165166
    166     Editor& editor() { return m_editor; }
    167     const Editor& editor() const { return m_editor; }
     167    Editor& editor() { return document()->editor(); }
     168    const Editor& editor() const { return document()->editor(); }
    168169    EventHandler& eventHandler() { return m_eventHandler; }
    169170    const EventHandler& eventHandler() const { return m_eventHandler; }
    170171    FrameLoader& loader() const;
    171172    NavigationScheduler& navigationScheduler() const;
    172     FrameSelection& selection() { return m_selection; }
    173     const FrameSelection& selection() const { return m_selection; }
     173    FrameSelection& selection() { return document()->selection(); }
     174    const FrameSelection& selection() const { return document()->selection(); }
    174175    FrameTree& tree() const;
    175176    CSSAnimationController& legacyAnimation() { return m_animationController; }
     
    339340
    340341    UniqueRef<ScriptController> m_script;
    341     UniqueRef<Editor> m_editor;
    342     UniqueRef<FrameSelection> m_selection;
    343342    UniqueRef<CSSAnimationController> m_animationController;
    344343
  • trunk/Source/WebCore/page/TextIndicator.cpp

    r260753 r260831  
    7373        return nullptr;
    7474
    75     bool indicatesCurrentSelection = range == frame->selection().selection().toNormalizedRange();
     75    auto document = makeRefPtr(frame->document());
     76    if (!document)
     77        return nullptr;
     78
     79    bool indicatesCurrentSelection = range == document->selection().selection().toNormalizedRange();
    7680
    7781    OptionSet<TemporarySelectionOption> temporarySelectionOptions;
     
    8185    temporarySelectionOptions.add(TemporarySelectionOption::EnableAppearanceUpdates);
    8286#endif
    83     TemporarySelectionChange selectionChange(*frame, { range }, temporarySelectionOptions);
     87    TemporarySelectionChange selectionChange(*document, { range }, temporarySelectionOptions);
    8488
    8589    TextIndicatorData data;
Note: See TracChangeset for help on using the changeset viewer.