1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_FRAME_WIDGET_H_
6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_FRAME_WIDGET_H_
7 
8 #include "mojo/public/mojom/base/text_direction.mojom-blink.h"
9 #include "third_party/blink/public/mojom/input/input_handler.mojom-blink.h"
10 #include "third_party/blink/public/mojom/manifest/display_mode.mojom-blink.h"
11 #include "third_party/blink/public/platform/web_text_input_info.h"
12 #include "third_party/blink/public/platform/web_text_input_type.h"
13 #include "third_party/blink/public/platform/web_vector.h"
14 #include "third_party/blink/public/web/web_swap_result.h"
15 #include "third_party/blink/public/web/web_widget_client.h"
16 #include "third_party/blink/renderer/platform/platform_export.h"
17 #include "ui/base/ime/mojom/text_input_state.mojom-blink.h"
18 #include "ui/base/ime/mojom/virtual_keyboard_types.mojom-blink.h"
19 
20 namespace cc {
21 class AnimationHost;
22 class Layer;
23 class PaintImage;
24 }  // namespace cc
25 
26 namespace blink {
27 
28 // In interface exposed within Blink from local root frames that provides
29 // local-root specific things related to compositing and input. This
30 // class extends the FrameWidgetInputHandler implementation. All API calls
31 // on this class occur on the main thread. input/FrameWidgetInputHandlerImpl
32 // which also implements the FrameWidgetInputHandler interface runs on the
33 // compositor thread and proxies calls to this class.
34 class PLATFORM_EXPORT FrameWidget
35     : public mojom::blink::FrameWidgetInputHandler {
36  public:
37   ~FrameWidget() override;
38 
39   // Returns the WebWidgetClient, which is implemented outside of blink.
40   virtual WebWidgetClient* Client() const = 0;
41 
42   // Returns the compositors's AnimationHost for the widget.
43   virtual cc::AnimationHost* AnimationHost() const = 0;
44 
45   // Set the browser's behavior when overscroll happens, e.g. whether to glow
46   // or navigate.
47   virtual void SetOverscrollBehavior(
48       const cc::OverscrollBehavior& overscroll_behavior) = 0;
49 
50   // Posts a task with the given delay, then calls ScheduleAnimation() on the
51   // Client().
52   virtual void RequestAnimationAfterDelay(const base::TimeDelta&) = 0;
53 
54   // Sets the root layer. The |layer| can be null when detaching the root layer.
55   virtual void SetRootLayer(scoped_refptr<cc::Layer> layer) = 0;
56 
57   // Used to update the active selection bounds. Pass a default-constructed
58   // LayerSelection to clear it.
59   virtual void RegisterSelection(cc::LayerSelection selection) = 0;
60 
61   // Image decode functionality.
62   virtual void RequestDecode(const cc::PaintImage&,
63                              base::OnceCallback<void(bool)>) = 0;
64 
65   // Forwards to WebFrameWidget::NotifySwapAndPresentationTime().
66   // The |callback| will be fired when the corresponding renderer frame is
67   // submitted (still called "swapped") to the display compositor (either with
68   // DidSwap or DidNotSwap).
69   virtual void NotifySwapAndPresentationTimeInBlink(
70       WebReportTimeCallback swap_callback,
71       WebReportTimeCallback presentation_callback) = 0;
72 
73   // Enable or disable BeginMainFrameNotExpected signals from the compositor,
74   // which are consumed by the blink scheduler.
75   virtual void RequestBeginMainFrameNotExpected(bool request) = 0;
76 
77   // A stable numeric Id for the local root's compositor. For tracing/debugging
78   // purposes.
79   virtual int GetLayerTreeId() = 0;
80 
81   // Set or get what event handlers exist in the document contained in the
82   // WebWidget in order to inform the compositor thread if it is able to handle
83   // an input event, or it needs to pass it to the main thread to be handled.
84   // The class is the type of input event, and for each class there is a
85   // properties defining if the compositor thread can handle the event.
86   virtual void SetEventListenerProperties(cc::EventListenerClass,
87                                           cc::EventListenerProperties) = 0;
88   virtual cc::EventListenerProperties EventListenerProperties(
89       cc::EventListenerClass) const = 0;
90 
91   // Returns the DisplayMode in use for the widget.
92   virtual mojom::blink::DisplayMode DisplayMode() const = 0;
93 
94   // Returns the window segments for the widget.
95   virtual const WebVector<gfx::Rect>& WindowSegments() const = 0;
96 
97   // Sets the ink metadata on the layer tree host
98   virtual void SetDelegatedInkMetadata(
99       std::unique_ptr<viz::DelegatedInkMetadata> metadata) = 0;
100 
101   // Called when the main thread overscrolled.
102   virtual void DidOverscroll(const gfx::Vector2dF& overscroll_delta,
103                              const gfx::Vector2dF& accumulated_overscroll,
104                              const gfx::PointF& position,
105                              const gfx::Vector2dF& velocity) = 0;
106 
107   // Requests that a gesture of |injected_type| be reissued at a later point in
108   // time. |injected_type| is required to be one of
109   // GestureScroll{Begin,Update,End}. The dispatched gesture will scroll the
110   // ScrollableArea identified by |scrollable_area_element_id| by the given
111   // delta + granularity.
112   virtual void InjectGestureScrollEvent(
113       WebGestureDevice device,
114       const gfx::Vector2dF& delta,
115       ui::ScrollGranularity granularity,
116       cc::ElementId scrollable_area_element_id,
117       WebInputEvent::Type injected_type) = 0;
118 
119   // Called when the cursor for the widget changes.
120   virtual void DidChangeCursor(const ui::Cursor&) = 0;
121 
122   // Return the composition character in window coordinates.
123   virtual void GetCompositionCharacterBoundsInWindow(
124       Vector<gfx::Rect>* bounds_in_dips) = 0;
125 
126   virtual gfx::Range CompositionRange() = 0;
127   // Returns ime_text_spans and corresponding window coordinates for the list
128   // of given spans.
129   virtual Vector<ui::mojom::blink::ImeTextSpanInfoPtr> GetImeTextSpansInfo(
130       const WebVector<ui::ImeTextSpan>& ime_text_spans) = 0;
131   virtual WebTextInputInfo TextInputInfo() = 0;
132   virtual ui::mojom::blink::VirtualKeyboardVisibilityRequest
133   GetLastVirtualKeyboardVisibilityRequest() = 0;
134   virtual bool ShouldSuppressKeyboardForFocusedElement() = 0;
135 
136   // Return the edit context bounds in window coordinates.
137   virtual void GetEditContextBoundsInWindow(
138       base::Optional<gfx::Rect>* control_bounds,
139       base::Optional<gfx::Rect>* selection_bounds) = 0;
140 
141   virtual int32_t ComputeWebTextInputNextPreviousFlags() = 0;
142   virtual void ResetVirtualKeyboardVisibilityRequest() = 0;
143 
144   // Return the selection bounds in window coordinates. Returns true if the
145   // bounds returned were different than the passed in focus and anchor bounds.
146   virtual bool GetSelectionBoundsInWindow(gfx::Rect* focus,
147                                           gfx::Rect* anchor,
148                                           base::i18n::TextDirection* focus_dir,
149                                           base::i18n::TextDirection* anchor_dir,
150                                           bool* is_anchor_first) = 0;
151 
152   // Clear any cached text input state.
153   virtual void ClearTextInputState() = 0;
154 
155   // This message sends a string being composed with an input method.
156   virtual bool SetComposition(const String& text,
157                               const Vector<ui::ImeTextSpan>& ime_text_spans,
158                               const gfx::Range& replacement_range,
159                               int selection_start,
160                               int selection_end) = 0;
161 
162   // This message deletes the current composition, inserts specified text, and
163   // moves the cursor.
164   virtual void CommitText(const String& text,
165                           const Vector<ui::ImeTextSpan>& ime_text_spans,
166                           const gfx::Range& replacement_range,
167                           int relative_cursor_pos) = 0;
168 
169   // This message inserts the ongoing composition.
170   virtual void FinishComposingText(bool keep_selection) = 0;
171 
172   virtual bool IsProvisional() = 0;
173   virtual uint64_t GetScrollableContainerIdAt(
174       const gfx::PointF& point_in_dips) = 0;
175 
ShouldHandleImeEvents()176   virtual bool ShouldHandleImeEvents() { return false; }
177 
178   virtual void SetEditCommandsForNextKeyEvent(
179       Vector<mojom::blink::EditCommandPtr> edit_commands) = 0;
180 
181   // Returns information about the screen where this widget is being displayed.
182   virtual const ScreenInfo& GetScreenInfo() = 0;
183 
184   // Called to get the position of the widget's window in screen
185   // coordinates. Note, the window includes any decorations such as borders,
186   // scrollbars, URL bar, tab strip, etc. if they exist.
187   virtual gfx::Rect WindowRect() = 0;
188 
189   // Called to get the view rect in screen coordinates. This is the actual
190   // content view area, i.e. doesn't include any window decorations.
191   virtual gfx::Rect ViewRect() = 0;
192 
193   // Converts from Blink coordinate (ie. Viewport/Physical pixels) space to
194   // DIPs.
195   virtual gfx::RectF BlinkSpaceToDIPs(const gfx::RectF&) = 0;
196   virtual gfx::Rect BlinkSpaceToEnclosedDIPs(const gfx::Rect&) = 0;
197   virtual gfx::Size BlinkSpaceToFlooredDIPs(const gfx::Size& size) = 0;
198 
199   // Converts from DIPs to Blink coordinate space (ie. Viewport/Physical
200   // pixels).
201   virtual gfx::RectF DIPsToBlinkSpace(const gfx::RectF& rect) = 0;
202   virtual gfx::PointF DIPsToBlinkSpace(const gfx::PointF& point) = 0;
203   virtual gfx::Point DIPsToRoundedBlinkSpace(const gfx::Point& point) = 0;
204   virtual float DIPsToBlinkSpace(float scalar) = 0;
205 
206   virtual void RequestMouseLock(
207       bool has_transient_user_activation,
208       bool request_unadjusted_movement,
209       mojom::blink::WidgetInputHandlerHost::RequestMouseLockCallback
210           callback) = 0;
211 
212   // Mouse capture has been lost.
213   virtual void MouseCaptureLost() = 0;
214 
215   // Determines whether composition can happen inline.
216   virtual bool CanComposeInline() = 0;
217 
218   // Determines if IME events should be sent to Plugin instead of processed to
219   // the currently focused frame.
220   virtual bool ShouldDispatchImeEventsToPlugin() = 0;
221 
222   // Set the composition in plugin.
223   virtual void ImeSetCompositionForPlugin(
224       const String& text,
225       const Vector<ui::ImeTextSpan>& ime_text_spans,
226       const gfx::Range& replacement_range,
227       int selection_start,
228       int selection_end) = 0;
229 
230   // Commit the text to plugin.
231   virtual void ImeCommitTextForPlugin(
232       const String& text,
233       const Vector<ui::ImeTextSpan>& ime_text_spans,
234       const gfx::Range& replacement_range,
235       int relative_cursor_pos) = 0;
236 
237   // Indicate composition is complete to plugin.
238   virtual void ImeFinishComposingTextForPlugin(bool keep_selection) = 0;
239 
240   // Returns the FrameSinkId for this widget which is used for identifying
241   // frames submitted from the compositor.
242   virtual const viz::FrameSinkId& GetFrameSinkId() = 0;
243 };
244 
245 }  // namespace blink
246 
247 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WIDGET_FRAME_WIDGET_H_
248