| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef AutoscrollController_h | 26 #ifndef AutoscrollController_h |
| 27 #define AutoscrollController_h | 27 #define AutoscrollController_h |
| 28 | 28 |
| 29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
| 30 #include "platform/geometry/FloatPoint.h" |
| 30 #include "platform/geometry/FloatSize.h" | 31 #include "platform/geometry/FloatSize.h" |
| 31 #include "platform/geometry/IntPoint.h" | 32 #include "platform/geometry/IntPoint.h" |
| 32 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
| 33 #include "platform/wtf/Time.h" | 34 #include "platform/wtf/Time.h" |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 class LocalFrame; | 38 class LocalFrame; |
| 38 class LocalFrameView; | |
| 39 class Node; | 39 class Node; |
| 40 class Page; | 40 class Page; |
| 41 class LayoutBox; | 41 class LayoutBox; |
| 42 class LayoutObject; | 42 class LayoutObject; |
| 43 class WebMouseEvent; | |
| 44 | 43 |
| 45 enum AutoscrollType { | 44 enum AutoscrollType { |
| 46 kNoAutoscroll, | 45 kNoAutoscroll, |
| 47 kAutoscrollForDragAndDrop, | 46 kAutoscrollForDragAndDrop, |
| 48 kAutoscrollForSelection, | 47 kAutoscrollForSelection, |
| 49 kAutoscrollForMiddleClickCanStop, | |
| 50 kAutoscrollForMiddleClick, | 48 kAutoscrollForMiddleClick, |
| 51 }; | 49 }; |
| 52 | 50 |
| 51 enum MiddleClickMode { |
| 52 // Middle button was just pressed but was neither released nor moved out of |
| 53 // the deadzone yet. |
| 54 kMiddleClickInitial, |
| 55 // Mouse was moved out of the deadzone while still holding middle mouse |
| 56 // button. In this mode, we'll stop autoscrolling when it's released. |
| 57 kMiddleClickHolding, |
| 58 // Middle button was released while still in the deadzone. In this mode, |
| 59 // we'll stop autoscrolling when any button is clicked. |
| 60 kMiddleClickToggled, |
| 61 }; |
| 62 |
| 53 // AutscrollController handels autoscroll and middle click autoscroll for | 63 // AutscrollController handels autoscroll and middle click autoscroll for |
| 54 // EventHandler. | 64 // EventHandler. |
| 55 class CORE_EXPORT AutoscrollController final | 65 class CORE_EXPORT AutoscrollController final |
| 56 : public GarbageCollected<AutoscrollController> { | 66 : public GarbageCollected<AutoscrollController> { |
| 57 public: | 67 public: |
| 58 static AutoscrollController* Create(Page&); | 68 static AutoscrollController* Create(Page&); |
| 59 DECLARE_TRACE(); | 69 DECLARE_TRACE(); |
| 60 | 70 |
| 61 static const int kNoMiddleClickAutoscrollRadius = 15; | 71 // Selection and drag-and-drop autoscroll. |
| 62 | |
| 63 void Animate(double monotonic_frame_begin_time); | 72 void Animate(double monotonic_frame_begin_time); |
| 64 bool AutoscrollInProgress() const; | 73 bool SelectionAutoscrollInProgress() const; |
| 65 bool AutoscrollInProgress(const LayoutBox*) const; | 74 bool AutoscrollInProgress(const LayoutBox*) const; |
| 66 bool MiddleClickAutoscrollInProgress() const; | |
| 67 void StartAutoscrollForSelection(LayoutObject*); | 75 void StartAutoscrollForSelection(LayoutObject*); |
| 68 void StopAutoscroll(); | 76 void StopAutoscroll(); |
| 69 void StopAutoscrollIfNeeded(LayoutObject*); | 77 void StopAutoscrollIfNeeded(LayoutObject*); |
| 70 void UpdateAutoscrollLayoutObject(); | 78 void UpdateAutoscrollLayoutObject(); |
| 71 void UpdateDragAndDrop(Node* target_node, | 79 void UpdateDragAndDrop(Node* target_node, |
| 72 const IntPoint& event_position, | 80 const IntPoint& event_position, |
| 73 TimeTicks event_time); | 81 TimeTicks event_time); |
| 82 |
| 83 // Middle-click autoscroll. |
| 84 void StartMiddleClickAutoscroll(LocalFrame*, |
| 85 const FloatPoint& position, |
| 86 const FloatPoint& position_global); |
| 87 void HandleMouseMoveForMiddleClickAutoscroll( |
| 88 LocalFrame*, |
| 89 const FloatPoint& position_global, |
| 90 bool is_middle_button); |
| 74 void HandleMouseReleaseForMiddleClickAutoscroll(LocalFrame*, | 91 void HandleMouseReleaseForMiddleClickAutoscroll(LocalFrame*, |
| 75 const WebMouseEvent&); | 92 bool is_middle_button); |
| 76 void StartMiddleClickAutoscroll(LayoutBox*, const IntPoint&); | 93 void StopMiddleClickAutoscroll(LocalFrame*); |
| 94 bool MiddleClickAutoscrollInProgress() const; |
| 77 | 95 |
| 78 private: | 96 private: |
| 79 explicit AutoscrollController(Page&); | 97 explicit AutoscrollController(Page&); |
| 80 | 98 |
| 81 void StartAutoscroll(); | 99 Member<Page> page_; |
| 100 AutoscrollType autoscroll_type_ = kNoAutoscroll; |
| 82 | 101 |
| 83 void UpdateMiddleClickAutoscrollState( | 102 // Selection and drag-and-drop autoscroll. |
| 84 LocalFrameView*, | 103 void ScheduleMainThreadAnimation(); |
| 85 const IntPoint& last_known_mouse_position); | 104 LayoutBox* autoscroll_layout_object_ = nullptr; |
| 86 FloatSize CalculateAutoscrollDelta(); | 105 LayoutBox* pressed_layout_object_ = nullptr; |
| 87 | |
| 88 Member<Page> page_; | |
| 89 LayoutBox* autoscroll_layout_object_; | |
| 90 LayoutBox* pressed_layout_object_; | |
| 91 AutoscrollType autoscroll_type_; | |
| 92 IntPoint drag_and_drop_autoscroll_reference_position_; | 106 IntPoint drag_and_drop_autoscroll_reference_position_; |
| 93 TimeTicks drag_and_drop_autoscroll_start_time_; | 107 TimeTicks drag_and_drop_autoscroll_start_time_; |
| 94 IntPoint middle_click_autoscroll_start_pos_; | 108 |
| 95 bool did_latch_for_middle_click_autoscroll_; | 109 // Middle-click autoscroll. |
| 110 FloatPoint middle_click_autoscroll_start_pos_global_; |
| 111 FloatSize last_velocity_; |
| 112 MiddleClickMode middle_click_mode_ = kMiddleClickInitial; |
| 96 }; | 113 }; |
| 97 | 114 |
| 98 } // namespace blink | 115 } // namespace blink |
| 99 | 116 |
| 100 #endif // AutoscrollController_h | 117 #endif // AutoscrollController_h |
| OLD | NEW |