blob: 11a269db7762dfedcc3bedfb6e21a328fcd24640 [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"
asvitkine8d51e9d2016-09-02 23:55:4318#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2119#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0020#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2721#include "base/sys_info.h"
fdoraya19b7702016-12-23 14:19:3122#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
[email protected]661eb9d2009-02-03 02:11:4824#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0325#include "cc/animation/animation_host.h"
xidachenfa0199e72017-05-11 11:34:2626#include "cc/input/touch_action.h"
danakjba65a0912017-09-21 16:38:4227#include "cc/trees/layer_tree_frame_sink.h"
loyso6e6efc42017-01-21 02:23:0328#include "cc/trees/layer_tree_host.h"
Fady Samuelc645ffe2017-07-24 17:28:2029#include "components/viz/common/frame_sinks/begin_frame_source.h"
danakjf20f4502017-09-26 17:13:3130#include "components/viz/common/frame_sinks/copy_output_request.h"
paulmeyer6ef5a792016-11-08 20:33:5831#include "content/common/drag_event_source_info.h"
32#include "content/common/drag_messages.h"
jonrossa2ff4f82018-02-16 17:27:4633#include "content/common/render_frame_metadata.mojom.h"
jcivelliae1560a2016-11-01 22:40:2334#include "content/common/render_message_filter.mojom.h"
Nasko Oskovf97e8b02017-07-25 02:45:4235#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3836#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5037#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1838#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1239#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2940#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4241#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5942#include "content/public/common/drop_data.h"
Khushal3e96e662017-10-30 23:16:5043#include "content/public/common/service_names.mojom.h"
Jaebaek Seo655110e2017-12-19 23:27:3944#include "content/public/common/use_zoom_for_dsf_policy.h"
mlamouriafca06dd2017-01-27 23:35:1845#include "content/public/renderer/content_renderer_client.h"
Saman Samid189e5dfd2017-12-20 22:55:3146#include "content/renderer/browser_plugin/browser_plugin.h"
[email protected]953bd0062013-08-01 00:58:4047#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3948#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5849#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5150#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1151#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2853#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2954#include "content/renderer/ime_event_guard.h"
dtapuska9ec1a912017-04-21 15:18:3155#include "content/renderer/input/main_thread_event_queue.h"
Dave Tapuska9db80842017-07-24 17:24:2656#include "content/renderer/input/widget_input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3257#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1658#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2759#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0560#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4461#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5562#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4463#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0964#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0465#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4766#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1867#include "ipc/ipc_sync_message.h"
Antoine Laboure55c9ef82017-11-10 18:51:2368#include "ipc/ipc_sync_message_filter.h"
Scott Violet02e38b92018-03-27 23:42:1469#include "ppapi/buildflags/buildflags.h"
[email protected]661eb9d2009-02-03 02:11:4870#include "skia/ext/platform_canvas.h"
Blink Reformata30d4232018-04-07 15:31:0671#include "third_party/blink/public/platform/file_path_conversion.h"
72#include "third_party/blink/public/platform/scheduler/web_main_thread_scheduler.h"
73#include "third_party/blink/public/platform/scheduler/web_render_widget_scheduling_state.h"
74#include "third_party/blink/public/platform/web_cursor_info.h"
75#include "third_party/blink/public/platform/web_drag_data.h"
76#include "third_party/blink/public/platform/web_drag_operation.h"
77#include "third_party/blink/public/platform/web_mouse_event.h"
78#include "third_party/blink/public/platform/web_point.h"
79#include "third_party/blink/public/platform/web_rect.h"
80#include "third_party/blink/public/platform/web_runtime_features.h"
81#include "third_party/blink/public/platform/web_size.h"
82#include "third_party/blink/public/platform/web_string.h"
83#include "third_party/blink/public/web/web_autofill_client.h"
84#include "third_party/blink/public/web/web_device_emulation_params.h"
85#include "third_party/blink/public/web/web_frame_widget.h"
86#include "third_party/blink/public/web/web_input_method_controller.h"
87#include "third_party/blink/public/web/web_local_frame.h"
88#include "third_party/blink/public/web/web_node.h"
89#include "third_party/blink/public/web/web_page_popup.h"
90#include "third_party/blink/public/web/web_popup_menu_info.h"
91#include "third_party/blink/public/web/web_range.h"
92#include "third_party/blink/public/web/web_settings.h"
93#include "third_party/blink/public/web/web_view.h"
94#include "third_party/blink/public/web/web_widget.h"
[email protected]d353541f2012-05-03 22:45:4195#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5996#include "ui/base/clipboard/clipboard.h"
Scott Violet8ff9c302018-02-22 22:28:3597#include "ui/base/ui_base_features.h"
dtapuska97286c882017-02-24 23:14:4398#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:5099#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:09100#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32101#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48102#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27103#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41104#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48105
[email protected]eeb93112013-05-01 19:41:10106#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15107#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24108#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10109#endif
110
[email protected]661eb9d2009-02-03 02:11:48111#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52112#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41113#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48114#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44115
sadrul943e3b32016-08-04 18:22:59116#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10117#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19118#endif
119
ekaramad330ba4232016-09-23 17:57:47120#if defined(OS_MACOSX)
121#include "content/renderer/text_input_client_observer.h"
122#endif
123
Ryan Landay9e42fd742017-08-12 01:59:11124using blink::WebImeTextSpan;
[email protected]180ef242013-11-07 06:50:46125using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43126using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59127using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58128using blink::WebDragOperationsMask;
129using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59130using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46131using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58132using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46133using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49134using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01135using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58136using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46137using blink::WebMouseEvent;
138using blink::WebMouseWheelEvent;
139using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11140using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46141using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11142using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46143using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48144using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46145using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46146using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59147using blink::WebString;
[email protected]180ef242013-11-07 06:50:46148using blink::WebTextDirection;
149using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25150using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46151using blink::WebVector;
152using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26153
paulmeyer90f6c31d2016-11-12 00:17:59154namespace content {
155
[email protected]6a4d7f62013-01-07 21:32:13156namespace {
[email protected]b256eca2013-07-11 10:57:40157
158typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
159
AJITH KUMAR V041c0b02017-08-08 10:39:20160static const int kInvalidNextPreviousFlagsValue = -1;
161
lfgbee1e0a2016-06-08 21:24:21162class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
163 public:
164 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
165 : webwidget_(webwidget) {}
166
167 void OnLockMouseACK(bool succeeded) override {
168 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54169 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21170 else
Blink Reformat1c4d759e2017-04-09 16:34:54171 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21172 }
173
Blink Reformat1c4d759e2017-04-09 16:34:54174 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21175
176 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
177 // The WebWidget handles mouse lock in Blink's handleInputEvent().
178 return false;
179 }
180
181 private:
182 blink::WebWidget* webwidget_;
183};
184
dglazkov97b6c2b2016-10-25 17:35:55185bool IsDateTimeInput(ui::TextInputType type) {
186 return type == ui::TEXT_INPUT_TYPE_DATE ||
187 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
188 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
189 type == ui::TEXT_INPUT_TYPE_MONTH ||
190 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
191}
192
paulmeyer90f6c31d2016-11-12 00:17:59193WebDragData DropMetaDataToWebDragData(
194 const std::vector<DropData::Metadata>& drop_meta_data) {
195 std::vector<WebDragData::Item> item_list;
196 for (const auto& meta_data_item : drop_meta_data) {
197 if (meta_data_item.kind == DropData::Kind::STRING) {
198 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54199 item.storage_type = WebDragData::Item::kStorageTypeString;
200 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59201 // Have to pass a dummy URL here instead of an empty URL because the
202 // DropData received by browser_plugins goes through a round trip:
203 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
204 // will contain an empty URL (which means no URL is dragged) if the URL in
205 // WebDragData is empty.
206 if (base::EqualsASCII(meta_data_item.mime_type,
207 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54208 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59209 }
210 item_list.push_back(item);
211 continue;
212 }
213
214 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
215 // just the mimetype. This is needed to drag files to WebView on Android
216 // platform.
217 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
218 !meta_data_item.filename.empty()) {
219 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54220 item.storage_type = WebDragData::Item::kStorageTypeFilename;
221 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59222 item_list.push_back(item);
223 continue;
224 }
225
226 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
227 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54228 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
229 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59230 item_list.push_back(item);
231 continue;
232 }
233 }
234
235 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54236 result.Initialize();
237 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59238 return result;
239}
240
241WebDragData DropDataToWebDragData(const DropData& drop_data) {
242 std::vector<WebDragData::Item> item_list;
243
244 // These fields are currently unused when dragging into WebKit.
245 DCHECK(drop_data.download_metadata.empty());
246 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23247 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59248
249 if (!drop_data.text.is_null()) {
250 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54251 item.storage_type = WebDragData::Item::kStorageTypeString;
252 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
253 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59254 item_list.push_back(item);
255 }
256
257 if (!drop_data.url.is_empty()) {
258 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54259 item.storage_type = WebDragData::Item::kStorageTypeString;
260 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
261 item.string_data = WebString::FromUTF8(drop_data.url.spec());
262 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59263 item_list.push_back(item);
264 }
265
266 if (!drop_data.html.is_null()) {
267 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54268 item.storage_type = WebDragData::Item::kStorageTypeString;
269 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
270 item.string_data = WebString::FromUTF16(drop_data.html.string());
271 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59272 item_list.push_back(item);
273 }
274
275 for (std::vector<ui::FileInfo>::const_iterator it =
276 drop_data.filenames.begin();
277 it != drop_data.filenames.end();
278 ++it) {
279 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54280 item.storage_type = WebDragData::Item::kStorageTypeFilename;
281 item.filename_data = blink::FilePathToWebString(it->path);
282 item.display_name_data =
kinukoa4293022017-01-27 06:43:25283 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59284 item_list.push_back(item);
285 }
286
287 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
288 drop_data.file_system_files.begin();
289 it != drop_data.file_system_files.end();
290 ++it) {
291 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54292 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
293 item.file_system_url = it->url;
294 item.file_system_file_size = it->size;
295 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59296 item_list.push_back(item);
297 }
298
Stuart Langley48300392017-11-02 03:54:44299 for (const auto& it : drop_data.custom_data) {
paulmeyer90f6c31d2016-11-12 00:17:59300 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54301 item.storage_type = WebDragData::Item::kStorageTypeString;
Stuart Langley48300392017-11-02 03:54:44302 item.string_type = WebString::FromUTF16(it.first);
303 item.string_data = WebString::FromUTF16(it.second);
paulmeyer90f6c31d2016-11-12 00:17:59304 item_list.push_back(item);
305 }
306
307 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54308 result.Initialize();
309 result.SetItems(item_list);
310 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59311 return result;
312}
313
lfg1568d112016-08-30 16:06:29314content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
315 nullptr;
316
317content::RenderWidget::RenderWidgetInitializedCallback
318 g_render_widget_initialized = nullptr;
319
dtapuskac4dd5be2016-10-25 15:11:10320ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
321 // Check the type is in the range representable by ui::TextInputType.
322 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
323 << "blink::WebTextInputType and ui::TextInputType not synchronized";
324 return static_cast<ui::TextInputType>(type);
325}
326
327ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
328 // Check the mode is in the range representable by ui::TextInputMode.
329 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
330 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
331 return static_cast<ui::TextInputMode>(mode);
332}
333
Mitsuru Oshima3c07b332018-02-06 04:56:50334// Returns true if the device scale is high enough that losing subpixel
335// antialiasing won't have a noticeable effect on text quality.
336static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) {
337#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
338 // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to
339 // composite all scrollers so that we get animated overlay scrollbars.
340 return true;
341#else
342 // 1.5 is a common touchscreen tablet device scale factor. For such
343 // devices main thread antialiasing is a heavy burden.
344 return device_scale_factor >= 1.5f;
345#endif
346}
347
348static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps,
349 float device_scale_factor) {
350 const base::CommandLine& command_line =
351 *base::CommandLine::ForCurrentProcess();
352 if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText))
353 return false;
354 if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText))
355 return true;
356 if (!compositor_deps->IsLcdTextEnabled())
357 return true;
358 return DeviceScaleEnsuresTextQuality(device_scale_factor);
359}
360
[email protected]b256eca2013-07-11 10:57:40361} // namespace
362
[email protected]b2e4c70132013-10-03 02:07:51363// RenderWidget ---------------------------------------------------------------
364
Hajime Hoshiabb3c8f2017-12-04 18:41:39365RenderWidget::RenderWidget(
366 int32_t widget_routing_id,
367 CompositorDependencies* compositor_deps,
368 blink::WebPopupType popup_type,
369 const ScreenInfo& screen_info,
370 bool swapped_out,
371 bool hidden,
372 bool never_visible,
373 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
374 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45375 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36376 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21377 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44378 owner_delegate_(nullptr),
[email protected]847a2582013-03-09 02:29:51379 auto_resize_mode_(false),
initial.commit09911bf2008-07-26 23:55:29380 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04381 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39382 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12383 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54384 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16385 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48386 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22387 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44388 is_swapped_out_(swapped_out),
dglazkov97b6c2b2016-10-25 17:35:55389 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40390 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20391 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20392 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53393 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18394 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12395 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48396 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04397 screen_info_(screen_info),
nonafa291792016-08-10 02:36:18398 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51399 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12400 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42401 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08402 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09403 has_focus_(false),
Nicolas Pena75a35d662018-04-05 20:13:44404 for_oopif_(false),
ekaramad330ba4232016-09-23 17:57:47405#if defined(OS_MACOSX)
406 text_input_client_observer_(new TextInputClientObserver(this)),
407#endif
Takashi SAKAMOTO870f6262017-08-22 04:08:27408 first_update_visual_state_after_hidden_(false),
tasakb95dbb50c2017-02-08 18:07:50409 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01410 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19411 widget_binding_(this, std::move(widget_request)),
Hajime Hoshiabb3c8f2017-12-04 18:41:39412 task_runner_(task_runner),
wjmaclean1d970622017-01-21 22:28:24413 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45414 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05415 if (!swapped_out)
416 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27417 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11418
419 // In tests there may not be a RenderThreadImpl.
420 if (RenderThreadImpl::current()) {
421 render_widget_scheduling_state_ = RenderThreadImpl::current()
Yuta Kitamura3331f5c2018-04-05 11:12:25422 ->GetWebMainThreadScheduler()
dcheng07945f632015-12-26 07:59:32423 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11424 render_widget_scheduling_state_->SetHidden(is_hidden_);
425 }
sadrul602ce1362017-01-26 06:41:10426#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14427 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
James Cook486d9642018-05-08 17:44:21428 if (features::IsMashEnabled())
Scott Violet1098538e2017-10-05 19:23:33429 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_);
sadrul602ce1362017-01-26 06:41:10430#endif
initial.commit09911bf2008-07-26 23:55:29431}
432
433RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21434 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16435
dtapuska9ec1a912017-04-21 15:18:31436 if (input_event_queue_)
437 input_event_queue_->ClearClient();
438
[email protected]992db4c2011-05-12 15:37:15439 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02440 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15441 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11442#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14443 // It is possible for a RenderWidget to be destroyed before it was embedded
444 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
445 // explicitly delete it here.
446 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11447#endif
initial.commit09911bf2008-07-26 23:55:29448}
449
[email protected]484955942010-08-19 16:13:18450// static
lfg1568d112016-08-30 16:06:29451void RenderWidget::InstallCreateHook(
452 CreateRenderWidgetFunction create_render_widget,
453 RenderWidgetInitializedCallback render_widget_initialized) {
454 CHECK(!g_create_render_widget && !g_render_widget_initialized);
455 g_create_render_widget = create_render_widget;
456 g_render_widget_initialized = render_widget_initialized;
457}
458
459// static
nickf7b38222016-11-22 21:59:35460RenderWidget* RenderWidget::CreateForPopup(
461 RenderViewImpl* opener,
462 CompositorDependencies* compositor_deps,
463 blink::WebPopupType popup_type,
Hajime Hoshiabb3c8f2017-12-04 18:41:39464 const ScreenInfo& screen_info,
465 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Dave Tapuska1bdf1832017-07-07 18:07:19466 mojom::WidgetPtr widget_channel;
467 mojom::WidgetRequest widget_channel_request =
468 mojo::MakeRequest(&widget_channel);
469
nick4df698d82016-11-11 20:39:23470 // Do a synchronous IPC to obtain a routing ID.
471 int32_t routing_id = MSG_ROUTING_NONE;
472 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19473 opener->GetRoutingID(), popup_type, std::move(widget_channel),
474 &routing_id)) {
nick4df698d82016-11-11 20:39:23475 return nullptr;
476 }
477
Hajime Hoshiabb3c8f2017-12-04 18:41:39478 scoped_refptr<RenderWidget> widget(new RenderWidget(
479 routing_id, compositor_deps, popup_type, screen_info, false, false, false,
480 task_runner, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35481 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24482 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
Tommy Nyquist4b749d02018-03-20 21:46:29483 widget->Init(std::move(opener_callback),
484 RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23485 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
486 return widget.get();
initial.commit09911bf2008-07-26 23:55:29487}
488
[email protected]484955942010-08-19 16:13:18489// static
kenrba7199832015-01-22 23:44:59490RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23491 int widget_routing_id,
kenrba7199832015-01-22 23:44:59492 bool hidden,
ccameron2f451532016-09-07 21:49:27493 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59494 CompositorDependencies* compositor_deps,
495 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23496 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55497 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
498 // same routing ID for both the view routing ID and the main frame widget
499 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23500 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55501 if (view) {
avi8a45c1092016-03-01 16:12:34502 view->AttachWebFrameWidget(
503 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
Lucas Furukawa Gadani6ccadf72018-02-13 10:29:10504 view->GetWidget()->UpdateWebViewWithDeviceScaleFactor();
avi8a45c1092016-03-01 16:12:34505 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55506 }
Hajime Hoshiabb3c8f2017-12-04 18:41:39507 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
Hajime Hoshi0cda8752018-05-11 08:25:54508 frame->GetTaskRunner(blink::TaskType::kInternalDefault);
dcheng35d31c112015-07-22 00:17:36509 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29510 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45511 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54512 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45513 hidden, false)
514 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54515 blink::kWebPopupTypeNone, screen_info, false,
Hajime Hoshiabb3c8f2017-12-04 18:41:39516 hidden, false, task_runner));
simonhong628f9812015-04-27 23:13:20517 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23518 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59519 // this function returns.
nickf7b38222016-11-22 21:59:35520 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23521 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
Lucas Furukawa Gadani6ccadf72018-02-13 10:29:10522 widget->UpdateWebViewWithDeviceScaleFactor();
nick4df698d82016-11-11 20:39:23523
524 if (g_render_widget_initialized)
525 g_render_widget_initialized(widget.get());
526 return widget.get();
kenrba7199832015-01-22 23:44:59527}
528
529// static
lfgcaab5142016-02-26 19:06:52530blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08531 RenderWidget* render_widget,
532 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54533 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08534}
535
536// static
kenrba7199832015-01-22 23:44:59537blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18538 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54539 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18540 break;
Blink Reformat1c4d759e2017-04-09 16:34:54541 case blink::kWebPopupTypePage:
542 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18543 default:
544 NOTREACHED();
545 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28546 return nullptr;
[email protected]484955942010-08-19 16:13:18547}
548
dchengda9b4bb2015-07-20 20:58:08549void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32550 OnClose();
kenrba7199832015-01-22 23:44:59551}
552
alexmos78c9c0d2016-10-14 18:57:03553void RenderWidget::SetSwappedOut(bool is_swapped_out) {
554 // We should only toggle between states.
555 DCHECK(is_swapped_out_ != is_swapped_out);
556 is_swapped_out_ = is_swapped_out;
557
558 // If we are swapping out, we will call ReleaseProcess, allowing the process
559 // to exit if all of its RenderViews are swapped out. We wait until the
560 // WasSwappedOut call to do this, to allow the unload handler to finish.
561 // If we are swapping in, we call AddRefProcess to prevent the process from
562 // exiting.
563 if (!is_swapped_out_)
564 RenderProcess::current()->AddRefProcess();
565}
566
nickf7b38222016-11-22 21:59:35567void RenderWidget::Init(const ShowCallback& show_callback,
568 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21569 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23570 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29571
Jeremy Roman04f27c372017-10-27 15:20:55572 input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45573
Dave Tapuska04bc5ee92018-04-17 19:03:31574 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:26575
Dave Tapuska04bc5ee92018-04-17 19:03:31576 widget_input_handler_manager_ = WidgetInputHandlerManager::Create(
577 weak_ptr_factory_.GetWeakPtr(),
578 render_thread_impl && compositor_
579 ? render_thread_impl->compositor_task_runner()
580 : nullptr,
581 render_thread_impl ? render_thread_impl->GetWebMainThreadScheduler()
582 : nullptr);
Dave Tapuska9db80842017-07-24 17:24:26583
nickf7b38222016-11-22 21:59:35584 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29585
lfg8ff33912016-09-13 20:59:21586 webwidget_internal_ = web_widget;
587 webwidget_mouse_lock_target_.reset(
588 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21589 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29590
nick4df698d82016-11-11 20:39:23591 RenderThread::Get()->AddRoute(routing_id_, this);
592 // Take a reference on behalf of the RenderThread. This will be balanced
593 // when we receive ViewMsg_Close.
594 AddRef();
595 if (RenderThreadImpl::current()) {
596 RenderThreadImpl::current()->WidgetCreated();
597 if (is_hidden_)
598 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29599 }
600}
601
[email protected]949b6592014-08-20 13:17:52602void RenderWidget::WasSwappedOut() {
603 // If we have been swapped out and no one else is using this process,
604 // it's safe to exit now.
605 CHECK(is_swapped_out_);
606 RenderProcess::current()->ReleaseProcess();
607}
608
[email protected]b2e4c70132013-10-03 02:07:51609void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39610 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51611 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43612 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00613 popup_screen_origin_for_emulation_ =
Lei Zhang9b359d32017-11-28 00:57:02614 emulator->original_screen_rect().origin();
Christopher Cameronaad15a0d2018-03-09 03:47:33615 UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:38616 emulator->original_screen_info());
[email protected]b2e4c70132013-10-03 02:07:51617}
618
[email protected]2d6836f42014-07-02 17:25:31619gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
620 if (screen_metrics_emulator_)
621 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
622 return anchor;
623}
624
thakis18e426412017-03-15 12:06:37625#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51626void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39627 ExternalPopupMenu* popup,
628 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00629 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51630}
[email protected]53907862014-03-25 15:42:40631#endif
[email protected]b2e4c70132013-10-03 02:07:51632
[email protected]b2e4c70132013-10-03 02:07:51633void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
634 if (screen_metrics_emulator_)
635 screen_metrics_emulator_->OnShowContextMenu(params);
636}
637
[email protected]a95986a82010-12-24 06:19:28638bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47639#if defined(OS_MACOSX)
640 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
641 return text_input_client_observer_->OnMessageReceived(message);
642#endif
lfgbee1e0a2016-06-08 21:24:21643 if (mouse_lock_dispatcher_ &&
644 mouse_lock_dispatcher_->OnMessageReceived(message))
645 return true;
646
[email protected]a95986a82010-12-24 06:19:28647 bool handled = true;
648 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
wjmacleanee244e02017-05-26 21:06:07649 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28650 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
Fady Samuel799e72192018-04-25 21:16:57651 IPC_MESSAGE_HANDLER(ViewMsg_SynchronizeVisualProperties,
652 OnSynchronizeVisualProperties)
dgozman9260b0a12015-03-16 13:45:20653 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
654 OnEnableDeviceEmulation)
655 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
656 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28657 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41658 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28659 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
660 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03661 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48662 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
663 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32664 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
Ken Buchanan8a319fb2017-11-15 18:37:12665 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRenderThrottlingStatus,
666 OnUpdateRenderThrottlingStatus)
lfg43e08e62016-02-03 18:51:37667 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
668 OnWaitNextFrameForTests)
paulmeyer90f6c31d2016-11-12 00:17:59669 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
670 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
671 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
672 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21673 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
674 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
675 OnDragSourceSystemDragEnded)
[email protected]a95986a82010-12-24 06:19:28676 IPC_MESSAGE_UNHANDLED(handled = false)
677 IPC_END_MESSAGE_MAP()
678 return handled;
679}
initial.commit09911bf2008-07-26 23:55:29680
681bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42682 // Don't send any messages after the browser has told us to close, and filter
683 // most outgoing messages while swapped out.
684 if ((is_swapped_out_ &&
685 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
686 closing_) {
initial.commit09911bf2008-07-26 23:55:29687 delete message;
688 return false;
689 }
690
691 // If given a messsage without a routing ID, then assign our routing ID.
692 if (message->routing_id() == MSG_ROUTING_NONE)
693 message->set_routing_id(routing_id_);
694
[email protected]380244092011-10-07 17:26:27695 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44696}
697
dtapuska014ed082016-11-11 21:58:48698void RenderWidget::SendOrCrash(IPC::Message* message) {
699 bool result = Send(message);
700 CHECK(closing_ || result) << "Failed to send message";
701}
702
ekaramad5aff1942017-01-06 01:26:35703bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26704 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
705 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
706 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
707 // will be processed regardless of page focus. We should revisit this after
708 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54709 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26710 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35711}
712
bokanc007c3a2015-02-03 07:15:56713void RenderWidget::SetWindowRectSynchronously(
714 const gfx::Rect& new_window_rect) {
Fady Samuel799e72192018-04-25 21:16:57715 VisualProperties visual_properties;
716 visual_properties.screen_info = screen_info_;
717 visual_properties.new_size = new_window_rect.size();
718 visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize(
Fady Samuela863f152018-03-09 16:10:03719 new_window_rect.size(), GetWebScreenInfo().device_scale_factor);
Fady Samuel799e72192018-04-25 21:16:57720 visual_properties.visible_viewport_size = new_window_rect.size();
721 visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
722 visual_properties.display_mode = display_mode_;
Fady Samuel799e72192018-04-25 21:16:57723 SynchronizeVisualProperties(visual_properties);
mfomitchev2600fd7c2016-02-17 20:53:39724
bokanc007c3a2015-02-03 07:15:56725 view_screen_rect_ = new_window_rect;
726 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02727 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56728 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02729}
730
initial.commit09911bf2008-07-26 23:55:29731void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32732 DCHECK(content::RenderThread::Get());
733 if (closing_)
734 return;
735 NotifyOnClose();
736 closing_ = true;
737
738 // Browser correspondence is no longer needed at this point.
739 if (routing_id_ != MSG_ROUTING_NONE) {
740 RenderThread::Get()->RemoveRoute(routing_id_);
741 SetHidden(false);
742 if (RenderThreadImpl::current())
743 RenderThreadImpl::current()->WidgetDestroyed();
744 }
745
746 if (for_oopif_) {
747 // Widgets for frames may be created and closed at any time while the frame
Ken Buchananed449bb2018-02-01 21:02:05748 // is alive. However, WebWidget must be closed synchronously because frame
749 // widgets and frames hold pointers to each other. The deferred call to
750 // Close() will complete cleanup and release |this|, but CloseWebWidget()
751 // prevents Close() from attempting to access members of an
752 // already-deleted frame.
753 CloseWebWidget();
dchengd96a27a2015-07-24 20:17:32754 }
Ken Buchananed449bb2018-02-01 21:02:05755 // If there is a Send call on the stack, then it could be dangerous to close
756 // now. Post a task that only gets invoked when there are no nested message
757 // loops.
758 task_runner_->PostNonNestableTask(FROM_HERE,
759 base::BindOnce(&RenderWidget::Close, this));
dchengd96a27a2015-07-24 20:17:32760
761 // Balances the AddRef taken when we called AddRoute.
762 Release();
initial.commit09911bf2008-07-26 23:55:29763}
764
Fady Samuel799e72192018-04-25 21:16:57765void RenderWidget::OnSynchronizeVisualProperties(
766 const VisualProperties& params) {
EhsanKbd2cea992017-11-23 18:49:08767 gfx::Size old_visible_viewport_size = visible_viewport_size_;
768
Fady Samuel799e72192018-04-25 21:16:57769 if (resizing_mode_selector_->ShouldAbortOnResize(this, params)) {
[email protected]b2e4c70132013-10-03 02:07:51770 return;
771 }
772
Fady Samuel799e72192018-04-25 21:16:57773 if (screen_metrics_emulator_) {
774 screen_metrics_emulator_->OnSynchronizeVisualProperties(params);
775 return;
776 }
777
778 SynchronizeVisualProperties(params);
EhsanKbd2cea992017-11-23 18:49:08779
780 if (old_visible_viewport_size != visible_viewport_size_) {
781 for (auto& render_frame : render_frames_)
782 render_frame.DidChangeVisibleViewport();
783 }
initial.commit09911bf2008-07-26 23:55:29784}
785
dgozman9260b0a12015-03-16 13:45:20786void RenderWidget::OnEnableDeviceEmulation(
Lei Zhang9b359d32017-11-28 00:57:02787 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39788 if (!screen_metrics_emulator_) {
Fady Samuel799e72192018-04-25 21:16:57789 VisualProperties resize_params;
mfomitchev2600fd7c2016-02-17 20:53:39790 resize_params.screen_info = screen_info_;
791 resize_params.new_size = size_;
Christopher Cameronaad15a0d2018-03-09 03:47:33792 resize_params.compositor_viewport_pixel_size =
793 compositor_viewport_pixel_size_;
Fady Samuela41e9d42018-03-01 21:31:58794 resize_params.local_surface_id = local_surface_id_;
795 resize_params.content_source_id = current_content_source_id_;
mfomitchev2600fd7c2016-02-17 20:53:39796 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39797 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
798 resize_params.display_mode = display_mode_;
799 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
800 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18801 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39802 } else {
dgozman9260b0a12015-03-16 13:45:20803 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39804 }
dgozman9260b0a12015-03-16 13:45:20805}
806
807void RenderWidget::OnDisableDeviceEmulation() {
808 screen_metrics_emulator_.reset();
809}
810
initial.commit09911bf2008-07-26 23:55:29811void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31812 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29813 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03814 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55815 for (auto& observer : render_frames_)
816 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29817}
818
Saman Samid709592b2018-02-03 00:38:10819void RenderWidget::OnWasShown(bool needs_repainting,
820 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41821 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29822 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21823 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29824 return;
825
tasakb95dbb50c2017-02-08 18:07:50826 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29827 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03828 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55829 for (auto& observer : render_frames_)
830 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29831
[email protected]8a23afb32014-04-30 22:40:23832 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29833 return;
initial.commit09911bf2008-07-26 23:55:29834
[email protected]3399dd822014-08-09 11:14:24835 if (compositor_) {
836 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11837 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
838 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
839 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54840 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24841 }
initial.commit09911bf2008-07-26 23:55:29842}
843
[email protected]53d3f302009-12-21 04:42:05844void RenderWidget::OnRequestMoveAck() {
845 DCHECK(pending_window_rect_count_);
846 pending_window_rect_count_--;
847}
848
[email protected]ed7defa2013-03-12 21:29:59849GURL RenderWidget::GetURLForGraphicsContext3D() {
850 return GURL();
[email protected]65225772011-05-12 21:10:24851}
852
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27853viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::Point& point) {
854 return input_handler_->GetFrameSinkIdAtPoint(point);
Navid Zolghadr0d86e5f2017-10-23 18:09:22855}
856
Dave Tapuskaea83d3bd2017-06-13 16:14:55857void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31858 const blink::WebCoalescedInputEvent& input_event,
859 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55860 HandledEventCallback callback) {
861 input_handler_->HandleInputEvent(input_event, latency_info,
862 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31863}
864
dtapuska9d46ef7d2017-05-26 19:06:06865scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
866 return input_event_queue_;
867}
868
fsamuel78f86e42016-01-20 04:10:23869void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21870 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54871 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23872}
873
874void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21875 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54876 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23877}
878
alexmos56567492016-09-13 00:52:46879void RenderWidget::OnSetEditCommandsForNextKeyEvent(
880 const EditCommands& edit_commands) {
881 edit_commands_ = edit_commands;
882}
883
fsamuel78f86e42016-01-20 04:10:23884void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08885 has_focus_ = enable;
886
lfg8ff33912016-09-13 20:59:21887 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54888 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08889
ericwilligers88e69742016-10-17 19:29:55890 for (auto& observer : render_frames_)
891 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23892}
893
dtapuska3d5624d32016-08-30 04:34:00894void RenderWidget::SetNeedsMainFrame() {
895 RenderWidgetCompositor* rwc = compositor();
896 if (!rwc)
897 return;
Blink Reformat1c4d759e2017-04-09 16:34:54898 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00899}
900
fsamuel78f86e42016-01-20 04:10:23901///////////////////////////////////////////////////////////////////////////////
902// RenderWidgetCompositorDelegate
903
904void RenderWidget::ApplyViewportDeltas(
905 const gfx::Vector2dF& inner_delta,
906 const gfx::Vector2dF& outer_delta,
907 const gfx::Vector2dF& elastic_overscroll_delta,
908 float page_scale,
909 float top_controls_delta) {
Ken Buchananed449bb2018-02-01 21:02:05910 if (!GetWebWidget())
911 return;
Blink Reformat1c4d759e2017-04-09 16:34:54912 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21913 elastic_overscroll_delta, page_scale,
914 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23915}
916
sahel1b47fda72017-03-28 17:03:07917void RenderWidget::RecordWheelAndTouchScrollingCount(
918 bool has_scrolled_by_wheel,
919 bool has_scrolled_by_touch) {
Ken Buchananed449bb2018-02-01 21:02:05920 if (!GetWebWidget())
921 return;
Blink Reformat1c4d759e2017-04-09 16:34:54922 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07923 has_scrolled_by_touch);
924}
925
Daniel Cheng224569ee2018-04-25 05:45:06926void RenderWidget::BeginMainFrame(base::TimeTicks frame_time) {
Ken Buchananed449bb2018-02-01 21:02:05927 if (!GetWebWidget())
928 return;
Daniel Cheng224569ee2018-04-25 05:45:06929 if (input_event_queue_)
930 input_event_queue_->DispatchRafAlignedInput(frame_time);
dtapuska3d5624d32016-08-30 04:34:00931
Daniel Cheng224569ee2018-04-25 05:45:06932 GetWebWidget()->BeginFrame(frame_time);
fsamuel78f86e42016-01-20 04:10:23933}
934
danakjc7afae52017-06-20 21:12:41935void RenderWidget::RequestNewLayerTreeFrameSink(
danakjc7afae52017-06-20 21:12:41936 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21937 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03938 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41939 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39940 DCHECK(!compositor_never_visible_);
jonrossa2ff4f82018-02-16 17:27:46941
942 // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which
943 // would then handle binding.
944 mojom::RenderFrameMetadataObserverPtr ptr;
945 mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr);
946 mojom::RenderFrameMetadataObserverClientPtrInfo client_info;
947 mojom::RenderFrameMetadataObserverClientRequest client_request =
948 mojo::MakeRequest(&client_info);
949 compositor_->CreateRenderFrameObserver(std::move(request),
950 std::move(client_info));
danakjc7afae52017-06-20 21:12:41951 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
danakjab9ef4d2017-10-31 23:38:33952 routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(),
jonrossa2ff4f82018-02-16 17:27:46953 callback, std::move(client_request), std::move(ptr));
[email protected]ba91a792013-02-06 09:48:28954}
955
fsamuel78f86e42016-01-20 04:10:23956void RenderWidget::DidCommitAndDrawCompositorFrame() {
957 // NOTE: Tests may break if this event is renamed or moved. See
958 // tab_capture_performancetest.cc.
959 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08960
ericwilligers88e69742016-10-17 19:29:55961 for (auto& observer : render_frames_)
962 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08963
fsamuel78f86e42016-01-20 04:10:23964 // Notify subclasses that we initiated the paint operation.
965 DidInitiatePaint();
966}
967
Saman Sami766e0b02018-01-31 17:19:20968void RenderWidget::DidCommitCompositorFrame() {
Saman Sami766e0b02018-01-31 17:19:20969}
fsamuel78f86e42016-01-20 04:10:23970
971void RenderWidget::DidCompletePageScaleAnimation() {}
972
danakj6c872fc02016-10-22 04:29:49973void RenderWidget::DidReceiveCompositorFrameAck() {
fsamuel78f86e42016-01-20 04:10:23974}
975
fsamuel78f86e42016-01-20 04:10:23976bool RenderWidget::IsClosing() const {
977 return host_closing_;
978}
979
danakj53eccbc2016-03-02 22:51:07980void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:54981 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29982}
983
Eric Seckler8af8c0e52018-01-17 23:45:53984void RenderWidget::UpdateVisualState(VisualStateUpdate requested_update) {
Ken Buchananed449bb2018-02-01 21:02:05985 if (!GetWebWidget())
986 return;
987
Eric Seckler8af8c0e52018-01-17 23:45:53988 bool pre_paint_only = requested_update == VisualStateUpdate::kPrePaint;
989 WebWidget::LifecycleUpdate lifecycle_update =
990 pre_paint_only ? WebWidget::LifecycleUpdate::kPrePaint
991 : WebWidget::LifecycleUpdate::kAll;
992
993 GetWebWidget()->UpdateLifecycle(lifecycle_update);
Blink Reformat1c4d759e2017-04-09 16:34:54994 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:50995
Eric Seckler8af8c0e52018-01-17 23:45:53996 if (first_update_visual_state_after_hidden_ && !pre_paint_only) {
Takashi SAKAMOTO870f6262017-08-22 04:08:27997 RecordTimeToFirstActivePaint();
998 first_update_visual_state_after_hidden_ = false;
999 }
1000}
tasakb95dbb50c2017-02-08 18:07:501001
Takashi SAKAMOTO870f6262017-08-22 04:08:271002void RenderWidget::RecordTimeToFirstActivePaint() {
tasakb95dbb50c2017-02-08 18:07:501003 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
tasakb95dbb50c2017-02-08 18:07:501004 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
Takashi SAKAMOTO870f6262017-08-22 04:08:271005 if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) {
1006 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1007 sample);
1008 }
1009 if (render_thread_impl->NeedsToRecordFirstActivePaint(
1010 TTFAP_5MIN_AFTER_BACKGROUNDED)) {
1011 UMA_HISTOGRAM_TIMES(
1012 "PurgeAndSuspend.Experimental.TimeToFirstActivePaint."
1013 "AfterBackgrounded.5min",
1014 sample);
1015 }
fsamuel78f86e42016-01-20 04:10:231016}
1017
1018void RenderWidget::WillBeginCompositorFrame() {
1019 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1020
Ken Buchananed449bb2018-02-01 21:02:051021 if (!GetWebWidget())
1022 return;
1023
Blink Reformat1c4d759e2017-04-09 16:34:541024 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291025
dglazkov06854c5c2016-08-31 00:19:591026 // The UpdateTextInputState can result in further layout and possibly
1027 // enable GPU acceleration so they need to be called before any painting
1028 // is done.
changwan75e3b2072017-01-16 02:55:001029 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591030 UpdateSelectionBounds();
1031
ericwilligers88e69742016-10-17 19:29:551032 for (auto& observer : render_frame_proxies_)
1033 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291034}
1035
jbroman6ccbc7d472016-07-27 04:45:411036std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041037 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411038 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1039 routing_id_, std::move(request));
1040}
1041
fsamuel72464894f2015-12-15 06:59:311042///////////////////////////////////////////////////////////////////////////////
1043// RenderWidgetInputHandlerDelegate
1044
avid7d6b2e2016-03-04 19:41:171045void RenderWidget::FocusChangeComplete() {
Ehsan Karamad655d7b8a2018-01-12 18:38:381046 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1047 if (!frame_widget)
ekaramad27ca69b12017-04-20 18:34:291048 return;
Ehsan Karamad655d7b8a2018-01-12 18:38:381049
ekaramad27ca69b12017-04-20 18:34:291050 blink::WebLocalFrame* focused =
Ehsan Karamad655d7b8a2018-01-12 18:38:381051 frame_widget->LocalRoot()->View()->FocusedFrame();
1052
ekaramad27ca69b12017-04-20 18:34:291053 if (focused && focused->AutofillClient())
1054 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171055}
fsamuel72464894f2015-12-15 06:59:311056
dtapuska1827dd22016-03-11 15:24:591057void RenderWidget::ObserveGestureEventAndResult(
1058 const blink::WebGestureEvent& gesture_event,
1059 const gfx::Vector2dF& unused_delta,
Sandra Sunac5cdd832017-12-11 03:27:131060 const cc::OverscrollBehavior& overscroll_behavior,
dtapuska1827dd22016-03-11 15:24:591061 bool event_processed) {
1062 if (!compositor_deps_->IsElasticOverscrollEnabled())
1063 return;
1064
1065 cc::InputHandlerScrollResult scroll_result;
1066 scroll_result.did_scroll = event_processed;
1067 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1068 scroll_result.unused_scroll_delta = unused_delta;
Sandra Sunac5cdd832017-12-11 03:27:131069 scroll_result.overscroll_behavior = overscroll_behavior;
dtapuska1827dd22016-03-11 15:24:591070
Dave Tapuska04bc5ee92018-04-17 19:03:311071 widget_input_handler_manager_->ObserveGestureEventOnMainThread(gesture_event,
1072 scroll_result);
dtapuska1827dd22016-03-11 15:24:591073}
1074
avid7d6b2e2016-03-04 19:41:171075void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461076 ClearEditCommands();
1077}
1078
1079void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1080 const std::string& value) {
1081 ClearEditCommands();
1082 edit_commands_.emplace_back(name, value);
1083}
1084
1085void RenderWidget::ClearEditCommands() {
1086 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171087}
fsamuel72464894f2015-12-15 06:59:311088
chongza8ba91fc2016-08-16 21:39:171089void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
Dave Tapuska04bc5ee92018-04-17 19:03:311090 if (mojom::WidgetInputHandlerHost* host =
1091 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1092 host->DidOverscroll(params);
Dave Tapuska139a72f2017-09-06 21:57:031093 }
fsamuel72464894f2015-12-15 06:59:311094}
1095
fsamuele8326c742016-01-12 00:49:391096void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1097 // Nothing to do here. RenderWidget created the |input_handler| and will take
1098 // ownership of it. We just verify here that we don't already have an input
1099 // handler.
1100 DCHECK(!input_handler_);
1101}
1102
changwan75e3b2072017-01-16 02:55:001103void RenderWidget::ShowVirtualKeyboard() {
1104 UpdateTextInputStateInternal(true, false);
1105}
1106
changwan62f57292017-02-17 08:28:251107void RenderWidget::ClearTextInputState() {
1108 text_input_info_ = blink::WebTextInputInfo();
1109 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1110 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1111 can_compose_inline_ = false;
1112 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201113 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251114}
1115
changwan75e3b2072017-01-16 02:55:001116void RenderWidget::UpdateTextInputState() {
1117 UpdateTextInputStateInternal(false, false);
1118}
1119
1120void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1121 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311122 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001123
fsamuel72464894f2015-12-15 06:59:311124 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001125 DCHECK(!reply_to_request);
1126 // show_virtual_keyboard should still be effective even if it was set inside
1127 // the IME
fsamuel72464894f2015-12-15 06:59:311128 // event guard.
changwan75e3b2072017-01-16 02:55:001129 if (show_virtual_keyboard)
1130 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311131 return;
1132 }
1133
dglazkov97b6c2b2016-10-25 17:35:551134 ui::TextInputType new_type = GetTextInputType();
1135 if (IsDateTimeInput(new_type))
1136 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311137
dglazkov97b6c2b2016-10-25 17:35:551138 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351139 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541140 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101141 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541142 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311143
1144 bool new_can_compose_inline = CanComposeInline();
1145
1146 // Only sends text input params if they are changed or if the ime should be
1147 // shown.
changwan75e3b2072017-01-16 02:55:001148 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561149 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1150 text_input_info_ != new_info ||
1151 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381152 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551153 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311154 params.mode = new_mode;
1155 params.flags = new_info.flags;
AJITH KUMAR V9e7b5572017-11-14 00:54:211156#if defined(OS_ANDROID)
AJITH KUMAR V041c0b02017-08-08 10:39:201157 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1158 // Due to a focus change, values will be reset by the frame.
1159 // That case we only need fresh NEXT/PREVIOUS information.
1160 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1161 // focusable status is changed.
1162 if (auto* controller = GetInputMethodController()) {
1163 next_previous_flags_ =
1164 controller->ComputeWebTextInputNextPreviousFlags();
1165 } else {
1166 // For safety in case GetInputMethodController() is null, because -1 is
1167 // invalid value to send to browser process.
1168 next_previous_flags_ = 0;
1169 }
1170 }
AJITH KUMAR V9e7b5572017-11-14 00:54:211171#else
1172 next_previous_flags_ = 0;
1173#endif
AJITH KUMAR V041c0b02017-08-08 10:39:201174 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541175 params.value = new_info.value.Utf8();
1176 params.selection_start = new_info.selection_start;
1177 params.selection_end = new_info.selection_end;
1178 params.composition_start = new_info.composition_start;
1179 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311180 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001181 // TODO(changwan): change instances of show_ime_if_needed to
1182 // show_virtual_keyboard.
1183 params.show_ime_if_needed = show_virtual_keyboard;
1184 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311185 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1186
1187 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551188 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311189 text_input_mode_ = new_mode;
1190 can_compose_inline_ = new_can_compose_inline;
1191 text_input_flags_ = new_info.flags;
1192 }
1193}
1194
1195bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581196 possible_drag_event_info_.event_source =
1197 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1198 possible_drag_event_info_.event_location =
Ella Ge1116059d2018-03-21 02:06:131199 gfx::ToFlooredPoint(event.PositionInScreen());
avid7d6b2e2016-03-04 19:41:171200
fsamuel72464894f2015-12-15 06:59:311201 return false;
1202}
1203
1204bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551205 for (auto& observer : render_frames_)
1206 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081207
paulmeyer6ef5a792016-11-08 20:33:581208 possible_drag_event_info_.event_source =
1209 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1210 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541211 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581212
avid7d6b2e2016-03-04 19:41:171213 if (owner_delegate_)
1214 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1215
fsamuel72464894f2015-12-15 06:59:311216 return false;
[email protected]fd847792013-10-24 17:12:351217}
1218
initial.commit09911bf2008-07-26 23:55:291219///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391220// RenderWidgetScreenMetricsDelegate
1221
1222void RenderWidget::Redraw() {
mfomitchev2600fd7c2016-02-17 20:53:391223 if (compositor_)
1224 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1225}
1226
bokanc63441c2016-04-27 15:49:121227void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541228 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121229}
1230
1231gfx::Size RenderWidget::GetSizeForWebWidget() const {
Fady Samuela863f152018-03-09 16:10:031232 if (IsUseZoomForDSFEnabled()) {
1233 return gfx::ScaleToCeiledSize(size_,
1234 GetOriginalScreenInfo().device_scale_factor);
1235 }
bokanc63441c2016-04-27 15:49:121236
1237 return size_;
1238}
1239
Fady Samuel799e72192018-04-25 21:16:571240void RenderWidget::SynchronizeVisualProperties(const VisualProperties& params) {
Saman Samif7731342018-01-24 22:18:441241 // The content_source_id that the browser sends us should never be larger than
1242 // |current_content_source_id_|.
1243 DCHECK_GE(1u << 30, current_content_source_id_ - params.content_source_id);
1244
Christopher Cameronbe7ecea2018-02-27 00:47:191245 // Inform the rendering thread of the color space indicate the presence of HDR
1246 // capabilities.
Miguel Casas5e1018052018-01-09 19:17:361247 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1248 if (render_thread)
Christopher Camerone9a30c12018-03-07 08:23:381249 render_thread->SetRenderingColorSpace(params.screen_info.color_space);
Miguel Casas5e1018052018-01-09 19:17:361250
mfomitchev2600fd7c2016-02-17 20:53:391251 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211252 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391253 return;
1254
Fady Samuele62be402018-03-29 03:19:531255 gfx::Size new_compositor_viewport_pixel_size =
1256 params.auto_resize_enabled
1257 ? gfx::ScaleToCeiledSize(size_,
1258 params.screen_info.device_scale_factor)
1259 : params.compositor_viewport_pixel_size;
Fady Samuel4392abb2018-05-10 21:01:211260 UpdateSurfaceAndScreenInfo(
1261 params.local_surface_id.value_or(viz::LocalSurfaceId()),
1262 new_compositor_viewport_pixel_size, params.screen_info);
Vladimir Levin98d76dad2018-04-21 00:21:291263 UpdateCaptureSequenceNumber(params.capture_sequence_number);
ianwene5fc5782016-08-18 04:05:151264 if (compositor_) {
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271265 compositor_->SetBrowserControlsHeight(
1266 params.top_controls_height, params.bottom_controls_height,
1267 params.browser_controls_shrink_blink_size);
1268 compositor_->SetRasterColorSpace(
1269 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151270 }
mfomitchev2600fd7c2016-02-17 20:53:391271
Fady Samuele62be402018-03-29 03:19:531272 if (params.auto_resize_enabled)
1273 return;
1274
mfomitchev2600fd7c2016-02-17 20:53:391275 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391276
1277 // NOTE: We may have entered fullscreen mode without changing our size.
1278 bool fullscreen_change =
1279 is_fullscreen_granted_ != params.is_fullscreen_granted;
1280 is_fullscreen_granted_ = params.is_fullscreen_granted;
1281 display_mode_ = params.display_mode;
1282
bokanc63441c2016-04-27 15:49:121283 size_ = params.new_size;
mfomitchev2600fd7c2016-02-17 20:53:391284
bokanc63441c2016-04-27 15:49:121285 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221286
mfomitchev2600fd7c2016-02-17 20:53:391287 WebSize visual_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391288 if (IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031289 visual_viewport_size =
1290 gfx::ScaleToCeiledSize(params.visible_viewport_size,
1291 GetOriginalScreenInfo().device_scale_factor);
mfomitchev2600fd7c2016-02-17 20:53:391292 } else {
1293 visual_viewport_size = visible_viewport_size_;
1294 }
Blink Reformat1c4d759e2017-04-09 16:34:541295 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391296
mfomitchev2600fd7c2016-02-17 20:53:391297 if (fullscreen_change)
1298 DidToggleFullscreen();
mfomitchev2600fd7c2016-02-17 20:53:391299}
1300
1301void RenderWidget::SetScreenMetricsEmulationParameters(
1302 bool enabled,
1303 const blink::WebDeviceEmulationParams& params) {
1304 // This is only supported in RenderView.
1305 NOTREACHED();
1306}
1307
1308void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1309 const gfx::Rect& window_screen_rect) {
1310 view_screen_rect_ = view_screen_rect;
1311 window_screen_rect_ = window_screen_rect;
1312}
1313
1314///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461315// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291316
Blink Reformat1c4d759e2017-04-09 16:34:541317blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221318 DCHECK(!host_closing_);
1319
loyso6e6efc42017-01-21 02:23:031320 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1321 auto animation_host = cc::AnimationHost::CreateMainInstance();
1322
wjmacleana755e302017-04-20 00:43:161323 // Oopif status must be set before the LayerTreeHost is created.
1324 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031325 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1326 compositor_.get(), compositor_.get(), animation_host.get(),
Christopher Camerone9a30c12018-03-07 08:23:381327 compositor_deps_, screen_info_);
loyso6e6efc42017-01-21 02:23:031328 compositor_->Initialize(std::move(layer_tree_host),
1329 std::move(animation_host));
1330
Christopher Cameronaad15a0d2018-03-09 03:47:331331 UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_,
Christopher Camerone9a30c12018-03-07 08:23:381332 screen_info_);
ccameron01912992017-05-23 07:34:031333 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091334 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011335 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391336 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411337 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221338 bool should_generate_frame_sink =
1339 !compositor_never_visible_ && RenderThreadImpl::current();
1340 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391341 compositor_->SetNeverVisible();
1342
pimanc4af3072015-10-02 03:45:591343 StartCompositor();
staraz067f58242016-11-07 21:06:411344 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1345 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331346 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371347
wjmaclean1d970622017-01-21 22:28:241348 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261349 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311350 input_event_queue_ = new MainThreadEventQueue(
Yuta Kitamura3331f5c2018-04-05 11:12:251351 this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(),
1352 render_thread->GetWebMainThreadScheduler(), should_generate_frame_sink);
wjmaclean1d970622017-01-21 22:28:241353 }
1354
Khushal3e96e662017-10-30 23:16:501355 UpdateURLForCompositorUkm();
1356
loyso50b51c22017-01-10 07:18:371357 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591358}
1359
Chris Harrelsond7ab99b2018-01-24 17:51:361360void RenderWidget::IntrinsicSizingInfoChanged(
1361 const blink::WebIntrinsicSizingInfo& sizing_info) {
1362 Send(new ViewHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info));
1363}
1364
ennef3c58142014-12-09 21:44:381365void RenderWidget::WillCloseLayerTreeView() {
1366 if (host_closing_)
1367 return;
1368
1369 // Prevent new compositors or output surfaces from being created.
1370 host_closing_ = true;
1371
[email protected]aeeedad2014-08-22 18:16:221372 // Always send this notification to prevent new layer tree views from
1373 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211374 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541375 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221376}
1377
Blink Reformat1c4d759e2017-04-09 16:34:541378void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1379 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481380 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1381 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1382 }
dglazkov79c426102015-08-31 21:22:431383
ericwilligers88e69742016-10-17 19:29:551384 for (auto& observer : render_frames_)
1385 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431386}
1387
[email protected]586871b2014-07-22 17:05:111388// static
dchengcedca5612016-04-09 01:40:151389std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111390 IPC::Message* msg,
1391 MessageDeliveryPolicy policy,
1392 FrameSwapMessageQueue* frame_swap_message_queue,
1393 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111394 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111395 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151396 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1397 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111398 &first_message_for_frame);
1399 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151400 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111401 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061402 return promise;
[email protected]586871b2014-07-22 17:05:111403 }
dcheng4b6b5ff2014-10-16 00:42:061404 return nullptr;
[email protected]586871b2014-07-22 17:05:111405}
1406
1407void RenderWidget::QueueMessage(IPC::Message* msg,
1408 MessageDeliveryPolicy policy) {
1409 // RenderThreadImpl::current() is NULL in some tests.
1410 if (!compositor_ || !RenderThreadImpl::current()) {
1411 Send(msg);
1412 return;
1413 }
1414
dchengcedca5612016-04-09 01:40:151415 std::unique_ptr<cc::SwapPromise> swap_promise =
1416 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111417 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111418 compositor_->GetSourceFrameNumber());
1419
Ken Buchanance710eb2017-08-30 23:46:521420 if (swap_promise)
dcheng07945f632015-12-26 07:59:321421 compositor_->QueueSwapPromise(std::move(swap_promise));
[email protected]586871b2014-07-22 17:05:111422}
1423
Blink Reformat1c4d759e2017-04-09 16:34:541424void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301425 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521426 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181427 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291428 // Only send a SetCursor message if we need to make a change.
1429 if (!current_cursor_.IsEqual(cursor)) {
1430 current_cursor_ = cursor;
1431 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1432 }
1433}
1434
aelias5971e47d2017-06-16 02:39:381435void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1436 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1437}
1438
1439void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1440 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1441}
1442
1443void RenderWidget::AutoscrollEnd() {
1444 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1445}
1446
initial.commit09911bf2008-07-26 23:55:291447// We are supposed to get a single call to Show for a newly created RenderWidget
1448// that was created via RenderWidget::CreateWebView. So, we wait until this
1449// point to dispatch the ShowWidget message.
1450//
1451// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281452// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291453//
Blink Reformat1c4d759e2017-04-09 16:34:541454void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291455 DCHECK(!did_show_) << "received extraneous Show call";
1456 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351457 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291458
[email protected]8de12d942010-11-17 20:42:441459 if (did_show_)
1460 return;
1461
1462 did_show_ = true;
nickf7b38222016-11-22 21:59:351463
1464 // The opener is responsible for actually showing this widget.
1465 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351466 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351467
bokanc007c3a2015-02-03 07:15:561468 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441469 // that's okay. It'll be ignored if as_popup is false, or the browser
1470 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561471 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291472}
1473
[email protected]2533ce12009-05-09 00:02:241474void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381475 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241476 Send(new ViewHostMsg_Close(routing_id_));
1477}
1478
dgozmancf9039cd2015-04-06 12:01:311479void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551480 for (auto& observer : render_frames_)
1481 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311482}
1483
Blink Reformat1c4d759e2017-04-09 16:34:541484void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081485 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321486 if (is_swapped_out_) {
1487 // This widget is currently swapped out, and the active widget is in a
1488 // different process. Have the browser route the close request to the
1489 // active widget instead, so that the correct unload handlers are run.
1490 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1491 return;
1492 }
1493
initial.commit09911bf2008-07-26 23:55:291494 // If a page calls window.close() twice, we'll end up here twice, but that's
1495 // OK. It is safe to send multiple Close messages.
1496
[email protected]2533ce12009-05-09 00:02:241497 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1498 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1499 // could be closed before the JS finishes executing. So instead, post a
1500 // message back to the message loop, which won't run until the JS is
1501 // complete, and then the Close message can be sent.
Hajime Hoshiabb3c8f2017-12-04 18:41:391502 task_runner_->PostTask(FROM_HERE,
1503 base::BindOnce(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291504}
1505
1506void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031507 screen_metrics_emulator_.reset();
Ken Buchananed449bb2018-02-01 21:02:051508 CloseWebWidget();
ennef3c58142014-12-09 21:44:381509 compositor_.reset();
Ken Buchananed449bb2018-02-01 21:02:051510}
1511
1512void RenderWidget::CloseWebWidget() {
1513 WillCloseLayerTreeView();
lfg8ff33912016-09-13 20:59:211514 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541515 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211516 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291517 }
1518}
1519
Mitsuru Oshima3c07b332018-02-06 04:56:501520void RenderWidget::UpdateWebViewWithDeviceScaleFactor() {
1521 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1522 blink::WebFrame* current_frame =
1523 frame_widget ? frame_widget->LocalRoot() : nullptr;
1524 blink::WebView* webview = current_frame ? current_frame->View() : nullptr;
1525 if (webview) {
1526 if (IsUseZoomForDSFEnabled())
Fady Samuela863f152018-03-09 16:10:031527 webview->SetZoomFactorForDeviceScaleFactor(
1528 GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501529 else
Fady Samuela863f152018-03-09 16:10:031530 webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor);
Mitsuru Oshima3c07b332018-02-06 04:56:501531
1532 webview->GetSettings()->SetPreferCompositingToLCDTextEnabled(
Christopher Camerone9a30c12018-03-07 08:23:381533 PreferCompositingToLCDText(compositor_deps_,
Fady Samuela863f152018-03-09 16:10:031534 GetWebScreenInfo().device_scale_factor));
Mitsuru Oshima3c07b332018-02-06 04:56:501535 }
1536}
1537
Ehsan Karamad655d7b8a2018-01-12 18:38:381538blink::WebFrameWidget* RenderWidget::GetFrameWidget() const {
1539 blink::WebWidget* web_widget = GetWebWidget();
1540 if (!web_widget)
1541 return nullptr;
1542
1543 if (!web_widget->IsWebFrameWidget()) {
1544 // TODO(ekaramad): This should not happen. If we have a WebWidget and we
1545 // need a WebFrameWidget then we should be getting a WebFrameWidget. But
1546 // unfortunately this does not seem to be the case in some scenarios --
1547 // specifically when a RenderViewImpl swaps out during navigation the
1548 // WebViewImpl loses its WebViewFrameWidget but sometimes we receive IPCs
1549 // which are destined for WebFrameWidget (https://crbug.com/669219).
1550 return nullptr;
1551 }
1552
1553 return static_cast<blink::WebFrameWidget*>(web_widget);
1554}
1555
bokan841fdc72016-10-06 00:16:351556void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1557 DCHECK(window_rect);
1558 float scale = popup_origin_scale_for_emulation_;
1559 if (!scale)
1560 return;
1561 window_rect->x =
1562 popup_view_origin_for_emulation_.x() +
1563 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1564 window_rect->y =
1565 popup_view_origin_for_emulation_.y() +
1566 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1567}
1568
1569void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1570 DCHECK(window_rect);
1571 float scale = popup_origin_scale_for_emulation_;
1572 if (!scale)
1573 return;
1574 window_rect->x =
1575 popup_screen_origin_for_emulation_.x() +
1576 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1577 window_rect->y =
1578 popup_screen_origin_for_emulation_.y() +
1579 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1580}
1581
Blink Reformat1c4d759e2017-04-09 16:34:541582WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351583 WebRect rect;
bokan6b08cd22016-10-05 00:55:211584 if (pending_window_rect_count_) {
1585 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1586 // the RootWindowRect is probably going to return wrong results since the
1587 // browser may not have processed the Move yet. There isn't really anything
1588 // good to do in this case, and it shouldn't happen - since this size is
1589 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351590 rect = pending_window_rect_;
1591 } else {
1592 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211593 }
[email protected]2533ce12009-05-09 00:02:241594
bokan841fdc72016-10-06 00:16:351595 ScreenRectToEmulatedIfNeeded(&rect);
1596 return rect;
bokan6b08cd22016-10-05 00:55:211597}
1598
Blink Reformat1c4d759e2017-04-09 16:34:541599WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351600 WebRect rect = view_screen_rect_;
1601 ScreenRectToEmulatedIfNeeded(&rect);
1602 return rect;
initial.commit09911bf2008-07-26 23:55:291603}
1604
Blink Reformat1c4d759e2017-04-09 16:34:541605void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301606 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541607 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301608}
1609
Blink Reformat1c4d759e2017-04-09 16:34:541610void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241611 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351612 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511613
[email protected]5b45ad42013-10-25 00:42:041614 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201615 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561616 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1617 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031618 } else {
bokanc007c3a2015-02-03 07:15:561619 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031620 }
initial.commit09911bf2008-07-26 23:55:291621 } else {
bokanc007c3a2015-02-03 07:15:561622 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291623 }
1624}
1625
[email protected]2533ce12009-05-09 00:02:241626void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1627 pending_window_rect_ = rect;
1628 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241629
bokan6b08cd22016-10-05 00:55:211630 // Popups don't get size updates back from the browser so just store the set
1631 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541632 if (popup_type_ != blink::kWebPopupTypeNone) {
1633 window_screen_rect_ = rect;
1634 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241635 }
[email protected]d4547452008-08-28 18:36:371636}
1637
wjmacleanee244e02017-05-26 21:06:071638void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1639 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071640 has_host_context_menu_location_ = true;
1641 host_context_menu_location_ = location;
1642 if (GetWebWidget()) {
1643 GetWebWidget()->ShowContextMenu(
1644 static_cast<blink::WebMenuSourceType>(source_type));
1645 }
1646 has_host_context_menu_location_ = false;
1647}
1648
[email protected]fa7b1dc2010-06-23 17:53:041649void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261650 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111651 const std::vector<WebImeTextSpan>& ime_text_spans,
chongz7eb752802016-01-27 21:28:071652 const gfx::Range& replacement_range,
Ryan Landay9e42fd742017-08-12 01:59:111653 int selection_start,
1654 int selection_end) {
ekaramad5aff1942017-01-06 01:26:351655 if (!ShouldHandleImeEvents())
1656 return;
1657
brettw4b461082016-11-19 18:55:161658#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491659 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
Ryan Landay9e42fd742017-08-12 01:59:111660 plugin->render_frame()->OnImeSetComposition(text, ime_text_spans,
EhsanK22d482e2017-08-10 17:29:491661 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091662 return;
1663 }
1664#endif
[email protected]66fca5bc2013-05-23 06:58:291665 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011666 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011667 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541668 !controller->SetComposition(
Ryan Landay9e42fd742017-08-12 01:59:111669 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561670 replacement_range.IsValid()
1671 ? WebRange(replacement_range.start(), replacement_range.length())
1672 : WebRange(),
1673 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041674 // If we failed to set the composition text, then we need to let the browser
1675 // process to cancel the input method's ongoing composition session, to make
1676 // sure we are in a consistent state.
Dave Tapuska04bc5ee92018-04-17 19:03:311677 if (mojom::WidgetInputHandlerHost* host =
1678 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1679 host->ImeCancelComposition();
Dave Tapuska139a72f2017-09-06 21:57:031680 }
[email protected]7f00efa2010-04-15 05:01:261681 }
nonafa291792016-08-10 02:36:181682 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041683}
1684
rlanday7efe2302017-01-11 00:14:281685void RenderWidget::OnImeCommitText(
1686 const base::string16& text,
Ryan Landay9e42fd742017-08-12 01:59:111687 const std::vector<WebImeTextSpan>& ime_text_spans,
rlanday7efe2302017-01-11 00:14:281688 const gfx::Range& replacement_range,
1689 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351690 if (!ShouldHandleImeEvents())
1691 return;
1692
brettw4b461082016-11-19 18:55:161693#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491694 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1695 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1696 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091697 return;
1698 }
1699#endif
[email protected]66fca5bc2013-05-23 06:58:291700 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391701 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261702 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541703 controller->CommitText(
Ryan Landay9e42fd742017-08-12 01:59:111704 WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans),
ekaramadce32ef9f2017-02-09 17:33:561705 replacement_range.IsValid()
1706 ? WebRange(replacement_range.start(), replacement_range.length())
1707 : WebRange(),
1708 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261709 }
aelias87b8f7c2016-09-14 03:19:291710 input_handler_->set_handling_input_event(false);
1711 UpdateCompositionInfo(false /* not an immediate request */);
1712}
1713
1714void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351715 if (!ShouldHandleImeEvents())
1716 return;
1717
brettw4b461082016-11-19 18:55:161718#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491719 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1720 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291721 return;
1722 }
1723#endif
1724
changwan38c3eb612016-12-09 01:45:561725 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291726 return;
1727 ImeEventGuard guard(this);
1728 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011729 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541730 controller->FinishComposingText(
1731 keep_selection ? WebInputMethodController::kKeepSelection
1732 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011733 }
fsamuele8326c742016-01-12 00:49:391734 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181735 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291736}
1737
Christopher Camerone9a30c12018-03-07 08:23:381738void RenderWidget::UpdateSurfaceAndScreenInfo(
Fady Samuel4392abb2018-05-10 21:01:211739 const viz::LocalSurfaceId& new_local_surface_id,
Christopher Cameronaad15a0d2018-03-09 03:47:331740 const gfx::Size& new_compositor_viewport_pixel_size,
Christopher Camerone9a30c12018-03-07 08:23:381741 const ScreenInfo& new_screen_info) {
Christopher Camerone9a30c12018-03-07 08:23:381742 bool orientation_changed =
1743 screen_info_.orientation_angle != new_screen_info.orientation_angle ||
1744 screen_info_.orientation_type != new_screen_info.orientation_type;
1745 bool web_device_scale_factor_changed =
1746 screen_info_.device_scale_factor != new_screen_info.device_scale_factor;
Fady Samuela863f152018-03-09 16:10:031747 ScreenInfo previous_original_screen_info = GetOriginalScreenInfo();
Christopher Cameronbe7ecea2018-02-27 00:47:191748
1749 local_surface_id_ = new_local_surface_id;
Christopher Cameronaad15a0d2018-03-09 03:47:331750 compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size;
Christopher Camerone9a30c12018-03-07 08:23:381751 screen_info_ = new_screen_info;
Christopher Cameronbe7ecea2018-02-27 00:47:191752
Christopher Camerone9a30c12018-03-07 08:23:381753 if (compositor_) {
Ken Buchananb2c9e262018-03-10 16:53:311754 compositor_->SetViewportVisibleRect(ViewportVisibleRect());
Christopher Camerone9a30c12018-03-07 08:23:381755 // Note carefully that the DSF specified in |new_screen_info| is not the
1756 // DSF used by the compositor during device emulation!
Fady Samuela863f152018-03-09 16:10:031757 compositor_->SetViewportSizeAndScale(
1758 compositor_viewport_pixel_size_,
1759 GetOriginalScreenInfo().device_scale_factor, local_surface_id_);
Christopher Camerone9a30c12018-03-07 08:23:381760 }
Christopher Cameronbe7ecea2018-02-27 00:47:191761
Christopher Camerone9a30c12018-03-07 08:23:381762 if (orientation_changed)
1763 OnOrientationChange();
Christopher Cameronbe7ecea2018-02-27 00:47:191764
Fady Samuela863f152018-03-09 16:10:031765 if (previous_original_screen_info != GetOriginalScreenInfo()) {
Christopher Camerone9a30c12018-03-07 08:23:381766 for (auto& observer : render_frame_proxies_)
Fady Samuela863f152018-03-09 16:10:031767 observer.OnScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:381768
1769 // Notify all embedded BrowserPlugins of the updated ScreenInfo.
1770 for (auto& observer : browser_plugins_)
Fady Samuela863f152018-03-09 16:10:031771 observer.ScreenInfoChanged(GetOriginalScreenInfo());
Christopher Camerone9a30c12018-03-07 08:23:381772 }
1773
1774 if (web_device_scale_factor_changed)
Christopher Cameronbe7ecea2018-02-27 00:47:191775 UpdateWebViewWithDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331776}
1777
Vladimir Levin98d76dad2018-04-21 00:21:291778void RenderWidget::UpdateCaptureSequenceNumber(
1779 uint32_t capture_sequence_number) {
1780 if (capture_sequence_number == last_capture_sequence_number_)
1781 return;
1782 last_capture_sequence_number_ = capture_sequence_number;
1783
1784 // Notify observers of the new capture sequence number.
1785 for (auto& observer : render_frame_proxies_)
1786 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
1787 for (auto& observer : browser_plugins_)
1788 observer.UpdateCaptureSequenceNumber(capture_sequence_number);
1789}
1790
[email protected]4873c7d2009-07-16 06:36:281791void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
EhsanK955ba582017-11-30 21:14:401792 if (auto* frame = GetFocusedWebLocalFrameInWidget())
1793 frame->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111794}
1795
[email protected]80ad8622012-11-07 16:33:031796void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1797 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511798 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391799 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1800 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511801 } else {
mfomitchev2600fd7c2016-02-17 20:53:391802 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511803 }
[email protected]80ad8622012-11-07 16:33:031804 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1805}
1806
lfgdb5c4ed2016-03-04 23:09:071807void RenderWidget::OnUpdateWindowScreenRect(
1808 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211809 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071810 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211811 else
lfgdb5c4ed2016-03-04 23:09:071812 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071813}
1814
kenrbea731792017-01-13 15:10:481815void RenderWidget::OnSetViewportIntersection(
Ken Buchananb2c9e262018-03-10 16:53:311816 const gfx::Rect& viewport_intersection,
1817 const gfx::Rect& compositor_visible_rect) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251818 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121819 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ken Buchananb2c9e262018-03-10 16:53:311820 compositor_visible_rect_ = compositor_visible_rect;
Ehsan Karamadf3ca2a82018-01-20 01:05:251821 frame_widget->SetRemoteViewportIntersection(viewport_intersection);
Ken Buchananb2c9e262018-03-10 16:53:311822 compositor_->SetViewportVisibleRect(ViewportVisibleRect());
kenrbea731792017-01-13 15:10:481823 }
1824}
1825
kenrb04323782017-06-23 01:23:321826void RenderWidget::OnSetIsInert(bool inert) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251827 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121828 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:251829 frame_widget->SetIsInert(inert);
kenrb04323782017-06-23 01:23:321830 }
1831}
1832
Ken Buchanan8a319fb2017-11-15 18:37:121833void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled,
1834 bool subtree_throttled) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251835 if (auto* frame_widget = GetFrameWidget()) {
Ken Buchanan8a319fb2017-11-15 18:37:121836 DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone);
Ehsan Karamadf3ca2a82018-01-20 01:05:251837 frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled);
Ken Buchanan8a319fb2017-11-15 18:37:121838 }
1839}
1840
paulmeyer90f6c31d2016-11-12 00:17:591841void RenderWidget::OnDragTargetDragEnter(
1842 const std::vector<DropData::Metadata>& drop_meta_data,
Ella Ge80a52dce2017-11-15 18:01:521843 const gfx::PointF& client_point,
1844 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591845 WebDragOperationsMask ops,
1846 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251847 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1848 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591849 return;
1850
Ehsan Karamadf3ca2a82018-01-20 01:05:251851 WebDragOperation operation = frame_widget->DragTargetDragEnter(
1852 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point,
1853 ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591854
1855 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1856}
1857
Ella Ge80a52dce2017-11-15 18:01:521858void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point,
1859 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591860 WebDragOperationsMask ops,
1861 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251862 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1863 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591864 return;
1865
Ehsan Karamadf3ca2a82018-01-20 01:05:251866 WebDragOperation operation = frame_widget->DragTargetDragOver(
1867 ConvertWindowPointToViewport(client_point), screen_point, ops,
1868 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591869
1870 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1871}
1872
Ella Ge80a52dce2017-11-15 18:01:521873void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point,
1874 const gfx::PointF& screen_point) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251875 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1876 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591877 return;
Ehsan Karamadf3ca2a82018-01-20 01:05:251878
1879 frame_widget
1880
Blink Reformat1c4d759e2017-04-09 16:34:541881 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171882 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591883}
1884
1885void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
Ella Ge80a52dce2017-11-15 18:01:521886 const gfx::PointF& client_point,
1887 const gfx::PointF& screen_point,
paulmeyer90f6c31d2016-11-12 00:17:591888 int key_modifiers) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251889 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1890 if (!frame_widget)
paulmeyer90f6c31d2016-11-12 00:17:591891 return;
1892
Ehsan Karamadf3ca2a82018-01-20 01:05:251893 frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data),
1894 ConvertWindowPointToViewport(client_point),
1895 screen_point, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591896}
1897
Ella Ge80a52dce2017-11-15 18:01:521898void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point,
1899 const gfx::PointF& screen_point,
paulmeyer8fc8ea92016-11-15 05:12:211900 WebDragOperation op) {
Ehsan Karamadf3ca2a82018-01-20 01:05:251901 blink::WebFrameWidget* frame_widget = GetFrameWidget();
1902 if (!frame_widget)
paulmeyer8fc8ea92016-11-15 05:12:211903 return;
1904
Ehsan Karamadf3ca2a82018-01-20 01:05:251905 frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
1906 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:211907}
1908
1909void RenderWidget::OnDragSourceSystemDragEnded() {
1910 if (!GetWebWidget())
1911 return;
1912
Blink Reformat1c4d759e2017-04-09 16:34:541913 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:211914}
1915
Blink Reformat1c4d759e2017-04-09 16:34:541916void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261917#if defined(OS_CHROMEOS)
1918 // On ChromeOS, virtual keyboard is triggered only when users leave the
1919 // mouse button or the finger and a text input element is focused at that
1920 // time. Focus event itself shouldn't trigger virtual keyboard.
1921 UpdateTextInputState();
1922#else
changwan75e3b2072017-01-16 02:55:001923 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261924#endif
boliu7b2be2f2016-11-04 04:58:311925
1926// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1927// virtual keyboard.
1928#if !defined(OS_ANDROID)
1929 FocusChangeComplete();
1930#endif
[email protected]0d1ebed12013-08-05 22:01:131931}
1932
fsamuel72464894f2015-12-15 06:59:311933ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161934#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491935 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
1936 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:091937#endif
ekaramad5aff1942017-01-06 01:26:351938 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541939 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:311940 return ui::TEXT_INPUT_TYPE_NONE;
1941}
1942
nonafa291792016-08-10 02:36:181943void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1944 if (!monitor_composition_info_ && !immediate_request)
1945 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591946
nonafa291792016-08-10 02:36:181947 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1948 gfx::Range range;
1949 std::vector<gfx::Rect> character_bounds;
1950
1951 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1952 // Composition information is only available on editable node.
1953 range = gfx::Range::InvalidRange();
1954 } else {
1955 GetCompositionRange(&range);
1956 GetCompositionCharacterBounds(&character_bounds);
1957 }
1958
1959 if (!immediate_request &&
1960 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311961 return;
nonafa291792016-08-10 02:36:181962 }
fsamuel72464894f2015-12-15 06:59:311963 composition_character_bounds_ = character_bounds;
1964 composition_range_ = range;
Dave Tapuska04bc5ee92018-04-17 19:03:311965 if (mojom::WidgetInputHandlerHost* host =
1966 widget_input_handler_manager_->GetWidgetInputHandlerHost()) {
1967 host->ImeCompositionRangeChanged(composition_range_,
1968 composition_character_bounds_);
Dave Tapuska139a72f2017-09-06 21:57:031969 }
fsamuel72464894f2015-12-15 06:59:311970}
1971
Blink Reformat1c4d759e2017-04-09 16:34:541972void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:541973 if (IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031974 float reverse = 1 / GetOriginalScreenInfo().device_scale_factor;
oshimad5279032015-12-16 18:22:331975 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541976 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461977 gfx::Rect window_rect =
1978 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1979 rect->x = window_rect.x();
1980 rect->y = window_rect.y();
1981 rect->width = window_rect.width();
1982 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541983 }
1984}
1985
Blink Reformat1c4d759e2017-04-09 16:34:541986void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:301987 if (IsUseZoomForDSFEnabled()) {
Fady Samuela863f152018-03-09 16:10:031988 rect->x *= GetOriginalScreenInfo().device_scale_factor;
1989 rect->y *= GetOriginalScreenInfo().device_scale_factor;
1990 rect->width *= GetOriginalScreenInfo().device_scale_factor;
1991 rect->height *= GetOriginalScreenInfo().device_scale_factor;
oshimaa6985b62016-01-27 08:58:301992 }
1993}
1994
changwan8c342742016-02-26 00:53:391995void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:261996#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:391997 DCHECK(!ime_event_guard_);
1998 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:001999 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:212000#endif
Dave Tapuska9db80842017-07-24 17:24:262001}
[email protected]105dffb42013-02-20 03:46:212002
ekaramadc9b70a72017-03-23 16:14:232003void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
2004 bool monitor_updates) {
2005 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:182006 if (!immediate_request)
2007 return;
2008 UpdateCompositionInfo(true /* immediate request */);
2009}
2010
[email protected]fcdc5642014-05-09 14:32:242011void RenderWidget::OnOrientationChange() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382012 if (auto* frame_widget = GetFrameWidget()) {
Alex Moshchuk0b409c42017-09-13 02:09:002013 // LocalRoot() might return null for provisional main frames. In this case,
2014 // the frame hasn't committed a navigation and is not swapped into the tree
2015 // yet, so it doesn't make sense to send orientation change events to it.
2016 //
2017 // TODO(https://crbug.com/578349): This check should be cleaned up
2018 // once provisional frames are gone.
Ehsan Karamad655d7b8a2018-01-12 18:38:382019 if (frame_widget->LocalRoot())
2020 frame_widget->LocalRoot()->SendOrientationChangeEvent();
lfg8d649cc2017-04-28 18:04:302021 }
[email protected]fcdc5642014-05-09 14:32:242022}
2023
[email protected]bee16aab2009-08-26 15:55:032024void RenderWidget::SetHidden(bool hidden) {
2025 if (is_hidden_ == hidden)
2026 return;
2027
jdduke8fac9d102014-12-20 02:40:132028 // The status has changed. Tell the RenderThread about it and ensure
2029 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032030 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132031
Scott Violet1098538e2017-10-05 19:23:332032#if defined(USE_AURA)
James Cook486d9642018-05-08 17:44:212033 if (features::IsMashEnabled())
Scott Violet1098538e2017-10-05 19:23:332034 RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden);
2035#endif
2036
Saman Sami58ed4392018-01-31 20:54:192037 // RenderThreadImpl::current() could be null in tests.
2038 if (RenderThreadImpl::current()) {
2039 if (is_hidden_) {
2040 RenderThreadImpl::current()->WidgetHidden();
2041 first_update_visual_state_after_hidden_ = true;
2042 } else {
2043 RenderThreadImpl::current()->WidgetRestored();
2044 }
Lei Zhang9b359d32017-11-28 00:57:022045 }
alexclarke7fa93942015-10-21 15:37:112046
2047 if (render_widget_scheduling_state_)
2048 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032049}
2050
[email protected]2b624c562011-10-27 22:58:262051void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212052 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262053 return;
2054
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122055 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542056 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262057 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542058 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262059 }
[email protected]2b624c562011-10-27 22:58:262060}
2061
changwanf2a707b2015-10-30 08:22:162062void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2063 if (!ime_event_guard_)
2064 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292065}
2066
changwanf2a707b2015-10-30 08:22:162067void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2068 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002069 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162070 return;
2071 }
2072 ime_event_guard_ = nullptr;
2073
[email protected]66fca5bc2013-05-23 06:58:292074 // While handling an ime event, text input state and selection bounds updates
2075 // are ignored. These must explicitly be updated once finished handling the
2076 // ime event.
2077 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472078#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002079 if (guard->show_virtual_keyboard())
2080 ShowVirtualKeyboard();
2081 else
2082 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472083#endif
[email protected]66fca5bc2013-05-23 06:58:292084}
2085
[email protected]7c8873e2013-02-05 08:03:012086void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162087#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492088 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092089 // TODO(kinaba) http://crbug.com/101101
2090 // Current Pepper IME API does not handle selection bounds. So we simply
2091 // use the caret position as an empty range for now. It will be updated
2092 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492093 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542094 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092095 *focus = caret;
2096 *anchor = caret;
2097 return;
2098 }
2099#endif
[email protected]7c8873e2013-02-05 08:03:012100 WebRect focus_webrect;
2101 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542102 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2103 ConvertViewportToWindow(&focus_webrect);
2104 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242105 *focus = focus_webrect;
2106 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322107}
2108
[email protected]e99ef6f2011-10-16 01:13:002109void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082110 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212111 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002112 return;
changwanf2a707b2015-10-30 08:22:162113 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292114 return;
[email protected]e99ef6f2011-10-16 01:13:002115
mohsenb0eeba72015-08-09 06:20:082116#if defined(USE_AURA)
2117 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2118 // Aura beucause composited selection updates are not working for webview tags
2119 // which regresses IME inside webview. Remove this when composited selection
2120 // updates are fixed for webviews. See, http://crbug.com/510568.
2121 bool send_ipc = true;
2122#else
jddukeacf809e2014-09-23 20:38:382123 // With composited selection updates, the selection bounds will be reported
2124 // directly by the compositor, in which case explicit IPC selection
2125 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082126 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542127 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082128#endif
2129 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382130 ViewHostMsg_SelectionBounds_Params params;
EhsanK955ba582017-11-30 21:14:402131 params.is_anchor_first = false;
jddukeacf809e2014-09-23 20:38:382132 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2133 if (selection_anchor_rect_ != params.anchor_rect ||
2134 selection_focus_rect_ != params.focus_rect) {
2135 selection_anchor_rect_ = params.anchor_rect;
2136 selection_focus_rect_ = params.focus_rect;
EhsanK955ba582017-11-30 21:14:402137 if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) {
2138 focused_frame->SelectionTextDirection(params.focus_dir,
2139 params.anchor_dir);
2140 params.is_anchor_first = focused_frame->IsSelectionAnchorFirst();
2141 }
jddukeacf809e2014-09-23 20:38:382142 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2143 }
[email protected]58b48a0d2012-06-13 07:01:352144 }
jddukeacf809e2014-09-23 20:38:382145
nonafa291792016-08-10 02:36:182146 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002147}
2148
lfgb00fcad2016-07-14 14:16:332149void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2150 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542151 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332152 if (size_.width() != new_size_in_window.width ||
2153 size_.height() != new_size_in_window.height) {
2154 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2155
2156 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542157 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2158 size_.height());
lfgb00fcad2016-07-14 14:16:332159 view_screen_rect_ = new_pos;
2160 window_screen_rect_ = new_pos;
2161 }
2162
Christopher Camerone9a30c12018-03-07 08:23:382163 // TODO(ccameron): Note that this destroys any information differentiating
Christopher Cameronaad15a0d2018-03-09 03:47:332164 // |size_| from |compositor_viewport_pixel_size_|. Also note that the
2165 // calculation of |new_compositor_viewport_pixel_size| does not appear to
2166 // take into account device emulation.
Fady Samuel4392abb2018-05-10 21:01:212167 if (compositor_)
2168 compositor_->RequestNewLocalSurfaceId();
Christopher Cameronaad15a0d2018-03-09 03:47:332169 gfx::Size new_compositor_viewport_pixel_size =
Fady Samuela863f152018-03-09 16:10:032170 gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor);
Fady Samuel4392abb2018-05-10 21:01:212171 UpdateSurfaceAndScreenInfo(
2172 local_surface_id_, new_compositor_viewport_pixel_size, screen_info_);
lfgb00fcad2016-07-14 14:16:332173 }
2174}
2175
[email protected]58b48a0d2012-06-13 07:01:352176void RenderWidget::GetCompositionCharacterBounds(
2177 std::vector<gfx::Rect>* bounds) {
2178 DCHECK(bounds);
2179 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092180
brettw4b461082016-11-19 18:55:162181#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492182 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092183 return;
2184#endif
2185
Ehsan Karamad4975af6d2018-02-09 16:58:162186 blink::WebInputMethodController* controller = GetInputMethodController();
2187 if (!controller)
ekaramad2a46d632016-07-19 13:33:092188 return;
2189 blink::WebVector<blink::WebRect> bounds_from_blink;
Ehsan Karamad4975af6d2018-02-09 16:58:162190 if (!controller->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092191 return;
2192
2193 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542194 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092195 bounds->push_back(bounds_from_blink[i]);
2196 }
[email protected]58b48a0d2012-06-13 07:01:352197}
2198
[email protected]db4fc1e2013-09-06 20:01:512199void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162200#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492201 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092202 return;
2203#endif
EhsanKcdee7b72017-11-08 21:30:092204 blink::WebInputMethodController* controller = GetInputMethodController();
2205 WebRange web_range = controller ? controller->CompositionRange() : WebRange();
Blink Reformat1c4d759e2017-04-09 16:34:542206 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212207 *range = gfx::Range::InvalidRange();
2208 return;
[email protected]88dbe32f2013-06-20 23:31:362209 }
Blink Reformat1c4d759e2017-04-09 16:34:542210 range->set_start(web_range.StartOffset());
2211 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362212}
2213
[email protected]501ea13d2013-07-09 17:03:292214bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512215 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292216 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082217 if (!range.IsValid())
2218 return false;
[email protected]501ea13d2013-07-09 17:03:292219 if (composition_range_ != range)
2220 return true;
2221 if (bounds.size() != composition_character_bounds_.size())
2222 return true;
2223 for (size_t i = 0; i < bounds.size(); ++i) {
2224 if (bounds[i] != composition_character_bounds_[i])
2225 return true;
2226 }
2227 return false;
2228}
[email protected]501ea13d2013-07-09 17:03:292229
[email protected]ad26ef42011-06-17 07:59:452230bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162231#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492232 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2233 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092234#endif
[email protected]ad26ef42011-06-17 07:59:452235 return true;
[email protected]56ea1a62011-05-30 07:05:572236}
2237
Blink Reformat1c4d759e2017-04-09 16:34:542238blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272239 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542240 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542241 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272242 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542243 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2244 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272245 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542246 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272247 switch (screen_info_.orientation_type) {
2248 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542249 web_screen_info.orientation_type =
2250 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272251 break;
2252 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542253 web_screen_info.orientation_type =
2254 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272255 break;
2256 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542257 web_screen_info.orientation_type =
2258 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272259 break;
2260 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542261 web_screen_info.orientation_type =
2262 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272263 break;
2264 default:
Blink Reformat1c4d759e2017-04-09 16:34:542265 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272266 break;
2267 }
Blink Reformat1c4d759e2017-04-09 16:34:542268 web_screen_info.orientation_angle = screen_info_.orientation_angle;
Fady Samuel85a1bf72017-10-27 14:30:202269
ccameron2f451532016-09-07 21:49:272270 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282271}
2272
Blink Reformat1c4d759e2017-04-09 16:34:542273void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2274 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022275#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562276 if (event_cancelled)
2277 return;
Blink Reformat1c4d759e2017-04-09 16:34:542278 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002279 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542280 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212281 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352282 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542283 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002284 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462285 else
changwan75e3b2072017-01-16 02:55:002286 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562287 }
ekaramada110f642016-12-21 19:47:282288// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2289// crbug/420130.
2290#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542291 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282292 return;
2293
2294 // TODO(estade): hit test the event against focused node to make sure
2295 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352296 blink::WebInputMethodController* controller = GetInputMethodController();
2297 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542298 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282299
2300 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542301 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282302#endif
[email protected]c68c3e4e2013-01-24 00:36:562303#endif
2304}
2305
Blink Reformat1c4d759e2017-04-09 16:34:542306void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312307 const blink::WebFloatSize& overscrollDelta,
2308 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422309 const blink::WebFloatPoint& position,
sunyunjiabbea8a92017-08-31 11:18:542310 const blink::WebFloatSize& velocity,
danakje819b622018-05-01 20:27:142311 const cc::OverscrollBehavior& behavior) {
bokan731ec382016-04-07 03:16:482312#if defined(OS_MACOSX)
2313 // On OSX the user can disable the elastic overscroll effect. If that's the
2314 // case, don't forward the overscroll notification.
2315 DCHECK(compositor_deps());
2316 if (!compositor_deps()->IsElasticOverscrollEnabled())
2317 return;
2318#endif
bokane53a10f2016-04-13 23:48:312319 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
sunyunjiabbea8a92017-08-31 11:18:542320 position, velocity, behavior);
sataya.m582c9ce2015-06-09 08:03:422321}
2322
[email protected]7912e822014-04-16 02:37:032323void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392324 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542325 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032326}
2327
[email protected]24ed0432013-04-24 07:50:312328RenderWidgetCompositor* RenderWidget::compositor() const {
2329 return compositor_.get();
2330}
2331
fsamuel72464894f2015-12-15 06:59:312332void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392333 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372334}
[email protected]c3d45532011-10-07 19:20:402335
Blink Reformat1c4d759e2017-04-09 16:34:542336void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
W. James MacLean662d5382018-03-29 18:33:082337 if (has_touch_handlers_ && *has_touch_handlers_ == has_handlers)
2338 return;
2339
2340 has_touch_handlers_ = has_handlers;
alexclarke7fa93942015-10-21 15:37:112341 if (render_widget_scheduling_state_)
2342 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552343 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2344}
2345
Dave Tapuskadfe486c12017-06-09 16:53:132346void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2347 if (input_event_queue_)
2348 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2349}
2350
Dave Tapuskabafc2ba32017-11-28 01:54:372351void RenderWidget::RequestUnbufferedInputEvents() {
2352 if (input_event_queue_)
2353 input_event_queue_->RequestUnbufferedInputEvents();
2354}
2355
xidachenfa0199e72017-05-11 11:34:262356void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
Dave Tapuskab28a1082017-08-30 15:37:262357 if (!input_handler_->ProcessTouchAction(touch_action))
[email protected]5d0bbdfa92013-12-10 00:35:512358 return;
2359
Dave Tapuska04bc5ee92018-04-17 19:03:312360 widget_input_handler_manager_->ProcessTouchAction(touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512361}
2362
[email protected]e3244ed2014-06-20 20:04:272363void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2364 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162365}
2366
[email protected]e3244ed2014-06-20 20:04:272367void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2368 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162369}
2370
[email protected]de3c5d82014-05-28 22:12:592371void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2372 render_frames_.AddObserver(frame);
2373}
2374
2375void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2376 render_frames_.RemoveObserver(frame);
2377}
2378
Saman Samid189e5dfd2017-12-20 22:55:312379void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2380 browser_plugins_.AddObserver(browser_plugin);
Saman Sami50d1e0c2018-03-13 20:03:492381 browser_plugin->ScreenInfoChanged(GetOriginalScreenInfo());
Saman Samid189e5dfd2017-12-20 22:55:312382}
2383
2384void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) {
2385 browser_plugins_.RemoveObserver(browser_plugin);
2386}
2387
lfg43e08e62016-02-03 18:51:372388void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2389 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2390 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2391}
2392
Fady Samuela863f152018-03-09 16:10:032393const ScreenInfo& RenderWidget::GetWebScreenInfo() const {
2394 return screen_info_;
Christopher Camerone9a30c12018-03-07 08:23:382395}
2396
Fady Samuela863f152018-03-09 16:10:032397const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const {
Christopher Camerone9a30c12018-03-07 08:23:382398 return screen_metrics_emulator_
2399 ? screen_metrics_emulator_->original_screen_info()
Fady Samuela863f152018-03-09 16:10:032400 : screen_info_;
oshima50872a72016-03-04 13:26:182401}
2402
Ella Ge80a52dce2017-11-15 18:01:522403gfx::PointF RenderWidget::ConvertWindowPointToViewport(
2404 const gfx::PointF& point) {
paulmeyer90f6c31d2016-11-12 00:17:592405 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542406 ConvertWindowToViewport(&point_in_viewport);
Ella Ge80a52dce2017-11-15 18:01:522407 return gfx::PointF(point_in_viewport.x, point_in_viewport.y);
2408}
2409
2410gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) {
2411 return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point)));
paulmeyer90f6c31d2016-11-12 00:17:592412}
2413
Blink Reformat1c4d759e2017-04-09 16:34:542414bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212415 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2416}
2417
Blink Reformat1c4d759e2017-04-09 16:34:542418void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212419 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2420}
2421
Blink Reformat1c4d759e2017-04-09 16:34:542422bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212423 return mouse_lock_dispatcher_->IsMouseLockedTo(
2424 webwidget_mouse_lock_target_.get());
2425}
2426
Blink Reformat1c4d759e2017-04-09 16:34:542427void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582428 const WebDragData& data,
2429 WebDragOperationsMask mask,
2430 const WebImage& image,
2431 const WebPoint& webImageOffset) {
2432 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542433 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582434 DropData drop_data(DropDataBuilder::Build(data));
2435 drop_data.referrer_policy = policy;
2436 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592437 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542438 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582439 possible_drag_event_info_));
2440}
2441
kenrb5d78b842017-03-06 21:06:012442uint32_t RenderWidget::GetContentSourceId() {
2443 return current_content_source_id_;
2444}
2445
Saman Samif7731342018-01-24 22:18:442446void RenderWidget::DidNavigate() {
Saman Sami26a1fcd2018-04-10 17:12:212447 ++current_content_source_id_;
Saman Samif7731342018-01-24 22:18:442448 if (!compositor_)
2449 return;
Saman Sami26a1fcd2018-04-10 17:12:212450 compositor_->SetContentSourceId(current_content_source_id_);
Christopher Cameronbe7ecea2018-02-27 00:47:192451
Fady Samueleeab73952018-05-08 03:00:002452 // When surface synchronization is off, an invalid viz::LcoalSurfaceId does
2453 // not defer commit. Thus, the invalid ID will be plumbed all the way to draw
2454 // time. If a valid viz::LocalSurfaceId is sandwiched by two invalid ones,
2455 // then the valid viz::LocalSurfaceId may never makes its way into the
2456 // RenderFrameMetadata and be used by the browser. This can cause hangs in
2457 // certain cases. Thus, we avoid pushing an invalid viz::LocalSurfaceId
2458 // to cc.
2459 if (IsSurfaceSynchronizationEnabled()) {
2460 UpdateSurfaceAndScreenInfo(viz::LocalSurfaceId(),
2461 compositor_viewport_pixel_size_, screen_info_);
2462 }
kenrb5d78b842017-03-06 21:06:012463}
2464
lfg8ff33912016-09-13 20:59:212465blink::WebWidget* RenderWidget::GetWebWidget() const {
2466 return webwidget_internal_;
2467}
2468
ekaramad2daaf672016-11-10 20:29:012469blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2470 const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382471 if (auto* frame_widget = GetFrameWidget())
2472 return frame_widget->GetActiveWebInputMethodController();
2473
2474 return nullptr;
ekaramad2daaf672016-11-10 20:29:012475}
2476
Dave Tapuska139a72f2017-09-06 21:57:032477void RenderWidget::SetupWidgetInputHandler(
2478 mojom::WidgetInputHandlerRequest request,
2479 mojom::WidgetInputHandlerHostPtr host) {
Dave Tapuskab66c28f2017-11-15 17:18:472480 widget_input_handler_manager_->AddInterface(std::move(request),
2481 std::move(host));
Dave Tapuska525eb15e2017-08-17 21:05:502482}
2483
Dave Tapuska485aca92017-08-08 00:47:582484void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2485 // Close the old binding if there was one.
2486 // A RenderWidgetHost should not need more than one channel.
2487 widget_binding_.Close();
2488 widget_binding_.Bind(std::move(request));
2489}
2490
Fady Samuelca9ecb72018-05-05 05:59:272491bool RenderWidget::IsSurfaceSynchronizationEnabled() const {
2492 return compositor_ && compositor_->IsSurfaceSynchronizationEnabled();
2493}
2494
Khushal3e96e662017-10-30 23:16:502495void RenderWidget::UpdateURLForCompositorUkm() {
2496 DCHECK(compositor_);
Ehsan Karamad655d7b8a2018-01-12 18:38:382497 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2498 if (!frame_widget)
Khushal3e96e662017-10-30 23:16:502499 return;
2500
Ehsan Karamad655d7b8a2018-01-12 18:38:382501 auto* render_frame = RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot());
Khushal3e96e662017-10-30 23:16:502502 if (!render_frame->IsMainFrame())
2503 return;
2504
2505 compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url());
2506}
2507
EhsanK955ba582017-11-30 21:14:402508blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
Ehsan Karamad655d7b8a2018-01-12 18:38:382509 if (auto* frame_widget = GetFrameWidget())
2510 return frame_widget->FocusedWebLocalFrameInWidget();
2511 return nullptr;
EhsanK955ba582017-11-30 21:14:402512}
2513
EhsanK22d482e2017-08-10 17:29:492514#if BUILDFLAG(ENABLE_PLUGINS)
2515PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
Ehsan Karamad655d7b8a2018-01-12 18:38:382516 blink::WebFrameWidget* frame_widget = GetFrameWidget();
2517 if (!frame_widget)
EhsanK22d482e2017-08-10 17:29:492518 return nullptr;
2519
2520 // Focused pepper instance might not always be in the focused frame. For
2521 // instance if a pepper instance and its embedder frame are focused an then
2522 // another frame takes focus using javascript, the embedder frame will no
2523 // longer be focused while the pepper instance is (the embedder frame's
2524 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2525 // is fullscreen, clicking into the pepper will not refocus the embedder
2526 // frame. This is why we have to traverse the whole frame tree to find the
2527 // focused plugin.
Ehsan Karamad655d7b8a2018-01-12 18:38:382528 blink::WebFrame* current_frame = frame_widget->LocalRoot();
EhsanK22d482e2017-08-10 17:29:492529 while (current_frame) {
2530 RenderFrameImpl* render_frame =
2531 current_frame->IsWebLocalFrame()
2532 ? RenderFrameImpl::FromWebFrame(current_frame)
2533 : nullptr;
2534 if (render_frame && render_frame->focused_pepper_plugin())
2535 return render_frame->focused_pepper_plugin();
2536 current_frame = current_frame->TraverseNext();
2537 }
2538 return nullptr;
2539}
2540#endif
2541
Ken Buchananb2c9e262018-03-10 16:53:312542gfx::Rect RenderWidget::ViewportVisibleRect() {
2543 return for_oopif_ ? compositor_visible_rect_
2544 : gfx::Rect(compositor_viewport_pixel_size_);
2545}
2546
Saman Sami50d1e0c2018-03-13 20:03:492547base::WeakPtr<RenderWidget> RenderWidget::AsWeakPtr() {
2548 return weak_ptr_factory_.GetWeakPtr();
2549}
2550
[email protected]e9ff79c2012-10-19 21:31:262551} // namespace content