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