blob: 9b6b9a586c8bc2b36961c37f9f20d2c917268a34 [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"
oshima750cb4342015-10-31 00:59:0132#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5833#include "content/common/drag_event_source_info.h"
34#include "content/common/drag_messages.h"
[email protected]c084330e02013-04-27 01:08:1535#include "content/common/input_messages.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"
mlamouriafca06dd2017-01-27 23:35:1846#include "content/public/renderer/content_renderer_client.h"
Fady Samuel85a1bf72017-10-27 14:30:2047#include "content/renderer/browser_plugin/browser_plugin_manager.h"
[email protected]953bd0062013-08-01 00:58:4048#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3949#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5850#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5151#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1153#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2854#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2955#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1356#include "content/renderer/input/input_handler_manager.h"
dtapuska9ec1a912017-04-21 15:18:3157#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2658#include "content/renderer/input/widget_input_handler_manager.h"
Scott Violet1098538e2017-10-05 19:23:3359#include "content/renderer/mash_util.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"
brettw4b461082016-11-19 18:55:1671#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4872#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2573#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1874#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5975#include "third_party/WebKit/public/platform/WebDragData.h"
76#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5577#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1178#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3079#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3080#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3081#include "third_party/WebKit/public/platform/WebSize.h"
82#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5183#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
84#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2985#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4386#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5987#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0188#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5989#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1190#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3191#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
93#include "third_party/WebKit/public/web/WebRange.h"
Donn Denman43a439e2017-08-29 04:20:4594#include "third_party/WebKit/public/web/WebTappedInfo.h"
kenrba7199832015-01-22 23:44:5995#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0896#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4197#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5998#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:1399#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:43100#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50101#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09102#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32103#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48104#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27105#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41106#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48107
[email protected]eeb93112013-05-01 19:41:10108#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15109#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24110#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10111#endif
112
[email protected]661eb9d2009-02-03 02:11:48113#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52114#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41115#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48116#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44117
sadrul943e3b32016-08-04 18:22:59118#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10119#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19120#endif
121
ekaramad330ba4232016-09-23 17:57:47122#if defined(OS_MACOSX)
123#include "content/renderer/text_input_client_observer.h"
124#endif
125
Ryan Landay9e42fd742017-08-12 01:59:11126using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46127using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43128using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59129using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58130using blink::WebDragOperationsMask;
131using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59132using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46133using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58134using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46135using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49136using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01137using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58138using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46139using blink::WebMouseEvent;
140using blink::WebMouseWheelEvent;
141using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11142using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46143using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11144using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46145using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48146using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46147using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46148using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59149using blink::WebString;
Donn Denman43a439e2017-08-29 04:20:45150using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46151using blink::WebTextDirection;
152using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25153using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46154using blink::WebVector;
155using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26156
paulmeyer90f6c31d2016-11-12 00:17:59157namespace content {
158
[email protected]6a4d7f62013-01-07 21:32:13159namespace {
[email protected]b256eca2013-07-11 10:57:40160
161typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
162
AJITH KUMAR V041c0b02017-08-08 10:39:20163static const int kInvalidNextPreviousFlagsValue = -1;
164
lfgbee1e0a2016-06-08 21:24:21165class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
166 public:
167 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
168 : webwidget_(webwidget) {}
169
170 void OnLockMouseACK(bool succeeded) override {
171 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54172 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21173 else
Blink Reformat1c4d759e2017-04-09 16:34:54174 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21175 }
176
Blink Reformat1c4d759e2017-04-09 16:34:54177 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21178
179 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
180 // The WebWidget handles mouse lock in Blink's handleInputEvent().
181 return false;
182 }
183
184 private:
185 blink::WebWidget* webwidget_;
186};
187
dglazkov97b6c2b2016-10-25 17:35:55188bool IsDateTimeInput(ui::TextInputType type) {
189 return type == ui::TEXT_INPUT_TYPE_DATE ||
190 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
191 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
192 type == ui::TEXT_INPUT_TYPE_MONTH ||
193 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
194}
195
paulmeyer90f6c31d2016-11-12 00:17:59196WebDragData DropMetaDataToWebDragData(
197 const std::vector<DropData::Metadata>& drop_meta_data) {
198 std::vector<WebDragData::Item> item_list;
199 for (const auto& meta_data_item : drop_meta_data) {
200 if (meta_data_item.kind == DropData::Kind::STRING) {
201 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54202 item.storage_type = WebDragData::Item::kStorageTypeString;
203 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59204 // Have to pass a dummy URL here instead of an empty URL because the
205 // DropData received by browser_plugins goes through a round trip:
206 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
207 // will contain an empty URL (which means no URL is dragged) if the URL in
208 // WebDragData is empty.
209 if (base::EqualsASCII(meta_data_item.mime_type,
210 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54211 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59212 }
213 item_list.push_back(item);
214 continue;
215 }
216
217 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
218 // just the mimetype. This is needed to drag files to WebView on Android
219 // platform.
220 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
221 !meta_data_item.filename.empty()) {
222 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54223 item.storage_type = WebDragData::Item::kStorageTypeFilename;
224 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59225 item_list.push_back(item);
226 continue;
227 }
228
229 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
230 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54231 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
232 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59233 item_list.push_back(item);
234 continue;
235 }
236 }
237
238 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54239 result.Initialize();
240 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59241 return result;
242}
243
244WebDragData DropDataToWebDragData(const DropData& drop_data) {
245 std::vector<WebDragData::Item> item_list;
246
247 // These fields are currently unused when dragging into WebKit.
248 DCHECK(drop_data.download_metadata.empty());
249 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23250 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59251
252 if (!drop_data.text.is_null()) {
253 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54254 item.storage_type = WebDragData::Item::kStorageTypeString;
255 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
256 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59257 item_list.push_back(item);
258 }
259
260 if (!drop_data.url.is_empty()) {
261 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54262 item.storage_type = WebDragData::Item::kStorageTypeString;
263 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
264 item.string_data = WebString::FromUTF8(drop_data.url.spec());
265 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59266 item_list.push_back(item);
267 }
268
269 if (!drop_data.html.is_null()) {
270 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54271 item.storage_type = WebDragData::Item::kStorageTypeString;
272 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
273 item.string_data = WebString::FromUTF16(drop_data.html.string());
274 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59275 item_list.push_back(item);
276 }
277
278 for (std::vector<ui::FileInfo>::const_iterator it =
279 drop_data.filenames.begin();
280 it != drop_data.filenames.end();
281 ++it) {
282 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54283 item.storage_type = WebDragData::Item::kStorageTypeFilename;
284 item.filename_data = blink::FilePathToWebString(it->path);
285 item.display_name_data =
kinukoa4293022017-01-27 06:43:25286 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59287 item_list.push_back(item);
288 }
289
290 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
291 drop_data.file_system_files.begin();
292 it != drop_data.file_system_files.end();
293 ++it) {
294 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54295 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
296 item.file_system_url = it->url;
297 item.file_system_file_size = it->size;
298 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59299 item_list.push_back(item);
300 }
301
Stuart Langley48300392017-11-02 03:54:44302 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59303 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54304 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44305 item.string_type = WebString::FromUTF16(it.first);
306 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59307 item_list.push_back(item);
308 }
309
310 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54311 result.Initialize();
312 result.SetItems(item_list);
313 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59314 return result;
315}
316
lfg1568d112016-08-30 16:06:29317content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
318 nullptr;
319
320content::RenderWidget::RenderWidgetInitializedCallback
321 g_render_widget_initialized = nullptr;
322
dtapuskac4dd5be2016-10-25 15:11:10323ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
324 // Check the type is in the range representable by ui::TextInputType.
325 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
326 << "blink::WebTextInputType and ui::TextInputType not synchronized";
327 return static_cast<ui::TextInputType>(type);
328}
329
330ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
331 // Check the mode is in the range representable by ui::TextInputMode.
332 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
333 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
334 return static_cast<ui::TextInputMode>(mode);
335}
336
[email protected]b256eca2013-07-11 10:57:40337} // namespace
338
[email protected]b2e4c70132013-10-03 02:07:51339// RenderWidget ---------------------------------------------------------------
340
nick8331f8ad2016-11-15 20:42:45341RenderWidget::RenderWidget(int32_t widget_routing_id,
342 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36343 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27344 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04345 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03346 bool hidden,
Dave Tapuska1bdf1832017-07-07 18:07:19347 bool never_visible,
348 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45349 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36350 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21351 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44352 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29353 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51354 auto_resize_mode_(false),
Fady Samueld10aadd82017-11-03 18:23:57355 need_resize_ack_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29356 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04357 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39358 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12359 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54360 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16361 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48362 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22363 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44364 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20365 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55366 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40367 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20368 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20369 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53370 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18371 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12372 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48373 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04374 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27375 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18376 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51377 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12378 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42379 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08380 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24381 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09382 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47383#if defined(OS_MACOSX)
384 text_input_client_observer_(new TextInputClientObserver(this)),
385#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27386 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50387 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01388 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19389 widget_binding_(this, std::move(widget_request)),
wjmaclean1d970622017-01-21 22:28:24390 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45391 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05392 if (!swapped_out)
393 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27394 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11395
396 // In tests there may not be a RenderThreadImpl.
397 if (RenderThreadImpl::current()) {
398 render_widget_scheduling_state_ = RenderThreadImpl::current()
399 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32400 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11401 render_widget_scheduling_state_->SetHidden(is_hidden_);
402 }
sadrul602ce1362017-01-26 06:41:10403#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14404 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Scott Violet1098538e2017-10-05 19:23:33405 if (IsRunningInMash())
406 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10407#endif
initial.commit09911bf2008-07-26 23:55:29408}
409
410RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21411 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16412
dtapuska9ec1a912017-04-21 15:18:31413 if (input_event_queue_)
414 input_event_queue_->ClearClient();
415
[email protected]992db4c2011-05-12 15:37:15416 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02417 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15418 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11419#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14420 // It is possible for a RenderWidget to be destroyed before it was embedded
421 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
422 // explicitly delete it here.
423 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11424#endif
initial.commit09911bf2008-07-26 23:55:29425}
426
[email protected]484955942010-08-19 16:13:18427// static
lfg1568d112016-08-30 16:06:29428void RenderWidget::InstallCreateHook(
429 CreateRenderWidgetFunction create_render_widget,
430 RenderWidgetInitializedCallback render_widget_initialized) {
431 CHECK(!g_create_render_widget && !g_render_widget_initialized);
432 g_create_render_widget = create_render_widget;
433 g_render_widget_initialized = render_widget_initialized;
434}
435
436// static
nickf7b38222016-11-22 21:59:35437RenderWidget* RenderWidget::CreateForPopup(
438 RenderViewImpl* opener,
439 CompositorDependencies* compositor_deps,
440 blink::WebPopupType popup_type,
441 const ScreenInfo& screen_info) {
Dave Tapuska1bdf1832017-07-07 18:07:19442 mojom::WidgetPtr widget_channel;
443 mojom::WidgetRequest widget_channel_request =
444 mojo::MakeRequest(&widget_channel);
445
nick4df698d82016-11-11 20:39:23446 // Do a synchronous IPC to obtain a routing ID.
447 int32_t routing_id = MSG_ROUTING_NONE;
448 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19449 opener->GetRoutingID(), popup_type, std::move(widget_channel),
450 &routing_id)) {
nick4df698d82016-11-11 20:39:23451 return nullptr;
452 }
453
nick8331f8ad2016-11-15 20:42:45454 scoped_refptr<RenderWidget> widget(
455 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
Dave Tapuska1bdf1832017-07-07 18:07:19456 false, false, false, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35457 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24458 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35459 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23460 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
461 return widget.get();
initial.commit09911bf2008-07-26 23:55:29462}
463
[email protected]484955942010-08-19 16:13:18464// static
kenrba7199832015-01-22 23:44:59465RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23466 int widget_routing_id,
kenrba7199832015-01-22 23:44:59467 bool hidden,
ccameron2f451532016-09-07 21:49:27468 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59469 CompositorDependencies* compositor_deps,
470 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23471 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55472 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
473 // same routing ID for both the view routing ID and the main frame widget
474 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23475 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55476 if (view) {
avi8a45c1092016-03-01 16:12:34477 view->AttachWebFrameWidget(
478 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
479 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55480 }
dcheng35d31c112015-07-22 00:17:36481 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29482 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45483 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54484 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45485 hidden, false)
486 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54487 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45488 hidden, false));
simonhong628f9812015-04-27 23:13:20489 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23490 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59491 // this function returns.
nickf7b38222016-11-22 21:59:35492 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23493 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
494
495 if (g_render_widget_initialized)
496 g_render_widget_initialized(widget.get());
497 return widget.get();
kenrba7199832015-01-22 23:44:59498}
499
500// static
lfgcaab5142016-02-26 19:06:52501blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08502 RenderWidget* render_widget,
503 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54504 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08505}
506
507// static
kenrba7199832015-01-22 23:44:59508blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18509 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54510 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18511 break;
Blink Reformat1c4d759e2017-04-09 16:34:54512 case blink::kWebPopupTypePage:
513 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18514 default:
515 NOTREACHED();
516 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28517 return nullptr;
[email protected]484955942010-08-19 16:13:18518}
519
dchengda9b4bb2015-07-20 20:58:08520void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32521 OnClose();
kenrba7199832015-01-22 23:44:59522}
523
alexmos78c9c0d2016-10-14 18:57:03524void RenderWidget::SetSwappedOut(bool is_swapped_out) {
525 // We should only toggle between states.
526 DCHECK(is_swapped_out_ != is_swapped_out);
527 is_swapped_out_ = is_swapped_out;
528
529 // If we are swapping out, we will call ReleaseProcess, allowing the process
530 // to exit if all of its RenderViews are swapped out. We wait until the
531 // WasSwappedOut call to do this, to allow the unload handler to finish.
532 // If we are swapping in, we call AddRefProcess to prevent the process from
533 // exiting.
534 if (!is_swapped_out_)
535 RenderProcess::current()->AddRefProcess();
536}
537
nickf7b38222016-11-22 21:59:35538void RenderWidget::Init(const ShowCallback& show_callback,
539 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21540 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23541 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29542
Jeremy Roman04f27c372017-10-27 15:20:55543 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45544
Dave Tapuska9db80842017-07-24 17:24:26545 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
546 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
547
Dave Tapuska525eb15e2017-08-17 21:05:50548 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
Dave Tapuska139a72f2017-09-06 21:57:03549 weak_ptr_factory_.GetWeakPtr(),
Dave Tapuska9db80842017-07-24 17:24:26550 render_thread_impl && compositor_
551 ? render_thread_impl->compositor_task_runner()
552 : nullptr,
553 render_thread_impl ? render_thread_impl->GetRendererScheduler()
554 : nullptr);
555 }
556
nickf7b38222016-11-22 21:59:35557 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29558
lfg8ff33912016-09-13 20:59:21559 webwidget_internal_ = web_widget;
560 webwidget_mouse_lock_target_.reset(
561 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21562 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29563
nick4df698d82016-11-11 20:39:23564 RenderThread::Get()->AddRoute(routing_id_, this);
565 // Take a reference on behalf of the RenderThread. This will be balanced
566 // when we receive ViewMsg_Close.
567 AddRef();
568 if (RenderThreadImpl::current()) {
569 RenderThreadImpl::current()->WidgetCreated();
570 if (is_hidden_)
571 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29572 }
573}
574
[email protected]949b6592014-08-20 13:17:52575void RenderWidget::WasSwappedOut() {
576 // If we have been swapped out and no one else is using this process,
577 // it's safe to exit now.
578 CHECK(is_swapped_out_);
579 RenderProcess::current()->ReleaseProcess();
580}
581
[email protected]b2e4c70132013-10-03 02:07:51582void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39583 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51584 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43585 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00586 popup_screen_origin_for_emulation_ =
587 gfx::Point(emulator->original_screen_rect().origin().x(),
588 emulator->original_screen_rect().origin().y());
[email protected]5f75aa42014-04-01 23:00:56589 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27590 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51591}
592
[email protected]2d6836f42014-07-02 17:25:31593gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
594 if (screen_metrics_emulator_)
595 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
596 return anchor;
597}
598
thakis18e426412017-03-15 12:06:37599#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51600void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39601 ExternalPopupMenu* popup,
602 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00603 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51604}
[email protected]53907862014-03-25 15:42:40605#endif
[email protected]b2e4c70132013-10-03 02:07:51606
607void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
608 if (screen_metrics_emulator_)
609 screen_metrics_emulator_->OnShowContextMenu(params);
610}
611
[email protected]a95986a82010-12-24 06:19:28612bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47613#if defined(OS_MACOSX)
614 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
615 return text_input_client_observer_->OnMessageReceived(message);
616#endif
lfgbee1e0a2016-06-08 21:24:21617 if (mouse_lock_dispatcher_ &&
618 mouse_lock_dispatcher_->OnMessageReceived(message))
619 return true;
620
[email protected]a95986a82010-12-24 06:19:28621 bool handled = true;
622 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15623 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22624 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
625 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22626 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29627 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
628 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
629 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15630 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46631 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
632 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15633 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
wjmacleanee244e02017-05-26 21:06:07634 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28635 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28636 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
Fady Samuel319e429c2017-10-02 18:31:55637 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
638 OnSetLocalSurfaceIdForAutoResize)
dgozman9260b0a12015-03-16 13:45:20639 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
640 OnEnableDeviceEmulation)
641 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
642 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28643 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41644 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25645 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28646 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
647 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03648 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48649 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
650 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32651 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
lfg43e08e62016-02-03 18:51:37652 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
653 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23654 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
655 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59656 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
657 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
658 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
659 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21660 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
661 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
662 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21663#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39664 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
665 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21666#endif
[email protected]a95986a82010-12-24 06:19:28667 IPC_MESSAGE_UNHANDLED(handled = false)
668 IPC_END_MESSAGE_MAP()
669 return handled;
670}
initial.commit09911bf2008-07-26 23:55:29671
672bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42673 // Don't send any messages after the browser has told us to close, and filter
674 // most outgoing messages while swapped out.
675 if ((is_swapped_out_ &&
676 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
677 closing_) {
initial.commit09911bf2008-07-26 23:55:29678 delete message;
679 return false;
680 }
681
682 // If given a messsage without a routing ID, then assign our routing ID.
683 if (message->routing_id() == MSG_ROUTING_NONE)
684 message->set_routing_id(routing_id_);
685
[email protected]380244092011-10-07 17:26:27686 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44687}
688
dtapuska014ed082016-11-11 21:58:48689void RenderWidget::SendOrCrash(IPC::Message* message) {
690 bool result = Send(message);
691 CHECK(closing_ || result) << "Failed to send message";
692}
693
ekaramad5aff1942017-01-06 01:26:35694bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26695 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
696 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
697 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
698 // will be processed regardless of page focus. We should revisit this after
699 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54700 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26701 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35702}
703
bokanc007c3a2015-02-03 07:15:56704void RenderWidget::SetWindowRectSynchronously(
705 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39706 ResizeParams params;
707 params.screen_info = screen_info_;
708 params.new_size = new_window_rect.size();
709 params.physical_backing_size =
710 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39711 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39712 params.is_fullscreen_granted = is_fullscreen_granted_;
713 params.display_mode = display_mode_;
714 params.needs_resize_ack = false;
715 Resize(params);
716
bokanc007c3a2015-02-03 07:15:56717 view_screen_rect_ = new_window_rect;
718 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02719 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56720 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02721}
722
initial.commit09911bf2008-07-26 23:55:29723void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32724 DCHECK(content::RenderThread::Get());
725 if (closing_)
726 return;
727 NotifyOnClose();
728 closing_ = true;
729
730 // Browser correspondence is no longer needed at this point.
731 if (routing_id_ != MSG_ROUTING_NONE) {
732 RenderThread::Get()->RemoveRoute(routing_id_);
733 SetHidden(false);
734 if (RenderThreadImpl::current())
735 RenderThreadImpl::current()->WidgetDestroyed();
736 }
737
738 if (for_oopif_) {
739 // Widgets for frames may be created and closed at any time while the frame
740 // is alive. However, the closing process must happen synchronously. Frame
741 // widget and frames hold pointers to each other. If Close() is deferred to
742 // the message loop like in the non-frame widget case, WebWidget::close()
743 // can end up accessing members of an already-deleted frame.
744 Close();
745 } else {
746 // If there is a Send call on the stack, then it could be dangerous to close
747 // now. Post a task that only gets invoked when there are no nested message
748 // loops.
749 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
tzikff2a81a2017-09-15 05:10:06750 FROM_HERE, base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32751 }
752
753 // Balances the AddRef taken when we called AddRoute.
754 Release();
initial.commit09911bf2008-07-26 23:55:29755}
756
fsamuel664e8b62016-01-20 19:54:01757void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04758 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32759 return;
760
[email protected]b2e4c70132013-10-03 02:07:51761 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39762 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51763 return;
764 }
765
mfomitchev2600fd7c2016-02-17 20:53:39766 Resize(params);
initial.commit09911bf2008-07-26 23:55:29767}
768
Fady Samuel319e429c2017-10-02 18:31:55769void RenderWidget::OnSetLocalSurfaceIdForAutoResize(
770 uint64_t sequence_number,
771 const viz::LocalSurfaceId& local_surface_id) {
772 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number)
773 return;
Fady Samueld10aadd82017-11-03 18:23:57774 AutoResizeCompositor(local_surface_id);
Fady Samuel319e429c2017-10-02 18:31:55775}
776
dgozman9260b0a12015-03-16 13:45:20777void RenderWidget::OnEnableDeviceEmulation(
Nasko Oskovf97e8b02017-07-25 02:45:42778 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39779 if (!screen_metrics_emulator_) {
780 ResizeParams resize_params;
781 resize_params.screen_info = screen_info_;
782 resize_params.new_size = size_;
783 resize_params.physical_backing_size = physical_backing_size_;
784 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39785 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
786 resize_params.display_mode = display_mode_;
787 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
788 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18789 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39790 } else {
dgozman9260b0a12015-03-16 13:45:20791 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39792 }
dgozman9260b0a12015-03-16 13:45:20793}
794
795void RenderWidget::OnDisableDeviceEmulation() {
796 screen_metrics_emulator_.reset();
797}
798
initial.commit09911bf2008-07-26 23:55:29799void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31800 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29801 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03802 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55803 for (auto& observer : render_frames_)
804 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29805}
806
[email protected]3399dd822014-08-09 11:14:24807void RenderWidget::OnWasShown(bool needs_repainting,
808 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41809 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29810 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21811 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29812 return;
813
tasakb95dbb50c2017-02-08 18:07:50814 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29815 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03816 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55817 for (auto& observer : render_frames_)
818 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29819
[email protected]8a23afb32014-04-30 22:40:23820 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29821 return;
initial.commit09911bf2008-07-26 23:55:29822
[email protected]3399dd822014-08-09 11:14:24823 if (compositor_) {
824 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11825 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
826 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
827 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54828 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24829 }
initial.commit09911bf2008-07-26 23:55:29830}
831
[email protected]53d3f302009-12-21 04:42:05832void RenderWidget::OnRequestMoveAck() {
833 DCHECK(pending_window_rect_count_);
834 pending_window_rect_count_--;
835}
836
[email protected]ed7defa2013-03-12 21:29:59837GURL RenderWidget::GetURLForGraphicsContext3D() {
838 return GURL();
[email protected]65225772011-05-12 21:10:24839}
840
nzolghadr5d8596502017-01-23 22:59:35841void RenderWidget::OnHandleInputEvent(
842 const blink::WebInputEvent* input_event,
843 const std::vector<const blink::WebInputEvent*>& coalesced_events,
844 const ui::LatencyInfo& latency_info,
845 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23846 if (!input_event)
847 return;
nzolghadr5d8596502017-01-23 22:59:35848
Dave Tapuskaea83d3bd2017-06-13 16:14:55849 HandledEventCallback callback;
850 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
851 callback = base::Bind(
852 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
853 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
854 }
nzolghadr5d8596502017-01-23 22:59:35855 input_handler_->HandleInputEvent(
856 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55857 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23858}
859
Navid Zolghadr0d86e5f2017-10-23 18:09:22860int RenderWidget::GetWidgetRoutingIdAtPoint(const gfx::Point& point) {
861 return input_handler_->GetWidgetRoutingIdAtPoint(point);
862}
863
Dave Tapuskaea83d3bd2017-06-13 16:14:55864void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31865 const blink::WebCoalescedInputEvent& input_event,
866 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55867 HandledEventCallback callback) {
868 input_handler_->HandleInputEvent(input_event, latency_info,
869 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31870}
871
Dave Tapuskaea83d3bd2017-06-13 16:14:55872void RenderWidget::SendInputEventAck(
873 blink::WebInputEvent::Type type,
874 uint32_t touch_event_id,
875 InputEventAckState ack_state,
876 const ui::LatencyInfo& latency_info,
Dave Tapuskab28a1082017-08-30 15:37:26877 std::unique_ptr<ui::DidOverscrollParams> overscroll_params,
878 base::Optional<cc::TouchAction> touch_action) {
Dave Tapuskaea83d3bd2017-06-13 16:14:55879 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
Dave Tapuskab28a1082017-08-30 15:37:26880 latency_info, std::move(overscroll_params), touch_event_id,
881 touch_action);
dtapuska9ec1a912017-04-21 15:18:31882 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
883}
884
dtapuska9d46ef7d2017-05-26 19:06:06885scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
886 return input_event_queue_;
887}
888
fsamuel78f86e42016-01-20 04:10:23889void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21890 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54891 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23892}
893
894void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21895 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54896 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23897}
898
alexmos56567492016-09-13 00:52:46899void RenderWidget::OnSetEditCommandsForNextKeyEvent(
900 const EditCommands& edit_commands) {
901 edit_commands_ = edit_commands;
902}
903
fsamuel78f86e42016-01-20 04:10:23904void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08905 has_focus_ = enable;
906
lfg8ff33912016-09-13 20:59:21907 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54908 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08909
ericwilligers88e69742016-10-17 19:29:55910 for (auto& observer : render_frames_)
911 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23912}
913
dtapuska3d5624d32016-08-30 04:34:00914void RenderWidget::SetNeedsMainFrame() {
915 RenderWidgetCompositor* rwc = compositor();
916 if (!rwc)
917 return;
Blink Reformat1c4d759e2017-04-09 16:34:54918 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00919}
920
fsamuel78f86e42016-01-20 04:10:23921///////////////////////////////////////////////////////////////////////////////
922// RenderWidgetCompositorDelegate
923
924void RenderWidget::ApplyViewportDeltas(
925 const gfx::Vector2dF& inner_delta,
926 const gfx::Vector2dF& outer_delta,
927 const gfx::Vector2dF& elastic_overscroll_delta,
928 float page_scale,
929 float top_controls_delta) {
Blink Reformat1c4d759e2017-04-09 16:34:54930 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21931 elastic_overscroll_delta, page_scale,
932 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23933}
934
sahel1b47fda72017-03-28 17:03:07935void RenderWidget::RecordWheelAndTouchScrollingCount(
936 bool has_scrolled_by_wheel,
937 bool has_scrolled_by_touch) {
Blink Reformat1c4d759e2017-04-09 16:34:54938 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07939 has_scrolled_by_touch);
940}
941
fsamuel78f86e42016-01-20 04:10:23942void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska9ec1a912017-04-21 15:18:31943 if (input_event_queue_) {
944 input_event_queue_->DispatchRafAlignedInput(
945 ui::EventTimeStampFromSeconds(frame_time_sec));
946 }
dtapuska3d5624d32016-08-30 04:34:00947
Blink Reformat1c4d759e2017-04-09 16:34:54948 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23949}
950
danakjc7afae52017-06-20 21:12:41951void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:41952 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21953 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03954 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41955 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39956 DCHECK(!compositor_never_visible_);
danakjc7afae52017-06-20 21:12:41957 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:33958 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
959 callback);
[email protected]ba91a792013-02-06 09:48:28960}
961
fsamuel78f86e42016-01-20 04:10:23962void RenderWidget::DidCommitAndDrawCompositorFrame() {
963 // NOTE: Tests may break if this event is renamed or moved. See
964 // tab_capture_performancetest.cc.
965 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08966
ericwilligers88e69742016-10-17 19:29:55967 for (auto& observer : render_frames_)
968 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08969
fsamuel78f86e42016-01-20 04:10:23970 // Notify subclasses that we initiated the paint operation.
971 DidInitiatePaint();
972}
973
974void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55975 for (auto& observer : render_frames_)
976 observer.DidCommitCompositorFrame();
977 for (auto& observer : render_frame_proxies_)
978 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23979}
980
981void RenderWidget::DidCompletePageScaleAnimation() {}
982
danakj6c872fc02016-10-22 04:29:49983void RenderWidget::DidReceiveCompositorFrameAck() {
984 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
Fady Samuelcc3e3b4a2017-10-03 02:09:21985 DidResizeOrRepaintAck();
fsamuel78f86e42016-01-20 04:10:23986}
987
fsamuel78f86e42016-01-20 04:10:23988bool RenderWidget::IsClosing() const {
989 return host_closing_;
990}
991
danakj53eccbc2016-03-02 22:51:07992void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:54993 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29994}
995
fsamuel78f86e42016-01-20 04:10:23996void RenderWidget::UpdateVisualState() {
Blink Reformat1c4d759e2017-04-09 16:34:54997 GetWebWidget()->UpdateAllLifecyclePhases();
998 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:50999
Takashi SAKAMOTO870f6262017-08-22 04:08:271000 if (first_update_visual_state_after_hidden_) {
1001 RecordTimeToFirstActivePaint();
1002 first_update_visual_state_after_hidden_ = false;
1003 }
1004}
tasakb95dbb50c2017-02-08 18:07:501005
Takashi SAKAMOTO870f6262017-08-22 04:08:271006void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501007 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501008 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271009 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1010 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1011 sample);
1012 }
1013 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1014 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1015 UMA_HISTOGRAM_TIMES(
1016 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1017 "AfterBackgrounded.5min",
1018 sample);
1019 }
fsamuel78f86e42016-01-20 04:10:231020}
1021
1022void RenderWidget::WillBeginCompositorFrame() {
1023 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1024
Blink Reformat1c4d759e2017-04-09 16:34:541025 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291026
dglazkov06854c5c2016-08-31 00:19:591027 // The UpdateTextInputState can result in further layout and possibly
1028 // enable GPU acceleration so they need to be called before any painting
1029 // is done.
changwan75e3b2072017-01-16 02:55:001030 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591031 UpdateSelectionBounds();
1032
ericwilligers88e69742016-10-17 19:29:551033 for (auto& observer : render_frame_proxies_)
1034 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291035}
1036
jbroman6ccbc7d472016-07-27 04:45:411037std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041038 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411039 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1040 routing_id_, std::move(request));
1041}
1042
fsamuel72464894f2015-12-15 06:59:311043///////////////////////////////////////////////////////////////////////////////
1044// RenderWidgetInputHandlerDelegate
1045
avid7d6b2e2016-03-04 19:41:171046void RenderWidget::FocusChangeComplete() {
ekaramad27ca69b12017-04-20 18:34:291047 if (!GetWebWidget()->IsWebFrameWidget())
1048 return;
1049 blink::WebLocalFrame* focused =
1050 static_cast<blink::WebFrameWidget*>(GetWebWidget())
1051 ->LocalRoot()
1052 ->View()
1053 ->FocusedFrame();
1054 if (focused && focused->AutofillClient())
1055 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171056}
fsamuel72464894f2015-12-15 06:59:311057
1058bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:171059 if (owner_delegate_)
1060 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
1061
fsamuel72464894f2015-12-15 06:59:311062 return true;
1063}
1064
dtapuska1827dd22016-03-11 15:24:591065void RenderWidget::ObserveGestureEventAndResult(
1066 const blink::WebGestureEvent& gesture_event,
1067 const gfx::Vector2dF& unused_delta,
1068 bool event_processed) {
1069 if (!compositor_deps_->IsElasticOverscrollEnabled())
1070 return;
1071
1072 cc::InputHandlerScrollResult scroll_result;
1073 scroll_result.did_scroll = event_processed;
1074 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1075 scroll_result.unused_scroll_delta = unused_delta;
1076
1077 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1078 InputHandlerManager* input_handler_manager =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281079 render_thread ? render_thread->input_handler_manager() : nullptr;
dtapuska1827dd22016-03-11 15:24:591080 if (input_handler_manager) {
1081 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1082 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261083 } else if (widget_input_handler_manager_) {
1084 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1085 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591086 }
1087}
1088
avid7d6b2e2016-03-04 19:41:171089void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461090 ClearEditCommands();
1091}
1092
1093void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1094 const std::string& value) {
1095 ClearEditCommands();
1096 edit_commands_.emplace_back(name, value);
1097}
1098
1099void RenderWidget::ClearEditCommands() {
1100 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171101}
fsamuel72464894f2015-12-15 06:59:311102
chongza8ba91fc2016-08-16 21:39:171103void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska139a72f2017-09-06 21:57:031104 if (widget_input_handler_manager_) {
1105 WidgetInputHandlerManager::WidgetInputHandlerHost host =
1106 widget_input_handler_manager_->GetWidgetInputHandlerHost();
1107 (*host)->DidOverscroll(params);
1108 } else {
1109 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1110 }
fsamuel72464894f2015-12-15 06:59:311111}
1112
fsamuele8326c742016-01-12 00:49:391113void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1114 // Nothing to do here. RenderWidget created the |input_handler| and will take
1115 // ownership of it. We just verify here that we don't already have an input
1116 // handler.
1117 DCHECK(!input_handler_);
1118}
1119
changwan75e3b2072017-01-16 02:55:001120void RenderWidget::ShowVirtualKeyboard() {
1121 UpdateTextInputStateInternal(true, false);
1122}
1123
changwan62f57292017-02-17 08:28:251124void RenderWidget::ClearTextInputState() {
1125 text_input_info_ = blink::WebTextInputInfo();
1126 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1127 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1128 can_compose_inline_ = false;
1129 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201130 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251131}
1132
changwan75e3b2072017-01-16 02:55:001133void RenderWidget::UpdateTextInputState() {
1134 UpdateTextInputStateInternal(false, false);
1135}
1136
1137void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1138 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311139 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001140
fsamuel72464894f2015-12-15 06:59:311141 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001142 DCHECK(!reply_to_request);
1143 // show_virtual_keyboard should still be effective even if it was set inside
1144 // the IME
fsamuel72464894f2015-12-15 06:59:311145 // event guard.
changwan75e3b2072017-01-16 02:55:001146 if (show_virtual_keyboard)
1147 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311148 return;
1149 }
1150
dglazkov97b6c2b2016-10-25 17:35:551151 ui::TextInputType new_type = GetTextInputType();
1152 if (IsDateTimeInput(new_type))
1153 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311154
dglazkov97b6c2b2016-10-25 17:35:551155 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351156 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541157 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101158 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541159 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311160
1161 bool new_can_compose_inline = CanComposeInline();
1162
1163 // Only sends text input params if they are changed or if the ime should be
1164 // shown.
changwan75e3b2072017-01-16 02:55:001165 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561166 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1167 text_input_info_ != new_info ||
1168 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381169 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551170 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311171 params.mode = new_mode;
1172 params.flags = new_info.flags;
AJITH KUMAR V041c0b02017-08-08 10:39:201173 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1174 // Due to a focus change, values will be reset by the frame.
1175 // That case we only need fresh NEXT/PREVIOUS information.
1176 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1177 // focusable status is changed.
1178 if (auto* controller = GetInputMethodController()) {
1179 next_previous_flags_ =
1180 controller->ComputeWebTextInputNextPreviousFlags();
1181 } else {
1182 // For safety in case GetInputMethodController() is null, because -1 is
1183 // invalid value to send to browser process.
1184 next_previous_flags_ = 0;
1185 }
1186 }
1187 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541188 params.value = new_info.value.Utf8();
1189 params.selection_start = new_info.selection_start;
1190 params.selection_end = new_info.selection_end;
1191 params.composition_start = new_info.composition_start;
1192 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311193 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001194 // TODO(changwan): change instances of show_ime_if_needed to
1195 // show_virtual_keyboard.
1196 params.show_ime_if_needed = show_virtual_keyboard;
1197 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311198 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1199
1200 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551201 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311202 text_input_mode_ = new_mode;
1203 can_compose_inline_ = new_can_compose_inline;
1204 text_input_flags_ = new_info.flags;
1205 }
1206}
1207
1208bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581209 possible_drag_event_info_.event_source =
1210 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1211 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541212 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171213
fsamuel72464894f2015-12-15 06:59:311214 return false;
1215}
1216
1217bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551218 for (auto& observer : render_frames_)
1219 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081220
paulmeyer6ef5a792016-11-08 20:33:581221 possible_drag_event_info_.event_source =
1222 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1223 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541224 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581225
avid7d6b2e2016-03-04 19:41:171226 if (owner_delegate_)
1227 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1228
fsamuel72464894f2015-12-15 06:59:311229 return false;
[email protected]fd847792013-10-24 17:12:351230}
1231
initial.commit09911bf2008-07-26 23:55:291232///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391233// RenderWidgetScreenMetricsDelegate
1234
1235void RenderWidget::Redraw() {
1236 set_next_paint_is_resize_ack();
1237 if (compositor_)
1238 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1239}
1240
bokanc63441c2016-04-27 15:49:121241void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541242 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121243}
1244
1245gfx::Size RenderWidget::GetSizeForWebWidget() const {
1246 if (IsUseZoomForDSFEnabled())
1247 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1248
1249 return size_;
1250}
1251
mfomitchev2600fd7c2016-02-17 20:53:391252void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581253 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271254 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1255 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581256
Fady Samuel85a1bf72017-10-27 14:30:201257 bool screen_info_changed = screen_info_ != params.screen_info;
1258
mfomitchev2600fd7c2016-02-17 20:53:391259 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581260
ccameron2f451532016-09-07 21:49:271261 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1262 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581263 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581264 }
mfomitchev2600fd7c2016-02-17 20:53:391265
1266 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1267 // A resize ack shouldn't be requested if we have not ACK'd the previous
1268 // one.
1269 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1270 }
1271
1272 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211273 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391274 return;
1275
fsamuelca02c4e2017-05-09 13:34:141276 if (params.local_surface_id)
1277 local_surface_id_ = *params.local_surface_id;
1278
ianwene5fc5782016-08-18 04:05:151279 if (compositor_) {
Fady Samuel319e429c2017-10-02 18:31:551280 // If surface synchronization is enabled, then this will use the provided
fsamuelca02c4e2017-05-09 13:34:141281 // |local_surface_id_| to submit the next generated CompositorFrame.
1282 // If the ID is not valid, then the compositor will defer commits until
1283 // it receives a valid surface ID. This is a no-op if surface
1284 // synchronization is disabled.
Fady Samuel2bb02292017-10-17 23:59:151285 DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() ||
1286 !params.needs_resize_ack || local_surface_id_.is_valid());
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271287 compositor_->SetViewportSize(params.physical_backing_size,
1288 local_surface_id_);
1289 compositor_->SetBrowserControlsHeight(
1290 params.top_controls_height, params.bottom_controls_height,
1291 params.browser_controls_shrink_blink_size);
1292 compositor_->SetRasterColorSpace(
1293 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151294 }
mfomitchev2600fd7c2016-02-17 20:53:391295
mfomitchev2600fd7c2016-02-17 20:53:391296 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391297
1298 // NOTE: We may have entered fullscreen mode without changing our size.
1299 bool fullscreen_change =
1300 is_fullscreen_granted_ != params.is_fullscreen_granted;
1301 is_fullscreen_granted_ = params.is_fullscreen_granted;
1302 display_mode_ = params.display_mode;
1303
bokanc63441c2016-04-27 15:49:121304 size_ = params.new_size;
1305 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391306
bokanc63441c2016-04-27 15:49:121307 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221308
mfomitchev2600fd7c2016-02-17 20:53:391309 WebSize visual_viewport_size;
1310
1311 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181312 visual_viewport_size = gfx::ScaleToCeiledSize(
1313 params.visible_viewport_size,
1314 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391315 } else {
1316 visual_viewport_size = visible_viewport_size_;
1317 }
1318
Blink Reformat1c4d759e2017-04-09 16:34:541319 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391320
bokanc63441c2016-04-27 15:49:121321 // When resizing, we want to wait to paint before ACK'ing the resize. This
1322 // ensures that we only resize as fast as we can paint. We only need to
1323 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391324 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1325 // In this case there is no paint/composite and therefore no
Fady Samuelcc3e3b4a2017-10-03 02:09:211326 // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to
1327 // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a
1328 // different message.
mfomitchev2600fd7c2016-02-17 20:53:391329 DCHECK(!params.needs_resize_ack);
1330 }
1331
1332 // Send the Resize_ACK flag once we paint again if requested.
1333 if (params.needs_resize_ack)
1334 set_next_paint_is_resize_ack();
1335
1336 if (fullscreen_change)
1337 DidToggleFullscreen();
1338
engedy6cb63c92016-02-23 14:14:581339 if (orientation_changed)
1340 OnOrientationChange();
1341
Fady Samuel85a1bf72017-10-27 14:30:201342 if (screen_info_changed) {
1343 for (auto& observer : render_frame_proxies_)
1344 observer.OnScreenInfoChanged(params.screen_info);
1345
1346 // Notify all BrowserPlugins of the updated ScreenInfo.
1347 if (BrowserPluginManager::Get())
1348 BrowserPluginManager::Get()->ScreenInfoChanged(params.screen_info);
1349 }
1350
mfomitchev2600fd7c2016-02-17 20:53:391351 // If a resize ack is requested and it isn't set-up, then no more resizes will
1352 // come in and in general things will go wrong.
1353 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1354}
1355
1356void RenderWidget::SetScreenMetricsEmulationParameters(
1357 bool enabled,
1358 const blink::WebDeviceEmulationParams& params) {
1359 // This is only supported in RenderView.
1360 NOTREACHED();
1361}
1362
1363void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1364 const gfx::Rect& window_screen_rect) {
1365 view_screen_rect_ = view_screen_rect;
1366 window_screen_rect_ = window_screen_rect;
1367}
1368
1369///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461370// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291371
Fady Samueld10aadd82017-11-03 18:23:571372void RenderWidget::AutoResizeCompositor(
1373 const viz::LocalSurfaceId& local_surface_id) {
danakjddaec912015-09-25 19:38:401374 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
Fady Samueld10aadd82017-11-03 18:23:571375 local_surface_id_ = local_surface_id;
[email protected]97e1bf72013-03-06 14:06:051376 if (compositor_)
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271377 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
[email protected]97e1bf72013-03-06 14:06:051378}
1379
Blink Reformat1c4d759e2017-04-09 16:34:541380blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221381 DCHECK(!host_closing_);
1382
loyso6e6efc42017-01-21 02:23:031383 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1384 auto animation_host = cc::AnimationHost::CreateMainInstance();
1385
wjmacleana755e302017-04-20 00:43:161386 // Oopif status must be set before the LayerTreeHost is created.
1387 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031388 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1389 compositor_.get(), compositor_.get(), animation_host.get(),
1390 compositor_deps_, device_scale_factor_, screen_info_);
1391 compositor_->Initialize(std::move(layer_tree_host),
1392 std::move(animation_host));
1393
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271394 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
oshimad5279032015-12-16 18:22:331395 OnDeviceScaleFactorChanged();
ccameron01912992017-05-23 07:34:031396 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091397 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011398 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391399 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411400 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221401 bool should_generate_frame_sink =
1402 !compositor_never_visible_ && RenderThreadImpl::current();
1403 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391404 compositor_->SetNeverVisible();
1405
pimanc4af3072015-10-02 03:45:591406 StartCompositor();
staraz067f58242016-11-07 21:06:411407 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1408 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331409 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371410
wjmaclean1d970622017-01-21 22:28:241411 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261412 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311413 input_event_queue_ = new MainThreadEventQueue(
1414 this, render_thread->GetRendererScheduler()->CompositorTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221415 render_thread->GetRendererScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261416
1417 InputHandlerManager* input_handler_manager =
1418 render_thread->input_handler_manager();
1419 if (input_handler_manager) {
1420 input_handler_manager->AddInputHandler(
1421 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1422 weak_ptr_factory_.GetWeakPtr(),
1423 compositor_deps_->IsScrollAnimatorEnabled());
1424 has_added_input_handler_ = true;
1425 }
wjmaclean1d970622017-01-21 22:28:241426 }
1427
Khushal3e96e662017-10-30 23:16:501428 UpdateURLForCompositorUkm();
1429
loyso50b51c22017-01-10 07:18:371430 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591431}
1432
ennef3c58142014-12-09 21:44:381433void RenderWidget::WillCloseLayerTreeView() {
1434 if (host_closing_)
1435 return;
1436
1437 // Prevent new compositors or output surfaces from being created.
1438 host_closing_ = true;
1439
[email protected]aeeedad2014-08-22 18:16:221440 // Always send this notification to prevent new layer tree views from
1441 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211442 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541443 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221444}
1445
Blink Reformat1c4d759e2017-04-09 16:34:541446void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1447 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481448 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1449 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1450 }
dglazkov79c426102015-08-31 21:22:431451
ericwilligers88e69742016-10-17 19:29:551452 for (auto& observer : render_frames_)
1453 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431454}
1455
[email protected]586871b2014-07-22 17:05:111456// static
dchengcedca5612016-04-09 01:40:151457std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111458 IPC::Message* msg,
1459 MessageDeliveryPolicy policy,
1460 FrameSwapMessageQueue* frame_swap_message_queue,
1461 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111462 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111463 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151464 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1465 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111466 &first_message_for_frame);
1467 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151468 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111469 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061470 return promise;
[email protected]586871b2014-07-22 17:05:111471 }
dcheng4b6b5ff2014-10-16 00:42:061472 return nullptr;
[email protected]586871b2014-07-22 17:05:111473}
1474
1475void RenderWidget::QueueMessage(IPC::Message* msg,
1476 MessageDeliveryPolicy policy) {
1477 // RenderThreadImpl::current() is NULL in some tests.
1478 if (!compositor_ || !RenderThreadImpl::current()) {
1479 Send(msg);
1480 return;
1481 }
1482
dchengcedca5612016-04-09 01:40:151483 std::unique_ptr<cc::SwapPromise> swap_promise =
1484 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111485 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111486 compositor_->GetSourceFrameNumber());
1487
Ken Buchanance710eb2017-08-30 23:46:521488 if (swap_promise)
dcheng07945f632015-12-26 07:59:321489 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111490}
1491
Blink Reformat1c4d759e2017-04-09 16:34:541492void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301493 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521494 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181495 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291496 // Only send a SetCursor message if we need to make a change.
1497 if (!current_cursor_.IsEqual(cursor)) {
1498 current_cursor_ = cursor;
1499 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1500 }
1501}
1502
aelias5971e47d2017-06-16 02:39:381503void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1504 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1505}
1506
1507void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1508 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1509}
1510
1511void RenderWidget::AutoscrollEnd() {
1512 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1513}
1514
initial.commit09911bf2008-07-26 23:55:291515// We are supposed to get a single call to Show for a newly created RenderWidget
1516// that was created via RenderWidget::CreateWebView. So, we wait until this
1517// point to dispatch the ShowWidget message.
1518//
1519// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281520// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291521//
Blink Reformat1c4d759e2017-04-09 16:34:541522void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291523 DCHECK(!did_show_) << "received extraneous Show call";
1524 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351525 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291526
[email protected]8de12d942010-11-17 20:42:441527 if (did_show_)
1528 return;
1529
1530 did_show_ = true;
nickf7b38222016-11-22 21:59:351531
1532 // The opener is responsible for actually showing this widget.
1533 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351534 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351535
bokanc007c3a2015-02-03 07:15:561536 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441537 // that's okay. It'll be ignored if as_popup is false, or the browser
1538 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561539 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291540}
1541
[email protected]2533ce12009-05-09 00:02:241542void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381543 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241544 Send(new ViewHostMsg_Close(routing_id_));
1545}
1546
dgozmancf9039cd2015-04-06 12:01:311547void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551548 for (auto& observer : render_frames_)
1549 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311550}
1551
Blink Reformat1c4d759e2017-04-09 16:34:541552void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081553 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321554 if (is_swapped_out_) {
1555 // This widget is currently swapped out, and the active widget is in a
1556 // different process. Have the browser route the close request to the
1557 // active widget instead, so that the correct unload handlers are run.
1558 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1559 return;
1560 }
1561
initial.commit09911bf2008-07-26 23:55:291562 // If a page calls window.close() twice, we'll end up here twice, but that's
1563 // OK. It is safe to send multiple Close messages.
1564
[email protected]2533ce12009-05-09 00:02:241565 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1566 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1567 // could be closed before the JS finishes executing. So instead, post a
1568 // message back to the message loop, which won't run until the JS is
1569 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081570 base::ThreadTaskRunnerHandle::Get()->PostTask(
tzikff2a81a2017-09-15 05:10:061571 FROM_HERE, base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291572}
1573
1574void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031575 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381576 WillCloseLayerTreeView();
1577 compositor_.reset();
lfg8ff33912016-09-13 20:59:211578 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541579 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211580 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291581 }
1582}
1583
bokan841fdc72016-10-06 00:16:351584void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1585 DCHECK(window_rect);
1586 float scale = popup_origin_scale_for_emulation_;
1587 if (!scale)
1588 return;
1589 window_rect->x =
1590 popup_view_origin_for_emulation_.x() +
1591 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1592 window_rect->y =
1593 popup_view_origin_for_emulation_.y() +
1594 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1595}
1596
1597void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1598 DCHECK(window_rect);
1599 float scale = popup_origin_scale_for_emulation_;
1600 if (!scale)
1601 return;
1602 window_rect->x =
1603 popup_screen_origin_for_emulation_.x() +
1604 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1605 window_rect->y =
1606 popup_screen_origin_for_emulation_.y() +
1607 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1608}
1609
Blink Reformat1c4d759e2017-04-09 16:34:541610WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351611 WebRect rect;
bokan6b08cd22016-10-05 00:55:211612 if (pending_window_rect_count_) {
1613 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1614 // the RootWindowRect is probably going to return wrong results since the
1615 // browser may not have processed the Move yet. There isn't really anything
1616 // good to do in this case, and it shouldn't happen - since this size is
1617 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351618 rect = pending_window_rect_;
1619 } else {
1620 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211621 }
[email protected]2533ce12009-05-09 00:02:241622
bokan841fdc72016-10-06 00:16:351623 ScreenRectToEmulatedIfNeeded(&rect);
1624 return rect;
bokan6b08cd22016-10-05 00:55:211625}
1626
Blink Reformat1c4d759e2017-04-09 16:34:541627WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351628 WebRect rect = view_screen_rect_;
1629 ScreenRectToEmulatedIfNeeded(&rect);
1630 return rect;
initial.commit09911bf2008-07-26 23:55:291631}
1632
Blink Reformat1c4d759e2017-04-09 16:34:541633void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301634 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541635 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301636}
1637
Blink Reformat1c4d759e2017-04-09 16:34:541638void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241639 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351640 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511641
[email protected]5b45ad42013-10-25 00:42:041642 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201643 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561644 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1645 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031646 } else {
bokanc007c3a2015-02-03 07:15:561647 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031648 }
initial.commit09911bf2008-07-26 23:55:291649 } else {
bokanc007c3a2015-02-03 07:15:561650 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291651 }
1652}
1653
[email protected]2533ce12009-05-09 00:02:241654void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1655 pending_window_rect_ = rect;
1656 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241657
bokan6b08cd22016-10-05 00:55:211658 // Popups don't get size updates back from the browser so just store the set
1659 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541660 if (popup_type_ != blink::kWebPopupTypeNone) {
1661 window_screen_rect_ = rect;
1662 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241663 }
[email protected]d4547452008-08-28 18:36:371664}
1665
wjmacleanee244e02017-05-26 21:06:071666void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1667 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071668 has_host_context_menu_location_ = true;
1669 host_context_menu_location_ = location;
1670 if (GetWebWidget()) {
1671 GetWebWidget()->ShowContextMenu(
1672 static_cast<blink::WebMenuSourceType>(source_type));
1673 }
1674 has_host_context_menu_location_ = false;
1675}
1676
[email protected]fa7b1dc2010-06-23 17:53:041677void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261678 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111679 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071680 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111681 int selection_start,
1682 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351683 if (!ShouldHandleImeEvents())
1684 return;
1685
brettw4b461082016-11-19 18:55:161686#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491687 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111688 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491689 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091690 return;
1691 }
1692#endif
[email protected]66fca5bc2013-05-23 06:58:291693 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011694 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011695 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541696 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111697 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561698 replacement_range.IsValid()
1699 ? WebRange(replacement_range.start(), replacement_range.length())
1700 : WebRange(),
1701 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041702 // If we failed to set the composition text, then we need to let the browser
1703 // process to cancel the input method's ongoing composition session, to make
1704 // sure we are in a consistent state.
Dave Tapuska139a72f2017-09-06 21:57:031705 if (widget_input_handler_manager_) {
1706 WidgetInputHandlerManager::WidgetInputHandlerHost host =
1707 widget_input_handler_manager_->GetWidgetInputHandlerHost();
1708 (*host)->ImeCancelComposition();
1709 } else {
1710 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1711 }
[email protected]7f00efa2010-04-15 05:01:261712 }
nonafa291792016-08-10 02:36:181713 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041714}
1715
rlanday7efe2302017-01-11 00:14:281716void RenderWidget::OnImeCommitText(
1717 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111718 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281719 const gfx::Range& replacement_range,
1720 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351721 if (!ShouldHandleImeEvents())
1722 return;
1723
brettw4b461082016-11-19 18:55:161724#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491725 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1726 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1727 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091728 return;
1729 }
1730#endif
[email protected]66fca5bc2013-05-23 06:58:291731 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391732 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261733 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541734 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111735 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561736 replacement_range.IsValid()
1737 ? WebRange(replacement_range.start(), replacement_range.length())
1738 : WebRange(),
1739 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261740 }
aelias87b8f7c2016-09-14 03:19:291741 input_handler_->set_handling_input_event(false);
1742 UpdateCompositionInfo(false /* not an immediate request */);
1743}
1744
1745void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351746 if (!ShouldHandleImeEvents())
1747 return;
1748
brettw4b461082016-11-19 18:55:161749#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491750 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1751 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291752 return;
1753 }
1754#endif
1755
changwan38c3eb612016-12-09 01:45:561756 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291757 return;
1758 ImeEventGuard guard(this);
1759 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011760 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541761 controller->FinishComposingText(
1762 keep_selection ? WebInputMethodController::kKeepSelection
1763 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011764 }
fsamuele8326c742016-01-12 00:49:391765 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181766 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291767}
1768
oshimad5279032015-12-16 18:22:331769void RenderWidget::OnDeviceScaleFactorChanged() {
1770 if (!compositor_)
1771 return;
oshimad5279032015-12-16 18:22:331772 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181773 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331774 else
Blink Reformat1c4d759e2017-04-09 16:34:541775 compositor_->SetDeviceScaleFactor(device_scale_factor_);
oshimad5279032015-12-16 18:22:331776}
1777
[email protected]0bc1f572013-04-17 01:46:311778void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121779 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211780 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121781 return;
1782
[email protected]0bc1f572013-04-17 01:46:311783 // Even if the browser provides an empty damage rect, it's still expecting to
1784 // receive a repaint ack so just damage the entire widget bounds.
1785 if (size_to_paint.IsEmpty()) {
1786 size_to_paint = size_;
1787 }
1788
[email protected]ec7dc112008-08-06 05:30:121789 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051790 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311791 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121792}
1793
[email protected]4873c7d2009-07-16 06:36:281794void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211795 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111796 return;
Blink Reformat1c4d759e2017-04-09 16:34:541797 GetWebWidget()->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111798}
1799
[email protected]80ad8622012-11-07 16:33:031800void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1801 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511802 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391803 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1804 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511805 } else {
mfomitchev2600fd7c2016-02-17 20:53:391806 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511807 }
[email protected]80ad8622012-11-07 16:33:031808 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1809}
1810
lfgdb5c4ed2016-03-04 23:09:071811void RenderWidget::OnUpdateWindowScreenRect(
1812 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211813 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071814 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211815 else
lfgdb5c4ed2016-03-04 23:09:071816 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071817}
1818
kenrbea731792017-01-13 15:10:481819void RenderWidget::OnSetViewportIntersection(
1820 const gfx::Rect& viewport_intersection) {
Blink Reformat1c4d759e2017-04-09 16:34:541821 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1822 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
kenrbea731792017-01-13 15:10:481823 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541824 ->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:481825 }
1826}
1827
kenrb04323782017-06-23 01:23:321828void RenderWidget::OnSetIsInert(bool inert) {
1829 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1830 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
1831 static_cast<WebFrameWidget*>(GetWebWidget())->SetIsInert(inert);
1832 }
1833}
1834
paulmeyer90f6c31d2016-11-12 00:17:591835void RenderWidget::OnDragTargetDragEnter(
1836 const std::vector<DropData::Metadata>& drop_meta_data,
1837 const gfx::Point& client_point,
1838 const gfx::Point& screen_point,
1839 WebDragOperationsMask ops,
1840 int key_modifiers) {
1841 if (!GetWebWidget())
1842 return;
1843
Blink Reformat1c4d759e2017-04-09 16:34:541844 DCHECK(GetWebWidget()->IsWebFrameWidget());
1845 WebDragOperation operation =
1846 static_cast<WebFrameWidget*>(GetWebWidget())
1847 ->DragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1848 client_point, screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591849
1850 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1851}
1852
1853void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1854 const gfx::Point& screen_point,
1855 WebDragOperationsMask ops,
1856 int key_modifiers) {
1857 if (!GetWebWidget())
1858 return;
1859
Blink Reformat1c4d759e2017-04-09 16:34:541860 DCHECK(GetWebWidget()->IsWebFrameWidget());
paulmeyer90f6c31d2016-11-12 00:17:591861 WebDragOperation operation =
Blink Reformat1c4d759e2017-04-09 16:34:541862 static_cast<WebFrameWidget*>(GetWebWidget())
1863 ->DragTargetDragOver(ConvertWindowPointToViewport(client_point),
1864 screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591865
1866 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1867}
1868
kenrb07c272802017-02-07 23:48:171869void RenderWidget::OnDragTargetDragLeave(const gfx::Point& client_point,
1870 const gfx::Point& screen_point) {
paulmeyer90f6c31d2016-11-12 00:17:591871 if (!GetWebWidget())
1872 return;
Blink Reformat1c4d759e2017-04-09 16:34:541873 DCHECK(GetWebWidget()->IsWebFrameWidget());
kenrb07c272802017-02-07 23:48:171874 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541875 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171876 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591877}
1878
1879void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1880 const gfx::Point& client_point,
1881 const gfx::Point& screen_point,
1882 int key_modifiers) {
1883 if (!GetWebWidget())
1884 return;
1885
Blink Reformat1c4d759e2017-04-09 16:34:541886 DCHECK(GetWebWidget()->IsWebFrameWidget());
1887 static_cast<WebFrameWidget*>(GetWebWidget())
1888 ->DragTargetDrop(DropDataToWebDragData(drop_data),
1889 ConvertWindowPointToViewport(client_point), screen_point,
1890 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591891}
1892
paulmeyer8fc8ea92016-11-15 05:12:211893void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1894 const gfx::Point& screen_point,
1895 WebDragOperation op) {
1896 if (!GetWebWidget())
1897 return;
1898
Blink Reformat1c4d759e2017-04-09 16:34:541899 static_cast<WebFrameWidget*>(GetWebWidget())
1900 ->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
1901 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:211902}
1903
1904void RenderWidget::OnDragSourceSystemDragEnded() {
1905 if (!GetWebWidget())
1906 return;
1907
Blink Reformat1c4d759e2017-04-09 16:34:541908 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:211909}
1910
Blink Reformat1c4d759e2017-04-09 16:34:541911void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261912#if defined(OS_CHROMEOS)
1913 // On ChromeOS, virtual keyboard is triggered only when users leave the
1914 // mouse button or the finger and a text input element is focused at that
1915 // time. Focus event itself shouldn't trigger virtual keyboard.
1916 UpdateTextInputState();
1917#else
changwan75e3b2072017-01-16 02:55:001918 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261919#endif
boliu7b2be2f2016-11-04 04:58:311920
1921// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1922// virtual keyboard.
1923#if !defined(OS_ANDROID)
1924 FocusChangeComplete();
1925#endif
[email protected]0d1ebed12013-08-05 22:01:131926}
1927
fsamuel72464894f2015-12-15 06:59:311928ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161929#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491930 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
1931 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:091932#endif
ekaramad5aff1942017-01-06 01:26:351933 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541934 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:311935 return ui::TEXT_INPUT_TYPE_NONE;
1936}
1937
nonafa291792016-08-10 02:36:181938void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1939 if (!monitor_composition_info_ && !immediate_request)
1940 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591941
nonafa291792016-08-10 02:36:181942 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1943 gfx::Range range;
1944 std::vector<gfx::Rect> character_bounds;
1945
1946 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1947 // Composition information is only available on editable node.
1948 range = gfx::Range::InvalidRange();
1949 } else {
1950 GetCompositionRange(&range);
1951 GetCompositionCharacterBounds(&character_bounds);
1952 }
1953
1954 if (!immediate_request &&
1955 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311956 return;
nonafa291792016-08-10 02:36:181957 }
fsamuel72464894f2015-12-15 06:59:311958 composition_character_bounds_ = character_bounds;
1959 composition_range_ = range;
Dave Tapuska139a72f2017-09-06 21:57:031960 if (widget_input_handler_manager_) {
1961 WidgetInputHandlerManager::WidgetInputHandlerHost host =
1962 widget_input_handler_manager_->GetWidgetInputHandlerHost();
1963 (*host)->ImeCompositionRangeChanged(composition_range_,
1964 composition_character_bounds_);
1965 } else {
1966 Send(new InputHostMsg_ImeCompositionRangeChanged(
1967 routing_id(), composition_range_, composition_character_bounds_));
1968 }
fsamuel72464894f2015-12-15 06:59:311969}
1970
Blink Reformat1c4d759e2017-04-09 16:34:541971void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:541972 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461973 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331974 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541975 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461976 gfx::Rect window_rect =
1977 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1978 rect->x = window_rect.x();
1979 rect->y = window_rect.y();
1980 rect->width = window_rect.width();
1981 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541982 }
1983}
1984
Blink Reformat1c4d759e2017-04-09 16:34:541985void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:301986 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181987 rect->x *= GetOriginalDeviceScaleFactor();
1988 rect->y *= GetOriginalDeviceScaleFactor();
1989 rect->width *= GetOriginalDeviceScaleFactor();
1990 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301991 }
1992}
1993
W. James MacLeanb5846e52017-08-31 20:39:501994void RenderWidget::TransferActiveWheelFlingAnimation(
1995 const blink::WebActiveWheelFlingParameters& params) {
1996 blink::WebWidget* web_widget = GetWebWidget();
1997 if (web_widget && web_widget->IsWebFrameWidget()) {
1998 static_cast<blink::WebFrameWidget*>(web_widget)
1999 ->TransferActiveWheelFlingAnimation(params);
2000 }
2001}
2002
changwan8c342742016-02-26 00:53:392003void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262004#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392005 DCHECK(!ime_event_guard_);
2006 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002007 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212008#endif
Dave Tapuska9db80842017-07-24 17:24:262009}
[email protected]105dffb42013-02-20 03:46:212010
ekaramadc9b70a72017-03-23 16:14:232011void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2012 bool monitor_updates) {
2013 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182014 if (!immediate_request)
2015 return;
2016 UpdateCompositionInfo(true /* immediate request */);
2017}
2018
[email protected]fcdc5642014-05-09 14:32:242019void RenderWidget::OnOrientationChange() {
lfg8d649cc2017-04-28 18:04:302020 WebWidget* web_widget = GetWebWidget();
2021 if (web_widget && web_widget->IsWebFrameWidget()) {
2022 WebFrameWidget* web_frame_widget = static_cast<WebFrameWidget*>(web_widget);
Alex Moshchuk0b409c42017-09-13 02:09:002023 // LocalRoot() might return null for provisional main frames. In this case,
2024 // the frame hasn't committed a navigation and is not swapped into the tree
2025 // yet, so it doesn't make sense to send orientation change events to it.
2026 //
2027 // TODO(https://crbug.com/578349): This check should be cleaned up
2028 // once provisional frames are gone.
2029 if (web_frame_widget->LocalRoot())
2030 web_frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302031 }
[email protected]fcdc5642014-05-09 14:32:242032}
2033
[email protected]bee16aab2009-08-26 15:55:032034void RenderWidget::SetHidden(bool hidden) {
2035 if (is_hidden_ == hidden)
2036 return;
2037
jdduke8fac9d102014-12-20 02:40:132038 // The status has changed. Tell the RenderThread about it and ensure
2039 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032040 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132041
Scott Violet1098538e2017-10-05 19:23:332042#if defined(USE_AURA)
2043 if (IsRunningInMash())
2044 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2045#endif
2046
tasakb95dbb50c2017-02-08 18:07:502047 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:002048 RenderThreadImpl::current()->WidgetHidden();
Takashi SAKAMOTO870f6262017-08-22 04:08:272049 first_update_visual_state_after_hidden_ = true;
Nasko Oskovf97e8b02017-07-25 02:45:422050 } else
[email protected]b2db9272014-01-10 17:42:002051 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:112052
2053 if (render_widget_scheduling_state_)
2054 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032055}
2056
[email protected]2b624c562011-10-27 22:58:262057void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212058 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262059 return;
2060
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122061 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542062 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262063 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542064 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262065 }
[email protected]2b624c562011-10-27 22:58:262066}
2067
[email protected]674741932009-02-04 23:44:462068bool RenderWidget::next_paint_is_resize_ack() const {
Fady Samuelcc3e3b4a2017-10-03 02:09:212069 return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack(
2070 next_paint_flags_);
[email protected]674741932009-02-04 23:44:462071}
2072
[email protected]674741932009-02-04 23:44:462073void RenderWidget::set_next_paint_is_resize_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212074 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462075}
2076
[email protected]674741932009-02-04 23:44:462077void RenderWidget::set_next_paint_is_repaint_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212078 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462079}
2080
changwanf2a707b2015-10-30 08:22:162081void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2082 if (!ime_event_guard_)
2083 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292084}
2085
changwanf2a707b2015-10-30 08:22:162086void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2087 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002088 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162089 return;
2090 }
2091 ime_event_guard_ = nullptr;
2092
[email protected]66fca5bc2013-05-23 06:58:292093 // While handling an ime event, text input state and selection bounds updates
2094 // are ignored. These must explicitly be updated once finished handling the
2095 // ime event.
2096 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472097#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002098 if (guard->show_virtual_keyboard())
2099 ShowVirtualKeyboard();
2100 else
2101 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472102#endif
[email protected]66fca5bc2013-05-23 06:58:292103}
2104
[email protected]7c8873e2013-02-05 08:03:012105void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162106#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492107 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092108 // TODO(kinaba) http://crbug.com/101101
2109 // Current Pepper IME API does not handle selection bounds. So we simply
2110 // use the caret position as an empty range for now. It will be updated
2111 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492112 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542113 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092114 *focus = caret;
2115 *anchor = caret;
2116 return;
2117 }
2118#endif
[email protected]7c8873e2013-02-05 08:03:012119 WebRect focus_webrect;
2120 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542121 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2122 ConvertViewportToWindow(&focus_webrect);
2123 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242124 *focus = focus_webrect;
2125 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322126}
2127
[email protected]e99ef6f2011-10-16 01:13:002128void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082129 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212130 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002131 return;
changwanf2a707b2015-10-30 08:22:162132 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292133 return;
[email protected]e99ef6f2011-10-16 01:13:002134
mohsenb0eeba72015-08-09 06:20:082135#if defined(USE_AURA)
2136 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2137 // Aura beucause composited selection updates are not working for webview tags
2138 // which regresses IME inside webview. Remove this when composited selection
2139 // updates are fixed for webviews. See, http://crbug.com/510568.
2140 bool send_ipc = true;
2141#else
jddukeacf809e2014-09-23 20:38:382142 // With composited selection updates, the selection bounds will be reported
2143 // directly by the compositor, in which case explicit IPC selection
2144 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082145 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542146 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082147#endif
2148 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382149 ViewHostMsg_SelectionBounds_Params params;
2150 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2151 if (selection_anchor_rect_ != params.anchor_rect ||
2152 selection_focus_rect_ != params.focus_rect) {
2153 selection_anchor_rect_ = params.anchor_rect;
2154 selection_focus_rect_ = params.focus_rect;
Blink Reformat1c4d759e2017-04-09 16:34:542155 GetWebWidget()->SelectionTextDirection(params.focus_dir,
lfg8ff33912016-09-13 20:59:212156 params.anchor_dir);
Blink Reformat1c4d759e2017-04-09 16:34:542157 params.is_anchor_first = GetWebWidget()->IsSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:382158 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2159 }
[email protected]58b48a0d2012-06-13 07:01:352160 }
jddukeacf809e2014-09-23 20:38:382161
nonafa291792016-08-10 02:36:182162 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002163}
2164
lfgb00fcad2016-07-14 14:16:332165void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2166 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542167 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332168 if (size_.width() != new_size_in_window.width ||
2169 size_.height() != new_size_in_window.height) {
2170 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2171
2172 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542173 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2174 size_.height());
lfgb00fcad2016-07-14 14:16:332175 view_screen_rect_ = new_pos;
2176 window_screen_rect_ = new_pos;
2177 }
2178
Fady Samueld10aadd82017-11-03 18:23:572179 AutoResizeCompositor(viz::LocalSurfaceId());
lfgb00fcad2016-07-14 14:16:332180
Fady Samuel319e429c2017-10-02 18:31:552181 if (!resizing_mode_selector_->is_synchronous_mode()) {
Fady Samueld10aadd82017-11-03 18:23:572182 need_resize_ack_for_auto_resize_ = true;
Fady Samuel319e429c2017-10-02 18:31:552183 // If surface synchronization is off, then ResizeAcks go to the browser in
2184 // response to a DidReceiveCompositorFrame. With surface synchronization
2185 // on, that notification will not arrive here because the compositor is
2186 // deferring commits and thus submission of CompositorFrames.
2187 if (!size_.IsEmpty() && compositor_ &&
2188 compositor_->IsSurfaceSynchronizationEnabled()) {
Fady Samuelcc3e3b4a2017-10-03 02:09:212189 DidResizeOrRepaintAck();
Fady Samuel319e429c2017-10-02 18:31:552190 }
2191 }
lfgb00fcad2016-07-14 14:16:332192 }
2193}
2194
[email protected]58b48a0d2012-06-13 07:01:352195void RenderWidget::GetCompositionCharacterBounds(
2196 std::vector<gfx::Rect>* bounds) {
2197 DCHECK(bounds);
2198 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092199
brettw4b461082016-11-19 18:55:162200#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492201 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092202 return;
2203#endif
2204
lfg8ff33912016-09-13 20:59:212205 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092206 return;
2207 blink::WebVector<blink::WebRect> bounds_from_blink;
Blink Reformat1c4d759e2017-04-09 16:34:542208 if (!GetWebWidget()->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092209 return;
2210
2211 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542212 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092213 bounds->push_back(bounds_from_blink[i]);
2214 }
[email protected]58b48a0d2012-06-13 07:01:352215}
2216
[email protected]db4fc1e2013-09-06 20:01:512217void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162218#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492219 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092220 return;
2221#endif
EhsanKcdee7b72017-11-08 21:30:092222 blink::WebInputMethodController* controller = GetInputMethodController();
2223 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542224 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212225 *range = gfx::Range::InvalidRange();
2226 return;
[email protected]88dbe32f2013-06-20 23:31:362227 }
Blink Reformat1c4d759e2017-04-09 16:34:542228 range->set_start(web_range.StartOffset());
2229 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362230}
2231
[email protected]501ea13d2013-07-09 17:03:292232bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512233 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292234 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082235 if (!range.IsValid())
2236 return false;
[email protected]501ea13d2013-07-09 17:03:292237 if (composition_range_ != range)
2238 return true;
2239 if (bounds.size() != composition_character_bounds_.size())
2240 return true;
2241 for (size_t i = 0; i < bounds.size(); ++i) {
2242 if (bounds[i] != composition_character_bounds_[i])
2243 return true;
2244 }
2245 return false;
2246}
[email protected]501ea13d2013-07-09 17:03:292247
[email protected]ad26ef42011-06-17 07:59:452248bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162249#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492250 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2251 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092252#endif
[email protected]ad26ef42011-06-17 07:59:452253 return true;
[email protected]56ea1a62011-05-30 07:05:572254}
2255
Blink Reformat1c4d759e2017-04-09 16:34:542256blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272257 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542258 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542259 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272260 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542261 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2262 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272263 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542264 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272265 switch (screen_info_.orientation_type) {
2266 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542267 web_screen_info.orientation_type =
2268 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272269 break;
2270 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542271 web_screen_info.orientation_type =
2272 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272273 break;
2274 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542275 web_screen_info.orientation_type =
2276 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272277 break;
2278 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542279 web_screen_info.orientation_type =
2280 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272281 break;
2282 default:
Blink Reformat1c4d759e2017-04-09 16:34:542283 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272284 break;
2285 }
Blink Reformat1c4d759e2017-04-09 16:34:542286 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202287
ccameron2f451532016-09-07 21:49:272288 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282289}
2290
donnda070f3c2015-01-16 19:54:112291#if defined(OS_ANDROID)
Donn Denman43a439e2017-08-29 04:20:452292void RenderWidget::ShowUnhandledTapUIIfNeeded(
2293 const WebTappedInfo& tapped_info) {
2294 // Unpack tapped_info. TODO(donnd): inline unpacking.
2295 bool page_changed = tapped_info.PageChanged();
2296 const WebNode& tapped_node = tapped_info.GetNode();
2297 const WebPoint& tapped_position = tapped_info.Position();
Blink Reformat1c4d759e2017-04-09 16:34:542298 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2299 !tapped_node.IsContentEditable() &&
2300 !tapped_node.IsInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112301 if (should_trigger) {
Donn Denman43a439e2017-08-29 04:20:452302 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(
2303 routing_id_, tapped_position.x, tapped_position.y));
donnda070f3c2015-01-16 19:54:112304 }
2305}
2306#endif
2307
Blink Reformat1c4d759e2017-04-09 16:34:542308void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2309 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022310#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562311 if (event_cancelled)
2312 return;
Blink Reformat1c4d759e2017-04-09 16:34:542313 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002314 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542315 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212316 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352317 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542318 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002319 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462320 else
changwan75e3b2072017-01-16 02:55:002321 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562322 }
ekaramada110f642016-12-21 19:47:282323// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2324// crbug/420130.
2325#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542326 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282327 return;
2328
2329 // TODO(estade): hit test the event against focused node to make sure
2330 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352331 blink::WebInputMethodController* controller = GetInputMethodController();
2332 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542333 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282334
2335 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542336 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282337#endif
[email protected]c68c3e4e2013-01-24 00:36:562338#endif
2339}
2340
Blink Reformat1c4d759e2017-04-09 16:34:542341void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312342 const blink::WebFloatSize& overscrollDelta,
2343 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422344 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542345 const blink::WebFloatSize& velocity,
2346 const blink::WebScrollBoundaryBehavior& behavior) {
bokan731ec382016-04-07 03:16:482347#if defined(OS_MACOSX)
2348 // On OSX the user can disable the elastic overscroll effect. If that's the
2349 // case, don't forward the overscroll notification.
2350 DCHECK(compositor_deps());
2351 if (!compositor_deps()->IsElasticOverscrollEnabled())
2352 return;
2353#endif
bokane53a10f2016-04-13 23:48:312354 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542355 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422356}
2357
[email protected]7912e822014-04-16 02:37:032358void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392359 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542360 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032361}
2362
[email protected]24ed0432013-04-24 07:50:312363RenderWidgetCompositor* RenderWidget::compositor() const {
2364 return compositor_.get();
2365}
2366
fsamuel72464894f2015-12-15 06:59:312367void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392368 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372369}
[email protected]c3d45532011-10-07 19:20:402370
Blink Reformat1c4d759e2017-04-09 16:34:542371void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112372 if (render_widget_scheduling_state_)
2373 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552374 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2375}
2376
Dave Tapuskadfe486c12017-06-09 16:53:132377void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2378 if (input_event_queue_)
2379 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2380}
2381
xidachenfa0199e72017-05-11 11:34:262382void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262383 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512384 return;
2385
Dave Tapuska139a72f2017-09-06 21:57:032386 if (widget_input_handler_manager_) {
2387 widget_input_handler_manager_->ProcessTouchAction(touch_action);
2388 } else {
2389 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
2390 }
[email protected]5d0bbdfa92013-12-10 00:35:512391}
2392
[email protected]e3244ed2014-06-20 20:04:272393void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2394 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162395}
2396
[email protected]e3244ed2014-06-20 20:04:272397void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2398 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162399}
2400
[email protected]de3c5d82014-05-28 22:12:592401void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2402 render_frames_.AddObserver(frame);
2403}
2404
2405void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2406 render_frames_.RemoveObserver(frame);
2407}
2408
lfg43e08e62016-02-03 18:51:372409void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2410 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2411 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2412}
2413
oshima50872a72016-03-04 13:26:182414float RenderWidget::GetOriginalDeviceScaleFactor() const {
2415 return
2416 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272417 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182418 device_scale_factor_;
2419}
2420
paulmeyer90f6c31d2016-11-12 00:17:592421gfx::Point RenderWidget::ConvertWindowPointToViewport(
2422 const gfx::Point& point) {
2423 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542424 ConvertWindowToViewport(&point_in_viewport);
paulmeyer90f6c31d2016-11-12 00:17:592425 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2426}
2427
Blink Reformat1c4d759e2017-04-09 16:34:542428bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212429 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2430}
2431
Blink Reformat1c4d759e2017-04-09 16:34:542432void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212433 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2434}
2435
Blink Reformat1c4d759e2017-04-09 16:34:542436bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212437 return mouse_lock_dispatcher_->IsMouseLockedTo(
2438 webwidget_mouse_lock_target_.get());
2439}
2440
Blink Reformat1c4d759e2017-04-09 16:34:542441void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582442 const WebDragData& data,
2443 WebDragOperationsMask mask,
2444 const WebImage& image,
2445 const WebPoint& webImageOffset) {
2446 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542447 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582448 DropData drop_data(DropDataBuilder::Build(data));
2449 drop_data.referrer_policy = policy;
2450 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592451 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542452 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582453 possible_drag_event_info_));
2454}
2455
kenrb5d78b842017-03-06 21:06:012456uint32_t RenderWidget::GetContentSourceId() {
2457 return current_content_source_id_;
2458}
2459
2460void RenderWidget::IncrementContentSourceId() {
2461 if (compositor_)
2462 compositor_->SetContentSourceId(++current_content_source_id_);
2463}
2464
lfg8ff33912016-09-13 20:59:212465blink::WebWidget* RenderWidget::GetWebWidget() const {
2466 return webwidget_internal_;
2467}
2468
ekaramad2daaf672016-11-10 20:29:012469blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2470 const {
Blink Reformat1c4d759e2017-04-09 16:34:542471 if (!GetWebWidget()->IsWebFrameWidget()) {
ekaramad5a9f52a2016-12-07 01:35:182472 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2473 // when the RenderWidget is swapped out. We should top sending IPCs from the
2474 // browser side (https://crbug.com/669219).
2475 // If there is no WebFrameWidget, then there will be no
2476 // InputMethodControllers for a WebLocalFrame.
2477 return nullptr;
2478 }
ekaramad2daaf672016-11-10 20:29:012479 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:542480 ->GetActiveWebInputMethodController();
ekaramad2daaf672016-11-10 20:29:012481}
2482
Dave Tapuska139a72f2017-09-06 21:57:032483void RenderWidget::SetupWidgetInputHandler(
2484 mojom::WidgetInputHandlerRequest request,
2485 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuska525eb15e2017-08-17 21:05:502486 widget_input_handler_manager_->AddInterface(std::move(request));
Dave Tapuska139a72f2017-09-06 21:57:032487 widget_input_handler_manager_->SetWidgetInputHandlerHost(std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502488}
2489
Dave Tapuska485aca92017-08-08 00:47:582490void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2491 // Close the old binding if there was one.
2492 // A RenderWidgetHost should not need more than one channel.
2493 widget_binding_.Close();
2494 widget_binding_.Bind(std::move(request));
2495}
2496
Fady Samuelcc3e3b4a2017-10-03 02:09:212497void RenderWidget::DidResizeOrRepaintAck() {
Fady Samueld10aadd82017-11-03 18:23:572498 if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_)
Fady Samuel319e429c2017-10-02 18:31:552499 return;
2500
Fady Samuelcc3e3b4a2017-10-03 02:09:212501 ViewHostMsg_ResizeOrRepaint_ACK_Params params;
Fady Samuel319e429c2017-10-02 18:31:552502 params.view_size = size_;
2503 params.flags = next_paint_flags_;
2504 params.sequence_number = ++resize_or_repaint_ack_num_;
2505
Fady Samuelcc3e3b4a2017-10-03 02:09:212506 Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params));
Fady Samuel319e429c2017-10-02 18:31:552507 next_paint_flags_ = 0;
Fady Samueld10aadd82017-11-03 18:23:572508 need_resize_ack_for_auto_resize_ = false;
Fady Samuel319e429c2017-10-02 18:31:552509}
2510
Khushal3e96e662017-10-30 23:16:502511void RenderWidget::UpdateURLForCompositorUkm() {
2512 DCHECK(compositor_);
2513
2514 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2515 return;
2516
2517 auto* render_frame = RenderFrameImpl::FromWebFrame(
2518 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot());
2519 if (!render_frame->IsMainFrame())
2520 return;
2521
2522 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2523}
2524
EhsanK22d482e2017-08-10 17:29:492525#if BUILDFLAG(ENABLE_PLUGINS)
2526PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
2527 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2528 return nullptr;
2529
2530 // Focused pepper instance might not always be in the focused frame. For
2531 // instance if a pepper instance and its embedder frame are focused an then
2532 // another frame takes focus using javascript, the embedder frame will no
2533 // longer be focused while the pepper instance is (the embedder frame's
2534 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2535 // is fullscreen, clicking into the pepper will not refocus the embedder
2536 // frame. This is why we have to traverse the whole frame tree to find the
2537 // focused plugin.
2538 blink::WebFrame* current_frame =
2539 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot();
2540 while (current_frame) {
2541 RenderFrameImpl* render_frame =
2542 current_frame->IsWebLocalFrame()
2543 ? RenderFrameImpl::FromWebFrame(current_frame)
2544 : nullptr;
2545 if (render_frame && render_frame->focused_pepper_plugin())
2546 return render_frame->focused_pepper_plugin();
2547 current_frame = current_frame->TraverseNext();
2548 }
2549 return nullptr;
2550}
2551#endif
2552
[email protected]e9ff79c2012-10-19 21:31:262553} // namespace content