blob: 316edef0fe93a20fd5fa2fdf6af2dc5a81dc2275 [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"
Antoine Laboure55c9ef82017-11-10 18:51:2371#include "ipc/ipc_sync_message_filter.h"
brettw4b461082016-11-19 18:55:1672#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4873#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2574#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1875#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5976#include "third_party/WebKit/public/platform/WebDragData.h"
77#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5578#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1179#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3080#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3081#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3082#include "third_party/WebKit/public/platform/WebSize.h"
83#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5184#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
85#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2986#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4387#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5988#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0189#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5990#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1191#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3193#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
94#include "third_party/WebKit/public/web/WebRange.h"
Donn Denman43a439e2017-08-29 04:20:4595#include "third_party/WebKit/public/web/WebTappedInfo.h"
kenrba7199832015-01-22 23:44:5996#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0897#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4198#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5999#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:13100#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:43101#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:50102#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09103#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32104#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48105#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27106#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41107#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48108
[email protected]eeb93112013-05-01 19:41:10109#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15110#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24111#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10112#endif
113
[email protected]661eb9d2009-02-03 02:11:48114#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52115#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41116#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48117#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44118
sadrul943e3b32016-08-04 18:22:59119#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10120#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19121#endif
122
ekaramad330ba4232016-09-23 17:57:47123#if defined(OS_MACOSX)
124#include "content/renderer/text_input_client_observer.h"
125#endif
126
Ryan Landay9e42fd742017-08-12 01:59:11127using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46128using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43129using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59130using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58131using blink::WebDragOperationsMask;
132using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59133using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46134using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58135using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46136using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49137using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01138using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58139using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46140using blink::WebMouseEvent;
141using blink::WebMouseWheelEvent;
142using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11143using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46144using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11145using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46146using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48147using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46148using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46149using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59150using blink::WebString;
Donn Denman43a439e2017-08-29 04:20:45151using blink::WebTappedInfo;
[email protected]180ef242013-11-07 06:50:46152using blink::WebTextDirection;
153using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25154using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46155using blink::WebVector;
156using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26157
paulmeyer90f6c31d2016-11-12 00:17:59158namespace content {
159
[email protected]6a4d7f62013-01-07 21:32:13160namespace {
[email protected]b256eca2013-07-11 10:57:40161
162typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
163
AJITH KUMAR V041c0b02017-08-08 10:39:20164static const int kInvalidNextPreviousFlagsValue = -1;
165
lfgbee1e0a2016-06-08 21:24:21166class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
167 public:
168 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
169 : webwidget_(webwidget) {}
170
171 void OnLockMouseACK(bool succeeded) override {
172 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54173 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21174 else
Blink Reformat1c4d759e2017-04-09 16:34:54175 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21176 }
177
Blink Reformat1c4d759e2017-04-09 16:34:54178 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21179
180 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
181 // The WebWidget handles mouse lock in Blink's handleInputEvent().
182 return false;
183 }
184
185 private:
186 blink::WebWidget* webwidget_;
187};
188
dglazkov97b6c2b2016-10-25 17:35:55189bool IsDateTimeInput(ui::TextInputType type) {
190 return type == ui::TEXT_INPUT_TYPE_DATE ||
191 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
192 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
193 type == ui::TEXT_INPUT_TYPE_MONTH ||
194 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
195}
196
paulmeyer90f6c31d2016-11-12 00:17:59197WebDragData DropMetaDataToWebDragData(
198 const std::vector<DropData::Metadata>& drop_meta_data) {
199 std::vector<WebDragData::Item> item_list;
200 for (const auto& meta_data_item : drop_meta_data) {
201 if (meta_data_item.kind == DropData::Kind::STRING) {
202 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54203 item.storage_type = WebDragData::Item::kStorageTypeString;
204 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59205 // Have to pass a dummy URL here instead of an empty URL because the
206 // DropData received by browser_plugins goes through a round trip:
207 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
208 // will contain an empty URL (which means no URL is dragged) if the URL in
209 // WebDragData is empty.
210 if (base::EqualsASCII(meta_data_item.mime_type,
211 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54212 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59213 }
214 item_list.push_back(item);
215 continue;
216 }
217
218 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
219 // just the mimetype. This is needed to drag files to WebView on Android
220 // platform.
221 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
222 !meta_data_item.filename.empty()) {
223 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54224 item.storage_type = WebDragData::Item::kStorageTypeFilename;
225 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59226 item_list.push_back(item);
227 continue;
228 }
229
230 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
231 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54232 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
233 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59234 item_list.push_back(item);
235 continue;
236 }
237 }
238
239 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54240 result.Initialize();
241 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59242 return result;
243}
244
245WebDragData DropDataToWebDragData(const DropData& drop_data) {
246 std::vector<WebDragData::Item> item_list;
247
248 // These fields are currently unused when dragging into WebKit.
249 DCHECK(drop_data.download_metadata.empty());
250 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23251 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59252
253 if (!drop_data.text.is_null()) {
254 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54255 item.storage_type = WebDragData::Item::kStorageTypeString;
256 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
257 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59258 item_list.push_back(item);
259 }
260
261 if (!drop_data.url.is_empty()) {
262 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54263 item.storage_type = WebDragData::Item::kStorageTypeString;
264 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
265 item.string_data = WebString::FromUTF8(drop_data.url.spec());
266 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59267 item_list.push_back(item);
268 }
269
270 if (!drop_data.html.is_null()) {
271 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54272 item.storage_type = WebDragData::Item::kStorageTypeString;
273 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
274 item.string_data = WebString::FromUTF16(drop_data.html.string());
275 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59276 item_list.push_back(item);
277 }
278
279 for (std::vector<ui::FileInfo>::const_iterator it =
280 drop_data.filenames.begin();
281 it != drop_data.filenames.end();
282 ++it) {
283 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54284 item.storage_type = WebDragData::Item::kStorageTypeFilename;
285 item.filename_data = blink::FilePathToWebString(it->path);
286 item.display_name_data =
kinukoa4293022017-01-27 06:43:25287 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59288 item_list.push_back(item);
289 }
290
291 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
292 drop_data.file_system_files.begin();
293 it != drop_data.file_system_files.end();
294 ++it) {
295 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54296 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
297 item.file_system_url = it->url;
298 item.file_system_file_size = it->size;
299 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59300 item_list.push_back(item);
301 }
302
Stuart Langley48300392017-11-02 03:54:44303 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59304 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54305 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44306 item.string_type = WebString::FromUTF16(it.first);
307 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59308 item_list.push_back(item);
309 }
310
311 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54312 result.Initialize();
313 result.SetItems(item_list);
314 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59315 return result;
316}
317
lfg1568d112016-08-30 16:06:29318content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
319 nullptr;
320
321content::RenderWidget::RenderWidgetInitializedCallback
322 g_render_widget_initialized = nullptr;
323
dtapuskac4dd5be2016-10-25 15:11:10324ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
325 // Check the type is in the range representable by ui::TextInputType.
326 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
327 << "blink::WebTextInputType and ui::TextInputType not synchronized";
328 return static_cast<ui::TextInputType>(type);
329}
330
331ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
332 // Check the mode is in the range representable by ui::TextInputMode.
333 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
334 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
335 return static_cast<ui::TextInputMode>(mode);
336}
337
[email protected]b256eca2013-07-11 10:57:40338} // namespace
339
[email protected]b2e4c70132013-10-03 02:07:51340// RenderWidget ---------------------------------------------------------------
341
nick8331f8ad2016-11-15 20:42:45342RenderWidget::RenderWidget(int32_t widget_routing_id,
343 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36344 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27345 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04346 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03347 bool hidden,
Dave Tapuska1bdf1832017-07-07 18:07:19348 bool never_visible,
349 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45350 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36351 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21352 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44353 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29354 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51355 auto_resize_mode_(false),
Fady Samueld10aadd82017-11-03 18:23:57356 need_resize_ack_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29357 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04358 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39359 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12360 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54361 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16362 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48363 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22364 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44365 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20366 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55367 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40368 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20369 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20370 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53371 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18372 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12373 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48374 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04375 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27376 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18377 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51378 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12379 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42380 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08381 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24382 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09383 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47384#if defined(OS_MACOSX)
385 text_input_client_observer_(new TextInputClientObserver(this)),
386#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27387 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50388 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01389 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19390 widget_binding_(this, std::move(widget_request)),
wjmaclean1d970622017-01-21 22:28:24391 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45392 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05393 if (!swapped_out)
394 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27395 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11396
397 // In tests there may not be a RenderThreadImpl.
398 if (RenderThreadImpl::current()) {
399 render_widget_scheduling_state_ = RenderThreadImpl::current()
400 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32401 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11402 render_widget_scheduling_state_->SetHidden(is_hidden_);
403 }
sadrul602ce1362017-01-26 06:41:10404#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14405 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
Scott Violet1098538e2017-10-05 19:23:33406 if (IsRunningInMash())
407 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10408#endif
initial.commit09911bf2008-07-26 23:55:29409}
410
411RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21412 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16413
dtapuska9ec1a912017-04-21 15:18:31414 if (input_event_queue_)
415 input_event_queue_->ClearClient();
416
[email protected]992db4c2011-05-12 15:37:15417 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02418 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15419 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11420#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14421 // It is possible for a RenderWidget to be destroyed before it was embedded
422 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
423 // explicitly delete it here.
424 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11425#endif
initial.commit09911bf2008-07-26 23:55:29426}
427
[email protected]484955942010-08-19 16:13:18428// static
lfg1568d112016-08-30 16:06:29429void RenderWidget::InstallCreateHook(
430 CreateRenderWidgetFunction create_render_widget,
431 RenderWidgetInitializedCallback render_widget_initialized) {
432 CHECK(!g_create_render_widget && !g_render_widget_initialized);
433 g_create_render_widget = create_render_widget;
434 g_render_widget_initialized = render_widget_initialized;
435}
436
437// static
nickf7b38222016-11-22 21:59:35438RenderWidget* RenderWidget::CreateForPopup(
439 RenderViewImpl* opener,
440 CompositorDependencies* compositor_deps,
441 blink::WebPopupType popup_type,
442 const ScreenInfo& screen_info) {
Dave Tapuska1bdf1832017-07-07 18:07:19443 mojom::WidgetPtr widget_channel;
444 mojom::WidgetRequest widget_channel_request =
445 mojo::MakeRequest(&widget_channel);
446
nick4df698d82016-11-11 20:39:23447 // Do a synchronous IPC to obtain a routing ID.
448 int32_t routing_id = MSG_ROUTING_NONE;
449 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19450 opener->GetRoutingID(), popup_type, std::move(widget_channel),
451 &routing_id)) {
nick4df698d82016-11-11 20:39:23452 return nullptr;
453 }
454
nick8331f8ad2016-11-15 20:42:45455 scoped_refptr<RenderWidget> widget(
456 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
Dave Tapuska1bdf1832017-07-07 18:07:19457 false, false, false, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35458 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24459 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35460 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23461 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
462 return widget.get();
initial.commit09911bf2008-07-26 23:55:29463}
464
[email protected]484955942010-08-19 16:13:18465// static
kenrba7199832015-01-22 23:44:59466RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23467 int widget_routing_id,
kenrba7199832015-01-22 23:44:59468 bool hidden,
ccameron2f451532016-09-07 21:49:27469 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59470 CompositorDependencies* compositor_deps,
471 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23472 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55473 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
474 // same routing ID for both the view routing ID and the main frame widget
475 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23476 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55477 if (view) {
avi8a45c1092016-03-01 16:12:34478 view->AttachWebFrameWidget(
479 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
480 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55481 }
dcheng35d31c112015-07-22 00:17:36482 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29483 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45484 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54485 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45486 hidden, false)
487 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54488 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45489 hidden, false));
simonhong628f9812015-04-27 23:13:20490 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23491 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59492 // this function returns.
nickf7b38222016-11-22 21:59:35493 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23494 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
495
496 if (g_render_widget_initialized)
497 g_render_widget_initialized(widget.get());
498 return widget.get();
kenrba7199832015-01-22 23:44:59499}
500
501// static
lfgcaab5142016-02-26 19:06:52502blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08503 RenderWidget* render_widget,
504 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54505 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08506}
507
508// static
kenrba7199832015-01-22 23:44:59509blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18510 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54511 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18512 break;
Blink Reformat1c4d759e2017-04-09 16:34:54513 case blink::kWebPopupTypePage:
514 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18515 default:
516 NOTREACHED();
517 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28518 return nullptr;
[email protected]484955942010-08-19 16:13:18519}
520
dchengda9b4bb2015-07-20 20:58:08521void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32522 OnClose();
kenrba7199832015-01-22 23:44:59523}
524
alexmos78c9c0d2016-10-14 18:57:03525void RenderWidget::SetSwappedOut(bool is_swapped_out) {
526 // We should only toggle between states.
527 DCHECK(is_swapped_out_ != is_swapped_out);
528 is_swapped_out_ = is_swapped_out;
529
530 // If we are swapping out, we will call ReleaseProcess, allowing the process
531 // to exit if all of its RenderViews are swapped out. We wait until the
532 // WasSwappedOut call to do this, to allow the unload handler to finish.
533 // If we are swapping in, we call AddRefProcess to prevent the process from
534 // exiting.
535 if (!is_swapped_out_)
536 RenderProcess::current()->AddRefProcess();
537}
538
nickf7b38222016-11-22 21:59:35539void RenderWidget::Init(const ShowCallback& show_callback,
540 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21541 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23542 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29543
Jeremy Roman04f27c372017-10-27 15:20:55544 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45545
Dave Tapuska9db80842017-07-24 17:24:26546 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
547 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
548
Dave Tapuska525eb15e2017-08-17 21:05:50549 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
Dave Tapuska139a72f2017-09-06 21:57:03550 weak_ptr_factory_.GetWeakPtr(),
Dave Tapuska9db80842017-07-24 17:24:26551 render_thread_impl && compositor_
552 ? render_thread_impl->compositor_task_runner()
553 : nullptr,
554 render_thread_impl ? render_thread_impl->GetRendererScheduler()
555 : nullptr);
556 }
557
nickf7b38222016-11-22 21:59:35558 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29559
lfg8ff33912016-09-13 20:59:21560 webwidget_internal_ = web_widget;
561 webwidget_mouse_lock_target_.reset(
562 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21563 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29564
nick4df698d82016-11-11 20:39:23565 RenderThread::Get()->AddRoute(routing_id_, this);
566 // Take a reference on behalf of the RenderThread. This will be balanced
567 // when we receive ViewMsg_Close.
568 AddRef();
569 if (RenderThreadImpl::current()) {
570 RenderThreadImpl::current()->WidgetCreated();
571 if (is_hidden_)
572 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29573 }
574}
575
[email protected]949b6592014-08-20 13:17:52576void RenderWidget::WasSwappedOut() {
577 // If we have been swapped out and no one else is using this process,
578 // it's safe to exit now.
579 CHECK(is_swapped_out_);
580 RenderProcess::current()->ReleaseProcess();
581}
582
[email protected]b2e4c70132013-10-03 02:07:51583void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39584 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51585 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43586 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00587 popup_screen_origin_for_emulation_ =
588 gfx::Point(emulator->original_screen_rect().origin().x(),
589 emulator->original_screen_rect().origin().y());
[email protected]5f75aa42014-04-01 23:00:56590 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27591 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51592}
593
[email protected]2d6836f42014-07-02 17:25:31594gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
595 if (screen_metrics_emulator_)
596 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
597 return anchor;
598}
599
thakis18e426412017-03-15 12:06:37600#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51601void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39602 ExternalPopupMenu* popup,
603 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00604 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51605}
[email protected]53907862014-03-25 15:42:40606#endif
[email protected]b2e4c70132013-10-03 02:07:51607
Fady Samuel69b33b52017-11-08 22:01:52608void RenderWidget::SetLocalSurfaceIdForAutoResize(
609 uint64_t sequence_number,
610 const content::ScreenInfo& screen_info,
611 const viz::LocalSurfaceId& local_surface_id) {
612 bool screen_info_changed = screen_info_ != screen_info;
613
614 screen_info_ = screen_info;
615 if (device_scale_factor_ != screen_info_.device_scale_factor) {
616 device_scale_factor_ = screen_info_.device_scale_factor;
617 OnDeviceScaleFactorChanged();
618 }
619
620 if (screen_info_changed) {
621 for (auto& observer : render_frame_proxies_)
622 observer.OnScreenInfoChanged(screen_info);
623
624 // Notify all BrowserPlugins of the updated ScreenInfo.
625 if (BrowserPluginManager::Get())
626 BrowserPluginManager::Get()->ScreenInfoChanged(screen_info);
627 }
628
629 AutoResizeCompositor(local_surface_id);
630}
631
[email protected]b2e4c70132013-10-03 02:07:51632void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
633 if (screen_metrics_emulator_)
634 screen_metrics_emulator_->OnShowContextMenu(params);
635}
636
[email protected]a95986a82010-12-24 06:19:28637bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47638#if defined(OS_MACOSX)
639 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
640 return text_input_client_observer_->OnMessageReceived(message);
641#endif
lfgbee1e0a2016-06-08 21:24:21642 if (mouse_lock_dispatcher_ &&
643 mouse_lock_dispatcher_->OnMessageReceived(message))
644 return true;
645
[email protected]a95986a82010-12-24 06:19:28646 bool handled = true;
647 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15648 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22649 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
650 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22651 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29652 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
653 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
654 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15655 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46656 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
657 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15658 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
wjmacleanee244e02017-05-26 21:06:07659 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28660 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28661 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
Fady Samuel319e429c2017-10-02 18:31:55662 IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize,
663 OnSetLocalSurfaceIdForAutoResize)
dgozman9260b0a12015-03-16 13:45:20664 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
665 OnEnableDeviceEmulation)
666 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
667 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28668 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41669 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25670 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28671 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
672 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03673 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48674 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
675 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32676 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
lfg43e08e62016-02-03 18:51:37677 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
678 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23679 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
680 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59681 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
682 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
683 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
684 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21685 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
686 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
687 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21688#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39689 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
690 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21691#endif
[email protected]a95986a82010-12-24 06:19:28692 IPC_MESSAGE_UNHANDLED(handled = false)
693 IPC_END_MESSAGE_MAP()
694 return handled;
695}
initial.commit09911bf2008-07-26 23:55:29696
697bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42698 // Don't send any messages after the browser has told us to close, and filter
699 // most outgoing messages while swapped out.
700 if ((is_swapped_out_ &&
701 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
702 closing_) {
initial.commit09911bf2008-07-26 23:55:29703 delete message;
704 return false;
705 }
706
707 // If given a messsage without a routing ID, then assign our routing ID.
708 if (message->routing_id() == MSG_ROUTING_NONE)
709 message->set_routing_id(routing_id_);
710
[email protected]380244092011-10-07 17:26:27711 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44712}
713
dtapuska014ed082016-11-11 21:58:48714void RenderWidget::SendOrCrash(IPC::Message* message) {
715 bool result = Send(message);
716 CHECK(closing_ || result) << "Failed to send message";
717}
718
ekaramad5aff1942017-01-06 01:26:35719bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26720 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
721 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
722 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
723 // will be processed regardless of page focus. We should revisit this after
724 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54725 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26726 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35727}
728
bokanc007c3a2015-02-03 07:15:56729void RenderWidget::SetWindowRectSynchronously(
730 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39731 ResizeParams params;
732 params.screen_info = screen_info_;
733 params.new_size = new_window_rect.size();
734 params.physical_backing_size =
735 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39736 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39737 params.is_fullscreen_granted = is_fullscreen_granted_;
738 params.display_mode = display_mode_;
739 params.needs_resize_ack = false;
740 Resize(params);
741
bokanc007c3a2015-02-03 07:15:56742 view_screen_rect_ = new_window_rect;
743 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02744 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56745 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02746}
747
initial.commit09911bf2008-07-26 23:55:29748void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32749 DCHECK(content::RenderThread::Get());
750 if (closing_)
751 return;
752 NotifyOnClose();
753 closing_ = true;
754
755 // Browser correspondence is no longer needed at this point.
756 if (routing_id_ != MSG_ROUTING_NONE) {
757 RenderThread::Get()->RemoveRoute(routing_id_);
758 SetHidden(false);
759 if (RenderThreadImpl::current())
760 RenderThreadImpl::current()->WidgetDestroyed();
761 }
762
763 if (for_oopif_) {
764 // Widgets for frames may be created and closed at any time while the frame
765 // is alive. However, the closing process must happen synchronously. Frame
766 // widget and frames hold pointers to each other. If Close() is deferred to
767 // the message loop like in the non-frame widget case, WebWidget::close()
768 // can end up accessing members of an already-deleted frame.
769 Close();
770 } else {
771 // If there is a Send call on the stack, then it could be dangerous to close
772 // now. Post a task that only gets invoked when there are no nested message
773 // loops.
774 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
tzikff2a81a2017-09-15 05:10:06775 FROM_HERE, base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32776 }
777
778 // Balances the AddRef taken when we called AddRoute.
779 Release();
initial.commit09911bf2008-07-26 23:55:29780}
781
fsamuel664e8b62016-01-20 19:54:01782void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04783 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32784 return;
785
[email protected]b2e4c70132013-10-03 02:07:51786 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39787 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51788 return;
789 }
790
mfomitchev2600fd7c2016-02-17 20:53:39791 Resize(params);
initial.commit09911bf2008-07-26 23:55:29792}
793
Fady Samuel319e429c2017-10-02 18:31:55794void RenderWidget::OnSetLocalSurfaceIdForAutoResize(
795 uint64_t sequence_number,
Fady Samuel69b33b52017-11-08 22:01:52796 const gfx::Size& min_size,
797 const gfx::Size& max_size,
798 const content::ScreenInfo& screen_info,
Fady Samuel319e429c2017-10-02 18:31:55799 const viz::LocalSurfaceId& local_surface_id) {
800 if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number)
801 return;
Fady Samuel69b33b52017-11-08 22:01:52802
803 SetLocalSurfaceIdForAutoResize(sequence_number, screen_info,
804 local_surface_id);
Fady Samuel319e429c2017-10-02 18:31:55805}
806
dgozman9260b0a12015-03-16 13:45:20807void RenderWidget::OnEnableDeviceEmulation(
Nasko Oskovf97e8b02017-07-25 02:45:42808 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39809 if (!screen_metrics_emulator_) {
810 ResizeParams resize_params;
811 resize_params.screen_info = screen_info_;
812 resize_params.new_size = size_;
813 resize_params.physical_backing_size = physical_backing_size_;
814 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39815 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
816 resize_params.display_mode = display_mode_;
817 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
818 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18819 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39820 } else {
dgozman9260b0a12015-03-16 13:45:20821 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39822 }
dgozman9260b0a12015-03-16 13:45:20823}
824
825void RenderWidget::OnDisableDeviceEmulation() {
826 screen_metrics_emulator_.reset();
827}
828
initial.commit09911bf2008-07-26 23:55:29829void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31830 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29831 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03832 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55833 for (auto& observer : render_frames_)
834 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29835}
836
[email protected]3399dd822014-08-09 11:14:24837void RenderWidget::OnWasShown(bool needs_repainting,
838 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41839 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29840 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21841 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29842 return;
843
tasakb95dbb50c2017-02-08 18:07:50844 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29845 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03846 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55847 for (auto& observer : render_frames_)
848 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29849
[email protected]8a23afb32014-04-30 22:40:23850 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29851 return;
initial.commit09911bf2008-07-26 23:55:29852
[email protected]3399dd822014-08-09 11:14:24853 if (compositor_) {
854 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11855 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
856 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
857 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54858 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24859 }
initial.commit09911bf2008-07-26 23:55:29860}
861
[email protected]53d3f302009-12-21 04:42:05862void RenderWidget::OnRequestMoveAck() {
863 DCHECK(pending_window_rect_count_);
864 pending_window_rect_count_--;
865}
866
[email protected]ed7defa2013-03-12 21:29:59867GURL RenderWidget::GetURLForGraphicsContext3D() {
868 return GURL();
[email protected]65225772011-05-12 21:10:24869}
870
nzolghadr5d8596502017-01-23 22:59:35871void RenderWidget::OnHandleInputEvent(
872 const blink::WebInputEvent* input_event,
873 const std::vector<const blink::WebInputEvent*>& coalesced_events,
874 const ui::LatencyInfo& latency_info,
875 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23876 if (!input_event)
877 return;
nzolghadr5d8596502017-01-23 22:59:35878
Dave Tapuskaea83d3bd2017-06-13 16:14:55879 HandledEventCallback callback;
880 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
881 callback = base::Bind(
882 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
883 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
884 }
nzolghadr5d8596502017-01-23 22:59:35885 input_handler_->HandleInputEvent(
886 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55887 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23888}
889
Navid Zolghadr0d86e5f2017-10-23 18:09:22890int RenderWidget::GetWidgetRoutingIdAtPoint(const gfx::Point& point) {
891 return input_handler_->GetWidgetRoutingIdAtPoint(point);
892}
893
Dave Tapuskaea83d3bd2017-06-13 16:14:55894void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31895 const blink::WebCoalescedInputEvent& input_event,
896 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55897 HandledEventCallback callback) {
898 input_handler_->HandleInputEvent(input_event, latency_info,
899 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31900}
901
Dave Tapuskaea83d3bd2017-06-13 16:14:55902void RenderWidget::SendInputEventAck(
903 blink::WebInputEvent::Type type,
904 uint32_t touch_event_id,
905 InputEventAckState ack_state,
906 const ui::LatencyInfo& latency_info,
Dave Tapuskab28a1082017-08-30 15:37:26907 std::unique_ptr<ui::DidOverscrollParams> overscroll_params,
908 base::Optional<cc::TouchAction> touch_action) {
Dave Tapuskaea83d3bd2017-06-13 16:14:55909 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
Dave Tapuskab28a1082017-08-30 15:37:26910 latency_info, std::move(overscroll_params), touch_event_id,
911 touch_action);
dtapuska9ec1a912017-04-21 15:18:31912 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
913}
914
dtapuska9d46ef7d2017-05-26 19:06:06915scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
916 return input_event_queue_;
917}
918
fsamuel78f86e42016-01-20 04:10:23919void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21920 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54921 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23922}
923
924void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21925 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54926 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23927}
928
alexmos56567492016-09-13 00:52:46929void RenderWidget::OnSetEditCommandsForNextKeyEvent(
930 const EditCommands& edit_commands) {
931 edit_commands_ = edit_commands;
932}
933
fsamuel78f86e42016-01-20 04:10:23934void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08935 has_focus_ = enable;
936
lfg8ff33912016-09-13 20:59:21937 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54938 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08939
ericwilligers88e69742016-10-17 19:29:55940 for (auto& observer : render_frames_)
941 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23942}
943
dtapuska3d5624d32016-08-30 04:34:00944void RenderWidget::SetNeedsMainFrame() {
945 RenderWidgetCompositor* rwc = compositor();
946 if (!rwc)
947 return;
Blink Reformat1c4d759e2017-04-09 16:34:54948 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00949}
950
fsamuel78f86e42016-01-20 04:10:23951///////////////////////////////////////////////////////////////////////////////
952// RenderWidgetCompositorDelegate
953
954void RenderWidget::ApplyViewportDeltas(
955 const gfx::Vector2dF& inner_delta,
956 const gfx::Vector2dF& outer_delta,
957 const gfx::Vector2dF& elastic_overscroll_delta,
958 float page_scale,
959 float top_controls_delta) {
Blink Reformat1c4d759e2017-04-09 16:34:54960 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21961 elastic_overscroll_delta, page_scale,
962 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23963}
964
sahel1b47fda72017-03-28 17:03:07965void RenderWidget::RecordWheelAndTouchScrollingCount(
966 bool has_scrolled_by_wheel,
967 bool has_scrolled_by_touch) {
Blink Reformat1c4d759e2017-04-09 16:34:54968 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07969 has_scrolled_by_touch);
970}
971
fsamuel78f86e42016-01-20 04:10:23972void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska9ec1a912017-04-21 15:18:31973 if (input_event_queue_) {
974 input_event_queue_->DispatchRafAlignedInput(
975 ui::EventTimeStampFromSeconds(frame_time_sec));
976 }
dtapuska3d5624d32016-08-30 04:34:00977
Blink Reformat1c4d759e2017-04-09 16:34:54978 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23979}
980
danakjc7afae52017-06-20 21:12:41981void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:41982 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21983 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03984 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41985 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39986 DCHECK(!compositor_never_visible_);
danakjc7afae52017-06-20 21:12:41987 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:33988 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
989 callback);
[email protected]ba91a792013-02-06 09:48:28990}
991
fsamuel78f86e42016-01-20 04:10:23992void RenderWidget::DidCommitAndDrawCompositorFrame() {
993 // NOTE: Tests may break if this event is renamed or moved. See
994 // tab_capture_performancetest.cc.
995 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08996
ericwilligers88e69742016-10-17 19:29:55997 for (auto& observer : render_frames_)
998 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08999
fsamuel78f86e42016-01-20 04:10:231000 // Notify subclasses that we initiated the paint operation.
1001 DidInitiatePaint();
1002}
1003
1004void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:551005 for (auto& observer : render_frames_)
1006 observer.DidCommitCompositorFrame();
1007 for (auto& observer : render_frame_proxies_)
1008 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:231009}
1010
1011void RenderWidget::DidCompletePageScaleAnimation() {}
1012
danakj6c872fc02016-10-22 04:29:491013void RenderWidget::DidReceiveCompositorFrameAck() {
1014 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
Fady Samuelcc3e3b4a2017-10-03 02:09:211015 DidResizeOrRepaintAck();
fsamuel78f86e42016-01-20 04:10:231016}
1017
fsamuel78f86e42016-01-20 04:10:231018bool RenderWidget::IsClosing() const {
1019 return host_closing_;
1020}
1021
danakj53eccbc2016-03-02 22:51:071022void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:541023 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:291024}
1025
fsamuel78f86e42016-01-20 04:10:231026void RenderWidget::UpdateVisualState() {
Blink Reformat1c4d759e2017-04-09 16:34:541027 GetWebWidget()->UpdateAllLifecyclePhases();
1028 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:501029
Takashi SAKAMOTO870f6262017-08-22 04:08:271030 if (first_update_visual_state_after_hidden_) {
1031 RecordTimeToFirstActivePaint();
1032 first_update_visual_state_after_hidden_ = false;
1033 }
1034}
tasakb95dbb50c2017-02-08 18:07:501035
Takashi SAKAMOTO870f6262017-08-22 04:08:271036void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501037 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501038 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271039 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1040 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1041 sample);
1042 }
1043 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1044 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1045 UMA_HISTOGRAM_TIMES(
1046 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1047 "AfterBackgrounded.5min",
1048 sample);
1049 }
fsamuel78f86e42016-01-20 04:10:231050}
1051
1052void RenderWidget::WillBeginCompositorFrame() {
1053 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1054
Blink Reformat1c4d759e2017-04-09 16:34:541055 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291056
dglazkov06854c5c2016-08-31 00:19:591057 // The UpdateTextInputState can result in further layout and possibly
1058 // enable GPU acceleration so they need to be called before any painting
1059 // is done.
changwan75e3b2072017-01-16 02:55:001060 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591061 UpdateSelectionBounds();
1062
ericwilligers88e69742016-10-17 19:29:551063 for (auto& observer : render_frame_proxies_)
1064 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291065}
1066
jbroman6ccbc7d472016-07-27 04:45:411067std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041068 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411069 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1070 routing_id_, std::move(request));
1071}
1072
fsamuel72464894f2015-12-15 06:59:311073///////////////////////////////////////////////////////////////////////////////
1074// RenderWidgetInputHandlerDelegate
1075
avid7d6b2e2016-03-04 19:41:171076void RenderWidget::FocusChangeComplete() {
ekaramad27ca69b12017-04-20 18:34:291077 if (!GetWebWidget()->IsWebFrameWidget())
1078 return;
1079 blink::WebLocalFrame* focused =
1080 static_cast<blink::WebFrameWidget*>(GetWebWidget())
1081 ->LocalRoot()
1082 ->View()
1083 ->FocusedFrame();
1084 if (focused && focused->AutofillClient())
1085 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171086}
fsamuel72464894f2015-12-15 06:59:311087
1088bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:171089 if (owner_delegate_)
1090 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
1091
fsamuel72464894f2015-12-15 06:59:311092 return true;
1093}
1094
dtapuska1827dd22016-03-11 15:24:591095void RenderWidget::ObserveGestureEventAndResult(
1096 const blink::WebGestureEvent& gesture_event,
1097 const gfx::Vector2dF& unused_delta,
1098 bool event_processed) {
1099 if (!compositor_deps_->IsElasticOverscrollEnabled())
1100 return;
1101
1102 cc::InputHandlerScrollResult scroll_result;
1103 scroll_result.did_scroll = event_processed;
1104 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1105 scroll_result.unused_scroll_delta = unused_delta;
1106
1107 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1108 InputHandlerManager* input_handler_manager =
Ivan Kotenkov2c0d2bb32017-11-01 15:41:281109 render_thread ? render_thread->input_handler_manager() : nullptr;
dtapuska1827dd22016-03-11 15:24:591110 if (input_handler_manager) {
1111 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1112 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261113 } else if (widget_input_handler_manager_) {
1114 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1115 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591116 }
1117}
1118
avid7d6b2e2016-03-04 19:41:171119void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461120 ClearEditCommands();
1121}
1122
1123void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1124 const std::string& value) {
1125 ClearEditCommands();
1126 edit_commands_.emplace_back(name, value);
1127}
1128
1129void RenderWidget::ClearEditCommands() {
1130 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171131}
fsamuel72464894f2015-12-15 06:59:311132
chongza8ba91fc2016-08-16 21:39:171133void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska139a72f2017-09-06 21:57:031134 if (widget_input_handler_manager_) {
1135 WidgetInputHandlerManager::WidgetInputHandlerHost host =
1136 widget_input_handler_manager_->GetWidgetInputHandlerHost();
1137 (*host)->DidOverscroll(params);
1138 } else {
1139 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1140 }
fsamuel72464894f2015-12-15 06:59:311141}
1142
fsamuele8326c742016-01-12 00:49:391143void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1144 // Nothing to do here. RenderWidget created the |input_handler| and will take
1145 // ownership of it. We just verify here that we don't already have an input
1146 // handler.
1147 DCHECK(!input_handler_);
1148}
1149
changwan75e3b2072017-01-16 02:55:001150void RenderWidget::ShowVirtualKeyboard() {
1151 UpdateTextInputStateInternal(true, false);
1152}
1153
changwan62f57292017-02-17 08:28:251154void RenderWidget::ClearTextInputState() {
1155 text_input_info_ = blink::WebTextInputInfo();
1156 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1157 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1158 can_compose_inline_ = false;
1159 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201160 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251161}
1162
changwan75e3b2072017-01-16 02:55:001163void RenderWidget::UpdateTextInputState() {
1164 UpdateTextInputStateInternal(false, false);
1165}
1166
1167void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1168 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311169 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001170
fsamuel72464894f2015-12-15 06:59:311171 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001172 DCHECK(!reply_to_request);
1173 // show_virtual_keyboard should still be effective even if it was set inside
1174 // the IME
fsamuel72464894f2015-12-15 06:59:311175 // event guard.
changwan75e3b2072017-01-16 02:55:001176 if (show_virtual_keyboard)
1177 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311178 return;
1179 }
1180
dglazkov97b6c2b2016-10-25 17:35:551181 ui::TextInputType new_type = GetTextInputType();
1182 if (IsDateTimeInput(new_type))
1183 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311184
dglazkov97b6c2b2016-10-25 17:35:551185 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351186 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541187 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101188 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541189 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311190
1191 bool new_can_compose_inline = CanComposeInline();
1192
1193 // Only sends text input params if they are changed or if the ime should be
1194 // shown.
changwan75e3b2072017-01-16 02:55:001195 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561196 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1197 text_input_info_ != new_info ||
1198 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381199 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551200 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311201 params.mode = new_mode;
1202 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211203#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201204 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1205 // Due to a focus change, values will be reset by the frame.
1206 // That case we only need fresh NEXT/PREVIOUS information.
1207 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1208 // focusable status is changed.
1209 if (auto* controller = GetInputMethodController()) {
1210 next_previous_flags_ =
1211 controller->ComputeWebTextInputNextPreviousFlags();
1212 } else {
1213 // For safety in case GetInputMethodController() is null, because -1 is
1214 // invalid value to send to browser process.
1215 next_previous_flags_ = 0;
1216 }
1217 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211218#else
1219 next_previous_flags_ = 0;
1220#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201221 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541222 params.value = new_info.value.Utf8();
1223 params.selection_start = new_info.selection_start;
1224 params.selection_end = new_info.selection_end;
1225 params.composition_start = new_info.composition_start;
1226 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311227 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001228 // TODO(changwan): change instances of show_ime_if_needed to
1229 // show_virtual_keyboard.
1230 params.show_ime_if_needed = show_virtual_keyboard;
1231 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311232 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1233
1234 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551235 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311236 text_input_mode_ = new_mode;
1237 can_compose_inline_ = new_can_compose_inline;
1238 text_input_flags_ = new_info.flags;
1239 }
1240}
1241
1242bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581243 possible_drag_event_info_.event_source =
1244 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1245 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541246 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171247
fsamuel72464894f2015-12-15 06:59:311248 return false;
1249}
1250
1251bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551252 for (auto& observer : render_frames_)
1253 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081254
paulmeyer6ef5a792016-11-08 20:33:581255 possible_drag_event_info_.event_source =
1256 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1257 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541258 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581259
avid7d6b2e2016-03-04 19:41:171260 if (owner_delegate_)
1261 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1262
fsamuel72464894f2015-12-15 06:59:311263 return false;
[email protected]fd847792013-10-24 17:12:351264}
1265
initial.commit09911bf2008-07-26 23:55:291266///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391267// RenderWidgetScreenMetricsDelegate
1268
1269void RenderWidget::Redraw() {
1270 set_next_paint_is_resize_ack();
1271 if (compositor_)
1272 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1273}
1274
bokanc63441c2016-04-27 15:49:121275void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541276 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121277}
1278
1279gfx::Size RenderWidget::GetSizeForWebWidget() const {
1280 if (IsUseZoomForDSFEnabled())
1281 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1282
1283 return size_;
1284}
1285
mfomitchev2600fd7c2016-02-17 20:53:391286void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581287 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271288 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1289 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581290
Fady Samuel85a1bf72017-10-27 14:30:201291 bool screen_info_changed = screen_info_ != params.screen_info;
1292
mfomitchev2600fd7c2016-02-17 20:53:391293 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581294
ccameron2f451532016-09-07 21:49:271295 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1296 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581297 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581298 }
mfomitchev2600fd7c2016-02-17 20:53:391299
1300 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1301 // A resize ack shouldn't be requested if we have not ACK'd the previous
1302 // one.
1303 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1304 }
1305
1306 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211307 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391308 return;
1309
fsamuelca02c4e2017-05-09 13:34:141310 if (params.local_surface_id)
1311 local_surface_id_ = *params.local_surface_id;
1312
ianwene5fc5782016-08-18 04:05:151313 if (compositor_) {
Fady Samuel319e429c2017-10-02 18:31:551314 // If surface synchronization is enabled, then this will use the provided
fsamuelca02c4e2017-05-09 13:34:141315 // |local_surface_id_| to submit the next generated CompositorFrame.
1316 // If the ID is not valid, then the compositor will defer commits until
1317 // it receives a valid surface ID. This is a no-op if surface
1318 // synchronization is disabled.
Fady Samuel2bb02292017-10-17 23:59:151319 DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() ||
1320 !params.needs_resize_ack || local_surface_id_.is_valid());
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271321 compositor_->SetViewportSize(params.physical_backing_size,
1322 local_surface_id_);
1323 compositor_->SetBrowserControlsHeight(
1324 params.top_controls_height, params.bottom_controls_height,
1325 params.browser_controls_shrink_blink_size);
1326 compositor_->SetRasterColorSpace(
1327 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151328 }
mfomitchev2600fd7c2016-02-17 20:53:391329
mfomitchev2600fd7c2016-02-17 20:53:391330 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391331
1332 // NOTE: We may have entered fullscreen mode without changing our size.
1333 bool fullscreen_change =
1334 is_fullscreen_granted_ != params.is_fullscreen_granted;
1335 is_fullscreen_granted_ = params.is_fullscreen_granted;
1336 display_mode_ = params.display_mode;
1337
bokanc63441c2016-04-27 15:49:121338 size_ = params.new_size;
1339 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391340
bokanc63441c2016-04-27 15:49:121341 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221342
mfomitchev2600fd7c2016-02-17 20:53:391343 WebSize visual_viewport_size;
1344
1345 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181346 visual_viewport_size = gfx::ScaleToCeiledSize(
1347 params.visible_viewport_size,
1348 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391349 } else {
1350 visual_viewport_size = visible_viewport_size_;
1351 }
1352
Blink Reformat1c4d759e2017-04-09 16:34:541353 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391354
bokanc63441c2016-04-27 15:49:121355 // When resizing, we want to wait to paint before ACK'ing the resize. This
1356 // ensures that we only resize as fast as we can paint. We only need to
1357 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391358 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1359 // In this case there is no paint/composite and therefore no
Fady Samuelcc3e3b4a2017-10-03 02:09:211360 // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to
1361 // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a
1362 // different message.
mfomitchev2600fd7c2016-02-17 20:53:391363 DCHECK(!params.needs_resize_ack);
1364 }
1365
1366 // Send the Resize_ACK flag once we paint again if requested.
1367 if (params.needs_resize_ack)
1368 set_next_paint_is_resize_ack();
1369
1370 if (fullscreen_change)
1371 DidToggleFullscreen();
1372
engedy6cb63c92016-02-23 14:14:581373 if (orientation_changed)
1374 OnOrientationChange();
1375
Fady Samuel85a1bf72017-10-27 14:30:201376 if (screen_info_changed) {
1377 for (auto& observer : render_frame_proxies_)
1378 observer.OnScreenInfoChanged(params.screen_info);
1379
1380 // Notify all BrowserPlugins of the updated ScreenInfo.
1381 if (BrowserPluginManager::Get())
1382 BrowserPluginManager::Get()->ScreenInfoChanged(params.screen_info);
1383 }
1384
mfomitchev2600fd7c2016-02-17 20:53:391385 // If a resize ack is requested and it isn't set-up, then no more resizes will
1386 // come in and in general things will go wrong.
1387 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1388}
1389
1390void RenderWidget::SetScreenMetricsEmulationParameters(
1391 bool enabled,
1392 const blink::WebDeviceEmulationParams& params) {
1393 // This is only supported in RenderView.
1394 NOTREACHED();
1395}
1396
1397void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1398 const gfx::Rect& window_screen_rect) {
1399 view_screen_rect_ = view_screen_rect;
1400 window_screen_rect_ = window_screen_rect;
1401}
1402
1403///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461404// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291405
Fady Samueld10aadd82017-11-03 18:23:571406void RenderWidget::AutoResizeCompositor(
1407 const viz::LocalSurfaceId& local_surface_id) {
danakjddaec912015-09-25 19:38:401408 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
Fady Samueld10aadd82017-11-03 18:23:571409 local_surface_id_ = local_surface_id;
[email protected]97e1bf72013-03-06 14:06:051410 if (compositor_)
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271411 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
[email protected]97e1bf72013-03-06 14:06:051412}
1413
Blink Reformat1c4d759e2017-04-09 16:34:541414blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221415 DCHECK(!host_closing_);
1416
loyso6e6efc42017-01-21 02:23:031417 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1418 auto animation_host = cc::AnimationHost::CreateMainInstance();
1419
wjmacleana755e302017-04-20 00:43:161420 // Oopif status must be set before the LayerTreeHost is created.
1421 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031422 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1423 compositor_.get(), compositor_.get(), animation_host.get(),
1424 compositor_deps_, device_scale_factor_, screen_info_);
1425 compositor_->Initialize(std::move(layer_tree_host),
1426 std::move(animation_host));
1427
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271428 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
oshimad5279032015-12-16 18:22:331429 OnDeviceScaleFactorChanged();
ccameron01912992017-05-23 07:34:031430 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091431 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011432 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391433 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411434 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221435 bool should_generate_frame_sink =
1436 !compositor_never_visible_ && RenderThreadImpl::current();
1437 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391438 compositor_->SetNeverVisible();
1439
pimanc4af3072015-10-02 03:45:591440 StartCompositor();
staraz067f58242016-11-07 21:06:411441 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1442 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331443 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371444
wjmaclean1d970622017-01-21 22:28:241445 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261446 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311447 input_event_queue_ = new MainThreadEventQueue(
1448 this, render_thread->GetRendererScheduler()->CompositorTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221449 render_thread->GetRendererScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261450
1451 InputHandlerManager* input_handler_manager =
1452 render_thread->input_handler_manager();
1453 if (input_handler_manager) {
1454 input_handler_manager->AddInputHandler(
1455 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1456 weak_ptr_factory_.GetWeakPtr(),
1457 compositor_deps_->IsScrollAnimatorEnabled());
1458 has_added_input_handler_ = true;
1459 }
wjmaclean1d970622017-01-21 22:28:241460 }
1461
Khushal3e96e662017-10-30 23:16:501462 UpdateURLForCompositorUkm();
1463
loyso50b51c22017-01-10 07:18:371464 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591465}
1466
ennef3c58142014-12-09 21:44:381467void RenderWidget::WillCloseLayerTreeView() {
1468 if (host_closing_)
1469 return;
1470
1471 // Prevent new compositors or output surfaces from being created.
1472 host_closing_ = true;
1473
[email protected]aeeedad2014-08-22 18:16:221474 // Always send this notification to prevent new layer tree views from
1475 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211476 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541477 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221478}
1479
Blink Reformat1c4d759e2017-04-09 16:34:541480void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1481 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481482 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1483 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1484 }
dglazkov79c426102015-08-31 21:22:431485
ericwilligers88e69742016-10-17 19:29:551486 for (auto& observer : render_frames_)
1487 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431488}
1489
[email protected]586871b2014-07-22 17:05:111490// static
dchengcedca5612016-04-09 01:40:151491std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111492 IPC::Message* msg,
1493 MessageDeliveryPolicy policy,
1494 FrameSwapMessageQueue* frame_swap_message_queue,
1495 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111496 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111497 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151498 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1499 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111500 &first_message_for_frame);
1501 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151502 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111503 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061504 return promise;
[email protected]586871b2014-07-22 17:05:111505 }
dcheng4b6b5ff2014-10-16 00:42:061506 return nullptr;
[email protected]586871b2014-07-22 17:05:111507}
1508
1509void RenderWidget::QueueMessage(IPC::Message* msg,
1510 MessageDeliveryPolicy policy) {
1511 // RenderThreadImpl::current() is NULL in some tests.
1512 if (!compositor_ || !RenderThreadImpl::current()) {
1513 Send(msg);
1514 return;
1515 }
1516
dchengcedca5612016-04-09 01:40:151517 std::unique_ptr<cc::SwapPromise> swap_promise =
1518 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111519 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111520 compositor_->GetSourceFrameNumber());
1521
Ken Buchanance710eb2017-08-30 23:46:521522 if (swap_promise)
dcheng07945f632015-12-26 07:59:321523 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111524}
1525
Blink Reformat1c4d759e2017-04-09 16:34:541526void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301527 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521528 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181529 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291530 // Only send a SetCursor message if we need to make a change.
1531 if (!current_cursor_.IsEqual(cursor)) {
1532 current_cursor_ = cursor;
1533 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1534 }
1535}
1536
aelias5971e47d2017-06-16 02:39:381537void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1538 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1539}
1540
1541void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1542 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1543}
1544
1545void RenderWidget::AutoscrollEnd() {
1546 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1547}
1548
initial.commit09911bf2008-07-26 23:55:291549// We are supposed to get a single call to Show for a newly created RenderWidget
1550// that was created via RenderWidget::CreateWebView. So, we wait until this
1551// point to dispatch the ShowWidget message.
1552//
1553// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281554// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291555//
Blink Reformat1c4d759e2017-04-09 16:34:541556void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291557 DCHECK(!did_show_) << "received extraneous Show call";
1558 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351559 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291560
[email protected]8de12d942010-11-17 20:42:441561 if (did_show_)
1562 return;
1563
1564 did_show_ = true;
nickf7b38222016-11-22 21:59:351565
1566 // The opener is responsible for actually showing this widget.
1567 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351568 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351569
bokanc007c3a2015-02-03 07:15:561570 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441571 // that's okay. It'll be ignored if as_popup is false, or the browser
1572 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561573 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]2533ce12009-05-09 00:02:241576void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381577 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241578 Send(new ViewHostMsg_Close(routing_id_));
1579}
1580
dgozmancf9039cd2015-04-06 12:01:311581void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551582 for (auto& observer : render_frames_)
1583 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311584}
1585
Blink Reformat1c4d759e2017-04-09 16:34:541586void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081587 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321588 if (is_swapped_out_) {
1589 // This widget is currently swapped out, and the active widget is in a
1590 // different process. Have the browser route the close request to the
1591 // active widget instead, so that the correct unload handlers are run.
1592 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1593 return;
1594 }
1595
initial.commit09911bf2008-07-26 23:55:291596 // If a page calls window.close() twice, we'll end up here twice, but that's
1597 // OK. It is safe to send multiple Close messages.
1598
[email protected]2533ce12009-05-09 00:02:241599 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1600 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1601 // could be closed before the JS finishes executing. So instead, post a
1602 // message back to the message loop, which won't run until the JS is
1603 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081604 base::ThreadTaskRunnerHandle::Get()->PostTask(
tzikff2a81a2017-09-15 05:10:061605 FROM_HERE, base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291606}
1607
1608void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031609 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381610 WillCloseLayerTreeView();
1611 compositor_.reset();
lfg8ff33912016-09-13 20:59:211612 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541613 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211614 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291615 }
1616}
1617
bokan841fdc72016-10-06 00:16:351618void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1619 DCHECK(window_rect);
1620 float scale = popup_origin_scale_for_emulation_;
1621 if (!scale)
1622 return;
1623 window_rect->x =
1624 popup_view_origin_for_emulation_.x() +
1625 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1626 window_rect->y =
1627 popup_view_origin_for_emulation_.y() +
1628 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1629}
1630
1631void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1632 DCHECK(window_rect);
1633 float scale = popup_origin_scale_for_emulation_;
1634 if (!scale)
1635 return;
1636 window_rect->x =
1637 popup_screen_origin_for_emulation_.x() +
1638 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1639 window_rect->y =
1640 popup_screen_origin_for_emulation_.y() +
1641 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1642}
1643
Blink Reformat1c4d759e2017-04-09 16:34:541644WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351645 WebRect rect;
bokan6b08cd22016-10-05 00:55:211646 if (pending_window_rect_count_) {
1647 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1648 // the RootWindowRect is probably going to return wrong results since the
1649 // browser may not have processed the Move yet. There isn't really anything
1650 // good to do in this case, and it shouldn't happen - since this size is
1651 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351652 rect = pending_window_rect_;
1653 } else {
1654 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211655 }
[email protected]2533ce12009-05-09 00:02:241656
bokan841fdc72016-10-06 00:16:351657 ScreenRectToEmulatedIfNeeded(&rect);
1658 return rect;
bokan6b08cd22016-10-05 00:55:211659}
1660
Blink Reformat1c4d759e2017-04-09 16:34:541661WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351662 WebRect rect = view_screen_rect_;
1663 ScreenRectToEmulatedIfNeeded(&rect);
1664 return rect;
initial.commit09911bf2008-07-26 23:55:291665}
1666
Blink Reformat1c4d759e2017-04-09 16:34:541667void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301668 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541669 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301670}
1671
Blink Reformat1c4d759e2017-04-09 16:34:541672void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241673 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351674 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511675
[email protected]5b45ad42013-10-25 00:42:041676 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201677 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561678 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1679 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031680 } else {
bokanc007c3a2015-02-03 07:15:561681 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031682 }
initial.commit09911bf2008-07-26 23:55:291683 } else {
bokanc007c3a2015-02-03 07:15:561684 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291685 }
1686}
1687
[email protected]2533ce12009-05-09 00:02:241688void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1689 pending_window_rect_ = rect;
1690 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241691
bokan6b08cd22016-10-05 00:55:211692 // Popups don't get size updates back from the browser so just store the set
1693 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541694 if (popup_type_ != blink::kWebPopupTypeNone) {
1695 window_screen_rect_ = rect;
1696 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241697 }
[email protected]d4547452008-08-28 18:36:371698}
1699
wjmacleanee244e02017-05-26 21:06:071700void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1701 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071702 has_host_context_menu_location_ = true;
1703 host_context_menu_location_ = location;
1704 if (GetWebWidget()) {
1705 GetWebWidget()->ShowContextMenu(
1706 static_cast<blink::WebMenuSourceType>(source_type));
1707 }
1708 has_host_context_menu_location_ = false;
1709}
1710
[email protected]fa7b1dc2010-06-23 17:53:041711void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261712 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111713 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071714 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111715 int selection_start,
1716 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351717 if (!ShouldHandleImeEvents())
1718 return;
1719
brettw4b461082016-11-19 18:55:161720#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491721 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111722 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491723 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091724 return;
1725 }
1726#endif
[email protected]66fca5bc2013-05-23 06:58:291727 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011728 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011729 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541730 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111731 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561732 replacement_range.IsValid()
1733 ? WebRange(replacement_range.start(), replacement_range.length())
1734 : WebRange(),
1735 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041736 // If we failed to set the composition text, then we need to let the browser
1737 // process to cancel the input method's ongoing composition session, to make
1738 // sure we are in a consistent state.
Dave Tapuska139a72f2017-09-06 21:57:031739 if (widget_input_handler_manager_) {
1740 WidgetInputHandlerManager::WidgetInputHandlerHost host =
1741 widget_input_handler_manager_->GetWidgetInputHandlerHost();
1742 (*host)->ImeCancelComposition();
1743 } else {
1744 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
1745 }
[email protected]7f00efa2010-04-15 05:01:261746 }
nonafa291792016-08-10 02:36:181747 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041748}
1749
rlanday7efe2302017-01-11 00:14:281750void RenderWidget::OnImeCommitText(
1751 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111752 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281753 const gfx::Range& replacement_range,
1754 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351755 if (!ShouldHandleImeEvents())
1756 return;
1757
brettw4b461082016-11-19 18:55:161758#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491759 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1760 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1761 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091762 return;
1763 }
1764#endif
[email protected]66fca5bc2013-05-23 06:58:291765 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391766 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261767 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541768 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111769 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561770 replacement_range.IsValid()
1771 ? WebRange(replacement_range.start(), replacement_range.length())
1772 : WebRange(),
1773 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261774 }
aelias87b8f7c2016-09-14 03:19:291775 input_handler_->set_handling_input_event(false);
1776 UpdateCompositionInfo(false /* not an immediate request */);
1777}
1778
1779void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351780 if (!ShouldHandleImeEvents())
1781 return;
1782
brettw4b461082016-11-19 18:55:161783#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491784 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1785 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291786 return;
1787 }
1788#endif
1789
changwan38c3eb612016-12-09 01:45:561790 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291791 return;
1792 ImeEventGuard guard(this);
1793 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011794 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541795 controller->FinishComposingText(
1796 keep_selection ? WebInputMethodController::kKeepSelection
1797 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011798 }
fsamuele8326c742016-01-12 00:49:391799 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181800 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291801}
1802
oshimad5279032015-12-16 18:22:331803void RenderWidget::OnDeviceScaleFactorChanged() {
1804 if (!compositor_)
1805 return;
oshimad5279032015-12-16 18:22:331806 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181807 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331808 else
Blink Reformat1c4d759e2017-04-09 16:34:541809 compositor_->SetDeviceScaleFactor(device_scale_factor_);
oshimad5279032015-12-16 18:22:331810}
1811
[email protected]0bc1f572013-04-17 01:46:311812void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121813 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211814 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121815 return;
1816
[email protected]0bc1f572013-04-17 01:46:311817 // Even if the browser provides an empty damage rect, it's still expecting to
1818 // receive a repaint ack so just damage the entire widget bounds.
1819 if (size_to_paint.IsEmpty()) {
1820 size_to_paint = size_;
1821 }
1822
[email protected]ec7dc112008-08-06 05:30:121823 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051824 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311825 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121826}
1827
[email protected]4873c7d2009-07-16 06:36:281828void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211829 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111830 return;
Blink Reformat1c4d759e2017-04-09 16:34:541831 GetWebWidget()->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111832}
1833
[email protected]80ad8622012-11-07 16:33:031834void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1835 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511836 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391837 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1838 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511839 } else {
mfomitchev2600fd7c2016-02-17 20:53:391840 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511841 }
[email protected]80ad8622012-11-07 16:33:031842 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1843}
1844
lfgdb5c4ed2016-03-04 23:09:071845void RenderWidget::OnUpdateWindowScreenRect(
1846 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211847 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071848 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211849 else
lfgdb5c4ed2016-03-04 23:09:071850 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071851}
1852
kenrbea731792017-01-13 15:10:481853void RenderWidget::OnSetViewportIntersection(
1854 const gfx::Rect& viewport_intersection) {
Colin Blundell584f5ac22017-11-13 11:16:451855 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1856 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
kenrbea731792017-01-13 15:10:481857 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541858 ->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:481859 }
1860}
1861
kenrb04323782017-06-23 01:23:321862void RenderWidget::OnSetIsInert(bool inert) {
Colin Blundell584f5ac22017-11-13 11:16:451863 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1864 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
kenrb04323782017-06-23 01:23:321865 static_cast<WebFrameWidget*>(GetWebWidget())->SetIsInert(inert);
1866 }
1867}
1868
paulmeyer90f6c31d2016-11-12 00:17:591869void RenderWidget::OnDragTargetDragEnter(
1870 const std::vector<DropData::Metadata>& drop_meta_data,
1871 const gfx::Point& client_point,
1872 const gfx::Point& screen_point,
1873 WebDragOperationsMask ops,
1874 int key_modifiers) {
1875 if (!GetWebWidget())
1876 return;
1877
Blink Reformat1c4d759e2017-04-09 16:34:541878 DCHECK(GetWebWidget()->IsWebFrameWidget());
1879 WebDragOperation operation =
1880 static_cast<WebFrameWidget*>(GetWebWidget())
1881 ->DragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1882 client_point, screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591883
1884 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1885}
1886
1887void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1888 const gfx::Point& screen_point,
1889 WebDragOperationsMask ops,
1890 int key_modifiers) {
1891 if (!GetWebWidget())
1892 return;
1893
Blink Reformat1c4d759e2017-04-09 16:34:541894 DCHECK(GetWebWidget()->IsWebFrameWidget());
paulmeyer90f6c31d2016-11-12 00:17:591895 WebDragOperation operation =
Blink Reformat1c4d759e2017-04-09 16:34:541896 static_cast<WebFrameWidget*>(GetWebWidget())
1897 ->DragTargetDragOver(ConvertWindowPointToViewport(client_point),
1898 screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591899
1900 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1901}
1902
kenrb07c272802017-02-07 23:48:171903void RenderWidget::OnDragTargetDragLeave(const gfx::Point& client_point,
1904 const gfx::Point& screen_point) {
paulmeyer90f6c31d2016-11-12 00:17:591905 if (!GetWebWidget())
1906 return;
Blink Reformat1c4d759e2017-04-09 16:34:541907 DCHECK(GetWebWidget()->IsWebFrameWidget());
kenrb07c272802017-02-07 23:48:171908 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541909 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171910 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591911}
1912
1913void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1914 const gfx::Point& client_point,
1915 const gfx::Point& screen_point,
1916 int key_modifiers) {
1917 if (!GetWebWidget())
1918 return;
1919
Blink Reformat1c4d759e2017-04-09 16:34:541920 DCHECK(GetWebWidget()->IsWebFrameWidget());
1921 static_cast<WebFrameWidget*>(GetWebWidget())
1922 ->DragTargetDrop(DropDataToWebDragData(drop_data),
1923 ConvertWindowPointToViewport(client_point), screen_point,
1924 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591925}
1926
paulmeyer8fc8ea92016-11-15 05:12:211927void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1928 const gfx::Point& screen_point,
1929 WebDragOperation op) {
1930 if (!GetWebWidget())
1931 return;
1932
Blink Reformat1c4d759e2017-04-09 16:34:541933 static_cast<WebFrameWidget*>(GetWebWidget())
1934 ->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
1935 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:211936}
1937
1938void RenderWidget::OnDragSourceSystemDragEnded() {
1939 if (!GetWebWidget())
1940 return;
1941
Blink Reformat1c4d759e2017-04-09 16:34:541942 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:211943}
1944
Blink Reformat1c4d759e2017-04-09 16:34:541945void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261946#if defined(OS_CHROMEOS)
1947 // On ChromeOS, virtual keyboard is triggered only when users leave the
1948 // mouse button or the finger and a text input element is focused at that
1949 // time. Focus event itself shouldn't trigger virtual keyboard.
1950 UpdateTextInputState();
1951#else
changwan75e3b2072017-01-16 02:55:001952 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261953#endif
boliu7b2be2f2016-11-04 04:58:311954
1955// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1956// virtual keyboard.
1957#if !defined(OS_ANDROID)
1958 FocusChangeComplete();
1959#endif
[email protected]0d1ebed12013-08-05 22:01:131960}
1961
fsamuel72464894f2015-12-15 06:59:311962ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161963#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491964 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
1965 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:091966#endif
ekaramad5aff1942017-01-06 01:26:351967 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541968 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:311969 return ui::TEXT_INPUT_TYPE_NONE;
1970}
1971
nonafa291792016-08-10 02:36:181972void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1973 if (!monitor_composition_info_ && !immediate_request)
1974 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591975
nonafa291792016-08-10 02:36:181976 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1977 gfx::Range range;
1978 std::vector<gfx::Rect> character_bounds;
1979
1980 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1981 // Composition information is only available on editable node.
1982 range = gfx::Range::InvalidRange();
1983 } else {
1984 GetCompositionRange(&range);
1985 GetCompositionCharacterBounds(&character_bounds);
1986 }
1987
1988 if (!immediate_request &&
1989 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311990 return;
nonafa291792016-08-10 02:36:181991 }
fsamuel72464894f2015-12-15 06:59:311992 composition_character_bounds_ = character_bounds;
1993 composition_range_ = range;
Dave Tapuska139a72f2017-09-06 21:57:031994 if (widget_input_handler_manager_) {
1995 WidgetInputHandlerManager::WidgetInputHandlerHost host =
1996 widget_input_handler_manager_->GetWidgetInputHandlerHost();
1997 (*host)->ImeCompositionRangeChanged(composition_range_,
1998 composition_character_bounds_);
1999 } else {
2000 Send(new InputHostMsg_ImeCompositionRangeChanged(
2001 routing_id(), composition_range_, composition_character_bounds_));
2002 }
fsamuel72464894f2015-12-15 06:59:312003}
2004
Blink Reformat1c4d759e2017-04-09 16:34:542005void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:542006 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:462007 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:332008 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:542009 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:462010 gfx::Rect window_rect =
2011 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
2012 rect->x = window_rect.x();
2013 rect->y = window_rect.y();
2014 rect->width = window_rect.width();
2015 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:542016 }
2017}
2018
Blink Reformat1c4d759e2017-04-09 16:34:542019void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:302020 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:182021 rect->x *= GetOriginalDeviceScaleFactor();
2022 rect->y *= GetOriginalDeviceScaleFactor();
2023 rect->width *= GetOriginalDeviceScaleFactor();
2024 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:302025 }
2026}
2027
W. James MacLeanb5846e52017-08-31 20:39:502028void RenderWidget::TransferActiveWheelFlingAnimation(
2029 const blink::WebActiveWheelFlingParameters& params) {
2030 blink::WebWidget* web_widget = GetWebWidget();
2031 if (web_widget && web_widget->IsWebFrameWidget()) {
2032 static_cast<blink::WebFrameWidget*>(web_widget)
2033 ->TransferActiveWheelFlingAnimation(params);
2034 }
2035}
2036
changwan8c342742016-02-26 00:53:392037void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:262038#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392039 DCHECK(!ime_event_guard_);
2040 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:002041 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212042#endif
Dave Tapuska9db80842017-07-24 17:24:262043}
[email protected]105dffb42013-02-20 03:46:212044
ekaramadc9b70a72017-03-23 16:14:232045void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2046 bool monitor_updates) {
2047 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182048 if (!immediate_request)
2049 return;
2050 UpdateCompositionInfo(true /* immediate request */);
2051}
2052
[email protected]fcdc5642014-05-09 14:32:242053void RenderWidget::OnOrientationChange() {
lfg8d649cc2017-04-28 18:04:302054 WebWidget* web_widget = GetWebWidget();
2055 if (web_widget && web_widget->IsWebFrameWidget()) {
2056 WebFrameWidget* web_frame_widget = static_cast<WebFrameWidget*>(web_widget);
Alex Moshchuk0b409c42017-09-13 02:09:002057 // LocalRoot() might return null for provisional main frames. In this case,
2058 // the frame hasn't committed a navigation and is not swapped into the tree
2059 // yet, so it doesn't make sense to send orientation change events to it.
2060 //
2061 // TODO(https://crbug.com/578349): This check should be cleaned up
2062 // once provisional frames are gone.
2063 if (web_frame_widget->LocalRoot())
2064 web_frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302065 }
[email protected]fcdc5642014-05-09 14:32:242066}
2067
[email protected]bee16aab2009-08-26 15:55:032068void RenderWidget::SetHidden(bool hidden) {
2069 if (is_hidden_ == hidden)
2070 return;
2071
jdduke8fac9d102014-12-20 02:40:132072 // The status has changed. Tell the RenderThread about it and ensure
2073 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032074 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132075
Scott Violet1098538e2017-10-05 19:23:332076#if defined(USE_AURA)
2077 if (IsRunningInMash())
2078 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2079#endif
2080
tasakb95dbb50c2017-02-08 18:07:502081 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:002082 RenderThreadImpl::current()->WidgetHidden();
Takashi SAKAMOTO870f6262017-08-22 04:08:272083 first_update_visual_state_after_hidden_ = true;
Nasko Oskovf97e8b02017-07-25 02:45:422084 } else
[email protected]b2db9272014-01-10 17:42:002085 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:112086
2087 if (render_widget_scheduling_state_)
2088 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032089}
2090
[email protected]2b624c562011-10-27 22:58:262091void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212092 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262093 return;
2094
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122095 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542096 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262097 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542098 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262099 }
[email protected]2b624c562011-10-27 22:58:262100}
2101
[email protected]674741932009-02-04 23:44:462102bool RenderWidget::next_paint_is_resize_ack() const {
Fady Samuelcc3e3b4a2017-10-03 02:09:212103 return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack(
2104 next_paint_flags_);
[email protected]674741932009-02-04 23:44:462105}
2106
[email protected]674741932009-02-04 23:44:462107void RenderWidget::set_next_paint_is_resize_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212108 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462109}
2110
[email protected]674741932009-02-04 23:44:462111void RenderWidget::set_next_paint_is_repaint_ack() {
Fady Samuelcc3e3b4a2017-10-03 02:09:212112 next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462113}
2114
changwanf2a707b2015-10-30 08:22:162115void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2116 if (!ime_event_guard_)
2117 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292118}
2119
changwanf2a707b2015-10-30 08:22:162120void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2121 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002122 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162123 return;
2124 }
2125 ime_event_guard_ = nullptr;
2126
[email protected]66fca5bc2013-05-23 06:58:292127 // While handling an ime event, text input state and selection bounds updates
2128 // are ignored. These must explicitly be updated once finished handling the
2129 // ime event.
2130 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472131#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002132 if (guard->show_virtual_keyboard())
2133 ShowVirtualKeyboard();
2134 else
2135 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472136#endif
[email protected]66fca5bc2013-05-23 06:58:292137}
2138
[email protected]7c8873e2013-02-05 08:03:012139void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162140#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492141 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092142 // TODO(kinaba) http://crbug.com/101101
2143 // Current Pepper IME API does not handle selection bounds. So we simply
2144 // use the caret position as an empty range for now. It will be updated
2145 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492146 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542147 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092148 *focus = caret;
2149 *anchor = caret;
2150 return;
2151 }
2152#endif
[email protected]7c8873e2013-02-05 08:03:012153 WebRect focus_webrect;
2154 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542155 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2156 ConvertViewportToWindow(&focus_webrect);
2157 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242158 *focus = focus_webrect;
2159 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322160}
2161
[email protected]e99ef6f2011-10-16 01:13:002162void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082163 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212164 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002165 return;
changwanf2a707b2015-10-30 08:22:162166 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292167 return;
[email protected]e99ef6f2011-10-16 01:13:002168
mohsenb0eeba72015-08-09 06:20:082169#if defined(USE_AURA)
2170 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2171 // Aura beucause composited selection updates are not working for webview tags
2172 // which regresses IME inside webview. Remove this when composited selection
2173 // updates are fixed for webviews. See, http://crbug.com/510568.
2174 bool send_ipc = true;
2175#else
jddukeacf809e2014-09-23 20:38:382176 // With composited selection updates, the selection bounds will be reported
2177 // directly by the compositor, in which case explicit IPC selection
2178 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082179 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542180 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082181#endif
2182 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382183 ViewHostMsg_SelectionBounds_Params params;
2184 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2185 if (selection_anchor_rect_ != params.anchor_rect ||
2186 selection_focus_rect_ != params.focus_rect) {
2187 selection_anchor_rect_ = params.anchor_rect;
2188 selection_focus_rect_ = params.focus_rect;
Blink Reformat1c4d759e2017-04-09 16:34:542189 GetWebWidget()->SelectionTextDirection(params.focus_dir,
lfg8ff33912016-09-13 20:59:212190 params.anchor_dir);
Blink Reformat1c4d759e2017-04-09 16:34:542191 params.is_anchor_first = GetWebWidget()->IsSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:382192 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2193 }
[email protected]58b48a0d2012-06-13 07:01:352194 }
jddukeacf809e2014-09-23 20:38:382195
nonafa291792016-08-10 02:36:182196 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002197}
2198
lfgb00fcad2016-07-14 14:16:332199void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2200 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542201 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332202 if (size_.width() != new_size_in_window.width ||
2203 size_.height() != new_size_in_window.height) {
2204 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2205
2206 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542207 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2208 size_.height());
lfgb00fcad2016-07-14 14:16:332209 view_screen_rect_ = new_pos;
2210 window_screen_rect_ = new_pos;
2211 }
2212
Fady Samueld10aadd82017-11-03 18:23:572213 AutoResizeCompositor(viz::LocalSurfaceId());
lfgb00fcad2016-07-14 14:16:332214
Fady Samuel319e429c2017-10-02 18:31:552215 if (!resizing_mode_selector_->is_synchronous_mode()) {
Fady Samueld10aadd82017-11-03 18:23:572216 need_resize_ack_for_auto_resize_ = true;
Fady Samuel319e429c2017-10-02 18:31:552217 // If surface synchronization is off, then ResizeAcks go to the browser in
2218 // response to a DidReceiveCompositorFrame. With surface synchronization
2219 // on, that notification will not arrive here because the compositor is
2220 // deferring commits and thus submission of CompositorFrames.
2221 if (!size_.IsEmpty() && compositor_ &&
2222 compositor_->IsSurfaceSynchronizationEnabled()) {
Fady Samuelcc3e3b4a2017-10-03 02:09:212223 DidResizeOrRepaintAck();
Fady Samuel319e429c2017-10-02 18:31:552224 }
2225 }
lfgb00fcad2016-07-14 14:16:332226 }
2227}
2228
[email protected]58b48a0d2012-06-13 07:01:352229void RenderWidget::GetCompositionCharacterBounds(
2230 std::vector<gfx::Rect>* bounds) {
2231 DCHECK(bounds);
2232 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092233
brettw4b461082016-11-19 18:55:162234#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492235 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092236 return;
2237#endif
2238
lfg8ff33912016-09-13 20:59:212239 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092240 return;
2241 blink::WebVector<blink::WebRect> bounds_from_blink;
Blink Reformat1c4d759e2017-04-09 16:34:542242 if (!GetWebWidget()->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092243 return;
2244
2245 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542246 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092247 bounds->push_back(bounds_from_blink[i]);
2248 }
[email protected]58b48a0d2012-06-13 07:01:352249}
2250
[email protected]db4fc1e2013-09-06 20:01:512251void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162252#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492253 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092254 return;
2255#endif
EhsanKcdee7b72017-11-08 21:30:092256 blink::WebInputMethodController* controller = GetInputMethodController();
2257 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542258 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212259 *range = gfx::Range::InvalidRange();
2260 return;
[email protected]88dbe32f2013-06-20 23:31:362261 }
Blink Reformat1c4d759e2017-04-09 16:34:542262 range->set_start(web_range.StartOffset());
2263 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362264}
2265
[email protected]501ea13d2013-07-09 17:03:292266bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512267 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292268 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082269 if (!range.IsValid())
2270 return false;
[email protected]501ea13d2013-07-09 17:03:292271 if (composition_range_ != range)
2272 return true;
2273 if (bounds.size() != composition_character_bounds_.size())
2274 return true;
2275 for (size_t i = 0; i < bounds.size(); ++i) {
2276 if (bounds[i] != composition_character_bounds_[i])
2277 return true;
2278 }
2279 return false;
2280}
[email protected]501ea13d2013-07-09 17:03:292281
[email protected]ad26ef42011-06-17 07:59:452282bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162283#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492284 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2285 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092286#endif
[email protected]ad26ef42011-06-17 07:59:452287 return true;
[email protected]56ea1a62011-05-30 07:05:572288}
2289
Blink Reformat1c4d759e2017-04-09 16:34:542290blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272291 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542292 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542293 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272294 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542295 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2296 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272297 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542298 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272299 switch (screen_info_.orientation_type) {
2300 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542301 web_screen_info.orientation_type =
2302 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272303 break;
2304 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542305 web_screen_info.orientation_type =
2306 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272307 break;
2308 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542309 web_screen_info.orientation_type =
2310 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272311 break;
2312 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542313 web_screen_info.orientation_type =
2314 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272315 break;
2316 default:
Blink Reformat1c4d759e2017-04-09 16:34:542317 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272318 break;
2319 }
Blink Reformat1c4d759e2017-04-09 16:34:542320 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202321
ccameron2f451532016-09-07 21:49:272322 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282323}
2324
donnda070f3c2015-01-16 19:54:112325#if defined(OS_ANDROID)
Donn Denman43a439e2017-08-29 04:20:452326void RenderWidget::ShowUnhandledTapUIIfNeeded(
2327 const WebTappedInfo& tapped_info) {
2328 // Unpack tapped_info. TODO(donnd): inline unpacking.
2329 bool page_changed = tapped_info.PageChanged();
2330 const WebNode& tapped_node = tapped_info.GetNode();
2331 const WebPoint& tapped_position = tapped_info.Position();
Blink Reformat1c4d759e2017-04-09 16:34:542332 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2333 !tapped_node.IsContentEditable() &&
2334 !tapped_node.IsInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112335 if (should_trigger) {
Donn Denman43a439e2017-08-29 04:20:452336 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(
2337 routing_id_, tapped_position.x, tapped_position.y));
donnda070f3c2015-01-16 19:54:112338 }
2339}
2340#endif
2341
Blink Reformat1c4d759e2017-04-09 16:34:542342void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2343 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022344#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562345 if (event_cancelled)
2346 return;
Blink Reformat1c4d759e2017-04-09 16:34:542347 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002348 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542349 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212350 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352351 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542352 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002353 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462354 else
changwan75e3b2072017-01-16 02:55:002355 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562356 }
ekaramada110f642016-12-21 19:47:282357// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2358// crbug/420130.
2359#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542360 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282361 return;
2362
2363 // TODO(estade): hit test the event against focused node to make sure
2364 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352365 blink::WebInputMethodController* controller = GetInputMethodController();
2366 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542367 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282368
2369 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542370 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282371#endif
[email protected]c68c3e4e2013-01-24 00:36:562372#endif
2373}
2374
Blink Reformat1c4d759e2017-04-09 16:34:542375void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312376 const blink::WebFloatSize& overscrollDelta,
2377 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422378 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542379 const blink::WebFloatSize& velocity,
2380 const blink::WebScrollBoundaryBehavior& behavior) {
bokan731ec382016-04-07 03:16:482381#if defined(OS_MACOSX)
2382 // On OSX the user can disable the elastic overscroll effect. If that's the
2383 // case, don't forward the overscroll notification.
2384 DCHECK(compositor_deps());
2385 if (!compositor_deps()->IsElasticOverscrollEnabled())
2386 return;
2387#endif
bokane53a10f2016-04-13 23:48:312388 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542389 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422390}
2391
[email protected]7912e822014-04-16 02:37:032392void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392393 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542394 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032395}
2396
[email protected]24ed0432013-04-24 07:50:312397RenderWidgetCompositor* RenderWidget::compositor() const {
2398 return compositor_.get();
2399}
2400
fsamuel72464894f2015-12-15 06:59:312401void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392402 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372403}
[email protected]c3d45532011-10-07 19:20:402404
Blink Reformat1c4d759e2017-04-09 16:34:542405void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112406 if (render_widget_scheduling_state_)
2407 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552408 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2409}
2410
Dave Tapuskadfe486c12017-06-09 16:53:132411void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2412 if (input_event_queue_)
2413 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2414}
2415
xidachenfa0199e72017-05-11 11:34:262416void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262417 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512418 return;
2419
Dave Tapuska139a72f2017-09-06 21:57:032420 if (widget_input_handler_manager_) {
2421 widget_input_handler_manager_->ProcessTouchAction(touch_action);
2422 } else {
2423 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
2424 }
[email protected]5d0bbdfa92013-12-10 00:35:512425}
2426
[email protected]e3244ed2014-06-20 20:04:272427void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2428 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162429}
2430
[email protected]e3244ed2014-06-20 20:04:272431void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2432 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162433}
2434
[email protected]de3c5d82014-05-28 22:12:592435void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2436 render_frames_.AddObserver(frame);
2437}
2438
2439void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2440 render_frames_.RemoveObserver(frame);
2441}
2442
lfg43e08e62016-02-03 18:51:372443void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2444 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2445 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2446}
2447
oshima50872a72016-03-04 13:26:182448float RenderWidget::GetOriginalDeviceScaleFactor() const {
2449 return
2450 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272451 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182452 device_scale_factor_;
2453}
2454
paulmeyer90f6c31d2016-11-12 00:17:592455gfx::Point RenderWidget::ConvertWindowPointToViewport(
2456 const gfx::Point& point) {
2457 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542458 ConvertWindowToViewport(&point_in_viewport);
paulmeyer90f6c31d2016-11-12 00:17:592459 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2460}
2461
Blink Reformat1c4d759e2017-04-09 16:34:542462bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212463 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2464}
2465
Blink Reformat1c4d759e2017-04-09 16:34:542466void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212467 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2468}
2469
Blink Reformat1c4d759e2017-04-09 16:34:542470bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212471 return mouse_lock_dispatcher_->IsMouseLockedTo(
2472 webwidget_mouse_lock_target_.get());
2473}
2474
Blink Reformat1c4d759e2017-04-09 16:34:542475void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582476 const WebDragData& data,
2477 WebDragOperationsMask mask,
2478 const WebImage& image,
2479 const WebPoint& webImageOffset) {
2480 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542481 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582482 DropData drop_data(DropDataBuilder::Build(data));
2483 drop_data.referrer_policy = policy;
2484 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592485 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542486 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582487 possible_drag_event_info_));
2488}
2489
kenrb5d78b842017-03-06 21:06:012490uint32_t RenderWidget::GetContentSourceId() {
2491 return current_content_source_id_;
2492}
2493
2494void RenderWidget::IncrementContentSourceId() {
2495 if (compositor_)
2496 compositor_->SetContentSourceId(++current_content_source_id_);
2497}
2498
lfg8ff33912016-09-13 20:59:212499blink::WebWidget* RenderWidget::GetWebWidget() const {
2500 return webwidget_internal_;
2501}
2502
ekaramad2daaf672016-11-10 20:29:012503blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2504 const {
Blink Reformat1c4d759e2017-04-09 16:34:542505 if (!GetWebWidget()->IsWebFrameWidget()) {
ekaramad5a9f52a2016-12-07 01:35:182506 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2507 // when the RenderWidget is swapped out. We should top sending IPCs from the
2508 // browser side (https://crbug.com/669219).
2509 // If there is no WebFrameWidget, then there will be no
2510 // InputMethodControllers for a WebLocalFrame.
2511 return nullptr;
2512 }
ekaramad2daaf672016-11-10 20:29:012513 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:542514 ->GetActiveWebInputMethodController();
ekaramad2daaf672016-11-10 20:29:012515}
2516
Dave Tapuska139a72f2017-09-06 21:57:032517void RenderWidget::SetupWidgetInputHandler(
2518 mojom::WidgetInputHandlerRequest request,
2519 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuska525eb15e2017-08-17 21:05:502520 widget_input_handler_manager_->AddInterface(std::move(request));
Dave Tapuska139a72f2017-09-06 21:57:032521 widget_input_handler_manager_->SetWidgetInputHandlerHost(std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502522}
2523
Dave Tapuska485aca92017-08-08 00:47:582524void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2525 // Close the old binding if there was one.
2526 // A RenderWidgetHost should not need more than one channel.
2527 widget_binding_.Close();
2528 widget_binding_.Bind(std::move(request));
2529}
2530
Fady Samuelcc3e3b4a2017-10-03 02:09:212531void RenderWidget::DidResizeOrRepaintAck() {
Fady Samueld10aadd82017-11-03 18:23:572532 if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_)
Fady Samuel319e429c2017-10-02 18:31:552533 return;
2534
Fady Samuelcc3e3b4a2017-10-03 02:09:212535 ViewHostMsg_ResizeOrRepaint_ACK_Params params;
Fady Samuel319e429c2017-10-02 18:31:552536 params.view_size = size_;
2537 params.flags = next_paint_flags_;
2538 params.sequence_number = ++resize_or_repaint_ack_num_;
2539
Fady Samuelcc3e3b4a2017-10-03 02:09:212540 Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params));
Fady Samuel319e429c2017-10-02 18:31:552541 next_paint_flags_ = 0;
Fady Samueld10aadd82017-11-03 18:23:572542 need_resize_ack_for_auto_resize_ = false;
Fady Samuel319e429c2017-10-02 18:31:552543}
2544
Khushal3e96e662017-10-30 23:16:502545void RenderWidget::UpdateURLForCompositorUkm() {
2546 DCHECK(compositor_);
2547
2548 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2549 return;
2550
2551 auto* render_frame = RenderFrameImpl::FromWebFrame(
2552 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot());
2553 if (!render_frame->IsMainFrame())
2554 return;
2555
2556 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2557}
2558
EhsanK22d482e2017-08-10 17:29:492559#if BUILDFLAG(ENABLE_PLUGINS)
2560PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
2561 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2562 return nullptr;
2563
2564 // Focused pepper instance might not always be in the focused frame. For
2565 // instance if a pepper instance and its embedder frame are focused an then
2566 // another frame takes focus using javascript, the embedder frame will no
2567 // longer be focused while the pepper instance is (the embedder frame's
2568 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2569 // is fullscreen, clicking into the pepper will not refocus the embedder
2570 // frame. This is why we have to traverse the whole frame tree to find the
2571 // focused plugin.
2572 blink::WebFrame* current_frame =
2573 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot();
2574 while (current_frame) {
2575 RenderFrameImpl* render_frame =
2576 current_frame->IsWebLocalFrame()
2577 ? RenderFrameImpl::FromWebFrame(current_frame)
2578 : nullptr;
2579 if (render_frame && render_frame->focused_pepper_plugin())
2580 return render_frame->focused_pepper_plugin();
2581 current_frame = current_frame->TraverseNext();
2582 }
2583 return nullptr;
2584}
2585#endif
2586
[email protected]e9ff79c2012-10-19 21:31:262587} // namespace content