| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 synthetic_move_sent_(false), | |
| 443 cursor_visibility_state_in_renderer_(UNKNOWN), | 373 cursor_visibility_state_in_renderer_(UNKNOWN), |
| 444 #if defined(OS_WIN) | 374 #if defined(OS_WIN) |
| 445 legacy_render_widget_host_HWND_(nullptr), | 375 legacy_render_widget_host_HWND_(nullptr), |
| 446 legacy_window_destroyed_(false), | 376 legacy_window_destroyed_(false), |
| 447 virtual_keyboard_requested_(false), | 377 virtual_keyboard_requested_(false), |
| 448 #endif | 378 #endif |
| 449 has_snapped_to_boundary_(false), | 379 has_snapped_to_boundary_(false), |
| 450 is_guest_view_hack_(is_guest_view_hack), | 380 is_guest_view_hack_(is_guest_view_hack), |
| 451 set_focus_on_mouse_down_or_key_event_(false), | |
| 452 device_scale_factor_(0.0f), | 381 device_scale_factor_(0.0f), |
| 453 disable_input_event_router_for_testing_(false), | |
| 454 last_active_widget_process_id_(ChildProcessHost::kInvalidUniqueID), | 382 last_active_widget_process_id_(ChildProcessHost::kInvalidUniqueID), |
| 455 last_active_widget_routing_id_(MSG_ROUTING_NONE), | 383 last_active_widget_routing_id_(MSG_ROUTING_NONE), |
| 384 event_handler_(new RenderWidgetHostViewEventHandler(host_, this, this)), |
| 456 weak_ptr_factory_(this) { | 385 weak_ptr_factory_(this) { |
| 457 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 386 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 458 delegated_frame_host_ = base::MakeUnique<DelegatedFrameHost>( | 387 delegated_frame_host_ = base::MakeUnique<DelegatedFrameHost>( |
| 459 factory->GetContextFactory()->AllocateFrameSinkId(), this); | 388 factory->GetContextFactory()->AllocateFrameSinkId(), this); |
| 460 | 389 |
| 461 if (!is_guest_view_hack_) | 390 if (!is_guest_view_hack_) |
| 462 host_->SetView(this); | 391 host_->SetView(this); |
| 463 | 392 |
| 464 // Let the page-level input event router know about our surface ID | 393 // Let the page-level input event router know about our surface ID |
| 465 // namespace for surface-based hit testing. | 394 // namespace for surface-based hit testing. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or | 453 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or |
| 525 // similar mechanism to ensure a second popup doesn't cause the first one | 454 // similar mechanism to ensure a second popup doesn't cause the first one |
| 526 // to never get a chance to filter events. See crbug.com/160589. | 455 // to never get a chance to filter events. See crbug.com/160589. |
| 527 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_); | 456 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_); |
| 528 if (transient_window_client) { | 457 if (transient_window_client) { |
| 529 transient_window_client->RemoveTransientChild( | 458 transient_window_client->RemoveTransientChild( |
| 530 popup_parent_host_view_->window_, old_child->window_); | 459 popup_parent_host_view_->window_, old_child->window_); |
| 531 } | 460 } |
| 532 old_child->popup_parent_host_view_ = NULL; | 461 old_child->popup_parent_host_view_ = NULL; |
| 533 } | 462 } |
| 534 popup_parent_host_view_->popup_child_host_view_ = this; | 463 popup_parent_host_view_->SetPopupChild(this); |
| 535 window_->SetType(ui::wm::WINDOW_TYPE_MENU); | 464 window_->SetType(ui::wm::WINDOW_TYPE_MENU); |
| 536 window_->Init(ui::LAYER_SOLID_COLOR); | 465 window_->Init(ui::LAYER_SOLID_COLOR); |
| 537 window_->SetName("RenderWidgetHostViewAura"); | 466 window_->SetName("RenderWidgetHostViewAura"); |
| 538 window_->layer()->SetColor(background_color_); | 467 window_->layer()->SetColor(background_color_); |
| 539 | 468 |
| 540 // Setting the transient child allows for the popup to get mouse events when | 469 // Setting the transient child allows for the popup to get mouse events when |
| 541 // in a system modal dialog. Do this before calling ParentWindowWithContext | 470 // in a system modal dialog. Do this before calling ParentWindowWithContext |
| 542 // below so that the transient parent is visible to WindowTreeClient. | 471 // below so that the transient parent is visible to WindowTreeClient. |
| 543 // This fixes crbug.com/328593. | 472 // This fixes crbug.com/328593. |
| 544 if (transient_window_client) { | 473 if (transient_window_client) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 569 window_->Init(ui::LAYER_SOLID_COLOR); | 498 window_->Init(ui::LAYER_SOLID_COLOR); |
| 570 window_->SetName("RenderWidgetHostViewAura"); | 499 window_->SetName("RenderWidgetHostViewAura"); |
| 571 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 500 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 572 window_->layer()->SetColor(background_color_); | 501 window_->layer()->SetColor(background_color_); |
| 573 | 502 |
| 574 aura::Window* parent = NULL; | 503 aura::Window* parent = NULL; |
| 575 gfx::Rect bounds; | 504 gfx::Rect bounds; |
| 576 if (reference_host_view) { | 505 if (reference_host_view) { |
| 577 aura::Window* reference_window = | 506 aura::Window* reference_window = |
| 578 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; | 507 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; |
| 579 if (reference_window) { | 508 event_handler_->TrackHost(reference_window); |
| 580 host_tracker_.reset(new aura::WindowTracker); | |
| 581 host_tracker_->Add(reference_window); | |
| 582 } | |
| 583 display::Display display = | 509 display::Display display = |
| 584 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window); | 510 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window); |
| 585 parent = reference_window->GetRootWindow(); | 511 parent = reference_window->GetRootWindow(); |
| 586 bounds = display.bounds(); | 512 bounds = display.bounds(); |
| 587 } | 513 } |
| 588 aura::client::ParentWindowWithContext(window_, parent, bounds); | 514 aura::client::ParentWindowWithContext(window_, parent, bounds); |
| 589 Show(); | 515 Show(); |
| 590 Focus(); | 516 Focus(); |
| 591 | 517 |
| 592 const display::Display display = | 518 const display::Display display = |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 | 658 |
| 733 const cc::BeginFrameArgs& RenderWidgetHostViewAura::LastUsedBeginFrameArgs() | 659 const cc::BeginFrameArgs& RenderWidgetHostViewAura::LastUsedBeginFrameArgs() |
| 734 const { | 660 const { |
| 735 return last_begin_frame_args_; | 661 return last_begin_frame_args_; |
| 736 } | 662 } |
| 737 | 663 |
| 738 void RenderWidgetHostViewAura::OnBeginFrameSourcePausedChanged(bool paused) { | 664 void RenderWidgetHostViewAura::OnBeginFrameSourcePausedChanged(bool paused) { |
| 739 // Only used on Android WebView. | 665 // Only used on Android WebView. |
| 740 } | 666 } |
| 741 | 667 |
| 742 void RenderWidgetHostViewAura::SetKeyboardFocus() { | |
| 743 #if defined(OS_WIN) | |
| 744 if (CanFocus()) { | |
| 745 aura::WindowTreeHost* host = window_->GetHost(); | |
| 746 if (host) { | |
| 747 gfx::AcceleratedWidget hwnd = host->GetAcceleratedWidget(); | |
| 748 if (!(::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE)) | |
| 749 ::SetFocus(hwnd); | |
| 750 } | |
| 751 } | |
| 752 #endif | |
| 753 // TODO(wjmaclean): can host_ ever be null? | |
| 754 if (host_ && set_focus_on_mouse_down_or_key_event_) { | |
| 755 set_focus_on_mouse_down_or_key_event_ = false; | |
| 756 host_->Focus(); | |
| 757 } | |
| 758 } | |
| 759 | |
| 760 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { | 668 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { |
| 761 RenderViewHost* rvh = RenderViewHost::From(host_); | 669 RenderViewHost* rvh = RenderViewHost::From(host_); |
| 762 if (!rvh) | 670 if (!rvh) |
| 763 return nullptr; | 671 return nullptr; |
| 764 FrameTreeNode* focused_frame = | 672 FrameTreeNode* focused_frame = |
| 765 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); | 673 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); |
| 766 if (!focused_frame) | 674 if (!focused_frame) |
| 767 return nullptr; | 675 return nullptr; |
| 768 | 676 |
| 769 return focused_frame->current_frame_host(); | 677 return focused_frame->current_frame_host(); |
| 770 } | 678 } |
| 771 | 679 |
| 772 bool RenderWidgetHostViewAura::CanRendererHandleEvent( | |
| 773 const ui::MouseEvent* event, | |
| 774 bool mouse_locked, | |
| 775 bool selection_popup) const { | |
| 776 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) | |
| 777 return false; | |
| 778 | |
| 779 if (event->type() == ui::ET_MOUSE_EXITED) { | |
| 780 if (mouse_locked || selection_popup) | |
| 781 return false; | |
| 782 #if defined(OS_WIN) | |
| 783 // Don't forward the mouse leave message which is received when the context | |
| 784 // menu is displayed by the page. This confuses the page and causes state | |
| 785 // changes. | |
| 786 if (IsShowingContextMenu()) | |
| 787 return false; | |
| 788 #endif | |
| 789 return true; | |
| 790 } | |
| 791 | |
| 792 #if defined(OS_WIN) | |
| 793 // Renderer cannot handle WM_XBUTTON or NC events. | |
| 794 switch (event->native_event().message) { | |
| 795 case WM_XBUTTONDOWN: | |
| 796 case WM_XBUTTONUP: | |
| 797 case WM_XBUTTONDBLCLK: | |
| 798 case WM_NCMOUSELEAVE: | |
| 799 case WM_NCMOUSEMOVE: | |
| 800 case WM_NCLBUTTONDOWN: | |
| 801 case WM_NCLBUTTONUP: | |
| 802 case WM_NCLBUTTONDBLCLK: | |
| 803 case WM_NCRBUTTONDOWN: | |
| 804 case WM_NCRBUTTONUP: | |
| 805 case WM_NCRBUTTONDBLCLK: | |
| 806 case WM_NCMBUTTONDOWN: | |
| 807 case WM_NCMBUTTONUP: | |
| 808 case WM_NCMBUTTONDBLCLK: | |
| 809 case WM_NCXBUTTONDOWN: | |
| 810 case WM_NCXBUTTONUP: | |
| 811 case WM_NCXBUTTONDBLCLK: | |
| 812 return false; | |
| 813 default: | |
| 814 break; | |
| 815 } | |
| 816 #elif defined(USE_X11) | |
| 817 // Renderer only supports standard mouse buttons, so ignore programmable | |
| 818 // buttons. | |
| 819 switch (event->type()) { | |
| 820 case ui::ET_MOUSE_PRESSED: | |
| 821 case ui::ET_MOUSE_RELEASED: { | |
| 822 const int kAllowedButtons = ui::EF_LEFT_MOUSE_BUTTON | | |
| 823 ui::EF_MIDDLE_MOUSE_BUTTON | | |
| 824 ui::EF_RIGHT_MOUSE_BUTTON; | |
| 825 return (event->flags() & kAllowedButtons) != 0; | |
| 826 } | |
| 827 default: | |
| 828 break; | |
| 829 } | |
| 830 #endif | |
| 831 return true; | |
| 832 } | |
| 833 | |
| 834 bool RenderWidgetHostViewAura::ShouldRouteEvent(const ui::Event* event) const { | |
| 835 // We should route an event in two cases: | |
| 836 // 1) Mouse events are routed only if cross-process frames are possible. | |
| 837 // 2) Touch events are always routed. In the absence of a BrowserPlugin | |
| 838 // we expect the routing to always send the event to this view. If | |
| 839 // one or more BrowserPlugins are present, then the event may be targeted | |
| 840 // to one of them, or this view. This allows GuestViews to have access to | |
| 841 // them while still forcing pinch-zoom to be handled by the top-level | |
| 842 // frame. TODO(wjmaclean): At present, this doesn't work for OOPIF, but | |
| 843 // it should be a simple extension to modify RenderWidgetHostViewChildFrame | |
| 844 // in a similar manner to RenderWidgetHostViewGuest. | |
| 845 bool result = host_->delegate() && host_->delegate()->GetInputEventRouter() && | |
| 846 !disable_input_event_router_for_testing_; | |
| 847 // ScrollEvents get transformed into MouseWheel events, and so are treated | |
| 848 // the same as mouse events for routing purposes. | |
| 849 if (event->IsMouseEvent() || event->type() == ui::ET_SCROLL) | |
| 850 result = result && SiteIsolationPolicy::AreCrossProcessFramesPossible(); | |
| 851 return result; | |
| 852 } | |
| 853 | |
| 854 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { | 680 void RenderWidgetHostViewAura::HandleParentBoundsChanged() { |
| 855 SnapToPhysicalPixelBoundary(); | 681 SnapToPhysicalPixelBoundary(); |
| 856 #if defined(OS_WIN) | 682 #if defined(OS_WIN) |
| 857 if (legacy_render_widget_host_HWND_) { | 683 if (legacy_render_widget_host_HWND_) { |
| 858 legacy_render_widget_host_HWND_->SetBounds( | 684 legacy_render_widget_host_HWND_->SetBounds( |
| 859 window_->GetBoundsInRootWindow()); | 685 window_->GetBoundsInRootWindow()); |
| 860 } | 686 } |
| 861 #endif | 687 #endif |
| 862 if (!in_shutdown_) { | 688 if (!in_shutdown_) { |
| 863 // Send screen rects through the delegate if there is one. Not every | 689 // 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... |
| 901 } | 727 } |
| 902 | 728 |
| 903 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color) { | 729 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color) { |
| 904 RenderWidgetHostViewBase::SetBackgroundColor(color); | 730 RenderWidgetHostViewBase::SetBackgroundColor(color); |
| 905 bool opaque = GetBackgroundOpaque(); | 731 bool opaque = GetBackgroundOpaque(); |
| 906 host_->SetBackgroundOpaque(opaque); | 732 host_->SetBackgroundOpaque(opaque); |
| 907 window_->layer()->SetFillsBoundsOpaquely(opaque); | 733 window_->layer()->SetFillsBoundsOpaquely(opaque); |
| 908 window_->layer()->SetColor(color); | 734 window_->layer()->SetColor(color); |
| 909 } | 735 } |
| 910 | 736 |
| 737 bool RenderWidgetHostViewAura::IsMouseLocked() { |
| 738 return event_handler_->mouse_locked(); |
| 739 } |
| 740 |
| 911 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const { | 741 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const { |
| 912 gfx::Rect requested_rect(GetRequestedRendererSize()); | 742 gfx::Rect requested_rect(GetRequestedRendererSize()); |
| 913 requested_rect.Inset(insets_); | 743 requested_rect.Inset(insets_); |
| 914 return requested_rect.size(); | 744 return requested_rect.size(); |
| 915 } | 745 } |
| 916 | 746 |
| 917 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { | 747 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) { |
| 918 if (insets != insets_) { | 748 if (insets != insets_) { |
| 919 insets_ = insets; | 749 insets_ = insets; |
| 920 host_->WasResized(); | 750 host_->WasResized(); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 gfx::NativeViewAccessible | 1095 gfx::NativeViewAccessible |
| 1266 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { | 1096 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { |
| 1267 #if defined(OS_WIN) | 1097 #if defined(OS_WIN) |
| 1268 if (legacy_render_widget_host_HWND_) | 1098 if (legacy_render_widget_host_HWND_) |
| 1269 return legacy_render_widget_host_HWND_->window_accessible(); | 1099 return legacy_render_widget_host_HWND_->window_accessible(); |
| 1270 #endif | 1100 #endif |
| 1271 return NULL; | 1101 return NULL; |
| 1272 } | 1102 } |
| 1273 | 1103 |
| 1274 bool RenderWidgetHostViewAura::LockMouse() { | 1104 bool RenderWidgetHostViewAura::LockMouse() { |
| 1275 aura::Window* root_window = window_->GetRootWindow(); | 1105 return event_handler_->LockMouse(); |
| 1276 if (!root_window) | |
| 1277 return false; | |
| 1278 | |
| 1279 if (mouse_locked_) | |
| 1280 return true; | |
| 1281 | |
| 1282 mouse_locked_ = true; | |
| 1283 #if !defined(OS_WIN) | |
| 1284 window_->SetCapture(); | |
| 1285 #else | |
| 1286 UpdateMouseLockRegion(); | |
| 1287 #endif | |
| 1288 aura::client::CursorClient* cursor_client = | |
| 1289 aura::client::GetCursorClient(root_window); | |
| 1290 if (cursor_client) { | |
| 1291 cursor_client->HideCursor(); | |
| 1292 cursor_client->LockCursor(); | |
| 1293 } | |
| 1294 | |
| 1295 if (ShouldMoveToCenter()) { | |
| 1296 synthetic_move_sent_ = true; | |
| 1297 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
| 1298 } | |
| 1299 tooltip_disabler_.reset(new aura::client::ScopedTooltipDisabler(root_window)); | |
| 1300 return true; | |
| 1301 } | 1106 } |
| 1302 | 1107 |
| 1303 void RenderWidgetHostViewAura::UnlockMouse() { | 1108 void RenderWidgetHostViewAura::UnlockMouse() { |
| 1304 tooltip_disabler_.reset(); | 1109 event_handler_->UnlockMouse(); |
| 1305 | |
| 1306 aura::Window* root_window = window_->GetRootWindow(); | |
| 1307 if (!mouse_locked_ || !root_window) | |
| 1308 return; | |
| 1309 | |
| 1310 mouse_locked_ = false; | |
| 1311 | |
| 1312 if (window_->HasCapture()) | |
| 1313 window_->ReleaseCapture(); | |
| 1314 | |
| 1315 #if defined(OS_WIN) | |
| 1316 ::ClipCursor(NULL); | |
| 1317 #endif | |
| 1318 | |
| 1319 // Ensure that the global mouse position is updated here to its original | |
| 1320 // value. If we don't do this then the synthesized mouse move which is posted | |
| 1321 // after the cursor is moved ends up getting a large movement delta which is | |
| 1322 // not what sites expect. The delta is computed in the | |
| 1323 // ModifyEventMovementAndCoords function. | |
| 1324 global_mouse_position_ = unlocked_global_mouse_position_; | |
| 1325 window_->MoveCursorTo(unlocked_mouse_position_); | |
| 1326 | |
| 1327 aura::client::CursorClient* cursor_client = | |
| 1328 aura::client::GetCursorClient(root_window); | |
| 1329 if (cursor_client) { | |
| 1330 cursor_client->UnlockCursor(); | |
| 1331 cursor_client->ShowCursor(); | |
| 1332 } | |
| 1333 | |
| 1334 host_->LostMouseLock(); | |
| 1335 } | 1110 } |
| 1336 | 1111 |
| 1337 //////////////////////////////////////////////////////////////////////////////// | 1112 //////////////////////////////////////////////////////////////////////////////// |
| 1338 // RenderWidgetHostViewAura, ui::TextInputClient implementation: | 1113 // RenderWidgetHostViewAura, ui::TextInputClient implementation: |
| 1339 void RenderWidgetHostViewAura::SetCompositionText( | 1114 void RenderWidgetHostViewAura::SetCompositionText( |
| 1340 const ui::CompositionText& composition) { | 1115 const ui::CompositionText& composition) { |
| 1341 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) | 1116 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget()) |
| 1342 return; | 1117 return; |
| 1343 | 1118 |
| 1344 // TODO(suzhe): convert both renderer_host and renderer to use | 1119 // TODO(suzhe): convert both renderer_host and renderer to use |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 } | 1169 } |
| 1395 | 1170 |
| 1396 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { | 1171 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) { |
| 1397 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | 1172 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
| 1398 popup_child_host_view_->InsertChar(event); | 1173 popup_child_host_view_->InsertChar(event); |
| 1399 return; | 1174 return; |
| 1400 } | 1175 } |
| 1401 | 1176 |
| 1402 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 | 1177 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547 |
| 1403 // TODO(wjmaclean): can host_ ever be null? | 1178 // TODO(wjmaclean): can host_ ever be null? |
| 1404 if (host_ && | 1179 if (host_ && (event_handler_->accept_return_character() || |
| 1405 (accept_return_character_ || event.GetCharacter() != ui::VKEY_RETURN)) { | 1180 event.GetCharacter() != ui::VKEY_RETURN)) { |
| 1406 // Send a blink::WebInputEvent::Char event to |host_|. | 1181 // Send a blink::WebInputEvent::Char event to |host_|. |
| 1407 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); | 1182 ForwardKeyboardEvent(NativeWebKeyboardEvent(event, event.GetCharacter())); |
| 1408 } | 1183 } |
| 1409 } | 1184 } |
| 1410 | 1185 |
| 1411 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { | 1186 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const { |
| 1412 if (text_input_manager_ && text_input_manager_->GetTextInputState()) | 1187 if (text_input_manager_ && text_input_manager_->GetTextInputState()) |
| 1413 return text_input_manager_->GetTextInputState()->type; | 1188 return text_input_manager_->GetTextInputState()->type; |
| 1414 return ui::TEXT_INPUT_TYPE_NONE; | 1189 return ui::TEXT_INPUT_TYPE_NONE; |
| 1415 } | 1190 } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 return false; | 1539 return false; |
| 1765 } | 1540 } |
| 1766 | 1541 |
| 1767 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { | 1542 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { |
| 1768 } | 1543 } |
| 1769 | 1544 |
| 1770 //////////////////////////////////////////////////////////////////////////////// | 1545 //////////////////////////////////////////////////////////////////////////////// |
| 1771 // RenderWidgetHostViewAura, ui::EventHandler implementation: | 1546 // RenderWidgetHostViewAura, ui::EventHandler implementation: |
| 1772 | 1547 |
| 1773 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { | 1548 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
| 1774 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); | 1549 event_handler_->OnKeyEvent(event); |
| 1775 | |
| 1776 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { | |
| 1777 popup_child_host_view_->OnKeyEvent(event); | |
| 1778 if (event->handled()) | |
| 1779 return; | |
| 1780 } | |
| 1781 | |
| 1782 // We need to handle the Escape key for Pepper Flash. | |
| 1783 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { | |
| 1784 // Focus the window we were created from. | |
| 1785 if (host_tracker_.get() && !host_tracker_->windows().empty()) { | |
| 1786 aura::Window* host = *(host_tracker_->windows().begin()); | |
| 1787 aura::client::FocusClient* client = aura::client::GetFocusClient(host); | |
| 1788 if (client) { | |
| 1789 // Calling host->Focus() may delete |this|. We create a local observer | |
| 1790 // for that. In that case we exit without further access to any members. | |
| 1791 aura::WindowTracker tracker; | |
| 1792 aura::Window* window = window_; | |
| 1793 tracker.Add(window); | |
| 1794 host->Focus(); | |
| 1795 if (!tracker.Contains(window)) { | |
| 1796 event->SetHandled(); | |
| 1797 return; | |
| 1798 } | |
| 1799 } | |
| 1800 } | |
| 1801 Shutdown(); | |
| 1802 } else { | |
| 1803 if (event->key_code() == ui::VKEY_RETURN) { | |
| 1804 // Do not forward return key release events if no press event was handled. | |
| 1805 if (event->type() == ui::ET_KEY_RELEASED && !accept_return_character_) | |
| 1806 return; | |
| 1807 // Accept return key character events between press and release events. | |
| 1808 accept_return_character_ = event->type() == ui::ET_KEY_PRESSED; | |
| 1809 } | |
| 1810 | |
| 1811 // Call SetKeyboardFocus() for not only ET_KEY_PRESSED but also | |
| 1812 // ET_KEY_RELEASED. If a user closed the hotdog menu with ESC key press, | |
| 1813 // we need to notify focus to Blink on ET_KEY_RELEASED for ESC key. | |
| 1814 SetKeyboardFocus(); | |
| 1815 // We don't have to communicate with an input method here. | |
| 1816 NativeWebKeyboardEvent webkit_event(*event); | |
| 1817 ForwardKeyboardEvent(webkit_event); | |
| 1818 } | |
| 1819 event->SetHandled(); | |
| 1820 } | 1550 } |
| 1821 | 1551 |
| 1822 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { | 1552 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { |
| 1823 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent"); | 1553 event_handler_->OnMouseEvent(event); |
| 1824 | |
| 1825 ForwardMouseEventToParent(event); | |
| 1826 // TODO(mgiuca): Return if event->handled() returns true. This currently | |
| 1827 // breaks drop-down lists which means something is incorrectly setting | |
| 1828 // event->handled to true (http://crbug.com/577983). | |
| 1829 | |
| 1830 if (mouse_locked_) { | |
| 1831 aura::client::CursorClient* cursor_client = | |
| 1832 aura::client::GetCursorClient(window_->GetRootWindow()); | |
| 1833 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); | |
| 1834 | |
| 1835 if (event->type() == ui::ET_MOUSEWHEEL) { | |
| 1836 blink::WebMouseWheelEvent mouse_wheel_event = | |
| 1837 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event), | |
| 1838 base::Bind(&GetScreenLocationFromEvent)); | |
| 1839 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) | |
| 1840 host_->ForwardWheelEvent(mouse_wheel_event); | |
| 1841 return; | |
| 1842 } | |
| 1843 | |
| 1844 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
| 1845 | |
| 1846 // If we receive non client mouse messages while we are in the locked state | |
| 1847 // it probably means that the mouse left the borders of our window and | |
| 1848 // needs to be moved back to the center. | |
| 1849 if (event->flags() & ui::EF_IS_NON_CLIENT) { | |
| 1850 synthetic_move_sent_ = true; | |
| 1851 window_->MoveCursorTo(center); | |
| 1852 return; | |
| 1853 } | |
| 1854 | |
| 1855 blink::WebMouseEvent mouse_event = | |
| 1856 ui::MakeWebMouseEvent(*event, base::Bind(&GetScreenLocationFromEvent)); | |
| 1857 | |
| 1858 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || | |
| 1859 event->type() == ui::ET_MOUSE_DRAGGED) && | |
| 1860 mouse_event.x == center.x() && mouse_event.y == center.y(); | |
| 1861 | |
| 1862 // For fractional scale factors, the conversion from pixels to dip and | |
| 1863 // vice versa could result in off by 1 or 2 errors which hurts us because | |
| 1864 // we want to avoid sending the artificial move to center event to the | |
| 1865 // renderer. Sending the move to center to the renderer cause the cursor | |
| 1866 // to bounce around the center of the screen leading to the lock operation | |
| 1867 // not working correctly. | |
| 1868 // Workaround is to treat a mouse move or drag event off by at most 2 px | |
| 1869 // from the center as a move to center event. | |
| 1870 if (synthetic_move_sent_ && | |
| 1871 IsFractionalScaleFactor(current_device_scale_factor_)) { | |
| 1872 if (event->type() == ui::ET_MOUSE_MOVED || | |
| 1873 event->type() == ui::ET_MOUSE_DRAGGED) { | |
| 1874 if ((abs(mouse_event.x - center.x()) <= 2) && | |
| 1875 (abs(mouse_event.y - center.y()) <= 2)) { | |
| 1876 is_move_to_center_event = true; | |
| 1877 } | |
| 1878 } | |
| 1879 } | |
| 1880 | |
| 1881 ModifyEventMovementAndCoords(&mouse_event); | |
| 1882 | |
| 1883 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | |
| 1884 if (should_not_forward) { | |
| 1885 synthetic_move_sent_ = false; | |
| 1886 } else { | |
| 1887 // Check if the mouse has reached the border and needs to be centered. | |
| 1888 if (ShouldMoveToCenter()) { | |
| 1889 synthetic_move_sent_ = true; | |
| 1890 window_->MoveCursorTo(center); | |
| 1891 } | |
| 1892 bool is_selection_popup = popup_child_host_view_ && | |
| 1893 popup_child_host_view_->NeedsInputGrab(); | |
| 1894 // Forward event to renderer. | |
| 1895 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && | |
| 1896 !(event->flags() & ui::EF_FROM_TOUCH)) { | |
| 1897 host_->ForwardMouseEvent(mouse_event); | |
| 1898 // Ensure that we get keyboard focus on mouse down as a plugin window | |
| 1899 // may have grabbed keyboard focus. | |
| 1900 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 1901 SetKeyboardFocus(); | |
| 1902 } | |
| 1903 } | |
| 1904 return; | |
| 1905 } | |
| 1906 | |
| 1907 // As the overscroll is handled during scroll events from the trackpad, the | |
| 1908 // RWHVA window is transformed by the overscroll controller. This transform | |
| 1909 // triggers a synthetic mouse-move event to be generated (by the aura | |
| 1910 // RootWindow). But this event interferes with the overscroll gesture. So, | |
| 1911 // ignore such synthetic mouse-move events if an overscroll gesture is in | |
| 1912 // progress. | |
| 1913 if (overscroll_controller_ && | |
| 1914 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE && | |
| 1915 event->flags() & ui::EF_IS_SYNTHESIZED && | |
| 1916 (event->type() == ui::ET_MOUSE_ENTERED || | |
| 1917 event->type() == ui::ET_MOUSE_EXITED || | |
| 1918 event->type() == ui::ET_MOUSE_MOVED)) { | |
| 1919 event->StopPropagation(); | |
| 1920 return; | |
| 1921 } | |
| 1922 | |
| 1923 if (event->type() == ui::ET_MOUSEWHEEL) { | |
| 1924 #if defined(OS_WIN) | |
| 1925 // We get mouse wheel/scroll messages even if we are not in the foreground. | |
| 1926 // So here we check if we have any owned popup windows in the foreground and | |
| 1927 // dismiss them. | |
| 1928 aura::WindowTreeHost* host = window_->GetHost(); | |
| 1929 if (host) { | |
| 1930 HWND parent = host->GetAcceleratedWidget(); | |
| 1931 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT); | |
| 1932 EnumThreadWindows(GetCurrentThreadId(), | |
| 1933 DismissOwnedPopups, | |
| 1934 reinterpret_cast<LPARAM>(toplevel_hwnd)); | |
| 1935 } | |
| 1936 #endif | |
| 1937 blink::WebMouseWheelEvent mouse_wheel_event = | |
| 1938 ui::MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent&>(*event), | |
| 1939 base::Bind(&GetScreenLocationFromEvent)); | |
| 1940 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) { | |
| 1941 if (ShouldRouteEvent(event)) { | |
| 1942 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( | |
| 1943 this, &mouse_wheel_event, *event->latency()); | |
| 1944 } else { | |
| 1945 ProcessMouseWheelEvent(mouse_wheel_event, *event->latency()); | |
| 1946 } | |
| 1947 } | |
| 1948 } else { | |
| 1949 bool is_selection_popup = | |
| 1950 popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab(); | |
| 1951 if (CanRendererHandleEvent(event, mouse_locked_, is_selection_popup) && | |
| 1952 !(event->flags() & ui::EF_FROM_TOUCH)) { | |
| 1953 // Confirm existing composition text on mouse press, to make sure | |
| 1954 // the input caret won't be moved with an ongoing composition text. | |
| 1955 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 1956 FinishImeCompositionSession(); | |
| 1957 | |
| 1958 blink::WebMouseEvent mouse_event = ui::MakeWebMouseEvent( | |
| 1959 *event, base::Bind(&GetScreenLocationFromEvent)); | |
| 1960 ModifyEventMovementAndCoords(&mouse_event); | |
| 1961 if (ShouldRouteEvent(event)) { | |
| 1962 host_->delegate()->GetInputEventRouter()->RouteMouseEvent( | |
| 1963 this, &mouse_event, *event->latency()); | |
| 1964 } else { | |
| 1965 ProcessMouseEvent(mouse_event, *event->latency()); | |
| 1966 } | |
| 1967 | |
| 1968 // Ensure that we get keyboard focus on mouse down as a plugin window may | |
| 1969 // have grabbed keyboard focus. | |
| 1970 if (event->type() == ui::ET_MOUSE_PRESSED) | |
| 1971 SetKeyboardFocus(); | |
| 1972 } | |
| 1973 } | |
| 1974 | |
| 1975 switch (event->type()) { | |
| 1976 case ui::ET_MOUSE_PRESSED: | |
| 1977 window_->SetCapture(); | |
| 1978 break; | |
| 1979 case ui::ET_MOUSE_RELEASED: | |
| 1980 if (!NeedsMouseCapture()) | |
| 1981 window_->ReleaseCapture(); | |
| 1982 break; | |
| 1983 default: | |
| 1984 break; | |
| 1985 } | |
| 1986 | |
| 1987 if (!IsXButtonUpEvent(event)) | |
| 1988 event->SetHandled(); | |
| 1989 } | 1554 } |
| 1990 | 1555 |
| 1991 cc::FrameSinkId RenderWidgetHostViewAura::FrameSinkIdAtPoint( | 1556 cc::FrameSinkId RenderWidgetHostViewAura::FrameSinkIdAtPoint( |
| 1992 cc::SurfaceHittestDelegate* delegate, | 1557 cc::SurfaceHittestDelegate* delegate, |
| 1993 const gfx::Point& point, | 1558 const gfx::Point& point, |
| 1994 gfx::Point* transformed_point) { | 1559 gfx::Point* transformed_point) { |
| 1995 DCHECK(device_scale_factor_ != 0.0f); | 1560 DCHECK(device_scale_factor_ != 0.0f); |
| 1996 | 1561 |
| 1997 // The surface hittest happens in device pixels, so we need to convert the | 1562 // The surface hittest happens in device pixels, so we need to convert the |
| 1998 // |point| from DIPs to pixels before hittesting. | 1563 // |point| from DIPs to pixels before hittesting. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 if (rvh && rvh->GetDelegate()) | 1633 if (rvh && rvh->GetDelegate()) |
| 2069 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); | 1634 rvh->GetDelegate()->SetIsVirtualKeyboardRequested(false); |
| 2070 | 1635 |
| 2071 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); | 1636 DCHECK(ui::OnScreenKeyboardDisplayManager::GetInstance()); |
| 2072 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); | 1637 ui::OnScreenKeyboardDisplayManager::GetInstance()->DismissVirtualKeyboard(); |
| 2073 } | 1638 } |
| 2074 #endif | 1639 #endif |
| 2075 } | 1640 } |
| 2076 | 1641 |
| 2077 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { | 1642 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
| 2078 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); | 1643 event_handler_->OnScrollEvent(event); |
| 2079 | |
| 2080 if (event->type() == ui::ET_SCROLL) { | |
| 2081 #if !defined(OS_WIN) | |
| 2082 // TODO(ananta) | |
| 2083 // Investigate if this is true for Windows 8 Metro ASH as well. | |
| 2084 if (event->finger_count() != 2) | |
| 2085 return; | |
| 2086 #endif | |
| 2087 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEventFlingCancel(); | |
| 2088 // Coordinates need to be transferred to the fling cancel gesture only | |
| 2089 // for Surface-targeting to ensure that it is targeted to the correct | |
| 2090 // RenderWidgetHost. | |
| 2091 gesture_event.x = event->x(); | |
| 2092 gesture_event.y = event->y(); | |
| 2093 blink::WebMouseWheelEvent mouse_wheel_event = ui::MakeWebMouseWheelEvent( | |
| 2094 *event, base::Bind(&GetScreenLocationFromEvent)); | |
| 2095 if (ShouldRouteEvent(event)) { | |
| 2096 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
| 2097 this, &gesture_event, ui::LatencyInfo(ui::SourceEventType::WHEEL)); | |
| 2098 host_->delegate()->GetInputEventRouter()->RouteMouseWheelEvent( | |
| 2099 this, &mouse_wheel_event, *event->latency()); | |
| 2100 } else { | |
| 2101 host_->ForwardGestureEvent(gesture_event); | |
| 2102 host_->ForwardWheelEventWithLatencyInfo(mouse_wheel_event, | |
| 2103 *event->latency()); | |
| 2104 } | |
| 2105 RecordAction(base::UserMetricsAction("TrackpadScroll")); | |
| 2106 } else if (event->type() == ui::ET_SCROLL_FLING_START || | |
| 2107 event->type() == ui::ET_SCROLL_FLING_CANCEL) { | |
| 2108 blink::WebGestureEvent gesture_event = ui::MakeWebGestureEvent( | |
| 2109 *event, base::Bind(&GetScreenLocationFromEvent)); | |
| 2110 if (ShouldRouteEvent(event)) { | |
| 2111 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
| 2112 this, &gesture_event, ui::LatencyInfo(ui::SourceEventType::WHEEL)); | |
| 2113 } else { | |
| 2114 host_->ForwardGestureEvent(gesture_event); | |
| 2115 } | |
| 2116 if (event->type() == ui::ET_SCROLL_FLING_START) | |
| 2117 RecordAction(base::UserMetricsAction("TrackpadScrollFling")); | |
| 2118 } | |
| 2119 | |
| 2120 event->SetHandled(); | |
| 2121 } | 1644 } |
| 2122 | 1645 |
| 2123 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { | 1646 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { |
| 2124 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent"); | 1647 event_handler_->OnTouchEvent(event); |
| 2125 | |
| 2126 bool had_no_pointer = !pointer_state_.GetPointerCount(); | |
| 2127 | |
| 2128 // Update the touch event first. | |
| 2129 if (!pointer_state_.OnTouch(*event)) { | |
| 2130 event->StopPropagation(); | |
| 2131 return; | |
| 2132 } | |
| 2133 | |
| 2134 blink::WebTouchEvent touch_event; | |
| 2135 bool handled = selection_controller_->WillHandleTouchEvent(pointer_state_); | |
| 2136 if (handled) { | |
| 2137 event->SetHandled(); | |
| 2138 } else { | |
| 2139 touch_event = ui::CreateWebTouchEventFromMotionEvent( | |
| 2140 pointer_state_, event->may_cause_scrolling()); | |
| 2141 } | |
| 2142 pointer_state_.CleanupRemovedTouchPoints(*event); | |
| 2143 | |
| 2144 if (handled) | |
| 2145 return; | |
| 2146 | |
| 2147 if (had_no_pointer) | |
| 2148 selection_controller_client_->OnTouchDown(); | |
| 2149 if (!pointer_state_.GetPointerCount()) | |
| 2150 selection_controller_client_->OnTouchUp(); | |
| 2151 | |
| 2152 // It is important to always mark events as being handled asynchronously when | |
| 2153 // they are forwarded. This ensures that the current event does not get | |
| 2154 // processed by the gesture recognizer before events currently awaiting | |
| 2155 // dispatch in the touch queue. | |
| 2156 event->DisableSynchronousHandling(); | |
| 2157 | |
| 2158 // Set unchanged touch point to StateStationary for touchmove and | |
| 2159 // touchcancel to make sure only send one ack per WebTouchEvent. | |
| 2160 MarkUnchangedTouchPointsAsStationary(&touch_event, event->touch_id()); | |
| 2161 if (ShouldRouteEvent(event)) { | |
| 2162 host_->delegate()->GetInputEventRouter()->RouteTouchEvent( | |
| 2163 this, &touch_event, *event->latency()); | |
| 2164 } else { | |
| 2165 ProcessTouchEvent(touch_event, *event->latency()); | |
| 2166 } | |
| 2167 } | 1648 } |
| 2168 | 1649 |
| 2169 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { | 1650 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { |
| 2170 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent"); | 1651 event_handler_->OnGestureEvent(event); |
| 2171 | |
| 2172 if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN || | |
| 2173 event->type() == ui::ET_GESTURE_PINCH_UPDATE || | |
| 2174 event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { | |
| 2175 event->SetHandled(); | |
| 2176 return; | |
| 2177 } | |
| 2178 | |
| 2179 HandleGestureForTouchSelection(event); | |
| 2180 if (event->handled()) | |
| 2181 return; | |
| 2182 | |
| 2183 // Confirm existing composition text on TAP gesture, to make sure the input | |
| 2184 // caret won't be moved with an ongoing composition text. | |
| 2185 if (event->type() == ui::ET_GESTURE_TAP) | |
| 2186 FinishImeCompositionSession(); | |
| 2187 | |
| 2188 blink::WebGestureEvent gesture = | |
| 2189 ui::MakeWebGestureEvent(*event, base::Bind(&GetScreenLocationFromEvent)); | |
| 2190 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 2191 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an | |
| 2192 // event to stop any in-progress flings. | |
| 2193 blink::WebGestureEvent fling_cancel = gesture; | |
| 2194 fling_cancel.type = blink::WebInputEvent::GestureFlingCancel; | |
| 2195 fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen; | |
| 2196 if (ShouldRouteEvent(event)) { | |
| 2197 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
| 2198 this, &fling_cancel, ui::LatencyInfo(ui::SourceEventType::TOUCH)); | |
| 2199 } else { | |
| 2200 host_->ForwardGestureEvent(fling_cancel); | |
| 2201 } | |
| 2202 } | |
| 2203 | |
| 2204 if (gesture.type != blink::WebInputEvent::Undefined) { | |
| 2205 if (ShouldRouteEvent(event)) { | |
| 2206 host_->delegate()->GetInputEventRouter()->RouteGestureEvent( | |
| 2207 this, &gesture, *event->latency()); | |
| 2208 } else { | |
| 2209 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency()); | |
| 2210 } | |
| 2211 | |
| 2212 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | |
| 2213 event->type() == ui::ET_GESTURE_SCROLL_UPDATE || | |
| 2214 event->type() == ui::ET_GESTURE_SCROLL_END) { | |
| 2215 RecordAction(base::UserMetricsAction("TouchscreenScroll")); | |
| 2216 } else if (event->type() == ui::ET_SCROLL_FLING_START) { | |
| 2217 RecordAction(base::UserMetricsAction("TouchscreenScrollFling")); | |
| 2218 } | |
| 2219 } | |
| 2220 | |
| 2221 // If a gesture is not processed by the webpage, then WebKit processes it | |
| 2222 // (e.g. generates synthetic mouse events). | |
| 2223 event->SetHandled(); | |
| 2224 } | 1652 } |
| 2225 | 1653 |
| 2226 //////////////////////////////////////////////////////////////////////////////// | 1654 //////////////////////////////////////////////////////////////////////////////// |
| 2227 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: | 1655 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: |
| 2228 | 1656 |
| 2229 bool RenderWidgetHostViewAura::ShouldActivate() const { | 1657 bool RenderWidgetHostViewAura::ShouldActivate() const { |
| 2230 aura::WindowTreeHost* host = window_->GetHost(); | 1658 aura::WindowTreeHost* host = window_->GetHost(); |
| 2231 if (!host) | 1659 if (!host) |
| 2232 return true; | 1660 return true; |
| 2233 const ui::Event* event = host->dispatcher()->current_event(); | 1661 const ui::Event* event = host->dispatcher()->current_event(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2355 display::Screen::GetScreen()->RemoveObserver(this); | 1783 display::Screen::GetScreen()->RemoveObserver(this); |
| 2356 | 1784 |
| 2357 // This call is usually no-op since |this| object is already removed from | 1785 // This call is usually no-op since |this| object is already removed from |
| 2358 // the Aura root window and we don't have a way to get an input method | 1786 // the Aura root window and we don't have a way to get an input method |
| 2359 // object associated with the window, but just in case. | 1787 // object associated with the window, but just in case. |
| 2360 DetachFromInputMethod(); | 1788 DetachFromInputMethod(); |
| 2361 } | 1789 } |
| 2362 if (popup_parent_host_view_) { | 1790 if (popup_parent_host_view_) { |
| 2363 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || | 1791 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL || |
| 2364 popup_parent_host_view_->popup_child_host_view_ == this); | 1792 popup_parent_host_view_->popup_child_host_view_ == this); |
| 2365 popup_parent_host_view_->popup_child_host_view_ = NULL; | 1793 popup_parent_host_view_->SetPopupChild(nullptr); |
| 2366 } | 1794 } |
| 2367 if (popup_child_host_view_) { | 1795 if (popup_child_host_view_) { |
| 2368 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || | 1796 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL || |
| 2369 popup_child_host_view_->popup_parent_host_view_ == this); | 1797 popup_child_host_view_->popup_parent_host_view_ == this); |
| 2370 popup_child_host_view_->popup_parent_host_view_ = NULL; | 1798 popup_child_host_view_->popup_parent_host_view_ = NULL; |
| 2371 } | 1799 } |
| 2372 event_filter_for_popup_exit_.reset(); | 1800 event_filter_for_popup_exit_.reset(); |
| 2373 | 1801 |
| 2374 #if defined(OS_WIN) | 1802 #if defined(OS_WIN) |
| 2375 // The LegacyRenderWidgetHostHWND window should have been destroyed in | 1803 // The LegacyRenderWidgetHostHWND window should have been destroyed in |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2386 | 1814 |
| 2387 #endif | 1815 #endif |
| 2388 | 1816 |
| 2389 if (text_input_manager_) | 1817 if (text_input_manager_) |
| 2390 text_input_manager_->RemoveObserver(this); | 1818 text_input_manager_->RemoveObserver(this); |
| 2391 } | 1819 } |
| 2392 | 1820 |
| 2393 void RenderWidgetHostViewAura::CreateAuraWindow() { | 1821 void RenderWidgetHostViewAura::CreateAuraWindow() { |
| 2394 DCHECK(!window_); | 1822 DCHECK(!window_); |
| 2395 window_ = new aura::Window(this); | 1823 window_ = new aura::Window(this); |
| 1824 event_handler_->set_window(window_); |
| 2396 window_observer_.reset(new WindowObserver(this)); | 1825 window_observer_.reset(new WindowObserver(this)); |
| 2397 | 1826 |
| 2398 aura::client::SetTooltipText(window_, &tooltip_); | 1827 aura::client::SetTooltipText(window_, &tooltip_); |
| 2399 aura::client::SetActivationDelegate(window_, this); | 1828 aura::client::SetActivationDelegate(window_, this); |
| 2400 aura::client::SetFocusChangeObserver(window_, this); | 1829 aura::client::SetFocusChangeObserver(window_, this); |
| 2401 window_->set_layer_owner_delegate(delegated_frame_host_.get()); | 1830 window_->set_layer_owner_delegate(delegated_frame_host_.get()); |
| 2402 display::Screen::GetScreen()->AddObserver(this); | 1831 display::Screen::GetScreen()->AddObserver(this); |
| 2403 } | 1832 } |
| 2404 | 1833 |
| 2405 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { | 1834 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2485 return popup_type_ == blink::WebPopupTypePage; | 1914 return popup_type_ == blink::WebPopupTypePage; |
| 2486 } | 1915 } |
| 2487 | 1916 |
| 2488 bool RenderWidgetHostViewAura::NeedsMouseCapture() { | 1917 bool RenderWidgetHostViewAura::NeedsMouseCapture() { |
| 2489 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 1918 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 2490 return NeedsInputGrab(); | 1919 return NeedsInputGrab(); |
| 2491 #endif | 1920 #endif |
| 2492 return false; | 1921 return false; |
| 2493 } | 1922 } |
| 2494 | 1923 |
| 2495 void RenderWidgetHostViewAura::FinishImeCompositionSession() { | 1924 void RenderWidgetHostViewAura::SetTooltipsEnabled(bool enable) { |
| 2496 if (!has_composition_text_) | 1925 if (enable) { |
| 2497 return; | 1926 tooltip_disabler_.reset(); |
| 2498 | |
| 2499 if (!!text_input_manager_ && !!text_input_manager_->GetActiveWidget()) { | |
| 2500 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false); | |
| 2501 } | |
| 2502 ImeCancelComposition(); | |
| 2503 } | |
| 2504 | |
| 2505 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords( | |
| 2506 blink::WebMouseEvent* event) { | |
| 2507 // If the mouse has just entered, we must report zero movementX/Y. Hence we | |
| 2508 // reset any global_mouse_position set previously. | |
| 2509 if (event->type == blink::WebInputEvent::MouseEnter || | |
| 2510 event->type == blink::WebInputEvent::MouseLeave) | |
| 2511 global_mouse_position_.SetPoint(event->globalX, event->globalY); | |
| 2512 | |
| 2513 // Movement is computed by taking the difference of the new cursor position | |
| 2514 // and the previous. Under mouse lock the cursor will be warped back to the | |
| 2515 // center so that we are not limited by clipping boundaries. | |
| 2516 // We do not measure movement as the delta from cursor to center because | |
| 2517 // we may receive more mouse movement events before our warp has taken | |
| 2518 // effect. | |
| 2519 event->movementX = event->globalX - global_mouse_position_.x(); | |
| 2520 event->movementY = event->globalY - global_mouse_position_.y(); | |
| 2521 | |
| 2522 global_mouse_position_.SetPoint(event->globalX, event->globalY); | |
| 2523 | |
| 2524 // Under mouse lock, coordinates of mouse are locked to what they were when | |
| 2525 // mouse lock was entered. | |
| 2526 if (mouse_locked_) { | |
| 2527 event->x = unlocked_mouse_position_.x(); | |
| 2528 event->y = unlocked_mouse_position_.y(); | |
| 2529 event->windowX = unlocked_mouse_position_.x(); | |
| 2530 event->windowY = unlocked_mouse_position_.y(); | |
| 2531 event->globalX = unlocked_global_mouse_position_.x(); | |
| 2532 event->globalY = unlocked_global_mouse_position_.y(); | |
| 2533 } else { | 1927 } else { |
| 2534 unlocked_mouse_position_.SetPoint(event->x, event->y); | 1928 tooltip_disabler_.reset( |
| 2535 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY); | 1929 new aura::client::ScopedTooltipDisabler(window_->GetRootWindow())); |
| 2536 } | 1930 } |
| 2537 } | 1931 } |
| 2538 | 1932 |
| 2539 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState( | 1933 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState( |
| 2540 bool is_visible) { | 1934 bool is_visible) { |
| 2541 if (host_->is_hidden() || | 1935 if (host_->is_hidden() || |
| 2542 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || | 1936 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) || |
| 2543 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) | 1937 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible)) |
| 2544 return; | 1938 return; |
| 2545 | 1939 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2568 | 1962 |
| 2569 if (snapped && snapped != window_) | 1963 if (snapped && snapped != window_) |
| 2570 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); | 1964 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer()); |
| 2571 | 1965 |
| 2572 has_snapped_to_boundary_ = true; | 1966 has_snapped_to_boundary_ = true; |
| 2573 } | 1967 } |
| 2574 | 1968 |
| 2575 bool RenderWidgetHostViewAura::OnShowContextMenu( | 1969 bool RenderWidgetHostViewAura::OnShowContextMenu( |
| 2576 const ContextMenuParams& params) { | 1970 const ContextMenuParams& params) { |
| 2577 #if defined(OS_WIN) | 1971 #if defined(OS_WIN) |
| 2578 last_context_menu_params_.reset(); | 1972 event_handler_->SetContextMenuParams(params); |
| 2579 | 1973 return params.source_type != ui::MENU_SOURCE_LONG_PRESS; |
| 2580 if (params.source_type == ui::MENU_SOURCE_LONG_PRESS) { | 1974 #else |
| 2581 last_context_menu_params_.reset(new ContextMenuParams); | |
| 2582 *last_context_menu_params_ = params; | |
| 2583 return false; | |
| 2584 } | |
| 2585 #endif | |
| 2586 return true; | 1975 return true; |
| 1976 #endif // defined(OS_WIN) |
| 2587 } | 1977 } |
| 2588 | 1978 |
| 2589 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest( | 1979 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest( |
| 2590 std::unique_ptr<TouchSelectionControllerClientAura> client) { | 1980 std::unique_ptr<TouchSelectionControllerClientAura> client) { |
| 2591 selection_controller_client_.swap(client); | 1981 selection_controller_client_.swap(client); |
| 2592 CreateSelectionController(); | 1982 CreateSelectionController(); |
| 2593 disable_input_event_router_for_testing_ = true; | |
| 2594 } | 1983 } |
| 2595 | 1984 |
| 2596 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { | 1985 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
| 2597 SnapToPhysicalPixelBoundary(); | 1986 SnapToPhysicalPixelBoundary(); |
| 2598 // Don't recursively call SetBounds if this bounds update is the result of | 1987 // Don't recursively call SetBounds if this bounds update is the result of |
| 2599 // a Window::SetBoundsInternal call. | 1988 // a Window::SetBoundsInternal call. |
| 2600 if (!in_bounds_changed_) | 1989 if (!in_bounds_changed_) |
| 2601 window_->SetBounds(rect); | 1990 window_->SetBounds(rect); |
| 2602 host_->WasResized(); | 1991 host_->WasResized(); |
| 2603 delegated_frame_host_->WasResized(); | 1992 delegated_frame_host_->WasResized(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2639 const gfx::Rect& clip) { | 2028 const gfx::Rect& clip) { |
| 2640 if (!clip.IsEmpty()) { | 2029 if (!clip.IsEmpty()) { |
| 2641 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); | 2030 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); |
| 2642 if (!to_paint.IsEmpty()) | 2031 if (!to_paint.IsEmpty()) |
| 2643 window_->SchedulePaintInRect(to_paint); | 2032 window_->SchedulePaintInRect(to_paint); |
| 2644 } else { | 2033 } else { |
| 2645 window_->SchedulePaintInRect(rect); | 2034 window_->SchedulePaintInRect(rect); |
| 2646 } | 2035 } |
| 2647 } | 2036 } |
| 2648 | 2037 |
| 2649 bool RenderWidgetHostViewAura::ShouldMoveToCenter() { | |
| 2650 gfx::Rect rect = window_->bounds(); | |
| 2651 rect = ConvertRectToScreen(rect); | |
| 2652 int border_x = rect.width() * kMouseLockBorderPercentage / 100; | |
| 2653 int border_y = rect.height() * kMouseLockBorderPercentage / 100; | |
| 2654 | |
| 2655 return global_mouse_position_.x() < rect.x() + border_x || | |
| 2656 global_mouse_position_.x() > rect.right() - border_x || | |
| 2657 global_mouse_position_.y() < rect.y() + border_y || | |
| 2658 global_mouse_position_.y() > rect.bottom() - border_y; | |
| 2659 } | |
| 2660 | |
| 2661 void RenderWidgetHostViewAura::AddedToRootWindow() { | 2038 void RenderWidgetHostViewAura::AddedToRootWindow() { |
| 2662 window_->GetHost()->AddObserver(this); | 2039 window_->GetHost()->AddObserver(this); |
| 2663 UpdateScreenInfo(window_); | 2040 UpdateScreenInfo(window_); |
| 2664 | 2041 |
| 2665 aura::client::CursorClient* cursor_client = | 2042 aura::client::CursorClient* cursor_client = |
| 2666 aura::client::GetCursorClient(window_->GetRootWindow()); | 2043 aura::client::GetCursorClient(window_->GetRootWindow()); |
| 2667 if (cursor_client) { | 2044 if (cursor_client) { |
| 2668 cursor_client->AddObserver(this); | 2045 cursor_client->AddObserver(this); |
| 2669 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); | 2046 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible()); |
| 2670 } | 2047 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2757 ui::TouchSelectionController::Config tsc_config; | 2134 ui::TouchSelectionController::Config tsc_config; |
| 2758 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds( | 2135 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds( |
| 2759 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms()); | 2136 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms()); |
| 2760 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance() | 2137 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance() |
| 2761 ->max_touch_move_in_pixels_for_click(); | 2138 ->max_touch_move_in_pixels_for_click(); |
| 2762 tsc_config.enable_longpress_drag_selection = false; | 2139 tsc_config.enable_longpress_drag_selection = false; |
| 2763 selection_controller_.reset(new ui::TouchSelectionController( | 2140 selection_controller_.reset(new ui::TouchSelectionController( |
| 2764 selection_controller_client_.get(), tsc_config)); | 2141 selection_controller_client_.get(), tsc_config)); |
| 2765 } | 2142 } |
| 2766 | 2143 |
| 2767 void RenderWidgetHostViewAura::HandleGestureForTouchSelection( | |
| 2768 ui::GestureEvent* event) { | |
| 2769 switch (event->type()) { | |
| 2770 case ui::ET_GESTURE_LONG_PRESS: | |
| 2771 if (selection_controller_->WillHandleLongPressEvent( | |
| 2772 event->time_stamp(), event->location_f())) { | |
| 2773 event->SetHandled(); | |
| 2774 } | |
| 2775 break; | |
| 2776 case ui::ET_GESTURE_TAP: | |
| 2777 if (selection_controller_->WillHandleTapEvent( | |
| 2778 event->location_f(), event->details().tap_count())) { | |
| 2779 event->SetHandled(); | |
| 2780 } | |
| 2781 break; | |
| 2782 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 2783 selection_controller_client_->OnScrollStarted(); | |
| 2784 break; | |
| 2785 case ui::ET_GESTURE_SCROLL_END: | |
| 2786 selection_controller_client_->OnScrollCompleted(); | |
| 2787 break; | |
| 2788 #if defined(OS_WIN) | |
| 2789 case ui::ET_GESTURE_LONG_TAP: { | |
| 2790 if (!last_context_menu_params_) | |
| 2791 break; | |
| 2792 | |
| 2793 std::unique_ptr<ContextMenuParams> context_menu_params = | |
| 2794 std::move(last_context_menu_params_); | |
| 2795 | |
| 2796 // On Windows we want to display the context menu when the long press | |
| 2797 // gesture is released. To achieve that, we switch the saved context | |
| 2798 // menu params source type to MENU_SOURCE_TOUCH. This is to ensure that | |
| 2799 // the RenderWidgetHostViewAura::OnShowContextMenu function which is | |
| 2800 // called from the ShowContextMenu call below, does not treat it as | |
| 2801 // a context menu request coming in from the long press gesture. | |
| 2802 DCHECK(context_menu_params->source_type == ui::MENU_SOURCE_LONG_PRESS); | |
| 2803 context_menu_params->source_type = ui::MENU_SOURCE_TOUCH; | |
| 2804 | |
| 2805 RenderViewHostDelegateView* delegate_view = | |
| 2806 GetRenderViewHostDelegateView(); | |
| 2807 if (delegate_view) | |
| 2808 delegate_view->ShowContextMenu(GetFocusedFrame(), | |
| 2809 *context_menu_params); | |
| 2810 | |
| 2811 event->SetHandled(); | |
| 2812 // WARNING: we may have been deleted during the call to ShowContextMenu(). | |
| 2813 break; | |
| 2814 } | |
| 2815 #endif | |
| 2816 default: | |
| 2817 break; | |
| 2818 } | |
| 2819 } | |
| 2820 | |
| 2821 void RenderWidgetHostViewAura::ForwardMouseEventToParent( | |
| 2822 ui::MouseEvent* event) { | |
| 2823 // Needed to propagate mouse event to |window_->parent()->delegate()|, but | |
| 2824 // note that it might be something other than a WebContentsViewAura instance. | |
| 2825 // TODO(pkotwicz): Find a better way of doing this. | |
| 2826 // In fullscreen mode which is typically used by flash, don't forward | |
| 2827 // the mouse events to the parent. The renderer and the plugin process | |
| 2828 // handle these events. | |
| 2829 if (is_fullscreen_) | |
| 2830 return; | |
| 2831 | |
| 2832 if (event->flags() & ui::EF_FROM_TOUCH) | |
| 2833 return; | |
| 2834 | |
| 2835 if (!window_->parent() || !window_->parent()->delegate()) | |
| 2836 return; | |
| 2837 | |
| 2838 // Take a copy of |event|, to avoid ConvertLocationToTarget mutating the | |
| 2839 // event. | |
| 2840 std::unique_ptr<ui::Event> event_copy = ui::Event::Clone(*event); | |
| 2841 ui::MouseEvent* mouse_event = static_cast<ui::MouseEvent*>(event_copy.get()); | |
| 2842 mouse_event->ConvertLocationToTarget(window_, window_->parent()); | |
| 2843 window_->parent()->delegate()->OnMouseEvent(mouse_event); | |
| 2844 if (mouse_event->handled()) | |
| 2845 event->SetHandled(); | |
| 2846 } | |
| 2847 | |
| 2848 RenderViewHostDelegateView* | |
| 2849 RenderWidgetHostViewAura::GetRenderViewHostDelegateView() { | |
| 2850 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will | |
| 2851 // actually show the disambiguation popup. | |
| 2852 RenderViewHost* rvh = RenderViewHost::From(host_); | |
| 2853 if (!rvh) | |
| 2854 return nullptr; | |
| 2855 | |
| 2856 RenderViewHostDelegate* delegate = rvh->GetDelegate(); | |
| 2857 if (!delegate) | |
| 2858 return nullptr; | |
| 2859 | |
| 2860 return delegate->GetDelegateView(); | |
| 2861 } | |
| 2862 | |
| 2863 //////////////////////////////////////////////////////////////////////////////// | 2144 //////////////////////////////////////////////////////////////////////////////// |
| 2864 // DelegatedFrameHost, public: | 2145 // DelegatedFrameHost, public: |
| 2865 | 2146 |
| 2866 ui::Layer* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const { | 2147 ui::Layer* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const { |
| 2867 return window_->layer(); | 2148 return window_->layer(); |
| 2868 } | 2149 } |
| 2869 | 2150 |
| 2870 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const { | 2151 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const { |
| 2871 return !host_->is_hidden(); | 2152 return !host_->is_hidden(); |
| 2872 } | 2153 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3044 if (GetTextInputManager() | 2325 if (GetTextInputManager() |
| 3045 ->GetTextSelection(focused_view) | 2326 ->GetTextSelection(focused_view) |
| 3046 ->GetSelectedText(&selected_text)) { | 2327 ->GetSelectedText(&selected_text)) { |
| 3047 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. | 2328 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. |
| 3048 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); | 2329 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); |
| 3049 clipboard_writer.WriteText(selected_text); | 2330 clipboard_writer.WriteText(selected_text); |
| 3050 } | 2331 } |
| 3051 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) | 2332 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) |
| 3052 } | 2333 } |
| 3053 | 2334 |
| 2335 void RenderWidgetHostViewAura::SetPopupChild( |
| 2336 RenderWidgetHostViewAura* popup_child_host_view) { |
| 2337 popup_child_host_view_ = popup_child_host_view; |
| 2338 event_handler_->SetPopupChild( |
| 2339 popup_child_host_view, |
| 2340 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr); |
| 2341 } |
| 2342 |
| 3054 } // namespace content | 2343 } // namespace content |
| OLD | NEW |