Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: third_party/WebKit/Source/core/page/AutoscrollController.cpp

Issue 2289213002: Implement Middle Click Autoscroll on all platforms not just Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' of https://chromium.googlesource.com/chromium/src into panscroll Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 5 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return m_autoscrollType == AutoscrollForSelection; 67 return m_autoscrollType == AutoscrollForSelection;
68 } 68 }
69 69
70 bool AutoscrollController::autoscrollInProgress(const LayoutBox* layoutObject) c onst 70 bool AutoscrollController::autoscrollInProgress(const LayoutBox* layoutObject) c onst
71 { 71 {
72 return m_autoscrollLayoutObject == layoutObject; 72 return m_autoscrollLayoutObject == layoutObject;
73 } 73 }
74 74
75 void AutoscrollController::startAutoscrollForSelection(LayoutObject* layoutObjec t) 75 void AutoscrollController::startAutoscrollForSelection(LayoutObject* layoutObjec t)
76 { 76 {
77 // We don't want to trigger the autoscroll or the panScroll if it's already active 77 // We don't want to trigger the autoscroll or the middleClickAutoscroll if i t's already active
78 if (m_autoscrollType != NoAutoscroll) 78 if (m_autoscrollType != NoAutoscroll)
79 return; 79 return;
80 LayoutBox* scrollable = LayoutBox::findAutoscrollable(layoutObject); 80 LayoutBox* scrollable = LayoutBox::findAutoscrollable(layoutObject);
81 if (!scrollable) 81 if (!scrollable)
82 scrollable = layoutObject->isListBox() ? toLayoutListBox(layoutObject) : nullptr; 82 scrollable = layoutObject->isListBox() ? toLayoutListBox(layoutObject) : nullptr;
83 if (!scrollable) 83 if (!scrollable)
84 return; 84 return;
85 85
86 m_pressedLayoutObject = layoutObject && layoutObject->isBox() ? toLayoutBox( layoutObject) : nullptr; 86 m_pressedLayoutObject = layoutObject && layoutObject->isBox() ? toLayoutBox( layoutObject) : nullptr;
87 m_autoscrollType = AutoscrollForSelection; 87 m_autoscrollType = AutoscrollForSelection;
88 m_autoscrollLayoutObject = scrollable; 88 m_autoscrollLayoutObject = scrollable;
89 startAutoscroll(); 89 startAutoscroll();
90 } 90 }
91 91
92 void AutoscrollController::stopAutoscroll() 92 void AutoscrollController::stopAutoscroll()
93 { 93 {
94 if (m_pressedLayoutObject) { 94 if (m_pressedLayoutObject) {
95 m_pressedLayoutObject->stopAutoscroll(); 95 m_pressedLayoutObject->stopAutoscroll();
96 m_pressedLayoutObject = nullptr; 96 m_pressedLayoutObject = nullptr;
97 } 97 }
98 LayoutBox* scrollable = m_autoscrollLayoutObject; 98 LayoutBox* scrollable = m_autoscrollLayoutObject;
99 m_autoscrollLayoutObject = nullptr; 99 m_autoscrollLayoutObject = nullptr;
100 100
101 if (!scrollable) 101 if (!scrollable)
102 return; 102 return;
103 103
104 #if OS(WIN) 104 if (RuntimeEnabledFeatures::middleClickAutoscrollEnabled() && middleClickAut oscrollInProgress()) {
105 if (panScrollInProgress()) {
106 if (FrameView* view = scrollable->frame()->view()) { 105 if (FrameView* view = scrollable->frame()->view()) {
107 view->setCursor(pointerCursor()); 106 view->setCursor(pointerCursor());
108 } 107 }
109 } 108 }
110 #endif
111
112 m_autoscrollType = NoAutoscroll; 109 m_autoscrollType = NoAutoscroll;
113 } 110 }
114 111
115 void AutoscrollController::stopAutoscrollIfNeeded(LayoutObject* layoutObject) 112 void AutoscrollController::stopAutoscrollIfNeeded(LayoutObject* layoutObject)
116 { 113 {
117 if (m_pressedLayoutObject == layoutObject) 114 if (m_pressedLayoutObject == layoutObject)
118 m_pressedLayoutObject = nullptr; 115 m_pressedLayoutObject = nullptr;
119 116
120 if (m_autoscrollLayoutObject != layoutObject) 117 if (m_autoscrollLayoutObject != layoutObject)
121 return; 118 return;
122 m_autoscrollLayoutObject = nullptr; 119 m_autoscrollLayoutObject = nullptr;
123 m_autoscrollType = NoAutoscroll; 120 m_autoscrollType = NoAutoscroll;
124 } 121 }
125 122
126 void AutoscrollController::updateAutoscrollLayoutObject() 123 void AutoscrollController::updateAutoscrollLayoutObject()
127 { 124 {
128 if (!m_autoscrollLayoutObject) 125 if (!m_autoscrollLayoutObject)
129 return; 126 return;
130 127
131 LayoutObject* layoutObject = m_autoscrollLayoutObject; 128 LayoutObject* layoutObject = m_autoscrollLayoutObject;
132 129
133 #if OS(WIN) 130 if (RuntimeEnabledFeatures::middleClickAutoscrollEnabled()) {
134 HitTestResult hitTest = layoutObject->frame()->eventHandler().hitTestResultA tPoint(m_panScrollStartPos, HitTestRequest::ReadOnly | HitTestRequest::Active); 131 HitTestResult hitTest = layoutObject->frame()->eventHandler().hitTestRes ultAtPoint(m_middleClickAutoscrollStartPos, HitTestRequest::ReadOnly | HitTestRe quest::Active);
135 132
136 if (Node* nodeAtPoint = hitTest.innerNode()) 133 if (Node* nodeAtPoint = hitTest.innerNode())
137 layoutObject = nodeAtPoint->layoutObject(); 134 layoutObject = nodeAtPoint->layoutObject();
138 #endif 135 }
139 136
140 while (layoutObject && !(layoutObject->isBox() && toLayoutBox(layoutObject)- >canAutoscroll())) 137 while (layoutObject && !(layoutObject->isBox() && toLayoutBox(layoutObject)- >canAutoscroll()))
141 layoutObject = layoutObject->parent(); 138 layoutObject = layoutObject->parent();
142 139
143 m_autoscrollLayoutObject = layoutObject && layoutObject->isBox() ? toLayoutB ox(layoutObject) : nullptr; 140 m_autoscrollLayoutObject = layoutObject && layoutObject->isBox() ? toLayoutB ox(layoutObject) : nullptr;
144 141
145 if (m_autoscrollType != NoAutoscroll && !m_autoscrollLayoutObject) 142 if (m_autoscrollType != NoAutoscroll && !m_autoscrollLayoutObject)
146 m_autoscrollType = NoAutoscroll; 143 m_autoscrollType = NoAutoscroll;
147 } 144 }
148 145
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 m_autoscrollType = AutoscrollForDragAndDrop; 177 m_autoscrollType = AutoscrollForDragAndDrop;
181 m_autoscrollLayoutObject = scrollable; 178 m_autoscrollLayoutObject = scrollable;
182 m_dragAndDropAutoscrollStartTime = eventTime; 179 m_dragAndDropAutoscrollStartTime = eventTime;
183 startAutoscroll(); 180 startAutoscroll();
184 } else if (m_autoscrollLayoutObject != scrollable) { 181 } else if (m_autoscrollLayoutObject != scrollable) {
185 m_dragAndDropAutoscrollStartTime = eventTime; 182 m_dragAndDropAutoscrollStartTime = eventTime;
186 m_autoscrollLayoutObject = scrollable; 183 m_autoscrollLayoutObject = scrollable;
187 } 184 }
188 } 185 }
189 186
190 #if OS(WIN) 187 void AutoscrollController::handleMouseReleaseForMiddleClickAutoscroll(LocalFrame * frame, const PlatformMouseEvent& mouseEvent)
191 void AutoscrollController::handleMouseReleaseForPanScrolling(LocalFrame* frame, const PlatformMouseEvent& mouseEvent)
192 { 188 {
189 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled());
193 if (!frame->isMainFrame()) 190 if (!frame->isMainFrame())
194 return; 191 return;
195 switch (m_autoscrollType) { 192 switch (m_autoscrollType) {
196 case AutoscrollForPan: 193 case AutoscrollForMiddleClick:
197 if (mouseEvent.pointerProperties().button == WebPointerProperties::Butto n::Middle) 194 if (mouseEvent.pointerProperties().button == WebPointerProperties::Butto n::Middle)
198 m_autoscrollType = AutoscrollForPanCanStop; 195 m_autoscrollType = AutoscrollForMiddleClickCanStop;
199 break; 196 break;
200 case AutoscrollForPanCanStop: 197 case AutoscrollForMiddleClickCanStop:
201 stopAutoscroll(); 198 stopAutoscroll();
202 break; 199 break;
203 case AutoscrollForDragAndDrop: 200 case AutoscrollForDragAndDrop:
204 case AutoscrollForSelection: 201 case AutoscrollForSelection:
205 case NoAutoscroll: 202 case NoAutoscroll:
206 // Nothing to do. 203 // Nothing to do.
207 break; 204 break;
208 } 205 }
209 } 206 }
210 207
211 bool AutoscrollController::panScrollInProgress() const 208 bool AutoscrollController::middleClickAutoscrollInProgress() const
212 { 209 {
213 return m_autoscrollType == AutoscrollForPanCanStop || m_autoscrollType == Au toscrollForPan; 210 return m_autoscrollType == AutoscrollForMiddleClickCanStop || m_autoscrollTy pe == AutoscrollForMiddleClick;
214 } 211 }
215 212
216 void AutoscrollController::startPanScrolling(LayoutBox* scrollable, const IntPoi nt& lastKnownMousePosition) 213 void AutoscrollController::startMiddleClickAutoscroll(LayoutBox* scrollable, con st IntPoint& lastKnownMousePosition)
217 { 214 {
218 // We don't want to trigger the autoscroll or the panScroll if it's already active 215 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled());
216 // We don't want to trigger the autoscroll or the middleClickAutoscroll if i t's already active
219 if (m_autoscrollType != NoAutoscroll) 217 if (m_autoscrollType != NoAutoscroll)
220 return; 218 return;
221 219
222 m_autoscrollType = AutoscrollForPan; 220 m_autoscrollType = AutoscrollForMiddleClick;
223 m_autoscrollLayoutObject = scrollable; 221 m_autoscrollLayoutObject = scrollable;
224 m_panScrollStartPos = lastKnownMousePosition; 222 m_middleClickAutoscrollStartPos = lastKnownMousePosition;
225 223
226 UseCounter::count(m_page->mainFrame(), UseCounter::PanScrollingStart); 224 UseCounter::count(m_page->mainFrame(), UseCounter::MiddleClickAutoscrollStar t);
227 startAutoscroll(); 225 startAutoscroll();
228 } 226 }
229 #else
230 bool AutoscrollController::panScrollInProgress() const
231 {
232 return false;
233 }
234 #endif
235 227
236 void AutoscrollController::animate(double) 228 void AutoscrollController::animate(double)
237 { 229 {
238 if (!m_autoscrollLayoutObject || !m_autoscrollLayoutObject->frame()) { 230 if (!m_autoscrollLayoutObject || !m_autoscrollLayoutObject->frame()) {
239 stopAutoscroll(); 231 stopAutoscroll();
240 return; 232 return;
241 } 233 }
242 234
243 EventHandler& eventHandler = m_autoscrollLayoutObject->frame()->eventHandler (); 235 EventHandler& eventHandler = m_autoscrollLayoutObject->frame()->eventHandler ();
244 switch (m_autoscrollType) { 236 switch (m_autoscrollType) {
245 case AutoscrollForDragAndDrop: 237 case AutoscrollForDragAndDrop:
246 if (WTF::monotonicallyIncreasingTime() - m_dragAndDropAutoscrollStartTim e > autoscrollDelay) 238 if (WTF::monotonicallyIncreasingTime() - m_dragAndDropAutoscrollStartTim e > autoscrollDelay)
247 m_autoscrollLayoutObject->autoscroll(m_dragAndDropAutoscrollReferenc ePosition); 239 m_autoscrollLayoutObject->autoscroll(m_dragAndDropAutoscrollReferenc ePosition);
248 break; 240 break;
249 case AutoscrollForSelection: 241 case AutoscrollForSelection:
250 if (!eventHandler.mousePressed()) { 242 if (!eventHandler.mousePressed()) {
251 stopAutoscroll(); 243 stopAutoscroll();
252 return; 244 return;
253 } 245 }
254 eventHandler.updateSelectionForMouseDrag(); 246 eventHandler.updateSelectionForMouseDrag();
255 m_autoscrollLayoutObject->autoscroll(eventHandler.lastKnownMousePosition ()); 247 m_autoscrollLayoutObject->autoscroll(eventHandler.lastKnownMousePosition ());
256 break; 248 break;
257 case NoAutoscroll: 249 case NoAutoscroll:
258 break; 250 break;
259 #if OS(WIN) 251 case AutoscrollForMiddleClickCanStop:
260 case AutoscrollForPanCanStop: 252 case AutoscrollForMiddleClick:
261 case AutoscrollForPan: 253 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled());
262 if (!panScrollInProgress()) { 254 if (!middleClickAutoscrollInProgress()) {
263 stopAutoscroll(); 255 stopAutoscroll();
264 return; 256 return;
265 } 257 }
266 if (FrameView* view = m_autoscrollLayoutObject->frame()->view()) 258 if (FrameView* view = m_autoscrollLayoutObject->frame()->view())
267 updatePanScrollState(view, eventHandler.lastKnownMousePosition()); 259 updateMiddleClickAutoscrollState(view, eventHandler.lastKnownMousePo sition());
268 m_autoscrollLayoutObject->panScroll(m_panScrollStartPos); 260 m_autoscrollLayoutObject->middleClickAutoscroll(m_middleClickAutoscrollS tartPos);
269 break; 261 break;
270 #endif
271 } 262 }
272 if (m_autoscrollType != NoAutoscroll && m_autoscrollLayoutObject) 263 if (m_autoscrollType != NoAutoscroll && m_autoscrollLayoutObject)
273 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame ()->view()); 264 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame ()->view());
274 } 265 }
275 266
276 void AutoscrollController::startAutoscroll() 267 void AutoscrollController::startAutoscroll()
277 { 268 {
278 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame()-> view()); 269 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame()-> view());
279 } 270 }
280 271
281 #if OS(WIN) 272 void AutoscrollController::updateMiddleClickAutoscrollState(FrameView* view, con st IntPoint& lastKnownMousePosition)
282 void AutoscrollController::updatePanScrollState(FrameView* view, const IntPoint& lastKnownMousePosition)
283 { 273 {
274 DCHECK(RuntimeEnabledFeatures::middleClickAutoscrollEnabled());
284 // At the original click location we draw a 4 arrowed icon. Over this icon t here won't be any scroll 275 // At the original click location we draw a 4 arrowed icon. Over this icon t here won't be any scroll
285 // So we don't want to change the cursor over this area 276 // So we don't want to change the cursor over this area
286 bool east = m_panScrollStartPos.x() < (lastKnownMousePosition.x() - noPanScr ollRadius); 277 bool east = m_middleClickAutoscrollStartPos.x() < (lastKnownMousePosition.x( ) - noMiddleClickAutoscrollRadius);
287 bool west = m_panScrollStartPos.x() > (lastKnownMousePosition.x() + noPanScr ollRadius); 278 bool west = m_middleClickAutoscrollStartPos.x() > (lastKnownMousePosition.x( ) + noMiddleClickAutoscrollRadius);
288 bool north = m_panScrollStartPos.y() > (lastKnownMousePosition.y() + noPanSc rollRadius); 279 bool north = m_middleClickAutoscrollStartPos.y() > (lastKnownMousePosition.y () + noMiddleClickAutoscrollRadius);
289 bool south = m_panScrollStartPos.y() < (lastKnownMousePosition.y() - noPanSc rollRadius); 280 bool south = m_middleClickAutoscrollStartPos.y() < (lastKnownMousePosition.y () - noMiddleClickAutoscrollRadius);
290 281
291 if (m_autoscrollType == AutoscrollForPan && (east || west || north || south) ) 282 if (m_autoscrollType == AutoscrollForMiddleClick && (east || west || north | | south))
292 m_autoscrollType = AutoscrollForPanCanStop; 283 m_autoscrollType = AutoscrollForMiddleClickCanStop;
293 284
294 if (north) { 285 if (north) {
295 if (east) 286 if (east)
296 view->setCursor(northEastPanningCursor()); 287 view->setCursor(northEastPanningCursor());
297 else if (west) 288 else if (west)
298 view->setCursor(northWestPanningCursor()); 289 view->setCursor(northWestPanningCursor());
299 else 290 else
300 view->setCursor(northPanningCursor()); 291 view->setCursor(northPanningCursor());
301 } else if (south) { 292 } else if (south) {
302 if (east) 293 if (east)
303 view->setCursor(southEastPanningCursor()); 294 view->setCursor(southEastPanningCursor());
304 else if (west) 295 else if (west)
305 view->setCursor(southWestPanningCursor()); 296 view->setCursor(southWestPanningCursor());
306 else 297 else
307 view->setCursor(southPanningCursor()); 298 view->setCursor(southPanningCursor());
308 } else if (east) { 299 } else if (east) {
309 view->setCursor(eastPanningCursor()); 300 view->setCursor(eastPanningCursor());
310 } else if (west) { 301 } else if (west) {
311 view->setCursor(westPanningCursor()); 302 view->setCursor(westPanningCursor());
312 } else { 303 } else {
313 view->setCursor(middlePanningCursor()); 304 view->setCursor(middlePanningCursor());
314 } 305 }
315 } 306 }
316 #endif
317 307
318 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698