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

Side by Side Diff: content/renderer/render_widget.cc

Issue 1209043002: Bundle main thread overscroll data with event ack messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « content/renderer/render_widget.h ('k') | content/renderer/render_widget_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer/render_widget.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 next_paint_flags_(0), 484 next_paint_flags_(0),
485 auto_resize_mode_(false), 485 auto_resize_mode_(false),
486 need_update_rect_for_auto_resize_(false), 486 need_update_rect_for_auto_resize_(false),
487 did_show_(false), 487 did_show_(false),
488 is_hidden_(hidden), 488 is_hidden_(hidden),
489 never_visible_(never_visible), 489 never_visible_(never_visible),
490 is_fullscreen_granted_(false), 490 is_fullscreen_granted_(false),
491 display_mode_(blink::WebDisplayModeUndefined), 491 display_mode_(blink::WebDisplayModeUndefined),
492 has_focus_(false), 492 has_focus_(false),
493 handling_input_event_(false), 493 handling_input_event_(false),
494 handling_event_overscroll_(nullptr),
494 handling_ime_event_(false), 495 handling_ime_event_(false),
495 handling_event_type_(WebInputEvent::Undefined), 496 handling_event_type_(WebInputEvent::Undefined),
496 ignore_ack_for_mouse_move_from_debugger_(false), 497 ignore_ack_for_mouse_move_from_debugger_(false),
497 closing_(false), 498 closing_(false),
498 host_closing_(false), 499 host_closing_(false),
499 is_swapped_out_(swapped_out), 500 is_swapped_out_(swapped_out),
500 for_oopif_(false), 501 for_oopif_(false),
501 input_method_is_active_(false), 502 input_method_is_active_(false),
502 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 503 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
503 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 504 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 void RenderWidget::OnSwapBuffersComplete() { 1061 void RenderWidget::OnSwapBuffersComplete() {
1061 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); 1062 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
1062 1063
1063 // Notify subclasses that composited rendering was flushed to the screen. 1064 // Notify subclasses that composited rendering was flushed to the screen.
1064 DidFlushPaint(); 1065 DidFlushPaint();
1065 } 1066 }
1066 1067
1067 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, 1068 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
1068 const ui::LatencyInfo& latency_info, 1069 const ui::LatencyInfo& latency_info,
1069 bool is_keyboard_shortcut) { 1070 bool is_keyboard_shortcut) {
1070 base::AutoReset<bool> handling_input_event_resetter(
1071 &handling_input_event_, true);
1072 if (!input_event) 1071 if (!input_event)
1073 return; 1072 return;
1073 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1074 true);
1074 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( 1075 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1075 &handling_event_type_, input_event->type); 1076 &handling_event_type_, input_event->type);
1077
1078 // Calls into |didOverscroll()| while handling this event will populate
1079 // |event_overscroll|, which in turn will be bundled with the event ack.
1080 scoped_ptr<DidOverscrollParams> event_overscroll;
1081 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1082 handling_event_overscroll_resetter(&handling_event_overscroll_,
1083 &event_overscroll);
1084
1076 #if defined(OS_ANDROID) 1085 #if defined(OS_ANDROID)
1077 // On Android, when a key is pressed or sent from the Keyboard using IME, 1086 // On Android, when a key is pressed or sent from the Keyboard using IME,
1078 // |AdapterInputConnection| generates input key events to make sure all JS 1087 // |AdapterInputConnection| generates input key events to make sure all JS
1079 // listeners that monitor KeyUp and KeyDown events receive the proper key 1088 // listeners that monitor KeyUp and KeyDown events receive the proper key
1080 // code. Since this input key event comes from IME, we need to set the 1089 // code. Since this input key event comes from IME, we need to set the
1081 // IME event guard here to make sure it does not interfere with other IME 1090 // IME event guard here to make sure it does not interfere with other IME
1082 // events. 1091 // events.
1083 scoped_ptr<ImeEventGuard> ime_event_guard_maybe; 1092 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1084 if (WebInputEvent::isKeyboardEventType(input_event->type)) { 1093 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1085 const WebKeyboardEvent& key_event = 1094 const WebKeyboardEvent& key_event =
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 1228
1220 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); 1229 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1221 1230
1222 // Note that we can't use handling_event_type_ here since it will be overriden 1231 // Note that we can't use handling_event_type_ here since it will be overriden
1223 // by reentrant calls for events after the paused one. 1232 // by reentrant calls for events after the paused one.
1224 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ && 1233 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1225 input_event->type == WebInputEvent::MouseMove; 1234 input_event->type == WebInputEvent::MouseMove;
1226 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) && 1235 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1227 !no_ack) { 1236 !no_ack) {
1228 InputEventAck ack(input_event->type, ack_result, swap_latency_info, 1237 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
1238 event_overscroll.Pass(),
1229 WebInputEventTraits::GetUniqueTouchEventId(*input_event)); 1239 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
1230 scoped_ptr<IPC::Message> response( 1240 scoped_ptr<IPC::Message> response(
1231 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack)); 1241 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1232 if (rate_limiting_wanted && frame_pending && !is_hidden_) { 1242 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
1233 // We want to rate limit the input events in this case, so we'll wait for 1243 // We want to rate limit the input events in this case, so we'll wait for
1234 // painting to finish before ACKing this message. 1244 // painting to finish before ACKing this message.
1235 TRACE_EVENT_INSTANT0("renderer", 1245 TRACE_EVENT_INSTANT0("renderer",
1236 "RenderWidget::OnHandleInputEvent ack throttled", 1246 "RenderWidget::OnHandleInputEvent ack throttled",
1237 TRACE_EVENT_SCOPE_THREAD); 1247 TRACE_EVENT_SCOPE_THREAD);
1238 if (pending_input_event_ack_) { 1248 if (pending_input_event_ack_) {
1239 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck", 1249 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1240 pending_input_event_ack_.get()); 1250 pending_input_event_ack_.get());
1241 // As two different kinds of events could cause us to postpone an ack 1251 // As two different kinds of events could cause us to postpone an ack
1242 // we send it now, if we have one pending. The Browser should never 1252 // we send it now, if we have one pending. The Browser should never
1243 // send us the same kind of event we are delaying the ack for. 1253 // send us the same kind of event we are delaying the ack for.
1244 Send(pending_input_event_ack_.release()); 1254 Send(pending_input_event_ack_.release());
1245 } 1255 }
1246 pending_input_event_ack_ = response.Pass(); 1256 pending_input_event_ack_ = response.Pass();
1247 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck", 1257 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1248 pending_input_event_ack_.get()); 1258 pending_input_event_ack_.get());
1249 if (compositor_) 1259 if (compositor_)
1250 compositor_->NotifyInputThrottledUntilCommit(); 1260 compositor_->NotifyInputThrottledUntilCommit();
1251 } else { 1261 } else {
1252 Send(response.release()); 1262 Send(response.release());
1253 } 1263 }
1264 } else {
1265 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
1254 } 1266 }
1255 if (!no_ack && RenderThreadImpl::current()) { 1267 if (!no_ack && RenderThreadImpl::current()) {
1256 RenderThreadImpl::current() 1268 RenderThreadImpl::current()
1257 ->GetRendererScheduler() 1269 ->GetRendererScheduler()
1258 ->DidHandleInputEventOnMainThread(*input_event); 1270 ->DidHandleInputEventOnMainThread(*input_event);
1259 } 1271 }
1260 if (input_event->type == WebInputEvent::MouseMove) 1272 if (input_event->type == WebInputEvent::MouseMove)
1261 ignore_ack_for_mouse_move_from_debugger_ = false; 1273 ignore_ack_for_mouse_move_from_debugger_ = false;
1262 1274
1263 #if defined(OS_ANDROID) 1275 #if defined(OS_ANDROID)
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 } 2226 }
2215 #endif 2227 #endif
2216 } 2228 }
2217 2229
2218 void RenderWidget::didOverscroll( 2230 void RenderWidget::didOverscroll(
2219 const blink::WebFloatSize& unusedDelta, 2231 const blink::WebFloatSize& unusedDelta,
2220 const blink::WebFloatSize& accumulatedRootOverScroll, 2232 const blink::WebFloatSize& accumulatedRootOverScroll,
2221 const blink::WebFloatPoint& position, 2233 const blink::WebFloatPoint& position,
2222 const blink::WebFloatSize& velocity) { 2234 const blink::WebFloatSize& velocity) {
2223 DidOverscrollParams params; 2235 DidOverscrollParams params;
2224 // TODO(jdduke): Consider bundling the overscroll with the input event ack to
2225 // save an IPC.
2226 params.accumulated_overscroll = gfx::Vector2dF( 2236 params.accumulated_overscroll = gfx::Vector2dF(
2227 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height); 2237 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2228 params.latest_overscroll_delta = 2238 params.latest_overscroll_delta =
2229 gfx::Vector2dF(unusedDelta.width, unusedDelta.height); 2239 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
2230 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is 2240 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2231 // fixed. 2241 // fixed.
2232 params.current_fling_velocity = 2242 params.current_fling_velocity =
2233 gfx::Vector2dF(-velocity.width, -velocity.height); 2243 gfx::Vector2dF(-velocity.width, -velocity.height);
2234 params.causal_event_viewport_point = gfx::PointF(position.x, position.y); 2244 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
2245
2246 // If we're currently handling an event, stash the overscroll data such that
2247 // it can be bundled in the event ack.
2248 if (handling_event_overscroll_) {
2249 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2250 return;
2251 }
2252
2235 Send(new InputHostMsg_DidOverscroll(routing_id_, params)); 2253 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2236 } 2254 }
2237 2255
2238 void RenderWidget::StartCompositor() { 2256 void RenderWidget::StartCompositor() {
2239 // For widgets that are never visible, we don't need the compositor to run 2257 // For widgets that are never visible, we don't need the compositor to run
2240 // at all. 2258 // at all.
2241 if (never_visible_) 2259 if (never_visible_)
2242 return; 2260 return;
2243 // In tests without a RenderThreadImpl, don't set ready as this kicks 2261 // In tests without a RenderThreadImpl, don't set ready as this kicks
2244 // off creating output surfaces that the test can't create. 2262 // off creating output surfaces that the test can't create.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2473 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2456 video_hole_frames_.AddObserver(frame); 2474 video_hole_frames_.AddObserver(frame);
2457 } 2475 }
2458 2476
2459 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2477 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2460 video_hole_frames_.RemoveObserver(frame); 2478 video_hole_frames_.RemoveObserver(frame);
2461 } 2479 }
2462 #endif // defined(VIDEO_HOLE) 2480 #endif // defined(VIDEO_HOLE)
2463 2481
2464 } // namespace content 2482 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | content/renderer/render_widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698