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_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "content/browser/renderer_host/dip_util.h" | 34 #include "content/browser/renderer_host/dip_util.h" |
35 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" | 35 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" |
36 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" | 36 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" |
37 #include "content/browser/renderer_host/overscroll_controller.h" | 37 #include "content/browser/renderer_host/overscroll_controller.h" |
38 #include "content/browser/renderer_host/render_view_host_delegate.h" | 38 #include "content/browser/renderer_host/render_view_host_delegate.h" |
39 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 39 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
40 #include "content/browser/renderer_host/render_view_host_impl.h" | 40 #include "content/browser/renderer_host/render_view_host_impl.h" |
41 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 41 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
42 #include "content/browser/renderer_host/render_widget_host_impl.h" | 42 #include "content/browser/renderer_host/render_widget_host_impl.h" |
43 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 43 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
44 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" | |
44 #include "content/browser/renderer_host/ui_events_helper.h" | 45 #include "content/browser/renderer_host/ui_events_helper.h" |
45 #include "content/common/content_switches_internal.h" | 46 #include "content/common/content_switches_internal.h" |
46 #include "content/common/input_messages.h" | 47 #include "content/common/input_messages.h" |
47 #include "content/common/site_isolation_policy.h" | 48 #include "content/common/site_isolation_policy.h" |
48 #include "content/common/text_input_state.h" | 49 #include "content/common/text_input_state.h" |
49 #include "content/common/view_messages.h" | 50 #include "content/common/view_messages.h" |
50 #include "content/public/browser/content_browser_client.h" | 51 #include "content/public/browser/content_browser_client.h" |
51 #include "content/public/browser/overscroll_configuration.h" | 52 #include "content/public/browser/overscroll_configuration.h" |
52 #include "content/public/browser/render_view_host.h" | 53 #include "content/public/browser/render_view_host.h" |
53 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 54 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 using gfx::SkIRectToRect; | 116 using gfx::SkIRectToRect; |
116 | 117 |
117 using blink::WebInputEvent; | 118 using blink::WebInputEvent; |
118 using blink::WebGestureEvent; | 119 using blink::WebGestureEvent; |
119 using blink::WebTouchEvent; | 120 using blink::WebTouchEvent; |
120 | 121 |
121 namespace content { | 122 namespace content { |
122 | 123 |
123 namespace { | 124 namespace { |
124 | 125 |
125 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting | |
126 // the border of the view, in order to get valid movement information. However, | |
127 // forcing the cursor back to the center of the view after each mouse move | |
128 // doesn't work well. It reduces the frequency of useful mouse move messages | |
129 // significantly. Therefore, we move the cursor to the center of the view only | |
130 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width | |
131 // of the border area, in percentage of the corresponding dimension. | |
132 const int kMouseLockBorderPercentage = 15; | |
133 | |
134 // When accelerated compositing is enabled and a widget resize is pending, | 126 // When accelerated compositing is enabled and a widget resize is pending, |
135 // we delay further resizes of the UI. The following constant is the maximum | 127 // we delay further resizes of the UI. The following constant is the maximum |
136 // length of time that we should delay further UI resizes while waiting for a | 128 // length of time that we should delay further UI resizes while waiting for a |
137 // resized frame from a renderer. | 129 // resized frame from a renderer. |
138 const int kResizeLockTimeoutMs = 67; | 130 const int kResizeLockTimeoutMs = 67; |
139 | 131 |
140 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
141 // A callback function for EnumThreadWindows to enumerate and dismiss | |
142 // any owned popup windows. | |
143 BOOL CALLBACK DismissOwnedPopups(HWND window, LPARAM arg) { | |
144 const HWND toplevel_hwnd = reinterpret_cast<HWND>(arg); | |
145 | 133 |
146 if (::IsWindowVisible(window)) { | |
147 const HWND owner = ::GetWindow(window, GW_OWNER); | |
148 if (toplevel_hwnd == owner) { | |
149 ::PostMessage(window, WM_CANCELMODE, 0, 0); | |
150 } | |
151 } | |
152 | |
153 return TRUE; | |
154 } | |
155 #endif | |
156 | |
157 // We don't mark these as handled so that they're sent back to the | |
158 // DefWindowProc so it can generate WM_APPCOMMAND as necessary. | |
159 bool IsXButtonUpEvent(const ui::MouseEvent* event) { | |
160 #if defined(OS_WIN) | |
161 switch (event->native_event().message) { | |
162 case WM_XBUTTONUP: | |
163 case WM_NCXBUTTONUP: | |
164 return true; | |
165 } | |
166 #endif | |
167 return false; | |
168 } | |
169 | |
170 bool IsFractionalScaleFactor(float scale_factor) { | |
171 return (scale_factor - static_cast<int>(scale_factor)) > 0; | |
172 } | |
173 | |
174 // Reset unchanged touch point to StateStationary for touchmove and | |
175 // touchcancel. | |
176 void MarkUnchangedTouchPointsAsStationary( | |
177 blink::WebTouchEvent* event, | |
178 int changed_touch_id) { | |
179 if (event->type == blink::WebInputEvent::TouchMove || | |
180 event->type == blink::WebInputEvent::TouchCancel) { | |
181 for (size_t i = 0; i < event->touchesLength; ++i) { | |
182 if (event->touches[i].id != changed_touch_id) | |
183 event->touches[i].state = blink::WebTouchPoint::StateStationary; | |
184 } | |
185 } | |
186 } | |
187 | |
188 gfx::Point GetScreenLocationFromEvent(const ui::LocatedEvent& event) { | |
189 aura::Window* root = | |
190 static_cast<aura::Window*>(event.target())->GetRootWindow(); | |
191 aura::client::ScreenPositionClient* spc = | |
192 aura::client::GetScreenPositionClient(root); | |
193 if (!spc) | |
194 return event.root_location(); | |
195 | |
196 gfx::Point screen_location(event.root_location()); | |
197 spc->ConvertPointToScreen(root, &screen_location); | |
198 return screen_location; | |
199 } | |
200 | |
201 #if defined(OS_WIN) | |
202 // This class implements the ui::OnScreenKeyboardObserver interface | 134 // This class implements the ui::OnScreenKeyboardObserver interface |
203 // which provides notifications about the on screen keyboard on Windows getting | 135 // which provides notifications about the on screen keyboard on Windows getting |
204 // displayed or hidden in response to taps on editable fields. | 136 // displayed or hidden in response to taps on editable fields. |
205 // It provides functionality to request blink to scroll the input field if it | 137 // It provides functionality to request blink to scroll the input field if it |
206 // is obscured by the on screen keyboard. | 138 // is obscured by the on screen keyboard. |
207 class WinScreenKeyboardObserver : public ui::OnScreenKeyboardObserver { | 139 class WinScreenKeyboardObserver : public ui::OnScreenKeyboardObserver { |
208 public: | 140 public: |
209 WinScreenKeyboardObserver(RenderWidgetHostImpl* host, | 141 WinScreenKeyboardObserver(RenderWidgetHostImpl* host, |
210 const gfx::Point& location_in_screen, | 142 const gfx::Point& location_in_screen, |
211 float scale_factor, | 143 float scale_factor, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 // The location in DIPs where the touch occurred. | 202 // The location in DIPs where the touch occurred. |
271 gfx::Point location_in_screen_; | 203 gfx::Point location_in_screen_; |
272 // The current device scale factor. | 204 // The current device scale factor. |
273 float device_scale_factor_; | 205 float device_scale_factor_; |
274 | 206 |
275 // The content Window. | 207 // The content Window. |
276 aura::Window* window_; | 208 aura::Window* window_; |
277 | 209 |
278 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); | 210 DISALLOW_COPY_AND_ASSIGN(WinScreenKeyboardObserver); |
279 }; | 211 }; |
280 #endif | 212 #endif // defined(OS_WIN) |
281 | 213 |
282 } // namespace | 214 } // namespace |
283 | 215 |
284 // We need to watch for mouse events outside a Web Popup or its parent | 216 // We need to watch for mouse events outside a Web Popup or its parent |
285 // and dismiss the popup for certain events. | 217 // and dismiss the popup for certain events. |
286 class RenderWidgetHostViewAura::EventFilterForPopupExit | 218 class RenderWidgetHostViewAura::EventFilterForPopupExit |
287 : public ui::EventHandler { | 219 : public ui::EventHandler { |
288 public: | 220 public: |
289 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) | 221 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) |
290 : rwhva_(rwhva) { | 222 : rwhva_(rwhva) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 aura::Window* target = static_cast<aura::Window*>(event->target()); | 256 aura::Window* target = static_cast<aura::Window*>(event->target()); |
325 if (target != window_ && | 257 if (target != window_ && |
326 (!popup_parent_host_view_ || | 258 (!popup_parent_host_view_ || |
327 target != popup_parent_host_view_->window_)) { | 259 target != popup_parent_host_view_->window_)) { |
328 // If we enter this code path it means that we did not receive any focus | 260 // If we enter this code path it means that we did not receive any focus |
329 // lost notifications for the popup window. Ensure that blink is aware | 261 // lost notifications for the popup window. Ensure that blink is aware |
330 // of the fact that focus was lost for the host window by sending a Blur | 262 // of the fact that focus was lost for the host window by sending a Blur |
331 // notification. We also set a flag in the view indicating that we need | 263 // notification. We also set a flag in the view indicating that we need |
332 // to force a Focus notification on the next mouse down. | 264 // to force a Focus notification on the next mouse down. |
333 if (popup_parent_host_view_ && popup_parent_host_view_->host_) { | 265 if (popup_parent_host_view_ && popup_parent_host_view_->host_) { |
334 popup_parent_host_view_->set_focus_on_mouse_down_or_key_event_ = true; | 266 popup_parent_host_view_->event_handler() |
267 ->set_focus_on_mouse_down_or_key_event(true); | |
335 popup_parent_host_view_->host_->Blur(); | 268 popup_parent_host_view_->host_->Blur(); |
336 } | 269 } |
337 // Note: popup_parent_host_view_ may be NULL when there are multiple | 270 // Note: popup_parent_host_view_ may be NULL when there are multiple |
338 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup(). | 271 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup(). |
339 Shutdown(); | 272 Shutdown(); |
340 } | 273 } |
341 } | 274 } |
342 | 275 |
343 // We have to implement the WindowObserver interface on a separate object | 276 // We have to implement the WindowObserver interface on a separate object |
344 // because clang doesn't like implementing multiple interfaces that have | 277 // because clang doesn't like implementing multiple interfaces that have |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 //////////////////////////////////////////////////////////////////////////////// | 359 //////////////////////////////////////////////////////////////////////////////// |
427 // RenderWidgetHostViewAura, public: | 360 // RenderWidgetHostViewAura, public: |
428 | 361 |
429 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, | 362 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
430 bool is_guest_view_hack) | 363 bool is_guest_view_hack) |
431 : host_(RenderWidgetHostImpl::From(host)), | 364 : host_(RenderWidgetHostImpl::From(host)), |
432 window_(nullptr), | 365 window_(nullptr), |
433 delegated_frame_host_(new DelegatedFrameHost(this)), | 366 delegated_frame_host_(new DelegatedFrameHost(this)), |
434 in_shutdown_(false), | 367 in_shutdown_(false), |
435 in_bounds_changed_(false), | 368 in_bounds_changed_(false), |
436 is_fullscreen_(false), | |
437 popup_parent_host_view_(nullptr), | 369 popup_parent_host_view_(nullptr), |
438 popup_child_host_view_(nullptr), | 370 popup_child_host_view_(nullptr), |
439 is_loading_(false), | 371 is_loading_(false), |
440 has_composition_text_(false), | 372 has_composition_text_(false), |
441 accept_return_character_(false), | |
442 begin_frame_source_(nullptr), | 373 begin_frame_source_(nullptr), |
443 synthetic_move_sent_(false), | |
444 cursor_visibility_state_in_renderer_(UNKNOWN), | 374 cursor_visibility_state_in_renderer_(UNKNOWN), |
445 #if defined(OS_WIN) | 375 #if defined(OS_WIN) |
446 legacy_render_widget_host_HWND_(nullptr), | 376 legacy_render_widget_host_HWND_(nullptr), |
447 legacy_window_destroyed_(false), | 377 legacy_window_destroyed_(false), |
448 virtual_keyboard_requested_(false), | 378 virtual_keyboard_requested_(false), |
449 #endif | 379 #endif |
450 has_snapped_to_boundary_(false), | 380 has_snapped_to_boundary_(false), |
451 is_guest_view_hack_(is_guest_view_hack), | 381 is_guest_view_hack_(is_guest_view_hack), |
452 set_focus_on_mouse_down_or_key_event_(false), | |
453 device_scale_factor_(0.0f), | 382 device_scale_factor_(0.0f), |
454 disable_input_event_router_for_testing_(false), | |
455 last_active_widget_process_id_(ChildProcessHost::kInvalidUniqueID), | 383 last_active_widget_process_id_(ChildProcessHost::kInvalidUniqueID), |
456 last_active_widget_routing_id_(MSG_ROUTING_NONE), | 384 last_active_widget_routing_id_(MSG_ROUTING_NONE), |
385 event_handler_(new RenderWidgetHostViewEventHandler(host_, this, this)), | |
457 weak_ptr_factory_(this) { | 386 weak_ptr_factory_(this) { |
458 if (!is_guest_view_hack_) | 387 if (!is_guest_view_hack_) |
459 host_->SetView(this); | 388 host_->SetView(this); |
460 | 389 |
461 // Let the page-level input event router know about our surface ID | 390 // Let the page-level input event router know about our surface ID |
462 // namespace for surface-based hit testing. | 391 // namespace for surface-based hit testing. |
463 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { | 392 if (host_->delegate() && host_->delegate()->GetInputEventRouter()) { |
464 host_->delegate()->GetInputEventRouter()->AddSurfaceClientIdOwner( | 393 host_->delegate()->GetInputEventRouter()->AddSurfaceClientIdOwner( |
465 GetSurfaceClientId(), this); | 394 GetSurfaceClientId(), this); |
466 } | 395 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or | 450 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or |
522 // similar mechanism to ensure a second popup doesn't cause the first one | 451 // similar mechanism to ensure a second popup doesn't cause the first one |
523 // to never get a chance to filter events. See crbug.com/160589. | 452 // to never get a chance to filter events. See crbug.com/160589. |
524 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_); | 453 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_); |
525 if (transient_window_client) { | 454 if (transient_window_client) { |
526 transient_window_client->RemoveTransientChild( | 455 transient_window_client->RemoveTransientChild( |
527 popup_parent_host_view_->window_, old_child->window_); | 456 popup_parent_host_view_->window_, old_child->window_); |
528 } | 457 } |
529 old_child->popup_parent_host_view_ = NULL; | 458 old_child->popup_parent_host_view_ = NULL; |
530 } | 459 } |
531 popup_parent_host_view_->popup_child_host_view_ = this; | 460 popup_parent_host_view_->SetPopupChild(this); |
532 window_->SetType(ui::wm::WINDOW_TYPE_MENU); | 461 window_->SetType(ui::wm::WINDOW_TYPE_MENU); |
533 window_->Init(ui::LAYER_SOLID_COLOR); | 462 window_->Init(ui::LAYER_SOLID_COLOR); |
534 window_->SetName("RenderWidgetHostViewAura"); | 463 window_->SetName("RenderWidgetHostViewAura"); |
535 window_->layer()->SetColor(background_color_); | 464 window_->layer()->SetColor(background_color_); |
536 | 465 |
537 // Setting the transient child allows for the popup to get mouse events when | 466 // Setting the transient child allows for the popup to get mouse events when |
538 // in a system modal dialog. Do this before calling ParentWindowWithContext | 467 // in a system modal dialog. Do this before calling ParentWindowWithContext |
539 // below so that the transient parent is visible to WindowTreeClient. | 468 // below so that the transient parent is visible to WindowTreeClient. |
540 // This fixes crbug.com/328593. | 469 // This fixes crbug.com/328593. |
541 if (transient_window_client) { | 470 if (transient_window_client) { |
(...skipping 24 matching lines...) Expand all Loading... | |
566 window_->Init(ui::LAYER_SOLID_COLOR); | 495 window_->Init(ui::LAYER_SOLID_COLOR); |
567 window_->SetName("RenderWidgetHostViewAura"); | 496 window_->SetName("RenderWidgetHostViewAura"); |
568 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 497 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
569 window_->layer()->SetColor(background_color_); | 498 window_->layer()->SetColor(background_color_); |
570 | 499 |
571 aura::Window* parent = NULL; | 500 aura::Window* parent = NULL; |
572 gfx::Rect bounds; | 501 gfx::Rect bounds; |
573 if (reference_host_view) { | 502 if (reference_host_view) { |
574 aura::Window* reference_window = | 503 aura::Window* reference_window = |
575 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; | 504 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; |
576 if (reference_window) { | 505 event_handler_->TrackHost(reference_window); |
577 host_tracker_.reset(new aura::WindowTracker); | |
578 host_tracker_->Add(reference_window); | |
579 } | |
580 display::Display display = | 506 display::Display display = |
581 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window); | 507 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window); |
582 parent = reference_window->GetRootWindow(); | 508 parent = reference_window->GetRootWindow(); |
583 bounds = display.bounds(); | 509 bounds = display.bounds(); |
584 } | 510 } |
585 aura::client::ParentWindowWithContext(window_, parent, bounds); | 511 aura::client::ParentWindowWithContext(window_, parent, bounds); |
586 Show(); | 512 Show(); |
587 Focus(); | 513 Focus(); |
588 | 514 |
589 const display::Display display = | 515 const display::Display display = |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
729 | 655 |
730 const cc::BeginFrameArgs& RenderWidgetHostViewAura::LastUsedBeginFrameArgs() | 656 const cc::BeginFrameArgs& RenderWidgetHostViewAura::LastUsedBeginFrameArgs() |
731 const { | 657 const { |
732 return last_begin_frame_args_; | 658 return last_begin_frame_args_; |
733 } | 659 } |
734 | 660 |
735 void RenderWidgetHostViewAura::OnBeginFrameSourcePausedChanged(bool paused) { | 661 void RenderWidgetHostViewAura::OnBeginFrameSourcePausedChanged(bool paused) { |
736 // Only used on Android WebView. | 662 // Only used on Android WebView. |
737 } | 663 } |
738 | 664 |
739 void RenderWidgetHostViewAura::SetKeyboardFocus() { | |
740 #if defined(OS_WIN) | |
741 if (CanFocus()) { | |
742 aura::WindowTreeHost* host = window_->GetHost(); | |
743 if (host) { | |
744 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); | |
745 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) | |
746 ::SetFocus(hwnd); | |
747 } | |
748 } | |
749 #endif | |
750 // TODO(wjmaclean): can host_ ever be null? | |
751 if (host_ && set_focus_on_mouse_down_or_key_event_) { | |
752 set_focus_on_mouse_down_or_key_event_ = false; | |
753 host_->Focus(); | |
754 } | |
755 } | |
756 | |
757 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { | 665 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { |
758 RenderViewHost* rvh = RenderViewHost::From(host_); | 666 RenderViewHost* rvh = RenderViewHost::From(host_); |
759 if (!rvh) | 667 if (!rvh) |
760 return nullptr; | 668 return nullptr; |
761 FrameTreeNode* focused_frame = | 669 FrameTreeNode* focused_frame = |
762 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); | 670 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); |
763 if (!focused_frame) | 671 if (!focused_frame) |
764 return nullptr; | 672 return nullptr; |
765 | 673 |
766 return focused_frame->current_frame_host(); | 674 return focused_frame->current_frame_host(); |
767 } | 675 } |
768 | 676 |
769 bool RenderWidgetHostViewAura::CanRendererHandleEvent( | |
770 const ui::MouseEvent* event, | |
771 bool mouse_locked, | |
772 bool selection_popup) const { | |
773 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) | |
774 return false; | |
775 | |
776 if (event->type() == ui::ET_MOUSE_EXITED) { | |
777 if (mouse_locked || selection_popup) | |
778 return false; | |
779 #if defined(OS_WIN) | |
780 // Don't forward the mouse leave message which is received when the context | |
781 // menu is displayed by the page. This confuses the page and causes state | |
782 // changes. | |
783 if (IsShowingContextMenu()) | |
784 return false; | |
785 #endif | |
786 return true; | |
787 } | |
788 | |
789 #if defined(OS_WIN) | |
790 // Renderer cannot handle WM_XBUTTON or NC events. | |
791 switch (event->native_event().message) { | |
792 case WM_XBUTTONDOWN: | |
793 case WM_XBUTTONUP: | |
794 case WM_XBUTTONDBLCLK: | |
795 case WM_NCMOUSELEAVE: | |
796 case WM_NCMOUSEMOVE: | |
797 case WM_NCLBUTTONDOWN: | |
798 case WM_NCLBUTTONUP: | |
799 case WM_NCLBUTTONDBLCLK: | |
800 case WM_NCRBUTTONDOWN: | |
801 case WM_NCRBUTTONUP: | |
802 case WM_NCRBUTTONDBLCLK: | |
803 case WM_NCMBUTTONDOWN: | |
804 case WM_NCMBUTTONUP: | |
805 case WM_NCMBUTTONDBLCLK: | |
806 case WM_NCXBUTTONDOWN: | |
807 case WM_NCXBUTTONUP: | |
808 case WM_NCXBUTTONDBLCLK: | |
809 return false; | |
810 default: | |
811 break; | |
812 } | |
813 #elif defined(USE_X11) | |
814 // Renderer only supports standard mouse buttons, so ignore programmable | |
815 // buttons. | |
816 switch (event->type()) { | |
817 case ui::ET_MOUSE_PRESSED: | |
818 case ui::ET_MOUSE_RELEASED: { | |
819 const int kAllowedButtons = ui::EF_LEFT_MOUSE_BUTTON | | |
820 ui::EF_MIDDLE_MOUSE_BUTTON | | |
821 ui::EF_RIGHT_MOUSE_BUTTON; | |
822 return (event->flags() & kAllowedButtons) != 0; | |
823 } | |
824 default: | |
825 break; | |
826 } | |
827 #endif | |
828 return true; | |
829 } | |
830 | |
831 bool RenderWidgetHostViewAura::ShouldRouteEvent(const ui::Event* event) const { | |
832 // We should route an event in two cases: | |
833 // 1) Mouse events are routed only if cross-process frames are possible. | |
834 // 2) Touch events are always routed. In the absence of a BrowserPlugin | |
835 // we expect the routing to always send the event to this view. If | |
836 // one or more BrowserPlugins are present, then the event may be targeted | |
837 // to one of them, or this view. This allows GuestViews to have access to | |
838 // them while still forcing pinch-zoom to be handled by the top-level | |
839 // frame. TODO(wjmaclean): At present, this doesn't work for OOPIF, but | |
840 // it should be a simple extension to modify RenderWidgetHostViewChildFrame | |
841 // in a similar manner to RenderWidgetHostViewGuest. | |
842 bool result = host_->delegate() && host_->delegate()->GetInputEventRouter() && | |
843 !disable_input_event_router_for_testing_; | |
844 // ScrollEvents get transformed into MouseWheel events, and so are treated | |
845 // the same as mouse events for routing purposes. | |
846 if (event->IsMouseEvent() || event->type() == ui::ET_SCROLL) | |
847 result = result && SiteIsolationPolicy::AreCrossProcessFramesPossible(); | |
848 return result; | |
849 } | |
850 | |
851 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { | 677 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { |
852 SnapToPhysicalPixelBoundary(); | 678 SnapToPhysicalPixelBoundary(); |
853 #if defined(OS_WIN) | 679 #if defined(OS_WIN) |
854 if (legacy_render_widget_host_HWND_) { | 680 if (legacy_render_widget_host_HWND_) { |
855 legacy_render_widget_host_HWND_->SetBounds( | 681 legacy_render_widget_host_HWND_->SetBounds( |
856 window_->GetBoundsInRootWindow()); | 682 window_->GetBoundsInRootWindow()); |
857 } | 683 } |
858 #endif | 684 #endif |
859 if (!in_shutdown_) { | 685 if (!in_shutdown_) { |
860 // Send screen rects through the delegate if there is one. Not every | 686 // Send screen rects through the delegate if there is one. Not every |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 } | 724 } |
899 | 725 |
900 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color) { | 726 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color) { |
901 RenderWidgetHostViewBase::SetBackgroundColor(color); | 727 RenderWidgetHostViewBase::SetBackgroundColor(color); |
902 bool opaque = GetBackgroundOpaque(); | 728 bool opaque = GetBackgroundOpaque(); |
903 host_->SetBackgroundOpaque(opaque); | 729 host_->SetBackgroundOpaque(opaque); |
904 window_->layer()->SetFillsBoundsOpaquely(opaque); | 730 window_->layer()->SetFillsBoundsOpaquely(opaque); |
905 window_->layer()->SetColor(color); | 731 window_->layer()->SetColor(color); |
906 } | 732 } |
907 | 733 |
734 bool RenderWidgetHostViewAura::IsMouseLocked() { | |
735 return event_handler_->mouse_locked(); | |
736 } | |
737 | |
908 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const { | 738 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const { |
909 gfx::Rect requested_rect(GetRequestedRendererSize()); | 739 gfx::Rect requested_rect(GetRequestedRendererSize()); |
910 requested_rect.Inset(insets_); | 740 requested_rect.Inset(insets_); |
911 return requested_rect.size(); | 741 return requested_rect.size(); |
912 } | 742 } |
913 | 743 |
914 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 744 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
915 if (insets != insets_) { | 745 if (insets != insets_) { |
916 insets_ = insets; | 746 insets_ = insets; |
917 host_->WasResized(); | 747 host_->WasResized(); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1262 gfx::NativeViewAccessible | 1092 gfx::NativeViewAccessible |
1263 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { | 1093 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { |
1264 #if defined(OS_WIN) | 1094 #if defined(OS_WIN) |
1265 if (legacy_render_widget_host_HWND_) | 1095 if (legacy_render_widget_host_HWND_) |
1266 return legacy_render_widget_host_HWND_->window_accessible(); | 1096 return legacy_render_widget_host_HWND_->window_accessible(); |
1267 #endif | 1097 #endif |
1268 return NULL; | 1098 return NULL; |
1269 } | 1099 } |
1270 | 1100 |
1271 bool RenderWidgetHostViewAura::LockMouse() { | 1101 bool RenderWidgetHostViewAura::LockMouse() { |
1272 aura::Window* root_window = window_->GetRootWindow(); | 1102 return event_handler_->LockMouse(); |
1273 if (!root_window) | |
1274 return false; | |
1275 | |
1276 if (mouse_locked_) | |
1277 return true; | |
1278 | |
1279 mouse_locked_ = true; | |
1280 #if !defined(OS_WIN) | |
1281 window_->SetCapture(); | |
1282 #else | |
1283 UpdateMouseLockRegion(); | |
1284 #endif | |
1285 aura::client::CursorClient* cursor_client = | |
1286 aura::client::GetCursorClient(root_window); | |
1287 if (cursor_client) { | |
1288 cursor_client->HideCursor(); | |
1289 cursor_client->LockCursor(); | |
1290 } | |
1291 | |
1292 if (ShouldMoveToCenter()) { | |
1293 synthetic_move_sent_ = true; | |
1294 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
1295 } | |
1296 tooltip_disabler_.reset(new aura::client::ScopedTooltipDisabler(root_window)); | |
1297 return true; | |
1298 } | 1103 } |
1299 | 1104 |
1300 void RenderWidgetHostViewAura::UnlockMouse() { | 1105 void RenderWidgetHostViewAura::UnlockMouse() { |
1301 tooltip_disabler_.reset(); | 1106 event_handler_->UnlockMouse(); |
1302 | |
1303 aura::Window* root_window = window_->GetRootWindow(); | |
1304 if (!mouse_locked_ || !root_window) | |
1305 return; | |
1306 | |
1307 mouse_locked_ = false; | |
1308 | |
1309 if (window_->HasCapture()) | |
1310 window_->ReleaseCapture(); | |
1311 | |
1312 #if defined(OS_WIN) | |
1313 ::ClipCursor(NULL); | |
1314 #endif | |
1315 | |
1316 // Ensure that the global mouse position is updated here to its original | |
1317 // value. If we don't do this then the synthesized mouse move which is posted | |
1318 // after the cursor is moved ends up getting a large movement delta which is | |
1319 // not what sites expect. The delta is computed in the | |
1320 // ModifyEventMovementAndCoords function. | |
1321 global_mouse_position_ = unlocked_global_mouse_position_; | |
1322 window_->MoveCursorTo(unlocked_mouse_position_); | |
1323 | |
1324 aura::client::CursorClient* cursor_client = | |
1325 aura::client::GetCursorClient(root_window); | |
1326 if (cursor_client) { | |
1327 cursor_client->UnlockCursor(); | |
1328 cursor_client->ShowCursor(); | |
1329 } | |
1330 | |
1331 host_->LostMouseLock(); | |
1332 } | 1107 } |
1333 | 1108 |
1334 //////////////////////////////////////////////////////////////////////////////// | 1109 //////////////////////////////////////////////////////////////////////////////// |
1335 // RenderWidgetHostViewAura, ui::TextInputClient implementation: | 1110 // RenderWidgetHostViewAura, ui::TextInputClient implementation: |
1336 void RenderWidgetHostViewAura::SetCompositionText( | 1111 void RenderWidgetHostViewAura::SetCompositionText( |
1337 const ui::CompositionText& composition) { | 1112 const ui::CompositionText& composition) { |
1338 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) | 1113 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) |
1339 return; | 1114 return; |
1340 | 1115 |
1341 // TODO(suzhe): convert both renderer_host and renderer to use | 1116 // TODO(suzhe): convert both renderer_host and renderer to use |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1391 } | 1166 } |
1392 | 1167 |
1393 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1168 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
1394 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1169 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
1395 popup_child_host_view_->InsertChar(event); | 1170 popup_child_host_view_->InsertChar(event); |
1396 return; | 1171 return; |
1397 } | 1172 } |
1398 | 1173 |
1399 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1174 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
1400 // TODO(wjmaclean): can host_ ever be null? | 1175 // TODO(wjmaclean): can host_ ever be null? |
1401 if (host_ && | 1176 if (host_ && (event_handler_->accept_return_character() || |
1402 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1177 event.GetCharacter() != ui::VKEY_RETURN)) { |
1403 // Send a blink::WebInputEvent::Char event to |host_|. | 1178 // Send a blink::WebInputEvent::Char event to |host_|. |
1404 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1179 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
1405 } | 1180 } |
1406 } | 1181 } |
1407 | 1182 |
1408 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1183 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
1409 if (text_input_manager_ && text_input_manager_->GetTextInputState()) | 1184 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
1410 return text_input_manager_->GetTextInputState()->type; | 1185 return text_input_manager_->GetTextInputState()->type; |
1411 return ui::TEXT_INPUT_TYPE_NONE; | 1186 return ui::TEXT_INPUT_TYPE_NONE; |
1412 } | 1187 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1761 return false; | 1536 return false; |
1762 } | 1537 } |
1763 | 1538 |
1764 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { | 1539 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { |
1765 } | 1540 } |
1766 | 1541 |
1767 //////////////////////////////////////////////////////////////////////////////// | 1542 //////////////////////////////////////////////////////////////////////////////// |
1768 // RenderWidgetHostViewAura, ui::EventHandler implementation: | 1543 // RenderWidgetHostViewAura, ui::EventHandler implementation: |
1769 | 1544 |
1770 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { | 1545 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
1771 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); | 1546 event_handler_->OnKeyEvent(event); |
1772 | |
1773 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | |
1774 popup_child_host_view_->OnKeyEvent(event); | |
1775 if (event->handled()) | |
1776 return; | |
1777 } | |
1778 | |
1779 // We need to handle the Escape key for Pepper Flash. | |
1780 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { | |
1781 // Focus the window we were created from. | |
1782 if (host_tracker_.get() && !host_tracker_->windows().empty()) { | |
1783 aura::Window* host = *(host_tracker_->windows().begin()); | |
1784 aura::client::FocusClient* client = aura::client::GetFocusClient(host); | |
1785 if (client) { | |
1786 // Calling host->Focus() may delete |this|. We create a local observer | |
1787 // for that. In that case we exit without further access to any members. | |
1788 aura::WindowTracker tracker; | |
1789 aura::Window* window = window_; | |
1790 tracker.Add(window); | |
1791 host->Focus(); | |
1792 if (!tracker.Contains(window)) { | |
1793 event->SetHandled(); | |
1794 return; | |
1795 } | |
1796 } | |
1797 } | |
1798 Shutdown(); | |
1799 } else { | |
1800 if (event->key_code() == ui::VKEY_RETURN) { | |
1801 // Do not forward return key release events if no press event was handled. | |
1802 if (event->type() == ui::ET_KEY_RELEASED && !accept_return_character_) | |
1803 return; | |
1804 // Accept return key character events between press and release events. | |
1805 accept_return_character_ = event->type() == ui::ET_KEY_PRESSED; | |
1806 } | |
1807 | |
1808 // Call SetKeyboardFocus() for not only ET_KEY_PRESSED but also | |
1809 // ET_KEY_RELEASED. If a user closed the hotdog menu with ESC key press, | |
1810 // we need to notify focus to Blink on ET_KEY_RELEASED for ESC key. | |
1811 SetKeyboardFocus(); | |
1812 // We don't have to communicate with an input method here. | |
1813 NativeWebKeyboardEvent webkit_event(*event); | |
1814 ForwardKeyboardEvent(webkit_event); | |
1815 } | |
1816 event->SetHandled(); | |
1817 } | 1547 } |
1818 | 1548 |
1819 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { | 1549 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { |
1820 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent"); | 1550 event_handler_->OnMouseEvent(event); |
1821 | |
1822 ForwardMouseEventToParent(event); | |
1823 // TODO(mgiuca): Return if event->handled() returns true. This currently | |
1824 // breaks drop-down lists which means something is incorrectly setting | |
1825 // event->handled to true (http://crbug.com/577983). | |
1826 | |
1827 if (mouse_locked_) { | |
1828 aura::client::CursorClient* cursor_client = | |
1829 aura::client::GetCursorClient(window_->GetRootWindow()); | |
1830 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); | |
1831 | |
1832 if (event->type() == ui::ET_MOUSEWHEEL) { | |
1833 blink::WebMouseWheelEvent mouse_wheel_event = | |
1834 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event), | |
1835 base::Bind(&GetScreenLocationFromEvent)); | |
1836 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) | |
1837 host_->ForwardWheelEvent(mouse_wheel_event); | |
1838 return; | |
1839 } | |
1840 | |
1841 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
1842 | |
1843 // If we receive non client mouse messages while we are in the locked state | |
1844 // it probably means that the mouse left the borders of our window and | |
1845 // needs to be moved back to the center. | |
1846 if (event->flags() & ui::EF_IS_NON_CLIENT) { | |
1847 synthetic_move_sent_ = true; | |
1848 window_->MoveCursorTo(center); | |
1849 return; | |
1850 } | |
1851 | |
1852 blink::WebMouseEvent mouse_event = | |
1853 ui::MakeWebMouseEvent(*event, base::Bind(&GetScreenLocationFromEvent)); | |
1854 | |
1855 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || | |
1856 event->type() == ui::ET_MOUSE_DRAGGED) && | |
1857 mouse_event.x == center.x() && mouse_event.y == center.y(); | |
1858 | |
1859 // For fractional scale factors, the conversion from pixels to dip and | |
1860 // vice versa could result in off by 1 or 2 errors which hurts us because | |
1861 // we want to avoid sending the artificial move to center event to the | |
1862 // renderer. Sending the move to center to the renderer cause the cursor | |
1863 // to bounce around the center of the screen leading to the lock operation | |
1864 // not working correctly. | |
1865 // Workaround is to treat a mouse move or drag event off by at most 2 px | |
1866 // from the center as a move to center event. | |
1867 if (synthetic_move_sent_ && | |
1868 IsFractionalScaleFactor(current_device_scale_factor_)) { | |
1869 if (event->type() == ui::ET_MOUSE_MOVED || | |
1870 event->type() == ui::ET_MOUSE_DRAGGED) { | |
1871 if ((abs(mouse_event.x - center.x()) <= 2) && | |
1872 (abs(mouse_event.y - center.y()) <= 2)) { | |
1873 is_move_to_center_event = true; | |
1874 } | |
1875 } | |
1876 } | |
1877 | |
1878 ModifyEventMovementAndCoords(&mouse_event); | |
1879 | |
1880 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | |
1881 if (should_not_forward) { | |
1882 synthetic_move_sent_ = false; | |
1883 } else { | |
1884 // Check if the mouse has reached the border and needs to be centered. | |
1885 if (ShouldMoveToCenter()) { | |
1886 synthetic_move_sent_ = true; | |
1887 window_->MoveCursorTo(center); | |
1888 } | |
1889 bool is_selection_popup = popup_child_host_view_ && | |
1890 popup_child_host_view_->NeedsInputGrab(); | |
1891 // Forward event to renderer. | |
1892 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && | |
1893 !(event->flags() & ui::EF_FROM_TOUCH)) { | |
1894 host_->ForwardMouseEvent(mouse_event); | |
1895 // Ensure that we get keyboard focus on mouse down as a plugin window | |
1896 // may have grabbed keyboard focus. | |
1897 if (event->type() == ui::ET_MOUSE_PRESSED) | |
1898 SetKeyboardFocus(); | |
1899 } | |
1900 } | |
1901 return; | |
1902 } | |
1903 | |
1904 // As the overscroll is handled during scroll events from the trackpad, the | |
1905 // RWHVA window is transformed by the overscroll controller. This transform | |
1906 // triggers a synthetic mouse-move event to be generated (by the aura | |
1907 // RootWindow). But this event interferes with the overscroll gesture. So, | |
1908 // ignore such synthetic mouse-move events if an overscroll gesture is in | |
1909 // progress. | |
1910 if (overscroll_controller_ && | |
1911 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE && | |
1912 event->flags() & ui::EF_IS_SYNTHESIZED && | |
1913 (event->type() == ui::ET_MOUSE_ENTERED || | |
1914 event->type() == ui::ET_MOUSE_EXITED || | |
1915 event->type() == ui::ET_MOUSE_MOVED)) { | |
1916 event->StopPropagation(); | |
1917 return; | |
1918 } | |
1919 | |
1920 if (event->type() == ui::ET_MOUSEWHEEL) { | |
1921 #if defined(OS_WIN) | |
1922 // We get mouse wheel/scroll messages even if we are not in the foreground. | |
1923 // So here we check if we have any owned popup windows in the foreground and | |
1924 // dismiss them. | |
1925 aura::WindowTreeHost* host = window_->GetHost(); | |
1926 if (host) { | |
1927 HWND parent = host->GetAcceleratedWidget(); | |
1928 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); | |
1929 EnumThreadWindows(GetCurrentThreadId(), | |
1930 DismissOwnedPopups, | |
1931 reinterpret_cast<LPARAM>(toplevel_hwnd)); | |
1932 } | |
1933 #endif | |
1934 blink::WebMouseWheelEvent mouse_wheel_event = | |
1935 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event), | |
1936 base::Bind(&GetScreenLocationFromEvent)); | |
1937 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) { | |
1938 if (ShouldRouteEvent(event)) { | |
1939 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( | |
1940 this, &mouse_wheel_event); | |
1941 } else { | |
1942 ProcessMouseWheelEvent(mouse_wheel_event, *event->latency()); | |
1943 } | |
1944 } | |
1945 } else { | |
1946 bool is_selection_popup = | |
1947 popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab(); | |
1948 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && | |
1949 !(event->flags() & ui::EF_FROM_TOUCH)) { | |
1950 // Confirm existing composition text on mouse press, to make sure | |
1951 // the input caret won't be moved with an ongoing composition text. | |
1952 if (event->type() == ui::ET_MOUSE_PRESSED) | |
1953 FinishImeCompositionSession(); | |
1954 | |
1955 blink::WebMouseEvent mouse_event = ui::MakeWebMouseEvent( | |
1956 *event, base::Bind(&GetScreenLocationFromEvent)); | |
1957 ModifyEventMovementAndCoords(&mouse_event); | |
1958 if (ShouldRouteEvent(event)) { | |
1959 host_->delegate()->GetInputEventRouter()->RouteMouseEvent(this, | |
1960 &mouse_event); | |
1961 } else { | |
1962 ProcessMouseEvent(mouse_event, *event->latency()); | |
1963 } | |
1964 | |
1965 // Ensure that we get keyboard focus on mouse down as a plugin window may | |
1966 // have grabbed keyboard focus. | |
1967 if (event->type() == ui::ET_MOUSE_PRESSED) | |
1968 SetKeyboardFocus(); | |
1969 } | |
1970 } | |
1971 | |
1972 switch (event->type()) { | |
1973 case ui::ET_MOUSE_PRESSED: | |
1974 window_->SetCapture(); | |
1975 break; | |
1976 case ui::ET_MOUSE_RELEASED: | |
1977 if (!NeedsMouseCapture()) | |
1978 window_->ReleaseCapture(); | |
1979 break; | |
1980 default: | |
1981 break; | |
1982 } | |
1983 | |
1984 if (!IsXButtonUpEvent(event)) | |
1985 event->SetHandled(); | |
1986 } | 1551 } |
1987 | 1552 |
1988 uint32_t RenderWidgetHostViewAura::SurfaceClientIdAtPoint( | 1553 uint32_t RenderWidgetHostViewAura::SurfaceClientIdAtPoint( |
1989 cc::SurfaceHittestDelegate* delegate, | 1554 cc::SurfaceHittestDelegate* delegate, |
1990 const gfx::Point& point, | 1555 const gfx::Point& point, |
1991 gfx::Point* transformed_point) { | 1556 gfx::Point* transformed_point) { |
1992 DCHECK(device_scale_factor_ != 0.0f); | 1557 DCHECK(device_scale_factor_ != 0.0f); |
1993 | 1558 |
1994 // The surface hittest happens in device pixels, so we need to convert the | 1559 // The surface hittest happens in device pixels, so we need to convert the |
1995 // |point| from DIPs to pixels before hittesting. | 1560 // |point| from DIPs to pixels before hittesting. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2063 if (rvh && rvh->GetDelegate()) | 1628 if (rvh && rvh->GetDelegate()) |
2064 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); | 1629 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); |
2065 | 1630 |
2066 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); | 1631 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); |
2067 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); | 1632 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); |
2068 } | 1633 } |
2069 #endif | 1634 #endif |
2070 } | 1635 } |
2071 | 1636 |
2072 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { | 1637 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
2073 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); | 1638 event_handler_->OnScrollEvent(event); |
2074 | |
2075 if (event->type() == ui::ET_SCROLL) { | |
2076 #if !defined(OS_WIN) | |
2077 // TODO(ananta) | |
2078 // Investigate if this is true for Windows 8 Metro ASH as well. | |
2079 if (event->finger_count() != 2) | |
2080 return; | |
2081 #endif | |
2082 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEventFlingCancel(); | |
2083 // Coordinates need to be transferred to the fling cancel gesture only | |
2084 // for Surface-targeting to ensure that it is targeted to the correct | |
2085 // RenderWidgetHost. | |
2086 gesture_event.x = event->x(); | |
2087 gesture_event.y = event->y(); | |
2088 blink::WebMouseWheelEvent mouse_wheel_event = ui::MakeWebMouseWheelEvent( | |
2089 *event, base::Bind(&GetScreenLocationFromEvent)); | |
2090 if (ShouldRouteEvent(event)) { | |
2091 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
2092 this, &gesture_event, ui::LatencyInfo()); | |
2093 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( | |
2094 this, &mouse_wheel_event); | |
2095 } else { | |
2096 host_->ForwardGestureEvent(gesture_event); | |
2097 host_->ForwardWheelEventWithLatencyInfo(mouse_wheel_event, | |
2098 *event->latency()); | |
2099 } | |
2100 RecordAction(base::UserMetricsAction("TrackpadScroll")); | |
2101 } else if (event->type() == ui::ET_SCROLL_FLING_START || | |
2102 event->type() == ui::ET_SCROLL_FLING_CANCEL) { | |
2103 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEvent( | |
2104 *event, base::Bind(&GetScreenLocationFromEvent)); | |
2105 if (ShouldRouteEvent(event)) { | |
2106 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
2107 this, &gesture_event, ui::LatencyInfo()); | |
2108 } else { | |
2109 host_->ForwardGestureEvent(gesture_event); | |
2110 } | |
2111 if (event->type() == ui::ET_SCROLL_FLING_START) | |
2112 RecordAction(base::UserMetricsAction("TrackpadScrollFling")); | |
2113 } | |
2114 | |
2115 event->SetHandled(); | |
2116 } | 1639 } |
2117 | 1640 |
2118 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { | 1641 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { |
2119 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent"); | 1642 event_handler_->OnTouchEvent(event); |
2120 | |
2121 bool had_no_pointer = !pointer_state_.GetPointerCount(); | |
2122 | |
2123 // Update the touch event first. | |
2124 if (!pointer_state_.OnTouch(*event)) { | |
2125 event->StopPropagation(); | |
2126 return; | |
2127 } | |
2128 | |
2129 blink::WebTouchEvent touch_event; | |
2130 bool handled = selection_controller_->WillHandleTouchEvent(pointer_state_); | |
2131 if (handled) { | |
2132 event->SetHandled(); | |
2133 } else { | |
2134 touch_event = ui::CreateWebTouchEventFromMotionEvent( | |
2135 pointer_state_, event->may_cause_scrolling()); | |
2136 } | |
2137 pointer_state_.CleanupRemovedTouchPoints(*event); | |
2138 | |
2139 if (handled) | |
2140 return; | |
2141 | |
2142 if (had_no_pointer) | |
2143 selection_controller_client_->OnTouchDown(); | |
2144 if (!pointer_state_.GetPointerCount()) | |
2145 selection_controller_client_->OnTouchUp(); | |
2146 | |
2147 // It is important to always mark events as being handled asynchronously when | |
2148 // they are forwarded. This ensures that the current event does not get | |
2149 // processed by the gesture recognizer before events currently awaiting | |
2150 // dispatch in the touch queue. | |
2151 event->DisableSynchronousHandling(); | |
2152 | |
2153 // Set unchanged touch point to StateStationary for touchmove and | |
2154 // touchcancel to make sure only send one ack per WebTouchEvent. | |
2155 MarkUnchangedTouchPointsAsStationary(&touch_event, event->touch_id()); | |
2156 if (ShouldRouteEvent(event)) { | |
2157 host_->delegate()->GetInputEventRouter()->RouteTouchEvent( | |
2158 this, &touch_event, *event->latency()); | |
2159 } else { | |
2160 ProcessTouchEvent(touch_event, *event->latency()); | |
2161 } | |
2162 } | 1643 } |
2163 | 1644 |
2164 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { | 1645 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { |
2165 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent"); | 1646 event_handler_->OnGestureEvent(event); |
2166 | |
2167 if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN || | |
2168 event->type() == ui::ET_GESTURE_PINCH_UPDATE || | |
2169 event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { | |
2170 event->SetHandled(); | |
2171 return; | |
2172 } | |
2173 | |
2174 HandleGestureForTouchSelection(event); | |
2175 if (event->handled()) | |
2176 return; | |
2177 | |
2178 // Confirm existing composition text on TAP gesture, to make sure the input | |
2179 // caret won't be moved with an ongoing composition text. | |
2180 if (event->type() == ui::ET_GESTURE_TAP) | |
2181 FinishImeCompositionSession(); | |
2182 | |
2183 blink::WebGestureEvent gesture = | |
2184 ui::MakeWebGestureEvent(*event, base::Bind(&GetScreenLocationFromEvent)); | |
2185 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
2186 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an | |
2187 // event to stop any in-progress flings. | |
2188 blink::WebGestureEvent fling_cancel = gesture; | |
2189 fling_cancel.type = blink::WebInputEvent::GestureFlingCancel; | |
2190 fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen; | |
2191 if (ShouldRouteEvent(event)) { | |
2192 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
2193 this, &fling_cancel, ui::LatencyInfo()); | |
2194 } else { | |
2195 host_->ForwardGestureEvent(fling_cancel); | |
2196 } | |
2197 } | |
2198 | |
2199 if (gesture.type != blink::WebInputEvent::Undefined) { | |
2200 if (ShouldRouteEvent(event)) { | |
2201 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
2202 this, &gesture, *event->latency()); | |
2203 } else { | |
2204 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency()); | |
2205 } | |
2206 | |
2207 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | |
2208 event->type() == ui::ET_GESTURE_SCROLL_UPDATE || | |
2209 event->type() == ui::ET_GESTURE_SCROLL_END) { | |
2210 RecordAction(base::UserMetricsAction("TouchscreenScroll")); | |
2211 } else if (event->type() == ui::ET_SCROLL_FLING_START) { | |
2212 RecordAction(base::UserMetricsAction("TouchscreenScrollFling")); | |
2213 } | |
2214 } | |
2215 | |
2216 // If a gesture is not processed by the webpage, then WebKit processes it | |
2217 // (e.g. generates synthetic mouse events). | |
2218 event->SetHandled(); | |
2219 } | 1647 } |
2220 | 1648 |
2221 //////////////////////////////////////////////////////////////////////////////// | 1649 //////////////////////////////////////////////////////////////////////////////// |
2222 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: | 1650 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: |
2223 | 1651 |
2224 bool RenderWidgetHostViewAura::ShouldActivate() const { | 1652 bool RenderWidgetHostViewAura::ShouldActivate() const { |
2225 aura::WindowTreeHost* host = window_->GetHost(); | 1653 aura::WindowTreeHost* host = window_->GetHost(); |
2226 if (!host) | 1654 if (!host) |
2227 return true; | 1655 return true; |
2228 const ui::Event* event = host->dispatcher()->current_event(); | 1656 const ui::Event* event = host->dispatcher()->current_event(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2350 display::Screen::GetScreen()->RemoveObserver(this); | 1778 display::Screen::GetScreen()->RemoveObserver(this); |
2351 | 1779 |
2352 // This call is usually no-op since |this| object is already removed from | 1780 // This call is usually no-op since |this| object is already removed from |
2353 // the Aura root window and we don't have a way to get an input method | 1781 // the Aura root window and we don't have a way to get an input method |
2354 // object associated with the window, but just in case. | 1782 // object associated with the window, but just in case. |
2355 DetachFromInputMethod(); | 1783 DetachFromInputMethod(); |
2356 } | 1784 } |
2357 if (popup_parent_host_view_) { | 1785 if (popup_parent_host_view_) { |
2358 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 1786 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
2359 popup_parent_host_view_->popup_child_host_view_ == this); | 1787 popup_parent_host_view_->popup_child_host_view_ == this); |
2360 popup_parent_host_view_->popup_child_host_view_ = NULL; | 1788 popup_parent_host_view_->SetPopupChild(nullptr); |
2361 } | 1789 } |
2362 if (popup_child_host_view_) { | 1790 if (popup_child_host_view_) { |
2363 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || | 1791 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || |
2364 popup_child_host_view_->popup_parent_host_view_ == this); | 1792 popup_child_host_view_->popup_parent_host_view_ == this); |
2365 popup_child_host_view_->popup_parent_host_view_ = NULL; | 1793 popup_child_host_view_->popup_parent_host_view_ = NULL; |
2366 } | 1794 } |
2367 event_filter_for_popup_exit_.reset(); | 1795 event_filter_for_popup_exit_.reset(); |
2368 | 1796 |
2369 #if defined(OS_WIN) | 1797 #if defined(OS_WIN) |
2370 // The LegacyRenderWidgetHostHWND window should have been destroyed in | 1798 // The LegacyRenderWidgetHostHWND window should have been destroyed in |
(...skipping 10 matching lines...) Expand all Loading... | |
2381 | 1809 |
2382 #endif | 1810 #endif |
2383 | 1811 |
2384 if (text_input_manager_) | 1812 if (text_input_manager_) |
2385 text_input_manager_->RemoveObserver(this); | 1813 text_input_manager_->RemoveObserver(this); |
2386 } | 1814 } |
2387 | 1815 |
2388 void RenderWidgetHostViewAura::CreateAuraWindow() { | 1816 void RenderWidgetHostViewAura::CreateAuraWindow() { |
2389 DCHECK(!window_); | 1817 DCHECK(!window_); |
2390 window_ = new aura::Window(this); | 1818 window_ = new aura::Window(this); |
1819 event_handler_->set_window(window_); | |
2391 window_observer_.reset(new WindowObserver(this)); | 1820 window_observer_.reset(new WindowObserver(this)); |
2392 | 1821 |
2393 aura::client::SetTooltipText(window_, &tooltip_); | 1822 aura::client::SetTooltipText(window_, &tooltip_); |
2394 aura::client::SetActivationDelegate(window_, this); | 1823 aura::client::SetActivationDelegate(window_, this); |
2395 aura::client::SetFocusChangeObserver(window_, this); | 1824 aura::client::SetFocusChangeObserver(window_, this); |
2396 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 1825 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
2397 display::Screen::GetScreen()->AddObserver(this); | 1826 display::Screen::GetScreen()->AddObserver(this); |
2398 } | 1827 } |
2399 | 1828 |
2400 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { | 1829 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2480 return popup_type_ == blink::WebPopupTypePage; | 1909 return popup_type_ == blink::WebPopupTypePage; |
2481 } | 1910 } |
2482 | 1911 |
2483 bool RenderWidgetHostViewAura::NeedsMouseCapture() { | 1912 bool RenderWidgetHostViewAura::NeedsMouseCapture() { |
2484 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1913 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
2485 return NeedsInputGrab(); | 1914 return NeedsInputGrab(); |
2486 #endif | 1915 #endif |
2487 return false; | 1916 return false; |
2488 } | 1917 } |
2489 | 1918 |
2490 void RenderWidgetHostViewAura::FinishImeCompositionSession() { | 1919 void RenderWidgetHostViewAura::SetTooltipsEnabled(bool enable) { |
2491 if (!has_composition_text_) | 1920 if (enable) { |
2492 return; | 1921 tooltip_disabler_.reset(); |
2493 | |
2494 if (!!text_input_manager_ && !!text_input_manager_->GetActiveWidget()) { | |
2495 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false); | |
2496 } | |
2497 ImeCancelComposition(); | |
2498 } | |
2499 | |
2500 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( | |
2501 blink::WebMouseEvent* event) { | |
2502 // If the mouse has just entered, we must report zero movementX/Y. Hence we | |
2503 // reset any global_mouse_position set previously. | |
2504 if (event->type == blink::WebInputEvent::MouseEnter || | |
2505 event->type == blink::WebInputEvent::MouseLeave) | |
2506 global_mouse_position_.SetPoint(event->globalX, event->globalY); | |
2507 | |
2508 // Movement is computed by taking the difference of the new cursor position | |
2509 // and the previous. Under mouse lock the cursor will be warped back to the | |
2510 // center so that we are not limited by clipping boundaries. | |
2511 // We do not measure movement as the delta from cursor to center because | |
2512 // we may receive more mouse movement events before our warp has taken | |
2513 // effect. | |
2514 event->movementX = event->globalX - global_mouse_position_.x(); | |
2515 event->movementY = event->globalY - global_mouse_position_.y(); | |
2516 | |
2517 global_mouse_position_.SetPoint(event->globalX, event->globalY); | |
2518 | |
2519 // Under mouse lock, coordinates of mouse are locked to what they were when | |
2520 // mouse lock was entered. | |
2521 if (mouse_locked_) { | |
2522 event->x = unlocked_mouse_position_.x(); | |
2523 event->y = unlocked_mouse_position_.y(); | |
2524 event->windowX = unlocked_mouse_position_.x(); | |
2525 event->windowY = unlocked_mouse_position_.y(); | |
2526 event->globalX = unlocked_global_mouse_position_.x(); | |
2527 event->globalY = unlocked_global_mouse_position_.y(); | |
2528 } else { | 1922 } else { |
2529 unlocked_mouse_position_.SetPoint(event->x, event->y); | 1923 tooltip_disabler_.reset( |
2530 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); | 1924 new aura::client::ScopedTooltipDisabler(window_->GetRootWindow())); |
2531 } | 1925 } |
2532 } | 1926 } |
2533 | 1927 |
2534 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState( | 1928 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState( |
2535 bool is_visible) { | 1929 bool is_visible) { |
2536 if (host_->is_hidden() || | 1930 if (host_->is_hidden() || |
2537 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || | 1931 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || |
2538 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) | 1932 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) |
2539 return; | 1933 return; |
2540 | 1934 |
(...skipping 22 matching lines...) Expand all Loading... | |
2563 | 1957 |
2564 if (snapped && snapped != window_) | 1958 if (snapped && snapped != window_) |
2565 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); | 1959 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); |
2566 | 1960 |
2567 has_snapped_to_boundary_ = true; | 1961 has_snapped_to_boundary_ = true; |
2568 } | 1962 } |
2569 | 1963 |
2570 bool RenderWidgetHostViewAura::OnShowContextMenu( | 1964 bool RenderWidgetHostViewAura::OnShowContextMenu( |
2571 const ContextMenuParams& params) { | 1965 const ContextMenuParams& params) { |
2572 #if defined(OS_WIN) | 1966 #if defined(OS_WIN) |
2573 last_context_menu_params_.reset(); | 1967 event_handler_->SetContextMenuParams(params); |
2574 | 1968 return params.source_type != ui::MENU_SOURCE_LONG_PRESS; |
2575 if (params.source_type == ui::MENU_SOURCE_LONG_PRESS) { | 1969 #else |
2576 last_context_menu_params_.reset(new ContextMenuParams); | |
2577 *last_context_menu_params_ = params; | |
2578 return false; | |
2579 } | |
2580 #endif | |
2581 return true; | 1970 return true; |
1971 #endif // defined(OS_WIN) | |
2582 } | 1972 } |
2583 | 1973 |
2584 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest( | 1974 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest( |
2585 std::unique_ptr<TouchSelectionControllerClientAura> client) { | 1975 std::unique_ptr<TouchSelectionControllerClientAura> client) { |
2586 selection_controller_client_.swap(client); | 1976 selection_controller_client_.swap(client); |
2587 CreateSelectionController(); | 1977 CreateSelectionController(); |
2588 disable_input_event_router_for_testing_ = true; | |
2589 } | 1978 } |
2590 | 1979 |
2591 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { | 1980 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
2592 SnapToPhysicalPixelBoundary(); | 1981 SnapToPhysicalPixelBoundary(); |
2593 // Don't recursively call SetBounds if this bounds update is the result of | 1982 // Don't recursively call SetBounds if this bounds update is the result of |
2594 // a Window::SetBoundsInternal call. | 1983 // a Window::SetBoundsInternal call. |
2595 if (!in_bounds_changed_) | 1984 if (!in_bounds_changed_) |
2596 window_->SetBounds(rect); | 1985 window_->SetBounds(rect); |
2597 host_->WasResized(); | 1986 host_->WasResized(); |
2598 delegated_frame_host_->WasResized(); | 1987 delegated_frame_host_->WasResized(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2634 const gfx::Rect& clip) { | 2023 const gfx::Rect& clip) { |
2635 if (!clip.IsEmpty()) { | 2024 if (!clip.IsEmpty()) { |
2636 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); | 2025 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); |
2637 if (!to_paint.IsEmpty()) | 2026 if (!to_paint.IsEmpty()) |
2638 window_->SchedulePaintInRect(to_paint); | 2027 window_->SchedulePaintInRect(to_paint); |
2639 } else { | 2028 } else { |
2640 window_->SchedulePaintInRect(rect); | 2029 window_->SchedulePaintInRect(rect); |
2641 } | 2030 } |
2642 } | 2031 } |
2643 | 2032 |
2644 bool RenderWidgetHostViewAura::ShouldMoveToCenter() { | |
2645 gfx::Rect rect = window_->bounds(); | |
2646 rect = ConvertRectToScreen(rect); | |
2647 int border_x = rect.width() * kMouseLockBorderPercentage / 100; | |
2648 int border_y = rect.height() * kMouseLockBorderPercentage / 100; | |
2649 | |
2650 return global_mouse_position_.x() < rect.x() + border_x || | |
2651 global_mouse_position_.x() > rect.right() - border_x || | |
2652 global_mouse_position_.y() < rect.y() + border_y || | |
2653 global_mouse_position_.y() > rect.bottom() - border_y; | |
2654 } | |
2655 | |
2656 void RenderWidgetHostViewAura::AddedToRootWindow() { | 2033 void RenderWidgetHostViewAura::AddedToRootWindow() { |
2657 window_->GetHost()->AddObserver(this); | 2034 window_->GetHost()->AddObserver(this); |
2658 UpdateScreenInfo(window_); | 2035 UpdateScreenInfo(window_); |
2659 | 2036 |
2660 aura::client::CursorClient* cursor_client = | 2037 aura::client::CursorClient* cursor_client = |
2661 aura::client::GetCursorClient(window_->GetRootWindow()); | 2038 aura::client::GetCursorClient(window_->GetRootWindow()); |
2662 if (cursor_client) { | 2039 if (cursor_client) { |
2663 cursor_client->AddObserver(this); | 2040 cursor_client->AddObserver(this); |
2664 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); | 2041 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
2665 } | 2042 } |
(...skipping 28 matching lines...) Expand all Loading... | |
2694 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow()); | 2071 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow()); |
2695 #endif | 2072 #endif |
2696 } | 2073 } |
2697 | 2074 |
2698 void RenderWidgetHostViewAura::DetachFromInputMethod() { | 2075 void RenderWidgetHostViewAura::DetachFromInputMethod() { |
2699 ui::InputMethod* input_method = GetInputMethod(); | 2076 ui::InputMethod* input_method = GetInputMethod(); |
2700 if (input_method) | 2077 if (input_method) |
2701 input_method->DetachTextInputClient(this); | 2078 input_method->DetachTextInputClient(this); |
2702 } | 2079 } |
2703 | 2080 |
2704 void RenderWidgetHostViewAura::ForwardKeyboardEvent( | 2081 void RenderWidgetHostViewAura::ForwardKeyboardEvent( |
tdresser
2016/09/23 13:54:09
The exact boundary between RenderWidgetHostViewAur
jonross
2016/10/05 15:37:57
Yeah I went with a minimal bounds change.
RenderW
| |
2705 const NativeWebKeyboardEvent& event) { | 2082 const NativeWebKeyboardEvent& event) { |
2706 RenderWidgetHostImpl* target_host = host_; | 2083 RenderWidgetHostImpl* target_host = host_; |
2707 | 2084 |
2708 // If there are multiple widgets on the page (such as when there are | 2085 // If there are multiple widgets on the page (such as when there are |
2709 // out-of-process iframes), pick the one that should process this event. | 2086 // out-of-process iframes), pick the one that should process this event. |
2710 if (host_->delegate()) | 2087 if (host_->delegate()) |
2711 target_host = host_->delegate()->GetFocusedRenderWidgetHost(host_); | 2088 target_host = host_->delegate()->GetFocusedRenderWidgetHost(host_); |
2712 if (!target_host) | 2089 if (!target_host) |
2713 return; | 2090 return; |
2714 | 2091 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2752 ui::TouchSelectionController::Config tsc_config; | 2129 ui::TouchSelectionController::Config tsc_config; |
2753 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds( | 2130 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds( |
2754 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms()); | 2131 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms()); |
2755 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance() | 2132 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance() |
2756 ->max_touch_move_in_pixels_for_click(); | 2133 ->max_touch_move_in_pixels_for_click(); |
2757 tsc_config.enable_longpress_drag_selection = false; | 2134 tsc_config.enable_longpress_drag_selection = false; |
2758 selection_controller_.reset(new ui::TouchSelectionController( | 2135 selection_controller_.reset(new ui::TouchSelectionController( |
2759 selection_controller_client_.get(), tsc_config)); | 2136 selection_controller_client_.get(), tsc_config)); |
2760 } | 2137 } |
2761 | 2138 |
2762 void RenderWidgetHostViewAura::HandleGestureForTouchSelection( | |
2763 ui::GestureEvent* event) { | |
2764 switch (event->type()) { | |
2765 case ui::ET_GESTURE_LONG_PRESS: | |
2766 if (selection_controller_->WillHandleLongPressEvent( | |
2767 event->time_stamp(), event->location_f())) { | |
2768 event->SetHandled(); | |
2769 } | |
2770 break; | |
2771 case ui::ET_GESTURE_TAP: | |
2772 if (selection_controller_->WillHandleTapEvent( | |
2773 event->location_f(), event->details().tap_count())) { | |
2774 event->SetHandled(); | |
2775 } | |
2776 break; | |
2777 case ui::ET_GESTURE_SCROLL_BEGIN: | |
2778 selection_controller_client_->OnScrollStarted(); | |
2779 break; | |
2780 case ui::ET_GESTURE_SCROLL_END: | |
2781 selection_controller_client_->OnScrollCompleted(); | |
2782 break; | |
2783 #if defined(OS_WIN) | |
2784 case ui::ET_GESTURE_LONG_TAP: { | |
2785 if (!last_context_menu_params_) | |
2786 break; | |
2787 | |
2788 std::unique_ptr<ContextMenuParams> context_menu_params = | |
2789 std::move(last_context_menu_params_); | |
2790 | |
2791 // On Windows we want to display the context menu when the long press | |
2792 // gesture is released. To achieve that, we switch the saved context | |
2793 // menu params source type to MENU_SOURCE_TOUCH. This is to ensure that | |
2794 // the RenderWidgetHostViewAura::OnShowContextMenu function which is | |
2795 // called from the ShowContextMenu call below, does not treat it as | |
2796 // a context menu request coming in from the long press gesture. | |
2797 DCHECK(context_menu_params->source_type == ui::MENU_SOURCE_LONG_PRESS); | |
2798 context_menu_params->source_type = ui::MENU_SOURCE_TOUCH; | |
2799 | |
2800 RenderViewHostDelegateView* delegate_view = | |
2801 GetRenderViewHostDelegateView(); | |
2802 if (delegate_view) | |
2803 delegate_view->ShowContextMenu(GetFocusedFrame(), | |
2804 *context_menu_params); | |
2805 | |
2806 event->SetHandled(); | |
2807 // WARNING: we may have been deleted during the call to ShowContextMenu(). | |
2808 break; | |
2809 } | |
2810 #endif | |
2811 default: | |
2812 break; | |
2813 } | |
2814 } | |
2815 | |
2816 void RenderWidgetHostViewAura::ForwardMouseEventToParent( | |
2817 ui::MouseEvent* event) { | |
2818 // Needed to propagate mouse event to |window_->parent()->delegate()|, but | |
2819 // note that it might be something other than a WebContentsViewAura instance. | |
2820 // TODO(pkotwicz): Find a better way of doing this. | |
2821 // In fullscreen mode which is typically used by flash, don't forward | |
2822 // the mouse events to the parent. The renderer and the plugin process | |
2823 // handle these events. | |
2824 if (is_fullscreen_) | |
2825 return; | |
2826 | |
2827 if (event->flags() & ui::EF_FROM_TOUCH) | |
2828 return; | |
2829 | |
2830 if (!window_->parent() || !window_->parent()->delegate()) | |
2831 return; | |
2832 | |
2833 // Take a copy of |event|, to avoid ConvertLocationToTarget mutating the | |
2834 // event. | |
2835 std::unique_ptr<ui::Event> event_copy = ui::Event::Clone(*event); | |
2836 ui::MouseEvent* mouse_event = static_cast<ui::MouseEvent*>(event_copy.get()); | |
2837 mouse_event->ConvertLocationToTarget(window_, window_->parent()); | |
2838 window_->parent()->delegate()->OnMouseEvent(mouse_event); | |
2839 if (mouse_event->handled()) | |
2840 event->SetHandled(); | |
2841 } | |
2842 | |
2843 RenderViewHostDelegateView* | |
2844 RenderWidgetHostViewAura::GetRenderViewHostDelegateView() { | |
2845 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will | |
2846 // actually show the disambiguation popup. | |
2847 RenderViewHost* rvh = RenderViewHost::From(host_); | |
2848 if (!rvh) | |
2849 return nullptr; | |
2850 | |
2851 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
2852 if (!delegate) | |
2853 return nullptr; | |
2854 | |
2855 return delegate->GetDelegateView(); | |
2856 } | |
2857 | |
2858 //////////////////////////////////////////////////////////////////////////////// | 2139 //////////////////////////////////////////////////////////////////////////////// |
2859 // DelegatedFrameHost, public: | 2140 // DelegatedFrameHost, public: |
2860 | 2141 |
2861 ui::Layer* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const { | 2142 ui::Layer* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const { |
2862 return window_->layer(); | 2143 return window_->layer(); |
2863 } | 2144 } |
2864 | 2145 |
2865 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const { | 2146 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const { |
2866 return !host_->is_hidden(); | 2147 return !host_->is_hidden(); |
2867 } | 2148 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3039 if (GetTextInputManager() | 2320 if (GetTextInputManager() |
3040 ->GetTextSelection(focused_view) | 2321 ->GetTextSelection(focused_view) |
3041 ->GetSelectedText(&selected_text)) { | 2322 ->GetSelectedText(&selected_text)) { |
3042 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | 2323 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. |
3043 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | 2324 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); |
3044 clipboard_writer.WriteText(selected_text); | 2325 clipboard_writer.WriteText(selected_text); |
3045 } | 2326 } |
3046 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | 2327 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
3047 } | 2328 } |
3048 | 2329 |
2330 void RenderWidgetHostViewAura::SetPopupChild( | |
2331 RenderWidgetHostViewAura* popup_child_host_view) { | |
2332 popup_child_host_view_ = popup_child_host_view; | |
2333 event_handler_->SetPopupChild( | |
2334 popup_child_host_view, | |
2335 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr); | |
2336 } | |
2337 | |
3049 } // namespace content | 2338 } // namespace content |
OLD | NEW |