OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/devtools/protocol/input_handler.h" | 5 #include "content/browser/devtools/protocol/input_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // static | 205 // static |
206 std::vector<InputHandler*> InputHandler::ForAgentHost( | 206 std::vector<InputHandler*> InputHandler::ForAgentHost( |
207 DevToolsAgentHostImpl* host) { | 207 DevToolsAgentHostImpl* host) { |
208 return DevToolsSession::HandlersForAgentHost<InputHandler>( | 208 return DevToolsSession::HandlersForAgentHost<InputHandler>( |
209 host, Input::Metainfo::domainName); | 209 host, Input::Metainfo::domainName); |
210 } | 210 } |
211 | 211 |
212 void InputHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { | 212 void InputHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { |
213 ClearPendingKeyAndMouseCallbacks(); | 213 ClearPendingKeyAndMouseCallbacks(); |
214 if (host_) | 214 if (host_) { |
215 host_->GetRenderWidgetHost()->RemoveInputEventObserver(this); | 215 host_->GetRenderWidgetHost()->RemoveInputEventObserver(this); |
| 216 if (ignore_input_events_) |
| 217 host_->GetRenderWidgetHost()->SetIgnoreInputEvents(false); |
| 218 } |
216 host_ = host; | 219 host_ = host; |
217 if (host) | 220 if (host) { |
218 host->GetRenderWidgetHost()->AddInputEventObserver(this); | 221 host->GetRenderWidgetHost()->AddInputEventObserver(this); |
| 222 if (ignore_input_events_) |
| 223 host_->GetRenderWidgetHost()->SetIgnoreInputEvents(true); |
| 224 } |
219 } | 225 } |
220 | 226 |
221 void InputHandler::OnInputEvent(const blink::WebInputEvent& event) { | 227 void InputHandler::OnInputEvent(const blink::WebInputEvent& event) { |
222 input_queued_ = true; | 228 input_queued_ = true; |
223 } | 229 } |
224 | 230 |
225 void InputHandler::OnInputEventAck(const blink::WebInputEvent& event) { | 231 void InputHandler::OnInputEventAck(const blink::WebInputEvent& event) { |
226 if (blink::WebInputEvent::IsKeyboardEventType(event.GetType()) && | 232 if (blink::WebInputEvent::IsKeyboardEventType(event.GetType()) && |
227 !pending_key_callbacks_.empty()) { | 233 !pending_key_callbacks_.empty()) { |
228 pending_key_callbacks_.front()->sendSuccess(); | 234 pending_key_callbacks_.front()->sendSuccess(); |
(...skipping 10 matching lines...) Expand all Loading... |
239 } | 245 } |
240 | 246 |
241 void InputHandler::OnSwapCompositorFrame( | 247 void InputHandler::OnSwapCompositorFrame( |
242 const cc::CompositorFrameMetadata& frame_metadata) { | 248 const cc::CompositorFrameMetadata& frame_metadata) { |
243 page_scale_factor_ = frame_metadata.page_scale_factor; | 249 page_scale_factor_ = frame_metadata.page_scale_factor; |
244 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; | 250 scrollable_viewport_size_ = frame_metadata.scrollable_viewport_size; |
245 } | 251 } |
246 | 252 |
247 Response InputHandler::Disable() { | 253 Response InputHandler::Disable() { |
248 ClearPendingKeyAndMouseCallbacks(); | 254 ClearPendingKeyAndMouseCallbacks(); |
249 if (host_) | 255 if (host_) { |
250 host_->GetRenderWidgetHost()->RemoveInputEventObserver(this); | 256 host_->GetRenderWidgetHost()->RemoveInputEventObserver(this); |
| 257 if (ignore_input_events_) |
| 258 host_->GetRenderWidgetHost()->SetIgnoreInputEvents(false); |
| 259 } |
| 260 ignore_input_events_ = false; |
251 return Response::OK(); | 261 return Response::OK(); |
252 } | 262 } |
253 | 263 |
254 void InputHandler::DispatchKeyEvent( | 264 void InputHandler::DispatchKeyEvent( |
255 const std::string& type, | 265 const std::string& type, |
256 Maybe<int> modifiers, | 266 Maybe<int> modifiers, |
257 Maybe<double> timestamp, | 267 Maybe<double> timestamp, |
258 Maybe<std::string> text, | 268 Maybe<std::string> text, |
259 Maybe<std::string> unmodified_text, | 269 Maybe<std::string> unmodified_text, |
260 Maybe<std::string> key_identifier, | 270 Maybe<std::string> key_identifier, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 if (!host_ || !host_->GetRenderWidgetHost()) | 461 if (!host_ || !host_->GetRenderWidgetHost()) |
452 return Response::InternalError(); | 462 return Response::InternalError(); |
453 | 463 |
454 if (wheel_event) | 464 if (wheel_event) |
455 host_->GetRenderWidgetHost()->ForwardWheelEvent(*wheel_event); | 465 host_->GetRenderWidgetHost()->ForwardWheelEvent(*wheel_event); |
456 else | 466 else |
457 host_->GetRenderWidgetHost()->ForwardMouseEvent(*mouse_event); | 467 host_->GetRenderWidgetHost()->ForwardMouseEvent(*mouse_event); |
458 return Response::OK(); | 468 return Response::OK(); |
459 } | 469 } |
460 | 470 |
| 471 Response InputHandler::SetIgnoreInputEvents(bool ignore) { |
| 472 ignore_input_events_ = ignore; |
| 473 if (host_) |
| 474 host_->GetRenderWidgetHost()->SetIgnoreInputEvents(ignore); |
| 475 return Response::OK(); |
| 476 } |
| 477 |
461 void InputHandler::SynthesizePinchGesture( | 478 void InputHandler::SynthesizePinchGesture( |
462 int x, | 479 int x, |
463 int y, | 480 int y, |
464 double scale_factor, | 481 double scale_factor, |
465 Maybe<int> relative_speed, | 482 Maybe<int> relative_speed, |
466 Maybe<std::string> gesture_source_type, | 483 Maybe<std::string> gesture_source_type, |
467 std::unique_ptr<SynthesizePinchGestureCallback> callback) { | 484 std::unique_ptr<SynthesizePinchGestureCallback> callback) { |
468 if (!host_ || !host_->GetRenderWidgetHost()) { | 485 if (!host_ || !host_->GetRenderWidgetHost()) { |
469 callback->sendFailure(Response::InternalError()); | 486 callback->sendFailure(Response::InternalError()); |
470 return; | 487 return; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 } | 678 } |
662 | 679 |
663 bool InputHandler::PointIsWithinContents(gfx::PointF point) const { | 680 bool InputHandler::PointIsWithinContents(gfx::PointF point) const { |
664 gfx::Rect bounds = host_->GetView()->GetViewBounds(); | 681 gfx::Rect bounds = host_->GetView()->GetViewBounds(); |
665 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). | 682 bounds -= bounds.OffsetFromOrigin(); // Translate the bounds to (0,0). |
666 return bounds.Contains(point.x(), point.y()); | 683 return bounds.Contains(point.x(), point.y()); |
667 } | 684 } |
668 | 685 |
669 } // namespace protocol | 686 } // namespace protocol |
670 } // namespace content | 687 } // namespace content |
OLD | NEW |