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

Unified Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 11858007: Splits SmoothGestureController from RenderWidgetHostImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Single smooth scroll Created 7 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_impl.cc
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index e81f0f3483598c5f739428f7288904567e3350cf..2c7aa1f7a7686527ca2f28eb7e731a27a91250da 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -29,6 +29,7 @@
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_helper.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h"
+#include "content/browser/renderer_host/smooth_scroll_gesture_controller.h"
#include "content/browser/renderer_host/tap_suppression_controller.h"
#include "content/browser/renderer_host/touch_event_queue.h"
#include "content/common/accessibility_messages.h"
@@ -36,7 +37,6 @@
#include "content/common/gpu/gpu_messages.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_widget_host_view_port.h"
-#include "content/port/browser/smooth_scroll_gesture.h"
#include "content/public/browser/compositor_util.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h"
@@ -87,9 +87,6 @@ namespace {
// This timeout impacts the "choppiness" of our window resize perf.
const int kPaintMsgTimeoutMS = 50;
-// How many milliseconds apart synthetic scroll messages should be sent.
-static const int kSyntheticScrollMessageIntervalMs = 8;
-
// Returns |true| if the two wheel events should be coalesced.
bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event,
const WebMouseWheelEvent& new_event) {
@@ -177,7 +174,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
allow_privileged_mouse_lock_(false),
has_touch_handler_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
- tick_active_smooth_scroll_gestures_task_posted_(false),
+ smooth_scroll_gesture_controller_(new SmoothScrollGestureController()),
touch_event_queue_(new TouchEventQueue(this)),
gesture_event_filter_(new GestureEventFilter(this)),
touch_event_state_(INPUT_EVENT_ACK_STATE_UNKNOWN) {
@@ -305,7 +302,7 @@ void RenderWidgetHostImpl::SendScreenRects() {
}
int RenderWidgetHostImpl::SyntheticScrollMessageInterval() const {
- return kSyntheticScrollMessageIntervalMs;
+ return smooth_scroll_gesture_controller_->SyntheticScrollMessageInterval();
}
void RenderWidgetHostImpl::SetOverscrollControllerEnabled(bool enabled) {
@@ -1211,6 +1208,7 @@ void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event,
}
in_process_event_types_.push(input_event.type);
+ smooth_scroll_gesture_controller_->OnForwardInputEvent();
rjkroege 2013/02/21 19:26:33 In the SmoothScrollGestureController, you say that
bulach 2013/02/22 16:55:14 Done.
// Transmit any pending wheel events on a non-wheel event. This ensures that
// the renderer receives the final PhaseEnded wheel event, which is necessary
@@ -1771,11 +1769,7 @@ void RenderWidgetHostImpl::OnInputEventAck(
if (decrement_in_flight_event_count() == 0)
StopHangMonitorTimeout();
- // If an input ack is pending, then hold off ticking the gesture
- // until we get an input ack.
- if (in_process_event_types_.empty() &&
- !active_smooth_scroll_gestures_.empty())
- TickActiveSmoothScrollGesture();
+ smooth_scroll_gesture_controller_->OnInputEventACK(this);
int type = static_cast<int>(event_type);
if (type < WebInputEvent::Undefined) {
@@ -1815,89 +1809,12 @@ void RenderWidgetHostImpl::OnInputEventAck(
}
void RenderWidgetHostImpl::OnBeginSmoothScroll(
- int gesture_id, const ViewHostMsg_BeginSmoothScroll_Params &params) {
+ const ViewHostMsg_BeginSmoothScroll_Params& params,
+ bool* smooth_scroll_started) {
if (!view_)
return;
- active_smooth_scroll_gestures_.insert(
- std::make_pair(gesture_id,
- view_->CreateSmoothScrollGesture(
- params.scroll_down, params.pixels_to_scroll,
- params.mouse_event_x, params.mouse_event_y)));
-
- // If an input ack is pending, then hold off ticking the gesture
- // until we get an input ack.
- if (!in_process_event_types_.empty())
- return;
- if (tick_active_smooth_scroll_gestures_task_posted_)
- return;
- TickActiveSmoothScrollGesture();
-}
-
-void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() {
- TRACE_EVENT0("input", "RenderWidgetHostImpl::TickActiveSmoothScrollGesture");
- tick_active_smooth_scroll_gestures_task_posted_ = false;
- if (active_smooth_scroll_gestures_.empty()) {
- TRACE_EVENT_INSTANT0("input", "EarlyOut_NoActiveScrollGesture");
- return;
- }
-
- base::TimeTicks now = TimeTicks::HighResNow();
- base::TimeDelta preferred_interval =
- base::TimeDelta::FromMilliseconds(kSyntheticScrollMessageIntervalMs);
- base::TimeDelta time_until_next_ideal_interval =
- (last_smooth_scroll_gestures_tick_time_ + preferred_interval) -
- now;
- if (time_until_next_ideal_interval.InMilliseconds() > 0) {
- TRACE_EVENT_INSTANT1(
- "input", "EarlyOut_TickedTooRecently",
- "delay", time_until_next_ideal_interval.InMilliseconds());
- // Post a task.
- tick_active_smooth_scroll_gestures_task_posted_ = true;
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture,
- weak_factory_.GetWeakPtr()),
- time_until_next_ideal_interval);
- return;
- }
-
- last_smooth_scroll_gestures_tick_time_ = now;
-
- // Separate ticking of gestures from sending their completion messages.
- std::vector<int> ids_that_are_done;
- for (SmoothScrollGestureMap::iterator it =
- active_smooth_scroll_gestures_.begin();
- it != active_smooth_scroll_gestures_.end();
- ++it) {
-
- bool active = it->second->ForwardInputEvents(now, this);
- if (!active)
- ids_that_are_done.push_back(it->first);
- }
-
- // Delete completed gestures and send their completion event.
- for(size_t i = 0; i < ids_that_are_done.size(); i++) {
- int id = ids_that_are_done[i];
- SmoothScrollGestureMap::iterator it =
- active_smooth_scroll_gestures_.find(id);
- DCHECK(it != active_smooth_scroll_gestures_.end());
- active_smooth_scroll_gestures_.erase(it);
-
- Send(new ViewMsg_SmoothScrollCompleted(routing_id_, id));
- }
-
- // No need to post the next tick if an input is in flight.
- if (!in_process_event_types_.empty())
- return;
-
- TRACE_EVENT_INSTANT1("input", "PostTickTask",
- "delay", preferred_interval.InMilliseconds());
- tick_active_smooth_scroll_gestures_task_posted_ = true;
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&RenderWidgetHostImpl::TickActiveSmoothScrollGesture,
- weak_factory_.GetWeakPtr()),
- preferred_interval);
+ *smooth_scroll_started =
+ smooth_scroll_gesture_controller_->OnBeginSmoothScroll(view_, params);
}
void RenderWidgetHostImpl::OnSelectRangeAck() {

Powered by Google App Engine
This is Rietveld 408576698