1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
12 #include "base/auto_reset.h"
13 #include "base/command_line.h"
14 #include "base/feature_list.h"
15 #include "base/functional/bind.h"
16 #include "base/functional/callback_helpers.h"
17 #include "base/logging.h"
18 #include "base/memory/raw_ptr.h"
19 #include "base/metrics/histogram_functions.h"
20 #include "base/strings/strcat.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/trace_event/trace_event.h"
24 #include "build/build_config.h"
25 #include "build/chromeos_buildflags.h"
26 #include "cc/layers/layer.h"
27 #include "cc/trees/layer_tree_settings.h"
28 #include "components/viz/common/features.h"
29 #include "components/viz/common/frame_sinks/copy_output_request.h"
30 #include "components/viz/common/frame_sinks/copy_output_result.h"
31 #include "components/viz/common/surfaces/local_surface_id.h"
32 #include "content/browser/accessibility/browser_accessibility_manager.h"
33 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
34 #include "content/browser/bad_message.h"
35 #include "content/browser/gpu/compositor_util.h"
36 #include "content/browser/renderer_host/cursor_manager.h"
37 #include "content/browser/renderer_host/delegated_frame_host_client_aura.h"
38 #include "content/browser/renderer_host/dip_util.h"
39 #include "content/browser/renderer_host/frame_tree.h"
40 #include "content/browser/renderer_host/frame_tree_node.h"
41 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
42 #include "content/browser/renderer_host/input/touch_selection_controller_client_aura.h"
43 #include "content/browser/renderer_host/overscroll_controller.h"
44 #include "content/browser/renderer_host/render_frame_host_impl.h"
45 #include "content/browser/renderer_host/render_view_host_delegate.h"
46 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
47 #include "content/browser/renderer_host/render_view_host_impl.h"
48 #include "content/browser/renderer_host/render_widget_host_delegate.h"
49 #include "content/browser/renderer_host/render_widget_host_impl.h"
50 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
51 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h"
52 #include "content/browser/renderer_host/ui_events_helper.h"
53 #include "content/browser/renderer_host/visible_time_request_trigger.h"
54 #include "content/public/browser/content_browser_client.h"
55 #include "content/public/browser/device_service.h"
56 #include "content/public/browser/render_view_host.h"
57 #include "content/public/common/content_features.h"
58 #include "content/public/common/page_visibility_state.h"
59 #include "services/service_manager/public/cpp/interface_provider.h"
60 #include "third_party/blink/public/common/input/web_input_event.h"
61 #include "third_party/blink/public/mojom/input/input_handler.mojom-forward.h"
62 #include "third_party/blink/public/mojom/widget/record_content_to_visible_time_request.mojom.h"
63 #include "ui/accessibility/aura/aura_window_properties.h"
64 #include "ui/accessibility/platform/ax_platform_node.h"
65 #include "ui/aura/client/aura_constants.h"
66 #include "ui/aura/client/cursor_client.h"
67 #include "ui/aura/client/cursor_client_observer.h"
68 #include "ui/aura/client/focus_client.h"
69 #include "ui/aura/client/screen_position_client.h"
70 #include "ui/aura/client/transient_window_client.h"
71 #include "ui/aura/client/window_parenting_client.h"
72 #include "ui/aura/env.h"
73 #include "ui/aura/window.h"
74 #include "ui/aura/window_event_dispatcher.h"
75 #include "ui/aura/window_observer.h"
76 #include "ui/aura/window_tree_host.h"
77 #include "ui/aura_extra/window_position_in_root_monitor.h"
78 #include "ui/base/clipboard/clipboard.h"
79 #include "ui/base/clipboard/scoped_clipboard_writer.h"
80 #include "ui/base/cursor/cursor.h"
81 #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
82 #include "ui/base/hit_test.h"
83 #include "ui/base/ime/input_method.h"
84 #include "ui/base/ime/mojom/text_input_state.mojom.h"
85 #include "ui/base/owned_window_anchor.h"
86 #include "ui/base/ui_base_features.h"
87 #include "ui/base/ui_base_switches.h"
88 #include "ui/base/ui_base_types.h"
89 #include "ui/display/screen.h"
90 #include "ui/events/blink/blink_event_util.h"
91 #include "ui/events/blink/did_overscroll_params.h"
92 #include "ui/events/blink/web_input_event.h"
93 #include "ui/events/event.h"
94 #include "ui/events/event_observer.h"
95 #include "ui/events/event_utils.h"
96 #include "ui/events/gesture_detection/gesture_configuration.h"
97 #include "ui/events/gestures/gesture_recognizer.h"
98 #include "ui/events/keycodes/dom/dom_code.h"
99 #include "ui/gfx/canvas.h"
100 #include "ui/gfx/color_palette.h"
101 #include "ui/gfx/geometry/dip_util.h"
102 #include "ui/gfx/geometry/rect_conversions.h"
103 #include "ui/gfx/geometry/size_conversions.h"
104 #include "ui/gfx/geometry/skia_conversions.h"
105 #include "ui/touch_selection/touch_selection_controller.h"
106 #include "ui/wm/core/coordinate_conversion.h"
107 #include "ui/wm/public/activation_client.h"
108 #include "ui/wm/public/scoped_tooltip_disabler.h"
109 #include "ui/wm/public/tooltip_client.h"
111 #if BUILDFLAG(IS_WIN)
112 #include "base/time/time.h"
113 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
114 #include "content/browser/accessibility/browser_accessibility_win.h"
115 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
116 #include "ui/accessibility/platform/ax_fragment_root_win.h"
117 #include "ui/base/ime/virtual_keyboard_controller.h"
118 #include "ui/base/ime/virtual_keyboard_controller_observer.h"
119 #include "ui/base/win/hidden_window.h"
120 #include "ui/display/win/screen_win.h"
121 #include "ui/gfx/gdi_util.h"
124 #if BUILDFLAG(IS_LINUX)
125 #include "content/browser/accessibility/browser_accessibility_auralinux.h"
126 #include "ui/base/ime/linux/text_edit_command_auralinux.h"
127 #include "ui/base/ime/text_input_flags.h"
128 #include "ui/linux/linux_ui.h"
131 #if BUILDFLAG(IS_CHROMEOS_ASH)
132 #include "ui/wm/core/ime_util_chromeos.h"
135 #if BUILDFLAG(IS_CHROMEOS_ASH)
136 #include "ui/base/ime/ash/extension_ime_util.h"
137 #include "ui/base/ime/ash/input_method_manager.h"
140 #if BUILDFLAG(IS_CHROMEOS)
141 #include "ui/base/ime/mojom/virtual_keyboard_types.mojom.h"
144 #if BUILDFLAG(IS_EFL)
145 #include "base/base_switches.h"
148 using gfx::RectToSkIRect;
149 using gfx::SkIRectToRect;
151 using blink::WebInputEvent;
152 using blink::WebGestureEvent;
153 using blink::WebTouchEvent;
157 // We need to watch for mouse events outside a Web Popup or its parent
158 // and dismiss the popup for certain events.
159 class RenderWidgetHostViewAura::EventObserverForPopupExit
160 : public ui::EventObserver {
162 explicit EventObserverForPopupExit(RenderWidgetHostViewAura* rwhva)
164 aura::Env* env = aura::Env::GetInstance();
165 env->AddEventObserver(this, env,
166 {ui::ET_MOUSE_PRESSED, ui::ET_TOUCH_PRESSED});
169 EventObserverForPopupExit(const EventObserverForPopupExit&) = delete;
170 EventObserverForPopupExit& operator=(const EventObserverForPopupExit&) =
173 ~EventObserverForPopupExit() override {
174 aura::Env::GetInstance()->RemoveEventObserver(this);
177 // ui::EventObserver:
178 void OnEvent(const ui::Event& event) override {
179 rwhva_->ApplyEventObserverForPopupExit(*event.AsLocatedEvent());
183 raw_ptr<RenderWidgetHostViewAura> rwhva_;
186 void RenderWidgetHostViewAura::ApplyEventObserverForPopupExit(
187 const ui::LocatedEvent& event) {
188 DCHECK(event.type() == ui::ET_MOUSE_PRESSED ||
189 event.type() == ui::ET_TOUCH_PRESSED);
194 // |target| may be null.
195 aura::Window* target = static_cast<aura::Window*>(event.target());
196 if (target != window_ &&
197 (!popup_parent_host_view_ ||
198 target != popup_parent_host_view_->window_)) {
199 // If we enter this code path it means that we did not receive any focus
200 // lost notifications for the popup window. Ensure that blink is aware
201 // of the fact that focus was lost for the host window by sending a Blur
202 // notification. We also set a flag in the view indicating that we need
203 // to force a Focus notification on the next mouse down.
204 if (popup_parent_host_view_ && popup_parent_host_view_->host()) {
205 popup_parent_host_view_->event_handler()
206 ->set_focus_on_mouse_down_or_key_event(true);
207 popup_parent_host_view_->host()->Blur();
209 // Note: popup_parent_host_view_ may be NULL when there are multiple
210 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
215 // We have to implement the WindowObserver interface on a separate object
216 // because clang doesn't like implementing multiple interfaces that have
217 // methods with the same name. This object is owned by the
218 // RenderWidgetHostViewAura.
219 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver {
221 explicit WindowObserver(RenderWidgetHostViewAura* view)
223 view_->window_->AddObserver(this);
226 WindowObserver(const WindowObserver&) = delete;
227 WindowObserver& operator=(const WindowObserver&) = delete;
229 ~WindowObserver() override { view_->window_->RemoveObserver(this); }
231 // Overridden from aura::WindowObserver:
232 void OnWindowAddedToRootWindow(aura::Window* window) override {
233 if (window == view_->window_)
234 view_->AddedToRootWindow();
237 void OnWindowRemovingFromRootWindow(aura::Window* window,
238 aura::Window* new_root) override {
239 if (window == view_->window_)
240 view_->RemovingFromRootWindow();
243 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
244 view_->ParentHierarchyChanged();
247 void OnWindowTitleChanged(aura::Window* window) override {
248 if (window == view_->window_)
249 view_->WindowTitleChanged();
253 raw_ptr<RenderWidgetHostViewAura> view_;
256 ////////////////////////////////////////////////////////////////////////////////
257 // RenderWidgetHostViewAura, public:
259 RenderWidgetHostViewAura::RenderWidgetHostViewAura(
260 RenderWidgetHost* widget_host,
261 WebContents& web_contents)
262 : RenderWidgetHostViewBase(widget_host),
265 in_bounds_changed_(false),
266 popup_parent_host_view_(nullptr),
267 popup_child_host_view_(nullptr),
269 has_composition_text_(false),
270 added_frame_observer_(false),
271 cursor_visibility_state_in_renderer_(UNKNOWN),
272 #if BUILDFLAG(IS_WIN)
273 legacy_render_widget_host_HWND_(nullptr),
274 legacy_window_destroyed_(false),
276 device_scale_factor_(0.0f),
277 event_handler_(new RenderWidgetHostViewEventHandler(host(), this, this)),
278 frame_sink_id_(host()->GetFrameSinkId()),
279 visibility_(host()->is_hidden() ? Visibility::HIDDEN
280 : Visibility::VISIBLE) {
281 // CreateDelegatedFrameHostClient() and CreateAuraWindow() assume that the
282 // FrameSinkId is valid. RenderWidgetHostImpl::GetFrameSinkId() always returns
283 // a valid FrameSinkId.
284 DCHECK(frame_sink_id_.is_valid());
286 CreateDelegatedFrameHostClient();
288 host()->SetView(this);
290 // We should start observing the TextInputManager for IME-related events as
291 // well as monitoring its lifetime.
292 if (GetTextInputManager())
293 GetTextInputManager()->AddObserver(this);
295 cursor_manager_ = std::make_unique<CursorManager>(this);
297 selection_controller_client_ =
298 std::make_unique<TouchSelectionControllerClientAura>(this);
299 CreateSelectionController();
301 RenderWidgetHostOwnerDelegate* owner_delegate = host()->owner_delegate();
302 if (owner_delegate) {
303 // NOTE: This will not be run for child frame widgets, which do not have
304 // an owner delegate and won't get a RenderViewHost here.
305 double_tap_to_zoom_enabled_ =
306 owner_delegate->GetWebkitPreferencesForWidget()
307 .double_tap_to_zoom_enabled;
310 host()->render_frame_metadata_provider()->AddObserver(this);
312 #if BUILDFLAG(IS_EFL)
314 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableOffscreenRendering)
315 ? std::make_unique<RWHVAuraOffscreenHelperEfl>(this, &web_contents)
316 : std::make_unique<RWHVAuraCommonHelperEfl>(this, &web_contents);
320 ////////////////////////////////////////////////////////////////////////////////
321 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
323 void RenderWidgetHostViewAura::InitAsChild(gfx::NativeView parent_view) {
324 DCHECK_EQ(widget_type_, WidgetType::kFrame);
325 CreateAuraWindow(aura::client::WINDOW_TYPE_CONTROL);
328 parent_view->AddChild(GetNativeView());
330 #if BUILDFLAG(IS_EFL)
331 efl_helper_->SetAuraParentWindow(parent_view);
334 device_scale_factor_ = GetDeviceScaleFactor();
336 aura::Window* root = window_->GetRootWindow();
338 auto* cursor_client = aura::client::GetCursorClient(root);
340 UpdateSystemCursorSize(cursor_client->GetSystemCursorSize());
343 #if BUILDFLAG(IS_WIN)
344 // This will fetch and set the display features.
345 EnsureDevicePostureServiceConnection();
349 void RenderWidgetHostViewAura::InitAsPopup(
350 RenderWidgetHostView* parent_host_view,
351 const gfx::Rect& bounds_in_screen,
352 const gfx::Rect& anchor_rect) {
353 DCHECK_EQ(widget_type_, WidgetType::kPopup);
354 DCHECK(!static_cast<RenderWidgetHostViewBase*>(parent_host_view)
355 ->IsRenderWidgetHostViewChildFrame());
357 popup_parent_host_view_ =
358 static_cast<RenderWidgetHostViewAura*>(parent_host_view);
360 // TransientWindowClient may be NULL during tests.
361 aura::client::TransientWindowClient* transient_window_client =
362 aura::client::GetTransientWindowClient();
363 RenderWidgetHostViewAura* old_child =
364 popup_parent_host_view_->popup_child_host_view_;
366 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
367 // similar mechanism to ensure a second popup doesn't cause the first one
368 // to never get a chance to filter events. See crbug.com/160589.
369 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_);
370 if (transient_window_client) {
371 transient_window_client->RemoveTransientChild(
372 popup_parent_host_view_->window_, old_child->window_);
374 old_child->popup_parent_host_view_ = nullptr;
376 popup_parent_host_view_->SetPopupChild(this);
377 CreateAuraWindow(aura::client::WINDOW_TYPE_MENU);
378 // Use transparent background color for the popup in order to avoid flashing
379 // the white background on popup open when dark color-scheme is used.
380 SetContentBackgroundColor(SK_ColorTRANSPARENT);
382 // Setting the transient child allows for the popup to get mouse events when
383 // in a system modal dialog. Do this before calling ParentWindowWithContext
384 // below so that the transient parent is visible to WindowTreeClient.
385 // This fixes crbug.com/328593.
386 if (transient_window_client) {
387 transient_window_client->AddTransientChild(
388 popup_parent_host_view_->window_, window_);
391 ui::OwnedWindowAnchor owned_window_anchor = {
392 anchor_rect, ui::OwnedWindowAnchorPosition::kBottomLeft,
393 ui::OwnedWindowAnchorGravity::kBottomRight,
394 ui::OwnedWindowConstraintAdjustment::kAdjustmentFlipY};
395 window_->SetProperty(aura::client::kOwnedWindowAnchor, owned_window_anchor);
397 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow();
398 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen,
399 display::kInvalidDisplayId);
401 SetBounds(bounds_in_screen);
403 if (NeedsMouseCapture())
404 window_->SetCapture();
406 event_observer_for_popup_exit_ =
407 std::make_unique<EventObserverForPopupExit>(this);
409 device_scale_factor_ = GetDeviceScaleFactor();
411 // If HiDPI capture mode is active for the parent, propagate the scale
412 // override to the popup window also. Its content was created assuming
413 // that the new window will share the parent window's scale. See
414 // https://crbug.com/1354703 .
415 SetScaleOverrideForCapture(
416 popup_parent_host_view_->GetScaleOverrideForCapture());
418 auto* cursor_client = aura::client::GetCursorClient(root);
420 UpdateSystemCursorSize(cursor_client->GetSystemCursorSize());
422 #if BUILDFLAG(IS_WIN)
423 // This will fetch and set the display features.
424 EnsureDevicePostureServiceConnection();
428 void RenderWidgetHostViewAura::Hide() {
430 visibility_ = Visibility::HIDDEN;
434 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) {
435 // For a SetSize operation, we don't care what coordinate system the origin
436 // of the window is in, it's only important to make sure that the origin
437 // remains constant after the operation.
438 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size));
441 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) {
442 gfx::Point relative_origin(rect.origin());
444 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but
445 // Window::SetBounds() takes parent coordinates, so do the conversion here.
446 aura::Window* root = window_->GetRootWindow();
448 aura::client::ScreenPositionClient* screen_position_client =
449 aura::client::GetScreenPositionClient(root);
450 if (screen_position_client) {
451 screen_position_client->ConvertPointFromScreen(window_->parent(),
456 InternalSetBounds(gfx::Rect(relative_origin, rect.size()));
459 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() {
463 #if BUILDFLAG(IS_WIN)
464 HWND RenderWidgetHostViewAura::GetHostWindowHWND() const {
465 aura::WindowTreeHost* host = window_->GetHost();
466 return host ? host->GetAcceleratedWidget() : nullptr;
470 gfx::NativeViewAccessible RenderWidgetHostViewAura::GetNativeViewAccessible() {
471 #if BUILDFLAG(IS_WIN)
472 aura::WindowTreeHost* window_host = window_->GetHost();
474 return static_cast<gfx::NativeViewAccessible>(NULL);
476 BrowserAccessibilityManager* manager =
477 host()->GetOrCreateRootBrowserAccessibilityManager();
479 return ToBrowserAccessibilityWin(manager->GetBrowserAccessibilityRoot())
482 #elif BUILDFLAG(IS_LINUX)
483 BrowserAccessibilityManager* manager =
484 host()->GetOrCreateRootBrowserAccessibilityManager();
485 if (manager && manager->GetBrowserAccessibilityRoot())
486 return manager->GetBrowserAccessibilityRoot()->GetNativeViewAccessible();
489 NOTIMPLEMENTED_LOG_ONCE();
490 return static_cast<gfx::NativeViewAccessible>(nullptr);
493 ui::TextInputClient* RenderWidgetHostViewAura::GetTextInputClient() {
497 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() const {
498 FrameTreeNode* focused_frame = host()->frame_tree()->GetFocusedFrame();
501 return focused_frame->current_frame_host();
504 void RenderWidgetHostViewAura::HandleBoundsInRootChanged() {
505 #if BUILDFLAG(IS_WIN)
506 if (legacy_render_widget_host_HWND_) {
507 legacy_render_widget_host_HWND_->SetBounds(
508 window_->GetBoundsInRootWindow());
512 // Send screen rects through the delegate if there is one. Not every
513 // RenderWidgetHost has a delegate (for example, drop-down widgets).
514 if (host_->delegate())
515 host_->delegate()->SendScreenRects();
517 host_->SendScreenRects();
520 UpdateInsetsWithVirtualKeyboardEnabled();
523 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
524 if (window_->parent()) {
525 // Track changes of the window relative to the root. This is done to snap
526 // `window_` to a pixel boundary, which could change when the bounds
527 // relative to the root changes. An example where this happens:
528 // The fast resize code path for bookmarks where in the parent of RWHVA
529 // which is WCV has its bounds changed before the bookmark is hidden. This
530 // results in the traditional bounds change notification for the WCV
531 // reporting the old bounds as the bookmark is still around. Observing all
532 // the ancestors of the RWHVA window enables us to know when the bounds of
533 // the window relative to root changes and allows us to snap accordingly.
534 position_in_root_observer_ =
535 std::make_unique<aura_extra::WindowPositionInRootMonitor>(
538 &RenderWidgetHostViewAura::HandleBoundsInRootChanged,
539 base::Unretained(this)));
541 position_in_root_observer_.reset();
543 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
544 HandleBoundsInRootChanged();
547 void RenderWidgetHostViewAura::Focus() {
548 // Make sure we have a FocusClient before attempting to Focus(). In some
549 // situations we may not yet be in a valid Window hierarchy (such as reloading
550 // after out of memory discarded the tab).
551 aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
555 #if BUILDFLAG(IS_EFL)
556 efl_helper_->Focus(true);
560 bool RenderWidgetHostViewAura::HasFocus() {
561 return window_->HasFocus();
564 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() {
565 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
566 return delegated_frame_host_->CanCopyFromCompositingSurface();
569 #if BUILDFLAG(IS_EFL)
570 void RenderWidgetHostViewAura::BackgroundColorReceived(int callback_id,
572 efl_helper_->BackgroundColorReceived(callback_id, bg_color);
575 void RenderWidgetHostViewAura::DidGetContentSnapshot(const SkBitmap& bitmap,
577 efl_helper_->DidGetContentSnapshot(bitmap, request_id);
580 void RenderWidgetHostViewAura::DidHandleKeyEvent(
581 blink::WebInputEvent::Type input_event_type,
583 efl_helper_->DidHandleKeyEvent(input_event_type, processed);
586 void RenderWidgetHostViewAura::SelectionChanged(const std::u16string& text,
588 const gfx::Range& range) {
589 RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
590 efl_helper_->SelectionChanged(text, offset, range);
593 void RenderWidgetHostViewAura::TextInputStateChanged(
594 const ui::mojom::TextInputState& params) {
595 RenderWidgetHostViewBase::TextInputStateChanged(params);
596 efl_helper_->TextInputStateChanged(params);
600 void RenderWidgetHostViewAura::EnsureSurfaceSynchronizedForWebTest() {
601 ++latest_capture_sequence_number_;
602 SynchronizeVisualProperties(cc::DeadlinePolicy::UseInfiniteDeadline(),
606 bool RenderWidgetHostViewAura::IsShowing() {
607 return window_->IsVisible();
610 void RenderWidgetHostViewAura::WasUnOccluded() {
611 ShowImpl(PageVisibilityState::kVisible);
614 void RenderWidgetHostViewAura::ShowImpl(PageVisibilityState page_visibility) {
615 // OnShowWithPageVisibility will not call NotifyHostAndDelegateOnWasShown,
616 // which updates `visibility_`, unless the host is hidden. Make sure no update
618 DCHECK(host_->is_hidden() || visibility_ == Visibility::VISIBLE);
619 OnShowWithPageVisibility(page_visibility);
622 void RenderWidgetHostViewAura::NotifyHostAndDelegateOnWasShown(
623 blink::mojom::RecordContentToVisibleTimeRequestPtr tab_switch_start_state) {
624 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
625 DCHECK(host_->is_hidden());
626 DCHECK_NE(visibility_, Visibility::VISIBLE);
628 auto* wth = window()->GetHost();
629 if (wth && allocate_local_surface_id_on_next_show_) {
630 wth->window()->AllocateLocalSurfaceId();
631 wth->compositor()->SetLocalSurfaceIdFromParent(
632 wth->window()->GetLocalSurfaceId());
634 allocate_local_surface_id_on_next_show_ = false;
636 visibility_ = Visibility::VISIBLE;
638 bool has_saved_frame = delegated_frame_host_->HasSavedFrame();
640 bool show_reason_bfcache_restore =
641 tab_switch_start_state
642 ? tab_switch_start_state->show_reason_bfcache_restore
645 // No need to check for saved frames for the case of bfcache restore.
646 if (show_reason_bfcache_restore) {
647 host()->WasShown(tab_switch_start_state.Clone());
649 host()->WasShown(has_saved_frame
650 ? blink::mojom::RecordContentToVisibleTimeRequestPtr()
651 : tab_switch_start_state.Clone());
653 aura::Window* root = window_->GetRootWindow();
655 aura::client::CursorClient* cursor_client =
656 aura::client::GetCursorClient(root);
658 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
662 // If the frame for the renderer is already available, then the
663 // tab-switching time is the presentation time for the browser-compositor.
664 delegated_frame_host_->WasShown(
665 GetLocalSurfaceId(), window_->bounds().size(),
666 has_saved_frame ? std::move(tab_switch_start_state)
667 : blink::mojom::RecordContentToVisibleTimeRequestPtr());
669 #if BUILDFLAG(IS_WIN)
674 void RenderWidgetHostViewAura::HideImpl() {
675 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
676 DCHECK(visibility_ == Visibility::HIDDEN ||
677 visibility_ == Visibility::OCCLUDED);
679 #if BUILDFLAG(IS_EFL)
683 if (!host()->is_hidden()) {
685 aura::WindowTreeHost* host = window_->GetHost();
686 aura::Window* parent = window_->parent();
687 aura::Window::OcclusionState parent_occl_state =
688 parent ? parent->GetOcclusionState()
689 : aura::Window::OcclusionState::UNKNOWN;
690 aura::Window::OcclusionState native_win_occlusion_state =
691 host ? host->GetNativeWindowOcclusionState()
692 : aura::Window::OcclusionState::UNKNOWN;
693 DelegatedFrameHost::HiddenCause cause;
694 if (parent_occl_state == aura::Window::OcclusionState::OCCLUDED &&
695 native_win_occlusion_state ==
696 aura::Window::OcclusionState::OCCLUDED) {
697 cause = DelegatedFrameHost::HiddenCause::kOccluded;
699 cause = DelegatedFrameHost::HiddenCause::kOther;
701 delegated_frame_host_->WasHidden(cause);
702 #if BUILDFLAG(IS_WIN)
704 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the
705 // global hidden window on the same lines as Windowed plugin windows.
706 if (legacy_render_widget_host_HWND_)
707 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
712 #if BUILDFLAG(IS_WIN)
713 if (legacy_render_widget_host_HWND_)
714 legacy_render_widget_host_HWND_->Hide();
718 void RenderWidgetHostViewAura::WasOccluded() {
719 visibility_ = Visibility::OCCLUDED;
723 void RenderWidgetHostViewAura::
724 RequestSuccessfulPresentationTimeFromHostOrDelegate(
725 blink::mojom::RecordContentToVisibleTimeRequestPtr
726 visible_time_request) {
727 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
728 DCHECK(!host_->is_hidden());
729 DCHECK_EQ(visibility_, Visibility::VISIBLE);
730 DCHECK(visible_time_request);
732 bool has_saved_frame = delegated_frame_host_->HasSavedFrame();
734 // No need to check for saved frames for the case of bfcache restore.
735 if (visible_time_request->show_reason_bfcache_restore || !has_saved_frame) {
736 host()->RequestSuccessfulPresentationTimeForNextFrame(
737 visible_time_request.Clone());
740 // If the frame for the renderer is already available, then the
741 // tab-switching time is the presentation time for the browser-compositor.
742 if (has_saved_frame) {
743 delegated_frame_host_->RequestSuccessfulPresentationTimeForNextFrame(
744 std::move(visible_time_request));
748 void RenderWidgetHostViewAura::
749 CancelSuccessfulPresentationTimeRequestForHostAndDelegate() {
750 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
751 DCHECK(!host_->is_hidden());
752 DCHECK_EQ(visibility_, Visibility::VISIBLE);
754 host()->CancelSuccessfulPresentationTimeRequest();
755 delegated_frame_host_->CancelSuccessfulPresentationTimeRequest();
758 bool RenderWidgetHostViewAura::ShouldSkipCursorUpdate() const {
759 aura::Window* root_window = window_->GetRootWindow();
761 display::Screen* screen = display::Screen::GetScreen();
764 // Ignore cursor update messages if the window under the cursor is not us.
765 #if BUILDFLAG(IS_WIN)
766 gfx::Point cursor_screen_point = screen->GetCursorScreenPoint();
767 aura::Window* window_at_screen_point =
768 screen->GetWindowAtScreenPoint(cursor_screen_point);
769 // On Windows we may fail to retrieve the aura Window at the current cursor
770 // position. This is because the WindowFromPoint API may return the legacy
771 // window which is not associated with an aura Window. In this case we need
772 // to get the aura window for the parent of the legacy window.
773 if (!window_at_screen_point && legacy_render_widget_host_HWND_) {
774 HWND hwnd_at_point = ::WindowFromPoint(cursor_screen_point.ToPOINT());
776 if (hwnd_at_point == legacy_render_widget_host_HWND_->hwnd())
777 hwnd_at_point = legacy_render_widget_host_HWND_->GetParent();
779 display::win::ScreenWin* screen_win =
780 static_cast<display::win::ScreenWin*>(screen);
781 window_at_screen_point = screen_win->GetNativeWindowFromHWND(hwnd_at_point);
783 if (!window_at_screen_point ||
784 (window_at_screen_point->GetRootWindow() != root_window)) {
787 #elif !BUILDFLAG(IS_CHROMEOS_ASH)
788 if (!screen->IsWindowUnderCursor(root_window))
790 #endif // !BUILDFLAG(IS_CHROMEOS_ASH)
794 bool RenderWidgetHostViewAura::ShouldShowStaleContentOnEviction() {
795 return host() && host()->ShouldShowStaleContentOnEviction();
798 gfx::Rect RenderWidgetHostViewAura::GetViewBounds() {
799 #if BUILDFLAG(IS_EFL)
800 if (offscreen_helper())
801 return offscreen_helper()->GetViewBounds();
803 return window_->GetBoundsInScreen();
806 void RenderWidgetHostViewAura::UpdateBackgroundColor() {
807 DCHECK(GetBackgroundColor());
809 SkColor color = *GetBackgroundColor();
810 // Set transparent bg for Browser process
811 if (color == SK_ColorTRANSPARENT && GetCompositor()) {
812 GetCompositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
815 bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
816 window_->layer()->SetFillsBoundsOpaquely(opaque);
817 window_->layer()->SetColor(color);
820 #if BUILDFLAG(IS_WIN)
821 void RenderWidgetHostViewAura::EnsureDevicePostureServiceConnection() {
822 if (device_posture_provider_.is_bound() &&
823 device_posture_provider_.is_connected()) {
826 GetDeviceService().BindDevicePostureProvider(
827 device_posture_provider_.BindNewPipeAndPassReceiver());
828 device_posture_provider_->AddListenerAndGetCurrentViewportSegments(
829 device_posture_receiver_.BindNewPipeAndPassRemote(),
830 base::BindOnce(&RenderWidgetHostViewAura::OnViewportSegmentsChanged,
831 base::Unretained(this)));
835 void RenderWidgetHostViewAura::OnViewportSegmentsChanged(
836 const std::vector<gfx::Rect>& segments) {
837 display_feature_ = absl::nullopt;
838 viewport_segments_.clear();
839 if (segments.empty()) {
840 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
841 window_->GetLocalSurfaceId());
845 if (segments.size() >= 2) {
846 viewport_segments_ = std::move(segments);
847 ComputeDisplayFeature();
849 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
850 window_->GetLocalSurfaceId());
853 void RenderWidgetHostViewAura::ComputeDisplayFeature() {
854 if (viewport_segments_.size() < 2) {
858 display_feature_ = absl::nullopt;
859 if (!window_->GetRootWindow()) {
863 const display::Display display =
864 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
865 // Set the display feature only if the browser window is maximized or
867 if (window_->GetRootWindow()->GetBoundsInScreen() != display.work_area() &&
868 window_->GetRootWindow()->GetBoundsInScreen() != display.bounds()) {
872 float dip_scale = 1 / device_scale_factor_;
873 // Segments coming from the platform are in native resolution.
874 gfx::Rect transformed_display_feature =
875 gfx::ScaleToRoundedRect(viewport_segments_[1], dip_scale);
876 transformed_display_feature.Offset(-GetViewBounds().x(),
877 -GetViewBounds().y());
878 transformed_display_feature.Intersect(gfx::Rect(GetVisibleViewportSize()));
879 if (transformed_display_feature.x() == 0) {
880 display_feature_ = {DisplayFeature::Orientation::kHorizontal,
881 transformed_display_feature.y(),
882 transformed_display_feature.height()};
883 } else if (transformed_display_feature.y() == 0) {
884 display_feature_ = {DisplayFeature::Orientation::kVertical,
885 transformed_display_feature.x(),
886 transformed_display_feature.width()};
890 absl::optional<DisplayFeature> RenderWidgetHostViewAura::GetDisplayFeature() {
891 return display_feature_;
894 void RenderWidgetHostViewAura::SetDisplayFeatureForTesting(
895 const DisplayFeature* display_feature) {
897 display_feature_ = *display_feature;
899 display_feature_ = absl::nullopt;
902 void RenderWidgetHostViewAura::WindowTitleChanged() {
903 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
904 delegated_frame_host_->WindowTitleChanged(
905 base::UTF16ToUTF8(window_->GetTitle()));
908 bool RenderWidgetHostViewAura::IsMouseLocked() {
909 return event_handler_->mouse_locked();
912 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() {
913 #if BUILDFLAG(IS_EFL)
914 if (efl_helper_->IsOffscreenMode())
915 return efl_helper_->GetVisibleViewportSize();
917 gfx::Rect requested_rect(GetRequestedRendererSize());
918 requested_rect.Inset(insets_);
919 return requested_rect.size();
922 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
923 TRACE_EVENT0("vk", "RenderWidgetHostViewAura::SetInsets");
924 if (insets != insets_) {
926 window_->AllocateLocalSurfaceId();
927 if (!insets.IsEmpty()) {
928 inset_surface_id_ = window_->GetLocalSurfaceId();
930 inset_surface_id_ = viz::LocalSurfaceId();
932 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
933 window_->GetLocalSurfaceId());
937 void RenderWidgetHostViewAura::UpdateCursor(const ui::Cursor& cursor) {
938 GetCursorManager()->UpdateCursor(this, cursor);
941 void RenderWidgetHostViewAura::DisplayCursor(const ui::Cursor& cursor) {
942 current_cursor_ = WebCursor(cursor);
943 const display::Display display =
944 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
945 current_cursor_.SetDisplayInfo(display);
946 UpdateCursorIfOverSelf();
949 CursorManager* RenderWidgetHostViewAura::GetCursorManager() {
950 return cursor_manager_.get();
953 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
954 is_loading_ = is_loading;
955 UpdateCursorIfOverSelf();
958 void RenderWidgetHostViewAura::RenderProcessGone() {
959 UpdateCursorIfOverSelf();
963 void RenderWidgetHostViewAura::ShowWithVisibility(
964 PageVisibilityState page_visibility) {
965 // Make sure we grab updated ScreenInfos before synchronizing visual
966 // properties, in case they have changed or this is the initial show.
969 #if BUILDFLAG(IS_EFL)
973 // If the viz::LocalSurfaceId is invalid, we may have been evicted,
974 // and no other visual properties have since been changed. Allocate a new id
975 // and start synchronizing.
976 if (!window_->GetLocalSurfaceId().is_valid()) {
977 window_->AllocateLocalSurfaceId();
978 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
979 window_->GetLocalSurfaceId());
983 ShowImpl(page_visibility);
984 #if BUILDFLAG(IS_WIN)
985 if (page_visibility != PageVisibilityState::kVisible &&
986 legacy_render_widget_host_HWND_) {
987 legacy_render_widget_host_HWND_->Hide();
989 #endif // BUILDFLAG(IS_WIN)
992 void RenderWidgetHostViewAura::Destroy() {
993 // Beware, this function is not called on all destruction paths. If |window_|
994 // has been created, then it will implicitly end up calling
995 // ~RenderWidgetHostViewAura when |window_| is destroyed. Otherwise, The
996 // destructor is invoked directly from here. So all destruction/cleanup code
997 // should happen there, not here.
999 // Call this here in case any observers need access to `this` before we
1000 // destruct the derived class.
1001 NotifyObserversAboutShutdown();
1009 void RenderWidgetHostViewAura::UpdateTooltipUnderCursor(
1010 const std::u16string& tooltip_text) {
1011 if (GetCursorManager()->IsViewUnderCursor(this))
1012 UpdateTooltip(tooltip_text);
1015 void RenderWidgetHostViewAura::UpdateTooltip(
1016 const std::u16string& tooltip_text) {
1017 SetTooltipText(tooltip_text);
1019 wm::TooltipClient* tooltip_client =
1020 wm::GetTooltipClient(window_->GetRootWindow());
1021 if (tooltip_client) {
1022 // Content tooltips should be visible indefinitely.
1023 tooltip_client->SetHideTooltipTimeout(window_, {});
1024 tooltip_client->UpdateTooltip(window_);
1028 void RenderWidgetHostViewAura::UpdateTooltipFromKeyboard(
1029 const std::u16string& tooltip_text,
1030 const gfx::Rect& bounds) {
1031 SetTooltipText(tooltip_text);
1033 wm::TooltipClient* tooltip_client =
1034 wm::GetTooltipClient(window_->GetRootWindow());
1035 if (tooltip_client) {
1036 // Content tooltips should be visible indefinitely.
1037 tooltip_client->SetHideTooltipTimeout(window_, {});
1038 tooltip_client->UpdateTooltipFromKeyboard(bounds, window_);
1042 void RenderWidgetHostViewAura::ClearKeyboardTriggeredTooltip() {
1043 if (!window_ || !window_->GetHost())
1046 wm::TooltipClient* tooltip_client =
1047 wm::GetTooltipClient(window_->GetRootWindow());
1048 if (!tooltip_client || !tooltip_client->IsTooltipSetFromKeyboard(window_))
1051 SetTooltipText(std::u16string());
1052 tooltip_client->UpdateTooltipFromKeyboard(gfx::Rect(), window_);
1055 uint32_t RenderWidgetHostViewAura::GetCaptureSequenceNumber() const {
1056 return latest_capture_sequence_number_;
1059 void RenderWidgetHostViewAura::CopyFromSurface(
1060 const gfx::Rect& src_subrect,
1061 const gfx::Size& dst_size,
1062 base::OnceCallback<void(const SkBitmap&)> callback) {
1063 base::WeakPtr<RenderWidgetHostImpl> popup_host;
1064 base::WeakPtr<DelegatedFrameHost> popup_frame_host;
1065 if (popup_child_host_view_) {
1066 popup_host = popup_child_host_view_->host()->GetWeakPtr();
1068 popup_child_host_view_->GetDelegatedFrameHost()->GetWeakPtr();
1070 RenderWidgetHostViewBase::CopyMainAndPopupFromSurface(
1071 host()->GetWeakPtr(), delegated_frame_host_->GetWeakPtr(), popup_host,
1072 popup_frame_host, src_subrect, dst_size, device_scale_factor_,
1073 std::move(callback));
1076 #if BUILDFLAG(IS_WIN)
1077 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
1078 return (legacy_render_widget_host_HWND_ != nullptr);
1081 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
1083 display::Screen::GetScreen()
1084 ->DIPToScreenRectInWindow(window_, window_->GetBoundsInScreen())
1086 ::ClipCursor(&window_rect);
1089 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
1090 legacy_render_widget_host_HWND_ = nullptr;
1091 legacy_window_destroyed_ = true;
1095 gfx::NativeViewAccessible
1096 RenderWidgetHostViewAura::GetParentNativeViewAccessible() {
1097 // If a popup_parent_host_view_ exists, that means we are in a popup (such as
1098 // datetime) and our accessible parent window is popup_parent_host_view_
1099 if (popup_parent_host_view_) {
1100 DCHECK_EQ(widget_type_, WidgetType::kPopup);
1101 return popup_parent_host_view_->GetParentNativeViewAccessible();
1104 if (window_->parent()) {
1105 return window_->parent()->GetProperty(
1106 aura::client::kParentNativeViewAccessibleKey);
1112 void RenderWidgetHostViewAura::ClearFallbackSurfaceForCommitPending() {
1113 delegated_frame_host_->ClearFallbackSurfaceForCommitPending();
1114 window_->InvalidateLocalSurfaceId();
1117 void RenderWidgetHostViewAura::ResetFallbackToFirstNavigationSurface() {
1118 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
1119 delegated_frame_host_->ResetFallbackToFirstNavigationSurface();
1122 bool RenderWidgetHostViewAura::RequestRepaintForTesting() {
1123 return SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
1127 void RenderWidgetHostViewAura::DidStopFlinging() {
1128 selection_controller_client_->OnScrollCompleted();
1131 void RenderWidgetHostViewAura::TransformPointToRootSurface(gfx::PointF* point) {
1132 aura::Window* root = window_->GetRootWindow();
1133 aura::Window::ConvertPointToTarget(window_, root, point);
1134 *point = root->GetRootWindow()->transform().MapPoint(*point);
1137 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() {
1138 aura::Window* top_level = window_->GetToplevelWindow();
1139 gfx::Rect bounds(top_level->GetBoundsInScreen());
1141 #if BUILDFLAG(IS_WIN)
1142 // TODO(zturner,iyengar): This will break when we remove support for NPAPI and
1143 // remove the legacy hwnd, so a better fix will need to be decided when that
1145 if (UsesNativeWindowFrame()) {
1146 // aura::Window doesn't take into account non-client area of native windows
1147 // (e.g. HWNDs), so for that case ask Windows directly what the bounds are.
1148 aura::WindowTreeHost* host = top_level->GetHost();
1150 return top_level->GetBoundsInScreen();
1152 // If this is a headless window return the headless window bounds stored in
1153 // Aura window properties instead of the actual platform window bounds which
1154 // may be different.
1155 if (gfx::Rect* headless_bounds =
1156 host->window()->GetProperty(aura::client::kHeadlessBoundsKey)) {
1157 return *headless_bounds;
1160 RECT window_rect = {0};
1161 HWND hwnd = host->GetAcceleratedWidget();
1162 ::GetWindowRect(hwnd, &window_rect);
1163 bounds = gfx::Rect(window_rect);
1165 // Maximized windows are outdented from the work area by the frame thickness
1166 // even though this "frame" is not painted. This confuses code (and people)
1167 // that think of a maximized window as corresponding exactly to the work
1168 // area. Correct for this by subtracting the frame thickness back off.
1169 if (::IsZoomed(hwnd)) {
1170 bounds.Inset(gfx::Insets::VH(GetSystemMetrics(SM_CYSIZEFRAME),
1171 GetSystemMetrics(SM_CXSIZEFRAME)));
1172 bounds.Inset(GetSystemMetrics(SM_CXPADDEDBORDER));
1175 // Pixels come back from GetWindowHost, so we need to convert those back to
1177 bounds = display::Screen::GetScreen()->ScreenToDIPRectInWindow(top_level,
1186 void RenderWidgetHostViewAura::WheelEventAck(
1187 const blink::WebMouseWheelEvent& event,
1188 blink::mojom::InputEventResultState ack_result) {
1189 if (overscroll_controller_) {
1190 overscroll_controller_->ReceivedEventACK(
1191 event, (blink::mojom::InputEventResultState::kConsumed == ack_result));
1195 void RenderWidgetHostViewAura::DidOverscroll(
1196 const ui::DidOverscrollParams& params) {
1197 if (overscroll_controller_)
1198 overscroll_controller_->OnDidOverscroll(params);
1199 #if BUILDFLAG(IS_EFL)
1200 efl_helper_->DidOverscroll(params);
1204 void RenderWidgetHostViewAura::GestureEventAck(
1205 const blink::WebGestureEvent& event,
1206 blink::mojom::InputEventResultState ack_result,
1207 blink::mojom::ScrollResultDataPtr scroll_result_data) {
1208 const blink::WebInputEvent::Type event_type = event.GetType();
1209 if (event_type == blink::WebGestureEvent::Type::kGestureScrollBegin ||
1210 event_type == blink::WebGestureEvent::Type::kGestureScrollEnd) {
1211 if (host()->delegate()) {
1212 host()->delegate()->SetTopControlsGestureScrollInProgress(
1213 event_type == blink::WebGestureEvent::Type::kGestureScrollBegin);
1217 if (overscroll_controller_) {
1218 overscroll_controller_->ReceivedEventACK(
1219 event, (blink::mojom::InputEventResultState::kConsumed == ack_result));
1220 // Terminate an active fling when the ACK for a GSU generated from the fling
1221 // progress (GSU with inertial state) is consumed and the overscrolling mode
1222 // is not |OVERSCROLL_NONE|. The early fling termination generates a GSE
1223 // which completes the overscroll action. Without this change the overscroll
1224 // action would complete at the end of the active fling progress which
1225 // causes noticeable delay in cases that the fling velocity is large.
1226 // https://crbug.com/797855
1227 if (event_type == blink::WebInputEvent::Type::kGestureScrollUpdate &&
1228 event.data.scroll_update.inertial_phase ==
1229 blink::WebGestureEvent::InertialPhaseState::kMomentum &&
1230 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE) {
1235 // Stop flinging if a GSU event with momentum phase is sent to the renderer
1236 // but not consumed.
1237 StopFlingingIfNecessary(event, ack_result);
1239 event_handler_->GestureEventAck(event, ack_result);
1241 ForwardTouchpadZoomEventIfNecessary(event, ack_result);
1244 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1245 const TouchEventWithLatencyInfo& touch,
1246 blink::mojom::InputEventResultState ack_result) {
1247 aura::WindowTreeHost* window_host = window_->GetHost();
1248 // |host| is NULL during tests.
1252 // The TouchScrollStarted event is generated & consumed downstream from the
1253 // TouchEventQueue. So we don't expect an ACK up here.
1254 DCHECK(touch.event.GetType() !=
1255 blink::WebInputEvent::Type::kTouchScrollStarted);
1257 ui::EventResult result =
1258 (ack_result == blink::mojom::InputEventResultState::kConsumed)
1262 blink::WebTouchPoint::State required_state;
1263 switch (touch.event.GetType()) {
1264 case blink::WebInputEvent::Type::kTouchStart:
1265 required_state = blink::WebTouchPoint::State::kStatePressed;
1267 case blink::WebInputEvent::Type::kTouchEnd:
1268 required_state = blink::WebTouchPoint::State::kStateReleased;
1270 case blink::WebInputEvent::Type::kTouchMove:
1271 required_state = blink::WebTouchPoint::State::kStateMoved;
1273 case blink::WebInputEvent::Type::kTouchCancel:
1274 required_state = blink::WebTouchPoint::State::kStateCancelled;
1277 required_state = blink::WebTouchPoint::State::kStateUndefined;
1282 #if BUILDFLAG(IS_EFL)
1283 if (touch.event.GetType() == blink::WebInputEvent::Type::kTouchStart)
1284 efl_helper_->SetTouchStartConsumed(result == ui::ER_HANDLED);
1286 if (touch.event.GetType() == blink::WebInputEvent::Type::kTouchEnd)
1287 efl_helper_->SetTouchEndConsumed(result == ui::ER_HANDLED);
1290 // Only send acks for one changed touch point.
1291 bool sent_ack = false;
1292 for (size_t i = 0; i < touch.event.touches_length; ++i) {
1293 if (touch.event.touches[i].state == required_state) {
1295 window_host->dispatcher()->ProcessedTouchEvent(
1296 touch.event.unique_touch_event_id, window_, result,
1297 InputEventResultStateIsSetBlocking(ack_result));
1298 if (touch.event.touch_start_or_first_touch_move &&
1299 result == ui::ER_HANDLED && host()->delegate() &&
1300 host()->delegate()->GetInputEventRouter()) {
1303 ->GetInputEventRouter()
1304 ->OnHandledTouchStartOrFirstTouchMove(
1305 touch.event.unique_touch_event_id);
1312 std::unique_ptr<SyntheticGestureTarget>
1313 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1314 return std::unique_ptr<SyntheticGestureTarget>(
1315 new SyntheticGestureTargetAura(host()));
1318 blink::mojom::InputEventResultState RenderWidgetHostViewAura::FilterInputEvent(
1319 const blink::WebInputEvent& input_event) {
1320 bool consumed = false;
1321 if (input_event.GetType() == WebInputEvent::Type::kGestureFlingStart) {
1322 const WebGestureEvent& gesture_event =
1323 static_cast<const WebGestureEvent&>(input_event);
1324 // Zero-velocity touchpad flings are an Aura-specific signal that the
1325 // touchpad scroll has ended, and should not be forwarded to the renderer.
1326 if (gesture_event.SourceDevice() == blink::WebGestureDevice::kTouchpad &&
1327 !gesture_event.data.fling_start.velocity_x &&
1328 !gesture_event.data.fling_start.velocity_y) {
1333 if (overscroll_controller_)
1334 consumed |= overscroll_controller_->WillHandleEvent(input_event);
1336 // Touch events should always propagate to the renderer.
1337 if (WebTouchEvent::IsTouchEventType(input_event.GetType()))
1338 return blink::mojom::InputEventResultState::kNotConsumed;
1341 input_event.GetType() == blink::WebInputEvent::Type::kGestureFlingStart) {
1342 // Here we indicate that there was no consumer for this event, as
1343 // otherwise the fling animation system will try to run an animation
1344 // and will also expect a notification when the fling ends. Since
1345 // CrOS just uses the GestureFlingStart with zero-velocity as a means
1346 // of indicating that touchpad scroll has ended, we don't actually want
1347 // a fling animation. Note: Similar code exists in
1348 // RenderWidgetHostViewChildFrame::FilterInputEvent()
1349 return blink::mojom::InputEventResultState::kNoConsumerExists;
1352 return consumed ? blink::mojom::InputEventResultState::kConsumed
1353 : blink::mojom::InputEventResultState::kNotConsumed;
1356 gfx::AcceleratedWidget
1357 RenderWidgetHostViewAura::AccessibilityGetAcceleratedWidget() {
1358 #if BUILDFLAG(IS_WIN)
1359 if (legacy_render_widget_host_HWND_)
1360 return legacy_render_widget_host_HWND_->hwnd();
1362 return gfx::kNullAcceleratedWidget;
1365 gfx::NativeViewAccessible
1366 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1367 #if BUILDFLAG(IS_WIN)
1368 if (legacy_render_widget_host_HWND_) {
1369 return legacy_render_widget_host_HWND_->window_accessible();
1373 if (window_->parent()) {
1374 return window_->parent()->GetProperty(
1375 aura::client::kParentNativeViewAccessibleKey);
1381 void RenderWidgetHostViewAura::SetMainFrameAXTreeID(ui::AXTreeID id) {
1382 window_->SetProperty(ui::kChildAXTreeID, id.ToString());
1385 blink::mojom::PointerLockResult RenderWidgetHostViewAura::LockMouse(
1386 bool request_unadjusted_movement) {
1387 return event_handler_->LockMouse(request_unadjusted_movement);
1390 blink::mojom::PointerLockResult RenderWidgetHostViewAura::ChangeMouseLock(
1391 bool request_unadjusted_movement) {
1392 return event_handler_->ChangeMouseLock(request_unadjusted_movement);
1395 void RenderWidgetHostViewAura::UnlockMouse() {
1396 event_handler_->UnlockMouse();
1399 bool RenderWidgetHostViewAura::GetIsMouseLockedUnadjustedMovementForTesting() {
1400 return event_handler_->mouse_locked_unadjusted_movement();
1403 bool RenderWidgetHostViewAura::LockKeyboard(
1404 absl::optional<base::flat_set<ui::DomCode>> codes) {
1405 return event_handler_->LockKeyboard(std::move(codes));
1408 void RenderWidgetHostViewAura::UnlockKeyboard() {
1409 event_handler_->UnlockKeyboard();
1412 bool RenderWidgetHostViewAura::IsKeyboardLocked() {
1413 return event_handler_->IsKeyboardLocked();
1416 base::flat_map<std::string, std::string>
1417 RenderWidgetHostViewAura::GetKeyboardLayoutMap() {
1418 aura::WindowTreeHost* host = window_->GetHost();
1420 return host->GetKeyboardLayoutMap();
1424 ////////////////////////////////////////////////////////////////////////////////
1425 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
1426 void RenderWidgetHostViewAura::SetCompositionText(
1427 const ui::CompositionText& composition) {
1428 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1431 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
1432 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
1433 text_input_manager_->GetActiveWidget()->ImeSetComposition(
1434 composition.text, composition.ime_text_spans, gfx::Range::InvalidRange(),
1435 composition.selection.end(), composition.selection.end());
1437 has_composition_text_ = !composition.text.empty();
1440 size_t RenderWidgetHostViewAura::ConfirmCompositionText(bool keep_selection) {
1441 if (text_input_manager_ && text_input_manager_->GetActiveWidget() &&
1442 has_composition_text_) {
1443 text_input_manager_->GetActiveWidget()->ImeFinishComposingText(
1446 has_composition_text_ = false;
1447 // TODO(crbug/1109604): Return the number of characters committed by this
1449 return std::numeric_limits<size_t>::max();
1452 void RenderWidgetHostViewAura::ClearCompositionText() {
1453 if (text_input_manager_ && text_input_manager_->GetActiveWidget() &&
1454 has_composition_text_)
1455 text_input_manager_->GetActiveWidget()->ImeCancelComposition();
1456 has_composition_text_ = false;
1459 void RenderWidgetHostViewAura::InsertText(
1460 const std::u16string& text,
1461 InsertTextCursorBehavior cursor_behavior) {
1462 DCHECK_NE(GetTextInputType(), ui::TEXT_INPUT_TYPE_NONE);
1464 if (text_input_manager_ && text_input_manager_->GetActiveWidget()) {
1465 const int relative_cursor_position =
1466 cursor_behavior == InsertTextCursorBehavior::kMoveCursorBeforeText
1469 text_input_manager_->GetActiveWidget()->ImeCommitText(
1470 text, std::vector<ui::ImeTextSpan>(), gfx::Range::InvalidRange(),
1471 relative_cursor_position);
1473 has_composition_text_ = false;
1476 void RenderWidgetHostViewAura::InsertChar(const ui::KeyEvent& event) {
1477 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1478 popup_child_host_view_->InsertChar(event);
1482 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1483 if (event_handler_->accept_return_character() ||
1484 event.GetCharacter() != ui::VKEY_RETURN) {
1485 // Send a blink::WebInputEvent::Char event to |host_|.
1486 ForwardKeyboardEventWithLatencyInfo(
1487 NativeWebKeyboardEvent(event, event.GetCharacter()), *event.latency(),
1492 bool RenderWidgetHostViewAura::CanInsertImage() {
1493 RenderFrameHostImpl* render_frame_host = GetFocusedFrame();
1495 if (!render_frame_host) {
1499 return render_frame_host->has_focused_richly_editable_element();
1502 void RenderWidgetHostViewAura::InsertImage(const GURL& src) {
1503 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1505 if (!input_handler) {
1509 input_handler->ExecuteEditCommand("PasteFromImageURL",
1510 base::UTF8ToUTF16(src.spec()));
1513 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1514 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1515 return text_input_manager_->GetTextInputState()->type;
1516 return ui::TEXT_INPUT_TYPE_NONE;
1519 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const {
1520 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1521 return text_input_manager_->GetTextInputState()->mode;
1522 return ui::TEXT_INPUT_MODE_DEFAULT;
1525 base::i18n::TextDirection RenderWidgetHostViewAura::GetTextDirection() const {
1526 NOTIMPLEMENTED_LOG_ONCE();
1527 return base::i18n::UNKNOWN_DIRECTION;
1530 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1531 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1532 return text_input_manager_->GetTextInputState()->flags;
1536 bool RenderWidgetHostViewAura::CanComposeInline() const {
1537 if (text_input_manager_ && text_input_manager_->GetTextInputState())
1538 return text_input_manager_->GetTextInputState()->can_compose_inline;
1542 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen(
1543 const gfx::Rect& rect) const {
1544 gfx::Point origin = rect.origin();
1545 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1547 aura::Window* root_window = window_->GetRootWindow();
1550 aura::client::ScreenPositionClient* screen_position_client =
1551 aura::client::GetScreenPositionClient(root_window);
1552 if (!screen_position_client)
1554 screen_position_client->ConvertPointToScreen(window_, &origin);
1555 screen_position_client->ConvertPointToScreen(window_, &end);
1556 return gfx::Rect(origin.x(), origin.y(), base::ClampSub(end.x(), origin.x()),
1557 base::ClampSub(end.y(), origin.y()));
1560 gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen(
1561 const gfx::Rect& rect) const {
1562 gfx::Rect result = rect;
1563 if (window_->GetRootWindow() &&
1564 aura::client::GetScreenPositionClient(window_->GetRootWindow()))
1565 wm::ConvertRectFromScreen(window_, &result);
1569 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const {
1570 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1573 // Check selection bound first (currently populated only for EditContext)
1574 const absl::optional<gfx::Rect> text_selection_bound =
1575 text_input_manager_->GetTextSelectionBounds();
1576 if (text_selection_bound)
1577 return ConvertRectToScreen(text_selection_bound.value());
1579 // If no selection bound, we fall back to use selection region.
1580 const TextInputManager::SelectionRegion* region =
1581 text_input_manager_->GetSelectionRegion();
1582 gfx::Rect caret_rect = ConvertRectToScreen(
1583 gfx::RectBetweenSelectionBounds(region->anchor, region->focus));
1584 TRACE_EVENT1("ime", "RenderWidgetHostViewAura::GetCaretBounds", "caret_rect",
1585 caret_rect.ToString());
1589 gfx::Rect RenderWidgetHostViewAura::GetSelectionBoundingBox() const {
1590 auto* focused_view = GetFocusedViewForTextSelection();
1594 const gfx::Rect bounding_box =
1595 text_input_manager_->GetSelectionRegion(focused_view)->bounding_box;
1596 if (bounding_box.IsEmpty())
1599 return ConvertRectToScreen(bounding_box);
1602 bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
1604 gfx::Rect* rect) const {
1607 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1610 const TextInputManager::CompositionRangeInfo* composition_range_info =
1611 text_input_manager_->GetCompositionRangeInfo();
1613 if (index >= composition_range_info->character_bounds.size())
1615 *rect = ConvertRectToScreen(composition_range_info->character_bounds[index]);
1616 TRACE_EVENT1("ime", "RenderWidgetHostViewAura::GetCompositionCharacterBounds",
1617 "comp_char_rect", rect->ToString());
1621 bool RenderWidgetHostViewAura::HasCompositionText() const {
1622 return has_composition_text_;
1625 ui::TextInputClient::FocusReason RenderWidgetHostViewAura::GetFocusReason()
1627 if (!window_->HasFocus())
1628 return ui::TextInputClient::FOCUS_REASON_NONE;
1630 switch (last_pointer_type_before_focus_) {
1631 case ui::EventPointerType::kMouse:
1632 return ui::TextInputClient::FOCUS_REASON_MOUSE;
1633 case ui::EventPointerType::kPen:
1634 return ui::TextInputClient::FOCUS_REASON_PEN;
1635 case ui::EventPointerType::kTouch:
1636 return ui::TextInputClient::FOCUS_REASON_TOUCH;
1638 return ui::TextInputClient::FOCUS_REASON_OTHER;
1642 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const {
1643 if (!text_input_manager_ || !GetFocusedWidget())
1646 const ui::mojom::TextInputState* state =
1647 text_input_manager_->GetTextInputState();
1651 range->set_start(0);
1652 range->set_end(state->value ? state->value->length() : 0);
1656 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1657 gfx::Range* range) const {
1658 if (!text_input_manager_ || !GetFocusedWidget())
1661 const ui::mojom::TextInputState* state =
1662 text_input_manager_->GetTextInputState();
1663 // Return false when there is no composition.
1664 if (!state || !state->composition)
1667 *range = state->composition.value();
1671 bool RenderWidgetHostViewAura::GetEditableSelectionRange(
1672 gfx::Range* range) const {
1673 if (!text_input_manager_ || !GetFocusedWidget())
1676 const ui::mojom::TextInputState* state =
1677 text_input_manager_->GetTextInputState();
1681 *range = state->selection;
1685 bool RenderWidgetHostViewAura::SetEditableSelectionRange(
1686 const gfx::Range& range) {
1687 // TODO(crbug.com/915630): Write an unit test for this method.
1688 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1691 input_handler->SetEditableSelectionOffsets(range.start(), range.end());
1695 bool RenderWidgetHostViewAura::GetTextFromRange(const gfx::Range& range,
1696 std::u16string* text) const {
1697 if (!text_input_manager_ || !GetFocusedWidget())
1700 const ui::mojom::TextInputState* state =
1701 text_input_manager_->GetTextInputState();
1705 gfx::Range text_range;
1706 GetTextRange(&text_range);
1708 if (!text_range.Contains(range)) {
1712 if (!state->value) {
1716 if (text_range.EqualsIgnoringDirection(range)) {
1717 // Avoid calling substr whose performance is low.
1718 *text = *state->value;
1720 *text = state->value->substr(range.GetMin(), range.length());
1725 void RenderWidgetHostViewAura::OnInputMethodChanged() {
1726 // TODO(suzhe): implement the newly added "locale" property of HTML DOM
1730 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
1731 base::i18n::TextDirection direction) {
1732 if (!GetTextInputManager() && !GetTextInputManager()->GetActiveWidget())
1735 GetTextInputManager()->GetActiveWidget()->UpdateTextDirection(direction);
1736 GetTextInputManager()->GetActiveWidget()->NotifyTextDirection();
1740 void RenderWidgetHostViewAura::ExtendSelectionAndDelete(
1741 size_t before, size_t after) {
1742 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1745 input_handler->ExtendSelectionAndDelete(before, after);
1748 #if BUILDFLAG(IS_CHROMEOS)
1749 void RenderWidgetHostViewAura::ExtendSelectionAndReplace(
1752 const base::StringPiece16 replacement_text) {
1753 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1754 if (!input_handler) {
1757 input_handler->ExtendSelectionAndReplace(before, after,
1758 std::u16string(replacement_text));
1762 void RenderWidgetHostViewAura::EnsureCaretNotInRect(
1763 const gfx::Rect& rect_in_screen) {
1764 keyboard_occluded_bounds_ = rect_in_screen;
1766 // If keyboard is disabled, reset the insets_.
1767 if (keyboard_occluded_bounds_.IsEmpty()) {
1768 SetInsets(gfx::Insets());
1770 UpdateInsetsWithVirtualKeyboardEnabled();
1773 aura::Window* top_level_window = window_->GetToplevelWindow();
1774 #if BUILDFLAG(IS_CHROMEOS_ASH)
1775 wm::EnsureWindowNotInRect(top_level_window, keyboard_occluded_bounds_);
1778 // Perform overscroll if the caret is still hidden by the keyboard.
1779 const gfx::Rect hidden_window_bounds_in_screen = gfx::IntersectRects(
1780 keyboard_occluded_bounds_, top_level_window->GetBoundsInScreen());
1782 if (hidden_window_bounds_in_screen.IsEmpty())
1785 ScrollFocusedEditableNodeIntoView();
1788 bool RenderWidgetHostViewAura::IsTextEditCommandEnabled(
1789 ui::TextEditCommand command) const {
1793 void RenderWidgetHostViewAura::SetTextEditCommandForNextKeyEvent(
1794 ui::TextEditCommand command) {}
1796 ukm::SourceId RenderWidgetHostViewAura::GetClientSourceForMetrics() const {
1797 RenderFrameHostImpl* frame = GetFocusedFrame();
1798 // ukm::SourceId is not available while prerendering.
1799 if (frame && !frame->IsInLifecycleState(
1800 RenderFrameHost::LifecycleState::kPrerendering)) {
1801 return frame->GetPageUkmSourceId();
1803 return ukm::SourceId();
1806 bool RenderWidgetHostViewAura::ShouldDoLearning() {
1807 return GetTextInputManager() && GetTextInputManager()->should_do_learning();
1810 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
1811 bool RenderWidgetHostViewAura::SetCompositionFromExistingText(
1812 const gfx::Range& range,
1813 const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
1814 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1817 input_handler->SetCompositionFromExistingText(range.start(), range.end(),
1819 has_composition_text_ = true;
1825 #if BUILDFLAG(IS_CHROMEOS)
1826 gfx::Range RenderWidgetHostViewAura::GetAutocorrectRange() const {
1827 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1828 return gfx::Range();
1829 return text_input_manager_->GetAutocorrectRange();
1832 gfx::Rect RenderWidgetHostViewAura::GetAutocorrectCharacterBounds() const {
1833 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1836 const std::vector<ui::mojom::ImeTextSpanInfoPtr>& ime_text_spans_info =
1837 text_input_manager_->GetTextInputState()->ime_text_spans_info;
1839 unsigned autocorrect_span_found = 0;
1841 for (const auto& ime_text_span_info : ime_text_spans_info) {
1842 if (ime_text_span_info->span.type == ui::ImeTextSpan::Type::kAutocorrect) {
1843 bounds = ConvertRectToScreen(ime_text_span_info->bounds);
1844 autocorrect_span_found++;
1847 // Assuming there is only one autocorrect span at any point in time.
1848 DCHECK_LE(autocorrect_span_found, 1u);
1852 bool RenderWidgetHostViewAura::SetAutocorrectRange(
1853 const gfx::Range& range) {
1854 if (!range.is_empty()) {
1855 base::UmaHistogramEnumeration(
1856 "InputMethod.Assistive.Autocorrect.Count",
1857 TextInputClient::SubClass::kRenderWidgetHostViewAura);
1859 #if BUILDFLAG(IS_CHROMEOS_ASH)
1860 auto* input_method_manager = ash::input_method::InputMethodManager::Get();
1861 if (input_method_manager &&
1862 ash::extension_ime_util::IsExperimentalMultilingual(
1863 input_method_manager->GetActiveIMEState()
1864 ->GetCurrentInputMethod()
1866 base::UmaHistogramEnumeration(
1867 "InputMethod.MultilingualExperiment.Autocorrect.Count",
1868 TextInputClient::SubClass::kRenderWidgetHostViewAura);
1873 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1877 input_handler->ClearImeTextSpansByType(0,
1878 std::numeric_limits<uint32_t>::max(),
1879 ui::ImeTextSpan::Type::kAutocorrect);
1881 if (range.is_empty())
1884 ui::ImeTextSpan ui_ime_text_span;
1885 ui_ime_text_span.type = ui::ImeTextSpan::Type::kAutocorrect;
1886 ui_ime_text_span.start_offset = 0;
1887 ui_ime_text_span.end_offset = range.length();
1888 ui_ime_text_span.underline_style = ui::ImeTextSpan::UnderlineStyle::kDot;
1889 ui_ime_text_span.underline_color =
1890 SkColorSetA(gfx::kGoogleGrey700, SK_AlphaOPAQUE * 0.7);
1891 ui_ime_text_span.thickness = ui::ImeTextSpan::Thickness::kThick;
1893 input_handler->AddImeTextSpansToExistingText(range.start(), range.end(),
1894 {ui_ime_text_span});
1898 absl::optional<ui::GrammarFragment>
1899 RenderWidgetHostViewAura::GetGrammarFragmentAtCursor() const {
1900 if (!text_input_manager_ || !text_input_manager_->GetActiveWidget())
1901 return absl::nullopt;
1902 gfx::Range selection_range;
1903 if (GetEditableSelectionRange(&selection_range)) {
1904 return text_input_manager_->GetGrammarFragment(selection_range);
1906 return absl::nullopt;
1910 bool RenderWidgetHostViewAura::ClearGrammarFragments(const gfx::Range& range) {
1911 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1915 input_handler->ClearImeTextSpansByType(
1916 range.start(), range.end(), ui::ImeTextSpan::Type::kGrammarSuggestion);
1920 bool RenderWidgetHostViewAura::AddGrammarFragments(
1921 const std::vector<ui::GrammarFragment>& fragments) {
1922 if (!fragments.empty()) {
1923 base::UmaHistogramEnumeration(
1924 "InputMethod.Assistive.Grammar.Count",
1925 TextInputClient::SubClass::kRenderWidgetHostViewAura);
1928 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
1929 if (!input_handler || fragments.empty())
1932 unsigned max_fragment_end = 0;
1933 std::vector<::ui::ImeTextSpan> ime_text_spans;
1934 ime_text_spans.reserve(fragments.size());
1935 for (auto& fragment : fragments) {
1936 ui::ImeTextSpan ui_ime_text_span;
1937 ui_ime_text_span.type = ui::ImeTextSpan::Type::kGrammarSuggestion;
1938 ui_ime_text_span.start_offset = fragment.range.start();
1939 ui_ime_text_span.end_offset = fragment.range.end();
1940 ui_ime_text_span.thickness = ui::ImeTextSpan::Thickness::kThick;
1941 ui_ime_text_span.underline_style = ui::ImeTextSpan::UnderlineStyle::kDot;
1942 ui_ime_text_span.underline_color = gfx::kGoogleBlue400;
1943 ui_ime_text_span.suggestions = {fragment.suggestion};
1945 ime_text_spans.push_back(ui_ime_text_span);
1946 if (fragment.range.end() > max_fragment_end) {
1947 max_fragment_end = fragment.range.end();
1950 input_handler->AddImeTextSpansToExistingText(0, max_fragment_end,
1958 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
1959 void RenderWidgetHostViewAura::GetActiveTextInputControlLayoutBounds(
1960 absl::optional<gfx::Rect>* control_bounds,
1961 absl::optional<gfx::Rect>* selection_bounds) {
1962 if (text_input_manager_) {
1963 const absl::optional<gfx::Rect> text_control_bounds =
1964 text_input_manager_->GetTextControlBounds();
1965 if (text_control_bounds) {
1966 *control_bounds = ConvertRectToScreen(text_control_bounds.value());
1969 "RenderWidgetHostViewAura::GetActiveTextInputControlLayoutBounds",
1970 "control_bounds_rect", control_bounds->value().ToString());
1972 // Selection bounds are currently populated only for EditContext.
1973 // For editable elements we use GetCompositionCharacterBounds.
1974 const absl::optional<gfx::Rect> text_selection_bounds =
1975 text_input_manager_->GetTextSelectionBounds();
1976 if (text_selection_bounds) {
1977 *selection_bounds = ConvertRectToScreen(text_selection_bounds.value());
1983 #if BUILDFLAG(IS_WIN)
1984 void RenderWidgetHostViewAura::SetActiveCompositionForAccessibility(
1985 const gfx::Range& range,
1986 const std::u16string& active_composition_text,
1987 bool is_composition_committed) {
1988 BrowserAccessibilityManager* manager =
1989 host()->GetRootBrowserAccessibilityManager();
1991 ui::AXPlatformNodeWin* focus_node = static_cast<ui::AXPlatformNodeWin*>(
1992 ui::AXPlatformNode::FromNativeViewAccessible(
1993 manager->GetFocus()->GetNativeViewAccessible()));
1995 // Notify accessibility object about this composition
1996 focus_node->OnActiveComposition(range, active_composition_text,
1997 is_composition_committed);
2003 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH)
2004 ui::TextInputClient::EditingContext
2005 RenderWidgetHostViewAura::GetTextEditingContext() {
2006 ui::TextInputClient::EditingContext editing_context;
2007 // We use the focused frame's URL here and not the main frame because
2008 // TSF(Windows Text Service Framework) works on the active editable element
2009 // context and it uses this information to assist the UIA(Microsoft UI
2010 // Automation) service to determine the character that is being typed by the
2011 // user via IME composition, the URL of the site that the user is typing on
2012 // and other text related services that are used by the UIA clients to power
2013 // accessibility features on Windows. We want to expose the focused frame's
2014 // URL to TSF that notifies the UIA service which uses this info and the
2015 // focused element's data to provide better screen reading capabilities.
2016 RenderFrameHostImpl* frame = GetFocusedFrame();
2018 editing_context.page_url = frame->GetLastCommittedURL();
2019 return editing_context;
2023 #if BUILDFLAG(IS_WIN)
2024 void RenderWidgetHostViewAura::NotifyOnFrameFocusChanged() {
2025 if (GetInputMethod()) {
2026 GetInputMethod()->OnUrlChanged();
2031 ////////////////////////////////////////////////////////////////////////////////
2032 // RenderWidgetHostViewAura, display::DisplayObserver implementation:
2034 void RenderWidgetHostViewAura::OnDisplayMetricsChanged(
2035 const display::Display& display,
2037 display::Screen* screen = display::Screen::GetScreen();
2038 if (display.id() != screen->GetDisplayNearestWindow(window_).id())
2041 if (window_->GetHost() && window_->GetHost()->device_scale_factor() !=
2042 display.device_scale_factor()) {
2043 // The DisplayMetrics changed, but the Compositor hasn't been updated yet.
2044 // Delay updating until the Compositor is updated as well, otherwise we
2045 // are likely to hit surface invariants (LocalSurfaceId generated with a
2046 // size/scale-factor that differs from scale-factor used by Compositor).
2047 needs_to_update_display_metrics_ = true;
2050 ProcessDisplayMetricsChanged();
2053 ////////////////////////////////////////////////////////////////////////////////
2054 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
2056 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
2060 gfx::Size RenderWidgetHostViewAura::GetMaximumSize() const {
2064 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
2065 const gfx::Rect& new_bounds) {
2066 base::AutoReset<bool> in_bounds_changed(&in_bounds_changed_, true);
2067 // We care about this whenever RenderWidgetHostViewAura is not owned by a
2068 // WebContentsViewAura since changes to the Window's bounds need to be
2069 // messaged to the renderer. WebContentsViewAura invokes SetSize() or
2070 // SetBounds() itself. No matter how we got here, any redundant calls are
2072 SetSize(new_bounds.size());
2074 if (GetInputMethod()) {
2075 GetInputMethod()->OnCaretBoundsChanged(this);
2076 UpdateInsetsWithVirtualKeyboardEnabled();
2080 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
2081 if (IsMouseLocked())
2082 return ui::mojom::CursorType::kNone;
2083 return current_cursor_.GetNativeCursor();
2086 int RenderWidgetHostViewAura::GetNonClientComponent(
2087 const gfx::Point& point) const {
2091 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
2092 aura::Window* child,
2093 const gfx::Point& location) {
2097 bool RenderWidgetHostViewAura::CanFocus() {
2098 return widget_type_ == WidgetType::kFrame;
2101 void RenderWidgetHostViewAura::OnCaptureLost() {
2102 host()->LostCapture();
2105 void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext& context) {
2109 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
2110 float old_device_scale_factor,
2111 float new_device_scale_factor) {
2112 if (!window_->GetRootWindow())
2115 // TODO(crbug.com/1446142): Add unittest for lacros.
2116 if (needs_to_update_display_metrics_ ||
2117 old_device_scale_factor != new_device_scale_factor) {
2118 ProcessDisplayMetricsChanged();
2121 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
2122 window_->GetLocalSurfaceId());
2124 device_scale_factor_ = new_device_scale_factor;
2125 const display::Display display =
2126 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
2127 // Sometimes GetDisplayNearestWindow returns the default monitor. We don't
2128 // want to use that here.
2129 if (display.is_valid()) {
2130 DCHECK_EQ(new_device_scale_factor, display.device_scale_factor());
2131 current_cursor_.SetDisplayInfo(display);
2135 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) {
2136 #if BUILDFLAG(IS_WIN)
2137 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is
2138 // destroyed. Normally we control when that happens via the Destroy call
2139 // in the dtor. However there may be cases where the window is destroyed
2140 // by Windows, i.e. the parent window is destroyed before the
2141 // RenderWidgetHostViewAura instance goes away etc. To avoid that we
2142 // destroy the LegacyRenderWidgetHostHWND instance here.
2143 if (legacy_render_widget_host_HWND_) {
2144 // The Destroy call below will delete the LegacyRenderWidgetHostHWND
2146 legacy_render_widget_host_HWND_.ExtractAsDangling()->Destroy();
2150 // Make sure that the input method no longer references to this object before
2151 // this object is removed from the root window (i.e. this object loses access
2152 // to the input method).
2153 DetachFromInputMethod(true);
2155 if (overscroll_controller_)
2156 overscroll_controller_->Reset();
2159 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) {
2160 // This is not called on all destruction paths (e.g. if this view was never
2161 // inialized properly to create the window). So the destruction/cleanup code
2162 // that do not depend on |window_| should happen in the destructor, not here.
2166 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
2169 bool RenderWidgetHostViewAura::HasHitTestMask() const {
2173 void RenderWidgetHostViewAura::GetHitTestMask(SkPath* mask) const {}
2175 bool RenderWidgetHostViewAura::RequiresDoubleTapGestureEvents() const {
2176 RenderWidgetHostOwnerDelegate* owner_delegate = host()->owner_delegate();
2177 // TODO(crbug.com/916715): Child local roots do not work here?
2178 if (!owner_delegate)
2180 return double_tap_to_zoom_enabled_;
2183 ////////////////////////////////////////////////////////////////////////////////
2184 // RenderWidgetHostViewAura, ui::EventHandler implementation:
2186 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
2187 last_pointer_type_ = ui::EventPointerType::kUnknown;
2188 event_handler_->OnKeyEvent(event);
2191 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
2192 #if BUILDFLAG(IS_WIN)
2193 if (event->type() == ui::ET_MOUSE_MOVED) {
2194 if (event->location() == last_mouse_move_location_ &&
2195 event->movement().IsZero()) {
2196 event->SetHandled();
2199 last_mouse_move_location_ = event->location();
2202 #if BUILDFLAG(IS_EFL)
2204 efl_helper_->OnMouseOrTouchEvent(event);
2206 last_pointer_type_ = ui::EventPointerType::kMouse;
2207 event_handler_->OnMouseEvent(event);
2210 bool RenderWidgetHostViewAura::HasFallbackSurface() const {
2211 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2212 return delegated_frame_host_->HasFallbackSurface();
2215 bool RenderWidgetHostViewAura::TransformPointToCoordSpaceForView(
2216 const gfx::PointF& point,
2217 RenderWidgetHostViewBase* target_view,
2218 gfx::PointF* transformed_point) {
2219 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2221 if (target_view == this) {
2222 *transformed_point = point;
2226 // In TransformPointToLocalCoordSpace() there is a Point-to-Pixel conversion,
2227 // but it is not necessary here because the final target view is responsible
2228 // for converting before computing the final transform.
2229 return target_view->TransformPointToLocalCoordSpace(
2230 point, GetCurrentSurfaceId(), transformed_point);
2233 viz::FrameSinkId RenderWidgetHostViewAura::GetRootFrameSinkId() {
2234 if (!GetCompositor())
2235 return viz::FrameSinkId();
2237 return GetCompositor()->frame_sink_id();
2240 viz::SurfaceId RenderWidgetHostViewAura::GetCurrentSurfaceId() const {
2241 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2242 return delegated_frame_host_->GetCurrentSurfaceId();
2245 void RenderWidgetHostViewAura::FocusedNodeChanged(
2247 const gfx::Rect& node_bounds_in_screen
2248 #if BUILDFLAG(IS_TIZEN_TV)
2250 bool is_radio_or_checkbox,
2251 int password_input_minlength,
2254 #if BUILDFLAG(IS_EFL)
2256 bool is_content_editable
2259 // The last gesture most likely caused the focus change. The focus reason will
2260 // be incorrect if the focus was triggered without a user gesture.
2261 // TODO(https://crbug.com/824604): Get the focus reason from the renderer
2262 // process instead to get the true focus reason.
2263 last_pointer_type_before_focus_ = last_pointer_type_;
2265 auto* input_method = GetInputMethod();
2267 input_method->CancelComposition(this);
2268 has_composition_text_ = false;
2270 #if defined(USE_EFL)
2271 efl_helper_->FocusedNodeChanged(
2273 #if BUILDFLAG(IS_TIZEN_TV)
2275 is_radio_or_checkbox, password_input_minlength, input_maxlength
2278 is_content_editable);
2281 #if BUILDFLAG(IS_WIN)
2282 if (window_ && virtual_keyboard_controller_win_) {
2283 virtual_keyboard_controller_win_->FocusedNodeChanged(editable);
2288 #if defined(TIZEN_VIDEO_HOLE)
2289 void RenderWidgetHostViewAura::DidMoveWebView() {
2290 if (!on_webview_moved_callback_.is_null())
2291 on_webview_moved_callback_.Run();
2294 void RenderWidgetHostViewAura::SetWebViewMovedCallback(
2295 const base::RepeatingClosure on_webview_moved) {
2296 on_webview_moved_callback_ = std::move(on_webview_moved);
2300 #if BUILDFLAG(IS_TIZEN_TV)
2301 void RenderWidgetHostViewAura::DidEdgeScrollBy(const gfx::Point& offset,
2303 efl_helper_->DidEdgeScrollBy(offset, handled);
2307 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
2308 event_handler_->OnScrollEvent(event);
2311 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
2312 #if BUILDFLAG(IS_EFL)
2314 efl_helper_->OnMouseOrTouchEvent(event);
2316 last_pointer_type_ = event->pointer_details().pointer_type;
2317 ui::InputMethod* input_method = GetInputMethod();
2318 if (window_ && window_->HasFocus() && input_method) {
2319 input_method->OnTouch(event->pointer_details().pointer_type);
2321 event_handler_->OnTouchEvent(event);
2324 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
2325 last_pointer_type_ = event->details().primary_pointer_type();
2326 #if BUILDFLAG(IS_EFL)
2327 // Gesture event will be processed and forwarded via efl helper.
2328 efl_helper_->OnGestureEvent(event);
2331 event_handler_->OnGestureEvent(event);
2334 base::StringPiece RenderWidgetHostViewAura::GetLogContext() const {
2335 return "RenderWidgetHostViewAura";
2338 ////////////////////////////////////////////////////////////////////////////////
2339 // RenderWidgetHostViewAura, wm::ActivationDelegate implementation:
2341 bool RenderWidgetHostViewAura::ShouldActivate() const {
2342 aura::WindowTreeHost* host = window_->GetHost();
2345 const ui::Event* event = host->dispatcher()->current_event();
2349 ////////////////////////////////////////////////////////////////////////////////
2350 // RenderWidgetHostViewAura, aura::client::CursorClientObserver implementation:
2352 void RenderWidgetHostViewAura::OnCursorVisibilityChanged(bool is_visible) {
2353 NotifyRendererOfCursorVisibilityState(is_visible);
2356 void RenderWidgetHostViewAura::OnSystemCursorSizeChanged(
2357 const gfx::Size& system_cursor_size) {
2358 UpdateSystemCursorSize(system_cursor_size);
2361 ////////////////////////////////////////////////////////////////////////////////
2362 // RenderWidgetHostViewAura, aura::client::FocusChangeObserver implementation:
2364 void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
2365 aura::Window* lost_focus) {
2366 LOG(INFO) << "OnWindowFocused, Gained : " << gained_focus
2367 << ", Lost : " << lost_focus;
2368 if (window_ == gained_focus) {
2369 #if !BUILDFLAG(IS_TIZEN_TV)
2370 // We need to honor input bypass if the associated tab does not want input.
2371 // This gives the current focused window a chance to be the text input
2372 // client and handle events.
2373 if (host()->IsIgnoringInputEvents())
2378 UpdateActiveState(true);
2380 ui::InputMethod* input_method = GetInputMethod();
2382 // Ask the system-wide IME to send all TextInputClient messages to |this|
2384 input_method->SetFocusedTextInputClient(this);
2387 BrowserAccessibilityManager* manager =
2388 host()->GetRootBrowserAccessibilityManager();
2390 manager->OnWindowFocused();
2394 if (window_ != lost_focus) {
2399 UpdateActiveState(false);
2400 host()->LostFocus();
2402 DetachFromInputMethod(false);
2404 // TODO(wjmaclean): Do we need to let TouchSelectionControllerClientAura
2405 // handle this, just in case it stomps on a new highlight in another view
2406 // that has just become focused? So far it doesn't appear to be a problem,
2407 // but we should keep an eye on it.
2408 selection_controller_->HideAndDisallowShowingAutomatically();
2410 if (overscroll_controller_)
2411 overscroll_controller_->Cancel();
2413 BrowserAccessibilityManager* manager =
2414 host()->GetRootBrowserAccessibilityManager();
2416 manager->OnWindowBlurred();
2418 // Close the child popup window if we lose focus (e.g. due to a JS alert or
2419 // system modal dialog). This is particularly important if
2420 // |popup_child_host_view_| has mouse capture.
2421 if (popup_child_host_view_)
2422 popup_child_host_view_->Shutdown();
2425 ////////////////////////////////////////////////////////////////////////////////
2426 // RenderWidgetHostViewAura, aura::WindowTreeHostObserver implementation:
2428 void RenderWidgetHostViewAura::OnHostMovedInPixels(aura::WindowTreeHost* host) {
2429 TRACE_EVENT0("ui", "RenderWidgetHostViewAura::OnHostMovedInPixels");
2434 ////////////////////////////////////////////////////////////////////////////////
2435 // RenderWidgetHostViewAura, RenderFrameMetadataProvider::Observer
2437 void RenderWidgetHostViewAura::OnRenderFrameMetadataChangedAfterActivation(
2438 base::TimeTicks activation_time) {
2439 const cc::RenderFrameMetadata& metadata =
2440 host()->render_frame_metadata_provider()->LastRenderFrameMetadata();
2442 // TODO(crbug/1308932): Remove toSkColor and make all SkColor4f.
2443 SetContentBackgroundColor(metadata.root_background_color.toSkColor());
2444 if (inset_surface_id_.is_valid() && metadata.local_surface_id &&
2445 metadata.local_surface_id.value().is_valid() &&
2446 metadata.local_surface_id.value().IsSameOrNewerThan(inset_surface_id_)) {
2447 inset_surface_id_ = viz::LocalSurfaceId();
2448 ScrollFocusedEditableNodeIntoView();
2451 if (metadata.selection.start != selection_start_ ||
2452 metadata.selection.end != selection_end_) {
2453 selection_start_ = metadata.selection.start;
2454 selection_end_ = metadata.selection.end;
2455 selection_controller_client_->UpdateClientSelectionBounds(selection_start_,
2460 #if BUILDFLAG(IS_EFL)
2461 RWHVAuraOffscreenHelperEfl* RenderWidgetHostViewAura::offscreen_helper() {
2462 if (!efl_helper_->IsOffscreenMode()) {
2463 DLOG(INFO) << "Onscreen rendering mode is set";
2467 return static_cast<RWHVAuraOffscreenHelperEfl*>(efl_helper_.get());
2470 void RenderWidgetHostViewAura::DidChangeInputType(bool is_password_field) {
2471 efl_helper_->DidChangeInputType(is_password_field);
2474 void RenderWidgetHostViewAura::OnGetFocusedNodeBounds(const gfx::RectF& rect) {
2475 efl_helper_->OnGetFocusedNodeBounds(rect);
2478 void RenderWidgetHostViewAura::OnGetMainFrameScrollbarVisible(int callback_id,
2480 efl_helper_->OnGetMainFrameScrollbarVisible(callback_id, visible);
2484 ////////////////////////////////////////////////////////////////////////////////
2485 // RenderWidgetHostViewAura, private:
2487 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2488 host()->render_frame_metadata_provider()->RemoveObserver(this);
2490 // Ask the RWH to drop reference to us.
2491 host()->ViewDestroyed();
2493 // Dismiss any visible touch selection handles or touch selection menu.
2494 selection_controller_->HideAndDisallowShowingAutomatically();
2495 selection_controller_.reset();
2496 selection_controller_client_.reset();
2498 GetCursorManager()->ViewBeingDestroyed(this);
2500 delegated_frame_host_.reset();
2501 window_observer_.reset();
2503 if (window_->GetHost())
2504 window_->GetHost()->RemoveObserver(this);
2506 wm::SetTooltipText(window_, nullptr);
2508 // This call is usually no-op since |this| object is already removed from
2509 // the Aura root window and we don't have a way to get an input method
2510 // object associated with the window, but just in case.
2511 DetachFromInputMethod(true);
2513 if (popup_parent_host_view_) {
2514 DCHECK(!popup_parent_host_view_->popup_child_host_view_ ||
2515 popup_parent_host_view_->popup_child_host_view_ == this);
2516 popup_parent_host_view_->SetPopupChild(nullptr);
2518 if (popup_child_host_view_) {
2519 DCHECK(!popup_child_host_view_->popup_parent_host_view_ ||
2520 popup_child_host_view_->popup_parent_host_view_ == this);
2521 popup_child_host_view_->popup_parent_host_view_ = nullptr;
2523 event_observer_for_popup_exit_.reset();
2525 #if BUILDFLAG(IS_WIN)
2526 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2527 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2529 DCHECK(!legacy_render_widget_host_HWND_);
2532 if (text_input_manager_)
2533 text_input_manager_->RemoveObserver(this);
2536 void RenderWidgetHostViewAura::CreateAuraWindow(aura::client::WindowType type) {
2538 window_ = new aura::Window(this);
2539 window_->SetName("RenderWidgetHostViewAura");
2540 event_handler_->set_window(window_);
2541 window_observer_ = std::make_unique<WindowObserver>(this);
2543 wm::SetTooltipText(window_, &tooltip_);
2544 wm::SetActivationDelegate(window_, this);
2545 aura::client::SetFocusChangeObserver(window_, this);
2546 display_observer_.emplace(this);
2548 window_->SetType(type);
2549 window_->Init(ui::LAYER_SOLID_COLOR);
2550 window_->layer()->SetColor(GetBackgroundColor() ? *GetBackgroundColor()
2552 // This needs to happen only after |window_| has been initialized using
2553 // Init(), because it needs to have the layer.
2554 window_->SetEmbedFrameSinkId(frame_sink_id_);
2557 void RenderWidgetHostViewAura::CreateDelegatedFrameHostClient() {
2558 delegated_frame_host_client_ =
2559 std::make_unique<DelegatedFrameHostClientAura>(this);
2560 delegated_frame_host_ = std::make_unique<DelegatedFrameHost>(
2561 frame_sink_id_, delegated_frame_host_client_.get(),
2562 false /* should_register_frame_sink_id */);
2565 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
2566 if (host()->GetProcess()->FastShutdownStarted())
2569 aura::Window* root_window = window_->GetRootWindow();
2573 if (ShouldSkipCursorUpdate())
2576 display::Screen* screen = display::Screen::GetScreen();
2578 gfx::Point root_window_point = screen->GetCursorScreenPoint();
2579 aura::client::ScreenPositionClient* screen_position_client =
2580 aura::client::GetScreenPositionClient(root_window);
2581 if (screen_position_client) {
2582 screen_position_client->ConvertPointFromScreen(
2583 root_window, &root_window_point);
2586 if (root_window->GetEventHandlerForPoint(root_window_point) != window_)
2589 gfx::NativeCursor cursor = current_cursor_.GetNativeCursor();
2590 // Do not show loading cursor when the cursor is currently hidden.
2591 if (is_loading_ && cursor != ui::mojom::CursorType::kNone)
2592 cursor = ui::Cursor(ui::mojom::CursorType::kPointer);
2594 aura::client::CursorClient* cursor_client =
2595 aura::client::GetCursorClient(root_window);
2596 if (cursor_client) {
2597 cursor_client->SetCursor(cursor);
2601 bool RenderWidgetHostViewAura::SynchronizeVisualProperties(
2602 const cc::DeadlinePolicy& deadline_policy,
2603 const absl::optional<viz::LocalSurfaceId>& child_local_surface_id) {
2605 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2607 window_->UpdateLocalSurfaceIdFromEmbeddedClient(child_local_surface_id);
2608 // If the viz::LocalSurfaceId is invalid, we may have been evicted,
2609 // allocate a new one to establish bounds.
2610 if (!GetLocalSurfaceId().is_valid())
2611 window_->AllocateLocalSurfaceId();
2613 delegated_frame_host_->EmbedSurface(
2614 GetLocalSurfaceId(), window_->bounds().size(), deadline_policy);
2616 return host()->SynchronizeVisualProperties();
2619 void RenderWidgetHostViewAura::OnDidUpdateVisualPropertiesComplete(
2620 const cc::RenderFrameMetadata& metadata) {
2623 if (host()->delegate()) {
2624 host()->delegate()->SetTopControlsShownRatio(
2625 host(), metadata.top_controls_shown_ratio);
2628 if (host()->is_hidden()) {
2629 // When an embedded child responds, we want to accept its changes to the
2630 // viz::LocalSurfaceId. However we do not want to embed surfaces while
2631 // hidden. Nor do we want to embed invalid ids when we are evicted. Becoming
2632 // visible will generate a new id, if necessary, and begin embedding.
2633 window_->UpdateLocalSurfaceIdFromEmbeddedClient(metadata.local_surface_id);
2635 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
2636 metadata.local_surface_id);
2640 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const {
2643 aura::Window* root_window = window_->GetRootWindow();
2646 return root_window->GetHost()->GetInputMethod();
2649 RenderWidgetHostViewBase*
2650 RenderWidgetHostViewAura::GetFocusedViewForTextSelection() const {
2651 // We obtain the TextSelection from focused RWH which is obtained from the
2653 return GetFocusedWidget() ? GetFocusedWidget()->GetView() : nullptr;
2656 void RenderWidgetHostViewAura::Shutdown() {
2657 if (!in_shutdown_) {
2658 in_shutdown_ = true;
2659 host()->ShutdownAndDestroyWidget(true);
2663 ui::mojom::VirtualKeyboardMode
2664 RenderWidgetHostViewAura::GetVirtualKeyboardMode() {
2665 // overlaycontent flag can only be set from main frame.
2666 RenderFrameHostImpl* frame = host()->frame_tree()->GetMainFrame();
2668 return ui::mojom::VirtualKeyboardMode::kUnset;
2670 return frame->GetPage().virtual_keyboard_mode();
2673 void RenderWidgetHostViewAura::NotifyVirtualKeyboardOverlayRect(
2674 const gfx::Rect& keyboard_rect) {
2675 // geometrychange event can only be fired on main frame and not focused frame
2676 // which could be an iframe.
2677 RenderFrameHostImpl* frame = host()->frame_tree()->GetMainFrame();
2681 if (GetVirtualKeyboardMode() !=
2682 ui::mojom::VirtualKeyboardMode::kOverlaysContent) {
2685 gfx::Rect keyboard_root_relative_rect = keyboard_rect;
2686 if (!keyboard_root_relative_rect.IsEmpty()) {
2687 // If the rect is non-empty, we need to transform it to be widget-relative
2688 // window (DIP coordinates). The input is client coordinates for the root
2690 // Transform the widget rect origin to root relative coords.
2691 gfx::PointF root_widget_origin(0.f, 0.f);
2692 TransformPointToRootSurface(&root_widget_origin);
2693 gfx::Rect root_widget_rect =
2694 gfx::Rect(root_widget_origin.x(), root_widget_origin.y(),
2695 GetViewBounds().width(), GetViewBounds().height());
2696 // Intersect the keyboard rect with the root widget bounds and transform
2697 // back to widget-relative coordinates, which will be sent to the renderer.
2698 keyboard_root_relative_rect.Intersect(root_widget_rect);
2699 keyboard_root_relative_rect.Offset(-root_widget_origin.x(),
2700 -root_widget_origin.y());
2702 frame->GetPage().NotifyVirtualKeyboardOverlayRect(
2703 keyboard_root_relative_rect);
2706 bool RenderWidgetHostViewAura::IsHTMLFormPopup() const {
2707 return !!popup_parent_host_view_;
2710 bool RenderWidgetHostViewAura::FocusedFrameHasStickyActivation() const {
2711 // Unless user has interacted with the iframe, we shouldn't be displaying VK
2712 // or fire geometrychange event.
2713 RenderFrameHostImpl* frame = GetFocusedFrame();
2717 return frame->frame_tree_node()->HasStickyUserActivation();
2720 TouchSelectionControllerClientManager*
2721 RenderWidgetHostViewAura::GetTouchSelectionControllerClientManager() {
2722 return selection_controller_client_.get();
2725 bool RenderWidgetHostViewAura::NeedsInputGrab() {
2726 return widget_type_ == WidgetType::kPopup;
2729 bool RenderWidgetHostViewAura::NeedsMouseCapture() {
2730 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
2731 return NeedsInputGrab();
2737 void RenderWidgetHostViewAura::SetTooltipsEnabled(bool enable) {
2739 tooltip_disabler_.reset();
2742 std::make_unique<wm::ScopedTooltipDisabler>(window_->GetRootWindow());
2746 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2748 if (host()->is_hidden() ||
2749 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2750 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2753 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
2754 host()->OnCursorVisibilityStateChanged(is_visible);
2757 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
2759 overscroll_controller_.reset();
2760 else if (!overscroll_controller_)
2761 overscroll_controller_ = std::make_unique<OverscrollController>();
2764 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest(
2765 std::unique_ptr<TouchSelectionControllerClientAura> client) {
2766 selection_controller_client_.swap(client);
2767 CreateSelectionController();
2770 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
2771 // Don't recursively call SetBounds if this bounds update is the result of
2772 // a Window::SetBoundsInternal call.
2773 if (!in_bounds_changed_)
2774 window_->SetBounds(rect);
2776 if (!viewport_segments_.empty()) {
2777 // The view bounds have changed so if we have viewport segments from the
2778 // platform we need to make sure display_feature_ is updated considering the
2780 ComputeDisplayFeature();
2783 // Even if not showing yet, we need to synchronize on size. As the renderer
2784 // needs to begin layout. Waiting until we show to start layout leads to
2785 // significant delays in embedding the first shown surface (500+ ms.)
2786 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
2787 window_->GetLocalSurfaceId());
2789 #if BUILDFLAG(IS_WIN)
2792 if (IsMouseLocked())
2793 UpdateMouseLockRegion();
2797 void RenderWidgetHostViewAura::UpdateInsetsWithVirtualKeyboardEnabled() {
2798 // Update insets if the keyboard is shown.
2799 if (!keyboard_occluded_bounds_.IsEmpty()) {
2800 SetInsets(gfx::Insets::TLBR(
2802 gfx::IntersectRects(GetViewBounds(), keyboard_occluded_bounds_)
2808 #if BUILDFLAG(IS_WIN)
2809 void RenderWidgetHostViewAura::UpdateLegacyWin() {
2810 if (legacy_window_destroyed_ || !GetHostWindowHWND())
2813 if (!legacy_render_widget_host_HWND_) {
2814 legacy_render_widget_host_HWND_ =
2815 LegacyRenderWidgetHostHWND::Create(GetHostWindowHWND(), this);
2818 if (legacy_render_widget_host_HWND_) {
2819 legacy_render_widget_host_HWND_->UpdateParent(GetHostWindowHWND());
2820 legacy_render_widget_host_HWND_->SetBounds(
2821 window_->GetBoundsInRootWindow());
2822 // There are cases where the parent window is created, made visible and
2823 // the associated RenderWidget is also visible before the
2824 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
2826 if (!host()->is_hidden())
2827 legacy_render_widget_host_HWND_->Show();
2832 void RenderWidgetHostViewAura::AddedToRootWindow() {
2833 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2835 #if BUILDFLAG(IS_EFL)
2836 efl_helper_->AuraChildWindowAdded();
2839 window_->GetHost()->AddObserver(this);
2842 aura::client::CursorClient* cursor_client =
2843 aura::client::GetCursorClient(window_->GetRootWindow());
2844 if (cursor_client) {
2845 cursor_client->AddObserver(this);
2846 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
2849 ui::InputMethod* input_method = GetInputMethod();
2851 input_method->SetFocusedTextInputClient(this);
2854 #if BUILDFLAG(IS_WIN)
2858 delegated_frame_host_->AttachToCompositor(GetCompositor());
2861 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2862 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2864 aura::client::CursorClient* cursor_client =
2865 aura::client::GetCursorClient(window_->GetRootWindow());
2867 cursor_client->RemoveObserver(this);
2869 DetachFromInputMethod(true);
2871 window_->GetHost()->RemoveObserver(this);
2872 delegated_frame_host_->DetachFromCompositor();
2874 #if BUILDFLAG(IS_WIN)
2875 // Update the legacy window's parent temporarily to the hidden window. It
2876 // will eventually get reparented to the right root.
2877 if (legacy_render_widget_host_HWND_)
2878 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
2882 void RenderWidgetHostViewAura::DetachFromInputMethod(bool is_removed) {
2883 ui::InputMethod* input_method = GetInputMethod();
2885 input_method->DetachTextInputClient(this);
2886 #if BUILDFLAG(IS_CHROMEOS_ASH)
2887 wm::RestoreWindowBoundsOnClientFocusLost(window_->GetToplevelWindow());
2888 #endif // BUILDFLAG(IS_CHROMEOS_ASH)
2891 #if BUILDFLAG(IS_WIN)
2892 // If window is getting destroyed, then reset the VK controller, else,
2893 // dismiss the VK and notify about the keyboard inset since window has lost
2895 if (virtual_keyboard_controller_win_) {
2897 virtual_keyboard_controller_win_.reset();
2899 virtual_keyboard_controller_win_->HideAndNotifyKeyboardInset();
2901 #endif // BUILDFLAG(IS_WIN)
2904 void RenderWidgetHostViewAura::ForwardKeyboardEventWithLatencyInfo(
2905 const NativeWebKeyboardEvent& event,
2906 const ui::LatencyInfo& latency,
2907 bool* update_event) {
2908 RenderWidgetHostImpl* target_host = host();
2910 // If there are multiple widgets on the page (such as when there are
2911 // out-of-process iframes), pick the one that should process this event.
2912 if (host()->delegate())
2913 target_host = host()->delegate()->GetFocusedRenderWidgetHost(host());
2917 #if BUILDFLAG(IS_LINUX)
2918 auto* linux_ui = ui::LinuxUi::instance();
2919 std::vector<ui::TextEditCommandAuraLinux> commands;
2920 if (!event.skip_if_unhandled && linux_ui && event.os_event &&
2921 linux_ui->GetTextEditCommandsForEvent(
2923 base::FeatureList::IsEnabled(
2924 blink::features::kArrowKeysInVerticalWritingModes)
2925 ? GetTextInputFlags()
2926 : ui::TEXT_INPUT_FLAG_NONE,
2928 // Transform from ui/ types to content/ types.
2929 std::vector<blink::mojom::EditCommandPtr> edit_commands;
2930 for (std::vector<ui::TextEditCommandAuraLinux>::const_iterator it =
2931 commands.begin(); it != commands.end(); ++it) {
2932 edit_commands.push_back(blink::mojom::EditCommand::New(
2933 it->GetCommandString(), it->argument()));
2936 target_host->ForwardKeyboardEventWithCommands(
2937 event, latency, std::move(edit_commands), update_event);
2942 target_host->ForwardKeyboardEventWithCommands(
2943 event, latency, std::vector<blink::mojom::EditCommandPtr>(),
2947 void RenderWidgetHostViewAura::CreateSelectionController() {
2948 ui::TouchSelectionController::Config tsc_config;
2949 tsc_config.max_tap_duration = base::Milliseconds(
2950 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms());
2951 tsc_config.tap_slop = ui::GestureConfiguration::GetInstance()
2952 ->max_touch_move_in_pixels_for_click();
2953 tsc_config.enable_longpress_drag_selection =
2954 features::IsTouchTextEditingRedesignEnabled();
2955 selection_controller_ = std::make_unique<ui::TouchSelectionController>(
2956 selection_controller_client_.get(), tsc_config);
2959 void RenderWidgetHostViewAura::DidNavigateMainFramePreCommit() {
2960 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2962 // Invalidate the surface so that we don't attempt to evict it multiple times.
2963 window_->InvalidateLocalSurfaceId();
2964 delegated_frame_host_->DidNavigateMainFramePreCommit();
2965 CancelActiveTouches();
2968 void RenderWidgetHostViewAura::DidEnterBackForwardCache() {
2969 CHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
2971 window_->AllocateLocalSurfaceId();
2972 delegated_frame_host_->DidEnterBackForwardCache();
2973 // If we have the fallback content timer running, force it to stop. Else, when
2974 // the page is restored the timer could also fire, setting whatever
2975 // `DelegatedFrameHost::first_local_surface_id_after_navigation_` as the
2976 // fallback to our Surfacelayer.
2978 // This is safe for BFCache restore because we will supply specific fallback
2979 // surfaces for BFCache.
2981 // We do not want to call this in `RWHImpl::WasHidden()` because in the case
2982 // of `Visibility::OCCLUDED` we still want to keep the timer running.
2984 // Called after to prevent prematurely evict the BFCached surface.
2985 host()->ForceFirstFrameAfterNavigationTimeout();
2988 const viz::FrameSinkId& RenderWidgetHostViewAura::GetFrameSinkId() const {
2989 return frame_sink_id_;
2992 const viz::LocalSurfaceId& RenderWidgetHostViewAura::GetLocalSurfaceId() const {
2993 return window_->GetLocalSurfaceId();
2996 void RenderWidgetHostViewAura::OnUpdateTextInputStateCalled(
2997 TextInputManager* text_input_manager,
2998 RenderWidgetHostViewBase* updated_view,
2999 bool did_update_state) {
3000 DCHECK_EQ(text_input_manager_, text_input_manager);
3002 if (!GetInputMethod())
3005 if (did_update_state)
3006 GetInputMethod()->OnTextInputTypeChanged(this);
3008 const ui::mojom::TextInputState* state =
3009 text_input_manager_->GetTextInputState();
3011 #if BUILDFLAG(IS_CHROMEOS)
3012 if (state && state->type != ui::TEXT_INPUT_TYPE_NONE) {
3013 if (state->last_vk_visibility_request ==
3014 ui::mojom::VirtualKeyboardVisibilityRequest::SHOW) {
3015 GetInputMethod()->SetVirtualKeyboardVisibilityIfEnabled(true);
3016 } else if (state->last_vk_visibility_request ==
3017 ui::mojom::VirtualKeyboardVisibilityRequest::HIDE) {
3018 GetInputMethod()->SetVirtualKeyboardVisibilityIfEnabled(false);
3023 // Show the virtual keyboard if needed.
3024 if (state && state->type != ui::TEXT_INPUT_TYPE_NONE &&
3025 state->mode != ui::TEXT_INPUT_MODE_NONE) {
3026 #if !BUILDFLAG(IS_WIN)
3027 if (state->show_ime_if_needed &&
3028 GetInputMethod()->GetTextInputClient() == this) {
3029 GetInputMethod()->SetVirtualKeyboardVisibilityIfEnabled(true);
3031 // TODO(crbug.com/1031786): Remove this once TSF fix for input pane policy
3033 #elif BUILDFLAG(IS_WIN)
3034 if (GetInputMethod()) {
3035 if (!virtual_keyboard_controller_win_) {
3036 virtual_keyboard_controller_win_ =
3037 std::make_unique<VirtualKeyboardControllerWin>(this,
3040 virtual_keyboard_controller_win_->UpdateTextInputState(state);
3045 // Ensure that selection bounds changes are sent to the IME.
3046 if (state && state->type != ui::TEXT_INPUT_TYPE_NONE) {
3047 text_input_manager->NotifySelectionBoundsChanged(updated_view);
3050 if (auto* render_widget_host = updated_view->host()) {
3051 // Monitor the composition information if there is a focused editable node.
3052 render_widget_host->RequestCompositionUpdates(
3053 false /* immediate_request */,
3055 (state->type != ui::TEXT_INPUT_TYPE_NONE) /* monitor_updates */);
3059 void RenderWidgetHostViewAura::OnImeCancelComposition(
3060 TextInputManager* text_input_manager,
3061 RenderWidgetHostViewBase* view) {
3062 // |view| is not necessarily the one corresponding to
3063 // TextInputManager::GetActiveWidget() as RenderWidgetHostViewAura can call
3064 // this method to finish any ongoing composition in response to a mouse down
3066 if (GetInputMethod())
3067 GetInputMethod()->CancelComposition(this);
3068 has_composition_text_ = false;
3071 void RenderWidgetHostViewAura::OnSelectionBoundsChanged(
3072 TextInputManager* text_input_manager,
3073 RenderWidgetHostViewBase* updated_view) {
3074 // Note: accessibility caret move events are no longer fired directly here,
3075 // because they were redundant with the events fired by the top level window
3076 // by HWNDMessageHandler::OnCaretBoundsChanged().
3077 if (GetInputMethod())
3078 GetInputMethod()->OnCaretBoundsChanged(this);
3081 void RenderWidgetHostViewAura::OnTextSelectionChanged(
3082 TextInputManager* text_input_manager,
3083 RenderWidgetHostViewBase* updated_view) {
3084 if (!GetTextInputManager())
3087 // We obtain the TextSelection from focused RWH which is obtained from the
3089 RenderWidgetHostViewBase* focused_view =
3090 GetFocusedWidget() ? GetFocusedWidget()->GetView() : nullptr;
3095 // IMF relies on the |OnCaretBoundsChanged| for the surrounding text changed
3096 // events to IME. Explicitly call |OnCaretBoundsChanged| here so that IMF can
3097 // know about the surrounding text changes when the caret bounds are not
3098 // changed. e.g. When the rendered text is wider than the input field,
3099 // deleting the last character won't change the caret bounds but will change
3100 // the surrounding text.
3101 if (GetInputMethod())
3102 GetInputMethod()->OnCaretBoundsChanged(this);
3104 if (ui::Clipboard::IsSupportedClipboardBuffer(
3105 ui::ClipboardBuffer::kSelection)) {
3106 const TextInputManager::TextSelection* selection =
3107 GetTextInputManager()->GetTextSelection(focused_view);
3108 if (selection->selected_text().length()) {
3109 // Set the ClipboardBuffer::kSelection to the ui::Clipboard.
3110 ui::ScopedClipboardWriter clipboard_writer(
3111 ui::ClipboardBuffer::kSelection);
3112 clipboard_writer.WriteText(selection->selected_text());
3117 void RenderWidgetHostViewAura::SetPopupChild(
3118 RenderWidgetHostViewAura* popup_child_host_view) {
3119 popup_child_host_view_ = popup_child_host_view;
3120 event_handler_->SetPopupChild(
3121 popup_child_host_view,
3122 popup_child_host_view ? popup_child_host_view->event_handler() : nullptr);
3125 void RenderWidgetHostViewAura::ScrollFocusedEditableNodeIntoView() {
3126 auto* input_handler = GetFrameWidgetInputHandlerForFocusedWidget();
3129 input_handler->ScrollFocusedEditableNodeIntoView();
3132 void RenderWidgetHostViewAura::OnSynchronizedDisplayPropertiesChanged(
3134 SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
3138 viz::ScopedSurfaceIdAllocator
3139 RenderWidgetHostViewAura::DidUpdateVisualProperties(
3140 const cc::RenderFrameMetadata& metadata) {
3141 base::OnceCallback<void()> allocation_task = base::BindOnce(
3142 &RenderWidgetHostViewAura::OnDidUpdateVisualPropertiesComplete,
3143 weak_ptr_factory_.GetWeakPtr(), metadata);
3144 return window_->GetSurfaceIdAllocator(std::move(allocation_task));
3147 void RenderWidgetHostViewAura::DidNavigate() {
3148 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
3151 // Navigating while hidden should not allocate a new LocalSurfaceID. Once
3152 // sizes are ready, or we begin to Show, we can then allocate the new
3154 window_->InvalidateLocalSurfaceId();
3156 if (is_first_navigation_) {
3157 // The first navigation does not need a new LocalSurfaceID. The renderer
3158 // can use the ID that was already provided.
3159 SynchronizeVisualProperties(cc::DeadlinePolicy::UseExistingDeadline(),
3160 window_->GetLocalSurfaceId());
3162 SynchronizeVisualProperties(cc::DeadlinePolicy::UseExistingDeadline(),
3166 delegated_frame_host_->DidNavigate();
3167 is_first_navigation_ = false;
3170 MouseWheelPhaseHandler* RenderWidgetHostViewAura::GetMouseWheelPhaseHandler() {
3171 return &event_handler_->mouse_wheel_phase_handler();
3174 void RenderWidgetHostViewAura::TakeFallbackContentFrom(
3175 RenderWidgetHostView* view) {
3176 DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)
3177 ->IsRenderWidgetHostViewChildFrame());
3178 RenderWidgetHostViewAura* view_aura =
3179 static_cast<RenderWidgetHostViewAura*>(view);
3180 CopyBackgroundColorIfPresentFrom(*view);
3182 DCHECK(delegated_frame_host_) << "Cannot be invoked during destruction.";
3183 DCHECK(view_aura->delegated_frame_host_);
3184 delegated_frame_host_->TakeFallbackContentFrom(
3185 view_aura->delegated_frame_host_.get());
3188 bool RenderWidgetHostViewAura::CanSynchronizeVisualProperties() {
3189 return !needs_to_update_display_metrics_;
3192 std::vector<std::unique_ptr<ui::TouchEvent>>
3193 RenderWidgetHostViewAura::ExtractAndCancelActiveTouches() {
3194 aura::Env* env = aura::Env::GetInstance();
3195 std::vector<std::unique_ptr<ui::TouchEvent>> touches =
3196 env->gesture_recognizer()->ExtractTouches(window());
3197 CancelActiveTouches();
3201 void RenderWidgetHostViewAura::TransferTouches(
3202 const std::vector<std::unique_ptr<ui::TouchEvent>>& touches) {
3203 aura::Env* env = aura::Env::GetInstance();
3204 env->gesture_recognizer()->TransferTouches(window(), touches);
3207 void RenderWidgetHostViewAura::SetLastPointerType(
3208 ui::EventPointerType last_pointer_type) {
3209 last_pointer_type_ = last_pointer_type;
3212 void RenderWidgetHostViewAura::InvalidateLocalSurfaceIdAndAllocationGroup() {
3213 window_->InvalidateLocalSurfaceId(/*also_invalidate_allocation_group=*/true);
3216 void RenderWidgetHostViewAura::InvalidateLocalSurfaceIdOnEviction() {
3217 window_->InvalidateLocalSurfaceId();
3220 void RenderWidgetHostViewAura::ProcessDisplayMetricsChanged() {
3221 // TODO(crbug.com/1169291): Unify per-platform DisplayObserver instances.
3222 needs_to_update_display_metrics_ = false;
3224 current_cursor_.SetDisplayInfo(
3225 display::Screen::GetScreen()->GetDisplayNearestWindow(window_));
3226 UpdateCursorIfOverSelf();
3229 void RenderWidgetHostViewAura::CancelActiveTouches() {
3230 aura::Env* env = aura::Env::GetInstance();
3231 env->gesture_recognizer()->CancelActiveTouches(window());
3234 blink::mojom::FrameWidgetInputHandler*
3235 RenderWidgetHostViewAura::GetFrameWidgetInputHandlerForFocusedWidget() {
3236 auto* focused_widget = GetFocusedWidget();
3237 if (!focused_widget)
3239 return focused_widget->GetFrameWidgetInputHandler();
3242 void RenderWidgetHostViewAura::SetTooltipText(
3243 const std::u16string& tooltip_text) {
3244 tooltip_ = tooltip_text;
3245 if (tooltip_observer_for_testing_)
3246 tooltip_observer_for_testing_->OnTooltipTextUpdated(tooltip_text);
3249 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() {
3250 if (!window_ || !window_->GetHost())
3253 return window_->GetHost()->compositor();
3256 } // namespace content