Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 2317333002: Refactor EventHandler out of RenderWidgetHostViewAura (Closed)
Patch Set: Fix Windows Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 358
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 in_shutdown_(false), 366 in_shutdown_(false),
434 in_bounds_changed_(false), 367 in_bounds_changed_(false),
435 is_fullscreen_(false),
436 popup_parent_host_view_(nullptr), 368 popup_parent_host_view_(nullptr),
437 popup_child_host_view_(nullptr), 369 popup_child_host_view_(nullptr),
438 is_loading_(false), 370 is_loading_(false),
439 has_composition_text_(false), 371 has_composition_text_(false),
440 accept_return_character_(false),
441 begin_frame_source_(nullptr), 372 begin_frame_source_(nullptr),
442 needs_begin_frames_(false), 373 needs_begin_frames_(false),
443 needs_flush_input_(false), 374 needs_flush_input_(false),
444 added_frame_observer_(false), 375 added_frame_observer_(false),
445 synthetic_move_sent_(false),
446 cursor_visibility_state_in_renderer_(UNKNOWN), 376 cursor_visibility_state_in_renderer_(UNKNOWN),
447 #if defined(OS_WIN) 377 #if defined(OS_WIN)
448 legacy_render_widget_host_HWND_(nullptr), 378 legacy_render_widget_host_HWND_(nullptr),
449 legacy_window_destroyed_(false), 379 legacy_window_destroyed_(false),
450 virtual_keyboard_requested_(false), 380 virtual_keyboard_requested_(false),
451 #endif 381 #endif
452 has_snapped_to_boundary_(false), 382 has_snapped_to_boundary_(false),
453 is_guest_view_hack_(is_guest_view_hack), 383 is_guest_view_hack_(is_guest_view_hack),
454 set_focus_on_mouse_down_or_key_event_(false),
455 device_scale_factor_(0.0f), 384 device_scale_factor_(0.0f),
456 disable_input_event_router_for_testing_(false),
457 last_active_widget_process_id_(ChildProcessHost::kInvalidUniqueID), 385 last_active_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
458 last_active_widget_routing_id_(MSG_ROUTING_NONE), 386 last_active_widget_routing_id_(MSG_ROUTING_NONE),
387 event_handler_(new RenderWidgetHostViewEventHandler(host_, this, this)),
459 weak_ptr_factory_(this) { 388 weak_ptr_factory_(this) {
460 // GuestViews have two RenderWidgetHostViews and so we need to make sure 389 // GuestViews have two RenderWidgetHostViews and so we need to make sure
461 // we don't have FrameSinkId collisions. 390 // we don't have FrameSinkId collisions.
462 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 391 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
463 cc::FrameSinkId frame_sink_id = 392 cc::FrameSinkId frame_sink_id =
464 is_guest_view_hack_ 393 is_guest_view_hack_
465 ? factory->GetContextFactory()->AllocateFrameSinkId() 394 ? factory->GetContextFactory()->AllocateFrameSinkId()
466 : cc::FrameSinkId( 395 : cc::FrameSinkId(
467 base::checked_cast<uint32_t>(host_->GetProcess()->GetID()), 396 base::checked_cast<uint32_t>(host_->GetProcess()->GetID()),
468 base::checked_cast<uint32_t>(host_->GetRoutingID())); 397 base::checked_cast<uint32_t>(host_->GetRoutingID()));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or 464 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
536 // similar mechanism to ensure a second popup doesn't cause the first one 465 // similar mechanism to ensure a second popup doesn't cause the first one
537 // to never get a chance to filter events. See crbug.com/160589. 466 // to never get a chance to filter events. See crbug.com/160589.
538 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_); 467 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_);
539 if (transient_window_client) { 468 if (transient_window_client) {
540 transient_window_client->RemoveTransientChild( 469 transient_window_client->RemoveTransientChild(
541 popup_parent_host_view_->window_, old_child->window_); 470 popup_parent_host_view_->window_, old_child->window_);
542 } 471 }
543 old_child->popup_parent_host_view_ = NULL; 472 old_child->popup_parent_host_view_ = NULL;
544 } 473 }
545 popup_parent_host_view_->popup_child_host_view_ = this; 474 popup_parent_host_view_->SetPopupChild(this);
546 window_->SetType(ui::wm::WINDOW_TYPE_MENU); 475 window_->SetType(ui::wm::WINDOW_TYPE_MENU);
547 window_->Init(ui::LAYER_SOLID_COLOR); 476 window_->Init(ui::LAYER_SOLID_COLOR);
548 window_->SetName("RenderWidgetHostViewAura"); 477 window_->SetName("RenderWidgetHostViewAura");
549 window_->layer()->SetColor(background_color_); 478 window_->layer()->SetColor(background_color_);
550 479
551 // Setting the transient child allows for the popup to get mouse events when 480 // Setting the transient child allows for the popup to get mouse events when
552 // in a system modal dialog. Do this before calling ParentWindowWithContext 481 // in a system modal dialog. Do this before calling ParentWindowWithContext
553 // below so that the transient parent is visible to WindowTreeClient. 482 // below so that the transient parent is visible to WindowTreeClient.
554 // This fixes crbug.com/328593. 483 // This fixes crbug.com/328593.
555 if (transient_window_client) { 484 if (transient_window_client) {
(...skipping 24 matching lines...) Expand all
580 window_->Init(ui::LAYER_SOLID_COLOR); 509 window_->Init(ui::LAYER_SOLID_COLOR);
581 window_->SetName("RenderWidgetHostViewAura"); 510 window_->SetName("RenderWidgetHostViewAura");
582 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 511 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
583 window_->layer()->SetColor(background_color_); 512 window_->layer()->SetColor(background_color_);
584 513
585 aura::Window* parent = NULL; 514 aura::Window* parent = NULL;
586 gfx::Rect bounds; 515 gfx::Rect bounds;
587 if (reference_host_view) { 516 if (reference_host_view) {
588 aura::Window* reference_window = 517 aura::Window* reference_window =
589 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; 518 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_;
590 if (reference_window) { 519 event_handler_->TrackHost(reference_window);
591 host_tracker_.reset(new aura::WindowTracker);
592 host_tracker_->Add(reference_window);
593 }
594 display::Display display = 520 display::Display display =
595 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window); 521 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window);
596 parent = reference_window->GetRootWindow(); 522 parent = reference_window->GetRootWindow();
597 bounds = display.bounds(); 523 bounds = display.bounds();
598 } 524 }
599 aura::client::ParentWindowWithContext(window_, parent, bounds); 525 aura::client::ParentWindowWithContext(window_, parent, bounds);
600 Show(); 526 Show();
601 Focus(); 527 Focus();
602 528
603 const display::Display display = 529 const display::Display display =
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 687
762 const cc::BeginFrameArgs& RenderWidgetHostViewAura::LastUsedBeginFrameArgs() 688 const cc::BeginFrameArgs& RenderWidgetHostViewAura::LastUsedBeginFrameArgs()
763 const { 689 const {
764 return last_begin_frame_args_; 690 return last_begin_frame_args_;
765 } 691 }
766 692
767 void RenderWidgetHostViewAura::OnBeginFrameSourcePausedChanged(bool paused) { 693 void RenderWidgetHostViewAura::OnBeginFrameSourcePausedChanged(bool paused) {
768 // Only used on Android WebView. 694 // Only used on Android WebView.
769 } 695 }
770 696
771 void RenderWidgetHostViewAura::SetKeyboardFocus() {
772 #if defined(OS_WIN)
773 if (CanFocus()) {
774 aura::WindowTreeHost* host = window_->GetHost();
775 if (host) {
776 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget();
777 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE))
778 ::SetFocus(hwnd);
779 }
780 }
781 #endif
782 // TODO(wjmaclean): can host_ ever be null?
783 if (host_ && set_focus_on_mouse_down_or_key_event_) {
784 set_focus_on_mouse_down_or_key_event_ = false;
785 host_->Focus();
786 }
787 }
788
789 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { 697 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() {
790 RenderViewHost* rvh = RenderViewHost::From(host_); 698 RenderViewHost* rvh = RenderViewHost::From(host_);
791 if (!rvh) 699 if (!rvh)
792 return nullptr; 700 return nullptr;
793 FrameTreeNode* focused_frame = 701 FrameTreeNode* focused_frame =
794 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); 702 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame();
795 if (!focused_frame) 703 if (!focused_frame)
796 return nullptr; 704 return nullptr;
797 705
798 return focused_frame->current_frame_host(); 706 return focused_frame->current_frame_host();
799 } 707 }
800 708
801 bool RenderWidgetHostViewAura::CanRendererHandleEvent(
802 const ui::MouseEvent* event,
803 bool mouse_locked,
804 bool selection_popup) const {
805 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED)
806 return false;
807
808 if (event->type() == ui::ET_MOUSE_EXITED) {
809 if (mouse_locked || selection_popup)
810 return false;
811 #if defined(OS_WIN)
812 // Don't forward the mouse leave message which is received when the context
813 // menu is displayed by the page. This confuses the page and causes state
814 // changes.
815 if (IsShowingContextMenu())
816 return false;
817 #endif
818 return true;
819 }
820
821 #if defined(OS_WIN)
822 // Renderer cannot handle WM_XBUTTON or NC events.
823 switch (event->native_event().message) {
824 case WM_XBUTTONDOWN:
825 case WM_XBUTTONUP:
826 case WM_XBUTTONDBLCLK:
827 case WM_NCMOUSELEAVE:
828 case WM_NCMOUSEMOVE:
829 case WM_NCLBUTTONDOWN:
830 case WM_NCLBUTTONUP:
831 case WM_NCLBUTTONDBLCLK:
832 case WM_NCRBUTTONDOWN:
833 case WM_NCRBUTTONUP:
834 case WM_NCRBUTTONDBLCLK:
835 case WM_NCMBUTTONDOWN:
836 case WM_NCMBUTTONUP:
837 case WM_NCMBUTTONDBLCLK:
838 case WM_NCXBUTTONDOWN:
839 case WM_NCXBUTTONUP:
840 case WM_NCXBUTTONDBLCLK:
841 return false;
842 default:
843 break;
844 }
845 #elif defined(USE_X11)
846 // Renderer only supports standard mouse buttons, so ignore programmable
847 // buttons.
848 switch (event->type()) {
849 case ui::ET_MOUSE_PRESSED:
850 case ui::ET_MOUSE_RELEASED: {
851 const int kAllowedButtons = ui::EF_LEFT_MOUSE_BUTTON |
852 ui::EF_MIDDLE_MOUSE_BUTTON |
853 ui::EF_RIGHT_MOUSE_BUTTON;
854 return (event->flags() & kAllowedButtons) != 0;
855 }
856 default:
857 break;
858 }
859 #endif
860 return true;
861 }
862
863 bool RenderWidgetHostViewAura::ShouldRouteEvent(const ui::Event* event) const {
864 // We should route an event in two cases:
865 // 1) Mouse events are routed only if cross-process frames are possible.
866 // 2) Touch events are always routed. In the absence of a BrowserPlugin
867 // we expect the routing to always send the event to this view. If
868 // one or more BrowserPlugins are present, then the event may be targeted
869 // to one of them, or this view. This allows GuestViews to have access to
870 // them while still forcing pinch-zoom to be handled by the top-level
871 // frame. TODO(wjmaclean): At present, this doesn't work for OOPIF, but
872 // it should be a simple extension to modify RenderWidgetHostViewChildFrame
873 // in a similar manner to RenderWidgetHostViewGuest.
874 bool result = host_->delegate() && host_->delegate()->GetInputEventRouter() &&
875 !disable_input_event_router_for_testing_;
876 // ScrollEvents get transformed into MouseWheel events, and so are treated
877 // the same as mouse events for routing purposes.
878 if (event->IsMouseEvent() || event->type() == ui::ET_SCROLL)
879 result = result && SiteIsolationPolicy::AreCrossProcessFramesPossible();
880 return result;
881 }
882
883 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { 709 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
884 SnapToPhysicalPixelBoundary(); 710 SnapToPhysicalPixelBoundary();
885 #if defined(OS_WIN) 711 #if defined(OS_WIN)
886 if (legacy_render_widget_host_HWND_) { 712 if (legacy_render_widget_host_HWND_) {
887 legacy_render_widget_host_HWND_->SetBounds( 713 legacy_render_widget_host_HWND_->SetBounds(
888 window_->GetBoundsInRootWindow()); 714 window_->GetBoundsInRootWindow());
889 } 715 }
890 #endif 716 #endif
891 if (!in_shutdown_) { 717 if (!in_shutdown_) {
892 // Send screen rects through the delegate if there is one. Not every 718 // Send screen rects through the delegate if there is one. Not every
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 } 756 }
931 757
932 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color) { 758 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color) {
933 RenderWidgetHostViewBase::SetBackgroundColor(color); 759 RenderWidgetHostViewBase::SetBackgroundColor(color);
934 bool opaque = GetBackgroundOpaque(); 760 bool opaque = GetBackgroundOpaque();
935 host_->SetBackgroundOpaque(opaque); 761 host_->SetBackgroundOpaque(opaque);
936 window_->layer()->SetFillsBoundsOpaquely(opaque); 762 window_->layer()->SetFillsBoundsOpaquely(opaque);
937 window_->layer()->SetColor(color); 763 window_->layer()->SetColor(color);
938 } 764 }
939 765
766 bool RenderWidgetHostViewAura::IsMouseLocked() {
767 return event_handler_->mouse_locked();
768 }
769
940 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const { 770 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const {
941 gfx::Rect requested_rect(GetRequestedRendererSize()); 771 gfx::Rect requested_rect(GetRequestedRendererSize());
942 requested_rect.Inset(insets_); 772 requested_rect.Inset(insets_);
943 return requested_rect.size(); 773 return requested_rect.size();
944 } 774 }
945 775
946 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { 776 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
947 if (insets != insets_) { 777 if (insets != insets_) {
948 insets_ = insets; 778 insets_ = insets;
949 host_->WasResized(); 779 host_->WasResized();
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 gfx::NativeViewAccessible 1124 gfx::NativeViewAccessible
1295 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { 1125 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1296 #if defined(OS_WIN) 1126 #if defined(OS_WIN)
1297 if (legacy_render_widget_host_HWND_) 1127 if (legacy_render_widget_host_HWND_)
1298 return legacy_render_widget_host_HWND_->window_accessible(); 1128 return legacy_render_widget_host_HWND_->window_accessible();
1299 #endif 1129 #endif
1300 return NULL; 1130 return NULL;
1301 } 1131 }
1302 1132
1303 bool RenderWidgetHostViewAura::LockMouse() { 1133 bool RenderWidgetHostViewAura::LockMouse() {
1304 aura::Window* root_window = window_->GetRootWindow(); 1134 return event_handler_->LockMouse();
1305 if (!root_window)
1306 return false;
1307
1308 if (mouse_locked_)
1309 return true;
1310
1311 mouse_locked_ = true;
1312 #if !defined(OS_WIN)
1313 window_->SetCapture();
1314 #else
1315 UpdateMouseLockRegion();
1316 #endif
1317 aura::client::CursorClient* cursor_client =
1318 aura::client::GetCursorClient(root_window);
1319 if (cursor_client) {
1320 cursor_client->HideCursor();
1321 cursor_client->LockCursor();
1322 }
1323
1324 if (ShouldMoveToCenter()) {
1325 synthetic_move_sent_ = true;
1326 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint());
1327 }
1328 tooltip_disabler_.reset(new aura::client::ScopedTooltipDisabler(root_window));
1329 return true;
1330 } 1135 }
1331 1136
1332 void RenderWidgetHostViewAura::UnlockMouse() { 1137 void RenderWidgetHostViewAura::UnlockMouse() {
1333 tooltip_disabler_.reset(); 1138 event_handler_->UnlockMouse();
1334
1335 aura::Window* root_window = window_->GetRootWindow();
1336 if (!mouse_locked_ || !root_window)
1337 return;
1338
1339 mouse_locked_ = false;
1340
1341 if (window_->HasCapture())
1342 window_->ReleaseCapture();
1343
1344 #if defined(OS_WIN)
1345 ::ClipCursor(NULL);
1346 #endif
1347
1348 // Ensure that the global mouse position is updated here to its original
1349 // value. If we don't do this then the synthesized mouse move which is posted
1350 // after the cursor is moved ends up getting a large movement delta which is
1351 // not what sites expect. The delta is computed in the
1352 // ModifyEventMovementAndCoords function.
1353 global_mouse_position_ = unlocked_global_mouse_position_;
1354 window_->MoveCursorTo(unlocked_mouse_position_);
1355
1356 aura::client::CursorClient* cursor_client =
1357 aura::client::GetCursorClient(root_window);
1358 if (cursor_client) {
1359 cursor_client->UnlockCursor();
1360 cursor_client->ShowCursor();
1361 }
1362
1363 host_->LostMouseLock();
1364 } 1139 }
1365 1140
1366 //////////////////////////////////////////////////////////////////////////////// 1141 ////////////////////////////////////////////////////////////////////////////////
1367 // RenderWidgetHostViewAura, ui::TextInputClient implementation: 1142 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
1368 void RenderWidgetHostViewAura::SetCompositionText( 1143 void RenderWidgetHostViewAura::SetCompositionText(
1369 const ui::CompositionText& composition) { 1144 const ui::CompositionText& composition) {
1370 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) 1145 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1371 return; 1146 return;
1372 1147
1373 // TODO(suzhe): convert both renderer_host and renderer to use 1148 // TODO(suzhe): convert both renderer_host and renderer to use
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 } 1198 }
1424 1199
1425 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { 1200 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) {
1426 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { 1201 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1427 popup_child_host_view_->InsertChar(event); 1202 popup_child_host_view_->InsertChar(event);
1428 return; 1203 return;
1429 } 1204 }
1430 1205
1431 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 1206 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1432 // TODO(wjmaclean): can host_ ever be null? 1207 // TODO(wjmaclean): can host_ ever be null?
1433 if (host_ && 1208 if (host_ && (event_handler_->accept_return_character() ||
1434 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { 1209 event.GetCharacter() != ui::VKEY_RETURN)) {
1435 // Send a blink::WebInputEvent::Char event to |host_|. 1210 // Send a blink::WebInputEvent::Char event to |host_|.
1436 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); 1211 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter()));
1437 } 1212 }
1438 } 1213 }
1439 1214
1440 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { 1215 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1441 if (text_input_manager_ && text_input_manager_->GetTextInputState()) 1216 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1442 return text_input_manager_->GetTextInputState()->type; 1217 return text_input_manager_->GetTextInputState()->type;
1443 return ui::TEXT_INPUT_TYPE_NONE; 1218 return ui::TEXT_INPUT_TYPE_NONE;
1444 } 1219 }
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 return false; 1568 return false;
1794 } 1569 }
1795 1570
1796 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { 1571 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const {
1797 } 1572 }
1798 1573
1799 //////////////////////////////////////////////////////////////////////////////// 1574 ////////////////////////////////////////////////////////////////////////////////
1800 // RenderWidgetHostViewAura, ui::EventHandler implementation: 1575 // RenderWidgetHostViewAura, ui::EventHandler implementation:
1801 1576
1802 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { 1577 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
1803 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); 1578 event_handler_->OnKeyEvent(event);
1804
1805 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1806 popup_child_host_view_->OnKeyEvent(event);
1807 if (event->handled())
1808 return;
1809 }
1810
1811 // We need to handle the Escape key for Pepper Flash.
1812 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
1813 // Focus the window we were created from.
1814 if (host_tracker_.get() && !host_tracker_->windows().empty()) {
1815 aura::Window* host = *(host_tracker_->windows().begin());
1816 aura::client::FocusClient* client = aura::client::GetFocusClient(host);
1817 if (client) {
1818 // Calling host->Focus() may delete |this|. We create a local observer
1819 // for that. In that case we exit without further access to any members.
1820 aura::WindowTracker tracker;
1821 aura::Window* window = window_;
1822 tracker.Add(window);
1823 host->Focus();
1824 if (!tracker.Contains(window)) {
1825 event->SetHandled();
1826 return;
1827 }
1828 }
1829 }
1830 Shutdown();
1831 } else {
1832 if (event->key_code() == ui::VKEY_RETURN) {
1833 // Do not forward return key release events if no press event was handled.
1834 if (event->type() == ui::ET_KEY_RELEASED && !accept_return_character_)
1835 return;
1836 // Accept return key character events between press and release events.
1837 accept_return_character_ = event->type() == ui::ET_KEY_PRESSED;
1838 }
1839
1840 // Call SetKeyboardFocus() for not only ET_KEY_PRESSED but also
1841 // ET_KEY_RELEASED. If a user closed the hotdog menu with ESC key press,
1842 // we need to notify focus to Blink on ET_KEY_RELEASED for ESC key.
1843 SetKeyboardFocus();
1844 // We don't have to communicate with an input method here.
1845 NativeWebKeyboardEvent webkit_event(*event);
1846 ForwardKeyboardEvent(webkit_event);
1847 }
1848 event->SetHandled();
1849 } 1579 }
1850 1580
1851 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { 1581 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
1852 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent"); 1582 event_handler_->OnMouseEvent(event);
1853
1854 ForwardMouseEventToParent(event);
1855 // TODO(mgiuca): Return if event->handled() returns true. This currently
1856 // breaks drop-down lists which means something is incorrectly setting
1857 // event->handled to true (http://crbug.com/577983).
1858
1859 if (mouse_locked_) {
1860 aura::client::CursorClient* cursor_client =
1861 aura::client::GetCursorClient(window_->GetRootWindow());
1862 DCHECK(!cursor_client || !cursor_client->IsCursorVisible());
1863
1864 if (event->type() == ui::ET_MOUSEWHEEL) {
1865 blink::WebMouseWheelEvent mouse_wheel_event =
1866 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event),
1867 base::Bind(&GetScreenLocationFromEvent));
1868 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0)
1869 host_->ForwardWheelEvent(mouse_wheel_event);
1870 return;
1871 }
1872
1873 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint());
1874
1875 // If we receive non client mouse messages while we are in the locked state
1876 // it probably means that the mouse left the borders of our window and
1877 // needs to be moved back to the center.
1878 if (event->flags() & ui::EF_IS_NON_CLIENT) {
1879 synthetic_move_sent_ = true;
1880 window_->MoveCursorTo(center);
1881 return;
1882 }
1883
1884 blink::WebMouseEvent mouse_event =
1885 ui::MakeWebMouseEvent(*event, base::Bind(&GetScreenLocationFromEvent));
1886
1887 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED ||
1888 event->type() == ui::ET_MOUSE_DRAGGED) &&
1889 mouse_event.x == center.x() && mouse_event.y == center.y();
1890
1891 // For fractional scale factors, the conversion from pixels to dip and
1892 // vice versa could result in off by 1 or 2 errors which hurts us because
1893 // we want to avoid sending the artificial move to center event to the
1894 // renderer. Sending the move to center to the renderer cause the cursor
1895 // to bounce around the center of the screen leading to the lock operation
1896 // not working correctly.
1897 // Workaround is to treat a mouse move or drag event off by at most 2 px
1898 // from the center as a move to center event.
1899 if (synthetic_move_sent_ &&
1900 IsFractionalScaleFactor(current_device_scale_factor_)) {
1901 if (event->type() == ui::ET_MOUSE_MOVED ||
1902 event->type() == ui::ET_MOUSE_DRAGGED) {
1903 if ((abs(mouse_event.x - center.x()) <= 2) &&
1904 (abs(mouse_event.y - center.y()) <= 2)) {
1905 is_move_to_center_event = true;
1906 }
1907 }
1908 }
1909
1910 ModifyEventMovementAndCoords(*event, &mouse_event);
1911
1912 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_;
1913 if (should_not_forward) {
1914 synthetic_move_sent_ = false;
1915 } else {
1916 // Check if the mouse has reached the border and needs to be centered.
1917 if (ShouldMoveToCenter()) {
1918 synthetic_move_sent_ = true;
1919 window_->MoveCursorTo(center);
1920 }
1921 bool is_selection_popup = popup_child_host_view_ &&
1922 popup_child_host_view_->NeedsInputGrab();
1923 // Forward event to renderer.
1924 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) &&
1925 !(event->flags() & ui::EF_FROM_TOUCH)) {
1926 host_->ForwardMouseEvent(mouse_event);
1927 // Ensure that we get keyboard focus on mouse down as a plugin window
1928 // may have grabbed keyboard focus.
1929 if (event->type() == ui::ET_MOUSE_PRESSED)
1930 SetKeyboardFocus();
1931 }
1932 }
1933 return;
1934 }
1935
1936 // As the overscroll is handled during scroll events from the trackpad, the
1937 // RWHVA window is transformed by the overscroll controller. This transform
1938 // triggers a synthetic mouse-move event to be generated (by the aura
1939 // RootWindow). But this event interferes with the overscroll gesture. So,
1940 // ignore such synthetic mouse-move events if an overscroll gesture is in
1941 // progress.
1942 if (overscroll_controller_ &&
1943 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE &&
1944 event->flags() & ui::EF_IS_SYNTHESIZED &&
1945 (event->type() == ui::ET_MOUSE_ENTERED ||
1946 event->type() == ui::ET_MOUSE_EXITED ||
1947 event->type() == ui::ET_MOUSE_MOVED)) {
1948 event->StopPropagation();
1949 return;
1950 }
1951
1952 if (event->type() == ui::ET_MOUSEWHEEL) {
1953 #if defined(OS_WIN)
1954 // We get mouse wheel/scroll messages even if we are not in the foreground.
1955 // So here we check if we have any owned popup windows in the foreground and
1956 // dismiss them.
1957 aura::WindowTreeHost* host = window_->GetHost();
1958 if (host) {
1959 HWND parent = host->GetAcceleratedWidget();
1960 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT);
1961 EnumThreadWindows(GetCurrentThreadId(),
1962 DismissOwnedPopups,
1963 reinterpret_cast<LPARAM>(toplevel_hwnd));
1964 }
1965 #endif
1966 blink::WebMouseWheelEvent mouse_wheel_event =
1967 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event),
1968 base::Bind(&GetScreenLocationFromEvent));
1969 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) {
1970 if (ShouldRouteEvent(event)) {
1971 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent(
1972 this, &mouse_wheel_event, *event->latency());
1973 } else {
1974 ProcessMouseWheelEvent(mouse_wheel_event, *event->latency());
1975 }
1976 }
1977 } else {
1978 bool is_selection_popup =
1979 popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab();
1980 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) &&
1981 !(event->flags() & ui::EF_FROM_TOUCH)) {
1982 // Confirm existing composition text on mouse press, to make sure
1983 // the input caret won't be moved with an ongoing composition text.
1984 if (event->type() == ui::ET_MOUSE_PRESSED)
1985 FinishImeCompositionSession();
1986
1987 blink::WebMouseEvent mouse_event = ui::MakeWebMouseEvent(
1988 *event, base::Bind(&GetScreenLocationFromEvent));
1989 ModifyEventMovementAndCoords(*event, &mouse_event);
1990 if (ShouldRouteEvent(event)) {
1991 host_->delegate()->GetInputEventRouter()->RouteMouseEvent(
1992 this, &mouse_event, *event->latency());
1993 } else {
1994 ProcessMouseEvent(mouse_event, *event->latency());
1995 }
1996
1997 // Ensure that we get keyboard focus on mouse down as a plugin window may
1998 // have grabbed keyboard focus.
1999 if (event->type() == ui::ET_MOUSE_PRESSED)
2000 SetKeyboardFocus();
2001 }
2002 }
2003
2004 switch (event->type()) {
2005 case ui::ET_MOUSE_PRESSED:
2006 window_->SetCapture();
2007 break;
2008 case ui::ET_MOUSE_RELEASED:
2009 if (!NeedsMouseCapture())
2010 window_->ReleaseCapture();
2011 break;
2012 default:
2013 break;
2014 }
2015
2016 if (!IsXButtonUpEvent(event))
2017 event->SetHandled();
2018 } 1583 }
2019 1584
2020 cc::FrameSinkId RenderWidgetHostViewAura::FrameSinkIdAtPoint( 1585 cc::FrameSinkId RenderWidgetHostViewAura::FrameSinkIdAtPoint(
2021 cc::SurfaceHittestDelegate* delegate, 1586 cc::SurfaceHittestDelegate* delegate,
2022 const gfx::Point& point, 1587 const gfx::Point& point,
2023 gfx::Point* transformed_point) { 1588 gfx::Point* transformed_point) {
2024 DCHECK(device_scale_factor_ != 0.0f); 1589 DCHECK(device_scale_factor_ != 0.0f);
2025 1590
2026 // The surface hittest happens in device pixels, so we need to convert the 1591 // The surface hittest happens in device pixels, so we need to convert the
2027 // |point| from DIPs to pixels before hittesting. 1592 // |point| from DIPs to pixels before hittesting.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 if (rvh && rvh->GetDelegate()) 1666 if (rvh && rvh->GetDelegate())
2102 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); 1667 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false);
2103 1668
2104 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); 1669 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance());
2105 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); 1670 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard();
2106 } 1671 }
2107 #endif 1672 #endif
2108 } 1673 }
2109 1674
2110 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { 1675 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
2111 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); 1676 event_handler_->OnScrollEvent(event);
2112
2113 if (event->type() == ui::ET_SCROLL) {
2114 #if !defined(OS_WIN)
2115 // TODO(ananta)
2116 // Investigate if this is true for Windows 8 Metro ASH as well.
2117 if (event->finger_count() != 2)
2118 return;
2119 #endif
2120 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEventFlingCancel();
2121 // Coordinates need to be transferred to the fling cancel gesture only
2122 // for Surface-targeting to ensure that it is targeted to the correct
2123 // RenderWidgetHost.
2124 gesture_event.x = event->x();
2125 gesture_event.y = event->y();
2126 blink::WebMouseWheelEvent mouse_wheel_event = ui::MakeWebMouseWheelEvent(
2127 *event, base::Bind(&GetScreenLocationFromEvent));
2128 if (ShouldRouteEvent(event)) {
2129 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
2130 this, &gesture_event, ui::LatencyInfo(ui::SourceEventType::WHEEL));
2131 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent(
2132 this, &mouse_wheel_event, *event->latency());
2133 } else {
2134 host_->ForwardGestureEvent(gesture_event);
2135 host_->ForwardWheelEventWithLatencyInfo(mouse_wheel_event,
2136 *event->latency());
2137 }
2138 RecordAction(base::UserMetricsAction("TrackpadScroll"));
2139 } else if (event->type() == ui::ET_SCROLL_FLING_START ||
2140 event->type() == ui::ET_SCROLL_FLING_CANCEL) {
2141 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEvent(
2142 *event, base::Bind(&GetScreenLocationFromEvent));
2143 if (ShouldRouteEvent(event)) {
2144 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
2145 this, &gesture_event, ui::LatencyInfo(ui::SourceEventType::WHEEL));
2146 } else {
2147 host_->ForwardGestureEvent(gesture_event);
2148 }
2149 if (event->type() == ui::ET_SCROLL_FLING_START)
2150 RecordAction(base::UserMetricsAction("TrackpadScrollFling"));
2151 }
2152
2153 event->SetHandled();
2154 } 1677 }
2155 1678
2156 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { 1679 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
2157 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent"); 1680 event_handler_->OnTouchEvent(event);
2158
2159 bool had_no_pointer = !pointer_state_.GetPointerCount();
2160
2161 // Update the touch event first.
2162 if (!pointer_state_.OnTouch(*event)) {
2163 event->StopPropagation();
2164 return;
2165 }
2166
2167 blink::WebTouchEvent touch_event;
2168 bool handled = selection_controller_->WillHandleTouchEvent(pointer_state_);
2169 if (handled) {
2170 event->SetHandled();
2171 } else {
2172 touch_event = ui::CreateWebTouchEventFromMotionEvent(
2173 pointer_state_, event->may_cause_scrolling());
2174 }
2175 pointer_state_.CleanupRemovedTouchPoints(*event);
2176
2177 if (handled)
2178 return;
2179
2180 if (had_no_pointer)
2181 selection_controller_client_->OnTouchDown();
2182 if (!pointer_state_.GetPointerCount())
2183 selection_controller_client_->OnTouchUp();
2184
2185 // It is important to always mark events as being handled asynchronously when
2186 // they are forwarded. This ensures that the current event does not get
2187 // processed by the gesture recognizer before events currently awaiting
2188 // dispatch in the touch queue.
2189 event->DisableSynchronousHandling();
2190
2191 // Set unchanged touch point to StateStationary for touchmove and
2192 // touchcancel to make sure only send one ack per WebTouchEvent.
2193 MarkUnchangedTouchPointsAsStationary(&touch_event, event->touch_id());
2194 if (ShouldRouteEvent(event)) {
2195 host_->delegate()->GetInputEventRouter()->RouteTouchEvent(
2196 this, &touch_event, *event->latency());
2197 } else {
2198 ProcessTouchEvent(touch_event, *event->latency());
2199 }
2200 } 1681 }
2201 1682
2202 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { 1683 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
2203 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent"); 1684 event_handler_->OnGestureEvent(event);
2204
2205 if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
2206 event->type() == ui::ET_GESTURE_PINCH_UPDATE ||
2207 event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) {
2208 event->SetHandled();
2209 return;
2210 }
2211
2212 HandleGestureForTouchSelection(event);
2213 if (event->handled())
2214 return;
2215
2216 // Confirm existing composition text on TAP gesture, to make sure the input
2217 // caret won't be moved with an ongoing composition text.
2218 if (event->type() == ui::ET_GESTURE_TAP)
2219 FinishImeCompositionSession();
2220
2221 blink::WebGestureEvent gesture =
2222 ui::MakeWebGestureEvent(*event, base::Bind(&GetScreenLocationFromEvent));
2223 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
2224 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an
2225 // event to stop any in-progress flings.
2226 blink::WebGestureEvent fling_cancel = gesture;
2227 fling_cancel.type = blink::WebInputEvent::GestureFlingCancel;
2228 fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen;
2229 if (ShouldRouteEvent(event)) {
2230 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
2231 this, &fling_cancel, ui::LatencyInfo(ui::SourceEventType::TOUCH));
2232 } else {
2233 host_->ForwardGestureEvent(fling_cancel);
2234 }
2235 }
2236
2237 if (gesture.type != blink::WebInputEvent::Undefined) {
2238 if (ShouldRouteEvent(event)) {
2239 host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
2240 this, &gesture, *event->latency());
2241 } else {
2242 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency());
2243 }
2244
2245 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
2246 event->type() == ui::ET_GESTURE_SCROLL_UPDATE ||
2247 event->type() == ui::ET_GESTURE_SCROLL_END) {
2248 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
2249 } else if (event->type() == ui::ET_SCROLL_FLING_START) {
2250 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
2251 }
2252 }
2253
2254 // If a gesture is not processed by the webpage, then WebKit processes it
2255 // (e.g. generates synthetic mouse events).
2256 event->SetHandled();
2257 } 1685 }
2258 1686
2259 //////////////////////////////////////////////////////////////////////////////// 1687 ////////////////////////////////////////////////////////////////////////////////
2260 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: 1688 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
2261 1689
2262 bool RenderWidgetHostViewAura::ShouldActivate() const { 1690 bool RenderWidgetHostViewAura::ShouldActivate() const {
2263 aura::WindowTreeHost* host = window_->GetHost(); 1691 aura::WindowTreeHost* host = window_->GetHost();
2264 if (!host) 1692 if (!host)
2265 return true; 1693 return true;
2266 const ui::Event* event = host->dispatcher()->current_event(); 1694 const ui::Event* event = host->dispatcher()->current_event();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 display::Screen::GetScreen()->RemoveObserver(this); 1816 display::Screen::GetScreen()->RemoveObserver(this);
2389 1817
2390 // This call is usually no-op since |this| object is already removed from 1818 // This call is usually no-op since |this| object is already removed from
2391 // the Aura root window and we don't have a way to get an input method 1819 // the Aura root window and we don't have a way to get an input method
2392 // object associated with the window, but just in case. 1820 // object associated with the window, but just in case.
2393 DetachFromInputMethod(); 1821 DetachFromInputMethod();
2394 } 1822 }
2395 if (popup_parent_host_view_) { 1823 if (popup_parent_host_view_) {
2396 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || 1824 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL ||
2397 popup_parent_host_view_->popup_child_host_view_ == this); 1825 popup_parent_host_view_->popup_child_host_view_ == this);
2398 popup_parent_host_view_->popup_child_host_view_ = NULL; 1826 popup_parent_host_view_->SetPopupChild(nullptr);
2399 } 1827 }
2400 if (popup_child_host_view_) { 1828 if (popup_child_host_view_) {
2401 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || 1829 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL ||
2402 popup_child_host_view_->popup_parent_host_view_ == this); 1830 popup_child_host_view_->popup_parent_host_view_ == this);
2403 popup_child_host_view_->popup_parent_host_view_ = NULL; 1831 popup_child_host_view_->popup_parent_host_view_ = NULL;
2404 } 1832 }
2405 event_filter_for_popup_exit_.reset(); 1833 event_filter_for_popup_exit_.reset();
2406 1834
2407 #if defined(OS_WIN) 1835 #if defined(OS_WIN)
2408 // The LegacyRenderWidgetHostHWND window should have been destroyed in 1836 // The LegacyRenderWidgetHostHWND window should have been destroyed in
(...skipping 10 matching lines...) Expand all
2419 1847
2420 #endif 1848 #endif
2421 1849
2422 if (text_input_manager_) 1850 if (text_input_manager_)
2423 text_input_manager_->RemoveObserver(this); 1851 text_input_manager_->RemoveObserver(this);
2424 } 1852 }
2425 1853
2426 void RenderWidgetHostViewAura::CreateAuraWindow() { 1854 void RenderWidgetHostViewAura::CreateAuraWindow() {
2427 DCHECK(!window_); 1855 DCHECK(!window_);
2428 window_ = new aura::Window(this); 1856 window_ = new aura::Window(this);
1857 event_handler_->set_window(window_);
2429 window_observer_.reset(new WindowObserver(this)); 1858 window_observer_.reset(new WindowObserver(this));
2430 1859
2431 aura::client::SetTooltipText(window_, &tooltip_); 1860 aura::client::SetTooltipText(window_, &tooltip_);
2432 aura::client::SetActivationDelegate(window_, this); 1861 aura::client::SetActivationDelegate(window_, this);
2433 aura::client::SetFocusChangeObserver(window_, this); 1862 aura::client::SetFocusChangeObserver(window_, this);
2434 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 1863 window_->set_layer_owner_delegate(delegated_frame_host_.get());
2435 display::Screen::GetScreen()->AddObserver(this); 1864 display::Screen::GetScreen()->AddObserver(this);
2436 } 1865 }
2437 1866
2438 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { 1867 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 return popup_type_ == blink::WebPopupTypePage; 1947 return popup_type_ == blink::WebPopupTypePage;
2519 } 1948 }
2520 1949
2521 bool RenderWidgetHostViewAura::NeedsMouseCapture() { 1950 bool RenderWidgetHostViewAura::NeedsMouseCapture() {
2522 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1951 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2523 return NeedsInputGrab(); 1952 return NeedsInputGrab();
2524 #endif 1953 #endif
2525 return false; 1954 return false;
2526 } 1955 }
2527 1956
2528 void RenderWidgetHostViewAura::FinishImeCompositionSession() { 1957 void RenderWidgetHostViewAura::SetTooltipsEnabled(bool enable) {
2529 if (!has_composition_text_) 1958 if (enable) {
1959 tooltip_disabler_.reset();
1960 } else {
1961 tooltip_disabler_.reset(
1962 new aura::client::ScopedTooltipDisabler(window_->GetRootWindow()));
1963 }
1964 }
1965
1966 void RenderWidgetHostViewAura::ShowContextMenu(
1967 const ContextMenuParams& params) {
1968 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will
1969 // actually show the disambiguation popup.
1970 RenderViewHost* rvh = RenderViewHost::From(host_);
1971 if (!rvh)
2530 return; 1972 return;
2531 1973
2532 if (!!text_input_manager_ && !!text_input_manager_->GetActiveWidget()) { 1974 RenderViewHostDelegate* delegate = rvh->GetDelegate();
2533 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false); 1975 if (!delegate)
2534 } 1976 return;
2535 ImeCancelComposition();
2536 }
2537 1977
2538 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( 1978 RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView();
2539 const ui::MouseEvent& ui_mouse_event, 1979 if (!delegate_view)
2540 blink::WebMouseEvent* event) { 1980 return;
2541 // If the mouse has just entered, we must report zero movementX/Y. Hence we 1981 delegate_view->ShowContextMenu(GetFocusedFrame(), params);
2542 // reset any global_mouse_position set previously.
2543 if (ui_mouse_event.type() == ui::ET_MOUSE_ENTERED ||
2544 ui_mouse_event.type() == ui::ET_MOUSE_EXITED) {
2545 global_mouse_position_.SetPoint(event->globalX, event->globalY);
2546 }
2547
2548 // Movement is computed by taking the difference of the new cursor position
2549 // and the previous. Under mouse lock the cursor will be warped back to the
2550 // center so that we are not limited by clipping boundaries.
2551 // We do not measure movement as the delta from cursor to center because
2552 // we may receive more mouse movement events before our warp has taken
2553 // effect.
2554 event->movementX = event->globalX - global_mouse_position_.x();
2555 event->movementY = event->globalY - global_mouse_position_.y();
2556
2557 global_mouse_position_.SetPoint(event->globalX, event->globalY);
2558
2559 // Under mouse lock, coordinates of mouse are locked to what they were when
2560 // mouse lock was entered.
2561 if (mouse_locked_) {
2562 event->x = unlocked_mouse_position_.x();
2563 event->y = unlocked_mouse_position_.y();
2564 event->windowX = unlocked_mouse_position_.x();
2565 event->windowY = unlocked_mouse_position_.y();
2566 event->globalX = unlocked_global_mouse_position_.x();
2567 event->globalY = unlocked_global_mouse_position_.y();
2568 } else {
2569 unlocked_mouse_position_.SetPoint(event->x, event->y);
2570 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY);
2571 }
2572 } 1982 }
2573 1983
2574 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState( 1984 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2575 bool is_visible) { 1985 bool is_visible) {
2576 if (host_->is_hidden() || 1986 if (host_->is_hidden() ||
2577 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || 1987 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2578 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) 1988 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2579 return; 1989 return;
2580 1990
2581 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE; 1991 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
(...skipping 21 matching lines...) Expand all
2603 2013
2604 if (snapped && snapped != window_) 2014 if (snapped && snapped != window_)
2605 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); 2015 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer());
2606 2016
2607 has_snapped_to_boundary_ = true; 2017 has_snapped_to_boundary_ = true;
2608 } 2018 }
2609 2019
2610 bool RenderWidgetHostViewAura::OnShowContextMenu( 2020 bool RenderWidgetHostViewAura::OnShowContextMenu(
2611 const ContextMenuParams& params) { 2021 const ContextMenuParams& params) {
2612 #if defined(OS_WIN) 2022 #if defined(OS_WIN)
2613 last_context_menu_params_.reset(); 2023 event_handler_->SetContextMenuParams(params);
2614 2024 return params.source_type != ui::MENU_SOURCE_LONG_PRESS;
2615 if (params.source_type == ui::MENU_SOURCE_LONG_PRESS) { 2025 #else
2616 last_context_menu_params_.reset(new ContextMenuParams);
2617 *last_context_menu_params_ = params;
2618 return false;
2619 }
2620 #endif
2621 return true; 2026 return true;
2027 #endif // defined(OS_WIN)
2622 } 2028 }
2623 2029
2624 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest( 2030 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest(
2625 std::unique_ptr<TouchSelectionControllerClientAura> client) { 2031 std::unique_ptr<TouchSelectionControllerClientAura> client) {
2626 selection_controller_client_.swap(client); 2032 selection_controller_client_.swap(client);
2627 CreateSelectionController(); 2033 CreateSelectionController();
2628 disable_input_event_router_for_testing_ = true;
2629 } 2034 }
2630 2035
2631 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { 2036 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
2632 SnapToPhysicalPixelBoundary(); 2037 SnapToPhysicalPixelBoundary();
2633 // Don't recursively call SetBounds if this bounds update is the result of 2038 // Don't recursively call SetBounds if this bounds update is the result of
2634 // a Window::SetBoundsInternal call. 2039 // a Window::SetBoundsInternal call.
2635 if (!in_bounds_changed_) 2040 if (!in_bounds_changed_)
2636 window_->SetBounds(rect); 2041 window_->SetBounds(rect);
2637 host_->WasResized(); 2042 host_->WasResized();
2638 delegated_frame_host_->WasResized(); 2043 delegated_frame_host_->WasResized();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 const gfx::Rect& clip) { 2079 const gfx::Rect& clip) {
2675 if (!clip.IsEmpty()) { 2080 if (!clip.IsEmpty()) {
2676 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); 2081 gfx::Rect to_paint = gfx::SubtractRects(rect, clip);
2677 if (!to_paint.IsEmpty()) 2082 if (!to_paint.IsEmpty())
2678 window_->SchedulePaintInRect(to_paint); 2083 window_->SchedulePaintInRect(to_paint);
2679 } else { 2084 } else {
2680 window_->SchedulePaintInRect(rect); 2085 window_->SchedulePaintInRect(rect);
2681 } 2086 }
2682 } 2087 }
2683 2088
2684 bool RenderWidgetHostViewAura::ShouldMoveToCenter() {
2685 gfx::Rect rect = window_->bounds();
2686 rect = ConvertRectToScreen(rect);
2687 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
2688 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
2689
2690 return global_mouse_position_.x() < rect.x() + border_x ||
2691 global_mouse_position_.x() > rect.right() - border_x ||
2692 global_mouse_position_.y() < rect.y() + border_y ||
2693 global_mouse_position_.y() > rect.bottom() - border_y;
2694 }
2695
2696 void RenderWidgetHostViewAura::AddedToRootWindow() { 2089 void RenderWidgetHostViewAura::AddedToRootWindow() {
2697 window_->GetHost()->AddObserver(this); 2090 window_->GetHost()->AddObserver(this);
2698 UpdateScreenInfo(window_); 2091 UpdateScreenInfo(window_);
2699 2092
2700 aura::client::CursorClient* cursor_client = 2093 aura::client::CursorClient* cursor_client =
2701 aura::client::GetCursorClient(window_->GetRootWindow()); 2094 aura::client::GetCursorClient(window_->GetRootWindow());
2702 if (cursor_client) { 2095 if (cursor_client) {
2703 cursor_client->AddObserver(this); 2096 cursor_client->AddObserver(this);
2704 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); 2097 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
2705 } 2098 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2792 ui::TouchSelectionController::Config tsc_config; 2185 ui::TouchSelectionController::Config tsc_config;
2793 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds( 2186 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds(
2794 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms()); 2187 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms());
2795 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance() 2188 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance()
2796 ->max_touch_move_in_pixels_for_click(); 2189 ->max_touch_move_in_pixels_for_click();
2797 tsc_config.enable_longpress_drag_selection = false; 2190 tsc_config.enable_longpress_drag_selection = false;
2798 selection_controller_.reset(new ui::TouchSelectionController( 2191 selection_controller_.reset(new ui::TouchSelectionController(
2799 selection_controller_client_.get(), tsc_config)); 2192 selection_controller_client_.get(), tsc_config));
2800 } 2193 }
2801 2194
2802 void RenderWidgetHostViewAura::HandleGestureForTouchSelection(
2803 ui::GestureEvent* event) {
2804 switch (event->type()) {
2805 case ui::ET_GESTURE_LONG_PRESS:
2806 if (selection_controller_->WillHandleLongPressEvent(
2807 event->time_stamp(), event->location_f())) {
2808 event->SetHandled();
2809 }
2810 break;
2811 case ui::ET_GESTURE_TAP:
2812 if (selection_controller_->WillHandleTapEvent(
2813 event->location_f(), event->details().tap_count())) {
2814 event->SetHandled();
2815 }
2816 break;
2817 case ui::ET_GESTURE_SCROLL_BEGIN:
2818 selection_controller_client_->OnScrollStarted();
2819 break;
2820 case ui::ET_GESTURE_SCROLL_END:
2821 selection_controller_client_->OnScrollCompleted();
2822 break;
2823 #if defined(OS_WIN)
2824 case ui::ET_GESTURE_LONG_TAP: {
2825 if (!last_context_menu_params_)
2826 break;
2827
2828 std::unique_ptr<ContextMenuParams> context_menu_params =
2829 std::move(last_context_menu_params_);
2830
2831 // On Windows we want to display the context menu when the long press
2832 // gesture is released. To achieve that, we switch the saved context
2833 // menu params source type to MENU_SOURCE_TOUCH. This is to ensure that
2834 // the RenderWidgetHostViewAura::OnShowContextMenu function which is
2835 // called from the ShowContextMenu call below, does not treat it as
2836 // a context menu request coming in from the long press gesture.
2837 DCHECK(context_menu_params->source_type == ui::MENU_SOURCE_LONG_PRESS);
2838 context_menu_params->source_type = ui::MENU_SOURCE_TOUCH;
2839
2840 RenderViewHostDelegateView* delegate_view =
2841 GetRenderViewHostDelegateView();
2842 if (delegate_view)
2843 delegate_view->ShowContextMenu(GetFocusedFrame(),
2844 *context_menu_params);
2845
2846 event->SetHandled();
2847 // WARNING: we may have been deleted during the call to ShowContextMenu().
2848 break;
2849 }
2850 #endif
2851 default:
2852 break;
2853 }
2854 }
2855
2856 void RenderWidgetHostViewAura::ForwardMouseEventToParent(
2857 ui::MouseEvent* event) {
2858 // Needed to propagate mouse event to |window_->parent()->delegate()|, but
2859 // note that it might be something other than a WebContentsViewAura instance.
2860 // TODO(pkotwicz): Find a better way of doing this.
2861 // In fullscreen mode which is typically used by flash, don't forward
2862 // the mouse events to the parent. The renderer and the plugin process
2863 // handle these events.
2864 if (is_fullscreen_)
2865 return;
2866
2867 if (event->flags() & ui::EF_FROM_TOUCH)
2868 return;
2869
2870 if (!window_->parent() || !window_->parent()->delegate())
2871 return;
2872
2873 // Take a copy of |event|, to avoid ConvertLocationToTarget mutating the
2874 // event.
2875 std::unique_ptr<ui::Event> event_copy = ui::Event::Clone(*event);
2876 ui::MouseEvent* mouse_event = static_cast<ui::MouseEvent*>(event_copy.get());
2877 mouse_event->ConvertLocationToTarget(window_, window_->parent());
2878 window_->parent()->delegate()->OnMouseEvent(mouse_event);
2879 if (mouse_event->handled())
2880 event->SetHandled();
2881 }
2882
2883 RenderViewHostDelegateView*
2884 RenderWidgetHostViewAura::GetRenderViewHostDelegateView() {
2885 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will
2886 // actually show the disambiguation popup.
2887 RenderViewHost* rvh = RenderViewHost::From(host_);
2888 if (!rvh)
2889 return nullptr;
2890
2891 RenderViewHostDelegate* delegate = rvh->GetDelegate();
2892 if (!delegate)
2893 return nullptr;
2894
2895 return delegate->GetDelegateView();
2896 }
2897
2898 //////////////////////////////////////////////////////////////////////////////// 2195 ////////////////////////////////////////////////////////////////////////////////
2899 // DelegatedFrameHost, public: 2196 // DelegatedFrameHost, public:
2900 2197
2901 ui::Layer* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const { 2198 ui::Layer* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const {
2902 return window_->layer(); 2199 return window_->layer();
2903 } 2200 }
2904 2201
2905 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const { 2202 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const {
2906 return !host_->is_hidden(); 2203 return !host_->is_hidden();
2907 } 2204 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
3079 if (GetTextInputManager() 2376 if (GetTextInputManager()
3080 ->GetTextSelection(focused_view) 2377 ->GetTextSelection(focused_view)
3081 ->GetSelectedText(&selected_text)) { 2378 ->GetSelectedText(&selected_text)) {
3082 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. 2379 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
3083 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); 2380 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
3084 clipboard_writer.WriteText(selected_text); 2381 clipboard_writer.WriteText(selected_text);
3085 } 2382 }
3086 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) 2383 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
3087 } 2384 }
3088 2385
2386 void RenderWidgetHostViewAura::SetPopupChild(
2387 RenderWidgetHostViewAura* popup_child_host_view) {
2388 popup_child_host_view_ = popup_child_host_view;
2389 event_handler_->SetPopupChild(
2390 popup_child_host_view,
2391 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr);
2392 }
2393
3089 } // namespace content 2394 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698