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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 9 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
10 #include "content/common/input/input_event_utils.h" | |
11 #include "content/public/browser/overscroll_configuration.h" | 10 #include "content/public/browser/overscroll_configuration.h" |
12 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
13 | 12 |
14 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
15 | 14 |
16 namespace { | 15 namespace { |
17 | 16 |
18 bool IsScrollEndEffectEnabled() { | 17 bool IsScrollEndEffectEnabled() { |
19 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 18 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
20 switches::kScrollEndEffect) == "1"; | 19 switches::kScrollEndEffect) == "1"; |
21 } | 20 } |
22 | 21 |
23 bool IsGestureEventFromTouchpad(const blink::WebInputEvent& event) { | 22 bool IsGestureEventFromTouchpad(const blink::WebInputEvent& event) { |
24 DCHECK(blink::WebInputEvent::isGestureEventType(event.type)); | 23 DCHECK(blink::WebInputEvent::isGestureEventType(event.type)); |
25 const blink::WebGestureEvent& gesture = | 24 const blink::WebGestureEvent& gesture = |
26 static_cast<const blink::WebGestureEvent&>(event); | 25 static_cast<const blink::WebGestureEvent&>(event); |
27 return gesture.sourceDevice == blink::WebGestureDeviceTouchpad; | 26 return gesture.sourceDevice == blink::WebGestureDeviceTouchpad; |
28 } | 27 } |
29 | 28 |
30 } // namespace | 29 } // namespace |
31 | 30 |
32 namespace content { | 31 namespace content { |
33 | 32 |
34 OverscrollController::OverscrollController() | 33 OverscrollController::OverscrollController() |
35 : overscroll_mode_(OVERSCROLL_NONE), | 34 : overscroll_mode_(OVERSCROLL_NONE), |
36 scroll_state_(STATE_UNKNOWN), | 35 scroll_state_(STATE_UNKNOWN), |
37 overscroll_delta_x_(0.f), | 36 overscroll_delta_x_(0.f), |
38 overscroll_delta_y_(0.f), | 37 overscroll_delta_y_(0.f), |
39 delegate_(NULL), | 38 delegate_(NULL) {} |
40 use_gesture_wheel_scrolling_(UseGestureBasedWheelScrolling()) {} | |
41 | 39 |
42 OverscrollController::~OverscrollController() { | 40 OverscrollController::~OverscrollController() { |
43 } | 41 } |
44 | 42 |
45 bool OverscrollController::ShouldProcessEvent( | 43 bool OverscrollController::ShouldProcessEvent( |
46 const blink::WebInputEvent& event) { | 44 const blink::WebInputEvent& event) { |
47 if (use_gesture_wheel_scrolling_) { | |
48 switch (event.type) { | 45 switch (event.type) { |
49 case blink::WebInputEvent::MouseWheel: | 46 case blink::WebInputEvent::MouseWheel: |
50 return false; | 47 return false; |
51 case blink::WebInputEvent::GestureScrollBegin: | 48 case blink::WebInputEvent::GestureScrollBegin: |
52 case blink::WebInputEvent::GestureScrollUpdate: | 49 case blink::WebInputEvent::GestureScrollUpdate: |
53 case blink::WebInputEvent::GestureScrollEnd: { | 50 case blink::WebInputEvent::GestureScrollEnd: { |
54 const blink::WebGestureEvent& gesture = | 51 const blink::WebGestureEvent& gesture = |
55 static_cast<const blink::WebGestureEvent&>(event); | 52 static_cast<const blink::WebGestureEvent&>(event); |
56 if (gesture.sourceDevice == blink::WebGestureDeviceTouchpad) | 53 if (gesture.sourceDevice == blink::WebGestureDeviceTouchpad) |
57 return true; | 54 return true; |
(...skipping 11 matching lines...) Expand all Loading... |
69 default: | 66 default: |
70 scrollUnits = blink::WebGestureEvent::Pixels; | 67 scrollUnits = blink::WebGestureEvent::Pixels; |
71 break; | 68 break; |
72 } | 69 } |
73 | 70 |
74 return scrollUnits == blink::WebGestureEvent::PrecisePixels; | 71 return scrollUnits == blink::WebGestureEvent::PrecisePixels; |
75 } | 72 } |
76 default: | 73 default: |
77 break; | 74 break; |
78 } | 75 } |
79 } | |
80 return true; | 76 return true; |
81 } | 77 } |
82 | 78 |
83 bool OverscrollController::WillHandleEvent(const blink::WebInputEvent& event) { | 79 bool OverscrollController::WillHandleEvent(const blink::WebInputEvent& event) { |
84 if (!ShouldProcessEvent(event)) | 80 if (!ShouldProcessEvent(event)) |
85 return false; | 81 return false; |
86 | 82 |
87 bool reset_scroll_state = false; | 83 bool reset_scroll_state = false; |
88 if (scroll_state_ != STATE_UNKNOWN || | 84 if (scroll_state_ != STATE_UNKNOWN || |
89 overscroll_delta_x_ || overscroll_delta_y_) { | 85 overscroll_delta_x_ || overscroll_delta_y_) { |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 overscroll_mode_ = mode; | 420 overscroll_mode_ = mode; |
425 if (overscroll_mode_ == OVERSCROLL_NONE) | 421 if (overscroll_mode_ == OVERSCROLL_NONE) |
426 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 422 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
427 else | 423 else |
428 scroll_state_ = STATE_OVERSCROLLING; | 424 scroll_state_ = STATE_OVERSCROLLING; |
429 if (delegate_) | 425 if (delegate_) |
430 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); | 426 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); |
431 } | 427 } |
432 | 428 |
433 } // namespace content | 429 } // namespace content |
OLD | NEW |