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

Side by Side Diff: content/renderer/input/input_scroll_elasticity_controller.h

Issue 713413002: Hook ScrollElasticityController to InputHandlerProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missed files Created 6 years, 1 month 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_INPUT_INPUT_SCROLL_ELASTICITY_CONTROLLER_H_ 5 #ifndef CONTENT_RENDERER_INPUT_INPUT_SCROLL_ELASTICITY_CONTROLLER_H_
6 #define CONTENT_RENDERER_INPUT_INPUT_SCROLL_ELASTICITY_CONTROLLER_H_ 6 #define CONTENT_RENDERER_INPUT_INPUT_SCROLL_ELASTICITY_CONTROLLER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/time/time.h" 9 #include "base/memory/weak_ptr.h"
10 #include "cc/input/scroll_elasticity_controller.h"
10 #include "third_party/WebKit/public/web/WebInputEvent.h" 11 #include "third_party/WebKit/public/web/WebInputEvent.h"
11 #include "ui/gfx/geometry/vector2d_f.h"
12 12
13 // ScrollElasticityController and ScrollElasticityControllerClient are based on 13 // InputScrollElasticityController is based on
14 // WebKit/Source/platform/mac/ScrollElasticityController.h 14 // WebKit/Source/platform/mac/ScrollElasticityController.h
15 /* 15 /*
16 * Copyright (C) 2011 Apple Inc. All rights reserved. 16 * Copyright (C) 2011 Apple Inc. All rights reserved.
17 * 17 *
18 * Redistribution and use in source and binary forms, with or without 18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions 19 * modification, are permitted provided that the following conditions
20 * are met: 20 * are met:
21 * 1. Redistributions of source code must retain the above copyright 21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer. 22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright 23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the 24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution. 25 * documentation and/or other materials provided with the distribution.
26 * 26 *
27 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 27 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
37 * THE POSSIBILITY OF SUCH DAMAGE. 37 * THE POSSIBILITY OF SUCH DAMAGE.
38 */ 38 */
39 39
40 namespace cc {
41 struct InputHandlerScrollResult;
42 } // namespace cc
43
40 namespace content { 44 namespace content {
41 45
42 class ScrollElasticityControllerClient { 46 class InputScrollElasticityController : public cc::ScrollElasticityController {
43 protected: 47 public:
44 virtual ~ScrollElasticityControllerClient() {} 48 explicit InputScrollElasticityController(
49 cc::ScrollElasticityControllerClient* client);
50 virtual ~InputScrollElasticityController();
jdduke (slow) 2014/11/12 02:32:24 Nit: ~InputScrollElasticityController() override;
jdduke (slow) 2014/11/12 02:45:59 Oh, hmm, I didn't notice that the base class doesn
45 51
46 public: 52 base::WeakPtr<InputScrollElasticityController> GetWeakPtr();
47 virtual bool AllowsHorizontalStretching() = 0; 53 void ObserveWheelEventAndResult(
48 virtual bool AllowsVerticalStretching() = 0; 54 const blink::WebMouseWheelEvent& wheel_event,
49 // The amount that the view is stretched past the normal allowable bounds. 55 const cc::InputHandlerScrollResult& scroll_result);
50 // The "overhang" amount.
51 virtual gfx::Vector2dF StretchAmount() = 0;
52 virtual bool PinnedInDirection(const gfx::Vector2dF& direction) = 0;
53 virtual bool CanScrollHorizontally() = 0;
54 virtual bool CanScrollVertically() = 0;
55 56
56 // Return the absolute scroll position, not relative to the scroll origin. 57 // cc::ScrollElasticityController implementation:
57 virtual gfx::Vector2dF AbsoluteScrollPosition() = 0; 58 void WillShutdown() override;
59 void Animate(base::TimeTicks time) override;
58 60
59 virtual void ImmediateScrollBy(const gfx::Vector2dF& scroll) = 0; 61 private:
60 virtual void ImmediateScrollByWithoutContentEdgeConstraints(
61 const gfx::Vector2dF& scroll) = 0;
62 virtual void StartSnapRubberbandTimer() = 0;
63 virtual void StopSnapRubberbandTimer() = 0;
64
65 // If the current scroll position is within the overhang area, this function
66 // will cause
67 // the page to scroll to the nearest boundary point.
68 virtual void AdjustScrollPositionToBoundsIfNecessary() = 0;
69 };
70
71 class ScrollElasticityController {
72 public:
73 explicit ScrollElasticityController(ScrollElasticityControllerClient*);
74
75 // This method is responsible for both scrolling and rubber-banding. 62 // This method is responsible for both scrolling and rubber-banding.
76 // 63 //
77 // Events are passed by IPC from the embedder. Events on Mac are grouped 64 // Events are passed by IPC from the embedder. Events on Mac are grouped
78 // into "gestures". If this method returns 'true', then this object has 65 // into "gestures". If this method returns 'true', then this object has
79 // handled the event. It expects the embedder to continue to forward events 66 // handled the event. It expects the embedder to continue to forward events
80 // from the gesture. 67 // from the gesture.
81 // 68 //
82 // This method makes the assumption that there is only 1 input device being 69 // This method makes the assumption that there is only 1 input device being
83 // used at a time. If the user simultaneously uses multiple input devices, 70 // used at a time. If the user simultaneously uses multiple input devices,
84 // Cocoa does not correctly pass all the gestureBegin/End events. The state 71 // Cocoa does not correctly pass all the gestureBegin/End events. The state
85 // of this class is guaranteed to become eventually consistent, once the 72 // of this class is guaranteed to become eventually consistent, once the
86 // user stops using multiple input devices. 73 // user stops using multiple input devices.
87 bool HandleWheelEvent(const blink::WebMouseWheelEvent& wheel_event); 74 bool HandleWheelEvent(const blink::WebMouseWheelEvent& wheel_event);
88 void SnapRubberbandTimerFired(); 75 void SnapRubberbandTimerFired();
89 76
90 bool IsRubberbandInProgress() const; 77 bool IsRubberbandInProgress() const;
91 78
92 private:
93 void StopSnapRubberbandTimer(); 79 void StopSnapRubberbandTimer();
94 void SnapRubberband(); 80 void SnapRubberband();
95 81
96 // This method determines whether a given event should be handled. The 82 // This method determines whether a given event should be handled. The
97 // logic for control events of gestures (PhaseBegan, PhaseEnded) is handled 83 // logic for control events of gestures (PhaseBegan, PhaseEnded) is handled
98 // elsewhere. 84 // elsewhere.
99 // 85 //
100 // This class handles almost all wheel events. All of the following 86 // This class handles almost all wheel events. All of the following
101 // conditions must be met for this class to ignore an event: 87 // conditions must be met for this class to ignore an event:
102 // + No previous events in this gesture have caused any scrolling or rubber 88 // + No previous events in this gesture have caused any scrolling or rubber
103 // banding. 89 // banding.
104 // + The event contains a horizontal component. 90 // + The event contains a horizontal component.
105 // + The client's view is pinned in the horizontal direction of the event. 91 // + The client's view is pinned in the horizontal direction of the event.
106 // + The wheel event disallows rubber banding in the horizontal direction 92 // + The wheel event disallows rubber banding in the horizontal direction
107 // of the event. 93 // of the event.
108 bool ShouldHandleEvent(const blink::WebMouseWheelEvent& wheel_event); 94 bool ShouldHandleEvent(const blink::WebMouseWheelEvent& wheel_event);
109 95
110 ScrollElasticityControllerClient* client_; 96 cc::ScrollElasticityControllerClient* client_;
111 97
112 // There is an active scroll gesture event. This parameter only gets set to 98 // There is an active scroll gesture event. This parameter only gets set to
113 // false after the rubber band has been snapped, and before a new gesture 99 // false after the rubber band has been snapped, and before a new gesture
114 // has begun. A careful audit of the code may deprecate the need for this 100 // has begun. A careful audit of the code may deprecate the need for this
115 // parameter. 101 // parameter.
116 bool in_scroll_gesture_; 102 bool in_scroll_gesture_;
117 // At least one event in the current gesture has been consumed and has 103 // At least one event in the current gesture has been consumed and has
118 // caused the view to scroll or rubber band. All future events in this 104 // caused the view to scroll or rubber band. All future events in this
119 // gesture will be consumed and overscrolls will cause rubberbanding. 105 // gesture will be consumed and overscrolls will cause rubberbanding.
120 bool has_scrolled_; 106 bool has_scrolled_;
121 bool momentum_scroll_in_progress_; 107 bool momentum_scroll_in_progress_;
122 bool ignore_momentum_scrolls_; 108 bool ignore_momentum_scrolls_;
123 109
124 // Used with blink::WebInputEvent::timeStampSeconds, in seconds since epoch. 110 // Used with blink::WebInputEvent::timeStampSeconds, in seconds since epoch.
125 double last_momentum_scroll_timestamp_; 111 double last_momentum_scroll_timestamp_;
126 gfx::Vector2dF overflow_scroll_delta_; 112 gfx::Vector2dF overflow_scroll_delta_;
127 gfx::Vector2dF stretch_scroll_force_; 113 gfx::Vector2dF stretch_scroll_force_;
128 gfx::Vector2dF momentum_velocity_; 114 gfx::Vector2dF momentum_velocity_;
129 115
130 // Rubber band state. 116 // Rubber band state.
131 base::Time start_time_; 117 base::Time start_time_;
132 gfx::Vector2dF start_stretch_; 118 gfx::Vector2dF start_stretch_;
133 gfx::Vector2dF orig_origin_; 119 gfx::Vector2dF orig_origin_;
134 gfx::Vector2dF orig_velocity_; 120 gfx::Vector2dF orig_velocity_;
135 121
136 bool snap_rubberband_timer_is_active_; 122 bool snap_rubberband_timer_is_active_;
137 123
138 DISALLOW_COPY_AND_ASSIGN(ScrollElasticityController); 124 base::WeakPtrFactory<InputScrollElasticityController> weak_factory_;
125 DISALLOW_COPY_AND_ASSIGN(InputScrollElasticityController);
139 }; 126 };
140 127
141 } // namespace content 128 } // namespace content
142 129
143 #endif // CONTENT_RENDERER_INPUT_INPUT_SCROLL_ELASTICITY_CONTROLLER_H_ 130 #endif // CONTENT_RENDERER_INPUT_INPUT_SCROLL_ELASTICITY_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698