Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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) | |
| 191 void AutoscrollController::handleMouseReleaseForPanScrolling(LocalFrame* frame, const PlatformMouseEvent& mouseEvent) | 187 void AutoscrollController::handleMouseReleaseForPanScrolling(LocalFrame* frame, const PlatformMouseEvent& mouseEvent) |
| 192 { | 188 { |
| 193 if (!frame->isMainFrame()) | 189 if (!frame->isMainFrame()) |
| 194 return; | 190 return; |
| 195 switch (m_autoscrollType) { | 191 switch (m_autoscrollType) { |
| 196 case AutoscrollForPan: | 192 case AutoscrollForPan: |
| 197 if (mouseEvent.pointerProperties().button == WebPointerProperties::Butto n::Middle) | 193 if (mouseEvent.pointerProperties().button == WebPointerProperties::Butto n::Middle) |
| 198 m_autoscrollType = AutoscrollForPanCanStop; | 194 m_autoscrollType = AutoscrollForPanCanStop; |
| 199 break; | 195 break; |
| 200 case AutoscrollForPanCanStop: | 196 case AutoscrollForPanCanStop: |
| 201 stopAutoscroll(); | 197 stopAutoscroll(); |
| 202 break; | 198 break; |
| 203 case AutoscrollForDragAndDrop: | 199 case AutoscrollForDragAndDrop: |
| 204 case AutoscrollForSelection: | 200 case AutoscrollForSelection: |
| 205 case NoAutoscroll: | 201 case NoAutoscroll: |
| 206 // Nothing to do. | 202 // Nothing to do. |
| 207 break; | 203 break; |
| 208 } | 204 } |
| 209 } | 205 } |
| 210 | 206 |
| 211 bool AutoscrollController::panScrollInProgress() const | 207 bool AutoscrollController::middleClickAutoscrollInProgress() const |
| 212 { | 208 { |
| 213 return m_autoscrollType == AutoscrollForPanCanStop || m_autoscrollType == Au toscrollForPan; | 209 return m_autoscrollType == AutoscrollForPanCanStop || m_autoscrollType == Au toscrollForPan; |
| 214 } | 210 } |
| 215 | 211 |
| 216 void AutoscrollController::startPanScrolling(LayoutBox* scrollable, const IntPoi nt& lastKnownMousePosition) | 212 void AutoscrollController::startPanScrolling(LayoutBox* scrollable, const IntPoi nt& lastKnownMousePosition) |
| 217 { | 213 { |
| 218 // We don't want to trigger the autoscroll or the panScroll if it's already active | 214 // We don't want to trigger the autoscroll or the middleClickAutoscroll if i t's already active |
| 219 if (m_autoscrollType != NoAutoscroll) | 215 if (m_autoscrollType != NoAutoscroll) |
| 220 return; | 216 return; |
| 221 | 217 |
| 222 m_autoscrollType = AutoscrollForPan; | 218 m_autoscrollType = AutoscrollForPan; |
| 223 m_autoscrollLayoutObject = scrollable; | 219 m_autoscrollLayoutObject = scrollable; |
| 224 m_panScrollStartPos = lastKnownMousePosition; | 220 m_middleClickAutoscrollStartPos = lastKnownMousePosition; |
| 225 | 221 |
| 226 startAutoscroll(); | 222 startAutoscroll(); |
| 227 } | 223 } |
| 228 #else | |
| 229 bool AutoscrollController::panScrollInProgress() const | |
| 230 { | |
| 231 return false; | |
| 232 } | |
| 233 #endif | |
| 234 | 224 |
| 235 // FIXME: This would get get better animation fidelity if it used the monotonicF rameBeginTime instead | 225 // FIXME: This would get get better animation fidelity if it used the monotonicF rameBeginTime instead |
| 236 // of WTF::currentTime(). | 226 // of WTF::currentTime(). |
| 237 void AutoscrollController::animate(double) | 227 void AutoscrollController::animate(double) |
| 238 { | 228 { |
| 239 if (!m_autoscrollLayoutObject) { | 229 if (!m_autoscrollLayoutObject) { |
| 240 stopAutoscroll(); | 230 stopAutoscroll(); |
| 241 return; | 231 return; |
| 242 } | 232 } |
| 243 | 233 |
| 244 EventHandler& eventHandler = m_autoscrollLayoutObject->frame()->eventHandler (); | 234 EventHandler& eventHandler = m_autoscrollLayoutObject->frame()->eventHandler (); |
| 245 switch (m_autoscrollType) { | 235 switch (m_autoscrollType) { |
| 246 case AutoscrollForDragAndDrop: | 236 case AutoscrollForDragAndDrop: |
| 247 if (WTF::currentTime() - m_dragAndDropAutoscrollStartTime > autoscrollDe lay) | 237 if (WTF::currentTime() - m_dragAndDropAutoscrollStartTime > autoscrollDe lay) |
| 248 m_autoscrollLayoutObject->autoscroll(m_dragAndDropAutoscrollReferenc ePosition); | 238 m_autoscrollLayoutObject->autoscroll(m_dragAndDropAutoscrollReferenc ePosition); |
| 249 break; | 239 break; |
| 250 case AutoscrollForSelection: | 240 case AutoscrollForSelection: |
| 251 if (!eventHandler.mousePressed()) { | 241 if (!eventHandler.mousePressed()) { |
| 252 stopAutoscroll(); | 242 stopAutoscroll(); |
| 253 return; | 243 return; |
| 254 } | 244 } |
| 255 eventHandler.updateSelectionForMouseDrag(); | 245 eventHandler.updateSelectionForMouseDrag(); |
| 256 m_autoscrollLayoutObject->autoscroll(eventHandler.lastKnownMousePosition ()); | 246 m_autoscrollLayoutObject->autoscroll(eventHandler.lastKnownMousePosition ()); |
| 257 break; | 247 break; |
| 258 case NoAutoscroll: | 248 case NoAutoscroll: |
| 259 break; | 249 break; |
| 260 #if OS(WIN) | |
| 261 case AutoscrollForPanCanStop: | 250 case AutoscrollForPanCanStop: |
| 262 case AutoscrollForPan: | 251 case AutoscrollForPan: |
|
bokan
2016/09/07 16:33:46
Please add a DCHECK here that the middleClickAutoS
| |
| 263 if (!panScrollInProgress()) { | 252 if (!middleClickAutoscrollInProgress()) { |
| 264 stopAutoscroll(); | 253 stopAutoscroll(); |
| 265 return; | 254 return; |
| 266 } | 255 } |
| 267 if (FrameView* view = m_autoscrollLayoutObject->frame()->view()) | 256 if (FrameView* view = m_autoscrollLayoutObject->frame()->view()) |
| 268 updatePanScrollState(view, eventHandler.lastKnownMousePosition()); | 257 updatePanScrollState(view, eventHandler.lastKnownMousePosition()); |
| 269 m_autoscrollLayoutObject->panScroll(m_panScrollStartPos); | 258 m_autoscrollLayoutObject->middleClickAutoscroll(m_middleClickAutoscrollS tartPos); |
| 270 break; | 259 break; |
| 271 #endif | |
| 272 } | 260 } |
| 273 if (m_autoscrollType != NoAutoscroll && m_autoscrollLayoutObject) | 261 if (m_autoscrollType != NoAutoscroll && m_autoscrollLayoutObject) |
| 274 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame ()->view()); | 262 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame ()->view()); |
| 275 } | 263 } |
| 276 | 264 |
| 277 void AutoscrollController::startAutoscroll() | 265 void AutoscrollController::startAutoscroll() |
| 278 { | 266 { |
| 279 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame()-> view()); | 267 m_page->chromeClient().scheduleAnimation(m_autoscrollLayoutObject->frame()-> view()); |
| 280 } | 268 } |
| 281 | 269 |
| 282 #if OS(WIN) | |
| 283 void AutoscrollController::updatePanScrollState(FrameView* view, const IntPoint& lastKnownMousePosition) | 270 void AutoscrollController::updatePanScrollState(FrameView* view, const IntPoint& lastKnownMousePosition) |
| 284 { | 271 { |
| 285 // At the original click location we draw a 4 arrowed icon. Over this icon t here won't be any scroll | 272 // At the original click location we draw a 4 arrowed icon. Over this icon t here won't be any scroll |
| 286 // So we don't want to change the cursor over this area | 273 // So we don't want to change the cursor over this area |
| 287 bool east = m_panScrollStartPos.x() < (lastKnownMousePosition.x() - noPanScr ollRadius); | 274 bool east = m_middleClickAutoscrollStartPos.x() < (lastKnownMousePosition.x( ) - noPanScrollRadius); |
| 288 bool west = m_panScrollStartPos.x() > (lastKnownMousePosition.x() + noPanScr ollRadius); | 275 bool west = m_middleClickAutoscrollStartPos.x() > (lastKnownMousePosition.x( ) + noPanScrollRadius); |
| 289 bool north = m_panScrollStartPos.y() > (lastKnownMousePosition.y() + noPanSc rollRadius); | 276 bool north = m_middleClickAutoscrollStartPos.y() > (lastKnownMousePosition.y () + noPanScrollRadius); |
| 290 bool south = m_panScrollStartPos.y() < (lastKnownMousePosition.y() - noPanSc rollRadius); | 277 bool south = m_middleClickAutoscrollStartPos.y() < (lastKnownMousePosition.y () - noPanScrollRadius); |
| 291 | 278 |
| 292 if (m_autoscrollType == AutoscrollForPan && (east || west || north || south) ) | 279 if (m_autoscrollType == AutoscrollForPan && (east || west || north || south) ) |
| 293 m_autoscrollType = AutoscrollForPanCanStop; | 280 m_autoscrollType = AutoscrollForPanCanStop; |
| 294 | 281 |
| 295 if (north) { | 282 if (north) { |
| 296 if (east) | 283 if (east) |
| 297 view->setCursor(northEastPanningCursor()); | 284 view->setCursor(northEastPanningCursor()); |
| 298 else if (west) | 285 else if (west) |
| 299 view->setCursor(northWestPanningCursor()); | 286 view->setCursor(northWestPanningCursor()); |
| 300 else | 287 else |
| 301 view->setCursor(northPanningCursor()); | 288 view->setCursor(northPanningCursor()); |
| 302 } else if (south) { | 289 } else if (south) { |
| 303 if (east) | 290 if (east) |
| 304 view->setCursor(southEastPanningCursor()); | 291 view->setCursor(southEastPanningCursor()); |
| 305 else if (west) | 292 else if (west) |
| 306 view->setCursor(southWestPanningCursor()); | 293 view->setCursor(southWestPanningCursor()); |
| 307 else | 294 else |
| 308 view->setCursor(southPanningCursor()); | 295 view->setCursor(southPanningCursor()); |
| 309 } else if (east) { | 296 } else if (east) { |
| 310 view->setCursor(eastPanningCursor()); | 297 view->setCursor(eastPanningCursor()); |
| 311 } else if (west) { | 298 } else if (west) { |
| 312 view->setCursor(westPanningCursor()); | 299 view->setCursor(westPanningCursor()); |
| 313 } else { | 300 } else { |
| 314 view->setCursor(middlePanningCursor()); | 301 view->setCursor(middlePanningCursor()); |
| 315 } | 302 } |
| 316 } | 303 } |
| 317 #endif | |
| 318 | 304 |
| 319 } // namespace blink | 305 } // namespace blink |
| OLD | NEW |