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/logging.h" |
7 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 8 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
8 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
9 #include "content/public/browser/overscroll_configuration.h" | 9 #include "content/public/browser/overscroll_configuration.h" |
10 #include "content/public/browser/render_widget_host_view.h" | |
11 | 10 |
12 using WebKit::WebInputEvent; | 11 using WebKit::WebInputEvent; |
13 | 12 |
14 namespace content { | 13 namespace content { |
15 | 14 |
16 OverscrollController::OverscrollController( | 15 OverscrollController::OverscrollController() |
17 RenderWidgetHostImpl* render_widget_host) | 16 : overscroll_mode_(OVERSCROLL_NONE), |
18 : render_widget_host_(render_widget_host), | |
19 overscroll_mode_(OVERSCROLL_NONE), | |
20 scroll_state_(STATE_UNKNOWN), | 17 scroll_state_(STATE_UNKNOWN), |
21 overscroll_delta_x_(0.f), | 18 overscroll_delta_x_(0.f), |
22 overscroll_delta_y_(0.f), | 19 overscroll_delta_y_(0.f), |
23 delegate_(NULL) { | 20 delegate_(NULL) { |
24 } | 21 } |
25 | 22 |
26 OverscrollController::~OverscrollController() { | 23 OverscrollController::~OverscrollController() { |
27 } | 24 } |
28 | 25 |
29 OverscrollController::Disposition OverscrollController::DispatchEvent( | 26 OverscrollController::Disposition OverscrollController::DispatchEvent( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (overscroll_mode_ == OVERSCROLL_NONE) | 135 if (overscroll_mode_ == OVERSCROLL_NONE) |
139 return false; | 136 return false; |
140 | 137 |
141 // Complete the overscroll gesture if there was a mouse move or a scroll-end | 138 // Complete the overscroll gesture if there was a mouse move or a scroll-end |
142 // after the threshold. | 139 // after the threshold. |
143 if (event.type != WebKit::WebInputEvent::MouseMove && | 140 if (event.type != WebKit::WebInputEvent::MouseMove && |
144 event.type != WebKit::WebInputEvent::GestureScrollEnd && | 141 event.type != WebKit::WebInputEvent::GestureScrollEnd && |
145 event.type != WebKit::WebInputEvent::GestureFlingStart) | 142 event.type != WebKit::WebInputEvent::GestureFlingStart) |
146 return false; | 143 return false; |
147 | 144 |
148 RenderWidgetHostView* view = render_widget_host_->GetView(); | 145 DCHECK(delegate_); |
149 if (!view->IsShowing()) | 146 gfx::Rect bounds = delegate_->GetVisibleBounds(); |
150 return false; | |
151 | |
152 const gfx::Rect& bounds = view->GetViewBounds(); | |
153 if (bounds.IsEmpty()) | 147 if (bounds.IsEmpty()) |
154 return false; | 148 return false; |
155 | 149 |
156 if (event.type == WebKit::WebInputEvent::GestureFlingStart) { | 150 if (event.type == WebKit::WebInputEvent::GestureFlingStart) { |
157 // Check to see if the fling is in the same direction of the overscroll. | 151 // Check to see if the fling is in the same direction of the overscroll. |
158 const WebKit::WebGestureEvent gesture = | 152 const WebKit::WebGestureEvent gesture = |
159 static_cast<const WebKit::WebGestureEvent&>(event); | 153 static_cast<const WebKit::WebGestureEvent&>(event); |
160 switch (overscroll_mode_) { | 154 switch (overscroll_mode_) { |
161 case OVERSCROLL_EAST: | 155 case OVERSCROLL_EAST: |
162 if (gesture.data.flingStart.velocityX < 0) | 156 if (gesture.data.flingStart.velocityX < 0) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 overscroll_mode_ = mode; | 350 overscroll_mode_ = mode; |
357 if (overscroll_mode_ == OVERSCROLL_NONE) | 351 if (overscroll_mode_ == OVERSCROLL_NONE) |
358 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; | 352 overscroll_delta_x_ = overscroll_delta_y_ = 0.f; |
359 else | 353 else |
360 scroll_state_ = STATE_OVERSCROLLING; | 354 scroll_state_ = STATE_OVERSCROLLING; |
361 if (delegate_) | 355 if (delegate_) |
362 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); | 356 delegate_->OnOverscrollModeChange(old_mode, overscroll_mode_); |
363 } | 357 } |
364 | 358 |
365 } // namespace content | 359 } // namespace content |
OLD | NEW |