blob: a985c6e962a8e2fa47be5663c3e4734703b81394 [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
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4319#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
fdoraya19b7702016-12-23 14:19:3123#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0124#include "base/trace_event/trace_event.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0326#include "cc/animation/animation_host.h"
xidachenfa0199e72017-05-11 11:34:2627#include "cc/input/touch_action.h"
danakjba65a0912017-09-21 16:38:4228#include "cc/trees/layer_tree_frame_sink.h"
loyso6e6efc42017-01-21 02:23:0329#include "cc/trees/layer_tree_host.h"
Fady Samuelc645ffe2017-07-24 17:28:2030#include "components/viz/common/frame_sinks/begin_frame_source.h"
danakjf20f4502017-09-26 17:13:3131#include "components/viz/common/frame_sinks/copy_output_request.h"
paulmeyer6ef5a792016-11-08 20:33:5832#include "content/common/drag_event_source_info.h"
33#include "content/common/drag_messages.h"
[email protected]c084330e02013-04-27 01:08:1534#include "content/common/input_messages.h"
jonrossa2ff4f82018-02-16 17:27:4635#include "content/common/render_frame_metadata.mojom.h"
jcivelliae1560a2016-11-01 22:40:2336#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4237#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3838#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5039#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1840#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1241#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2942#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4243#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5944#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5045#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3946#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1847#include "content/public/renderer/content_renderer_client.h"
Saman Samid189e5dfd2017-12-20 22:55:3148#include "content/renderer/browser_plugin/browser_plugin.h"
[email protected]953bd0062013-08-01 00:58:4049#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3950#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5851#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5152#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1153#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1154#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2855#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2956#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1357#include "content/renderer/input/input_handler_manager.h"
dtapuska9ec1a912017-04-21 15:18:3158#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2659#include "content/renderer/input/widget_input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3260#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1661#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2762#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0563#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4464#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5565#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4466#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0967#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0468#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4769#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1870#include "ipc/ipc_sync_message.h"
Antoine Laboure55c9ef82017-11-10 18:51:2371#include "ipc/ipc_sync_message_filter.h"
brettw4b461082016-11-19 18:55:1672#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4873#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2574#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1875#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5976#include "third_party/WebKit/public/platform/WebDragData.h"
77#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5578#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1179#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3080#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3081#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3082#include "third_party/WebKit/public/platform/WebSize.h"
83#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5184#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
85#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2986#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4387#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5988#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0189#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5990#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1191#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3193#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
94#include "third_party/WebKit/public/web/WebRange.h"
Mitsuru Oshima3c07b332018-02-06 04:56:5095#include "third_party/WebKit/public/web/WebSettings.h"
Donn Denman3c1267c62018-03-08 22:08:5996#include "third_party/WebKit/public/web/WebTappedInfo.h"
kenrba7199832015-01-22 23:44:5997#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0898#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4199#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:59100#include "ui/base/clipboard/clipboard.h"
Scott Violet8ff9c302018-02-22 22:28:35101#include "ui/base/ui_base_features.h"
dtapuska97286c882017-02-24 23:14:43102#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50103#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09104#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32105#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48106#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27107#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41108#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48109
[email protected]eeb93112013-05-01 19:41:10110#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15111#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24112#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10113#endif
114
[email protected]661eb9d2009-02-03 02:11:48115#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52116#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41117#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48118#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44119
sadrul943e3b32016-08-04 18:22:59120#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10121#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19122#endif
123
ekaramad330ba4232016-09-23 17:57:47124#if defined(OS_MACOSX)
125#include "content/renderer/text_input_client_observer.h"
126#endif
127
Ryan Landay9e42fd742017-08-12 01:59:11128using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46129using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43130using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59131using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58132using blink::WebDragOperationsMask;
133using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59134using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46135using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58136using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46137using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49138using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01139using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58140using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46141using blink::WebMouseEvent;
142using blink::WebMouseWheelEvent;
143using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11144using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46145using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11146using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46147using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48148using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46149using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46150using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59151using blink::WebString;
Donn Denman3c1267c62018-03-08 22:08:59152using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46153using blink::WebTextDirection;
154using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25155using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46156using blink::WebVector;
157using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26158
paulmeyer90f6c31d2016-11-12 00:17:59159namespace content {
160
[email protected]6a4d7f62013-01-07 21:32:13161namespace {
[email protected]b256eca2013-07-11 10:57:40162
163typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
164
AJITH KUMAR V041c0b02017-08-08 10:39:20165static const int kInvalidNextPreviousFlagsValue = -1;
166
lfgbee1e0a2016-06-08 21:24:21167class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
168 public:
169 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
170 : webwidget_(webwidget) {}
171
172 void OnLockMouseACK(bool succeeded) override {
173 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54174 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21175 else
Blink Reformat1c4d759e2017-04-09 16:34:54176 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21177 }
178
Blink Reformat1c4d759e2017-04-09 16:34:54179 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21180
181 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
182 // The WebWidget handles mouse lock in Blink's handleInputEvent().
183 return false;
184 }
185
186 private:
187 blink::WebWidget* webwidget_;
188};
189
dglazkov97b6c2b2016-10-25 17:35:55190bool IsDateTimeInput(ui::TextInputType type) {
191 return type == ui::TEXT_INPUT_TYPE_DATE ||
192 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
193 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
194 type == ui::TEXT_INPUT_TYPE_MONTH ||
195 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
196}
197
paulmeyer90f6c31d2016-11-12 00:17:59198WebDragData DropMetaDataToWebDragData(
199 const std::vector<DropData::Metadata>& drop_meta_data) {
200 std::vector<WebDragData::Item> item_list;
201 for (const auto& meta_data_item : drop_meta_data) {
202 if (meta_data_item.kind == DropData::Kind::STRING) {
203 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54204 item.storage_type = WebDragData::Item::kStorageTypeString;
205 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59206 // Have to pass a dummy URL here instead of an empty URL because the
207 // DropData received by browser_plugins goes through a round trip:
208 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
209 // will contain an empty URL (which means no URL is dragged) if the URL in
210 // WebDragData is empty.
211 if (base::EqualsASCII(meta_data_item.mime_type,
212 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54213 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59214 }
215 item_list.push_back(item);
216 continue;
217 }
218
219 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
220 // just the mimetype. This is needed to drag files to WebView on Android
221 // platform.
222 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
223 !meta_data_item.filename.empty()) {
224 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54225 item.storage_type = WebDragData::Item::kStorageTypeFilename;
226 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59227 item_list.push_back(item);
228 continue;
229 }
230
231 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
232 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54233 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
234 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59235 item_list.push_back(item);
236 continue;
237 }
238 }
239
240 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54241 result.Initialize();
242 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59243 return result;
244}
245
246WebDragData DropDataToWebDragData(const DropData& drop_data) {
247 std::vector<WebDragData::Item> item_list;
248
249 // These fields are currently unused when dragging into WebKit.
250 DCHECK(drop_data.download_metadata.empty());
251 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23252 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59253
254 if (!drop_data.text.is_null()) {
255 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54256 item.storage_type = WebDragData::Item::kStorageTypeString;
257 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
258 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59259 item_list.push_back(item);
260 }
261
262 if (!drop_data.url.is_empty()) {
263 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54264 item.storage_type = WebDragData::Item::kStorageTypeString;
265 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
266 item.string_data = WebString::FromUTF8(drop_data.url.spec());
267 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59268 item_list.push_back(item);
269 }
270
271 if (!drop_data.html.is_null()) {
272 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54273 item.storage_type = WebDragData::Item::kStorageTypeString;
274 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
275 item.string_data = WebString::FromUTF16(drop_data.html.string());
276 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59277 item_list.push_back(item);
278 }
279
280 for (std::vector<ui::FileInfo>::const_iterator it =
281 drop_data.filenames.begin();
282 it != drop_data.filenames.end();
283 ++it) {
284 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54285 item.storage_type = WebDragData::Item::kStorageTypeFilename;
286 item.filename_data = blink::FilePathToWebString(it->path);
287 item.display_name_data =
kinukoa4293022017-01-27 06:43:25288 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59289 item_list.push_back(item);
290 }
291
292 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
293 drop_data.file_system_files.begin();
294 it != drop_data.file_system_files.end();
295 ++it) {
296 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54297 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
298 item.file_system_url = it->url;
299 item.file_system_file_size = it->size;
300 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59301 item_list.push_back(item);
302 }
303
Stuart Langley48300392017-11-02 03:54:44304 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59305 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54306 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44307 item.string_type = WebString::FromUTF16(it.first);
308 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59309 item_list.push_back(item);
310 }
311
312 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54313 result.Initialize();
314 result.SetItems(item_list);
315 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59316 return result;
317}
318
lfg1568d112016-08-30 16:06:29319content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
320 nullptr;
321
322content::RenderWidget::RenderWidgetInitializedCallback
323 g_render_widget_initialized = nullptr;
324
dtapuskac4dd5be2016-10-25 15:11:10325ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
326 // Check the type is in the range representable by ui::TextInputType.
327 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
328 << "blink::WebTextInputType and ui::TextInputType not synchronized";
329 return static_cast<ui::TextInputType>(type);
330}
331
332ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
333 // Check the mode is in the range representable by ui::TextInputMode.
334 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
335 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
336 return static_cast<ui::TextInputMode>(mode);
337}
338
Mitsuru Oshima3c07b332018-02-06 04:56:50339// Returns true if the device scale is high enough that losing subpixel
340// antialiasing won't have a noticeable effect on text quality.
341static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
342#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
343 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
344 // composite all scrollers so that we get animated overlay scrollbars.
345 return true;
346#else
347 // 1.5 is a common touchscreen tablet device scale factor. For such
348 // devices main thread antialiasing is a heavy burden.
349 return device_scale_factor >= 1.5f;
350#endif
351}
352
353static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
354 float device_scale_factor) {
355 const base::CommandLine& command_line =
356 *base::CommandLine::ForCurrentProcess();
357 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
358 return false;
359 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
360 return true;
361 if (!compositor_deps->IsLcdTextEnabled())
362 return true;
363 return DeviceScaleEnsuresTextQuality(device_scale_factor);
364}
365
[email protected]b256eca2013-07-11 10:57:40366} // namespace
367
[email protected]b2e4c70132013-10-03 02:07:51368// RenderWidget ---------------------------------------------------------------
369
Hajime Hoshiabb3c8f2017-12-04 18:41:39370RenderWidget::RenderWidget(
371 int32_t widget_routing_id,
372 CompositorDependencies* compositor_deps,
373 blink::WebPopupType popup_type,
374 const ScreenInfo& screen_info,
375 bool swapped_out,
376 bool hidden,
377 bool never_visible,
378 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
379 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45380 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36381 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21382 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44383 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29384 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51385 auto_resize_mode_(false),
Fady Samueld10aadd82017-11-03 18:23:57386 need_resize_ack_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29387 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04388 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39389 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12390 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54391 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16392 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48393 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22394 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44395 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20396 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55397 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40398 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20399 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20400 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53401 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18402 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12403 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48404 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04405 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),
wjmaclean1d970622017-01-21 22:28:24411 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09412 has_focus_(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)),
Hajime Hoshiabb3c8f2017-12-04 18:41:39420 task_runner_(task_runner),
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]8b3f0eb2012-05-03 19:15:05423 if (!swapped_out)
424 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27425 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11426
427 // In tests there may not be a RenderThreadImpl.
428 if (RenderThreadImpl::current()) {
429 render_widget_scheduling_state_ = RenderThreadImpl::current()
430 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32431 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11432 render_widget_scheduling_state_->SetHidden(is_hidden_);
433 }
sadrul602ce1362017-01-26 06:41:10434#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14435 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Scott Violet8ff9c302018-02-22 22:28:35436 if (features::IsMusEnabled())
Scott Violet1098538e2017-10-05 19:23:33437 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10438#endif
initial.commit09911bf2008-07-26 23:55:29439}
440
441RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21442 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16443
dtapuska9ec1a912017-04-21 15:18:31444 if (input_event_queue_)
445 input_event_queue_->ClearClient();
446
[email protected]992db4c2011-05-12 15:37:15447 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02448 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15449 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11450#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14451 // It is possible for a RenderWidget to be destroyed before it was embedded
452 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
453 // explicitly delete it here.
454 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11455#endif
initial.commit09911bf2008-07-26 23:55:29456}
457
[email protected]484955942010-08-19 16:13:18458// static
lfg1568d112016-08-30 16:06:29459void RenderWidget::InstallCreateHook(
460 CreateRenderWidgetFunction create_render_widget,
461 RenderWidgetInitializedCallback render_widget_initialized) {
462 CHECK(!g_create_render_widget && !g_render_widget_initialized);
463 g_create_render_widget = create_render_widget;
464 g_render_widget_initialized = render_widget_initialized;
465}
466
467// static
nickf7b38222016-11-22 21:59:35468RenderWidget* RenderWidget::CreateForPopup(
469 RenderViewImpl* opener,
470 CompositorDependencies* compositor_deps,
471 blink::WebPopupType popup_type,
Hajime Hoshiabb3c8f2017-12-04 18:41:39472 const ScreenInfo& screen_info,
473 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Dave Tapuska1bdf1832017-07-07 18:07:19474 mojom::WidgetPtr widget_channel;
475 mojom::WidgetRequest widget_channel_request =
476 mojo::MakeRequest(&widget_channel);
477
nick4df698d82016-11-11 20:39:23478 // Do a synchronous IPC to obtain a routing ID.
479 int32_t routing_id = MSG_ROUTING_NONE;
480 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19481 opener->GetRoutingID(), popup_type, std::move(widget_channel),
482 &routing_id)) {
nick4df698d82016-11-11 20:39:23483 return nullptr;
484 }
485
Hajime Hoshiabb3c8f2017-12-04 18:41:39486 scoped_refptr<RenderWidget> widget(new RenderWidget(
487 routing_id, compositor_deps, popup_type, screen_info, false, false, false,
488 task_runner, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35489 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24490 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35491 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23492 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
493 return widget.get();
initial.commit09911bf2008-07-26 23:55:29494}
495
[email protected]484955942010-08-19 16:13:18496// static
kenrba7199832015-01-22 23:44:59497RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23498 int widget_routing_id,
kenrba7199832015-01-22 23:44:59499 bool hidden,
ccameron2f451532016-09-07 21:49:27500 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59501 CompositorDependencies* compositor_deps,
502 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23503 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55504 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
505 // same routing ID for both the view routing ID and the main frame widget
506 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23507 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55508 if (view) {
avi8a45c1092016-03-01 16:12:34509 view->AttachWebFrameWidget(
510 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
Lucas Furukawa Gadani6ccadf72018-02-13 10:29:10511 view->GetWidget()->UpdateWebViewWithDeviceScaleFactor();
avi8a45c1092016-03-01 16:12:34512 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55513 }
Hajime Hoshiabb3c8f2017-12-04 18:41:39514 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
515 frame->GetTaskRunner(blink::TaskType::kUnthrottled);
dcheng35d31c112015-07-22 00:17:36516 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29517 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45518 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54519 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45520 hidden, false)
521 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54522 blink::kWebPopupTypeNone, screen_info, false,
Hajime Hoshiabb3c8f2017-12-04 18:41:39523 hidden, false, task_runner));
simonhong628f9812015-04-27 23:13:20524 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23525 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59526 // this function returns.
nickf7b38222016-11-22 21:59:35527 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23528 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
Lucas Furukawa Gadani6ccadf72018-02-13 10:29:10529 widget->UpdateWebViewWithDeviceScaleFactor();
nick4df698d82016-11-11 20:39:23530
531 if (g_render_widget_initialized)
532 g_render_widget_initialized(widget.get());
533 return widget.get();
kenrba7199832015-01-22 23:44:59534}
535
536// static
lfgcaab5142016-02-26 19:06:52537blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08538 RenderWidget* render_widget,
539 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54540 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08541}
542
543// static
kenrba7199832015-01-22 23:44:59544blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18545 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54546 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18547 break;
Blink Reformat1c4d759e2017-04-09 16:34:54548 case blink::kWebPopupTypePage:
549 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18550 default:
551 NOTREACHED();
552 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28553 return nullptr;
[email protected]484955942010-08-19 16:13:18554}
555
dchengda9b4bb2015-07-20 20:58:08556void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32557 OnClose();
kenrba7199832015-01-22 23:44:59558}
559
alexmos78c9c0d2016-10-14 18:57:03560void RenderWidget::SetSwappedOut(bool is_swapped_out) {
561 // We should only toggle between states.
562 DCHECK(is_swapped_out_ != is_swapped_out);
563 is_swapped_out_ = is_swapped_out;
564
565 // If we are swapping out, we will call ReleaseProcess, allowing the process
566 // to exit if all of its RenderViews are swapped out. We wait until the
567 // WasSwappedOut call to do this, to allow the unload handler to finish.
568 // If we are swapping in, we call AddRefProcess to prevent the process from
569 // exiting.
570 if (!is_swapped_out_)
571 RenderProcess::current()->AddRefProcess();
572}
573
nickf7b38222016-11-22 21:59:35574void RenderWidget::Init(const ShowCallback& show_callback,
575 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21576 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23577 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29578
Jeremy Roman04f27c372017-10-27 15:20:55579 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45580
Dave Tapuska9db80842017-07-24 17:24:26581 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
582 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
583
Dave Tapuska525eb15e2017-08-17 21:05:50584 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
Dave Tapuska139a72f2017-09-06 21:57:03585 weak_ptr_factory_.GetWeakPtr(),
Dave Tapuska9db80842017-07-24 17:24:26586 render_thread_impl && compositor_
587 ? render_thread_impl->compositor_task_runner()
588 : nullptr,
589 render_thread_impl ? render_thread_impl->GetRendererScheduler()
590 : nullptr);
591 }
592
nickf7b38222016-11-22 21:59:35593 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29594
lfg8ff33912016-09-13 20:59:21595 webwidget_internal_ = web_widget;
596 webwidget_mouse_lock_target_.reset(
597 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21598 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29599
nick4df698d82016-11-11 20:39:23600 RenderThread::Get()->AddRoute(routing_id_, this);
601 // Take a reference on behalf of the RenderThread. This will be balanced
602 // when we receive ViewMsg_Close.
603 AddRef();
604 if (RenderThreadImpl::current()) {
605 RenderThreadImpl::current()->WidgetCreated();
606 if (is_hidden_)
607 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29608 }
609}
610
[email protected]949b6592014-08-20 13:17:52611void RenderWidget::WasSwappedOut() {
612 // If we have been swapped out and no one else is using this process,
613 // it's safe to exit now.
614 CHECK(is_swapped_out_);
615 RenderProcess::current()->ReleaseProcess();
616}
617
[email protected]b2e4c70132013-10-03 02:07:51618void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39619 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51620 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43621 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00622 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02623 emulator->original_screen_rect().origin();
Christopher Cameronaad15a0d2018-03-09 03:47:33624 UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:38625 emulator->original_screen_info());
[email protected]b2e4c70132013-10-03 02:07:51626}
627
[email protected]2d6836f42014-07-02 17:25:31628gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
629 if (screen_metrics_emulator_)
630 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
631 return anchor;
632}
633
thakis18e426412017-03-15 12:06:37634#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51635void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39636 ExternalPopupMenu* popup,
637 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00638 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51639}
[email protected]53907862014-03-25 15:42:40640#endif
[email protected]b2e4c70132013-10-03 02:07:51641
Fady Samuel69b33b52017-11-08 22:01:52642void RenderWidget::SetLocalSurfaceIdForAutoResize(
643 uint64_t sequence_number,
644 const content::ScreenInfo& screen_info,
Saman Samif7731342018-01-24 22:18:44645 uint32_t content_source_id,
Fady Samuel69b33b52017-11-08 22:01:52646 const viz::LocalSurfaceId& local_surface_id) {
Fady Samuela41e9d42018-03-01 21:31:58647 DCHECK(!size_.IsEmpty());
648
Saman Samif7731342018-01-24 22:18:44649 // If the given LocalSurfaceId was generated before navigation, don't use it.
650 // We should receive a new LocalSurfaceId later.
Christopher Cameronbe7ecea2018-02-27 00:47:19651 viz::LocalSurfaceId new_local_surface_id =
652 content_source_id != current_content_source_id_ ? viz::LocalSurfaceId()
653 : local_surface_id;
Christopher Cameronbe7ecea2018-02-27 00:47:19654 // TODO(ccameron): If there is a meaningful distinction between |size_| and
Christopher Cameronaad15a0d2018-03-09 03:47:33655 // |compositor_viewport_pixel_size_| is it okay to ignore that distinction
656 // here, and assume that |compositor_viewport_pixel_size_| is just |size_| in
657 // pixels? Also note that the computation of
658 // |new_compositor_viewport_pixel_size| does not appear to take into account
659 // device emulation.
Christopher Camerone9a30c12018-03-07 08:23:38660 float new_device_scale_factor = screen_info.device_scale_factor;
Christopher Cameronaad15a0d2018-03-09 03:47:33661 gfx::Size new_compositor_viewport_pixel_size =
Christopher Camerone9a30c12018-03-07 08:23:38662 gfx::ScaleToCeiledSize(size_, new_device_scale_factor);
Christopher Cameronaad15a0d2018-03-09 03:47:33663 UpdateSurfaceAndScreenInfo(new_local_surface_id,
664 new_compositor_viewport_pixel_size, screen_info);
Fady Samuel69b33b52017-11-08 22:01:52665}
666
[email protected]b2e4c70132013-10-03 02:07:51667void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
668 if (screen_metrics_emulator_)
669 screen_metrics_emulator_->OnShowContextMenu(params);
670}
671
[email protected]a95986a82010-12-24 06:19:28672bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47673#if defined(OS_MACOSX)
674 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
675 return text_input_client_observer_->OnMessageReceived(message);
676#endif
lfgbee1e0a2016-06-08 21:24:21677 if (mouse_lock_dispatcher_ &&
678 mouse_lock_dispatcher_->OnMessageReceived(message))
679 return true;
680
[email protected]a95986a82010-12-24 06:19:28681 bool handled = true;
682 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15683 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22684 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
685 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22686 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29687 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
688 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
689 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15690 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46691 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
692 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15693 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
wjmacleanee244e02017-05-26 21:06:07694 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28695 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28696 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
Fady Samuel319e429c2017-10-02 18:31:55697 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
698 OnSetLocalSurfaceIdForAutoResize)
dgozman9260b0a12015-03-16 13:45:20699 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
700 OnEnableDeviceEmulation)
701 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
702 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28703 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41704 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25705 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28706 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
707 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03708 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48709 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
710 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32711 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
Ken Buchanan8a319fb2017-11-15 18:37:12712 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRenderThrottlingStatus,
713 OnUpdateRenderThrottlingStatus)
lfg43e08e62016-02-03 18:51:37714 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
715 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23716 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
717 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59718 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
719 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
720 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
721 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21722 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
723 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
724 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21725#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39726 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
727 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21728#endif
[email protected]a95986a82010-12-24 06:19:28729 IPC_MESSAGE_UNHANDLED(handled = false)
730 IPC_END_MESSAGE_MAP()
731 return handled;
732}
initial.commit09911bf2008-07-26 23:55:29733
734bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42735 // Don't send any messages after the browser has told us to close, and filter
736 // most outgoing messages while swapped out.
737 if ((is_swapped_out_ &&
738 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
739 closing_) {
initial.commit09911bf2008-07-26 23:55:29740 delete message;
741 return false;
742 }
743
744 // If given a messsage without a routing ID, then assign our routing ID.
745 if (message->routing_id() == MSG_ROUTING_NONE)
746 message->set_routing_id(routing_id_);
747
[email protected]380244092011-10-07 17:26:27748 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44749}
750
dtapuska014ed082016-11-11 21:58:48751void RenderWidget::SendOrCrash(IPC::Message* message) {
752 bool result = Send(message);
753 CHECK(closing_ || result) << "Failed to send message";
754}
755
ekaramad5aff1942017-01-06 01:26:35756bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26757 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
758 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
759 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
760 // will be processed regardless of page focus. We should revisit this after
761 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54762 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26763 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35764}
765
bokanc007c3a2015-02-03 07:15:56766void RenderWidget::SetWindowRectSynchronously(
767 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39768 ResizeParams params;
769 params.screen_info = screen_info_;
770 params.new_size = new_window_rect.size();
Christopher Cameronaad15a0d2018-03-09 03:47:33771 params.compositor_viewport_pixel_size =
Christopher Camerone9a30c12018-03-07 08:23:38772 gfx::ScaleToCeiledSize(new_window_rect.size(), GetWebDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:39773 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39774 params.is_fullscreen_granted = is_fullscreen_granted_;
775 params.display_mode = display_mode_;
776 params.needs_resize_ack = false;
777 Resize(params);
778
bokanc007c3a2015-02-03 07:15:56779 view_screen_rect_ = new_window_rect;
780 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02781 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56782 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02783}
784
initial.commit09911bf2008-07-26 23:55:29785void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32786 DCHECK(content::RenderThread::Get());
787 if (closing_)
788 return;
789 NotifyOnClose();
790 closing_ = true;
791
792 // Browser correspondence is no longer needed at this point.
793 if (routing_id_ != MSG_ROUTING_NONE) {
794 RenderThread::Get()->RemoveRoute(routing_id_);
795 SetHidden(false);
796 if (RenderThreadImpl::current())
797 RenderThreadImpl::current()->WidgetDestroyed();
798 }
799
800 if (for_oopif_) {
801 // Widgets for frames may be created and closed at any time while the frame
Ken Buchananed449bb2018-02-01 21:02:05802 // is alive. However, WebWidget must be closed synchronously because frame
803 // widgets and frames hold pointers to each other. The deferred call to
804 // Close() will complete cleanup and release |this|, but CloseWebWidget()
805 // prevents Close() from attempting to access members of an
806 // already-deleted frame.
807 CloseWebWidget();
dchengd96a27a2015-07-24 20:17:32808 }
Ken Buchananed449bb2018-02-01 21:02:05809 // If there is a Send call on the stack, then it could be dangerous to close
810 // now. Post a task that only gets invoked when there are no nested message
811 // loops.
812 task_runner_->PostNonNestableTask(FROM_HERE,
813 base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32814
815 // Balances the AddRef taken when we called AddRoute.
816 Release();
initial.commit09911bf2008-07-26 23:55:29817}
818
fsamuel664e8b62016-01-20 19:54:01819void RenderWidget::OnResize(const ResizeParams& params) {
EhsanKbd2cea992017-11-23 18:49:08820 gfx::Size old_visible_viewport_size = visible_viewport_size_;
821
[email protected]5b45ad42013-10-25 00:42:04822 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32823 return;
824
[email protected]b2e4c70132013-10-03 02:07:51825 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39826 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51827 return;
828 }
829
mfomitchev2600fd7c2016-02-17 20:53:39830 Resize(params);
EhsanKbd2cea992017-11-23 18:49:08831
832 if (old_visible_viewport_size != visible_viewport_size_) {
833 for (auto& render_frame : render_frames_)
834 render_frame.DidChangeVisibleViewport();
835 }
initial.commit09911bf2008-07-26 23:55:29836}
837
Fady Samuel319e429c2017-10-02 18:31:55838void RenderWidget::OnSetLocalSurfaceIdForAutoResize(
839 uint64_t sequence_number,
Fady Samuel69b33b52017-11-08 22:01:52840 const gfx::Size& min_size,
841 const gfx::Size& max_size,
842 const content::ScreenInfo& screen_info,
Saman Samif7731342018-01-24 22:18:44843 uint32_t content_source_id,
Fady Samuel319e429c2017-10-02 18:31:55844 const viz::LocalSurfaceId& local_surface_id) {
Fady Samuel1ee6fb5c2018-02-16 03:27:46845 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number) {
846 DidResizeOrRepaintAck();
Fady Samuel319e429c2017-10-02 18:31:55847 return;
Fady Samuel1ee6fb5c2018-02-16 03:27:46848 }
Christopher Camerone9a30c12018-03-07 08:23:38849 // TODO(ccameron): This does not appear to interact correctly with device
850 // emulation (compare with the intercepting of ScreenInfo in OnResize).
Fady Samuel69b33b52017-11-08 22:01:52851 SetLocalSurfaceIdForAutoResize(sequence_number, screen_info,
Saman Samif7731342018-01-24 22:18:44852 content_source_id, local_surface_id);
Fady Samuel319e429c2017-10-02 18:31:55853}
854
dgozman9260b0a12015-03-16 13:45:20855void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02856 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39857 if (!screen_metrics_emulator_) {
858 ResizeParams resize_params;
859 resize_params.screen_info = screen_info_;
860 resize_params.new_size = size_;
Christopher Cameronaad15a0d2018-03-09 03:47:33861 resize_params.compositor_viewport_pixel_size =
862 compositor_viewport_pixel_size_;
Fady Samuela41e9d42018-03-01 21:31:58863 resize_params.local_surface_id = local_surface_id_;
864 resize_params.content_source_id = current_content_source_id_;
mfomitchev2600fd7c2016-02-17 20:53:39865 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39866 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
867 resize_params.display_mode = display_mode_;
868 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
869 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18870 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39871 } else {
dgozman9260b0a12015-03-16 13:45:20872 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39873 }
dgozman9260b0a12015-03-16 13:45:20874}
875
876void RenderWidget::OnDisableDeviceEmulation() {
877 screen_metrics_emulator_.reset();
878}
879
initial.commit09911bf2008-07-26 23:55:29880void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31881 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29882 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03883 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55884 for (auto& observer : render_frames_)
885 observer.WasHidden();
Saman Sami58ed4392018-01-31 20:54:19886
887 // Ack the resize if we have to, so that the next time we're visible we get a
888 // fresh ResizeParams right away; otherwise we'll start painting based on a
889 // stale ResizeParams.
890 DidResizeOrRepaintAck();
initial.commit09911bf2008-07-26 23:55:29891}
892
Saman Samid709592b2018-02-03 00:38:10893void RenderWidget::OnWasShown(bool needs_repainting,
894 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41895 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29896 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21897 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29898 return;
899
tasakb95dbb50c2017-02-08 18:07:50900 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29901 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03902 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55903 for (auto& observer : render_frames_)
904 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29905
[email protected]8a23afb32014-04-30 22:40:23906 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29907 return;
initial.commit09911bf2008-07-26 23:55:29908
[email protected]3399dd822014-08-09 11:14:24909 if (compositor_) {
910 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11911 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
912 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
913 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54914 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24915 }
initial.commit09911bf2008-07-26 23:55:29916}
917
[email protected]53d3f302009-12-21 04:42:05918void RenderWidget::OnRequestMoveAck() {
919 DCHECK(pending_window_rect_count_);
920 pending_window_rect_count_--;
921}
922
[email protected]ed7defa2013-03-12 21:29:59923GURL RenderWidget::GetURLForGraphicsContext3D() {
924 return GURL();
[email protected]65225772011-05-12 21:10:24925}
926
nzolghadr5d8596502017-01-23 22:59:35927void RenderWidget::OnHandleInputEvent(
928 const blink::WebInputEvent* input_event,
929 const std::vector<const blink::WebInputEvent*>& coalesced_events,
930 const ui::LatencyInfo& latency_info,
931 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23932 if (!input_event)
933 return;
nzolghadr5d8596502017-01-23 22:59:35934
Dave Tapuskaea83d3bd2017-06-13 16:14:55935 HandledEventCallback callback;
936 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
937 callback = base::Bind(
938 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
939 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
940 }
nzolghadr5d8596502017-01-23 22:59:35941 input_handler_->HandleInputEvent(
942 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55943 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23944}
945
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27946viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::Point& point) {
947 return input_handler_->GetFrameSinkIdAtPoint(point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22948}
949
Dave Tapuskaea83d3bd2017-06-13 16:14:55950void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31951 const blink::WebCoalescedInputEvent& input_event,
952 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55953 HandledEventCallback callback) {
954 input_handler_->HandleInputEvent(input_event, latency_info,
955 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31956}
957
Dave Tapuskaea83d3bd2017-06-13 16:14:55958void RenderWidget::SendInputEventAck(
959 blink::WebInputEvent::Type type,
960 uint32_t touch_event_id,
961 InputEventAckState ack_state,
962 const ui::LatencyInfo& latency_info,
Dave Tapuskab28a1082017-08-30 15:37:26963 std::unique_ptr<ui::DidOverscrollParams> overscroll_params,
964 base::Optional<cc::TouchAction> touch_action) {
Dave Tapuskaea83d3bd2017-06-13 16:14:55965 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
Dave Tapuskab28a1082017-08-30 15:37:26966 latency_info, std::move(overscroll_params), touch_event_id,
967 touch_action);
dtapuska9ec1a912017-04-21 15:18:31968 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
969}
970
dtapuska9d46ef7d2017-05-26 19:06:06971scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
972 return input_event_queue_;
973}
974
fsamuel78f86e42016-01-20 04:10:23975void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21976 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54977 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23978}
979
980void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21981 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54982 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23983}
984
alexmos56567492016-09-13 00:52:46985void RenderWidget::OnSetEditCommandsForNextKeyEvent(
986 const EditCommands& edit_commands) {
987 edit_commands_ = edit_commands;
988}
989
fsamuel78f86e42016-01-20 04:10:23990void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08991 has_focus_ = enable;
992
lfg8ff33912016-09-13 20:59:21993 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54994 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08995
ericwilligers88e69742016-10-17 19:29:55996 for (auto& observer : render_frames_)
997 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23998}
999
dtapuska3d5624d32016-08-30 04:34:001000void RenderWidget::SetNeedsMainFrame() {
1001 RenderWidgetCompositor* rwc = compositor();
1002 if (!rwc)
1003 return;
Blink Reformat1c4d759e2017-04-09 16:34:541004 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:001005}
1006
fsamuel78f86e42016-01-20 04:10:231007///////////////////////////////////////////////////////////////////////////////
1008// RenderWidgetCompositorDelegate
1009
1010void RenderWidget::ApplyViewportDeltas(
1011 const gfx::Vector2dF& inner_delta,
1012 const gfx::Vector2dF& outer_delta,
1013 const gfx::Vector2dF& elastic_overscroll_delta,
1014 float page_scale,
1015 float top_controls_delta) {
Ken Buchananed449bb2018-02-01 21:02:051016 if (!GetWebWidget())
1017 return;
Blink Reformat1c4d759e2017-04-09 16:34:541018 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:211019 elastic_overscroll_delta, page_scale,
1020 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:231021}
1022
sahel1b47fda72017-03-28 17:03:071023void RenderWidget::RecordWheelAndTouchScrollingCount(
1024 bool has_scrolled_by_wheel,
1025 bool has_scrolled_by_touch) {
Ken Buchananed449bb2018-02-01 21:02:051026 if (!GetWebWidget())
1027 return;
Blink Reformat1c4d759e2017-04-09 16:34:541028 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:071029 has_scrolled_by_touch);
1030}
1031
fsamuel78f86e42016-01-20 04:10:231032void RenderWidget::BeginMainFrame(double frame_time_sec) {
Ken Buchananed449bb2018-02-01 21:02:051033 if (!GetWebWidget())
1034 return;
dtapuska9ec1a912017-04-21 15:18:311035 if (input_event_queue_) {
1036 input_event_queue_->DispatchRafAlignedInput(
1037 ui::EventTimeStampFromSeconds(frame_time_sec));
1038 }
dtapuska3d5624d32016-08-30 04:34:001039
Blink Reformat1c4d759e2017-04-09 16:34:541040 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:231041}
1042
danakjc7afae52017-06-20 21:12:411043void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:411044 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:211045 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:031046 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:411047 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:391048 DCHECK(!compositor_never_visible_);
jonrossa2ff4f82018-02-16 17:27:461049
1050 // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
1051 // would then handle binding.
1052 mojom::RenderFrameMetadataObserverPtr ptr;
1053 mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr);
1054 mojom::RenderFrameMetadataObserverClientPtrInfo client_info;
1055 mojom::RenderFrameMetadataObserverClientRequest client_request =
1056 mojo::MakeRequest(&client_info);
1057 compositor_->CreateRenderFrameObserver(std::move(request),
1058 std::move(client_info));
danakjc7afae52017-06-20 21:12:411059 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:331060 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
jonrossa2ff4f82018-02-16 17:27:461061 callback, std::move(client_request), std::move(ptr));
[email protected]ba91a792013-02-06 09:48:281062}
1063
fsamuel78f86e42016-01-20 04:10:231064void RenderWidget::DidCommitAndDrawCompositorFrame() {
1065 // NOTE: Tests may break if this event is renamed or moved. See
1066 // tab_capture_performancetest.cc.
1067 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:081068
Saman Sami766e0b02018-01-31 17:19:201069 // If we haven't commited yet, then this method was called as a response to a
1070 // previous commit and should not be used to ack the resize.
1071 if (did_commit_after_resize_)
1072 DidResizeOrRepaintAck();
Saman Sami9ee04be2018-01-25 01:31:251073
ericwilligers88e69742016-10-17 19:29:551074 for (auto& observer : render_frames_)
1075 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:081076
fsamuel78f86e42016-01-20 04:10:231077 // Notify subclasses that we initiated the paint operation.
1078 DidInitiatePaint();
1079}
1080
Saman Sami766e0b02018-01-31 17:19:201081void RenderWidget::DidCommitCompositorFrame() {
1082 did_commit_after_resize_ = true;
1083}
fsamuel78f86e42016-01-20 04:10:231084
1085void RenderWidget::DidCompletePageScaleAnimation() {}
1086
danakj6c872fc02016-10-22 04:29:491087void RenderWidget::DidReceiveCompositorFrameAck() {
fsamuel78f86e42016-01-20 04:10:231088}
1089
fsamuel78f86e42016-01-20 04:10:231090bool RenderWidget::IsClosing() const {
1091 return host_closing_;
1092}
1093
danakj53eccbc2016-03-02 22:51:071094void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:541095 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:291096}
1097
Eric Seckler8af8c0e52018-01-17 23:45:531098void RenderWidget::UpdateVisualState(VisualStateUpdate requested_update) {
Ken Buchananed449bb2018-02-01 21:02:051099 if (!GetWebWidget())
1100 return;
1101
Eric Seckler8af8c0e52018-01-17 23:45:531102 bool pre_paint_only = requested_update == VisualStateUpdate::kPrePaint;
1103 WebWidget::LifecycleUpdate lifecycle_update =
1104 pre_paint_only ? WebWidget::LifecycleUpdate::kPrePaint
1105 : WebWidget::LifecycleUpdate::kAll;
1106
1107 GetWebWidget()->UpdateLifecycle(lifecycle_update);
Blink Reformat1c4d759e2017-04-09 16:34:541108 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501109
Eric Seckler8af8c0e52018-01-17 23:45:531110 if (first_update_visual_state_after_hidden_ && !pre_paint_only) {
Takashi SAKAMOTO870f6262017-08-22 04:08:271111 RecordTimeToFirstActivePaint();
1112 first_update_visual_state_after_hidden_ = false;
1113 }
1114}
tasakb95dbb50c2017-02-08 18:07:501115
Takashi SAKAMOTO870f6262017-08-22 04:08:271116void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501117 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501118 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271119 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1120 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1121 sample);
1122 }
1123 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1124 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1125 UMA_HISTOGRAM_TIMES(
1126 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1127 "AfterBackgrounded.5min",
1128 sample);
1129 }
fsamuel78f86e42016-01-20 04:10:231130}
1131
1132void RenderWidget::WillBeginCompositorFrame() {
1133 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1134
Ken Buchananed449bb2018-02-01 21:02:051135 if (!GetWebWidget())
1136 return;
1137
Blink Reformat1c4d759e2017-04-09 16:34:541138 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291139
dglazkov06854c5c2016-08-31 00:19:591140 // The UpdateTextInputState can result in further layout and possibly
1141 // enable GPU acceleration so they need to be called before any painting
1142 // is done.
changwan75e3b2072017-01-16 02:55:001143 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591144 UpdateSelectionBounds();
1145
ericwilligers88e69742016-10-17 19:29:551146 for (auto& observer : render_frame_proxies_)
1147 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291148}
1149
jbroman6ccbc7d472016-07-27 04:45:411150std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041151 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411152 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1153 routing_id_, std::move(request));
1154}
1155
fsamuel72464894f2015-12-15 06:59:311156///////////////////////////////////////////////////////////////////////////////
1157// RenderWidgetInputHandlerDelegate
1158
avid7d6b2e2016-03-04 19:41:171159void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381160 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1161 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291162 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381163
ekaramad27ca69b12017-04-20 18:34:291164 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381165 frame_widget->LocalRoot()->View()->FocusedFrame();
1166
ekaramad27ca69b12017-04-20 18:34:291167 if (focused && focused->AutofillClient())
1168 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171169}
fsamuel72464894f2015-12-15 06:59:311170
dtapuska1827dd22016-03-11 15:24:591171void RenderWidget::ObserveGestureEventAndResult(
1172 const blink::WebGestureEvent& gesture_event,
1173 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131174 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591175 bool event_processed) {
1176 if (!compositor_deps_->IsElasticOverscrollEnabled())
1177 return;
1178
1179 cc::InputHandlerScrollResult scroll_result;
1180 scroll_result.did_scroll = event_processed;
1181 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1182 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131183 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591184
1185 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1186 InputHandlerManager* input_handler_manager =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281187 render_thread ? render_thread->input_handler_manager() : nullptr;
dtapuska1827dd22016-03-11 15:24:591188 if (input_handler_manager) {
1189 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1190 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261191 } else if (widget_input_handler_manager_) {
1192 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1193 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591194 }
1195}
1196
avid7d6b2e2016-03-04 19:41:171197void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461198 ClearEditCommands();
1199}
1200
1201void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1202 const std::string& value) {
1203 ClearEditCommands();
1204 edit_commands_.emplace_back(name, value);
1205}
1206
1207void RenderWidget::ClearEditCommands() {
1208 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171209}
fsamuel72464894f2015-12-15 06:59:311210
chongza8ba91fc2016-08-16 21:39:171211void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska139a72f2017-09-06 21:57:031212 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051213 if (mojom::WidgetInputHandlerHost* host =
1214 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1215 host->DidOverscroll(params);
1216 }
Dave Tapuska139a72f2017-09-06 21:57:031217 } else {
1218 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1219 }
fsamuel72464894f2015-12-15 06:59:311220}
1221
fsamuele8326c742016-01-12 00:49:391222void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1223 // Nothing to do here. RenderWidget created the |input_handler| and will take
1224 // ownership of it. We just verify here that we don't already have an input
1225 // handler.
1226 DCHECK(!input_handler_);
1227}
1228
changwan75e3b2072017-01-16 02:55:001229void RenderWidget::ShowVirtualKeyboard() {
1230 UpdateTextInputStateInternal(true, false);
1231}
1232
changwan62f57292017-02-17 08:28:251233void RenderWidget::ClearTextInputState() {
1234 text_input_info_ = blink::WebTextInputInfo();
1235 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1236 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1237 can_compose_inline_ = false;
1238 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201239 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251240}
1241
changwan75e3b2072017-01-16 02:55:001242void RenderWidget::UpdateTextInputState() {
1243 UpdateTextInputStateInternal(false, false);
1244}
1245
1246void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1247 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311248 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001249
fsamuel72464894f2015-12-15 06:59:311250 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001251 DCHECK(!reply_to_request);
1252 // show_virtual_keyboard should still be effective even if it was set inside
1253 // the IME
fsamuel72464894f2015-12-15 06:59:311254 // event guard.
changwan75e3b2072017-01-16 02:55:001255 if (show_virtual_keyboard)
1256 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311257 return;
1258 }
1259
dglazkov97b6c2b2016-10-25 17:35:551260 ui::TextInputType new_type = GetTextInputType();
1261 if (IsDateTimeInput(new_type))
1262 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311263
dglazkov97b6c2b2016-10-25 17:35:551264 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351265 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541266 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101267 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541268 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311269
1270 bool new_can_compose_inline = CanComposeInline();
1271
1272 // Only sends text input params if they are changed or if the ime should be
1273 // shown.
changwan75e3b2072017-01-16 02:55:001274 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561275 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1276 text_input_info_ != new_info ||
1277 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381278 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551279 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311280 params.mode = new_mode;
1281 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211282#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201283 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1284 // Due to a focus change, values will be reset by the frame.
1285 // That case we only need fresh NEXT/PREVIOUS information.
1286 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1287 // focusable status is changed.
1288 if (auto* controller = GetInputMethodController()) {
1289 next_previous_flags_ =
1290 controller->ComputeWebTextInputNextPreviousFlags();
1291 } else {
1292 // For safety in case GetInputMethodController() is null, because -1 is
1293 // invalid value to send to browser process.
1294 next_previous_flags_ = 0;
1295 }
1296 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211297#else
1298 next_previous_flags_ = 0;
1299#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201300 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541301 params.value = new_info.value.Utf8();
1302 params.selection_start = new_info.selection_start;
1303 params.selection_end = new_info.selection_end;
1304 params.composition_start = new_info.composition_start;
1305 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311306 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001307 // TODO(changwan): change instances of show_ime_if_needed to
1308 // show_virtual_keyboard.
1309 params.show_ime_if_needed = show_virtual_keyboard;
1310 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311311 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1312
1313 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551314 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311315 text_input_mode_ = new_mode;
1316 can_compose_inline_ = new_can_compose_inline;
1317 text_input_flags_ = new_info.flags;
1318 }
1319}
1320
1321bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581322 possible_drag_event_info_.event_source =
1323 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1324 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541325 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171326
fsamuel72464894f2015-12-15 06:59:311327 return false;
1328}
1329
1330bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551331 for (auto& observer : render_frames_)
1332 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081333
paulmeyer6ef5a792016-11-08 20:33:581334 possible_drag_event_info_.event_source =
1335 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1336 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541337 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581338
avid7d6b2e2016-03-04 19:41:171339 if (owner_delegate_)
1340 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1341
fsamuel72464894f2015-12-15 06:59:311342 return false;
[email protected]fd847792013-10-24 17:12:351343}
1344
initial.commit09911bf2008-07-26 23:55:291345///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391346// RenderWidgetScreenMetricsDelegate
1347
1348void RenderWidget::Redraw() {
1349 set_next_paint_is_resize_ack();
1350 if (compositor_)
1351 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1352}
1353
bokanc63441c2016-04-27 15:49:121354void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541355 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121356}
1357
1358gfx::Size RenderWidget::GetSizeForWebWidget() const {
1359 if (IsUseZoomForDSFEnabled())
1360 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1361
1362 return size_;
1363}
1364
mfomitchev2600fd7c2016-02-17 20:53:391365void RenderWidget::Resize(const ResizeParams& params) {
Saman Samif7731342018-01-24 22:18:441366 // The content_source_id that the browser sends us should never be larger than
1367 // |current_content_source_id_|.
1368 DCHECK_GE(1u << 30, current_content_source_id_ - params.content_source_id);
1369
Saman Sami766e0b02018-01-31 17:19:201370 // If this resize needs to be acked, make sure we ack it only after we commit.
1371 // It is possible to get DidCommitAndDraw calls that belong to the previous
1372 // commit, in which case we should not ack this resize.
1373 if (params.needs_resize_ack)
1374 did_commit_after_resize_ = false;
1375
Christopher Cameronbe7ecea2018-02-27 00:47:191376 // Inform the rendering thread of the color space indicate the presence of HDR
1377 // capabilities.
Miguel Casas5e1018052018-01-09 19:17:361378 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1379 if (render_thread)
Christopher Camerone9a30c12018-03-07 08:23:381380 render_thread->SetRenderingColorSpace(params.screen_info.color_space);
Miguel Casas5e1018052018-01-09 19:17:361381
mfomitchev2600fd7c2016-02-17 20:53:391382 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1383 // A resize ack shouldn't be requested if we have not ACK'd the previous
1384 // one.
Saman Samif7731342018-01-24 22:18:441385 DCHECK(!compositor_ || !params.needs_resize_ack ||
1386 !next_paint_is_resize_ack());
mfomitchev2600fd7c2016-02-17 20:53:391387 }
1388
1389 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211390 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391391 return;
1392
Saman Samif7731342018-01-24 22:18:441393 // If the content_source_id of ResizeParams doesn't match
1394 // |current_content_source_id_|, then the given LocalSurfaceId was generated
1395 // before the navigation. Continue with the resize but don't use the
1396 // LocalSurfaceId until the right one comes.
Fady Samuela41e9d42018-03-01 21:31:581397 viz::LocalSurfaceId new_local_surface_id;
Saman Samif7731342018-01-24 22:18:441398 if (params.local_surface_id &&
1399 params.content_source_id == current_content_source_id_) {
Christopher Cameronbe7ecea2018-02-27 00:47:191400 new_local_surface_id = *params.local_surface_id;
Saman Samif7731342018-01-24 22:18:441401 }
Christopher Cameronaad15a0d2018-03-09 03:47:331402 UpdateSurfaceAndScreenInfo(new_local_surface_id,
1403 params.compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381404 params.screen_info);
ianwene5fc5782016-08-18 04:05:151405 if (compositor_) {
Fady Samuel319e429c2017-10-02 18:31:551406 // If surface synchronization is enabled, then this will use the provided
fsamuelca02c4e2017-05-09 13:34:141407 // |local_surface_id_| to submit the next generated CompositorFrame.
1408 // If the ID is not valid, then the compositor will defer commits until
1409 // it receives a valid surface ID. This is a no-op if surface
1410 // synchronization is disabled.
Fady Samuel2bb02292017-10-17 23:59:151411 DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() ||
Fady Samuela41e9d42018-03-01 21:31:581412 !params.needs_resize_ack || !params.local_surface_id ||
1413 params.local_surface_id->is_valid());
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271414 compositor_->SetBrowserControlsHeight(
1415 params.top_controls_height, params.bottom_controls_height,
1416 params.browser_controls_shrink_blink_size);
1417 compositor_->SetRasterColorSpace(
1418 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151419 }
mfomitchev2600fd7c2016-02-17 20:53:391420
mfomitchev2600fd7c2016-02-17 20:53:391421 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391422
1423 // NOTE: We may have entered fullscreen mode without changing our size.
1424 bool fullscreen_change =
1425 is_fullscreen_granted_ != params.is_fullscreen_granted;
1426 is_fullscreen_granted_ = params.is_fullscreen_granted;
1427 display_mode_ = params.display_mode;
1428
bokanc63441c2016-04-27 15:49:121429 size_ = params.new_size;
mfomitchev2600fd7c2016-02-17 20:53:391430
bokanc63441c2016-04-27 15:49:121431 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221432
mfomitchev2600fd7c2016-02-17 20:53:391433 WebSize visual_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391434 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181435 visual_viewport_size = gfx::ScaleToCeiledSize(
1436 params.visible_viewport_size,
1437 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391438 } else {
1439 visual_viewport_size = visible_viewport_size_;
1440 }
Blink Reformat1c4d759e2017-04-09 16:34:541441 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391442
bokanc63441c2016-04-27 15:49:121443 // When resizing, we want to wait to paint before ACK'ing the resize. This
1444 // ensures that we only resize as fast as we can paint. We only need to
1445 // send an ACK if we are resized to a non-empty rect.
Christopher Cameronaad15a0d2018-03-09 03:47:331446 if (params.new_size.IsEmpty() ||
1447 params.compositor_viewport_pixel_size.IsEmpty()) {
mfomitchev2600fd7c2016-02-17 20:53:391448 // In this case there is no paint/composite and therefore no
Fady Samuelcc3e3b4a2017-10-03 02:09:211449 // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to
1450 // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a
1451 // different message.
mfomitchev2600fd7c2016-02-17 20:53:391452 DCHECK(!params.needs_resize_ack);
1453 }
1454
1455 // Send the Resize_ACK flag once we paint again if requested.
1456 if (params.needs_resize_ack)
1457 set_next_paint_is_resize_ack();
1458
1459 if (fullscreen_change)
1460 DidToggleFullscreen();
1461
mfomitchev2600fd7c2016-02-17 20:53:391462 // If a resize ack is requested and it isn't set-up, then no more resizes will
1463 // come in and in general things will go wrong.
1464 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
Saman Samif7731342018-01-24 22:18:441465
1466 // If this resize was initiated before navigation and surface synchronization
1467 // is on, it is not expected to be acked.
1468 if (compositor_ && compositor_->IsSurfaceSynchronizationEnabled() &&
1469 params.needs_resize_ack && !local_surface_id_.is_valid()) {
1470 DCHECK_NE(params.content_source_id, current_content_source_id_);
1471 reset_next_paint_is_resize_ack();
1472 }
mfomitchev2600fd7c2016-02-17 20:53:391473}
1474
1475void RenderWidget::SetScreenMetricsEmulationParameters(
1476 bool enabled,
1477 const blink::WebDeviceEmulationParams& params) {
1478 // This is only supported in RenderView.
1479 NOTREACHED();
1480}
1481
1482void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1483 const gfx::Rect& window_screen_rect) {
1484 view_screen_rect_ = view_screen_rect;
1485 window_screen_rect_ = window_screen_rect;
1486}
1487
1488///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461489// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291490
Blink Reformat1c4d759e2017-04-09 16:34:541491blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221492 DCHECK(!host_closing_);
1493
loyso6e6efc42017-01-21 02:23:031494 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1495 auto animation_host = cc::AnimationHost::CreateMainInstance();
1496
wjmacleana755e302017-04-20 00:43:161497 // Oopif status must be set before the LayerTreeHost is created.
1498 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031499 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1500 compositor_.get(), compositor_.get(), animation_host.get(),
Christopher Camerone9a30c12018-03-07 08:23:381501 compositor_deps_, screen_info_);
loyso6e6efc42017-01-21 02:23:031502 compositor_->Initialize(std::move(layer_tree_host),
1503 std::move(animation_host));
1504
Saman Samif7731342018-01-24 22:18:441505 // We can get into this state if surface synchronization is on and the last
1506 // resize was initiated before navigation, in which case we don't have to ack
1507 // it.
1508 if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ &&
1509 next_paint_is_resize_ack() && !local_surface_id_.is_valid()) {
1510 reset_next_paint_is_resize_ack();
1511 }
1512
Christopher Cameronaad15a0d2018-03-09 03:47:331513 UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:381514 screen_info_);
ccameron01912992017-05-23 07:34:031515 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091516 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011517 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391518 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411519 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221520 bool should_generate_frame_sink =
1521 !compositor_never_visible_ && RenderThreadImpl::current();
1522 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391523 compositor_->SetNeverVisible();
1524
pimanc4af3072015-10-02 03:45:591525 StartCompositor();
staraz067f58242016-11-07 21:06:411526 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1527 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331528 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371529
wjmaclean1d970622017-01-21 22:28:241530 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261531 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311532 input_event_queue_ = new MainThreadEventQueue(
Alexander Timinbb0860d2018-01-29 13:27:161533 this, render_thread->GetRendererScheduler()->InputTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221534 render_thread->GetRendererScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261535
1536 InputHandlerManager* input_handler_manager =
1537 render_thread->input_handler_manager();
1538 if (input_handler_manager) {
1539 input_handler_manager->AddInputHandler(
1540 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1541 weak_ptr_factory_.GetWeakPtr(),
1542 compositor_deps_->IsScrollAnimatorEnabled());
1543 has_added_input_handler_ = true;
1544 }
wjmaclean1d970622017-01-21 22:28:241545 }
1546
Khushal3e96e662017-10-30 23:16:501547 UpdateURLForCompositorUkm();
1548
loyso50b51c22017-01-10 07:18:371549 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591550}
1551
Chris Harrelsond7ab99b2018-01-24 17:51:361552void RenderWidget::IntrinsicSizingInfoChanged(
1553 const blink::WebIntrinsicSizingInfo& sizing_info) {
1554 Send(new ViewHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
1555}
1556
ennef3c58142014-12-09 21:44:381557void RenderWidget::WillCloseLayerTreeView() {
1558 if (host_closing_)
1559 return;
1560
1561 // Prevent new compositors or output surfaces from being created.
1562 host_closing_ = true;
1563
[email protected]aeeedad2014-08-22 18:16:221564 // Always send this notification to prevent new layer tree views from
1565 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211566 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541567 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221568}
1569
Blink Reformat1c4d759e2017-04-09 16:34:541570void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1571 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481572 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1573 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1574 }
dglazkov79c426102015-08-31 21:22:431575
ericwilligers88e69742016-10-17 19:29:551576 for (auto& observer : render_frames_)
1577 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431578}
1579
[email protected]586871b2014-07-22 17:05:111580// static
dchengcedca5612016-04-09 01:40:151581std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111582 IPC::Message* msg,
1583 MessageDeliveryPolicy policy,
1584 FrameSwapMessageQueue* frame_swap_message_queue,
1585 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111586 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111587 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151588 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1589 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111590 &first_message_for_frame);
1591 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151592 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111593 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061594 return promise;
[email protected]586871b2014-07-22 17:05:111595 }
dcheng4b6b5ff2014-10-16 00:42:061596 return nullptr;
[email protected]586871b2014-07-22 17:05:111597}
1598
1599void RenderWidget::QueueMessage(IPC::Message* msg,
1600 MessageDeliveryPolicy policy) {
1601 // RenderThreadImpl::current() is NULL in some tests.
1602 if (!compositor_ || !RenderThreadImpl::current()) {
1603 Send(msg);
1604 return;
1605 }
1606
dchengcedca5612016-04-09 01:40:151607 std::unique_ptr<cc::SwapPromise> swap_promise =
1608 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111609 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111610 compositor_->GetSourceFrameNumber());
1611
Ken Buchanance710eb2017-08-30 23:46:521612 if (swap_promise)
dcheng07945f632015-12-26 07:59:321613 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111614}
1615
Blink Reformat1c4d759e2017-04-09 16:34:541616void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301617 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521618 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181619 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291620 // Only send a SetCursor message if we need to make a change.
1621 if (!current_cursor_.IsEqual(cursor)) {
1622 current_cursor_ = cursor;
1623 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1624 }
1625}
1626
aelias5971e47d2017-06-16 02:39:381627void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1628 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1629}
1630
1631void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1632 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1633}
1634
1635void RenderWidget::AutoscrollEnd() {
1636 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1637}
1638
initial.commit09911bf2008-07-26 23:55:291639// We are supposed to get a single call to Show for a newly created RenderWidget
1640// that was created via RenderWidget::CreateWebView. So, we wait until this
1641// point to dispatch the ShowWidget message.
1642//
1643// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281644// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291645//
Blink Reformat1c4d759e2017-04-09 16:34:541646void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291647 DCHECK(!did_show_) << "received extraneous Show call";
1648 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351649 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291650
[email protected]8de12d942010-11-17 20:42:441651 if (did_show_)
1652 return;
1653
1654 did_show_ = true;
nickf7b38222016-11-22 21:59:351655
1656 // The opener is responsible for actually showing this widget.
1657 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351658 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351659
bokanc007c3a2015-02-03 07:15:561660 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441661 // that's okay. It'll be ignored if as_popup is false, or the browser
1662 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561663 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291664}
1665
[email protected]2533ce12009-05-09 00:02:241666void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381667 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241668 Send(new ViewHostMsg_Close(routing_id_));
1669}
1670
dgozmancf9039cd2015-04-06 12:01:311671void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551672 for (auto& observer : render_frames_)
1673 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311674}
1675
Blink Reformat1c4d759e2017-04-09 16:34:541676void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081677 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321678 if (is_swapped_out_) {
1679 // This widget is currently swapped out, and the active widget is in a
1680 // different process. Have the browser route the close request to the
1681 // active widget instead, so that the correct unload handlers are run.
1682 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1683 return;
1684 }
1685
initial.commit09911bf2008-07-26 23:55:291686 // If a page calls window.close() twice, we'll end up here twice, but that's
1687 // OK. It is safe to send multiple Close messages.
1688
[email protected]2533ce12009-05-09 00:02:241689 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1690 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1691 // could be closed before the JS finishes executing. So instead, post a
1692 // message back to the message loop, which won't run until the JS is
1693 // complete, and then the Close message can be sent.
Hajime Hoshiabb3c8f2017-12-04 18:41:391694 task_runner_->PostTask(FROM_HERE,
1695 base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291696}
1697
1698void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031699 screen_metrics_emulator_.reset();
Ken Buchananed449bb2018-02-01 21:02:051700 CloseWebWidget();
ennef3c58142014-12-09 21:44:381701 compositor_.reset();
Ken Buchananed449bb2018-02-01 21:02:051702}
1703
1704void RenderWidget::CloseWebWidget() {
1705 WillCloseLayerTreeView();
lfg8ff33912016-09-13 20:59:211706 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541707 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211708 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291709 }
1710}
1711
Mitsuru Oshima3c07b332018-02-06 04:56:501712void RenderWidget::UpdateWebViewWithDeviceScaleFactor() {
1713 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1714 blink::WebFrame* current_frame =
1715 frame_widget ? frame_widget->LocalRoot() : nullptr;
1716 blink::WebView* webview = current_frame ? current_frame->View() : nullptr;
1717 if (webview) {
1718 if (IsUseZoomForDSFEnabled())
Christopher Camerone9a30c12018-03-07 08:23:381719 webview->SetZoomFactorForDeviceScaleFactor(GetWebDeviceScaleFactor());
Mitsuru Oshima3c07b332018-02-06 04:56:501720 else
Christopher Camerone9a30c12018-03-07 08:23:381721 webview->SetDeviceScaleFactor(GetWebDeviceScaleFactor());
Mitsuru Oshima3c07b332018-02-06 04:56:501722
1723 webview->GetSettings()->SetPreferCompositingToLCDTextEnabled(
Christopher Camerone9a30c12018-03-07 08:23:381724 PreferCompositingToLCDText(compositor_deps_,
1725 GetWebDeviceScaleFactor()));
Mitsuru Oshima3c07b332018-02-06 04:56:501726 }
1727}
1728
Ehsan Karamad655d7b8a2018-01-12 18:38:381729blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
1730 blink::WebWidget* web_widget = GetWebWidget();
1731 if (!web_widget)
1732 return nullptr;
1733
1734 if (!web_widget->IsWebFrameWidget()) {
1735 // TODO(ekaramad): This should not happen. If we have a WebWidget and we
1736 // need a WebFrameWidget then we should be getting a WebFrameWidget. But
1737 // unfortunately this does not seem to be the case in some scenarios --
1738 // specifically when a RenderViewImpl swaps out during navigation the
1739 // WebViewImpl loses its WebViewFrameWidget but sometimes we receive IPCs
1740 // which are destined for WebFrameWidget (https://crbug.com/669219).
1741 return nullptr;
1742 }
1743
1744 return static_cast<blink::WebFrameWidget*>(web_widget);
1745}
1746
bokan841fdc72016-10-06 00:16:351747void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1748 DCHECK(window_rect);
1749 float scale = popup_origin_scale_for_emulation_;
1750 if (!scale)
1751 return;
1752 window_rect->x =
1753 popup_view_origin_for_emulation_.x() +
1754 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1755 window_rect->y =
1756 popup_view_origin_for_emulation_.y() +
1757 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1758}
1759
1760void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1761 DCHECK(window_rect);
1762 float scale = popup_origin_scale_for_emulation_;
1763 if (!scale)
1764 return;
1765 window_rect->x =
1766 popup_screen_origin_for_emulation_.x() +
1767 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1768 window_rect->y =
1769 popup_screen_origin_for_emulation_.y() +
1770 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1771}
1772
Blink Reformat1c4d759e2017-04-09 16:34:541773WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351774 WebRect rect;
bokan6b08cd22016-10-05 00:55:211775 if (pending_window_rect_count_) {
1776 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1777 // the RootWindowRect is probably going to return wrong results since the
1778 // browser may not have processed the Move yet. There isn't really anything
1779 // good to do in this case, and it shouldn't happen - since this size is
1780 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351781 rect = pending_window_rect_;
1782 } else {
1783 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211784 }
[email protected]2533ce12009-05-09 00:02:241785
bokan841fdc72016-10-06 00:16:351786 ScreenRectToEmulatedIfNeeded(&rect);
1787 return rect;
bokan6b08cd22016-10-05 00:55:211788}
1789
Blink Reformat1c4d759e2017-04-09 16:34:541790WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351791 WebRect rect = view_screen_rect_;
1792 ScreenRectToEmulatedIfNeeded(&rect);
1793 return rect;
initial.commit09911bf2008-07-26 23:55:291794}
1795
Blink Reformat1c4d759e2017-04-09 16:34:541796void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301797 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541798 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301799}
1800
Blink Reformat1c4d759e2017-04-09 16:34:541801void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241802 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351803 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511804
[email protected]5b45ad42013-10-25 00:42:041805 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201806 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561807 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1808 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031809 } else {
bokanc007c3a2015-02-03 07:15:561810 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031811 }
initial.commit09911bf2008-07-26 23:55:291812 } else {
bokanc007c3a2015-02-03 07:15:561813 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291814 }
1815}
1816
[email protected]2533ce12009-05-09 00:02:241817void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1818 pending_window_rect_ = rect;
1819 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241820
bokan6b08cd22016-10-05 00:55:211821 // Popups don't get size updates back from the browser so just store the set
1822 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541823 if (popup_type_ != blink::kWebPopupTypeNone) {
1824 window_screen_rect_ = rect;
1825 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241826 }
[email protected]d4547452008-08-28 18:36:371827}
1828
wjmacleanee244e02017-05-26 21:06:071829void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1830 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071831 has_host_context_menu_location_ = true;
1832 host_context_menu_location_ = location;
1833 if (GetWebWidget()) {
1834 GetWebWidget()->ShowContextMenu(
1835 static_cast<blink::WebMenuSourceType>(source_type));
1836 }
1837 has_host_context_menu_location_ = false;
1838}
1839
[email protected]fa7b1dc2010-06-23 17:53:041840void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261841 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111842 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071843 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111844 int selection_start,
1845 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351846 if (!ShouldHandleImeEvents())
1847 return;
1848
brettw4b461082016-11-19 18:55:161849#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491850 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111851 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491852 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091853 return;
1854 }
1855#endif
[email protected]66fca5bc2013-05-23 06:58:291856 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011857 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011858 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541859 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111860 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561861 replacement_range.IsValid()
1862 ? WebRange(replacement_range.start(), replacement_range.length())
1863 : WebRange(),
1864 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041865 // If we failed to set the composition text, then we need to let the browser
1866 // process to cancel the input method's ongoing composition session, to make
1867 // sure we are in a consistent state.
Dave Tapuska139a72f2017-09-06 21:57:031868 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:051869 if (mojom::WidgetInputHandlerHost* host =
1870 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1871 host->ImeCancelComposition();
1872 }
Dave Tapuska139a72f2017-09-06 21:57:031873 } else {
1874 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1875 }
[email protected]7f00efa2010-04-15 05:01:261876 }
nonafa291792016-08-10 02:36:181877 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041878}
1879
rlanday7efe2302017-01-11 00:14:281880void RenderWidget::OnImeCommitText(
1881 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111882 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281883 const gfx::Range& replacement_range,
1884 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351885 if (!ShouldHandleImeEvents())
1886 return;
1887
brettw4b461082016-11-19 18:55:161888#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491889 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1890 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1891 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091892 return;
1893 }
1894#endif
[email protected]66fca5bc2013-05-23 06:58:291895 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391896 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261897 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541898 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111899 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561900 replacement_range.IsValid()
1901 ? WebRange(replacement_range.start(), replacement_range.length())
1902 : WebRange(),
1903 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261904 }
aelias87b8f7c2016-09-14 03:19:291905 input_handler_->set_handling_input_event(false);
1906 UpdateCompositionInfo(false /* not an immediate request */);
1907}
1908
1909void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351910 if (!ShouldHandleImeEvents())
1911 return;
1912
brettw4b461082016-11-19 18:55:161913#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491914 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1915 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291916 return;
1917 }
1918#endif
1919
changwan38c3eb612016-12-09 01:45:561920 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291921 return;
1922 ImeEventGuard guard(this);
1923 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011924 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541925 controller->FinishComposingText(
1926 keep_selection ? WebInputMethodController::kKeepSelection
1927 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011928 }
fsamuele8326c742016-01-12 00:49:391929 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181930 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291931}
1932
Christopher Camerone9a30c12018-03-07 08:23:381933void RenderWidget::UpdateSurfaceAndScreenInfo(
Christopher Cameronbe7ecea2018-02-27 00:47:191934 viz::LocalSurfaceId new_local_surface_id,
Christopher Cameronaad15a0d2018-03-09 03:47:331935 const gfx::Size& new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381936 const ScreenInfo& new_screen_info) {
1937 bool screen_info_changed = screen_info_ != new_screen_info;
1938 bool orientation_changed =
1939 screen_info_.orientation_angle != new_screen_info.orientation_angle ||
1940 screen_info_.orientation_type != new_screen_info.orientation_type;
1941 bool web_device_scale_factor_changed =
1942 screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
Christopher Cameronbe7ecea2018-02-27 00:47:191943
1944 local_surface_id_ = new_local_surface_id;
Christopher Cameronaad15a0d2018-03-09 03:47:331945 compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size;
Christopher Camerone9a30c12018-03-07 08:23:381946 screen_info_ = new_screen_info;
Christopher Cameronbe7ecea2018-02-27 00:47:191947
Christopher Camerone9a30c12018-03-07 08:23:381948 if (compositor_) {
1949 // Note carefully that the DSF specified in |new_screen_info| is not the
1950 // DSF used by the compositor during device emulation!
Christopher Cameronaad15a0d2018-03-09 03:47:331951 compositor_->SetViewportSizeAndScale(compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:381952 GetOriginalDeviceScaleFactor(),
1953 local_surface_id_);
1954 }
Christopher Cameronbe7ecea2018-02-27 00:47:191955
Christopher Camerone9a30c12018-03-07 08:23:381956 if (orientation_changed)
1957 OnOrientationChange();
Christopher Cameronbe7ecea2018-02-27 00:47:191958
Christopher Camerone9a30c12018-03-07 08:23:381959 if (screen_info_changed) {
1960 for (auto& observer : render_frame_proxies_)
1961 observer.OnScreenInfoChanged(screen_info_);
1962
1963 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
1964 for (auto& observer : browser_plugins_)
1965 observer.ScreenInfoChanged(screen_info_);
1966 }
1967
1968 if (web_device_scale_factor_changed)
Christopher Cameronbe7ecea2018-02-27 00:47:191969 UpdateWebViewWithDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331970}
1971
[email protected]0bc1f572013-04-17 01:46:311972void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121973 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211974 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121975 return;
1976
[email protected]0bc1f572013-04-17 01:46:311977 // Even if the browser provides an empty damage rect, it's still expecting to
1978 // receive a repaint ack so just damage the entire widget bounds.
1979 if (size_to_paint.IsEmpty()) {
1980 size_to_paint = size_;
1981 }
1982
[email protected]ec7dc112008-08-06 05:30:121983 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051984 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311985 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121986}
1987
[email protected]4873c7d2009-07-16 06:36:281988void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:401989 if (auto* frame = GetFocusedWebLocalFrameInWidget())
1990 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111991}
1992
[email protected]80ad8622012-11-07 16:33:031993void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1994 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511995 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391996 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1997 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511998 } else {
mfomitchev2600fd7c2016-02-17 20:53:391999 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:512000 }
[email protected]80ad8622012-11-07 16:33:032001 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
2002}
2003
lfgdb5c4ed2016-03-04 23:09:072004void RenderWidget::OnUpdateWindowScreenRect(
2005 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:212006 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:072007 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:212008 else
lfgdb5c4ed2016-03-04 23:09:072009 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:072010}
2011
kenrbea731792017-01-13 15:10:482012void RenderWidget::OnSetViewportIntersection(
2013 const gfx::Rect& viewport_intersection) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252014 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:122015 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:252016 frame_widget->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:482017 }
2018}
2019
kenrb04323782017-06-23 01:23:322020void RenderWidget::OnSetIsInert(bool inert) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252021 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:122022 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:252023 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:322024 }
2025}
2026
Ken Buchanan8a319fb2017-11-15 18:37:122027void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
2028 bool subtree_throttled) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252029 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:122030 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:252031 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:122032 }
2033}
2034
paulmeyer90f6c31d2016-11-12 00:17:592035void RenderWidget::OnDragTargetDragEnter(
2036 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:522037 const gfx::PointF& client_point,
2038 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592039 WebDragOperationsMask ops,
2040 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252041 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2042 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592043 return;
2044
Ehsan Karamadf3ca2a82018-01-20 01:05:252045 WebDragOperation operation = frame_widget->DragTargetDragEnter(
2046 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
2047 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592048
2049 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2050}
2051
Ella Ge80a52dce2017-11-15 18:01:522052void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
2053 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592054 WebDragOperationsMask ops,
2055 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252056 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2057 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592058 return;
2059
Ehsan Karamadf3ca2a82018-01-20 01:05:252060 WebDragOperation operation = frame_widget->DragTargetDragOver(
2061 ConvertWindowPointToViewport(client_point), screen_point, ops,
2062 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592063
2064 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
2065}
2066
Ella Ge80a52dce2017-11-15 18:01:522067void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
2068 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252069 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2070 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592071 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:252072
2073 frame_widget
2074
Blink Reformat1c4d759e2017-04-09 16:34:542075 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:172076 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:592077}
2078
2079void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:522080 const gfx::PointF& client_point,
2081 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:592082 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252083 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2084 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:592085 return;
2086
Ehsan Karamadf3ca2a82018-01-20 01:05:252087 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
2088 ConvertWindowPointToViewport(client_point),
2089 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:592090}
2091
Ella Ge80a52dce2017-11-15 18:01:522092void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
2093 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:212094 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:252095 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2096 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:212097 return;
2098
Ehsan Karamadf3ca2a82018-01-20 01:05:252099 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
2100 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:212101}
2102
2103void RenderWidget::OnDragSourceSystemDragEnded() {
2104 if (!GetWebWidget())
2105 return;
2106
Blink Reformat1c4d759e2017-04-09 16:34:542107 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:212108}
2109
Blink Reformat1c4d759e2017-04-09 16:34:542110void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:262111#if defined(OS_CHROMEOS)
2112 // On ChromeOS, virtual keyboard is triggered only when users leave the
2113 // mouse button or the finger and a text input element is focused at that
2114 // time. Focus event itself shouldn't trigger virtual keyboard.
2115 UpdateTextInputState();
2116#else
changwan75e3b2072017-01-16 02:55:002117 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:262118#endif
boliu7b2be2f2016-11-04 04:58:312119
2120// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
2121// virtual keyboard.
2122#if !defined(OS_ANDROID)
2123 FocusChangeComplete();
2124#endif
[email protected]0d1ebed12013-08-05 22:01:132125}
2126
fsamuel72464894f2015-12-15 06:59:312127ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:162128#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492129 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2130 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:092131#endif
ekaramad5aff1942017-01-06 01:26:352132 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:542133 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:312134 return ui::TEXT_INPUT_TYPE_NONE;
2135}
2136
nonafa291792016-08-10 02:36:182137void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
2138 if (!monitor_composition_info_ && !immediate_request)
2139 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:592140
nonafa291792016-08-10 02:36:182141 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
2142 gfx::Range range;
2143 std::vector<gfx::Rect> character_bounds;
2144
2145 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
2146 // Composition information is only available on editable node.
2147 range = gfx::Range::InvalidRange();
2148 } else {
2149 GetCompositionRange(&range);
2150 GetCompositionCharacterBounds(&character_bounds);
2151 }
2152
2153 if (!immediate_request &&
2154 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:312155 return;
nonafa291792016-08-10 02:36:182156 }
fsamuel72464894f2015-12-15 06:59:312157 composition_character_bounds_ = character_bounds;
2158 composition_range_ = range;
Dave Tapuska139a72f2017-09-06 21:57:032159 if (widget_input_handler_manager_) {
Dave Tapuska84c090502017-11-28 18:10:052160 if (mojom::WidgetInputHandlerHost* host =
2161 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
2162 host->ImeCompositionRangeChanged(composition_range_,
2163 composition_character_bounds_);
2164 }
Dave Tapuska139a72f2017-09-06 21:57:032165 } else {
2166 Send(new InputHostMsg_ImeCompositionRangeChanged(
2167 routing_id(), composition_range_, composition_character_bounds_));
2168 }
fsamuel72464894f2015-12-15 06:59:312169}
2170
Blink Reformat1c4d759e2017-04-09 16:34:542171void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:542172 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:462173 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332174 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542175 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462176 gfx::Rect window_rect =
2177 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2178 rect->x = window_rect.x();
2179 rect->y = window_rect.y();
2180 rect->width = window_rect.width();
2181 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542182 }
2183}
2184
Blink Reformat1c4d759e2017-04-09 16:34:542185void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:302186 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:182187 rect->x *= GetOriginalDeviceScaleFactor();
2188 rect->y *= GetOriginalDeviceScaleFactor();
2189 rect->width *= GetOriginalDeviceScaleFactor();
2190 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:302191 }
2192}
2193
changwan8c342742016-02-26 00:53:392194void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262195#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392196 DCHECK(!ime_event_guard_);
2197 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002198 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212199#endif
Dave Tapuska9db80842017-07-24 17:24:262200}
[email protected]105dffb42013-02-20 03:46:212201
ekaramadc9b70a72017-03-23 16:14:232202void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2203 bool monitor_updates) {
2204 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182205 if (!immediate_request)
2206 return;
2207 UpdateCompositionInfo(true /* immediate request */);
2208}
2209
[email protected]fcdc5642014-05-09 14:32:242210void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382211 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002212 // LocalRoot() might return null for provisional main frames. In this case,
2213 // the frame hasn't committed a navigation and is not swapped into the tree
2214 // yet, so it doesn't make sense to send orientation change events to it.
2215 //
2216 // TODO(https://crbug.com/578349): This check should be cleaned up
2217 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382218 if (frame_widget->LocalRoot())
2219 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302220 }
[email protected]fcdc5642014-05-09 14:32:242221}
2222
[email protected]bee16aab2009-08-26 15:55:032223void RenderWidget::SetHidden(bool hidden) {
2224 if (is_hidden_ == hidden)
2225 return;
2226
jdduke8fac9d102014-12-20 02:40:132227 // The status has changed. Tell the RenderThread about it and ensure
2228 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032229 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132230
Scott Violet1098538e2017-10-05 19:23:332231#if defined(USE_AURA)
Scott Violet8ff9c302018-02-22 22:28:352232 if (features::IsMusEnabled())
Scott Violet1098538e2017-10-05 19:23:332233 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2234#endif
2235
Saman Sami58ed4392018-01-31 20:54:192236 // RenderThreadImpl::current() could be null in tests.
2237 if (RenderThreadImpl::current()) {
2238 if (is_hidden_) {
2239 RenderThreadImpl::current()->WidgetHidden();
2240 first_update_visual_state_after_hidden_ = true;
2241 } else {
2242 RenderThreadImpl::current()->WidgetRestored();
2243 }
Lei Zhang9b359d32017-11-28 00:57:022244 }
alexclarke7fa93942015-10-21 15:37:112245
2246 if (render_widget_scheduling_state_)
2247 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032248}
2249
[email protected]2b624c562011-10-27 22:58:262250void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212251 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262252 return;
2253
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122254 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542255 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262256 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542257 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262258 }
[email protected]2b624c562011-10-27 22:58:262259}
2260
[email protected]674741932009-02-04 23:44:462261bool RenderWidget::next_paint_is_resize_ack() const {
Fady Samuelcc3e3b4a2017-10-03 02:09:212262 return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack(
2263 next_paint_flags_);
[email protected]674741932009-02-04 23:44:462264}
2265
[email protected]674741932009-02-04 23:44:462266void RenderWidget::set_next_paint_is_resize_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212267 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462268}
2269
[email protected]674741932009-02-04 23:44:462270void RenderWidget::set_next_paint_is_repaint_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212271 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462272}
2273
Saman Samif7731342018-01-24 22:18:442274void RenderWidget::reset_next_paint_is_resize_ack() {
2275 DCHECK(next_paint_is_resize_ack());
2276 next_paint_flags_ ^= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
2277}
2278
changwanf2a707b2015-10-30 08:22:162279void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2280 if (!ime_event_guard_)
2281 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292282}
2283
changwanf2a707b2015-10-30 08:22:162284void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2285 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002286 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162287 return;
2288 }
2289 ime_event_guard_ = nullptr;
2290
[email protected]66fca5bc2013-05-23 06:58:292291 // While handling an ime event, text input state and selection bounds updates
2292 // are ignored. These must explicitly be updated once finished handling the
2293 // ime event.
2294 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472295#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002296 if (guard->show_virtual_keyboard())
2297 ShowVirtualKeyboard();
2298 else
2299 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472300#endif
[email protected]66fca5bc2013-05-23 06:58:292301}
2302
[email protected]7c8873e2013-02-05 08:03:012303void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162304#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492305 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092306 // TODO(kinaba) http://crbug.com/101101
2307 // Current Pepper IME API does not handle selection bounds. So we simply
2308 // use the caret position as an empty range for now. It will be updated
2309 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492310 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542311 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092312 *focus = caret;
2313 *anchor = caret;
2314 return;
2315 }
2316#endif
[email protected]7c8873e2013-02-05 08:03:012317 WebRect focus_webrect;
2318 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542319 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2320 ConvertViewportToWindow(&focus_webrect);
2321 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242322 *focus = focus_webrect;
2323 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322324}
2325
[email protected]e99ef6f2011-10-16 01:13:002326void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082327 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212328 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002329 return;
changwanf2a707b2015-10-30 08:22:162330 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292331 return;
[email protected]e99ef6f2011-10-16 01:13:002332
mohsenb0eeba72015-08-09 06:20:082333#if defined(USE_AURA)
2334 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2335 // Aura beucause composited selection updates are not working for webview tags
2336 // which regresses IME inside webview. Remove this when composited selection
2337 // updates are fixed for webviews. See, http://crbug.com/510568.
2338 bool send_ipc = true;
2339#else
jddukeacf809e2014-09-23 20:38:382340 // With composited selection updates, the selection bounds will be reported
2341 // directly by the compositor, in which case explicit IPC selection
2342 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082343 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542344 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082345#endif
2346 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382347 ViewHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402348 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382349 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2350 if (selection_anchor_rect_ != params.anchor_rect ||
2351 selection_focus_rect_ != params.focus_rect) {
2352 selection_anchor_rect_ = params.anchor_rect;
2353 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402354 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2355 focused_frame->SelectionTextDirection(params.focus_dir,
2356 params.anchor_dir);
2357 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2358 }
jddukeacf809e2014-09-23 20:38:382359 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2360 }
[email protected]58b48a0d2012-06-13 07:01:352361 }
jddukeacf809e2014-09-23 20:38:382362
nonafa291792016-08-10 02:36:182363 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002364}
2365
lfgb00fcad2016-07-14 14:16:332366void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2367 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542368 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332369 if (size_.width() != new_size_in_window.width ||
2370 size_.height() != new_size_in_window.height) {
2371 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2372
2373 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542374 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2375 size_.height());
lfgb00fcad2016-07-14 14:16:332376 view_screen_rect_ = new_pos;
2377 window_screen_rect_ = new_pos;
2378 }
2379
Christopher Camerone9a30c12018-03-07 08:23:382380 // TODO(ccameron): Note that this destroys any information differentiating
Christopher Cameronaad15a0d2018-03-09 03:47:332381 // |size_| from |compositor_viewport_pixel_size_|. Also note that the
2382 // calculation of |new_compositor_viewport_pixel_size| does not appear to
2383 // take into account device emulation.
2384 gfx::Size new_compositor_viewport_pixel_size =
Christopher Camerone9a30c12018-03-07 08:23:382385 gfx::ScaleToCeiledSize(size_, GetWebDeviceScaleFactor());
Christopher Cameronaad15a0d2018-03-09 03:47:332386 UpdateSurfaceAndScreenInfo(viz::LocalSurfaceId(),
2387 new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:382388 screen_info_);
lfgb00fcad2016-07-14 14:16:332389
Fady Samuel319e429c2017-10-02 18:31:552390 if (!resizing_mode_selector_->is_synchronous_mode()) {
Fady Samueld10aadd82017-11-03 18:23:572391 need_resize_ack_for_auto_resize_ = true;
Fady Samuel319e429c2017-10-02 18:31:552392 // If surface synchronization is off, then ResizeAcks go to the browser in
2393 // response to a DidReceiveCompositorFrame. With surface synchronization
2394 // on, that notification will not arrive here because the compositor is
2395 // deferring commits and thus submission of CompositorFrames.
2396 if (!size_.IsEmpty() && compositor_ &&
Fady Samuel1ee6fb5c2018-02-16 03:27:462397 compositor_->IsSurfaceSynchronizationEnabled() &&
2398 !auto_resize_ack_callback_.callback()) {
2399 auto_resize_ack_callback_.Reset(
2400 base::BindOnce(&RenderWidget::DidResizeOrRepaintAck,
2401 weak_ptr_factory_.GetWeakPtr()));
2402 base::ThreadTaskRunnerHandle::Get()->PostTask(
2403 FROM_HERE, auto_resize_ack_callback_.callback());
Fady Samuel319e429c2017-10-02 18:31:552404 }
2405 }
lfgb00fcad2016-07-14 14:16:332406 }
2407}
2408
[email protected]58b48a0d2012-06-13 07:01:352409void RenderWidget::GetCompositionCharacterBounds(
2410 std::vector<gfx::Rect>* bounds) {
2411 DCHECK(bounds);
2412 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092413
brettw4b461082016-11-19 18:55:162414#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492415 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092416 return;
2417#endif
2418
Ehsan Karamad4975af6d2018-02-09 16:58:162419 blink::WebInputMethodController* controller = GetInputMethodController();
2420 if (!controller)
ekaramad2a46d632016-07-19 13:33:092421 return;
2422 blink::WebVector<blink::WebRect> bounds_from_blink;
Ehsan Karamad4975af6d2018-02-09 16:58:162423 if (!controller->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092424 return;
2425
2426 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542427 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092428 bounds->push_back(bounds_from_blink[i]);
2429 }
[email protected]58b48a0d2012-06-13 07:01:352430}
2431
[email protected]db4fc1e2013-09-06 20:01:512432void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162433#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492434 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092435 return;
2436#endif
EhsanKcdee7b72017-11-08 21:30:092437 blink::WebInputMethodController* controller = GetInputMethodController();
2438 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542439 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212440 *range = gfx::Range::InvalidRange();
2441 return;
[email protected]88dbe32f2013-06-20 23:31:362442 }
Blink Reformat1c4d759e2017-04-09 16:34:542443 range->set_start(web_range.StartOffset());
2444 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362445}
2446
[email protected]501ea13d2013-07-09 17:03:292447bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512448 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292449 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082450 if (!range.IsValid())
2451 return false;
[email protected]501ea13d2013-07-09 17:03:292452 if (composition_range_ != range)
2453 return true;
2454 if (bounds.size() != composition_character_bounds_.size())
2455 return true;
2456 for (size_t i = 0; i < bounds.size(); ++i) {
2457 if (bounds[i] != composition_character_bounds_[i])
2458 return true;
2459 }
2460 return false;
2461}
[email protected]501ea13d2013-07-09 17:03:292462
[email protected]ad26ef42011-06-17 07:59:452463bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162464#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492465 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2466 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092467#endif
[email protected]ad26ef42011-06-17 07:59:452468 return true;
[email protected]56ea1a62011-05-30 07:05:572469}
2470
Blink Reformat1c4d759e2017-04-09 16:34:542471blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272472 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542473 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542474 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272475 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542476 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2477 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272478 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542479 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272480 switch (screen_info_.orientation_type) {
2481 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542482 web_screen_info.orientation_type =
2483 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272484 break;
2485 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542486 web_screen_info.orientation_type =
2487 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272488 break;
2489 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542490 web_screen_info.orientation_type =
2491 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272492 break;
2493 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542494 web_screen_info.orientation_type =
2495 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272496 break;
2497 default:
Blink Reformat1c4d759e2017-04-09 16:34:542498 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272499 break;
2500 }
Blink Reformat1c4d759e2017-04-09 16:34:542501 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202502
ccameron2f451532016-09-07 21:49:272503 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282504}
2505
Donn Denman3c1267c62018-03-08 22:08:592506#if defined(OS_ANDROID)
2507void RenderWidget::ShowUnhandledTapUIIfNeeded(
2508 const WebTappedInfo& tapped_info) {
2509 // Unpack tapped_info. TODO(donnd): inline unpacking.
2510 bool page_changed = tapped_info.PageChanged();
2511 const WebNode& tapped_node = tapped_info.GetNode();
2512 const WebPoint& tapped_position = tapped_info.Position();
2513 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2514 !tapped_node.IsContentEditable() &&
2515 !tapped_node.IsInsideFocusableElementOrARIAWidget();
2516 if (should_trigger) {
2517 float x_px = IsUseZoomForDSFEnabled()
2518 ? tapped_position.x
2519 : tapped_position.x * GetWebDeviceScaleFactor();
2520 float y_px = IsUseZoomForDSFEnabled()
2521 ? tapped_position.y
2522 : tapped_position.y * GetWebDeviceScaleFactor();
2523 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_, x_px, y_px));
2524 }
2525}
2526#endif
2527
Blink Reformat1c4d759e2017-04-09 16:34:542528void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2529 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022530#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562531 if (event_cancelled)
2532 return;
Blink Reformat1c4d759e2017-04-09 16:34:542533 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002534 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542535 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212536 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352537 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542538 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002539 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462540 else
changwan75e3b2072017-01-16 02:55:002541 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562542 }
ekaramada110f642016-12-21 19:47:282543// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2544// crbug/420130.
2545#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542546 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282547 return;
2548
2549 // TODO(estade): hit test the event against focused node to make sure
2550 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352551 blink::WebInputMethodController* controller = GetInputMethodController();
2552 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542553 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282554
2555 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542556 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282557#endif
[email protected]c68c3e4e2013-01-24 00:36:562558#endif
2559}
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,
Sandra Sun2288e8532017-11-30 22:50:162566 const blink::WebOverscrollBehavior& 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
[email protected]7912e822014-04-16 02:37:032578void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392579 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542580 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032581}
2582
[email protected]24ed0432013-04-24 07:50:312583RenderWidgetCompositor* RenderWidget::compositor() const {
2584 return compositor_.get();
2585}
2586
fsamuel72464894f2015-12-15 06:59:312587void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392588 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372589}
[email protected]c3d45532011-10-07 19:20:402590
Blink Reformat1c4d759e2017-04-09 16:34:542591void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112592 if (render_widget_scheduling_state_)
2593 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552594 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2595}
2596
Dave Tapuskadfe486c12017-06-09 16:53:132597void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2598 if (input_event_queue_)
2599 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2600}
2601
Dave Tapuskabafc2ba32017-11-28 01:54:372602void RenderWidget::RequestUnbufferedInputEvents() {
2603 if (input_event_queue_)
2604 input_event_queue_->RequestUnbufferedInputEvents();
2605}
2606
xidachenfa0199e72017-05-11 11:34:262607void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262608 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512609 return;
2610
Dave Tapuska139a72f2017-09-06 21:57:032611 if (widget_input_handler_manager_) {
2612 widget_input_handler_manager_->ProcessTouchAction(touch_action);
2613 } else {
2614 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
2615 }
[email protected]5d0bbdfa92013-12-10 00:35:512616}
2617
[email protected]e3244ed2014-06-20 20:04:272618void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2619 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162620}
2621
[email protected]e3244ed2014-06-20 20:04:272622void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2623 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162624}
2625
[email protected]de3c5d82014-05-28 22:12:592626void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2627 render_frames_.AddObserver(frame);
2628}
2629
2630void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2631 render_frames_.RemoveObserver(frame);
2632}
2633
Saman Samid189e5dfd2017-12-20 22:55:312634void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2635 browser_plugins_.AddObserver(browser_plugin);
2636}
2637
2638void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2639 browser_plugins_.RemoveObserver(browser_plugin);
2640}
2641
lfg43e08e62016-02-03 18:51:372642void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2643 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2644 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2645}
2646
Christopher Camerone9a30c12018-03-07 08:23:382647float RenderWidget::GetWebDeviceScaleFactor() const {
2648 return screen_info_.device_scale_factor;
2649}
2650
oshima50872a72016-03-04 13:26:182651float RenderWidget::GetOriginalDeviceScaleFactor() const {
Christopher Camerone9a30c12018-03-07 08:23:382652 return screen_metrics_emulator_
2653 ? screen_metrics_emulator_->original_screen_info()
2654 .device_scale_factor
2655 : screen_info_.device_scale_factor;
oshima50872a72016-03-04 13:26:182656}
2657
Ella Ge80a52dce2017-11-15 18:01:522658gfx::PointF RenderWidget::ConvertWindowPointToViewport(
2659 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:592660 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542661 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:522662 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
2663}
2664
2665gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
2666 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:592667}
2668
Blink Reformat1c4d759e2017-04-09 16:34:542669bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212670 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2671}
2672
Blink Reformat1c4d759e2017-04-09 16:34:542673void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212674 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2675}
2676
Blink Reformat1c4d759e2017-04-09 16:34:542677bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212678 return mouse_lock_dispatcher_->IsMouseLockedTo(
2679 webwidget_mouse_lock_target_.get());
2680}
2681
Blink Reformat1c4d759e2017-04-09 16:34:542682void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582683 const WebDragData& data,
2684 WebDragOperationsMask mask,
2685 const WebImage& image,
2686 const WebPoint& webImageOffset) {
2687 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542688 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582689 DropData drop_data(DropDataBuilder::Build(data));
2690 drop_data.referrer_policy = policy;
2691 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592692 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542693 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582694 possible_drag_event_info_));
2695}
2696
kenrb5d78b842017-03-06 21:06:012697uint32_t RenderWidget::GetContentSourceId() {
2698 return current_content_source_id_;
2699}
2700
Saman Samif7731342018-01-24 22:18:442701void RenderWidget::DidNavigate() {
2702 if (!compositor_)
2703 return;
2704 compositor_->SetContentSourceId(++current_content_source_id_);
Christopher Cameronbe7ecea2018-02-27 00:47:192705
Christopher Cameronaad15a0d2018-03-09 03:47:332706 UpdateSurfaceAndScreenInfo(viz::LocalSurfaceId(),
2707 compositor_viewport_pixel_size_, screen_info_);
Christopher Cameronbe7ecea2018-02-27 00:47:192708
Saman Samif7731342018-01-24 22:18:442709 // If surface synchronization is on, navigation implicitly acks any resize
2710 // that has happened so far so we can get the next ResizeParams containing the
2711 // LocalSurfaceId that should be used after navigation.
2712 if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ &&
2713 next_paint_is_resize_ack()) {
2714 reset_next_paint_is_resize_ack();
2715 }
kenrb5d78b842017-03-06 21:06:012716}
2717
lfg8ff33912016-09-13 20:59:212718blink::WebWidget* RenderWidget::GetWebWidget() const {
2719 return webwidget_internal_;
2720}
2721
ekaramad2daaf672016-11-10 20:29:012722blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2723 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382724 if (auto* frame_widget = GetFrameWidget())
2725 return frame_widget->GetActiveWebInputMethodController();
2726
2727 return nullptr;
ekaramad2daaf672016-11-10 20:29:012728}
2729
Dave Tapuska139a72f2017-09-06 21:57:032730void RenderWidget::SetupWidgetInputHandler(
2731 mojom::WidgetInputHandlerRequest request,
2732 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:472733 widget_input_handler_manager_->AddInterface(std::move(request),
2734 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502735}
2736
Dave Tapuska485aca92017-08-08 00:47:582737void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2738 // Close the old binding if there was one.
2739 // A RenderWidgetHost should not need more than one channel.
2740 widget_binding_.Close();
2741 widget_binding_.Bind(std::move(request));
2742}
2743
Fady Samuelcc3e3b4a2017-10-03 02:09:212744void RenderWidget::DidResizeOrRepaintAck() {
Fady Samueld10aadd82017-11-03 18:23:572745 if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_)
Fady Samuel319e429c2017-10-02 18:31:552746 return;
2747
Fady Samuelcc3e3b4a2017-10-03 02:09:212748 ViewHostMsg_ResizeOrRepaint_ACK_Params params;
Fady Samuel319e429c2017-10-02 18:31:552749 params.view_size = size_;
2750 params.flags = next_paint_flags_;
2751 params.sequence_number = ++resize_or_repaint_ack_num_;
2752
Fady Samuelcc3e3b4a2017-10-03 02:09:212753 Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params));
Fady Samuel319e429c2017-10-02 18:31:552754 next_paint_flags_ = 0;
Fady Samueld10aadd82017-11-03 18:23:572755 need_resize_ack_for_auto_resize_ = false;
Fady Samuel319e429c2017-10-02 18:31:552756}
2757
Khushal3e96e662017-10-30 23:16:502758void RenderWidget::UpdateURLForCompositorUkm() {
2759 DCHECK(compositor_);
Ehsan Karamad655d7b8a2018-01-12 18:38:382760 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2761 if (!frame_widget)
Khushal3e96e662017-10-30 23:16:502762 return;
2763
Ehsan Karamad655d7b8a2018-01-12 18:38:382764 auto* render_frame = RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
Khushal3e96e662017-10-30 23:16:502765 if (!render_frame->IsMainFrame())
2766 return;
2767
2768 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2769}
2770
EhsanK955ba582017-11-30 21:14:402771blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382772 if (auto* frame_widget = GetFrameWidget())
2773 return frame_widget->FocusedWebLocalFrameInWidget();
2774 return nullptr;
EhsanK955ba582017-11-30 21:14:402775}
2776
EhsanK22d482e2017-08-10 17:29:492777#if BUILDFLAG(ENABLE_PLUGINS)
2778PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382779 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2780 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:492781 return nullptr;
2782
2783 // Focused pepper instance might not always be in the focused frame. For
2784 // instance if a pepper instance and its embedder frame are focused an then
2785 // another frame takes focus using javascript, the embedder frame will no
2786 // longer be focused while the pepper instance is (the embedder frame's
2787 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2788 // is fullscreen, clicking into the pepper will not refocus the embedder
2789 // frame. This is why we have to traverse the whole frame tree to find the
2790 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:382791 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:492792 while (current_frame) {
2793 RenderFrameImpl* render_frame =
2794 current_frame->IsWebLocalFrame()
2795 ? RenderFrameImpl::FromWebFrame(current_frame)
2796 : nullptr;
2797 if (render_frame && render_frame->focused_pepper_plugin())
2798 return render_frame->focused_pepper_plugin();
2799 current_frame = current_frame->TraverseNext();
2800 }
2801 return nullptr;
2802}
2803#endif
2804
[email protected]e9ff79c2012-10-19 21:31:262805} // namespace content