Commit c95e53ad authored by husky@chromium.org's avatar husky@chromium.org

Throttle SelectRange IPC

This code is used by the Android port. We add a SelectRange_ACK to
throttle the rate at which the selection changes. Without throttling,
the selection handle updates can fall behind the user's touch input.

BUG=138939


Review URL: https://chromiumcodereview.appspot.com/10823077

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151304 0039d316-1c4b-4281-b951-d872f2087c98
parent 284b03c2
...@@ -130,6 +130,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, ...@@ -130,6 +130,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
should_auto_resize_(false), should_auto_resize_(false),
mouse_move_pending_(false), mouse_move_pending_(false),
mouse_wheel_pending_(false), mouse_wheel_pending_(false),
select_range_pending_(false),
needs_repainting_on_restore_(false), needs_repainting_on_restore_(false),
is_unresponsive_(false), is_unresponsive_(false),
in_flight_event_count_(0), in_flight_event_count_(0),
...@@ -285,6 +286,7 @@ bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { ...@@ -285,6 +286,7 @@ bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) {
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnMsgUpdateIsDelayed) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnMsgUpdateIsDelayed)
IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck)
IPC_MESSAGE_HANDLER(ViewHostMsg_BeginSmoothScroll, OnMsgBeginSmoothScroll) IPC_MESSAGE_HANDLER(ViewHostMsg_BeginSmoothScroll, OnMsgBeginSmoothScroll)
IPC_MESSAGE_HANDLER(ViewHostMsg_SelectRange_ACK, OnMsgSelectRangeAck)
IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus)
IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur)
IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
...@@ -1083,6 +1085,10 @@ void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status, ...@@ -1083,6 +1085,10 @@ void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status,
mouse_wheel_pending_ = false; mouse_wheel_pending_ = false;
coalesced_mouse_wheel_events_.clear(); coalesced_mouse_wheel_events_.clear();
// Must reset these to ensure that SelectRange works with a new renderer.
select_range_pending_ = false;
next_selection_range_.reset();
// Must reset these to ensure that gesture events work with a new renderer. // Must reset these to ensure that gesture events work with a new renderer.
gesture_event_filter_->Reset(); gesture_event_filter_->Reset();
...@@ -1586,6 +1592,14 @@ void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() { ...@@ -1586,6 +1592,14 @@ void RenderWidgetHostImpl::TickActiveSmoothScrollGesture() {
} }
} }
void RenderWidgetHostImpl::OnMsgSelectRangeAck() {
select_range_pending_ = false;
if (next_selection_range_.get()) {
scoped_ptr<SelectionRange> next(next_selection_range_.Pass());
SelectRange(next->start, next->end);
}
}
void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { void RenderWidgetHostImpl::ProcessWheelAck(bool processed) {
mouse_wheel_pending_ = false; mouse_wheel_pending_ = false;
...@@ -1878,6 +1892,16 @@ void RenderWidgetHostImpl::ScrollFocusedEditableNodeIntoRect( ...@@ -1878,6 +1892,16 @@ void RenderWidgetHostImpl::ScrollFocusedEditableNodeIntoRect(
void RenderWidgetHostImpl::SelectRange(const gfx::Point& start, void RenderWidgetHostImpl::SelectRange(const gfx::Point& start,
const gfx::Point& end) { const gfx::Point& end) {
if (select_range_pending_) {
if (!next_selection_range_.get()) {
next_selection_range_.reset(new SelectionRange());
}
next_selection_range_->start = start;
next_selection_range_->end = end;
return;
}
select_range_pending_ = true;
Send(new ViewMsg_SelectRange(GetRoutingID(), start, end)); Send(new ViewMsg_SelectRange(GetRoutingID(), start, end));
} }
......
...@@ -505,6 +505,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, ...@@ -505,6 +505,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
void OnMsgInputEventAck(WebKit::WebInputEvent::Type event_type, void OnMsgInputEventAck(WebKit::WebInputEvent::Type event_type,
bool processed); bool processed);
void OnMsgBeginSmoothScroll(bool scroll_down, bool scroll_far); void OnMsgBeginSmoothScroll(bool scroll_down, bool scroll_far);
void OnMsgSelectRangeAck();
virtual void OnMsgFocus(); virtual void OnMsgFocus();
virtual void OnMsgBlur(); virtual void OnMsgBlur();
void OnMsgHasTouchEventHandlers(bool has_handlers); void OnMsgHasTouchEventHandlers(bool has_handlers);
...@@ -681,6 +682,15 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, ...@@ -681,6 +682,15 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
// would be queued) results in very slow scrolling. // would be queued) results in very slow scrolling.
WheelEventQueue coalesced_mouse_wheel_events_; WheelEventQueue coalesced_mouse_wheel_events_;
// (Similar to |mouse_move_pending_|.) True while waiting for SelectRange_ACK.
bool select_range_pending_;
// (Similar to |next_mouse_move_|.) The next SelectRange to send, if any.
struct SelectionRange {
gfx::Point start, end;
};
scoped_ptr<SelectionRange> next_selection_range_;
// The time when an input event was sent to the RenderWidget. // The time when an input event was sent to the RenderWidget.
base::TimeTicks input_event_start_time_; base::TimeTicks input_event_start_time_;
......
...@@ -978,6 +978,7 @@ IPC_MESSAGE_ROUTED0(ViewMsg_SelectAll) ...@@ -978,6 +978,7 @@ IPC_MESSAGE_ROUTED0(ViewMsg_SelectAll)
IPC_MESSAGE_ROUTED0(ViewMsg_Unselect) IPC_MESSAGE_ROUTED0(ViewMsg_Unselect)
// Requests the renderer to select the region between two points. // Requests the renderer to select the region between two points.
// Expects a SelectRange_ACK message when finished.
IPC_MESSAGE_ROUTED2(ViewMsg_SelectRange, IPC_MESSAGE_ROUTED2(ViewMsg_SelectRange,
gfx::Point /* start */, gfx::Point /* start */,
gfx::Point /* end */) gfx::Point /* end */)
...@@ -1841,6 +1842,8 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_SetTooltipText, ...@@ -1841,6 +1842,8 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_SetTooltipText,
string16 /* tooltip text string */, string16 /* tooltip text string */,
WebKit::WebTextDirection /* text direction hint */) WebKit::WebTextDirection /* text direction hint */)
IPC_MESSAGE_ROUTED0(ViewHostMsg_SelectRange_ACK)
// Notification that the text selection has changed. // Notification that the text selection has changed.
// Note: The secound parameter is the character based offset of the string16 // Note: The secound parameter is the character based offset of the string16
// text in the document. // text in the document.
......
...@@ -1297,6 +1297,8 @@ void RenderViewImpl::OnSelectRange(const gfx::Point& start, ...@@ -1297,6 +1297,8 @@ void RenderViewImpl::OnSelectRange(const gfx::Point& start,
if (!webview()) if (!webview())
return; return;
Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
handling_select_range_ = true; handling_select_range_ = true;
webview()->focusedFrame()->selectRange(start, end); webview()->focusedFrame()->selectRange(start, end);
handling_select_range_ = false; handling_select_range_ = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment