| 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 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "core/page/AutoscrollController.h" | 30 #include "core/page/AutoscrollController.h" |
| 31 | 31 |
| 32 #include "core/frame/FrameView.h" | 32 #include "core/frame/FrameView.h" |
| 33 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
| 34 #include "core/layout/HitTestResult.h" | 34 #include "core/layout/HitTestResult.h" |
| 35 #include "core/layout/LayoutBox.h" |
| 35 #include "core/layout/LayoutListBox.h" | 36 #include "core/layout/LayoutListBox.h" |
| 36 #include "core/page/Chrome.h" | 37 #include "core/page/Chrome.h" |
| 37 #include "core/page/EventHandler.h" | 38 #include "core/page/EventHandler.h" |
| 38 #include "core/page/Page.h" | 39 #include "core/page/Page.h" |
| 39 #include "core/rendering/RenderBox.h" | |
| 40 #include "wtf/CurrentTime.h" | 40 #include "wtf/CurrentTime.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 // Delay time in second for start autoscroll if pointer is in border edge of scr
ollable element. | 44 // Delay time in second for start autoscroll if pointer is in border edge of scr
ollable element. |
| 45 static double autoscrollDelay = 0.2; | 45 static double autoscrollDelay = 0.2; |
| 46 | 46 |
| 47 PassOwnPtr<AutoscrollController> AutoscrollController::create(Page& page) | 47 PassOwnPtr<AutoscrollController> AutoscrollController::create(Page& page) |
| 48 { | 48 { |
| 49 return adoptPtr(new AutoscrollController(page)); | 49 return adoptPtr(new AutoscrollController(page)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 AutoscrollController::AutoscrollController(Page& page) | 52 AutoscrollController::AutoscrollController(Page& page) |
| 53 : m_page(page) | 53 : m_page(page) |
| 54 , m_autoscrollRenderer(nullptr) | 54 , m_autoscrollRenderer(nullptr) |
| 55 , m_autoscrollType(NoAutoscroll) | 55 , m_autoscrollType(NoAutoscroll) |
| 56 , m_dragAndDropAutoscrollStartTime(0) | 56 , m_dragAndDropAutoscrollStartTime(0) |
| 57 { | 57 { |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool AutoscrollController::autoscrollInProgress() const | 60 bool AutoscrollController::autoscrollInProgress() const |
| 61 { | 61 { |
| 62 return m_autoscrollType == AutoscrollForSelection; | 62 return m_autoscrollType == AutoscrollForSelection; |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool AutoscrollController::autoscrollInProgress(const RenderBox* renderer) const | 65 bool AutoscrollController::autoscrollInProgress(const LayoutBox* renderer) const |
| 66 { | 66 { |
| 67 return m_autoscrollRenderer == renderer; | 67 return m_autoscrollRenderer == renderer; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void AutoscrollController::startAutoscrollForSelection(LayoutObject* renderer) | 70 void AutoscrollController::startAutoscrollForSelection(LayoutObject* renderer) |
| 71 { | 71 { |
| 72 // We don't want to trigger the autoscroll or the panScroll if it's already
active | 72 // We don't want to trigger the autoscroll or the panScroll if it's already
active |
| 73 if (m_autoscrollType != NoAutoscroll) | 73 if (m_autoscrollType != NoAutoscroll) |
| 74 return; | 74 return; |
| 75 RenderBox* scrollable = RenderBox::findAutoscrollable(renderer); | 75 LayoutBox* scrollable = LayoutBox::findAutoscrollable(renderer); |
| 76 if (!scrollable) | 76 if (!scrollable) |
| 77 scrollable = renderer->isListBox() ? toLayoutListBox(renderer) : nullptr
; | 77 scrollable = renderer->isListBox() ? toLayoutListBox(renderer) : nullptr
; |
| 78 if (!scrollable) | 78 if (!scrollable) |
| 79 return; | 79 return; |
| 80 m_autoscrollType = AutoscrollForSelection; | 80 m_autoscrollType = AutoscrollForSelection; |
| 81 m_autoscrollRenderer = scrollable; | 81 m_autoscrollRenderer = scrollable; |
| 82 startAutoscroll(); | 82 startAutoscroll(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void AutoscrollController::stopAutoscroll() | 85 void AutoscrollController::stopAutoscroll() |
| 86 { | 86 { |
| 87 RenderBox* scrollable = m_autoscrollRenderer; | 87 LayoutBox* scrollable = m_autoscrollRenderer; |
| 88 m_autoscrollRenderer = nullptr; | 88 m_autoscrollRenderer = nullptr; |
| 89 | 89 |
| 90 if (!scrollable) | 90 if (!scrollable) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 scrollable->stopAutoscroll(); | 93 scrollable->stopAutoscroll(); |
| 94 #if OS(WIN) | 94 #if OS(WIN) |
| 95 if (panScrollInProgress()) { | 95 if (panScrollInProgress()) { |
| 96 if (FrameView* view = scrollable->frame()->view()) { | 96 if (FrameView* view = scrollable->frame()->view()) { |
| 97 view->removePanScrollIcon(); | 97 view->removePanScrollIcon(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 118 | 118 |
| 119 LayoutObject* renderer = m_autoscrollRenderer; | 119 LayoutObject* renderer = m_autoscrollRenderer; |
| 120 | 120 |
| 121 #if OS(WIN) | 121 #if OS(WIN) |
| 122 HitTestResult hitTest = renderer->frame()->eventHandler().hitTestResultAtPoi
nt(m_panScrollStartPos, HitTestRequest::ReadOnly | HitTestRequest::Active); | 122 HitTestResult hitTest = renderer->frame()->eventHandler().hitTestResultAtPoi
nt(m_panScrollStartPos, HitTestRequest::ReadOnly | HitTestRequest::Active); |
| 123 | 123 |
| 124 if (Node* nodeAtPoint = hitTest.innerNode()) | 124 if (Node* nodeAtPoint = hitTest.innerNode()) |
| 125 renderer = nodeAtPoint->renderer(); | 125 renderer = nodeAtPoint->renderer(); |
| 126 #endif | 126 #endif |
| 127 | 127 |
| 128 while (renderer && !(renderer->isBox() && toRenderBox(renderer)->canAutoscro
ll())) | 128 while (renderer && !(renderer->isBox() && toLayoutBox(renderer)->canAutoscro
ll())) |
| 129 renderer = renderer->parent(); | 129 renderer = renderer->parent(); |
| 130 m_autoscrollRenderer = renderer && renderer->isBox() ? toRenderBox(renderer)
: nullptr; | 130 m_autoscrollRenderer = renderer && renderer->isBox() ? toLayoutBox(renderer)
: nullptr; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoin
t& eventPosition, double eventTime) | 133 void AutoscrollController::updateDragAndDrop(Node* dropTargetNode, const IntPoin
t& eventPosition, double eventTime) |
| 134 { | 134 { |
| 135 if (!dropTargetNode || !dropTargetNode->renderer()) { | 135 if (!dropTargetNode || !dropTargetNode->renderer()) { |
| 136 stopAutoscroll(); | 136 stopAutoscroll(); |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 | 139 |
| 140 if (m_autoscrollRenderer && m_autoscrollRenderer->frame() != dropTargetNode-
>renderer()->frame()) | 140 if (m_autoscrollRenderer && m_autoscrollRenderer->frame() != dropTargetNode-
>renderer()->frame()) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 RenderBox* scrollable = RenderBox::findAutoscrollable(dropTargetNode->render
er()); | 143 LayoutBox* scrollable = LayoutBox::findAutoscrollable(dropTargetNode->render
er()); |
| 144 if (!scrollable) { | 144 if (!scrollable) { |
| 145 stopAutoscroll(); | 145 stopAutoscroll(); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 Page* page = scrollable->frame() ? scrollable->frame()->page() : nullptr; | 149 Page* page = scrollable->frame() ? scrollable->frame()->page() : nullptr; |
| 150 if (!page) { | 150 if (!page) { |
| 151 stopAutoscroll(); | 151 stopAutoscroll(); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 stopAutoscroll(); | 185 stopAutoscroll(); |
| 186 break; | 186 break; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool AutoscrollController::panScrollInProgress() const | 190 bool AutoscrollController::panScrollInProgress() const |
| 191 { | 191 { |
| 192 return m_autoscrollType == AutoscrollForPanCanStop || m_autoscrollType == Au
toscrollForPan; | 192 return m_autoscrollType == AutoscrollForPanCanStop || m_autoscrollType == Au
toscrollForPan; |
| 193 } | 193 } |
| 194 | 194 |
| 195 void AutoscrollController::startPanScrolling(RenderBox* scrollable, const IntPoi
nt& lastKnownMousePosition) | 195 void AutoscrollController::startPanScrolling(LayoutBox* scrollable, const IntPoi
nt& lastKnownMousePosition) |
| 196 { | 196 { |
| 197 // We don't want to trigger the autoscroll or the panScroll if it's already
active | 197 // We don't want to trigger the autoscroll or the panScroll if it's already
active |
| 198 if (m_autoscrollType != NoAutoscroll) | 198 if (m_autoscrollType != NoAutoscroll) |
| 199 return; | 199 return; |
| 200 | 200 |
| 201 m_autoscrollType = AutoscrollForPan; | 201 m_autoscrollType = AutoscrollForPan; |
| 202 m_autoscrollRenderer = scrollable; | 202 m_autoscrollRenderer = scrollable; |
| 203 m_panScrollStartPos = lastKnownMousePosition; | 203 m_panScrollStartPos = lastKnownMousePosition; |
| 204 | 204 |
| 205 if (FrameView* view = scrollable->frame()->view()) | 205 if (FrameView* view = scrollable->frame()->view()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } else if (east) | 290 } else if (east) |
| 291 view->setCursor(eastPanningCursor()); | 291 view->setCursor(eastPanningCursor()); |
| 292 else if (west) | 292 else if (west) |
| 293 view->setCursor(westPanningCursor()); | 293 view->setCursor(westPanningCursor()); |
| 294 else | 294 else |
| 295 view->setCursor(middlePanningCursor()); | 295 view->setCursor(middlePanningCursor()); |
| 296 } | 296 } |
| 297 #endif | 297 #endif |
| 298 | 298 |
| 299 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |