[M120 Migration] Implement rotation for Aura
[platform/framework/web/chromium-efl.git] / content / browser / renderer_host / render_widget_host_view_aura.h
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.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <memory>
13 #include <set>
14 #include <string>
15 #include <vector>
16
17 #include "base/functional/callback.h"
18 #include "base/gtest_prod_util.h"
19 #include "base/memory/raw_ptr.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/strings/string_piece.h"
22 #include "base/time/time.h"
23 #include "build/build_config.h"
24 #include "build/chromeos_buildflags.h"
25 #include "cc/layers/deadline_policy.h"
26 #include "components/viz/common/frame_sinks/begin_frame_args.h"
27 #include "components/viz/common/frame_sinks/begin_frame_source.h"
28 #include "content/browser/accessibility/browser_accessibility_manager.h"
29 #include "content/browser/compositor/image_transport_factory.h"
30 #include "content/browser/renderer_host/render_widget_host_view_base.h"
31 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h"
32 #include "content/browser/renderer_host/text_input_manager.h"
33 #include "content/common/content_export.h"
34 #include "content/common/cursors/webcursor.h"
35 #include "content/public/browser/context_menu_params.h"
36 #include "content/public/browser/visibility.h"
37 #include "services/device/public/mojom/device_posture_provider.mojom.h"
38 #include "third_party/blink/public/mojom/input/input_handler.mojom-forward.h"
39 #include "third_party/blink/public/mojom/widget/record_content_to_visible_time_request.mojom-forward.h"
40 #include "third_party/skia/include/core/SkRegion.h"
41 #include "ui/aura/client/cursor_client_observer.h"
42 #include "ui/aura/client/focus_change_observer.h"
43 #include "ui/aura/client/window_types.h"
44 #include "ui/aura/window_delegate.h"
45 #include "ui/aura/window_tree_host_observer.h"
46 #include "ui/base/ime/text_input_client.h"
47 #include "ui/display/display_observer.h"
48 #include "ui/gfx/geometry/insets.h"
49 #include "ui/gfx/geometry/rect.h"
50 #include "ui/gfx/selection_bound.h"
51 #include "ui/wm/public/activation_delegate.h"
52
53 #if BUILDFLAG(IS_WIN)
54 #include "content/browser/renderer_host/virtual_keyboard_controller_win.h"
55 #include "mojo/public/cpp/bindings/receiver.h"
56 #include "mojo/public/cpp/bindings/remote.h"
57 #endif
58
59 #if BUILDFLAG(IS_EFL)
60 #include "content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.h"
61 #endif
62
63 namespace aura_extra {
64 class WindowPositionInRootMonitor;
65 }
66
67 namespace wm {
68 class ScopedTooltipDisabler;
69 }
70
71 namespace gfx {
72 class Display;
73 class Point;
74 class Rect;
75 }
76
77 namespace ui {
78 enum class DomCode : uint32_t;
79 class InputMethod;
80 class LocatedEvent;
81 }
82
83 namespace content {
84 #if BUILDFLAG(IS_WIN)
85 class LegacyRenderWidgetHostHWND;
86 class DirectManipulationBrowserTestBase;
87 #endif
88
89 class CursorManager;
90 class DelegatedFrameHost;
91 class DelegatedFrameHostClient;
92 class MouseWheelPhaseHandler;
93 class RenderFrameHostImpl;
94 class RenderWidgetHostView;
95 class TouchSelectionControllerClientAura;
96
97 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
98 class CONTENT_EXPORT RenderWidgetHostViewAura
99     : public RenderWidgetHostViewBase,
100       public RenderWidgetHostViewEventHandler::Delegate,
101       public RenderFrameMetadataProvider::Observer,
102       public TextInputManager::Observer,
103       public ui::TextInputClient,
104       public display::DisplayObserver,
105       public aura::WindowTreeHostObserver,
106       public aura::WindowDelegate,
107       public wm::ActivationDelegate,
108       public aura::client::FocusChangeObserver,
109       public aura::client::CursorClientObserver,
110       public device::mojom::DeviceViewportSegmentsClient {
111  public:
112   explicit RenderWidgetHostViewAura(RenderWidgetHost* host,
113                                     WebContents& web_contents);
114   RenderWidgetHostViewAura(const RenderWidgetHostViewAura&) = delete;
115   RenderWidgetHostViewAura& operator=(const RenderWidgetHostViewAura&) = delete;
116
117   // RenderWidgetHostView implementation.
118   void InitAsChild(gfx::NativeView parent_view) override;
119   void SetSize(const gfx::Size& size) override;
120   void SetBounds(const gfx::Rect& rect) override;
121   gfx::NativeView GetNativeView() override;
122   gfx::NativeViewAccessible GetNativeViewAccessible() override;
123   ui::TextInputClient* GetTextInputClient() override;
124   bool HasFocus() override;
125   void Hide() override;
126   bool IsShowing() override;
127   void WasUnOccluded() override;
128   void WasOccluded() override;
129   gfx::Rect GetViewBounds() override;
130   bool IsMouseLocked() override;
131   gfx::Size GetVisibleViewportSize() override;
132   void SetInsets(const gfx::Insets& insets) override;
133   TouchSelectionControllerClientManager*
134   GetTouchSelectionControllerClientManager() override;
135   ui::mojom::VirtualKeyboardMode GetVirtualKeyboardMode() override;
136   void NotifyVirtualKeyboardOverlayRect(
137       const gfx::Rect& keyboard_rect) override;
138   bool IsHTMLFormPopup() const override;
139
140   // Overridden from RenderWidgetHostViewBase:
141   void InitAsPopup(RenderWidgetHostView* parent_host_view,
142                    const gfx::Rect& pos,
143                    const gfx::Rect& anchor_rect) override;
144   void Focus() override;
145   void UpdateCursor(const ui::Cursor& cursor) override;
146   void DisplayCursor(const ui::Cursor& cursor) override;
147   CursorManager* GetCursorManager() override;
148   void SetIsLoading(bool is_loading) override;
149   void RenderProcessGone() override;
150   void ShowWithVisibility(PageVisibilityState page_visibility) final;
151   void Destroy() override;
152   void UpdateTooltipUnderCursor(const std::u16string& tooltip_text) override;
153   void UpdateTooltip(const std::u16string& tooltip_text) override;
154   void UpdateTooltipFromKeyboard(const std::u16string& tooltip_text,
155                                  const gfx::Rect& bounds) override;
156   void ClearKeyboardTriggeredTooltip() override;
157   uint32_t GetCaptureSequenceNumber() const override;
158   bool IsSurfaceAvailableForCopy() override;
159   void CopyFromSurface(
160       const gfx::Rect& src_rect,
161       const gfx::Size& output_size,
162       base::OnceCallback<void(const SkBitmap&)> callback) override;
163   void EnsureSurfaceSynchronizedForWebTest() override;
164   void TransformPointToRootSurface(gfx::PointF* point) override;
165   gfx::Rect GetBoundsInRootWindow() override;
166   void WheelEventAck(const blink::WebMouseWheelEvent& event,
167                      blink::mojom::InputEventResultState ack_result) override;
168   void GestureEventAck(
169       const blink::WebGestureEvent& event,
170       blink::mojom::InputEventResultState ack_result,
171       blink::mojom::ScrollResultDataPtr scroll_result_data) override;
172   void DidOverscroll(const ui::DidOverscrollParams& params) override;
173   void ProcessAckedTouchEvent(
174       const TouchEventWithLatencyInfo& touch,
175       blink::mojom::InputEventResultState ack_result) override;
176   std::unique_ptr<SyntheticGestureTarget> CreateSyntheticGestureTarget()
177       override;
178   blink::mojom::InputEventResultState FilterInputEvent(
179       const blink::WebInputEvent& input_event) override;
180   gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget() override;
181   gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible() override;
182   void SetMainFrameAXTreeID(ui::AXTreeID id) override;
183   blink::mojom::PointerLockResult LockMouse(
184       bool request_unadjusted_movement) override;
185   blink::mojom::PointerLockResult ChangeMouseLock(
186       bool request_unadjusted_movement) override;
187   void UnlockMouse() override;
188   bool GetIsMouseLockedUnadjustedMovementForTesting() override;
189   bool LockKeyboard(absl::optional<base::flat_set<ui::DomCode>> codes) override;
190   void UnlockKeyboard() override;
191 #if BUILDFLAG(IS_TIZEN_TV)
192   // notify web browser video playing status
193   void VideoPlayingStatusReceived(bool is_playing, int callback_id) override;
194 #endif
195   bool IsKeyboardLocked() override;
196 #if BUILDFLAG(IS_TIZEN)
197   // Sets rotation degrees. Expected values are one of { 0, 90, 180, 270 }.
198   void UpdateRotationDegrees(int rotation_degrees);
199 #endif
200   base::flat_map<std::string, std::string> GetKeyboardLayoutMap() override;
201   void InvalidateLocalSurfaceIdAndAllocationGroup() override;
202   void ClearFallbackSurfaceForCommitPending() override;
203   void ResetFallbackToFirstNavigationSurface() override;
204   bool RequestRepaintForTesting() override;
205   void DidStopFlinging() override;
206   void DidNavigateMainFramePreCommit() override;
207   void DidEnterBackForwardCache() override;
208   const viz::FrameSinkId& GetFrameSinkId() const override;
209   const viz::LocalSurfaceId& GetLocalSurfaceId() const override;
210   bool TransformPointToCoordSpaceForView(
211       const gfx::PointF& point,
212       RenderWidgetHostViewBase* target_view,
213       gfx::PointF* transformed_point) override;
214   viz::FrameSinkId GetRootFrameSinkId() override;
215   viz::SurfaceId GetCurrentSurfaceId() const override;
216   void FocusedNodeChanged(bool is_editable_node,
217                           const gfx::Rect& node_bounds_in_screen
218 #if BUILDFLAG(IS_TIZEN_TV)
219                           ,
220                           bool is_radio_or_checkbox,
221                           int password_input_minlength,
222                           int input_maxlength
223 #endif
224 #if defined(USE_EFL)
225                           ,
226                           bool is_content_editable
227 #endif
228                           ) override;
229 #if defined(TIZEN_VIDEO_HOLE)
230   void DidMoveWebView();
231   void SetWebViewMovedCallback(const base::RepeatingClosure on_webview_moved);
232 #endif
233
234 #if BUILDFLAG(IS_TIZEN_TV)
235   //Browser edge scroll
236   void DidEdgeScrollBy(const gfx::Point& offset, bool handled) override ;
237   void NotifyTrackInfoToBrowser(int active_track_id,
238                                 const std::string& url,
239                                 const std::string& lang) override;
240 #endif
241   void OnSynchronizedDisplayPropertiesChanged(bool rotation = false) override;
242   viz::ScopedSurfaceIdAllocator DidUpdateVisualProperties(
243       const cc::RenderFrameMetadata& metadata) override;
244   void DidNavigate() override;
245   void TakeFallbackContentFrom(RenderWidgetHostView* view) override;
246   bool CanSynchronizeVisualProperties() override;
247   std::vector<std::unique_ptr<ui::TouchEvent>> ExtractAndCancelActiveTouches()
248       override;
249   void TransferTouches(
250       const std::vector<std::unique_ptr<ui::TouchEvent>>& touches) override;
251   // TODO(lanwei): Use TestApi interface to write functions that are used in
252   // tests and remove FRIEND_TEST_ALL_PREFIXES.
253   void SetLastPointerType(ui::EventPointerType last_pointer_type) override;
254
255   // Overridden from ui::TextInputClient:
256   void SetCompositionText(const ui::CompositionText& composition) override;
257   size_t ConfirmCompositionText(bool keep_selection) override;
258   void ClearCompositionText() override;
259   void InsertText(const std::u16string& text,
260                   InsertTextCursorBehavior cursor_behavior) override;
261   void InsertChar(const ui::KeyEvent& event) override;
262   bool CanInsertImage() override;
263   void InsertImage(const GURL& src) override;
264   ui::TextInputType GetTextInputType() const override;
265   ui::TextInputMode GetTextInputMode() const override;
266   base::i18n::TextDirection GetTextDirection() const override;
267   int GetTextInputFlags() const override;
268   bool CanComposeInline() const override;
269   gfx::Rect GetCaretBounds() const override;
270   gfx::Rect GetSelectionBoundingBox() const override;
271   bool GetCompositionCharacterBounds(size_t index,
272                                      gfx::Rect* rect) const override;
273   bool HasCompositionText() const override;
274   ui::TextInputClient::FocusReason GetFocusReason() const override;
275   bool GetTextRange(gfx::Range* range) const override;
276   bool GetCompositionTextRange(gfx::Range* range) const override;
277   bool GetEditableSelectionRange(gfx::Range* range) const override;
278   bool SetEditableSelectionRange(const gfx::Range& range) override;
279   bool GetTextFromRange(const gfx::Range& range,
280                         std::u16string* text) const override;
281   void OnInputMethodChanged() override;
282   bool ChangeTextDirectionAndLayoutAlignment(
283       base::i18n::TextDirection direction) override;
284   void ExtendSelectionAndDelete(size_t before, size_t after) override;
285 #if BUILDFLAG(IS_CHROMEOS)
286   void ExtendSelectionAndReplace(size_t before,
287                                  size_t after,
288                                  base::StringPiece16 replacement_text) override;
289 #endif
290   void EnsureCaretNotInRect(const gfx::Rect& rect) override;
291   bool IsTextEditCommandEnabled(ui::TextEditCommand command) const override;
292   void SetTextEditCommandForNextKeyEvent(ui::TextEditCommand command) override;
293   ukm::SourceId GetClientSourceForMetrics() const override;
294   bool ShouldDoLearning() override;
295
296 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
297   bool SetCompositionFromExistingText(
298       const gfx::Range& range,
299       const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) override;
300 #endif
301
302 #if BUILDFLAG(IS_CHROMEOS)
303   gfx::Range GetAutocorrectRange() const override;
304   gfx::Rect GetAutocorrectCharacterBounds() const override;
305   bool SetAutocorrectRange(const gfx::Range& range) override;
306   absl::optional<ui::GrammarFragment> GetGrammarFragmentAtCursor()
307       const override;
308   bool ClearGrammarFragments(const gfx::Range& range) override;
309   bool AddGrammarFragments(
310       const std::vector<ui::GrammarFragment>& fragments) override;
311 #endif
312
313 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
314   // Returns the control and selection bounds of the EditContext or control
315   // bounds of the active editable element. This is used to report the layout
316   // bounds of the text input control to TSF on Windows.
317   void GetActiveTextInputControlLayoutBounds(
318       absl::optional<gfx::Rect>* control_bounds,
319       absl::optional<gfx::Rect>* selection_bounds) override;
320 #endif
321
322 #if BUILDFLAG(IS_WIN)
323   // API to notify accessibility whether there is an active composition
324   // from TSF or not.
325   // It notifies the composition range, composition text and whether the
326   // composition has been committed or not.
327   void SetActiveCompositionForAccessibility(
328       const gfx::Range& range,
329       const std::u16string& active_composition_text,
330       bool is_composition_committed) override;
331 #endif
332
333 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_ASH)
334   // Returns the editing context of the active web content.
335   // This is currently used by TSF and ChromeOS to fetch the URL of the active
336   // web content.
337   // https://docs.microsoft.com/en-us/windows/win32/tsf/predefined-properties
338   ui::TextInputClient::EditingContext GetTextEditingContext() override;
339 #endif
340
341 #if BUILDFLAG(IS_WIN)
342   // Notify TSF (via text store) when URL of the frame in focus changes.
343   void NotifyOnFrameFocusChanged() override;
344 #endif
345
346   // Overridden from display::DisplayObserver:
347   void OnDisplayMetricsChanged(const display::Display& display,
348                                uint32_t metrics) override;
349
350   // Overridden from aura::WindowDelegate:
351   gfx::Size GetMinimumSize() const override;
352   gfx::Size GetMaximumSize() const override;
353   void OnBoundsChanged(const gfx::Rect& old_bounds,
354                        const gfx::Rect& new_bounds) override;
355   gfx::NativeCursor GetCursor(const gfx::Point& point) override;
356   int GetNonClientComponent(const gfx::Point& point) const override;
357   bool ShouldDescendIntoChildForEventHandling(
358       aura::Window* child,
359       const gfx::Point& location) override;
360   bool CanFocus() override;
361   void OnCaptureLost() override;
362   void OnPaint(const ui::PaintContext& context) override;
363   void OnDeviceScaleFactorChanged(float old_device_scale_factor,
364                                   float new_device_scale_factor) override;
365   void OnWindowDestroying(aura::Window* window) override;
366   void OnWindowDestroyed(aura::Window* window) override;
367   void OnWindowTargetVisibilityChanged(bool visible) override;
368   bool HasHitTestMask() const override;
369   void GetHitTestMask(SkPath* mask) const override;
370   bool RequiresDoubleTapGestureEvents() const override;
371
372   // Overridden from ui::EventHandler:
373   void OnKeyEvent(ui::KeyEvent* event) override;
374   void OnMouseEvent(ui::MouseEvent* event) override;
375   void OnScrollEvent(ui::ScrollEvent* event) override;
376   void OnTouchEvent(ui::TouchEvent* event) override;
377   void OnGestureEvent(ui::GestureEvent* event) override;
378   base::StringPiece GetLogContext() const override;
379
380   // Overridden from wm::ActivationDelegate:
381   bool ShouldActivate() const override;
382
383   // Overridden from aura::client::CursorClientObserver:
384   void OnCursorVisibilityChanged(bool is_visible) override;
385
386   // Overridden from aura::client::CursorClientObserver:
387   void OnSystemCursorSizeChanged(const gfx::Size& cursor_size) override;
388
389   // Overridden from aura::client::FocusChangeObserver:
390   void OnWindowFocused(aura::Window* gained_focus,
391                        aura::Window* lost_focus) override;
392
393   // Overridden from aura::WindowTreeHostObserver:
394   void OnHostMovedInPixels(aura::WindowTreeHost* host) override;
395
396   // RenderFrameMetadataProvider::Observer implementation.
397   void OnRenderFrameMetadataChangedBeforeActivation(
398       const cc::RenderFrameMetadata& metadata) override {}
399   void OnRenderFrameMetadataChangedAfterActivation(
400       base::TimeTicks activation_time) override;
401   void OnRenderFrameSubmission() override {}
402   void OnLocalSurfaceIdChanged(
403       const cc::RenderFrameMetadata& metadata) override {}
404
405 #if BUILDFLAG(IS_WIN)
406   // Gets the HWND of the host window.
407   HWND GetHostWindowHWND() const;
408
409   // Updates the cursor clip region. Used for mouse locking.
410   void UpdateMouseLockRegion();
411
412   // Notification that the LegacyRenderWidgetHostHWND was destroyed.
413   void OnLegacyWindowDestroyed();
414 #endif
415
416   gfx::NativeViewAccessible GetParentNativeViewAccessible();
417
418   // Method to indicate if this instance is shutting down or closing.
419   // TODO(shrikant): Discuss around to see if it makes sense to add this method
420   // as part of RenderWidgetHostView.
421   bool IsClosing() const { return in_shutdown_; }
422
423   // Sets whether the overscroll controller should be enabled for this page.
424   void SetOverscrollControllerEnabled(bool enabled);
425
426   void SnapToPhysicalPixelBoundary();
427
428   // Used in tests to set a mock client for touch selection controller. It will
429   // create a new touch selection controller for the new client.
430   void SetSelectionControllerClientForTest(
431       std::unique_ptr<TouchSelectionControllerClientAura> client);
432
433   // RenderWidgetHostViewEventHandler::Delegate:
434   gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const override;
435   void ForwardKeyboardEventWithLatencyInfo(const NativeWebKeyboardEvent& event,
436                                            const ui::LatencyInfo& latency,
437                                            bool* update_event) override;
438   RenderFrameHostImpl* GetFocusedFrame() const;
439   bool NeedsMouseCapture() override;
440   void SetTooltipsEnabled(bool enable) override;
441   void Shutdown() override;
442
443   bool FocusedFrameHasStickyActivation() const;
444
445   RenderWidgetHostViewEventHandler* event_handler() {
446     return event_handler_.get();
447   }
448
449   void ScrollFocusedEditableNodeIntoView();
450
451   ui::EventPointerType GetLastPointerType() const { return last_pointer_type_; }
452
453   MouseWheelPhaseHandler* GetMouseWheelPhaseHandler() override;
454
455   ui::Compositor* GetCompositor() override;
456
457   void AllocateLocalSurfaceIdOnNextShow() {
458     allocate_local_surface_id_on_next_show_ = true;
459   }
460
461   DelegatedFrameHost* GetDelegatedFrameHostForTesting() const {
462     return delegated_frame_host_.get();
463   }
464
465 #if BUILDFLAG(IS_EFL)
466   void DidChangeInputType(bool is_password_field) override;
467   aura::Window* window() { return window_; }
468   RWHVAuraCommonHelperEfl* aura_efl_helper() { return efl_helper_.get(); }
469   RWHVAuraOffscreenHelperEfl* offscreen_helper();
470   void DidGetContentSnapshot(const SkBitmap& bitmap, int request_id) override;
471   void DidHandleKeyEvent(blink::WebInputEvent::Type input_event,
472                          bool processed) override;
473   void SelectionChanged(const std::u16string& text,
474                         size_t offset,
475                         const gfx::Range& range) override;
476   void TextInputStateChanged(const ui::mojom::TextInputState& params) override;
477   void BackgroundColorReceived(int callback_id, SkColor bg_color) override;
478   void OnGetFocusedNodeBounds(const gfx::RectF& rect) override;
479   void OnGetMainFrameScrollbarVisible(int callback_id, bool visible) override;
480 #endif
481
482  protected:
483   ~RenderWidgetHostViewAura() override;
484
485 #if !BUILDFLAG(IS_EFL)
486   // Exposed for tests.
487   aura::Window* window() { return window_; }
488 #endif
489
490   DelegatedFrameHost* GetDelegatedFrameHost() const {
491     return delegated_frame_host_.get();
492   }
493
494   // RenderWidgetHostViewBase:
495   void UpdateBackgroundColor() override;
496   bool HasFallbackSurface() const override;
497   absl::optional<DisplayFeature> GetDisplayFeature() override;
498   void SetDisplayFeatureForTesting(
499       const DisplayFeature* display_feature) override;
500   void NotifyHostAndDelegateOnWasShown(
501       blink::mojom::RecordContentToVisibleTimeRequestPtr visible_time_request)
502       final;
503   void RequestSuccessfulPresentationTimeFromHostOrDelegate(
504       blink::mojom::RecordContentToVisibleTimeRequestPtr visible_time_request)
505       final;
506   void CancelSuccessfulPresentationTimeRequestForHostAndDelegate() final;
507
508   // May be overridden in tests.
509   virtual bool ShouldSkipCursorUpdate() const;
510
511  private:
512   friend class DelegatedFrameHostClientAura;
513   friend class FakeRenderWidgetHostViewAura;
514   friend class InputMethodAuraTestBase;
515   friend class RenderWidgetHostViewAuraTest;
516   friend class RenderWidgetHostViewAuraBrowserTest;
517   friend class RenderWidgetHostViewAuraDevtoolsBrowserTest;
518   friend class RenderWidgetHostViewAuraCopyRequestTest;
519   friend class TestInputMethodObserver;
520 #if BUILDFLAG(IS_WIN)
521   friend class AccessibilityObjectLifetimeWinBrowserTest;
522   friend class AccessibilityTreeLinkageWinBrowserTest;
523   friend class DirectManipulationBrowserTestBase;
524 #endif
525   FRIEND_TEST_ALL_PREFIXES(InputMethodResultAuraTest,
526                            FinishImeCompositionSession);
527   FRIEND_TEST_ALL_PREFIXES(PaintHoldingRenderWidgetHostViewBrowserTest,
528                            PaintHoldingOnNavigation);
529   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
530                            PopupRetainsCaptureAfterMouseRelease);
531   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SetCompositionText);
532   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, FocusedNodeChanged);
533   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventState);
534   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
535                            TouchEventPositionsArentRounded);
536   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TouchEventSyncAsync);
537   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, Resize);
538   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SwapNotifiesWindow);
539   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, MirrorLayers);
540   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
541                            SkippedDelegatedFrames);
542   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
543                            ResizeAfterReceivingFrame);
544   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
545                            ChildGeneratedResizeRoutesLocalSurfaceId);
546   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, MissingFramesDontLock);
547   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, OutputSurfaceIdChange);
548   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
549                            DiscardDelegatedFrames);
550   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
551                            DiscardDelegatedFramesWithLocking);
552   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SoftwareDPIChange);
553   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
554                            UpdateCursorIfOverSelf);
555   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
556                            VisibleViewportTest);
557   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
558                            OverscrollResetsOnBlur);
559   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
560                            FinishCompositionByMouse);
561   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
562                            ForwardsBeginFrameAcks);
563   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
564                            VirtualKeyboardFocusEnsureCaretInRect);
565   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
566                            DiscardDelegatedFramesWithMemoryPressure);
567   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraInputMethodTest,
568                            OnCaretBoundsChanged);
569   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraInputMethodTest,
570                            OnCaretBoundsChangedInputModeNone);
571   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraInputMethodFocusTest,
572                            OnFocusLost);
573   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraKeyboardTest,
574                            KeyboardObserverDestroyed);
575   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraKeyboardTest,
576                            NoKeyboardObserverForMouseInput);
577   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraKeyboardTest,
578                            KeyboardObserverForOnlyTouchInput);
579   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraKeyboardTest,
580                            KeyboardObserverForFocusedNodeChanged);
581   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraKeyboardTest,
582                            KeyboardObserverForPenInput);
583   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraKeyboardTest,
584                            KeyboardObserverDetachDuringWindowDestroy);
585   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
586                            DropFallbackWhenHidden);
587   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
588                            CompositorFrameSinkChange);
589   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, SurfaceChanges);
590   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
591                            DeviceScaleFactorChanges);
592   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, HideThenShow);
593   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
594                            DropFallbackIfResizedWhileHidden);
595   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
596                            DontDropFallbackIfNotResizedWhileHidden);
597   FRIEND_TEST_ALL_PREFIXES(SitePerProcessHitTestBrowserTest, PopupMenuTest);
598   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
599                            NewContentRenderingTimeout);
600   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
601                            AllocateLocalSurfaceIdOnEviction);
602   FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest,
603                            WebContentsViewReparent);
604   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, TakeFallbackContent);
605   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
606                            TakeFallbackContentForPrerender);
607   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
608                            DiscardDelegatedFrames);
609   FRIEND_TEST_ALL_PREFIXES(SitePerProcessHitTestBrowserTest,
610                            ScrollOOPIFEditableElement);
611   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, OcclusionHidesTooltip);
612   FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest,
613                            UpdateInsetsWithVirtualKeyboardEnabled);
614
615   class WindowObserver;
616   friend class WindowObserver;
617
618   friend void VerifyStaleContentOnFrameEviction(
619       RenderWidgetHostView* render_widget_host_view);
620
621   void CreateAuraWindow(aura::client::WindowType type);
622
623   // Returns true if a stale frame content needs to be set for the current RWHV.
624   // This is primarily useful during various CrOS animations to prevent showing
625   // a white screen and instead showing a snapshot of the frame content that
626   // was most recently evicted.
627   bool ShouldShowStaleContentOnEviction();
628
629   void CreateDelegatedFrameHostClient();
630
631   void UpdateCursorIfOverSelf();
632
633   bool SynchronizeVisualProperties(
634       const cc::DeadlinePolicy& deadline_policy,
635       const absl::optional<viz::LocalSurfaceId>& child_local_surface_id);
636
637   void OnDidUpdateVisualPropertiesComplete(
638       const cc::RenderFrameMetadata& metadata);
639
640   // Set the bounds of the window and handle size changes.  Assumes the caller
641   // has already adjusted the origin of |rect| to conform to whatever coordinate
642   // space is required by the aura::Window.
643   void InternalSetBounds(const gfx::Rect& rect);
644
645   // Update the insets for bounds change when the virtual keyboard is shown.
646   void UpdateInsetsWithVirtualKeyboardEnabled();
647
648 #if BUILDFLAG(IS_WIN)
649   // Creates and/or updates the legacy dummy window which corresponds to
650   // the bounds of the webcontents. It is needed for accessibility and
651   // for scrolling to work in legacy drivers for trackpoints/trackpads, etc.
652   void UpdateLegacyWin();
653
654   bool UsesNativeWindowFrame() const;
655 #endif
656
657   ui::InputMethod* GetInputMethod() const;
658
659   // Get the focused view that should be used for retrieving the text selection.
660   RenderWidgetHostViewBase* GetFocusedViewForTextSelection() const;
661
662   // Returns whether the widget needs an input grab to work properly.
663   bool NeedsInputGrab();
664
665   // Sends an IPC to the renderer process to communicate whether or not
666   // the mouse cursor is visible anywhere on the screen.
667   void NotifyRendererOfCursorVisibilityState(bool is_visible);
668
669   // Called after |window_| is parented to a WindowEventDispatcher.
670   void AddedToRootWindow();
671
672   // Called prior to removing |window_| from a WindowEventDispatcher.
673   void RemovingFromRootWindow();
674
675   // TextInputManager::Observer implementation.
676   void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
677                                     RenderWidgetHostViewBase* updated_view,
678                                     bool did_update_state) override;
679   void OnImeCancelComposition(TextInputManager* text_input_manager,
680                               RenderWidgetHostViewBase* updated_view) override;
681   void OnSelectionBoundsChanged(
682       TextInputManager* text_input_manager,
683       RenderWidgetHostViewBase* updated_view) override;
684   void OnTextSelectionChanged(TextInputManager* text_input_mangager,
685                               RenderWidgetHostViewBase* updated_view) override;
686
687   // Detaches |this| from the input method object.
688   // is_removed flag is true if this is called while the window is
689   // getting removed/destroyed, false, otherwise.
690   void DetachFromInputMethod(bool is_removed);
691
692   // Dismisses a Web Popup on a mouse or touch press outside the popup and its
693   // parent.
694   void ApplyEventObserverForPopupExit(const ui::LocatedEvent& event);
695
696   // Converts |rect| from screen coordinate to window coordinate.
697   gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const;
698
699   // Called when the bounds of `window_` relative to the root change.
700   void HandleBoundsInRootChanged();
701
702   // Called when the parent window hierarchy for our window changes.
703   void ParentHierarchyChanged();
704
705   // Helper function to create a selection controller.
706   void CreateSelectionController();
707
708   // Used to set the |popup_child_host_view_| on the |popup_parent_host_view_|
709   // and to notify the |event_handler_|.
710   void SetPopupChild(RenderWidgetHostViewAura* popup_child_host_view);
711
712   // Called when the window title is changed.
713   void WindowTitleChanged();
714
715   void InvalidateLocalSurfaceIdOnEviction();
716
717   // Called to process a display metrics change.
718   void ProcessDisplayMetricsChanged();
719
720   void CancelActiveTouches();
721
722   // Common part of UnOccluded() and Show().
723   void ShowImpl(PageVisibilityState page_visibility);
724
725   // Common part of Occluded() and Hide().
726   void HideImpl();
727
728   blink::mojom::FrameWidgetInputHandler*
729   GetFrameWidgetInputHandlerForFocusedWidget();
730
731   void SetTooltipText(const std::u16string& tooltip_text);
732
733 #if BUILDFLAG(IS_WIN)
734   // Ensure that we're connecting to the device posture provider to
735   // get the DisplayFeatures.
736   void EnsureDevicePostureServiceConnection();
737 #endif
738
739   // DeviceViewportSegmentClient.
740   void OnViewportSegmentsChanged(
741       const std::vector<gfx::Rect>& segments) override;
742
743   // Provided a list of viewport segments, calculate and set the
744   // DisplayFeature.
745   void ComputeDisplayFeature();
746
747   raw_ptr<aura::Window> window_;
748
749   std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client_;
750   // NOTE: this may be null during destruction.
751   std::unique_ptr<DelegatedFrameHost> delegated_frame_host_;
752
753   std::unique_ptr<WindowObserver> window_observer_;
754
755   // Tracks the ancestors of the RWHVA window for window location changes.
756   std::unique_ptr<aura_extra::WindowPositionInRootMonitor>
757       position_in_root_observer_;
758
759   // Are we in the process of closing?  Tracked so we don't try to shutdown
760   // again while inside shutdown, causing a double-free.
761   bool in_shutdown_;
762
763   // True if in the process of handling a window bounds changed notification.
764   bool in_bounds_changed_;
765
766   // Our parent host view, if this is a popup.  NULL otherwise.
767   raw_ptr<RenderWidgetHostViewAura, DanglingUntriaged> popup_parent_host_view_;
768
769   // Our child popup host. NULL if we do not have a child popup.
770   raw_ptr<RenderWidgetHostViewAura, DanglingUntriaged> popup_child_host_view_;
771
772   class EventObserverForPopupExit;
773   std::unique_ptr<EventObserverForPopupExit> event_observer_for_popup_exit_;
774
775 #if BUILDFLAG(IS_TIZEN)
776   // rotation degree
777   int rotation_ = 0;
778 #endif
779
780   // True when content is being loaded. Used to show an hourglass cursor.
781   bool is_loading_;
782
783   // The cursor for the page. This is passed up from the renderer.
784   WebCursor current_cursor_;
785
786   // Indicates if there is onging composition text.
787   bool has_composition_text_;
788
789   // Current tooltip text.
790   std::u16string tooltip_;
791
792   // Whether or not a frame observer has been added.
793   bool added_frame_observer_;
794
795   // Used to track the last cursor visibility update that was sent to the
796   // renderer via NotifyRendererOfCursorVisibilityState().
797   enum CursorVisibilityState {
798     UNKNOWN,
799     VISIBLE,
800     NOT_VISIBLE,
801   };
802   CursorVisibilityState cursor_visibility_state_in_renderer_;
803
804 #if BUILDFLAG(IS_WIN)
805   // The LegacyRenderWidgetHostHWND class provides a dummy HWND which is used
806   // for accessibility, as the container for windowless plugins like
807   // Flash/Silverlight, etc and for legacy drivers for trackpoints/trackpads,
808   // etc.
809   // The LegacyRenderWidgetHostHWND instance is created during the first call
810   // to RenderWidgetHostViewAura::InternalSetBounds. The instance is destroyed
811   // when the LegacyRenderWidgetHostHWND hwnd is destroyed.
812   raw_ptr<content::LegacyRenderWidgetHostHWND> legacy_render_widget_host_HWND_;
813
814   // Set to true if the legacy_render_widget_host_HWND_ instance was destroyed
815   // by Windows. This could happen if the browser window was destroyed by
816   // DestroyWindow for e.g. This flag helps ensure that we don't try to create
817   // the LegacyRenderWidgetHostHWND instance again as that would be a futile
818   // exercise.
819   bool legacy_window_destroyed_;
820
821   // Contains a copy of the last context menu request parameters. Only set when
822   // we receive a request to show the context menu on a long press.
823   std::unique_ptr<ContextMenuParams> last_context_menu_params_;
824
825   // Handles the showing/hiding of the VK on Windows.
826   friend class VirtualKeyboardControllerWin;
827   std::unique_ptr<VirtualKeyboardControllerWin>
828       virtual_keyboard_controller_win_;
829
830   gfx::Point last_mouse_move_location_;
831 #endif
832
833   // The last selection bounds reported to the view.
834   gfx::SelectionBound selection_start_;
835   gfx::SelectionBound selection_end_;
836
837   // The insets for the window bounds (not for screen) when the window is
838   // partially occluded.
839   gfx::Insets insets_;
840
841   // Cache the occluded bounds in screen coordinate of the virtual keyboard.
842   gfx::Rect keyboard_occluded_bounds_;
843
844   std::unique_ptr<wm::ScopedTooltipDisabler> tooltip_disabler_;
845
846   float device_scale_factor_;
847
848   // While this is a ui::EventHandler for targetting, |event_handler_| actually
849   // provides an implementation, and directs events to |host_|.
850   std::unique_ptr<RenderWidgetHostViewEventHandler> event_handler_;
851
852   // If this object is the main view of a RenderWidgetHostImpl, this value
853   // equals to the FrameSinkId of that widget.
854   const viz::FrameSinkId frame_sink_id_;
855
856   std::unique_ptr<CursorManager> cursor_manager_;
857
858   // Latest capture sequence number which is incremented when the caller
859   // requests surfaces be synchronized via
860   // EnsureSurfaceSynchronizedForWebTest().
861   uint32_t latest_capture_sequence_number_ = 0u;
862
863   // The pointer type of the most recent gesture/mouse/touch event.
864   ui::EventPointerType last_pointer_type_ = ui::EventPointerType::kUnknown;
865   // The pointer type that caused the most recent focus. This value will be
866   // incorrect if the focus was not triggered by a user gesture.
867   ui::EventPointerType last_pointer_type_before_focus_ =
868       ui::EventPointerType::kUnknown;
869
870   bool is_first_navigation_ = true;
871   viz::LocalSurfaceId inset_surface_id_;
872
873   // See OnDisplayMetricsChanged() for details.
874   bool needs_to_update_display_metrics_ = false;
875
876   // Saved value of WebPreferences' |double_tap_to_zoom_enabled|.
877   bool double_tap_to_zoom_enabled_ = false;
878
879   // Current visibility state. Initialized based on
880   // RenderWidgetHostImpl::is_hidden().
881   Visibility visibility_;
882
883   // Represents a feature of the physical display whose offset and mask_length
884   // are expressed in DIPs relative to the view. See display_feature.h for more
885   // details.
886   absl::optional<DisplayFeature> display_feature_;
887   // Viewport segments returned by the platform.
888   std::vector<gfx::Rect> viewport_segments_;
889
890 #if BUILDFLAG(IS_WIN)
891   mojo::Remote<device::mojom::DevicePostureProvider> device_posture_provider_;
892   mojo::Receiver<device::mojom::DeviceViewportSegmentsClient>
893       device_posture_receiver_{this};
894 #endif
895
896   absl::optional<display::ScopedDisplayObserver> display_observer_;
897
898 #if BUILDFLAG(IS_EFL)
899   std::unique_ptr<RWHVAuraCommonHelperEfl> efl_helper_;
900 #endif
901
902   bool allocate_local_surface_id_on_next_show_ = false;
903
904 #if defined(TIZEN_VIDEO_HOLE)
905   base::RepeatingClosure on_webview_moved_callback_;
906 #endif
907
908   base::WeakPtrFactory<RenderWidgetHostViewAura> weak_ptr_factory_{this};
909 };
910
911 }  // namespace content
912
913 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_AURA_H_