blob: 8cc8e864faf316b0238e3badf395dc5f8adbd956 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4319#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
fdoraya19b7702016-12-23 14:19:3123#include "base/threading/thread_task_runner_handle.h"
primiano9e38d552015-01-28 04:18:0124#include "base/trace_event/trace_event.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0326#include "cc/animation/animation_host.h"
xidachenfa0199e72017-05-11 11:34:2627#include "cc/input/touch_action.h"
jbroman6ccbc7d472016-07-27 04:45:4128#include "cc/output/copy_output_request.h"
danakjc7afae52017-06-20 21:12:4129#include "cc/output/layer_tree_frame_sink.h"
fsamuel78f86e42016-01-20 04:10:2330#include "cc/scheduler/begin_frame_source.h"
loyso6e6efc42017-01-21 02:23:0331#include "cc/trees/layer_tree_host.h"
oshima750cb4342015-10-31 00:59:0132#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5833#include "content/common/drag_event_source_info.h"
34#include "content/common/drag_messages.h"
[email protected]9017d7852013-11-21 17:47:3535#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1536#include "content/common/input_messages.h"
jcivelliae1560a2016-11-01 22:40:2337#include "content/common/render_message_filter.mojom.h"
[email protected]992db4c2011-05-12 15:37:1538#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3839#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5040#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1841#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1242#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4244#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5945#include "content/public/common/drop_data.h"
mlamouriafca06dd2017-01-27 23:35:1846#include "content/public/renderer/content_renderer_client.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"
[email protected]7a72d452013-12-13 10:01:1355#include "content/renderer/input/input_handler_manager.h"
dtapuska9ec1a912017-04-21 15:18:3156#include "content/renderer/input/main_thread_event_queue.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"
brettw4b461082016-11-19 18:55:1668#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4869#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2570#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1871#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5972#include "third_party/WebKit/public/platform/WebDragData.h"
73#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5574#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1175#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3076#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3077#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3078#include "third_party/WebKit/public/platform/WebSize.h"
79#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5180#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
81#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2982#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4383#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5984#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0185#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5986#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1187#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3188#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3189#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
90#include "third_party/WebKit/public/web/WebRange.h"
kenrba7199832015-01-22 23:44:5991#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0892#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4193#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5994#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:1395#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:4396#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:5097#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0998#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3299#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48100#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27101#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41102#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48103
[email protected]eeb93112013-05-01 19:41:10104#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15105#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24106#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10107#endif
108
[email protected]661eb9d2009-02-03 02:11:48109#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52110#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41111#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48112#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44113
sadrul943e3b32016-08-04 18:22:59114#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10115#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19116#endif
117
ekaramad330ba4232016-09-23 17:57:47118#if defined(OS_MACOSX)
119#include "content/renderer/text_input_client_observer.h"
120#endif
121
[email protected]180ef242013-11-07 06:50:46122using blink::WebCompositionUnderline;
123using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43124using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59125using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58126using blink::WebDragOperationsMask;
127using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59128using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46129using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58130using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46131using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49132using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01133using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58134using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46135using blink::WebMouseEvent;
136using blink::WebMouseWheelEvent;
137using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11138using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46139using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11140using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46141using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48142using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46143using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46144using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59145using blink::WebString;
[email protected]180ef242013-11-07 06:50:46146using blink::WebTextDirection;
147using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25148using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46149using blink::WebVector;
150using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26151
paulmeyer90f6c31d2016-11-12 00:17:59152namespace content {
153
[email protected]6a4d7f62013-01-07 21:32:13154namespace {
[email protected]b256eca2013-07-11 10:57:40155
156typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
157
lfgbee1e0a2016-06-08 21:24:21158class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
159 public:
160 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
161 : webwidget_(webwidget) {}
162
163 void OnLockMouseACK(bool succeeded) override {
164 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54165 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21166 else
Blink Reformat1c4d759e2017-04-09 16:34:54167 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21168 }
169
Blink Reformat1c4d759e2017-04-09 16:34:54170 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21171
172 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
173 // The WebWidget handles mouse lock in Blink's handleInputEvent().
174 return false;
175 }
176
177 private:
178 blink::WebWidget* webwidget_;
179};
180
dglazkov97b6c2b2016-10-25 17:35:55181bool IsDateTimeInput(ui::TextInputType type) {
182 return type == ui::TEXT_INPUT_TYPE_DATE ||
183 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
184 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
185 type == ui::TEXT_INPUT_TYPE_MONTH ||
186 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
187}
188
paulmeyer90f6c31d2016-11-12 00:17:59189WebDragData DropMetaDataToWebDragData(
190 const std::vector<DropData::Metadata>& drop_meta_data) {
191 std::vector<WebDragData::Item> item_list;
192 for (const auto& meta_data_item : drop_meta_data) {
193 if (meta_data_item.kind == DropData::Kind::STRING) {
194 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54195 item.storage_type = WebDragData::Item::kStorageTypeString;
196 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59197 // Have to pass a dummy URL here instead of an empty URL because the
198 // DropData received by browser_plugins goes through a round trip:
199 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
200 // will contain an empty URL (which means no URL is dragged) if the URL in
201 // WebDragData is empty.
202 if (base::EqualsASCII(meta_data_item.mime_type,
203 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54204 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59205 }
206 item_list.push_back(item);
207 continue;
208 }
209
210 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
211 // just the mimetype. This is needed to drag files to WebView on Android
212 // platform.
213 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
214 !meta_data_item.filename.empty()) {
215 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54216 item.storage_type = WebDragData::Item::kStorageTypeFilename;
217 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59218 item_list.push_back(item);
219 continue;
220 }
221
222 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
223 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54224 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
225 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59226 item_list.push_back(item);
227 continue;
228 }
229 }
230
231 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54232 result.Initialize();
233 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59234 return result;
235}
236
237WebDragData DropDataToWebDragData(const DropData& drop_data) {
238 std::vector<WebDragData::Item> item_list;
239
240 // These fields are currently unused when dragging into WebKit.
241 DCHECK(drop_data.download_metadata.empty());
242 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23243 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59244
245 if (!drop_data.text.is_null()) {
246 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54247 item.storage_type = WebDragData::Item::kStorageTypeString;
248 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
249 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59250 item_list.push_back(item);
251 }
252
253 if (!drop_data.url.is_empty()) {
254 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54255 item.storage_type = WebDragData::Item::kStorageTypeString;
256 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
257 item.string_data = WebString::FromUTF8(drop_data.url.spec());
258 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59259 item_list.push_back(item);
260 }
261
262 if (!drop_data.html.is_null()) {
263 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54264 item.storage_type = WebDragData::Item::kStorageTypeString;
265 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
266 item.string_data = WebString::FromUTF16(drop_data.html.string());
267 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59268 item_list.push_back(item);
269 }
270
271 for (std::vector<ui::FileInfo>::const_iterator it =
272 drop_data.filenames.begin();
273 it != drop_data.filenames.end();
274 ++it) {
275 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54276 item.storage_type = WebDragData::Item::kStorageTypeFilename;
277 item.filename_data = blink::FilePathToWebString(it->path);
278 item.display_name_data =
kinukoa4293022017-01-27 06:43:25279 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59280 item_list.push_back(item);
281 }
282
283 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
284 drop_data.file_system_files.begin();
285 it != drop_data.file_system_files.end();
286 ++it) {
287 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54288 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
289 item.file_system_url = it->url;
290 item.file_system_file_size = it->size;
291 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59292 item_list.push_back(item);
293 }
294
295 for (std::map<base::string16, base::string16>::const_iterator it =
296 drop_data.custom_data.begin();
297 it != drop_data.custom_data.end();
298 ++it) {
299 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54300 item.storage_type = WebDragData::Item::kStorageTypeString;
301 item.string_type = WebString::FromUTF16(it->first);
302 item.string_data = WebString::FromUTF16(it->second);
paulmeyer90f6c31d2016-11-12 00:17:59303 item_list.push_back(item);
304 }
305
306 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54307 result.Initialize();
308 result.SetItems(item_list);
309 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59310 return result;
311}
312
lfg1568d112016-08-30 16:06:29313content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
314 nullptr;
315
316content::RenderWidget::RenderWidgetInitializedCallback
317 g_render_widget_initialized = nullptr;
318
dtapuskac4dd5be2016-10-25 15:11:10319ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
320 // Check the type is in the range representable by ui::TextInputType.
321 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
322 << "blink::WebTextInputType and ui::TextInputType not synchronized";
323 return static_cast<ui::TextInputType>(type);
324}
325
326ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
327 // Check the mode is in the range representable by ui::TextInputMode.
328 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
329 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
330 return static_cast<ui::TextInputMode>(mode);
331}
332
[email protected]b256eca2013-07-11 10:57:40333} // namespace
334
[email protected]b2e4c70132013-10-03 02:07:51335// RenderWidget ---------------------------------------------------------------
336
nick8331f8ad2016-11-15 20:42:45337RenderWidget::RenderWidget(int32_t widget_routing_id,
338 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36339 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27340 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04341 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03342 bool hidden,
Dave Tapuska1bdf1832017-07-07 18:07:19343 bool never_visible,
344 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45345 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36346 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21347 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44348 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29349 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51350 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09351 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29352 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04353 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39354 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12355 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54356 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16357 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48358 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22359 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44360 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20361 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55362 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40363 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20364 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53365 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18366 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12367 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48368 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04369 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27370 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18371 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51372 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12373 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42374 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08375 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24376 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09377 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47378#if defined(OS_MACOSX)
379 text_input_client_observer_(new TextInputClientObserver(this)),
380#endif
wjmaclean1d970622017-01-21 22:28:24381 focused_pepper_plugin_(nullptr),
tasakb95dbb50c2017-02-08 18:07:50382 time_to_first_active_paint_recorded_(true),
383 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01384 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19385 widget_binding_(this, std::move(widget_request)),
wjmaclean1d970622017-01-21 22:28:24386 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45387 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05388 if (!swapped_out)
389 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27390 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11391
392 // In tests there may not be a RenderThreadImpl.
393 if (RenderThreadImpl::current()) {
394 render_widget_scheduling_state_ = RenderThreadImpl::current()
395 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32396 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11397 render_widget_scheduling_state_->SetHidden(is_hidden_);
398 }
sadrul602ce1362017-01-26 06:41:10399#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14400 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
sadrul602ce1362017-01-26 06:41:10401#endif
initial.commit09911bf2008-07-26 23:55:29402}
403
404RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21405 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16406
dtapuska9ec1a912017-04-21 15:18:31407 if (input_event_queue_)
408 input_event_queue_->ClearClient();
409
[email protected]992db4c2011-05-12 15:37:15410 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02411 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15412 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11413#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14414 // It is possible for a RenderWidget to be destroyed before it was embedded
415 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
416 // explicitly delete it here.
417 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11418#endif
initial.commit09911bf2008-07-26 23:55:29419}
420
[email protected]484955942010-08-19 16:13:18421// static
lfg1568d112016-08-30 16:06:29422void RenderWidget::InstallCreateHook(
423 CreateRenderWidgetFunction create_render_widget,
424 RenderWidgetInitializedCallback render_widget_initialized) {
425 CHECK(!g_create_render_widget && !g_render_widget_initialized);
426 g_create_render_widget = create_render_widget;
427 g_render_widget_initialized = render_widget_initialized;
428}
429
430// static
nickf7b38222016-11-22 21:59:35431RenderWidget* RenderWidget::CreateForPopup(
432 RenderViewImpl* opener,
433 CompositorDependencies* compositor_deps,
434 blink::WebPopupType popup_type,
435 const ScreenInfo& screen_info) {
Dave Tapuska1bdf1832017-07-07 18:07:19436 mojom::WidgetPtr widget_channel;
437 mojom::WidgetRequest widget_channel_request =
438 mojo::MakeRequest(&widget_channel);
439
nick4df698d82016-11-11 20:39:23440 // Do a synchronous IPC to obtain a routing ID.
441 int32_t routing_id = MSG_ROUTING_NONE;
442 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19443 opener->GetRoutingID(), popup_type, std::move(widget_channel),
444 &routing_id)) {
nick4df698d82016-11-11 20:39:23445 return nullptr;
446 }
447
nick8331f8ad2016-11-15 20:42:45448 scoped_refptr<RenderWidget> widget(
449 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
Dave Tapuska1bdf1832017-07-07 18:07:19450 false, false, false, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35451 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24452 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35453 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23454 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
455 return widget.get();
initial.commit09911bf2008-07-26 23:55:29456}
457
[email protected]484955942010-08-19 16:13:18458// static
kenrba7199832015-01-22 23:44:59459RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23460 int widget_routing_id,
kenrba7199832015-01-22 23:44:59461 bool hidden,
ccameron2f451532016-09-07 21:49:27462 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59463 CompositorDependencies* compositor_deps,
464 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23465 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55466 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
467 // same routing ID for both the view routing ID and the main frame widget
468 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23469 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55470 if (view) {
avi8a45c1092016-03-01 16:12:34471 view->AttachWebFrameWidget(
472 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
473 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55474 }
dcheng35d31c112015-07-22 00:17:36475 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29476 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45477 ? g_create_render_widget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54478 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45479 hidden, false)
480 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54481 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45482 hidden, false));
simonhong628f9812015-04-27 23:13:20483 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23484 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59485 // this function returns.
nickf7b38222016-11-22 21:59:35486 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23487 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
488
489 if (g_render_widget_initialized)
490 g_render_widget_initialized(widget.get());
491 return widget.get();
kenrba7199832015-01-22 23:44:59492}
493
494// static
lfgcaab5142016-02-26 19:06:52495blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08496 RenderWidget* render_widget,
497 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54498 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08499}
500
501// static
kenrba7199832015-01-22 23:44:59502blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18503 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54504 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18505 break;
Blink Reformat1c4d759e2017-04-09 16:34:54506 case blink::kWebPopupTypePage:
507 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18508 default:
509 NOTREACHED();
510 }
511 return NULL;
512}
513
dchengda9b4bb2015-07-20 20:58:08514void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32515 OnClose();
kenrba7199832015-01-22 23:44:59516}
517
alexmos78c9c0d2016-10-14 18:57:03518void RenderWidget::SetSwappedOut(bool is_swapped_out) {
519 // We should only toggle between states.
520 DCHECK(is_swapped_out_ != is_swapped_out);
521 is_swapped_out_ = is_swapped_out;
522
523 // If we are swapping out, we will call ReleaseProcess, allowing the process
524 // to exit if all of its RenderViews are swapped out. We wait until the
525 // WasSwappedOut call to do this, to allow the unload handler to finish.
526 // If we are swapping in, we call AddRefProcess to prevent the process from
527 // exiting.
528 if (!is_swapped_out_)
529 RenderProcess::current()->AddRefProcess();
530}
531
nickf7b38222016-11-22 21:59:35532void RenderWidget::Init(const ShowCallback& show_callback,
533 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21534 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23535 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29536
sadrul9fe48922017-01-23 18:59:49537 input_handler_ = base::MakeUnique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45538
nickf7b38222016-11-22 21:59:35539 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29540
lfg8ff33912016-09-13 20:59:21541 webwidget_internal_ = web_widget;
542 webwidget_mouse_lock_target_.reset(
543 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21544 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29545
nick4df698d82016-11-11 20:39:23546 RenderThread::Get()->AddRoute(routing_id_, this);
547 // Take a reference on behalf of the RenderThread. This will be balanced
548 // when we receive ViewMsg_Close.
549 AddRef();
550 if (RenderThreadImpl::current()) {
551 RenderThreadImpl::current()->WidgetCreated();
552 if (is_hidden_)
553 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29554 }
555}
556
[email protected]949b6592014-08-20 13:17:52557void RenderWidget::WasSwappedOut() {
558 // If we have been swapped out and no one else is using this process,
559 // it's safe to exit now.
560 CHECK(is_swapped_out_);
561 RenderProcess::current()->ReleaseProcess();
562}
563
[email protected]b2e4c70132013-10-03 02:07:51564void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39565 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51566 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43567 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49568 popup_screen_origin_for_emulation_ = gfx::Point(
569 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
570 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56571 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27572 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51573}
574
[email protected]2d6836f42014-07-02 17:25:31575gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
576 if (screen_metrics_emulator_)
577 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
578 return anchor;
579}
580
thakis18e426412017-03-15 12:06:37581#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51582void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39583 ExternalPopupMenu* popup,
584 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49585 popup->SetOriginScaleAndOffsetForEmulation(
586 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51587}
[email protected]53907862014-03-25 15:42:40588#endif
[email protected]b2e4c70132013-10-03 02:07:51589
590void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
591 if (screen_metrics_emulator_)
592 screen_metrics_emulator_->OnShowContextMenu(params);
593}
594
[email protected]a95986a82010-12-24 06:19:28595bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47596#if defined(OS_MACOSX)
597 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
598 return text_input_client_observer_->OnMessageReceived(message);
599#endif
lfgbee1e0a2016-06-08 21:24:21600 if (mouse_lock_dispatcher_ &&
601 mouse_lock_dispatcher_->OnMessageReceived(message))
602 return true;
603
[email protected]a95986a82010-12-24 06:19:28604 bool handled = true;
605 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15606 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22607 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
608 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22609 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29610 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
611 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
612 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15613 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46614 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
615 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15616 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35617 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
618 OnSyntheticGestureCompleted)
wjmacleanee244e02017-05-26 21:06:07619 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28620 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28621 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20622 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
623 OnEnableDeviceEmulation)
624 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
625 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28626 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41627 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25628 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28629 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
630 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03631 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48632 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
633 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32634 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
lfg43e08e62016-02-03 18:51:37635 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
636 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23637 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
638 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59639 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
640 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
641 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
642 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21643 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
644 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
645 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21646#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39647 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
648 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21649#endif
[email protected]a95986a82010-12-24 06:19:28650 IPC_MESSAGE_UNHANDLED(handled = false)
651 IPC_END_MESSAGE_MAP()
652 return handled;
653}
initial.commit09911bf2008-07-26 23:55:29654
655bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15656 // Don't send any messages after the browser has told us to close, and filter
657 // most outgoing messages while swapped out.
658 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26659 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11660 closing_) {
initial.commit09911bf2008-07-26 23:55:29661 delete message;
662 return false;
663 }
664
665 // If given a messsage without a routing ID, then assign our routing ID.
666 if (message->routing_id() == MSG_ROUTING_NONE)
667 message->set_routing_id(routing_id_);
668
[email protected]380244092011-10-07 17:26:27669 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44670}
671
dtapuska014ed082016-11-11 21:58:48672void RenderWidget::SendOrCrash(IPC::Message* message) {
673 bool result = Send(message);
674 CHECK(closing_ || result) << "Failed to send message";
675}
676
ekaramad5aff1942017-01-06 01:26:35677bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26678 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
679 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
680 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
681 // will be processed regardless of page focus. We should revisit this after
682 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54683 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26684 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35685}
686
bokanc007c3a2015-02-03 07:15:56687void RenderWidget::SetWindowRectSynchronously(
688 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39689 ResizeParams params;
690 params.screen_info = screen_info_;
691 params.new_size = new_window_rect.size();
692 params.physical_backing_size =
693 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39694 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39695 params.is_fullscreen_granted = is_fullscreen_granted_;
696 params.display_mode = display_mode_;
697 params.needs_resize_ack = false;
698 Resize(params);
699
bokanc007c3a2015-02-03 07:15:56700 view_screen_rect_ = new_window_rect;
701 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02702 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56703 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02704}
705
initial.commit09911bf2008-07-26 23:55:29706void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32707 DCHECK(content::RenderThread::Get());
708 if (closing_)
709 return;
710 NotifyOnClose();
711 closing_ = true;
712
713 // Browser correspondence is no longer needed at this point.
714 if (routing_id_ != MSG_ROUTING_NONE) {
715 RenderThread::Get()->RemoveRoute(routing_id_);
716 SetHidden(false);
717 if (RenderThreadImpl::current())
718 RenderThreadImpl::current()->WidgetDestroyed();
719 }
720
721 if (for_oopif_) {
722 // Widgets for frames may be created and closed at any time while the frame
723 // is alive. However, the closing process must happen synchronously. Frame
724 // widget and frames hold pointers to each other. If Close() is deferred to
725 // the message loop like in the non-frame widget case, WebWidget::close()
726 // can end up accessing members of an already-deleted frame.
727 Close();
728 } else {
729 // If there is a Send call on the stack, then it could be dangerous to close
730 // now. Post a task that only gets invoked when there are no nested message
731 // loops.
732 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
733 FROM_HERE, base::Bind(&RenderWidget::Close, this));
734 }
735
736 // Balances the AddRef taken when we called AddRoute.
737 Release();
initial.commit09911bf2008-07-26 23:55:29738}
739
fsamuel664e8b62016-01-20 19:54:01740void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04741 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32742 return;
743
[email protected]b2e4c70132013-10-03 02:07:51744 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39745 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51746 return;
747 }
748
mfomitchev2600fd7c2016-02-17 20:53:39749 Resize(params);
initial.commit09911bf2008-07-26 23:55:29750}
751
dgozman9260b0a12015-03-16 13:45:20752void RenderWidget::OnEnableDeviceEmulation(
753 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39754 if (!screen_metrics_emulator_) {
755 ResizeParams resize_params;
756 resize_params.screen_info = screen_info_;
757 resize_params.new_size = size_;
758 resize_params.physical_backing_size = physical_backing_size_;
759 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39760 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
761 resize_params.display_mode = display_mode_;
762 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
763 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18764 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39765 } else {
dgozman9260b0a12015-03-16 13:45:20766 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39767 }
dgozman9260b0a12015-03-16 13:45:20768}
769
770void RenderWidget::OnDisableDeviceEmulation() {
771 screen_metrics_emulator_.reset();
772}
773
initial.commit09911bf2008-07-26 23:55:29774void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31775 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29776 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03777 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55778 for (auto& observer : render_frames_)
779 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29780}
781
[email protected]3399dd822014-08-09 11:14:24782void RenderWidget::OnWasShown(bool needs_repainting,
783 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41784 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29785 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21786 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29787 return;
788
tasakb95dbb50c2017-02-08 18:07:50789 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29790 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03791 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55792 for (auto& observer : render_frames_)
793 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29794
[email protected]8a23afb32014-04-30 22:40:23795 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29796 return;
initial.commit09911bf2008-07-26 23:55:29797
[email protected]3399dd822014-08-09 11:14:24798 if (compositor_) {
799 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11800 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
801 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
802 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54803 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24804 }
initial.commit09911bf2008-07-26 23:55:29805}
806
[email protected]53d3f302009-12-21 04:42:05807void RenderWidget::OnRequestMoveAck() {
808 DCHECK(pending_window_rect_count_);
809 pending_window_rect_count_--;
810}
811
[email protected]ed7defa2013-03-12 21:29:59812GURL RenderWidget::GetURLForGraphicsContext3D() {
813 return GURL();
[email protected]65225772011-05-12 21:10:24814}
815
nzolghadr5d8596502017-01-23 22:59:35816void RenderWidget::OnHandleInputEvent(
817 const blink::WebInputEvent* input_event,
818 const std::vector<const blink::WebInputEvent*>& coalesced_events,
819 const ui::LatencyInfo& latency_info,
820 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23821 if (!input_event)
822 return;
nzolghadr5d8596502017-01-23 22:59:35823
Dave Tapuskaea83d3bd2017-06-13 16:14:55824 HandledEventCallback callback;
825 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
826 callback = base::Bind(
827 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
828 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
829 }
nzolghadr5d8596502017-01-23 22:59:35830 input_handler_->HandleInputEvent(
831 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55832 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23833}
834
Dave Tapuskaea83d3bd2017-06-13 16:14:55835void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31836 const blink::WebCoalescedInputEvent& input_event,
837 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55838 HandledEventCallback callback) {
839 input_handler_->HandleInputEvent(input_event, latency_info,
840 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31841}
842
Dave Tapuskaea83d3bd2017-06-13 16:14:55843void RenderWidget::SendInputEventAck(
844 blink::WebInputEvent::Type type,
845 uint32_t touch_event_id,
846 InputEventAckState ack_state,
847 const ui::LatencyInfo& latency_info,
848 std::unique_ptr<ui::DidOverscrollParams> overscroll_params) {
849 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
850 latency_info, std::move(overscroll_params), touch_event_id);
dtapuska9ec1a912017-04-21 15:18:31851 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
852}
853
dtapuska9d46ef7d2017-05-26 19:06:06854scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
855 return input_event_queue_;
856}
857
fsamuel78f86e42016-01-20 04:10:23858void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21859 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54860 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23861}
862
863void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21864 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54865 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23866}
867
alexmos56567492016-09-13 00:52:46868void RenderWidget::OnSetEditCommandsForNextKeyEvent(
869 const EditCommands& edit_commands) {
870 edit_commands_ = edit_commands;
871}
872
fsamuel78f86e42016-01-20 04:10:23873void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08874 has_focus_ = enable;
875
lfg8ff33912016-09-13 20:59:21876 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54877 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08878
ericwilligers88e69742016-10-17 19:29:55879 for (auto& observer : render_frames_)
880 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23881}
882
dtapuska3d5624d32016-08-30 04:34:00883void RenderWidget::SetNeedsMainFrame() {
884 RenderWidgetCompositor* rwc = compositor();
885 if (!rwc)
886 return;
Blink Reformat1c4d759e2017-04-09 16:34:54887 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00888}
889
fsamuel78f86e42016-01-20 04:10:23890///////////////////////////////////////////////////////////////////////////////
891// RenderWidgetCompositorDelegate
892
893void RenderWidget::ApplyViewportDeltas(
894 const gfx::Vector2dF& inner_delta,
895 const gfx::Vector2dF& outer_delta,
896 const gfx::Vector2dF& elastic_overscroll_delta,
897 float page_scale,
898 float top_controls_delta) {
Blink Reformat1c4d759e2017-04-09 16:34:54899 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21900 elastic_overscroll_delta, page_scale,
901 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23902}
903
sahel1b47fda72017-03-28 17:03:07904void RenderWidget::RecordWheelAndTouchScrollingCount(
905 bool has_scrolled_by_wheel,
906 bool has_scrolled_by_touch) {
Blink Reformat1c4d759e2017-04-09 16:34:54907 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07908 has_scrolled_by_touch);
909}
910
fsamuel78f86e42016-01-20 04:10:23911void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska9ec1a912017-04-21 15:18:31912 if (input_event_queue_) {
913 input_event_queue_->DispatchRafAlignedInput(
914 ui::EventTimeStampFromSeconds(frame_time_sec));
915 }
dtapuska3d5624d32016-08-30 04:34:00916
Blink Reformat1c4d759e2017-04-09 16:34:54917 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23918}
919
danakjc7afae52017-06-20 21:12:41920void RenderWidget::RequestNewLayerTreeFrameSink(
fsamuelcf3002e2017-03-20 23:13:47921 bool fallback,
danakjc7afae52017-06-20 21:12:41922 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21923 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03924 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41925 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39926 DCHECK(!compositor_never_visible_);
danakjc7afae52017-06-20 21:12:41927 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
fsamuelcf3002e2017-03-20 23:13:47928 fallback, routing_id_, frame_swap_message_queue_,
929 GetURLForGraphicsContext3D(), callback);
[email protected]ba91a792013-02-06 09:48:28930}
931
fsamuel78f86e42016-01-20 04:10:23932void RenderWidget::DidCommitAndDrawCompositorFrame() {
933 // NOTE: Tests may break if this event is renamed or moved. See
934 // tab_capture_performancetest.cc.
935 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08936
ericwilligers88e69742016-10-17 19:29:55937 for (auto& observer : render_frames_)
938 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08939
fsamuel78f86e42016-01-20 04:10:23940 // Notify subclasses that we initiated the paint operation.
941 DidInitiatePaint();
942}
943
944void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55945 for (auto& observer : render_frames_)
946 observer.DidCommitCompositorFrame();
947 for (auto& observer : render_frame_proxies_)
948 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23949}
950
951void RenderWidget::DidCompletePageScaleAnimation() {}
952
danakj6c872fc02016-10-22 04:29:49953void RenderWidget::DidReceiveCompositorFrameAck() {
954 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23955
pimanbfb2ceb2016-03-18 21:32:58956 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23957 return;
958 }
959
960 ViewHostMsg_UpdateRect_Params params;
961 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23962 params.flags = next_paint_flags_;
963
964 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
965 next_paint_flags_ = 0;
966 need_update_rect_for_auto_resize_ = false;
967}
968
fsamuel78f86e42016-01-20 04:10:23969bool RenderWidget::IsClosing() const {
970 return host_closing_;
971}
972
danakj53eccbc2016-03-02 22:51:07973void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:54974 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29975}
976
fsamuel78f86e42016-01-20 04:10:23977void RenderWidget::UpdateVisualState() {
Blink Reformat1c4d759e2017-04-09 16:34:54978 GetWebWidget()->UpdateAllLifecyclePhases();
979 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:50980
981 if (time_to_first_active_paint_recorded_)
982 return;
983
984 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
985 if (!render_thread_impl->NeedsToRecordFirstActivePaint())
986 return;
987
988 time_to_first_active_paint_recorded_ = true;
989 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
990 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
991 sample);
fsamuel78f86e42016-01-20 04:10:23992}
993
994void RenderWidget::WillBeginCompositorFrame() {
995 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
996
Blink Reformat1c4d759e2017-04-09 16:34:54997 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:29998
dglazkov06854c5c2016-08-31 00:19:59999 // The UpdateTextInputState can result in further layout and possibly
1000 // enable GPU acceleration so they need to be called before any painting
1001 // is done.
changwan75e3b2072017-01-16 02:55:001002 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591003 UpdateSelectionBounds();
1004
ericwilligers88e69742016-10-17 19:29:551005 for (auto& observer : render_frame_proxies_)
1006 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291007}
1008
jbroman6ccbc7d472016-07-27 04:45:411009std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
1010 std::unique_ptr<cc::CopyOutputRequest> request) {
1011 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1012 routing_id_, std::move(request));
1013}
1014
fsamuel72464894f2015-12-15 06:59:311015///////////////////////////////////////////////////////////////////////////////
1016// RenderWidgetInputHandlerDelegate
1017
avid7d6b2e2016-03-04 19:41:171018void RenderWidget::FocusChangeComplete() {
ekaramad27ca69b12017-04-20 18:34:291019 if (!GetWebWidget()->IsWebFrameWidget())
1020 return;
1021 blink::WebLocalFrame* focused =
1022 static_cast<blink::WebFrameWidget*>(GetWebWidget())
1023 ->LocalRoot()
1024 ->View()
1025 ->FocusedFrame();
1026 if (focused && focused->AutofillClient())
1027 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171028}
fsamuel72464894f2015-12-15 06:59:311029
1030bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:171031 if (owner_delegate_)
1032 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
1033
fsamuel72464894f2015-12-15 06:59:311034 return true;
1035}
1036
dtapuska1827dd22016-03-11 15:24:591037void RenderWidget::ObserveGestureEventAndResult(
1038 const blink::WebGestureEvent& gesture_event,
1039 const gfx::Vector2dF& unused_delta,
1040 bool event_processed) {
1041 if (!compositor_deps_->IsElasticOverscrollEnabled())
1042 return;
1043
1044 cc::InputHandlerScrollResult scroll_result;
1045 scroll_result.did_scroll = event_processed;
1046 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1047 scroll_result.unused_scroll_delta = unused_delta;
1048
1049 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1050 InputHandlerManager* input_handler_manager =
1051 render_thread ? render_thread->input_handler_manager() : NULL;
1052 if (input_handler_manager) {
1053 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1054 routing_id_, gesture_event, scroll_result);
1055 }
1056}
1057
avid7d6b2e2016-03-04 19:41:171058void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461059 ClearEditCommands();
1060}
1061
1062void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1063 const std::string& value) {
1064 ClearEditCommands();
1065 edit_commands_.emplace_back(name, value);
1066}
1067
1068void RenderWidget::ClearEditCommands() {
1069 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171070}
fsamuel72464894f2015-12-15 06:59:311071
chongza8ba91fc2016-08-16 21:39:171072void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:311073 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1074}
1075
fsamuele8326c742016-01-12 00:49:391076void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1077 // Nothing to do here. RenderWidget created the |input_handler| and will take
1078 // ownership of it. We just verify here that we don't already have an input
1079 // handler.
1080 DCHECK(!input_handler_);
1081}
1082
changwan75e3b2072017-01-16 02:55:001083void RenderWidget::ShowVirtualKeyboard() {
1084 UpdateTextInputStateInternal(true, false);
1085}
1086
changwan62f57292017-02-17 08:28:251087void RenderWidget::ClearTextInputState() {
1088 text_input_info_ = blink::WebTextInputInfo();
1089 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1090 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1091 can_compose_inline_ = false;
1092 text_input_flags_ = 0;
1093}
1094
changwan75e3b2072017-01-16 02:55:001095void RenderWidget::UpdateTextInputState() {
1096 UpdateTextInputStateInternal(false, false);
1097}
1098
1099void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1100 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311101 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001102
fsamuel72464894f2015-12-15 06:59:311103 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001104 DCHECK(!reply_to_request);
1105 // show_virtual_keyboard should still be effective even if it was set inside
1106 // the IME
fsamuel72464894f2015-12-15 06:59:311107 // event guard.
changwan75e3b2072017-01-16 02:55:001108 if (show_virtual_keyboard)
1109 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311110 return;
1111 }
1112
dglazkov97b6c2b2016-10-25 17:35:551113 ui::TextInputType new_type = GetTextInputType();
1114 if (IsDateTimeInput(new_type))
1115 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311116
dglazkov97b6c2b2016-10-25 17:35:551117 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351118 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541119 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101120 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541121 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311122
1123 bool new_can_compose_inline = CanComposeInline();
1124
1125 // Only sends text input params if they are changed or if the ime should be
1126 // shown.
changwan75e3b2072017-01-16 02:55:001127 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561128 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1129 text_input_info_ != new_info ||
1130 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381131 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551132 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311133 params.mode = new_mode;
1134 params.flags = new_info.flags;
Blink Reformat1c4d759e2017-04-09 16:34:541135 params.value = new_info.value.Utf8();
1136 params.selection_start = new_info.selection_start;
1137 params.selection_end = new_info.selection_end;
1138 params.composition_start = new_info.composition_start;
1139 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311140 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001141 // TODO(changwan): change instances of show_ime_if_needed to
1142 // show_virtual_keyboard.
1143 params.show_ime_if_needed = show_virtual_keyboard;
1144 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311145 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1146
1147 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551148 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311149 text_input_mode_ = new_mode;
1150 can_compose_inline_ = new_can_compose_inline;
1151 text_input_flags_ = new_info.flags;
1152 }
1153}
1154
1155bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581156 possible_drag_event_info_.event_source =
1157 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1158 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541159 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171160
fsamuel72464894f2015-12-15 06:59:311161 return false;
1162}
1163
1164bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551165 for (auto& observer : render_frames_)
1166 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081167
paulmeyer6ef5a792016-11-08 20:33:581168 possible_drag_event_info_.event_source =
1169 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1170 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541171 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581172
avid7d6b2e2016-03-04 19:41:171173 if (owner_delegate_)
1174 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1175
fsamuel72464894f2015-12-15 06:59:311176 return false;
[email protected]fd847792013-10-24 17:12:351177}
1178
initial.commit09911bf2008-07-26 23:55:291179///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391180// RenderWidgetScreenMetricsDelegate
1181
1182void RenderWidget::Redraw() {
1183 set_next_paint_is_resize_ack();
1184 if (compositor_)
1185 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1186}
1187
bokanc63441c2016-04-27 15:49:121188void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541189 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121190}
1191
1192gfx::Size RenderWidget::GetSizeForWebWidget() const {
1193 if (IsUseZoomForDSFEnabled())
1194 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1195
1196 return size_;
1197}
1198
mfomitchev2600fd7c2016-02-17 20:53:391199void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581200 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271201 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1202 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581203
mfomitchev2600fd7c2016-02-17 20:53:391204 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581205
ccameron2f451532016-09-07 21:49:271206 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1207 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581208 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581209 }
mfomitchev2600fd7c2016-02-17 20:53:391210
1211 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1212 // A resize ack shouldn't be requested if we have not ACK'd the previous
1213 // one.
1214 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1215 }
1216
1217 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211218 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391219 return;
1220
fsamuelca02c4e2017-05-09 13:34:141221 if (params.local_surface_id)
1222 local_surface_id_ = *params.local_surface_id;
1223
ianwene5fc5782016-08-18 04:05:151224 if (compositor_) {
Blink Reformat1c4d759e2017-04-09 16:34:541225 compositor_->SetViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151226 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameron24c87c32017-03-14 21:50:421227 compositor_->SetRasterColorSpace(
ccameronab0aab82017-06-24 17:21:541228 screen_info_.color_space.GetParametricApproximation());
fsamuelca02c4e2017-05-09 13:34:141229 // If surface synchronization is enable, then this will use the provided
1230 // |local_surface_id_| to submit the next generated CompositorFrame.
1231 // If the ID is not valid, then the compositor will defer commits until
1232 // it receives a valid surface ID. This is a no-op if surface
1233 // synchronization is disabled.
1234 compositor_->SetLocalSurfaceId(local_surface_id_);
ianwene5fc5782016-08-18 04:05:151235 }
mfomitchev2600fd7c2016-02-17 20:53:391236
mfomitchev2600fd7c2016-02-17 20:53:391237 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391238
1239 // NOTE: We may have entered fullscreen mode without changing our size.
1240 bool fullscreen_change =
1241 is_fullscreen_granted_ != params.is_fullscreen_granted;
1242 is_fullscreen_granted_ = params.is_fullscreen_granted;
1243 display_mode_ = params.display_mode;
1244
bokanc63441c2016-04-27 15:49:121245 size_ = params.new_size;
1246 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391247
bokanc63441c2016-04-27 15:49:121248 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221249
mfomitchev2600fd7c2016-02-17 20:53:391250 WebSize visual_viewport_size;
1251
1252 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181253 visual_viewport_size = gfx::ScaleToCeiledSize(
1254 params.visible_viewport_size,
1255 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391256 } else {
1257 visual_viewport_size = visible_viewport_size_;
1258 }
1259
Blink Reformat1c4d759e2017-04-09 16:34:541260 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391261
bokanc63441c2016-04-27 15:49:121262 // When resizing, we want to wait to paint before ACK'ing the resize. This
1263 // ensures that we only resize as fast as we can paint. We only need to
1264 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391265 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1266 // In this case there is no paint/composite and therefore no
1267 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1268 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1269 DCHECK(!params.needs_resize_ack);
1270 }
1271
1272 // Send the Resize_ACK flag once we paint again if requested.
1273 if (params.needs_resize_ack)
1274 set_next_paint_is_resize_ack();
1275
1276 if (fullscreen_change)
1277 DidToggleFullscreen();
1278
engedy6cb63c92016-02-23 14:14:581279 if (orientation_changed)
1280 OnOrientationChange();
1281
mfomitchev2600fd7c2016-02-17 20:53:391282 // If a resize ack is requested and it isn't set-up, then no more resizes will
1283 // come in and in general things will go wrong.
1284 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1285}
1286
1287void RenderWidget::SetScreenMetricsEmulationParameters(
1288 bool enabled,
1289 const blink::WebDeviceEmulationParams& params) {
1290 // This is only supported in RenderView.
1291 NOTREACHED();
1292}
1293
1294void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1295 const gfx::Rect& window_screen_rect) {
1296 view_screen_rect_ = view_screen_rect;
1297 window_screen_rect_ = window_screen_rect;
1298}
1299
1300///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461301// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291302
[email protected]3a1c8a8032013-03-18 22:35:321303void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401304 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051305 if (compositor_)
Blink Reformat1c4d759e2017-04-09 16:34:541306 compositor_->SetViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051307}
1308
Blink Reformat1c4d759e2017-04-09 16:34:541309blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221310 DCHECK(!host_closing_);
1311
loyso6e6efc42017-01-21 02:23:031312 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1313 auto animation_host = cc::AnimationHost::CreateMainInstance();
1314
wjmacleana755e302017-04-20 00:43:161315 // Oopif status must be set before the LayerTreeHost is created.
1316 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031317 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1318 compositor_.get(), compositor_.get(), animation_host.get(),
1319 compositor_deps_, device_scale_factor_, screen_info_);
1320 compositor_->Initialize(std::move(layer_tree_host),
1321 std::move(animation_host));
1322
Blink Reformat1c4d759e2017-04-09 16:34:541323 compositor_->SetViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331324 OnDeviceScaleFactorChanged();
ccameron01912992017-05-23 07:34:031325 compositor_->SetRasterColorSpace(
ccameronab0aab82017-06-24 17:21:541326 screen_info_.color_space.GetParametricApproximation());
kenrb5d78b842017-03-06 21:06:011327 compositor_->SetContentSourceId(current_content_source_id_);
fsamuelca02c4e2017-05-09 13:34:141328 compositor_->SetLocalSurfaceId(local_surface_id_);
sievers71c62dd52015-10-07 01:44:391329 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411330 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221331 bool should_generate_frame_sink =
1332 !compositor_never_visible_ && RenderThreadImpl::current();
1333 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391334 compositor_->SetNeverVisible();
1335
pimanc4af3072015-10-02 03:45:591336 StartCompositor();
staraz067f58242016-11-07 21:06:411337 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1338 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331339 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371340
wjmaclean1d970622017-01-21 22:28:241341 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1342 // render_thread may be NULL in tests.
1343 InputHandlerManager* input_handler_manager =
1344 render_thread ? render_thread->input_handler_manager() : NULL;
1345 if (input_handler_manager) {
dtapuska9ec1a912017-04-21 15:18:311346 input_event_queue_ = new MainThreadEventQueue(
1347 this, render_thread->GetRendererScheduler()->CompositorTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221348 render_thread->GetRendererScheduler(), should_generate_frame_sink);
wjmaclean1d970622017-01-21 22:28:241349 input_handler_manager->AddInputHandler(
dtapuska9ec1a912017-04-21 15:18:311350 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
wjmaclean1d970622017-01-21 22:28:241351 weak_ptr_factory_.GetWeakPtr(),
1352 compositor_deps_->IsScrollAnimatorEnabled());
1353 has_added_input_handler_ = true;
1354 }
1355
loyso50b51c22017-01-10 07:18:371356 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591357}
1358
ennef3c58142014-12-09 21:44:381359void RenderWidget::WillCloseLayerTreeView() {
1360 if (host_closing_)
1361 return;
1362
1363 // Prevent new compositors or output surfaces from being created.
1364 host_closing_ = true;
1365
[email protected]aeeedad2014-08-22 18:16:221366 // Always send this notification to prevent new layer tree views from
1367 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211368 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541369 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221370}
1371
Blink Reformat1c4d759e2017-04-09 16:34:541372void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1373 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481374 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1375 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1376 }
dglazkov79c426102015-08-31 21:22:431377
ericwilligers88e69742016-10-17 19:29:551378 for (auto& observer : render_frames_)
1379 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431380}
1381
[email protected]586871b2014-07-22 17:05:111382// static
dchengcedca5612016-04-09 01:40:151383std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111384 IPC::Message* msg,
1385 MessageDeliveryPolicy policy,
1386 FrameSwapMessageQueue* frame_swap_message_queue,
1387 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111388 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111389 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151390 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1391 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111392 &first_message_for_frame);
1393 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151394 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111395 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061396 return promise;
[email protected]586871b2014-07-22 17:05:111397 }
dcheng4b6b5ff2014-10-16 00:42:061398 return nullptr;
[email protected]586871b2014-07-22 17:05:111399}
1400
1401void RenderWidget::QueueMessage(IPC::Message* msg,
1402 MessageDeliveryPolicy policy) {
1403 // RenderThreadImpl::current() is NULL in some tests.
1404 if (!compositor_ || !RenderThreadImpl::current()) {
1405 Send(msg);
1406 return;
1407 }
1408
dchengcedca5612016-04-09 01:40:151409 std::unique_ptr<cc::SwapPromise> swap_promise =
1410 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111411 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111412 compositor_->GetSourceFrameNumber());
1413
1414 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321415 compositor_->QueueSwapPromise(std::move(swap_promise));
danakj87fbafb2017-04-04 16:54:111416 // Request a main frame. This might either A) request a commit ahead of time
1417 // or B) request a commit which is not needed because there are not pending
1418 // updates. If B) then the frame will be aborted early and the swap promises
1419 // will be broken (see EarlyOut_NoUpdates).
Blink Reformat1c4d759e2017-04-09 16:34:541420 compositor_->SetNeedsBeginFrame();
[email protected]586871b2014-07-22 17:05:111421 }
1422}
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.
skyostiled8969c2015-07-20 16:57:081502 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211503 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291504}
1505
[email protected]9017d7852013-11-21 17:47:351506void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151507 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351508 const SyntheticGestureCompletionCallback& callback) {
1509 DCHECK(!callback.is_null());
1510
1511 pending_synthetic_gesture_callbacks_.push(callback);
1512
1513 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321514 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351515
1516 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1517}
1518
initial.commit09911bf2008-07-26 23:55:291519void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031520 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381521 WillCloseLayerTreeView();
1522 compositor_.reset();
lfg8ff33912016-09-13 20:59:211523 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541524 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211525 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291526 }
1527}
1528
bokan841fdc72016-10-06 00:16:351529void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1530 DCHECK(window_rect);
1531 float scale = popup_origin_scale_for_emulation_;
1532 if (!scale)
1533 return;
1534 window_rect->x =
1535 popup_view_origin_for_emulation_.x() +
1536 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1537 window_rect->y =
1538 popup_view_origin_for_emulation_.y() +
1539 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1540}
1541
1542void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1543 DCHECK(window_rect);
1544 float scale = popup_origin_scale_for_emulation_;
1545 if (!scale)
1546 return;
1547 window_rect->x =
1548 popup_screen_origin_for_emulation_.x() +
1549 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1550 window_rect->y =
1551 popup_screen_origin_for_emulation_.y() +
1552 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1553}
1554
Blink Reformat1c4d759e2017-04-09 16:34:541555WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351556 WebRect rect;
bokan6b08cd22016-10-05 00:55:211557 if (pending_window_rect_count_) {
1558 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1559 // the RootWindowRect is probably going to return wrong results since the
1560 // browser may not have processed the Move yet. There isn't really anything
1561 // good to do in this case, and it shouldn't happen - since this size is
1562 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351563 rect = pending_window_rect_;
1564 } else {
1565 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211566 }
[email protected]2533ce12009-05-09 00:02:241567
bokan841fdc72016-10-06 00:16:351568 ScreenRectToEmulatedIfNeeded(&rect);
1569 return rect;
bokan6b08cd22016-10-05 00:55:211570}
1571
Blink Reformat1c4d759e2017-04-09 16:34:541572WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351573 WebRect rect = view_screen_rect_;
1574 ScreenRectToEmulatedIfNeeded(&rect);
1575 return rect;
initial.commit09911bf2008-07-26 23:55:291576}
1577
Blink Reformat1c4d759e2017-04-09 16:34:541578void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301579 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541580 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301581}
1582
Blink Reformat1c4d759e2017-04-09 16:34:541583void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241584 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351585 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511586
[email protected]5b45ad42013-10-25 00:42:041587 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201588 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561589 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1590 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031591 } else {
bokanc007c3a2015-02-03 07:15:561592 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031593 }
initial.commit09911bf2008-07-26 23:55:291594 } else {
bokanc007c3a2015-02-03 07:15:561595 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291596 }
1597}
1598
[email protected]2533ce12009-05-09 00:02:241599void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1600 pending_window_rect_ = rect;
1601 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241602
bokan6b08cd22016-10-05 00:55:211603 // Popups don't get size updates back from the browser so just store the set
1604 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541605 if (popup_type_ != blink::kWebPopupTypeNone) {
1606 window_screen_rect_ = rect;
1607 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241608 }
[email protected]d4547452008-08-28 18:36:371609}
1610
wjmacleanee244e02017-05-26 21:06:071611void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1612 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071613 has_host_context_menu_location_ = true;
1614 host_context_menu_location_ = location;
1615 if (GetWebWidget()) {
1616 GetWebWidget()->ShowContextMenu(
1617 static_cast<blink::WebMenuSourceType>(source_type));
1618 }
1619 has_host_context_menu_location_ = false;
1620}
1621
[email protected]fa7b1dc2010-06-23 17:53:041622void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261623 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041624 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071625 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041626 int selection_start, int selection_end) {
ekaramad5aff1942017-01-06 01:26:351627 if (!ShouldHandleImeEvents())
1628 return;
1629
brettw4b461082016-11-19 18:55:161630#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091631 if (focused_pepper_plugin_) {
1632 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1633 text, underlines, selection_start, selection_end);
1634 return;
1635 }
1636#endif
[email protected]66fca5bc2013-05-23 06:58:291637 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011638 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011639 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541640 !controller->SetComposition(
1641 WebString::FromUTF16(text),
ekaramadce32ef9f2017-02-09 17:33:561642 WebVector<WebCompositionUnderline>(underlines),
1643 replacement_range.IsValid()
1644 ? WebRange(replacement_range.start(), replacement_range.length())
1645 : WebRange(),
1646 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041647 // If we failed to set the composition text, then we need to let the browser
1648 // process to cancel the input method's ongoing composition session, to make
1649 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221650 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261651 }
nonafa291792016-08-10 02:36:181652 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041653}
1654
rlanday7efe2302017-01-11 00:14:281655void RenderWidget::OnImeCommitText(
1656 const base::string16& text,
1657 const std::vector<WebCompositionUnderline>& underlines,
1658 const gfx::Range& replacement_range,
1659 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351660 if (!ShouldHandleImeEvents())
1661 return;
1662
brettw4b461082016-11-19 18:55:161663#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091664 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291665 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1666 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091667 return;
1668 }
1669#endif
[email protected]66fca5bc2013-05-23 06:58:291670 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391671 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261672 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541673 controller->CommitText(
1674 WebString::FromUTF16(text),
ekaramadce32ef9f2017-02-09 17:33:561675 WebVector<WebCompositionUnderline>(underlines),
1676 replacement_range.IsValid()
1677 ? WebRange(replacement_range.start(), replacement_range.length())
1678 : WebRange(),
1679 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261680 }
aelias87b8f7c2016-09-14 03:19:291681 input_handler_->set_handling_input_event(false);
1682 UpdateCompositionInfo(false /* not an immediate request */);
1683}
1684
1685void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351686 if (!ShouldHandleImeEvents())
1687 return;
1688
brettw4b461082016-11-19 18:55:161689#if BUILDFLAG(ENABLE_PLUGINS)
aelias87b8f7c2016-09-14 03:19:291690 if (focused_pepper_plugin_) {
1691 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1692 keep_selection);
1693 return;
1694 }
1695#endif
1696
changwan38c3eb612016-12-09 01:45:561697 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291698 return;
1699 ImeEventGuard guard(this);
1700 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011701 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541702 controller->FinishComposingText(
1703 keep_selection ? WebInputMethodController::kKeepSelection
1704 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011705 }
fsamuele8326c742016-01-12 00:49:391706 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181707 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291708}
1709
oshimad5279032015-12-16 18:22:331710void RenderWidget::OnDeviceScaleFactorChanged() {
1711 if (!compositor_)
1712 return;
oshimad5279032015-12-16 18:22:331713 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181714 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331715 else
Blink Reformat1c4d759e2017-04-09 16:34:541716 compositor_->SetDeviceScaleFactor(device_scale_factor_);
oshimad5279032015-12-16 18:22:331717}
1718
[email protected]0bc1f572013-04-17 01:46:311719void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121720 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211721 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121722 return;
1723
[email protected]0bc1f572013-04-17 01:46:311724 // Even if the browser provides an empty damage rect, it's still expecting to
1725 // receive a repaint ack so just damage the entire widget bounds.
1726 if (size_to_paint.IsEmpty()) {
1727 size_to_paint = size_;
1728 }
1729
[email protected]ec7dc112008-08-06 05:30:121730 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051731 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311732 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121733}
1734
[email protected]79fa22e2013-08-23 15:18:121735void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351736 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1737
1738 pending_synthetic_gesture_callbacks_.front().Run();
1739 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271740}
1741
[email protected]4873c7d2009-07-16 06:36:281742void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211743 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111744 return;
Blink Reformat1c4d759e2017-04-09 16:34:541745 GetWebWidget()->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111746}
1747
[email protected]80ad8622012-11-07 16:33:031748void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1749 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511750 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391751 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1752 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511753 } else {
mfomitchev2600fd7c2016-02-17 20:53:391754 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511755 }
[email protected]80ad8622012-11-07 16:33:031756 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1757}
1758
lfgdb5c4ed2016-03-04 23:09:071759void RenderWidget::OnUpdateWindowScreenRect(
1760 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211761 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071762 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211763 else
lfgdb5c4ed2016-03-04 23:09:071764 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071765}
1766
kenrbea731792017-01-13 15:10:481767void RenderWidget::OnSetViewportIntersection(
1768 const gfx::Rect& viewport_intersection) {
Blink Reformat1c4d759e2017-04-09 16:34:541769 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1770 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
kenrbea731792017-01-13 15:10:481771 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541772 ->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:481773 }
1774}
1775
kenrb04323782017-06-23 01:23:321776void RenderWidget::OnSetIsInert(bool inert) {
1777 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1778 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
1779 static_cast<WebFrameWidget*>(GetWebWidget())->SetIsInert(inert);
1780 }
1781}
1782
paulmeyer90f6c31d2016-11-12 00:17:591783void RenderWidget::OnDragTargetDragEnter(
1784 const std::vector<DropData::Metadata>& drop_meta_data,
1785 const gfx::Point& client_point,
1786 const gfx::Point& screen_point,
1787 WebDragOperationsMask ops,
1788 int key_modifiers) {
1789 if (!GetWebWidget())
1790 return;
1791
Blink Reformat1c4d759e2017-04-09 16:34:541792 DCHECK(GetWebWidget()->IsWebFrameWidget());
1793 WebDragOperation operation =
1794 static_cast<WebFrameWidget*>(GetWebWidget())
1795 ->DragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1796 client_point, screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591797
1798 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1799}
1800
1801void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1802 const gfx::Point& screen_point,
1803 WebDragOperationsMask ops,
1804 int key_modifiers) {
1805 if (!GetWebWidget())
1806 return;
1807
Blink Reformat1c4d759e2017-04-09 16:34:541808 DCHECK(GetWebWidget()->IsWebFrameWidget());
paulmeyer90f6c31d2016-11-12 00:17:591809 WebDragOperation operation =
Blink Reformat1c4d759e2017-04-09 16:34:541810 static_cast<WebFrameWidget*>(GetWebWidget())
1811 ->DragTargetDragOver(ConvertWindowPointToViewport(client_point),
1812 screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591813
1814 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1815}
1816
kenrb07c272802017-02-07 23:48:171817void RenderWidget::OnDragTargetDragLeave(const gfx::Point& client_point,
1818 const gfx::Point& screen_point) {
paulmeyer90f6c31d2016-11-12 00:17:591819 if (!GetWebWidget())
1820 return;
Blink Reformat1c4d759e2017-04-09 16:34:541821 DCHECK(GetWebWidget()->IsWebFrameWidget());
kenrb07c272802017-02-07 23:48:171822 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541823 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171824 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591825}
1826
1827void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1828 const gfx::Point& client_point,
1829 const gfx::Point& screen_point,
1830 int key_modifiers) {
1831 if (!GetWebWidget())
1832 return;
1833
Blink Reformat1c4d759e2017-04-09 16:34:541834 DCHECK(GetWebWidget()->IsWebFrameWidget());
1835 static_cast<WebFrameWidget*>(GetWebWidget())
1836 ->DragTargetDrop(DropDataToWebDragData(drop_data),
1837 ConvertWindowPointToViewport(client_point), screen_point,
1838 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591839}
1840
paulmeyer8fc8ea92016-11-15 05:12:211841void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1842 const gfx::Point& screen_point,
1843 WebDragOperation op) {
1844 if (!GetWebWidget())
1845 return;
1846
Blink Reformat1c4d759e2017-04-09 16:34:541847 static_cast<WebFrameWidget*>(GetWebWidget())
1848 ->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
1849 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:211850}
1851
1852void RenderWidget::OnDragSourceSystemDragEnded() {
1853 if (!GetWebWidget())
1854 return;
1855
Blink Reformat1c4d759e2017-04-09 16:34:541856 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:211857}
1858
Blink Reformat1c4d759e2017-04-09 16:34:541859void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261860#if defined(OS_CHROMEOS)
1861 // On ChromeOS, virtual keyboard is triggered only when users leave the
1862 // mouse button or the finger and a text input element is focused at that
1863 // time. Focus event itself shouldn't trigger virtual keyboard.
1864 UpdateTextInputState();
1865#else
changwan75e3b2072017-01-16 02:55:001866 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261867#endif
boliu7b2be2f2016-11-04 04:58:311868
1869// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1870// virtual keyboard.
1871#if !defined(OS_ANDROID)
1872 FocusChangeComplete();
1873#endif
[email protected]0d1ebed12013-08-05 22:01:131874}
1875
fsamuel72464894f2015-12-15 06:59:311876ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161877#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091878 if (focused_pepper_plugin_)
1879 return focused_pepper_plugin_->text_input_type();
1880#endif
ekaramad5aff1942017-01-06 01:26:351881 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541882 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:311883 return ui::TEXT_INPUT_TYPE_NONE;
1884}
1885
nonafa291792016-08-10 02:36:181886void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1887 if (!monitor_composition_info_ && !immediate_request)
1888 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591889
nonafa291792016-08-10 02:36:181890 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1891 gfx::Range range;
1892 std::vector<gfx::Rect> character_bounds;
1893
1894 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1895 // Composition information is only available on editable node.
1896 range = gfx::Range::InvalidRange();
1897 } else {
1898 GetCompositionRange(&range);
1899 GetCompositionCharacterBounds(&character_bounds);
1900 }
1901
1902 if (!immediate_request &&
1903 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311904 return;
nonafa291792016-08-10 02:36:181905 }
fsamuel72464894f2015-12-15 06:59:311906 composition_character_bounds_ = character_bounds;
1907 composition_range_ = range;
1908 Send(new InputHostMsg_ImeCompositionRangeChanged(
1909 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311910}
1911
Blink Reformat1c4d759e2017-04-09 16:34:541912void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:541913 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461914 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331915 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541916 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461917 gfx::Rect window_rect =
1918 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1919 rect->x = window_rect.x();
1920 rect->y = window_rect.y();
1921 rect->width = window_rect.width();
1922 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541923 }
1924}
1925
Blink Reformat1c4d759e2017-04-09 16:34:541926void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:301927 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181928 rect->x *= GetOriginalDeviceScaleFactor();
1929 rect->y *= GetOriginalDeviceScaleFactor();
1930 rect->width *= GetOriginalDeviceScaleFactor();
1931 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301932 }
1933}
1934
[email protected]adb362312014-06-28 06:04:241935#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:391936void RenderWidget::OnRequestTextInputStateUpdate() {
1937 DCHECK(!ime_event_guard_);
1938 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:001939 UpdateTextInputStateInternal(false, true /* reply_to_request */);
changwan8c342742016-02-26 00:53:391940}
[email protected]105dffb42013-02-20 03:46:211941#endif
1942
ekaramadc9b70a72017-03-23 16:14:231943void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
1944 bool monitor_updates) {
1945 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:181946 if (!immediate_request)
1947 return;
1948 UpdateCompositionInfo(true /* immediate request */);
1949}
1950
wjmaclean8a795f32016-08-11 23:49:581951void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191952 if (device_scale_factor_ == device_scale_factor)
1953 return;
1954
1955 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331956 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581957 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191958}
1959
[email protected]fcdc5642014-05-09 14:32:241960void RenderWidget::OnOrientationChange() {
lfg8d649cc2017-04-28 18:04:301961 WebWidget* web_widget = GetWebWidget();
1962 if (web_widget && web_widget->IsWebFrameWidget()) {
1963 WebFrameWidget* web_frame_widget = static_cast<WebFrameWidget*>(web_widget);
1964 web_frame_widget->LocalRoot()->SendOrientationChangeEvent();
1965 }
[email protected]fcdc5642014-05-09 14:32:241966}
1967
[email protected]bee16aab2009-08-26 15:55:031968void RenderWidget::SetHidden(bool hidden) {
1969 if (is_hidden_ == hidden)
1970 return;
1971
jdduke8fac9d102014-12-20 02:40:131972 // The status has changed. Tell the RenderThread about it and ensure
1973 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031974 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131975
tasakb95dbb50c2017-02-08 18:07:501976 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:001977 RenderThreadImpl::current()->WidgetHidden();
tasakb95dbb50c2017-02-08 18:07:501978 time_to_first_active_paint_recorded_ = false;
1979 } else
[email protected]b2db9272014-01-10 17:42:001980 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111981
1982 if (render_widget_scheduling_state_)
1983 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031984}
1985
[email protected]2b624c562011-10-27 22:58:261986void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211987 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261988 return;
1989
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121990 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:541991 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261992 } else {
Blink Reformat1c4d759e2017-04-09 16:34:541993 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261994 }
[email protected]2b624c562011-10-27 22:58:261995}
1996
[email protected]674741932009-02-04 23:44:461997bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051998 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461999}
2000
[email protected]674741932009-02-04 23:44:462001void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052002 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462003}
2004
[email protected]674741932009-02-04 23:44:462005void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052006 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462007}
2008
changwanf2a707b2015-10-30 08:22:162009void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2010 if (!ime_event_guard_)
2011 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292012}
2013
changwanf2a707b2015-10-30 08:22:162014void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2015 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002016 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162017 return;
2018 }
2019 ime_event_guard_ = nullptr;
2020
[email protected]66fca5bc2013-05-23 06:58:292021 // While handling an ime event, text input state and selection bounds updates
2022 // are ignored. These must explicitly be updated once finished handling the
2023 // ime event.
2024 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472025#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002026 if (guard->show_virtual_keyboard())
2027 ShowVirtualKeyboard();
2028 else
2029 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472030#endif
[email protected]66fca5bc2013-05-23 06:58:292031}
2032
[email protected]7c8873e2013-02-05 08:03:012033void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162034#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092035 if (focused_pepper_plugin_) {
2036 // TODO(kinaba) http://crbug.com/101101
2037 // Current Pepper IME API does not handle selection bounds. So we simply
2038 // use the caret position as an empty range for now. It will be updated
2039 // after Pepper API equips features related to surrounding text retrieval.
2040 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542041 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092042 *focus = caret;
2043 *anchor = caret;
2044 return;
2045 }
2046#endif
[email protected]7c8873e2013-02-05 08:03:012047 WebRect focus_webrect;
2048 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542049 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2050 ConvertViewportToWindow(&focus_webrect);
2051 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242052 *focus = focus_webrect;
2053 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322054}
2055
[email protected]e99ef6f2011-10-16 01:13:002056void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082057 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212058 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002059 return;
changwanf2a707b2015-10-30 08:22:162060 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292061 return;
[email protected]e99ef6f2011-10-16 01:13:002062
mohsenb0eeba72015-08-09 06:20:082063#if defined(USE_AURA)
2064 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2065 // Aura beucause composited selection updates are not working for webview tags
2066 // which regresses IME inside webview. Remove this when composited selection
2067 // updates are fixed for webviews. See, http://crbug.com/510568.
2068 bool send_ipc = true;
2069#else
jddukeacf809e2014-09-23 20:38:382070 // With composited selection updates, the selection bounds will be reported
2071 // directly by the compositor, in which case explicit IPC selection
2072 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082073 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542074 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082075#endif
2076 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382077 ViewHostMsg_SelectionBounds_Params params;
2078 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2079 if (selection_anchor_rect_ != params.anchor_rect ||
2080 selection_focus_rect_ != params.focus_rect) {
2081 selection_anchor_rect_ = params.anchor_rect;
2082 selection_focus_rect_ = params.focus_rect;
Blink Reformat1c4d759e2017-04-09 16:34:542083 GetWebWidget()->SelectionTextDirection(params.focus_dir,
lfg8ff33912016-09-13 20:59:212084 params.anchor_dir);
Blink Reformat1c4d759e2017-04-09 16:34:542085 params.is_anchor_first = GetWebWidget()->IsSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:382086 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2087 }
[email protected]58b48a0d2012-06-13 07:01:352088 }
jddukeacf809e2014-09-23 20:38:382089
nonafa291792016-08-10 02:36:182090 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002091}
2092
lfgb00fcad2016-07-14 14:16:332093void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2094 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542095 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332096 if (size_.width() != new_size_in_window.width ||
2097 size_.height() != new_size_in_window.height) {
2098 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2099
2100 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542101 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2102 size_.height());
lfgb00fcad2016-07-14 14:16:332103 view_screen_rect_ = new_pos;
2104 window_screen_rect_ = new_pos;
2105 }
2106
2107 AutoResizeCompositor();
2108
2109 if (!resizing_mode_selector_->is_synchronous_mode())
2110 need_update_rect_for_auto_resize_ = true;
2111 }
2112}
2113
[email protected]58b48a0d2012-06-13 07:01:352114void RenderWidget::GetCompositionCharacterBounds(
2115 std::vector<gfx::Rect>* bounds) {
2116 DCHECK(bounds);
2117 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092118
brettw4b461082016-11-19 18:55:162119#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092120 if (focused_pepper_plugin_)
2121 return;
2122#endif
2123
lfg8ff33912016-09-13 20:59:212124 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092125 return;
2126 blink::WebVector<blink::WebRect> bounds_from_blink;
Blink Reformat1c4d759e2017-04-09 16:34:542127 if (!GetWebWidget()->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092128 return;
2129
2130 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542131 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092132 bounds->push_back(bounds_from_blink[i]);
2133 }
[email protected]58b48a0d2012-06-13 07:01:352134}
2135
[email protected]db4fc1e2013-09-06 20:01:512136void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162137#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092138 if (focused_pepper_plugin_)
2139 return;
2140#endif
Blink Reformat1c4d759e2017-04-09 16:34:542141 WebRange web_range = GetWebWidget()->CompositionRange();
2142 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212143 *range = gfx::Range::InvalidRange();
2144 return;
[email protected]88dbe32f2013-06-20 23:31:362145 }
Blink Reformat1c4d759e2017-04-09 16:34:542146 range->set_start(web_range.StartOffset());
2147 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362148}
2149
[email protected]501ea13d2013-07-09 17:03:292150bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512151 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292152 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082153 if (!range.IsValid())
2154 return false;
[email protected]501ea13d2013-07-09 17:03:292155 if (composition_range_ != range)
2156 return true;
2157 if (bounds.size() != composition_character_bounds_.size())
2158 return true;
2159 for (size_t i = 0; i < bounds.size(); ++i) {
2160 if (bounds[i] != composition_character_bounds_[i])
2161 return true;
2162 }
2163 return false;
2164}
[email protected]501ea13d2013-07-09 17:03:292165
[email protected]ad26ef42011-06-17 07:59:452166bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162167#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092168 if (focused_pepper_plugin_)
2169 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
2170#endif
[email protected]ad26ef42011-06-17 07:59:452171 return true;
[email protected]56ea1a62011-05-30 07:05:572172}
2173
Blink Reformat1c4d759e2017-04-09 16:34:542174blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272175 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542176 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542177 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272178 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542179 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2180 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272181 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542182 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272183 switch (screen_info_.orientation_type) {
2184 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542185 web_screen_info.orientation_type =
2186 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272187 break;
2188 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542189 web_screen_info.orientation_type =
2190 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272191 break;
2192 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542193 web_screen_info.orientation_type =
2194 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272195 break;
2196 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542197 web_screen_info.orientation_type =
2198 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272199 break;
2200 default:
Blink Reformat1c4d759e2017-04-09 16:34:542201 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272202 break;
2203 }
Blink Reformat1c4d759e2017-04-09 16:34:542204 web_screen_info.orientation_angle = screen_info_.orientation_angle;
ccameron2f451532016-09-07 21:49:272205 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282206}
2207
donnda070f3c2015-01-16 19:54:112208#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542209void RenderWidget::ShowUnhandledTapUIIfNeeded(const WebPoint& tapped_position,
2210 const WebNode& tapped_node,
2211 bool page_changed) {
Blink Reformat1c4d759e2017-04-09 16:34:542212 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2213 !tapped_node.IsContentEditable() &&
2214 !tapped_node.IsInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112215 if (should_trigger) {
2216 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2217 tapped_position.x, tapped_position.y));
2218 }
2219}
2220#endif
2221
Blink Reformat1c4d759e2017-04-09 16:34:542222void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2223 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022224#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562225 if (event_cancelled)
2226 return;
Blink Reformat1c4d759e2017-04-09 16:34:542227 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002228 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542229 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212230 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352231 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542232 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002233 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462234 else
changwan75e3b2072017-01-16 02:55:002235 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562236 }
ekaramada110f642016-12-21 19:47:282237// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2238// crbug/420130.
2239#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542240 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282241 return;
2242
2243 // TODO(estade): hit test the event against focused node to make sure
2244 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352245 blink::WebInputMethodController* controller = GetInputMethodController();
2246 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542247 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282248
2249 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542250 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282251#endif
[email protected]c68c3e4e2013-01-24 00:36:562252#endif
2253}
2254
Blink Reformat1c4d759e2017-04-09 16:34:542255void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312256 const blink::WebFloatSize& overscrollDelta,
2257 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422258 const blink::WebFloatPoint& position,
2259 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482260#if defined(OS_MACOSX)
2261 // On OSX the user can disable the elastic overscroll effect. If that's the
2262 // case, don't forward the overscroll notification.
2263 DCHECK(compositor_deps());
2264 if (!compositor_deps()->IsElasticOverscrollEnabled())
2265 return;
2266#endif
bokane53a10f2016-04-13 23:48:312267 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392268 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422269}
2270
[email protected]7912e822014-04-16 02:37:032271void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392272 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542273 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032274}
2275
[email protected]24ed0432013-04-24 07:50:312276RenderWidgetCompositor* RenderWidget::compositor() const {
2277 return compositor_.get();
2278}
2279
fsamuel72464894f2015-12-15 06:59:312280void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392281 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372282}
[email protected]c3d45532011-10-07 19:20:402283
Blink Reformat1c4d759e2017-04-09 16:34:542284void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112285 if (render_widget_scheduling_state_)
2286 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552287 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2288}
2289
Dave Tapuskadfe486c12017-06-09 16:53:132290void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2291 if (input_event_queue_)
2292 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2293}
2294
xidachenfa0199e72017-05-11 11:34:262295void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
[email protected]5d0bbdfa92013-12-10 00:35:512296 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2297 // when blink is emulating touch with mouse).
Blink Reformat1c4d759e2017-04-09 16:34:542298 if (input_handler_->handling_event_type() != WebInputEvent::kTouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512299 return;
2300
xidachenfa0199e72017-05-11 11:34:262301 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
[email protected]5d0bbdfa92013-12-10 00:35:512302}
2303
[email protected]e3244ed2014-06-20 20:04:272304void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2305 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162306}
2307
[email protected]e3244ed2014-06-20 20:04:272308void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2309 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162310}
2311
[email protected]de3c5d82014-05-28 22:12:592312void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2313 render_frames_.AddObserver(frame);
2314}
2315
2316void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2317 render_frames_.RemoveObserver(frame);
2318}
2319
lfg43e08e62016-02-03 18:51:372320void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2321 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2322 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2323}
2324
oshima50872a72016-03-04 13:26:182325float RenderWidget::GetOriginalDeviceScaleFactor() const {
2326 return
2327 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272328 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182329 device_scale_factor_;
2330}
2331
paulmeyer90f6c31d2016-11-12 00:17:592332gfx::Point RenderWidget::ConvertWindowPointToViewport(
2333 const gfx::Point& point) {
2334 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542335 ConvertWindowToViewport(&point_in_viewport);
paulmeyer90f6c31d2016-11-12 00:17:592336 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2337}
2338
Blink Reformat1c4d759e2017-04-09 16:34:542339bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212340 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2341}
2342
Blink Reformat1c4d759e2017-04-09 16:34:542343void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212344 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2345}
2346
Blink Reformat1c4d759e2017-04-09 16:34:542347bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212348 return mouse_lock_dispatcher_->IsMouseLockedTo(
2349 webwidget_mouse_lock_target_.get());
2350}
2351
Blink Reformat1c4d759e2017-04-09 16:34:542352void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582353 const WebDragData& data,
2354 WebDragOperationsMask mask,
2355 const WebImage& image,
2356 const WebPoint& webImageOffset) {
2357 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542358 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582359 DropData drop_data(DropDataBuilder::Build(data));
2360 drop_data.referrer_policy = policy;
2361 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592362 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542363 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582364 possible_drag_event_info_));
2365}
2366
kenrb5d78b842017-03-06 21:06:012367uint32_t RenderWidget::GetContentSourceId() {
2368 return current_content_source_id_;
2369}
2370
2371void RenderWidget::IncrementContentSourceId() {
2372 if (compositor_)
2373 compositor_->SetContentSourceId(++current_content_source_id_);
2374}
2375
lfg8ff33912016-09-13 20:59:212376blink::WebWidget* RenderWidget::GetWebWidget() const {
2377 return webwidget_internal_;
2378}
2379
ekaramad2daaf672016-11-10 20:29:012380blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2381 const {
Blink Reformat1c4d759e2017-04-09 16:34:542382 if (!GetWebWidget()->IsWebFrameWidget()) {
ekaramad5a9f52a2016-12-07 01:35:182383 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2384 // when the RenderWidget is swapped out. We should top sending IPCs from the
2385 // browser side (https://crbug.com/669219).
2386 // If there is no WebFrameWidget, then there will be no
2387 // InputMethodControllers for a WebLocalFrame.
2388 return nullptr;
2389 }
ekaramad2daaf672016-11-10 20:29:012390 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:542391 ->GetActiveWebInputMethodController();
ekaramad2daaf672016-11-10 20:29:012392}
2393
[email protected]e9ff79c2012-10-19 21:31:262394} // namespace content