| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 std::vector<RenderWidgetHostID> hosts_; | 155 std::vector<RenderWidgetHostID> hosts_; |
| 156 size_t current_index_; | 156 size_t current_index_; |
| 157 | 157 |
| 158 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostIteratorImpl); | 158 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostIteratorImpl); |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 inline blink::WebGestureEvent CreateScrollBeginForWrapping( | 161 inline blink::WebGestureEvent CreateScrollBeginForWrapping( |
| 162 const blink::WebGestureEvent& gesture_event) { | 162 const blink::WebGestureEvent& gesture_event) { |
| 163 DCHECK(gesture_event.type == blink::WebInputEvent::GestureScrollUpdate); | 163 DCHECK(gesture_event.type() == blink::WebInputEvent::GestureScrollUpdate); |
| 164 | 164 |
| 165 blink::WebGestureEvent wrap_gesture_scroll_begin( | 165 blink::WebGestureEvent wrap_gesture_scroll_begin( |
| 166 blink::WebInputEvent::GestureScrollBegin, gesture_event.modifiers, | 166 blink::WebInputEvent::GestureScrollBegin, gesture_event.modifiers(), |
| 167 gesture_event.timeStampSeconds); | 167 gesture_event.timeStampSeconds()); |
| 168 wrap_gesture_scroll_begin.sourceDevice = gesture_event.sourceDevice; | 168 wrap_gesture_scroll_begin.sourceDevice = gesture_event.sourceDevice; |
| 169 wrap_gesture_scroll_begin.data.scrollBegin.deltaXHint = 0; | 169 wrap_gesture_scroll_begin.data.scrollBegin.deltaXHint = 0; |
| 170 wrap_gesture_scroll_begin.data.scrollBegin.deltaYHint = 0; | 170 wrap_gesture_scroll_begin.data.scrollBegin.deltaYHint = 0; |
| 171 wrap_gesture_scroll_begin.resendingPluginId = gesture_event.resendingPluginId; | 171 wrap_gesture_scroll_begin.resendingPluginId = gesture_event.resendingPluginId; |
| 172 wrap_gesture_scroll_begin.data.scrollBegin.deltaHintUnits = | 172 wrap_gesture_scroll_begin.data.scrollBegin.deltaHintUnits = |
| 173 gesture_event.data.scrollUpdate.deltaUnits; | 173 gesture_event.data.scrollUpdate.deltaUnits; |
| 174 | 174 |
| 175 return wrap_gesture_scroll_begin; | 175 return wrap_gesture_scroll_begin; |
| 176 } | 176 } |
| 177 | 177 |
| 178 inline blink::WebGestureEvent CreateScrollEndForWrapping( | 178 inline blink::WebGestureEvent CreateScrollEndForWrapping( |
| 179 const blink::WebGestureEvent& gesture_event) { | 179 const blink::WebGestureEvent& gesture_event) { |
| 180 DCHECK(gesture_event.type == blink::WebInputEvent::GestureScrollUpdate); | 180 DCHECK(gesture_event.type() == blink::WebInputEvent::GestureScrollUpdate); |
| 181 | 181 |
| 182 blink::WebGestureEvent wrap_gesture_scroll_end( | 182 blink::WebGestureEvent wrap_gesture_scroll_end( |
| 183 blink::WebInputEvent::GestureScrollEnd, gesture_event.modifiers, | 183 blink::WebInputEvent::GestureScrollEnd, gesture_event.modifiers(), |
| 184 gesture_event.timeStampSeconds); | 184 gesture_event.timeStampSeconds()); |
| 185 wrap_gesture_scroll_end.sourceDevice = gesture_event.sourceDevice; | 185 wrap_gesture_scroll_end.sourceDevice = gesture_event.sourceDevice; |
| 186 wrap_gesture_scroll_end.resendingPluginId = gesture_event.resendingPluginId; | 186 wrap_gesture_scroll_end.resendingPluginId = gesture_event.resendingPluginId; |
| 187 wrap_gesture_scroll_end.data.scrollEnd.deltaUnits = | 187 wrap_gesture_scroll_end.data.scrollEnd.deltaUnits = |
| 188 gesture_event.data.scrollUpdate.deltaUnits; | 188 gesture_event.data.scrollUpdate.deltaUnits; |
| 189 | 189 |
| 190 return wrap_gesture_scroll_end; | 190 return wrap_gesture_scroll_end; |
| 191 } | 191 } |
| 192 | 192 |
| 193 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) { | 193 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) { |
| 194 std::vector<DropData::Metadata> metadata; | 194 std::vector<DropData::Metadata> metadata; |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 return; | 1099 return; |
| 1100 | 1100 |
| 1101 // TODO(wjmaclean) Remove the code for supporting resending gesture events | 1101 // TODO(wjmaclean) Remove the code for supporting resending gesture events |
| 1102 // when WebView transitions to OOPIF and BrowserPlugin is removed. | 1102 // when WebView transitions to OOPIF and BrowserPlugin is removed. |
| 1103 // http://crbug.com/533069 | 1103 // http://crbug.com/533069 |
| 1104 bool* is_in_gesture_scroll = | 1104 bool* is_in_gesture_scroll = |
| 1105 gesture_event.sourceDevice == | 1105 gesture_event.sourceDevice == |
| 1106 blink::WebGestureDevice::WebGestureDeviceTouchpad | 1106 blink::WebGestureDevice::WebGestureDeviceTouchpad |
| 1107 ? &is_in_touchpad_gesture_scroll_ | 1107 ? &is_in_touchpad_gesture_scroll_ |
| 1108 : &is_in_touchscreen_gesture_scroll_; | 1108 : &is_in_touchscreen_gesture_scroll_; |
| 1109 if (gesture_event.type == blink::WebInputEvent::GestureScrollBegin) { | 1109 if (gesture_event.type() == blink::WebInputEvent::GestureScrollBegin) { |
| 1110 DCHECK(!(*is_in_gesture_scroll)); | 1110 DCHECK(!(*is_in_gesture_scroll)); |
| 1111 *is_in_gesture_scroll = true; | 1111 *is_in_gesture_scroll = true; |
| 1112 } else if (gesture_event.type == blink::WebInputEvent::GestureScrollEnd || | 1112 } else if (gesture_event.type() == blink::WebInputEvent::GestureScrollEnd || |
| 1113 gesture_event.type == blink::WebInputEvent::GestureFlingStart) { | 1113 gesture_event.type() == blink::WebInputEvent::GestureFlingStart) { |
| 1114 DCHECK(*is_in_gesture_scroll || | 1114 DCHECK(*is_in_gesture_scroll || |
| 1115 (gesture_event.type == blink::WebInputEvent::GestureFlingStart && | 1115 (gesture_event.type() == blink::WebInputEvent::GestureFlingStart && |
| 1116 gesture_event.sourceDevice == | 1116 gesture_event.sourceDevice == |
| 1117 blink::WebGestureDevice::WebGestureDeviceTouchpad)); | 1117 blink::WebGestureDevice::WebGestureDeviceTouchpad)); |
| 1118 *is_in_gesture_scroll = false; | 1118 *is_in_gesture_scroll = false; |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 bool scroll_update_needs_wrapping = | 1121 bool scroll_update_needs_wrapping = |
| 1122 gesture_event.type == blink::WebInputEvent::GestureScrollUpdate && | 1122 gesture_event.type() == blink::WebInputEvent::GestureScrollUpdate && |
| 1123 gesture_event.resendingPluginId != -1 && !(*is_in_gesture_scroll); | 1123 gesture_event.resendingPluginId != -1 && !(*is_in_gesture_scroll); |
| 1124 | 1124 |
| 1125 // TODO(crbug.com/544782): Fix WebViewGuestScrollTest.TestGuestWheelScrolls- | 1125 // TODO(crbug.com/544782): Fix WebViewGuestScrollTest.TestGuestWheelScrolls- |
| 1126 // Bubble to test the resending logic of gesture events. | 1126 // Bubble to test the resending logic of gesture events. |
| 1127 if (scroll_update_needs_wrapping) { | 1127 if (scroll_update_needs_wrapping) { |
| 1128 ForwardGestureEventWithLatencyInfo( | 1128 ForwardGestureEventWithLatencyInfo( |
| 1129 CreateScrollBeginForWrapping(gesture_event), | 1129 CreateScrollBeginForWrapping(gesture_event), |
| 1130 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( | 1130 ui::WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( |
| 1131 gesture_event)); | 1131 gesture_event)); |
| 1132 } | 1132 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 return; | 1191 return; |
| 1192 | 1192 |
| 1193 if (!process_->HasConnection()) | 1193 if (!process_->HasConnection()) |
| 1194 return; | 1194 return; |
| 1195 | 1195 |
| 1196 // First, let keypress listeners take a shot at handling the event. If a | 1196 // First, let keypress listeners take a shot at handling the event. If a |
| 1197 // listener handles the event, it should not be propagated to the renderer. | 1197 // listener handles the event, it should not be propagated to the renderer. |
| 1198 if (KeyPressListenersHandleEvent(key_event)) { | 1198 if (KeyPressListenersHandleEvent(key_event)) { |
| 1199 // Some keypresses that are accepted by the listener may be followed by Char | 1199 // Some keypresses that are accepted by the listener may be followed by Char |
| 1200 // and KeyUp events, which should be ignored. | 1200 // and KeyUp events, which should be ignored. |
| 1201 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1201 if (key_event.type() == WebKeyboardEvent::RawKeyDown) |
| 1202 suppress_events_until_keydown_ = true; | 1202 suppress_events_until_keydown_ = true; |
| 1203 return; | 1203 return; |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 // Double check the type to make sure caller hasn't sent us nonsense that | 1206 // Double check the type to make sure caller hasn't sent us nonsense that |
| 1207 // will mess up our key queue. | 1207 // will mess up our key queue. |
| 1208 if (!WebInputEvent::isKeyboardEventType(key_event.type)) | 1208 if (!WebInputEvent::isKeyboardEventType(key_event.type())) |
| 1209 return; | 1209 return; |
| 1210 | 1210 |
| 1211 if (suppress_events_until_keydown_) { | 1211 if (suppress_events_until_keydown_) { |
| 1212 // If the preceding RawKeyDown event was handled by the browser, then we | 1212 // If the preceding RawKeyDown event was handled by the browser, then we |
| 1213 // need to suppress all events generated by it until the next RawKeyDown or | 1213 // need to suppress all events generated by it until the next RawKeyDown or |
| 1214 // KeyDown event. | 1214 // KeyDown event. |
| 1215 if (key_event.type == WebKeyboardEvent::KeyUp || | 1215 if (key_event.type() == WebKeyboardEvent::KeyUp || |
| 1216 key_event.type == WebKeyboardEvent::Char) | 1216 key_event.type() == WebKeyboardEvent::Char) |
| 1217 return; | 1217 return; |
| 1218 DCHECK(key_event.type == WebKeyboardEvent::RawKeyDown || | 1218 DCHECK(key_event.type() == WebKeyboardEvent::RawKeyDown || |
| 1219 key_event.type == WebKeyboardEvent::KeyDown); | 1219 key_event.type() == WebKeyboardEvent::KeyDown); |
| 1220 suppress_events_until_keydown_ = false; | 1220 suppress_events_until_keydown_ = false; |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 bool is_shortcut = false; | 1223 bool is_shortcut = false; |
| 1224 | 1224 |
| 1225 // Only pre-handle the key event if it's not handled by the input method. | 1225 // Only pre-handle the key event if it's not handled by the input method. |
| 1226 if (delegate_ && !key_event.skip_in_browser) { | 1226 if (delegate_ && !key_event.skip_in_browser) { |
| 1227 // We need to set |suppress_events_until_keydown_| to true if | 1227 // We need to set |suppress_events_until_keydown_| to true if |
| 1228 // PreHandleKeyboardEvent() returns true, but |this| may already be | 1228 // PreHandleKeyboardEvent() returns true, but |this| may already be |
| 1229 // destroyed at that time. So set |suppress_events_until_keydown_| true | 1229 // destroyed at that time. So set |suppress_events_until_keydown_| true |
| 1230 // here, then revert it afterwards when necessary. | 1230 // here, then revert it afterwards when necessary. |
| 1231 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1231 if (key_event.type() == WebKeyboardEvent::RawKeyDown) |
| 1232 suppress_events_until_keydown_ = true; | 1232 suppress_events_until_keydown_ = true; |
| 1233 | 1233 |
| 1234 // Tab switching/closing accelerators aren't sent to the renderer to avoid | 1234 // Tab switching/closing accelerators aren't sent to the renderer to avoid |
| 1235 // a hung/malicious renderer from interfering. | 1235 // a hung/malicious renderer from interfering. |
| 1236 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) | 1236 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) |
| 1237 return; | 1237 return; |
| 1238 | 1238 |
| 1239 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 1239 if (key_event.type() == WebKeyboardEvent::RawKeyDown) |
| 1240 suppress_events_until_keydown_ = false; | 1240 suppress_events_until_keydown_ = false; |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) | 1243 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) |
| 1244 return; | 1244 return; |
| 1245 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); | 1245 ui::LatencyInfo latency_info(ui::SourceEventType::OTHER); |
| 1246 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event, | 1246 NativeWebKeyboardEventWithLatencyInfo key_event_with_latency(key_event, |
| 1247 latency_info); | 1247 latency_info); |
| 1248 key_event_with_latency.event.isBrowserShortcut = is_shortcut; | 1248 key_event_with_latency.event.isBrowserShortcut = is_shortcut; |
| 1249 DispatchInputEventWithLatencyInfo(key_event, &key_event_with_latency.latency); | 1249 DispatchInputEventWithLatencyInfo(key_event, &key_event_with_latency.latency); |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2058 zoomed_bitmap.setPixels(0); | 2058 zoomed_bitmap.setPixels(0); |
| 2059 Send(new ViewMsg_ReleaseDisambiguationPopupBitmap(GetRoutingID(), id)); | 2059 Send(new ViewMsg_ReleaseDisambiguationPopupBitmap(GetRoutingID(), id)); |
| 2060 } | 2060 } |
| 2061 | 2061 |
| 2062 void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { | 2062 void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { |
| 2063 ignore_input_events_ = ignore_input_events; | 2063 ignore_input_events_ = ignore_input_events; |
| 2064 } | 2064 } |
| 2065 | 2065 |
| 2066 bool RenderWidgetHostImpl::KeyPressListenersHandleEvent( | 2066 bool RenderWidgetHostImpl::KeyPressListenersHandleEvent( |
| 2067 const NativeWebKeyboardEvent& event) { | 2067 const NativeWebKeyboardEvent& event) { |
| 2068 if (event.skip_in_browser || event.type != WebKeyboardEvent::RawKeyDown) | 2068 if (event.skip_in_browser || event.type() != WebKeyboardEvent::RawKeyDown) |
| 2069 return false; | 2069 return false; |
| 2070 | 2070 |
| 2071 for (size_t i = 0; i < key_press_event_callbacks_.size(); i++) { | 2071 for (size_t i = 0; i < key_press_event_callbacks_.size(); i++) { |
| 2072 size_t original_size = key_press_event_callbacks_.size(); | 2072 size_t original_size = key_press_event_callbacks_.size(); |
| 2073 if (key_press_event_callbacks_[i].Run(event)) | 2073 if (key_press_event_callbacks_[i].Run(event)) |
| 2074 return true; | 2074 return true; |
| 2075 | 2075 |
| 2076 // Check whether the callback that just ran removed itself, in which case | 2076 // Check whether the callback that just ran removed itself, in which case |
| 2077 // the iterator needs to be decremented to properly account for the removal. | 2077 // the iterator needs to be decremented to properly account for the removal. |
| 2078 size_t current_size = key_press_event_callbacks_.size(); | 2078 size_t current_size = key_press_event_callbacks_.size(); |
| 2079 if (current_size != original_size) { | 2079 if (current_size != original_size) { |
| 2080 DCHECK_EQ(original_size - 1, current_size); | 2080 DCHECK_EQ(original_size - 1, current_size); |
| 2081 --i; | 2081 --i; |
| 2082 } | 2082 } |
| 2083 } | 2083 } |
| 2084 | 2084 |
| 2085 return false; | 2085 return false; |
| 2086 } | 2086 } |
| 2087 | 2087 |
| 2088 InputEventAckState RenderWidgetHostImpl::FilterInputEvent( | 2088 InputEventAckState RenderWidgetHostImpl::FilterInputEvent( |
| 2089 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) { | 2089 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) { |
| 2090 // Don't ignore touch cancel events, since they may be sent while input | 2090 // Don't ignore touch cancel events, since they may be sent while input |
| 2091 // events are being ignored in order to keep the renderer from getting | 2091 // events are being ignored in order to keep the renderer from getting |
| 2092 // confused about how many touches are active. | 2092 // confused about how many touches are active. |
| 2093 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel) | 2093 if (ShouldDropInputEvents() && event.type() != WebInputEvent::TouchCancel) |
| 2094 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 2094 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
| 2095 | 2095 |
| 2096 if (!process_->HasConnection()) | 2096 if (!process_->HasConnection()) |
| 2097 return INPUT_EVENT_ACK_STATE_UNKNOWN; | 2097 return INPUT_EVENT_ACK_STATE_UNKNOWN; |
| 2098 | 2098 |
| 2099 if (delegate_) { | 2099 if (delegate_) { |
| 2100 if (event.type == WebInputEvent::MouseDown || | 2100 if (event.type() == WebInputEvent::MouseDown || |
| 2101 event.type == WebInputEvent::TouchStart) { | 2101 event.type() == WebInputEvent::TouchStart) { |
| 2102 delegate_->FocusOwningWebContents(this); | 2102 delegate_->FocusOwningWebContents(this); |
| 2103 } | 2103 } |
| 2104 if (event.type == WebInputEvent::MouseDown || | 2104 if (event.type() == WebInputEvent::MouseDown || |
| 2105 event.type == WebInputEvent::GestureScrollBegin || | 2105 event.type() == WebInputEvent::GestureScrollBegin || |
| 2106 event.type == WebInputEvent::TouchStart || | 2106 event.type() == WebInputEvent::TouchStart || |
| 2107 event.type == WebInputEvent::RawKeyDown) { | 2107 event.type() == WebInputEvent::RawKeyDown) { |
| 2108 delegate_->OnUserInteraction(this, event.type); | 2108 delegate_->OnUserInteraction(this, event.type()); |
| 2109 } | 2109 } |
| 2110 } | 2110 } |
| 2111 | 2111 |
| 2112 return view_ ? view_->FilterInputEvent(event) | 2112 return view_ ? view_->FilterInputEvent(event) |
| 2113 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 2113 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 2114 } | 2114 } |
| 2115 | 2115 |
| 2116 void RenderWidgetHostImpl::IncrementInFlightEventCount( | 2116 void RenderWidgetHostImpl::IncrementInFlightEventCount( |
| 2117 blink::WebInputEvent::Type event_type) { | 2117 blink::WebInputEvent::Type event_type) { |
| 2118 increment_in_flight_event_count(); | 2118 increment_in_flight_event_count(); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2526 // different from the receiver's. | 2526 // different from the receiver's. |
| 2527 file_system_file.url = | 2527 file_system_file.url = |
| 2528 GURL(storage::GetIsolatedFileSystemRootURIString( | 2528 GURL(storage::GetIsolatedFileSystemRootURIString( |
| 2529 file_system_url.origin(), filesystem_id, std::string()) | 2529 file_system_url.origin(), filesystem_id, std::string()) |
| 2530 .append(register_name)); | 2530 .append(register_name)); |
| 2531 file_system_file.filesystem_id = filesystem_id; | 2531 file_system_file.filesystem_id = filesystem_id; |
| 2532 } | 2532 } |
| 2533 } | 2533 } |
| 2534 | 2534 |
| 2535 } // namespace content | 2535 } // namespace content |
| OLD | NEW |