Changeset 294846 in webkit
- Timestamp:
- May 25, 2022, 4:50:02 PM (4 years ago)
- Location:
- branches/safari-613-branch/Source/WebCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
page/AutoscrollController.cpp (modified) (13 diffs)
-
page/AutoscrollController.h (modified) (2 diffs)
-
page/EventHandler.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-613-branch/Source/WebCore/ChangeLog
r294845 r294846 1 2022-05-19 Alan Coon <alancoon@apple.com> 2 3 Cherry-pick r293094. rdar://problem/91683009 4 5 Some AutoscrollController cleanup 6 https://bugs.webkit.org/show_bug.cgi?id=239512 7 8 Reviewed by Alan Bujtas. 9 10 Have AutoscrollController store a WeakPtr to the render object. Address an apparent 11 null de-ref in AutoscrollController::stopAutoscrollTimer() where the Frame can null. 12 13 Refactor updateDragAndDrop() with a lambda so that all the code paths that exit early 14 clearly call stopAutoscrollTimer() which nulls out the renderer. 15 16 * page/AutoscrollController.cpp: 17 (WebCore::AutoscrollController::autoscrollRenderer const): 18 (WebCore::AutoscrollController::startAutoscrollForSelection): 19 (WebCore::AutoscrollController::stopAutoscrollTimer): 20 (WebCore::AutoscrollController::updateAutoscrollRenderer): 21 (WebCore::AutoscrollController::updateDragAndDrop): 22 (WebCore::AutoscrollController::startPanScrolling): 23 * page/AutoscrollController.h: 24 * page/EventHandler.cpp: 25 (WebCore::EventHandler::startPanScrolling): 26 27 Canonical link: https://commits.webkit.org/249805@main 28 git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293094 268f45cc-cd09-0410-ab3c-d52691b4dbfc 29 30 2022-04-20 Simon Fraser <simon.fraser@apple.com> 31 32 Some AutoscrollController cleanup 33 https://bugs.webkit.org/show_bug.cgi?id=239512 34 35 Reviewed by Alan Bujtas. 36 37 Have AutoscrollController store a WeakPtr to the render object. Address an apparent 38 null de-ref in AutoscrollController::stopAutoscrollTimer() where the Frame can null. 39 40 Refactor updateDragAndDrop() with a lambda so that all the code paths that exit early 41 clearly call stopAutoscrollTimer() which nulls out the renderer. 42 43 * page/AutoscrollController.cpp: 44 (WebCore::AutoscrollController::autoscrollRenderer const): 45 (WebCore::AutoscrollController::startAutoscrollForSelection): 46 (WebCore::AutoscrollController::stopAutoscrollTimer): 47 (WebCore::AutoscrollController::updateAutoscrollRenderer): 48 (WebCore::AutoscrollController::updateDragAndDrop): 49 (WebCore::AutoscrollController::startPanScrolling): 50 * page/AutoscrollController.h: 51 * page/EventHandler.cpp: 52 (WebCore::EventHandler::startPanScrolling): 53 1 54 2022-05-19 Alan Coon <alancoon@apple.com> 2 55 -
branches/safari-613-branch/Source/WebCore/page/AutoscrollController.cpp
r277295 r294846 57 57 AutoscrollController::AutoscrollController() 58 58 : m_autoscrollTimer(*this, &AutoscrollController::autoscrollTimerFired) 59 , m_autoscrollRenderer(nullptr)60 , m_autoscrollType(NoAutoscroll)61 59 { 62 60 } … … 64 62 RenderBox* AutoscrollController::autoscrollRenderer() const 65 63 { 66 return m_autoscrollRenderer ;64 return m_autoscrollRenderer.get(); 67 65 } 68 66 … … 77 75 if (m_autoscrollTimer.isActive()) 78 76 return; 79 RenderBox* scrollable = RenderBox::findAutoscrollable(renderer);77 auto* scrollable = RenderBox::findAutoscrollable(renderer); 80 78 if (!scrollable) 81 79 return; 82 80 m_autoscrollType = AutoscrollForSelection; 83 m_autoscrollRenderer = scrollable;81 m_autoscrollRenderer = WeakPtr { *scrollable }; 84 82 startAutoscrollTimer(); 85 83 } … … 87 85 void AutoscrollController::stopAutoscrollTimer(bool rendererIsBeingDestroyed) 88 86 { 89 RenderBox* scrollable = m_autoscrollRenderer; 87 auto scrollable = m_autoscrollRenderer; 88 90 89 m_autoscrollTimer.stop(); 91 90 m_autoscrollRenderer = nullptr; … … 94 93 return; 95 94 96 Frame& frame = scrollable->frame();97 if (autoscrollInProgress() && frame .eventHandler().mouseDownWasInSubframe()) {98 if (auto subframe = frame .eventHandler().subframeForTargetNode(frame.eventHandler().mousePressNode()))95 auto* frame = scrollable->document().frame(); 96 if (autoscrollInProgress() && frame && frame->eventHandler().mouseDownWasInSubframe()) { 97 if (auto subframe = frame->eventHandler().subframeForTargetNode(frame->eventHandler().mousePressNode())) 99 98 subframe->eventHandler().stopAutoscrollTimer(rendererIsBeingDestroyed); 100 99 return; … … 103 102 if (!rendererIsBeingDestroyed) 104 103 scrollable->stopAutoscroll(); 104 105 105 #if ENABLE(PAN_SCROLLING) 106 106 if (panScrollInProgress()) { … … 115 115 #if ENABLE(PAN_SCROLLING) 116 116 // If we're not in the top frame we notify it that we are not doing a panScroll any more. 117 if ( !frame.isMainFrame())118 frame .mainFrame().eventHandler().didPanScrollStop();117 if (frame && !frame->isMainFrame()) 118 frame->mainFrame().eventHandler().didPanScrollStop(); 119 119 #endif 120 120 } … … 125 125 return; 126 126 127 RenderObject* renderer = m_autoscrollRenderer ;127 RenderObject* renderer = m_autoscrollRenderer.get(); 128 128 129 129 #if ENABLE(PAN_SCROLLING) … … 131 131 HitTestResult hitTest = m_autoscrollRenderer->frame().eventHandler().hitTestResultAtPoint(m_panScrollStartPos, hitType); 132 132 133 if ( Node* nodeAtPoint = hitTest.innerNode())133 if (auto* nodeAtPoint = hitTest.innerNode()) 134 134 renderer = nodeAtPoint->renderer(); 135 135 #endif … … 137 137 while (renderer && !(is<RenderBox>(*renderer) && downcast<RenderBox>(*renderer).canAutoscroll())) 138 138 renderer = renderer->parent(); 139 m_autoscrollRenderer = is<RenderBox>(renderer) ? downcast<RenderBox>(renderer) : nullptr; 139 140 if (!is<RenderBox>(renderer)) { 141 m_autoscrollRenderer = nullptr; 142 return; 143 } 144 145 m_autoscrollRenderer = WeakPtr { downcast<RenderBox>(*renderer) }; 140 146 } 141 147 142 148 void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoint& eventPosition, WallTime eventTime) 143 149 { 144 if (!dropTargetNode) { 145 stopAutoscrollTimer(); 146 return; 147 } 148 149 RenderBox* scrollable = RenderBox::findAutoscrollable(dropTargetNode->renderer()); 150 IntSize offset; 151 auto findDragAndDropScroller = [&]() -> RenderBox* { 152 if (!dropTargetNode) 153 return nullptr; 154 155 auto* scrollable = RenderBox::findAutoscrollable(dropTargetNode->renderer()); 156 if (!scrollable) 157 return nullptr; 158 159 auto& frame = scrollable->frame(); 160 auto* page = frame.page(); 161 if (!page || !page->settings().autoscrollForDragAndDropEnabled()) 162 return nullptr; 163 164 offset = scrollable->calculateAutoscrollDirection(eventPosition); 165 if (offset.isZero()) 166 return nullptr; 167 168 return scrollable; 169 }; 170 171 RenderBox* scrollable = findDragAndDropScroller(); 150 172 if (!scrollable) { 151 173 stopAutoscrollTimer(); … … 153 175 } 154 176 155 Frame& frame = scrollable->frame();156 157 Page* page = frame.page();158 if (!page || !page->settings().autoscrollForDragAndDropEnabled()) {159 stopAutoscrollTimer();160 return;161 }162 163 IntSize offset = scrollable->calculateAutoscrollDirection(eventPosition);164 if (offset.isZero()) {165 stopAutoscrollTimer();166 return;167 }168 169 177 m_dragAndDropAutoscrollReferencePosition = eventPosition + offset; 170 178 171 179 if (m_autoscrollType == NoAutoscroll) { 172 180 m_autoscrollType = AutoscrollForDragAndDrop; 173 m_autoscrollRenderer = scrollable;181 m_autoscrollRenderer = WeakPtr { *scrollable }; 174 182 m_dragAndDropAutoscrollStartTime = eventTime; 175 183 startAutoscrollTimer(); 176 184 } else if (m_autoscrollRenderer != scrollable) { 177 185 m_dragAndDropAutoscrollStartTime = eventTime; 178 m_autoscrollRenderer = scrollable;186 m_autoscrollRenderer = WeakPtr { *scrollable }; 179 187 } 180 188 } … … 211 219 } 212 220 213 void AutoscrollController::startPanScrolling(RenderBox *scrollable, const IntPoint& lastKnownMousePosition)221 void AutoscrollController::startPanScrolling(RenderBox& scrollable, const IntPoint& lastKnownMousePosition) 214 222 { 215 223 // We don't want to trigger the autoscroll or the panScroll if it's already active … … 218 226 219 227 m_autoscrollType = AutoscrollForPan; 220 m_autoscrollRenderer = scrollable;228 m_autoscrollRenderer = WeakPtr { scrollable }; 221 229 m_panScrollStartPos = lastKnownMousePosition; 222 230 223 if ( FrameView* view = scrollable->frame().view())231 if (auto* view = scrollable.frame().view()) 224 232 view->addPanScrollIcon(lastKnownMousePosition); 225 scrollable->frame().eventHandler().didPanScrollStart(); 233 234 scrollable.frame().eventHandler().didPanScrollStart(); 226 235 startAutoscrollTimer(); 227 236 } -
branches/safari-613-branch/Source/WebCore/page/AutoscrollController.h
r222392 r294846 67 67 void handleMouseReleaseEvent(const PlatformMouseEvent&); 68 68 void setPanScrollInProgress(bool); 69 void startPanScrolling(RenderBox *, const IntPoint&);69 void startPanScrolling(RenderBox&, const IntPoint&); 70 70 #endif 71 71 … … 78 78 79 79 Timer m_autoscrollTimer; 80 RenderBox*m_autoscrollRenderer;81 AutoscrollType m_autoscrollType ;80 WeakPtr<RenderBox> m_autoscrollRenderer; 81 AutoscrollType m_autoscrollType { NoAutoscroll }; 82 82 IntPoint m_dragAndDropAutoscrollReferencePosition; 83 83 WallTime m_dragAndDropAutoscrollStartTime; -
branches/safari-613-branch/Source/WebCore/page/EventHandler.cpp
r292987 r294846 1126 1126 void EventHandler::startPanScrolling(RenderElement& renderer) 1127 1127 { 1128 #if !PLATFORM(IOS_FAMILY)1129 1128 if (!is<RenderBox>(renderer)) 1130 1129 return; 1131 m_autoscrollController->startPanScrolling( &downcast<RenderBox>(renderer), lastKnownMousePosition());1130 m_autoscrollController->startPanScrolling(downcast<RenderBox>(renderer), lastKnownMousePosition()); 1132 1131 invalidateClick(); 1133 #endif1134 1132 } 1135 1133
Note:
See TracChangeset
for help on using the changeset viewer.