Changeset 282191 in webkit
- Timestamp:
- Sep 8, 2021, 9:37:45 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 28 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/dom/Element.cpp (modified) (2 diffs)
-
WebCore/editing/FrameSelection.cpp (modified) (4 diffs)
-
WebCore/editing/cocoa/AutofillElements.cpp (modified) (1 diff)
-
WebCore/editing/cocoa/DictionaryLookup.mm (modified) (1 diff)
-
WebCore/history/BackForwardCache.cpp (modified) (1 diff)
-
WebCore/history/CachedPage.cpp (modified) (1 diff)
-
WebCore/html/BaseDateAndTimeInputType.cpp (modified) (1 diff)
-
WebCore/html/HTMLFrameElementBase.cpp (modified) (1 diff)
-
WebCore/page/DOMWindow.cpp (modified) (1 diff)
-
WebCore/page/EventHandler.cpp (modified) (5 diffs)
-
WebCore/page/FocusController.h (modified) (2 diffs)
-
WebCore/page/Frame.cpp (modified) (1 diff)
-
WebCore/page/Page.cpp (modified) (7 diffs)
-
WebCore/page/ios/EventHandlerIOS.mm (modified) (1 diff)
-
WebCore/page/mac/EventHandlerMac.mm (modified) (1 diff)
-
WebCore/page/mac/ServicesOverlayController.mm (modified) (3 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp (modified) (1 diff)
-
WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp (modified) (1 diff)
-
WebKit/WebProcess/Plugins/PluginView.cpp (modified) (1 diff)
-
WebKit/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm (modified) (1 diff)
-
WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm (modified) (3 diffs)
-
WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (modified) (4 diffs)
-
WebKit/WebProcess/WebPage/FindController.cpp (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebPage.cpp (modified) (44 diffs)
-
WebKit/WebProcess/WebPage/ios/FindControllerIOS.mm (modified) (2 diffs)
-
WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (71 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r282190 r282191 1 2021-09-08 Ryosuke Niwa <rniwa@webkit.org> 2 3 Deploy CheckedRef on FocusController 4 https://bugs.webkit.org/show_bug.cgi?id=230037 5 6 Reviewed by Wenson Hsieh. 7 8 Make FocusController inherit from CanMakeCheckedPtr and deploy CheckedRef / CheckedPtr wherever appropriate. 9 10 * dom/Element.cpp: 11 (WebCore::Element::focus): 12 (WebCore::Element::blur): 13 * editing/FrameSelection.cpp: 14 (WebCore::FrameSelection::selectFrameElementInParentIfFullySelected): 15 (WebCore::FrameSelection::setFocusedElementIfNeeded): 16 * editing/cocoa/AutofillElements.cpp: 17 (WebCore::AutofillElements::computeAutofillElements): 18 * editing/cocoa/DictionaryLookup.mm: 19 (WebCore::DictionaryLookup::rangeAtHitTestResult): 20 * history/BackForwardCache.cpp: 21 (WebCore::BackForwardCache::trySuspendPage): 22 * history/CachedPage.cpp: 23 (WebCore::CachedPage::restore): 24 * html/BaseDateAndTimeInputType.cpp: 25 (WebCore::BaseDateAndTimeInputType::handleFocusEvent): 26 * html/HTMLFrameElementBase.cpp: 27 (WebCore::HTMLFrameElementBase::setFocus): 28 * page/DOMWindow.cpp: 29 (WebCore::DOMWindow::focus): 30 * page/EventHandler.cpp: 31 (WebCore::EventHandler::handlePasteGlobalSelection): 32 (WebCore::EventHandler::dispatchMouseEvent): 33 (WebCore::EventHandler::defaultArrowEventHandler): 34 (WebCore::EventHandler::defaultTabEventHandler): 35 (WebCore::EventHandler::focusDocumentView): 36 * page/FocusController.h: 37 * page/Frame.cpp: 38 (WebCore::Frame::willDetachPage): 39 * page/Page.cpp: 40 (WebCore::Page::findString): 41 (WebCore::Page::replaceSelectionWithText): 42 (WebCore::Page::editableElementsInRect const): 43 (WebCore::Page::selection const): 44 (WebCore::Page::setActivityState): 45 (WebCore::Page::revealCurrentSelection): 46 * page/ios/EventHandlerIOS.mm: 47 (WebCore::EventHandler::focusDocumentView): 48 * page/mac/EventHandlerMac.mm: 49 (WebCore::EventHandler::focusDocumentView): 50 * page/mac/ServicesOverlayController.mm: 51 (WebCore::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown const): 52 (WebCore::ServicesOverlayController::telephoneNumberRangesForFocusedFrame): 53 (WebCore::ServicesOverlayController::handleClick): 54 1 55 2021-09-08 Fujii Hironori <Hironori.Fujii@sony.com> 2 56 -
trunk/Source/WebCore/dom/Element.cpp
r281793 r282191 3112 3112 // If a focus event handler changes the focus to a different node it 3113 3113 // does not make sense to continue and update appearence. 3114 if (! page->focusController().setFocusedElement(newTarget.get(), *document->frame(), optionsWithVisibility))3114 if (!CheckedRef(page->focusController())->setFocusedElement(newTarget.get(), *document->frame(), optionsWithVisibility)) 3115 3115 return; 3116 3116 } … … 3171 3171 { 3172 3172 if (treeScope().focusedElementInScope() == this) { 3173 if ( Frame*frame = document().frame())3174 frame->page()->focusController().setFocusedElement(nullptr, *frame);3173 if (RefPtr frame = document().frame()) 3174 CheckedRef(frame->page()->focusController())->setFocusedElement(nullptr, *frame); 3175 3175 else 3176 3176 document().setFocusedElement(nullptr); -
trunk/Source/WebCore/editing/FrameSelection.cpp
r281685 r282191 1977 1977 // Focus on the parent frame, and then select from before this element to after. 1978 1978 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); 1979 if (parent->selection().shouldChangeSelection(newSelection) ) {1980 page->focusController().setFocusedFrame(parent.get());1979 if (parent->selection().shouldChangeSelection(newSelection) && page) { 1980 CheckedRef(page->focusController())->setFocusedFrame(parent.get()); 1981 1981 // Previous focus can trigger DOM events, ensure the selection did not become orphan. 1982 1982 if (newSelection.isOrphan()) … … 2271 2271 bool caretBrowsing = m_document->settings().caretBrowsingEnabled(); 2272 2272 if (caretBrowsing) { 2273 if (Element* anchor = enclosingAnchorElement(m_selection.base())) { 2274 m_document->page()->focusController().setFocusedElement(anchor, *m_document->frame()); 2273 if (RefPtr anchor = enclosingAnchorElement(m_selection.base())) { 2274 CheckedRef focusController { m_document->page()->focusController() }; 2275 focusController->setFocusedElement(anchor.get(), *m_document->frame()); 2275 2276 return; 2276 2277 } … … 2284 2285 // work in the long term, but this is the safest fix at this time. 2285 2286 if (target->isMouseFocusable() && !isFrameElement(target)) { 2286 m_document->page()->focusController().setFocusedElement(target, *m_document->frame());2287 CheckedRef(m_document->page()->focusController())->setFocusedElement(target, *m_document->frame()); 2287 2288 return; 2288 2289 } … … 2293 2294 2294 2295 if (caretBrowsing) 2295 m_document->page()->focusController().setFocusedElement(nullptr, *m_document->frame());2296 CheckedRef(m_document->page()->focusController())->setFocusedElement(nullptr, *m_document->frame()); 2296 2297 } 2297 2298 -
trunk/Source/WebCore/editing/cocoa/AutofillElements.cpp
r278253 r282191 84 84 if (!start->document().page()) 85 85 return std::nullopt; 86 FocusController& focusController = start->document().page()->focusController();86 CheckedRef focusController = { start->document().page()->focusController() }; 87 87 if (start->isPasswordField()) { 88 88 auto previousElement = previousAutofillableElement(start.ptr(), focusController); -
trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm
r278253 r282191 319 319 position = firstPositionInOrBeforeNode(node); 320 320 321 auto selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();321 auto selection = CheckedRef(frame->page()->focusController())->focusedOrMainFrame().selection().selection(); 322 322 NSRange selectionRange; 323 323 NSUInteger hitIndex; -
trunk/Source/WebCore/history/BackForwardCache.cpp
r277356 r282191 440 440 // Focus the main frame, defocusing a focused subframe (if we have one). We do this here, 441 441 // before the page enters the back/forward cache, while we still can dispatch DOM blur/focus events. 442 if ( page.focusController().focusedFrame())443 page.focusController().setFocusedFrame(&page.mainFrame());442 if (CheckedRef focusController { page.focusController() }; focusController->focusedFrame()) 443 focusController->setFocusedFrame(&page.mainFrame()); 444 444 445 445 // Fire the pagehide event in all frames. -
trunk/Source/WebCore/history/CachedPage.cpp
r275527 r282191 133 133 // Restore the focus appearance for the focused element. 134 134 // FIXME: Right now we don't support pages w/ frames in the b/f cache. This may need to be tweaked when we add support for that. 135 Document* focusedDocument = page.focusController().focusedOrMainFrame().document();136 if ( Element*element = focusedDocument->focusedElement()) {135 RefPtr focusedDocument = CheckedRef(page.focusController())->focusedOrMainFrame().document(); 136 if (RefPtr element = focusedDocument->focusedElement()) { 137 137 #if PLATFORM(IOS_FAMILY) 138 138 // We don't want focused nodes changing scroll position when restoring from the cache -
trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp
r280419 r282191 445 445 // not be focused as the element is losing focus entirely. 446 446 if (auto* page = element()->document().page()) 447 page->focusController().advanceFocus(direction, 0); 447 CheckedRef(page->focusController())->advanceFocus(direction, 0); 448 448 449 } else { 449 450 // If the element received focus in any other direction, transfer focus to the first focusable child. -
trunk/Source/WebCore/html/HTMLFrameElementBase.cpp
r276628 r282191 191 191 HTMLFrameOwnerElement::setFocus(received, visibility); 192 192 if (Page* page = document().page()) { 193 CheckedRef focusController { page->focusController() }; 193 194 if (received) 194 page->focusController().setFocusedFrame(contentFrame());195 else if ( page->focusController().focusedFrame() == contentFrame()) // Focus may have already been given to another frame, don't take it away.196 page->focusController().setFocusedFrame(0);195 focusController->setFocusedFrame(contentFrame()); 196 else if (focusController->focusedFrame() == contentFrame()) // Focus may have already been given to another frame, don't take it away. 197 focusController->setFocusedFrame(nullptr); 197 198 } 198 199 } -
trunk/Source/WebCore/page/DOMWindow.cpp
r281848 r282191 1000 1000 1001 1001 // Clear the current frame's focused node if a new frame is about to be focused. 1002 RefPtr focusedFrame = page->focusController().focusedFrame();1002 RefPtr focusedFrame = CheckedRef(page->focusController())->focusedFrame(); 1003 1003 if (focusedFrame && focusedFrame != frame) 1004 1004 focusedFrame->document()->setFocusedElement(nullptr); -
trunk/Source/WebCore/page/EventHandler.cpp
r282165 r282191 2232 2232 if (!m_frame.page()) 2233 2233 return false; 2234 Frame& focusFrame = m_frame.page()->focusController().focusedOrMainFrame();2234 Frame& focusFrame = CheckedRef(m_frame.page()->focusController())->focusedOrMainFrame(); 2235 2235 // Do not paste here if the focus was moved somewhere else. 2236 2236 if (&m_frame == &focusFrame && m_frame.editor().client()->supportsGlobalSelection()) … … 2749 2749 // If focus shift is blocked, we eat the event. 2750 2750 auto* page = m_frame.page(); 2751 if (page && ! page->focusController().setFocusedElement(element.get(), m_frame, { { }, { }, { }, FocusTrigger::Click, { } }))2751 if (page && !CheckedRef(page->focusController())->setFocusedElement(element.get(), m_frame, { { }, { }, { }, FocusTrigger::Click, { } })) 2752 2752 return false; 2753 2753 … … 4326 4326 return; 4327 4327 4328 if ( page->focusController().advanceFocus(focusDirection, &event))4328 if (CheckedRef(page->focusController())->advanceFocus(focusDirection, &event)) 4329 4329 event.setDefaultHandled(); 4330 4330 } … … 4351 4351 return; 4352 4352 4353 if ( page->focusController().advanceFocus(event.shiftKey() ? FocusDirection::Backward : FocusDirection::Forward, &event))4353 if (CheckedRef(page->focusController())->advanceFocus(event.shiftKey() ? FocusDirection::Backward : FocusDirection::Forward, &event)) 4354 4354 event.setDefaultHandled(); 4355 4355 } … … 4728 4728 { 4729 4729 if (Page* page = m_frame.page()) 4730 page->focusController().setFocusedFrame(&m_frame);4730 CheckedRef(page->focusController())->setFocusedFrame(&m_frame); 4731 4731 } 4732 4732 #endif // !PLATFORM(COCOA) -
trunk/Source/WebCore/page/FocusController.h
r276016 r282191 30 30 #include "LayoutRect.h" 31 31 #include "Timer.h" 32 #include <wtf/CheckedRef.h> 32 33 #include <wtf/Forward.h> 33 34 #include <wtf/RefPtr.h> … … 48 49 struct FocusCandidate; 49 50 50 class FocusController {51 class FocusController : public CanMakeCheckedPtr { 51 52 WTF_MAKE_FAST_ALLOCATED; 52 53 public: -
trunk/Source/WebCore/page/Frame.cpp
r280504 r282191 778 778 // FIXME: It's unclear as to why this is called more than once, but it is, 779 779 // so page() could be NULL. 780 if (page() && page()->focusController().focusedFrame() == this) 781 page()->focusController().setFocusedFrame(nullptr); 780 if (page()) { 781 CheckedRef focusController { page()->focusController() }; 782 if (focusController->focusedFrame() == this) 783 focusController->setFocusedFrame(nullptr); 784 } 785 782 786 783 787 if (page() && page()->scrollingCoordinator() && m_view) -
trunk/Source/WebCore/page/Page.cpp
r282130 r282191 722 722 723 723 CanWrap canWrap = options.contains(WrapAround) ? CanWrap::Yes : CanWrap::No; 724 Frame* frame = &focusController().focusedOrMainFrame(); 725 Frame* startFrame = frame; 724 CheckedRef focusController { *m_focusController }; 725 RefPtr frame = &focusController->focusedOrMainFrame(); 726 RefPtr startFrame = frame; 726 727 do { 727 728 if (frame->editor().findString(target, (options - WrapAround) | StartInSelection)) { 728 729 if (frame != startFrame) 729 730 startFrame->selection().clear(); 730 focusController ().setFocusedFrame(frame);731 focusController->setFocusedFrame(frame.get()); 731 732 return true; 732 733 } 733 frame = incrementFrame(frame , !options.contains(Backwards), canWrap, didWrap);734 frame = incrementFrame(frame.get(), !options.contains(Backwards), canWrap, didWrap); 734 735 } while (frame && frame != startFrame); 735 736 … … 740 741 *didWrap = DidWrap::Yes; 741 742 bool found = startFrame->editor().findString(target, options | WrapAround | StartInSelection); 742 focusController ().setFocusedFrame(frame);743 focusController->setFocusedFrame(frame.get()); 743 744 return found; 744 745 } … … 940 941 uint32_t Page::replaceSelectionWithText(const String& replacementText) 941 942 { 942 auto frame = makeRef(focusController().focusedOrMainFrame());943 Ref frame = CheckedRef(focusController())->focusedOrMainFrame(); 943 944 auto selection = frame->selection().selection(); 944 945 if (!selection.isContentEditable()) … … 1021 1022 // focused element is inside the search rect it's the most likely target for future editing operations, 1022 1023 // even if it's empty. So, we special case it here. 1023 if ( auto* focusedElement = focusController().focusedOrMainFrame().document()->focusedElement()) {1024 if (RefPtr focusedElement = CheckedRef(focusController())->focusedOrMainFrame().document()->focusedElement()) { 1024 1025 if (searchRectInRootViewCoordinates.inclusivelyIntersects(focusedElement->boundingBoxInRootViewCoordinates())) { 1025 1026 if (auto* editableElement = rootEditableElement(*focusedElement)) … … 1032 1033 const VisibleSelection& Page::selection() const 1033 1034 { 1034 return focusController().focusedOrMainFrame().selection().selection();1035 return CheckedRef(focusController())->focusedOrMainFrame().selection().selection(); 1035 1036 } 1036 1037 … … 2338 2339 m_activityState = activityState; 2339 2340 2340 m_focusController->setActivityState(activityState);2341 CheckedRef(*m_focusController)->setActivityState(activityState); 2341 2342 2342 2343 if (changed & ActivityState::IsVisible) … … 3539 3540 void Page::revealCurrentSelection() 3540 3541 { 3541 focusController().focusedOrMainFrame().selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterIfNeeded);3542 CheckedRef(focusController())->focusedOrMainFrame().selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterIfNeeded); 3542 3543 } 3543 3544 -
trunk/Source/WebCore/page/ios/EventHandlerIOS.mm
r281728 r282191 199 199 200 200 RELEASE_ASSERT(page == m_frame.page()); 201 page->focusController().setFocusedFrame(&m_frame);201 CheckedRef(page->focusController())->setFocusedFrame(&m_frame); 202 202 } 203 203 -
trunk/Source/WebCore/page/mac/EventHandlerMac.mm
r280807 r282191 189 189 190 190 RELEASE_ASSERT(page == m_frame.page()); 191 page->focusController().setFocusedFrame(&m_frame);191 CheckedRef(page->focusController())->setFocusedFrame(&m_frame); 192 192 } 193 193 -
trunk/Source/WebCore/page/mac/ServicesOverlayController.mm
r278530 r282191 283 283 284 284 Seconds minimumTimeUntilHighlightShouldBeShown = 200_ms; 285 if ( m_page.focusController().focusedOrMainFrame().selection().selection().isContentEditable())285 if (CheckedRef(m_page.focusController())->focusedOrMainFrame().selection().selection().isContentEditable()) 286 286 minimumTimeUntilHighlightShouldBeShown = 1_s; 287 287 … … 474 474 Vector<SimpleRange> ServicesOverlayController::telephoneNumberRangesForFocusedFrame() 475 475 { 476 return m_page.focusController().focusedOrMainFrame().editor().detectedTelephoneNumberRanges();476 return CheckedRef(m_page.focusController())->focusedOrMainFrame().editor().detectedTelephoneNumberRanges(); 477 477 } 478 478 … … 645 645 selectedTelephoneNumbers.append(plainText(range)); 646 646 647 m_page.chrome().client().handleSelectionServiceClick( m_page.focusController().focusedOrMainFrame().selection(), selectedTelephoneNumbers, windowPoint);647 m_page.chrome().client().handleSelectionServiceClick(CheckedRef(m_page.focusController())->focusedOrMainFrame().selection(), selectedTelephoneNumbers, windowPoint); 648 648 } else if (highlight.type() == DataDetectorHighlight::Type::TelephoneNumber) 649 649 m_page.chrome().client().handleTelephoneNumberClick(plainText(highlight.range()), windowPoint); -
trunk/Source/WebKit/ChangeLog
r282190 r282191 1 2021-09-08 Ryosuke Niwa <rniwa@webkit.org> 2 3 Deploy CheckedRef on FocusController 4 https://bugs.webkit.org/show_bug.cgi?id=230037 5 6 Reviewed by Wenson Hsieh. 7 8 * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp: 9 (WKBundleFrameFocus): 10 * WebProcess/InjectedBundle/API/c/WKBundlePage.cpp: 11 (WKAccessibilityFocusedObject): 12 * WebProcess/Plugins/PluginView.cpp: 13 (WebKit::PluginView::focusPluginElement): 14 * WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm: 15 (WebKit::changeWordCase): 16 * WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm: 17 (WebKit::TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection): 18 (WebKit::TextCheckingControllerProxy::replaceRelativeToSelection): 19 (WebKit::TextCheckingControllerProxy::removeAnnotationRelativeToSelection): 20 * WebProcess/WebPage/Cocoa/WebPageCocoa.mm: 21 (WebKit::WebPage::performDictionaryLookupAtLocation): 22 (WebKit::WebPage::performDictionaryLookupOfCurrentSelection): 23 (WebKit::WebPage::insertDictatedTextAsync): 24 * WebProcess/WebPage/FindController.cpp: 25 (WebKit::FindController::showFindIndicatorInSelection): 26 * WebProcess/WebPage/WebPage.cpp: 27 (WebKit::WebPage::editorState const): 28 (WebKit::WebPage::changeFontAttributes): 29 (WebKit::WebPage::changeFont): 30 (WebKit::WebPage::updateEditorStateAfterLayoutIfEditabilityChanged): 31 (WebKit::WebPage::executeEditingCommand): 32 (WebKit::WebPage::setEditable): 33 (WebKit::WebPage::increaseListLevel): 34 (WebKit::WebPage::decreaseListLevel): 35 (WebKit::WebPage::changeListType): 36 (WebKit::WebPage::setBaseWritingDirection): 37 (WebKit::WebPage::isEditingCommandEnabled): 38 (WebKit::WebPage::contextMenuForKeyEvent): 39 (WebKit::WebPage::handleKeyEventByRelinquishingFocusToChrome): 40 (WebKit::WebPage::validateCommand): 41 (WebKit::WebPage::requestFontAttributesAtSelectionStart): 42 (WebKit::WebPage::centerSelectionInVisibleArea): 43 (WebKit::WebPage::insertNewlineInQuotedContent): 44 (WebKit::WebPage::viewWillStartLiveResize): 45 (WebKit::WebPage::viewWillEndLiveResize): 46 (WebKit::WebPage::setInitialFocus): 47 (WebKit::WebPage::getSelectionOrContentsAsString): 48 (WebKit::WebPage::advanceToNextMisspelling): 49 (WebKit::WebPage::hasRichlyEditableSelection const): 50 (WebKit::WebPage::changeSpellingToWord): 51 (WebKit::WebPage::uppercaseWord): 52 (WebKit::WebPage::lowercaseWord): 53 (WebKit::WebPage::capitalizeWord): 54 (WebKit::WebPage::clearSelection): 55 (WebKit::WebPage::restoreSelectionInFocusedEditableElement): 56 (WebKit::WebPage::handleAlternativeTextUIResult): 57 (WebKit::WebPage::setCompositionForTesting): 58 (WebKit::WebPage::hasCompositionForTesting): 59 (WebKit::WebPage::confirmCompositionForTesting): 60 (WebKit::WebPage::setTextAsync): 61 (WebKit::WebPage::insertTextAsync): 62 (WebKit::WebPage::hasMarkedText): 63 (WebKit::WebPage::getMarkedRangeAsync): 64 (WebKit::WebPage::getSelectedRangeAsync): 65 (WebKit::WebPage::characterIndexForPointAsync): 66 (WebKit::WebPage::firstRectForCharacterRangeAsync): 67 (WebKit::WebPage::setCompositionAsync): 68 (WebKit::WebPage::confirmCompositionAsync): 69 (WebKit::WebPage::didChangeSelectionOrOverflowScrollPosition): 70 (WebKit::WebPage::didEndUserTriggeredSelectionChanges): 71 (WebKit::WebPage::sendEditorStateUpdate): 72 (WebKit::WebPage::flushPendingEditorStateUpdate): 73 (WebKit::WebPage::insertAttachment): 74 (WebKit::WebPage::createAppHighlightInSelectedRange): 75 (WebKit::WebPage::restoreAppHighlightsAndScrollToIndex): 76 * WebProcess/WebPage/ios/FindControllerIOS.mm: 77 (WebKit::FindController::didFindString): 78 * WebProcess/WebPage/ios/WebPageIOS.mm: 79 (WebKit::WebPage::platformWillPerformEditingCommand): 80 (WebKit::WebPage::getSelectionContext): 81 (WebKit::WebPage::updateSelectionAppearance): 82 (WebKit::WebPage::generateSyntheticEditingCommand): 83 (WebKit::WebPage::completeSyntheticClick): 84 (WebKit::WebPage::didConcludeEditDrag): 85 (WebKit::WebPage::clearSelectionAfterTapIfNeeded): 86 (WebKit::WebPage::selectWithGesture): 87 (WebKit::WebPage::clearSelection): 88 (WebKit::WebPage::dispatchSyntheticMouseEventsForSelectionGesture): 89 (WebKit::WebPage::updateSelectionWithTouches): 90 (WebKit::WebPage::selectWithTwoTouches): 91 (WebKit::WebPage::extendSelection): 92 (WebKit::WebPage::platformDidSelectAll): 93 (WebKit::WebPage::selectWordBackward): 94 (WebKit::WebPage::moveSelectionByOffset): 95 (WebKit::WebPage::startAutoscrollAtPosition): 96 (WebKit::WebPage::requestEvasionRectsAboveSelection): 97 (WebKit::WebPage::getRectsForGranularityWithSelectionOffset): 98 (WebKit::WebPage::storeSelectionForAccessibility): 99 (WebKit::WebPage::getRectsAtSelectionOffsetWithText): 100 (WebKit::WebPage::selectPositionAtPoint): 101 (WebKit::WebPage::selectPositionAtBoundaryWithDirection): 102 (WebKit::WebPage::moveSelectionAtBoundaryWithDirection): 103 (WebKit::WebPage::setFocusedFrameBeforeSelectingTextAtLocation): 104 (WebKit::WebPage::setSelectionRange): 105 (WebKit::WebPage::updateSelectionWithExtentPointAndBoundary): 106 (WebKit::WebPage::updateSelectionWithExtentPoint): 107 (WebKit::WebPage::requestDictationContext): 108 (WebKit::WebPage::replaceSelectedText): 109 (WebKit::WebPage::replaceDictatedText): 110 (WebKit::WebPage::requestAutocorrectionData): 111 (WebKit::WebPage::applyAutocorrectionInternal): 112 (WebKit::WebPage::autocorrectionContext): 113 (WebKit::focusedElementPositionInformation): 114 (WebKit::nextAssistableElement): 115 (WebKit::WebPage::focusedElementInformation): 116 (WebKit::WebPage::hardwareKeyboardAvailabilityChanged): 117 (WebKit::WebPage::insertTextPlaceholder): 118 (WebKit::WebPage::updateSelectionWithDelta): 119 (WebKit::WebPage::requestDocumentEditingContext): 120 (WebKit::WebPage::focusTextInputContextAndPlaceCaret): 121 (WebKit::WebPage::animationDidFinishForElement): 122 1 123 2021-09-08 Fujii Hironori <Hironori.Fujii@sony.com> 2 124 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp
r271013 r282191 282 282 void WKBundleFrameFocus(WKBundleFrameRef frameRef) 283 283 { 284 WebCore::Frame*coreFrame = WebKit::toImpl(frameRef)->coreFrame();284 RefPtr coreFrame = WebKit::toImpl(frameRef)->coreFrame(); 285 285 if (!coreFrame) 286 286 return; 287 287 288 coreFrame->page()->focusController().setFocusedFrame(coreFrame);289 } 288 CheckedRef(coreFrame->page()->focusController())->setFocusedFrame(coreFrame.get()); 289 } -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp
r278253 r282191 279 279 return 0; 280 280 281 auto* focusedDocument = page->focusController().focusedOrMainFrame().document();281 RefPtr focusedDocument = CheckedRef(page->focusController())->focusedOrMainFrame().document(); 282 282 if (!focusedDocument) 283 283 return 0; -
trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp
r280689 r282191 1102 1102 1103 1103 if (Page* page = frame()->page()) 1104 page->focusController().setFocusedElement(m_pluginElement.get(), *frame());1104 CheckedRef(page->focusController())->setFocusedElement(m_pluginElement.get(), *frame()); 1105 1105 else 1106 frame()->document()->setFocusedElement(m_pluginElement.get());1106 RefPtr(frame()->document())->setFocusedElement(m_pluginElement.get()); 1107 1107 } 1108 1108 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebEditorClientMac.mm
r244932 r282191 66 66 static void changeWordCase(WebPage* page, NSString *(*changeCase)(NSString *)) 67 67 { 68 Frame& frame = page->corePage()->focusController().focusedOrMainFrame();69 if (!frame .editor().canEdit())68 Ref frame = CheckedRef(page->corePage()->focusController())->focusedOrMainFrame(); 69 if (!frame->editor().canEdit()) 70 70 return; 71 71 72 frame .editor().command("selectWord").execute();72 frame->editor().command("selectWord").execute(); 73 73 74 NSString *selectedString = frame .displayStringModifiedByEncoding(frame.editor().selectedText());75 page->replaceSelectionWithText( &frame, changeCase(selectedString));74 NSString *selectedString = frame->displayStringModifiedByEncoding(frame->editor().selectedText()); 75 page->replaceSelectionWithText(frame.ptr(), changeCase(selectedString)); 76 76 } 77 77 -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm
r278253 r282191 74 74 std::optional<TextCheckingControllerProxy::RangeAndOffset> TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection(int64_t offset, uint64_t length) 75 75 { 76 auto& frameSelection = m_page.corePage()->focusController().focusedOrMainFrame().selection();77 auto &selection = frameSelection.selection();76 auto& frameSelection = CheckedRef(m_page.corePage()->focusController()).focusedOrMainFrame().selection(); 77 auto selection = frameSelection.selection(); 78 78 79 autoroot = frameSelection.rootEditableElementOrDocumentElement();79 RefPtr root = frameSelection.rootEditableElementOrDocumentElement(); 80 80 if (!root) 81 81 return std::nullopt; … … 97 97 void TextCheckingControllerProxy::replaceRelativeToSelection(const WebCore::AttributedString& annotatedString, int64_t selectionOffset, uint64_t length, uint64_t relativeReplacementLocation, uint64_t relativeReplacementLength) 98 98 { 99 Frame& frame = m_page.corePage()->focusController().focusedOrMainFrame();100 FrameSelection &frameSelection = frame.selection();101 autoroot = frameSelection.rootEditableElementOrDocumentElement();99 Ref frame = CheckedRef(m_page.corePage()->focusController())->focusedOrMainFrame(); 100 FrameSelection frameSelection = frame.selection(); 101 RefPtr root = frameSelection.rootEditableElementOrDocumentElement(); 102 102 if (!root) 103 103 return; … … 156 156 auto removeCoreSpellingMarkers = annotation == "NSSpellingState"; 157 157 auto types = removeCoreSpellingMarkers ? relevantMarkerTypes() : WebCore::DocumentMarker::PlatformTextChecking; 158 m_page.corePage()->focusController().focusedOrMainFrame().document()->markers().filterMarkers(rangeAndOffset->range, [&] (const DocumentMarker& marker) { 158 RefPtr document = CheckedRef(m_page.corePage()->focusController()).focusedOrMainFrame().document(); 159 document->markers().filterMarkers(rangeAndOffset->range, [&] (const DocumentMarker& marker) { 159 160 if (!WTF::holds_alternative<WebCore::DocumentMarker::PlatformTextCheckingData>(marker.data())) 160 161 return false; -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
r281277 r282191 126 126 auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)), hitType); 127 127 128 auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();128 RefPtr frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &CheckedRef(m_page->focusController())->focusedOrMainFrame(); 129 129 if (!frame) 130 130 return; … … 150 150 void WebPage::performDictionaryLookupOfCurrentSelection() 151 151 { 152 auto& frame = m_page->focusController().focusedOrMainFrame();153 performDictionaryLookupForSelection(frame, frame .selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);152 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 153 performDictionaryLookupForSelection(frame, frame->selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade); 154 154 } 155 155 … … 226 226 void WebPage::insertDictatedTextAsync(const String& text, const EditingRange& replacementEditingRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, InsertTextOptions&& options) 227 227 { 228 auto& frame = m_page->focusController().focusedOrMainFrame(); 229 Ref<Frame> protector { frame }; 228 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 230 229 231 230 if (replacementEditingRange.location != notFound) { 232 231 auto replacementRange = EditingRange::toRange(frame, replacementEditingRange); 233 232 if (replacementRange) 234 frame .selection().setSelection(VisibleSelection { *replacementRange });233 frame->selection().setSelection(VisibleSelection { *replacementRange }); 235 234 } 236 235 … … 238 237 send(Messages::WebPageProxy::RegisterInsertionUndoGrouping { }); 239 238 240 RefPtr<Element> focusedElement = frame .document() ? frame.document()->focusedElement() : nullptr;239 RefPtr<Element> focusedElement = frame->document() ? frame->document()->focusedElement() : nullptr; 241 240 if (focusedElement && options.shouldSimulateKeyboardInput) 242 241 focusedElement->dispatchEvent(Event::create(eventNames().keydownEvent, Event::CanBubble::Yes, Event::IsCancelable::Yes)); 243 242 244 ASSERT(!frame .editor().hasComposition());245 frame .editor().insertDictatedText(text, dictationAlternativeLocations, nullptr /* triggeringEvent */);243 ASSERT(!frame->editor().hasComposition()); 244 frame->editor().insertDictatedText(text, dictationAlternativeLocations, nullptr /* triggeringEvent */); 246 245 247 246 if (focusedElement && options.shouldSimulateKeyboardInput) { -
trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp
r281782 r282191 436 436 void FindController::showFindIndicatorInSelection() 437 437 { 438 Frame& selectedFrame = m_webPage->corePage()->focusController().focusedOrMainFrame();438 Ref selectedFrame = CheckedRef(m_webPage->corePage()->focusController())->focusedOrMainFrame(); 439 439 updateFindIndicator(selectedFrame, false); 440 440 } -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r282130 r282191 1208 1208 { 1209 1209 // Ref the frame because this function may perform layout, which may cause frame destruction. 1210 Ref<Frame> frame = m_page->focusController().focusedOrMainFrame();1210 Ref<Frame> frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1211 1211 1212 1212 EditorState result; … … 1266 1266 void WebPage::changeFontAttributes(WebCore::FontAttributeChanges&& changes) 1267 1267 { 1268 auto& frame = m_page->focusController().focusedOrMainFrame();1269 if (frame .selection().selection().isContentEditable())1270 frame .editor().applyStyleToSelection(changes.createEditingStyle(), changes.editAction(), Editor::ColorFilterMode::InvertColor);1268 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1269 if (frame->selection().selection().isContentEditable()) 1270 frame->editor().applyStyleToSelection(changes.createEditingStyle(), changes.editAction(), Editor::ColorFilterMode::InvertColor); 1271 1271 } 1272 1272 1273 1273 void WebPage::changeFont(WebCore::FontChanges&& changes) 1274 1274 { 1275 auto& frame = m_page->focusController().focusedOrMainFrame();1276 if (frame .selection().selection().isContentEditable())1277 frame .editor().applyStyleToSelection(changes.createEditingStyle(), EditAction::SetFont, Editor::ColorFilterMode::InvertColor);1275 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1276 if (frame->selection().selection().isContentEditable()) 1277 frame->editor().applyStyleToSelection(changes.createEditingStyle(), EditAction::SetFont, Editor::ColorFilterMode::InvertColor); 1278 1278 } 1279 1279 … … 1311 1311 return; 1312 1312 1313 Frame& frame = m_page->focusController().focusedOrMainFrame();1314 EditorStateIsContentEditable editorStateIsContentEditable = frame .selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;1313 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1314 EditorStateIsContentEditable editorStateIsContentEditable = frame->selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No; 1315 1315 if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable) 1316 1316 scheduleFullEditorStateUpdate(); … … 1426 1426 platformWillPerformEditingCommand(); 1427 1427 1428 auto& frame = m_page->focusController().focusedOrMainFrame();1428 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1429 1429 1430 1430 if (PluginView* pluginView = focusedPluginViewForFrame(frame)) { … … 1433 1433 } 1434 1434 1435 frame .editor().command(commandName).execute(argument);1435 frame->editor().command(commandName).execute(argument); 1436 1436 } 1437 1437 … … 1440 1440 m_page->setEditable(editable); 1441 1441 m_page->setTabKeyCyclesThroughElements(!editable); 1442 Frame& frame = m_page->focusController().focusedOrMainFrame();1442 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1443 1443 if (editable) { 1444 frame .editor().applyEditingStyleToBodyElement();1444 frame->editor().applyEditingStyleToBodyElement(); 1445 1445 // If the page is made editable and the selection is empty, set it to something. 1446 if (frame .selection().isNone())1447 frame .selection().setSelectionFromNone();1446 if (frame->selection().isNone()) 1447 frame->selection().setSelectionFromNone(); 1448 1448 } 1449 1449 } … … 1451 1451 void WebPage::increaseListLevel() 1452 1452 { 1453 m_page->focusController().focusedOrMainFrame().editor().increaseSelectionListLevel(); 1453 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1454 frame->editor().increaseSelectionListLevel(); 1454 1455 } 1455 1456 1456 1457 void WebPage::decreaseListLevel() 1457 1458 { 1458 m_page->focusController().focusedOrMainFrame().editor().decreaseSelectionListLevel(); 1459 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1460 frame->editor().decreaseSelectionListLevel(); 1459 1461 } 1460 1462 1461 1463 void WebPage::changeListType() 1462 1464 { 1463 m_page->focusController().focusedOrMainFrame().editor().changeSelectionListType(); 1465 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1466 frame->editor().changeSelectionListType(); 1464 1467 } 1465 1468 1466 1469 void WebPage::setBaseWritingDirection(WritingDirection direction) 1467 1470 { 1468 m_page->focusController().focusedOrMainFrame().editor().setBaseWritingDirection(direction); 1471 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1472 frame->editor().setBaseWritingDirection(direction); 1469 1473 } 1470 1474 1471 1475 bool WebPage::isEditingCommandEnabled(const String& commandName) 1472 1476 { 1473 Frame& frame = m_page->focusController().focusedOrMainFrame();1477 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1474 1478 1475 1479 if (PluginView* pluginView = focusedPluginViewForFrame(frame)) 1476 1480 return pluginView->isEditingCommandEnabled(commandName); 1477 1481 1478 Editor::Command command = frame .editor().command(commandName);1482 Editor::Command command = frame->editor().command(commandName); 1479 1483 return command.isSupported() && command.isEnabled(); 1480 1484 } … … 2908 2912 #endif 2909 2913 2910 Frame& frame = m_page->focusController().focusedOrMainFrame();2911 bool handled = frame .eventHandler().sendContextMenuEventForKey();2914 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2915 bool handled = frame->eventHandler().sendContextMenuEventForKey(); 2912 2916 #if ENABLE(CONTEXT_MENUS) 2913 2917 if (handled) … … 3094 3098 // elements inside the view. We can only do this for shift-tab, not tab itself because 3095 3099 // tabKeyCyclesThroughElements is used to make tab character insertion work in editable web views. 3096 return m_page->focusController().relinquishFocusToChrome(FocusDirection::Backward);3100 return CheckedRef(m_page->focusController())->relinquishFocusToChrome(FocusDirection::Backward); 3097 3101 } 3098 3102 … … 3101 3105 bool isEnabled = false; 3102 3106 int32_t state = 0; 3103 Frame& frame = m_page->focusController().focusedOrMainFrame();3107 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 3104 3108 if (PluginView* pluginView = focusedPluginViewForFrame(frame)) 3105 3109 isEnabled = pluginView->isEditingCommandEnabled(commandName); 3106 3110 else { 3107 Editor::Command command = frame .editor().command(commandName);3111 Editor::Command command = frame->editor().command(commandName); 3108 3112 state = (command.state() != TriState::False); 3109 3113 isEnabled = command.isSupported() && command.isEnabled(); … … 3161 3165 void WebPage::requestFontAttributesAtSelectionStart(CompletionHandler<void(const WebCore::FontAttributes&)>&& completionHandler) 3162 3166 { 3163 completionHandler( m_page->focusController().focusedOrMainFrame().editor().fontAttributesAtSelectionStart());3167 completionHandler(CheckedRef(m_page->focusController())->focusedOrMainFrame().editor().fontAttributesAtSelectionStart()); 3164 3168 } 3165 3169 … … 3310 3314 void WebPage::centerSelectionInVisibleArea() 3311 3315 { 3312 Frame& frame = m_page->focusController().focusedOrMainFrame();3313 frame .selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterAlways);3316 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 3317 frame->selection().revealSelection(SelectionRevealMode::Reveal, ScrollAlignment::alignCenterAlways); 3314 3318 findController().showFindIndicatorInSelection(); 3315 3319 } … … 3342 3346 void WebPage::insertNewlineInQuotedContent() 3343 3347 { 3344 Frame& frame = m_page->focusController().focusedOrMainFrame();3345 if (frame .selection().isNone())3346 return; 3347 frame .editor().insertParagraphSeparatorInQuotedContent();3348 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 3349 if (frame->selection().isNone()) 3350 return; 3351 frame->editor().insertParagraphSeparatorInQuotedContent(); 3348 3352 } 3349 3353 … … 3393 3397 3394 3398 // FIXME: This should propagate to all ScrollableAreas. 3395 Frame& frame = m_page->focusController().focusedOrMainFrame();3396 if ( FrameView* view = frame.view())3399 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 3400 if (RefPtr view = frame->view()) 3397 3401 view->willStartLiveResize(); 3398 3402 } … … 3404 3408 3405 3409 // FIXME: This should propagate to all ScrollableAreas. 3406 Frame& frame = m_page->focusController().focusedOrMainFrame();3407 if ( FrameView* view = frame.view())3410 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 3411 if (RefPtr view = frame->view()) 3408 3412 view->willEndLiveResize(); 3409 3413 } … … 3416 3420 SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true }; 3417 3421 3418 Frame& frame = m_page->focusController().focusedOrMainFrame(); 3419 frame.document()->setFocusedElement(0); 3422 CheckedRef focusController { m_page->focusController() }; 3423 Ref frame = focusController->focusedOrMainFrame(); 3424 frame->document()->setFocusedElement(nullptr); 3420 3425 3421 3426 if (isKeyboardEventValid && event.type() == WebEvent::KeyDown) { 3422 3427 PlatformKeyboardEvent platformEvent(platform(event)); 3423 3428 platformEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); 3424 m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, &KeyboardEvent::create(platformEvent, &frame.windowProxy()).get());3429 focusController->setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, &KeyboardEvent::create(platformEvent, &frame->windowProxy()).get()); 3425 3430 completionHandler(); 3426 3431 return; 3427 3432 } 3428 3433 3429 m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, nullptr);3434 focusController->setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, nullptr); 3430 3435 completionHandler(); 3431 3436 } … … 3813 3818 void WebPage::getSelectionOrContentsAsString(CompletionHandler<void(const String&)>&& callback) 3814 3819 { 3815 WebFrame* focusedOrMainFrame = WebFrame::fromCoreFrame( m_page->focusController().focusedOrMainFrame());3820 WebFrame* focusedOrMainFrame = WebFrame::fromCoreFrame(CheckedRef(m_page->focusController())->focusedOrMainFrame()); 3816 3821 String resultString = focusedOrMainFrame->selectionAsString(); 3817 3822 if (resultString.isEmpty()) … … 4765 4770 void WebPage::advanceToNextMisspelling(bool startBeforeSelection) 4766 4771 { 4767 Frame& frame = m_page->focusController().focusedOrMainFrame();4768 frame .editor().advanceToNextMisspelling(startBeforeSelection);4772 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4773 frame->editor().advanceToNextMisspelling(startBeforeSelection); 4769 4774 } 4770 4775 #endif … … 4772 4777 bool WebPage::hasRichlyEditableSelection() const 4773 4778 { 4774 auto& frame = m_page->focusController().focusedOrMainFrame();4779 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4775 4780 if (m_page->dragCaretController().isContentRichlyEditable()) 4776 4781 return true; 4777 4782 4778 return frame .selection().selection().isContentRichlyEditable();4783 return frame->selection().selection().isContentRichlyEditable(); 4779 4784 } 4780 4785 4781 4786 void WebPage::changeSpellingToWord(const String& word) 4782 4787 { 4783 replaceSelectionWithText(& m_page->focusController().focusedOrMainFrame(), word);4788 replaceSelectionWithText(&CheckedRef(m_page->focusController())->focusedOrMainFrame(), word); 4784 4789 } 4785 4790 … … 4803 4808 void WebPage::uppercaseWord() 4804 4809 { 4805 m_page->focusController().focusedOrMainFrame().editor().uppercaseWord(); 4810 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4811 frame->editor().uppercaseWord(); 4806 4812 } 4807 4813 4808 4814 void WebPage::lowercaseWord() 4809 4815 { 4810 m_page->focusController().focusedOrMainFrame().editor().lowercaseWord(); 4816 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4817 frame->editor().lowercaseWord(); 4811 4818 } 4812 4819 4813 4820 void WebPage::capitalizeWord() 4814 4821 { 4815 m_page->focusController().focusedOrMainFrame().editor().capitalizeWord(); 4822 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4823 frame->editor().capitalizeWord(); 4816 4824 } 4817 4825 #endif … … 4851 4859 void WebPage::clearSelection() 4852 4860 { 4853 m_page->focusController().focusedOrMainFrame().selection().clear(); 4861 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4862 frame->selection().clear(); 4854 4863 } 4855 4864 #endif … … 4857 4866 void WebPage::restoreSelectionInFocusedEditableElement() 4858 4867 { 4859 Frame& frame = m_page->focusController().focusedOrMainFrame();4860 if (!frame .selection().isNone())4861 return; 4862 4863 if ( auto document = frame.document()) {4864 if ( autoelement = document->focusedElement())4868 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4869 if (!frame->selection().isNone()) 4870 return; 4871 4872 if (RefPtr document = frame->document()) { 4873 if (RefPtr element = document->focusedElement()) 4865 4874 element->updateFocusAppearance(SelectionRestorationMode::RestoreOrSelectAll, SelectionRevealMode::DoNotReveal); 4866 4875 } … … 5577 5586 void WebPage::handleAlternativeTextUIResult(const String& result) 5578 5587 { 5579 Frame& frame = m_page->focusController().focusedOrMainFrame();5580 frame .editor().handleAlternativeTextUIResult(result);5588 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5589 frame->editor().handleAlternativeTextUIResult(result); 5581 5590 } 5582 5591 #endif … … 5601 5610 void WebPage::setCompositionForTesting(const String& compositionString, uint64_t from, uint64_t length, bool suppressUnderline, const Vector<CompositionHighlight>& highlights) 5602 5611 { 5603 Frame& frame = m_page->focusController().focusedOrMainFrame();5604 if (!frame .editor().canEdit())5612 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5613 if (!frame->editor().canEdit()) 5605 5614 return; 5606 5615 … … 5609 5618 underlines.append(CompositionUnderline(0, compositionString.length(), CompositionUnderlineColor::TextColor, Color(Color::black), false)); 5610 5619 5611 frame .editor().setComposition(compositionString, underlines, highlights, from, from + length);5620 frame->editor().setComposition(compositionString, underlines, highlights, from, from + length); 5612 5621 } 5613 5622 5614 5623 bool WebPage::hasCompositionForTesting() 5615 5624 { 5616 Frame& frame = m_page->focusController().focusedOrMainFrame();5617 return frame .editor().hasComposition();5625 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5626 return frame->editor().hasComposition(); 5618 5627 } 5619 5628 5620 5629 void WebPage::confirmCompositionForTesting(const String& compositionString) 5621 5630 { 5622 Frame& frame = m_page->focusController().focusedOrMainFrame();5623 if (!frame .editor().canEdit())5631 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5632 if (!frame->editor().canEdit()) 5624 5633 return; 5625 5634 5626 5635 if (compositionString.isNull()) 5627 frame .editor().confirmComposition();5628 frame .editor().confirmComposition(compositionString);5636 frame->editor().confirmComposition(); 5637 frame->editor().confirmComposition(compositionString); 5629 5638 } 5630 5639 … … 5742 5751 void WebPage::setTextAsync(const String& text) 5743 5752 { 5744 auto frame = makeRef(m_page->focusController().focusedOrMainFrame());5753 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5745 5754 if (frame->selection().selection().isContentEditable()) { 5746 5755 UserTypingGestureIndicator indicator(frame.get()); … … 5765 5774 platformWillPerformEditingCommand(); 5766 5775 5767 auto& frame = m_page->focusController().focusedOrMainFrame(); 5768 5769 Ref<Frame> protector(frame); 5770 5771 UserGestureIndicator gestureIndicator { options.processingUserGesture ? ProcessingUserGesture : NotProcessingUserGesture, frame.document() }; 5776 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5777 5778 UserGestureIndicator gestureIndicator { options.processingUserGesture ? ProcessingUserGesture : NotProcessingUserGesture, frame->document() }; 5772 5779 5773 5780 bool replacesText = false; … … 5775 5782 if (auto replacementRange = EditingRange::toRange(frame, replacementEditingRange, options.editingRangeIsRelativeTo)) { 5776 5783 SetForScope<bool> isSelectingTextWhileInsertingAsynchronously(m_isSelectingTextWhileInsertingAsynchronously, options.suppressSelectionUpdate); 5777 frame .selection().setSelection(VisibleSelection(*replacementRange));5784 frame->selection().setSelection(VisibleSelection(*replacementRange)); 5778 5785 replacesText = replacementEditingRange.length; 5779 5786 } … … 5783 5790 send(Messages::WebPageProxy::RegisterInsertionUndoGrouping()); 5784 5791 5785 RefPtr <Element> focusedElement = frame.document() ? frame.document()->focusedElement() : nullptr;5792 RefPtr focusedElement = frame->document() ? frame->document()->focusedElement() : nullptr; 5786 5793 if (focusedElement && options.shouldSimulateKeyboardInput) 5787 5794 focusedElement->dispatchEvent(Event::create(eventNames().keydownEvent, Event::CanBubble::Yes, Event::IsCancelable::Yes)); 5788 5795 5789 if (!frame .editor().hasComposition()) {5796 if (!frame->editor().hasComposition()) { 5790 5797 // An insertText: might be handled by other responders in the chain if we don't handle it. 5791 5798 // One example is space bar that results in scrolling down the page. 5792 frame .editor().insertText(text, nullptr, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard);5799 frame->editor().insertText(text, nullptr, replacesText ? TextEventInputAutocompletion : TextEventInputKeyboard); 5793 5800 } else 5794 frame .editor().confirmComposition(text);5801 frame->editor().confirmComposition(text); 5795 5802 5796 5803 if (focusedElement && options.shouldSimulateKeyboardInput) { … … 5802 5809 void WebPage::hasMarkedText(CompletionHandler<void(bool)>&& completionHandler) 5803 5810 { 5804 completionHandler( m_page->focusController().focusedOrMainFrame().editor().hasComposition());5811 completionHandler(CheckedRef(m_page->focusController())->focusedOrMainFrame().editor().hasComposition()); 5805 5812 } 5806 5813 5807 5814 void WebPage::getMarkedRangeAsync(CompletionHandler<void(const EditingRange&)>&& completionHandler) 5808 5815 { 5809 Frame& frame = m_page->focusController().focusedOrMainFrame();5810 completionHandler(EditingRange::fromRange(frame, frame .editor().compositionRange()));5816 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5817 completionHandler(EditingRange::fromRange(frame, frame->editor().compositionRange())); 5811 5818 } 5812 5819 5813 5820 void WebPage::getSelectedRangeAsync(CompletionHandler<void(const EditingRange&)>&& completionHandler) 5814 5821 { 5815 Frame& frame = m_page->focusController().focusedOrMainFrame();5816 completionHandler(EditingRange::fromRange(frame, frame .selection().selection().toNormalizedRange()));5822 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5823 completionHandler(EditingRange::fromRange(frame, frame->selection().selection().toNormalizedRange())); 5817 5824 } 5818 5825 … … 5821 5828 constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::DisallowUserAgentShadowContent, HitTestRequest::Type::AllowChildFrameContent }; 5822 5829 auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(point, hitType); 5823 auto& frame = result.innerNonSharedNode() ? *result.innerNodeFrame() : m_page->focusController().focusedOrMainFrame();5824 auto range = frame .rangeForPoint(result.roundedPointInInnerNodeFrame());5830 Ref frame = result.innerNonSharedNode() ? *result.innerNodeFrame() : CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5831 auto range = frame->rangeForPoint(result.roundedPointInInnerNodeFrame()); 5825 5832 auto editingRange = EditingRange::fromRange(frame, range); 5826 5833 completionHandler(editingRange.location); … … 5829 5836 void WebPage::firstRectForCharacterRangeAsync(const EditingRange& editingRange, CompletionHandler<void(const WebCore::IntRect&, const EditingRange&)>&& completionHandler) 5830 5837 { 5831 auto& frame = m_page->focusController().focusedOrMainFrame();5838 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5832 5839 auto range = EditingRange::toRange(frame, editingRange); 5833 5840 if (!range) … … 5835 5842 5836 5843 // FIXME: Pass an EditingRange that matches the range of the first rect, rather than the entire passed-in range? 5837 auto rect = frame.view()->contentsToWindow(frame.editor().firstRectForRange(*range));5844 auto rect = RefPtr(frame->view())->contentsToWindow(frame->editor().firstRectForRange(*range)); 5838 5845 completionHandler(rect, editingRange); 5839 5846 } … … 5843 5850 platformWillPerformEditingCommand(); 5844 5851 5845 auto& frame = m_page->focusController().focusedOrMainFrame();5846 if (frame .selection().selection().isContentEditable()) {5852 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5853 if (frame->selection().selection().isContentEditable()) { 5847 5854 if (replacementEditingRange.location != notFound) { 5848 5855 if (auto replacementRange = EditingRange::toRange(frame, replacementEditingRange)) 5849 frame .selection().setSelection(VisibleSelection(*replacementRange));5856 frame->selection().setSelection(VisibleSelection(*replacementRange)); 5850 5857 } 5851 frame .editor().setComposition(text, underlines, highlights, selection.location, selection.location + selection.length);5858 frame->editor().setComposition(text, underlines, highlights, selection.location, selection.location + selection.length); 5852 5859 } 5853 5860 } … … 5857 5864 platformWillPerformEditingCommand(); 5858 5865 5859 Frame& frame = m_page->focusController().focusedOrMainFrame();5860 frame .editor().confirmComposition();5866 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5867 frame->editor().confirmComposition(); 5861 5868 } 5862 5869 … … 5942 5949 void WebPage::didChangeSelectionOrOverflowScrollPosition() 5943 5950 { 5944 Frame& frame = m_page->focusController().focusedOrMainFrame();5951 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 5945 5952 // The act of getting Dictionary Popup info can make selection changes that we should not propagate to the UIProcess. 5946 5953 // Specifically, if there is a caret selection, it will change to a range selection of the word around the caret. And 5947 5954 // then it will change back. 5948 if (frame .editor().isGettingDictionaryPopupInfo())5955 if (frame->editor().isGettingDictionaryPopupInfo()) 5949 5956 return; 5950 5957 … … 5960 5967 if (!hasPreviouslyFocusedDueToUserInteraction && m_hasEverFocusedElementDueToUserInteractionSincePageTransition) { 5961 5968 #if HAVE(TOUCH_BAR) 5962 if (frame .document()->quirks().isTouchBarUpdateSupressedForHiddenContentEditable()) {5969 if (frame->document()->quirks().isTouchBarUpdateSupressedForHiddenContentEditable()) { 5963 5970 m_isTouchBarUpdateSupressedForHiddenContentEditable = true; 5964 5971 send(Messages::WebPageProxy::SetIsTouchBarUpdateSupressedForHiddenContentEditable(m_isTouchBarUpdateSupressedForHiddenContentEditable)); 5965 5972 } 5966 5973 5967 if (frame .document()->quirks().isNeverRichlyEditableForTouchBar()) {5974 if (frame->document()->quirks().isNeverRichlyEditableForTouchBar()) { 5968 5975 m_isNeverRichlyEditableForTouchBar = true; 5969 5976 send(Messages::WebPageProxy::SetIsNeverRichlyEditableForTouchBar(m_isNeverRichlyEditableForTouchBar)); … … 5978 5985 // FIXME: Many changes that affect composition node do not go through didChangeSelection(). We need to do something when DOM manipulation affects the composition, because otherwise input method's idea about it will be different from Editor's. 5979 5986 // FIXME: We can't cancel composition when selection changes to NoSelection, but we probably should. 5980 if (frame .editor().hasComposition() && !frame.editor().ignoreSelectionChanges() && !frame.selection().isNone()) {5981 frame .editor().cancelComposition();5987 if (frame->editor().hasComposition() && !frame->editor().ignoreSelectionChanges() && !frame->selection().isNone()) { 5988 frame->editor().cancelComposition(); 5982 5989 discardedComposition(); 5983 5990 return; … … 6109 6116 void WebPage::didEndUserTriggeredSelectionChanges() 6110 6117 { 6111 Frame& frame = m_page->focusController().focusedOrMainFrame();6112 if (!frame .editor().ignoreSelectionChanges())6118 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 6119 if (!frame->editor().ignoreSelectionChanges()) 6113 6120 sendEditorStateUpdate(); 6114 6121 } … … 6498 6505 void WebPage::sendEditorStateUpdate() 6499 6506 { 6500 Frame& frame = m_page->focusController().focusedOrMainFrame();6501 if (frame .editor().ignoreSelectionChanges() || !frame.document() || !frame.document()->hasLivingRenderTree())6507 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 6508 if (frame->editor().ignoreSelectionChanges() || !frame->document() || !frame->document()->hasLivingRenderTree()) 6502 6509 return; 6503 6510 … … 6587 6594 return; 6588 6595 6589 Frame& frame = m_page->focusController().focusedOrMainFrame();6590 if (frame .editor().ignoreSelectionChanges())6596 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 6597 if (frame->editor().ignoreSelectionChanges()) 6591 6598 return; 6592 6599 … … 7166 7173 void WebPage::insertAttachment(const String& identifier, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType, CompletionHandler<void()>&& callback) 7167 7174 { 7168 auto& frame = m_page->focusController().focusedOrMainFrame();7169 frame .editor().insertAttachment(identifier, WTFMove(fileSize), fileName, contentType);7175 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 7176 frame->editor().insertAttachment(identifier, WTFMove(fileSize), fileName, contentType); 7170 7177 callback(); 7171 7178 } … … 7631 7638 SetForScope<WebCore::HighlightRequestOriginatedInApp> highlightRequestOriginScope { m_highlightRequestOriginatedInApp, requestOriginatedInApp }; 7632 7639 7633 auto document = makeRefPtr(m_page->focusController().focusedOrMainFrame().document());7640 RefPtr document = CheckedRef(m_page->focusController())->focusedOrMainFrame().document(); 7634 7641 7635 7642 auto frame = makeRefPtr(document->frame()); … … 7649 7656 void WebPage::restoreAppHighlightsAndScrollToIndex(const Vector<SharedMemory::IPCHandle>&& memoryHandles, const std::optional<unsigned> index) 7650 7657 { 7651 auto document = makeRefPtr(m_page->focusController().focusedOrMainFrame().document());7658 RefPtr document = CheckedRef(m_page->focusController())->focusedOrMainFrame().document(); 7652 7659 7653 7660 unsigned i = 0; -
trunk/Source/WebKit/WebProcess/WebPage/ios/FindControllerIOS.mm
r278560 r282191 158 158 // Therefore, we need to force an update no matter what. 159 159 160 Frame& frame = m_webPage->corePage()->focusController().focusedOrMainFrame();161 frame .selection().setUpdateAppearanceEnabled(true);162 frame .selection().updateAppearance();163 frame .selection().setUpdateAppearanceEnabled(false);160 Ref frame = CheckedRef(m_webPage->corePage()->focusController())->focusedOrMainFrame(); 161 frame->selection().setUpdateAppearanceEnabled(true); 162 frame->selection().updateAppearance(); 163 frame->selection().setUpdateAppearanceEnabled(false); 164 164 165 165 // Scrolling the main frame is handled by the SmartMagnificationController class but we still … … 168 168 // text, so we reveal the text at the center of the viewport. 169 169 // FIXME: Find a better way to estimate the obscured area (https://webkit.org/b/183889). 170 frame .selection().revealSelection(SelectionRevealMode::RevealUpToMainFrame, ScrollAlignment::alignCenterAlways, WebCore::DoNotRevealExtent);170 frame->selection().revealSelection(SelectionRevealMode::RevealUpToMainFrame, ScrollAlignment::alignCenterAlways, WebCore::DoNotRevealExtent); 171 171 } 172 172 -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r281970 r282191 358 358 { 359 359 #if ENABLE(CONTENT_CHANGE_OBSERVER) 360 auto& frame = m_page->focusController().focusedOrMainFrame();361 if ( auto* document = frame.document()) {360 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 361 if (RefPtr document = frame->document()) { 362 362 if (auto* holdingTank = document->domTimerHoldingTankIfExists()) 363 363 holdingTank->removeAll(); … … 573 573 void WebPage::getSelectionContext(CompletionHandler<void(const String&, const String&, const String&)>&& completionHandler) 574 574 { 575 Frame& frame = m_page->focusController().focusedOrMainFrame();576 if (!frame .selection().isRange())575 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 576 if (!frame->selection().isRange()) 577 577 return completionHandler({ }, { }, { }); 578 578 const int selectionExtendedContextLength = 350; 579 579 580 auto& selection = frame .selection().selection();580 auto& selection = frame->selection().selection(); 581 581 String selectedText = plainTextForContext(selection.firstRange()); 582 582 String textBefore = plainTextForDisplay(rangeExpandedByCharactersInDirectionAtWordBoundary(selection.start(), selectionExtendedContextLength, SelectionDirection::Backward)); … … 666 666 void WebPage::updateSelectionAppearance() 667 667 { 668 auto& frame = m_page->focusController().focusedOrMainFrame();669 auto& editor = frame .editor();668 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 669 auto& editor = frame->editor(); 670 670 if (editor.ignoreSelectionChanges()) 671 671 return; … … 674 674 return; 675 675 676 if (!editor.hasComposition() && frame .selection().selection().isNone())676 if (!editor.hasComposition() && frame->selection().selection().isNone()) 677 677 return; 678 678 … … 695 695 { 696 696 PlatformKeyboardEvent keyEvent; 697 auto& frame = m_page->focusController().focusedOrMainFrame();697 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 698 698 699 699 OptionSet<PlatformEvent::Modifier> modifiers; … … 734 734 PlatformKeyboardEvent::setCurrentModifierState(modifiers); 735 735 736 frame .eventHandler().keyEvent(keyEvent);736 frame->eventHandler().keyEvent(keyEvent); 737 737 } 738 738 … … 839 839 Frame& mainframe = m_page->mainFrame(); 840 840 841 RefPtr<Frame> oldFocusedFrame = m_page->focusController().focusedFrame();841 RefPtr<Frame> oldFocusedFrame = CheckedRef(m_page->focusController())->focusedFrame(); 842 842 RefPtr<Element> oldFocusedElement = oldFocusedFrame ? oldFocusedFrame->document()->focusedElement() : nullptr; 843 843 … … 865 865 return; 866 866 867 RefPtr<Frame> newFocusedFrame = m_page->focusController().focusedFrame();867 RefPtr<Frame> newFocusedFrame = CheckedRef(m_page->focusController())->focusedFrame(); 868 868 RefPtr<Element> newFocusedElement = newFocusedFrame ? newFocusedFrame->document()->focusedElement() : nullptr; 869 869 … … 1002 1002 m_pendingImageElementsForDropSnapshot.clear(); 1003 1003 1004 auto frame = makeRef(m_page->focusController().focusedOrMainFrame());1004 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1005 1005 if (auto selectionRange = frame->selection().selection().toNormalizedRange()) { 1006 1006 m_pendingImageElementsForDropSnapshot = visibleImageElementsInRangeWithNonLoadedImages(*selectionRange); … … 1174 1174 void WebPage::clearSelectionAfterTapIfNeeded() 1175 1175 { 1176 if (m_page->focusController().focusedOrMainFrame().selection().selection().isContentEditable()) 1176 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1177 if (frame->selection().selection().isContentEditable()) 1177 1178 return; 1178 1179 … … 1377 1378 setFocusedFrameBeforeSelectingTextAtLocation(point); 1378 1379 1379 auto& frame = m_page->focusController().focusedOrMainFrame();1380 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1380 1381 VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement); 1381 1382 … … 1389 1390 switch (static_cast<GestureType>(gestureType)) { 1390 1391 case GestureType::PhraseBoundary: { 1391 if (!frame .editor().hasComposition())1392 if (!frame->editor().hasComposition()) 1392 1393 break; 1393 auto markedRange = frame .editor().compositionRange();1394 auto markedRange = frame->editor().compositionRange(); 1394 1395 auto startPosition = VisiblePosition { makeDeprecatedLegacyPosition(markedRange->start) }; 1395 1396 position = std::clamp(position, startPosition, VisiblePosition { makeDeprecatedLegacyPosition(markedRange->end) }); 1396 1397 if (wkGestureState != GestureRecognizerState::Began) 1397 flags = distanceBetweenPositions(startPosition, frame .selection().selection().start()) != distanceBetweenPositions(startPosition, position) ? PhraseBoundaryChanged : OptionSet<SelectionFlags> { };1398 flags = distanceBetweenPositions(startPosition, frame->selection().selection().start()) != distanceBetweenPositions(startPosition, position) ? PhraseBoundaryChanged : OptionSet<SelectionFlags> { }; 1398 1399 else 1399 1400 flags = PhraseBoundaryChanged; … … 1499 1500 } 1500 1501 if (range) 1501 frame .selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);1502 frame->selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 1502 1503 1503 1504 completionHandler(point, gestureType, gestureState, flags); … … 1697 1698 { 1698 1699 m_startingGestureRange = std::nullopt; 1699 m_page->focusController().focusedOrMainFrame().selection().clear();1700 CheckedRef(m_page->focusController())->focusedOrMainFrame().selection().clear(); 1700 1701 } 1701 1702 1702 1703 void WebPage::dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch touch, const IntPoint& point) 1703 1704 { 1704 auto frame = makeRef(m_page->focusController().focusedOrMainFrame());1705 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1705 1706 if (!frame->selection().selection().isContentEditable()) 1706 1707 return; … … 1733 1734 void WebPage::updateSelectionWithTouches(const IntPoint& point, SelectionTouch selectionTouch, bool baseIsStart, CompletionHandler<void(const WebCore::IntPoint&, SelectionTouch, OptionSet<SelectionFlags>)>&& completionHandler) 1734 1735 { 1735 Frame& frame = m_page->focusController().focusedOrMainFrame();1736 IntPoint pointInDocument = frame.view()->rootViewToContents(point);1737 VisiblePosition position = frame .visiblePositionForPoint(pointInDocument);1736 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1737 IntPoint pointInDocument = RefPtr(frame->view())->rootViewToContents(point); 1738 VisiblePosition position = frame->visiblePositionForPoint(pointInDocument); 1738 1739 if (position.isNull()) 1739 1740 return completionHandler(point, selectionTouch, { }); … … 1751 1752 1752 1753 case SelectionTouch::Ended: 1753 if (frame .selection().selection().isContentEditable())1754 if (frame->selection().selection().isContentEditable()) 1754 1755 range = makeSimpleRange(closestWordBoundaryForPosition(position)); 1755 1756 else … … 1758 1759 1759 1760 case SelectionTouch::EndedMovingForward: 1760 range = rangeAtWordBoundaryForPosition( &frame, position, baseIsStart, SelectionDirection::Forward);1761 range = rangeAtWordBoundaryForPosition(frame.ptr(), position, baseIsStart, SelectionDirection::Forward); 1761 1762 break; 1762 1763 1763 1764 case SelectionTouch::EndedMovingBackward: 1764 range = rangeAtWordBoundaryForPosition( &frame, position, baseIsStart, SelectionDirection::Backward);1765 range = rangeAtWordBoundaryForPosition(frame.ptr(), position, baseIsStart, SelectionDirection::Backward); 1765 1766 break; 1766 1767 … … 1771 1772 1772 1773 if (range) 1773 frame .selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);1774 frame->selection().setSelectedRange(range, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 1774 1775 1775 1776 completionHandler(point, selectionTouch, flags); … … 1778 1779 void WebPage::selectWithTwoTouches(const WebCore::IntPoint& from, const WebCore::IntPoint& to, GestureType gestureType, GestureRecognizerState gestureState, CompletionHandler<void(const WebCore::IntPoint&, GestureType, GestureRecognizerState, OptionSet<SelectionFlags>)>&& completionHandler) 1779 1780 { 1780 Frame& frame = m_page->focusController().focusedOrMainFrame(); 1781 auto fromPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(from)); 1782 auto toPosition = frame.visiblePositionForPoint(frame.view()->rootViewToContents(to)); 1781 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1782 RefPtr view = frame->view(); 1783 auto fromPosition = frame->visiblePositionForPoint(view->rootViewToContents(from)); 1784 auto toPosition = frame->visiblePositionForPoint(view->rootViewToContents(to)); 1783 1785 if (auto range = makeSimpleRange(fromPosition, toPosition)) { 1784 1786 if (!(fromPosition < toPosition)) 1785 1787 std::swap(range->start, range->end); 1786 frame .selection().setSelectedRange(range, fromPosition.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);1788 frame->selection().setSelectedRange(range, fromPosition.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 1787 1789 } 1788 1790 … … 1795 1797 auto callCompletionHandlerOnExit = makeScopeExit(WTFMove(completionHandler)); 1796 1798 1797 Frame& frame = m_page->focusController().focusedOrMainFrame();1799 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1798 1800 // For the moment we handle only TextGranularity::WordGranularity. 1799 if (granularity != TextGranularity::WordGranularity || !frame .selection().isCaret())1800 return; 1801 1802 VisiblePosition position = frame .selection().selection().start();1801 if (granularity != TextGranularity::WordGranularity || !frame->selection().isCaret()) 1802 return; 1803 1804 VisiblePosition position = frame->selection().selection().start(); 1803 1805 auto wordRange = wordRangeFromPosition(position); 1804 1806 if (!wordRange) … … 1808 1810 bool shouldDispatchMouseEvents = shouldDispatchSyntheticMouseEventsWhenModifyingSelection(); 1809 1811 if (shouldDispatchMouseEvents) { 1810 auto startLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->start)).absoluteCaretBounds()).center(); 1811 endLocationForSyntheticMouseEvents = frame.view()->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->end)).absoluteCaretBounds()).center(); 1812 RefPtr view = frame->view(); 1813 auto startLocationForSyntheticMouseEvents = view->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->start)).absoluteCaretBounds()).center(); 1814 endLocationForSyntheticMouseEvents = view->contentsToRootView(VisiblePosition(makeDeprecatedLegacyPosition(wordRange->end)).absoluteCaretBounds()).center(); 1812 1815 dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startLocationForSyntheticMouseEvents); 1813 1816 dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endLocationForSyntheticMouseEvents); 1814 1817 } 1815 1818 1816 frame .selection().setSelectedRange(wordRange, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);1819 frame->selection().setSelectedRange(wordRange, position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 1817 1820 1818 1821 if (shouldDispatchMouseEvents) … … 1825 1828 return; 1826 1829 1827 auto frame = makeRef(m_page->focusController().focusedOrMainFrame()); 1828 auto startCaretRect = frame->view()->contentsToRootView(VisiblePosition(frame->selection().selection().start()).absoluteCaretBounds()); 1829 auto endCaretRect = frame->view()->contentsToRootView(VisiblePosition(frame->selection().selection().end()).absoluteCaretBounds()); 1830 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1831 RefPtr view = frame->view(); 1832 auto startCaretRect = view->contentsToRootView(VisiblePosition(frame->selection().selection().start()).absoluteCaretBounds()); 1833 auto endCaretRect = view->contentsToRootView(VisiblePosition(frame->selection().selection().end()).absoluteCaretBounds()); 1830 1834 dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Started, startCaretRect.center()); 1831 1835 dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch::Moved, endCaretRect.center()); … … 1835 1839 void WebPage::selectWordBackward() 1836 1840 { 1837 Frame& frame = m_page->focusController().focusedOrMainFrame();1838 if (!frame .selection().isCaret())1839 return; 1840 1841 auto position = frame .selection().selection().visibleStart();1841 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1842 if (!frame->selection().isCaret()) 1843 return; 1844 1845 auto position = frame->selection().selection().visibleStart(); 1842 1846 auto startPosition = positionOfNextBoundaryOfGranularity(position, TextGranularity::WordGranularity, SelectionDirection::Backward); 1843 1847 if (startPosition.isNull() || startPosition == position) 1844 1848 return; 1845 1849 1846 frame .selection().setSelectedRange(makeSimpleRange(startPosition, position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);1850 frame->selection().setSelectedRange(makeSimpleRange(startPosition, position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 1847 1851 } 1848 1852 1849 1853 void WebPage::moveSelectionByOffset(int32_t offset, CompletionHandler<void()>&& completionHandler) 1850 1854 { 1851 Frame& frame = m_page->focusController().focusedOrMainFrame();1855 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1852 1856 1853 VisiblePosition startPosition = frame .selection().selection().end();1857 VisiblePosition startPosition = frame->selection().selection().end(); 1854 1858 if (startPosition.isNull()) 1855 1859 return; … … 1862 1866 } 1863 1867 if (position.isNotNull() && startPosition != position) 1864 frame .selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);1868 frame->selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 1865 1869 completionHandler(); 1866 1870 } … … 1873 1877 } 1874 1878 1875 Frame& frame = m_page->focusController().focusedOrMainFrame();1876 auto& selection = frame .selection().selection();1879 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1880 auto& selection = frame->selection().selection(); 1877 1881 if (!selection.isRange()) 1878 1882 return; … … 1884 1888 return; 1885 1889 1886 m_page->mainFrame().eventHandler().startSelectionAutoscroll(renderer, positionInWindow);1890 Ref(m_page->mainFrame())->eventHandler().startSelectionAutoscroll(renderer, positionInWindow); 1887 1891 } 1888 1892 … … 1894 1898 void WebPage::requestEvasionRectsAboveSelection(CompletionHandler<void(const Vector<FloatRect>&)>&& reply) 1895 1899 { 1896 auto& frame = m_page->focusController().focusedOrMainFrame();1897 auto frameView = makeRefPtr(frame .view());1900 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 1901 auto frameView = makeRefPtr(frame->view()); 1898 1902 if (!frameView) { 1899 1903 reply({ }); … … 1901 1905 } 1902 1906 1903 auto & selection = frame.selection().selection();1907 auto selection = frame->selection().selection(); 1904 1908 if (selection.isNone()) { 1905 1909 reply({ }); … … 1920 1924 float scaleFactor = pageScaleFactor(); 1921 1925 const double factorOfContentArea = 0.5; 1922 auto unobscuredContentArea = m_page->mainFrame().view()->unobscuredContentRect().area();1926 auto unobscuredContentArea = RefPtr(m_page->mainFrame().view())->unobscuredContentRect().area(); 1923 1927 if (unobscuredContentArea.hasOverflowed()) { 1924 1928 reply({ }); … … 1932 1936 selectionBoundsInRootViewCoordinates = frameView->contentsToRootView(unionRect(RenderObject::absoluteTextRects(*selectedRange))); 1933 1937 else 1934 selectionBoundsInRootViewCoordinates = frameView->contentsToRootView(frame .selection().absoluteCaretBounds());1938 selectionBoundsInRootViewCoordinates = frameView->contentsToRootView(frame->selection().absoluteCaretBounds()); 1935 1939 1936 1940 auto centerOfTargetBounds = selectionBoundsInRootViewCoordinates.center(); … … 1939 1943 auto clickableNonEditableNode = [&] (const FloatPoint& locationInRootViewCoordinates) -> Node* { 1940 1944 FloatPoint adjustedPoint; 1941 auto* hitNode = m_page->mainFrame().nodeRespondingToClickEvents(locationInRootViewCoordinates, adjustedPoint);1945 auto* hitNode = Ref(m_page->mainFrame())->nodeRespondingToClickEvents(locationInRootViewCoordinates, adjustedPoint); 1942 1946 if (!hitNode || is<HTMLBodyElement>(hitNode) || is<Document>(hitNode) || hitNode->hasEditableStyle()) 1943 1947 return nullptr; … … 1995 1999 void WebPage::getRectsForGranularityWithSelectionOffset(WebCore::TextGranularity granularity, int32_t offset, CompletionHandler<void(const Vector<WebCore::SelectionGeometry>&)>&& completionHandler) 1996 2000 { 1997 Frame& frame = m_page->focusController().focusedOrMainFrame();1998 1999 auto selection = m_storedSelectionForAccessibility.isNone() ? frame .selection().selection() : m_storedSelectionForAccessibility;2001 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2002 2003 auto selection = m_storedSelectionForAccessibility.isNone() ? frame->selection().selection() : m_storedSelectionForAccessibility; 2000 2004 auto position = visiblePositionForPositionWithOffset(selection.visibleStart(), offset); 2001 2005 auto direction = offset < 0 ? SelectionDirection::Backward : SelectionDirection::Forward; … … 2007 2011 2008 2012 auto selectionGeometries = RenderObject::collectSelectionGeometriesWithoutUnionInteriorLines(*range); 2009 convertContentToRootView(*frame.view(), selectionGeometries); 2013 RefPtr view = frame->view(); 2014 convertContentToRootView(*view, selectionGeometries); 2010 2015 completionHandler(selectionGeometries); 2011 2016 } … … 2016 2021 m_storedSelectionForAccessibility = VisibleSelection(); 2017 2022 else { 2018 Frame& frame = m_page->focusController().focusedOrMainFrame();2023 Frame& frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2019 2024 m_storedSelectionForAccessibility = frame.selection().selection(); 2020 2025 } … … 2035 2040 void WebPage::getRectsAtSelectionOffsetWithText(int32_t offset, const String& text, CompletionHandler<void(const Vector<WebCore::SelectionGeometry>&)>&& completionHandler) 2036 2041 { 2037 Frame& frame = m_page->focusController().focusedOrMainFrame();2038 auto& selection = m_storedSelectionForAccessibility.isNone() ? frame .selection().selection() : m_storedSelectionForAccessibility;2042 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2043 auto& selection = m_storedSelectionForAccessibility.isNone() ? frame->selection().selection() : m_storedSelectionForAccessibility; 2039 2044 auto startPosition = visiblePositionForPositionWithOffset(selection.visibleStart(), offset); 2040 2045 auto range = makeSimpleRange(startPosition, visiblePositionForPositionWithOffset(startPosition, text.length())); … … 2053 2058 2054 2059 auto selectionGeometries = RenderObject::collectSelectionGeometriesWithoutUnionInteriorLines(*range); 2055 convertContentToRootView(*frame.view(), selectionGeometries); 2060 RefPtr view = frame->view(); 2061 convertContentToRootView(*view, selectionGeometries); 2056 2062 completionHandler(selectionGeometries); 2057 2063 } … … 2070 2076 setFocusedFrameBeforeSelectingTextAtLocation(point); 2071 2077 2072 auto& frame = m_page->focusController().focusedOrMainFrame();2078 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2073 2079 VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement); 2074 2080 2075 2081 if (position.isNotNull()) 2076 frame .selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);2082 frame->selection().setSelectedRange(makeSimpleRange(position), position.affinity(), WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 2077 2083 completionHandler(); 2078 2084 } … … 2080 2086 void WebPage::selectPositionAtBoundaryWithDirection(const WebCore::IntPoint& point, WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, bool isInteractingWithFocusedElement, CompletionHandler<void()>&& completionHandler) 2081 2087 { 2082 auto& frame = m_page->focusController().focusedOrMainFrame();2088 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2083 2089 VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement); 2084 2090 … … 2086 2092 position = positionOfNextBoundaryOfGranularity(position, granularity, direction); 2087 2093 if (position.isNotNull()) 2088 frame .selection().setSelectedRange(makeSimpleRange(position), Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);2094 frame->selection().setSelectedRange(makeSimpleRange(position), Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 2089 2095 } 2090 2096 completionHandler(); … … 2093 2099 void WebPage::moveSelectionAtBoundaryWithDirection(WebCore::TextGranularity granularity, WebCore::SelectionDirection direction, CompletionHandler<void()>&& completionHandler) 2094 2100 { 2095 Frame& frame = m_page->focusController().focusedOrMainFrame();2096 2097 if (!frame .selection().selection().isNone()) {2101 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2102 2103 if (!frame->selection().selection().isNone()) { 2098 2104 bool isForward = (direction == SelectionDirection::Forward || direction == SelectionDirection::Right); 2099 VisiblePosition position = (isForward) ? frame .selection().selection().visibleEnd() : frame.selection().selection().visibleStart();2105 VisiblePosition position = (isForward) ? frame->selection().selection().visibleEnd() : frame->selection().selection().visibleStart(); 2100 2106 position = positionOfNextBoundaryOfGranularity(position, granularity, direction); 2101 2107 if (position.isNotNull()) 2102 frame .selection().setSelectedRange(makeSimpleRange(position), isForward? Affinity::Upstream : Affinity::Downstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);2108 frame->selection().setSelectedRange(makeSimpleRange(position), isForward? Affinity::Upstream : Affinity::Downstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 2103 2109 } 2104 2110 completionHandler(); … … 2149 2155 { 2150 2156 constexpr OptionSet<HitTestRequest::Type> hitType { HitTestRequest::Type::ReadOnly, HitTestRequest::Type::Active, HitTestRequest::Type::AllowVisibleChildFrameContentOnly }; 2151 auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(point, hitType);2157 auto result = Ref(m_page->mainFrame())->eventHandler().hitTestResultAtPoint(point, hitType); 2152 2158 auto* hitNode = result.innerNode(); 2153 if (hitNode && hitNode->renderer()) 2154 m_page->focusController().setFocusedFrame(result.innerNodeFrame()); 2159 if (hitNode && hitNode->renderer()) { 2160 RefPtr frame = result.innerNodeFrame(); 2161 CheckedRef(m_page->focusController())->setFocusedFrame(frame.get()); 2162 } 2155 2163 } 2156 2164 … … 2159 2167 setFocusedFrameBeforeSelectingTextAtLocation(point); 2160 2168 2161 auto& frame = m_page->focusController().focusedOrMainFrame();2169 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2162 2170 auto range = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement); 2163 2171 if (range) 2164 frame .selection().setSelectedRange(*range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);2172 frame->selection().setSelectedRange(*range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 2165 2173 m_initialSelection = range; 2166 2174 } … … 2198 2206 void WebPage::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint& point, WebCore::TextGranularity granularity, bool isInteractingWithFocusedElement, CompletionHandler<void(bool)>&& callback) 2199 2207 { 2200 auto& frame = m_page->focusController().focusedOrMainFrame();2208 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2201 2209 auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement); 2202 2210 auto newRange = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement); … … 2216 2224 2217 2225 if (auto range = makeSimpleRange(selectionStart, selectionEnd)) 2218 frame .selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);2226 frame->selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 2219 2227 2220 2228 callback(selectionStart == initialSelectionStartPosition); … … 2223 2231 void WebPage::updateSelectionWithExtentPoint(const WebCore::IntPoint& point, bool isInteractingWithFocusedElement, RespectSelectionAnchor respectSelectionAnchor, CompletionHandler<void(bool)>&& callback) 2224 2232 { 2225 auto& frame = m_page->focusController().focusedOrMainFrame();2233 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2226 2234 auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement); 2227 2235 … … 2234 2242 if (respectSelectionAnchor == RespectSelectionAnchor::Yes) { 2235 2243 if (m_selectionAnchor == Start) { 2236 selectionStart = frame .selection().selection().visibleStart();2244 selectionStart = frame->selection().selection().visibleStart(); 2237 2245 selectionEnd = position; 2238 2246 if (position <= selectionStart) { 2239 2247 selectionStart = selectionStart.previous(); 2240 selectionEnd = frame .selection().selection().visibleEnd();2248 selectionEnd = frame->selection().selection().visibleEnd(); 2241 2249 m_selectionAnchor = End; 2242 2250 } 2243 2251 } else { 2244 2252 selectionStart = position; 2245 selectionEnd = frame .selection().selection().visibleEnd();2253 selectionEnd = frame->selection().selection().visibleEnd(); 2246 2254 if (position >= selectionEnd) { 2247 selectionStart = frame .selection().selection().visibleStart();2255 selectionStart = frame->selection().selection().visibleStart(); 2248 2256 selectionEnd = selectionEnd.next(); 2249 2257 m_selectionAnchor = Start; … … 2251 2259 } 2252 2260 } else { 2253 auto currentStart = frame .selection().selection().visibleStart();2254 auto currentEnd = frame .selection().selection().visibleEnd();2261 auto currentStart = frame->selection().selection().visibleStart(); 2262 auto currentEnd = frame->selection().selection().visibleEnd(); 2255 2263 if (position <= currentStart) { 2256 2264 selectionStart = position; … … 2263 2271 2264 2272 if (auto range = makeSimpleRange(selectionStart, selectionEnd)) 2265 frame .selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);2273 frame->selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered); 2266 2274 2267 2275 callback(m_selectionAnchor == Start); … … 2270 2278 void WebPage::requestDictationContext(CompletionHandler<void(const String&, const String&, const String&)>&& completionHandler) 2271 2279 { 2272 Frame& frame = m_page->focusController().focusedOrMainFrame();2273 VisiblePosition startPosition = frame .selection().selection().start();2274 VisiblePosition endPosition = frame .selection().selection().end();2280 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2281 VisiblePosition startPosition = frame->selection().selection().start(); 2282 VisiblePosition endPosition = frame->selection().selection().end(); 2275 2283 const unsigned dictationContextWordCount = 5; 2276 2284 2277 String selectedText = plainTextForContext(frame .selection().selection().toNormalizedRange());2285 String selectedText = plainTextForContext(frame->selection().selection().toNormalizedRange()); 2278 2286 2279 2287 String contextBefore; … … 2308 2316 void WebPage::replaceSelectedText(const String& oldText, const String& newText) 2309 2317 { 2310 Frame& frame = m_page->focusController().focusedOrMainFrame(); 2311 auto wordRange = frame.selection().isCaret() 2312 ? wordRangeFromPosition(frame.selection().selection().start()) 2313 : frame.selection().selection().toNormalizedRange(); 2318 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2319 auto wordRange = frame->selection().isCaret() ? wordRangeFromPosition(frame->selection().selection().start()) : frame->selection().selection().toNormalizedRange(); 2314 2320 if (plainTextForContext(wordRange) != oldText) 2315 2321 return; 2316 frame .editor().setIgnoreSelectionChanges(true);2317 frame .selection().setSelectedRange(wordRange, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes);2318 frame .editor().insertText(newText, 0);2319 frame .editor().setIgnoreSelectionChanges(false);2322 frame->editor().setIgnoreSelectionChanges(true); 2323 frame->selection().setSelectedRange(wordRange, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes); 2324 frame->editor().insertText(newText, 0); 2325 frame->editor().setIgnoreSelectionChanges(false); 2320 2326 } 2321 2327 2322 2328 void WebPage::replaceDictatedText(const String& oldText, const String& newText) 2323 2329 { 2324 Frame& frame = m_page->focusController().focusedOrMainFrame();2325 if (frame .selection().isNone())2330 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2331 if (frame->selection().isNone()) 2326 2332 return; 2327 2333 2328 if (frame .selection().isRange()) {2329 frame .editor().deleteSelectionWithSmartDelete(false);2330 return; 2331 } 2332 VisiblePosition position = frame .selection().selection().start();2334 if (frame->selection().isRange()) { 2335 frame->editor().deleteSelectionWithSmartDelete(false); 2336 return; 2337 } 2338 VisiblePosition position = frame->selection().selection().start(); 2333 2339 for (size_t i = 0; i < oldText.length(); ++i) 2334 2340 position = position.previous(); 2335 2341 if (position.isNull()) 2336 position = startOfDocument(frame .document());2337 auto range = makeSimpleRange(position, frame .selection().selection().start());2342 position = startOfDocument(frame->document()); 2343 auto range = makeSimpleRange(position, frame->selection().selection().start()); 2338 2344 2339 2345 if (plainTextForContext(range) != oldText) … … 2341 2347 2342 2348 // We don't want to notify the client that the selection has changed until we are done inserting the new text. 2343 frame .editor().setIgnoreSelectionChanges(true);2344 frame .selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes);2345 frame .editor().insertText(newText, 0);2346 frame .editor().setIgnoreSelectionChanges(false);2349 frame->editor().setIgnoreSelectionChanges(true); 2350 frame->selection().setSelectedRange(range, Affinity::Upstream, WebCore::FrameSelection::ShouldCloseTyping::Yes); 2351 frame->editor().insertText(newText, 0); 2352 frame->editor().setIgnoreSelectionChanges(false); 2347 2353 } 2348 2354 2349 2355 void WebPage::requestAutocorrectionData(const String& textForAutocorrection, CompletionHandler<void(WebAutocorrectionData)>&& reply) 2350 2356 { 2351 auto& frame = m_page->focusController().focusedOrMainFrame();2352 if (!frame .selection().isCaret()) {2357 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2358 if (!frame->selection().isCaret()) { 2353 2359 reply({ }); 2354 2360 return; 2355 2361 } 2356 2362 2357 auto range = wordRangeFromPosition(frame .selection().selection().visibleStart());2363 auto range = wordRangeFromPosition(frame->selection().selection().visibleStart()); 2358 2364 if (!range) { 2359 2365 reply({ }); … … 2376 2382 2377 2383 auto rootViewSelectionRects = selectionGeometries.map([&](const auto& selectionGeometry) -> FloatRect { 2378 return frame .view()->contentsToRootView(selectionGeometry.rect());2384 return frame->view()->contentsToRootView(selectionGeometry.rect()); 2379 2385 }); 2380 2386 2381 2387 bool multipleFonts = false; 2382 2388 CTFontRef font = nil; 2383 if (auto coreFont = frame .editor().fontForSelection(multipleFonts))2389 if (auto coreFont = frame->editor().fontForSelection(multipleFonts)) 2384 2390 font = coreFont->getCTFont(); 2385 2391 … … 2417 2423 bool WebPage::applyAutocorrectionInternal(const String& correction, const String& originalText) 2418 2424 { 2419 auto& frame = m_page->focusController().focusedOrMainFrame();2420 if (!frame .selection().isCaretOrRange())2425 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2426 if (!frame->selection().isCaretOrRange()) 2421 2427 return false; 2422 2428 … … 2425 2431 auto originalTextWithFoldedQuoteMarks = foldQuoteMarks(originalText); 2426 2432 2427 if (frame .selection().isCaret()) {2428 auto position = frame .selection().selection().visibleStart();2433 if (frame->selection().isCaret()) { 2434 auto position = frame->selection().selection().visibleStart(); 2429 2435 range = wordRangeFromPosition(position); 2430 2436 textForRange = plainTextForContext(range); … … 2437 2443 position = position.previous(); 2438 2444 if (position.isNull()) 2439 position = startOfDocument(frame .document());2440 range = makeSimpleRange(position, frame .selection().selection().start());2445 position = startOfDocument(frame->document()); 2446 range = makeSimpleRange(position, frame->selection().selection().start()); 2441 2447 textForRange = plainTextForContext(range); 2442 2448 unsigned loopCount = 0; … … 2444 2450 while (textForRange.length() && textForRange.length() > originalText.length() && loopCount < maxPositionsAttempts) { 2445 2451 position = position.next(); 2446 if (position.isNotNull() && position >= frame .selection().selection().start())2452 if (position.isNotNull() && position >= frame->selection().selection().start()) 2447 2453 range = std::nullopt; 2448 2454 else 2449 range = makeSimpleRange(position, frame .selection().selection().start());2455 range = makeSimpleRange(position, frame->selection().selection().start()); 2450 2456 textForRange = plainTextForContext(range); 2451 2457 loopCount++; … … 2460 2466 } else { 2461 2467 // Range selection. 2462 range = frame .selection().selection().toNormalizedRange();2468 range = frame->selection().selection().toNormalizedRange(); 2463 2469 if (!range) 2464 2470 return false; … … 2475 2481 affinity = VisiblePosition(makeDeprecatedLegacyPosition(range->start), Affinity::Upstream).affinity(); 2476 2482 2477 frame .selection().setSelectedRange(range, affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes);2483 frame->selection().setSelectedRange(range, affinity, WebCore::FrameSelection::ShouldCloseTyping::Yes); 2478 2484 if (correction.length()) 2479 frame .editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion);2485 frame->editor().insertText(correction, 0, originalText.isEmpty() ? TextEventInputKeyboard : TextEventInputAutocompletion); 2480 2486 else if (originalText.length()) 2481 frame .editor().deleteWithDirection(SelectionDirection::Backward, TextGranularity::CharacterGranularity, false, true);2487 frame->editor().deleteWithDirection(SelectionDirection::Backward, TextGranularity::CharacterGranularity, false, true); 2482 2488 return true; 2483 2489 } … … 2491 2497 EditingRange markedTextRange; 2492 2498 2493 auto& frame = m_page->focusController().focusedOrMainFrame();2494 VisiblePosition startPosition = frame .selection().selection().start();2495 VisiblePosition endPosition = frame .selection().selection().end();2499 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 2500 VisiblePosition startPosition = frame->selection().selection().start(); 2501 VisiblePosition endPosition = frame->selection().selection().end(); 2496 2502 const unsigned minContextWordCount = 3; 2497 2503 const unsigned minContextLenght = 12; 2498 2504 const unsigned maxContextLength = 30; 2499 2505 2500 if (frame .selection().isRange())2501 selectedText = plainTextForContext(frame .selection().selection().toNormalizedRange());2502 2503 if (auto compositionRange = frame .editor().compositionRange()) {2506 if (frame->selection().isRange()) 2507 selectedText = plainTextForContext(frame->selection().selection().toNormalizedRange()); 2508 2509 if (auto compositionRange = frame->editor().compositionRange()) { 2504 2510 auto markedTextBefore = plainTextForContext(makeSimpleRange(compositionRange->start, startPosition)); 2505 2511 auto markedTextAfter = plainTextForContext(makeSimpleRange(endPosition, compositionRange->end)); … … 2637 2643 static void focusedElementPositionInformation(WebPage& page, Element& focusedElement, const InteractionInformationRequest& request, InteractionInformationAtPosition& info) 2638 2644 { 2639 const Frame& frame = page.corePage()->focusController().focusedOrMainFrame();2640 if (!frame .editor().hasComposition())2645 Ref frame = CheckedRef(page.corePage()->focusController())->focusedOrMainFrame(); 2646 if (!frame->editor().hasComposition()) 2641 2647 return; 2642 2648 2643 2649 const uint32_t kHitAreaWidth = 66; 2644 2650 const uint32_t kHitAreaHeight = 66; 2645 FrameView& view = *frame.view();2646 IntPoint adjustedPoint(view .rootViewToContents(request.point));2651 Ref view = *frame->view(); 2652 IntPoint adjustedPoint(view->rootViewToContents(request.point)); 2647 2653 IntPoint constrainedPoint = constrainPoint(adjustedPoint, frame, focusedElement); 2648 VisiblePosition position = frame .visiblePositionForPoint(constrainedPoint);2649 2650 auto compositionRange = frame .editor().compositionRange();2654 VisiblePosition position = frame->visiblePositionForPoint(constrainedPoint); 2655 2656 auto compositionRange = frame->editor().compositionRange(); 2651 2657 if (!compositionRange) 2652 2658 return; … … 2658 2664 else if (position > endPosition) 2659 2665 position = endPosition; 2660 IntRect caretRect = view .contentsToRootView(position.absoluteCaretBounds());2666 IntRect caretRect = view->contentsToRootView(position.absoluteCaretBounds()); 2661 2667 float deltaX = abs(caretRect.x() + (caretRect.width() / 2) - request.point.x()); 2662 2668 float deltaYFromTheTop = abs(caretRect.y() - request.point.y()); … … 3146 3152 } 3147 3153 3148 static inline Element*nextAssistableElement(Node* startNode, Page& page, bool isForward)3154 static inline RefPtr<Element> nextAssistableElement(Node* startNode, Page& page, bool isForward) 3149 3155 { 3150 3156 if (!is<Element>(startNode)) 3151 3157 return nullptr; 3152 3158 3153 Element* nextElement = downcast<Element>(startNode); 3159 RefPtr nextElement = downcast<Element>(startNode); 3160 CheckedRef focusController { page.focusController() }; 3154 3161 do { 3155 nextElement = isForward 3156 ? page.focusController().nextFocusableElement(*nextElement) 3157 : page.focusController().previousFocusableElement(*nextElement); 3162 nextElement = isForward ? focusController->nextFocusableElement(*nextElement) : focusController->previousFocusableElement(*nextElement); 3158 3163 } while (nextElement && (!isAssistableElement(*nextElement) || isObscuredElement(*nextElement))); 3159 3164 … … 3163 3168 void WebPage::focusNextFocusedElement(bool isForward, CompletionHandler<void()>&& completionHandler) 3164 3169 { 3165 Element*nextElement = nextAssistableElement(m_focusedElement.get(), *m_page, isForward);3170 auto nextElement = nextAssistableElement(m_focusedElement.get(), *m_page, isForward); 3166 3171 m_userIsInteracting = true; 3167 3172 if (nextElement) … … 3173 3178 std::optional<FocusedElementInformation> WebPage::focusedElementInformation() 3174 3179 { 3175 RefPtr<Document> document = m_page->focusController().focusedOrMainFrame().document();3180 RefPtr<Document> document = CheckedRef(m_page->focusController())->focusedOrMainFrame().document(); 3176 3181 if (!document || !document->view()) 3177 3182 return std::nullopt; … … 3219 3224 information.allowsUserScaling = m_viewportConfiguration.allowsUserScaling(); 3220 3225 information.allowsUserScalingIgnoringAlwaysScalable = m_viewportConfiguration.allowsUserScalingIgnoringAlwaysScalable(); 3221 if (auto *nextElement = nextAssistableElement(focusedElement.get(), *m_page, true)) {3226 if (auto nextElement = nextAssistableElement(focusedElement.get(), *m_page, true)) { 3222 3227 information.nextNodeRect = rootViewBounds(*nextElement); 3223 3228 information.hasNextNode = true; 3224 3229 } 3225 if (auto *previousElement = nextAssistableElement(focusedElement.get(), *m_page, false)) {3230 if (auto previousElement = nextAssistableElement(focusedElement.get(), *m_page, false)) { 3226 3231 information.previousNodeRect = rootViewBounds(*previousElement); 3227 3232 information.hasPreviousNode = true; … … 4247 4252 m_keyboardIsAttached = keyboardIsAttached; 4248 4253 4249 if ( auto* focusedFrame = m_page->focusController().focusedFrame())4254 if (RefPtr focusedFrame = CheckedRef(m_page->focusController())->focusedFrame()) 4250 4255 focusedFrame->eventHandler().capsLockStateMayHaveChanged(); 4251 4256 } … … 4268 4273 { 4269 4274 // Inserting the placeholder may run JavaScript, which can do anything, including frame destruction. 4270 Ref<Frame> frame = corePage()->focusController().focusedOrMainFrame();4275 Ref<Frame> frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4271 4276 auto placeholder = frame->editor().insertTextPlaceholder(size); 4272 4277 completionHandler(placeholder ? contextForElement(*placeholder) : std::nullopt); … … 4285 4290 void WebPage::updateSelectionWithDelta(int64_t locationDelta, int64_t lengthDelta, CompletionHandler<void()>&& completionHandler) 4286 4291 { 4287 auto frame = makeRef(corePage()->focusController().focusedOrMainFrame());4292 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4288 4293 auto root = makeRefPtr(frame->selection().rootEditableElementOrDocumentElement()); 4289 4294 auto selectionRange = frame->selection().selection().toNormalizedRange(); … … 4367 4372 } 4368 4373 4369 m_page->focusController().focusedOrMainFrame().document()->updateLayoutIgnorePendingStylesheets();4370 4371 Ref<Frame> frame = m_page->focusController().focusedOrMainFrame(); 4374 Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame(); 4375 makeRefPtr(frame->document())->updateLayoutIgnorePendingStylesheets(); 4376 4372 4377 VisibleSelection selection = frame->selection().selection(); 4373 4378 … … 4557 4562 UserGestureIndicator gestureIndicator { ProcessingUserGesture, &target->document() }; 4558 4563 SetForScope<bool> userIsInteractingChange { m_userIsInteracting, true }; 4559 m_page->focusController().setFocusedElement(target.get(), targetFrame);4564 CheckedRef(m_page->focusController())->setFocusedElement(target.get(), targetFrame); 4560 4565 4561 4566 // Setting the focused element could tear down the element's renderer. Check that we still have one. … … 4617 4622 void WebPage::animationDidFinishForElement(const WebCore::Element& animatedElement) 4618 4623 { 4619 auto frame = makeRef(m_page->focusController().focusedOrMainFrame());4624 Ref frame = makeRef(CheckedRef(m_page->focusController())->focusedOrMainFrame()); 4620 4625 auto& selection = frame->selection().selection(); 4621 4626 if (selection.isNoneOrOrphaned())
Note:
See TracChangeset
for help on using the changeset viewer.