Chromium Code Reviews| 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/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 auto_resize_enabled_(false), | 198 auto_resize_enabled_(false), |
| 199 waiting_for_screen_rects_ack_(false), | 199 waiting_for_screen_rects_ack_(false), |
| 200 needs_repainting_on_restore_(false), | 200 needs_repainting_on_restore_(false), |
| 201 is_unresponsive_(false), | 201 is_unresponsive_(false), |
| 202 in_flight_event_count_(0), | 202 in_flight_event_count_(0), |
| 203 in_get_backing_store_(false), | 203 in_get_backing_store_(false), |
| 204 ignore_input_events_(false), | 204 ignore_input_events_(false), |
| 205 text_direction_updated_(false), | 205 text_direction_updated_(false), |
| 206 text_direction_(blink::WebTextDirectionLeftToRight), | 206 text_direction_(blink::WebTextDirectionLeftToRight), |
| 207 text_direction_canceled_(false), | 207 text_direction_canceled_(false), |
| 208 suppress_next_char_events_(false), | 208 suppress_events_until_keydown_(false), |
| 209 pending_mouse_lock_request_(false), | 209 pending_mouse_lock_request_(false), |
| 210 allow_privileged_mouse_lock_(false), | 210 allow_privileged_mouse_lock_(false), |
| 211 has_touch_handler_(false), | 211 has_touch_handler_(false), |
| 212 is_in_touchpad_gesture_scroll_(false), | 212 is_in_touchpad_gesture_scroll_(false), |
| 213 is_in_touchscreen_gesture_scroll_(false), | 213 is_in_touchscreen_gesture_scroll_(false), |
| 214 received_paint_after_load_(false), | 214 received_paint_after_load_(false), |
| 215 next_browser_snapshot_id_(1), | 215 next_browser_snapshot_id_(1), |
| 216 owned_by_render_frame_host_(false), | 216 owned_by_render_frame_host_(false), |
| 217 is_focused_(false), | 217 is_focused_(false), |
| 218 hung_renderer_delay_( | 218 hung_renderer_delay_( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 if (!view_) | 380 if (!view_) |
| 381 return; | 381 return; |
| 382 | 382 |
| 383 last_view_screen_rect_ = view_->GetViewBounds(); | 383 last_view_screen_rect_ = view_->GetViewBounds(); |
| 384 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); | 384 last_window_screen_rect_ = view_->GetBoundsInRootWindow(); |
| 385 Send(new ViewMsg_UpdateScreenRects( | 385 Send(new ViewMsg_UpdateScreenRects( |
| 386 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); | 386 GetRoutingID(), last_view_screen_rect_, last_window_screen_rect_)); |
| 387 waiting_for_screen_rects_ack_ = true; | 387 waiting_for_screen_rects_ack_ = true; |
| 388 } | 388 } |
| 389 | 389 |
| 390 void RenderWidgetHostImpl::SuppressNextCharEvents() { | 390 void RenderWidgetHostImpl::SuppressEventsUntilKeyDown() { |
| 391 suppress_next_char_events_ = true; | 391 suppress_events_until_keydown_ = true; |
| 392 } | 392 } |
| 393 | 393 |
| 394 void RenderWidgetHostImpl::FlushInput() { | 394 void RenderWidgetHostImpl::FlushInput() { |
| 395 input_router_->RequestNotificationWhenFlushed(); | 395 input_router_->RequestNotificationWhenFlushed(); |
| 396 if (synthetic_gesture_controller_) | 396 if (synthetic_gesture_controller_) |
| 397 synthetic_gesture_controller_->Flush(base::TimeTicks::Now()); | 397 synthetic_gesture_controller_->Flush(base::TimeTicks::Now()); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void RenderWidgetHostImpl::SetNeedsFlush() { | 400 void RenderWidgetHostImpl::SetNeedsFlush() { |
| 401 if (view_) | 401 if (view_) |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 | 1111 |
| 1112 if (ShouldDropInputEvents()) | 1112 if (ShouldDropInputEvents()) |
| 1113 return; | 1113 return; |
| 1114 | 1114 |
| 1115 if (!process_->HasConnection()) | 1115 if (!process_->HasConnection()) |
| 1116 return; | 1116 return; |
| 1117 | 1117 |
| 1118 // First, let keypress listeners take a shot at handling the event. If a | 1118 // First, let keypress listeners take a shot at handling the event. If a |
| 1119 // listener handles the event, it should not be propagated to the renderer. | 1119 // listener handles the event, it should not be propagated to the renderer. |
| 1120 if (KeyPressListenersHandleEvent(key_event)) { | 1120 if (KeyPressListenersHandleEvent(key_event)) { |
| 1121 // Some keypresses that are accepted by the listener might have follow up | 1121 // Some keypresses that are accepted by the listener may be followed by Char |
|
dtapuska
2016/11/08 15:18:03
I guess the odd thing is that on platforms that ge
foolip
2016/11/08 15:23:15
I didn't try to understand the split between RawKe
| |
| 1122 // char events, which should be ignored. | 1122 // and KeyUp events, which should be ignored. |
| 1123 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1123 if (key_event.type == WebKeyboardEvent::RawKeyDown) |
| 1124 suppress_next_char_events_ = true; | 1124 suppress_events_until_keydown_ = true; |
| 1125 return; | 1125 return; |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 // Double check the type to make sure caller hasn't sent us nonsense that | 1128 // Double check the type to make sure caller hasn't sent us nonsense that |
| 1129 // will mess up our key queue. | 1129 // will mess up our key queue. |
| 1130 if (!WebInputEvent::isKeyboardEventType(key_event.type)) | 1130 if (!WebInputEvent::isKeyboardEventType(key_event.type)) |
| 1131 return; | 1131 return; |
| 1132 | 1132 |
| 1133 if (suppress_next_char_events_) { | 1133 if (suppress_events_until_keydown_) { |
| 1134 // If preceding RawKeyDown event was handled by the browser, then we need | 1134 // If the preceding RawKeyDown event was handled by the browser, then we |
| 1135 // suppress all Char events generated by it. Please note that, one | 1135 // need to suppress all events generated by it until the next RawKeyDown or |
| 1136 // RawKeyDown event may generate multiple Char events, so we can't reset | 1136 // KeyDown event. |
| 1137 // |suppress_next_char_events_| until we get a KeyUp or a RawKeyDown. | 1137 if (key_event.type == WebKeyboardEvent::KeyUp || |
| 1138 if (key_event.type == WebKeyboardEvent::Char) | 1138 key_event.type == WebKeyboardEvent::Char) |
| 1139 return; | 1139 return; |
| 1140 // We get a KeyUp or a RawKeyDown event. | 1140 DCHECK(key_event.type == WebKeyboardEvent::RawKeyDown || |
| 1141 suppress_next_char_events_ = false; | 1141 key_event.type == WebKeyboardEvent::KeyDown); |
| 1142 suppress_events_until_keydown_ = false; | |
| 1142 } | 1143 } |
| 1143 | 1144 |
| 1144 bool is_shortcut = false; | 1145 bool is_shortcut = false; |
| 1145 | 1146 |
| 1146 // Only pre-handle the key event if it's not handled by the input method. | 1147 // Only pre-handle the key event if it's not handled by the input method. |
| 1147 if (delegate_ && !key_event.skip_in_browser) { | 1148 if (delegate_ && !key_event.skip_in_browser) { |
| 1148 // We need to set |suppress_next_char_events_| to true if | 1149 // We need to set |suppress_events_until_keydown_| to true if |
| 1149 // PreHandleKeyboardEvent() returns true, but |this| may already be | 1150 // PreHandleKeyboardEvent() returns true, but |this| may already be |
| 1150 // destroyed at that time. So set |suppress_next_char_events_| true here, | 1151 // destroyed at that time. So set |suppress_events_until_keydown_| true |
| 1151 // then revert it afterwards when necessary. | 1152 // here, then revert it afterwards when necessary. |
| 1152 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1153 if (key_event.type == WebKeyboardEvent::RawKeyDown) |
| 1153 suppress_next_char_events_ = true; | 1154 suppress_events_until_keydown_ = true; |
| 1154 | 1155 |
| 1155 // Tab switching/closing accelerators aren't sent to the renderer to avoid | 1156 // Tab switching/closing accelerators aren't sent to the renderer to avoid |
| 1156 // a hung/malicious renderer from interfering. | 1157 // a hung/malicious renderer from interfering. |
| 1157 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) | 1158 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) |
| 1158 return; | 1159 return; |
| 1159 | 1160 |
| 1160 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1161 if (key_event.type == WebKeyboardEvent::RawKeyDown) |
| 1161 suppress_next_char_events_ = false; | 1162 suppress_events_until_keydown_ = false; |
| 1162 } | 1163 } |
| 1163 | 1164 |
| 1164 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) | 1165 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) |
| 1165 return; | 1166 return; |
| 1166 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); | 1167 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); |
| 1167 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event, | 1168 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event, |
| 1168 latency_info); | 1169 latency_info); |
| 1169 key_event_with_latency.event.isBrowserShortcut = is_shortcut; | 1170 key_event_with_latency.event.isBrowserShortcut = is_shortcut; |
| 1170 DispatchInputEventWithLatencyInfo(key_event, &key_event_with_latency.latency); | 1171 DispatchInputEventWithLatencyInfo(key_event, &key_event_with_latency.latency); |
| 1171 input_router_->SendKeyboardEvent(key_event_with_latency); | 1172 input_router_->SendKeyboardEvent(key_event_with_latency); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1343 if (!renderer_initialized_) | 1344 if (!renderer_initialized_) |
| 1344 return; | 1345 return; |
| 1345 | 1346 |
| 1346 // Clearing this flag causes us to re-create the renderer when recovering | 1347 // Clearing this flag causes us to re-create the renderer when recovering |
| 1347 // from a crashed renderer. | 1348 // from a crashed renderer. |
| 1348 renderer_initialized_ = false; | 1349 renderer_initialized_ = false; |
| 1349 | 1350 |
| 1350 waiting_for_screen_rects_ack_ = false; | 1351 waiting_for_screen_rects_ack_ = false; |
| 1351 | 1352 |
| 1352 // Must reset these to ensure that keyboard events work with a new renderer. | 1353 // Must reset these to ensure that keyboard events work with a new renderer. |
| 1353 suppress_next_char_events_ = false; | 1354 suppress_events_until_keydown_ = false; |
| 1354 | 1355 |
| 1355 // Reset some fields in preparation for recovering from a crash. | 1356 // Reset some fields in preparation for recovering from a crash. |
| 1356 ResetSizeAndRepaintPendingFlags(); | 1357 ResetSizeAndRepaintPendingFlags(); |
| 1357 current_size_.SetSize(0, 0); | 1358 current_size_.SetSize(0, 0); |
| 1358 // After the renderer crashes, the view is destroyed and so the | 1359 // After the renderer crashes, the view is destroyed and so the |
| 1359 // RenderWidgetHost cannot track its visibility anymore. We assume such | 1360 // RenderWidgetHost cannot track its visibility anymore. We assume such |
| 1360 // RenderWidgetHost to be invisible for the sake of internal accounting - be | 1361 // RenderWidgetHost to be invisible for the sake of internal accounting - be |
| 1361 // careful about changing this - see http://crbug.com/401859 and | 1362 // careful about changing this - see http://crbug.com/401859 and |
| 1362 // http://crbug.com/522795. | 1363 // http://crbug.com/522795. |
| 1363 // | 1364 // |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1996 } | 1997 } |
| 1997 | 1998 |
| 1998 if (view_) | 1999 if (view_) |
| 1999 view_->ProcessAckedTouchEvent(event, ack_result); | 2000 view_->ProcessAckedTouchEvent(event, ack_result); |
| 2000 } | 2001 } |
| 2001 | 2002 |
| 2002 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { | 2003 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { |
| 2003 if (type == BAD_ACK_MESSAGE) { | 2004 if (type == BAD_ACK_MESSAGE) { |
| 2004 bad_message::ReceivedBadMessage(process_, bad_message::RWH_BAD_ACK_MESSAGE); | 2005 bad_message::ReceivedBadMessage(process_, bad_message::RWH_BAD_ACK_MESSAGE); |
| 2005 } else if (type == UNEXPECTED_EVENT_TYPE) { | 2006 } else if (type == UNEXPECTED_EVENT_TYPE) { |
| 2006 suppress_next_char_events_ = false; | 2007 suppress_events_until_keydown_ = false; |
| 2007 } | 2008 } |
| 2008 } | 2009 } |
| 2009 | 2010 |
| 2010 void RenderWidgetHostImpl::OnSyntheticGestureCompleted( | 2011 void RenderWidgetHostImpl::OnSyntheticGestureCompleted( |
| 2011 SyntheticGesture::Result result) { | 2012 SyntheticGesture::Result result) { |
| 2012 Send(new InputMsg_SyntheticGestureCompleted(GetRoutingID())); | 2013 Send(new InputMsg_SyntheticGestureCompleted(GetRoutingID())); |
| 2013 } | 2014 } |
| 2014 | 2015 |
| 2015 bool RenderWidgetHostImpl::ShouldDropInputEvents() const { | 2016 bool RenderWidgetHostImpl::ShouldDropInputEvents() const { |
| 2016 return ignore_input_events_ || process_->IgnoreInputEvents() || !delegate_; | 2017 return ignore_input_events_ || process_->IgnoreInputEvents() || !delegate_; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2207 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; | 2208 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; |
| 2208 } | 2209 } |
| 2209 | 2210 |
| 2210 BrowserAccessibilityManager* | 2211 BrowserAccessibilityManager* |
| 2211 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { | 2212 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { |
| 2212 return delegate_ ? | 2213 return delegate_ ? |
| 2213 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; | 2214 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
| 2214 } | 2215 } |
| 2215 | 2216 |
| 2216 } // namespace content | 2217 } // namespace content |
| OLD | NEW |