OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/overscroll_controller.h" | 5 #include "content/browser/renderer_host/overscroll_controller.h" |
6 | 6 |
7 #include "content/browser/renderer_host/gesture_event_filter.h" | 7 #include "content/browser/renderer_host/gesture_event_filter.h" |
8 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 8 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 #include "content/public/browser/overscroll_configuration.h" | 10 #include "content/public/browser/overscroll_configuration.h" |
11 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
12 | 12 |
13 namespace { | |
14 | |
15 // Some gesture events can also be triggered from the trackpad. This function | |
16 // checks to see if |event| was generated from a touchscreen. | |
17 bool IsGestureEventFromTouchscreen(const WebKit::WebInputEvent& event) { | |
18 if (!WebKit::WebInputEvent::isGestureEventType(event.type)) | |
19 return false; | |
20 | |
21 if (event.type == WebKit::WebInputEvent::GestureFlingStart) { | |
22 const WebKit::WebGestureEvent& gevent = | |
23 static_cast<const WebKit::WebGestureEvent&>(event); | |
24 return gevent.data.flingStart.sourceDevice == | |
25 WebKit::WebGestureEvent::Touchscreen; | |
26 } | |
27 | |
28 return true; | |
29 } | |
30 | |
31 } | |
32 | |
33 namespace content { | 13 namespace content { |
34 | 14 |
35 OverscrollController::OverscrollController( | 15 OverscrollController::OverscrollController( |
36 RenderWidgetHostImpl* render_widget_host) | 16 RenderWidgetHostImpl* render_widget_host) |
37 : render_widget_host_(render_widget_host), | 17 : render_widget_host_(render_widget_host), |
38 overscroll_mode_(OVERSCROLL_NONE), | 18 overscroll_mode_(OVERSCROLL_NONE), |
39 overscroll_delta_x_(0.f), | 19 overscroll_delta_x_(0.f), |
40 overscroll_delta_y_(0.f), | 20 overscroll_delta_y_(0.f), |
41 delegate_(NULL) { | 21 delegate_(NULL) { |
42 } | 22 } |
43 | 23 |
44 OverscrollController::~OverscrollController() { | 24 OverscrollController::~OverscrollController() { |
45 } | 25 } |
46 | 26 |
47 bool OverscrollController::WillDispatchEvent( | 27 bool OverscrollController::WillDispatchEvent( |
48 const WebKit::WebInputEvent& event) { | 28 const WebKit::WebInputEvent& event) { |
49 if (DispatchEventCompletesAction(event)) { | 29 if (DispatchEventCompletesAction(event)) { |
50 CompleteAction(); | 30 CompleteAction(); |
51 | 31 |
52 // If the overscroll was caused by touch-scrolling, then the gesture event | 32 // If the overscroll was caused by touch-scrolling, then the gesture event |
53 // that completes the action needs to be sent to the renderer, because the | 33 // that completes the action needs to be sent to the renderer, because the |
54 // touch-scrolls maintain state in the renderer side (in the compositor, for | 34 // touch-scrolls maintain state in the renderer side (in the compositor, for |
55 // example), and the event that completes this action needs to be sent to | 35 // example), and the event that completes this action needs to be sent to |
56 // the renderer so that those states can be updated/reset appropriately. | 36 // the renderer so that those states can be updated/reset appropriately. |
57 // Send the event through the gesture-event filter when appropriate. | 37 // Send the event through the gesture-event filter when appropriate. |
58 if (IsGestureEventFromTouchscreen(event)) { | 38 if (ShouldForwardToGestureFilter(event)) { |
59 if (ShouldForwardToGestureFilter(event)) { | 39 const WebKit::WebGestureEvent& gevent = |
60 const WebKit::WebGestureEvent& gevent = | 40 static_cast<const WebKit::WebGestureEvent&>(event); |
61 static_cast<const WebKit::WebGestureEvent&>(event); | 41 return render_widget_host_->gesture_event_filter()-> |
62 return render_widget_host_->gesture_event_filter()-> | 42 ShouldForward(gevent); |
63 ShouldForward(gevent); | |
64 } | |
65 return true; | |
66 } | 43 } |
67 | 44 |
68 return false; | 45 return false; |
69 } | 46 } |
70 | 47 |
71 if (overscroll_mode_ != OVERSCROLL_NONE && DispatchEventResetsState(event)) { | 48 if (overscroll_mode_ != OVERSCROLL_NONE && DispatchEventResetsState(event)) { |
72 SetOverscrollMode(OVERSCROLL_NONE); | 49 SetOverscrollMode(OVERSCROLL_NONE); |
73 // The overscroll gesture status is being reset. If the event is a | 50 // The overscroll gesture status is being reset. If the event is a |
74 // touch-screen gesture event, then make sure the gesture event filter gets | 51 // gesture event (from either touchscreen or trackpad), then make sure the |
75 // the event first (if it didn't already process it). | 52 // gesture event filter gets the event first (if it didn't already process |
76 if (IsGestureEventFromTouchscreen(event) && | 53 // it). |
77 ShouldForwardToGestureFilter(event)) { | 54 if (ShouldForwardToGestureFilter(event)) { |
78 const WebKit::WebGestureEvent& gevent = | 55 const WebKit::WebGestureEvent& gevent = |
79 static_cast<const WebKit::WebGestureEvent&>(event); | 56 static_cast<const WebKit::WebGestureEvent&>(event); |
80 return render_widget_host_->gesture_event_filter()->ShouldForward(gevent); | 57 return render_widget_host_->gesture_event_filter()->ShouldForward(gevent); |
81 } | 58 } |
82 | 59 |
83 // Let the event be dispatched to the renderer. | 60 // Let the event be dispatched to the renderer. |
84 return true; | 61 return true; |
85 } | 62 } |
86 | 63 |
87 if (overscroll_mode_ != OVERSCROLL_NONE) { | 64 if (overscroll_mode_ != OVERSCROLL_NONE) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 OverscrollMode old_mode = overscroll_mode_; | 240 OverscrollMode old_mode = overscroll_mode_; |
264 overscroll_mode_ = mode; | 241 overscroll_mode_ = mode; |
265 if (overscroll_mode_ == OVERSCROLL_NONE) | 242 if (overscroll_mode_ == OVERSCROLL_NONE) |
266 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 243 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
267 if (delegate_) | 244 if (delegate_) |
268 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); | 245 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); |
269 } | 246 } |
270 | 247 |
271 bool OverscrollController::ShouldForwardToGestureFilter( | 248 bool OverscrollController::ShouldForwardToGestureFilter( |
272 const WebKit::WebInputEvent& event) const { | 249 const WebKit::WebInputEvent& event) const { |
273 DCHECK(IsGestureEventFromTouchscreen(event)); | 250 if (!WebKit::WebInputEvent::isGestureEventType(event.type)) |
| 251 return false; |
274 | 252 |
275 // If the GestureEventFilter already processed this event, then the event must | 253 // If the GestureEventFilter already processed this event, then the event must |
276 // not be sent to the filter again. | 254 // not be sent to the filter again. |
277 return !render_widget_host_->gesture_event_filter()->HasQueuedGestureEvents(); | 255 return !render_widget_host_->gesture_event_filter()->HasQueuedGestureEvents(); |
278 } | 256 } |
279 | 257 |
280 } // namespace content | 258 } // namespace content |
OLD | NEW |