blob: c71e60f105222ce98855f41df2f54dc97286bc29 [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)
Albert J. Wong3c93c182018-09-27 17:29:43591 IPC_MESSAGE_HANDLER(WidgetMsg_SetTextDirection, OnSetTextDirection)
592 IPC_MESSAGE_HANDLER(WidgetMsg_SetBounds_ACK, OnRequestSetBoundsAck)
593 IPC_MESSAGE_HANDLER(WidgetMsg_UpdateScreenRects, OnUpdateScreenRects)
594 IPC_MESSAGE_HANDLER(WidgetMsg_ForceRedraw, OnForceRedraw)
595 IPC_MESSAGE_HANDLER(WidgetMsg_SetViewportIntersection,
kenrbea731792017-01-13 15:10:48596 OnSetViewportIntersection)
Albert J. Wong3c93c182018-09-27 17:29:43597 IPC_MESSAGE_HANDLER(WidgetMsg_SetIsInert, OnSetIsInert)
598 IPC_MESSAGE_HANDLER(WidgetMsg_SetInheritedEffectiveTouchAction,
sunxd540a9962018-05-24 22:51:06599 OnSetInheritedEffectiveTouchAction)
Albert J. Wong3c93c182018-09-27 17:29:43600 IPC_MESSAGE_HANDLER(WidgetMsg_UpdateRenderThrottlingStatus,
Ken Buchanan8a319fb2017-11-15 18:37:12601 OnUpdateRenderThrottlingStatus)
Albert J. Wong3c93c182018-09-27 17:29:43602 IPC_MESSAGE_HANDLER(WidgetMsg_WaitForNextFrameForTests,
lfg43e08e62016-02-03 18:51:37603 OnWaitNextFrameForTests)
paulmeyer90f6c31d2016-11-12 00:17:59604 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
605 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
606 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
607 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21608 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
609 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
610 OnDragSourceSystemDragEnded)
[email protected]a95986a82010-12-24 06:19:28611 IPC_MESSAGE_UNHANDLED(handled = false)
612 IPC_END_MESSAGE_MAP()
613 return handled;
614}
initial.commit09911bf2008-07-26 23:55:29615
616bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42617 // Don't send any messages after the browser has told us to close, and filter
danakj6dcbc5962018-11-16 16:45:42618 // most outgoing messages when frozen.
619 if (closing_) {
620 delete message;
621 return false;
622 }
623 if (is_frozen_ && !SwappedOutMessages::CanSendWhileSwappedOut(message)) {
initial.commit09911bf2008-07-26 23:55:29624 delete message;
625 return false;
626 }
627
628 // If given a messsage without a routing ID, then assign our routing ID.
629 if (message->routing_id() == MSG_ROUTING_NONE)
630 message->set_routing_id(routing_id_);
631
[email protected]380244092011-10-07 17:26:27632 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44633}
634
dtapuska014ed082016-11-11 21:58:48635void RenderWidget::SendOrCrash(IPC::Message* message) {
636 bool result = Send(message);
637 CHECK(closing_ || result) << "Failed to send message";
638}
639
ekaramad5aff1942017-01-06 01:26:35640bool RenderWidget::ShouldHandleImeEvents() const {
Albert J. Wong7bbf22d2018-12-20 00:27:27641 if (delegate())
danakj89ae4532018-12-12 22:52:55642 return has_focus_;
643 if (for_child_local_root_frame_) {
644 // TODO(ekaramad): We track page focus in all RenderViews on the page but
645 // the RenderWidgets corresponding to child local roots do not get the
646 // update. For now, this method returns true when the RenderWidget is for a
647 // child local frame, i.e., IME events will be processed regardless of page
648 // focus. We should revisit this after page focus for OOPIFs has been fully
649 // resolved (https://crbug.com/689777).
650 return true;
651 }
652 // Not a frame widget.
653 return false;
ekaramad5aff1942017-01-06 01:26:35654}
655
initial.commit09911bf2008-07-26 23:55:29656void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32657 DCHECK(content::RenderThread::Get());
658 if (closing_)
659 return;
danakj292b63e2018-11-19 20:47:06660 for (auto& observer : render_frames_)
661 observer.WidgetWillClose();
dchengd96a27a2015-07-24 20:17:32662 closing_ = true;
663
664 // Browser correspondence is no longer needed at this point.
665 if (routing_id_ != MSG_ROUTING_NONE) {
666 RenderThread::Get()->RemoveRoute(routing_id_);
Albert J. Wongcb004632018-07-10 22:58:25667 g_routing_id_widget_map.Get().erase(routing_id_);
danakj678f0252018-11-09 21:46:34668 if (RenderThreadImpl::current()) {
669 // RenderWidgets may be hidden when they are closed. If we were previously
670 // hidden, we are being counted as such in RenderThreadImpl. Thus we
671 // remove that count here by calling WidgetRestored() even though we're
672 // clearly not becoming visible here.
673 if (is_hidden_)
674 RenderThreadImpl::current()->WidgetRestored();
dchengd96a27a2015-07-24 20:17:32675 RenderThreadImpl::current()->WidgetDestroyed();
danakj678f0252018-11-09 21:46:34676 }
dchengd96a27a2015-07-24 20:17:32677 }
678
danakj6dcbc5962018-11-16 16:45:42679 if (for_child_local_root_frame_) {
dchengd96a27a2015-07-24 20:17:32680 // Widgets for frames may be created and closed at any time while the frame
Ken Buchananed449bb2018-02-01 21:02:05681 // is alive. However, WebWidget must be closed synchronously because frame
682 // widgets and frames hold pointers to each other. The deferred call to
683 // Close() will complete cleanup and release |this|, but CloseWebWidget()
684 // prevents Close() from attempting to access members of an
685 // already-deleted frame.
686 CloseWebWidget();
dchengd96a27a2015-07-24 20:17:32687 }
Ken Buchananed449bb2018-02-01 21:02:05688 // If there is a Send call on the stack, then it could be dangerous to close
689 // now. Post a task that only gets invoked when there are no nested message
690 // loops.
Hajime Hoshi315a61f2018-08-14 17:27:28691 GetCleanupTaskRunner()->PostNonNestableTask(
692 FROM_HERE, base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32693
694 // Balances the AddRef taken when we called AddRoute.
695 Release();
initial.commit09911bf2008-07-26 23:55:29696}
697
Fady Samuel799e72192018-04-25 21:16:57698void RenderWidget::OnSynchronizeVisualProperties(
danakja2c9d0a92018-07-25 20:01:18699 const VisualProperties& original_params) {
700 TRACE_EVENT0("renderer", "RenderWidget::OnSynchronizeVisualProperties");
EhsanKbd2cea992017-11-23 18:49:08701
danakja2c9d0a92018-07-25 20:01:18702 VisualProperties params = original_params;
Albert J. Wong7bbf22d2018-12-20 00:27:27703 if (delegate()) {
704 delegate()->ApplyNewSizeForWidget(size_, params.new_size);
danakja2c9d0a92018-07-25 20:01:18705
706 if (display_mode_ != params.display_mode) {
707 display_mode_ = params.display_mode;
Albert J. Wong7bbf22d2018-12-20 00:27:27708 delegate()->ApplyNewDisplayModeForWidget(params.display_mode);
danakja2c9d0a92018-07-25 20:01:18709 }
710
711 bool auto_resize_mode_changed =
712 auto_resize_mode_ != params.auto_resize_enabled;
713 auto_resize_mode_ = params.auto_resize_enabled;
714 min_size_for_auto_resize_ = params.min_size_for_auto_resize;
715 max_size_for_auto_resize_ = params.max_size_for_auto_resize;
716
717 if (auto_resize_mode_) {
718 gfx::Size min_auto_size = min_size_for_auto_resize_;
719 gfx::Size max_auto_size = max_size_for_auto_resize_;
720 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
721 min_auto_size = gfx::ScaleToCeiledSize(
722 min_auto_size, params.screen_info.device_scale_factor);
723 max_auto_size = gfx::ScaleToCeiledSize(
724 max_auto_size, params.screen_info.device_scale_factor);
725 }
Albert J. Wong7bbf22d2018-12-20 00:27:27726 delegate()->ApplyAutoResizeLimitsForWidget(min_auto_size, max_auto_size);
danakja2c9d0a92018-07-25 20:01:18727 } else if (auto_resize_mode_changed) {
Albert J. Wong7bbf22d2018-12-20 00:27:27728 delegate()->DisableAutoResizeForWidget();
danakja2c9d0a92018-07-25 20:01:18729 if (params.new_size.IsEmpty())
730 return;
731 }
732
733 browser_controls_shrink_blink_size_ =
734 params.browser_controls_shrink_blink_size;
735 top_controls_height_ = params.top_controls_height;
736 bottom_controls_height_ = params.bottom_controls_height;
737
738 // TODO(fsamuel): Modifies the |params| that are used for
739 // SynchronizeVisualProperties(), but does not used this modified
740 // device_scale_factor for the auto-resize values, which is probably a bug.
741 if (device_scale_factor_for_testing_) {
742 params.screen_info.device_scale_factor =
743 *device_scale_factor_for_testing_;
744 params.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
745 params.new_size, params.screen_info.device_scale_factor);
746 }
[email protected]b2e4c70132013-10-03 02:07:51747 }
748
danakja2c9d0a92018-07-25 20:01:18749 if (!resizing_mode_selector_->ShouldAbortOnResize(this, params)) {
750 if (screen_metrics_emulator_) {
751 screen_metrics_emulator_->OnSynchronizeVisualProperties(params);
752 } else {
753 gfx::Size old_visible_viewport_size = visible_viewport_size_;
754 SynchronizeVisualProperties(params);
755 if (old_visible_viewport_size != visible_viewport_size_) {
756 for (auto& render_frame : render_frames_)
757 render_frame.DidChangeVisibleViewport();
758 }
759 }
Fady Samuel799e72192018-04-25 21:16:57760 }
761
Albert J. Wong7bbf22d2018-12-20 00:27:27762 if (delegate() && params.scroll_focused_node_into_view)
763 delegate()->ScrollFocusedNodeIntoViewForWidget();
initial.commit09911bf2008-07-26 23:55:29764}
765
dgozman9260b0a12015-03-16 13:45:20766void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02767 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39768 if (!screen_metrics_emulator_) {
Fady Samuel4255c182018-05-24 20:42:36769 VisualProperties visual_properties;
770 visual_properties.screen_info = screen_info_;
771 visual_properties.new_size = size_;
772 visual_properties.compositor_viewport_pixel_size =
Christopher Cameronaad15a0d2018-03-09 03:47:33773 compositor_viewport_pixel_size_;
Fady Samuel84d8a1f72018-11-08 00:26:17774 visual_properties.local_surface_id_allocation =
775 local_surface_id_allocation_from_parent_;
Fady Samuel4255c182018-05-24 20:42:36776 visual_properties.visible_viewport_size = visible_viewport_size_;
777 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
778 visual_properties.display_mode = display_mode_;
W. James MacLean2a90bff2018-11-05 20:52:47779 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
mfomitchev2600fd7c2016-02-17 20:53:39780 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
Albert J. Wong3c93c182018-09-27 17:29:43781 this, params, visual_properties, widget_screen_rect_,
Fady Samuel4255c182018-05-24 20:42:36782 window_screen_rect_));
oshima50872a72016-03-04 13:26:18783 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39784 } else {
dgozman9260b0a12015-03-16 13:45:20785 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39786 }
dgozman9260b0a12015-03-16 13:45:20787}
788
789void RenderWidget::OnDisableDeviceEmulation() {
790 screen_metrics_emulator_.reset();
791}
792
initial.commit09911bf2008-07-26 23:55:29793void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31794 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29795 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03796 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55797 for (auto& observer : render_frames_)
798 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29799}
800
Saman Samie61e5c032018-11-05 22:11:44801void RenderWidget::OnWasShown(base::TimeTicks show_request_timestamp,
802 bool was_evicted) {
[email protected]9e2e4632012-07-27 16:38:41803 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
danakj57f139f2018-11-19 19:23:46804 // TODO(danakj): Nothing should happen ideally if the RenderWidget is frozen!
805 // It's not visible! However.. the RenderView needs to see it as visible in
806 // order to make the Page visible /o\ so this is hard. We need to detangle
807 // page visibility from the main widget. https://crbug.com/419087
danakj678f0252018-11-09 21:46:34808
tasakb95dbb50c2017-02-08 18:07:50809 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29810 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03811 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55812 for (auto& observer : render_frames_)
813 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29814
Saman Samie61e5c032018-11-05 22:11:44815 if (was_evicted) {
816 for (auto& observer : render_frame_proxies_) {
817 observer.WasEvicted();
818 }
819 }
820
danakja6c10012018-07-06 14:25:36821 if (layer_tree_view_ && !show_request_timestamp.is_null()) {
822 layer_tree_view_->layer_tree_host()->RequestPresentationTimeForNextFrame(
Sadrul Habib Chowdhury8bc43cc2018-06-06 01:48:03823 CreateTabSwitchingTimeRecorder(show_request_timestamp));
[email protected]3399dd822014-08-09 11:14:24824 }
initial.commit09911bf2008-07-26 23:55:29825}
826
Avi Drissman014dec72018-06-07 02:34:01827void RenderWidget::OnRequestSetBoundsAck() {
[email protected]53d3f302009-12-21 04:42:05828 DCHECK(pending_window_rect_count_);
829 pending_window_rect_count_--;
830}
831
Albert J. Wongcb004632018-07-10 22:58:25832void RenderWidget::OnForceRedraw(int snapshot_id) {
833 if (LayerTreeView* ltv = layer_tree_view()) {
834 ltv->layer_tree_host()->RequestPresentationTimeForNextFrame(
835 base::BindOnce(&RenderWidget::DidPresentForceDrawFrame,
836 weak_ptr_factory_.GetWeakPtr(), snapshot_id));
837 ltv->SetNeedsForcedRedraw();
838 }
839}
840
841void RenderWidget::DidPresentForceDrawFrame(
842 int snapshot_id,
843 const gfx::PresentationFeedback& feedback) {
Albert J. Wong3c93c182018-09-27 17:29:43844 Send(new WidgetHostMsg_ForceRedrawComplete(routing_id(), snapshot_id));
Albert J. Wongcb004632018-07-10 22:58:25845}
846
Xianzhu Wangf02017ac2018-10-17 01:47:33847viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::PointF& point,
Ken Buchanan44d7e2f2018-08-23 14:18:05848 gfx::PointF* local_point) {
849 return input_handler_->GetFrameSinkIdAtPoint(point, local_point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22850}
851
Dave Tapuskaea83d3bd2017-06-13 16:14:55852void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31853 const blink::WebCoalescedInputEvent& input_event,
854 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55855 HandledEventCallback callback) {
Albert J. Wong7bbf22d2018-12-20 00:27:27856 if (delegate() && is_frozen_) {
danakja2c9d0a92018-07-25 20:01:18857 std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info,
858 nullptr, base::nullopt);
859 return;
860 }
Dave Tapuskaea83d3bd2017-06-13 16:14:55861 input_handler_->HandleInputEvent(input_event, latency_info,
862 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31863}
864
dtapuska9d46ef7d2017-05-26 19:06:06865scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
866 return input_event_queue_;
867}
868
fsamuel78f86e42016-01-20 04:10:23869void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21870 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54871 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23872}
873
874void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21875 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54876 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23877}
878
alexmos56567492016-09-13 00:52:46879void RenderWidget::OnSetEditCommandsForNextKeyEvent(
880 const EditCommands& edit_commands) {
881 edit_commands_ = edit_commands;
882}
883
Albert J. Wongcb004632018-07-10 22:58:25884void RenderWidget::OnSetActive(bool active) {
Albert J. Wong7bbf22d2018-12-20 00:27:27885 if (delegate())
886 delegate()->SetActiveForWidget(active);
Albert J. Wongcb004632018-07-10 22:58:25887}
888
fsamuel78f86e42016-01-20 04:10:23889void RenderWidget::OnSetFocus(bool enable) {
Albert J. Wong7bbf22d2018-12-20 00:27:27890 if (delegate())
891 delegate()->DidReceiveSetFocusEventForWidget();
danakja2c9d0a92018-07-25 20:01:18892 SetFocus(enable);
893}
894
895void RenderWidget::SetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08896 has_focus_ = enable;
897
lfg8ff33912016-09-13 20:59:21898 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54899 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08900
ericwilligers88e69742016-10-17 19:29:55901 for (auto& observer : render_frames_)
902 observer.RenderWidgetSetFocus(enable);
danakja2c9d0a92018-07-25 20:01:18903
Albert J. Wong7bbf22d2018-12-20 00:27:27904 if (delegate())
905 delegate()->DidChangeFocusForWidget();
fsamuel78f86e42016-01-20 04:10:23906}
907
dtapuska3d5624d32016-08-30 04:34:00908void RenderWidget::SetNeedsMainFrame() {
danakj53f46b82018-12-11 20:55:55909 // The WebWidgetClient is not |this| if tests override it for the WebView and
910 // WebViewClient.
911 blink::WebWidgetClient* client =
Albert J. Wong7bbf22d2018-12-20 00:27:27912 delegate() ? delegate()->GetWebWidgetClientForWidget() : this;
danakj53f46b82018-12-11 20:55:55913 client->ScheduleAnimation();
dtapuska3d5624d32016-08-30 04:34:00914}
915
fsamuel78f86e42016-01-20 04:10:23916///////////////////////////////////////////////////////////////////////////////
danakja6c10012018-07-06 14:25:36917// LayerTreeViewDelegate
fsamuel78f86e42016-01-20 04:10:23918
David Bokanc8e38d02018-10-08 21:56:01919void RenderWidget::ApplyViewportChanges(
920 const cc::ApplyViewportChangesArgs& args) {
Ken Buchananed449bb2018-02-01 21:02:05921 if (!GetWebWidget())
922 return;
David Bokanc8e38d02018-10-08 21:56:01923 GetWebWidget()->ApplyViewportChanges(args);
fsamuel78f86e42016-01-20 04:10:23924}
925
sahel1b47fda72017-03-28 17:03:07926void RenderWidget::RecordWheelAndTouchScrollingCount(
927 bool has_scrolled_by_wheel,
928 bool has_scrolled_by_touch) {
Ken Buchananed449bb2018-02-01 21:02:05929 if (!GetWebWidget())
930 return;
Blink Reformat1c4d759e2017-04-09 16:34:54931 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07932 has_scrolled_by_touch);
933}
934
Sahel Sharify676580c2019-01-10 21:49:49935void RenderWidget::SendOverscrollEventFromImplSide(
936 const gfx::Vector2dF& overscroll_delta,
937 cc::ElementId scroll_latched_element_id) {
938 if (!GetWebWidget())
939 return;
940 GetWebWidget()->SendOverscrollEventFromImplSide(overscroll_delta,
941 scroll_latched_element_id);
942}
943void RenderWidget::SendScrollEndEventFromImplSide(
944 cc::ElementId scroll_latched_element_id) {
945 if (!GetWebWidget())
946 return;
947 GetWebWidget()->SendScrollEndEventFromImplSide(scroll_latched_element_id);
948}
949
Daniel Cheng224569ee2018-04-25 05:45:06950void RenderWidget::BeginMainFrame(base::TimeTicks frame_time) {
Ken Buchananed449bb2018-02-01 21:02:05951 if (!GetWebWidget())
952 return;
Daniel Cheng224569ee2018-04-25 05:45:06953 if (input_event_queue_)
954 input_event_queue_->DispatchRafAlignedInput(frame_time);
dtapuska3d5624d32016-08-30 04:34:00955
Daniel Cheng224569ee2018-04-25 05:45:06956 GetWebWidget()->BeginFrame(frame_time);
fsamuel78f86e42016-01-20 04:10:23957}
958
danakjc7afae52017-06-20 21:12:41959void RenderWidget::RequestNewLayerTreeFrameSink(
danakja6c10012018-07-06 14:25:36960 LayerTreeFrameSinkCallback callback) {
[email protected]7912e822014-04-16 02:37:03961 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41962 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39963 DCHECK(!compositor_never_visible_);
danakjf87460792018-12-04 20:14:22964 // Frozen RenderWidgets should not be doing any compositing.
Scott Violetb04f16c2018-11-27 00:48:46965 DCHECK(!is_frozen_);
danakj678f0252018-11-09 21:46:34966
967 if (is_closing()) {
968 // In this case, we drop the request which means the compositor waits
969 // forever, which is fine since we're going to destroy it.
970 return;
971 }
jonrossa2ff4f82018-02-16 17:27:46972
danakjf87460792018-12-04 20:14:22973 // If we have a warmup in progress, wait for that and store the callback
974 // to be run when the warmup completes.
975 if (warmup_frame_sink_request_pending_) {
976 after_warmup_callback_ = std::move(callback);
977 return;
978 }
979 // If a warmup previously completed, use the result.
980 if (warmup_frame_sink_) {
981 std::move(callback).Run(std::move(warmup_frame_sink_));
982 return;
983 }
984
985 DoRequestNewLayerTreeFrameSink(std::move(callback));
986}
987
988void RenderWidget::DoRequestNewLayerTreeFrameSink(
989 LayerTreeFrameSinkCallback callback) {
jonrossa2ff4f82018-02-16 17:27:46990 // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
991 // would then handle binding.
992 mojom::RenderFrameMetadataObserverPtr ptr;
993 mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr);
994 mojom::RenderFrameMetadataObserverClientPtrInfo client_info;
995 mojom::RenderFrameMetadataObserverClientRequest client_request =
996 mojo::MakeRequest(&client_info);
danakj4b347212018-07-04 17:55:17997 auto render_frame_metadata_observer =
998 std::make_unique<RenderFrameMetadataObserverImpl>(std::move(request),
999 std::move(client_info));
danakja6c10012018-07-06 14:25:361000 layer_tree_view_->SetRenderFrameObserver(
danakj4b347212018-07-04 17:55:171001 std::move(render_frame_metadata_observer));
danakjf51754372018-12-13 23:20:011002 GURL url = GetWebWidget()->GetURLForDebugTrace();
danakjefabf312018-10-05 19:03:071003 // The |url| is not always available, fallback to a fixed string.
1004 if (url.is_empty())
1005 url = GURL("chrome://gpu/RenderWidget::RequestNewLayerTreeFrameSink");
danakj6dcbc5962018-11-16 16:45:421006 // TODO(danakj): This may not be accurate, depending on the intent. A child
1007 // local root could be in the same process as the view, so if the client is
1008 // meant to designate the process type, it seems kRenderer would be the
1009 // correct choice. If client is meant to designate the widget type, then
1010 // kOOPIF would denote that it is not for the main frame. However, kRenderer
1011 // would also be used for other widgets such as popups.
1012 const char* client_name = for_child_local_root_frame_ ? kOOPIF : kRenderer;
Scott Violetb04f16c2018-11-27 00:48:461013 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
1014 routing_id_, frame_swap_message_queue_, std::move(url),
1015 std::move(callback), std::move(client_request), std::move(ptr),
1016 client_name);
[email protected]ba91a792013-02-06 09:48:281017}
1018
fsamuel78f86e42016-01-20 04:10:231019void RenderWidget::DidCommitAndDrawCompositorFrame() {
1020 // NOTE: Tests may break if this event is renamed or moved. See
1021 // tab_capture_performancetest.cc.
1022 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081023
ericwilligers88e69742016-10-17 19:29:551024 for (auto& observer : render_frames_)
1025 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081026
fsamuel78f86e42016-01-20 04:10:231027 // Notify subclasses that we initiated the paint operation.
1028 DidInitiatePaint();
Yiming Zhou0f8836c22018-09-13 22:22:111029
Albert J. Wongfb64e142018-10-16 01:10:451030 Send(new WidgetHostMsg_DidCommitAndDrawCompositorFrame(routing_id_));
fsamuel78f86e42016-01-20 04:10:231031}
1032
Saman Sami766e0b02018-01-31 17:19:201033void RenderWidget::DidCommitCompositorFrame() {
Albert J. Wong7bbf22d2018-12-20 00:27:271034 if (delegate())
1035 delegate()->DidCommitCompositorFrameForWidget();
Saman Sami766e0b02018-01-31 17:19:201036}
fsamuel78f86e42016-01-20 04:10:231037
danakja2c9d0a92018-07-25 20:01:181038void RenderWidget::DidCompletePageScaleAnimation() {
Albert J. Wong7bbf22d2018-12-20 00:27:271039 if (delegate())
1040 delegate()->DidCompletePageScaleAnimationForWidget();
danakja2c9d0a92018-07-25 20:01:181041}
fsamuel78f86e42016-01-20 04:10:231042
danakj53f46b82018-12-11 20:55:551043void RenderWidget::ScheduleAnimation() {
1044 // This call is not needed in single thread mode for tests without a
1045 // scheduler, but they need to override the WebWidgetClient and replace this
1046 // method in order to schedule a synchronous composite task themselves.
1047 layer_tree_view_->SetNeedsBeginFrame();
initial.commit09911bf2008-07-26 23:55:291048}
1049
Stephen Chenneyec4312612018-11-21 12:40:161050void RenderWidget::UpdateVisualState(bool record_main_frame_metrics) {
Ken Buchananed449bb2018-02-01 21:02:051051 if (!GetWebWidget())
1052 return;
1053
Stephen Chenneyec4312612018-11-21 12:40:161054 // When recording main frame metrics set the lifecycle reason to
1055 // kBeginMainFrame, because this is the calller of UpdateLifecycle
1056 // for the main frame. Otherwise, set the reason to kTests, which is
1057 // the oinly other reason this method is called.
1058 WebWidget::LifecycleUpdateReason lifecycle_reason =
1059 record_main_frame_metrics
1060 ? WebWidget::LifecycleUpdateReason::kBeginMainFrame
1061 : WebWidget::LifecycleUpdateReason::kTest;
1062 GetWebWidget()->UpdateLifecycle(WebWidget::LifecycleUpdate::kAll,
1063 lifecycle_reason);
Blink Reformat1c4d759e2017-04-09 16:34:541064 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501065
Robert Flack3ef2ffb2018-09-06 20:38:201066 if (first_update_visual_state_after_hidden_) {
Takashi SAKAMOTO870f6262017-08-22 04:08:271067 RecordTimeToFirstActivePaint();
1068 first_update_visual_state_after_hidden_ = false;
1069 }
1070}
tasakb95dbb50c2017-02-08 18:07:501071
Takashi SAKAMOTO870f6262017-08-22 04:08:271072void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501073 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501074 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271075 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1076 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1077 sample);
1078 }
1079 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1080 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1081 UMA_HISTOGRAM_TIMES(
1082 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1083 "AfterBackgrounded.5min",
1084 sample);
1085 }
fsamuel78f86e42016-01-20 04:10:231086}
1087
Stephen Chenney9879a5c2018-09-26 14:21:421088void RenderWidget::RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time) {
1089 if (!GetWebWidget())
1090 return;
1091
1092 GetWebWidget()->RecordEndOfFrameMetrics(frame_begin_time);
1093}
1094
fsamuel78f86e42016-01-20 04:10:231095void RenderWidget::WillBeginCompositorFrame() {
1096 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1097
Ken Buchananed449bb2018-02-01 21:02:051098 if (!GetWebWidget())
1099 return;
1100
Blink Reformat1c4d759e2017-04-09 16:34:541101 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291102
dglazkov06854c5c2016-08-31 00:19:591103 // The UpdateTextInputState can result in further layout and possibly
1104 // enable GPU acceleration so they need to be called before any painting
1105 // is done.
changwan75e3b2072017-01-16 02:55:001106 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591107 UpdateSelectionBounds();
1108
ericwilligers88e69742016-10-17 19:29:551109 for (auto& observer : render_frame_proxies_)
1110 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291111}
1112
Kent Tamura21d1de62018-12-10 04:45:201113std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForWebTest(
Fady Samueldfecb7d2017-07-26 11:41:041114 std::unique_ptr<viz::CopyOutputRequest> request) {
Kent Tamura21d1de62018-12-10 04:45:201115 return RenderThreadImpl::current()->RequestCopyOfOutputForWebTest(
jbroman6ccbc7d472016-07-27 04:45:411116 routing_id_, std::move(request));
1117}
1118
fsamuel72464894f2015-12-15 06:59:311119///////////////////////////////////////////////////////////////////////////////
1120// RenderWidgetInputHandlerDelegate
1121
avid7d6b2e2016-03-04 19:41:171122void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381123 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1124 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291125 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381126
ekaramad27ca69b12017-04-20 18:34:291127 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381128 frame_widget->LocalRoot()->View()->FocusedFrame();
1129
ekaramad27ca69b12017-04-20 18:34:291130 if (focused && focused->AutofillClient())
1131 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171132}
fsamuel72464894f2015-12-15 06:59:311133
dtapuska1827dd22016-03-11 15:24:591134void RenderWidget::ObserveGestureEventAndResult(
1135 const blink::WebGestureEvent& gesture_event,
1136 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131137 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591138 bool event_processed) {
1139 if (!compositor_deps_->IsElasticOverscrollEnabled())
1140 return;
1141
1142 cc::InputHandlerScrollResult scroll_result;
1143 scroll_result.did_scroll = event_processed;
1144 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1145 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131146 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591147
Dave Tapuska04bc5ee92018-04-17 19:03:311148 widget_input_handler_manager_->ObserveGestureEventOnMainThread(gesture_event,
1149 scroll_result);
dtapuska1827dd22016-03-11 15:24:591150}
1151
avid7d6b2e2016-03-04 19:41:171152void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461153 ClearEditCommands();
1154}
1155
1156void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1157 const std::string& value) {
1158 ClearEditCommands();
1159 edit_commands_.emplace_back(name, value);
1160}
1161
1162void RenderWidget::ClearEditCommands() {
1163 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171164}
fsamuel72464894f2015-12-15 06:59:311165
chongza8ba91fc2016-08-16 21:39:171166void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska04bc5ee92018-04-17 19:03:311167 if (mojom::WidgetInputHandlerHost* host =
1168 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1169 host->DidOverscroll(params);
Dave Tapuska139a72f2017-09-06 21:57:031170 }
fsamuel72464894f2015-12-15 06:59:311171}
1172
fsamuele8326c742016-01-12 00:49:391173void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1174 // Nothing to do here. RenderWidget created the |input_handler| and will take
1175 // ownership of it. We just verify here that we don't already have an input
1176 // handler.
1177 DCHECK(!input_handler_);
1178}
1179
changwan75e3b2072017-01-16 02:55:001180void RenderWidget::ShowVirtualKeyboard() {
1181 UpdateTextInputStateInternal(true, false);
1182}
1183
changwan62f57292017-02-17 08:28:251184void RenderWidget::ClearTextInputState() {
1185 text_input_info_ = blink::WebTextInputInfo();
1186 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1187 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1188 can_compose_inline_ = false;
1189 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201190 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251191}
1192
changwan75e3b2072017-01-16 02:55:001193void RenderWidget::UpdateTextInputState() {
1194 UpdateTextInputStateInternal(false, false);
1195}
1196
1197void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1198 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311199 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001200
fsamuel72464894f2015-12-15 06:59:311201 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001202 DCHECK(!reply_to_request);
1203 // show_virtual_keyboard should still be effective even if it was set inside
1204 // the IME
fsamuel72464894f2015-12-15 06:59:311205 // event guard.
changwan75e3b2072017-01-16 02:55:001206 if (show_virtual_keyboard)
1207 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311208 return;
1209 }
1210
dglazkov97b6c2b2016-10-25 17:35:551211 ui::TextInputType new_type = GetTextInputType();
1212 if (IsDateTimeInput(new_type))
1213 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311214
dglazkov97b6c2b2016-10-25 17:35:551215 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351216 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541217 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101218 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541219 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311220
1221 bool new_can_compose_inline = CanComposeInline();
1222
1223 // Only sends text input params if they are changed or if the ime should be
1224 // shown.
changwan75e3b2072017-01-16 02:55:001225 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561226 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1227 text_input_info_ != new_info ||
1228 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381229 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551230 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311231 params.mode = new_mode;
1232 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211233#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201234 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1235 // Due to a focus change, values will be reset by the frame.
1236 // That case we only need fresh NEXT/PREVIOUS information.
Albert J. Wong3c93c182018-09-27 17:29:431237 // Also we won't send WidgetHostMsg_TextInputStateChanged if next/previous
AJITH KUMAR V041c0b02017-08-08 10:39:201238 // focusable status is changed.
1239 if (auto* controller = GetInputMethodController()) {
1240 next_previous_flags_ =
1241 controller->ComputeWebTextInputNextPreviousFlags();
1242 } else {
1243 // For safety in case GetInputMethodController() is null, because -1 is
1244 // invalid value to send to browser process.
1245 next_previous_flags_ = 0;
1246 }
1247 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211248#else
1249 next_previous_flags_ = 0;
1250#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201251 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541252 params.value = new_info.value.Utf8();
1253 params.selection_start = new_info.selection_start;
1254 params.selection_end = new_info.selection_end;
1255 params.composition_start = new_info.composition_start;
1256 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311257 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001258 // TODO(changwan): change instances of show_ime_if_needed to
1259 // show_virtual_keyboard.
1260 params.show_ime_if_needed = show_virtual_keyboard;
1261 params.reply_to_request = reply_to_request;
Albert J. Wong3c93c182018-09-27 17:29:431262 Send(new WidgetHostMsg_TextInputStateChanged(routing_id(), params));
fsamuel72464894f2015-12-15 06:59:311263
1264 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551265 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311266 text_input_mode_ = new_mode;
1267 can_compose_inline_ = new_can_compose_inline;
1268 text_input_flags_ = new_info.flags;
Eric Karl706ea6712018-12-21 22:41:381269
1270#if defined(OS_ANDROID)
1271 // If we send a new TextInputStateChanged message, we must also deliver a
1272 // new RenderFrameMetadata, as the IME will need this info to be updated.
1273 // TODO(ericrk): Consider folding the above IPC into RenderFrameMetadata.
1274 // https://crbug.com/912309
1275 if (layer_tree_view_ && IsSurfaceSynchronizationEnabled()) {
1276 layer_tree_view_->RequestForceSendMetadata();
1277 }
1278#endif
fsamuel72464894f2015-12-15 06:59:311279 }
1280}
1281
1282bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581283 possible_drag_event_info_.event_source =
1284 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1285 possible_drag_event_info_.event_location =
Ella Ge1116059d2018-03-21 02:06:131286 gfx::ToFlooredPoint(event.PositionInScreen());
avid7d6b2e2016-03-04 19:41:171287
fsamuel72464894f2015-12-15 06:59:311288 return false;
1289}
1290
1291bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551292 for (auto& observer : render_frames_)
1293 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081294
paulmeyer6ef5a792016-11-08 20:33:581295 possible_drag_event_info_.event_source =
1296 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1297 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541298 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581299
Albert J. Wong7bbf22d2018-12-20 00:27:271300 if (delegate())
1301 return delegate()->RenderWidgetWillHandleMouseEventForWidget(event);
avid7d6b2e2016-03-04 19:41:171302
fsamuel72464894f2015-12-15 06:59:311303 return false;
[email protected]fd847792013-10-24 17:12:351304}
1305
initial.commit09911bf2008-07-26 23:55:291306///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391307// RenderWidgetScreenMetricsDelegate
1308
1309void RenderWidget::Redraw() {
danakja6c10012018-07-06 14:25:361310 if (layer_tree_view_)
1311 layer_tree_view_->SetNeedsRedrawRect(gfx::Rect(size_));
mfomitchev2600fd7c2016-02-17 20:53:391312}
1313
bokanc63441c2016-04-27 15:49:121314void RenderWidget::ResizeWebWidget() {
danakja2c9d0a92018-07-25 20:01:181315 gfx::Size size = GetSizeForWebWidget();
Albert J. Wong7bbf22d2018-12-20 00:27:271316 if (delegate()) {
1317 delegate()->ResizeWebWidgetForWidget(size, top_controls_height_,
1318 bottom_controls_height_,
1319 browser_controls_shrink_blink_size_);
danakja2c9d0a92018-07-25 20:01:181320 return;
1321 }
1322 GetWebWidget()->Resize(size);
bokanc63441c2016-04-27 15:49:121323}
1324
1325gfx::Size RenderWidget::GetSizeForWebWidget() const {
danakj4b347212018-07-04 17:55:171326 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031327 return gfx::ScaleToCeiledSize(size_,
1328 GetOriginalScreenInfo().device_scale_factor);
1329 }
bokanc63441c2016-04-27 15:49:121330
1331 return size_;
1332}
1333
akaba3483d8f2018-07-10 21:43:091334void RenderWidget::UpdateZoom(double zoom_level) {
akabac6bd1212018-06-25 20:10:481335 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1336 if (!frame_widget)
1337 return;
1338 RenderFrameImpl* render_frame =
1339 RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
1340
akaba3483d8f2018-07-10 21:43:091341 // Return early if zoom level is unchanged.
1342 if (render_frame->GetZoomLevel() == zoom_level) {
akabac6bd1212018-06-25 20:10:481343 return;
1344 }
1345
akaba3483d8f2018-07-10 21:43:091346 render_frame->SetZoomLevel(zoom_level);
akabac6bd1212018-06-25 20:10:481347
1348 for (auto& observer : render_frame_proxies_)
akaba3483d8f2018-07-10 21:43:091349 observer.OnZoomLevelChanged(zoom_level);
akabac6bd1212018-06-25 20:10:481350
1351 for (auto& plugin : browser_plugins_)
akaba3483d8f2018-07-10 21:43:091352 plugin.OnZoomLevelChanged(zoom_level);
akabac6bd1212018-06-25 20:10:481353}
1354
Fady Samuel799e72192018-04-25 21:16:571355void RenderWidget::SynchronizeVisualProperties(const VisualProperties& params) {
Christopher Cameronbe7ecea2018-02-27 00:47:191356 // Inform the rendering thread of the color space indicate the presence of HDR
1357 // capabilities.
Miguel Casas5e1018052018-01-09 19:17:361358 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1359 if (render_thread)
Christopher Camerone9a30c12018-03-07 08:23:381360 render_thread->SetRenderingColorSpace(params.screen_info.color_space);
Miguel Casas5e1018052018-01-09 19:17:361361
mfomitchev2600fd7c2016-02-17 20:53:391362 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211363 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391364 return;
1365
W. James MacLean2a90bff2018-11-05 20:52:471366 // Only propagate the external PSF to non-main-frames.
Albert J. Wong7bbf22d2018-12-20 00:27:271367 if (!delegate())
W. James MacLean2a90bff2018-11-05 20:52:471368 layer_tree_view_->SetExternalPageScaleFactor(params.page_scale_factor);
1369
Fady Samuele62be402018-03-29 03:19:531370 gfx::Size new_compositor_viewport_pixel_size =
1371 params.auto_resize_enabled
1372 ? gfx::ScaleToCeiledSize(size_,
1373 params.screen_info.device_scale_factor)
1374 : params.compositor_viewport_pixel_size;
Fady Samuel84d8a1f72018-11-08 00:26:171375 UpdateSurfaceAndScreenInfo(params.local_surface_id_allocation.value_or(
1376 viz::LocalSurfaceIdAllocation()),
1377 new_compositor_viewport_pixel_size,
1378 params.screen_info);
Vladimir Levin98d76dad2018-04-21 00:21:291379 UpdateCaptureSequenceNumber(params.capture_sequence_number);
danakja6c10012018-07-06 14:25:361380 if (layer_tree_view_) {
1381 layer_tree_view_->SetBrowserControlsHeight(
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271382 params.top_controls_height, params.bottom_controls_height,
1383 params.browser_controls_shrink_blink_size);
danakja6c10012018-07-06 14:25:361384 layer_tree_view_->SetRasterColorSpace(
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271385 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151386 }
mfomitchev2600fd7c2016-02-17 20:53:391387
akaba3483d8f2018-07-10 21:43:091388 UpdateZoom(params.zoom_level);
akabac6bd1212018-06-25 20:10:481389
danakj21604ce2018-12-19 16:01:221390 if (!params.auto_resize_enabled) {
1391 visible_viewport_size_ = params.visible_viewport_size;
Fady Samuele62be402018-03-29 03:19:531392
danakj21604ce2018-12-19 16:01:221393 // NOTE: We may have entered fullscreen mode without changing our size.
1394 bool fullscreen_change =
1395 is_fullscreen_granted_ != params.is_fullscreen_granted;
1396 is_fullscreen_granted_ = params.is_fullscreen_granted;
1397 display_mode_ = params.display_mode;
mfomitchev2600fd7c2016-02-17 20:53:391398
danakj21604ce2018-12-19 16:01:221399 size_ = params.new_size;
mfomitchev2600fd7c2016-02-17 20:53:391400
danakj21604ce2018-12-19 16:01:221401 ResizeWebWidget();
mfomitchev2600fd7c2016-02-17 20:53:391402
danakj21604ce2018-12-19 16:01:221403 WebSize visual_viewport_size;
1404 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
1405 visual_viewport_size =
1406 gfx::ScaleToCeiledSize(params.visible_viewport_size,
1407 GetOriginalScreenInfo().device_scale_factor);
1408 } else {
1409 visual_viewport_size = visible_viewport_size_;
1410 }
1411 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
bokan71cb5b12016-04-27 03:45:221412
danakj21604ce2018-12-19 16:01:221413 if (fullscreen_change)
1414 DidToggleFullscreen();
mfomitchev2600fd7c2016-02-17 20:53:391415 }
W. James MacLean2a90bff2018-11-05 20:52:471416
Albert J. Wong7bbf22d2018-12-20 00:27:271417 if (!delegate()) {
W. James MacLean2a90bff2018-11-05 20:52:471418 // Make sure that page scale factor changes propagating down from the main
1419 // frame are relayed to nested OOPIFs/non-main-frames.
1420 page_scale_factor_from_mainframe_ = params.page_scale_factor;
1421 for (auto& observer : render_frame_proxies_)
1422 observer.OnPageScaleFactorChanged(params.page_scale_factor);
1423 }
mfomitchev2600fd7c2016-02-17 20:53:391424}
1425
1426void RenderWidget::SetScreenMetricsEmulationParameters(
1427 bool enabled,
1428 const blink::WebDeviceEmulationParams& params) {
Albert J. Wong7bbf22d2018-12-20 00:27:271429 // This is only supported in RenderView, which has an delegate().
1430 DCHECK(delegate());
1431 delegate()->SetScreenMetricsEmulationParametersForWidget(enabled, params);
mfomitchev2600fd7c2016-02-17 20:53:391432}
1433
Albert J. Wong3c93c182018-09-27 17:29:431434void RenderWidget::SetScreenRects(const gfx::Rect& widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:391435 const gfx::Rect& window_screen_rect) {
Albert J. Wong3c93c182018-09-27 17:29:431436 widget_screen_rect_ = widget_screen_rect;
mfomitchev2600fd7c2016-02-17 20:53:391437 window_screen_rect_ = window_screen_rect;
1438}
1439
1440///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461441// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291442
Chris Harrelsond7ab99b2018-01-24 17:51:361443void RenderWidget::IntrinsicSizingInfoChanged(
1444 const blink::WebIntrinsicSizingInfo& sizing_info) {
Albert J. Wong3c93c182018-09-27 17:29:431445 Send(new WidgetHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
Chris Harrelsond7ab99b2018-01-24 17:51:361446}
1447
Blink Reformat1c4d759e2017-04-09 16:34:541448void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1449 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
Albert J. Wongfb64e142018-10-16 01:10:451450 QueueMessage(new WidgetHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_));
dglazkovf0e1d6d2015-10-10 02:13:481451 }
dglazkov79c426102015-08-31 21:22:431452
ericwilligers88e69742016-10-17 19:29:551453 for (auto& observer : render_frames_)
1454 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431455}
1456
[email protected]586871b2014-07-22 17:05:111457// static
dchengcedca5612016-04-09 01:40:151458std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111459 IPC::Message* msg,
[email protected]586871b2014-07-22 17:05:111460 FrameSwapMessageQueue* frame_swap_message_queue,
1461 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111462 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111463 bool first_message_for_frame = false;
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491464 frame_swap_message_queue->QueueMessageForFrame(
1465 source_frame_number, base::WrapUnique(msg), &first_message_for_frame);
[email protected]586871b2014-07-22 17:05:111466 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151467 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111468 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061469 return promise;
[email protected]586871b2014-07-22 17:05:111470 }
dcheng4b6b5ff2014-10-16 00:42:061471 return nullptr;
[email protected]586871b2014-07-22 17:05:111472}
1473
danakj53802692018-07-25 21:46:441474void RenderWidget::SetHandlingInputEvent(bool handling_input_event) {
1475 input_handler_->set_handling_input_event(handling_input_event);
1476}
1477
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491478void RenderWidget::QueueMessage(IPC::Message* msg) {
[email protected]586871b2014-07-22 17:05:111479 // RenderThreadImpl::current() is NULL in some tests.
danakja6c10012018-07-06 14:25:361480 if (!layer_tree_view_ || !RenderThreadImpl::current()) {
[email protected]586871b2014-07-22 17:05:111481 Send(msg);
1482 return;
1483 }
1484
dchengcedca5612016-04-09 01:40:151485 std::unique_ptr<cc::SwapPromise> swap_promise =
Sadrul Habib Chowdhury4e0335cf2018-07-31 20:08:491486 QueueMessageImpl(msg, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111487 RenderThreadImpl::current()->sync_message_filter(),
danakja6c10012018-07-06 14:25:361488 layer_tree_view_->GetSourceFrameNumber());
[email protected]586871b2014-07-22 17:05:111489
Ken Buchanance710eb2017-08-30 23:46:521490 if (swap_promise)
danakja6c10012018-07-06 14:25:361491 layer_tree_view_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111492}
1493
Blink Reformat1c4d759e2017-04-09 16:34:541494void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301495 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521496 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181497 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291498 // Only send a SetCursor message if we need to make a change.
Navid Zolghadr293bb862018-12-12 18:15:411499 if (input_handler_->DidChangeCursor(cursor))
Albert J. Wong3c93c182018-09-27 17:29:431500 Send(new WidgetHostMsg_SetCursor(routing_id_, cursor));
initial.commit09911bf2008-07-26 23:55:291501}
1502
aelias5971e47d2017-06-16 02:39:381503void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
Albert J. Wong3c93c182018-09-27 17:29:431504 Send(new WidgetHostMsg_AutoscrollStart(routing_id_, point));
aelias5971e47d2017-06-16 02:39:381505}
1506
1507void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
Albert J. Wong3c93c182018-09-27 17:29:431508 Send(new WidgetHostMsg_AutoscrollFling(routing_id_, velocity));
aelias5971e47d2017-06-16 02:39:381509}
1510
1511void RenderWidget::AutoscrollEnd() {
Albert J. Wong3c93c182018-09-27 17:29:431512 Send(new WidgetHostMsg_AutoscrollEnd(routing_id_));
aelias5971e47d2017-06-16 02:39:381513}
1514
initial.commit09911bf2008-07-26 23:55:291515// We are supposed to get a single call to Show for a newly created RenderWidget
1516// that was created via RenderWidget::CreateWebView. So, we wait until this
1517// point to dispatch the ShowWidget message.
1518//
1519// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281520// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291521//
Blink Reformat1c4d759e2017-04-09 16:34:541522void RenderWidget::Show(WebNavigationPolicy policy) {
danakj65f423b72018-10-10 17:21:201523 if (!show_callback_) {
Albert J. Wong7bbf22d2018-12-20 00:27:271524 if (delegate()) {
danakja2c9d0a92018-07-25 20:01:181525 // When SupportsMultipleWindows is disabled, popups are reusing
danakj65f423b72018-10-10 17:21:201526 // the view's RenderWidget. In some scenarios, this makes blink to call
1527 // Show() twice. But otherwise, if it is enabled, we should not visit
1528 // Show() more than once.
Albert J. Wong7bbf22d2018-12-20 00:27:271529 DCHECK(!delegate()->SupportsMultipleWindowsForWidget());
danakj65f423b72018-10-10 17:21:201530 return;
danakja2c9d0a92018-07-25 20:01:181531 } else {
danakj65f423b72018-10-10 17:21:201532 NOTREACHED() << "received extraneous Show call";
danakja2c9d0a92018-07-25 20:01:181533 }
danakja2c9d0a92018-07-25 20:01:181534 }
1535
initial.commit09911bf2008-07-26 23:55:291536 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351537
1538 // The opener is responsible for actually showing this widget.
danakjdf1ceb72018-07-18 20:02:251539 std::move(show_callback_).Run(this, policy, initial_rect_);
nickf7b38222016-11-22 21:59:351540
bokanc007c3a2015-02-03 07:15:561541 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441542 // that's okay. It'll be ignored if as_popup is false, or the browser
1543 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561544 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291545}
1546
danakj17216f4d2018-10-16 22:57:321547LayerTreeView* RenderWidget::InitializeLayerTreeView() {
1548 TRACE_EVENT0("blink", "RenderWidget::InitializeLayerTreeView");
danakj17216f4d2018-10-16 22:57:321549
1550 layer_tree_view_ = std::make_unique<LayerTreeView>(
1551 this, compositor_deps_->GetCompositorMainThreadTaskRunner(),
1552 compositor_deps_->GetCompositorImplThreadTaskRunner(),
1553 compositor_deps_->GetTaskGraphRunner(),
1554 compositor_deps_->GetWebMainThreadScheduler());
1555 layer_tree_view_->Initialize(
danakj6dcbc5962018-11-16 16:45:421556 GenerateLayerTreeSettings(compositor_deps_, for_child_local_root_frame_,
danakj17216f4d2018-10-16 22:57:321557 screen_info_.rect.size(),
1558 screen_info_.device_scale_factor),
1559 compositor_deps_->CreateUkmRecorderFactory());
1560
Fady Samuel1c1ad3692018-11-06 23:28:401561 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
danakj17216f4d2018-10-16 22:57:321562 compositor_viewport_pixel_size_, screen_info_);
1563 layer_tree_view_->SetRasterColorSpace(
1564 screen_info_.color_space.GetRasterColorSpace());
1565 layer_tree_view_->SetContentSourceId(current_content_source_id_);
1566 // For background pages and certain tests, we don't want to trigger
1567 // LayerTreeFrameSink creation.
1568 bool should_generate_frame_sink =
1569 !compositor_never_visible_ && RenderThreadImpl::current();
danakje9be3162018-11-05 21:32:001570 if (!should_generate_frame_sink) {
1571 // Prevents SetVisible() from blink from doing anything.
danakj17216f4d2018-10-16 22:57:321572 layer_tree_view_->SetNeverVisible();
danakj6dcbc5962018-11-16 16:45:421573 } else if (!is_frozen_) {
danakje9be3162018-11-05 21:32:001574 // Begins the compositor's scheduler to start producing frames.
1575 // Don't do this if the RenderWidget is attached to a RenderViewImpl for a
danakjbc6ba9d22018-11-17 04:03:411576 // proxy main frame, as this RenderWidget is frozen then, and won't be
danakje9be3162018-11-05 21:32:001577 // used for compositing until a WebFrameWidget is attached.
1578 StartCompositor();
1579 }
danakj17216f4d2018-10-16 22:57:321580
danakj17216f4d2018-10-16 22:57:321581 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1582 layer_tree_view_->SetFrameSinkId(
1583 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
1584
1585 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1586 if (render_thread) {
1587 input_event_queue_ = base::MakeRefCounted<MainThreadEventQueue>(
1588 this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(),
1589 render_thread->GetWebMainThreadScheduler(), should_generate_frame_sink);
1590 }
1591
1592 return layer_tree_view_.get();
1593}
1594
danakjde8b7482018-11-15 23:45:021595void RenderWidget::StartCompositor() {
1596 if (!is_hidden_)
1597 layer_tree_view_->SetVisible(true);
1598}
1599
1600void RenderWidget::StopCompositor() {
1601 layer_tree_view_->SetVisible(false);
1602 // Drop all gpu resources, this makes SetVisible(true) more expensive/slower
1603 // but we don't expect to use this RenderWidget again until some possible
1604 // future navigation. This brings us a bit closer to emulating deleting the
1605 // RenderWidget instead of just stopping the compositor.
1606 layer_tree_view_->ReleaseLayerTreeFrameSink();
1607}
1608
danakj6dcbc5962018-11-16 16:45:421609void RenderWidget::SetIsFrozen(bool is_frozen) {
1610 DCHECK_NE(is_frozen, is_frozen_);
1611 is_frozen_ = is_frozen;
1612 if (is_frozen)
danakjde8b7482018-11-15 23:45:021613 StopCompositor();
1614 else
1615 StartCompositor();
1616}
1617
danakjf87460792018-12-04 20:14:221618void RenderWidget::WarmupCompositor() {
1619 DCHECK(is_frozen_);
1620
1621 // Tests have no RenderThreadImpl /o\.
1622 if (!RenderThreadImpl::current())
1623 return;
1624
1625 // Keeping things simple. This would cancel any outstanding warmup if we
1626 // happened to have one (this should be basically impossible). This avoids any
1627 // extra book keeping about the outstanding reqeust.
1628 warmup_weak_ptr_factory_.InvalidateWeakPtrs();
1629 // And if we already did a warmup then we're done.
1630 if (warmup_frame_sink_)
1631 return;
1632
1633 // Mark us pending the warmup frame sink *before* calling
1634 // DoRequestNewLayerTreeFrameSink() as it may run the reply callback
1635 // synchronously. So we don't want to change any state after the call
1636 // to DoRequestNewLayerTreeFrameSink() here.
1637 warmup_frame_sink_request_pending_ = true;
1638
1639 auto cb = base::BindOnce(&RenderWidget::OnReplyForWarmupCompositor,
1640 warmup_weak_ptr_factory_.GetWeakPtr());
1641 DoRequestNewLayerTreeFrameSink(std::move(cb));
1642}
1643
1644void RenderWidget::OnReplyForWarmupCompositor(
1645 std::unique_ptr<cc::LayerTreeFrameSink> sink) {
1646 warmup_frame_sink_request_pending_ = false;
1647
1648 if (after_warmup_callback_)
1649 std::move(after_warmup_callback_).Run(std::move(sink));
1650 else
1651 warmup_frame_sink_ = std::move(sink);
1652}
1653
1654void RenderWidget::AbortWarmupCompositor() {
1655 warmup_frame_sink_request_pending_ = false;
1656 // Drop any pending warmup.
1657 warmup_weak_ptr_factory_.InvalidateWeakPtrs();
1658 // And drop any completed one.
1659 warmup_frame_sink_.reset();
1660
1661 // If we had saved a callback to run after warmup, just do so now indicating
1662 // failure.
1663 if (after_warmup_callback_)
1664 std::move(after_warmup_callback_).Run(nullptr);
1665}
1666
[email protected]2533ce12009-05-09 00:02:241667void RenderWidget::DoDeferredClose() {
Albert J. Wong3c93c182018-09-27 17:29:431668 Send(new WidgetHostMsg_Close(routing_id_));
[email protected]2533ce12009-05-09 00:02:241669}
1670
Blink Reformat1c4d759e2017-04-09 16:34:541671void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081672 DCHECK(content::RenderThread::Get());
danakj6dcbc5962018-11-16 16:45:421673 if (is_frozen_) {
1674 // This widget is currently not active. The active main frame widget is in a
[email protected]e1c3a552012-05-04 20:51:321675 // different process. Have the browser route the close request to the
1676 // active widget instead, so that the correct unload handlers are run.
Albert J. Wongfb64e142018-10-16 01:10:451677 Send(new WidgetHostMsg_RouteCloseEvent(routing_id_));
[email protected]e1c3a552012-05-04 20:51:321678 return;
1679 }
1680
danakj292b63e2018-11-19 20:47:061681 // Prevent compositor from setting up new IPC channels, since we know a
1682 // WidgetMsg_Close is coming. We do this immediately, not in DoDeferredClose,
1683 // as the caller (eg WebPagePopupImpl) may start tearing down things after
1684 // calling this method, including detaching the frame from this RenderWidget.
1685 // Then trying to make a LayerTreeFrameSink would crash.
1686 // https://crbug.com/906340
1687 host_will_close_this_ = true;
1688
initial.commit09911bf2008-07-26 23:55:291689 // If a page calls window.close() twice, we'll end up here twice, but that's
1690 // OK. It is safe to send multiple Close messages.
danakj292b63e2018-11-19 20:47:061691 //
[email protected]2533ce12009-05-09 00:02:241692 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1693 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1694 // could be closed before the JS finishes executing. So instead, post a
1695 // message back to the message loop, which won't run until the JS is
1696 // complete, and then the Close message can be sent.
Hajime Hoshi315a61f2018-08-14 17:27:281697 GetCleanupTaskRunner()->PostTask(
1698 FROM_HERE, base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291699}
1700
1701void RenderWidget::Close() {
danakj6dcbc5962018-11-16 16:45:421702 // This was done immediately in the |for_child_local_root_frame_| case in the
1703 // OnClose() IPC handler.
1704 if (!for_child_local_root_frame_)
danakj5c5269b2018-11-06 00:39:111705 CloseWebWidget();
1706
danakja6c10012018-07-06 14:25:361707 layer_tree_view_.reset();
Albert J. Wong7bbf22d2018-12-20 00:27:271708 if (delegate())
1709 delegate()->DidCloseWidget();
Albert J. Wongd593de532018-09-06 05:42:151710 // Note the ACK is a control message going to the RenderProcessHost.
Albert J. Wong3c93c182018-09-27 17:29:431711 RenderThread::Get()->Send(new WidgetHostMsg_Close_ACK(routing_id()));
Ken Buchananed449bb2018-02-01 21:02:051712}
1713
1714void RenderWidget::CloseWebWidget() {
danakj35314ab2018-10-19 16:37:341715 // If the browser has not sent OnDisableDeviceEmulation, we have an emulator
1716 // hanging out still. Destroying it must happen *after* the IPC route is
1717 // removed so that another IPC does not arrive and re-create the emulator
1718 // during closing.
1719 //
1720 // This destruction is normally part of an IPC and expects objects to be alive
1721 // that would be alive while the IPC route is active such as the
1722 // |layer_tree_view_|. So we ensure that it is the first thing to be
1723 // destroyed here before deleting things from the RenderWidget or the
Albert J. Wong7bbf22d2018-12-20 00:27:271724 // delegate().
danakj35314ab2018-10-19 16:37:341725 //
1726 // TODO(danakj): The emulator could reset to non-emulated values in an
1727 // explicit method call (instead of in the destructor) that occurs when
1728 // emulation is disabled, but does not need to occur during RenderWidget
1729 // closing. Then we would not have to destroy this so carefully.
1730 screen_metrics_emulator_.reset();
1731
danakj5c5269b2018-11-06 00:39:111732 // Informs the WebWidget that compositor is being destroyed, so it can remove
1733 // references to it first.
1734 //
Albert J. Wong7bbf22d2018-12-20 00:27:271735 // When delegate() is present, the RenderWidget is for a main frame,
danakj5c5269b2018-11-06 00:39:111736 // and the GetWebWidget() is not the same as |webwidget_internal_|. However
1737 // that widget is responsible for doing WillCloseLayerTreeView() on the
1738 // |webwidget_internal_|, not us. Otherwise, they are the same and this is
1739 // notifying |webwidget_internal_|.
1740 GetWebWidget()->WillCloseLayerTreeView();
1741
Albert J. Wong7bbf22d2018-12-20 00:27:271742 // While the wrapping WebWidget from an delegate() is responsible for
danakj5c5269b2018-11-06 00:39:111743 // doing WillCloseLayerTreeView() on the |webwidget_internal_|, this class is
1744 // responsible for calling Close() on it. Notably, then, the wrapping
1745 // WebWidget does not.
1746 webwidget_internal_->Close();
1747 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291748}
1749
Mitsuru Oshima3c07b332018-02-06 04:56:501750void RenderWidget::UpdateWebViewWithDeviceScaleFactor() {
1751 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1752 blink::WebFrame* current_frame =
1753 frame_widget ? frame_widget->LocalRoot() : nullptr;
1754 blink::WebView* webview = current_frame ? current_frame->View() : nullptr;
1755 if (webview) {
danakj4b347212018-07-04 17:55:171756 if (compositor_deps_->IsUseZoomForDSFEnabled())
Fady Samuela863f152018-03-09 16:10:031757 webview->SetZoomFactorForDeviceScaleFactor(
1758 GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501759 else
Fady Samuela863f152018-03-09 16:10:031760 webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501761
1762 webview->GetSettings()->SetPreferCompositingToLCDTextEnabled(
Christopher Camerone9a30c12018-03-07 08:23:381763 PreferCompositingToLCDText(compositor_deps_,
Fady Samuela863f152018-03-09 16:10:031764 GetWebScreenInfo().device_scale_factor));
Mitsuru Oshima3c07b332018-02-06 04:56:501765 }
1766}
1767
Ehsan Karamad655d7b8a2018-01-12 18:38:381768blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
danakj89ae4532018-12-12 22:52:551769 // TODO(danakj): Remove this check and don't call this method for non-frames.
1770 if (!for_frame())
1771 return nullptr;
1772 // TODO(danakj): Is this needed? IPCs stop after closing, but code used to
1773 // check for a null WebWidget.
1774 if (closing_)
Ehsan Karamad655d7b8a2018-01-12 18:38:381775 return nullptr;
1776
danakj89ae4532018-12-12 22:52:551777 blink::WebWidget* widget;
Albert J. Wong7bbf22d2018-12-20 00:27:271778 if (delegate()) {
danakj89ae4532018-12-12 22:52:551779 // Main frame WebFrameWidgets are held by the delegate, the internal widget
1780 // points directly to the WebView.
1781 // TODO(ekaramad): We should drop IPCs when |is_frozen_| instead of
1782 // handling them and finding a null here. However there is also the case
1783 // of the frame being detached without the widget being frozen to be
1784 // resolved (https://crbug.com/906340). So for now this can return null.
Albert J. Wong7bbf22d2018-12-20 00:27:271785 widget = delegate()->GetWebWidgetForWidget();
danakj89ae4532018-12-12 22:52:551786 } else {
1787 // Subframes always have a WebFrameWidget themselves.
1788 widget = webwidget_internal_;
Ehsan Karamad655d7b8a2018-01-12 18:38:381789 }
danakj89ae4532018-12-12 22:52:551790 return static_cast<blink::WebFrameWidget*>(widget);
Ehsan Karamad655d7b8a2018-01-12 18:38:381791}
1792
bokan841fdc72016-10-06 00:16:351793void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1794 DCHECK(window_rect);
1795 float scale = popup_origin_scale_for_emulation_;
1796 if (!scale)
1797 return;
1798 window_rect->x =
1799 popup_view_origin_for_emulation_.x() +
1800 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1801 window_rect->y =
1802 popup_view_origin_for_emulation_.y() +
1803 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1804}
1805
1806void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1807 DCHECK(window_rect);
1808 float scale = popup_origin_scale_for_emulation_;
1809 if (!scale)
1810 return;
1811 window_rect->x =
1812 popup_screen_origin_for_emulation_.x() +
1813 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1814 window_rect->y =
1815 popup_screen_origin_for_emulation_.y() +
1816 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1817}
1818
Blink Reformat1c4d759e2017-04-09 16:34:541819WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351820 WebRect rect;
bokan6b08cd22016-10-05 00:55:211821 if (pending_window_rect_count_) {
1822 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1823 // the RootWindowRect is probably going to return wrong results since the
1824 // browser may not have processed the Move yet. There isn't really anything
1825 // good to do in this case, and it shouldn't happen - since this size is
1826 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351827 rect = pending_window_rect_;
1828 } else {
1829 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211830 }
[email protected]2533ce12009-05-09 00:02:241831
bokan841fdc72016-10-06 00:16:351832 ScreenRectToEmulatedIfNeeded(&rect);
1833 return rect;
bokan6b08cd22016-10-05 00:55:211834}
1835
Blink Reformat1c4d759e2017-04-09 16:34:541836WebRect RenderWidget::ViewRect() {
Albert J. Wong3c93c182018-09-27 17:29:431837 WebRect rect = widget_screen_rect_;
bokan841fdc72016-10-06 00:16:351838 ScreenRectToEmulatedIfNeeded(&rect);
1839 return rect;
initial.commit09911bf2008-07-26 23:55:291840}
1841
Blink Reformat1c4d759e2017-04-09 16:34:541842void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301843 WebTextDirection hint) {
Albert J. Wong3c93c182018-09-27 17:29:431844 Send(new WidgetHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301845}
1846
Blink Reformat1c4d759e2017-04-09 16:34:541847void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
danakj81d601e62018-10-09 22:15:051848 // This path is for the renderer to change the on-screen position/size of
1849 // the widget by changing its window rect. This is not possible for
1850 // RenderWidgets whose position/size are controlled by layout from another
danakj6dcbc5962018-11-16 16:45:421851 // frame tree (ie. child local root frames), as the window rect can only be
1852 // set by the browser.
1853 if (for_child_local_root_frame_)
danakj81d601e62018-10-09 22:15:051854 return;
1855
oshima33ec97cd2015-12-14 19:40:241856 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351857 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511858
danakj65f423b72018-10-10 17:21:201859 if (resizing_mode_selector_->is_synchronous_mode()) {
Kent Tamura21d1de62018-12-10 04:45:201860 // This is a web-test-only path. At one point, it was planned to be
danakj65f423b72018-10-10 17:21:201861 // removed. See https://crbug.com/309760.
bokanc007c3a2015-02-03 07:15:561862 SetWindowRectSynchronously(window_rect);
danakj65f423b72018-10-10 17:21:201863 return;
1864 }
1865
1866 if (show_callback_) {
1867 // The widget is not shown yet. Delay the |window_rect| being sent to the
1868 // browser until Show() is called so it can be sent with that IPC, once the
1869 // browser is ready for the info.
1870 initial_rect_ = window_rect;
1871 } else {
1872 Send(new WidgetHostMsg_RequestSetBounds(routing_id_, window_rect));
1873 SetPendingWindowRect(window_rect);
initial.commit09911bf2008-07-26 23:55:291874 }
1875}
1876
[email protected]2533ce12009-05-09 00:02:241877void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1878 pending_window_rect_ = rect;
1879 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241880
bokan6b08cd22016-10-05 00:55:211881 // Popups don't get size updates back from the browser so just store the set
1882 // values.
danakj89ae4532018-12-12 22:52:551883 if (!for_frame()) {
Blink Reformat1c4d759e2017-04-09 16:34:541884 window_screen_rect_ = rect;
Albert J. Wong3c93c182018-09-27 17:29:431885 widget_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241886 }
[email protected]d4547452008-08-28 18:36:371887}
1888
wjmacleanee244e02017-05-26 21:06:071889void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1890 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071891 has_host_context_menu_location_ = true;
1892 host_context_menu_location_ = location;
1893 if (GetWebWidget()) {
1894 GetWebWidget()->ShowContextMenu(
1895 static_cast<blink::WebMenuSourceType>(source_type));
1896 }
1897 has_host_context_menu_location_ = false;
1898}
1899
[email protected]fa7b1dc2010-06-23 17:53:041900void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261901 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111902 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071903 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111904 int selection_start,
1905 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351906 if (!ShouldHandleImeEvents())
1907 return;
1908
brettw4b461082016-11-19 18:55:161909#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491910 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111911 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491912 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091913 return;
1914 }
1915#endif
[email protected]66fca5bc2013-05-23 06:58:291916 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011917 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011918 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541919 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111920 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561921 replacement_range.IsValid()
1922 ? WebRange(replacement_range.start(), replacement_range.length())
1923 : WebRange(),
1924 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041925 // If we failed to set the composition text, then we need to let the browser
1926 // process to cancel the input method's ongoing composition session, to make
1927 // sure we are in a consistent state.
Dave Tapuska04bc5ee92018-04-17 19:03:311928 if (mojom::WidgetInputHandlerHost* host =
1929 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1930 host->ImeCancelComposition();
Dave Tapuska139a72f2017-09-06 21:57:031931 }
[email protected]7f00efa2010-04-15 05:01:261932 }
nonafa291792016-08-10 02:36:181933 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041934}
1935
rlanday7efe2302017-01-11 00:14:281936void RenderWidget::OnImeCommitText(
1937 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111938 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281939 const gfx::Range& replacement_range,
1940 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351941 if (!ShouldHandleImeEvents())
1942 return;
1943
brettw4b461082016-11-19 18:55:161944#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491945 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1946 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1947 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091948 return;
1949 }
1950#endif
[email protected]66fca5bc2013-05-23 06:58:291951 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391952 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261953 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541954 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111955 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561956 replacement_range.IsValid()
1957 ? WebRange(replacement_range.start(), replacement_range.length())
1958 : WebRange(),
1959 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261960 }
aelias87b8f7c2016-09-14 03:19:291961 input_handler_->set_handling_input_event(false);
1962 UpdateCompositionInfo(false /* not an immediate request */);
1963}
1964
1965void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351966 if (!ShouldHandleImeEvents())
1967 return;
1968
brettw4b461082016-11-19 18:55:161969#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491970 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1971 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291972 return;
1973 }
1974#endif
1975
changwan38c3eb612016-12-09 01:45:561976 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291977 return;
1978 ImeEventGuard guard(this);
1979 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011980 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541981 controller->FinishComposingText(
1982 keep_selection ? WebInputMethodController::kKeepSelection
1983 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011984 }
fsamuele8326c742016-01-12 00:49:391985 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181986 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291987}
1988
Christopher Camerone9a30c12018-03-07 08:23:381989void RenderWidget::UpdateSurfaceAndScreenInfo(
Fady Samuel1c1ad3692018-11-06 23:28:401990 const viz::LocalSurfaceIdAllocation& new_local_surface_id_allocation,
Christopher Cameronaad15a0d2018-03-09 03:47:331991 const gfx::Size& new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381992 const ScreenInfo& new_screen_info) {
Christopher Camerone9a30c12018-03-07 08:23:381993 bool orientation_changed =
1994 screen_info_.orientation_angle != new_screen_info.orientation_angle ||
1995 screen_info_.orientation_type != new_screen_info.orientation_type;
1996 bool web_device_scale_factor_changed =
1997 screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
Fady Samuela863f152018-03-09 16:10:031998 ScreenInfo previous_original_screen_info = GetOriginalScreenInfo();
Christopher Cameronbe7ecea2018-02-27 00:47:191999
Fady Samuel1c1ad3692018-11-06 23:28:402000 local_surface_id_allocation_from_parent_ = new_local_surface_id_allocation;
Christopher Cameronaad15a0d2018-03-09 03:47:332001 compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size;
Christopher Camerone9a30c12018-03-07 08:23:382002 screen_info_ = new_screen_info;
Christopher Cameronbe7ecea2018-02-27 00:47:192003
danakja6c10012018-07-06 14:25:362004 if (layer_tree_view_) {
2005 layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
Christopher Camerone9a30c12018-03-07 08:23:382006 // Note carefully that the DSF specified in |new_screen_info| is not the
2007 // DSF used by the compositor during device emulation!
danakja6c10012018-07-06 14:25:362008 layer_tree_view_->SetViewportSizeAndScale(
Fady Samuela863f152018-03-09 16:10:032009 compositor_viewport_pixel_size_,
Fady Samuel4255c182018-05-24 20:42:362010 GetOriginalScreenInfo().device_scale_factor,
Fady Samuel1c1ad3692018-11-06 23:28:402011 local_surface_id_allocation_from_parent_);
Christopher Camerone9a30c12018-03-07 08:23:382012 }
Christopher Cameronbe7ecea2018-02-27 00:47:192013
Christopher Camerone9a30c12018-03-07 08:23:382014 if (orientation_changed)
2015 OnOrientationChange();
Christopher Cameronbe7ecea2018-02-27 00:47:192016
Fady Samuela863f152018-03-09 16:10:032017 if (previous_original_screen_info != GetOriginalScreenInfo()) {
Christopher Camerone9a30c12018-03-07 08:23:382018 for (auto& observer : render_frame_proxies_)
Fady Samuela863f152018-03-09 16:10:032019 observer.OnScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:382020
2021 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
2022 for (auto& observer : browser_plugins_)
Fady Samuela863f152018-03-09 16:10:032023 observer.ScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:382024 }
2025
2026 if (web_device_scale_factor_changed)
Christopher Cameronbe7ecea2018-02-27 00:47:192027 UpdateWebViewWithDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332028}
2029
danakja2c9d0a92018-07-25 20:01:182030void RenderWidget::SetWindowRectSynchronously(
2031 const gfx::Rect& new_window_rect) {
2032 VisualProperties visual_properties;
2033 visual_properties.screen_info = screen_info_;
2034 visual_properties.new_size = new_window_rect.size();
2035 visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
2036 new_window_rect.size(), GetWebScreenInfo().device_scale_factor);
2037 visual_properties.visible_viewport_size = new_window_rect.size();
2038 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
2039 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:172040 visual_properties.local_surface_id_allocation =
2041 local_surface_id_allocation_from_parent_;
W. James MacLean2a90bff2018-11-05 20:52:472042 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:182043 // We are resizing the window from the renderer, so allocate a new
2044 // viz::LocalSurfaceId to avoid surface invariants violations in tests.
2045 if (layer_tree_view_)
2046 layer_tree_view_->RequestNewLocalSurfaceId();
2047 SynchronizeVisualProperties(visual_properties);
2048
Albert J. Wong3c93c182018-09-27 17:29:432049 widget_screen_rect_ = new_window_rect;
danakja2c9d0a92018-07-25 20:01:182050 window_screen_rect_ = new_window_rect;
danakj65f423b72018-10-10 17:21:202051 if (show_callback_) {
2052 // Tests may call here directly to control the window rect. If
2053 // Show() did not happen yet, the rect is stored to be passed to the
2054 // browser when the RenderWidget requests Show().
danakja2c9d0a92018-07-25 20:01:182055 initial_rect_ = new_window_rect;
danakj65f423b72018-10-10 17:21:202056 }
danakja2c9d0a92018-07-25 20:01:182057}
2058
Vladimir Levin98d76dad2018-04-21 00:21:292059void RenderWidget::UpdateCaptureSequenceNumber(
2060 uint32_t capture_sequence_number) {
2061 if (capture_sequence_number == last_capture_sequence_number_)
2062 return;
2063 last_capture_sequence_number_ = capture_sequence_number;
2064
2065 // Notify observers of the new capture sequence number.
2066 for (auto& observer : render_frame_proxies_)
2067 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
2068 for (auto& observer : browser_plugins_)
2069 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
2070}
2071
[email protected]4873c7d2009-07-16 06:36:282072void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:402073 if (auto* frame = GetFocusedWebLocalFrameInWidget())
2074 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:112075}
2076
Albert J. Wong3c93c182018-09-27 17:29:432077void RenderWidget::OnUpdateScreenRects(const gfx::Rect& widget_screen_rect,
[email protected]80ad8622012-11-07 16:33:032078 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:512079 if (screen_metrics_emulator_) {
Albert J. Wong3c93c182018-09-27 17:29:432080 screen_metrics_emulator_->OnUpdateScreenRects(widget_screen_rect,
mfomitchev2600fd7c2016-02-17 20:53:392081 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512082 } else {
Albert J. Wong3c93c182018-09-27 17:29:432083 SetScreenRects(widget_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512084 }
Albert J. Wong3c93c182018-09-27 17:29:432085 Send(new WidgetHostMsg_UpdateScreenRects_ACK(routing_id()));
[email protected]80ad8622012-11-07 16:33:032086}
2087
kenrbea731792017-01-13 15:10:482088void RenderWidget::OnSetViewportIntersection(
Ken Buchananb2c9e262018-03-10 16:53:312089 const gfx::Rect& viewport_intersection,
Stefan Zager54e25832018-08-14 22:15:312090 const gfx::Rect& compositor_visible_rect,
2091 bool occluded_or_obscured) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252092 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchananb2c9e262018-03-10 16:53:312093 compositor_visible_rect_ = compositor_visible_rect;
Stefan Zager54e25832018-08-14 22:15:312094 frame_widget->SetRemoteViewportIntersection(viewport_intersection,
2095 occluded_or_obscured);
danakja6c10012018-07-06 14:25:362096 layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect());
kenrbea731792017-01-13 15:10:482097 }
2098}
2099
kenrb04323782017-06-23 01:23:322100void RenderWidget::OnSetIsInert(bool inert) {
danakj89ae4532018-12-12 22:52:552101 if (auto* frame_widget = GetFrameWidget())
Ehsan Karamadf3ca2a82018-01-20 01:05:252102 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:322103}
2104
sunxd540a9962018-05-24 22:51:062105void RenderWidget::OnSetInheritedEffectiveTouchAction(
2106 cc::TouchAction touch_action) {
danakj89ae4532018-12-12 22:52:552107 if (auto* frame_widget = GetFrameWidget())
sunxd540a9962018-05-24 22:51:062108 frame_widget->SetInheritedEffectiveTouchAction(touch_action);
sunxd540a9962018-05-24 22:51:062109}
2110
Ken Buchanan8a319fb2017-11-15 18:37:122111void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
2112 bool subtree_throttled) {
danakj89ae4532018-12-12 22:52:552113 if (auto* frame_widget = GetFrameWidget())
Ehsan Karamadf3ca2a82018-01-20 01:05:252114 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:122115}
2116
paulmeyer90f6c31d2016-11-12 00:17:592117void RenderWidget::OnDragTargetDragEnter(
2118 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:522119 const gfx::PointF& client_point,
2120 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592121 WebDragOperationsMask ops,
2122 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252123 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2124 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592125 return;
2126
Ehsan Karamadf3ca2a82018-01-20 01:05:252127 WebDragOperation operation = frame_widget->DragTargetDragEnter(
2128 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
2129 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592130
2131 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2132}
2133
Ella Ge80a52dce2017-11-15 18:01:522134void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
2135 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592136 WebDragOperationsMask ops,
2137 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252138 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2139 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592140 return;
2141
Ehsan Karamadf3ca2a82018-01-20 01:05:252142 WebDragOperation operation = frame_widget->DragTargetDragOver(
2143 ConvertWindowPointToViewport(client_point), screen_point, ops,
2144 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592145
2146 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2147}
2148
Ella Ge80a52dce2017-11-15 18:01:522149void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
2150 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252151 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2152 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592153 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:252154
2155 frame_widget
Blink Reformat1c4d759e2017-04-09 16:34:542156 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:172157 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:592158}
2159
2160void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:522161 const gfx::PointF& client_point,
2162 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592163 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252164 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2165 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592166 return;
2167
Ehsan Karamadf3ca2a82018-01-20 01:05:252168 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
2169 ConvertWindowPointToViewport(client_point),
2170 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592171}
2172
Ella Ge80a52dce2017-11-15 18:01:522173void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
2174 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:212175 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252176 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2177 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212178 return;
2179
Ehsan Karamadf3ca2a82018-01-20 01:05:252180 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
2181 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:212182}
2183
2184void RenderWidget::OnDragSourceSystemDragEnded() {
2185 if (!GetWebWidget())
2186 return;
2187
Blink Reformat1c4d759e2017-04-09 16:34:542188 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:212189}
2190
Blink Reformat1c4d759e2017-04-09 16:34:542191void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:262192#if defined(OS_CHROMEOS)
2193 // On ChromeOS, virtual keyboard is triggered only when users leave the
2194 // mouse button or the finger and a text input element is focused at that
2195 // time. Focus event itself shouldn't trigger virtual keyboard.
2196 UpdateTextInputState();
2197#else
changwan75e3b2072017-01-16 02:55:002198 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:262199#endif
boliu7b2be2f2016-11-04 04:58:312200
2201// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
2202// virtual keyboard.
2203#if !defined(OS_ANDROID)
2204 FocusChangeComplete();
2205#endif
[email protected]0d1ebed12013-08-05 22:01:132206}
2207
fsamuel72464894f2015-12-15 06:59:312208ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:162209#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492210 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2211 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:092212#endif
ekaramad5aff1942017-01-06 01:26:352213 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:542214 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:312215 return ui::TEXT_INPUT_TYPE_NONE;
2216}
2217
nonafa291792016-08-10 02:36:182218void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
2219 if (!monitor_composition_info_ && !immediate_request)
2220 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:592221
nonafa291792016-08-10 02:36:182222 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2223 gfx::Range range;
2224 std::vector<gfx::Rect> character_bounds;
2225
2226 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2227 // Composition information is only available on editable node.
2228 range = gfx::Range::InvalidRange();
2229 } else {
2230 GetCompositionRange(&range);
2231 GetCompositionCharacterBounds(&character_bounds);
2232 }
2233
2234 if (!immediate_request &&
2235 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312236 return;
nonafa291792016-08-10 02:36:182237 }
fsamuel72464894f2015-12-15 06:59:312238 composition_character_bounds_ = character_bounds;
2239 composition_range_ = range;
Dave Tapuska04bc5ee92018-04-17 19:03:312240 if (mojom::WidgetInputHandlerHost* host =
2241 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2242 host->ImeCompositionRangeChanged(composition_range_,
2243 composition_character_bounds_);
Dave Tapuska139a72f2017-09-06 21:57:032244 }
fsamuel72464894f2015-12-15 06:59:312245}
2246
Blink Reformat1c4d759e2017-04-09 16:34:542247void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
danakj4b347212018-07-04 17:55:172248 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032249 float reverse = 1 / GetOriginalScreenInfo().device_scale_factor;
oshimad5279032015-12-16 18:22:332250 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542251 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462252 gfx::Rect window_rect =
2253 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2254 rect->x = window_rect.x();
2255 rect->y = window_rect.y();
2256 rect->width = window_rect.width();
2257 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542258 }
2259}
2260
Blink Reformat1c4d759e2017-04-09 16:34:542261void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
danakj4b347212018-07-04 17:55:172262 if (compositor_deps_->IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:032263 rect->x *= GetOriginalScreenInfo().device_scale_factor;
2264 rect->y *= GetOriginalScreenInfo().device_scale_factor;
2265 rect->width *= GetOriginalScreenInfo().device_scale_factor;
2266 rect->height *= GetOriginalScreenInfo().device_scale_factor;
oshimaa6985b62016-01-27 08:58:302267 }
2268}
2269
changwan8c342742016-02-26 00:53:392270void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262271#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392272 DCHECK(!ime_event_guard_);
2273 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002274 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212275#endif
Dave Tapuska9db80842017-07-24 17:24:262276}
[email protected]105dffb42013-02-20 03:46:212277
ekaramadc9b70a72017-03-23 16:14:232278void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2279 bool monitor_updates) {
2280 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182281 if (!immediate_request)
2282 return;
2283 UpdateCompositionInfo(true /* immediate request */);
2284}
2285
[email protected]fcdc5642014-05-09 14:32:242286void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382287 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002288 // LocalRoot() might return null for provisional main frames. In this case,
2289 // the frame hasn't committed a navigation and is not swapped into the tree
2290 // yet, so it doesn't make sense to send orientation change events to it.
2291 //
2292 // TODO(https://crbug.com/578349): This check should be cleaned up
2293 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382294 if (frame_widget->LocalRoot())
2295 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302296 }
[email protected]fcdc5642014-05-09 14:32:242297}
2298
[email protected]bee16aab2009-08-26 15:55:032299void RenderWidget::SetHidden(bool hidden) {
2300 if (is_hidden_ == hidden)
2301 return;
2302
jdduke8fac9d102014-12-20 02:40:132303 // The status has changed. Tell the RenderThread about it and ensure
2304 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032305 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132306
Scott Violet1098538e2017-10-05 19:23:332307#if defined(USE_AURA)
Scott Violete46b3352018-09-22 00:37:072308 if (features::IsMultiProcessMash())
Scott Violet1098538e2017-10-05 19:23:332309 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2310#endif
2311
Saman Sami58ed4392018-01-31 20:54:192312 // RenderThreadImpl::current() could be null in tests.
2313 if (RenderThreadImpl::current()) {
2314 if (is_hidden_) {
2315 RenderThreadImpl::current()->WidgetHidden();
2316 first_update_visual_state_after_hidden_ = true;
2317 } else {
2318 RenderThreadImpl::current()->WidgetRestored();
2319 }
Lei Zhang9b359d32017-11-28 00:57:022320 }
alexclarke7fa93942015-10-21 15:37:112321
2322 if (render_widget_scheduling_state_)
2323 render_widget_scheduling_state_->SetHidden(hidden);
danakj1b35e9d2018-11-07 19:09:282324
danakj57f139f2018-11-19 19:23:462325 // When the RenderWidget is frozen, visibility of the compositor is overridden
2326 // to always be hidden to prevent it from using resources that are not needed.
2327 // Unfortunately the main RenderWidget for a RenderView must be marked visible
2328 // even if the RenderView has a proxy main frame (and the RenderWidget is
2329 // frozen), in order for the RenderView to use the visibility signal from the
2330 // RenderWidget. This is bad. But we don't need to show the compositor to
2331 // satisfy that requirement.
2332 if (!is_frozen_)
2333 layer_tree_view_->SetVisible(!is_hidden_);
[email protected]bee16aab2009-08-26 15:55:032334}
2335
[email protected]2b624c562011-10-27 22:58:262336void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212337 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262338 return;
2339
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122340 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542341 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262342 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542343 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262344 }
[email protected]2b624c562011-10-27 22:58:262345}
2346
changwanf2a707b2015-10-30 08:22:162347void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2348 if (!ime_event_guard_)
2349 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292350}
2351
changwanf2a707b2015-10-30 08:22:162352void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
Jeremy Roman0b261f42018-08-28 15:36:012353 if (ime_event_guard_ != guard)
changwanf2a707b2015-10-30 08:22:162354 return;
changwanf2a707b2015-10-30 08:22:162355 ime_event_guard_ = nullptr;
2356
[email protected]66fca5bc2013-05-23 06:58:292357 // While handling an ime event, text input state and selection bounds updates
2358 // are ignored. These must explicitly be updated once finished handling the
2359 // ime event.
2360 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472361#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002362 if (guard->show_virtual_keyboard())
2363 ShowVirtualKeyboard();
2364 else
2365 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472366#endif
[email protected]66fca5bc2013-05-23 06:58:292367}
2368
[email protected]7c8873e2013-02-05 08:03:012369void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162370#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492371 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092372 // TODO(kinaba) http://crbug.com/101101
2373 // Current Pepper IME API does not handle selection bounds. So we simply
2374 // use the caret position as an empty range for now. It will be updated
2375 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492376 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542377 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092378 *focus = caret;
2379 *anchor = caret;
2380 return;
2381 }
2382#endif
[email protected]7c8873e2013-02-05 08:03:012383 WebRect focus_webrect;
2384 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542385 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2386 ConvertViewportToWindow(&focus_webrect);
2387 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242388 *focus = focus_webrect;
2389 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322390}
2391
[email protected]e99ef6f2011-10-16 01:13:002392void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082393 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212394 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002395 return;
changwanf2a707b2015-10-30 08:22:162396 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292397 return;
[email protected]e99ef6f2011-10-16 01:13:002398
mohsenb0eeba72015-08-09 06:20:082399#if defined(USE_AURA)
2400 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2401 // Aura beucause composited selection updates are not working for webview tags
2402 // which regresses IME inside webview. Remove this when composited selection
2403 // updates are fixed for webviews. See, http://crbug.com/510568.
2404 bool send_ipc = true;
2405#else
jddukeacf809e2014-09-23 20:38:382406 // With composited selection updates, the selection bounds will be reported
2407 // directly by the compositor, in which case explicit IPC selection
2408 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082409 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542410 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082411#endif
2412 if (send_ipc) {
Albert J. Wong3c93c182018-09-27 17:29:432413 WidgetHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402414 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382415 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2416 if (selection_anchor_rect_ != params.anchor_rect ||
2417 selection_focus_rect_ != params.focus_rect) {
2418 selection_anchor_rect_ = params.anchor_rect;
2419 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402420 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2421 focused_frame->SelectionTextDirection(params.focus_dir,
2422 params.anchor_dir);
2423 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2424 }
Albert J. Wong3c93c182018-09-27 17:29:432425 Send(new WidgetHostMsg_SelectionBoundsChanged(routing_id_, params));
jddukeacf809e2014-09-23 20:38:382426 }
[email protected]58b48a0d2012-06-13 07:01:352427 }
jddukeacf809e2014-09-23 20:38:382428
nonafa291792016-08-10 02:36:182429 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002430}
2431
lfgb00fcad2016-07-14 14:16:332432void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2433 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542434 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332435 if (size_.width() != new_size_in_window.width ||
2436 size_.height() != new_size_in_window.height) {
2437 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2438
2439 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542440 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2441 size_.height());
Albert J. Wong3c93c182018-09-27 17:29:432442 widget_screen_rect_ = new_pos;
lfgb00fcad2016-07-14 14:16:332443 window_screen_rect_ = new_pos;
2444 }
2445
Christopher Camerone9a30c12018-03-07 08:23:382446 // TODO(ccameron): Note that this destroys any information differentiating
Christopher Cameronaad15a0d2018-03-09 03:47:332447 // |size_| from |compositor_viewport_pixel_size_|. Also note that the
2448 // calculation of |new_compositor_viewport_pixel_size| does not appear to
2449 // take into account device emulation.
danakja6c10012018-07-06 14:25:362450 if (layer_tree_view_)
2451 layer_tree_view_->RequestNewLocalSurfaceId();
Christopher Cameronaad15a0d2018-03-09 03:47:332452 gfx::Size new_compositor_viewport_pixel_size =
Fady Samuela863f152018-03-09 16:10:032453 gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
Fady Samuel1c1ad3692018-11-06 23:28:402454 UpdateSurfaceAndScreenInfo(local_surface_id_allocation_from_parent_,
2455 new_compositor_viewport_pixel_size,
2456 screen_info_);
lfgb00fcad2016-07-14 14:16:332457 }
2458}
2459
[email protected]58b48a0d2012-06-13 07:01:352460void RenderWidget::GetCompositionCharacterBounds(
2461 std::vector<gfx::Rect>* bounds) {
2462 DCHECK(bounds);
2463 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092464
brettw4b461082016-11-19 18:55:162465#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492466 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092467 return;
2468#endif
2469
Ehsan Karamad4975af6d2018-02-09 16:58:162470 blink::WebInputMethodController* controller = GetInputMethodController();
2471 if (!controller)
ekaramad2a46d632016-07-19 13:33:092472 return;
2473 blink::WebVector<blink::WebRect> bounds_from_blink;
Ehsan Karamad4975af6d2018-02-09 16:58:162474 if (!controller->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092475 return;
2476
2477 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542478 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092479 bounds->push_back(bounds_from_blink[i]);
2480 }
[email protected]58b48a0d2012-06-13 07:01:352481}
2482
[email protected]db4fc1e2013-09-06 20:01:512483void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162484#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492485 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092486 return;
2487#endif
EhsanKcdee7b72017-11-08 21:30:092488 blink::WebInputMethodController* controller = GetInputMethodController();
2489 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542490 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212491 *range = gfx::Range::InvalidRange();
2492 return;
[email protected]88dbe32f2013-06-20 23:31:362493 }
Blink Reformat1c4d759e2017-04-09 16:34:542494 range->set_start(web_range.StartOffset());
2495 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362496}
2497
[email protected]501ea13d2013-07-09 17:03:292498bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512499 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292500 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082501 if (!range.IsValid())
2502 return false;
[email protected]501ea13d2013-07-09 17:03:292503 if (composition_range_ != range)
2504 return true;
2505 if (bounds.size() != composition_character_bounds_.size())
2506 return true;
2507 for (size_t i = 0; i < bounds.size(); ++i) {
2508 if (bounds[i] != composition_character_bounds_[i])
2509 return true;
2510 }
2511 return false;
2512}
[email protected]501ea13d2013-07-09 17:03:292513
[email protected]ad26ef42011-06-17 07:59:452514bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162515#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492516 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2517 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092518#endif
[email protected]ad26ef42011-06-17 07:59:452519 return true;
[email protected]56ea1a62011-05-30 07:05:572520}
2521
Blink Reformat1c4d759e2017-04-09 16:34:542522void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2523 bool event_cancelled) {
danakja2c9d0a92018-07-25 20:01:182524 if (event_cancelled) {
Albert J. Wong7bbf22d2018-12-20 00:27:272525 // The delegate() doesn't need to hear about cancelled events.
[email protected]c68c3e4e2013-01-24 00:36:562526 return;
danakja2c9d0a92018-07-25 20:01:182527 }
2528
2529#if defined(OS_ANDROID) || defined(USE_AURA)
Blink Reformat1c4d759e2017-04-09 16:34:542530 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002531 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542532 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212533 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352534 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542535 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002536 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462537 else
changwan75e3b2072017-01-16 02:55:002538 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562539 }
ekaramada110f642016-12-21 19:47:282540// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2541// crbug/420130.
2542#if defined(OS_WIN)
danakja2c9d0a92018-07-25 20:01:182543 if (event.GetType() == blink::WebGestureEvent::kGestureTap) {
2544 // TODO(estade): hit test the event against focused node to make sure
2545 // the tap actually hit the focused node.
2546 blink::WebInputMethodController* controller = GetInputMethodController();
2547 blink::WebTextInputType text_input_type =
2548 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282549
Albert J. Wong3c93c182018-09-27 17:29:432550 Send(new WidgetHostMsg_FocusedNodeTouched(
danakja2c9d0a92018-07-25 20:01:182551 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
2552 }
ekaramada110f642016-12-21 19:47:282553#endif
[email protected]c68c3e4e2013-01-24 00:36:562554#endif
danakja2c9d0a92018-07-25 20:01:182555
Albert J. Wong7bbf22d2018-12-20 00:27:272556 // The delegate() gets to respond to handling gestures last.
2557 if (delegate())
2558 delegate()->DidHandleGestureEventForWidget(event);
[email protected]c68c3e4e2013-01-24 00:36:562559}
2560
Blink Reformat1c4d759e2017-04-09 16:34:542561void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312562 const blink::WebFloatSize& overscrollDelta,
2563 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422564 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542565 const blink::WebFloatSize& velocity,
danakje819b622018-05-01 20:27:142566 const cc::OverscrollBehavior& behavior) {
bokan731ec382016-04-07 03:16:482567#if defined(OS_MACOSX)
2568 // On OSX the user can disable the elastic overscroll effect. If that's the
2569 // case, don't forward the overscroll notification.
2570 DCHECK(compositor_deps());
2571 if (!compositor_deps()->IsElasticOverscrollEnabled())
2572 return;
2573#endif
bokane53a10f2016-04-13 23:48:312574 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542575 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422576}
2577
danakj4b347212018-07-04 17:55:172578// static
2579cc::LayerTreeSettings RenderWidget::GenerateLayerTreeSettings(
2580 CompositorDependencies* compositor_deps,
2581 bool is_for_subframe,
2582 const gfx::Size& initial_screen_size,
2583 float initial_device_scale_factor) {
2584 const bool is_threaded =
2585 !!compositor_deps->GetCompositorImplThreadTaskRunner();
2586
2587 const base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess();
2588 cc::LayerTreeSettings settings;
2589
2590 settings.resource_settings.use_r16_texture =
2591 base::FeatureList::IsEnabled(media::kUseR16Texture);
2592
2593 settings.commit_to_active_tree = !is_threaded;
2594 settings.is_layer_tree_for_subframe = is_for_subframe;
2595
2596 // For web contents, layer transforms should scale up the contents of layers
2597 // to keep content always crisp when possible.
2598 settings.layer_transforms_should_scale_layer_contents = true;
2599
2600 settings.main_frame_before_activation_enabled =
2601 cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation);
2602
2603 // Checkerimaging is not supported for synchronous single-threaded mode, which
2604 // is what the renderer uses if its not threaded.
2605 settings.enable_checker_imaging =
2606 !cmd.HasSwitch(cc::switches::kDisableCheckerImaging) && is_threaded;
2607
2608#if defined(OS_ANDROID)
2609 // We can use a more aggressive limit on Android since decodes tend to take
2610 // longer on these devices.
2611 settings.min_image_bytes_to_checker = 512 * 1024; // 512kB
2612
2613 // Re-rasterization of checker-imaged content with software raster can be too
2614 // costly on Android.
2615 settings.only_checker_images_with_gpu_raster = true;
2616#endif
2617
2618 auto switch_value_as_int = [](const base::CommandLine& command_line,
2619 const std::string& switch_string, int min_value,
2620 int max_value, int* result) {
2621 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
2622 int int_value;
2623 if (base::StringToInt(string_value, &int_value) && int_value >= min_value &&
2624 int_value <= max_value) {
2625 *result = int_value;
2626 return true;
2627 } else {
2628 LOG(WARNING) << "Failed to parse switch " << switch_string << ": "
2629 << string_value;
2630 return false;
2631 }
2632 };
2633
2634 int default_tile_size = 256;
2635#if defined(OS_ANDROID)
2636 const gfx::Size screen_size =
2637 gfx::ScaleToFlooredSize(initial_screen_size, initial_device_scale_factor);
2638 int display_width = screen_size.width();
2639 int display_height = screen_size.height();
2640 int numTiles = (display_width * display_height) / (256 * 256);
2641 if (numTiles > 16)
2642 default_tile_size = 384;
2643 if (numTiles >= 40)
2644 default_tile_size = 512;
2645
2646 // Adjust for some resolutions that barely straddle an extra
2647 // tile when in portrait mode. This helps worst case scroll/raster
2648 // by not needing a full extra tile for each row.
2649 constexpr int tolerance = 10; // To avoid rounding errors.
2650 int portrait_width = std::min(display_width, display_height);
2651 if (default_tile_size == 256 && std::abs(portrait_width - 768) < tolerance)
2652 default_tile_size += 32;
2653 if (default_tile_size == 384 && std::abs(portrait_width - 1200) < tolerance)
2654 default_tile_size += 32;
2655#elif defined(OS_CHROMEOS) || defined(OS_MACOSX)
2656 // Use 512 for high DPI (dsf=2.0f) devices.
2657 if (initial_device_scale_factor >= 2.0f)
2658 default_tile_size = 512;
2659#endif
2660
2661 // TODO(danakj): This should not be a setting O_O; it should change when the
2662 // device scale factor on LayerTreeHost changes.
2663 settings.default_tile_size = gfx::Size(default_tile_size, default_tile_size);
2664 if (cmd.HasSwitch(switches::kDefaultTileWidth)) {
2665 int tile_width = 0;
2666 switch_value_as_int(cmd, switches::kDefaultTileWidth, 1,
2667 std::numeric_limits<int>::max(), &tile_width);
2668 settings.default_tile_size.set_width(tile_width);
2669 }
2670 if (cmd.HasSwitch(switches::kDefaultTileHeight)) {
2671 int tile_height = 0;
2672 switch_value_as_int(cmd, switches::kDefaultTileHeight, 1,
2673 std::numeric_limits<int>::max(), &tile_height);
2674 settings.default_tile_size.set_height(tile_height);
2675 }
2676
2677 int max_untiled_layer_width = settings.max_untiled_layer_size.width();
2678 if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) {
2679 switch_value_as_int(cmd, switches::kMaxUntiledLayerWidth, 1,
2680 std::numeric_limits<int>::max(),
2681 &max_untiled_layer_width);
2682 }
2683 int max_untiled_layer_height = settings.max_untiled_layer_size.height();
2684 if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) {
2685 switch_value_as_int(cmd, switches::kMaxUntiledLayerHeight, 1,
2686 std::numeric_limits<int>::max(),
2687 &max_untiled_layer_height);
2688 }
2689
2690 settings.max_untiled_layer_size =
2691 gfx::Size(max_untiled_layer_width, max_untiled_layer_height);
2692
2693 settings.gpu_rasterization_msaa_sample_count =
2694 compositor_deps->GetGpuRasterizationMSAASampleCount();
2695 settings.gpu_rasterization_forced =
2696 compositor_deps->IsGpuRasterizationForced();
2697
2698 settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled();
2699 settings.use_zero_copy = compositor_deps->IsZeroCopyEnabled();
2700 settings.use_partial_raster = compositor_deps->IsPartialRasterEnabled();
2701 settings.enable_elastic_overscroll =
2702 compositor_deps->IsElasticOverscrollEnabled();
2703 settings.resource_settings.use_gpu_memory_buffer_resources =
2704 compositor_deps->IsGpuMemoryBufferCompositorResourcesEnabled();
2705 settings.use_painted_device_scale_factor =
2706 compositor_deps->IsUseZoomForDSFEnabled();
2707
2708 // Build LayerTreeSettings from command line args.
2709 if (cmd.HasSwitch(cc::switches::kBrowserControlsShowThreshold)) {
2710 std::string top_threshold_str =
2711 cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsShowThreshold);
2712 double show_threshold;
2713 if (base::StringToDouble(top_threshold_str, &show_threshold) &&
2714 show_threshold >= 0.f && show_threshold <= 1.f)
2715 settings.top_controls_show_threshold = show_threshold;
2716 }
2717
2718 if (cmd.HasSwitch(cc::switches::kBrowserControlsHideThreshold)) {
2719 std::string top_threshold_str =
2720 cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsHideThreshold);
2721 double hide_threshold;
2722 if (base::StringToDouble(top_threshold_str, &hide_threshold) &&
2723 hide_threshold >= 0.f && hide_threshold <= 1.f)
2724 settings.top_controls_hide_threshold = hide_threshold;
2725 }
2726
Philip Rogersc55ab6a2018-12-05 17:29:192727 // Blink sends cc a layer list and property trees when either
2728 // BlinkGenPropertyTrees or CompositeAfterPaint are enabled.
Philip Rogersfc2f1162018-10-17 18:28:312729 settings.use_layer_lists =
2730 blink::WebRuntimeFeatures::IsBlinkGenPropertyTreesEnabled() ||
Philip Rogersc55ab6a2018-12-05 17:29:192731 blink::WebRuntimeFeatures::IsCompositeAfterPaintEnabled();
danakj4b347212018-07-04 17:55:172732
David Bokan163b6a72018-10-25 22:03:492733 // Blink currently doesn't support setting fractional scroll offsets so CC
2734 // must send integer values. We plan to eventually make Blink use fractional
2735 // offsets internally: https://crbug.com/414283.
2736 settings.commit_fractional_scroll_deltas =
2737 blink::WebRuntimeFeatures::IsFractionalScrollOffsetsEnabled();
2738
danakj4b347212018-07-04 17:55:172739 // The means the renderer compositor has 2 possible modes:
2740 // - Threaded compositing with a scheduler.
Kent Tamura21d1de62018-12-10 04:45:202741 // - Single threaded compositing without a scheduler (for web tests only).
2742 // Using the scheduler in web tests introduces additional composite steps
danakj4b347212018-07-04 17:55:172743 // that create flakiness.
2744 settings.single_thread_proxy_scheduler = false;
2745
2746 // These flags should be mirrored by UI versions in ui/compositor/.
2747 if (cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders))
2748 settings.initial_debug_state.show_debug_borders.set();
2749 settings.initial_debug_state.show_layer_animation_bounds_rects =
2750 cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds);
2751 settings.initial_debug_state.show_paint_rects =
2752 cmd.HasSwitch(switches::kShowPaintRects);
2753 settings.initial_debug_state.show_property_changed_rects =
2754 cmd.HasSwitch(cc::switches::kShowPropertyChangedRects);
2755 settings.initial_debug_state.show_surface_damage_rects =
2756 cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects);
2757 settings.initial_debug_state.show_screen_space_rects =
2758 cmd.HasSwitch(cc::switches::kShowScreenSpaceRects);
2759
2760 settings.initial_debug_state.SetRecordRenderingStats(
2761 cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking));
2762 settings.enable_surface_synchronization =
2763 features::IsSurfaceSynchronizationEnabled();
2764 settings.build_hit_test_data = features::IsVizHitTestingSurfaceLayerEnabled();
2765
2766 if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) {
2767 const int kMinSlowDownScaleFactor = 0;
2768 const int kMaxSlowDownScaleFactor = INT_MAX;
2769 switch_value_as_int(
2770 cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor,
2771 kMaxSlowDownScaleFactor,
2772 &settings.initial_debug_state.slow_down_raster_scale_factor);
2773 }
2774
2775 // This is default overlay scrollbar settings for Android and DevTools mobile
2776 // emulator. Aura Overlay Scrollbar will override below.
2777 settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY;
2778 settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
2779 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300);
2780 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
2781
2782#if defined(OS_ANDROID)
2783 bool using_synchronous_compositor =
2784 compositor_deps->UsingSynchronousCompositing();
2785 bool using_low_memory_policy = base::SysInfo::IsLowEndDevice();
2786
2787 settings.use_stream_video_draw_quad = true;
2788 settings.using_synchronous_renderer_compositor = using_synchronous_compositor;
2789 if (using_synchronous_compositor) {
2790 // Android WebView uses system scrollbars, so make ours invisible.
2791 // http://crbug.com/677348: This can't be done using hide_scrollbars
2792 // setting because supporting -webkit custom scrollbars is still desired
2793 // on sublayers.
2794 settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR;
2795 settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT;
2796
2797 settings.enable_early_damage_check =
2798 cmd.HasSwitch(cc::switches::kCheckDamageEarly);
2799 }
2800 // Android WebView handles root layer flings itself.
2801 settings.ignore_root_layer_flings = using_synchronous_compositor;
2802 // Memory policy on Android WebView does not depend on whether device is
2803 // low end, so always use default policy.
2804 if (using_low_memory_policy && !using_synchronous_compositor) {
2805 // On low-end we want to be very carefull about killing other
2806 // apps. So initially we use 50% more memory to avoid flickering
2807 // or raster-on-demand.
2808 settings.max_memory_for_prepaint_percentage = 67;
2809 } else {
2810 // On other devices we have increased memory excessively to avoid
2811 // raster-on-demand already, so now we reserve 50% _only_ to avoid
2812 // raster-on-demand, and use 50% of the memory otherwise.
2813 settings.max_memory_for_prepaint_percentage = 50;
2814 }
2815
2816 // TODO(danakj): Only do this on low end devices.
2817 settings.create_low_res_tiling = true;
2818
2819#else // defined(OS_ANDROID)
2820 bool using_synchronous_compositor = false; // Only for Android WebView.
2821 // On desktop, we never use the low memory policy unless we are simulating
2822 // low-end mode via a switch.
2823 bool using_low_memory_policy =
2824 cmd.HasSwitch(switches::kEnableLowEndDeviceMode);
2825
2826 if (ui::IsOverlayScrollbarEnabled()) {
2827 settings.scrollbar_animator = cc::LayerTreeSettings::AURA_OVERLAY;
2828 settings.scrollbar_fade_delay = ui::kOverlayScrollbarFadeDelay;
2829 settings.scrollbar_fade_duration = ui::kOverlayScrollbarFadeDuration;
2830 settings.scrollbar_thinning_duration =
2831 ui::kOverlayScrollbarThinningDuration;
2832 settings.scrollbar_flash_after_any_scroll_update =
2833 ui::OverlayScrollbarFlashAfterAnyScrollUpdate();
2834 settings.scrollbar_flash_when_mouse_enter =
2835 ui::OverlayScrollbarFlashWhenMouseEnter();
2836 }
2837
2838 // On desktop, if there's over 4GB of memory on the machine, increase the
2839 // working set size to 256MB for both gpu and software.
2840 const int kImageDecodeMemoryThresholdMB = 4 * 1024;
2841 if (base::SysInfo::AmountOfPhysicalMemoryMB() >=
2842 kImageDecodeMemoryThresholdMB) {
2843 settings.decoded_image_working_set_budget_bytes = 256 * 1024 * 1024;
2844 } else {
2845 // This is the default, but recorded here as well.
2846 settings.decoded_image_working_set_budget_bytes = 128 * 1024 * 1024;
2847 }
2848#endif // defined(OS_ANDROID)
2849
2850 if (using_low_memory_policy) {
2851 // RGBA_4444 textures are only enabled:
2852 // - If the user hasn't explicitly disabled them
2853 // - If system ram is <= 512MB (1GB devices are sometimes low-end).
2854 // - If we are not running in a WebView, where 4444 isn't supported.
2855 if (!cmd.HasSwitch(switches::kDisableRGBA4444Textures) &&
2856 base::SysInfo::AmountOfPhysicalMemoryMB() <= 512 &&
2857 !using_synchronous_compositor) {
2858 settings.use_rgba_4444 = viz::RGBA_4444;
2859
2860 // If we are going to unpremultiply and dither these tiles, we need to
2861 // allocate an additional RGBA_8888 intermediate for each tile
2862 // rasterization when rastering to RGBA_4444 to allow for dithering.
2863 // Setting a reasonable sized max tile size allows this intermediate to
2864 // be consistently reused.
2865 if (base::FeatureList::IsEnabled(
2866 kUnpremultiplyAndDitherLowBitDepthTiles)) {
2867 settings.max_gpu_raster_tile_size = gfx::Size(512, 256);
2868 settings.unpremultiply_and_dither_low_bit_depth_tiles = true;
2869 }
2870 }
2871 }
2872
2873 if (cmd.HasSwitch(switches::kEnableLowResTiling))
2874 settings.create_low_res_tiling = true;
2875 if (cmd.HasSwitch(switches::kDisableLowResTiling))
2876 settings.create_low_res_tiling = false;
2877
2878 if (cmd.HasSwitch(switches::kEnableRGBA4444Textures) &&
2879 !cmd.HasSwitch(switches::kDisableRGBA4444Textures)) {
2880 settings.use_rgba_4444 = true;
2881 }
2882
2883 settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB
2884 // Use 1/4th of staging buffers on low-end devices.
2885 if (base::SysInfo::IsLowEndDevice())
2886 settings.max_staging_buffer_usage_in_bytes /= 4;
2887
2888 cc::ManagedMemoryPolicy defaults = settings.memory_policy;
2889 settings.memory_policy = GetGpuMemoryPolicy(defaults, initial_screen_size,
2890 initial_device_scale_factor);
2891
2892 settings.disallow_non_exact_resource_reuse =
2893 cmd.HasSwitch(switches::kDisallowNonExactResourceReuse);
2894#if defined(OS_ANDROID)
2895 // TODO(crbug.com/746931): This feature appears to be causing visual
2896 // corruption on certain android devices. Will investigate and re-enable.
2897 settings.disallow_non_exact_resource_reuse = true;
2898#endif
2899
2900 if (cmd.HasSwitch(switches::kRunAllCompositorStagesBeforeDraw)) {
2901 settings.wait_for_all_pipeline_stages_before_draw = true;
2902 settings.enable_latency_recovery = false;
2903 }
2904
2905 settings.enable_image_animation_resync =
2906 !cmd.HasSwitch(switches::kDisableImageAnimationResync);
2907
Karolina Soltys4d60b402018-10-01 19:28:202908 settings.send_compositor_frame_ack = false;
2909
danakj4b347212018-07-04 17:55:172910 return settings;
2911}
2912
2913// static
2914cc::ManagedMemoryPolicy RenderWidget::GetGpuMemoryPolicy(
2915 const cc::ManagedMemoryPolicy& default_policy,
2916 const gfx::Size& initial_screen_size,
2917 float initial_device_scale_factor) {
2918 cc::ManagedMemoryPolicy actual = default_policy;
2919 actual.bytes_limit_when_visible = 0;
2920
2921 // If the value was overridden on the command line, use the specified value.
2922 static bool client_hard_limit_bytes_overridden =
2923 base::CommandLine::ForCurrentProcess()->HasSwitch(
2924 switches::kForceGpuMemAvailableMb);
2925 if (client_hard_limit_bytes_overridden) {
2926 if (base::StringToSizeT(
2927 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
2928 switches::kForceGpuMemAvailableMb),
2929 &actual.bytes_limit_when_visible))
2930 actual.bytes_limit_when_visible *= 1024 * 1024;
2931 return actual;
2932 }
2933
2934#if defined(OS_ANDROID)
2935 // We can't query available GPU memory from the system on Android.
2936 // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports
2937 // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports
2938 // 128MB java heap size). First we estimate physical memory using both.
2939 size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB();
2940 size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
2941 size_t physical_memory_mb = 0;
2942 if (base::SysInfo::IsLowEndDevice()) {
2943 // TODO(crbug.com/742534): The code below appears to no longer work.
2944 // |dalvik_mb| no longer follows the expected heuristic pattern, causing us
2945 // to over-estimate memory on low-end devices. This entire section probably
2946 // needs to be re-written, but for now we can address the low-end Android
2947 // issues by ignoring |dalvik_mb|.
2948 physical_memory_mb = physical_mb;
2949 } else if (dalvik_mb >= 256) {
2950 physical_memory_mb = dalvik_mb * 4;
2951 } else {
2952 physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3);
2953 }
2954
2955 // Now we take a default of 1/8th of memory on high-memory devices,
2956 // and gradually scale that back for low-memory devices (to be nicer
2957 // to other apps so they don't get killed). Examples:
2958 // Nexus 4/10(2GB) 256MB (normally 128MB)
2959 // Droid Razr M(1GB) 114MB (normally 57MB)
2960 // Galaxy Nexus(1GB) 100MB (normally 50MB)
2961 // Xoom(1GB) 100MB (normally 50MB)
2962 // Nexus S(low-end) 8MB (normally 8MB)
2963 // Note that the compositor now uses only some of this memory for
2964 // pre-painting and uses the rest only for 'emergencies'.
2965 if (actual.bytes_limit_when_visible == 0) {
2966 // NOTE: Non-low-end devices use only 50% of these limits,
2967 // except during 'emergencies' where 100% can be used.
2968 if (physical_memory_mb >= 1536)
2969 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB
2970 else if (physical_memory_mb >= 1152)
2971 actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB
2972 else if (physical_memory_mb >= 768)
2973 actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB
2974 else if (physical_memory_mb >= 513)
2975 actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB
2976 else
2977 // Devices with this little RAM have very little headroom so we hardcode
2978 // the limit rather than relying on the heuristics above. (They also use
2979 // 4444 textures so we can use a lower limit.)
2980 actual.bytes_limit_when_visible = 8;
2981
2982 actual.bytes_limit_when_visible =
2983 actual.bytes_limit_when_visible * 1024 * 1024;
2984 // Clamp the observed value to a specific range on Android.
2985 actual.bytes_limit_when_visible = std::max(
2986 actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024));
2987 actual.bytes_limit_when_visible =
2988 std::min(actual.bytes_limit_when_visible,
2989 static_cast<size_t>(256 * 1024 * 1024));
2990 }
2991 actual.priority_cutoff_when_visible =
2992 gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
2993#else
2994 // Ignore what the system said and give all clients the same maximum
2995 // allocation on desktop platforms.
2996 actual.bytes_limit_when_visible = 512 * 1024 * 1024;
2997 actual.priority_cutoff_when_visible =
2998 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
2999
3000 // For large monitors (4k), double the tile memory to avoid frequent out of
3001 // memory problems. 4k could mean a screen width of anywhere from 3840 to 4096
3002 // (see https://en.wikipedia.org/wiki/4K_resolution). We use 3500 as a proxy
3003 // for "large enough".
3004 static const int kLargeDisplayThreshold = 3500;
3005 int display_width =
3006 std::round(initial_screen_size.width() * initial_device_scale_factor);
3007 if (display_width >= kLargeDisplayThreshold)
3008 actual.bytes_limit_when_visible *= 2;
3009#endif
3010 return actual;
3011}
3012
Navid Zolghadr8fdb6114e2018-08-29 19:00:543013void RenderWidget::HasPointerRawMoveEventHandlers(bool has_handlers) {
3014 if (input_event_queue_)
3015 input_event_queue_->HasPointerRawMoveEventHandlers(has_handlers);
3016}
3017
Blink Reformat1c4d759e2017-04-09 16:34:543018void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
W. James MacLean662d5382018-03-29 18:33:083019 if (has_touch_handlers_ && *has_touch_handlers_ == has_handlers)
3020 return;
3021
3022 has_touch_handlers_ = has_handlers;
alexclarke7fa93942015-10-21 15:37:113023 if (render_widget_scheduling_state_)
3024 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
Albert J. Wongeb28e7e2018-10-12 00:57:433025 Send(new WidgetHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
[email protected]ce6689f2013-03-29 12:52:553026}
3027
Dave Tapuskadfe486c12017-06-09 16:53:133028void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
3029 if (input_event_queue_)
3030 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
3031}
3032
W. James MacLeand973a55b2018-11-29 21:39:133033void RenderWidget::AnimateDoubleTapZoomInMainFrame(
3034 const blink::WebPoint& point,
3035 const blink::WebRect& rect_to_zoom) {
3036 // Only oopif subframes should be sending this message.
Albert J. Wong7bbf22d2018-12-20 00:27:273037 DCHECK(!delegate());
W. James MacLeand973a55b2018-11-29 21:39:133038 Send(new WidgetHostMsg_AnimateDoubleTapZoomInMainFrame(routing_id(), point,
3039 rect_to_zoom));
3040}
3041
W. James MacLean5372eb72018-12-19 12:56:363042void RenderWidget::ZoomToFindInPageRectInMainFrame(
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 MacLean5372eb72018-12-19 12:56:363046 Send(new WidgetHostMsg_ZoomToFindInPageRectInMainFrame(routing_id(),
3047 rect_to_zoom));
3048}
3049
Dave Tapuskabafc2ba32017-11-28 01:54:373050void RenderWidget::RequestUnbufferedInputEvents() {
3051 if (input_event_queue_)
3052 input_event_queue_->RequestUnbufferedInputEvents();
3053}
3054
xidachenfa0199e72017-05-11 11:34:263055void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:263056 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:513057 return;
3058
Dave Tapuska04bc5ee92018-04-17 19:03:313059 widget_input_handler_manager_->ProcessTouchAction(touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:513060}
3061
[email protected]e3244ed2014-06-20 20:04:273062void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
3063 render_frame_proxies_.AddObserver(proxy);
W. James MacLean2a90bff2018-11-05 20:52:473064 // During initial page load, the main frame may have received page
3065 // scale factor information before the sub-frame proxies were registered, so
3066 // make sure we pass the page scale factor along here.
3067 proxy->OnPageScaleFactorChanged(page_scale_factor_from_mainframe_);
[email protected]bffc8302014-01-23 20:52:163068}
3069
[email protected]e3244ed2014-06-20 20:04:273070void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
3071 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:163072}
3073
[email protected]de3c5d82014-05-28 22:12:593074void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
3075 render_frames_.AddObserver(frame);
3076}
3077
3078void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
3079 render_frames_.RemoveObserver(frame);
3080}
3081
Saman Samid189e5dfd2017-12-20 22:55:313082void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
3083 browser_plugins_.AddObserver(browser_plugin);
Saman Sami50d1e0c2018-03-13 20:03:493084 browser_plugin->ScreenInfoChanged(GetOriginalScreenInfo());
Saman Samid189e5dfd2017-12-20 22:55:313085}
3086
3087void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
3088 browser_plugins_.RemoveObserver(browser_plugin);
3089}
3090
Albert J. Wong3c93c182018-09-27 17:29:433091void RenderWidget::OnWaitNextFrameForTests(
3092 int main_frame_thread_observer_routing_id) {
danakj53802692018-07-25 21:46:443093 // Sends an ACK to the browser process during the next compositor frame.
Albert J. Wong3c93c182018-09-27 17:29:433094 QueueMessage(new WidgetHostMsg_WaitForNextFrameForTests_ACK(
3095 main_frame_thread_observer_routing_id));
lfg43e08e62016-02-03 18:51:373096}
3097
Fady Samuela863f152018-03-09 16:10:033098const ScreenInfo& RenderWidget::GetWebScreenInfo() const {
3099 return screen_info_;
Christopher Camerone9a30c12018-03-07 08:23:383100}
3101
Fady Samuela863f152018-03-09 16:10:033102const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const {
Christopher Camerone9a30c12018-03-07 08:23:383103 return screen_metrics_emulator_
3104 ? screen_metrics_emulator_->original_screen_info()
Fady Samuela863f152018-03-09 16:10:033105 : screen_info_;
oshima50872a72016-03-04 13:26:183106}
3107
Ella Ge80a52dce2017-11-15 18:01:523108gfx::PointF RenderWidget::ConvertWindowPointToViewport(
3109 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:593110 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:543111 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:523112 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
3113}
3114
3115gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
3116 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:593117}
3118
Blink Reformat1c4d759e2017-04-09 16:34:543119bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:213120 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
3121}
3122
Blink Reformat1c4d759e2017-04-09 16:34:543123void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:213124 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
3125}
3126
Blink Reformat1c4d759e2017-04-09 16:34:543127bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:213128 return mouse_lock_dispatcher_->IsMouseLockedTo(
3129 webwidget_mouse_lock_target_.get());
3130}
3131
Richard Li49fe04d2018-10-21 09:07:193132void RenderWidget::StartDragging(network::mojom::ReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:583133 const WebDragData& data,
3134 WebDragOperationsMask mask,
danakj0c75ad82018-07-10 19:50:123135 const SkBitmap& drag_image,
danakjef1735a2018-11-13 19:34:443136 const gfx::Point& web_image_offset) {
3137 blink::WebRect offset_in_window(web_image_offset.x(), web_image_offset.y(), 0,
3138 0);
Blink Reformat1c4d759e2017-04-09 16:34:543139 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:583140 DropData drop_data(DropDataBuilder::Build(data));
3141 drop_data.referrer_policy = policy;
danakj0c75ad82018-07-10 19:50:123142 gfx::Vector2d image_offset(offset_in_window.x, offset_in_window.y);
3143 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, drag_image,
3144 image_offset, possible_drag_event_info_));
paulmeyer6ef5a792016-11-08 20:33:583145}
3146
kenrb5d78b842017-03-06 21:06:013147uint32_t RenderWidget::GetContentSourceId() {
3148 return current_content_source_id_;
3149}
3150
Saman Samif7731342018-01-24 22:18:443151void RenderWidget::DidNavigate() {
Saman Sami26a1fcd2018-04-10 17:12:213152 ++current_content_source_id_;
danakja6c10012018-07-06 14:25:363153 if (!layer_tree_view_)
Saman Samif7731342018-01-24 22:18:443154 return;
danakja6c10012018-07-06 14:25:363155 layer_tree_view_->SetContentSourceId(current_content_source_id_);
3156 layer_tree_view_->ClearCachesOnNextCommit();
kenrb5d78b842017-03-06 21:06:013157}
3158
lfg8ff33912016-09-13 20:59:213159blink::WebWidget* RenderWidget::GetWebWidget() const {
Albert J. Wong7bbf22d2018-12-20 00:27:273160 if (delegate()) {
3161 blink::WebWidget* delegate_widget = delegate()->GetWebWidgetForWidget();
danakja2c9d0a92018-07-25 20:01:183162 if (delegate_widget)
3163 return delegate_widget;
3164 }
lfg8ff33912016-09-13 20:59:213165 return webwidget_internal_;
3166}
3167
ekaramad2daaf672016-11-10 20:29:013168blink::WebInputMethodController* RenderWidget::GetInputMethodController()
3169 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:383170 if (auto* frame_widget = GetFrameWidget())
3171 return frame_widget->GetActiveWebInputMethodController();
3172
3173 return nullptr;
ekaramad2daaf672016-11-10 20:29:013174}
3175
Dave Tapuska139a72f2017-09-06 21:57:033176void RenderWidget::SetupWidgetInputHandler(
3177 mojom::WidgetInputHandlerRequest request,
3178 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:473179 widget_input_handler_manager_->AddInterface(std::move(request),
3180 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:503181}
3182
Dave Tapuska485aca92017-08-08 00:47:583183void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
3184 // Close the old binding if there was one.
3185 // A RenderWidgetHost should not need more than one channel.
3186 widget_binding_.Close();
3187 widget_binding_.Bind(std::move(request));
3188}
3189
Ken Buchanan94c0beb62018-06-22 19:56:243190void RenderWidget::SetMouseCapture(bool capture) {
3191 if (mojom::WidgetInputHandlerHost* host =
3192 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
3193 host->SetMouseCapture(capture);
3194 }
3195}
3196
danakj53802692018-07-25 21:46:443197void RenderWidget::SetWindowScreenRect(const gfx::Rect& window_screen_rect) {
3198 if (screen_metrics_emulator_)
3199 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
3200 else
3201 window_screen_rect_ = window_screen_rect;
3202}
3203
Fady Samuelca9ecb72018-05-05 05:59:273204bool RenderWidget::IsSurfaceSynchronizationEnabled() const {
danakja6c10012018-07-06 14:25:363205 return layer_tree_view_ &&
3206 layer_tree_view_->IsSurfaceSynchronizationEnabled();
Fady Samuelca9ecb72018-05-05 05:59:273207}
3208
W. James MacLean2a90bff2018-11-05 20:52:473209void RenderWidget::PageScaleFactorChanged(float page_scale_factor) {
3210 // Only the main frame pulls page scale information from the layer tree host.
3211 // Pages scale is shared with non-mainframe widgets via the IPC for
3212 // OnSynchronizeVisualProperties.
Albert J. Wong7bbf22d2018-12-20 00:27:273213 if (!delegate())
W. James MacLean2a90bff2018-11-05 20:52:473214 return;
3215
3216 page_scale_factor_from_mainframe_ = page_scale_factor;
3217 for (auto& observer : render_frame_proxies_)
3218 observer.OnPageScaleFactorChanged(page_scale_factor);
3219}
3220
danakj53802692018-07-25 21:46:443221void RenderWidget::UseSynchronousResizeModeForTesting(bool enable) {
3222 resizing_mode_selector_->set_is_synchronous_mode(enable);
danakja2c9d0a92018-07-25 20:01:183223}
3224
3225void RenderWidget::SetDeviceScaleFactorForTesting(float factor) {
3226 device_scale_factor_for_testing_ = factor;
3227
3228 VisualProperties visual_properties;
3229 visual_properties.screen_info = screen_info_;
3230 visual_properties.screen_info.device_scale_factor = factor;
3231 visual_properties.new_size = size();
3232 visual_properties.visible_viewport_size = visible_viewport_size_;
3233 visual_properties.compositor_viewport_pixel_size =
3234 gfx::ScaleToCeiledSize(size(), factor);
3235 visual_properties.browser_controls_shrink_blink_size = false;
3236 visual_properties.top_controls_height = 0.f;
3237 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3238 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:173239 visual_properties.local_surface_id_allocation =
3240 local_surface_id_allocation_from_parent_;
W. James MacLean2a90bff2018-11-05 20:52:473241 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183242 // We are changing the device scale factor from the renderer, so allocate a
3243 // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
3244 if (layer_tree_view_)
3245 layer_tree_view_->RequestNewLocalSurfaceId();
3246
3247 OnSynchronizeVisualProperties(visual_properties);
3248}
3249
3250void RenderWidget::SetDeviceColorSpaceForTesting(
3251 const gfx::ColorSpace& color_space) {
3252 VisualProperties visual_properties;
3253 visual_properties.screen_info = screen_info_;
3254 visual_properties.screen_info.color_space = color_space;
3255 visual_properties.new_size = size();
3256 visual_properties.visible_viewport_size = visible_viewport_size_;
3257 visual_properties.compositor_viewport_pixel_size =
3258 compositor_viewport_pixel_size_;
3259 visual_properties.browser_controls_shrink_blink_size = false;
3260 visual_properties.top_controls_height = 0.f;
3261 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3262 visual_properties.display_mode = display_mode_;
Fady Samuel84d8a1f72018-11-08 00:26:173263 visual_properties.local_surface_id_allocation =
3264 local_surface_id_allocation_from_parent_;
W. James MacLean2a90bff2018-11-05 20:52:473265 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183266 // We are changing the device color space from the renderer, so allocate a
3267 // new viz::LocalSurfaceId to avoid surface invariants violations in tests.
3268 if (layer_tree_view_)
3269 layer_tree_view_->RequestNewLocalSurfaceId();
3270 OnSynchronizeVisualProperties(visual_properties);
3271}
3272
3273void RenderWidget::SetWindowRectSynchronouslyForTesting(
3274 const gfx::Rect& new_window_rect) {
3275 SetWindowRectSynchronously(new_window_rect);
3276}
3277
3278void RenderWidget::EnableAutoResizeForTesting(const gfx::Size& min_size,
3279 const gfx::Size& max_size) {
3280 VisualProperties visual_properties;
3281 visual_properties.auto_resize_enabled = true;
3282 visual_properties.min_size_for_auto_resize = min_size;
3283 visual_properties.max_size_for_auto_resize = max_size;
Fady Samuel84d8a1f72018-11-08 00:26:173284 visual_properties.local_surface_id_allocation =
3285 base::Optional<viz::LocalSurfaceIdAllocation>(
3286 viz::LocalSurfaceIdAllocation(
3287 viz::LocalSurfaceId(1, 1, base::UnguessableToken::Create()),
3288 base::TimeTicks::Now()));
W. James MacLean2a90bff2018-11-05 20:52:473289 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183290 OnSynchronizeVisualProperties(visual_properties);
3291}
3292
3293void RenderWidget::DisableAutoResizeForTesting(const gfx::Size& new_size) {
3294 if (!auto_resize_mode_)
3295 return;
3296
3297 VisualProperties visual_properties;
3298 visual_properties.auto_resize_enabled = false;
3299 visual_properties.screen_info = screen_info_;
3300 visual_properties.new_size = new_size;
3301 visual_properties.compositor_viewport_pixel_size =
3302 compositor_viewport_pixel_size_;
3303 visual_properties.browser_controls_shrink_blink_size =
3304 browser_controls_shrink_blink_size_;
3305 visual_properties.top_controls_height = top_controls_height_;
3306 visual_properties.visible_viewport_size = visible_viewport_size_;
3307 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
3308 visual_properties.display_mode = display_mode_;
W. James MacLean2a90bff2018-11-05 20:52:473309 visual_properties.page_scale_factor = page_scale_factor_from_mainframe_;
danakja2c9d0a92018-07-25 20:01:183310 OnSynchronizeVisualProperties(visual_properties);
3311}
3312
EhsanK955ba582017-11-30 21:14:403313blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:383314 if (auto* frame_widget = GetFrameWidget())
3315 return frame_widget->FocusedWebLocalFrameInWidget();
3316 return nullptr;
EhsanK955ba582017-11-30 21:14:403317}
3318
EhsanK22d482e2017-08-10 17:29:493319#if BUILDFLAG(ENABLE_PLUGINS)
3320PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:383321 blink::WebFrameWidget* frame_widget = GetFrameWidget();
3322 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:493323 return nullptr;
3324
3325 // Focused pepper instance might not always be in the focused frame. For
3326 // instance if a pepper instance and its embedder frame are focused an then
3327 // another frame takes focus using javascript, the embedder frame will no
3328 // longer be focused while the pepper instance is (the embedder frame's
3329 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
3330 // is fullscreen, clicking into the pepper will not refocus the embedder
3331 // frame. This is why we have to traverse the whole frame tree to find the
3332 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:383333 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:493334 while (current_frame) {
3335 RenderFrameImpl* render_frame =
3336 current_frame->IsWebLocalFrame()
3337 ? RenderFrameImpl::FromWebFrame(current_frame)
3338 : nullptr;
3339 if (render_frame && render_frame->focused_pepper_plugin())
3340 return render_frame->focused_pepper_plugin();
3341 current_frame = current_frame->TraverseNext();
3342 }
3343 return nullptr;
3344}
3345#endif
3346
Ken Buchananb2c9e262018-03-10 16:53:313347gfx::Rect RenderWidget::ViewportVisibleRect() {
danakj6dcbc5962018-11-16 16:45:423348 return for_child_local_root_frame_
3349 ? compositor_visible_rect_
3350 : gfx::Rect(compositor_viewport_pixel_size_);
Ken Buchananb2c9e262018-03-10 16:53:313351}
3352
Hajime Hoshi315a61f2018-08-14 17:27:283353// static
3354scoped_refptr<base::SingleThreadTaskRunner>
3355RenderWidget::GetCleanupTaskRunner() {
3356 return RenderThreadImpl::current_blink_platform_impl()
3357 ->main_thread_scheduler()
3358 ->CleanupTaskRunner();
3359}
3360
Saman Sami50d1e0c2018-03-13 20:03:493361base::WeakPtr<RenderWidget> RenderWidget::AsWeakPtr() {
3362 return weak_ptr_factory_.GetWeakPtr();
3363}
3364
[email protected]e9ff79c2012-10-19 21:31:263365} // namespace content