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
3 // found in the LICENSE file.
4
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6
7 #include <set>
8 #include <utility>
9
10 #include "base/auto_reset.h"
11 #include "base/bind.h"
12 #include "base/callback_helpers.h"
13 #include "base/command_line.h"
14 #include "base/feature_list.h"
15 #include "base/logging.h"
16 #include "base/macros.h"
17 #include "base/metrics/histogram_functions.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/trace_event/trace_event.h"
20 #include "build/build_config.h"
21 #include "build/chromeos_buildflags.h"
22 #include "cc/layers/layer.h"
23 #include "cc/trees/layer_tree_settings.h"
24 #include "components/viz/common/features.h"
25 #include "components/viz/common/frame_sinks/copy_output_request.h"
26 #include "components/viz/common/frame_sinks/copy_output_result.h"
27 #include "components/viz/common/surfaces/local_surface_id.h"
28 #include "content/browser/accessibility/browser_accessibility_manager.h"
29 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
30 #include "content/browser/bad_message.h"
31 #include "content/browser/gpu/compositor_util.h"
32 #include "content/browser/renderer_host/cursor_manager.h"
33 #include "content/browser/renderer_host/delegated_frame_host_client_aura.h"
34 #include "content/browser/renderer_host/dip_util.h"
35 #include "content/browser/renderer_host/frame_tree.h"
36 #include "content/browser/renderer_host/frame_tree_node.h"
37 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
38 #include "content/browser/renderer_host/input/touch_selection_controller_client_aura.h"
39 #include "content/browser/renderer_host/overscroll_controller.h"
40 #include "content/browser/renderer_host/render_frame_host_impl.h"
41 #include "content/browser/renderer_host/render_view_host_delegate.h"
42 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
43 #include "content/browser/renderer_host/render_view_host_impl.h"
44 #include "content/browser/renderer_host/render_widget_host_delegate.h"
45 #include "content/browser/renderer_host/render_widget_host_impl.h"
46 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
47 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h"
48 #include "content/browser/renderer_host/ui_events_helper.h"
49 #include "content/common/input_messages.h"
50 #include "content/public/browser/content_browser_client.h"
51 #include "content/public/browser/render_view_host.h"
52 #include "content/public/common/content_features.h"
53 #include "content/public/common/use_zoom_for_dsf_policy.h"
54 #include "gpu/ipc/common/gpu_messages.h"
55 #include "services/service_manager/public/cpp/interface_provider.h"
56 #include "third_party/blink/public/common/input/web_input_event.h"
57 #include "ui/accessibility/accessibility_switches.h"
58 #include "ui/accessibility/aura/aura_window_properties.h"
59 #include "ui/accessibility/platform/ax_platform_node.h"
60 #include "ui/aura/client/aura_constants.h"
61 #include "ui/aura/client/cursor_client.h"
62 #include "ui/aura/client/cursor_client_observer.h"
63 #include "ui/aura/client/focus_client.h"
64 #include "ui/aura/client/screen_position_client.h"
65 #include "ui/aura/client/transient_window_client.h"
66 #include "ui/aura/client/window_parenting_client.h"
67 #include "ui/aura/env.h"
68 #include "ui/aura/window.h"
69 #include "ui/aura/window_event_dispatcher.h"
70 #include "ui/aura/window_observer.h"
71 #include "ui/aura/window_tree_host.h"
72 #include "ui/base/clipboard/scoped_clipboard_writer.h"
73 #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
74 #include "ui/base/hit_test.h"
75 #include "ui/base/ime/input_method.h"
76 #include "ui/base/ime/mojom/text_input_state.mojom.h"
77 #include "ui/base/ui_base_switches.h"
78 #include "ui/base/ui_base_types.h"
79 #include "ui/display/screen.h"
80 #include "ui/events/blink/blink_event_util.h"
81 #include "ui/events/blink/did_overscroll_params.h"
82 #include "ui/events/blink/web_input_event.h"
83 #include "ui/events/event.h"
84 #include "ui/events/event_observer.h"
85 #include "ui/events/event_utils.h"
86 #include "ui/events/gesture_detection/gesture_configuration.h"
87 #include "ui/events/gestures/gesture_recognizer.h"
88 #include "ui/events/keycodes/dom/dom_code.h"
89 #include "ui/gfx/canvas.h"
90 #include "ui/gfx/color_palette.h"
91 #include "ui/gfx/geometry/dip_util.h"
92 #include "ui/gfx/geometry/rect_conversions.h"
93 #include "ui/gfx/geometry/size_conversions.h"
94 #include "ui/gfx/skia_util.h"
95 #include "ui/touch_selection/touch_selection_controller.h"
96 #include "ui/wm/core/coordinate_conversion.h"
97 #include "ui/wm/public/activation_client.h"
98 #include "ui/wm/public/scoped_tooltip_disabler.h"
99 #include "ui/wm/public/tooltip_client.h"
100
101 #if defined(OS_WIN)
102 #include "base/time/time.h"
103 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
104 #include "content/browser/accessibility/browser_accessibility_win.h"
105 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
106 #include "ui/accessibility/platform/ax_fragment_root_win.h"
107 #include "ui/base/ime/input_method_keyboard_controller.h"
108 #include "ui/base/ime/input_method_keyboard_controller_observer.h"
109 #include "ui/base/win/hidden_window.h"
110 #include "ui/display/win/screen_win.h"
111 #include "ui/gfx/gdi_util.h"
112 #endif
113
114 #if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || defined(OS_BSD)
115 #include "content/browser/accessibility/browser_accessibility_auralinux.h"
116 #include "ui/base/ime/linux/text_edit_command_auralinux.h"
117 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
118 #endif
119
120 #if BUILDFLAG(IS_CHROMEOS_ASH)
121 #include "ui/wm/core/ime_util_chromeos.h"
122 #endif
123
124 #if defined(OS_FUCHSIA)
125 #include "ui/base/ime/input_method_keyboard_controller.h"
126 #endif
127
128 using gfx::RectToSkIRect;
129 using gfx::SkIRectToRect;
130
131 using blink::WebInputEvent;
132 using blink::WebGestureEvent;
133 using blink::WebTouchEvent;
134
135 namespace content {
136
137 // We need to watch for mouse events outside a Web Popup or its parent
138 // and dismiss the popup for certain events.
139 class RenderWidgetHostViewAura::EventObserverForPopupExit
140 : public ui::EventObserver {
141 public:
EventObserverForPopupExit(RenderWidgetHostViewAura * rwhva)142 explicit EventObserverForPopupExit(RenderWidgetHostViewAura* rwhva)
143 : rwhva_(rwhva) {
144 aura::Env* env = aura::Env::GetInstance();
145 env->AddEventObserver(this, env,
146 {ui::ET_MOUSE_PRESSED, ui::ET_TOUCH_PRESSED});
147 }
148
~EventObserverForPopupExit()149 ~EventObserverForPopupExit() override {
150 aura::Env::GetInstance()->RemoveEventObserver(this);
151 }
152
153 // ui::EventObserver:
OnEvent(const ui::Event & event)154 void OnEvent(const ui::Event& event) override {
155 rwhva_->ApplyEventObserverForPopupExit(*event.AsLocatedEvent());
156 }
157
158 private:
159 RenderWidgetHostViewAura* rwhva_;
160
161 DISALLOW_COPY_AND_ASSIGN(EventObserverForPopupExit);
162 };
163
ApplyEventObserverForPopupExit(const ui::LocatedEvent & event)164 void RenderWidgetHostViewAura::ApplyEventObserverForPopupExit(
165 const ui::LocatedEvent& event) {
166 DCHECK(event.type() == ui::ET_MOUSE_PRESSED ||
167 event.type() == ui::ET_TOUCH_PRESSED);
168
169 if (in_shutdown_ || is_fullscreen_)
170 return;
171
172 // |target| may be null.
173 aura::Window* target = static_cast<aura::Window*>(event.target());
174 if (target != window_ &&
175 (!popup_parent_host_view_ ||
176 target != popup_parent_host_view_->window_)) {
177 // If we enter this code path it means that we did not receive any focus
178 // lost notifications for the popup window. Ensure that blink is aware
179 // of the fact that focus was lost for the host window by sending a Blur
180 // notification. We also set a flag in the view indicating that we need
181 // to force a Focus notification on the next mouse down.
182 if (popup_parent_host_view_ && popup_parent_host_view_->host()) {
183 popup_parent_host_view_->event_handler()
184 ->set_focus_on_mouse_down_or_key_event(true);
185 popup_parent_host_view_->host()->Blur();
186 }
187 // Note: popup_parent_host_view_ may be NULL when there are multiple
188 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
189 Shutdown();
190 }
191 }
192
193 // We have to implement the WindowObserver interface on a separate object
194 // because clang doesn't like implementing multiple interfaces that have
195 // methods with the same name. This object is owned by the
196 // RenderWidgetHostViewAura.
197 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver {
198 public:
WindowObserver(RenderWidgetHostViewAura * view)199 explicit WindowObserver(RenderWidgetHostViewAura* view)
200 : view_(view) {
201 view_->window_->AddObserver(this);
202 }
203
~WindowObserver()204 ~WindowObserver() override { view_->window_->RemoveObserver(this); }
205
206 // Overridden from aura::WindowObserver:
OnWindowAddedToRootWindow(aura::Window * window)207 void OnWindowAddedToRootWindow(aura::Window* window) override {
208 if (window == view_->window_)
209 view_->AddedToRootWindow();
210 }
211
OnWindowRemovingFromRootWindow(aura::Window * window,aura::Window * new_root)212 void OnWindowRemovingFromRootWindow(aura::Window* window,
213 aura::Window* new_root) override {
214 if (window == view_->window_)
215 view_->RemovingFromRootWindow();
216 }
217
OnWindowHierarchyChanged(const HierarchyChangeParams & params)218 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
219 view_->ParentHierarchyChanged();
220 }
221
OnWindowTitleChanged(aura::Window * window)222 void OnWindowTitleChanged(aura::Window* window) override {
223 if (window == view_->window_)
224 view_->WindowTitleChanged();
225 }
226
227 private:
228 RenderWidgetHostViewAura* view_;
229
230 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
231 };
232
233 // This class provides functionality to observe the ancestors of the RWHVA for
234 // bounds changes. This is done to snap the RWHVA window to a pixel boundary,
235 // which could change when the bounds relative to the root changes.
236 // An example where this happens is below:-
237 // The fast resize code path for bookmarks where in the parent of RWHVA which
238 // is WCV has its bounds changed before the bookmark is hidden. This results in
239 // the traditional bounds change notification for the WCV reporting the old
240 // bounds as the bookmark is still around. Observing all the ancestors of the
241 // RWHVA window enables us to know when the bounds of the window relative to
242 // root changes and allows us to snap accordingly.
243 class RenderWidgetHostViewAura::WindowAncestorObserver
244 : public aura::WindowObserver {
245 public:
WindowAncestorObserver(RenderWidgetHostViewAura * view)246 explicit WindowAncestorObserver(RenderWidgetHostViewAura* view)
247 : view_(view) {
248 aura::Window* parent = view_->window_->parent();
249 while (parent) {
250 parent->AddObserver(this);
251 ancestors_.insert(parent);
252 parent = parent->parent();
253 }
254 }
255
~WindowAncestorObserver()256 ~WindowAncestorObserver() override {
257 RemoveAncestorObservers();
258 }
259
OnWindowBoundsChanged(aura::Window * window,const gfx::Rect & old_bounds,const gfx::Rect & new_bounds,ui::PropertyChangeReason reason)260 void OnWindowBoundsChanged(aura::Window* window,
261 const gfx::Rect& old_bounds,
262 const gfx::Rect& new_bounds,
263 ui::PropertyChangeReason reason) override {
264 DCHECK(ancestors_.find(window) != ancestors_.end());
265 if (new_bounds.origin() != old_bounds.origin())
266 view_->HandleParentBoundsChanged();
267 }
268
269 private:
RemoveAncestorObservers()270 void RemoveAncestorObservers() {
271 for (auto* ancestor : ancestors_)
272 ancestor->RemoveObserver(this);
273 ancestors_.clear();
274 }
275
276 RenderWidgetHostViewAura* view_;
277 std::set<aura::Window*> ancestors_;
278
279 DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver);
280 };
281
282
283 ////////////////////////////////////////////////////////////////////////////////
284 // RenderWidgetHostViewAura, public:
285
RenderWidgetHostViewAura(RenderWidgetHost * widget_host)286 RenderWidgetHostViewAura::RenderWidgetHostViewAura(
287 RenderWidgetHost* widget_host)
288 : RenderWidgetHostViewBase(widget_host),
289 window_(nullptr),
290 in_shutdown_(false),
291 in_bounds_changed_(false),
292 popup_parent_host_view_(nullptr),
293 popup_child_host_view_(nullptr),
294 is_loading_(false),
295 has_composition_text_(false),
296 added_frame_observer_(false),
297 cursor_visibility_state_in_renderer_(UNKNOWN),
298 #if defined(OS_WIN)
299 legacy_render_widget_host_HWND_(nullptr),
300 legacy_window_destroyed_(false),
301 #endif
302 device_scale_factor_(0.0f),
303 event_handler_(new RenderWidgetHostViewEventHandler(host(), this, this)),
304 frame_sink_id_(host()->GetFrameSinkId()) {
305 CreateDelegatedFrameHostClient();
306
307 host()->SetView(this);
308
309 // We should start observing the TextInputManager for IME-related events as
310 // well as monitoring its lifetime.
311 if (GetTextInputManager())
312 GetTextInputManager()->AddObserver(this);
313
314 cursor_manager_.reset(new CursorManager(this));
315
316 SetOverscrollControllerEnabled(
317 base::FeatureList::IsEnabled(features::kOverscrollHistoryNavigation));
318
319 selection_controller_client_.reset(
320 new TouchSelectionControllerClientAura(this));
321 CreateSelectionController();
322
323 RenderWidgetHostOwnerDelegate* owner_delegate = host()->owner_delegate();
324 if (owner_delegate) {
325 // NOTE: This will not be run for child frame widgets, which do not have
326 // an owner delegate and won't get a RenderViewHost here.
327 double_tap_to_zoom_enabled_ =
328 owner_delegate->GetWebkitPreferencesForWidget()
329 .double_tap_to_zoom_enabled;
330 }
331
332 host()->render_frame_metadata_provider()->AddObserver(this);
333 }
334
335 ////////////////////////////////////////////////////////////////////////////////
336 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
337
InitAsChild(gfx::NativeView parent_view)338 void RenderWidgetHostViewAura::InitAsChild(gfx::NativeView parent_view) {
339 DCHECK_EQ(widget_type_, WidgetType::kFrame);
340 CreateAuraWindow(aura::client::WINDOW_TYPE_CONTROL);
341
342 if (parent_view)
343 parent_view->AddChild(GetNativeView());
344
345 device_scale_factor_ = GetDeviceScaleFactor();
346 }
347
InitAsPopup(RenderWidgetHostView * parent_host_view,const gfx::Rect & bounds_in_screen)348 void RenderWidgetHostViewAura::InitAsPopup(
349 RenderWidgetHostView* parent_host_view,
350 const gfx::Rect& bounds_in_screen) {
351 DCHECK_EQ(widget_type_, WidgetType::kPopup);
352 DCHECK(!static_cast<RenderWidgetHostViewBase*>(parent_host_view)
353 ->IsRenderWidgetHostViewChildFrame());
354
355 popup_parent_host_view_ =
356 static_cast<RenderWidgetHostViewAura*>(parent_host_view);
357
358 // TransientWindowClient may be NULL during tests.
359 aura::client::TransientWindowClient* transient_window_client =
360 aura::client::GetTransientWindowClient();
361 RenderWidgetHostViewAura* old_child =
362 popup_parent_host_view_->popup_child_host_view_;
363 if (old_child) {
364 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
365 // similar mechanism to ensure a second popup doesn't cause the first one
366 // to never get a chance to filter events. See crbug.com/160589.
367 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_);
368 if (transient_window_client) {
369 transient_window_client->RemoveTransientChild(
370 popup_parent_host_view_->window_, old_child->window_);
371 }
372 old_child->popup_parent_host_view_ = nullptr;
373 }
374 popup_parent_host_view_->SetPopupChild(this);
375 CreateAuraWindow(aura::client::WINDOW_TYPE_MENU);
376 // Use transparent background color for the popup in order to avoid flashing
377 // the white background on popup open when dark color-scheme is used.
378 SetContentBackgroundColor(SK_ColorTRANSPARENT);
379
380 // Setting the transient child allows for the popup to get mouse events when
381 // in a system modal dialog. Do this before calling ParentWindowWithContext
382 // below so that the transient parent is visible to WindowTreeClient.
383 // This fixes crbug.com/328593.
384 if (transient_window_client) {
385 transient_window_client->AddTransientChild(
386 popup_parent_host_view_->window_, window_);
387 }
388
389 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow();
390 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen);
391
392 SetBounds(bounds_in_screen);
393 Show();
394 if (NeedsMouseCapture())
395 window_->SetCapture();
396
397 event_observer_for_popup_exit_ =
398 std::make_unique<EventObserverForPopupExit>(this);
399
400 device_scale_factor_ = GetDeviceScaleFactor();
401 }
402
InitAsFullscreen(RenderWidgetHostView * reference_host_view)403 void RenderWidgetHostViewAura::InitAsFullscreen(
404 RenderWidgetHostView* reference_host_view) {
405 DCHECK_EQ(widget_type_, WidgetType::kFrame);
406 is_fullscreen_ = true;
407 CreateAuraWindow(aura::client::WINDOW_TYPE_NORMAL);
408 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
409
410 aura::Window* parent = nullptr;
411 gfx::Rect bounds;
412 if (reference_host_view) {
413 aura::Window* reference_window =
414 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_;
415 event_handler_->TrackHost(reference_window);
416 display::Display display =
417 display::Screen::GetScreen()->GetDisplayNearestWindow(reference_window);
418 parent = reference_window->GetRootWindow();
419 bounds = display.bounds();
420 }
421 aura::client::ParentWindowWithContext(window_, parent, bounds);
422 Show();
423 Focus();
424
425 device_scale_factor_ = GetDeviceScaleFactor();
426 }
427
Show()428 void RenderWidgetHostViewAura::Show() {
429 // If the viz::LocalSurfaceId is invalid, we may have been evicted,
430 // and no other visual properties have since been changed. Allocate a new id
431 // and start synchronizing.
432 if (!window_->GetLocalSurfaceId().is_valid()) {
433 window_->AllocateLocalSurfaceId();
434 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
435 window_->GetLocalSurfaceId());
436 }
437
438 window_->Show();
439 WasUnOccluded();
440 }
441
Hide()442 void RenderWidgetHostViewAura::Hide() {
443 window_->Hide();
444 visibility_ = Visibility::HIDDEN;
445 HideImpl();
446 }
447
SetSize(const gfx::Size & size)448 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) {
449 // For a SetSize operation, we don't care what coordinate system the origin
450 // of the window is in, it's only important to make sure that the origin
451 // remains constant after the operation.
452 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size));
453 }
454
SetBounds(const gfx::Rect & rect)455 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) {
456 gfx::Point relative_origin(rect.origin());
457
458 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but
459 // Window::SetBounds() takes parent coordinates, so do the conversion here.
460 aura::Window* root = window_->GetRootWindow();
461 if (root) {
462 aura::client::ScreenPositionClient* screen_position_client =
463 aura::client::GetScreenPositionClient(root);
464 if (screen_position_client) {
465 screen_position_client->ConvertPointFromScreen(window_->parent(),
466 &relative_origin);
467 }
468 }
469
470 InternalSetBounds(gfx::Rect(relative_origin, rect.size()));
471 }
472
GetNativeView()473 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() {
474 return window_;
475 }
476
477 #if defined(OS_WIN)
GetHostWindowHWND() const478 HWND RenderWidgetHostViewAura::GetHostWindowHWND() const {
479 aura::WindowTreeHost* host = window_->GetHost();
480 return host ? host->GetAcceleratedWidget() : nullptr;
481 }
482 #endif
483
GetNativeViewAccessible()484 gfx::NativeViewAccessible RenderWidgetHostViewAura::GetNativeViewAccessible() {
485 #if defined(OS_WIN)
486 aura::WindowTreeHost* window_host = window_->GetHost();
487 if (!window_host)
488 return static_cast<gfx::NativeViewAccessible>(NULL);
489
490 BrowserAccessibilityManager* manager =
491 host()->GetOrCreateRootBrowserAccessibilityManager();
492 if (manager)
493 return ToBrowserAccessibilityWin(manager->GetRoot())->GetCOM();
494
495 #elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || defined(OS_BSD)
496 BrowserAccessibilityManager* manager =
497 host()->GetOrCreateRootBrowserAccessibilityManager();
498 if (manager && manager->GetRoot())
499 return manager->GetRoot()->GetNativeViewAccessible();
500 #endif
501
502 NOTIMPLEMENTED_LOG_ONCE();
503 return static_cast<gfx::NativeViewAccessible>(nullptr);
504 }
505
GetTextInputClient()506 ui::TextInputClient* RenderWidgetHostViewAura::GetTextInputClient() {
507 return this;
508 }
509
GetFocusedFrame() const510 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() const {
511 FrameTreeNode* focused_frame =
512 host()->delegate()->GetFrameTree()->GetFocusedFrame();
513 if (!focused_frame)
514 return nullptr;
515 return focused_frame->current_frame_host();
516 }
517
HandleParentBoundsChanged()518 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
519 #if defined(OS_WIN)
520 if (legacy_render_widget_host_HWND_) {
521 legacy_render_widget_host_HWND_->SetBounds(
522 window_->GetBoundsInRootWindow());
523 }
524 #endif
525 if (!in_shutdown_) {
526 // Send screen rects through the delegate if there is one. Not every
527 // RenderWidgetHost has a delegate (for example, drop-down widgets).
528 if (host_->delegate())
529 host_->delegate()->SendScreenRects();
530 else
531 host_->SendScreenRects();
532 }
533 }
534
ParentHierarchyChanged()535 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
536 ancestor_window_observer_.reset(new WindowAncestorObserver(this));
537 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
538 HandleParentBoundsChanged();
539 }
540
Focus()541 void RenderWidgetHostViewAura::Focus() {
542 // Make sure we have a FocusClient before attempting to Focus(). In some
543 // situations we may not yet be in a valid Window hierarchy (such as reloading
544 // after out of memory discarded the tab).
545 aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
546 if (client)
547 window_->Focus();
548 }
549
HasFocus()550 bool RenderWidgetHostViewAura::HasFocus() {
551 return window_->HasFocus();
552 }
553
IsSurfaceAvailableForCopy()554 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() {
555 if (!delegated_frame_host_)
556 return false;
557 return delegated_frame_host_->CanCopyFromCompositingSurface();
558 }
559
EnsureSurfaceSynchronizedForWebTest()560 void RenderWidgetHostViewAura::EnsureSurfaceSynchronizedForWebTest() {
561 ++latest_capture_sequence_number_;
562 SynchronizeVisualProperties(cc::DeadlinePolicy::UseInfiniteDeadline(),
563 base::nullopt);
564 }
565
IsShowing()566 bool RenderWidgetHostViewAura::IsShowing() {
567 return window_->IsVisible();
568 }
569
WasUnOccluded()570 void RenderWidgetHostViewAura::WasUnOccluded() {
571 const Visibility old_visibility = visibility_;
572 visibility_ = Visibility::VISIBLE;
573
574 if (!host_->is_hidden())
575 return;
576
577 if (old_visibility == Visibility::OCCLUDED) {
578 SetRecordContentToVisibleTimeRequest(
579 base::TimeTicks::Now(), false /* destination_is_loaded */,
580 false /* show_reason_tab_switching */,
581 true /* show_reason_unoccluded */,
582 false /* show_reason_bfcache_restore */);
583 }
584
585 auto tab_switch_start_state = TakeRecordContentToVisibleTimeRequest();
586 bool has_saved_frame =
587 delegated_frame_host_ ? delegated_frame_host_->HasSavedFrame() : false;
588
589 bool show_reason_bfcache_restore =
590 tab_switch_start_state
591 ? tab_switch_start_state->show_reason_bfcache_restore
592 : false;
593
594 // No need to check for saved frames for the case of bfcache restore.
595 if (show_reason_bfcache_restore) {
596 host()->WasShown(tab_switch_start_state.Clone());
597 } else {
598 host()->WasShown(has_saved_frame
599 ? blink::mojom::RecordContentToVisibleTimeRequestPtr()
600 : tab_switch_start_state.Clone());
601 }
602 aura::Window* root = window_->GetRootWindow();
603 if (root) {
604 aura::client::CursorClient* cursor_client =
605 aura::client::GetCursorClient(root);
606 if (cursor_client)
607 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
608 }
609
610 if (delegated_frame_host_) {
611 // If the frame for the renderer is already available, then the
612 // tab-switching time is the presentation time for the browser-compositor.
613 delegated_frame_host_->WasShown(
614 GetLocalSurfaceId(), window_->bounds().size(),
615 has_saved_frame ? std::move(tab_switch_start_state)
616 : blink::mojom::RecordContentToVisibleTimeRequestPtr());
617 }
618
619 #if defined(OS_WIN)
620 UpdateLegacyWin();
621 #endif
622 }
623
HideImpl()624 void RenderWidgetHostViewAura::HideImpl() {
625 DCHECK(visibility_ == Visibility::HIDDEN ||
626 visibility_ == Visibility::OCCLUDED);
627
628 if (!host()->is_hidden()) {
629 host()->WasHidden();
630 aura::WindowTreeHost* host = window_->GetHost();
631 if (delegated_frame_host_) {
632 aura::Window* parent = window_->parent();
633 aura::Window::OcclusionState parent_occl_state =
634 parent ? parent->occlusion_state()
635 : aura::Window::OcclusionState::UNKNOWN;
636 aura::Window::OcclusionState native_win_occlusion_state =
637 host ? host->GetNativeWindowOcclusionState()
638 : aura::Window::OcclusionState::UNKNOWN;
639 DelegatedFrameHost::HiddenCause cause;
640 if (parent_occl_state == aura::Window::OcclusionState::OCCLUDED &&
641 native_win_occlusion_state ==
642 aura::Window::OcclusionState::OCCLUDED) {
643 cause = DelegatedFrameHost::HiddenCause::kOccluded;
644 } else {
645 cause = DelegatedFrameHost::HiddenCause::kOther;
646 }
647 delegated_frame_host_->WasHidden(cause);
648 }
649 #if defined(OS_WIN)
650 if (host) {
651 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
652 // hidden window on the same lines as Windowed plugin windows.
653 if (legacy_render_widget_host_HWND_)
654 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
655 }
656 #endif
657 }
658
659 #if defined(OS_WIN)
660 if (legacy_render_widget_host_HWND_)
661 legacy_render_widget_host_HWND_->Hide();
662 #endif
663 }
664
WasOccluded()665 void RenderWidgetHostViewAura::WasOccluded() {
666 visibility_ = Visibility::OCCLUDED;
667 HideImpl();
668 }
669
ShouldShowStaleContentOnEviction()670 bool RenderWidgetHostViewAura::ShouldShowStaleContentOnEviction() {
671 return host() && host()->ShouldShowStaleContentOnEviction();
672 }
673
GetViewBounds()674 gfx::Rect RenderWidgetHostViewAura::GetViewBounds() {
675 return window_->GetBoundsInScreen();
676 }
677
UpdateBackgroundColor()678 void RenderWidgetHostViewAura::UpdateBackgroundColor() {
679 DCHECK(GetBackgroundColor());
680
681 SkColor color = *GetBackgroundColor();
682 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
683 window_->layer()->SetFillsBoundsOpaquely(opaque);
684 window_->layer()->SetColor(color);
685 }
686
GetDisplayFeature()687 base::Optional<DisplayFeature> RenderWidgetHostViewAura::GetDisplayFeature() {
688 return display_feature_;
689 }
690
SetDisplayFeatureForTesting(const DisplayFeature * display_feature)691 void RenderWidgetHostViewAura::SetDisplayFeatureForTesting(
692 const DisplayFeature* display_feature) {
693 if (display_feature)
694 display_feature_ = *display_feature;
695 else
696 display_feature_ = base::nullopt;
697 }
698
WindowTitleChanged()699 void RenderWidgetHostViewAura::WindowTitleChanged() {
700 if (delegated_frame_host_) {
701 delegated_frame_host_->WindowTitleChanged(
702 base::UTF16ToUTF8(window_->GetTitle()));
703 }
704 }
705
IsMouseLocked()706 bool RenderWidgetHostViewAura::IsMouseLocked() {
707 return event_handler_->mouse_locked();
708 }
709
GetVisibleViewportSize()710 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() {
711 gfx::Rect requested_rect(GetRequestedRendererSize());
712 requested_rect.Inset(insets_);
713 return requested_rect.size();
714 }
715
SetInsets(const gfx::Insets & insets)716 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
717 if (insets != insets_) {
718 insets_ = insets;
719 window_->AllocateLocalSurfaceId();
720 if (!insets.IsEmpty()) {
721 inset_surface_id_ = window_->GetLocalSurfaceId();
722 } else {
723 inset_surface_id_ = viz::LocalSurfaceId();
724 }
725 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
726 window_->GetLocalSurfaceId());
727 }
728 }
729
UpdateCursor(const WebCursor & cursor)730 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) {
731 GetCursorManager()->UpdateCursor(this, cursor);
732 }
733
DisplayCursor(const WebCursor & cursor)734 void RenderWidgetHostViewAura::DisplayCursor(const WebCursor& cursor) {
735 current_cursor_ = cursor;
736 const display::Display display =
737 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
738 current_cursor_.SetDisplayInfo(display);
739 UpdateCursorIfOverSelf();
740 }
741
GetCursorManager()742 CursorManager* RenderWidgetHostViewAura::GetCursorManager() {
743 return cursor_manager_.get();
744 }
745
SetIsLoading(bool is_loading)746 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
747 is_loading_ = is_loading;
748 UpdateCursorIfOverSelf();
749 }
750
RenderProcessGone()751 void RenderWidgetHostViewAura::RenderProcessGone() {
752 UpdateCursorIfOverSelf();
753 Destroy();
754 }
755
Destroy()756 void RenderWidgetHostViewAura::Destroy() {
757 // Beware, this function is not called on all destruction paths. If |window_|
758 // has been created, then it will implicitly end up calling
759 // ~RenderWidgetHostViewAura when |window_| is destroyed. Otherwise, The
760 // destructor is invoked directly from here. So all destruction/cleanup code
761 // should happen there, not here.
762 in_shutdown_ = true;
763 if (window_)
764 delete window_;
765 else
766 delete this;
767 }
768
SetTooltipText(const base::string16 & tooltip_text)769 void RenderWidgetHostViewAura::SetTooltipText(
770 const base::string16& tooltip_text) {
771 GetCursorManager()->SetTooltipTextForView(this, tooltip_text);
772 }
773
DisplayTooltipText(const base::string16 & tooltip_text)774 void RenderWidgetHostViewAura::DisplayTooltipText(
775 const base::string16& tooltip_text) {
776 tooltip_ = tooltip_text;
777 aura::Window* root_window = window_->GetRootWindow();
778 wm::TooltipClient* tooltip_client = wm::GetTooltipClient(root_window);
779 if (tooltip_client) {
780 tooltip_client->UpdateTooltip(window_);
781 // Content tooltips should be visible indefinitely.
782 tooltip_client->SetTooltipShownTimeout(window_, 0);
783 }
784 }
785
GetCaptureSequenceNumber() const786 uint32_t RenderWidgetHostViewAura::GetCaptureSequenceNumber() const {
787 return latest_capture_sequence_number_;
788 }
789
CopyFromSurface(const gfx::Rect & src_subrect,const gfx::Size & dst_size,base::OnceCallback<void (const SkBitmap &)> callback)790 void RenderWidgetHostViewAura::CopyFromSurface(
791 const gfx::Rect& src_subrect,
792 const gfx::Size& dst_size,
793 base::OnceCallback<void(const SkBitmap&)> callback) {
794 base::WeakPtr<RenderWidgetHostImpl> popup_host;
795 base::WeakPtr<DelegatedFrameHost> popup_frame_host;
796 if (popup_child_host_view_) {
797 popup_host = popup_child_host_view_->host()->GetWeakPtr();
798 popup_frame_host =
799 popup_child_host_view_->GetDelegatedFrameHost()->GetWeakPtr();
800 }
801 RenderWidgetHostViewBase::CopyMainAndPopupFromSurface(
802 host()->GetWeakPtr(), delegated_frame_host_->GetWeakPtr(), popup_host,
803 popup_frame_host, src_subrect, dst_size, device_scale_factor_,
804 std::move(callback));
805 }
806
807 #if defined(OS_WIN)
UsesNativeWindowFrame() const808 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
809 return (legacy_render_widget_host_HWND_ != nullptr);
810 }
811
UpdateMouseLockRegion()812 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
813 RECT window_rect =
814 display::Screen::GetScreen()
815 ->DIPToScreenRectInWindow(window_, window_->GetBoundsInScreen())
816 .ToRECT();
817 ::ClipCursor(&window_rect);
818 }
819
OnLegacyWindowDestroyed()820 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
821 legacy_render_widget_host_HWND_ = nullptr;
822 legacy_window_destroyed_ = true;
823 }
824 #endif
825
826 gfx::NativeViewAccessible
GetParentNativeViewAccessible()827 RenderWidgetHostViewAura::GetParentNativeViewAccessible() {
828 // If a popup_parent_host_view_ exists, that means we are in a popup (such as
829 // datetime) and our accessible parent window is popup_parent_host_view_
830 if (popup_parent_host_view_) {
831 DCHECK_EQ(widget_type_, WidgetType::kPopup);
832 return popup_parent_host_view_->GetParentNativeViewAccessible();
833 }
834
835 if (window_->parent()) {
836 return window_->parent()->GetProperty(
837 aura::client::kParentNativeViewAccessibleKey);
838 }
839
840 return nullptr;
841 }
842
ResetFallbackToFirstNavigationSurface()843 void RenderWidgetHostViewAura::ResetFallbackToFirstNavigationSurface() {
844 if (delegated_frame_host_)
845 delegated_frame_host_->ResetFallbackToFirstNavigationSurface();
846 }
847
RequestRepaintForTesting()848 bool RenderWidgetHostViewAura::RequestRepaintForTesting() {
849 return SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
850 base::nullopt);
851 }
852
DidStopFlinging()853 void RenderWidgetHostViewAura::DidStopFlinging() {
854 selection_controller_client_->OnScrollCompleted();
855 }
856
TransformPointToRootSurface(gfx::PointF * point)857 void RenderWidgetHostViewAura::TransformPointToRootSurface(gfx::PointF* point) {
858 aura::Window* root = window_->GetRootWindow();
859 aura::Window::ConvertPointToTarget(window_, root, point);
860 root->GetRootWindow()->transform().TransformPoint(point);
861 }
862
GetBoundsInRootWindow()863 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() {
864 aura::Window* top_level = window_->GetToplevelWindow();
865 gfx::Rect bounds(top_level->GetBoundsInScreen());
866
867 #if defined(OS_WIN)
868 // TODO(zturner,iyengar): This will break when we remove support for NPAPI and
869 // remove the legacy hwnd, so a better fix will need to be decided when that
870 // happens.
871 if (UsesNativeWindowFrame()) {
872 // aura::Window doesn't take into account non-client area of native windows
873 // (e.g. HWNDs), so for that case ask Windows directly what the bounds are.
874 aura::WindowTreeHost* host = top_level->GetHost();
875 if (!host)
876 return top_level->GetBoundsInScreen();
877 RECT window_rect = {0};
878 HWND hwnd = host->GetAcceleratedWidget();
879 ::GetWindowRect(hwnd, &window_rect);
880 bounds = gfx::Rect(window_rect);
881
882 // Maximized windows are outdented from the work area by the frame thickness
883 // even though this "frame" is not painted. This confuses code (and people)
884 // that think of a maximized window as corresponding exactly to the work
885 // area. Correct for this by subtracting the frame thickness back off.
886 if (::IsZoomed(hwnd)) {
887 bounds.Inset(GetSystemMetrics(SM_CXSIZEFRAME),
888 GetSystemMetrics(SM_CYSIZEFRAME));
889
890 bounds.Inset(GetSystemMetrics(SM_CXPADDEDBORDER),
891 GetSystemMetrics(SM_CXPADDEDBORDER));
892 }
893
894 // Pixels come back from GetWindowHost, so we need to convert those back to
895 // DIPs here.
896 bounds = display::Screen::GetScreen()->ScreenToDIPRectInWindow(top_level,
897 bounds);
898 }
899
900 #endif
901
902 return bounds;
903 }
904
WheelEventAck(const blink::WebMouseWheelEvent & event,blink::mojom::InputEventResultState ack_result)905 void RenderWidgetHostViewAura::WheelEventAck(
906 const blink::WebMouseWheelEvent& event,
907 blink::mojom::InputEventResultState ack_result) {
908 if (overscroll_controller_) {
909 overscroll_controller_->ReceivedEventACK(
910 event, (blink::mojom::InputEventResultState::kConsumed == ack_result));
911 }
912 }
913
DidOverscroll(const ui::DidOverscrollParams & params)914 void RenderWidgetHostViewAura::DidOverscroll(
915 const ui::DidOverscrollParams& params) {
916 if (overscroll_controller_)
917 overscroll_controller_->OnDidOverscroll(params);
918 }
919
GestureEventAck(const blink::WebGestureEvent & event,blink::mojom::InputEventResultState ack_result)920 void RenderWidgetHostViewAura::GestureEventAck(
921 const blink::WebGestureEvent& event,
922 blink::mojom::InputEventResultState ack_result) {
923 const blink::WebInputEvent::Type event_type = event.GetType();
924 if (event_type == blink::WebGestureEvent::Type::kGestureScrollBegin ||
925 event_type == blink::WebGestureEvent::Type::kGestureScrollEnd) {
926 if (host()->delegate()) {
927 host()->delegate()->SetTopControlsGestureScrollInProgress(
928 event_type == blink::WebGestureEvent::Type::kGestureScrollBegin);
929 }
930 }
931
932 if (overscroll_controller_) {
933 overscroll_controller_->ReceivedEventACK(
934 event, (blink::mojom::InputEventResultState::kConsumed == ack_result));
935 // Terminate an active fling when the ACK for a GSU generated from the fling
936 // progress (GSU with inertial state) is consumed and the overscrolling mode
937 // is not |OVERSCROLL_NONE|. The early fling termination generates a GSE
938 // which completes the overscroll action. Without this change the overscroll
939 // action would complete at the end of the active fling progress which
940 // causes noticeable delay in cases that the fling velocity is large.
941 // https://crbug.com/797855
942 if (event_type == blink::WebInputEvent::Type::kGestureScrollUpdate &&
943 event.data.scroll_update.inertial_phase ==
944 blink::WebGestureEvent::InertialPhaseState::kMomentum &&
945 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE) {
946 StopFling();
947 }
948 }
949
950 // Stop flinging if a GSU event with momentum phase is sent to the renderer
951 // but not consumed.
952 StopFlingingIfNecessary(event, ack_result);
953
954 event_handler_->GestureEventAck(event, ack_result);
955
956 ForwardTouchpadZoomEventIfNecessary(event, ack_result);
957 }
958
ProcessAckedTouchEvent(const TouchEventWithLatencyInfo & touch,blink::mojom::InputEventResultState ack_result)959 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
960 const TouchEventWithLatencyInfo& touch,
961 blink::mojom::InputEventResultState ack_result) {
962 aura::WindowTreeHost* window_host = window_->GetHost();
963 // |host| is NULL during tests.
964 if (!window_host)
965 return;
966
967 // The TouchScrollStarted event is generated & consumed downstream from the
968 // TouchEventQueue. So we don't expect an ACK up here.
969 DCHECK(touch.event.GetType() !=
970 blink::WebInputEvent::Type::kTouchScrollStarted);
971
972 ui::EventResult result =
973 (ack_result == blink::mojom::InputEventResultState::kConsumed)
974 ? ui::ER_HANDLED
975 : ui::ER_UNHANDLED;
976
977 blink::WebTouchPoint::State required_state;
978 switch (touch.event.GetType()) {
979 case blink::WebInputEvent::Type::kTouchStart:
980 required_state = blink::WebTouchPoint::State::kStatePressed;
981 break;
982 case blink::WebInputEvent::Type::kTouchEnd:
983 required_state = blink::WebTouchPoint::State::kStateReleased;
984 break;
985 case blink::WebInputEvent::Type::kTouchMove:
986 required_state = blink::WebTouchPoint::State::kStateMoved;
987 break;
988 case blink::WebInputEvent::Type::kTouchCancel:
989 required_state = blink::WebTouchPoint::State::kStateCancelled;
990 break;
991 default:
992 required_state = blink::WebTouchPoint::State::kStateUndefined;
993 NOTREACHED();
994 break;
995 }
996
997 // Only send acks for one changed touch point.
998 bool sent_ack = false;
999 for (size_t i = 0; i < touch.event.touches_length; ++i) {
1000 if (touch.event.touches[i].state == required_state) {
1001 DCHECK(!sent_ack);
1002 window_host->dispatcher()->ProcessedTouchEvent(
1003 touch.event.unique_touch_event_id, window_, result,
1004 InputEventResultStateIsSetNonBlocking(ack_result));
1005 if (touch.event.touch_start_or_first_touch_move &&
1006 result == ui::ER_HANDLED && host()->delegate() &&
1007 host()->delegate()->GetInputEventRouter()) {
1008 host()
1009 ->delegate()
1010 ->GetInputEventRouter()
1011 ->OnHandledTouchStartOrFirstTouchMove(
1012 touch.event.unique_touch_event_id);
1013 }
1014 sent_ack = true;
1015 }
1016 }
1017 }
1018
1019 std::unique_ptr<SyntheticGestureTarget>
CreateSyntheticGestureTarget()1020 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1021 return std::unique_ptr<SyntheticGestureTarget>(
1022 new SyntheticGestureTargetAura(host()));
1023 }
1024
FilterInputEvent(const blink::WebInputEvent & input_event)1025 blink::mojom::InputEventResultState RenderWidgetHostViewAura::FilterInputEvent(
1026 const blink::WebInputEvent& input_event) {
1027 bool consumed = false;
1028 if (input_event.GetType() == WebInputEvent::Type::kGestureFlingStart) {
1029 const WebGestureEvent& gesture_event =
1030 static_cast<const WebGestureEvent&>(input_event);
1031 // Zero-velocity touchpad flings are an Aura-specific signal that the
1032 // touchpad scroll has ended, and should not be forwarded to the renderer.
1033 if (gesture_event.SourceDevice() == blink::WebGestureDevice::kTouchpad &&
1034 !gesture_event.data.fling_start.velocity_x &&
1035 !gesture_event.data.fling_start.velocity_y) {
1036 consumed = true;
1037 }
1038 }
1039
1040 if (overscroll_controller_)
1041 consumed |= overscroll_controller_->WillHandleEvent(input_event);
1042
1043 // Touch events should always propagate to the renderer.
1044 if (WebTouchEvent::IsTouchEventType(input_event.GetType()))
1045 return blink::mojom::InputEventResultState::kNotConsumed;
1046
1047 if (consumed &&
1048 input_event.GetType() == blink::WebInputEvent::Type::kGestureFlingStart) {
1049 // Here we indicate that there was no consumer for this event, as
1050 // otherwise the fling animation system will try to run an animation
1051 // and will also expect a notification when the fling ends. Since
1052 // CrOS just uses the GestureFlingStart with zero-velocity as a means
1053 // of indicating that touchpad scroll has ended, we don't actually want
1054 // a fling animation. Note: Similar code exists in
1055 // RenderWidgetHostViewChildFrame::FilterInputEvent()
1056 return blink::mojom::InputEventResultState::kNoConsumerExists;
1057 }
1058
1059 return consumed ? blink::mojom::InputEventResultState::kConsumed
1060 : blink::mojom::InputEventResultState::kNotConsumed;
1061 }
1062
1063 BrowserAccessibilityManager*
CreateBrowserAccessibilityManager(BrowserAccessibilityDelegate * delegate,bool for_root_frame)1064 RenderWidgetHostViewAura::CreateBrowserAccessibilityManager(
1065 BrowserAccessibilityDelegate* delegate,
1066 bool for_root_frame) {
1067 BrowserAccessibilityManager* manager = nullptr;
1068 #if defined(OS_WIN)
1069 manager = new BrowserAccessibilityManagerWin(
1070 BrowserAccessibilityManagerWin::GetEmptyDocument(), delegate);
1071 #else
1072 manager = BrowserAccessibilityManager::Create(
1073 BrowserAccessibilityManager::GetEmptyDocument(), delegate);
1074 #endif
1075 return manager;
1076 }
1077
1078 gfx::AcceleratedWidget
AccessibilityGetAcceleratedWidget()1079 RenderWidgetHostViewAura::AccessibilityGetAcceleratedWidget() {
1080 #if defined(OS_WIN)
1081 if (legacy_render_widget_host_HWND_)
1082 return legacy_render_widget_host_HWND_->hwnd();
1083 #endif
1084 return gfx::kNullAcceleratedWidget;
1085 }
1086
1087 gfx::NativeViewAccessible
AccessibilityGetNativeViewAccessible()1088 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1089 #if defined(OS_WIN)
1090 if (legacy_render_widget_host_HWND_) {
1091 return legacy_render_widget_host_HWND_->window_accessible();
1092 }
1093 #endif
1094
1095 if (window_->parent()) {
1096 return window_->parent()->GetProperty(
1097 aura::client::kParentNativeViewAccessibleKey);
1098 }
1099
1100 return nullptr;
1101 }
1102
SetMainFrameAXTreeID(ui::AXTreeID id)1103 void RenderWidgetHostViewAura::SetMainFrameAXTreeID(ui::AXTreeID id) {
1104 window_->SetProperty(ui::kChildAXTreeID, id.ToString());
1105 }
1106
LockMouse(bool request_unadjusted_movement)1107 blink::mojom::PointerLockResult RenderWidgetHostViewAura::LockMouse(
1108 bool request_unadjusted_movement) {
1109 return event_handler_->LockMouse(request_unadjusted_movement);
1110 }
1111
ChangeMouseLock(bool request_unadjusted_movement)1112 blink::mojom::PointerLockResult RenderWidgetHostViewAura::ChangeMouseLock(
1113 bool request_unadjusted_movement) {
1114 return event_handler_->ChangeMouseLock(request_unadjusted_movement);
1115 }
1116
UnlockMouse()1117 void RenderWidgetHostViewAura::UnlockMouse() {
1118 event_handler_->UnlockMouse();
1119 }
1120
GetIsMouseLockedUnadjustedMovementForTesting()1121 bool RenderWidgetHostViewAura::GetIsMouseLockedUnadjustedMovementForTesting() {
1122 return event_handler_->mouse_locked_unadjusted_movement();
1123 }
1124
LockKeyboard(base::Optional<base::flat_set<ui::DomCode>> codes)1125 bool RenderWidgetHostViewAura::LockKeyboard(
1126 base::Optional<base::flat_set<ui::DomCode>> codes) {
1127 return event_handler_->LockKeyboard(std::move(codes));
1128 }
1129
UnlockKeyboard()1130 void RenderWidgetHostViewAura::UnlockKeyboard() {
1131 event_handler_->UnlockKeyboard();
1132 }
1133
IsKeyboardLocked()1134 bool RenderWidgetHostViewAura::IsKeyboardLocked() {
1135 return event_handler_->IsKeyboardLocked();
1136 }
1137
1138 base::flat_map<std::string, std::string>
GetKeyboardLayoutMap()1139 RenderWidgetHostViewAura::GetKeyboardLayoutMap() {
1140 aura::WindowTreeHost* host = window_->GetHost();
1141 if (host)
1142 return host->GetKeyboardLayoutMap();
1143 return {};
1144 }
1145
1146 ////////////////////////////////////////////////////////////////////////////////
1147 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
SetCompositionText(const ui::CompositionText & composition)1148 void RenderWidgetHostViewAura::SetCompositionText(
1149 const ui::CompositionText& composition) {
1150 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1151 return;
1152
1153 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
1154 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
1155 text_input_manager_->GetActiveWidget()->ImeSetComposition(
1156 composition.text, composition.ime_text_spans, gfx::Range::InvalidRange(),
1157 composition.selection.end(), composition.selection.end());
1158
1159 has_composition_text_ = !composition.text.empty();
1160 }
1161
ConfirmCompositionText(bool keep_selection)1162 uint32_t RenderWidgetHostViewAura::ConfirmCompositionText(bool keep_selection) {
1163 if (text_input_manager_ && text_input_manager_->GetActiveWidget() &&
1164 has_composition_text_) {
1165 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(
1166 keep_selection);
1167 }
1168 has_composition_text_ = false;
1169 // TODO(crbug/1109604): Return the number of characters committed by this
1170 // function.
1171 return UINT32_MAX;
1172 }
1173
ClearCompositionText()1174 void RenderWidgetHostViewAura::ClearCompositionText() {
1175 if (text_input_manager_ && text_input_manager_->GetActiveWidget() &&
1176 has_composition_text_)
1177 text_input_manager_->GetActiveWidget()->ImeCancelComposition();
1178 has_composition_text_ = false;
1179 }
1180
InsertText(const base::string16 & text)1181 void RenderWidgetHostViewAura::InsertText(const base::string16& text) {
1182 DCHECK_NE(GetTextInputType(), ui::TEXT_INPUT_TYPE_NONE);
1183
1184 if (text_input_manager_ && text_input_manager_->GetActiveWidget()) {
1185 if (text.length())
1186 text_input_manager_->GetActiveWidget()->ImeCommitText(
1187 text, std::vector<ui::ImeTextSpan>(), gfx::Range::InvalidRange(), 0);
1188 else if (has_composition_text_)
1189 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(false);
1190 }
1191 has_composition_text_ = false;
1192 }
1193
InsertChar(const ui::KeyEvent & event)1194 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) {
1195 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1196 popup_child_host_view_->InsertChar(event);
1197 return;
1198 }
1199
1200 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1201 if (event_handler_->accept_return_character() ||
1202 event.GetCharacter() != ui::VKEY_RETURN) {
1203 // Send a blink::WebInputEvent::Char event to |host_|.
1204 ForwardKeyboardEventWithLatencyInfo(
1205 NativeWebKeyboardEvent(event, event.GetCharacter()), *event.latency(),
1206 nullptr);
1207 }
1208 }
1209
GetTextInputType() const1210 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1211 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1212 return text_input_manager_->GetTextInputState()->type;
1213 return ui::TEXT_INPUT_TYPE_NONE;
1214 }
1215
GetTextInputMode() const1216 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const {
1217 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1218 return text_input_manager_->GetTextInputState()->mode;
1219 return ui::TEXT_INPUT_MODE_DEFAULT;
1220 }
1221
GetTextDirection() const1222 base::i18n::TextDirection RenderWidgetHostViewAura::GetTextDirection() const {
1223 NOTIMPLEMENTED_LOG_ONCE();
1224 return base::i18n::UNKNOWN_DIRECTION;
1225 }
1226
GetTextInputFlags() const1227 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1228 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1229 return text_input_manager_->GetTextInputState()->flags;
1230 return 0;
1231 }
1232
CanComposeInline() const1233 bool RenderWidgetHostViewAura::CanComposeInline() const {
1234 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1235 return text_input_manager_->GetTextInputState()->can_compose_inline;
1236 return true;
1237 }
1238
ConvertRectToScreen(const gfx::Rect & rect) const1239 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen(
1240 const gfx::Rect& rect) const {
1241 gfx::Point origin = rect.origin();
1242 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1243
1244 aura::Window* root_window = window_->GetRootWindow();
1245 if (!root_window)
1246 return rect;
1247 aura::client::ScreenPositionClient* screen_position_client =
1248 aura::client::GetScreenPositionClient(root_window);
1249 if (!screen_position_client)
1250 return rect;
1251 screen_position_client->ConvertPointToScreen(window_, &origin);
1252 screen_position_client->ConvertPointToScreen(window_, &end);
1253 return gfx::Rect(origin.x(), origin.y(), base::ClampSub(end.x(), origin.x()),
1254 base::ClampSub(end.y(), origin.y()));
1255 }
1256
ConvertRectFromScreen(const gfx::Rect & rect) const1257 gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen(
1258 const gfx::Rect& rect) const {
1259 gfx::Rect result = rect;
1260 if (window_->GetRootWindow() &&
1261 aura::client::GetScreenPositionClient(window_->GetRootWindow()))
1262 wm::ConvertRectFromScreen(window_, &result);
1263 return result;
1264 }
1265
GetCaretBounds() const1266 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const {
1267 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1268 return gfx::Rect();
1269
1270 const TextInputManager::SelectionRegion* region =
1271 text_input_manager_->GetSelectionRegion();
1272 return ConvertRectToScreen(
1273 gfx::RectBetweenSelectionBounds(region->anchor, region->focus));
1274 }
1275
GetCompositionCharacterBounds(uint32_t index,gfx::Rect * rect) const1276 bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
1277 uint32_t index,
1278 gfx::Rect* rect) const {
1279 DCHECK(rect);
1280
1281 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1282 return false;
1283
1284 const TextInputManager::CompositionRangeInfo* composition_range_info =
1285 text_input_manager_->GetCompositionRangeInfo();
1286
1287 if (index >= composition_range_info->character_bounds.size())
1288 return false;
1289 *rect = ConvertRectToScreen(composition_range_info->character_bounds[index]);
1290 return true;
1291 }
1292
HasCompositionText() const1293 bool RenderWidgetHostViewAura::HasCompositionText() const {
1294 return has_composition_text_;
1295 }
1296
GetFocusReason() const1297 ui::TextInputClient::FocusReason RenderWidgetHostViewAura::GetFocusReason()
1298 const {
1299 if (!window_->HasFocus())
1300 return ui::TextInputClient::FOCUS_REASON_NONE;
1301
1302 switch (last_pointer_type_before_focus_) {
1303 case ui::EventPointerType::kMouse:
1304 return ui::TextInputClient::FOCUS_REASON_MOUSE;
1305 case ui::EventPointerType::kPen:
1306 return ui::TextInputClient::FOCUS_REASON_PEN;
1307 case ui::EventPointerType::kTouch:
1308 return ui::TextInputClient::FOCUS_REASON_TOUCH;
1309 default:
1310 return ui::TextInputClient::FOCUS_REASON_OTHER;
1311 }
1312 }
1313
GetTextRange(gfx::Range * range) const1314 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const {
1315 if (!text_input_manager_ || !GetFocusedWidget())
1316 return false;
1317
1318 const ui::mojom::TextInputState* state =
1319 text_input_manager_->GetTextInputState();
1320 if (!state)
1321 return false;
1322
1323 range->set_start(0);
1324 range->set_end(state->value ? state->value->length() : 0);
1325 return true;
1326 }
1327
GetCompositionTextRange(gfx::Range * range) const1328 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1329 gfx::Range* range) const {
1330 if (!text_input_manager_ || !GetFocusedWidget())
1331 return false;
1332
1333 const ui::mojom::TextInputState* state =
1334 text_input_manager_->GetTextInputState();
1335 // Return false when there is no composition.
1336 if (!state || !state->composition)
1337 return false;
1338
1339 *range = state->composition.value();
1340 return true;
1341 }
1342
GetEditableSelectionRange(gfx::Range * range) const1343 bool RenderWidgetHostViewAura::GetEditableSelectionRange(
1344 gfx::Range* range) const {
1345 if (!text_input_manager_ || !GetFocusedWidget())
1346 return false;
1347
1348 const ui::mojom::TextInputState* state =
1349 text_input_manager_->GetTextInputState();
1350 if (!state)
1351 return false;
1352
1353 *range = state->selection;
1354 return true;
1355 }
1356
SetEditableSelectionRange(const gfx::Range & range)1357 bool RenderWidgetHostViewAura::SetEditableSelectionRange(
1358 const gfx::Range& range) {
1359 // TODO(crbug.com/915630): Write an unit test for this method.
1360 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1361 if (!input_handler)
1362 return false;
1363 input_handler->SetEditableSelectionOffsets(range.start(), range.end());
1364 return true;
1365 }
1366
DeleteRange(const gfx::Range & range)1367 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range& range) {
1368 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1369 NOTIMPLEMENTED_LOG_ONCE();
1370 return false;
1371 }
1372
GetTextFromRange(const gfx::Range & range,base::string16 * text) const1373 bool RenderWidgetHostViewAura::GetTextFromRange(
1374 const gfx::Range& range,
1375 base::string16* text) const {
1376 if (!text_input_manager_ || !GetFocusedWidget())
1377 return false;
1378
1379 const ui::mojom::TextInputState* state =
1380 text_input_manager_->GetTextInputState();
1381 if (!state)
1382 return false;
1383
1384 gfx::Range text_range;
1385 GetTextRange(&text_range);
1386
1387 if (!text_range.Contains(range)) {
1388 text->clear();
1389 return false;
1390 }
1391 if (!state->value) {
1392 text->clear();
1393 return true;
1394 }
1395 if (text_range.EqualsIgnoringDirection(range)) {
1396 // Avoid calling substr whose performance is low.
1397 *text = *state->value;
1398 } else {
1399 *text = state->value->substr(range.GetMin(), range.length());
1400 }
1401 return true;
1402 }
1403
OnInputMethodChanged()1404 void RenderWidgetHostViewAura::OnInputMethodChanged() {
1405 // TODO(suzhe): implement the newly added "locale" property of HTML DOM
1406 // TextEvent.
1407 }
1408
ChangeTextDirectionAndLayoutAlignment(base::i18n::TextDirection direction)1409 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
1410 base::i18n::TextDirection direction) {
1411 if (!GetTextInputManager() && !GetTextInputManager()->GetActiveWidget())
1412 return false;
1413
1414 GetTextInputManager()->GetActiveWidget()->UpdateTextDirection(direction);
1415 GetTextInputManager()->GetActiveWidget()->NotifyTextDirection();
1416 return true;
1417 }
1418
ExtendSelectionAndDelete(size_t before,size_t after)1419 void RenderWidgetHostViewAura::ExtendSelectionAndDelete(
1420 size_t before, size_t after) {
1421 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1422 if (!input_handler)
1423 return;
1424 input_handler->ExtendSelectionAndDelete(before, after);
1425 }
1426
EnsureCaretNotInRect(const gfx::Rect & rect_in_screen)1427 void RenderWidgetHostViewAura::EnsureCaretNotInRect(
1428 const gfx::Rect& rect_in_screen) {
1429 aura::Window* top_level_window = window_->GetToplevelWindow();
1430 #if BUILDFLAG(IS_CHROMEOS_ASH)
1431 wm::EnsureWindowNotInRect(top_level_window, rect_in_screen);
1432 #endif
1433
1434 // Perform overscroll if the caret is still hidden by the keyboard.
1435 const gfx::Rect hidden_window_bounds_in_screen = gfx::IntersectRects(
1436 rect_in_screen, top_level_window->GetBoundsInScreen());
1437 if (hidden_window_bounds_in_screen.IsEmpty())
1438 return;
1439
1440 gfx::Rect visible_area_in_local_space = gfx::SubtractRects(
1441 window_->GetBoundsInScreen(), hidden_window_bounds_in_screen);
1442 visible_area_in_local_space =
1443 ConvertRectFromScreen(visible_area_in_local_space);
1444 ScrollFocusedEditableNodeIntoRect(visible_area_in_local_space);
1445 }
1446
IsTextEditCommandEnabled(ui::TextEditCommand command) const1447 bool RenderWidgetHostViewAura::IsTextEditCommandEnabled(
1448 ui::TextEditCommand command) const {
1449 return false;
1450 }
1451
SetTextEditCommandForNextKeyEvent(ui::TextEditCommand command)1452 void RenderWidgetHostViewAura::SetTextEditCommandForNextKeyEvent(
1453 ui::TextEditCommand command) {}
1454
GetClientSourceForMetrics() const1455 ukm::SourceId RenderWidgetHostViewAura::GetClientSourceForMetrics() const {
1456 RenderFrameHostImpl* frame = GetFocusedFrame();
1457 if (frame) {
1458 return frame->GetPageUkmSourceId();
1459 }
1460 return ukm::SourceId();
1461 }
1462
ShouldDoLearning()1463 bool RenderWidgetHostViewAura::ShouldDoLearning() {
1464 return GetTextInputManager() && GetTextInputManager()->should_do_learning();
1465 }
1466
1467 #if defined(OS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH)
SetCompositionFromExistingText(const gfx::Range & range,const std::vector<ui::ImeTextSpan> & ui_ime_text_spans)1468 bool RenderWidgetHostViewAura::SetCompositionFromExistingText(
1469 const gfx::Range& range,
1470 const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
1471 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1472 if (!input_handler)
1473 return false;
1474 input_handler->SetCompositionFromExistingText(range.start(), range.end(),
1475 ui_ime_text_spans);
1476 has_composition_text_ = true;
1477 return true;
1478 }
1479
1480 #endif
1481
1482 #if BUILDFLAG(IS_CHROMEOS_ASH)
GetAutocorrectRange() const1483 gfx::Range RenderWidgetHostViewAura::GetAutocorrectRange() const {
1484 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1485 return gfx::Range();
1486
1487 const std::vector<ui::mojom::ImeTextSpanInfoPtr>& ime_text_spans_info =
1488 text_input_manager_->GetTextInputState()->ime_text_spans_info;
1489
1490 unsigned autocorrect_span_found = 0;
1491 gfx::Range range;
1492 for (const auto& ime_text_span_info : ime_text_spans_info) {
1493 if (ime_text_span_info->span.type == ui::ImeTextSpan::Type::kAutocorrect) {
1494 range = gfx::Range(ime_text_span_info->span.start_offset,
1495 ime_text_span_info->span.end_offset);
1496 autocorrect_span_found++;
1497 }
1498 }
1499 // Assuming there is only one autocorrect span at any point in time.
1500 DCHECK_LE(autocorrect_span_found, 1u);
1501 return range;
1502 }
1503
GetAutocorrectCharacterBounds() const1504 gfx::Rect RenderWidgetHostViewAura::GetAutocorrectCharacterBounds() const {
1505 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1506 return gfx::Rect();
1507
1508 const std::vector<ui::mojom::ImeTextSpanInfoPtr>& ime_text_spans_info =
1509 text_input_manager_->GetTextInputState()->ime_text_spans_info;
1510
1511 unsigned autocorrect_span_found = 0;
1512 gfx::Rect bounds;
1513 for (const auto& ime_text_span_info : ime_text_spans_info) {
1514 if (ime_text_span_info->span.type == ui::ImeTextSpan::Type::kAutocorrect) {
1515 bounds = ConvertRectToScreen(ime_text_span_info->bounds);
1516 autocorrect_span_found++;
1517 }
1518 }
1519 // Assuming there is only one autocorrect span at any point in time.
1520 DCHECK_LE(autocorrect_span_found, 1u);
1521 return bounds;
1522 }
1523
SetAutocorrectRange(const base::string16 & autocorrect_text,const gfx::Range & range)1524 bool RenderWidgetHostViewAura::SetAutocorrectRange(
1525 const base::string16& autocorrect_text,
1526 const gfx::Range& range) {
1527 base::UmaHistogramEnumeration(
1528 "InputMethod.Assistive.Autocorrect.Count",
1529 TextInputClient::SubClass::kRenderWidgetHostViewAura);
1530
1531 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1532 if (!input_handler)
1533 return false;
1534 if (autocorrect_text.empty()) {
1535 input_handler->ClearImeTextSpansByType(range.start(), range.end(),
1536 ui::ImeTextSpan::Type::kAutocorrect);
1537 return true;
1538 }
1539 ui::ImeTextSpan ui_ime_text_span;
1540 ui_ime_text_span.type = ui::ImeTextSpan::Type::kAutocorrect;
1541 ui_ime_text_span.start_offset = 0;
1542 ui_ime_text_span.end_offset = autocorrect_text.length();
1543 ui_ime_text_span.underline_style = ui::ImeTextSpan::UnderlineStyle::kDot;
1544 ui_ime_text_span.underline_color = gfx::kGoogleGrey700;
1545
1546 input_handler->AddImeTextSpansToExistingText(range.start(), range.end(),
1547 {ui_ime_text_span});
1548 return true;
1549 }
1550
ClearAutocorrectRange()1551 void RenderWidgetHostViewAura::ClearAutocorrectRange() {
1552 // TODO(crbug/1108170): Once we have a FrameWidgetInputHandlerMock, add a test
1553 // to verify that the ClearImeTextSpansByType function has been called.
1554 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1555 if (!input_handler)
1556 return;
1557 input_handler->ClearImeTextSpansByType(0, UINT32_MAX,
1558 ui::ImeTextSpan::Type::kAutocorrect);
1559 }
1560 #endif
1561
1562 #if defined(OS_WIN)
GetActiveTextInputControlLayoutBounds(base::Optional<gfx::Rect> * control_bounds,base::Optional<gfx::Rect> * selection_bounds)1563 void RenderWidgetHostViewAura::GetActiveTextInputControlLayoutBounds(
1564 base::Optional<gfx::Rect>* control_bounds,
1565 base::Optional<gfx::Rect>* selection_bounds) {
1566 if (text_input_manager_) {
1567 const ui::mojom::TextInputState* state =
1568 text_input_manager_->GetTextInputState();
1569 if (state) {
1570 if (state->edit_context_control_bounds)
1571 *control_bounds =
1572 ConvertRectToScreen(state->edit_context_control_bounds.value());
1573 // Selection bounds are currently populated only for EditContext.
1574 // For editable elements we use GetCompositionCharacterBounds.
1575 if (state->edit_context_selection_bounds)
1576 *selection_bounds =
1577 ConvertRectToScreen(state->edit_context_selection_bounds.value());
1578 }
1579 }
1580 }
1581
SetActiveCompositionForAccessibility(const gfx::Range & range,const base::string16 & active_composition_text,bool is_composition_committed)1582 void RenderWidgetHostViewAura::SetActiveCompositionForAccessibility(
1583 const gfx::Range& range,
1584 const base::string16& active_composition_text,
1585 bool is_composition_committed) {
1586 BrowserAccessibilityManager* manager =
1587 host()->GetRootBrowserAccessibilityManager();
1588 if (manager) {
1589 ui::AXPlatformNodeWin* focus_node = static_cast<ui::AXPlatformNodeWin*>(
1590 ui::AXPlatformNode::FromNativeViewAccessible(
1591 manager->GetFocus()->GetNativeViewAccessible()));
1592 if (focus_node) {
1593 // Notify accessibility object about this composition
1594 focus_node->OnActiveComposition(range, active_composition_text,
1595 is_composition_committed);
1596 }
1597 }
1598 }
1599
1600 #endif
1601
1602 ////////////////////////////////////////////////////////////////////////////////
1603 // RenderWidgetHostViewAura, display::DisplayObserver implementation:
1604
OnDisplayMetricsChanged(const display::Display & display,uint32_t metrics)1605 void RenderWidgetHostViewAura::OnDisplayMetricsChanged(
1606 const display::Display& display,
1607 uint32_t metrics) {
1608 display::Screen* screen = display::Screen::GetScreen();
1609 if (display.id() != screen->GetDisplayNearestWindow(window_).id())
1610 return;
1611
1612 if (window_->GetHost() && window_->GetHost()->device_scale_factor() !=
1613 display.device_scale_factor()) {
1614 // The DisplayMetrics changed, but the Compositor hasn't been updated yet.
1615 // Delay updating until the Compositor is updated as well, otherwise we
1616 // are likely to hit surface invariants (LocalSurfaceId generated with a
1617 // size/scale-factor that differs from scale-factor used by Compositor).
1618 needs_to_update_display_metrics_ = true;
1619 return;
1620 }
1621 ProcessDisplayMetricsChanged();
1622 }
1623
1624 ////////////////////////////////////////////////////////////////////////////////
1625 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
1626
GetMinimumSize() const1627 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
1628 return gfx::Size();
1629 }
1630
GetMaximumSize() const1631 gfx::Size RenderWidgetHostViewAura::GetMaximumSize() const {
1632 return gfx::Size();
1633 }
1634
OnBoundsChanged(const gfx::Rect & old_bounds,const gfx::Rect & new_bounds)1635 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
1636 const gfx::Rect& new_bounds) {
1637 base::AutoReset<bool> in_bounds_changed(&in_bounds_changed_, true);
1638 // We care about this whenever RenderWidgetHostViewAura is not owned by a
1639 // WebContentsViewAura since changes to the Window's bounds need to be
1640 // messaged to the renderer. WebContentsViewAura invokes SetSize() or
1641 // SetBounds() itself. No matter how we got here, any redundant calls are
1642 // harmless.
1643 SetSize(new_bounds.size());
1644
1645 if (GetInputMethod())
1646 GetInputMethod()->OnCaretBoundsChanged(this);
1647 }
1648
GetCursor(const gfx::Point & point)1649 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
1650 if (IsMouseLocked())
1651 return ui::mojom::CursorType::kNone;
1652 return current_cursor_.GetNativeCursor();
1653 }
1654
GetNonClientComponent(const gfx::Point & point) const1655 int RenderWidgetHostViewAura::GetNonClientComponent(
1656 const gfx::Point& point) const {
1657 return HTCLIENT;
1658 }
1659
ShouldDescendIntoChildForEventHandling(aura::Window * child,const gfx::Point & location)1660 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1661 aura::Window* child,
1662 const gfx::Point& location) {
1663 return true;
1664 }
1665
CanFocus()1666 bool RenderWidgetHostViewAura::CanFocus() {
1667 return widget_type_ == WidgetType::kFrame;
1668 }
1669
OnCaptureLost()1670 void RenderWidgetHostViewAura::OnCaptureLost() {
1671 host()->LostCapture();
1672 }
1673
OnPaint(const ui::PaintContext & context)1674 void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext& context) {
1675 NOTREACHED();
1676 }
1677
OnDeviceScaleFactorChanged(float old_device_scale_factor,float new_device_scale_factor)1678 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1679 float old_device_scale_factor,
1680 float new_device_scale_factor) {
1681 if (!window_->GetRootWindow())
1682 return;
1683
1684 if (needs_to_update_display_metrics_)
1685 ProcessDisplayMetricsChanged();
1686
1687 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
1688 window_->GetLocalSurfaceId());
1689
1690 device_scale_factor_ = new_device_scale_factor;
1691 const display::Display display =
1692 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
1693 DCHECK_EQ(new_device_scale_factor, display.device_scale_factor());
1694 current_cursor_.SetDisplayInfo(display);
1695 }
1696
OnWindowDestroying(aura::Window * window)1697 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) {
1698 #if defined(OS_WIN)
1699 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is
1700 // destroyed. Normally we control when that happens via the Destroy call
1701 // in the dtor. However there may be cases where the window is destroyed
1702 // by Windows, i.e. the parent window is destroyed before the
1703 // RenderWidgetHostViewAura instance goes away etc. To avoid that we
1704 // destroy the LegacyRenderWidgetHostHWND instance here.
1705 if (legacy_render_widget_host_HWND_) {
1706 legacy_render_widget_host_HWND_->Destroy();
1707 // The Destroy call above will delete the LegacyRenderWidgetHostHWND
1708 // instance.
1709 legacy_render_widget_host_HWND_ = nullptr;
1710 }
1711 #endif
1712
1713 // Make sure that the input method no longer references to this object before
1714 // this object is removed from the root window (i.e. this object loses access
1715 // to the input method).
1716 DetachFromInputMethod(true);
1717
1718 if (overscroll_controller_)
1719 overscroll_controller_->Reset();
1720 }
1721
OnWindowDestroyed(aura::Window * window)1722 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) {
1723 // This is not called on all destruction paths (e.g. if this view was never
1724 // inialized properly to create the window). So the destruction/cleanup code
1725 // that do not depend on |window_| should happen in the destructor, not here.
1726 delete this;
1727 }
1728
OnWindowTargetVisibilityChanged(bool visible)1729 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1730 }
1731
HasHitTestMask() const1732 bool RenderWidgetHostViewAura::HasHitTestMask() const {
1733 return false;
1734 }
1735
GetHitTestMask(SkPath * mask) const1736 void RenderWidgetHostViewAura::GetHitTestMask(SkPath* mask) const {}
1737
RequiresDoubleTapGestureEvents() const1738 bool RenderWidgetHostViewAura::RequiresDoubleTapGestureEvents() const {
1739 RenderWidgetHostOwnerDelegate* owner_delegate = host()->owner_delegate();
1740 // TODO(crbug.com/916715): Child local roots do not work here?
1741 if (!owner_delegate)
1742 return false;
1743 return double_tap_to_zoom_enabled_;
1744 }
1745
1746 ////////////////////////////////////////////////////////////////////////////////
1747 // RenderWidgetHostViewAura, ui::EventHandler implementation:
1748
OnKeyEvent(ui::KeyEvent * event)1749 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
1750 last_pointer_type_ = ui::EventPointerType::kUnknown;
1751 event_handler_->OnKeyEvent(event);
1752 }
1753
OnMouseEvent(ui::MouseEvent * event)1754 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
1755 #if defined(OS_WIN)
1756 if (event->type() == ui::ET_MOUSE_MOVED) {
1757 if (event->location() == last_mouse_move_location_ &&
1758 event->movement().IsZero()) {
1759 event->SetHandled();
1760 return;
1761 }
1762 last_mouse_move_location_ = event->location();
1763 }
1764 #endif
1765 last_pointer_type_ = ui::EventPointerType::kMouse;
1766 event_handler_->OnMouseEvent(event);
1767 }
1768
HasFallbackSurface() const1769 bool RenderWidgetHostViewAura::HasFallbackSurface() const {
1770 return delegated_frame_host_ && delegated_frame_host_->HasFallbackSurface();
1771 }
1772
TransformPointToCoordSpaceForView(const gfx::PointF & point,RenderWidgetHostViewBase * target_view,gfx::PointF * transformed_point)1773 bool RenderWidgetHostViewAura::TransformPointToCoordSpaceForView(
1774 const gfx::PointF& point,
1775 RenderWidgetHostViewBase* target_view,
1776 gfx::PointF* transformed_point) {
1777 if (target_view == this || !delegated_frame_host_) {
1778 *transformed_point = point;
1779 return true;
1780 }
1781
1782 // In TransformPointToLocalCoordSpace() there is a Point-to-Pixel conversion,
1783 // but it is not necessary here because the final target view is responsible
1784 // for converting before computing the final transform.
1785 return target_view->TransformPointToLocalCoordSpace(
1786 point, GetCurrentSurfaceId(), transformed_point);
1787 }
1788
GetRootFrameSinkId()1789 viz::FrameSinkId RenderWidgetHostViewAura::GetRootFrameSinkId() {
1790 if (!window_ || !window_->GetHost() || !window_->GetHost()->compositor())
1791 return viz::FrameSinkId();
1792
1793 return window_->GetHost()->compositor()->frame_sink_id();
1794 }
1795
GetCurrentSurfaceId() const1796 viz::SurfaceId RenderWidgetHostViewAura::GetCurrentSurfaceId() const {
1797 return delegated_frame_host_ ? delegated_frame_host_->GetCurrentSurfaceId()
1798 : viz::SurfaceId();
1799 }
1800
FocusedNodeChanged(bool editable,const gfx::Rect & node_bounds_in_screen)1801 void RenderWidgetHostViewAura::FocusedNodeChanged(
1802 bool editable,
1803 const gfx::Rect& node_bounds_in_screen) {
1804 // The last gesture most likely caused the focus change. The focus reason will
1805 // be incorrect if the focus was triggered without a user gesture.
1806 // TODO(https://crbug.com/824604): Get the focus reason from the renderer
1807 // process instead to get the true focus reason.
1808 last_pointer_type_before_focus_ = last_pointer_type_;
1809
1810 auto* input_method = GetInputMethod();
1811 if (input_method)
1812 input_method->CancelComposition(this);
1813 has_composition_text_ = false;
1814
1815 #if defined(OS_WIN)
1816 if (window_ && virtual_keyboard_controller_win_) {
1817 virtual_keyboard_controller_win_->FocusedNodeChanged(editable);
1818 }
1819 #elif defined(OS_FUCHSIA)
1820 if (!editable && window_) {
1821 if (input_method) {
1822 input_method->GetInputMethodKeyboardController()
1823 ->DismissVirtualKeyboard();
1824 }
1825 }
1826 #endif
1827 }
1828
OnScrollEvent(ui::ScrollEvent * event)1829 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
1830 event_handler_->OnScrollEvent(event);
1831 }
1832
OnTouchEvent(ui::TouchEvent * event)1833 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
1834 last_pointer_type_ = event->pointer_details().pointer_type;
1835 event_handler_->OnTouchEvent(event);
1836 }
1837
OnGestureEvent(ui::GestureEvent * event)1838 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
1839 last_pointer_type_ = event->details().primary_pointer_type();
1840 event_handler_->OnGestureEvent(event);
1841 }
1842
1843 ////////////////////////////////////////////////////////////////////////////////
1844 // RenderWidgetHostViewAura, wm::ActivationDelegate implementation:
1845
ShouldActivate() const1846 bool RenderWidgetHostViewAura::ShouldActivate() const {
1847 aura::WindowTreeHost* host = window_->GetHost();
1848 if (!host)
1849 return true;
1850 const ui::Event* event = host->dispatcher()->current_event();
1851 if (!event)
1852 return true;
1853 return is_fullscreen_;
1854 }
1855
1856 ////////////////////////////////////////////////////////////////////////////////
1857 // RenderWidgetHostViewAura, aura::client::CursorClientObserver implementation:
1858
OnCursorVisibilityChanged(bool is_visible)1859 void RenderWidgetHostViewAura::OnCursorVisibilityChanged(bool is_visible) {
1860 NotifyRendererOfCursorVisibilityState(is_visible);
1861 }
1862
1863 ////////////////////////////////////////////////////////////////////////////////
1864 // RenderWidgetHostViewAura, aura::client::FocusChangeObserver implementation:
1865
OnWindowFocused(aura::Window * gained_focus,aura::Window * lost_focus)1866 void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
1867 aura::Window* lost_focus) {
1868 if (window_ == gained_focus) {
1869 // We need to honor input bypass if the associated tab does not want input.
1870 // This gives the current focused window a chance to be the text input
1871 // client and handle events.
1872 if (host()->IsIgnoringInputEvents())
1873 return;
1874
1875 host()->GotFocus();
1876 host()->SetActive(true);
1877
1878 ui::InputMethod* input_method = GetInputMethod();
1879 if (input_method) {
1880 // Ask the system-wide IME to send all TextInputClient messages to |this|
1881 // object.
1882 input_method->SetFocusedTextInputClient(this);
1883 }
1884
1885 BrowserAccessibilityManager* manager =
1886 host()->GetRootBrowserAccessibilityManager();
1887 if (manager)
1888 manager->OnWindowFocused();
1889 return;
1890 }
1891
1892 if (window_ != lost_focus) {
1893 NOTREACHED();
1894 return;
1895 }
1896
1897 // Only lose focus if the associated tab doesn't want input. This ensures
1898 // focus losses from clicking on a page while it has a modal dialog won't
1899 // break it's text cursor after the dialog goes away.
1900 if (!host()->IsIgnoringInputEvents()) {
1901 host()->SetActive(false);
1902 host()->LostFocus();
1903
1904 DetachFromInputMethod(false);
1905 }
1906
1907 // TODO(wjmaclean): Do we need to let TouchSelectionControllerClientAura
1908 // handle this, just in case it stomps on a new highlight in another view
1909 // that has just become focused? So far it doesn't appear to be a problem,
1910 // but we should keep an eye on it.
1911 selection_controller_->HideAndDisallowShowingAutomatically();
1912
1913 if (overscroll_controller_)
1914 overscroll_controller_->Cancel();
1915
1916 BrowserAccessibilityManager* manager =
1917 host()->GetRootBrowserAccessibilityManager();
1918 if (manager)
1919 manager->OnWindowBlurred();
1920
1921 // If we lose the focus while fullscreen, close the window; Pepper Flash
1922 // won't do it for us (unlike NPAPI Flash). However, we do not close the
1923 // window if we lose the focus to a window on another display.
1924 display::Screen* screen = display::Screen::GetScreen();
1925 bool focusing_other_display =
1926 gained_focus && screen->GetNumDisplays() > 1 &&
1927 (screen->GetDisplayNearestWindow(window_).id() !=
1928 screen->GetDisplayNearestWindow(gained_focus).id());
1929 if (is_fullscreen_ && !in_shutdown_ && !focusing_other_display) {
1930 #if defined(OS_WIN)
1931 // On Windows, if we are switching to a non Aura Window on a different
1932 // screen we should not close the fullscreen window.
1933 if (!gained_focus) {
1934 POINT point = {0};
1935 ::GetCursorPos(&point);
1936 if (screen->GetDisplayNearestWindow(window_).id() !=
1937 screen->GetDisplayNearestPoint(gfx::Point(point)).id()) {
1938 return;
1939 }
1940 }
1941 #endif
1942 Shutdown();
1943 return;
1944 }
1945
1946 // Close the child popup window if we lose focus (e.g. due to a JS alert or
1947 // system modal dialog). This is particularly important if
1948 // |popup_child_host_view_| has mouse capture.
1949 if (popup_child_host_view_)
1950 popup_child_host_view_->Shutdown();
1951 }
1952
1953 ////////////////////////////////////////////////////////////////////////////////
1954 // RenderWidgetHostViewAura, aura::WindowTreeHostObserver implementation:
1955
OnHostMovedInPixels(aura::WindowTreeHost * host,const gfx::Point & new_origin_in_pixels)1956 void RenderWidgetHostViewAura::OnHostMovedInPixels(
1957 aura::WindowTreeHost* host,
1958 const gfx::Point& new_origin_in_pixels) {
1959 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMovedInPixels",
1960 "new_origin_in_pixels", new_origin_in_pixels.ToString());
1961
1962 UpdateScreenInfo(window_);
1963 }
1964
1965 ////////////////////////////////////////////////////////////////////////////////
1966 // RenderWidgetHostViewAura, RenderFrameMetadataProvider::Observer
1967 // implementation:
OnRenderFrameMetadataChangedAfterActivation()1968 void RenderWidgetHostViewAura::OnRenderFrameMetadataChangedAfterActivation() {
1969 const cc::RenderFrameMetadata& metadata =
1970 host()->render_frame_metadata_provider()->LastRenderFrameMetadata();
1971 SetContentBackgroundColor(metadata.root_background_color);
1972 if (inset_surface_id_.is_valid() && metadata.local_surface_id &&
1973 metadata.local_surface_id.value().is_valid() &&
1974 metadata.local_surface_id.value().IsSameOrNewerThan(inset_surface_id_)) {
1975 inset_surface_id_ = viz::LocalSurfaceId();
1976 ScrollFocusedEditableNodeIntoRect(gfx::Rect());
1977 }
1978
1979 if (metadata.selection.start != selection_start_ ||
1980 metadata.selection.end != selection_end_) {
1981 selection_start_ = metadata.selection.start;
1982 selection_end_ = metadata.selection.end;
1983 selection_controller_client_->UpdateClientSelectionBounds(selection_start_,
1984 selection_end_);
1985 }
1986 }
1987
1988 ////////////////////////////////////////////////////////////////////////////////
1989 // RenderWidgetHostViewAura, private:
1990
~RenderWidgetHostViewAura()1991 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
1992 host()->render_frame_metadata_provider()->RemoveObserver(this);
1993
1994 // Ask the RWH to drop reference to us.
1995 host()->ViewDestroyed();
1996
1997 selection_controller_.reset();
1998 selection_controller_client_.reset();
1999
2000 GetCursorManager()->ViewBeingDestroyed(this);
2001
2002 delegated_frame_host_.reset();
2003 window_observer_.reset();
2004 if (window_) {
2005 if (window_->GetHost())
2006 window_->GetHost()->RemoveObserver(this);
2007 UnlockMouse();
2008 wm::SetTooltipText(window_, nullptr);
2009 display::Screen::GetScreen()->RemoveObserver(this);
2010
2011 // This call is usually no-op since |this| object is already removed from
2012 // the Aura root window and we don't have a way to get an input method
2013 // object associated with the window, but just in case.
2014 DetachFromInputMethod(true);
2015 }
2016 if (popup_parent_host_view_) {
2017 DCHECK(!popup_parent_host_view_->popup_child_host_view_ ||
2018 popup_parent_host_view_->popup_child_host_view_ == this);
2019 popup_parent_host_view_->SetPopupChild(nullptr);
2020 }
2021 if (popup_child_host_view_) {
2022 DCHECK(!popup_child_host_view_->popup_parent_host_view_ ||
2023 popup_child_host_view_->popup_parent_host_view_ == this);
2024 popup_child_host_view_->popup_parent_host_view_ = nullptr;
2025 }
2026 event_observer_for_popup_exit_.reset();
2027
2028 #if defined(OS_WIN)
2029 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2030 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2031 // be set to NULL.
2032 DCHECK(!legacy_render_widget_host_HWND_);
2033 #endif
2034
2035 if (text_input_manager_)
2036 text_input_manager_->RemoveObserver(this);
2037 }
2038
CreateAuraWindow(aura::client::WindowType type)2039 void RenderWidgetHostViewAura::CreateAuraWindow(aura::client::WindowType type) {
2040 DCHECK(!window_);
2041 window_ = new aura::Window(this);
2042 window_->SetName("RenderWidgetHostViewAura");
2043 event_handler_->set_window(window_);
2044 window_observer_.reset(new WindowObserver(this));
2045
2046 wm::SetTooltipText(window_, &tooltip_);
2047 wm::SetActivationDelegate(window_, this);
2048 aura::client::SetFocusChangeObserver(window_, this);
2049 display::Screen::GetScreen()->AddObserver(this);
2050
2051 window_->SetType(type);
2052 window_->Init(ui::LAYER_SOLID_COLOR);
2053 window_->layer()->SetColor(GetBackgroundColor() ? *GetBackgroundColor()
2054 : SK_ColorWHITE);
2055 // This needs to happen only after |window_| has been initialized using
2056 // Init(), because it needs to have the layer.
2057 if (frame_sink_id_.is_valid())
2058 window_->SetEmbedFrameSinkId(frame_sink_id_);
2059 }
2060
CreateDelegatedFrameHostClient()2061 void RenderWidgetHostViewAura::CreateDelegatedFrameHostClient() {
2062 if (!frame_sink_id_.is_valid())
2063 return;
2064
2065 delegated_frame_host_client_ =
2066 std::make_unique<DelegatedFrameHostClientAura>(this);
2067 delegated_frame_host_ = std::make_unique<DelegatedFrameHost>(
2068 frame_sink_id_, delegated_frame_host_client_.get(),
2069 false /* should_register_frame_sink_id */);
2070
2071 // Let the page-level input event router know about our surface ID
2072 // namespace for surface-based hit testing.
2073 if (host()->delegate() && host()->delegate()->GetInputEventRouter()) {
2074 host()->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner(
2075 GetFrameSinkId(), this);
2076 }
2077 }
2078
UpdateCursorIfOverSelf()2079 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
2080 if (host()->GetProcess()->FastShutdownStarted())
2081 return;
2082
2083 aura::Window* root_window = window_->GetRootWindow();
2084 if (!root_window)
2085 return;
2086
2087 display::Screen* screen = display::Screen::GetScreen();
2088 DCHECK(screen);
2089
2090 gfx::Point cursor_screen_point = screen->GetCursorScreenPoint();
2091
2092 #if !BUILDFLAG(IS_CHROMEOS_ASH)
2093 // Ignore cursor update messages if the window under the cursor is not us.
2094 aura::Window* window_at_screen_point = screen->GetWindowAtScreenPoint(
2095 cursor_screen_point);
2096 #if defined(OS_WIN)
2097 // On Windows we may fail to retrieve the aura Window at the current cursor
2098 // position. This is because the WindowFromPoint API may return the legacy
2099 // window which is not associated with an aura Window. In this case we need
2100 // to get the aura window for the parent of the legacy window.
2101 if (!window_at_screen_point && legacy_render_widget_host_HWND_) {
2102 HWND hwnd_at_point = ::WindowFromPoint(cursor_screen_point.ToPOINT());
2103
2104 if (hwnd_at_point == legacy_render_widget_host_HWND_->hwnd())
2105 hwnd_at_point = legacy_render_widget_host_HWND_->GetParent();
2106
2107 display::win::ScreenWin* screen_win =
2108 static_cast<display::win::ScreenWin*>(screen);
2109 window_at_screen_point = screen_win->GetNativeWindowFromHWND(
2110 hwnd_at_point);
2111 }
2112 #endif // defined(OS_WIN)
2113 if (!window_at_screen_point ||
2114 (window_at_screen_point->GetRootWindow() != root_window)) {
2115 return;
2116 }
2117 #endif // !BUILDFLAG(IS_CHROMEOS_ASH)
2118
2119 gfx::Point root_window_point = cursor_screen_point;
2120 aura::client::ScreenPositionClient* screen_position_client =
2121 aura::client::GetScreenPositionClient(root_window);
2122 if (screen_position_client) {
2123 screen_position_client->ConvertPointFromScreen(
2124 root_window, &root_window_point);
2125 }
2126
2127 if (root_window->GetEventHandlerForPoint(root_window_point) != window_)
2128 return;
2129
2130 gfx::NativeCursor cursor = current_cursor_.GetNativeCursor();
2131 // Do not show loading cursor when the cursor is currently hidden.
2132 if (is_loading_ && cursor != ui::mojom::CursorType::kNone)
2133 cursor = ui::Cursor(ui::mojom::CursorType::kPointer);
2134
2135 aura::client::CursorClient* cursor_client =
2136 aura::client::GetCursorClient(root_window);
2137 if (cursor_client) {
2138 cursor_client->SetCursor(cursor);
2139 }
2140 }
2141
SynchronizeVisualProperties(const cc::DeadlinePolicy & deadline_policy,const base::Optional<viz::LocalSurfaceId> & child_local_surface_id)2142 bool RenderWidgetHostViewAura::SynchronizeVisualProperties(
2143 const cc::DeadlinePolicy& deadline_policy,
2144 const base::Optional<viz::LocalSurfaceId>& child_local_surface_id) {
2145 DCHECK(window_);
2146 window_->UpdateLocalSurfaceIdFromEmbeddedClient(child_local_surface_id);
2147 // If the viz::LocalSurfaceId is invalid, we may have been evicted,
2148 // allocate a new one to establish bounds.
2149 if (!GetLocalSurfaceId().is_valid())
2150 window_->AllocateLocalSurfaceId();
2151
2152 if (delegated_frame_host_) {
2153 delegated_frame_host_->EmbedSurface(
2154 GetLocalSurfaceId(), window_->bounds().size(), deadline_policy);
2155 }
2156 return host()->SynchronizeVisualProperties();
2157 }
2158
OnDidUpdateVisualPropertiesComplete(const cc::RenderFrameMetadata & metadata)2159 void RenderWidgetHostViewAura::OnDidUpdateVisualPropertiesComplete(
2160 const cc::RenderFrameMetadata& metadata) {
2161 DCHECK(window_);
2162
2163 if (host()->delegate()) {
2164 host()->delegate()->SetTopControlsShownRatio(
2165 host(), metadata.top_controls_shown_ratio);
2166 }
2167
2168 if (host()->is_hidden()) {
2169 // When an embedded child responds, we want to accept its changes to the
2170 // viz::LocalSurfaceId. However we do not want to embed surfaces while
2171 // hidden. Nor do we want to embed invalid ids when we are evicted. Becoming
2172 // visible will generate a new id, if necessary, and begin embedding.
2173 window_->UpdateLocalSurfaceIdFromEmbeddedClient(metadata.local_surface_id);
2174 } else {
2175 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
2176 metadata.local_surface_id);
2177 }
2178 }
2179
GetInputMethod() const2180 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const {
2181 if (!window_)
2182 return nullptr;
2183 aura::Window* root_window = window_->GetRootWindow();
2184 if (!root_window)
2185 return nullptr;
2186 return root_window->GetHost()->GetInputMethod();
2187 }
2188
2189 RenderWidgetHostViewBase*
GetFocusedViewForTextSelection()2190 RenderWidgetHostViewAura::GetFocusedViewForTextSelection() {
2191 // We obtain the TextSelection from focused RWH which is obtained from the
2192 // frame tree.
2193 return GetFocusedWidget() ? GetFocusedWidget()->GetView() : nullptr;
2194 }
2195
Shutdown()2196 void RenderWidgetHostViewAura::Shutdown() {
2197 if (!in_shutdown_) {
2198 in_shutdown_ = true;
2199 host()->ShutdownAndDestroyWidget(true);
2200 }
2201 }
2202
ShouldVirtualKeyboardOverlayContent() const2203 bool RenderWidgetHostViewAura::ShouldVirtualKeyboardOverlayContent() const {
2204 RenderFrameHostImpl* frame = GetFocusedFrame();
2205 if (!frame)
2206 return false;
2207
2208 return frame->ShouldVirtualKeyboardOverlayContent();
2209 }
2210
NotifyVirtualKeyboardOverlayRect(const gfx::Rect & keyboard_rect)2211 void RenderWidgetHostViewAura::NotifyVirtualKeyboardOverlayRect(
2212 const gfx::Rect& keyboard_rect) {
2213 RenderFrameHostImpl* frame = GetFocusedFrame();
2214 if (!frame)
2215 return;
2216 frame->NotifyVirtualKeyboardOverlayRect(keyboard_rect);
2217 }
2218
FocusedFrameHasStickyActivation() const2219 bool RenderWidgetHostViewAura::FocusedFrameHasStickyActivation() const {
2220 RenderFrameHostImpl* frame = GetFocusedFrame();
2221 if (!frame)
2222 return false;
2223
2224 return frame->frame_tree_node()->HasStickyUserActivation();
2225 }
2226
2227 TouchSelectionControllerClientManager*
GetTouchSelectionControllerClientManager()2228 RenderWidgetHostViewAura::GetTouchSelectionControllerClientManager() {
2229 return selection_controller_client_.get();
2230 }
2231
NeedsInputGrab()2232 bool RenderWidgetHostViewAura::NeedsInputGrab() {
2233 return widget_type_ == WidgetType::kPopup;
2234 }
2235
NeedsMouseCapture()2236 bool RenderWidgetHostViewAura::NeedsMouseCapture() {
2237 #if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || defined(OS_BSD)
2238 return NeedsInputGrab();
2239 #else
2240 return false;
2241 #endif
2242 }
2243
SetTooltipsEnabled(bool enable)2244 void RenderWidgetHostViewAura::SetTooltipsEnabled(bool enable) {
2245 if (enable) {
2246 tooltip_disabler_.reset();
2247 } else {
2248 tooltip_disabler_.reset(
2249 new wm::ScopedTooltipDisabler(window_->GetRootWindow()));
2250 }
2251 }
2252
NotifyRendererOfCursorVisibilityState(bool is_visible)2253 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2254 bool is_visible) {
2255 if (host()->is_hidden() ||
2256 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2257 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2258 return;
2259
2260 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
2261 host()->OnCursorVisibilityStateChanged(is_visible);
2262 }
2263
SetOverscrollControllerEnabled(bool enabled)2264 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
2265 if (!enabled)
2266 overscroll_controller_.reset();
2267 else if (!overscroll_controller_)
2268 overscroll_controller_.reset(new OverscrollController());
2269 }
2270
SetSelectionControllerClientForTest(std::unique_ptr<TouchSelectionControllerClientAura> client)2271 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest(
2272 std::unique_ptr<TouchSelectionControllerClientAura> client) {
2273 selection_controller_client_.swap(client);
2274 CreateSelectionController();
2275 }
2276
InternalSetBounds(const gfx::Rect & rect)2277 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
2278 // Don't recursively call SetBounds if this bounds update is the result of
2279 // a Window::SetBoundsInternal call.
2280 if (!in_bounds_changed_)
2281 window_->SetBounds(rect);
2282
2283 // Even if not showing yet, we need to synchronize on size. As the renderer
2284 // needs to begin layout. Waiting until we show to start layout leads to
2285 // significant delays in embedding the first shown surface (500+ ms.)
2286 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
2287 window_->GetLocalSurfaceId());
2288
2289 #if defined(OS_WIN)
2290 UpdateLegacyWin();
2291
2292 if (IsMouseLocked())
2293 UpdateMouseLockRegion();
2294 #endif
2295 }
2296
2297 #if defined(OS_WIN)
UpdateLegacyWin()2298 void RenderWidgetHostViewAura::UpdateLegacyWin() {
2299 if (legacy_window_destroyed_ || !GetHostWindowHWND())
2300 return;
2301
2302 if (!legacy_render_widget_host_HWND_) {
2303 legacy_render_widget_host_HWND_ =
2304 LegacyRenderWidgetHostHWND::Create(GetHostWindowHWND());
2305 }
2306
2307 if (legacy_render_widget_host_HWND_) {
2308 legacy_render_widget_host_HWND_->set_host(this);
2309 legacy_render_widget_host_HWND_->UpdateParent(GetHostWindowHWND());
2310 legacy_render_widget_host_HWND_->SetBounds(
2311 window_->GetBoundsInRootWindow());
2312 // There are cases where the parent window is created, made visible and
2313 // the associated RenderWidget is also visible before the
2314 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
2315 // here.
2316 if (!host()->is_hidden())
2317 legacy_render_widget_host_HWND_->Show();
2318 }
2319 }
2320 #endif
2321
AddedToRootWindow()2322 void RenderWidgetHostViewAura::AddedToRootWindow() {
2323 window_->GetHost()->AddObserver(this);
2324 UpdateScreenInfo(window_);
2325
2326 aura::client::CursorClient* cursor_client =
2327 aura::client::GetCursorClient(window_->GetRootWindow());
2328 if (cursor_client) {
2329 cursor_client->AddObserver(this);
2330 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
2331 }
2332 if (HasFocus()) {
2333 ui::InputMethod* input_method = GetInputMethod();
2334 if (input_method)
2335 input_method->SetFocusedTextInputClient(this);
2336 }
2337
2338 #if defined(OS_WIN)
2339 UpdateLegacyWin();
2340 #endif
2341
2342 if (delegated_frame_host_)
2343 delegated_frame_host_->AttachToCompositor(window_->GetHost()->compositor());
2344 }
2345
RemovingFromRootWindow()2346 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2347 aura::client::CursorClient* cursor_client =
2348 aura::client::GetCursorClient(window_->GetRootWindow());
2349 if (cursor_client)
2350 cursor_client->RemoveObserver(this);
2351
2352 DetachFromInputMethod(true);
2353
2354 window_->GetHost()->RemoveObserver(this);
2355 if (delegated_frame_host_)
2356 delegated_frame_host_->DetachFromCompositor();
2357
2358 #if defined(OS_WIN)
2359 // Update the legacy window's parent temporarily to the hidden window. It
2360 // will eventually get reparented to the right root.
2361 if (legacy_render_widget_host_HWND_)
2362 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
2363 #endif
2364 }
2365
DetachFromInputMethod(bool is_removed)2366 void RenderWidgetHostViewAura::DetachFromInputMethod(bool is_removed) {
2367 ui::InputMethod* input_method = GetInputMethod();
2368 if (input_method) {
2369 input_method->DetachTextInputClient(this);
2370 #if BUILDFLAG(IS_CHROMEOS_ASH)
2371 wm::RestoreWindowBoundsOnClientFocusLost(window_->GetToplevelWindow());
2372 #endif // BUILDFLAG(IS_CHROMEOS_ASH)
2373 }
2374
2375 #if defined(OS_WIN)
2376 // If window is getting destroyed, then reset the VK controller, else,
2377 // dismiss the VK and notify about the keyboard inset since window has lost
2378 // focus.
2379 if (virtual_keyboard_controller_win_) {
2380 if (is_removed)
2381 virtual_keyboard_controller_win_.reset();
2382 else
2383 virtual_keyboard_controller_win_->HideAndNotifyKeyboardInset();
2384 }
2385 #endif // defined(OS_WIN)
2386 }
2387
ForwardKeyboardEventWithLatencyInfo(const NativeWebKeyboardEvent & event,const ui::LatencyInfo & latency,bool * update_event)2388 void RenderWidgetHostViewAura::ForwardKeyboardEventWithLatencyInfo(
2389 const NativeWebKeyboardEvent& event,
2390 const ui::LatencyInfo& latency,
2391 bool* update_event) {
2392 RenderWidgetHostImpl* target_host = host();
2393
2394 // If there are multiple widgets on the page (such as when there are
2395 // out-of-process iframes), pick the one that should process this event.
2396 if (host()->delegate())
2397 target_host = host()->delegate()->GetFocusedRenderWidgetHost(host());
2398 if (!target_host)
2399 return;
2400
2401 #if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || defined(OS_BSD)
2402 ui::TextEditKeyBindingsDelegateAuraLinux* keybinding_delegate =
2403 ui::GetTextEditKeyBindingsDelegate();
2404 std::vector<ui::TextEditCommandAuraLinux> commands;
2405 if (!event.skip_in_browser &&
2406 keybinding_delegate &&
2407 event.os_event &&
2408 keybinding_delegate->MatchEvent(*event.os_event, &commands)) {
2409 // Transform from ui/ types to content/ types.
2410 std::vector<blink::mojom::EditCommandPtr> edit_commands;
2411 for (std::vector<ui::TextEditCommandAuraLinux>::const_iterator it =
2412 commands.begin(); it != commands.end(); ++it) {
2413 edit_commands.push_back(blink::mojom::EditCommand::New(
2414 it->GetCommandString(), it->argument()));
2415 }
2416
2417 target_host->ForwardKeyboardEventWithCommands(
2418 event, latency, std::move(edit_commands), update_event);
2419 return;
2420 }
2421 #endif
2422
2423 target_host->ForwardKeyboardEventWithCommands(
2424 event, latency, std::vector<blink::mojom::EditCommandPtr>(),
2425 update_event);
2426 }
2427
CreateSelectionController()2428 void RenderWidgetHostViewAura::CreateSelectionController() {
2429 ui::TouchSelectionController::Config tsc_config;
2430 tsc_config.max_tap_duration = base::TimeDelta::FromMilliseconds(
2431 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms());
2432 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance()
2433 ->max_touch_move_in_pixels_for_click();
2434 tsc_config.enable_longpress_drag_selection = false;
2435 selection_controller_.reset(new ui::TouchSelectionController(
2436 selection_controller_client_.get(), tsc_config));
2437 }
2438
OnDidNavigateMainFrameToNewPage()2439 void RenderWidgetHostViewAura::OnDidNavigateMainFrameToNewPage() {
2440 CancelActiveTouches();
2441 }
2442
GetFrameSinkId() const2443 const viz::FrameSinkId& RenderWidgetHostViewAura::GetFrameSinkId() const {
2444 return frame_sink_id_;
2445 }
2446
GetLocalSurfaceId() const2447 const viz::LocalSurfaceId& RenderWidgetHostViewAura::GetLocalSurfaceId() const {
2448 return window_->GetLocalSurfaceId();
2449 }
2450
OnUpdateTextInputStateCalled(TextInputManager * text_input_manager,RenderWidgetHostViewBase * updated_view,bool did_update_state)2451 void RenderWidgetHostViewAura::OnUpdateTextInputStateCalled(
2452 TextInputManager* text_input_manager,
2453 RenderWidgetHostViewBase* updated_view,
2454 bool did_update_state) {
2455 DCHECK_EQ(text_input_manager_, text_input_manager);
2456
2457 if (!GetInputMethod())
2458 return;
2459
2460 if (did_update_state)
2461 GetInputMethod()->OnTextInputTypeChanged(this);
2462
2463 const ui::mojom::TextInputState* state =
2464 text_input_manager_->GetTextInputState();
2465
2466 // Show the virtual keyboard if needed.
2467 if (state && state->type != ui::TEXT_INPUT_TYPE_NONE &&
2468 state->mode != ui::TEXT_INPUT_MODE_NONE) {
2469 bool show_virtual_keyboard = true;
2470 #if defined(OS_FUCHSIA)
2471 show_virtual_keyboard =
2472 GetLastPointerType() == ui::EventPointerType::kTouch;
2473 #endif
2474
2475 #if !defined(OS_WIN)
2476 if (state->show_ime_if_needed &&
2477 GetInputMethod()->GetTextInputClient() == this &&
2478 show_virtual_keyboard) {
2479 GetInputMethod()->ShowVirtualKeyboardIfEnabled();
2480 }
2481 // TODO(crbug.com/1031786): Remove this once TSF fix for input pane policy
2482 // is serviced
2483 #elif defined(OS_WIN)
2484 if (GetInputMethod() && show_virtual_keyboard) {
2485 if (!virtual_keyboard_controller_win_) {
2486 virtual_keyboard_controller_win_.reset(
2487 new VirtualKeyboardControllerWin(this, GetInputMethod()));
2488 }
2489 virtual_keyboard_controller_win_->UpdateTextInputState(state);
2490 }
2491 #endif
2492 }
2493
2494 // Ensure that selection bounds changes are sent to the IME.
2495 if (state && state->type != ui::TEXT_INPUT_TYPE_NONE) {
2496 text_input_manager->NotifySelectionBoundsChanged(updated_view);
2497 }
2498
2499 if (auto* render_widget_host = updated_view->host()) {
2500 // Monitor the composition information if there is a focused editable node.
2501 render_widget_host->RequestCompositionUpdates(
2502 false /* immediate_request */,
2503 state &&
2504 (state->type != ui::TEXT_INPUT_TYPE_NONE) /* monitor_updates */);
2505 }
2506 }
2507
OnImeCancelComposition(TextInputManager * text_input_manager,RenderWidgetHostViewBase * view)2508 void RenderWidgetHostViewAura::OnImeCancelComposition(
2509 TextInputManager* text_input_manager,
2510 RenderWidgetHostViewBase* view) {
2511 // |view| is not necessarily the one corresponding to
2512 // TextInputManager::GetActiveWidget() as RenderWidgetHostViewAura can call
2513 // this method to finish any ongoing composition in response to a mouse down
2514 // event.
2515 if (GetInputMethod())
2516 GetInputMethod()->CancelComposition(this);
2517 has_composition_text_ = false;
2518 }
2519
OnSelectionBoundsChanged(TextInputManager * text_input_manager,RenderWidgetHostViewBase * updated_view)2520 void RenderWidgetHostViewAura::OnSelectionBoundsChanged(
2521 TextInputManager* text_input_manager,
2522 RenderWidgetHostViewBase* updated_view) {
2523 // Note: accessibility caret move events are no longer fired directly here,
2524 // because they were redundant with the events fired by the top level window
2525 // by HWNDMessageHandler::OnCaretBoundsChanged().
2526 if (GetInputMethod())
2527 GetInputMethod()->OnCaretBoundsChanged(this);
2528 }
2529
OnTextSelectionChanged(TextInputManager * text_input_manager,RenderWidgetHostViewBase * updated_view)2530 void RenderWidgetHostViewAura::OnTextSelectionChanged(
2531 TextInputManager* text_input_manager,
2532 RenderWidgetHostViewBase* updated_view) {
2533 if (!GetTextInputManager())
2534 return;
2535
2536 // We obtain the TextSelection from focused RWH which is obtained from the
2537 // frame tree.
2538 RenderWidgetHostViewBase* focused_view =
2539 GetFocusedWidget() ? GetFocusedWidget()->GetView() : nullptr;
2540
2541 if (!focused_view)
2542 return;
2543
2544 // IMF relies on the |OnCaretBoundsChanged| for the surrounding text changed
2545 // events to IME. Explicitly call |OnCaretBoundsChanged| here so that IMF can
2546 // know about the surrounding text changes when the caret bounds are not
2547 // changed. e.g. When the rendered text is wider than the input field,
2548 // deleting the last character won't change the caret bounds but will change
2549 // the surrounding text.
2550 if (GetInputMethod())
2551 GetInputMethod()->OnCaretBoundsChanged(this);
2552
2553 #if defined(USE_X11) || (defined(USE_OZONE) && !BUILDFLAG(IS_CHROMEOS_ASH))
2554 const TextInputManager::TextSelection* selection =
2555 GetTextInputManager()->GetTextSelection(focused_view);
2556 if (selection->selected_text().length()) {
2557 // Set the ClipboardBuffer::kSelection to the ui::Clipboard.
2558 ui::ScopedClipboardWriter clipboard_writer(ui::ClipboardBuffer::kSelection);
2559 clipboard_writer.WriteText(selection->selected_text());
2560 }
2561 #endif // defined(USE_X11) || (defined(USE_OZONE) &&
2562 // !BUILDFLAG(IS_CHROMEOS_ASH))
2563 }
2564
SetPopupChild(RenderWidgetHostViewAura * popup_child_host_view)2565 void RenderWidgetHostViewAura::SetPopupChild(
2566 RenderWidgetHostViewAura* popup_child_host_view) {
2567 popup_child_host_view_ = popup_child_host_view;
2568 event_handler_->SetPopupChild(
2569 popup_child_host_view,
2570 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr);
2571 }
2572
ScrollFocusedEditableNodeIntoRect(const gfx::Rect & node_rect)2573 void RenderWidgetHostViewAura::ScrollFocusedEditableNodeIntoRect(
2574 const gfx::Rect& node_rect) {
2575 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
2576 if (!input_handler)
2577 return;
2578 input_handler->ScrollFocusedEditableNodeIntoRect(node_rect);
2579 }
2580
OnSynchronizedDisplayPropertiesChanged()2581 void RenderWidgetHostViewAura::OnSynchronizedDisplayPropertiesChanged() {
2582 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
2583 base::nullopt);
2584 }
2585
2586 viz::ScopedSurfaceIdAllocator
DidUpdateVisualProperties(const cc::RenderFrameMetadata & metadata)2587 RenderWidgetHostViewAura::DidUpdateVisualProperties(
2588 const cc::RenderFrameMetadata& metadata) {
2589 base::OnceCallback<void()> allocation_task = base::BindOnce(
2590 &RenderWidgetHostViewAura::OnDidUpdateVisualPropertiesComplete,
2591 weak_ptr_factory_.GetWeakPtr(), metadata);
2592 return window_->GetSurfaceIdAllocator(std::move(allocation_task));
2593 }
2594
DidNavigate()2595 void RenderWidgetHostViewAura::DidNavigate() {
2596 if (!IsShowing()) {
2597 // Navigating while hidden should not allocate a new LocalSurfaceID. Once
2598 // sizes are ready, or we begin to Show, we can then allocate the new
2599 // LocalSurfaceId.
2600 window_->InvalidateLocalSurfaceId();
2601 } else {
2602 if (is_first_navigation_) {
2603 // The first navigation does not need a new LocalSurfaceID. The renderer
2604 // can use the ID that was already provided.
2605 SynchronizeVisualProperties(cc::DeadlinePolicy::UseExistingDeadline(),
2606 window_->GetLocalSurfaceId());
2607 } else {
2608 SynchronizeVisualProperties(cc::DeadlinePolicy::UseExistingDeadline(),
2609 base::nullopt);
2610 }
2611 }
2612 if (delegated_frame_host_)
2613 delegated_frame_host_->DidNavigate();
2614 is_first_navigation_ = false;
2615 }
2616
GetMouseWheelPhaseHandler()2617 MouseWheelPhaseHandler* RenderWidgetHostViewAura::GetMouseWheelPhaseHandler() {
2618 return &event_handler_->mouse_wheel_phase_handler();
2619 }
2620
TakeFallbackContentFrom(RenderWidgetHostView * view)2621 void RenderWidgetHostViewAura::TakeFallbackContentFrom(
2622 RenderWidgetHostView* view) {
2623 DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)
2624 ->IsRenderWidgetHostViewChildFrame());
2625 RenderWidgetHostViewAura* view_aura =
2626 static_cast<RenderWidgetHostViewAura*>(view);
2627 base::Optional<SkColor> color = view_aura->GetBackgroundColor();
2628 if (color)
2629 SetBackgroundColor(*color);
2630
2631 if (delegated_frame_host_ && view_aura->delegated_frame_host_) {
2632 delegated_frame_host_->TakeFallbackContentFrom(
2633 view_aura->delegated_frame_host_.get());
2634 }
2635 host()->GetContentRenderingTimeoutFrom(view_aura->host());
2636 }
2637
CanSynchronizeVisualProperties()2638 bool RenderWidgetHostViewAura::CanSynchronizeVisualProperties() {
2639 return !needs_to_update_display_metrics_;
2640 }
2641
2642 std::vector<std::unique_ptr<ui::TouchEvent>>
ExtractAndCancelActiveTouches()2643 RenderWidgetHostViewAura::ExtractAndCancelActiveTouches() {
2644 aura::Env* env = aura::Env::GetInstance();
2645 std::vector<std::unique_ptr<ui::TouchEvent>> touches =
2646 env->gesture_recognizer()->ExtractTouches(window());
2647 CancelActiveTouches();
2648 return touches;
2649 }
2650
TransferTouches(const std::vector<std::unique_ptr<ui::TouchEvent>> & touches)2651 void RenderWidgetHostViewAura::TransferTouches(
2652 const std::vector<std::unique_ptr<ui::TouchEvent>>& touches) {
2653 aura::Env* env = aura::Env::GetInstance();
2654 env->gesture_recognizer()->TransferTouches(window(), touches);
2655 }
2656
SetLastPointerType(ui::EventPointerType last_pointer_type)2657 void RenderWidgetHostViewAura::SetLastPointerType(
2658 ui::EventPointerType last_pointer_type) {
2659 last_pointer_type_ = last_pointer_type;
2660 }
2661
InvalidateLocalSurfaceIdOnEviction()2662 void RenderWidgetHostViewAura::InvalidateLocalSurfaceIdOnEviction() {
2663 window_->InvalidateLocalSurfaceId();
2664 }
2665
ProcessDisplayMetricsChanged()2666 void RenderWidgetHostViewAura::ProcessDisplayMetricsChanged() {
2667 needs_to_update_display_metrics_ = false;
2668 UpdateScreenInfo(window_);
2669 current_cursor_.SetDisplayInfo(
2670 display::Screen::GetScreen()->GetDisplayNearestWindow(window_));
2671 UpdateCursorIfOverSelf();
2672 }
2673
CancelActiveTouches()2674 void RenderWidgetHostViewAura::CancelActiveTouches() {
2675 aura::Env* env = aura::Env::GetInstance();
2676 env->gesture_recognizer()->CancelActiveTouches(window());
2677 }
2678
2679 blink::mojom::FrameWidgetInputHandler*
GetFrameWidgetInputHandlerForFocusedWidget()2680 RenderWidgetHostViewAura::GetFrameWidgetInputHandlerForFocusedWidget() {
2681 auto* focused_widget = GetFocusedWidget();
2682 if (!focused_widget)
2683 return nullptr;
2684 return focused_widget->GetFrameWidgetInputHandler();
2685 }
2686
2687 } // namespace content
2688