web_widget.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * Copyright (C) 2009 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_WIDGET_H_
  31. #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_WIDGET_H_
  32. #include "base/callback.h"
  33. #include "base/time/time.h"
  34. #include "build/build_config.h"
  35. #include "cc/input/browser_controls_state.h"
  36. #include "cc/metrics/begin_main_frame_metrics.h"
  37. #include "cc/paint/element_id.h"
  38. #include "cc/trees/layer_tree_host_client.h"
  39. #include "third_party/blink/public/common/input/web_menu_source_type.h"
  40. #include "third_party/blink/public/common/metrics/document_update_reason.h"
  41. #include "third_party/blink/public/common/widget/screen_info.h"
  42. #include "third_party/blink/public/mojom/input/input_event_result.mojom-shared.h"
  43. #include "third_party/blink/public/mojom/input/pointer_lock_context.mojom-shared.h"
  44. #include "third_party/blink/public/mojom/input/pointer_lock_result.mojom-shared.h"
  45. #include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
  46. #include "third_party/blink/public/platform/cross_variant_mojo_util.h"
  47. #include "third_party/blink/public/platform/input/input_handler_proxy.h"
  48. #include "third_party/blink/public/platform/web_common.h"
  49. #include "third_party/blink/public/platform/web_input_event_result.h"
  50. #include "third_party/blink/public/platform/web_rect.h"
  51. #include "third_party/blink/public/platform/web_size.h"
  52. #include "third_party/blink/public/platform/web_text_input_info.h"
  53. #include "third_party/blink/public/platform/web_vector.h"
  54. #include "third_party/blink/public/web/web_hit_test_result.h"
  55. #include "third_party/blink/public/web/web_lifecycle_update.h"
  56. #include "third_party/blink/public/web/web_range.h"
  57. #include "third_party/blink/public/web/web_swap_result.h"
  58. namespace cc {
  59. class LayerTreeHost;
  60. class LayerTreeSettings;
  61. class TaskGraphRunner;
  62. class UkmRecorderFactory;
  63. }
  64. namespace ui {
  65. class Cursor;
  66. class LatencyInfo;
  67. }
  68. namespace blink {
  69. class SynchronousCompositorRegistry;
  70. struct VisualProperties;
  71. class WebCoalescedInputEvent;
  72. namespace scheduler {
  73. class WebRenderWidgetSchedulingState;
  74. class WebThreadScheduler;
  75. }
  76. class WebWidget {
  77. public:
  78. // Initialize compositing. This will create a LayerTreeHost but will not
  79. // allocate a frame sink or begin producing frames until SetCompositorVisible
  80. // is called. |settings| is typically null. When |settings| is null
  81. // the default settings will be used, tests may provide a |settings| object to
  82. // override the defaults.
  83. virtual cc::LayerTreeHost* InitializeCompositing(
  84. scheduler::WebThreadScheduler* main_thread_scheduler,
  85. cc::TaskGraphRunner* task_graph_runner,
  86. bool for_child_local_root_frame,
  87. const ScreenInfo& screen_info,
  88. std::unique_ptr<cc::UkmRecorderFactory> ukm_recorder_factory,
  89. const cc::LayerTreeSettings* settings) = 0;
  90. // This method closes and deletes the WebWidget. If a |cleanup_task| is
  91. // provided it should run on the |cleanup_runner| after the WebWidget has
  92. // added its own tasks to the |cleanup_runner|.
  93. virtual void Close(
  94. scoped_refptr<base::SingleThreadTaskRunner> cleanup_runner = nullptr) {}
  95. // Set the compositor as visible. If |visible| is true, then the compositor
  96. // will request a new layer frame sink and begin producing frames from the
  97. // compositor.
  98. virtual void SetCompositorVisible(bool visible) = 0;
  99. // Returns the current size of the WebWidget.
  100. virtual WebSize Size() { return WebSize(); }
  101. // Called to resize the WebWidget.
  102. virtual void Resize(const WebSize&) {}
  103. // Called to run through the entire set of document lifecycle phases needed
  104. // to render a frame of the web widget. This MUST be called before Paint,
  105. // and it may result in calls to WebViewClient::DidInvalidateRect (for
  106. // non-composited WebViews).
  107. // |reason| must be used to indicate the source of the
  108. // update for the purposes of metrics gathering.
  109. virtual void UpdateAllLifecyclePhases(DocumentUpdateReason reason) {
  110. UpdateLifecycle(WebLifecycleUpdate::kAll, reason);
  111. }
  112. // UpdateLifecycle is used to update to a specific lifestyle phase, as given
  113. // by |LifecycleUpdate|. To update all lifecycle phases, use
  114. // UpdateAllLifecyclePhases.
  115. // |reason| must be used to indicate the source of the
  116. // update for the purposes of metrics gathering.
  117. virtual void UpdateLifecycle(WebLifecycleUpdate requested_update,
  118. DocumentUpdateReason reason) {}
  119. // Called to inform the WebWidget of a change in theme.
  120. // Implementors that cache rendered copies of widgets need to re-render
  121. // on receiving this message
  122. virtual void ThemeChanged() {}
  123. // Do a hit test at given point and return the WebHitTestResult.
  124. virtual WebHitTestResult HitTestResultAt(const gfx::PointF&) = 0;
  125. // Called to inform the WebWidget of an input event.
  126. virtual WebInputEventResult HandleInputEvent(const WebCoalescedInputEvent&) {
  127. return WebInputEventResult::kNotHandled;
  128. }
  129. // Send any outstanding touch events. Touch events need to be grouped together
  130. // and any changes since the last time a touch event is going to be sent in
  131. // the new touch event.
  132. virtual WebInputEventResult DispatchBufferedTouchEvents() {
  133. return WebInputEventResult::kNotHandled;
  134. }
  135. // Called to inform the WebWidget that mouse capture was lost.
  136. virtual void MouseCaptureLost() {}
  137. // Called to inform the WebWidget of the mouse cursor's visibility.
  138. virtual void SetCursorVisibilityState(bool is_visible) {}
  139. // Called to inform the WebWidget that it has gained or lost keyboard focus.
  140. virtual void SetFocus(bool) {}
  141. // Returns the state of focus for the WebWidget.
  142. virtual bool HasFocus() { return false; }
  143. // Returns the anchor and focus bounds of the current selection.
  144. // If the selection range is empty, it returns the caret bounds.
  145. virtual bool SelectionBounds(WebRect& anchor, WebRect& focus) const {
  146. return false;
  147. }
  148. // Calling WebWidgetClient::requestPointerLock() will result in one
  149. // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
  150. virtual void DidAcquirePointerLock() {}
  151. virtual void DidNotAcquirePointerLock() {}
  152. // Pointer lock was held, but has been lost. This may be due to a
  153. // request via WebWidgetClient::requestPointerUnlock(), or for other
  154. // reasons such as the user exiting lock, window focus changing, etc.
  155. virtual void DidLosePointerLock() {}
  156. // Accessor to the WebWidget scheduing state.
  157. virtual scheduler::WebRenderWidgetSchedulingState*
  158. RendererWidgetSchedulingState() = 0;
  159. // When the WebWidget is part of a frame tree, returns the active url for
  160. // main frame of that tree, if the main frame is local in that tree. When
  161. // the WebWidget is of a different kind (e.g. a popup) it returns the active
  162. // url for the main frame of the frame tree that spawned the WebWidget, if
  163. // the main frame is local in that tree. When the relevant main frame is
  164. // remote in that frame tree, then the url is not known, and an empty url is
  165. // returned.
  166. virtual WebURL GetURLForDebugTrace() = 0;
  167. virtual void SetCursor(const ui::Cursor& cursor) = 0;
  168. // Get the current tooltip text.
  169. virtual WebString GetLastToolTipTextForTesting() const { return WebString(); }
  170. // Whether or not the widget is in the process of handling input events.
  171. virtual bool HandlingInputEvent() = 0;
  172. // Set state that the widget is in the process of handling input events.
  173. virtual void SetHandlingInputEvent(bool handling) = 0;
  174. using HandledEventCallback = base::OnceCallback<void(
  175. mojom::InputEventResultState ack_state,
  176. const ui::LatencyInfo& latency_info,
  177. std::unique_ptr<InputHandlerProxy::DidOverscrollParams>,
  178. base::Optional<cc::TouchAction>)>;
  179. // Process the input event, invoking the callback when complete. This
  180. // method will call the callback synchronously.
  181. virtual void ProcessInputEventSynchronouslyForTesting(
  182. const WebCoalescedInputEvent&,
  183. HandledEventCallback) = 0;
  184. virtual void DidOverscrollForTesting(
  185. const gfx::Vector2dF& overscroll_delta,
  186. const gfx::Vector2dF& accumulated_overscroll,
  187. const gfx::PointF& position_in_viewport,
  188. const gfx::Vector2dF& velocity_in_viewport) {}
  189. // Requests the text input state be updated. If anything has changed the
  190. // updated state will be sent to the browser.
  191. virtual void UpdateTextInputState() = 0;
  192. // Request Mouse Lock. This can be removed eventually when the mouse lock
  193. // dispatcher is moved into blink.
  194. virtual void RequestMouseLock(
  195. bool has_transient_user_activation,
  196. bool priviledged,
  197. bool request_unadjusted_movement,
  198. base::OnceCallback<
  199. void(mojom::PointerLockResult,
  200. CrossVariantMojoRemote<mojom::PointerLockContextInterfaceBase>)>
  201. callback) = 0;
  202. // Flush any pending input.
  203. virtual void FlushInputProcessedCallback() = 0;
  204. // Cancel the current composition.
  205. virtual void CancelCompositionForPepper() = 0;
  206. // Requests the selection bounds be updated.
  207. virtual void UpdateSelectionBounds() = 0;
  208. // Request the virtual keyboard be shown.
  209. virtual void ShowVirtualKeyboard() = 0;
  210. // Apply the visual properties to the widget.
  211. virtual void ApplyVisualProperties(
  212. const VisualProperties& visual_properties) = 0;
  213. // Returns information about the screen where this view's widgets are being
  214. // displayed.
  215. virtual const ScreenInfo& GetScreenInfo() = 0;
  216. // Returns original (non-emulated) information about the screen where this
  217. // view's widgets are being displayed.
  218. virtual const ScreenInfo& GetOriginalScreenInfo() = 0;
  219. // Called to get the position of the widget's window in screen
  220. // coordinates. Note, the window includes any decorations such as borders,
  221. // scrollbars, URL bar, tab strip, etc. if they exist.
  222. virtual gfx::Rect WindowRect() = 0;
  223. // Called to get the view rect in screen coordinates. This is the actual
  224. // content view area, i.e. doesn't include any window decorations.
  225. virtual gfx::Rect ViewRect() = 0;
  226. // Sets the screen rects (in screen coordinates).
  227. virtual void SetScreenRects(const gfx::Rect& widget_screen_rect,
  228. const gfx::Rect& window_screen_rect) = 0;
  229. // Returns the visible viewport size (in screen coorindates).
  230. virtual gfx::Size VisibleViewportSizeInDIPs() = 0;
  231. // Returns the emulator scale.
  232. virtual float GetEmulatorScale() { return 1.0f; }
  233. // Sets the pending window rects (in screen coordinates). This is used because
  234. // the window rect is delivered asynchronously to the browser. Pass in nullptr
  235. // to clear the pending window rect once the browser has acknowledged the
  236. // request.
  237. virtual void SetPendingWindowRect(const gfx::Rect* window_screen_rect) = 0;
  238. #if defined(OS_ANDROID)
  239. // Return the synchronous compositor registry.
  240. virtual SynchronousCompositorRegistry* GetSynchronousCompositorRegistry() = 0;
  241. #endif
  242. virtual bool IsHidden() const = 0;
  243. protected:
  244. ~WebWidget() = default;
  245. };
  246. } // namespace blink
  247. #endif