blob: 5c88ddbd892699b4613bec13e1befe2d05bc662b [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// 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#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
danakj4b347212018-07-04 17:55:177#include <cmath>
8#include <limits>
dchengcedca5612016-04-09 01:40:159#include <memory>
dcheng07945f632015-12-26 07:59:3210#include <utility>
11
[email protected]c27dd4f2014-05-22 18:05:1912#include "base/auto_reset.h"
danakj4b347212018-07-04 17:55:1713#include "base/base_switches.h"
[email protected]32876ae2011-11-15 22:25:2114#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0015#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1216#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/logging.h"
avi1023d012015-12-25 02:39:1418#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1519#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4020#include "base/memory/singleton.h"
asvitkine8d51e9d2016-09-02 23:55:4321#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2122#include "base/stl_util.h"
danakj4b347212018-07-04 17:55:1723#include "base/strings/string_number_conversions.h"
[email protected]74ebfb12013-06-07 20:48:0024#include "base/strings/utf_string_conversions.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0325#include "base/system/sys_info.h"
fdoraya19b7702016-12-23 14:19:3126#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0127#include "base/trace_event/trace_event.h"
[email protected]661eb9d2009-02-03 02:11:4828#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0329#include "cc/animation/animation_host.h"
danakj4b347212018-07-04 17:55:1730#include "cc/base/switches.h"
xidachenfa0199e72017-05-11 11:34:2631#include "cc/input/touch_action.h"
danakjba65a0912017-09-21 16:38:4232#include "cc/trees/layer_tree_frame_sink.h"
loyso6e6efc42017-01-21 02:23:0333#include "cc/trees/layer_tree_host.h"
danakj4c987652018-07-05 15:49:4134#include "cc/trees/ukm_manager.h"
danakj4b347212018-07-04 17:55:1735#include "components/viz/common/features.h"
Fady Samuelc645ffe2017-07-24 17:28:2036#include "components/viz/common/frame_sinks/begin_frame_source.h"
danakjf20f4502017-09-26 17:13:3137#include "components/viz/common/frame_sinks/copy_output_request.h"
danakj4b347212018-07-04 17:55:1738#include "components/viz/common/switches.h"
39#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5840#include "content/common/drag_event_source_info.h"
41#include "content/common/drag_messages.h"
jonrossa2ff4f82018-02-16 17:27:4642#include "content/common/render_frame_metadata.mojom.h"
jcivelliae1560a2016-11-01 22:40:2343#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4244#include "content/common/swapped_out_messages.h"
Sadrul Habib Chowdhury8bc43cc2018-06-06 01:48:0345#include "content/common/tab_switching_time_callback.h"
ekaramad9053e57b2016-04-26 20:00:3846#include "content/common/text_input_state.h"
Albert J. Wong3c93c182018-09-27 17:29:4347#include "content/common/widget_messages.h"
mlamouriafca06dd2017-01-27 23:35:1848#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1249#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2950#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4251#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5952#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5053#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3954#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1855#include "content/public/renderer/content_renderer_client.h"
Saman Samid189e5dfd2017-12-20 22:55:3156#include "content/renderer/browser_plugin/browser_plugin.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1357#include "content/renderer/compositor/layer_tree_view.h"
[email protected]953bd0062013-08-01 00:58:4058#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3959#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5860#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5161#include "content/renderer/external_popup_menu.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1362#include "content/renderer/frame_swap_message_queue.h"
[email protected]66fca5bc2013-05-23 06:58:2963#include "content/renderer/ime_event_guard.h"
dtapuska9ec1a912017-04-21 15:18:3164#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2665#include "content/renderer/input/widget_input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3266#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
Sadrul Habib Chowdhury31c98712018-12-11 04:15:1367#include "content/renderer/queue_message_swap_promise.h"
[email protected]bffc8302014-01-23 20:52:1668#include "content/renderer/render_frame_impl.h"
danakj4b347212018-07-04 17:55:1769#include "content/renderer/render_frame_metadata_observer_impl.h"
[email protected]e3244ed2014-06-20 20:04:2770#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0571#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4472#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5573#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0974#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0475#include "content/renderer/resizing_mode_selector.h"
danakj4b347212018-07-04 17:55:1776#include "gpu/command_buffer/service/gpu_switches.h"
ekaramad330ba4232016-09-23 17:57:4777#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1878#include "ipc/ipc_sync_message.h"
Antoine Laboure55c9ef82017-11-10 18:51:2379#include "ipc/ipc_sync_message_filter.h"
danakj4b347212018-07-04 17:55:1780#include "media/base/media_switches.h"
Scott Violet02e38b92018-03-27 23:42:1481#include "ppapi/buildflags/buildflags.h"
[email protected]661eb9d2009-02-03 02:11:4882#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0683#include "third_party/blink/public/platform/file_path_conversion.h"
Hajime Hoshi315a61f2018-08-14 17:27:2884#include "third_party/blink/public/platform/platform.h"
Blink Reformata30d4232018-04-07 15:31:0685#include "third_party/blink/public/platform/scheduler/web_render_widget_scheduling_state.h"
Yuta Kitamuradeb91bb2018-05-29 05:53:2086#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
Blink Reformata30d4232018-04-07 15:31:0687#include "third_party/blink/public/platform/web_cursor_info.h"
88#include "third_party/blink/public/platform/web_drag_data.h"
89#include "third_party/blink/public/platform/web_drag_operation.h"
90#include "third_party/blink/public/platform/web_mouse_event.h"
91#include "third_party/blink/public/platform/web_point.h"
92#include "third_party/blink/public/platform/web_rect.h"
93#include "third_party/blink/public/platform/web_runtime_features.h"
94#include "third_party/blink/public/platform/web_size.h"
95#include "third_party/blink/public/platform/web_string.h"
96#include "third_party/blink/public/web/web_autofill_client.h"
97#include "third_party/blink/public/web/web_device_emulation_params.h"
98#include "third_party/blink/public/web/web_frame_widget.h"
99#include "third_party/blink/public/web/web_input_method_controller.h"
100#include "third_party/blink/public/web/web_local_frame.h"
101#include "third_party/blink/public/web/web_node.h"
102#include "third_party/blink/public/web/web_page_popup.h"
103#include "third_party/blink/public/web/web_popup_menu_info.h"
104#include "third_party/blink/public/web/web_range.h"
105#include "third_party/blink/public/web/web_settings.h"
106#include "third_party/blink/public/web/web_view.h"
107#include "third_party/blink/public/web/web_widget.h"
[email protected]d353541f2012-05-03 22:45:41108#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:59109#include "ui/base/clipboard/clipboard.h"
Scott Violet8ff9c302018-02-22 22:28:35110#include "ui/base/ui_base_features.h"
danakj4b347212018-07-04 17:55:17111#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:43112#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50113#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09114#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32115#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48116#include "ui/gfx/skia_util.h"
danakj4b347212018-07-04 17:55:17117#include "ui/gfx/switches.h"
[email protected]c9e2cbbb2012-05-12 21:17:27118#include "ui/gl/gl_switches.h"
danakj4b347212018-07-04 17:55:17119#include "ui/native_theme/native_theme_features.h"
120#include "ui/native_theme/overlay_scrollbar_constants_aura.h"
[email protected]d353541f2012-05-03 22:45:41121#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48122
[email protected]eeb93112013-05-01 19:41:10123#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15124#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24125#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10126#endif
127
[email protected]661eb9d2009-02-03 02:11:48128#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52129#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41130#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48131#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44132
sadrul943e3b32016-08-04 18:22:59133#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10134#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19135#endif
136
ekaramad330ba4232016-09-23 17:57:47137#if defined(OS_MACOSX)
138#include "content/renderer/text_input_client_observer.h"
139#endif
140
Ryan Landay9e42fd742017-08-12 01:59:11141using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46142using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43143using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59144using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58145using blink::WebDragOperationsMask;
146using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59147using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46148using blink::WebGestureEvent;
149using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49150using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01151using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58152using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46153using blink::WebMouseEvent;
154using blink::WebMouseWheelEvent;
155using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11156using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46157using blink::WebPagePopup;
dglazkove353a372016-09-01 01:33:48158using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46159using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46160using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59161using blink::WebString;
[email protected]180ef242013-11-07 06:50:46162using blink::WebTextDirection;
163using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25164using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46165using blink::WebVector;
166using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26167
paulmeyer90f6c31d2016-11-12 00:17:59168namespace content {
169
[email protected]6a4d7f62013-01-07 21:32:13170namespace {
[email protected]b256eca2013-07-11 10:57:40171
Albert J. Wongcb004632018-07-10 22:58:25172using RoutingIDWidgetMap = std::map<int32_t, RenderWidget*>;
173base::LazyInstance<RoutingIDWidgetMap>::Leaky g_routing_id_widget_map =
174 LAZY_INSTANCE_INITIALIZER;
175
danakj4b347212018-07-04 17:55:17176const base::Feature kUnpremultiplyAndDitherLowBitDepthTiles = {
177 "UnpremultiplyAndDitherLowBitDepthTiles", base::FEATURE_ENABLED_BY_DEFAULT};
178
[email protected]b256eca2013-07-11 10:57:40179typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
180
AJITH KUMAR V041c0b02017-08-08 10:39:20181static const int kInvalidNextPreviousFlagsValue = -1;
yiyix6b90ef52018-10-09 19:55:30182static const char* kOOPIF = "OOPIF";
183static const char* kRenderer = "Renderer";
AJITH KUMAR V041c0b02017-08-08 10:39:20184
lfgbee1e0a2016-06-08 21:24:21185class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
186 public:
187 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
188 : webwidget_(webwidget) {}
189
190 void OnLockMouseACK(bool succeeded) override {
191 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54192 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21193 else
Blink Reformat1c4d759e2017-04-09 16:34:54194 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21195 }
196
Blink Reformat1c4d759e2017-04-09 16:34:54197 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21198
199 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
200 // The WebWidget handles mouse lock in Blink's handleInputEvent().
201 return false;
202 }
203
204 private:
205 blink::WebWidget* webwidget_;
206};
207
dglazkov97b6c2b2016-10-25 17:35:55208bool IsDateTimeInput(ui::TextInputType type) {
209 return type == ui::TEXT_INPUT_TYPE_DATE ||
210 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
211 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
212 type == ui::TEXT_INPUT_TYPE_MONTH ||
213 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
214}
215
paulmeyer90f6c31d2016-11-12 00:17:59216WebDragData DropMetaDataToWebDragData(
217 const std::vector<DropData::Metadata>& drop_meta_data) {
218 std::vector<WebDragData::Item> item_list;
219 for (const auto& meta_data_item : drop_meta_data) {
220 if (meta_data_item.kind == DropData::Kind::STRING) {
221 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54222 item.storage_type = WebDragData::Item::kStorageTypeString;
223 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59224 // Have to pass a dummy URL here instead of an empty URL because the
225 // DropData received by browser_plugins goes through a round trip:
226 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
227 // will contain an empty URL (which means no URL is dragged) if the URL in
228 // WebDragData is empty.
229 if (base::EqualsASCII(meta_data_item.mime_type,
230 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54231 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59232 }
233 item_list.push_back(item);
234 continue;
235 }
236
237 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
238 // just the mimetype. This is needed to drag files to WebView on Android
239 // platform.
240 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
241 !meta_data_item.filename.empty()) {
242 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54243 item.storage_type = WebDragData::Item::kStorageTypeFilename;
244 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59245 item_list.push_back(item);
246 continue;
247 }
248
249 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
250 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54251 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
252 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59253 item_list.push_back(item);
254 continue;
255 }
256 }
257
258 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54259 result.Initialize();
260 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59261 return result;
262}
263
264WebDragData DropDataToWebDragData(const DropData& drop_data) {
265 std::vector<WebDragData::Item> item_list;
266
267 // These fields are currently unused when dragging into WebKit.
268 DCHECK(drop_data.download_metadata.empty());
269 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23270 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59271
272 if (!drop_data.text.is_null()) {
273 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54274 item.storage_type = WebDragData::Item::kStorageTypeString;
275 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
276 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59277 item_list.push_back(item);
278 }
279
280 if (!drop_data.url.is_empty()) {
281 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54282 item.storage_type = WebDragData::Item::kStorageTypeString;
283 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
284 item.string_data = WebString::FromUTF8(drop_data.url.spec());
285 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59286 item_list.push_back(item);
287 }
288
289 if (!drop_data.html.is_null()) {
290 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54291 item.storage_type = WebDragData::Item::kStorageTypeString;
292 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
293 item.string_data = WebString::FromUTF16(drop_data.html.string());
294 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59295 item_list.push_back(item);
296 }
297
jdoerrie5a73d0fa2018-10-02 23:54:05298 for (auto it = drop_data.filenames.begin(); it != drop_data.filenames.end();
paulmeyer90f6c31d2016-11-12 00:17:59299 ++it) {
300 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54301 item.storage_type = WebDragData::Item::kStorageTypeFilename;
302 item.filename_data = blink::FilePathToWebString(it->path);
303 item.display_name_data =
kinukoa4293022017-01-27 06:43:25304 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59305 item_list.push_back(item);
306 }
307
jdoerrie5a73d0fa2018-10-02 23:54:05308 for (auto it = drop_data.file_system_files.begin();
309 it != drop_data.file_system_files.end(); ++it) {
paulmeyer90f6c31d2016-11-12 00:17:59310 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54311 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
312 item.file_system_url = it->url;
313 item.file_system_file_size = it->size;
314 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59315 item_list.push_back(item);
316 }
317
Stuart Langley48300392017-11-02 03:54:44318 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59319 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54320 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44321 item.string_type = WebString::FromUTF16(it.first);
322 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59323 item_list.push_back(item);
324 }
325
326 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54327 result.Initialize();
328 result.SetItems(item_list);
329 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59330 return result;
331}
332
dtapuskac4dd5be2016-10-25 15:11:10333ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
334 // Check the type is in the range representable by ui::TextInputType.
335 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
336 << "blink::WebTextInputType and ui::TextInputType not synchronized";
337 return static_cast<ui::TextInputType>(type);
338}
339
340ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
341 // Check the mode is in the range representable by ui::TextInputMode.
342 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
343 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
344 return static_cast<ui::TextInputMode>(mode);
345}
346
Mitsuru Oshima3c07b332018-02-06 04:56:50347// Returns true if the device scale is high enough that losing subpixel
348// antialiasing won't have a noticeable effect on text quality.
349static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
350#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
351 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
352 // composite all scrollers so that we get animated overlay scrollbars.
353 return true;
354#else
355 // 1.5 is a common touchscreen tablet device scale factor. For such
356 // devices main thread antialiasing is a heavy burden.
357 return device_scale_factor >= 1.5f;
358#endif
359}
360
361static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
362 float device_scale_factor) {
363 const base::CommandLine& command_line =
364 *base::CommandLine::ForCurrentProcess();
365 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
366 return false;
367 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
368 return true;
369 if (!compositor_deps->IsLcdTextEnabled())
370 return true;
371 return DeviceScaleEnsuresTextQuality(device_scale_factor);
372}
373
[email protected]b256eca2013-07-11 10:57:40374} // namespace
375
[email protected]b2e4c70132013-10-03 02:07:51376// RenderWidget ---------------------------------------------------------------
377
danakj829cdd142018-09-14 21:13:27378RenderWidget::RenderWidget(int32_t widget_routing_id,
379 CompositorDependencies* compositor_deps,
danakj829cdd142018-09-14 21:13:27380 const ScreenInfo& screen_info,
381 blink::WebDisplayMode display_mode,
danakj6dcbc5962018-11-16 16:45:42382 bool is_frozen,
danakj829cdd142018-09-14 21:13:27383 bool hidden,
384 bool never_visible,
385 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45386 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36387 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21388 webwidget_internal_(nullptr),
[email protected]847a2582013-03-09 02:29:51389 auto_resize_mode_(false),
[email protected]1ac10dca2013-08-20 20:47:04390 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39391 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12392 is_fullscreen_granted_(false),
danakj73dd3032018-07-28 17:49:53393 display_mode_(display_mode),
changwanf2a707b2015-10-30 08:22:16394 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48395 closing_(false),
danakj5c5269b2018-11-06 00:39:11396 host_will_close_this_(false),
danakj6dcbc5962018-11-16 16:45:42397 is_frozen_(is_frozen),
dglazkov97b6c2b2016-10-25 17:35:55398 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40399 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20400 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20401 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53402 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18403 composition_range_(gfx::Range::InvalidRange()),
[email protected]867125a02009-12-10 06:01:48404 pending_window_rect_count_(0),
Scott Violetae08f332018-07-27 17:37:23405 screen_info_(screen_info),
nonafa291792016-08-10 02:36:18406 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51407 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12408 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42409 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08410 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09411 has_focus_(false),
danakj6dcbc5962018-11-16 16:45:42412 for_child_local_root_frame_(false),
ekaramad330ba4232016-09-23 17:57:47413#if defined(OS_MACOSX)
414 text_input_client_observer_(new TextInputClientObserver(this)),
415#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27416 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50417 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01418 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19419 widget_binding_(this, std::move(widget_request)),
danakjf87460792018-12-04 20:14:22420 warmup_weak_ptr_factory_(this),
wjmaclean1d970622017-01-21 22:28:24421 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45422 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]380244092011-10-07 17:26:27423 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11424
425 // In tests there may not be a RenderThreadImpl.
426 if (RenderThreadImpl::current()) {
427 render_widget_scheduling_state_ = RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:25428 ->GetWebMainThreadScheduler()
dcheng07945f632015-12-26 07:59:32429 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11430 render_widget_scheduling_state_->SetHidden(is_hidden_);
431 }
sadrul602ce1362017-01-26 06:41:10432#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14433 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Scott Violete46b3352018-09-22 00:37:07434 if (features::IsMultiProcessMash())
Scott Violet1098538e2017-10-05 19:23:33435 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10436#endif
Albert J. Wongcb004632018-07-10 22:58:25437
438 if (routing_id_ != MSG_ROUTING_NONE)
439 g_routing_id_widget_map.Get().emplace(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29440}
441
442RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21443 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
Albert J. Wong7bbf22d2018-12-20 00:27:27444
Albert J. Wongcb004632018-07-10 22:58:25445 // TODO(ajwong): Add in check that routing_id_ has been removed from
446 // g_routing_id_widget_map once the shutdown semantics for RenderWidget
447 // and RenderViewImpl are rationalized. Currently, too many unit and
448 // browser tests delete a RenderWidget without correclty going through
449 // the shutdown. https://crbug.com/545684
[email protected]bffc8302014-01-23 20:52:16450
dtapuska9ec1a912017-04-21 15:18:31451 if (input_event_queue_)
452 input_event_queue_->ClearClient();
453
sadrul8185d972017-01-31 18:30:11454#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14455 // It is possible for a RenderWidget to be destroyed before it was embedded
456 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
457 // explicitly delete it here.
458 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11459#endif
initial.commit09911bf2008-07-26 23:55:29460}
461
[email protected]484955942010-08-19 16:13:18462// static
Albert J. Wongcb004632018-07-10 22:58:25463RenderWidget* RenderWidget::FromRoutingID(int32_t routing_id) {
464 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
jdoerrie5a73d0fa2018-10-02 23:54:05465 auto it = widgets->find(routing_id);
Albert J. Wongcb004632018-07-10 22:58:25466 return it == widgets->end() ? NULL : it->second;
467}
468
danakj25ec6e2b2018-09-26 17:01:31469void RenderWidget::InitForPopup(ShowCallback show_callback,
470 blink::WebPagePopup* web_page_popup) {
471 // Init() increments the reference count on |this|, making it
472 // self-referencing.
473 Init(std::move(show_callback), web_page_popup);
initial.commit09911bf2008-07-26 23:55:29474}
475
danakj6a816592018-09-25 18:30:56476void RenderWidget::InitForChildLocalRoot(
477 blink::WebFrameWidget* web_frame_widget) {
danakj6dcbc5962018-11-16 16:45:42478 for_child_local_root_frame_ = true;
danakj6a816592018-09-25 18:30:56479 // Init() increments the reference count on |this|, making it
480 // self-referencing.
481 Init(base::NullCallback(), web_frame_widget);
dchengda9b4bb2015-07-20 20:58:08482}
483
dchengda9b4bb2015-07-20 20:58:08484void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32485 OnClose();
kenrba7199832015-01-22 23:44:59486}
487
Scott Violetae08f332018-07-27 17:37:23488void RenderWidget::Init(ShowCallback show_callback, WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21489 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23490 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29491
danakj17216f4d2018-10-16 22:57:32492 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
493
Jeremy Roman04f27c372017-10-27 15:20:55494 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45495
danakj17216f4d2018-10-16 22:57:32496 LayerTreeView* layer_tree_view = InitializeLayerTreeView();
497 web_widget->SetLayerTreeView(layer_tree_view);
Dave Tapuska9db80842017-07-24 17:24:26498
danakj31699d5b2018-09-18 15:39:17499 blink::scheduler::WebThreadScheduler* main_thread_scheduler = nullptr;
500 if (render_thread_impl)
501 main_thread_scheduler = render_thread_impl->GetWebMainThreadScheduler();
Alexander Timin41e917d2018-07-02 16:25:35502 blink::scheduler::WebThreadScheduler* compositor_thread_scheduler =
503 blink::scheduler::WebThreadScheduler::CompositorThreadScheduler();
danakj31699d5b2018-09-18 15:39:17504 scoped_refptr<base::SingleThreadTaskRunner> compositor_input_task_runner;
danakj89ae4532018-12-12 22:52:55505 // Use the compositor thread task runner unless this is a popup or other such
506 // non-frame widgets. The |compositor_thread_scheduler| can be null in tests
507 // without a compositor thread.
508 if (for_frame() && compositor_thread_scheduler) {
509 compositor_input_task_runner =
510 compositor_thread_scheduler->InputTaskRunner();
danakj31699d5b2018-09-18 15:39:17511 }
Alexander Timin41e917d2018-07-02 16:25:35512
Dave Tapuska04bc5ee92018-04-17 19:03:31513 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
danakj31699d5b2018-09-18 15:39:17514 weak_ptr_factory_.GetWeakPtr(), std::move(compositor_input_task_runner),
515 main_thread_scheduler);
Dave Tapuska9db80842017-07-24 17:24:26516
danakjdf1ceb72018-07-18 20:02:25517 show_callback_ = std::move(show_callback);
initial.commit09911bf2008-07-26 23:55:29518
lfg8ff33912016-09-13 20:59:21519 webwidget_internal_ = web_widget;
520 webwidget_mouse_lock_target_.reset(
521 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21522 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29523
nick4df698d82016-11-11 20:39:23524 RenderThread::Get()->AddRoute(routing_id_, this);
525 // Take a reference on behalf of the RenderThread. This will be balanced
Albert J. Wong3c93c182018-09-27 17:29:43526 // when we receive WidgetMsg_Close.
nick4df698d82016-11-11 20:39:23527 AddRef();
528 if (RenderThreadImpl::current()) {
529 RenderThreadImpl::current()->WidgetCreated();
530 if (is_hidden_)
531 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29532 }
533}
534
danakj53802692018-07-25 21:46:44535void RenderWidget::ApplyEmulatedScreenMetricsForPopupWidget(
536 RenderWidget* origin_widget) {
537 RenderWidgetScreenMetricsEmulator* emulator =
538 origin_widget->screen_metrics_emulator_.get();
539 if (!emulator)
540 return;
[email protected]b2e4c70132013-10-03 02:07:51541 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43542 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00543 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02544 emulator->original_screen_rect().origin();
Fady Samuel1c1ad3692018-11-06 23:28:40545 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
546 compositor_viewport_pixel_size_,
547 emulator->original_screen_info());
[email protected]b2e4c70132013-10-03 02:07:51548}
549
[email protected]2d6836f42014-07-02 17:25:31550gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
551 if (screen_metrics_emulator_)
552 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
553 return anchor;
554}
555
thakis18e426412017-03-15 12:06:37556#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51557void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
Albert J. Wong7bbf22d2018-12-20 00:27:27558 ExternalPopupMenu* popup) {
559 if (screen_metrics_emulator_)
560 popup->SetOriginScaleForEmulation(screen_metrics_emulator_->scale());
[email protected]b2e4c70132013-10-03 02:07:51561}
[email protected]53907862014-03-25 15:42:40562#endif
[email protected]b2e4c70132013-10-03 02:07:51563
564void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
565 if (screen_metrics_emulator_)
566 screen_metrics_emulator_->OnShowContextMenu(params);
567}
568
[email protected]a95986a82010-12-24 06:19:28569bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47570#if defined(OS_MACOSX)
571 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
572 return text_input_client_observer_->OnMessageReceived(message);
573#endif
lfgbee1e0a2016-06-08 21:24:21574 if (mouse_lock_dispatcher_ &&
575 mouse_lock_dispatcher_->OnMessageReceived(message))
576 return true;
577
[email protected]a95986a82010-12-24 06:19:28578 bool handled = true;
579 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
Albert J. Wong3c93c182018-09-27 17:29:43580 IPC_MESSAGE_HANDLER(WidgetMsg_ShowContextMenu, OnShowContextMenu)
581 IPC_MESSAGE_HANDLER(WidgetMsg_Close, OnClose)
582 IPC_MESSAGE_HANDLER(WidgetMsg_SynchronizeVisualProperties,
Fady Samuel799e72192018-04-25 21:16:57583 OnSynchronizeVisualProperties)
Albert J. Wong3c93c182018-09-27 17:29:43584 IPC_MESSAGE_HANDLER(WidgetMsg_EnableDeviceEmulation,
dgozman9260b0a12015-03-16 13:45:20585 OnEnableDeviceEmulation)
Albert J. Wong3c93c182018-09-27 17:29:43586 IPC_MESSAGE_HANDLER(WidgetMsg_DisableDeviceEmulation,
dgozman9260b0a12015-03-16 13:45:20587 OnDisableDeviceEmulation)
Albert J. Wong3c93c182018-09-27 17:29:43588 IPC_MESSAGE_HANDLER(WidgetMsg_WasHidden, OnWasHidden)
589 IPC_MESSAGE_HANDLER(WidgetMsg_WasShown, OnWasShown)
590 IPC_MESSAGE_HANDLER(WidgetMsg_SetActive, OnSetActive)
591 IPC_MESSAGE_HANDLER(WidgetMsg_SetBackgroundOpaque, OnSetBackgroundOpaque)
592 IPC_MESSAGE_HANDLER(WidgetMsg_SetTextDirection, OnSetTextDirection)
593 IPC_MESSAGE_HANDLER(WidgetMsg_SetBounds_ACK, OnRequestSetBoundsAck)
594 IPC_MESSAGE_HANDLER(WidgetMsg_UpdateScreenRects, OnUpdateScreenRects)
595 IPC_MESSAGE_HANDLER(WidgetMsg_ForceRedraw, OnForceRedraw)
596 IPC_MESSAGE_HANDLER(WidgetMsg_SetViewportIntersection,
kenrbea731792017-01-13 15:10:48597 OnSetViewportIntersection)
Albert J. Wong3c93c182018-09-27 17:29:43598 IPC_MESSAGE_HANDLER(WidgetMsg_SetIsInert, OnSetIsInert)
599 IPC_MESSAGE_HANDLER(WidgetMsg_SetInheritedEffectiveTouchAction,
sunxd540a9962018-05-24 22:51:06600 OnSetInheritedEffectiveTouchAction)
Albert J. Wong3c93c182018-09-27 17:29:43601 IPC_MESSAGE_HANDLER(WidgetMsg_UpdateRenderThrottlingStatus,
Ken Buchanan8a319fb2017-11-15 18:37:12602 OnUpdateRenderThrottlingStatus)
Albert J. Wong3c93c182018-09-27 17:29:43603 IPC_MESSAGE_HANDLER(WidgetMsg_WaitForNextFrameForTests,
lfg43e08e62016-02-03 18:51:37604 OnWaitNextFrameForTests)
paulmeyer90f6c31d2016-11-12 00:17:59605 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
606 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
607 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
608 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21609 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
610 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
611 OnDragSourceSystemDragEnded)
[email protected]a95986a82010-12-24 06:19:28612 IPC_MESSAGE_UNHANDLED(handled = false)
613 IPC_END_MESSAGE_MAP()
614 return handled;
615}
initial.commit09911bf2008-07-26 23:55:29616
617bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42618 // Don't send any messages after the browser has told us to close, and filter
danakj6dcbc5962018-11-16 16:45:42619 // most outgoing messages when frozen.
620 if (closing_) {
621 delete message;
622 return false;
623 }
624 if (is_frozen_ && !SwappedOutMessages::CanSendWhileSwappedOut(message)) {
initial.commit09911bf2008-07-26 23:55:29625 delete message;
626 return false;
627 }
628
629 // If given a messsage without a routing ID, then assign our routing ID.
630 if (message->routing_id() == MSG_ROUTING_NONE)
631 message->set_routing_id(routing_id_);
632
[email protected]380244092011-10-07 17:26:27633 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44634}
635
dtapuska014ed082016-11-11 21:58:48636void RenderWidget::SendOrCrash(IPC::Message* message) {
637 bool result = Send(message);
638 CHECK(closing_ || result) << "Failed to send message";
639}
640
ekaramad5aff1942017-01-06 01:26:35641bool RenderWidget::ShouldHandleImeEvents() const {
Albert J. Wong7bbf22d2018-12-20 00:27:27642 if (delegate())
danakj89ae4532018-12-12 22:52:55643 return has_focus_;
644 if (for_child_local_root_frame_) {
645 // TODO(ekaramad): We track page focus in all RenderViews on the page but
646 // the RenderWidgets corresponding to child local roots do not get the
647 // update. For now, this method returns true when the RenderWidget is for a
648 // child local frame, i.e., IME events will be processed regardless of page
649 // focus. We should revisit this after page focus for OOPIFs has been fully
650 // resolved (https://crbug.com/689777).
651 return true;
652 }
653 // Not a frame widget.
654 return false;
ekaramad5aff1942017-01-06 01:26:35655}
656
initial.commit09911bf2008-07-26 23:55:29657void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32658 DCHECK(content::RenderThread::Get());
659 if (closing_)
660 return;
danakj292b63e2018-11-19 20:47:06661 for (auto& observer : render_frames_)
662 observer.WidgetWillClose();
dchengd96a27a2015-07-24 20:17:32663 closing_ = true;
664
665 // Browser correspondence is no longer needed at this point.
666 if (routing_id_ != MSG_ROUTING_NONE) {
667 RenderThread::Get()->RemoveRoute(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25668 g_routing_id_widget_map.Get().erase(routing_id_);
danakj678f0252018-11-09 21:46:34669 if (RenderThreadImpl::current()) {
670 // RenderWidgets may be hidden when they are closed. If we were previously
671 // hidden, we are being counted as such in RenderThreadImpl. Thus we
672 // remove that count here by calling WidgetRestored() even though we're
673 // clearly not becoming visible here.
674 if (is_hidden_)
675 RenderThreadImpl::current()->WidgetRestored();
dchengd96a27a2015-07-24 20:17:32676 RenderThreadImpl::current()->WidgetDestroyed();
danakj678f0252018-11-09 21:46:34677 }
dchengd96a27a2015-07-24 20:17:32678 }
679
danakj6dcbc5962018-11-16 16:45:42680 if (for_child_local_root_frame_) {
dchengd96a27a2015-07-24 20:17:32681 // Widgets for frames may be created and closed at any time while the frame
Ken Buchananed449bb2018-02-01 21:02:05682 // is alive. However, WebWidget must be closed synchronously because frame
683 // widgets and frames hold pointers to each other. The deferred call to
684 // Close() will complete cleanup and release |this|, but CloseWebWidget()
685 // prevents Close() from attempting to access members of an
686 // already-deleted frame.
687 CloseWebWidget();
dchengd96a27a2015-07-24 20:17:32688 }
Ken Buchananed449bb2018-02-01 21:02:05689 // If there is a Send call on the stack, then it could be dangerous to close
690 // now. Post a task that only gets invoked when there are no nested message
691 // loops.
Hajime Hoshi315a61f2018-08-14 17:27:28692 GetCleanupTaskRunner()->PostNonNestableTask(
693 FROM_HERE, base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32694
695 // Balances the AddRef taken when we called AddRoute.
696 Release();
initial.commit09911bf2008-07-26 23:55:29697}
698
Fady Samuel799e72192018-04-25 21:16:57699void RenderWidget::OnSynchronizeVisualProperties(
danakja2c9d0a92018-07-25 20:01:18700 const VisualProperties& original_params) {
701 TRACE_EVENT0("renderer", "RenderWidget::OnSynchronizeVisualProperties");
EhsanKbd2cea992017-11-23 18:49:08702
danakja2c9d0a92018-07-25 20:01:18703 VisualProperties params = original_params;
Albert J. Wong7bbf22d2018-12-20 00:27:27704 if (delegate()) {
705 delegate()->ApplyNewSizeForWidget(size_, params.new_size);
danakja2c9d0a92018-07-25 20:01:18706
707 if (display_mode_ != params.display_mode) {
708 display_mode_ = params.display_mode;
Albert J. Wong7bbf22d2018-12-20 00:27:27709 delegate()->ApplyNewDisplayModeForWidget(params.display_mode);
danakja2c9d0a92018-07-25 20:01:18710 }
711
712 bool auto_resize_mode_changed =
713 auto_resize_mode_ != params.auto_resize_enabled;
714 auto_resize_mode_ = params.auto_resize_enabled;
715 min_size_for_auto_resize_ = params.min_size_for_auto_resize;
716 max_size_for_auto_resize_ = params.max_size_for_auto_resize;
717
718 if (auto_resize_mode_) {
719 gfx::Size min_auto_size = min_size_for_auto_resize_;
720 gfx::Size max_auto_size = max_size_for_auto_resize_;
721 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
722 min_auto_size = gfx::ScaleToCeiledSize(
723 min_auto_size, params.screen_info.device_scale_factor);
724 max_auto_size = gfx::ScaleToCeiledSize(
725 max_auto_size, params.screen_info.device_scale_factor);
726 }
Albert J. Wong7bbf22d2018-12-20 00:27:27727 delegate()->ApplyAutoResizeLimitsForWidget(min_auto_size, max_auto_size);
danakja2c9d0a92018-07-25 20:01:18728 } else if (auto_resize_mode_changed) {
Albert J. Wong7bbf22d2018-12-20 00:27:27729 delegate()->DisableAutoResizeForWidget();
danakja2c9d0a92018-07-25 20:01:18730 if (params.new_size.IsEmpty())
731 return;
732 }
733
734 browser_controls_shrink_blink_size_ =
735 params.browser_controls_shrink_blink_size;
736 top_controls_height_ = params.top_controls_height;
737 bottom_controls_height_ = params.bottom_controls_height;
738
739 // TODO(fsamuel): Modifies the |params| that are used for
740 // SynchronizeVisualProperties(), but does not used this modified
741 // device_scale_factor for the auto-resize values, which is probably a bug.
742 if (device_scale_factor_for_testing_) {
743 params.screen_info.device_scale_factor =
744 *device_scale_factor_for_testing_;
745 params.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
746 params.new_size, params.screen_info.device_scale_factor);
747 }
[email protected]b2e4c70132013-10-03 02:07:51748 }
749
danakja2c9d0a92018-07-25 20:01:18750 if (!resizing_mode_selector_->ShouldAbortOnResize(this, params)) {
751 if (screen_metrics_emulator_) {
752 screen_metrics_emulator_->OnSynchronizeVisualProperties(params);
753 } else {
754 gfx::Size old_visible_viewport_size = visible_viewport_size_;
755 SynchronizeVisualProperties(params);
756 if (old_visible_viewport_size != visible_viewport_size_) {
757 for (auto& render_frame : render_frames_)
758 render_frame.DidChangeVisibleViewport();
759 }
760 }
Fady Samuel799e72192018-04-25 21:16:57761 }
762
Albert J. Wong7bbf22d2018-12-20 00:27:27763 if (delegate() && params.scroll_focused_node_into_view)
764 delegate()->ScrollFocusedNodeIntoViewForWidget();
initial.commit09911bf2008-07-26 23:55:29765}
766
dgozman9260b0a12015-03-16 13:45:20767void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02768 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39769 if (!screen_metrics_emulator_) {
Fady Samuel4255c182018-05-24 20:42:36770 VisualProperties visual_properties;
771 visual_properties.screen_info = screen_info_;
772 visual_properties.new_size = size_;
773 visual_properties.compositor_viewport_pixel_size =
Christopher Cameronaad15a0d2018-03-09 03:47:33774 compositor_viewport_pixel_size_;
Fady Samuel84d8a1f72018-11-08 00:26:17775 visual_properties.local_surface_id_allocation =
776 local_surface_id_allocation_from_parent_;
Fady Samuel4255c182018-05-24 20:42:36777 visual_properties.visible_viewport_size = visible_viewport_size_;
778 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
779 visual_properties.display_mode = display_mode_;
W. James MacLean2a90bff2018-11-05 20:52:47780 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
mfomitchev2600fd7c2016-02-17 20:53:39781 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
Albert J. Wong3c93c182018-09-27 17:29:43782 this, params, visual_properties, widget_screen_rect_,
Fady Samuel4255c182018-05-24 20:42:36783 window_screen_rect_));
oshima50872a72016-03-04 13:26:18784 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39785 } else {
dgozman9260b0a12015-03-16 13:45:20786 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39787 }
dgozman9260b0a12015-03-16 13:45:20788}
789
790void RenderWidget::OnDisableDeviceEmulation() {
791 screen_metrics_emulator_.reset();
792}
793
initial.commit09911bf2008-07-26 23:55:29794void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31795 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29796 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03797 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55798 for (auto& observer : render_frames_)
799 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29800}
801
Saman Samie61e5c032018-11-05 22:11:44802void RenderWidget::OnWasShown(base::TimeTicks show_request_timestamp,
803 bool was_evicted) {
[email protected]9e2e4632012-07-27 16:38:41804 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
danakj57f139f2018-11-19 19:23:46805 // TODO(danakj): Nothing should happen ideally if the RenderWidget is frozen!
806 // It's not visible! However.. the RenderView needs to see it as visible in
807 // order to make the Page visible /o\ so this is hard. We need to detangle
808 // page visibility from the main widget. https://crbug.com/419087
danakj678f0252018-11-09 21:46:34809
tasakb95dbb50c2017-02-08 18:07:50810 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29811 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03812 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55813 for (auto& observer : render_frames_)
814 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29815
Saman Samie61e5c032018-11-05 22:11:44816 if (was_evicted) {
817 for (auto& observer : render_frame_proxies_) {
818 observer.WasEvicted();
819 }
820 }
821
danakja6c10012018-07-06 14:25:36822 if (layer_tree_view_ && !show_request_timestamp.is_null()) {
823 layer_tree_view_->layer_tree_host()->RequestPresentationTimeForNextFrame(
Sadrul Habib Chowdhury8bc43cc2018-06-06 01:48:03824 CreateTabSwitchingTimeRecorder(show_request_timestamp));
[email protected]3399dd822014-08-09 11:14:24825 }
initial.commit09911bf2008-07-26 23:55:29826}
827
Avi Drissman014dec72018-06-07 02:34:01828void RenderWidget::OnRequestSetBoundsAck() {
[email protected]53d3f302009-12-21 04:42:05829 DCHECK(pending_window_rect_count_);
830 pending_window_rect_count_--;
831}
832
Albert J. Wongcb004632018-07-10 22:58:25833void RenderWidget::OnForceRedraw(int snapshot_id) {
834 if (LayerTreeView* ltv = layer_tree_view()) {
835 ltv->layer_tree_host()->RequestPresentationTimeForNextFrame(
836 base::BindOnce(&RenderWidget::DidPresentForceDrawFrame,
837 weak_ptr_factory_.GetWeakPtr(), snapshot_id));
838 ltv->SetNeedsForcedRedraw();
839 }
840}
841
842void RenderWidget::DidPresentForceDrawFrame(
843 int snapshot_id,
844 const gfx::PresentationFeedback& feedback) {
Albert J. Wong3c93c182018-09-27 17:29:43845 Send(new WidgetHostMsg_ForceRedrawComplete(routing_id(), snapshot_id));
Albert J. Wongcb004632018-07-10 22:58:25846}
847
Xianzhu Wangf02017ac2018-10-17 01:47:33848viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::PointF& point,
Ken Buchanan44d7e2f2018-08-23 14:18:05849 gfx::PointF* local_point) {
850 return input_handler_->GetFrameSinkIdAtPoint(point, local_point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22851}
852
Dave Tapuskaea83d3bd2017-06-13 16:14:55853void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31854 const blink::WebCoalescedInputEvent& input_event,
855 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55856 HandledEventCallback callback) {
Albert J. Wong7bbf22d2018-12-20 00:27:27857 if (delegate() && is_frozen_) {
danakja2c9d0a92018-07-25 20:01:18858 std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info,
859 nullptr, base::nullopt);
860 return;
861 }
Dave Tapuskaea83d3bd2017-06-13 16:14:55862 input_handler_->HandleInputEvent(input_event, latency_info,
863 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31864}
865
dtapuska9d46ef7d2017-05-26 19:06:06866scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
867 return input_event_queue_;
868}
869
fsamuel78f86e42016-01-20 04:10:23870void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21871 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54872 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23873}
874
875void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21876 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54877 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23878}
879
alexmos56567492016-09-13 00:52:46880void RenderWidget::OnSetEditCommandsForNextKeyEvent(
881 const EditCommands& edit_commands) {
882 edit_commands_ = edit_commands;
883}
884
Albert J. Wongcb004632018-07-10 22:58:25885void RenderWidget::OnSetActive(bool active) {
Albert J. Wong7bbf22d2018-12-20 00:27:27886 if (delegate())
887 delegate()->SetActiveForWidget(active);
Albert J. Wongcb004632018-07-10 22:58:25888}
889
890void RenderWidget::OnSetBackgroundOpaque(bool opaque) {
danakj89ae4532018-12-12 22:52:55891 // This IPC never sent when frozen.
892 DCHECK(!is_frozen_);
danakj0ba0e7b2018-09-25 19:37:13893 // Background opaque-ness modification is only supported for the main frame.
Albert J. Wong7bbf22d2018-12-20 00:27:27894 // The delegate() is used as proxy for this RenderWidget being attached
danakj0ba0e7b2018-09-25 19:37:13895 // to the main frame.
Albert J. Wong7bbf22d2018-12-20 00:27:27896 if (!delegate())
danakj0ba0e7b2018-09-25 19:37:13897 return;
898
danakj89ae4532018-12-12 22:52:55899 blink::WebFrameWidget* web_frame_widget = GetFrameWidget();
danakj0ba0e7b2018-09-25 19:37:13900 if (opaque) {
901 web_frame_widget->ClearBaseBackgroundColorOverride();
902 web_frame_widget->ClearBackgroundColorOverride();
903 } else {
904 web_frame_widget->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT);
905 web_frame_widget->SetBackgroundColorOverride(SK_ColorTRANSPARENT);
906 }
Albert J. Wongcb004632018-07-10 22:58:25907}
908
fsamuel78f86e42016-01-20 04:10:23909void RenderWidget::OnSetFocus(bool enable) {
Albert J. Wong7bbf22d2018-12-20 00:27:27910 if (delegate())
911 delegate()->DidReceiveSetFocusEventForWidget();
danakja2c9d0a92018-07-25 20:01:18912 SetFocus(enable);
913}
914
915void RenderWidget::SetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08916 has_focus_ = enable;
917
lfg8ff33912016-09-13 20:59:21918 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54919 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08920
ericwilligers88e69742016-10-17 19:29:55921 for (auto& observer : render_frames_)
922 observer.RenderWidgetSetFocus(enable);
danakja2c9d0a92018-07-25 20:01:18923
Albert J. Wong7bbf22d2018-12-20 00:27:27924 if (delegate())
925 delegate()->DidChangeFocusForWidget();
fsamuel78f86e42016-01-20 04:10:23926}
927
dtapuska3d5624d32016-08-30 04:34:00928void RenderWidget::SetNeedsMainFrame() {
danakj53f46b82018-12-11 20:55:55929 // The WebWidgetClient is not |this| if tests override it for the WebView and
930 // WebViewClient.
931 blink::WebWidgetClient* client =
Albert J. Wong7bbf22d2018-12-20 00:27:27932 delegate() ? delegate()->GetWebWidgetClientForWidget() : this;
danakj53f46b82018-12-11 20:55:55933 client->ScheduleAnimation();
dtapuska3d5624d32016-08-30 04:34:00934}
935
fsamuel78f86e42016-01-20 04:10:23936///////////////////////////////////////////////////////////////////////////////
danakja6c10012018-07-06 14:25:36937// LayerTreeViewDelegate
fsamuel78f86e42016-01-20 04:10:23938
David Bokanc8e38d02018-10-08 21:56:01939void RenderWidget::ApplyViewportChanges(
940 const cc::ApplyViewportChangesArgs& args) {
Ken Buchananed449bb2018-02-01 21:02:05941 if (!GetWebWidget())
942 return;
David Bokanc8e38d02018-10-08 21:56:01943 GetWebWidget()->ApplyViewportChanges(args);
fsamuel78f86e42016-01-20 04:10:23944}
945
sahel1b47fda72017-03-28 17:03:07946void RenderWidget::RecordWheelAndTouchScrollingCount(
947 bool has_scrolled_by_wheel,
948 bool has_scrolled_by_touch) {
Ken Buchananed449bb2018-02-01 21:02:05949 if (!GetWebWidget())
950 return;
Blink Reformat1c4d759e2017-04-09 16:34:54951 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07952 has_scrolled_by_touch);
953}
954
Daniel Cheng224569ee2018-04-25 05:45:06955void RenderWidget::BeginMainFrame(base::TimeTicks frame_time) {
Ken Buchananed449bb2018-02-01 21:02:05956 if (!GetWebWidget())
957 return;
Daniel Cheng224569ee2018-04-25 05:45:06958 if (input_event_queue_)
959 input_event_queue_->DispatchRafAlignedInput(frame_time);
dtapuska3d5624d32016-08-30 04:34:00960
Daniel Cheng224569ee2018-04-25 05:45:06961 GetWebWidget()->BeginFrame(frame_time);
fsamuel78f86e42016-01-20 04:10:23962}
963
danakjc7afae52017-06-20 21:12:41964void RenderWidget::RequestNewLayerTreeFrameSink(
danakja6c10012018-07-06 14:25:36965 LayerTreeFrameSinkCallback callback) {
[email protected]7912e822014-04-16 02:37:03966 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41967 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39968 DCHECK(!compositor_never_visible_);
danakjf87460792018-12-04 20:14:22969 // Frozen RenderWidgets should not be doing any compositing.
Scott Violetb04f16c2018-11-27 00:48:46970 DCHECK(!is_frozen_);
danakj678f0252018-11-09 21:46:34971
972 if (is_closing()) {
973 // In this case, we drop the request which means the compositor waits
974 // forever, which is fine since we're going to destroy it.
975 return;
976 }
jonrossa2ff4f82018-02-16 17:27:46977
danakjf87460792018-12-04 20:14:22978 // If we have a warmup in progress, wait for that and store the callback
979 // to be run when the warmup completes.
980 if (warmup_frame_sink_request_pending_) {
981 after_warmup_callback_ = std::move(callback);
982 return;
983 }
984 // If a warmup previously completed, use the result.
985 if (warmup_frame_sink_) {
986 std::move(callback).Run(std::move(warmup_frame_sink_));
987 return;
988 }
989
990 DoRequestNewLayerTreeFrameSink(std::move(callback));
991}
992
993void RenderWidget::DoRequestNewLayerTreeFrameSink(
994 LayerTreeFrameSinkCallback callback) {
jonrossa2ff4f82018-02-16 17:27:46995 // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
996 // would then handle binding.
997 mojom::RenderFrameMetadataObserverPtr ptr;
998 mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr);
999 mojom::RenderFrameMetadataObserverClientPtrInfo client_info;
1000 mojom::RenderFrameMetadataObserverClientRequest client_request =
1001 mojo::MakeRequest(&client_info);
danakj4b347212018-07-04 17:55:171002 auto render_frame_metadata_observer =
1003 std::make_unique<RenderFrameMetadataObserverImpl>(std::move(request),
1004 std::move(client_info));
danakja6c10012018-07-06 14:25:361005 layer_tree_view_->SetRenderFrameObserver(
danakj4b347212018-07-04 17:55:171006 std::move(render_frame_metadata_observer));
danakjf51754372018-12-13 23:20:011007 GURL url = GetWebWidget()->GetURLForDebugTrace();
danakjefabf312018-10-05 19:03:071008 // The |url| is not always available, fallback to a fixed string.
1009 if (url.is_empty())
1010 url = GURL("chrome://gpu/RenderWidget::RequestNewLayerTreeFrameSink");
danakj6dcbc5962018-11-16 16:45:421011 // TODO(danakj): This may not be accurate, depending on the intent. A child
1012 // local root could be in the same process as the view, so if the client is
1013 // meant to designate the process type, it seems kRenderer would be the
1014 // correct choice. If client is meant to designate the widget type, then
1015 // kOOPIF would denote that it is not for the main frame. However, kRenderer
1016 // would also be used for other widgets such as popups.
1017 const char* client_name = for_child_local_root_frame_ ? kOOPIF : kRenderer;
Scott Violetb04f16c2018-11-27 00:48:461018 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
1019 routing_id_, frame_swap_message_queue_, std::move(url),
1020 std::move(callback), std::move(client_request), std::move(ptr),
1021 client_name);
[email protected]ba91a792013-02-06 09:48:281022}
1023
fsamuel78f86e42016-01-20 04:10:231024void RenderWidget::DidCommitAndDrawCompositorFrame() {
1025 // NOTE: Tests may break if this event is renamed or moved. See
1026 // tab_capture_performancetest.cc.
1027 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081028
ericwilligers88e69742016-10-17 19:29:551029 for (auto& observer : render_frames_)
1030 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081031
fsamuel78f86e42016-01-20 04:10:231032 // Notify subclasses that we initiated the paint operation.
1033 DidInitiatePaint();
Yiming Zhou0f8836c22018-09-13 22:22:111034
Albert J. Wongfb64e142018-10-16 01:10:451035 Send(new WidgetHostMsg_DidCommitAndDrawCompositorFrame(routing_id_));
fsamuel78f86e42016-01-20 04:10:231036}
1037
Saman Sami766e0b02018-01-31 17:19:201038void RenderWidget::DidCommitCompositorFrame() {
Albert J. Wong7bbf22d2018-12-20 00:27:271039 if (delegate())
1040 delegate()->DidCommitCompositorFrameForWidget();
Saman Sami766e0b02018-01-31 17:19:201041}
fsamuel78f86e42016-01-20 04:10:231042
danakja2c9d0a92018-07-25 20:01:181043void RenderWidget::DidCompletePageScaleAnimation() {
Albert J. Wong7bbf22d2018-12-20 00:27:271044 if (delegate())
1045 delegate()->DidCompletePageScaleAnimationForWidget();
danakja2c9d0a92018-07-25 20:01:181046}
fsamuel78f86e42016-01-20 04:10:231047
danakj53f46b82018-12-11 20:55:551048void RenderWidget::ScheduleAnimation() {
1049 // This call is not needed in single thread mode for tests without a
1050 // scheduler, but they need to override the WebWidgetClient and replace this
1051 // method in order to schedule a synchronous composite task themselves.
1052 layer_tree_view_->SetNeedsBeginFrame();
initial.commit09911bf2008-07-26 23:55:291053}
1054
Stephen Chenneyec4312612018-11-21 12:40:161055void RenderWidget::UpdateVisualState(bool record_main_frame_metrics) {
Ken Buchananed449bb2018-02-01 21:02:051056 if (!GetWebWidget())
1057 return;
1058
Stephen Chenneyec4312612018-11-21 12:40:161059 // When recording main frame metrics set the lifecycle reason to
1060 // kBeginMainFrame, because this is the calller of UpdateLifecycle
1061 // for the main frame. Otherwise, set the reason to kTests, which is
1062 // the oinly other reason this method is called.
1063 WebWidget::LifecycleUpdateReason lifecycle_reason =
1064 record_main_frame_metrics
1065 ? WebWidget::LifecycleUpdateReason::kBeginMainFrame
1066 : WebWidget::LifecycleUpdateReason::kTest;
1067 GetWebWidget()->UpdateLifecycle(WebWidget::LifecycleUpdate::kAll,
1068 lifecycle_reason);
Blink Reformat1c4d759e2017-04-09 16:34:541069 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501070
Robert Flack3ef2ffb2018-09-06 20:38:201071 if (first_update_visual_state_after_hidden_) {
Takashi SAKAMOTO870f6262017-08-22 04:08:271072 RecordTimeToFirstActivePaint();
1073 first_update_visual_state_after_hidden_ = false;
1074 }
1075}
tasakb95dbb50c2017-02-08 18:07:501076
Takashi SAKAMOTO870f6262017-08-22 04:08:271077void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501078 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501079 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271080 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1081 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1082 sample);
1083 }
1084 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1085 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1086 UMA_HISTOGRAM_TIMES(
1087 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1088 "AfterBackgrounded.5min",
1089 sample);
1090 }
fsamuel78f86e42016-01-20 04:10:231091}
1092
Stephen Chenney9879a5c2018-09-26 14:21:421093void RenderWidget::RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time) {
1094 if (!GetWebWidget())
1095 return;
1096
1097 GetWebWidget()->RecordEndOfFrameMetrics(frame_begin_time);
1098}
1099
fsamuel78f86e42016-01-20 04:10:231100void RenderWidget::WillBeginCompositorFrame() {
1101 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1102
Ken Buchananed449bb2018-02-01 21:02:051103 if (!GetWebWidget())
1104 return;
1105
Blink Reformat1c4d759e2017-04-09 16:34:541106 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291107
dglazkov06854c5c2016-08-31 00:19:591108 // The UpdateTextInputState can result in further layout and possibly
1109 // enable GPU acceleration so they need to be called before any painting
1110 // is done.
changwan75e3b2072017-01-16 02:55:001111 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591112 UpdateSelectionBounds();
1113
ericwilligers88e69742016-10-17 19:29:551114 for (auto& observer : render_frame_proxies_)
1115 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291116}
1117
Kent Tamura21d1de62018-12-10 04:45:201118std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForWebTest(
Fady Samueldfecb7d2017-07-26 11:41:041119 std::unique_ptr<viz::CopyOutputRequest> request) {
Kent Tamura21d1de62018-12-10 04:45:201120 return RenderThreadImpl::current()->RequestCopyOfOutputForWebTest(
jbroman6ccbc7d472016-07-27 04:45:411121 routing_id_, std::move(request));
1122}
1123
fsamuel72464894f2015-12-15 06:59:311124///////////////////////////////////////////////////////////////////////////////
1125// RenderWidgetInputHandlerDelegate
1126
avid7d6b2e2016-03-04 19:41:171127void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381128 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1129 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291130 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381131
ekaramad27ca69b12017-04-20 18:34:291132 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381133 frame_widget->LocalRoot()->View()->FocusedFrame();
1134
ekaramad27ca69b12017-04-20 18:34:291135 if (focused && focused->AutofillClient())
1136 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171137}
fsamuel72464894f2015-12-15 06:59:311138
dtapuska1827dd22016-03-11 15:24:591139void RenderWidget::ObserveGestureEventAndResult(
1140 const blink::WebGestureEvent& gesture_event,
1141 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131142 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591143 bool event_processed) {
1144 if (!compositor_deps_->IsElasticOverscrollEnabled())
1145 return;
1146
1147 cc::InputHandlerScrollResult scroll_result;
1148 scroll_result.did_scroll = event_processed;
1149 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1150 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131151 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591152
Dave Tapuska04bc5ee92018-04-17 19:03:311153 widget_input_handler_manager_->ObserveGestureEventOnMainThread(gesture_event,
1154 scroll_result);
dtapuska1827dd22016-03-11 15:24:591155}
1156
avid7d6b2e2016-03-04 19:41:171157void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461158 ClearEditCommands();
1159}
1160
1161void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1162 const std::string& value) {
1163 ClearEditCommands();
1164 edit_commands_.emplace_back(name, value);
1165}
1166
1167void RenderWidget::ClearEditCommands() {
1168 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171169}
fsamuel72464894f2015-12-15 06:59:311170
chongza8ba91fc2016-08-16 21:39:171171void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska04bc5ee92018-04-17 19:03:311172 if (mojom::WidgetInputHandlerHost* host =
1173 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1174 host->DidOverscroll(params);
Dave Tapuska139a72f2017-09-06 21:57:031175 }
fsamuel72464894f2015-12-15 06:59:311176}
1177
fsamuele8326c742016-01-12 00:49:391178void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1179 // Nothing to do here. RenderWidget created the |input_handler| and will take
1180 // ownership of it. We just verify here that we don't already have an input
1181 // handler.
1182 DCHECK(!input_handler_);
1183}
1184
changwan75e3b2072017-01-16 02:55:001185void RenderWidget::ShowVirtualKeyboard() {
1186 UpdateTextInputStateInternal(true, false);
1187}
1188
changwan62f57292017-02-17 08:28:251189void RenderWidget::ClearTextInputState() {
1190 text_input_info_ = blink::WebTextInputInfo();
1191 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1192 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1193 can_compose_inline_ = false;
1194 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201195 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251196}
1197
changwan75e3b2072017-01-16 02:55:001198void RenderWidget::UpdateTextInputState() {
1199 UpdateTextInputStateInternal(false, false);
1200}
1201
1202void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1203 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311204 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001205
fsamuel72464894f2015-12-15 06:59:311206 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001207 DCHECK(!reply_to_request);
1208 // show_virtual_keyboard should still be effective even if it was set inside
1209 // the IME
fsamuel72464894f2015-12-15 06:59:311210 // event guard.
changwan75e3b2072017-01-16 02:55:001211 if (show_virtual_keyboard)
1212 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311213 return;
1214 }
1215
dglazkov97b6c2b2016-10-25 17:35:551216 ui::TextInputType new_type = GetTextInputType();
1217 if (IsDateTimeInput(new_type))
1218 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311219
dglazkov97b6c2b2016-10-25 17:35:551220 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351221 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541222 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101223 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541224 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311225
1226 bool new_can_compose_inline = CanComposeInline();
1227
1228 // Only sends text input params if they are changed or if the ime should be
1229 // shown.
changwan75e3b2072017-01-16 02:55:001230 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561231 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1232 text_input_info_ != new_info ||
1233 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381234 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551235 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311236 params.mode = new_mode;
1237 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211238#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201239 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1240 // Due to a focus change, values will be reset by the frame.
1241 // That case we only need fresh NEXT/PREVIOUS information.
Albert J. Wong3c93c182018-09-27 17:29:431242 // Also we won't send WidgetHostMsg_TextInputStateChanged if next/previous
AJITH KUMAR V041c0b02017-08-08 10:39:201243 // focusable status is changed.
1244 if (auto* controller = GetInputMethodController()) {
1245 next_previous_flags_ =
1246 controller->ComputeWebTextInputNextPreviousFlags();
1247 } else {
1248 // For safety in case GetInputMethodController() is null, because -1 is
1249 // invalid value to send to browser process.
1250 next_previous_flags_ = 0;
1251 }
1252 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211253#else
1254 next_previous_flags_ = 0;
1255#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201256 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541257 params.value = new_info.value.Utf8();
1258 params.selection_start = new_info.selection_start;
1259 params.selection_end = new_info.selection_end;
1260 params.composition_start = new_info.composition_start;
1261 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311262 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001263 // TODO(changwan): change instances of show_ime_if_needed to
1264 // show_virtual_keyboard.
1265 params.show_ime_if_needed = show_virtual_keyboard;
1266 params.reply_to_request = reply_to_request;
Albert J. Wong3c93c182018-09-27 17:29:431267 Send(new WidgetHostMsg_TextInputStateChanged(routing_id(), params));
fsamuel72464894f2015-12-15 06:59:311268
1269 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551270 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311271 text_input_mode_ = new_mode;
1272 can_compose_inline_ = new_can_compose_inline;
1273 text_input_flags_ = new_info.flags;
Eric Karl706ea6712018-12-21 22:41:381274
1275#if defined(OS_ANDROID)
1276 // If we send a new TextInputStateChanged message, we must also deliver a
1277 // new RenderFrameMetadata, as the IME will need this info to be updated.
1278 // TODO(ericrk): Consider folding the above IPC into RenderFrameMetadata.
1279 // https://crbug.com/912309
1280 if (layer_tree_view_ && IsSurfaceSynchronizationEnabled()) {
1281 layer_tree_view_->RequestForceSendMetadata();
1282 }
1283#endif
fsamuel72464894f2015-12-15 06:59:311284 }
1285}
1286
1287bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581288 possible_drag_event_info_.event_source =
1289 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1290 possible_drag_event_info_.event_location =
Ella Ge1116059d2018-03-21 02:06:131291 gfx::ToFlooredPoint(event.PositionInScreen());
avid7d6b2e2016-03-04 19:41:171292
fsamuel72464894f2015-12-15 06:59:311293 return false;
1294}
1295
1296bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551297 for (auto& observer : render_frames_)
1298 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081299
paulmeyer6ef5a792016-11-08 20:33:581300 possible_drag_event_info_.event_source =
1301 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1302 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541303 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581304
Albert J. Wong7bbf22d2018-12-20 00:27:271305 if (delegate())
1306 return delegate()->RenderWidgetWillHandleMouseEventForWidget(event);
avid7d6b2e2016-03-04 19:41:171307
fsamuel72464894f2015-12-15 06:59:311308 return false;
[email protected]fd847792013-10-24 17:12:351309}
1310
initial.commit09911bf2008-07-26 23:55:291311///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391312// RenderWidgetScreenMetricsDelegate
1313
1314void RenderWidget::Redraw() {
danakja6c10012018-07-06 14:25:361315 if (layer_tree_view_)
1316 layer_tree_view_->SetNeedsRedrawRect(gfx::Rect(size_));
mfomitchev2600fd7c2016-02-17 20:53:391317}
1318
bokanc63441c2016-04-27 15:49:121319void RenderWidget::ResizeWebWidget() {
danakja2c9d0a92018-07-25 20:01:181320 gfx::Size size = GetSizeForWebWidget();
Albert J. Wong7bbf22d2018-12-20 00:27:271321 if (delegate()) {
1322 delegate()->ResizeWebWidgetForWidget(size, top_controls_height_,
1323 bottom_controls_height_,
1324 browser_controls_shrink_blink_size_);
danakja2c9d0a92018-07-25 20:01:181325 return;
1326 }
1327 GetWebWidget()->Resize(size);
bokanc63441c2016-04-27 15:49:121328}
1329
1330gfx::Size RenderWidget::GetSizeForWebWidget() const {
danakj4b347212018-07-04 17:55:171331 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031332 return gfx::ScaleToCeiledSize(size_,
1333 GetOriginalScreenInfo().device_scale_factor);
1334 }
bokanc63441c2016-04-27 15:49:121335
1336 return size_;
1337}
1338
akaba3483d8f2018-07-10 21:43:091339void RenderWidget::UpdateZoom(double zoom_level) {
akabac6bd1212018-06-25 20:10:481340 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1341 if (!frame_widget)
1342 return;
1343 RenderFrameImpl* render_frame =
1344 RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
1345
akaba3483d8f2018-07-10 21:43:091346 // Return early if zoom level is unchanged.
1347 if (render_frame->GetZoomLevel() == zoom_level) {
akabac6bd1212018-06-25 20:10:481348 return;
1349 }
1350
akaba3483d8f2018-07-10 21:43:091351 render_frame->SetZoomLevel(zoom_level);
akabac6bd1212018-06-25 20:10:481352
1353 for (auto& observer : render_frame_proxies_)
akaba3483d8f2018-07-10 21:43:091354 observer.OnZoomLevelChanged(zoom_level);
akabac6bd1212018-06-25 20:10:481355
1356 for (auto& plugin : browser_plugins_)
akaba3483d8f2018-07-10 21:43:091357 plugin.OnZoomLevelChanged(zoom_level);
akabac6bd1212018-06-25 20:10:481358}
1359
Fady Samuel799e72192018-04-25 21:16:571360void RenderWidget::SynchronizeVisualProperties(const VisualProperties& params) {
Christopher Cameronbe7ecea2018-02-27 00:47:191361 // Inform the rendering thread of the color space indicate the presence of HDR
1362 // capabilities.
Miguel Casas5e1018052018-01-09 19:17:361363 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1364 if (render_thread)
Christopher Camerone9a30c12018-03-07 08:23:381365 render_thread->SetRenderingColorSpace(params.screen_info.color_space);
Miguel Casas5e1018052018-01-09 19:17:361366
mfomitchev2600fd7c2016-02-17 20:53:391367 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211368 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391369 return;
1370
W. James MacLean2a90bff2018-11-05 20:52:471371 // Only propagate the external PSF to non-main-frames.
Albert J. Wong7bbf22d2018-12-20 00:27:271372 if (!delegate())
W. James MacLean2a90bff2018-11-05 20:52:471373 layer_tree_view_->SetExternalPageScaleFactor(params.page_scale_factor);
1374
Fady Samuele62be402018-03-29 03:19:531375 gfx::Size new_compositor_viewport_pixel_size =
1376 params.auto_resize_enabled
1377 ? gfx::ScaleToCeiledSize(size_,
1378 params.screen_info.device_scale_factor)
1379 : params.compositor_viewport_pixel_size;
Fady Samuel84d8a1f72018-11-08 00:26:171380 UpdateSurfaceAndScreenInfo(params.local_surface_id_allocation.value_or(
1381 viz::LocalSurfaceIdAllocation()),
1382 new_compositor_viewport_pixel_size,
1383 params.screen_info);
Vladimir Levin98d76dad2018-04-21 00:21:291384 UpdateCaptureSequenceNumber(params.capture_sequence_number);
danakja6c10012018-07-06 14:25:361385 if (layer_tree_view_) {
1386 layer_tree_view_->SetBrowserControlsHeight(
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271387 params.top_controls_height, params.bottom_controls_height,
1388 params.browser_controls_shrink_blink_size);
danakja6c10012018-07-06 14:25:361389 layer_tree_view_->SetRasterColorSpace(
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271390 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151391 }
mfomitchev2600fd7c2016-02-17 20:53:391392
akaba3483d8f2018-07-10 21:43:091393 UpdateZoom(params.zoom_level);
akabac6bd1212018-06-25 20:10:481394
danakj21604ce2018-12-19 16:01:221395 if (!params.auto_resize_enabled) {
1396 visible_viewport_size_ = params.visible_viewport_size;
Fady Samuele62be402018-03-29 03:19:531397
danakj21604ce2018-12-19 16:01:221398 // NOTE: We may have entered fullscreen mode without changing our size.
1399 bool fullscreen_change =
1400 is_fullscreen_granted_ != params.is_fullscreen_granted;
1401 is_fullscreen_granted_ = params.is_fullscreen_granted;
1402 display_mode_ = params.display_mode;
mfomitchev2600fd7c2016-02-17 20:53:391403
danakj21604ce2018-12-19 16:01:221404 size_ = params.new_size;
mfomitchev2600fd7c2016-02-17 20:53:391405
danakj21604ce2018-12-19 16:01:221406 ResizeWebWidget();
mfomitchev2600fd7c2016-02-17 20:53:391407
danakj21604ce2018-12-19 16:01:221408 WebSize visual_viewport_size;
1409 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
1410 visual_viewport_size =
1411 gfx::ScaleToCeiledSize(params.visible_viewport_size,
1412 GetOriginalScreenInfo().device_scale_factor);
1413 } else {
1414 visual_viewport_size = visible_viewport_size_;
1415 }
1416 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
bokan71cb5b12016-04-27 03:45:221417
danakj21604ce2018-12-19 16:01:221418 if (fullscreen_change)
1419 DidToggleFullscreen();
mfomitchev2600fd7c2016-02-17 20:53:391420 }
W. James MacLean2a90bff2018-11-05 20:52:471421
Albert J. Wong7bbf22d2018-12-20 00:27:271422 if (!delegate()) {
W. James MacLean2a90bff2018-11-05 20:52:471423 // Make sure that page scale factor changes propagating down from the main
1424 // frame are relayed to nested OOPIFs/non-main-frames.
1425 page_scale_factor_from_mainframe_ = params.page_scale_factor;
1426 for (auto& observer : render_frame_proxies_)
1427 observer.OnPageScaleFactorChanged(params.page_scale_factor);
1428 }
mfomitchev2600fd7c2016-02-17 20:53:391429}
1430
1431void RenderWidget::SetScreenMetricsEmulationParameters(
1432 bool enabled,
1433 const blink::WebDeviceEmulationParams& params) {
Albert J. Wong7bbf22d2018-12-20 00:27:271434 // This is only supported in RenderView, which has an delegate().
1435 DCHECK(delegate());
1436 delegate()->SetScreenMetricsEmulationParametersForWidget(enabled, params);
mfomitchev2600fd7c2016-02-17 20:53:391437}
1438
Albert J. Wong3c93c182018-09-27 17:29:431439void RenderWidget::SetScreenRects(const gfx::Rect& widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:391440 const gfx::Rect& window_screen_rect) {
Albert J. Wong3c93c182018-09-27 17:29:431441 widget_screen_rect_ = widget_screen_rect;
mfomitchev2600fd7c2016-02-17 20:53:391442 window_screen_rect_ = window_screen_rect;
1443}
1444
1445///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461446// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291447
Chris Harrelsond7ab99b2018-01-24 17:51:361448void RenderWidget::IntrinsicSizingInfoChanged(
1449 const blink::WebIntrinsicSizingInfo& sizing_info) {
Albert J. Wong3c93c182018-09-27 17:29:431450 Send(new WidgetHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
Chris Harrelsond7ab99b2018-01-24 17:51:361451}
1452
Blink Reformat1c4d759e2017-04-09 16:34:541453void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1454 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
Albert J. Wongfb64e142018-10-16 01:10:451455 QueueMessage(new WidgetHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_));
dglazkovf0e1d6d2015-10-10 02:13:481456 }
dglazkov79c426102015-08-31 21:22:431457
ericwilligers88e69742016-10-17 19:29:551458 for (auto& observer : render_frames_)
1459 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431460}
1461
[email protected]586871b2014-07-22 17:05:111462// static
dchengcedca5612016-04-09 01:40:151463std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111464 IPC::Message* msg,
[email protected]586871b2014-07-22 17:05:111465 FrameSwapMessageQueue* frame_swap_message_queue,
1466 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111467 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111468 bool first_message_for_frame = false;
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491469 frame_swap_message_queue->QueueMessageForFrame(
1470 source_frame_number, base::WrapUnique(msg), &first_message_for_frame);
[email protected]586871b2014-07-22 17:05:111471 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151472 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111473 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061474 return promise;
[email protected]586871b2014-07-22 17:05:111475 }
dcheng4b6b5ff2014-10-16 00:42:061476 return nullptr;
[email protected]586871b2014-07-22 17:05:111477}
1478
danakj53802692018-07-25 21:46:441479void RenderWidget::SetHandlingInputEvent(bool handling_input_event) {
1480 input_handler_->set_handling_input_event(handling_input_event);
1481}
1482
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491483void RenderWidget::QueueMessage(IPC::Message* msg) {
[email protected]586871b2014-07-22 17:05:111484 // RenderThreadImpl::current() is NULL in some tests.
danakja6c10012018-07-06 14:25:361485 if (!layer_tree_view_ || !RenderThreadImpl::current()) {
[email protected]586871b2014-07-22 17:05:111486 Send(msg);
1487 return;
1488 }
1489
dchengcedca5612016-04-09 01:40:151490 std::unique_ptr<cc::SwapPromise> swap_promise =
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491491 QueueMessageImpl(msg, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111492 RenderThreadImpl::current()->sync_message_filter(),
danakja6c10012018-07-06 14:25:361493 layer_tree_view_->GetSourceFrameNumber());
[email protected]586871b2014-07-22 17:05:111494
Ken Buchanance710eb2017-08-30 23:46:521495 if (swap_promise)
danakja6c10012018-07-06 14:25:361496 layer_tree_view_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111497}
1498
Blink Reformat1c4d759e2017-04-09 16:34:541499void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301500 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521501 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181502 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291503 // Only send a SetCursor message if we need to make a change.
Navid Zolghadr293bb862018-12-12 18:15:411504 if (input_handler_->DidChangeCursor(cursor))
Albert J. Wong3c93c182018-09-27 17:29:431505 Send(new WidgetHostMsg_SetCursor(routing_id_, cursor));
initial.commit09911bf2008-07-26 23:55:291506}
1507
aelias5971e47d2017-06-16 02:39:381508void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
Albert J. Wong3c93c182018-09-27 17:29:431509 Send(new WidgetHostMsg_AutoscrollStart(routing_id_, point));
aelias5971e47d2017-06-16 02:39:381510}
1511
1512void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
Albert J. Wong3c93c182018-09-27 17:29:431513 Send(new WidgetHostMsg_AutoscrollFling(routing_id_, velocity));
aelias5971e47d2017-06-16 02:39:381514}
1515
1516void RenderWidget::AutoscrollEnd() {
Albert J. Wong3c93c182018-09-27 17:29:431517 Send(new WidgetHostMsg_AutoscrollEnd(routing_id_));
aelias5971e47d2017-06-16 02:39:381518}
1519
initial.commit09911bf2008-07-26 23:55:291520// We are supposed to get a single call to Show for a newly created RenderWidget
1521// that was created via RenderWidget::CreateWebView. So, we wait until this
1522// point to dispatch the ShowWidget message.
1523//
1524// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281525// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291526//
Blink Reformat1c4d759e2017-04-09 16:34:541527void RenderWidget::Show(WebNavigationPolicy policy) {
danakj65f423b72018-10-10 17:21:201528 if (!show_callback_) {
Albert J. Wong7bbf22d2018-12-20 00:27:271529 if (delegate()) {
danakja2c9d0a92018-07-25 20:01:181530 // When SupportsMultipleWindows is disabled, popups are reusing
danakj65f423b72018-10-10 17:21:201531 // the view's RenderWidget. In some scenarios, this makes blink to call
1532 // Show() twice. But otherwise, if it is enabled, we should not visit
1533 // Show() more than once.
Albert J. Wong7bbf22d2018-12-20 00:27:271534 DCHECK(!delegate()->SupportsMultipleWindowsForWidget());
danakj65f423b72018-10-10 17:21:201535 return;
danakja2c9d0a92018-07-25 20:01:181536 } else {
danakj65f423b72018-10-10 17:21:201537 NOTREACHED() << "received extraneous Show call";
danakja2c9d0a92018-07-25 20:01:181538 }
danakja2c9d0a92018-07-25 20:01:181539 }
1540
initial.commit09911bf2008-07-26 23:55:291541 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351542
1543 // The opener is responsible for actually showing this widget.
danakjdf1ceb72018-07-18 20:02:251544 std::move(show_callback_).Run(this, policy, initial_rect_);
nickf7b38222016-11-22 21:59:351545
bokanc007c3a2015-02-03 07:15:561546 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441547 // that's okay. It'll be ignored if as_popup is false, or the browser
1548 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561549 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291550}
1551
danakj17216f4d2018-10-16 22:57:321552LayerTreeView* RenderWidget::InitializeLayerTreeView() {
1553 TRACE_EVENT0("blink", "RenderWidget::InitializeLayerTreeView");
danakj17216f4d2018-10-16 22:57:321554
1555 layer_tree_view_ = std::make_unique<LayerTreeView>(
1556 this, compositor_deps_->GetCompositorMainThreadTaskRunner(),
1557 compositor_deps_->GetCompositorImplThreadTaskRunner(),
1558 compositor_deps_->GetTaskGraphRunner(),
1559 compositor_deps_->GetWebMainThreadScheduler());
1560 layer_tree_view_->Initialize(
danakj6dcbc5962018-11-16 16:45:421561 GenerateLayerTreeSettings(compositor_deps_, for_child_local_root_frame_,
danakj17216f4d2018-10-16 22:57:321562 screen_info_.rect.size(),
1563 screen_info_.device_scale_factor),
1564 compositor_deps_->CreateUkmRecorderFactory());
1565
Fady Samuel1c1ad3692018-11-06 23:28:401566 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
danakj17216f4d2018-10-16 22:57:321567 compositor_viewport_pixel_size_, screen_info_);
1568 layer_tree_view_->SetRasterColorSpace(
1569 screen_info_.color_space.GetRasterColorSpace());
1570 layer_tree_view_->SetContentSourceId(current_content_source_id_);
1571 // For background pages and certain tests, we don't want to trigger
1572 // LayerTreeFrameSink creation.
1573 bool should_generate_frame_sink =
1574 !compositor_never_visible_ && RenderThreadImpl::current();
danakje9be3162018-11-05 21:32:001575 if (!should_generate_frame_sink) {
1576 // Prevents SetVisible() from blink from doing anything.
danakj17216f4d2018-10-16 22:57:321577 layer_tree_view_->SetNeverVisible();
danakj6dcbc5962018-11-16 16:45:421578 } else if (!is_frozen_) {
danakje9be3162018-11-05 21:32:001579 // Begins the compositor's scheduler to start producing frames.
1580 // Don't do this if the RenderWidget is attached to a RenderViewImpl for a
danakjbc6ba9d22018-11-17 04:03:411581 // proxy main frame, as this RenderWidget is frozen then, and won't be
danakje9be3162018-11-05 21:32:001582 // used for compositing until a WebFrameWidget is attached.
1583 StartCompositor();
1584 }
danakj17216f4d2018-10-16 22:57:321585
danakj17216f4d2018-10-16 22:57:321586 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1587 layer_tree_view_->SetFrameSinkId(
1588 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
1589
1590 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1591 if (render_thread) {
1592 input_event_queue_ = base::MakeRefCounted<MainThreadEventQueue>(
1593 this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(),
1594 render_thread->GetWebMainThreadScheduler(), should_generate_frame_sink);
1595 }
1596
1597 return layer_tree_view_.get();
1598}
1599
danakjde8b7482018-11-15 23:45:021600void RenderWidget::StartCompositor() {
1601 if (!is_hidden_)
1602 layer_tree_view_->SetVisible(true);
1603}
1604
1605void RenderWidget::StopCompositor() {
1606 layer_tree_view_->SetVisible(false);
1607 // Drop all gpu resources, this makes SetVisible(true) more expensive/slower
1608 // but we don't expect to use this RenderWidget again until some possible
1609 // future navigation. This brings us a bit closer to emulating deleting the
1610 // RenderWidget instead of just stopping the compositor.
1611 layer_tree_view_->ReleaseLayerTreeFrameSink();
1612}
1613
danakj6dcbc5962018-11-16 16:45:421614void RenderWidget::SetIsFrozen(bool is_frozen) {
1615 DCHECK_NE(is_frozen, is_frozen_);
1616 is_frozen_ = is_frozen;
1617 if (is_frozen)
danakjde8b7482018-11-15 23:45:021618 StopCompositor();
1619 else
1620 StartCompositor();
1621}
1622
danakjf87460792018-12-04 20:14:221623void RenderWidget::WarmupCompositor() {
1624 DCHECK(is_frozen_);
1625
1626 // Tests have no RenderThreadImpl /o\.
1627 if (!RenderThreadImpl::current())
1628 return;
1629
1630 // Keeping things simple. This would cancel any outstanding warmup if we
1631 // happened to have one (this should be basically impossible). This avoids any
1632 // extra book keeping about the outstanding reqeust.
1633 warmup_weak_ptr_factory_.InvalidateWeakPtrs();
1634 // And if we already did a warmup then we're done.
1635 if (warmup_frame_sink_)
1636 return;
1637
1638 // Mark us pending the warmup frame sink *before* calling
1639 // DoRequestNewLayerTreeFrameSink() as it may run the reply callback
1640 // synchronously. So we don't want to change any state after the call
1641 // to DoRequestNewLayerTreeFrameSink() here.
1642 warmup_frame_sink_request_pending_ = true;
1643
1644 auto cb = base::BindOnce(&RenderWidget::OnReplyForWarmupCompositor,
1645 warmup_weak_ptr_factory_.GetWeakPtr());
1646 DoRequestNewLayerTreeFrameSink(std::move(cb));
1647}
1648
1649void RenderWidget::OnReplyForWarmupCompositor(
1650 std::unique_ptr<cc::LayerTreeFrameSink> sink) {
1651 warmup_frame_sink_request_pending_ = false;
1652
1653 if (after_warmup_callback_)
1654 std::move(after_warmup_callback_).Run(std::move(sink));
1655 else
1656 warmup_frame_sink_ = std::move(sink);
1657}
1658
1659void RenderWidget::AbortWarmupCompositor() {
1660 warmup_frame_sink_request_pending_ = false;
1661 // Drop any pending warmup.
1662 warmup_weak_ptr_factory_.InvalidateWeakPtrs();
1663 // And drop any completed one.
1664 warmup_frame_sink_.reset();
1665
1666 // If we had saved a callback to run after warmup, just do so now indicating
1667 // failure.
1668 if (after_warmup_callback_)
1669 std::move(after_warmup_callback_).Run(nullptr);
1670}
1671
[email protected]2533ce12009-05-09 00:02:241672void RenderWidget::DoDeferredClose() {
Albert J. Wong3c93c182018-09-27 17:29:431673 Send(new WidgetHostMsg_Close(routing_id_));
[email protected]2533ce12009-05-09 00:02:241674}
1675
Blink Reformat1c4d759e2017-04-09 16:34:541676void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081677 DCHECK(content::RenderThread::Get());
danakj6dcbc5962018-11-16 16:45:421678 if (is_frozen_) {
1679 // This widget is currently not active. The active main frame widget is in a
[email protected]e1c3a552012-05-04 20:51:321680 // different process. Have the browser route the close request to the
1681 // active widget instead, so that the correct unload handlers are run.
Albert J. Wongfb64e142018-10-16 01:10:451682 Send(new WidgetHostMsg_RouteCloseEvent(routing_id_));
[email protected]e1c3a552012-05-04 20:51:321683 return;
1684 }
1685
danakj292b63e2018-11-19 20:47:061686 // Prevent compositor from setting up new IPC channels, since we know a
1687 // WidgetMsg_Close is coming. We do this immediately, not in DoDeferredClose,
1688 // as the caller (eg WebPagePopupImpl) may start tearing down things after
1689 // calling this method, including detaching the frame from this RenderWidget.
1690 // Then trying to make a LayerTreeFrameSink would crash.
1691 // https://crbug.com/906340
1692 host_will_close_this_ = true;
1693
initial.commit09911bf2008-07-26 23:55:291694 // If a page calls window.close() twice, we'll end up here twice, but that's
1695 // OK. It is safe to send multiple Close messages.
danakj292b63e2018-11-19 20:47:061696 //
[email protected]2533ce12009-05-09 00:02:241697 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1698 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1699 // could be closed before the JS finishes executing. So instead, post a
1700 // message back to the message loop, which won't run until the JS is
1701 // complete, and then the Close message can be sent.
Hajime Hoshi315a61f2018-08-14 17:27:281702 GetCleanupTaskRunner()->PostTask(
1703 FROM_HERE, base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291704}
1705
1706void RenderWidget::Close() {
danakj6dcbc5962018-11-16 16:45:421707 // This was done immediately in the |for_child_local_root_frame_| case in the
1708 // OnClose() IPC handler.
1709 if (!for_child_local_root_frame_)
danakj5c5269b2018-11-06 00:39:111710 CloseWebWidget();
1711
danakja6c10012018-07-06 14:25:361712 layer_tree_view_.reset();
Albert J. Wong7bbf22d2018-12-20 00:27:271713 if (delegate())
1714 delegate()->DidCloseWidget();
Albert J. Wongd593de532018-09-06 05:42:151715 // Note the ACK is a control message going to the RenderProcessHost.
Albert J. Wong3c93c182018-09-27 17:29:431716 RenderThread::Get()->Send(new WidgetHostMsg_Close_ACK(routing_id()));
Ken Buchananed449bb2018-02-01 21:02:051717}
1718
1719void RenderWidget::CloseWebWidget() {
danakj35314ab2018-10-19 16:37:341720 // If the browser has not sent OnDisableDeviceEmulation, we have an emulator
1721 // hanging out still. Destroying it must happen *after* the IPC route is
1722 // removed so that another IPC does not arrive and re-create the emulator
1723 // during closing.
1724 //
1725 // This destruction is normally part of an IPC and expects objects to be alive
1726 // that would be alive while the IPC route is active such as the
1727 // |layer_tree_view_|. So we ensure that it is the first thing to be
1728 // destroyed here before deleting things from the RenderWidget or the
Albert J. Wong7bbf22d2018-12-20 00:27:271729 // delegate().
danakj35314ab2018-10-19 16:37:341730 //
1731 // TODO(danakj): The emulator could reset to non-emulated values in an
1732 // explicit method call (instead of in the destructor) that occurs when
1733 // emulation is disabled, but does not need to occur during RenderWidget
1734 // closing. Then we would not have to destroy this so carefully.
1735 screen_metrics_emulator_.reset();
1736
danakj5c5269b2018-11-06 00:39:111737 // Informs the WebWidget that compositor is being destroyed, so it can remove
1738 // references to it first.
1739 //
Albert J. Wong7bbf22d2018-12-20 00:27:271740 // When delegate() is present, the RenderWidget is for a main frame,
danakj5c5269b2018-11-06 00:39:111741 // and the GetWebWidget() is not the same as |webwidget_internal_|. However
1742 // that widget is responsible for doing WillCloseLayerTreeView() on the
1743 // |webwidget_internal_|, not us. Otherwise, they are the same and this is
1744 // notifying |webwidget_internal_|.
1745 GetWebWidget()->WillCloseLayerTreeView();
1746
Albert J. Wong7bbf22d2018-12-20 00:27:271747 // While the wrapping WebWidget from an delegate() is responsible for
danakj5c5269b2018-11-06 00:39:111748 // doing WillCloseLayerTreeView() on the |webwidget_internal_|, this class is
1749 // responsible for calling Close() on it. Notably, then, the wrapping
1750 // WebWidget does not.
1751 webwidget_internal_->Close();
1752 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291753}
1754
Mitsuru Oshima3c07b332018-02-06 04:56:501755void RenderWidget::UpdateWebViewWithDeviceScaleFactor() {
1756 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1757 blink::WebFrame* current_frame =
1758 frame_widget ? frame_widget->LocalRoot() : nullptr;
1759 blink::WebView* webview = current_frame ? current_frame->View() : nullptr;
1760 if (webview) {
danakj4b347212018-07-04 17:55:171761 if (compositor_deps_->IsUseZoomForDSFEnabled())
Fady Samuela863f152018-03-09 16:10:031762 webview->SetZoomFactorForDeviceScaleFactor(
1763 GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501764 else
Fady Samuela863f152018-03-09 16:10:031765 webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501766
1767 webview->GetSettings()->SetPreferCompositingToLCDTextEnabled(
Christopher Camerone9a30c12018-03-07 08:23:381768 PreferCompositingToLCDText(compositor_deps_,
Fady Samuela863f152018-03-09 16:10:031769 GetWebScreenInfo().device_scale_factor));
Mitsuru Oshima3c07b332018-02-06 04:56:501770 }
1771}
1772
Ehsan Karamad655d7b8a2018-01-12 18:38:381773blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
danakj89ae4532018-12-12 22:52:551774 // TODO(danakj): Remove this check and don't call this method for non-frames.
1775 if (!for_frame())
1776 return nullptr;
1777 // TODO(danakj): Is this needed? IPCs stop after closing, but code used to
1778 // check for a null WebWidget.
1779 if (closing_)
Ehsan Karamad655d7b8a2018-01-12 18:38:381780 return nullptr;
1781
danakj89ae4532018-12-12 22:52:551782 blink::WebWidget* widget;
Albert J. Wong7bbf22d2018-12-20 00:27:271783 if (delegate()) {
danakj89ae4532018-12-12 22:52:551784 // Main frame WebFrameWidgets are held by the delegate, the internal widget
1785 // points directly to the WebView.
1786 // TODO(ekaramad): We should drop IPCs when |is_frozen_| instead of
1787 // handling them and finding a null here. However there is also the case
1788 // of the frame being detached without the widget being frozen to be
1789 // resolved (https://crbug.com/906340). So for now this can return null.
Albert J. Wong7bbf22d2018-12-20 00:27:271790 widget = delegate()->GetWebWidgetForWidget();
danakj89ae4532018-12-12 22:52:551791 } else {
1792 // Subframes always have a WebFrameWidget themselves.
1793 widget = webwidget_internal_;
Ehsan Karamad655d7b8a2018-01-12 18:38:381794 }
danakj89ae4532018-12-12 22:52:551795 return static_cast<blink::WebFrameWidget*>(widget);
Ehsan Karamad655d7b8a2018-01-12 18:38:381796}
1797
bokan841fdc72016-10-06 00:16:351798void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1799 DCHECK(window_rect);
1800 float scale = popup_origin_scale_for_emulation_;
1801 if (!scale)
1802 return;
1803 window_rect->x =
1804 popup_view_origin_for_emulation_.x() +
1805 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1806 window_rect->y =
1807 popup_view_origin_for_emulation_.y() +
1808 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1809}
1810
1811void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1812 DCHECK(window_rect);
1813 float scale = popup_origin_scale_for_emulation_;
1814 if (!scale)
1815 return;
1816 window_rect->x =
1817 popup_screen_origin_for_emulation_.x() +
1818 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1819 window_rect->y =
1820 popup_screen_origin_for_emulation_.y() +
1821 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1822}
1823
Blink Reformat1c4d759e2017-04-09 16:34:541824WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351825 WebRect rect;
bokan6b08cd22016-10-05 00:55:211826 if (pending_window_rect_count_) {
1827 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1828 // the RootWindowRect is probably going to return wrong results since the
1829 // browser may not have processed the Move yet. There isn't really anything
1830 // good to do in this case, and it shouldn't happen - since this size is
1831 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351832 rect = pending_window_rect_;
1833 } else {
1834 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211835 }
[email protected]2533ce12009-05-09 00:02:241836
bokan841fdc72016-10-06 00:16:351837 ScreenRectToEmulatedIfNeeded(&rect);
1838 return rect;
bokan6b08cd22016-10-05 00:55:211839}
1840
Blink Reformat1c4d759e2017-04-09 16:34:541841WebRect RenderWidget::ViewRect() {
Albert J. Wong3c93c182018-09-27 17:29:431842 WebRect rect = widget_screen_rect_;
bokan841fdc72016-10-06 00:16:351843 ScreenRectToEmulatedIfNeeded(&rect);
1844 return rect;
initial.commit09911bf2008-07-26 23:55:291845}
1846
Blink Reformat1c4d759e2017-04-09 16:34:541847void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301848 WebTextDirection hint) {
Albert J. Wong3c93c182018-09-27 17:29:431849 Send(new WidgetHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301850}
1851
Blink Reformat1c4d759e2017-04-09 16:34:541852void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
danakj81d601e62018-10-09 22:15:051853 // This path is for the renderer to change the on-screen position/size of
1854 // the widget by changing its window rect. This is not possible for
1855 // RenderWidgets whose position/size are controlled by layout from another
danakj6dcbc5962018-11-16 16:45:421856 // frame tree (ie. child local root frames), as the window rect can only be
1857 // set by the browser.
1858 if (for_child_local_root_frame_)
danakj81d601e62018-10-09 22:15:051859 return;
1860
oshima33ec97cd2015-12-14 19:40:241861 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351862 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511863
danakj65f423b72018-10-10 17:21:201864 if (resizing_mode_selector_->is_synchronous_mode()) {
Kent Tamura21d1de62018-12-10 04:45:201865 // This is a web-test-only path. At one point, it was planned to be
danakj65f423b72018-10-10 17:21:201866 // removed. See https://crbug.com/309760.
bokanc007c3a2015-02-03 07:15:561867 SetWindowRectSynchronously(window_rect);
danakj65f423b72018-10-10 17:21:201868 return;
1869 }
1870
1871 if (show_callback_) {
1872 // The widget is not shown yet. Delay the |window_rect| being sent to the
1873 // browser until Show() is called so it can be sent with that IPC, once the
1874 // browser is ready for the info.
1875 initial_rect_ = window_rect;
1876 } else {
1877 Send(new WidgetHostMsg_RequestSetBounds(routing_id_, window_rect));
1878 SetPendingWindowRect(window_rect);
initial.commit09911bf2008-07-26 23:55:291879 }
1880}
1881
[email protected]2533ce12009-05-09 00:02:241882void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1883 pending_window_rect_ = rect;
1884 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241885
bokan6b08cd22016-10-05 00:55:211886 // Popups don't get size updates back from the browser so just store the set
1887 // values.
danakj89ae4532018-12-12 22:52:551888 if (!for_frame()) {
Blink Reformat1c4d759e2017-04-09 16:34:541889 window_screen_rect_ = rect;
Albert J. Wong3c93c182018-09-27 17:29:431890 widget_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241891 }
[email protected]d4547452008-08-28 18:36:371892}
1893
wjmacleanee244e02017-05-26 21:06:071894void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1895 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071896 has_host_context_menu_location_ = true;
1897 host_context_menu_location_ = location;
1898 if (GetWebWidget()) {
1899 GetWebWidget()->ShowContextMenu(
1900 static_cast<blink::WebMenuSourceType>(source_type));
1901 }
1902 has_host_context_menu_location_ = false;
1903}
1904
[email protected]fa7b1dc2010-06-23 17:53:041905void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261906 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111907 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071908 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111909 int selection_start,
1910 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351911 if (!ShouldHandleImeEvents())
1912 return;
1913
brettw4b461082016-11-19 18:55:161914#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491915 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111916 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491917 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091918 return;
1919 }
1920#endif
[email protected]66fca5bc2013-05-23 06:58:291921 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011922 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011923 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541924 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111925 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561926 replacement_range.IsValid()
1927 ? WebRange(replacement_range.start(), replacement_range.length())
1928 : WebRange(),
1929 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041930 // If we failed to set the composition text, then we need to let the browser
1931 // process to cancel the input method's ongoing composition session, to make
1932 // sure we are in a consistent state.
Dave Tapuska04bc5ee92018-04-17 19:03:311933 if (mojom::WidgetInputHandlerHost* host =
1934 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1935 host->ImeCancelComposition();
Dave Tapuska139a72f2017-09-06 21:57:031936 }
[email protected]7f00efa2010-04-15 05:01:261937 }
nonafa291792016-08-10 02:36:181938 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041939}
1940
rlanday7efe2302017-01-11 00:14:281941void RenderWidget::OnImeCommitText(
1942 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111943 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281944 const gfx::Range& replacement_range,
1945 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351946 if (!ShouldHandleImeEvents())
1947 return;
1948
brettw4b461082016-11-19 18:55:161949#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491950 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1951 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1952 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091953 return;
1954 }
1955#endif
[email protected]66fca5bc2013-05-23 06:58:291956 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391957 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261958 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541959 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111960 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561961 replacement_range.IsValid()
1962 ? WebRange(replacement_range.start(), replacement_range.length())
1963 : WebRange(),
1964 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261965 }
aelias87b8f7c2016-09-14 03:19:291966 input_handler_->set_handling_input_event(false);
1967 UpdateCompositionInfo(false /* not an immediate request */);
1968}
1969
1970void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351971 if (!ShouldHandleImeEvents())
1972 return;
1973
brettw4b461082016-11-19 18:55:161974#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491975 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1976 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291977 return;
1978 }
1979#endif
1980
changwan38c3eb612016-12-09 01:45:561981 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291982 return;
1983 ImeEventGuard guard(this);
1984 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011985 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541986 controller->FinishComposingText(
1987 keep_selection ? WebInputMethodController::kKeepSelection
1988 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011989 }
fsamuele8326c742016-01-12 00:49:391990 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181991 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291992}
1993
Christopher Camerone9a30c12018-03-07 08:23:381994void RenderWidget::UpdateSurfaceAndScreenInfo(
Fady Samuel1c1ad3692018-11-06 23:28:401995 const viz::LocalSurfaceIdAllocation& new_local_surface_id_allocation,
Christopher Cameronaad15a0d2018-03-09 03:47:331996 const gfx::Size& new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381997 const ScreenInfo& new_screen_info) {
Christopher Camerone9a30c12018-03-07 08:23:381998 bool orientation_changed =
1999 screen_info_.orientation_angle != new_screen_info.orientation_angle ||
2000 screen_info_.orientation_type != new_screen_info.orientation_type;
2001 bool web_device_scale_factor_changed =
2002 screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
Fady Samuela863f152018-03-09 16:10:032003 ScreenInfo previous_original_screen_info = GetOriginalScreenInfo();
Christopher Cameronbe7ecea2018-02-27 00:47:192004
Fady Samuel1c1ad3692018-11-06 23:28:402005 local_surface_id_allocation_from_parent_ = new_local_surface_id_allocation;
Christopher Cameronaad15a0d2018-03-09 03:47:332006 compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size;
Christopher Camerone9a30c12018-03-07 08:23:382007 screen_info_ = new_screen_info;
Christopher Cameronbe7ecea2018-02-27 00:47:192008
danakja6c10012018-07-06 14:25:362009 if (layer_tree_view_) {
2010 layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
Christopher Camerone9a30c12018-03-07 08:23:382011 // Note carefully that the DSF specified in |new_screen_info| is not the
2012 // DSF used by the compositor during device emulation!
danakja6c10012018-07-06 14:25:362013 layer_tree_view_->SetViewportSizeAndScale(
Fady Samuela863f152018-03-09 16:10:032014 compositor_viewport_pixel_size_,
Fady Samuel4255c182018-05-24 20:42:362015 GetOriginalScreenInfo().device_scale_factor,
Fady Samuel1c1ad3692018-11-06 23:28:402016 local_surface_id_allocation_from_parent_);
Christopher Camerone9a30c12018-03-07 08:23:382017 }
Christopher Cameronbe7ecea2018-02-27 00:47:192018
Christopher Camerone9a30c12018-03-07 08:23:382019 if (orientation_changed)
2020 OnOrientationChange();
Christopher Cameronbe7ecea2018-02-27 00:47:192021
Fady Samuela863f152018-03-09 16:10:032022 if (previous_original_screen_info != GetOriginalScreenInfo()) {
Christopher Camerone9a30c12018-03-07 08:23:382023 for (auto& observer : render_frame_proxies_)
Fady Samuela863f152018-03-09 16:10:032024 observer.OnScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:382025
2026 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
2027 for (auto& observer : browser_plugins_)
Fady Samuela863f152018-03-09 16:10:032028 observer.ScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:382029 }
2030
2031 if (web_device_scale_factor_changed)
Christopher Cameronbe7ecea2018-02-27 00:47:192032 UpdateWebViewWithDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332033}
2034
danakja2c9d0a92018-07-25 20:01:182035void RenderWidget::SetWindowRectSynchronously(
2036 const gfx::Rect& new_window_rect) {
2037 VisualProperties visual_properties;
2038 visual_properties.screen_info = screen_info_;
2039 visual_properties.new_size = new_window_rect.size();
2040 visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
2041 new_window_rect.size(), GetWebScreenInfo().device_scale_factor);
2042 visual_properties.visible_viewport_size = new_window_rect.size();
2043 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
2044 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:172045 visual_properties.local_surface_id_allocation =
2046 local_surface_id_allocation_from_parent_;
W. James MacLean2a90bff2018-11-05 20:52:472047 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:182048 // We are resizing the window from the renderer, so allocate a new
2049 // viz::LocalSurfaceId to avoid surface invariants violations in tests.
2050 if (layer_tree_view_)
2051 layer_tree_view_->RequestNewLocalSurfaceId();
2052 SynchronizeVisualProperties(visual_properties);
2053
Albert J. Wong3c93c182018-09-27 17:29:432054 widget_screen_rect_ = new_window_rect;
danakja2c9d0a92018-07-25 20:01:182055 window_screen_rect_ = new_window_rect;
danakj65f423b72018-10-10 17:21:202056 if (show_callback_) {
2057 // Tests may call here directly to control the window rect. If
2058 // Show() did not happen yet, the rect is stored to be passed to the
2059 // browser when the RenderWidget requests Show().
danakja2c9d0a92018-07-25 20:01:182060 initial_rect_ = new_window_rect;
danakj65f423b72018-10-10 17:21:202061 }
danakja2c9d0a92018-07-25 20:01:182062}
2063
Vladimir Levin98d76dad2018-04-21 00:21:292064void RenderWidget::UpdateCaptureSequenceNumber(
2065 uint32_t capture_sequence_number) {
2066 if (capture_sequence_number == last_capture_sequence_number_)
2067 return;
2068 last_capture_sequence_number_ = capture_sequence_number;
2069
2070 // Notify observers of the new capture sequence number.
2071 for (auto& observer : render_frame_proxies_)
2072 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
2073 for (auto& observer : browser_plugins_)
2074 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
2075}
2076
[email protected]4873c7d2009-07-16 06:36:282077void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:402078 if (auto* frame = GetFocusedWebLocalFrameInWidget())
2079 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:112080}
2081
Albert J. Wong3c93c182018-09-27 17:29:432082void RenderWidget::OnUpdateScreenRects(const gfx::Rect& widget_screen_rect,
[email protected]80ad8622012-11-07 16:33:032083 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:512084 if (screen_metrics_emulator_) {
Albert J. Wong3c93c182018-09-27 17:29:432085 screen_metrics_emulator_->OnUpdateScreenRects(widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:392086 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512087 } else {
Albert J. Wong3c93c182018-09-27 17:29:432088 SetScreenRects(widget_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512089 }
Albert J. Wong3c93c182018-09-27 17:29:432090 Send(new WidgetHostMsg_UpdateScreenRects_ACK(routing_id()));
[email protected]80ad8622012-11-07 16:33:032091}
2092
kenrbea731792017-01-13 15:10:482093void RenderWidget::OnSetViewportIntersection(
Ken Buchananb2c9e262018-03-10 16:53:312094 const gfx::Rect& viewport_intersection,
Stefan Zager54e25832018-08-14 22:15:312095 const gfx::Rect& compositor_visible_rect,
2096 bool occluded_or_obscured) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252097 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchananb2c9e262018-03-10 16:53:312098 compositor_visible_rect_ = compositor_visible_rect;
Stefan Zager54e25832018-08-14 22:15:312099 frame_widget->SetRemoteViewportIntersection(viewport_intersection,
2100 occluded_or_obscured);
danakja6c10012018-07-06 14:25:362101 layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
kenrbea731792017-01-13 15:10:482102 }
2103}
2104
kenrb04323782017-06-23 01:23:322105void RenderWidget::OnSetIsInert(bool inert) {
danakj89ae4532018-12-12 22:52:552106 if (auto* frame_widget = GetFrameWidget())
Ehsan Karamadf3ca2a82018-01-20 01:05:252107 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:322108}
2109
sunxd540a9962018-05-24 22:51:062110void RenderWidget::OnSetInheritedEffectiveTouchAction(
2111 cc::TouchAction touch_action) {
danakj89ae4532018-12-12 22:52:552112 if (auto* frame_widget = GetFrameWidget())
sunxd540a9962018-05-24 22:51:062113 frame_widget->SetInheritedEffectiveTouchAction(touch_action);
sunxd540a9962018-05-24 22:51:062114}
2115
Ken Buchanan8a319fb2017-11-15 18:37:122116void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
2117 bool subtree_throttled) {
danakj89ae4532018-12-12 22:52:552118 if (auto* frame_widget = GetFrameWidget())
Ehsan Karamadf3ca2a82018-01-20 01:05:252119 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:122120}
2121
paulmeyer90f6c31d2016-11-12 00:17:592122void RenderWidget::OnDragTargetDragEnter(
2123 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:522124 const gfx::PointF& client_point,
2125 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592126 WebDragOperationsMask ops,
2127 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252128 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2129 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592130 return;
2131
Ehsan Karamadf3ca2a82018-01-20 01:05:252132 WebDragOperation operation = frame_widget->DragTargetDragEnter(
2133 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
2134 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592135
2136 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2137}
2138
Ella Ge80a52dce2017-11-15 18:01:522139void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
2140 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592141 WebDragOperationsMask ops,
2142 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252143 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2144 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592145 return;
2146
Ehsan Karamadf3ca2a82018-01-20 01:05:252147 WebDragOperation operation = frame_widget->DragTargetDragOver(
2148 ConvertWindowPointToViewport(client_point), screen_point, ops,
2149 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592150
2151 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2152}
2153
Ella Ge80a52dce2017-11-15 18:01:522154void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
2155 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252156 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2157 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592158 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:252159
2160 frame_widget
Blink Reformat1c4d759e2017-04-09 16:34:542161 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:172162 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:592163}
2164
2165void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:522166 const gfx::PointF& client_point,
2167 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592168 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252169 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2170 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592171 return;
2172
Ehsan Karamadf3ca2a82018-01-20 01:05:252173 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
2174 ConvertWindowPointToViewport(client_point),
2175 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592176}
2177
Ella Ge80a52dce2017-11-15 18:01:522178void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
2179 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:212180 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252181 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2182 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212183 return;
2184
Ehsan Karamadf3ca2a82018-01-20 01:05:252185 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
2186 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:212187}
2188
2189void RenderWidget::OnDragSourceSystemDragEnded() {
2190 if (!GetWebWidget())
2191 return;
2192
Blink Reformat1c4d759e2017-04-09 16:34:542193 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:212194}
2195
Blink Reformat1c4d759e2017-04-09 16:34:542196void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:262197#if defined(OS_CHROMEOS)
2198 // On ChromeOS, virtual keyboard is triggered only when users leave the
2199 // mouse button or the finger and a text input element is focused at that
2200 // time. Focus event itself shouldn't trigger virtual keyboard.
2201 UpdateTextInputState();
2202#else
changwan75e3b2072017-01-16 02:55:002203 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:262204#endif
boliu7b2be2f2016-11-04 04:58:312205
2206// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
2207// virtual keyboard.
2208#if !defined(OS_ANDROID)
2209 FocusChangeComplete();
2210#endif
[email protected]0d1ebed12013-08-05 22:01:132211}
2212
fsamuel72464894f2015-12-15 06:59:312213ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:162214#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492215 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2216 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:092217#endif
ekaramad5aff1942017-01-06 01:26:352218 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:542219 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:312220 return ui::TEXT_INPUT_TYPE_NONE;
2221}
2222
nonafa291792016-08-10 02:36:182223void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
2224 if (!monitor_composition_info_ && !immediate_request)
2225 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:592226
nonafa291792016-08-10 02:36:182227 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2228 gfx::Range range;
2229 std::vector<gfx::Rect> character_bounds;
2230
2231 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2232 // Composition information is only available on editable node.
2233 range = gfx::Range::InvalidRange();
2234 } else {
2235 GetCompositionRange(&range);
2236 GetCompositionCharacterBounds(&character_bounds);
2237 }
2238
2239 if (!immediate_request &&
2240 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312241 return;
nonafa291792016-08-10 02:36:182242 }
fsamuel72464894f2015-12-15 06:59:312243 composition_character_bounds_ = character_bounds;
2244 composition_range_ = range;
Dave Tapuska04bc5ee92018-04-17 19:03:312245 if (mojom::WidgetInputHandlerHost* host =
2246 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2247 host->ImeCompositionRangeChanged(composition_range_,
2248 composition_character_bounds_);
Dave Tapuska139a72f2017-09-06 21:57:032249 }
fsamuel72464894f2015-12-15 06:59:312250}
2251
Blink Reformat1c4d759e2017-04-09 16:34:542252void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
danakj4b347212018-07-04 17:55:172253 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032254 float reverse = 1 / GetOriginalScreenInfo().device_scale_factor;
oshimad5279032015-12-16 18:22:332255 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542256 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462257 gfx::Rect window_rect =
2258 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2259 rect->x = window_rect.x();
2260 rect->y = window_rect.y();
2261 rect->width = window_rect.width();
2262 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542263 }
2264}
2265
Blink Reformat1c4d759e2017-04-09 16:34:542266void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
danakj4b347212018-07-04 17:55:172267 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032268 rect->x *= GetOriginalScreenInfo().device_scale_factor;
2269 rect->y *= GetOriginalScreenInfo().device_scale_factor;
2270 rect->width *= GetOriginalScreenInfo().device_scale_factor;
2271 rect->height *= GetOriginalScreenInfo().device_scale_factor;
oshimaa6985b62016-01-27 08:58:302272 }
2273}
2274
changwan8c342742016-02-26 00:53:392275void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262276#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392277 DCHECK(!ime_event_guard_);
2278 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002279 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212280#endif
Dave Tapuska9db80842017-07-24 17:24:262281}
[email protected]105dffb42013-02-20 03:46:212282
ekaramadc9b70a72017-03-23 16:14:232283void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2284 bool monitor_updates) {
2285 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182286 if (!immediate_request)
2287 return;
2288 UpdateCompositionInfo(true /* immediate request */);
2289}
2290
[email protected]fcdc5642014-05-09 14:32:242291void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382292 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002293 // LocalRoot() might return null for provisional main frames. In this case,
2294 // the frame hasn't committed a navigation and is not swapped into the tree
2295 // yet, so it doesn't make sense to send orientation change events to it.
2296 //
2297 // TODO(https://crbug.com/578349): This check should be cleaned up
2298 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382299 if (frame_widget->LocalRoot())
2300 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302301 }
[email protected]fcdc5642014-05-09 14:32:242302}
2303
[email protected]bee16aab2009-08-26 15:55:032304void RenderWidget::SetHidden(bool hidden) {
2305 if (is_hidden_ == hidden)
2306 return;
2307
jdduke8fac9d102014-12-20 02:40:132308 // The status has changed. Tell the RenderThread about it and ensure
2309 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032310 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132311
Scott Violet1098538e2017-10-05 19:23:332312#if defined(USE_AURA)
Scott Violete46b3352018-09-22 00:37:072313 if (features::IsMultiProcessMash())
Scott Violet1098538e2017-10-05 19:23:332314 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2315#endif
2316
Saman Sami58ed4392018-01-31 20:54:192317 // RenderThreadImpl::current() could be null in tests.
2318 if (RenderThreadImpl::current()) {
2319 if (is_hidden_) {
2320 RenderThreadImpl::current()->WidgetHidden();
2321 first_update_visual_state_after_hidden_ = true;
2322 } else {
2323 RenderThreadImpl::current()->WidgetRestored();
2324 }
Lei Zhang9b359d32017-11-28 00:57:022325 }
alexclarke7fa93942015-10-21 15:37:112326
2327 if (render_widget_scheduling_state_)
2328 render_widget_scheduling_state_->SetHidden(hidden);
danakj1b35e9d2018-11-07 19:09:282329
danakj57f139f2018-11-19 19:23:462330 // When the RenderWidget is frozen, visibility of the compositor is overridden
2331 // to always be hidden to prevent it from using resources that are not needed.
2332 // Unfortunately the main RenderWidget for a RenderView must be marked visible
2333 // even if the RenderView has a proxy main frame (and the RenderWidget is
2334 // frozen), in order for the RenderView to use the visibility signal from the
2335 // RenderWidget. This is bad. But we don't need to show the compositor to
2336 // satisfy that requirement.
2337 if (!is_frozen_)
2338 layer_tree_view_->SetVisible(!is_hidden_);
[email protected]bee16aab2009-08-26 15:55:032339}
2340
[email protected]2b624c562011-10-27 22:58:262341void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212342 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262343 return;
2344
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122345 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542346 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262347 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542348 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262349 }
[email protected]2b624c562011-10-27 22:58:262350}
2351
changwanf2a707b2015-10-30 08:22:162352void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2353 if (!ime_event_guard_)
2354 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292355}
2356
changwanf2a707b2015-10-30 08:22:162357void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
Jeremy Roman0b261f42018-08-28 15:36:012358 if (ime_event_guard_ != guard)
changwanf2a707b2015-10-30 08:22:162359 return;
changwanf2a707b2015-10-30 08:22:162360 ime_event_guard_ = nullptr;
2361
[email protected]66fca5bc2013-05-23 06:58:292362 // While handling an ime event, text input state and selection bounds updates
2363 // are ignored. These must explicitly be updated once finished handling the
2364 // ime event.
2365 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472366#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002367 if (guard->show_virtual_keyboard())
2368 ShowVirtualKeyboard();
2369 else
2370 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472371#endif
[email protected]66fca5bc2013-05-23 06:58:292372}
2373
[email protected]7c8873e2013-02-05 08:03:012374void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162375#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492376 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092377 // TODO(kinaba) http://crbug.com/101101
2378 // Current Pepper IME API does not handle selection bounds. So we simply
2379 // use the caret position as an empty range for now. It will be updated
2380 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492381 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542382 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092383 *focus = caret;
2384 *anchor = caret;
2385 return;
2386 }
2387#endif
[email protected]7c8873e2013-02-05 08:03:012388 WebRect focus_webrect;
2389 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542390 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2391 ConvertViewportToWindow(&focus_webrect);
2392 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242393 *focus = focus_webrect;
2394 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322395}
2396
[email protected]e99ef6f2011-10-16 01:13:002397void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082398 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212399 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002400 return;
changwanf2a707b2015-10-30 08:22:162401 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292402 return;
[email protected]e99ef6f2011-10-16 01:13:002403
mohsenb0eeba72015-08-09 06:20:082404#if defined(USE_AURA)
2405 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2406 // Aura beucause composited selection updates are not working for webview tags
2407 // which regresses IME inside webview. Remove this when composited selection
2408 // updates are fixed for webviews. See, http://crbug.com/510568.
2409 bool send_ipc = true;
2410#else
jddukeacf809e2014-09-23 20:38:382411 // With composited selection updates, the selection bounds will be reported
2412 // directly by the compositor, in which case explicit IPC selection
2413 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082414 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542415 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082416#endif
2417 if (send_ipc) {
Albert J. Wong3c93c182018-09-27 17:29:432418 WidgetHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402419 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382420 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2421 if (selection_anchor_rect_ != params.anchor_rect ||
2422 selection_focus_rect_ != params.focus_rect) {
2423 selection_anchor_rect_ = params.anchor_rect;
2424 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402425 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2426 focused_frame->SelectionTextDirection(params.focus_dir,
2427 params.anchor_dir);
2428 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2429 }
Albert J. Wong3c93c182018-09-27 17:29:432430 Send(new WidgetHostMsg_SelectionBoundsChanged(routing_id_, params));
jddukeacf809e2014-09-23 20:38:382431 }
[email protected]58b48a0d2012-06-13 07:01:352432 }
jddukeacf809e2014-09-23 20:38:382433
nonafa291792016-08-10 02:36:182434 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002435}
2436
lfgb00fcad2016-07-14 14:16:332437void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2438 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542439 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332440 if (size_.width() != new_size_in_window.width ||
2441 size_.height() != new_size_in_window.height) {
2442 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2443
2444 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542445 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2446 size_.height());
Albert J. Wong3c93c182018-09-27 17:29:432447 widget_screen_rect_ = new_pos;
lfgb00fcad2016-07-14 14:16:332448 window_screen_rect_ = new_pos;
2449 }
2450
Christopher Camerone9a30c12018-03-07 08:23:382451 // TODO(ccameron): Note that this destroys any information differentiating
Christopher Cameronaad15a0d2018-03-09 03:47:332452 // |size_| from |compositor_viewport_pixel_size_|. Also note that the
2453 // calculation of |new_compositor_viewport_pixel_size| does not appear to
2454 // take into account device emulation.
danakja6c10012018-07-06 14:25:362455 if (layer_tree_view_)
2456 layer_tree_view_->RequestNewLocalSurfaceId();
Christopher Cameronaad15a0d2018-03-09 03:47:332457 gfx::Size new_compositor_viewport_pixel_size =
Fady Samuela863f152018-03-09 16:10:032458 gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
Fady Samuel1c1ad3692018-11-06 23:28:402459 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
2460 new_compositor_viewport_pixel_size,
2461 screen_info_);
lfgb00fcad2016-07-14 14:16:332462 }
2463}
2464
[email protected]58b48a0d2012-06-13 07:01:352465void RenderWidget::GetCompositionCharacterBounds(
2466 std::vector<gfx::Rect>* bounds) {
2467 DCHECK(bounds);
2468 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092469
brettw4b461082016-11-19 18:55:162470#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492471 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092472 return;
2473#endif
2474
Ehsan Karamad4975af6d2018-02-09 16:58:162475 blink::WebInputMethodController* controller = GetInputMethodController();
2476 if (!controller)
ekaramad2a46d632016-07-19 13:33:092477 return;
2478 blink::WebVector<blink::WebRect> bounds_from_blink;
Ehsan Karamad4975af6d2018-02-09 16:58:162479 if (!controller->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092480 return;
2481
2482 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542483 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092484 bounds->push_back(bounds_from_blink[i]);
2485 }
[email protected]58b48a0d2012-06-13 07:01:352486}
2487
[email protected]db4fc1e2013-09-06 20:01:512488void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162489#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492490 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092491 return;
2492#endif
EhsanKcdee7b72017-11-08 21:30:092493 blink::WebInputMethodController* controller = GetInputMethodController();
2494 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542495 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212496 *range = gfx::Range::InvalidRange();
2497 return;
[email protected]88dbe32f2013-06-20 23:31:362498 }
Blink Reformat1c4d759e2017-04-09 16:34:542499 range->set_start(web_range.StartOffset());
2500 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362501}
2502
[email protected]501ea13d2013-07-09 17:03:292503bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512504 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292505 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082506 if (!range.IsValid())
2507 return false;
[email protected]501ea13d2013-07-09 17:03:292508 if (composition_range_ != range)
2509 return true;
2510 if (bounds.size() != composition_character_bounds_.size())
2511 return true;
2512 for (size_t i = 0; i < bounds.size(); ++i) {
2513 if (bounds[i] != composition_character_bounds_[i])
2514 return true;
2515 }
2516 return false;
2517}
[email protected]501ea13d2013-07-09 17:03:292518
[email protected]ad26ef42011-06-17 07:59:452519bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162520#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492521 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2522 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092523#endif
[email protected]ad26ef42011-06-17 07:59:452524 return true;
[email protected]56ea1a62011-05-30 07:05:572525}
2526
Blink Reformat1c4d759e2017-04-09 16:34:542527void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2528 bool event_cancelled) {
danakja2c9d0a92018-07-25 20:01:182529 if (event_cancelled) {
Albert J. Wong7bbf22d2018-12-20 00:27:272530 // The delegate() doesn't need to hear about cancelled events.
[email protected]c68c3e4e2013-01-24 00:36:562531 return;
danakja2c9d0a92018-07-25 20:01:182532 }
2533
2534#if defined(OS_ANDROID) || defined(USE_AURA)
Blink Reformat1c4d759e2017-04-09 16:34:542535 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002536 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542537 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212538 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352539 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542540 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002541 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462542 else
changwan75e3b2072017-01-16 02:55:002543 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562544 }
ekaramada110f642016-12-21 19:47:282545// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2546// crbug/420130.
2547#if defined(OS_WIN)
danakja2c9d0a92018-07-25 20:01:182548 if (event.GetType() == blink::WebGestureEvent::kGestureTap) {
2549 // TODO(estade): hit test the event against focused node to make sure
2550 // the tap actually hit the focused node.
2551 blink::WebInputMethodController* controller = GetInputMethodController();
2552 blink::WebTextInputType text_input_type =
2553 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282554
Albert J. Wong3c93c182018-09-27 17:29:432555 Send(new WidgetHostMsg_FocusedNodeTouched(
danakja2c9d0a92018-07-25 20:01:182556 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
2557 }
ekaramada110f642016-12-21 19:47:282558#endif
[email protected]c68c3e4e2013-01-24 00:36:562559#endif
danakja2c9d0a92018-07-25 20:01:182560
Albert J. Wong7bbf22d2018-12-20 00:27:272561 // The delegate() gets to respond to handling gestures last.
2562 if (delegate())
2563 delegate()->DidHandleGestureEventForWidget(event);
[email protected]c68c3e4e2013-01-24 00:36:562564}
2565
Blink Reformat1c4d759e2017-04-09 16:34:542566void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312567 const blink::WebFloatSize& overscrollDelta,
2568 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422569 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542570 const blink::WebFloatSize& velocity,
danakje819b622018-05-01 20:27:142571 const cc::OverscrollBehavior& behavior) {
bokan731ec382016-04-07 03:16:482572#if defined(OS_MACOSX)
2573 // On OSX the user can disable the elastic overscroll effect. If that's the
2574 // case, don't forward the overscroll notification.
2575 DCHECK(compositor_deps());
2576 if (!compositor_deps()->IsElasticOverscrollEnabled())
2577 return;
2578#endif
bokane53a10f2016-04-13 23:48:312579 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542580 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422581}
2582
danakj4b347212018-07-04 17:55:172583// static
2584cc::LayerTreeSettings RenderWidget::GenerateLayerTreeSettings(
2585 CompositorDependencies* compositor_deps,
2586 bool is_for_subframe,
2587 const gfx::Size& initial_screen_size,
2588 float initial_device_scale_factor) {
2589 const bool is_threaded =
2590 !!compositor_deps->GetCompositorImplThreadTaskRunner();
2591
2592 const base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess();
2593 cc::LayerTreeSettings settings;
2594
2595 settings.resource_settings.use_r16_texture =
2596 base::FeatureList::IsEnabled(media::kUseR16Texture);
2597
2598 settings.commit_to_active_tree = !is_threaded;
2599 settings.is_layer_tree_for_subframe = is_for_subframe;
2600
2601 // For web contents, layer transforms should scale up the contents of layers
2602 // to keep content always crisp when possible.
2603 settings.layer_transforms_should_scale_layer_contents = true;
2604
2605 settings.main_frame_before_activation_enabled =
2606 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation);
2607
2608 // Checkerimaging is not supported for synchronous single-threaded mode, which
2609 // is what the renderer uses if its not threaded.
2610 settings.enable_checker_imaging =
2611 !cmd.HasSwitch(cc::switches::kDisableCheckerImaging) && is_threaded;
2612
2613#if defined(OS_ANDROID)
2614 // We can use a more aggressive limit on Android since decodes tend to take
2615 // longer on these devices.
2616 settings.min_image_bytes_to_checker = 512 * 1024; // 512kB
2617
2618 // Re-rasterization of checker-imaged content with software raster can be too
2619 // costly on Android.
2620 settings.only_checker_images_with_gpu_raster = true;
2621#endif
2622
2623 auto switch_value_as_int = [](const base::CommandLine& command_line,
2624 const std::string& switch_string, int min_value,
2625 int max_value, int* result) {
2626 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
2627 int int_value;
2628 if (base::StringToInt(string_value, &int_value) && int_value >= min_value &&
2629 int_value <= max_value) {
2630 *result = int_value;
2631 return true;
2632 } else {
2633 LOG(WARNING) << "Failed to parse switch " << switch_string << ": "
2634 << string_value;
2635 return false;
2636 }
2637 };
2638
2639 int default_tile_size = 256;
2640#if defined(OS_ANDROID)
2641 const gfx::Size screen_size =
2642 gfx::ScaleToFlooredSize(initial_screen_size, initial_device_scale_factor);
2643 int display_width = screen_size.width();
2644 int display_height = screen_size.height();
2645 int numTiles = (display_width * display_height) / (256 * 256);
2646 if (numTiles > 16)
2647 default_tile_size = 384;
2648 if (numTiles >= 40)
2649 default_tile_size = 512;
2650
2651 // Adjust for some resolutions that barely straddle an extra
2652 // tile when in portrait mode. This helps worst case scroll/raster
2653 // by not needing a full extra tile for each row.
2654 constexpr int tolerance = 10; // To avoid rounding errors.
2655 int portrait_width = std::min(display_width, display_height);
2656 if (default_tile_size == 256 && std::abs(portrait_width - 768) < tolerance)
2657 default_tile_size += 32;
2658 if (default_tile_size == 384 && std::abs(portrait_width - 1200) < tolerance)
2659 default_tile_size += 32;
2660#elif defined(OS_CHROMEOS) || defined(OS_MACOSX)
2661 // Use 512 for high DPI (dsf=2.0f) devices.
2662 if (initial_device_scale_factor >= 2.0f)
2663 default_tile_size = 512;
2664#endif
2665
2666 // TODO(danakj): This should not be a setting O_O; it should change when the
2667 // device scale factor on LayerTreeHost changes.
2668 settings.default_tile_size = gfx::Size(default_tile_size, default_tile_size);
2669 if (cmd.HasSwitch(switches::kDefaultTileWidth)) {
2670 int tile_width = 0;
2671 switch_value_as_int(cmd, switches::kDefaultTileWidth, 1,
2672 std::numeric_limits<int>::max(), &tile_width);
2673 settings.default_tile_size.set_width(tile_width);
2674 }
2675 if (cmd.HasSwitch(switches::kDefaultTileHeight)) {
2676 int tile_height = 0;
2677 switch_value_as_int(cmd, switches::kDefaultTileHeight, 1,
2678 std::numeric_limits<int>::max(), &tile_height);
2679 settings.default_tile_size.set_height(tile_height);
2680 }
2681
2682 int max_untiled_layer_width = settings.max_untiled_layer_size.width();
2683 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) {
2684 switch_value_as_int(cmd, switches::kMaxUntiledLayerWidth, 1,
2685 std::numeric_limits<int>::max(),
2686 &max_untiled_layer_width);
2687 }
2688 int max_untiled_layer_height = settings.max_untiled_layer_size.height();
2689 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) {
2690 switch_value_as_int(cmd, switches::kMaxUntiledLayerHeight, 1,
2691 std::numeric_limits<int>::max(),
2692 &max_untiled_layer_height);
2693 }
2694
2695 settings.max_untiled_layer_size =
2696 gfx::Size(max_untiled_layer_width, max_untiled_layer_height);
2697
2698 settings.gpu_rasterization_msaa_sample_count =
2699 compositor_deps->GetGpuRasterizationMSAASampleCount();
2700 settings.gpu_rasterization_forced =
2701 compositor_deps->IsGpuRasterizationForced();
2702
2703 settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled();
2704 settings.use_zero_copy = compositor_deps->IsZeroCopyEnabled();
2705 settings.use_partial_raster = compositor_deps->IsPartialRasterEnabled();
2706 settings.enable_elastic_overscroll =
2707 compositor_deps->IsElasticOverscrollEnabled();
2708 settings.resource_settings.use_gpu_memory_buffer_resources =
2709 compositor_deps->IsGpuMemoryBufferCompositorResourcesEnabled();
2710 settings.use_painted_device_scale_factor =
2711 compositor_deps->IsUseZoomForDSFEnabled();
2712
2713 // Build LayerTreeSettings from command line args.
2714 if (cmd.HasSwitch(cc::switches::kBrowserControlsShowThreshold)) {
2715 std::string top_threshold_str =
2716 cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsShowThreshold);
2717 double show_threshold;
2718 if (base::StringToDouble(top_threshold_str, &show_threshold) &&
2719 show_threshold >= 0.f && show_threshold <= 1.f)
2720 settings.top_controls_show_threshold = show_threshold;
2721 }
2722
2723 if (cmd.HasSwitch(cc::switches::kBrowserControlsHideThreshold)) {
2724 std::string top_threshold_str =
2725 cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsHideThreshold);
2726 double hide_threshold;
2727 if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
2728 hide_threshold >= 0.f && hide_threshold <= 1.f)
2729 settings.top_controls_hide_threshold = hide_threshold;
2730 }
2731
Philip Rogersc55ab6a2018-12-05 17:29:192732 // Blink sends cc a layer list and property trees when either
2733 // BlinkGenPropertyTrees or CompositeAfterPaint are enabled.
Philip Rogersfc2f1162018-10-17 18:28:312734 settings.use_layer_lists =
2735 blink::WebRuntimeFeatures::IsBlinkGenPropertyTreesEnabled() ||
Philip Rogersc55ab6a2018-12-05 17:29:192736 blink::WebRuntimeFeatures::IsCompositeAfterPaintEnabled();
danakj4b347212018-07-04 17:55:172737
David Bokan163b6a72018-10-25 22:03:492738 // Blink currently doesn't support setting fractional scroll offsets so CC
2739 // must send integer values. We plan to eventually make Blink use fractional
2740 // offsets internally: https://crbug.com/414283.
2741 settings.commit_fractional_scroll_deltas =
2742 blink::WebRuntimeFeatures::IsFractionalScrollOffsetsEnabled();
2743
danakj4b347212018-07-04 17:55:172744 // The means the renderer compositor has 2 possible modes:
2745 // - Threaded compositing with a scheduler.
Kent Tamura21d1de62018-12-10 04:45:202746 // - Single threaded compositing without a scheduler (for web tests only).
2747 // Using the scheduler in web tests introduces additional composite steps
danakj4b347212018-07-04 17:55:172748 // that create flakiness.
2749 settings.single_thread_proxy_scheduler = false;
2750
2751 // These flags should be mirrored by UI versions in ui/compositor/.
2752 if (cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders))
2753 settings.initial_debug_state.show_debug_borders.set();
2754 settings.initial_debug_state.show_layer_animation_bounds_rects =
2755 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
2756 settings.initial_debug_state.show_paint_rects =
2757 cmd.HasSwitch(switches::kShowPaintRects);
2758 settings.initial_debug_state.show_property_changed_rects =
2759 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects);
2760 settings.initial_debug_state.show_surface_damage_rects =
2761 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects);
2762 settings.initial_debug_state.show_screen_space_rects =
2763 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects);
2764
2765 settings.initial_debug_state.SetRecordRenderingStats(
2766 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
2767 settings.enable_surface_synchronization =
2768 features::IsSurfaceSynchronizationEnabled();
2769 settings.build_hit_test_data = features::IsVizHitTestingSurfaceLayerEnabled();
2770
2771 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
2772 const int kMinSlowDownScaleFactor = 0;
2773 const int kMaxSlowDownScaleFactor = INT_MAX;
2774 switch_value_as_int(
2775 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor,
2776 kMaxSlowDownScaleFactor,
2777 &settings.initial_debug_state.slow_down_raster_scale_factor);
2778 }
2779
2780 // This is default overlay scrollbar settings for Android and DevTools mobile
2781 // emulator. Aura Overlay Scrollbar will override below.
2782 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY;
2783 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
2784 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300);
2785 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
2786
2787#if defined(OS_ANDROID)
2788 bool using_synchronous_compositor =
2789 compositor_deps->UsingSynchronousCompositing();
2790 bool using_low_memory_policy = base::SysInfo::IsLowEndDevice();
2791
2792 settings.use_stream_video_draw_quad = true;
2793 settings.using_synchronous_renderer_compositor = using_synchronous_compositor;
2794 if (using_synchronous_compositor) {
2795 // Android WebView uses system scrollbars, so make ours invisible.
2796 // http://crbug.com/677348: This can't be done using hide_scrollbars
2797 // setting because supporting -webkit custom scrollbars is still desired
2798 // on sublayers.
2799 settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR;
2800 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT;
2801
2802 settings.enable_early_damage_check =
2803 cmd.HasSwitch(cc::switches::kCheckDamageEarly);
2804 }
2805 // Android WebView handles root layer flings itself.
2806 settings.ignore_root_layer_flings = using_synchronous_compositor;
2807 // Memory policy on Android WebView does not depend on whether device is
2808 // low end, so always use default policy.
2809 if (using_low_memory_policy && !using_synchronous_compositor) {
2810 // On low-end we want to be very carefull about killing other
2811 // apps. So initially we use 50% more memory to avoid flickering
2812 // or raster-on-demand.
2813 settings.max_memory_for_prepaint_percentage = 67;
2814 } else {
2815 // On other devices we have increased memory excessively to avoid
2816 // raster-on-demand already, so now we reserve 50% _only_ to avoid
2817 // raster-on-demand, and use 50% of the memory otherwise.
2818 settings.max_memory_for_prepaint_percentage = 50;
2819 }
2820
2821 // TODO(danakj): Only do this on low end devices.
2822 settings.create_low_res_tiling = true;
2823
2824#else // defined(OS_ANDROID)
2825 bool using_synchronous_compositor = false; // Only for Android WebView.
2826 // On desktop, we never use the low memory policy unless we are simulating
2827 // low-end mode via a switch.
2828 bool using_low_memory_policy =
2829 cmd.HasSwitch(switches::kEnableLowEndDeviceMode);
2830
2831 if (ui::IsOverlayScrollbarEnabled()) {
2832 settings.scrollbar_animator = cc::LayerTreeSettings::AURA_OVERLAY;
2833 settings.scrollbar_fade_delay = ui::kOverlayScrollbarFadeDelay;
2834 settings.scrollbar_fade_duration = ui::kOverlayScrollbarFadeDuration;
2835 settings.scrollbar_thinning_duration =
2836 ui::kOverlayScrollbarThinningDuration;
2837 settings.scrollbar_flash_after_any_scroll_update =
2838 ui::OverlayScrollbarFlashAfterAnyScrollUpdate();
2839 settings.scrollbar_flash_when_mouse_enter =
2840 ui::OverlayScrollbarFlashWhenMouseEnter();
2841 }
2842
2843 // On desktop, if there's over 4GB of memory on the machine, increase the
2844 // working set size to 256MB for both gpu and software.
2845 const int kImageDecodeMemoryThresholdMB = 4 * 1024;
2846 if (base::SysInfo::AmountOfPhysicalMemoryMB() >=
2847 kImageDecodeMemoryThresholdMB) {
2848 settings.decoded_image_working_set_budget_bytes = 256 * 1024 * 1024;
2849 } else {
2850 // This is the default, but recorded here as well.
2851 settings.decoded_image_working_set_budget_bytes = 128 * 1024 * 1024;
2852 }
2853#endif // defined(OS_ANDROID)
2854
2855 if (using_low_memory_policy) {
2856 // RGBA_4444 textures are only enabled:
2857 // - If the user hasn't explicitly disabled them
2858 // - If system ram is <= 512MB (1GB devices are sometimes low-end).
2859 // - If we are not running in a WebView, where 4444 isn't supported.
2860 if (!cmd.HasSwitch(switches::kDisableRGBA4444Textures) &&
2861 base::SysInfo::AmountOfPhysicalMemoryMB() <= 512 &&
2862 !using_synchronous_compositor) {
2863 settings.use_rgba_4444 = viz::RGBA_4444;
2864
2865 // If we are going to unpremultiply and dither these tiles, we need to
2866 // allocate an additional RGBA_8888 intermediate for each tile
2867 // rasterization when rastering to RGBA_4444 to allow for dithering.
2868 // Setting a reasonable sized max tile size allows this intermediate to
2869 // be consistently reused.
2870 if (base::FeatureList::IsEnabled(
2871 kUnpremultiplyAndDitherLowBitDepthTiles)) {
2872 settings.max_gpu_raster_tile_size = gfx::Size(512, 256);
2873 settings.unpremultiply_and_dither_low_bit_depth_tiles = true;
2874 }
2875 }
2876 }
2877
2878 if (cmd.HasSwitch(switches::kEnableLowResTiling))
2879 settings.create_low_res_tiling = true;
2880 if (cmd.HasSwitch(switches::kDisableLowResTiling))
2881 settings.create_low_res_tiling = false;
2882
2883 if (cmd.HasSwitch(switches::kEnableRGBA4444Textures) &&
2884 !cmd.HasSwitch(switches::kDisableRGBA4444Textures)) {
2885 settings.use_rgba_4444 = true;
2886 }
2887
2888 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB
2889 // Use 1/4th of staging buffers on low-end devices.
2890 if (base::SysInfo::IsLowEndDevice())
2891 settings.max_staging_buffer_usage_in_bytes /= 4;
2892
2893 cc::ManagedMemoryPolicy defaults = settings.memory_policy;
2894 settings.memory_policy = GetGpuMemoryPolicy(defaults, initial_screen_size,
2895 initial_device_scale_factor);
2896
2897 settings.disallow_non_exact_resource_reuse =
2898 cmd.HasSwitch(switches::kDisallowNonExactResourceReuse);
2899#if defined(OS_ANDROID)
2900 // TODO(crbug.com/746931): This feature appears to be causing visual
2901 // corruption on certain android devices. Will investigate and re-enable.
2902 settings.disallow_non_exact_resource_reuse = true;
2903#endif
2904
2905 if (cmd.HasSwitch(switches::kRunAllCompositorStagesBeforeDraw)) {
2906 settings.wait_for_all_pipeline_stages_before_draw = true;
2907 settings.enable_latency_recovery = false;
2908 }
2909
2910 settings.enable_image_animation_resync =
2911 !cmd.HasSwitch(switches::kDisableImageAnimationResync);
2912
2913 settings.always_request_presentation_time =
2914 cmd.HasSwitch(cc::switches::kAlwaysRequestPresentationTime);
Karolina Soltys4d60b402018-10-01 19:28:202915
2916 settings.send_compositor_frame_ack = false;
2917
danakj4b347212018-07-04 17:55:172918 return settings;
2919}
2920
2921// static
2922cc::ManagedMemoryPolicy RenderWidget::GetGpuMemoryPolicy(
2923 const cc::ManagedMemoryPolicy& default_policy,
2924 const gfx::Size& initial_screen_size,
2925 float initial_device_scale_factor) {
2926 cc::ManagedMemoryPolicy actual = default_policy;
2927 actual.bytes_limit_when_visible = 0;
2928
2929 // If the value was overridden on the command line, use the specified value.
2930 static bool client_hard_limit_bytes_overridden =
2931 base::CommandLine::ForCurrentProcess()->HasSwitch(
2932 switches::kForceGpuMemAvailableMb);
2933 if (client_hard_limit_bytes_overridden) {
2934 if (base::StringToSizeT(
2935 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
2936 switches::kForceGpuMemAvailableMb),
2937 &actual.bytes_limit_when_visible))
2938 actual.bytes_limit_when_visible *= 1024 * 1024;
2939 return actual;
2940 }
2941
2942#if defined(OS_ANDROID)
2943 // We can't query available GPU memory from the system on Android.
2944 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports
2945 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports
2946 // 128MB java heap size). First we estimate physical memory using both.
2947 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB();
2948 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
2949 size_t physical_memory_mb = 0;
2950 if (base::SysInfo::IsLowEndDevice()) {
2951 // TODO(crbug.com/742534): The code below appears to no longer work.
2952 // |dalvik_mb| no longer follows the expected heuristic pattern, causing us
2953 // to over-estimate memory on low-end devices. This entire section probably
2954 // needs to be re-written, but for now we can address the low-end Android
2955 // issues by ignoring |dalvik_mb|.
2956 physical_memory_mb = physical_mb;
2957 } else if (dalvik_mb >= 256) {
2958 physical_memory_mb = dalvik_mb * 4;
2959 } else {
2960 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3);
2961 }
2962
2963 // Now we take a default of 1/8th of memory on high-memory devices,
2964 // and gradually scale that back for low-memory devices (to be nicer
2965 // to other apps so they don't get killed). Examples:
2966 // Nexus 4/10(2GB) 256MB (normally 128MB)
2967 // Droid Razr M(1GB) 114MB (normally 57MB)
2968 // Galaxy Nexus(1GB) 100MB (normally 50MB)
2969 // Xoom(1GB) 100MB (normally 50MB)
2970 // Nexus S(low-end) 8MB (normally 8MB)
2971 // Note that the compositor now uses only some of this memory for
2972 // pre-painting and uses the rest only for 'emergencies'.
2973 if (actual.bytes_limit_when_visible == 0) {
2974 // NOTE: Non-low-end devices use only 50% of these limits,
2975 // except during 'emergencies' where 100% can be used.
2976 if (physical_memory_mb >= 1536)
2977 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB
2978 else if (physical_memory_mb >= 1152)
2979 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB
2980 else if (physical_memory_mb >= 768)
2981 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB
2982 else if (physical_memory_mb >= 513)
2983 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB
2984 else
2985 // Devices with this little RAM have very little headroom so we hardcode
2986 // the limit rather than relying on the heuristics above. (They also use
2987 // 4444 textures so we can use a lower limit.)
2988 actual.bytes_limit_when_visible = 8;
2989
2990 actual.bytes_limit_when_visible =
2991 actual.bytes_limit_when_visible * 1024 * 1024;
2992 // Clamp the observed value to a specific range on Android.
2993 actual.bytes_limit_when_visible = std::max(
2994 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024));
2995 actual.bytes_limit_when_visible =
2996 std::min(actual.bytes_limit_when_visible,
2997 static_cast<size_t>(256 * 1024 * 1024));
2998 }
2999 actual.priority_cutoff_when_visible =
3000 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
3001#else
3002 // Ignore what the system said and give all clients the same maximum
3003 // allocation on desktop platforms.
3004 actual.bytes_limit_when_visible = 512 * 1024 * 1024;
3005 actual.priority_cutoff_when_visible =
3006 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
3007
3008 // For large monitors (4k), double the tile memory to avoid frequent out of
3009 // memory problems. 4k could mean a screen width of anywhere from 3840 to 4096
3010 // (see https://en.wikipedia.org/wiki/4K_resolution). We use 3500 as a proxy
3011 // for "large enough".
3012 static const int kLargeDisplayThreshold = 3500;
3013 int display_width =
3014 std::round(initial_screen_size.width() * initial_device_scale_factor);
3015 if (display_width >= kLargeDisplayThreshold)
3016 actual.bytes_limit_when_visible *= 2;
3017#endif
3018 return actual;
3019}
3020
Navid Zolghadr8fdb6114e2018-08-29 19:00:543021void RenderWidget::HasPointerRawMoveEventHandlers(bool has_handlers) {
3022 if (input_event_queue_)
3023 input_event_queue_->HasPointerRawMoveEventHandlers(has_handlers);
3024}
3025
Blink Reformat1c4d759e2017-04-09 16:34:543026void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
W. James MacLean662d5382018-03-29 18:33:083027 if (has_touch_handlers_ && *has_touch_handlers_ == has_handlers)
3028 return;
3029
3030 has_touch_handlers_ = has_handlers;
alexclarke7fa93942015-10-21 15:37:113031 if (render_widget_scheduling_state_)
3032 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
Albert J. Wongeb28e7e2018-10-12 00:57:433033 Send(new WidgetHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
[email protected]ce6689f2013-03-29 12:52:553034}
3035
Dave Tapuskadfe486c12017-06-09 16:53:133036void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
3037 if (input_event_queue_)
3038 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
3039}
3040
W. James MacLeand973a55b2018-11-29 21:39:133041void RenderWidget::AnimateDoubleTapZoomInMainFrame(
3042 const blink::WebPoint& point,
3043 const blink::WebRect& rect_to_zoom) {
3044 // Only oopif subframes should be sending this message.
Albert J. Wong7bbf22d2018-12-20 00:27:273045 DCHECK(!delegate());
W. James MacLeand973a55b2018-11-29 21:39:133046 Send(new WidgetHostMsg_AnimateDoubleTapZoomInMainFrame(routing_id(), point,
3047 rect_to_zoom));
3048}
3049
W. James MacLean5372eb72018-12-19 12:56:363050void RenderWidget::ZoomToFindInPageRectInMainFrame(
3051 const blink::WebRect& rect_to_zoom) {
3052 // Only oopif subframes should be sending this message.
Albert J. Wong7bbf22d2018-12-20 00:27:273053 DCHECK(!delegate_);
W. James MacLean5372eb72018-12-19 12:56:363054 Send(new WidgetHostMsg_ZoomToFindInPageRectInMainFrame(routing_id(),
3055 rect_to_zoom));
3056}
3057
Dave Tapuskabafc2ba32017-11-28 01:54:373058void RenderWidget::RequestUnbufferedInputEvents() {
3059 if (input_event_queue_)
3060 input_event_queue_->RequestUnbufferedInputEvents();
3061}
3062
xidachenfa0199e72017-05-11 11:34:263063void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:263064 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:513065 return;
3066
Dave Tapuska04bc5ee92018-04-17 19:03:313067 widget_input_handler_manager_->ProcessTouchAction(touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:513068}
3069
[email protected]e3244ed2014-06-20 20:04:273070void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
3071 render_frame_proxies_.AddObserver(proxy);
W. James MacLean2a90bff2018-11-05 20:52:473072 // During initial page load, the main frame may have received page
3073 // scale factor information before the sub-frame proxies were registered, so
3074 // make sure we pass the page scale factor along here.
3075 proxy->OnPageScaleFactorChanged(page_scale_factor_from_mainframe_);
[email protected]bffc8302014-01-23 20:52:163076}
3077
[email protected]e3244ed2014-06-20 20:04:273078void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
3079 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:163080}
3081
[email protected]de3c5d82014-05-28 22:12:593082void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
3083 render_frames_.AddObserver(frame);
3084}
3085
3086void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
3087 render_frames_.RemoveObserver(frame);
3088}
3089
Saman Samid189e5dfd2017-12-20 22:55:313090void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
3091 browser_plugins_.AddObserver(browser_plugin);
Saman Sami50d1e0c2018-03-13 20:03:493092 browser_plugin->ScreenInfoChanged(GetOriginalScreenInfo());
Saman Samid189e5dfd2017-12-20 22:55:313093}
3094
3095void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
3096 browser_plugins_.RemoveObserver(browser_plugin);
3097}
3098
Albert J. Wong3c93c182018-09-27 17:29:433099void RenderWidget::OnWaitNextFrameForTests(
3100 int main_frame_thread_observer_routing_id) {
danakj53802692018-07-25 21:46:443101 // Sends an ACK to the browser process during the next compositor frame.
Albert J. Wong3c93c182018-09-27 17:29:433102 QueueMessage(new WidgetHostMsg_WaitForNextFrameForTests_ACK(
3103 main_frame_thread_observer_routing_id));
lfg43e08e62016-02-03 18:51:373104}
3105
Fady Samuela863f152018-03-09 16:10:033106const ScreenInfo& RenderWidget::GetWebScreenInfo() const {
3107 return screen_info_;
Christopher Camerone9a30c12018-03-07 08:23:383108}
3109
Fady Samuela863f152018-03-09 16:10:033110const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const {
Christopher Camerone9a30c12018-03-07 08:23:383111 return screen_metrics_emulator_
3112 ? screen_metrics_emulator_->original_screen_info()
Fady Samuela863f152018-03-09 16:10:033113 : screen_info_;
oshima50872a72016-03-04 13:26:183114}
3115
Ella Ge80a52dce2017-11-15 18:01:523116gfx::PointF RenderWidget::ConvertWindowPointToViewport(
3117 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:593118 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:543119 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:523120 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
3121}
3122
3123gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
3124 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:593125}
3126
Blink Reformat1c4d759e2017-04-09 16:34:543127bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:213128 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
3129}
3130
Blink Reformat1c4d759e2017-04-09 16:34:543131void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:213132 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
3133}
3134
Blink Reformat1c4d759e2017-04-09 16:34:543135bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:213136 return mouse_lock_dispatcher_->IsMouseLockedTo(
3137 webwidget_mouse_lock_target_.get());
3138}
3139
Richard Li49fe04d2018-10-21 09:07:193140void RenderWidget::StartDragging(network::mojom::ReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:583141 const WebDragData& data,
3142 WebDragOperationsMask mask,
danakj0c75ad82018-07-10 19:50:123143 const SkBitmap& drag_image,
danakjef1735a2018-11-13 19:34:443144 const gfx::Point& web_image_offset) {
3145 blink::WebRect offset_in_window(web_image_offset.x(), web_image_offset.y(), 0,
3146 0);
Blink Reformat1c4d759e2017-04-09 16:34:543147 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:583148 DropData drop_data(DropDataBuilder::Build(data));
3149 drop_data.referrer_policy = policy;
danakj0c75ad82018-07-10 19:50:123150 gfx::Vector2d image_offset(offset_in_window.x, offset_in_window.y);
3151 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, drag_image,
3152 image_offset, possible_drag_event_info_));
paulmeyer6ef5a792016-11-08 20:33:583153}
3154
kenrb5d78b842017-03-06 21:06:013155uint32_t RenderWidget::GetContentSourceId() {
3156 return current_content_source_id_;
3157}
3158
Saman Samif7731342018-01-24 22:18:443159void RenderWidget::DidNavigate() {
Saman Sami26a1fcd2018-04-10 17:12:213160 ++current_content_source_id_;
danakja6c10012018-07-06 14:25:363161 if (!layer_tree_view_)
Saman Samif7731342018-01-24 22:18:443162 return;
danakja6c10012018-07-06 14:25:363163 layer_tree_view_->SetContentSourceId(current_content_source_id_);
3164 layer_tree_view_->ClearCachesOnNextCommit();
kenrb5d78b842017-03-06 21:06:013165}
3166
lfg8ff33912016-09-13 20:59:213167blink::WebWidget* RenderWidget::GetWebWidget() const {
Albert J. Wong7bbf22d2018-12-20 00:27:273168 if (delegate()) {
3169 blink::WebWidget* delegate_widget = delegate()->GetWebWidgetForWidget();
danakja2c9d0a92018-07-25 20:01:183170 if (delegate_widget)
3171 return delegate_widget;
3172 }
lfg8ff33912016-09-13 20:59:213173 return webwidget_internal_;
3174}
3175
ekaramad2daaf672016-11-10 20:29:013176blink::WebInputMethodController* RenderWidget::GetInputMethodController()
3177 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:383178 if (auto* frame_widget = GetFrameWidget())
3179 return frame_widget->GetActiveWebInputMethodController();
3180
3181 return nullptr;
ekaramad2daaf672016-11-10 20:29:013182}
3183
Dave Tapuska139a72f2017-09-06 21:57:033184void RenderWidget::SetupWidgetInputHandler(
3185 mojom::WidgetInputHandlerRequest request,
3186 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:473187 widget_input_handler_manager_->AddInterface(std::move(request),
3188 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:503189}
3190
Dave Tapuska485aca92017-08-08 00:47:583191void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
3192 // Close the old binding if there was one.
3193 // A RenderWidgetHost should not need more than one channel.
3194 widget_binding_.Close();
3195 widget_binding_.Bind(std::move(request));
3196}
3197
Ken Buchanan94c0beb62018-06-22 19:56:243198void RenderWidget::SetMouseCapture(bool capture) {
3199 if (mojom::WidgetInputHandlerHost* host =
3200 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
3201 host->SetMouseCapture(capture);
3202 }
3203}
3204
danakj53802692018-07-25 21:46:443205void RenderWidget::SetWindowScreenRect(const gfx::Rect& window_screen_rect) {
3206 if (screen_metrics_emulator_)
3207 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
3208 else
3209 window_screen_rect_ = window_screen_rect;
3210}
3211
Fady Samuelca9ecb72018-05-05 05:59:273212bool RenderWidget::IsSurfaceSynchronizationEnabled() const {
danakja6c10012018-07-06 14:25:363213 return layer_tree_view_ &&
3214 layer_tree_view_->IsSurfaceSynchronizationEnabled();
Fady Samuelca9ecb72018-05-05 05:59:273215}
3216
W. James MacLean2a90bff2018-11-05 20:52:473217void RenderWidget::PageScaleFactorChanged(float page_scale_factor) {
3218 // Only the main frame pulls page scale information from the layer tree host.
3219 // Pages scale is shared with non-mainframe widgets via the IPC for
3220 // OnSynchronizeVisualProperties.
Albert J. Wong7bbf22d2018-12-20 00:27:273221 if (!delegate())
W. James MacLean2a90bff2018-11-05 20:52:473222 return;
3223
3224 page_scale_factor_from_mainframe_ = page_scale_factor;
3225 for (auto& observer : render_frame_proxies_)
3226 observer.OnPageScaleFactorChanged(page_scale_factor);
3227}
3228
danakj53802692018-07-25 21:46:443229void RenderWidget::UseSynchronousResizeModeForTesting(bool enable) {
3230 resizing_mode_selector_->set_is_synchronous_mode(enable);
danakja2c9d0a92018-07-25 20:01:183231}
3232
3233void RenderWidget::SetDeviceScaleFactorForTesting(float factor) {
3234 device_scale_factor_for_testing_ = factor;
3235
3236 VisualProperties visual_properties;
3237 visual_properties.screen_info = screen_info_;
3238 visual_properties.screen_info.device_scale_factor = factor;
3239 visual_properties.new_size = size();
3240 visual_properties.visible_viewport_size = visible_viewport_size_;
3241 visual_properties.compositor_viewport_pixel_size =
3242 gfx::ScaleToCeiledSize(size(), factor);
3243 visual_properties.browser_controls_shrink_blink_size = false;
3244 visual_properties.top_controls_height = 0.f;
3245 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3246 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:173247 visual_properties.local_surface_id_allocation =
3248 local_surface_id_allocation_from_parent_;
W. James MacLean2a90bff2018-11-05 20:52:473249 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183250 // We are changing the device scale factor from the renderer, so allocate a
3251 // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
3252 if (layer_tree_view_)
3253 layer_tree_view_->RequestNewLocalSurfaceId();
3254
3255 OnSynchronizeVisualProperties(visual_properties);
3256}
3257
3258void RenderWidget::SetDeviceColorSpaceForTesting(
3259 const gfx::ColorSpace& color_space) {
3260 VisualProperties visual_properties;
3261 visual_properties.screen_info = screen_info_;
3262 visual_properties.screen_info.color_space = color_space;
3263 visual_properties.new_size = size();
3264 visual_properties.visible_viewport_size = visible_viewport_size_;
3265 visual_properties.compositor_viewport_pixel_size =
3266 compositor_viewport_pixel_size_;
3267 visual_properties.browser_controls_shrink_blink_size = false;
3268 visual_properties.top_controls_height = 0.f;
3269 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3270 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:173271 visual_properties.local_surface_id_allocation =
3272 local_surface_id_allocation_from_parent_;
W. James MacLean2a90bff2018-11-05 20:52:473273 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183274 // We are changing the device color space from the renderer, so allocate a
3275 // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
3276 if (layer_tree_view_)
3277 layer_tree_view_->RequestNewLocalSurfaceId();
3278 OnSynchronizeVisualProperties(visual_properties);
3279}
3280
3281void RenderWidget::SetWindowRectSynchronouslyForTesting(
3282 const gfx::Rect& new_window_rect) {
3283 SetWindowRectSynchronously(new_window_rect);
3284}
3285
3286void RenderWidget::EnableAutoResizeForTesting(const gfx::Size& min_size,
3287 const gfx::Size& max_size) {
3288 VisualProperties visual_properties;
3289 visual_properties.auto_resize_enabled = true;
3290 visual_properties.min_size_for_auto_resize = min_size;
3291 visual_properties.max_size_for_auto_resize = max_size;
Fady Samuel84d8a1f72018-11-08 00:26:173292 visual_properties.local_surface_id_allocation =
3293 base::Optional<viz::LocalSurfaceIdAllocation>(
3294 viz::LocalSurfaceIdAllocation(
3295 viz::LocalSurfaceId(1, 1, base::UnguessableToken::Create()),
3296 base::TimeTicks::Now()));
W. James MacLean2a90bff2018-11-05 20:52:473297 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183298 OnSynchronizeVisualProperties(visual_properties);
3299}
3300
3301void RenderWidget::DisableAutoResizeForTesting(const gfx::Size& new_size) {
3302 if (!auto_resize_mode_)
3303 return;
3304
3305 VisualProperties visual_properties;
3306 visual_properties.auto_resize_enabled = false;
3307 visual_properties.screen_info = screen_info_;
3308 visual_properties.new_size = new_size;
3309 visual_properties.compositor_viewport_pixel_size =
3310 compositor_viewport_pixel_size_;
3311 visual_properties.browser_controls_shrink_blink_size =
3312 browser_controls_shrink_blink_size_;
3313 visual_properties.top_controls_height = top_controls_height_;
3314 visual_properties.visible_viewport_size = visible_viewport_size_;
3315 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3316 visual_properties.display_mode = display_mode_;
W. James MacLean2a90bff2018-11-05 20:52:473317 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183318 OnSynchronizeVisualProperties(visual_properties);
3319}
3320
EhsanK955ba582017-11-30 21:14:403321blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:383322 if (auto* frame_widget = GetFrameWidget())
3323 return frame_widget->FocusedWebLocalFrameInWidget();
3324 return nullptr;
EhsanK955ba582017-11-30 21:14:403325}
3326
EhsanK22d482e2017-08-10 17:29:493327#if BUILDFLAG(ENABLE_PLUGINS)
3328PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:383329 blink::WebFrameWidget* frame_widget = GetFrameWidget();
3330 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:493331 return nullptr;
3332
3333 // Focused pepper instance might not always be in the focused frame. For
3334 // instance if a pepper instance and its embedder frame are focused an then
3335 // another frame takes focus using javascript, the embedder frame will no
3336 // longer be focused while the pepper instance is (the embedder frame's
3337 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
3338 // is fullscreen, clicking into the pepper will not refocus the embedder
3339 // frame. This is why we have to traverse the whole frame tree to find the
3340 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:383341 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:493342 while (current_frame) {
3343 RenderFrameImpl* render_frame =
3344 current_frame->IsWebLocalFrame()
3345 ? RenderFrameImpl::FromWebFrame(current_frame)
3346 : nullptr;
3347 if (render_frame && render_frame->focused_pepper_plugin())
3348 return render_frame->focused_pepper_plugin();
3349 current_frame = current_frame->TraverseNext();
3350 }
3351 return nullptr;
3352}
3353#endif
3354
Ken Buchananb2c9e262018-03-10 16:53:313355gfx::Rect RenderWidget::ViewportVisibleRect() {
danakj6dcbc5962018-11-16 16:45:423356 return for_child_local_root_frame_
3357 ? compositor_visible_rect_
3358 : gfx::Rect(compositor_viewport_pixel_size_);
Ken Buchananb2c9e262018-03-10 16:53:313359}
3360
Hajime Hoshi315a61f2018-08-14 17:27:283361// static
3362scoped_refptr<base::SingleThreadTaskRunner>
3363RenderWidget::GetCleanupTaskRunner() {
3364 return RenderThreadImpl::current_blink_platform_impl()
3365 ->main_thread_scheduler()
3366 ->CleanupTaskRunner();
3367}
3368
Saman Sami50d1e0c2018-03-13 20:03:493369base::WeakPtr<RenderWidget> RenderWidget::AsWeakPtr() {
3370 return weak_ptr_factory_.GetWeakPtr();
3371}
3372
[email protected]e9ff79c2012-10-19 21:31:263373} // namespace content