blob: 132866f3c1581a7f6b34948a64675c1d232edd0b [file] [log] [blame]
[email protected]9f4f3322012-01-18 22:29:561// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#ifndef CONTENT_RENDERER_RENDER_WIDGET_H_
6#define CONTENT_RENDERER_RENDER_WIDGET_H_
initial.commit09911bf2008-07-26 23:55:297
avi1023d012015-12-25 02:39:148#include <stddef.h>
9#include <stdint.h>
10
[email protected]0e241b4b2012-08-18 09:06:2711#include <map>
dchengcedca5612016-04-09 01:40:1512#include <memory>
xlai180af792016-08-26 22:07:4213#include <queue>
pwnallef669312017-01-07 01:17:2914#include <string>
15#include <vector>
[email protected]010ea08a2009-10-11 20:21:3216
[email protected]586871b2014-07-22 17:05:1117#include "base/callback.h"
Fady Samuel1ee6fb5c2018-02-16 03:27:4618#include "base/cancelable_callback.h"
[email protected]f3112a52011-09-30 23:47:4919#include "base/compiler_specific.h"
avi1023d012015-12-25 02:39:1420#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1521#include "base/memory/ref_counted.h"
wjmaclean1d970622017-01-21 22:28:2422#include "base/memory/weak_ptr.h"
[email protected]bffc8302014-01-23 20:52:1623#include "base/observer_list.h"
Gabriel Charette14520232018-04-30 23:27:2224#include "base/single_thread_task_runner.h"
[email protected]abb522162013-06-28 01:54:1625#include "base/time/time.h"
avi1023d012015-12-25 02:39:1426#include "build/build_config.h"
Sandra Sunac5cdd832017-12-11 03:27:1327#include "cc/input/overscroll_behavior.h"
xidachenfa0199e72017-05-11 11:34:2628#include "cc/input/touch_action.h"
danakj4b347212018-07-04 17:55:1729#include "cc/trees/layer_tree_settings.h"
30#include "cc/trees/managed_memory_policy.h"
Fady Samuel644df1d2017-07-13 01:13:0231#include "components/viz/common/surfaces/local_surface_id.h"
Scott Violetc78fef732018-03-06 17:42:5332#include "content/common/buildflags.h"
[email protected]f3112a52011-09-30 23:47:4933#include "content/common/content_export.h"
[email protected]c2809346d2014-03-20 00:11:0334#include "content/common/cursors/webcursor.h"
paulmeyer6ef5a792016-11-08 20:33:5835#include "content/common/drag_event_source_info.h"
alexmos56567492016-09-13 00:52:4636#include "content/common/edit_command.h"
Dave Tapuska1bdf1832017-07-07 18:07:1937#include "content/common/widget.mojom.h"
paulmeyer90f6c31d2016-11-12 00:17:5938#include "content/public/common/drop_data.h"
ccameron2f451532016-09-07 21:49:2739#include "content/public/common/screen_info.h"
mfomitchev2600fd7c2016-02-17 20:53:3940#include "content/renderer/devtools/render_widget_screen_metrics_emulator_delegate.h"
danakja6c10012018-07-06 14:25:3641#include "content/renderer/gpu/layer_tree_view_delegate.h"
dtapuska9ec1a912017-04-21 15:18:3142#include "content/renderer/input/main_thread_event_queue.h"
fsamuel72464894f2015-12-15 06:59:3143#include "content/renderer/input/render_widget_input_handler.h"
44#include "content/renderer/input/render_widget_input_handler_delegate.h"
[email protected]586871b2014-07-22 17:05:1145#include "content/renderer/message_delivery_policy.h"
lfgbee1e0a2016-06-08 21:24:2146#include "content/renderer/mouse_lock_dispatcher.h"
47#include "content/renderer/render_widget_mouse_lock_dispatcher.h"
[email protected]4f86bdb2012-11-10 19:11:1948#include "ipc/ipc_listener.h"
nick4df698d82016-11-11 20:39:2349#include "ipc/ipc_message.h"
[email protected]4f86bdb2012-11-10 19:11:1950#include "ipc/ipc_sender.h"
Dave Tapuska1bdf1832017-07-07 18:07:1951#include "mojo/public/cpp/bindings/binding.h"
Scott Violet02e38b92018-03-27 23:42:1452#include "ppapi/buildflags/buildflags.h"
Dmitry Gozman88ca5a992018-05-18 00:13:3353#include "third_party/blink/public/common/manifest/web_display_mode.h"
Blink Reformata30d4232018-04-07 15:31:0654#include "third_party/blink/public/platform/web_input_event.h"
55#include "third_party/blink/public/platform/web_rect.h"
56#include "third_party/blink/public/platform/web_referrer_policy.h"
57#include "third_party/blink/public/platform/web_text_input_info.h"
58#include "third_party/blink/public/web/web_ime_text_span.h"
59#include "third_party/blink/public/web/web_popup_type.h"
60#include "third_party/blink/public/web/web_text_direction.h"
61#include "third_party/blink/public/web/web_widget.h"
62#include "third_party/blink/public/web/web_widget_client.h"
[email protected]b256eca2013-07-11 10:57:4063#include "ui/base/ime/text_input_mode.h"
[email protected]ad26ef42011-06-17 07:59:4564#include "ui/base/ime/text_input_type.h"
[email protected]a09d53ce2014-01-31 00:46:4265#include "ui/base/ui_base_types.h"
tfarina93bfa912014-12-05 14:23:1566#include "ui/gfx/geometry/rect.h"
tfarina93bfa912014-12-05 14:23:1567#include "ui/gfx/geometry/vector2d_f.h"
[email protected]08397d52011-02-05 01:53:3868#include "ui/gfx/native_widget_types.h"
[email protected]db4fc1e2013-09-06 20:01:5169#include "ui/gfx/range/range.h"
[email protected]d353541f2012-05-03 22:45:4170#include "ui/surface/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2971
danakj870925d2016-05-03 20:07:3872class GURL;
73
[email protected]484955942010-08-19 16:13:1874namespace IPC {
[email protected]586871b2014-07-22 17:05:1175class SyncMessageFilter;
[email protected]484955942010-08-19 16:13:1876}
77
[email protected]180ef242013-11-07 06:50:4678namespace blink {
skyostil529caa292016-08-10 17:44:5179namespace scheduler {
Yuta Kitamura39219b42018-04-06 10:28:1480class WebRenderWidgetSchedulingState;
skyostil529caa292016-08-10 17:44:5181}
[email protected]19193682014-04-03 15:01:4382struct WebDeviceEmulationParams;
paulmeyer6ef5a792016-11-08 20:33:5883class WebDragData;
lfgcaab5142016-02-26 19:06:5284class WebFrameWidget;
[email protected]41d86852012-11-07 12:23:2485class WebGestureEvent;
ekaramad2daaf672016-11-10 20:29:0186class WebInputMethodController;
kenrba7199832015-01-22 23:44:5987class WebLocalFrame;
[email protected]6a8ddba52010-09-05 04:38:0688class WebMouseEvent;
donnda070f3c2015-01-16 19:54:1189struct WebPoint;
pwnallef669312017-01-07 01:17:2990} // namespace blink
[email protected]526476902011-10-06 20:34:0691
[email protected]586871b2014-07-22 17:05:1192namespace cc {
[email protected]586871b2014-07-22 17:05:1193class SwapPromise;
94}
[email protected]ba91a792013-02-06 09:48:2895
[email protected]db4fc1e2013-09-06 20:01:5196namespace gfx {
danakja2c9d0a92018-07-25 20:01:1897class ColorSpace;
[email protected]4de6d1692011-10-12 08:45:4498class Range;
99}
100
chongza8ba91fc2016-08-16 21:39:17101namespace ui {
102struct DidOverscrollParams;
103}
104
[email protected]e9ff79c2012-10-19 21:31:26105namespace content {
Saman Samid189e5dfd2017-12-20 22:55:31106class BrowserPlugin;
danakj6e3bf8012014-12-16 18:27:53107class CompositorDependencies;
[email protected]b2e4c70132013-10-03 02:07:51108class ExternalPopupMenu;
[email protected]586871b2014-07-22 17:05:11109class FrameSwapMessageQueue;
danakja2c9d0a92018-07-25 20:01:18110class IdleUserDetector;
changwanf2a707b2015-10-30 08:22:16111class ImeEventGuard;
danakja6c10012018-07-06 14:25:36112class LayerTreeView;
dtapuska9ec1a912017-04-21 15:18:31113class MainThreadEventQueue;
ekaramad2a46d632016-07-19 13:33:09114class PepperPluginInstanceImpl;
[email protected]bffc8302014-01-23 20:52:16115class RenderFrameImpl;
[email protected]e3244ed2014-06-20 20:04:27116class RenderFrameProxy;
nickf7b38222016-11-22 21:59:35117class RenderViewImpl;
avi40b5be7a2016-03-03 21:13:44118class RenderWidgetOwnerDelegate;
mfomitchev2600fd7c2016-02-17 20:53:39119class RenderWidgetScreenMetricsEmulator;
[email protected]5b45ad42013-10-25 00:42:04120class ResizingModeSelector;
ekaramad330ba4232016-09-23 17:57:47121class TextInputClientObserver;
Dave Tapuska9db80842017-07-24 17:24:26122class WidgetInputHandlerManager;
[email protected]b2e4c70132013-10-03 02:07:51123struct ContextMenuParams;
Fady Samuel799e72192018-04-25 21:16:57124struct VisualProperties;
[email protected]e9ff79c2012-10-19 21:31:26125
initial.commit09911bf2008-07-26 23:55:29126// RenderWidget provides a communication bridge between a WebWidget and
127// a RenderWidgetHost, the latter of which lives in a different process.
dchengd96a27a2015-07-24 20:17:32128//
129// RenderWidget is used to implement:
130// - RenderViewImpl (deprecated)
131// - Fullscreen mode (RenderWidgetFullScreen)
132// - Popup "menus" (like the color chooser and date picker)
133// - Widgets for frames (for out-of-process iframe support)
[email protected]f3112a52011-09-30 23:47:49134class CONTENT_EXPORT RenderWidget
[email protected]c47317e2012-06-20 22:35:31135 : public IPC::Listener,
136 public IPC::Sender,
danakj9a8a9cf2018-07-17 23:52:12137 public blink::WebWidgetClient,
Dave Tapuska1bdf1832017-07-07 18:07:19138 public mojom::Widget,
danakja6c10012018-07-06 14:25:36139 public LayerTreeViewDelegate,
fsamuel72464894f2015-12-15 06:59:31140 public RenderWidgetInputHandlerDelegate,
mfomitchev2600fd7c2016-02-17 20:53:39141 public RenderWidgetScreenMetricsEmulatorDelegate,
dtapuska9ec1a912017-04-21 15:18:31142 public base::RefCounted<RenderWidget>,
143 public MainThreadEventQueueClient {
initial.commit09911bf2008-07-26 23:55:29144 public:
danakjdf1ceb72018-07-18 20:02:25145 using ShowCallback =
146 base::OnceCallback<void(RenderWidget* widget_to_show,
147 blink::WebNavigationPolicy policy,
148 const gfx::Rect& initial_rect)>;
149
danakj53802692018-07-25 21:46:44150 // Time-To-First-Active-Paint(TTFAP) type
151 enum {
152 TTFAP_AFTER_PURGED,
153 TTFAP_5MIN_AFTER_BACKGROUNDED,
154 };
155
nickf7b38222016-11-22 21:59:35156 // Creates a new RenderWidget for a popup. |opener| is the RenderView that
157 // this widget lives inside.
Hajime Hoshiabb3c8f2017-12-04 18:41:39158 static RenderWidget* CreateForPopup(
159 RenderViewImpl* opener,
160 CompositorDependencies* compositor_deps,
161 blink::WebPopupType popup_type,
162 const ScreenInfo& screen_info,
163 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
initial.commit09911bf2008-07-26 23:55:29164
kenrba7199832015-01-22 23:44:59165 // Creates a new RenderWidget that will be attached to a RenderFrame.
nick4df698d82016-11-11 20:39:23166 static RenderWidget* CreateForFrame(int widget_routing_id,
kenrba7199832015-01-22 23:44:59167 bool hidden,
ccameron2f451532016-09-07 21:49:27168 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59169 CompositorDependencies* compositor_deps,
170 blink::WebLocalFrame* frame);
171
lfg1568d112016-08-30 16:06:29172 // Used by content_layouttest_support to hook into the creation of
173 // RenderWidgets.
nick8331f8ad2016-11-15 20:42:45174 using CreateRenderWidgetFunction = RenderWidget* (*)(int32_t,
175 CompositorDependencies*,
176 blink::WebPopupType,
Scott Violetae08f332018-07-27 17:37:23177 const ScreenInfo&,
nick8331f8ad2016-11-15 20:42:45178 bool,
179 bool,
180 bool);
lfg1568d112016-08-30 16:06:29181 using RenderWidgetInitializedCallback = void (*)(RenderWidget*);
182 static void InstallCreateHook(
183 CreateRenderWidgetFunction create_render_widget,
184 RenderWidgetInitializedCallback render_widget_initialized_callback);
185
danakj53802692018-07-25 21:46:44186 void set_owner_delegate(RenderWidgetOwnerDelegate* owner_delegate) {
187 DCHECK(!owner_delegate_);
188 owner_delegate_ = owner_delegate;
189 }
190 RenderWidgetOwnerDelegate* owner_delegate() const { return owner_delegate_; }
191
Albert J. Wongcb004632018-07-10 22:58:25192 // Returns the RenderWidget for the given routing ID.
193 static RenderWidget* FromRoutingID(int32_t routing_id);
194
dchengda9b4bb2015-07-20 20:58:08195 // Closes a RenderWidget that was created by |CreateForFrame|.
danakja2c9d0a92018-07-25 20:01:18196 void CloseForFrame();
[email protected]484955942010-08-19 16:13:18197
nick8331f8ad2016-11-15 20:42:45198 int32_t routing_id() const { return routing_id_; }
fsamuele8326c742016-01-12 00:49:39199
danakj6e3bf8012014-12-16 18:27:53200 CompositorDependencies* compositor_deps() const { return compositor_deps_; }
Ken Buchananed449bb2018-02-01 21:02:05201
202 // This can return nullptr while the RenderWidget is closing.
danakja2c9d0a92018-07-25 20:01:18203 blink::WebWidget* GetWebWidget() const;
ekaramad2daaf672016-11-10 20:29:01204
205 // Returns the current instance of WebInputMethodController which is to be
206 // used for IME related tasks. This instance corresponds to the one from
207 // focused frame and can be nullptr.
208 blink::WebInputMethodController* GetInputMethodController() const;
209
mfomitchev2600fd7c2016-02-17 20:53:39210 const gfx::Size& size() const { return size_; }
Christopher Cameron58089372018-03-08 23:11:13211 const gfx::Size& compositor_viewport_pixel_size() const {
Christopher Cameronaad15a0d2018-03-09 03:47:33212 return compositor_viewport_pixel_size_;
Christopher Cameron58089372018-03-08 23:11:13213 }
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12214 bool is_fullscreen_granted() const { return is_fullscreen_granted_; }
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12215 blink::WebDisplayMode display_mode() const { return display_mode_; }
[email protected]204f1df2012-01-04 20:21:13216 bool is_hidden() const { return is_hidden_; }
[email protected]4ee64622014-03-21 22:34:15217 // Temporary for debugging purposes...
218 bool closing() const { return closing_; }
pwnallef669312017-01-07 01:17:29219 bool has_host_context_menu_location() const {
[email protected]be1af0662014-07-29 19:55:51220 return has_host_context_menu_location_;
221 }
pwnallef669312017-01-07 01:17:29222 gfx::Point host_context_menu_location() const {
[email protected]be1af0662014-07-29 19:55:51223 return host_context_menu_location_;
[email protected]4ee64622014-03-21 22:34:15224 }
Ken Buchananb2c9e262018-03-10 16:53:31225 const gfx::Size& visible_viewport_size() const {
226 return visible_viewport_size_;
227 }
[email protected]589621b2010-09-23 22:01:07228
danakj53802692018-07-25 21:46:44229 ScreenInfo screen_info() const { return screen_info_; }
230 void set_screen_info(const ScreenInfo& info) { screen_info_ = info; }
avi40b5be7a2016-03-03 21:13:44231
alexmos78c9c0d2016-10-14 18:57:03232 // Sets whether this RenderWidget has been swapped out to be displayed by
233 // a RenderWidget in a different process. If so, no new IPC messages will be
234 // sent (only ACKs) and the process is free to exit when there are no other
235 // active RenderWidgets.
236 void SetSwappedOut(bool is_swapped_out);
pwnallef669312017-01-07 01:17:29237 bool is_swapped_out() const { return is_swapped_out_; }
alexmos78c9c0d2016-10-14 18:57:03238
alexmos56567492016-09-13 00:52:46239 // Manage edit commands to be used for the next keyboard event.
240 const EditCommands& edit_commands() const { return edit_commands_; }
241 void SetEditCommandForNextKeyEvent(const std::string& name,
242 const std::string& value);
243 void ClearEditCommands();
244
[email protected]bffc8302014-01-23 20:52:16245 // Functions to track out-of-process frames for special notifications.
[email protected]e3244ed2014-06-20 20:04:27246 void RegisterRenderFrameProxy(RenderFrameProxy* proxy);
247 void UnregisterRenderFrameProxy(RenderFrameProxy* proxy);
[email protected]bffc8302014-01-23 20:52:16248
[email protected]de3c5d82014-05-28 22:12:59249 // Functions to track all RenderFrame objects associated with this
250 // RenderWidget.
251 void RegisterRenderFrame(RenderFrameImpl* frame);
252 void UnregisterRenderFrame(RenderFrameImpl* frame);
253
Saman Samid189e5dfd2017-12-20 22:55:31254 // BrowserPlugins embedded by this RenderWidget register themselves here.
255 // These plugins need to be notified about changes to ScreenInfo.
256 void RegisterBrowserPlugin(BrowserPlugin* browser_plugin);
257 void UnregisterBrowserPlugin(BrowserPlugin* browser_plugin);
258
[email protected]c47317e2012-06-20 22:35:31259 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52260 bool OnMessageReceived(const IPC::Message& msg) override;
initial.commit09911bf2008-07-26 23:55:29261
[email protected]c47317e2012-06-20 22:35:31262 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52263 bool Send(IPC::Message* msg) override;
initial.commit09911bf2008-07-26 23:55:29264
danakja6c10012018-07-06 14:25:36265 // LayerTreeViewDelegate
fsamuel78f86e42016-01-20 04:10:23266 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
267 const gfx::Vector2dF& outer_delta,
268 const gfx::Vector2dF& elastic_overscroll_delta,
269 float page_scale,
270 float top_controls_delta) override;
sahel1b47fda72017-03-28 17:03:07271 void RecordWheelAndTouchScrollingCount(bool has_scrolled_by_wheel,
272 bool has_scrolled_by_touch) override;
Daniel Cheng224569ee2018-04-25 05:45:06273 void BeginMainFrame(base::TimeTicks frame_time) override;
danakjc7afae52017-06-20 21:12:41274 void RequestNewLayerTreeFrameSink(
danakja6c10012018-07-06 14:25:36275 LayerTreeFrameSinkCallback callback) override;
fsamuel78f86e42016-01-20 04:10:23276 void DidCommitAndDrawCompositorFrame() override;
277 void DidCommitCompositorFrame() override;
278 void DidCompletePageScaleAnimation() override;
danakj6c872fc02016-10-22 04:29:49279 void DidReceiveCompositorFrameAck() override;
fsamuel78f86e42016-01-20 04:10:23280 bool IsClosing() const override;
danakj53eccbc2016-03-02 22:51:07281 void RequestScheduleAnimation() override;
Eric Seckler8af8c0e52018-01-17 23:45:53282 void UpdateVisualState(VisualStateUpdate requested_update) override;
fsamuel78f86e42016-01-20 04:10:23283 void WillBeginCompositorFrame() override;
jbroman6ccbc7d472016-07-27 04:45:41284 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:04285 std::unique_ptr<viz::CopyOutputRequest> request) override;
fsamuel78f86e42016-01-20 04:10:23286
fsamuel72464894f2015-12-15 06:59:31287 // RenderWidgetInputHandlerDelegate
288 void FocusChangeComplete() override;
Sandra Sunac5cdd832017-12-11 03:27:13289 void ObserveGestureEventAndResult(
290 const blink::WebGestureEvent& gesture_event,
291 const gfx::Vector2dF& unused_delta,
292 const cc::OverscrollBehavior& overscroll_behavior,
293 bool event_processed) override;
dtapuska1827dd22016-03-11 15:24:59294
fsamuel72464894f2015-12-15 06:59:31295 void OnDidHandleKeyEvent() override;
chongza8ba91fc2016-08-16 21:39:17296 void OnDidOverscroll(const ui::DidOverscrollParams& params) override;
fsamuele8326c742016-01-12 00:49:39297 void SetInputHandler(RenderWidgetInputHandler* input_handler) override;
changwan75e3b2072017-01-16 02:55:00298 void ShowVirtualKeyboard() override;
299 void UpdateTextInputState() override;
changwan62f57292017-02-17 08:28:25300 void ClearTextInputState() override;
fsamuel72464894f2015-12-15 06:59:31301 bool WillHandleGestureEvent(const blink::WebGestureEvent& event) override;
302 bool WillHandleMouseEvent(const blink::WebMouseEvent& event) override;
303
Scott Violet1098538e2017-10-05 19:23:33304 // RenderWidgetScreenMetricsEmulatorDelegate
mfomitchev2600fd7c2016-02-17 20:53:39305 void Redraw() override;
Fady Samuel799e72192018-04-25 21:16:57306 void SynchronizeVisualProperties(
307 const VisualProperties& resize_params) override;
mfomitchev2600fd7c2016-02-17 20:53:39308 void SetScreenMetricsEmulationParameters(
309 bool enabled,
310 const blink::WebDeviceEmulationParams& params) override;
311 void SetScreenRects(const gfx::Rect& view_screen_rect,
312 const gfx::Rect& window_screen_rect) override;
313
[email protected]180ef242013-11-07 06:50:46314 // blink::WebWidgetClient
Blink Reformat1c4d759e2017-04-09 16:34:54315 blink::WebLayerTreeView* InitializeLayerTreeView() override;
Chris Harrelsond7ab99b2018-01-24 17:51:36316 void IntrinsicSizingInfoChanged(
317 const blink::WebIntrinsicSizingInfo&) override;
Blink Reformat1c4d759e2017-04-09 16:34:54318 void DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) override;
319 void DidChangeCursor(const blink::WebCursorInfo&) override;
aelias5971e47d2017-06-16 02:39:38320 void AutoscrollStart(const blink::WebFloatPoint& point) override;
321 void AutoscrollFling(const blink::WebFloatSize& velocity) override;
322 void AutoscrollEnd() override;
Blink Reformat1c4d759e2017-04-09 16:34:54323 void CloseWidgetSoon() override;
324 void Show(blink::WebNavigationPolicy) override;
325 blink::WebRect WindowRect() override;
326 blink::WebRect ViewRect() override;
327 void SetToolTipText(const blink::WebString& text,
avi5c77d212015-09-25 20:08:25328 blink::WebTextDirection hint) override;
Blink Reformat1c4d759e2017-04-09 16:34:54329 void SetWindowRect(const blink::WebRect&) override;
330 blink::WebScreenInfo GetScreenInfo() override;
331 void DidHandleGestureEvent(const blink::WebGestureEvent& event,
avi5c77d212015-09-25 20:08:25332 bool event_cancelled) override;
Blink Reformat1c4d759e2017-04-09 16:34:54333 void DidOverscroll(const blink::WebFloatSize& overscrollDelta,
bokane53a10f2016-04-13 23:48:31334 const blink::WebFloatSize& accumulatedOverscroll,
avi5c77d212015-09-25 20:08:25335 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:54336 const blink::WebFloatSize& velocity,
danakje819b622018-05-01 20:27:14337 const cc::OverscrollBehavior& behavior) override;
Blink Reformat1c4d759e2017-04-09 16:34:54338 void ShowVirtualKeyboardOnElementFocus() override;
339 void ConvertViewportToWindow(blink::WebRect* rect) override;
340 void ConvertWindowToViewport(blink::WebFloatRect* rect) override;
341 bool RequestPointerLock() override;
342 void RequestPointerUnlock() override;
343 bool IsPointerLocked() override;
344 void StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:58345 const blink::WebDragData& data,
346 blink::WebDragOperationsMask mask,
danakj0c75ad82018-07-10 19:50:12347 const SkBitmap& drag_image,
348 const blink::WebPoint& image_offset) override;
danakj53802692018-07-25 21:46:44349 void SetTouchAction(cc::TouchAction touch_action) override;
350 void RequestUnbufferedInputEvents() override;
351 void HasTouchEventHandlers(bool has_handlers) override;
352 void SetNeedsLowLatencyInput(bool) override;
[email protected]4873c7d2009-07-16 06:36:28353
fsamuel72464894f2015-12-15 06:59:31354 // Override point to obtain that the current input method state and caret
355 // position.
danakja2c9d0a92018-07-25 20:01:18356 ui::TextInputType GetTextInputType();
fsamuel72464894f2015-12-15 06:59:31357
danakj4b347212018-07-04 17:55:17358 // Internal helper that generates the LayerTreeSettings to be given to the
359 // compositor in StartCompositor().
360 static cc::LayerTreeSettings GenerateLayerTreeSettings(
361 CompositorDependencies* compositor_deps,
362 bool is_for_subframe,
363 const gfx::Size& initial_screen_size,
364 float initial_device_scale_factor);
365 // Internal helper that generates the ManagedMemoryPolicy to be given to the
366 // compositor in StartCompositor().
367 static cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
368 const cc::ManagedMemoryPolicy& policy,
369 const gfx::Size& initial_screen_size,
370 float initial_device_scale_factor);
371
[email protected]7912e822014-04-16 02:37:03372 // Begins the compositor's scheduler to start producing frames.
373 void StartCompositor();
374
[email protected]aeeedad2014-08-22 18:16:22375 // Stop compositing.
ennef3c58142014-12-09 21:44:38376 void WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:22377
danakja6c10012018-07-06 14:25:36378 LayerTreeView* layer_tree_view() const { return layer_tree_view_.get(); }
Dave Tapuska9db80842017-07-24 17:24:26379 WidgetInputHandlerManager* widget_input_handler_manager() {
380 return widget_input_handler_manager_.get();
381 }
fsamuel72464894f2015-12-15 06:59:31382 const RenderWidgetInputHandler& input_handler() const {
fsamuele8326c742016-01-12 00:49:39383 return *input_handler_;
fsamuel72464894f2015-12-15 06:59:31384 }
385
danakj53802692018-07-25 21:46:44386 void SetHandlingInputEvent(bool handling_input_event);
387
[email protected]586871b2014-07-22 17:05:11388 // Deliveres |message| together with compositor state change updates. The
389 // exact behavior depends on |policy|.
390 // This mechanism is not a drop-in replacement for IPC: messages sent this way
391 // will not be automatically available to BrowserMessageFilter, for example.
392 // FIFO ordering is preserved between messages enqueued with the same
393 // |policy|, the ordering between messages enqueued for different policies is
394 // undefined.
395 //
396 // |msg| message to send, ownership of |msg| is transferred.
397 // |policy| see the comment on MessageDeliveryPolicy.
398 void QueueMessage(IPC::Message* msg, MessageDeliveryPolicy policy);
399
changwanf2a707b2015-10-30 08:22:16400 // Handle start and finish of IME event guard.
401 void OnImeEventGuardStart(ImeEventGuard* guard);
402 void OnImeEventGuardFinish(ImeEventGuard* guard);
[email protected]66fca5bc2013-05-23 06:58:29403
danakj53802692018-07-25 21:46:44404 void ApplyEmulatedScreenMetricsForPopupWidget(RenderWidget* origin_widget);
[email protected]b2e4c70132013-10-03 02:07:51405
[email protected]2d6836f42014-07-02 17:25:31406 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51407
[email protected]7a4e2532013-12-02 21:30:02408 // Checks if the selection bounds have been changed. If they are changed,
409 // the new value will be sent to the browser process.
410 void UpdateSelectionBounds();
411
danakja2c9d0a92018-07-25 20:01:18412 void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end);
[email protected]e5e438d62014-03-27 21:47:16413
[email protected]a09d53ce2014-01-31 00:46:42414 void OnShowHostContextMenu(ContextMenuParams* params);
[email protected]7a4e2532013-12-02 21:30:02415
[email protected]7a4e2532013-12-02 21:30:02416 // Checks if the composition range or composition character bounds have been
417 // changed. If they are changed, the new value will be sent to the browser
yukawa5f21c6a2014-10-27 17:09:30418 // process. This method does nothing when the browser process is not able to
419 // handle composition range and composition character bounds.
nonafa291792016-08-10 02:36:18420 // If immediate_request is true, render sends the latest composition info to
421 // the browser even if the composition info is not changed.
422 void UpdateCompositionInfo(bool immediate_request);
[email protected]7a4e2532013-12-02 21:30:02423
danakja2c9d0a92018-07-25 20:01:18424 // Override point to obtain that the current composition character bounds.
425 // In the case of surrogate pairs, the character is treated as two characters:
426 // the bounds for first character is actual one, and the bounds for second
427 // character is zero width rectangle.
428 void GetCompositionCharacterBounds(std::vector<gfx::Rect>* character_bounds);
429
lfgb00fcad2016-07-14 14:16:33430 // Called when the Widget has changed size as a result of an auto-resize.
431 void DidAutoResize(const gfx::Size& new_size);
432
Albert J. Wongcb004632018-07-10 22:58:25433 void DidPresentForceDrawFrame(int snapshot_id,
434 const gfx::PresentationFeedback& feedback);
435
lfge0c2792ec2016-05-11 18:52:08436 // Indicates whether this widget has focus.
437 bool has_focus() const { return has_focus_; }
438
pwnallef669312017-01-07 01:17:29439 MouseLockDispatcher* mouse_lock_dispatcher() const {
lfgbee1e0a2016-06-08 21:24:21440 return mouse_lock_dispatcher_.get();
441 }
442
Fady Samuela863f152018-03-09 16:10:03443 // Returns the ScreenInfo exposed to Blink. In device emulation, this
444 // may not match the compositor ScreenInfo.
445 const ScreenInfo& GetWebScreenInfo() const;
Christopher Camerone9a30c12018-03-07 08:23:38446
Fady Samuela863f152018-03-09 16:10:03447 // When emulated, this returns the original (non-emulated) ScreenInfo.
448 const ScreenInfo& GetOriginalScreenInfo() const;
lfg1f9011c2016-08-17 21:18:42449
paulmeyer90f6c31d2016-11-12 00:17:59450 // Helper to convert |point| using ConvertWindowToViewport().
Ella Ge80a52dce2017-11-15 18:01:52451 gfx::PointF ConvertWindowPointToViewport(const gfx::PointF& point);
paulmeyer90f6c31d2016-11-12 00:17:59452 gfx::Point ConvertWindowPointToViewport(const gfx::Point& point);
kenrb5d78b842017-03-06 21:06:01453 uint32_t GetContentSourceId();
Saman Samif7731342018-01-24 22:18:44454 void DidNavigate();
kenrb5d78b842017-03-06 21:06:01455
Fady Samuele62be402018-03-29 03:19:53456 bool auto_resize_mode() const { return auto_resize_mode_; }
457
Fady Samuele62be402018-03-29 03:19:53458 const gfx::Size& min_size_for_auto_resize() const {
459 return min_size_for_auto_resize_;
460 }
461
462 const gfx::Size& max_size_for_auto_resize() const {
463 return max_size_for_auto_resize_;
464 }
Vladimir Levin98d76dad2018-04-21 00:21:29465
466 uint32_t capture_sequence_number() const {
467 return last_capture_sequence_number_;
468 }
469
dtapuska9ec1a912017-04-21 15:18:31470 // MainThreadEventQueueClient overrides.
471
472 // Requests a BeginMainFrame callback from the compositor.
473 void SetNeedsMainFrame() override;
474
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27475 viz::FrameSinkId GetFrameSinkIdAtPoint(const gfx::Point& point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22476
Dave Tapuskaea83d3bd2017-06-13 16:14:55477 void HandleInputEvent(const blink::WebCoalescedInputEvent& input_event,
478 const ui::LatencyInfo& latency_info,
479 HandledEventCallback callback) override;
Dave Tapuska139a72f2017-09-06 21:57:03480
481 void SetupWidgetInputHandler(mojom::WidgetInputHandlerRequest request,
482 mojom::WidgetInputHandlerHostPtr host) override;
dtapuska9ec1a912017-04-21 15:18:31483
dtapuska9d46ef7d2017-05-26 19:06:06484 scoped_refptr<MainThreadEventQueue> GetInputEventQueue();
485
Albert J. Wongcb004632018-07-10 22:58:25486 void OnSetActive(bool active);
danakja2c9d0a92018-07-25 20:01:18487 void OnSetFocus(bool enable);
Albert J. Wongcb004632018-07-10 22:58:25488 void OnSetBackgroundOpaque(bool opaque);
Dave Tapuska9db80842017-07-24 17:24:26489 void OnMouseCaptureLost();
490 void OnCursorVisibilityChange(bool is_visible);
491 void OnSetEditCommandsForNextKeyEvent(const EditCommands& edit_commands);
492 void OnImeSetComposition(
493 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:11494 const std::vector<blink::WebImeTextSpan>& ime_text_spans,
Dave Tapuska9db80842017-07-24 17:24:26495 const gfx::Range& replacement_range,
496 int selection_start,
497 int selection_end);
Ryan Landay9e42fd742017-08-12 01:59:11498 void OnImeCommitText(const base::string16& text,
499 const std::vector<blink::WebImeTextSpan>& ime_text_spans,
500 const gfx::Range& replacement_range,
501 int relative_cursor_pos);
Dave Tapuska9db80842017-07-24 17:24:26502 void OnImeFinishComposingText(bool keep_selection);
503
danakja2c9d0a92018-07-25 20:01:18504 // This does the actual focus change, but is called in more situations than
505 // just as an IPC message.
506 void SetFocus(bool enable);
507
Dave Tapuska9db80842017-07-24 17:24:26508 // Called by the browser process to update text input state.
509 void OnRequestTextInputStateUpdate();
510
511 // Called by the browser process to update the cursor and composition
Dave Tapuska04bc5ee92018-04-17 19:03:31512 // information by sending WidgetInputHandlerHost::ImeCompositionRangeChanged.
513 // If |immediate_request| is true, an IPC is sent back with current state.
Dave Tapuska9db80842017-07-24 17:24:26514 // When |monitor_update| is true, then RenderWidget will send the updates
515 // in each compositor frame when there are changes. Outside of compositor
516 // frame updates, a change in text selection might also lead to an update for
517 // composition info (when in monitor mode).
518 void OnRequestCompositionUpdates(bool immediate_request,
519 bool monitor_updates);
Dave Tapuska485aca92017-08-08 00:47:58520 void SetWidgetBinding(mojom::WidgetRequest request);
Dave Tapuska9db80842017-07-24 17:24:26521
Ken Buchanan94c0beb62018-06-22 19:56:24522 void SetMouseCapture(bool capture);
523
danakj53802692018-07-25 21:46:44524 void SetWindowScreenRect(const gfx::Rect& window_screen_rect);
Takashi SAKAMOTO870f6262017-08-22 04:08:27525
Fady Samuelca9ecb72018-05-05 05:59:27526 bool IsSurfaceSynchronizationEnabled() const;
527
danakj53802692018-07-25 21:46:44528 void UseSynchronousResizeModeForTesting(bool enable);
danakja2c9d0a92018-07-25 20:01:18529 void SetDeviceScaleFactorForTesting(float factor);
530 void SetDeviceColorSpaceForTesting(const gfx::ColorSpace& color_space);
531 void SetWindowRectSynchronouslyForTesting(const gfx::Rect& new_window_rect);
532 void EnableAutoResizeForTesting(const gfx::Size& min_size,
533 const gfx::Size& max_size);
534 void DisableAutoResizeForTesting(const gfx::Size& new_size);
535
Saman Sami50d1e0c2018-03-13 20:03:49536 base::WeakPtr<RenderWidget> AsWeakPtr();
537
initial.commit09911bf2008-07-26 23:55:29538 protected:
nick8331f8ad2016-11-15 20:42:45539 RenderWidget(int32_t widget_routing_id,
540 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36541 blink::WebPopupType popup_type,
Scott Violetae08f332018-07-27 17:37:23542 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04543 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03544 bool hidden,
Dave Tapuska1bdf1832017-07-07 18:07:19545 bool never_visible,
Hajime Hoshiabb3c8f2017-12-04 18:41:39546 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
Dave Tapuska1bdf1832017-07-07 18:07:19547 mojom::WidgetRequest widget_request = nullptr);
[email protected]ce2b28e2012-08-09 15:53:57548
danakja2c9d0a92018-07-25 20:01:18549 // Avoid making RenderWidget other than as a refptr.
dcheng6d18e402014-10-21 12:32:52550 ~RenderWidget() override;
initial.commit09911bf2008-07-26 23:55:29551
lfgcaab5142016-02-26 19:06:52552 static blink::WebFrameWidget* CreateWebFrameWidget(
danakj9a8a9cf2018-07-17 23:52:12553 blink::WebWidgetClient* widget_client,
lfgcaab5142016-02-26 19:06:52554 blink::WebLocalFrame* frame);
dchengda9b4bb2015-07-20 20:58:08555
556 // Creates a WebWidget based on the popup type.
557 static blink::WebWidget* CreateWebWidget(RenderWidget* render_widget);
558
nick4df698d82016-11-11 20:39:23559 // Called by Create() functions and subclasses to finish initialization.
danakj53802692018-07-25 21:46:44560 // |show_callback| will be invoked once WebWidgetClient::Show() occurs, and
561 // should be null if Show() won't be triggered for this widget.
Scott Violetae08f332018-07-27 17:37:23562 void Init(ShowCallback show_callback, blink::WebWidget* web_widget);
[email protected]484955942010-08-19 16:13:18563
danakj53802692018-07-25 21:46:44564 // Initialization methods used by the RenderViewImpl subclass.
565 //
danakja2c9d0a92018-07-25 20:01:18566 // Idle user detector is optionally set up and destroyed during
567 // initialization/teardown.
568 void SetUpIdleUserDetector();
danakj53802692018-07-25 21:46:44569 // Update the web view's device scale factor.
570 void UpdateWebViewWithDeviceScaleFactor();
Scott Violetae08f332018-07-27 17:37:23571 // Set the display mode during initialization.
572 void set_display_mode(blink::WebDisplayMode mode) { display_mode_ = mode; }
danakj53802692018-07-25 21:46:44573 // Informs that Show() will not happen.
574 void set_did_show() { did_show_ = true; }
575
576 // Close the underlying WebWidget and stop the compositor.
577 virtual void Close();
578
579 // Notify subclasses that we initiated the paint operation.
580 virtual void DidInitiatePaint() {}
581
582 // Gets the current URL or a placeholder constant for creating 3d contexts and
583 // attributing them back to a URL.
584 virtual GURL GetURLForGraphicsContext3D();
585
586 // RenderWidget IPC message handler that can be overridden by subclasses.
587 virtual void OnSynchronizeVisualProperties(const VisualProperties& params);
588
589#if defined(OS_MACOSX)
590 // On MacOSX this message arrives on RenderViewImpl instead of here, and it
591 // needs to be able to call back to the normal message handler here.
592 void OnClose();
593#endif
594
595 private:
596 // Friend RefCounted so that the dtor can be non-public. Using this class
597 // without ref-counting is an error.
598 friend class base::RefCounted<RenderWidget>;
599
600 // TODO(nasko): Temporarily friend RenderFrameImpl for WasSwappedOut(),
601 // while we move frame specific code away from RenderViewImpl/RenderWidget.
602 friend class RenderFrameImpl;
603
604 // For unit tests.
605 friend class InteractiveRenderWidget;
606 friend class PopupRenderWidget;
607 friend class QueueMessageSwapPromiseTest;
608 friend class RenderWidgetTest;
609 friend class RenderViewImplTest;
610 FRIEND_TEST_ALL_PREFIXES(RenderWidgetPopupUnittest, EmulatingPopupRect);
danakja2c9d0a92018-07-25 20:01:18611
[email protected]949b6592014-08-20 13:17:52612 // Allows the process to exit once the unload handler has finished, if there
613 // are no other active RenderWidgets.
614 void WasSwappedOut();
615
[email protected]2533ce12009-05-09 00:02:24616 void DoDeferredClose();
dgozmancf9039cd2015-04-06 12:01:31617 void NotifyOnClose();
dchengda9b4bb2015-07-20 20:58:08618
bokanc63441c2016-04-27 15:49:12619 gfx::Size GetSizeForWebWidget() const;
danakja2c9d0a92018-07-25 20:01:18620 void ResizeWebWidget();
bokanc63441c2016-04-27 15:49:12621
Ken Buchananed449bb2018-02-01 21:02:05622 // Just Close the WebWidget, in cases where the Close() will be deferred.
623 // It is safe to call this multiple times, which happens in the case of
624 // frame widgets beings closed, since subsequent calls are ignored.
625 void CloseWebWidget();
626
thakis18e426412017-03-15 12:06:37627#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51628 void SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39629 ExternalPopupMenu* popup,
630 RenderWidgetScreenMetricsEmulator* emulator);
[email protected]53907862014-03-25 15:42:40631#endif
[email protected]61e2b3cc2012-03-02 16:13:34632
danakj53802692018-07-25 21:46:44633 // RenderWidget IPC message handlers.
nzolghadr5d8596502017-01-23 22:59:35634 void OnHandleInputEvent(
635 const blink::WebInputEvent* event,
636 const std::vector<const blink::WebInputEvent*>& coalesced_events,
637 const ui::LatencyInfo& latency_info,
638 InputEventDispatchType dispatch_type);
danakj53802692018-07-25 21:46:44639#if !defined(OS_MACOSX)
naskoc288745f2015-05-01 22:54:21640 void OnClose();
danakj53802692018-07-25 21:46:44641#endif
[email protected]fc4404d2012-11-07 19:53:30642 void OnCreatingNewAck();
dgozman9260b0a12015-03-16 13:45:20643 void OnEnableDeviceEmulation(const blink::WebDeviceEmulationParams& params);
644 void OnDisableDeviceEmulation();
danakja2c9d0a92018-07-25 20:01:18645 void OnWasHidden();
646 void OnWasShown(bool needs_repainting,
647 base::TimeTicks show_request_timestamp);
avi1023d012015-12-25 02:39:14648 void OnCreateVideoAck(int32_t video_id);
649 void OnUpdateVideoAck(int32_t video_id);
Avi Drissman014dec72018-06-07 02:34:01650 void OnRequestSetBoundsAck();
Albert J. Wongcb004632018-07-10 22:58:25651 void OnForceRedraw(int snapshot_id);
danakja2c9d0a92018-07-25 20:01:18652 void OnShowContextMenu(ui::MenuSourceType source_type,
653 const gfx::Point& location);
oshimad5279032015-12-16 18:22:33654
[email protected]180ef242013-11-07 06:50:46655 void OnSetTextDirection(blink::WebTextDirection direction);
[email protected]872ae5b2011-05-26 20:20:50656 void OnGetFPS();
[email protected]80ad8622012-11-07 16:33:03657 void OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
658 const gfx::Rect& window_screen_rect);
Ken Buchananb2c9e262018-03-10 16:53:31659 void OnSetViewportIntersection(const gfx::Rect& viewport_intersection,
660 const gfx::Rect& compositor_visible_rect);
kenrb04323782017-06-23 01:23:32661 void OnSetIsInert(bool);
sunxd540a9962018-05-24 22:51:06662 void OnSetInheritedEffectiveTouchAction(cc::TouchAction touch_action);
Ken Buchanan8a319fb2017-11-15 18:37:12663 void OnUpdateRenderThrottlingStatus(bool is_throttled,
664 bool subtree_throttled);
paulmeyer90f6c31d2016-11-12 00:17:59665 void OnDragTargetDragEnter(
666 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:52667 const gfx::PointF& client_pt,
668 const gfx::PointF& screen_pt,
paulmeyer90f6c31d2016-11-12 00:17:59669 blink::WebDragOperationsMask operations_allowed,
670 int key_modifiers);
Ella Ge80a52dce2017-11-15 18:01:52671 void OnDragTargetDragOver(const gfx::PointF& client_pt,
672 const gfx::PointF& screen_pt,
paulmeyer90f6c31d2016-11-12 00:17:59673 blink::WebDragOperationsMask operations_allowed,
674 int key_modifiers);
Ella Ge80a52dce2017-11-15 18:01:52675 void OnDragTargetDragLeave(const gfx::PointF& client_point,
676 const gfx::PointF& screen_point);
paulmeyer90f6c31d2016-11-12 00:17:59677 void OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:52678 const gfx::PointF& client_pt,
679 const gfx::PointF& screen_pt,
paulmeyer90f6c31d2016-11-12 00:17:59680 int key_modifiers);
Ella Ge80a52dce2017-11-15 18:01:52681 void OnDragSourceEnded(const gfx::PointF& client_point,
682 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:21683 blink::WebDragOperation drag_operation);
684 void OnDragSourceSystemDragEnded();
lfg8d649cc2017-04-28 18:04:30685 void OnOrientationChange();
danakj53802692018-07-25 21:46:44686 void OnWaitNextFrameForTests(int routing_id);
[email protected]65225772011-05-12 21:10:24687
[email protected]bee16aab2009-08-26 15:55:03688 // Sets the "hidden" state of this widget. All accesses to is_hidden_ should
689 // use this method so that we can properly inform the RenderThread of our
690 // state.
691 void SetHidden(bool hidden);
692
[email protected]2b624c562011-10-27 22:58:26693 void DidToggleFullscreen();
694
Ken Buchananb2c9e262018-03-10 16:53:31695 // Returns a rect that the compositor needs to raster. For a main frame this
696 // is always the entire viewprot, but for out-of-process iframes this can be
697 // constrained to limit overdraw.
698 gfx::Rect ViewportVisibleRect();
699
[email protected]586871b2014-07-22 17:05:11700 // QueueMessage implementation extracted into a static method for easy
701 // testing.
dchengcedca5612016-04-09 01:40:15702 static std::unique_ptr<cc::SwapPromise> QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:11703 IPC::Message* msg,
704 MessageDeliveryPolicy policy,
705 FrameSwapMessageQueue* frame_swap_message_queue,
706 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:11707 int source_frame_number);
708
[email protected]88dbe32f2013-06-20 23:31:36709 // Returns the range of the text that is being composed or the selection if
710 // the composition does not exist.
danakja2c9d0a92018-07-25 20:01:18711 void GetCompositionRange(gfx::Range* range);
[email protected]88dbe32f2013-06-20 23:31:36712
[email protected]58b48a0d2012-06-13 07:01:35713 // Returns true if the composition range or composition character bounds
714 // should be sent to the browser process.
715 bool ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:51716 const gfx::Range& range,
[email protected]58b48a0d2012-06-13 07:01:35717 const std::vector<gfx::Rect>& bounds);
718
[email protected]ad26ef42011-06-17 07:59:45719 // Override point to obtain that the current input method state about
720 // composition text.
danakja2c9d0a92018-07-25 20:01:18721 bool CanComposeInline();
[email protected]56ea1a62011-05-30 07:05:57722
[email protected]2533ce12009-05-09 00:02:24723 // Set the pending window rect.
724 // Because the real render_widget is hosted in another process, there is
725 // a time period where we may have set a new window rect which has not yet
726 // been processed by the browser. So we maintain a pending window rect
727 // size. If JS code sets the WindowRect, and then immediately calls
728 // GetWindowRect() we'll use this pending window rect as the size.
[email protected]180ef242013-11-07 06:50:46729 void SetPendingWindowRect(const blink::WebRect& r);
[email protected]2533ce12009-05-09 00:02:24730
danakj53802692018-07-25 21:46:44731 // TODO(ekaramad): This method should not be confused with its RenderView
732 // variant, GetWebFrameWidget(). Currently Cast and AndroidWebview's
733 // ContentRendererClients are the only users of the public variant. The public
734 // method will eventually be removed from RenderView and uses of the method
735 // will obtain WebFrameWidget from WebLocalFrame.
736 // Returns the WebFrameWidget associated with this RenderWidget if any.
737 // Returns nullptr if GetWebWidget() returns nullptr or returns a WebWidget
738 // that is not a WebFrameWidget. A WebFrameWidget only makes sense when there
739 // a local root associated with it. RenderWidgetFullscreenPepper and a swapped
740 // out RenderWidgets are amongst the cases where this method returns nullptr.
741 blink::WebFrameWidget* GetFrameWidget() const;
[email protected]ce6689f2013-03-29 12:52:55742
danakj53802692018-07-25 21:46:44743 // Applies/Removes the DevTools device emulation transformation to/from a
744 // window rect.
745 void ScreenRectToEmulatedIfNeeded(blink::WebRect* window_rect) const;
746 void EmulatedToScreenRectIfNeeded(blink::WebRect* window_rect) const;
Dave Tapuskadfe486c12017-06-09 16:53:13747
danakj53802692018-07-25 21:46:44748 bool CreateWidget(int32_t opener_id,
749 blink::WebPopupType popup_type,
750 int32_t* routing_id);
Dave Tapuskabafc2ba32017-11-28 01:54:37751
danakj53802692018-07-25 21:46:44752 void UpdateSurfaceAndScreenInfo(
753 const viz::LocalSurfaceId& new_local_surface_id,
754 const gfx::Size& new_compositor_viewport_pixel_size,
755 const ScreenInfo& new_screen_info);
[email protected]5d0bbdfa92013-12-10 00:35:51756
danakj53802692018-07-25 21:46:44757 // Used to force the size of a window when running layout tests.
758 void SetWindowRectSynchronously(const gfx::Rect& new_window_rect);
759
760 void UpdateCaptureSequenceNumber(uint32_t capture_sequence_number);
761
762 // A variant of Send but is fatal if it fails. The browser may
763 // be waiting for this IPC Message and if the send fails the browser will
764 // be left in a state waiting for something that never comes. And if it
765 // never comes then it may later determine this is a hung renderer; so
766 // instead fail right away.
767 void SendOrCrash(IPC::Message* msg);
768
769 // Determines whether or not RenderWidget should process IME events from the
770 // browser. It always returns true unless there is no WebFrameWidget to
771 // handle the event, or there is no page focus.
772 bool ShouldHandleImeEvents() const;
773
774 void UpdateTextInputStateInternal(bool show_virtual_keyboard,
775 bool reply_to_request);
776
777 gfx::ColorSpace GetRasterColorSpace() const;
778
779 void SendInputEventAck(blink::WebInputEvent::Type type,
780 uint32_t touch_event_id,
781 InputEventAckState ack_state,
782 const ui::LatencyInfo& latency_info,
783 std::unique_ptr<ui::DidOverscrollParams>,
784 base::Optional<cc::TouchAction>);
785
786 void UpdateZoom(double zoom_level);
787
788#if BUILDFLAG(ENABLE_PLUGINS)
789 // Returns the focused pepper plugin, if any, inside the WebWidget. That is
790 // the pepper plugin which is focused inside a frame which belongs to the
791 // local root associated with this RenderWidget.
792 PepperPluginInstanceImpl* GetFocusedPepperPluginInsideWidget();
793#endif
794 void RecordTimeToFirstActivePaint();
795
796 // Updates the URL used by the compositor for keying UKM metrics.
797 // Note that this uses the main frame's URL and only if its available in the
798 // current process. In the case where it is not available, no metrics will be
799 // recorded.
800 void UpdateURLForCompositorUkm();
801
802 // This method returns the WebLocalFrame which is currently focused and
803 // belongs to the frame tree associated with this RenderWidget.
804 blink::WebLocalFrame* GetFocusedWebLocalFrameInWidget() const;
lfg43e08e62016-02-03 18:51:37805
initial.commit09911bf2008-07-26 23:55:29806 // Routing ID that allows us to communicate to the parent browser process
nick8331f8ad2016-11-15 20:42:45807 // RenderWidgetHost.
808 const int32_t routing_id_;
initial.commit09911bf2008-07-26 23:55:29809
danakj6e3bf8012014-12-16 18:27:53810 // Dependencies for initializing a compositor, including flags for optional
811 // features.
dcheng35d31c112015-07-22 00:17:36812 CompositorDependencies* const compositor_deps_;
danakj6e3bf8012014-12-16 18:27:53813
lfg8ff33912016-09-13 20:59:21814 // Use GetWebWidget() instead of using webwidget_internal_ directly.
[email protected]c5b3b5e2009-02-13 06:41:11815 // We are responsible for destroying this object via its Close method.
[email protected]4ee64622014-03-21 22:34:15816 // May be NULL when the window is closing.
lfg8ff33912016-09-13 20:59:21817 blink::WebWidget* webwidget_internal_;
initial.commit09911bf2008-07-26 23:55:29818
avi40b5be7a2016-03-03 21:13:44819 // The delegate of the owner of this object.
820 RenderWidgetOwnerDelegate* owner_delegate_;
821
[email protected]8926c602013-01-23 05:32:06822 // This is lazily constructed and must not outlive webwidget_.
danakja6c10012018-07-06 14:25:36823 std::unique_ptr<LayerTreeView> layer_tree_view_;
[email protected]8926c602013-01-23 05:32:06824
bokanc007c3a2015-02-03 07:15:56825 // The rect where this view should be initially shown.
826 gfx::Rect initial_rect_;
initial.commit09911bf2008-07-26 23:55:29827
initial.commit09911bf2008-07-26 23:55:29828 // We store the current cursor object so we can avoid spamming SetCursor
829 // messages.
830 WebCursor current_cursor_;
[email protected]88efb7ec2009-07-14 16:32:59831
danakja2c9d0a92018-07-25 20:01:18832 base::Optional<float> device_scale_factor_for_testing_;
833
Christopher Cameronbe7ecea2018-02-27 00:47:19834 // The size of the RenderWidget in DIPs. This may differ from
Christopher Cameronaad15a0d2018-03-09 03:47:33835 // |compositor_viewport_pixel_size_| in the following (and possibly other)
836 // cases: * On Android, for top and bottom controls * On OOPIF, due to
837 // rounding
initial.commit09911bf2008-07-26 23:55:29838 gfx::Size size_;
839
Christopher Cameronbe7ecea2018-02-27 00:47:19840 // The size of the compositor's surface in pixels.
Christopher Cameronaad15a0d2018-03-09 03:47:33841 gfx::Size compositor_viewport_pixel_size_;
[email protected]60d47ac2013-03-01 23:42:44842
Christopher Cameronbe7ecea2018-02-27 00:47:19843 // The size of the visible viewport in pixels.
[email protected]bb6378fe2014-04-28 21:19:44844 gfx::Size visible_viewport_size_;
845
[email protected]847a2582013-03-09 02:29:51846 // Whether the WebWidget is in auto resize mode, which is used for example
847 // by extension popups.
848 bool auto_resize_mode_;
849
Fady Samuele62be402018-03-29 03:19:53850 // The minimum size to use for auto-resize.
851 gfx::Size min_size_for_auto_resize_;
852
853 // The maximum size to use for auto-resize.
854 gfx::Size max_size_for_auto_resize_;
855
initial.commit09911bf2008-07-26 23:55:29856 // Set to true if we should ignore RenderWidget::Show calls.
857 bool did_show_;
858
859 // Indicates that we shouldn't bother generated paint events.
860 bool is_hidden_;
861
[email protected]7912e822014-04-16 02:37:03862 // Indicates that we are never visible, so never produce graphical output.
sievers71c62dd52015-10-07 01:44:39863 const bool compositor_never_visible_;
[email protected]7912e822014-04-16 02:37:03864
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12865 // Indicates whether tab-initiated fullscreen was granted.
866 bool is_fullscreen_granted_;
[email protected]ee41e7d22011-10-14 19:34:09867
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12868 // Indicates the display mode.
869 blink::WebDisplayMode display_mode_;
870
changwanf2a707b2015-10-30 08:22:16871 // It is possible that one ImeEventGuard is nested inside another
872 // ImeEventGuard. We keep track of the outermost one, and update it as needed.
873 ImeEventGuard* ime_event_guard_;
[email protected]e8f775f2013-02-14 21:00:50874
initial.commit09911bf2008-07-26 23:55:29875 // True if we have requested this widget be closed. No more messages will
876 // be sent, except for a Close.
877 bool closing_;
878
[email protected]aeeedad2014-08-22 18:16:22879 // True if it is known that the host is in the process of being shut down.
880 bool host_closing_;
881
[email protected]992db4c2011-05-12 15:37:15882 // Whether this RenderWidget is currently swapped out, such that the view is
883 // being rendered by another process. If all RenderWidgets in a process are
884 // swapped out, the process can exit.
885 bool is_swapped_out_;
886
[email protected]5b739cb2012-08-21 20:35:21887 // Stores information about the current text input.
[email protected]180ef242013-11-07 06:50:46888 blink::WebTextInputInfo text_input_info_;
[email protected]5b739cb2012-08-21 20:35:21889
dglazkov97b6c2b2016-10-25 17:35:55890 // Stores the current text input type of |webwidget_|.
891 ui::TextInputType text_input_type_;
892
[email protected]b256eca2013-07-11 10:57:40893 // Stores the current text input mode of |webwidget_|.
894 ui::TextInputMode text_input_mode_;
895
shuchen82ce8c52014-10-23 01:55:20896 // Stores the current text input flags of |webwidget_|.
897 int text_input_flags_;
898
AJITH KUMAR V041c0b02017-08-08 10:39:20899 // Indicates whether currently focused input field has next/previous focusable
900 // form input field.
901 int next_previous_flags_;
902
[email protected]86ba5fcb2013-09-04 00:36:53903 // Stores the current type of composition text rendering of |webwidget_|.
904 bool can_compose_inline_;
905
[email protected]e99ef6f2011-10-16 01:13:00906 // Stores the current selection bounds.
[email protected]7c8873e2013-02-05 08:03:01907 gfx::Rect selection_focus_rect_;
908 gfx::Rect selection_anchor_rect_;
initial.commit09911bf2008-07-26 23:55:29909
[email protected]58b48a0d2012-06-13 07:01:35910 // Stores the current composition character bounds.
911 std::vector<gfx::Rect> composition_character_bounds_;
912
913 // Stores the current composition range.
[email protected]db4fc1e2013-09-06 20:01:51914 gfx::Range composition_range_;
[email protected]58b48a0d2012-06-13 07:01:35915
[email protected]3e2b375b2010-04-07 17:03:12916 // The kind of popup this widget represents, NONE if not a popup.
[email protected]180ef242013-11-07 06:50:46917 blink::WebPopupType popup_type_;
[email protected]0ebf3872008-11-07 21:35:03918
[email protected]80ad8622012-11-07 16:33:03919 // While we are waiting for the browser to update window sizes, we track the
920 // pending size temporarily.
[email protected]2533ce12009-05-09 00:02:24921 int pending_window_rect_count_;
lfg0140a452016-07-19 19:15:05922 gfx::Rect pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:24923
[email protected]80ad8622012-11-07 16:33:03924 // The screen rects of the view and the window that contains it.
925 gfx::Rect view_screen_rect_;
926 gfx::Rect window_screen_rect_;
927
Dave Tapuska9db80842017-07-24 17:24:26928 scoped_refptr<WidgetInputHandlerManager> widget_input_handler_manager_;
929
dchengcedca5612016-04-09 01:40:15930 std::unique_ptr<RenderWidgetInputHandler> input_handler_;
[email protected]12fbad812009-09-01 18:21:24931
[email protected]fd847792013-10-24 17:12:35932 // The time spent in input handlers this frame. Used to throttle input acks.
933 base::TimeDelta total_input_handling_time_this_frame_;
934
[email protected]842f10652012-06-06 01:54:04935 // Properties of the screen hosting this RenderWidget instance.
ccameron2f451532016-09-07 21:49:27936 ScreenInfo screen_info_;
[email protected]842f10652012-06-06 01:54:04937
nonafa291792016-08-10 02:36:18938 // True if the IME requests updated composition info.
939 bool monitor_composition_info_;
940
dchengcedca5612016-04-09 01:40:15941 std::unique_ptr<RenderWidgetScreenMetricsEmulator> screen_metrics_emulator_;
[email protected]b2e4c70132013-10-03 02:07:51942
943 // Popups may be displaced when screen metrics emulation is enabled.
944 // These values are used to properly adjust popup position.
danakj2ef31b82015-10-21 18:18:02945 gfx::Point popup_view_origin_for_emulation_;
946 gfx::Point popup_screen_origin_for_emulation_;
[email protected]b2e4c70132013-10-03 02:07:51947 float popup_origin_scale_for_emulation_;
948
[email protected]586871b2014-07-22 17:05:11949 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue_;
dchengcedca5612016-04-09 01:40:15950 std::unique_ptr<ResizingModeSelector> resizing_mode_selector_;
[email protected]5b45ad42013-10-25 00:42:04951
[email protected]e3244ed2014-06-20 20:04:27952 // Lists of RenderFrameProxy objects that need to be notified of
953 // compositing-related events (e.g. DidCommitCompositorFrame).
brettw236d3172015-06-03 16:31:43954 base::ObserverList<RenderFrameProxy> render_frame_proxies_;
[email protected]bffc8302014-01-23 20:52:16955
[email protected]de3c5d82014-05-28 22:12:59956 // A list of RenderFrames associated with this RenderWidget. Notifications
957 // are sent to each frame in the list for events such as changing
958 // visibility state for example.
brettw236d3172015-06-03 16:31:43959 base::ObserverList<RenderFrameImpl> render_frames_;
[email protected]de3c5d82014-05-28 22:12:59960
Saman Samid189e5dfd2017-12-20 22:55:31961 base::ObserverList<BrowserPlugin> browser_plugins_;
962
[email protected]be1af0662014-07-29 19:55:51963 bool has_host_context_menu_location_;
964 gfx::Point host_context_menu_location_;
[email protected]a09d53ce2014-01-31 00:46:42965
Yuta Kitamura39219b42018-04-06 10:28:14966 std::unique_ptr<blink::scheduler::WebRenderWidgetSchedulingState>
alexclarke7fa93942015-10-21 15:37:11967 render_widget_scheduling_state_;
968
lfgbee1e0a2016-06-08 21:24:21969 // Mouse Lock dispatcher attached to this view.
970 std::unique_ptr<RenderWidgetMouseLockDispatcher> mouse_lock_dispatcher_;
971
972 // Wraps the |webwidget_| as a MouseLockDispatcher::LockTarget interface.
973 std::unique_ptr<MouseLockDispatcher::LockTarget> webwidget_mouse_lock_target_;
974
Fady Samuel4255c182018-05-24 20:42:36975 viz::LocalSurfaceId local_surface_id_from_parent_;
Fady Samuelda839bb2018-03-26 17:34:48976
lfge0c2792ec2016-05-11 18:52:08977 // Indicates whether this widget has focus.
978 bool has_focus_;
979
Nicolas Pena75a35d662018-04-05 20:13:44980 // Whether this RenderWidget is for an out-of-process iframe or not.
981 bool for_oopif_;
982
nickf7b38222016-11-22 21:59:35983 // A callback into the creator/opener of this widget, to be executed when
danakjdf1ceb72018-07-18 20:02:25984 // WebWidgetClient::Show() occurs.
nickf7b38222016-11-22 21:59:35985 ShowCallback show_callback_;
986
ekaramad330ba4232016-09-23 17:57:47987#if defined(OS_MACOSX)
988 // Responds to IPCs from TextInputClientMac regarding getting string at given
989 // position or range as well as finding character index at a given position.
990 std::unique_ptr<TextInputClientObserver> text_input_client_observer_;
991#endif
992
alexmos56567492016-09-13 00:52:46993 // Stores edit commands associated to the next key event.
994 // Will be cleared as soon as the next key event is processed.
995 EditCommands edit_commands_;
996
paulmeyer6ef5a792016-11-08 20:33:58997 // This field stores drag/drop related info for the event that is currently
998 // being handled. If the current event results in starting a drag/drop
999 // session, this info is sent to the browser along with other drag/drop info.
1000 DragEventSourceInfo possible_drag_event_info_;
1001
Takashi SAKAMOTO870f6262017-08-22 04:08:271002 bool first_update_visual_state_after_hidden_;
tasakb95dbb50c2017-02-08 18:07:501003 base::TimeTicks was_shown_time_;
1004
danakja2c9d0a92018-07-25 20:01:181005 // Whether or not Blink's viewport size should be shrunk by the height of the
1006 // URL-bar.
1007 bool browser_controls_shrink_blink_size_ = false;
1008 // The height of the browser top controls.
1009 float top_controls_height_ = 0.f;
1010 // The height of the browser bottom controls.
1011 float bottom_controls_height_ = 0.f;
1012
kenrb5d78b842017-03-06 21:06:011013 // This is initialized to zero and is incremented on each non-same-page
1014 // navigation commit by RenderFrameImpl. At that time it is sent to the
1015 // compositor so that it can tag compositor frames, and RenderFrameImpl is
1016 // responsible for sending it to the browser process to be used to match
1017 // each compositor frame to the most recent page navigation before it was
1018 // generated.
1019 // This only applies to main frames, and is not touched for subframe
1020 // RenderWidgets, where there is no concern around displaying unloaded
1021 // content.
1022 // TODO(kenrb, fsamuel): This should be removed when SurfaceIDs can be used
1023 // to replace it. See https://crbug.com/695579.
1024 uint32_t current_content_source_id_;
1025
dtapuska9ec1a912017-04-21 15:18:311026 scoped_refptr<MainThreadEventQueue> input_event_queue_;
1027
Dave Tapuska1bdf1832017-07-07 18:07:191028 mojo::Binding<mojom::Widget> widget_binding_;
Hajime Hoshiabb3c8f2017-12-04 18:41:391029 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
danakja2c9d0a92018-07-25 20:01:181030 // IdleUserDetector is setup optionally on RenderWidget by its creator, so may
1031 // be null.
1032 std::unique_ptr<IdleUserDetector> idle_user_detector_;
Hajime Hoshiabb3c8f2017-12-04 18:41:391033
Ken Buchananb2c9e262018-03-10 16:53:311034 gfx::Rect compositor_visible_rect_;
1035
W. James MacLean662d5382018-03-29 18:33:081036 // Different consumers in the browser process makes different assumptions, so
1037 // must always send the first IPC regardless of value.
1038 base::Optional<bool> has_touch_handlers_;
1039
Vladimir Levin98d76dad2018-04-21 00:21:291040 uint32_t last_capture_sequence_number_ = 0u;
1041
wjmaclean1d970622017-01-21 22:28:241042 base::WeakPtrFactory<RenderWidget> weak_ptr_factory_;
1043
[email protected]05d478752009-04-08 23:38:161044 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
initial.commit09911bf2008-07-26 23:55:291045};
1046
[email protected]e9ff79c2012-10-19 21:31:261047} // namespace content
1048
[email protected]2cff0052011-03-18 16:51:441049#endif // CONTENT_RENDERER_RENDER_WIDGET_H_