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