blob: 89e9a3af2a5cd3af0ec57359497ad4a05046a2f2 [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"
danakjc7afae52017-06-20 21:12:4128#include "cc/output/layer_tree_frame_sink.h"
loyso6e6efc42017-01-21 02:23:0329#include "cc/trees/layer_tree_host.h"
Fady Samuelc645ffe2017-07-24 17:28:2030#include "components/viz/common/frame_sinks/begin_frame_source.h"
Fady Samueldfecb7d2017-07-26 11:41:0431#include "components/viz/common/quads/copy_output_request.h"
oshima750cb4342015-10-31 00:59:0132#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5833#include "content/common/drag_event_source_info.h"
34#include "content/common/drag_messages.h"
[email protected]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"
Nasko Oskovf97e8b02017-07-25 02:45:4238#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"
Dave Tapuska9db80842017-07-24 17:24:2657#include "content/renderer/input/widget_input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3258#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1659#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2760#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0561#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4462#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5563#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4464#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0965#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0466#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4767#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1868#include "ipc/ipc_sync_message.h"
brettw4b461082016-11-19 18:55:1669#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4870#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2571#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1872#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5973#include "third_party/WebKit/public/platform/WebDragData.h"
74#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5575#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1176#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3077#include "third_party/WebKit/public/platform/WebRect.h"
nverne61d2da872017-05-24 10:15:3078#include "third_party/WebKit/public/platform/WebRuntimeFeatures.h"
[email protected]aaf68892013-07-18 00:11:3079#include "third_party/WebKit/public/platform/WebSize.h"
80#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5181#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
82#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
ekaramad27ca69b12017-04-20 18:34:2983#include "third_party/WebKit/public/web/WebAutofillClient.h"
[email protected]19193682014-04-03 15:01:4384#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5985#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0186#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5987#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1188#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3189#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3190#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
91#include "third_party/WebKit/public/web/WebRange.h"
kenrba7199832015-01-22 23:44:5992#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0893#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4194#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5995#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:1396#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:4397#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:5098#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0999#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:32100#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:48101#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:27102#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41103#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48104
[email protected]eeb93112013-05-01 19:41:10105#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15106#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24107#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10108#endif
109
[email protected]661eb9d2009-02-03 02:11:48110#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52111#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41112#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48113#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44114
sadrul943e3b32016-08-04 18:22:59115#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10116#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19117#endif
118
ekaramad330ba4232016-09-23 17:57:47119#if defined(OS_MACOSX)
120#include "content/renderer/text_input_client_observer.h"
121#endif
122
[email protected]180ef242013-11-07 06:50:46123using blink::WebCompositionUnderline;
124using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43125using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59126using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58127using blink::WebDragOperationsMask;
128using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59129using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46130using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58131using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46132using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49133using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01134using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58135using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46136using blink::WebMouseEvent;
137using blink::WebMouseWheelEvent;
138using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11139using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46140using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11141using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46142using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48143using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46144using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46145using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59146using blink::WebString;
[email protected]180ef242013-11-07 06:50:46147using blink::WebTextDirection;
148using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25149using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46150using blink::WebVector;
151using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26152
paulmeyer90f6c31d2016-11-12 00:17:59153namespace content {
154
[email protected]6a4d7f62013-01-07 21:32:13155namespace {
[email protected]b256eca2013-07-11 10:57:40156
157typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
158
AJITH KUMAR V041c0b02017-08-08 10:39:20159static const int kInvalidNextPreviousFlagsValue = -1;
160
lfgbee1e0a2016-06-08 21:24:21161class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
162 public:
163 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
164 : webwidget_(webwidget) {}
165
166 void OnLockMouseACK(bool succeeded) override {
167 if (succeeded)
Blink Reformat1c4d759e2017-04-09 16:34:54168 webwidget_->DidAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21169 else
Blink Reformat1c4d759e2017-04-09 16:34:54170 webwidget_->DidNotAcquirePointerLock();
lfgbee1e0a2016-06-08 21:24:21171 }
172
Blink Reformat1c4d759e2017-04-09 16:34:54173 void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); }
lfgbee1e0a2016-06-08 21:24:21174
175 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
176 // The WebWidget handles mouse lock in Blink's handleInputEvent().
177 return false;
178 }
179
180 private:
181 blink::WebWidget* webwidget_;
182};
183
dglazkov97b6c2b2016-10-25 17:35:55184bool IsDateTimeInput(ui::TextInputType type) {
185 return type == ui::TEXT_INPUT_TYPE_DATE ||
186 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
187 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
188 type == ui::TEXT_INPUT_TYPE_MONTH ||
189 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
190}
191
paulmeyer90f6c31d2016-11-12 00:17:59192WebDragData DropMetaDataToWebDragData(
193 const std::vector<DropData::Metadata>& drop_meta_data) {
194 std::vector<WebDragData::Item> item_list;
195 for (const auto& meta_data_item : drop_meta_data) {
196 if (meta_data_item.kind == DropData::Kind::STRING) {
197 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54198 item.storage_type = WebDragData::Item::kStorageTypeString;
199 item.string_type = WebString::FromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59200 // Have to pass a dummy URL here instead of an empty URL because the
201 // DropData received by browser_plugins goes through a round trip:
202 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
203 // will contain an empty URL (which means no URL is dragged) if the URL in
204 // WebDragData is empty.
205 if (base::EqualsASCII(meta_data_item.mime_type,
206 ui::Clipboard::kMimeTypeURIList)) {
Blink Reformat1c4d759e2017-04-09 16:34:54207 item.string_data = WebString::FromUTF8("about:dragdrop-placeholder");
paulmeyer90f6c31d2016-11-12 00:17:59208 }
209 item_list.push_back(item);
210 continue;
211 }
212
213 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
214 // just the mimetype. This is needed to drag files to WebView on Android
215 // platform.
216 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
217 !meta_data_item.filename.empty()) {
218 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54219 item.storage_type = WebDragData::Item::kStorageTypeFilename;
220 item.filename_data = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59221 item_list.push_back(item);
222 continue;
223 }
224
225 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
226 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54227 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
228 item.file_system_url = meta_data_item.file_system_url;
paulmeyer90f6c31d2016-11-12 00:17:59229 item_list.push_back(item);
230 continue;
231 }
232 }
233
234 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54235 result.Initialize();
236 result.SetItems(item_list);
paulmeyer90f6c31d2016-11-12 00:17:59237 return result;
238}
239
240WebDragData DropDataToWebDragData(const DropData& drop_data) {
241 std::vector<WebDragData::Item> item_list;
242
243 // These fields are currently unused when dragging into WebKit.
244 DCHECK(drop_data.download_metadata.empty());
245 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23246 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59247
248 if (!drop_data.text.is_null()) {
249 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54250 item.storage_type = WebDragData::Item::kStorageTypeString;
251 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText);
252 item.string_data = WebString::FromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59253 item_list.push_back(item);
254 }
255
256 if (!drop_data.url.is_empty()) {
257 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54258 item.storage_type = WebDragData::Item::kStorageTypeString;
259 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList);
260 item.string_data = WebString::FromUTF8(drop_data.url.spec());
261 item.title = WebString::FromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59262 item_list.push_back(item);
263 }
264
265 if (!drop_data.html.is_null()) {
266 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54267 item.storage_type = WebDragData::Item::kStorageTypeString;
268 item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML);
269 item.string_data = WebString::FromUTF16(drop_data.html.string());
270 item.base_url = drop_data.html_base_url;
paulmeyer90f6c31d2016-11-12 00:17:59271 item_list.push_back(item);
272 }
273
274 for (std::vector<ui::FileInfo>::const_iterator it =
275 drop_data.filenames.begin();
276 it != drop_data.filenames.end();
277 ++it) {
278 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54279 item.storage_type = WebDragData::Item::kStorageTypeFilename;
280 item.filename_data = blink::FilePathToWebString(it->path);
281 item.display_name_data =
kinukoa4293022017-01-27 06:43:25282 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59283 item_list.push_back(item);
284 }
285
286 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
287 drop_data.file_system_files.begin();
288 it != drop_data.file_system_files.end();
289 ++it) {
290 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54291 item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile;
292 item.file_system_url = it->url;
293 item.file_system_file_size = it->size;
294 item.file_system_id = blink::WebString::FromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59295 item_list.push_back(item);
296 }
297
298 for (std::map<base::string16, base::string16>::const_iterator it =
299 drop_data.custom_data.begin();
300 it != drop_data.custom_data.end();
301 ++it) {
302 WebDragData::Item item;
Blink Reformat1c4d759e2017-04-09 16:34:54303 item.storage_type = WebDragData::Item::kStorageTypeString;
304 item.string_type = WebString::FromUTF16(it->first);
305 item.string_data = WebString::FromUTF16(it->second);
paulmeyer90f6c31d2016-11-12 00:17:59306 item_list.push_back(item);
307 }
308
309 WebDragData result;
Blink Reformat1c4d759e2017-04-09 16:34:54310 result.Initialize();
311 result.SetItems(item_list);
312 result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59313 return result;
314}
315
lfg1568d112016-08-30 16:06:29316content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
317 nullptr;
318
319content::RenderWidget::RenderWidgetInitializedCallback
320 g_render_widget_initialized = nullptr;
321
dtapuskac4dd5be2016-10-25 15:11:10322ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
323 // Check the type is in the range representable by ui::TextInputType.
324 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
325 << "blink::WebTextInputType and ui::TextInputType not synchronized";
326 return static_cast<ui::TextInputType>(type);
327}
328
329ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
330 // Check the mode is in the range representable by ui::TextInputMode.
331 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
332 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
333 return static_cast<ui::TextInputMode>(mode);
334}
335
[email protected]b256eca2013-07-11 10:57:40336} // namespace
337
[email protected]b2e4c70132013-10-03 02:07:51338// RenderWidget ---------------------------------------------------------------
339
nick8331f8ad2016-11-15 20:42:45340RenderWidget::RenderWidget(int32_t widget_routing_id,
341 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36342 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27343 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04344 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03345 bool hidden,
Dave Tapuska1bdf1832017-07-07 18:07:19346 bool never_visible,
347 mojom::WidgetRequest widget_request)
nick8331f8ad2016-11-15 20:42:45348 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36349 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21350 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44351 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29352 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51353 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09354 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29355 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04356 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39357 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12358 is_fullscreen_granted_(false),
Blink Reformat1c4d759e2017-04-09 16:34:54359 display_mode_(blink::kWebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16360 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48361 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22362 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44363 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20364 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55365 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40366 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20367 text_input_flags_(0),
AJITH KUMAR V041c0b02017-08-08 10:39:20368 next_previous_flags_(kInvalidNextPreviousFlagsValue),
[email protected]86ba5fcb2013-09-04 00:36:53369 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18370 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12371 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48372 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04373 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27374 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18375 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51376 popup_origin_scale_for_emulation_(0.f),
samans26510e442017-06-01 22:29:12377 frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)),
[email protected]a09d53ce2014-01-31 00:46:42378 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08379 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24380 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09381 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47382#if defined(OS_MACOSX)
383 text_input_client_observer_(new TextInputClientObserver(this)),
384#endif
tasakb95dbb50c2017-02-08 18:07:50385 time_to_first_active_paint_recorded_(true),
386 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01387 current_content_source_id_(0),
Dave Tapuska1bdf1832017-07-07 18:07:19388 widget_binding_(this, std::move(widget_request)),
wjmaclean1d970622017-01-21 22:28:24389 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45390 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05391 if (!swapped_out)
392 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27393 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11394
395 // In tests there may not be a RenderThreadImpl.
396 if (RenderThreadImpl::current()) {
397 render_widget_scheduling_state_ = RenderThreadImpl::current()
398 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32399 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11400 render_widget_scheduling_state_->SetHidden(is_hidden_);
401 }
sadrul602ce1362017-01-26 06:41:10402#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14403 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
sadrul602ce1362017-01-26 06:41:10404#endif
initial.commit09911bf2008-07-26 23:55:29405}
406
407RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21408 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16409
dtapuska9ec1a912017-04-21 15:18:31410 if (input_event_queue_)
411 input_event_queue_->ClearClient();
412
[email protected]992db4c2011-05-12 15:37:15413 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02414 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15415 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11416#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14417 // It is possible for a RenderWidget to be destroyed before it was embedded
418 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
419 // explicitly delete it here.
420 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11421#endif
initial.commit09911bf2008-07-26 23:55:29422}
423
[email protected]484955942010-08-19 16:13:18424// static
lfg1568d112016-08-30 16:06:29425void RenderWidget::InstallCreateHook(
426 CreateRenderWidgetFunction create_render_widget,
427 RenderWidgetInitializedCallback render_widget_initialized) {
428 CHECK(!g_create_render_widget && !g_render_widget_initialized);
429 g_create_render_widget = create_render_widget;
430 g_render_widget_initialized = render_widget_initialized;
431}
432
433// static
nickf7b38222016-11-22 21:59:35434RenderWidget* RenderWidget::CreateForPopup(
435 RenderViewImpl* opener,
436 CompositorDependencies* compositor_deps,
437 blink::WebPopupType popup_type,
438 const ScreenInfo& screen_info) {
Dave Tapuska1bdf1832017-07-07 18:07:19439 mojom::WidgetPtr widget_channel;
440 mojom::WidgetRequest widget_channel_request =
441 mojo::MakeRequest(&widget_channel);
442
nick4df698d82016-11-11 20:39:23443 // Do a synchronous IPC to obtain a routing ID.
444 int32_t routing_id = MSG_ROUTING_NONE;
445 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
Dave Tapuska1bdf1832017-07-07 18:07:19446 opener->GetRoutingID(), popup_type, std::move(widget_channel),
447 &routing_id)) {
nick4df698d82016-11-11 20:39:23448 return nullptr;
449 }
450
nick8331f8ad2016-11-15 20:42:45451 scoped_refptr<RenderWidget> widget(
452 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
Dave Tapuska1bdf1832017-07-07 18:07:19453 false, false, false, std::move(widget_channel_request)));
nickf7b38222016-11-22 21:59:35454 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24455 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35456 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23457 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
458 return widget.get();
initial.commit09911bf2008-07-26 23:55:29459}
460
[email protected]484955942010-08-19 16:13:18461// static
kenrba7199832015-01-22 23:44:59462RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23463 int widget_routing_id,
kenrba7199832015-01-22 23:44:59464 bool hidden,
ccameron2f451532016-09-07 21:49:27465 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59466 CompositorDependencies* compositor_deps,
467 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23468 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55469 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
470 // same routing ID for both the view routing ID and the main frame widget
471 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23472 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55473 if (view) {
avi8a45c1092016-03-01 16:12:34474 view->AttachWebFrameWidget(
475 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
476 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55477 }
dcheng35d31c112015-07-22 00:17:36478 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29479 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45480 ? g_create_render_widget(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)
483 : new RenderWidget(widget_routing_id, compositor_deps,
Blink Reformat1c4d759e2017-04-09 16:34:54484 blink::kWebPopupTypeNone, screen_info, false,
nick8331f8ad2016-11-15 20:42:45485 hidden, false));
simonhong628f9812015-04-27 23:13:20486 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23487 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59488 // this function returns.
nickf7b38222016-11-22 21:59:35489 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23490 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
491
492 if (g_render_widget_initialized)
493 g_render_widget_initialized(widget.get());
494 return widget.get();
kenrba7199832015-01-22 23:44:59495}
496
497// static
lfgcaab5142016-02-26 19:06:52498blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08499 RenderWidget* render_widget,
500 blink::WebLocalFrame* frame) {
Blink Reformat1c4d759e2017-04-09 16:34:54501 return blink::WebFrameWidget::Create(render_widget, frame);
dchengda9b4bb2015-07-20 20:58:08502}
503
504// static
kenrba7199832015-01-22 23:44:59505blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18506 switch (render_widget->popup_type_) {
Blink Reformat1c4d759e2017-04-09 16:34:54507 case blink::kWebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18508 break;
Blink Reformat1c4d759e2017-04-09 16:34:54509 case blink::kWebPopupTypePage:
510 return WebPagePopup::Create(render_widget);
[email protected]484955942010-08-19 16:13:18511 default:
512 NOTREACHED();
513 }
514 return NULL;
515}
516
dchengda9b4bb2015-07-20 20:58:08517void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32518 OnClose();
kenrba7199832015-01-22 23:44:59519}
520
alexmos78c9c0d2016-10-14 18:57:03521void RenderWidget::SetSwappedOut(bool is_swapped_out) {
522 // We should only toggle between states.
523 DCHECK(is_swapped_out_ != is_swapped_out);
524 is_swapped_out_ = is_swapped_out;
525
526 // If we are swapping out, we will call ReleaseProcess, allowing the process
527 // to exit if all of its RenderViews are swapped out. We wait until the
528 // WasSwappedOut call to do this, to allow the unload handler to finish.
529 // If we are swapping in, we call AddRefProcess to prevent the process from
530 // exiting.
531 if (!is_swapped_out_)
532 RenderProcess::current()->AddRefProcess();
533}
534
nickf7b38222016-11-22 21:59:35535void RenderWidget::Init(const ShowCallback& show_callback,
536 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21537 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23538 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29539
sadrul9fe48922017-01-23 18:59:49540 input_handler_ = base::MakeUnique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45541
Dave Tapuska9db80842017-07-24 17:24:26542 if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) {
543 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
544
545 widget_input_handler_manager_ = new WidgetInputHandlerManager(
546 weak_ptr_factory_.GetWeakPtr(), RenderThread::Get()->GetChannel(),
547 render_thread_impl && compositor_
548 ? render_thread_impl->compositor_task_runner()
549 : nullptr,
550 render_thread_impl ? render_thread_impl->GetRendererScheduler()
551 : nullptr);
552 }
553
nickf7b38222016-11-22 21:59:35554 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29555
lfg8ff33912016-09-13 20:59:21556 webwidget_internal_ = web_widget;
557 webwidget_mouse_lock_target_.reset(
558 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21559 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29560
nick4df698d82016-11-11 20:39:23561 RenderThread::Get()->AddRoute(routing_id_, this);
562 // Take a reference on behalf of the RenderThread. This will be balanced
563 // when we receive ViewMsg_Close.
564 AddRef();
565 if (RenderThreadImpl::current()) {
566 RenderThreadImpl::current()->WidgetCreated();
567 if (is_hidden_)
568 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29569 }
570}
571
[email protected]949b6592014-08-20 13:17:52572void RenderWidget::WasSwappedOut() {
573 // If we have been swapped out and no one else is using this process,
574 // it's safe to exit now.
575 CHECK(is_swapped_out_);
576 RenderProcess::current()->ReleaseProcess();
577}
578
[email protected]b2e4c70132013-10-03 02:07:51579void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39580 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51581 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43582 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
Pavel Feldmancc099f72017-07-20 23:09:00583 popup_screen_origin_for_emulation_ =
584 gfx::Point(emulator->original_screen_rect().origin().x(),
585 emulator->original_screen_rect().origin().y());
[email protected]5f75aa42014-04-01 23:00:56586 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27587 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51588}
589
[email protected]2d6836f42014-07-02 17:25:31590gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
591 if (screen_metrics_emulator_)
592 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
593 return anchor;
594}
595
thakis18e426412017-03-15 12:06:37596#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51597void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39598 ExternalPopupMenu* popup,
599 RenderWidgetScreenMetricsEmulator* emulator) {
Pavel Feldmancc099f72017-07-20 23:09:00600 popup->SetOriginScaleForEmulation(emulator->scale());
[email protected]b2e4c70132013-10-03 02:07:51601}
[email protected]53907862014-03-25 15:42:40602#endif
[email protected]b2e4c70132013-10-03 02:07:51603
604void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
605 if (screen_metrics_emulator_)
606 screen_metrics_emulator_->OnShowContextMenu(params);
607}
608
[email protected]a95986a82010-12-24 06:19:28609bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47610#if defined(OS_MACOSX)
611 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
612 return text_input_client_observer_->OnMessageReceived(message);
613#endif
lfgbee1e0a2016-06-08 21:24:21614 if (mouse_lock_dispatcher_ &&
615 mouse_lock_dispatcher_->OnMessageReceived(message))
616 return true;
617
[email protected]a95986a82010-12-24 06:19:28618 bool handled = true;
619 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15620 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22621 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
622 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22623 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29624 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
625 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
626 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15627 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46628 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
629 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15630 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35631 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
632 OnSyntheticGestureCompleted)
wjmacleanee244e02017-05-26 21:06:07633 IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu)
[email protected]a95986a82010-12-24 06:19:28634 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28635 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20636 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
637 OnEnableDeviceEmulation)
638 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
639 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28640 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41641 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25642 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28643 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
644 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03645 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48646 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
647 OnSetViewportIntersection)
kenrb04323782017-06-23 01:23:32648 IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert)
lfg43e08e62016-02-03 18:51:37649 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
650 OnWaitNextFrameForTests)
ekaramadc9b70a72017-03-23 16:14:23651 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates,
652 OnRequestCompositionUpdates)
paulmeyer90f6c31d2016-11-12 00:17:59653 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
654 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
655 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
656 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21657 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
658 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
659 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21660#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39661 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
662 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21663#endif
[email protected]a95986a82010-12-24 06:19:28664 IPC_MESSAGE_UNHANDLED(handled = false)
665 IPC_END_MESSAGE_MAP()
666 return handled;
667}
initial.commit09911bf2008-07-26 23:55:29668
669bool RenderWidget::Send(IPC::Message* message) {
Nasko Oskovf97e8b02017-07-25 02:45:42670 // Don't send any messages after the browser has told us to close, and filter
671 // most outgoing messages while swapped out.
672 if ((is_swapped_out_ &&
673 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
674 closing_) {
initial.commit09911bf2008-07-26 23:55:29675 delete message;
676 return false;
677 }
678
679 // If given a messsage without a routing ID, then assign our routing ID.
680 if (message->routing_id() == MSG_ROUTING_NONE)
681 message->set_routing_id(routing_id_);
682
[email protected]380244092011-10-07 17:26:27683 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44684}
685
dtapuska014ed082016-11-11 21:58:48686void RenderWidget::SendOrCrash(IPC::Message* message) {
687 bool result = Send(message);
688 CHECK(closing_ || result) << "Failed to send message";
689}
690
ekaramad5aff1942017-01-06 01:26:35691bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26692 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
693 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
694 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
695 // will be processed regardless of page focus. We should revisit this after
696 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
Blink Reformat1c4d759e2017-04-09 16:34:54697 return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() &&
ekaramadb6483a052017-02-10 02:23:26698 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35699}
700
bokanc007c3a2015-02-03 07:15:56701void RenderWidget::SetWindowRectSynchronously(
702 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39703 ResizeParams params;
704 params.screen_info = screen_info_;
705 params.new_size = new_window_rect.size();
706 params.physical_backing_size =
707 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39708 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39709 params.is_fullscreen_granted = is_fullscreen_granted_;
710 params.display_mode = display_mode_;
711 params.needs_resize_ack = false;
712 Resize(params);
713
bokanc007c3a2015-02-03 07:15:56714 view_screen_rect_ = new_window_rect;
715 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02716 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56717 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02718}
719
initial.commit09911bf2008-07-26 23:55:29720void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32721 DCHECK(content::RenderThread::Get());
722 if (closing_)
723 return;
724 NotifyOnClose();
725 closing_ = true;
726
727 // Browser correspondence is no longer needed at this point.
728 if (routing_id_ != MSG_ROUTING_NONE) {
729 RenderThread::Get()->RemoveRoute(routing_id_);
730 SetHidden(false);
731 if (RenderThreadImpl::current())
732 RenderThreadImpl::current()->WidgetDestroyed();
733 }
734
735 if (for_oopif_) {
736 // Widgets for frames may be created and closed at any time while the frame
737 // is alive. However, the closing process must happen synchronously. Frame
738 // widget and frames hold pointers to each other. If Close() is deferred to
739 // the message loop like in the non-frame widget case, WebWidget::close()
740 // can end up accessing members of an already-deleted frame.
741 Close();
742 } else {
743 // If there is a Send call on the stack, then it could be dangerous to close
744 // now. Post a task that only gets invoked when there are no nested message
745 // loops.
746 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
747 FROM_HERE, base::Bind(&RenderWidget::Close, this));
748 }
749
750 // Balances the AddRef taken when we called AddRoute.
751 Release();
initial.commit09911bf2008-07-26 23:55:29752}
753
fsamuel664e8b62016-01-20 19:54:01754void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04755 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32756 return;
757
[email protected]b2e4c70132013-10-03 02:07:51758 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39759 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51760 return;
761 }
762
mfomitchev2600fd7c2016-02-17 20:53:39763 Resize(params);
initial.commit09911bf2008-07-26 23:55:29764}
765
dgozman9260b0a12015-03-16 13:45:20766void RenderWidget::OnEnableDeviceEmulation(
Nasko Oskovf97e8b02017-07-25 02:45:42767 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39768 if (!screen_metrics_emulator_) {
769 ResizeParams resize_params;
770 resize_params.screen_info = screen_info_;
771 resize_params.new_size = size_;
772 resize_params.physical_backing_size = physical_backing_size_;
773 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39774 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
775 resize_params.display_mode = display_mode_;
776 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
777 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18778 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39779 } else {
dgozman9260b0a12015-03-16 13:45:20780 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39781 }
dgozman9260b0a12015-03-16 13:45:20782}
783
784void RenderWidget::OnDisableDeviceEmulation() {
785 screen_metrics_emulator_.reset();
786}
787
initial.commit09911bf2008-07-26 23:55:29788void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31789 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29790 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03791 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55792 for (auto& observer : render_frames_)
793 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29794}
795
[email protected]3399dd822014-08-09 11:14:24796void RenderWidget::OnWasShown(bool needs_repainting,
797 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41798 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29799 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21800 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29801 return;
802
tasakb95dbb50c2017-02-08 18:07:50803 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29804 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03805 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55806 for (auto& observer : render_frames_)
807 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29808
[email protected]8a23afb32014-04-30 22:40:23809 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29810 return;
initial.commit09911bf2008-07-26 23:55:29811
[email protected]3399dd822014-08-09 11:14:24812 if (compositor_) {
813 ui::LatencyInfo swap_latency_info(latency_info);
danakj87fbafb2017-04-04 16:54:11814 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor =
815 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info);
816 // Force this SwapPromiseMonitor to trigger and insert a SwapPromise.
Blink Reformat1c4d759e2017-04-09 16:34:54817 compositor_->SetNeedsBeginFrame();
[email protected]3399dd822014-08-09 11:14:24818 }
initial.commit09911bf2008-07-26 23:55:29819}
820
[email protected]53d3f302009-12-21 04:42:05821void RenderWidget::OnRequestMoveAck() {
822 DCHECK(pending_window_rect_count_);
823 pending_window_rect_count_--;
824}
825
[email protected]ed7defa2013-03-12 21:29:59826GURL RenderWidget::GetURLForGraphicsContext3D() {
827 return GURL();
[email protected]65225772011-05-12 21:10:24828}
829
nzolghadr5d8596502017-01-23 22:59:35830void RenderWidget::OnHandleInputEvent(
831 const blink::WebInputEvent* input_event,
832 const std::vector<const blink::WebInputEvent*>& coalesced_events,
833 const ui::LatencyInfo& latency_info,
834 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23835 if (!input_event)
836 return;
nzolghadr5d8596502017-01-23 22:59:35837
Dave Tapuskaea83d3bd2017-06-13 16:14:55838 HandledEventCallback callback;
839 if (dispatch_type == DISPATCH_TYPE_BLOCKING) {
840 callback = base::Bind(
841 &RenderWidget::SendInputEventAck, this, input_event->GetType(),
842 ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event));
843 }
nzolghadr5d8596502017-01-23 22:59:35844 input_handler_->HandleInputEvent(
845 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
Dave Tapuskaea83d3bd2017-06-13 16:14:55846 latency_info, std::move(callback));
fsamuel78f86e42016-01-20 04:10:23847}
848
Dave Tapuskaea83d3bd2017-06-13 16:14:55849void RenderWidget::HandleInputEvent(
dtapuska9ec1a912017-04-21 15:18:31850 const blink::WebCoalescedInputEvent& input_event,
851 const ui::LatencyInfo& latency_info,
Dave Tapuskaea83d3bd2017-06-13 16:14:55852 HandledEventCallback callback) {
853 input_handler_->HandleInputEvent(input_event, latency_info,
854 std::move(callback));
dtapuska9ec1a912017-04-21 15:18:31855}
856
Dave Tapuskaea83d3bd2017-06-13 16:14:55857void RenderWidget::SendInputEventAck(
858 blink::WebInputEvent::Type type,
859 uint32_t touch_event_id,
860 InputEventAckState ack_state,
861 const ui::LatencyInfo& latency_info,
862 std::unique_ptr<ui::DidOverscrollParams> overscroll_params) {
863 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state,
864 latency_info, std::move(overscroll_params), touch_event_id);
dtapuska9ec1a912017-04-21 15:18:31865 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
866}
867
dtapuska9d46ef7d2017-05-26 19:06:06868scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() {
869 return input_event_queue_;
870}
871
fsamuel78f86e42016-01-20 04:10:23872void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21873 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54874 GetWebWidget()->SetCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23875}
876
877void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21878 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54879 GetWebWidget()->MouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23880}
881
alexmos56567492016-09-13 00:52:46882void RenderWidget::OnSetEditCommandsForNextKeyEvent(
883 const EditCommands& edit_commands) {
884 edit_commands_ = edit_commands;
885}
886
fsamuel78f86e42016-01-20 04:10:23887void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08888 has_focus_ = enable;
889
lfg8ff33912016-09-13 20:59:21890 if (GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:54891 GetWebWidget()->SetFocus(enable);
lfge0c2792ec2016-05-11 18:52:08892
ericwilligers88e69742016-10-17 19:29:55893 for (auto& observer : render_frames_)
894 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23895}
896
dtapuska3d5624d32016-08-30 04:34:00897void RenderWidget::SetNeedsMainFrame() {
898 RenderWidgetCompositor* rwc = compositor();
899 if (!rwc)
900 return;
Blink Reformat1c4d759e2017-04-09 16:34:54901 rwc->SetNeedsBeginFrame();
dtapuska3d5624d32016-08-30 04:34:00902}
903
fsamuel78f86e42016-01-20 04:10:23904///////////////////////////////////////////////////////////////////////////////
905// RenderWidgetCompositorDelegate
906
907void RenderWidget::ApplyViewportDeltas(
908 const gfx::Vector2dF& inner_delta,
909 const gfx::Vector2dF& outer_delta,
910 const gfx::Vector2dF& elastic_overscroll_delta,
911 float page_scale,
912 float top_controls_delta) {
Blink Reformat1c4d759e2017-04-09 16:34:54913 GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta,
lfg8ff33912016-09-13 20:59:21914 elastic_overscroll_delta, page_scale,
915 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23916}
917
sahel1b47fda72017-03-28 17:03:07918void RenderWidget::RecordWheelAndTouchScrollingCount(
919 bool has_scrolled_by_wheel,
920 bool has_scrolled_by_touch) {
Blink Reformat1c4d759e2017-04-09 16:34:54921 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
sahel1b47fda72017-03-28 17:03:07922 has_scrolled_by_touch);
923}
924
fsamuel78f86e42016-01-20 04:10:23925void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska9ec1a912017-04-21 15:18:31926 if (input_event_queue_) {
927 input_event_queue_->DispatchRafAlignedInput(
928 ui::EventTimeStampFromSeconds(frame_time_sec));
929 }
dtapuska3d5624d32016-08-30 04:34:00930
Blink Reformat1c4d759e2017-04-09 16:34:54931 GetWebWidget()->BeginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23932}
933
danakjc7afae52017-06-20 21:12:41934void RenderWidget::RequestNewLayerTreeFrameSink(
fsamuelcf3002e2017-03-20 23:13:47935 bool fallback,
danakjc7afae52017-06-20 21:12:41936 const LayerTreeFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21937 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03938 // For widgets that are never visible, we don't start the compositor, so we
danakjc7afae52017-06-20 21:12:41939 // never get a request for a cc::LayerTreeFrameSink.
sievers71c62dd52015-10-07 01:44:39940 DCHECK(!compositor_never_visible_);
danakjc7afae52017-06-20 21:12:41941 RenderThreadImpl::current()->RequestNewLayerTreeFrameSink(
fsamuelcf3002e2017-03-20 23:13:47942 fallback, routing_id_, frame_swap_message_queue_,
943 GetURLForGraphicsContext3D(), callback);
[email protected]ba91a792013-02-06 09:48:28944}
945
fsamuel78f86e42016-01-20 04:10:23946void RenderWidget::DidCommitAndDrawCompositorFrame() {
947 // NOTE: Tests may break if this event is renamed or moved. See
948 // tab_capture_performancetest.cc.
949 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08950
ericwilligers88e69742016-10-17 19:29:55951 for (auto& observer : render_frames_)
952 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08953
fsamuel78f86e42016-01-20 04:10:23954 // Notify subclasses that we initiated the paint operation.
955 DidInitiatePaint();
956}
957
958void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55959 for (auto& observer : render_frames_)
960 observer.DidCommitCompositorFrame();
961 for (auto& observer : render_frame_proxies_)
962 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23963}
964
965void RenderWidget::DidCompletePageScaleAnimation() {}
966
danakj6c872fc02016-10-22 04:29:49967void RenderWidget::DidReceiveCompositorFrameAck() {
968 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23969
pimanbfb2ceb2016-03-18 21:32:58970 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23971 return;
972 }
973
974 ViewHostMsg_UpdateRect_Params params;
975 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23976 params.flags = next_paint_flags_;
977
978 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
979 next_paint_flags_ = 0;
980 need_update_rect_for_auto_resize_ = false;
981}
982
fsamuel78f86e42016-01-20 04:10:23983bool RenderWidget::IsClosing() const {
984 return host_closing_;
985}
986
danakj53eccbc2016-03-02 22:51:07987void RenderWidget::RequestScheduleAnimation() {
Blink Reformat1c4d759e2017-04-09 16:34:54988 ScheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29989}
990
fsamuel78f86e42016-01-20 04:10:23991void RenderWidget::UpdateVisualState() {
Blink Reformat1c4d759e2017-04-09 16:34:54992 GetWebWidget()->UpdateAllLifecyclePhases();
993 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
tasakb95dbb50c2017-02-08 18:07:50994
995 if (time_to_first_active_paint_recorded_)
996 return;
997
998 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
999 if (!render_thread_impl->NeedsToRecordFirstActivePaint())
1000 return;
1001
1002 time_to_first_active_paint_recorded_ = true;
1003 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
1004 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
1005 sample);
fsamuel78f86e42016-01-20 04:10:231006}
1007
1008void RenderWidget::WillBeginCompositorFrame() {
1009 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1010
Blink Reformat1c4d759e2017-04-09 16:34:541011 GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true);
alancutter317a8e02017-04-05 10:09:291012
dglazkov06854c5c2016-08-31 00:19:591013 // The UpdateTextInputState can result in further layout and possibly
1014 // enable GPU acceleration so they need to be called before any painting
1015 // is done.
changwan75e3b2072017-01-16 02:55:001016 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:591017 UpdateSelectionBounds();
1018
ericwilligers88e69742016-10-17 19:29:551019 for (auto& observer : render_frame_proxies_)
1020 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:291021}
1022
jbroman6ccbc7d472016-07-27 04:45:411023std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
Fady Samueldfecb7d2017-07-26 11:41:041024 std::unique_ptr<viz::CopyOutputRequest> request) {
jbroman6ccbc7d472016-07-27 04:45:411025 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
1026 routing_id_, std::move(request));
1027}
1028
fsamuel72464894f2015-12-15 06:59:311029///////////////////////////////////////////////////////////////////////////////
1030// RenderWidgetInputHandlerDelegate
1031
avid7d6b2e2016-03-04 19:41:171032void RenderWidget::FocusChangeComplete() {
ekaramad27ca69b12017-04-20 18:34:291033 if (!GetWebWidget()->IsWebFrameWidget())
1034 return;
1035 blink::WebLocalFrame* focused =
1036 static_cast<blink::WebFrameWidget*>(GetWebWidget())
1037 ->LocalRoot()
1038 ->View()
1039 ->FocusedFrame();
1040 if (focused && focused->AutofillClient())
1041 focused->AutofillClient()->DidCompleteFocusChangeInFrame();
avid7d6b2e2016-03-04 19:41:171042}
fsamuel72464894f2015-12-15 06:59:311043
1044bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:171045 if (owner_delegate_)
1046 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
1047
fsamuel72464894f2015-12-15 06:59:311048 return true;
1049}
1050
dtapuska1827dd22016-03-11 15:24:591051void RenderWidget::ObserveGestureEventAndResult(
1052 const blink::WebGestureEvent& gesture_event,
1053 const gfx::Vector2dF& unused_delta,
1054 bool event_processed) {
1055 if (!compositor_deps_->IsElasticOverscrollEnabled())
1056 return;
1057
1058 cc::InputHandlerScrollResult scroll_result;
1059 scroll_result.did_scroll = event_processed;
1060 scroll_result.did_overscroll_root = !unused_delta.IsZero();
1061 scroll_result.unused_scroll_delta = unused_delta;
1062
1063 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1064 InputHandlerManager* input_handler_manager =
1065 render_thread ? render_thread->input_handler_manager() : NULL;
1066 if (input_handler_manager) {
1067 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1068 routing_id_, gesture_event, scroll_result);
Dave Tapuska9db80842017-07-24 17:24:261069 } else if (widget_input_handler_manager_) {
1070 widget_input_handler_manager_->ObserveGestureEventOnMainThread(
1071 gesture_event, scroll_result);
dtapuska1827dd22016-03-11 15:24:591072 }
1073}
1074
avid7d6b2e2016-03-04 19:41:171075void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461076 ClearEditCommands();
1077}
1078
1079void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1080 const std::string& value) {
1081 ClearEditCommands();
1082 edit_commands_.emplace_back(name, value);
1083}
1084
1085void RenderWidget::ClearEditCommands() {
1086 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171087}
fsamuel72464894f2015-12-15 06:59:311088
chongza8ba91fc2016-08-16 21:39:171089void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:311090 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1091}
1092
fsamuele8326c742016-01-12 00:49:391093void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1094 // Nothing to do here. RenderWidget created the |input_handler| and will take
1095 // ownership of it. We just verify here that we don't already have an input
1096 // handler.
1097 DCHECK(!input_handler_);
1098}
1099
changwan75e3b2072017-01-16 02:55:001100void RenderWidget::ShowVirtualKeyboard() {
1101 UpdateTextInputStateInternal(true, false);
1102}
1103
changwan62f57292017-02-17 08:28:251104void RenderWidget::ClearTextInputState() {
1105 text_input_info_ = blink::WebTextInputInfo();
1106 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1107 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1108 can_compose_inline_ = false;
1109 text_input_flags_ = 0;
AJITH KUMAR V041c0b02017-08-08 10:39:201110 next_previous_flags_ = kInvalidNextPreviousFlagsValue;
changwan62f57292017-02-17 08:28:251111}
1112
changwan75e3b2072017-01-16 02:55:001113void RenderWidget::UpdateTextInputState() {
1114 UpdateTextInputStateInternal(false, false);
1115}
1116
1117void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1118 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311119 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001120
fsamuel72464894f2015-12-15 06:59:311121 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001122 DCHECK(!reply_to_request);
1123 // show_virtual_keyboard should still be effective even if it was set inside
1124 // the IME
fsamuel72464894f2015-12-15 06:59:311125 // event guard.
changwan75e3b2072017-01-16 02:55:001126 if (show_virtual_keyboard)
1127 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311128 return;
1129 }
1130
dglazkov97b6c2b2016-10-25 17:35:551131 ui::TextInputType new_type = GetTextInputType();
1132 if (IsDateTimeInput(new_type))
1133 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311134
dglazkov97b6c2b2016-10-25 17:35:551135 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351136 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541137 new_info = controller->TextInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101138 const ui::TextInputMode new_mode =
Blink Reformat1c4d759e2017-04-09 16:34:541139 ConvertWebTextInputMode(new_info.input_mode);
fsamuel72464894f2015-12-15 06:59:311140
1141 bool new_can_compose_inline = CanComposeInline();
1142
1143 // Only sends text input params if they are changed or if the ime should be
1144 // shown.
changwan75e3b2072017-01-16 02:55:001145 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561146 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1147 text_input_info_ != new_info ||
1148 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381149 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551150 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311151 params.mode = new_mode;
1152 params.flags = new_info.flags;
AJITH KUMAR V041c0b02017-08-08 10:39:201153 if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) {
1154 // Due to a focus change, values will be reset by the frame.
1155 // That case we only need fresh NEXT/PREVIOUS information.
1156 // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous
1157 // focusable status is changed.
1158 if (auto* controller = GetInputMethodController()) {
1159 next_previous_flags_ =
1160 controller->ComputeWebTextInputNextPreviousFlags();
1161 } else {
1162 // For safety in case GetInputMethodController() is null, because -1 is
1163 // invalid value to send to browser process.
1164 next_previous_flags_ = 0;
1165 }
1166 }
1167 params.flags |= next_previous_flags_;
Blink Reformat1c4d759e2017-04-09 16:34:541168 params.value = new_info.value.Utf8();
1169 params.selection_start = new_info.selection_start;
1170 params.selection_end = new_info.selection_end;
1171 params.composition_start = new_info.composition_start;
1172 params.composition_end = new_info.composition_end;
fsamuel72464894f2015-12-15 06:59:311173 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001174 // TODO(changwan): change instances of show_ime_if_needed to
1175 // show_virtual_keyboard.
1176 params.show_ime_if_needed = show_virtual_keyboard;
1177 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311178 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1179
1180 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551181 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311182 text_input_mode_ = new_mode;
1183 can_compose_inline_ = new_can_compose_inline;
1184 text_input_flags_ = new_info.flags;
1185 }
1186}
1187
1188bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581189 possible_drag_event_info_.event_source =
1190 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1191 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541192 gfx::Point(event.global_x, event.global_y);
avid7d6b2e2016-03-04 19:41:171193
fsamuel72464894f2015-12-15 06:59:311194 return false;
1195}
1196
1197bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551198 for (auto& observer : render_frames_)
1199 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081200
paulmeyer6ef5a792016-11-08 20:33:581201 possible_drag_event_info_.event_source =
1202 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1203 possible_drag_event_info_.event_location =
Blink Reformat1c4d759e2017-04-09 16:34:541204 gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y);
paulmeyer6ef5a792016-11-08 20:33:581205
avid7d6b2e2016-03-04 19:41:171206 if (owner_delegate_)
1207 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1208
fsamuel72464894f2015-12-15 06:59:311209 return false;
[email protected]fd847792013-10-24 17:12:351210}
1211
initial.commit09911bf2008-07-26 23:55:291212///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391213// RenderWidgetScreenMetricsDelegate
1214
1215void RenderWidget::Redraw() {
1216 set_next_paint_is_resize_ack();
1217 if (compositor_)
1218 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1219}
1220
bokanc63441c2016-04-27 15:49:121221void RenderWidget::ResizeWebWidget() {
Blink Reformat1c4d759e2017-04-09 16:34:541222 GetWebWidget()->Resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121223}
1224
1225gfx::Size RenderWidget::GetSizeForWebWidget() const {
1226 if (IsUseZoomForDSFEnabled())
1227 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1228
1229 return size_;
1230}
1231
mfomitchev2600fd7c2016-02-17 20:53:391232void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581233 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271234 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1235 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581236
mfomitchev2600fd7c2016-02-17 20:53:391237 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581238
ccameron2f451532016-09-07 21:49:271239 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1240 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581241 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581242 }
mfomitchev2600fd7c2016-02-17 20:53:391243
1244 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1245 // A resize ack shouldn't be requested if we have not ACK'd the previous
1246 // one.
1247 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1248 }
1249
1250 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211251 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391252 return;
1253
fsamuelca02c4e2017-05-09 13:34:141254 if (params.local_surface_id)
1255 local_surface_id_ = *params.local_surface_id;
1256
ianwene5fc5782016-08-18 04:05:151257 if (compositor_) {
fsamuelca02c4e2017-05-09 13:34:141258 // If surface synchronization is enable, then this will use the provided
1259 // |local_surface_id_| to submit the next generated CompositorFrame.
1260 // If the ID is not valid, then the compositor will defer commits until
1261 // it receives a valid surface ID. This is a no-op if surface
1262 // synchronization is disabled.
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271263 compositor_->SetViewportSize(params.physical_backing_size,
1264 local_surface_id_);
1265 compositor_->SetBrowserControlsHeight(
1266 params.top_controls_height, params.bottom_controls_height,
1267 params.browser_controls_shrink_blink_size);
1268 compositor_->SetRasterColorSpace(
1269 screen_info_.color_space.GetRasterColorSpace());
ianwene5fc5782016-08-18 04:05:151270 }
mfomitchev2600fd7c2016-02-17 20:53:391271
mfomitchev2600fd7c2016-02-17 20:53:391272 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391273
1274 // NOTE: We may have entered fullscreen mode without changing our size.
1275 bool fullscreen_change =
1276 is_fullscreen_granted_ != params.is_fullscreen_granted;
1277 is_fullscreen_granted_ = params.is_fullscreen_granted;
1278 display_mode_ = params.display_mode;
1279
bokanc63441c2016-04-27 15:49:121280 size_ = params.new_size;
1281 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391282
bokanc63441c2016-04-27 15:49:121283 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221284
mfomitchev2600fd7c2016-02-17 20:53:391285 WebSize visual_viewport_size;
1286
1287 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181288 visual_viewport_size = gfx::ScaleToCeiledSize(
1289 params.visible_viewport_size,
1290 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391291 } else {
1292 visual_viewport_size = visible_viewport_size_;
1293 }
1294
Blink Reformat1c4d759e2017-04-09 16:34:541295 GetWebWidget()->ResizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391296
bokanc63441c2016-04-27 15:49:121297 // When resizing, we want to wait to paint before ACK'ing the resize. This
1298 // ensures that we only resize as fast as we can paint. We only need to
1299 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391300 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1301 // In this case there is no paint/composite and therefore no
1302 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1303 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1304 DCHECK(!params.needs_resize_ack);
1305 }
1306
1307 // Send the Resize_ACK flag once we paint again if requested.
1308 if (params.needs_resize_ack)
1309 set_next_paint_is_resize_ack();
1310
1311 if (fullscreen_change)
1312 DidToggleFullscreen();
1313
engedy6cb63c92016-02-23 14:14:581314 if (orientation_changed)
1315 OnOrientationChange();
1316
mfomitchev2600fd7c2016-02-17 20:53:391317 // If a resize ack is requested and it isn't set-up, then no more resizes will
1318 // come in and in general things will go wrong.
1319 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1320}
1321
1322void RenderWidget::SetScreenMetricsEmulationParameters(
1323 bool enabled,
1324 const blink::WebDeviceEmulationParams& params) {
1325 // This is only supported in RenderView.
1326 NOTREACHED();
1327}
1328
1329void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1330 const gfx::Rect& window_screen_rect) {
1331 view_screen_rect_ = view_screen_rect;
1332 window_screen_rect_ = window_screen_rect;
1333}
1334
1335///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461336// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291337
[email protected]3a1c8a8032013-03-18 22:35:321338void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401339 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271340 // A new LocalSurfaceId will need to be allocated by the browser for the new
1341 // size.
1342 local_surface_id_ = viz::LocalSurfaceId();
[email protected]97e1bf72013-03-06 14:06:051343 if (compositor_)
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271344 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
[email protected]97e1bf72013-03-06 14:06:051345}
1346
Blink Reformat1c4d759e2017-04-09 16:34:541347blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221348 DCHECK(!host_closing_);
1349
loyso6e6efc42017-01-21 02:23:031350 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1351 auto animation_host = cc::AnimationHost::CreateMainInstance();
1352
wjmacleana755e302017-04-20 00:43:161353 // Oopif status must be set before the LayerTreeHost is created.
1354 compositor_->SetIsForOopif(for_oopif_);
loyso6e6efc42017-01-21 02:23:031355 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1356 compositor_.get(), compositor_.get(), animation_host.get(),
1357 compositor_deps_, device_scale_factor_, screen_info_);
1358 compositor_->Initialize(std::move(layer_tree_host),
1359 std::move(animation_host));
1360
Sadrul Habib Chowdhury04d5dd4d2017-08-10 01:59:271361 compositor_->SetViewportSize(physical_backing_size_, local_surface_id_);
oshimad5279032015-12-16 18:22:331362 OnDeviceScaleFactorChanged();
ccameron01912992017-05-23 07:34:031363 compositor_->SetRasterColorSpace(
Christopher Camerona1ea2b72017-08-02 01:59:091364 screen_info_.color_space.GetRasterColorSpace());
kenrb5d78b842017-03-06 21:06:011365 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391366 // For background pages and certain tests, we don't want to trigger
danakjc7afae52017-06-20 21:12:411367 // LayerTreeFrameSink creation.
dtapuskab08611f2017-04-24 16:10:221368 bool should_generate_frame_sink =
1369 !compositor_never_visible_ && RenderThreadImpl::current();
1370 if (!should_generate_frame_sink)
sievers71c62dd52015-10-07 01:44:391371 compositor_->SetNeverVisible();
1372
pimanc4af3072015-10-02 03:45:591373 StartCompositor();
staraz067f58242016-11-07 21:06:411374 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1375 compositor_->SetFrameSinkId(
Fady Samueld5c26182017-07-12 02:43:331376 viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371377
wjmaclean1d970622017-01-21 22:28:241378 RenderThreadImpl* render_thread = RenderThreadImpl::current();
Dave Tapuska9db80842017-07-24 17:24:261379 if (render_thread) {
dtapuska9ec1a912017-04-21 15:18:311380 input_event_queue_ = new MainThreadEventQueue(
1381 this, render_thread->GetRendererScheduler()->CompositorTaskRunner(),
dtapuskab08611f2017-04-24 16:10:221382 render_thread->GetRendererScheduler(), should_generate_frame_sink);
Dave Tapuska9db80842017-07-24 17:24:261383
1384 InputHandlerManager* input_handler_manager =
1385 render_thread->input_handler_manager();
1386 if (input_handler_manager) {
1387 input_handler_manager->AddInputHandler(
1388 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1389 weak_ptr_factory_.GetWeakPtr(),
1390 compositor_deps_->IsScrollAnimatorEnabled());
1391 has_added_input_handler_ = true;
1392 }
wjmaclean1d970622017-01-21 22:28:241393 }
1394
loyso50b51c22017-01-10 07:18:371395 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591396}
1397
ennef3c58142014-12-09 21:44:381398void RenderWidget::WillCloseLayerTreeView() {
1399 if (host_closing_)
1400 return;
1401
1402 // Prevent new compositors or output surfaces from being created.
1403 host_closing_ = true;
1404
[email protected]aeeedad2014-08-22 18:16:221405 // Always send this notification to prevent new layer tree views from
1406 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211407 if (blink::WebWidget* widget = GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541408 widget->WillCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221409}
1410
Blink Reformat1c4d759e2017-04-09 16:34:541411void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1412 if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) {
dglazkovf0e1d6d2015-10-10 02:13:481413 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1414 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1415 }
dglazkov79c426102015-08-31 21:22:431416
ericwilligers88e69742016-10-17 19:29:551417 for (auto& observer : render_frames_)
1418 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431419}
1420
[email protected]586871b2014-07-22 17:05:111421// static
dchengcedca5612016-04-09 01:40:151422std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111423 IPC::Message* msg,
1424 MessageDeliveryPolicy policy,
1425 FrameSwapMessageQueue* frame_swap_message_queue,
1426 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111427 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111428 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151429 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1430 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111431 &first_message_for_frame);
1432 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151433 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111434 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061435 return promise;
[email protected]586871b2014-07-22 17:05:111436 }
dcheng4b6b5ff2014-10-16 00:42:061437 return nullptr;
[email protected]586871b2014-07-22 17:05:111438}
1439
1440void RenderWidget::QueueMessage(IPC::Message* msg,
1441 MessageDeliveryPolicy policy) {
1442 // RenderThreadImpl::current() is NULL in some tests.
1443 if (!compositor_ || !RenderThreadImpl::current()) {
1444 Send(msg);
1445 return;
1446 }
1447
dchengcedca5612016-04-09 01:40:151448 std::unique_ptr<cc::SwapPromise> swap_promise =
1449 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111450 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111451 compositor_->GetSourceFrameNumber());
1452
1453 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321454 compositor_->QueueSwapPromise(std::move(swap_promise));
danakj87fbafb2017-04-04 16:54:111455 // Request a main frame. This might either A) request a commit ahead of time
1456 // or B) request a commit which is not needed because there are not pending
1457 // updates. If B) then the frame will be aborted early and the swap promises
1458 // will be broken (see EarlyOut_NoUpdates).
Blink Reformat1c4d759e2017-04-09 16:34:541459 compositor_->SetNeedsBeginFrame();
[email protected]586871b2014-07-22 17:05:111460 }
1461}
1462
Blink Reformat1c4d759e2017-04-09 16:34:541463void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301464 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521465 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181466 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291467 // Only send a SetCursor message if we need to make a change.
1468 if (!current_cursor_.IsEqual(cursor)) {
1469 current_cursor_ = cursor;
1470 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1471 }
1472}
1473
aelias5971e47d2017-06-16 02:39:381474void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) {
1475 Send(new ViewHostMsg_AutoscrollStart(routing_id_, point));
1476}
1477
1478void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) {
1479 Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity));
1480}
1481
1482void RenderWidget::AutoscrollEnd() {
1483 Send(new ViewHostMsg_AutoscrollEnd(routing_id_));
1484}
1485
initial.commit09911bf2008-07-26 23:55:291486// We are supposed to get a single call to Show for a newly created RenderWidget
1487// that was created via RenderWidget::CreateWebView. So, we wait until this
1488// point to dispatch the ShowWidget message.
1489//
1490// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281491// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291492//
Blink Reformat1c4d759e2017-04-09 16:34:541493void RenderWidget::Show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291494 DCHECK(!did_show_) << "received extraneous Show call";
1495 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351496 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291497
[email protected]8de12d942010-11-17 20:42:441498 if (did_show_)
1499 return;
1500
1501 did_show_ = true;
nickf7b38222016-11-22 21:59:351502
1503 // The opener is responsible for actually showing this widget.
1504 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351505 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351506
bokanc007c3a2015-02-03 07:15:561507 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441508 // that's okay. It'll be ignored if as_popup is false, or the browser
1509 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561510 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291511}
1512
[email protected]2533ce12009-05-09 00:02:241513void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381514 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241515 Send(new ViewHostMsg_Close(routing_id_));
1516}
1517
dgozmancf9039cd2015-04-06 12:01:311518void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551519 for (auto& observer : render_frames_)
1520 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311521}
1522
Blink Reformat1c4d759e2017-04-09 16:34:541523void RenderWidget::CloseWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081524 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321525 if (is_swapped_out_) {
1526 // This widget is currently swapped out, and the active widget is in a
1527 // different process. Have the browser route the close request to the
1528 // active widget instead, so that the correct unload handlers are run.
1529 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1530 return;
1531 }
1532
initial.commit09911bf2008-07-26 23:55:291533 // If a page calls window.close() twice, we'll end up here twice, but that's
1534 // OK. It is safe to send multiple Close messages.
1535
[email protected]2533ce12009-05-09 00:02:241536 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1537 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1538 // could be closed before the JS finishes executing. So instead, post a
1539 // message back to the message loop, which won't run until the JS is
1540 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081541 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211542 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291543}
1544
[email protected]9017d7852013-11-21 17:47:351545void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151546 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351547 const SyntheticGestureCompletionCallback& callback) {
1548 DCHECK(!callback.is_null());
1549
1550 pending_synthetic_gesture_callbacks_.push(callback);
1551
1552 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321553 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351554
1555 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1556}
1557
initial.commit09911bf2008-07-26 23:55:291558void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031559 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381560 WillCloseLayerTreeView();
1561 compositor_.reset();
lfg8ff33912016-09-13 20:59:211562 if (webwidget_internal_) {
Blink Reformat1c4d759e2017-04-09 16:34:541563 webwidget_internal_->Close();
lfg8ff33912016-09-13 20:59:211564 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291565 }
1566}
1567
bokan841fdc72016-10-06 00:16:351568void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1569 DCHECK(window_rect);
1570 float scale = popup_origin_scale_for_emulation_;
1571 if (!scale)
1572 return;
1573 window_rect->x =
1574 popup_view_origin_for_emulation_.x() +
1575 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1576 window_rect->y =
1577 popup_view_origin_for_emulation_.y() +
1578 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1579}
1580
1581void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1582 DCHECK(window_rect);
1583 float scale = popup_origin_scale_for_emulation_;
1584 if (!scale)
1585 return;
1586 window_rect->x =
1587 popup_screen_origin_for_emulation_.x() +
1588 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1589 window_rect->y =
1590 popup_screen_origin_for_emulation_.y() +
1591 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1592}
1593
Blink Reformat1c4d759e2017-04-09 16:34:541594WebRect RenderWidget::WindowRect() {
bokan841fdc72016-10-06 00:16:351595 WebRect rect;
bokan6b08cd22016-10-05 00:55:211596 if (pending_window_rect_count_) {
1597 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1598 // the RootWindowRect is probably going to return wrong results since the
1599 // browser may not have processed the Move yet. There isn't really anything
1600 // good to do in this case, and it shouldn't happen - since this size is
1601 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351602 rect = pending_window_rect_;
1603 } else {
1604 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211605 }
[email protected]2533ce12009-05-09 00:02:241606
bokan841fdc72016-10-06 00:16:351607 ScreenRectToEmulatedIfNeeded(&rect);
1608 return rect;
bokan6b08cd22016-10-05 00:55:211609}
1610
Blink Reformat1c4d759e2017-04-09 16:34:541611WebRect RenderWidget::ViewRect() {
bokan841fdc72016-10-06 00:16:351612 WebRect rect = view_screen_rect_;
1613 ScreenRectToEmulatedIfNeeded(&rect);
1614 return rect;
initial.commit09911bf2008-07-26 23:55:291615}
1616
Blink Reformat1c4d759e2017-04-09 16:34:541617void RenderWidget::SetToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301618 WebTextDirection hint) {
Blink Reformat1c4d759e2017-04-09 16:34:541619 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301620}
1621
Blink Reformat1c4d759e2017-04-09 16:34:541622void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) {
oshima33ec97cd2015-12-14 19:40:241623 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351624 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511625
[email protected]5b45ad42013-10-25 00:42:041626 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201627 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561628 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1629 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031630 } else {
bokanc007c3a2015-02-03 07:15:561631 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031632 }
initial.commit09911bf2008-07-26 23:55:291633 } else {
bokanc007c3a2015-02-03 07:15:561634 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291635 }
1636}
1637
[email protected]2533ce12009-05-09 00:02:241638void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1639 pending_window_rect_ = rect;
1640 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241641
bokan6b08cd22016-10-05 00:55:211642 // Popups don't get size updates back from the browser so just store the set
1643 // values.
Blink Reformat1c4d759e2017-04-09 16:34:541644 if (popup_type_ != blink::kWebPopupTypeNone) {
1645 window_screen_rect_ = rect;
1646 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241647 }
[email protected]d4547452008-08-28 18:36:371648}
1649
wjmacleanee244e02017-05-26 21:06:071650void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type,
1651 const gfx::Point& location) {
wjmacleanee244e02017-05-26 21:06:071652 has_host_context_menu_location_ = true;
1653 host_context_menu_location_ = location;
1654 if (GetWebWidget()) {
1655 GetWebWidget()->ShowContextMenu(
1656 static_cast<blink::WebMenuSourceType>(source_type));
1657 }
1658 has_host_context_menu_location_ = false;
1659}
1660
[email protected]fa7b1dc2010-06-23 17:53:041661void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261662 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041663 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071664 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041665 int selection_start, int selection_end) {
ekaramad5aff1942017-01-06 01:26:351666 if (!ShouldHandleImeEvents())
1667 return;
1668
brettw4b461082016-11-19 18:55:161669#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491670 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1671 plugin->render_frame()->OnImeSetComposition(text, underlines,
1672 selection_start, selection_end);
ekaramad2a46d632016-07-19 13:33:091673 return;
1674 }
1675#endif
[email protected]66fca5bc2013-05-23 06:58:291676 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011677 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011678 if (!controller ||
Blink Reformat1c4d759e2017-04-09 16:34:541679 !controller->SetComposition(
1680 WebString::FromUTF16(text),
ekaramadce32ef9f2017-02-09 17:33:561681 WebVector<WebCompositionUnderline>(underlines),
1682 replacement_range.IsValid()
1683 ? WebRange(replacement_range.start(), replacement_range.length())
1684 : WebRange(),
1685 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041686 // If we failed to set the composition text, then we need to let the browser
1687 // process to cancel the input method's ongoing composition session, to make
1688 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221689 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261690 }
nonafa291792016-08-10 02:36:181691 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041692}
1693
rlanday7efe2302017-01-11 00:14:281694void RenderWidget::OnImeCommitText(
1695 const base::string16& text,
1696 const std::vector<WebCompositionUnderline>& underlines,
1697 const gfx::Range& replacement_range,
1698 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351699 if (!ShouldHandleImeEvents())
1700 return;
1701
brettw4b461082016-11-19 18:55:161702#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491703 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1704 plugin->render_frame()->OnImeCommitText(text, replacement_range,
1705 relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091706 return;
1707 }
1708#endif
[email protected]66fca5bc2013-05-23 06:58:291709 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391710 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261711 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541712 controller->CommitText(
1713 WebString::FromUTF16(text),
ekaramadce32ef9f2017-02-09 17:33:561714 WebVector<WebCompositionUnderline>(underlines),
1715 replacement_range.IsValid()
1716 ? WebRange(replacement_range.start(), replacement_range.length())
1717 : WebRange(),
1718 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261719 }
aelias87b8f7c2016-09-14 03:19:291720 input_handler_->set_handling_input_event(false);
1721 UpdateCompositionInfo(false /* not an immediate request */);
1722}
1723
1724void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351725 if (!ShouldHandleImeEvents())
1726 return;
1727
brettw4b461082016-11-19 18:55:161728#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491729 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
1730 plugin->render_frame()->OnImeFinishComposingText(keep_selection);
aelias87b8f7c2016-09-14 03:19:291731 return;
1732 }
1733#endif
1734
changwan38c3eb612016-12-09 01:45:561735 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291736 return;
1737 ImeEventGuard guard(this);
1738 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011739 if (auto* controller = GetInputMethodController()) {
Blink Reformat1c4d759e2017-04-09 16:34:541740 controller->FinishComposingText(
1741 keep_selection ? WebInputMethodController::kKeepSelection
1742 : WebInputMethodController::kDoNotKeepSelection);
ekaramad2daaf672016-11-10 20:29:011743 }
fsamuele8326c742016-01-12 00:49:391744 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181745 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291746}
1747
oshimad5279032015-12-16 18:22:331748void RenderWidget::OnDeviceScaleFactorChanged() {
1749 if (!compositor_)
1750 return;
oshimad5279032015-12-16 18:22:331751 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181752 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331753 else
Blink Reformat1c4d759e2017-04-09 16:34:541754 compositor_->SetDeviceScaleFactor(device_scale_factor_);
oshimad5279032015-12-16 18:22:331755}
1756
[email protected]0bc1f572013-04-17 01:46:311757void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121758 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211759 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121760 return;
1761
[email protected]0bc1f572013-04-17 01:46:311762 // Even if the browser provides an empty damage rect, it's still expecting to
1763 // receive a repaint ack so just damage the entire widget bounds.
1764 if (size_to_paint.IsEmpty()) {
1765 size_to_paint = size_;
1766 }
1767
[email protected]ec7dc112008-08-06 05:30:121768 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051769 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311770 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121771}
1772
[email protected]79fa22e2013-08-23 15:18:121773void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351774 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1775
1776 pending_synthetic_gesture_callbacks_.front().Run();
1777 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271778}
1779
[email protected]4873c7d2009-07-16 06:36:281780void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211781 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111782 return;
Blink Reformat1c4d759e2017-04-09 16:34:541783 GetWebWidget()->SetTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111784}
1785
[email protected]80ad8622012-11-07 16:33:031786void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1787 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511788 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391789 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1790 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511791 } else {
mfomitchev2600fd7c2016-02-17 20:53:391792 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511793 }
[email protected]80ad8622012-11-07 16:33:031794 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1795}
1796
lfgdb5c4ed2016-03-04 23:09:071797void RenderWidget::OnUpdateWindowScreenRect(
1798 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211799 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071800 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211801 else
lfgdb5c4ed2016-03-04 23:09:071802 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071803}
1804
kenrbea731792017-01-13 15:10:481805void RenderWidget::OnSetViewportIntersection(
1806 const gfx::Rect& viewport_intersection) {
Blink Reformat1c4d759e2017-04-09 16:34:541807 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1808 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
kenrbea731792017-01-13 15:10:481809 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541810 ->SetRemoteViewportIntersection(viewport_intersection);
kenrbea731792017-01-13 15:10:481811 }
1812}
1813
kenrb04323782017-06-23 01:23:321814void RenderWidget::OnSetIsInert(bool inert) {
1815 if (GetWebWidget() && GetWebWidget()->IsWebFrameWidget()) {
1816 DCHECK(popup_type_ == WebPopupType::kWebPopupTypeNone);
1817 static_cast<WebFrameWidget*>(GetWebWidget())->SetIsInert(inert);
1818 }
1819}
1820
paulmeyer90f6c31d2016-11-12 00:17:591821void RenderWidget::OnDragTargetDragEnter(
1822 const std::vector<DropData::Metadata>& drop_meta_data,
1823 const gfx::Point& client_point,
1824 const gfx::Point& screen_point,
1825 WebDragOperationsMask ops,
1826 int key_modifiers) {
1827 if (!GetWebWidget())
1828 return;
1829
Blink Reformat1c4d759e2017-04-09 16:34:541830 DCHECK(GetWebWidget()->IsWebFrameWidget());
1831 WebDragOperation operation =
1832 static_cast<WebFrameWidget*>(GetWebWidget())
1833 ->DragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1834 client_point, screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591835
1836 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1837}
1838
1839void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1840 const gfx::Point& screen_point,
1841 WebDragOperationsMask ops,
1842 int key_modifiers) {
1843 if (!GetWebWidget())
1844 return;
1845
Blink Reformat1c4d759e2017-04-09 16:34:541846 DCHECK(GetWebWidget()->IsWebFrameWidget());
paulmeyer90f6c31d2016-11-12 00:17:591847 WebDragOperation operation =
Blink Reformat1c4d759e2017-04-09 16:34:541848 static_cast<WebFrameWidget*>(GetWebWidget())
1849 ->DragTargetDragOver(ConvertWindowPointToViewport(client_point),
1850 screen_point, ops, key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591851
1852 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1853}
1854
kenrb07c272802017-02-07 23:48:171855void RenderWidget::OnDragTargetDragLeave(const gfx::Point& client_point,
1856 const gfx::Point& screen_point) {
paulmeyer90f6c31d2016-11-12 00:17:591857 if (!GetWebWidget())
1858 return;
Blink Reformat1c4d759e2017-04-09 16:34:541859 DCHECK(GetWebWidget()->IsWebFrameWidget());
kenrb07c272802017-02-07 23:48:171860 static_cast<WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:541861 ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point),
kenrb07c272802017-02-07 23:48:171862 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591863}
1864
1865void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1866 const gfx::Point& client_point,
1867 const gfx::Point& screen_point,
1868 int key_modifiers) {
1869 if (!GetWebWidget())
1870 return;
1871
Blink Reformat1c4d759e2017-04-09 16:34:541872 DCHECK(GetWebWidget()->IsWebFrameWidget());
1873 static_cast<WebFrameWidget*>(GetWebWidget())
1874 ->DragTargetDrop(DropDataToWebDragData(drop_data),
1875 ConvertWindowPointToViewport(client_point), screen_point,
1876 key_modifiers);
paulmeyer90f6c31d2016-11-12 00:17:591877}
1878
paulmeyer8fc8ea92016-11-15 05:12:211879void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1880 const gfx::Point& screen_point,
1881 WebDragOperation op) {
1882 if (!GetWebWidget())
1883 return;
1884
Blink Reformat1c4d759e2017-04-09 16:34:541885 static_cast<WebFrameWidget*>(GetWebWidget())
1886 ->DragSourceEndedAt(ConvertWindowPointToViewport(client_point),
1887 screen_point, op);
paulmeyer8fc8ea92016-11-15 05:12:211888}
1889
1890void RenderWidget::OnDragSourceSystemDragEnded() {
1891 if (!GetWebWidget())
1892 return;
1893
Blink Reformat1c4d759e2017-04-09 16:34:541894 static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded();
paulmeyer8fc8ea92016-11-15 05:12:211895}
1896
Blink Reformat1c4d759e2017-04-09 16:34:541897void RenderWidget::ShowVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261898#if defined(OS_CHROMEOS)
1899 // On ChromeOS, virtual keyboard is triggered only when users leave the
1900 // mouse button or the finger and a text input element is focused at that
1901 // time. Focus event itself shouldn't trigger virtual keyboard.
1902 UpdateTextInputState();
1903#else
changwan75e3b2072017-01-16 02:55:001904 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261905#endif
boliu7b2be2f2016-11-04 04:58:311906
1907// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1908// virtual keyboard.
1909#if !defined(OS_ANDROID)
1910 FocusChangeComplete();
1911#endif
[email protected]0d1ebed12013-08-05 22:01:131912}
1913
fsamuel72464894f2015-12-15 06:59:311914ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161915#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:491916 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
1917 return plugin->text_input_type();
ekaramad2a46d632016-07-19 13:33:091918#endif
ekaramad5aff1942017-01-06 01:26:351919 if (auto* controller = GetInputMethodController())
Blink Reformat1c4d759e2017-04-09 16:34:541920 return ConvertWebTextInputType(controller->TextInputType());
fsamuel72464894f2015-12-15 06:59:311921 return ui::TEXT_INPUT_TYPE_NONE;
1922}
1923
nonafa291792016-08-10 02:36:181924void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1925 if (!monitor_composition_info_ && !immediate_request)
1926 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591927
nonafa291792016-08-10 02:36:181928 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1929 gfx::Range range;
1930 std::vector<gfx::Rect> character_bounds;
1931
1932 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1933 // Composition information is only available on editable node.
1934 range = gfx::Range::InvalidRange();
1935 } else {
1936 GetCompositionRange(&range);
1937 GetCompositionCharacterBounds(&character_bounds);
1938 }
1939
1940 if (!immediate_request &&
1941 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311942 return;
nonafa291792016-08-10 02:36:181943 }
fsamuel72464894f2015-12-15 06:59:311944 composition_character_bounds_ = character_bounds;
1945 composition_range_ = range;
1946 Send(new InputHostMsg_ImeCompositionRangeChanged(
1947 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311948}
1949
Blink Reformat1c4d759e2017-04-09 16:34:541950void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) {
oshimaf866dab2015-12-05 00:41:541951 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461952 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331953 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541954 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461955 gfx::Rect window_rect =
1956 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1957 rect->x = window_rect.x();
1958 rect->y = window_rect.y();
1959 rect->width = window_rect.width();
1960 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541961 }
1962}
1963
Blink Reformat1c4d759e2017-04-09 16:34:541964void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) {
oshimaa6985b62016-01-27 08:58:301965 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181966 rect->x *= GetOriginalDeviceScaleFactor();
1967 rect->y *= GetOriginalDeviceScaleFactor();
1968 rect->width *= GetOriginalDeviceScaleFactor();
1969 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301970 }
1971}
1972
changwan8c342742016-02-26 00:53:391973void RenderWidget::OnRequestTextInputStateUpdate() {
Dave Tapuska9db80842017-07-24 17:24:261974#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:391975 DCHECK(!ime_event_guard_);
1976 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:001977 UpdateTextInputStateInternal(false, true /* reply_to_request */);
[email protected]105dffb42013-02-20 03:46:211978#endif
Dave Tapuska9db80842017-07-24 17:24:261979}
[email protected]105dffb42013-02-20 03:46:211980
ekaramadc9b70a72017-03-23 16:14:231981void RenderWidget::OnRequestCompositionUpdates(bool immediate_request,
1982 bool monitor_updates) {
1983 monitor_composition_info_ = monitor_updates;
nonafa291792016-08-10 02:36:181984 if (!immediate_request)
1985 return;
1986 UpdateCompositionInfo(true /* immediate request */);
1987}
1988
wjmaclean8a795f32016-08-11 23:49:581989void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191990 if (device_scale_factor_ == device_scale_factor)
1991 return;
1992
1993 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331994 OnDeviceScaleFactorChanged();
wjmaclean8a795f32016-08-11 23:49:581995 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191996}
1997
[email protected]fcdc5642014-05-09 14:32:241998void RenderWidget::OnOrientationChange() {
lfg8d649cc2017-04-28 18:04:301999 WebWidget* web_widget = GetWebWidget();
2000 if (web_widget && web_widget->IsWebFrameWidget()) {
2001 WebFrameWidget* web_frame_widget = static_cast<WebFrameWidget*>(web_widget);
2002 web_frame_widget->LocalRoot()->SendOrientationChangeEvent();
2003 }
[email protected]fcdc5642014-05-09 14:32:242004}
2005
[email protected]bee16aab2009-08-26 15:55:032006void RenderWidget::SetHidden(bool hidden) {
2007 if (is_hidden_ == hidden)
2008 return;
2009
jdduke8fac9d102014-12-20 02:40:132010 // The status has changed. Tell the RenderThread about it and ensure
2011 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:032012 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:132013
tasakb95dbb50c2017-02-08 18:07:502014 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:002015 RenderThreadImpl::current()->WidgetHidden();
tasakb95dbb50c2017-02-08 18:07:502016 time_to_first_active_paint_recorded_ = false;
Nasko Oskovf97e8b02017-07-25 02:45:422017 } else
[email protected]b2db9272014-01-10 17:42:002018 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:112019
2020 if (render_widget_scheduling_state_)
2021 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:032022}
2023
[email protected]2b624c562011-10-27 22:58:262024void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:212025 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:262026 return;
2027
mikhail.pozdnyakovf2c902a2015-04-14 08:09:122028 if (is_fullscreen_granted_) {
Blink Reformat1c4d759e2017-04-09 16:34:542029 GetWebWidget()->DidEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:262030 } else {
Blink Reformat1c4d759e2017-04-09 16:34:542031 GetWebWidget()->DidExitFullscreen();
[email protected]2b624c562011-10-27 22:58:262032 }
[email protected]2b624c562011-10-27 22:58:262033}
2034
[email protected]674741932009-02-04 23:44:462035bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052036 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462037}
2038
[email protected]674741932009-02-04 23:44:462039void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052040 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462041}
2042
[email protected]674741932009-02-04 23:44:462043void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052044 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462045}
2046
changwanf2a707b2015-10-30 08:22:162047void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
2048 if (!ime_event_guard_)
2049 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:292050}
2051
changwanf2a707b2015-10-30 08:22:162052void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
2053 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:002054 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:162055 return;
2056 }
2057 ime_event_guard_ = nullptr;
2058
[email protected]66fca5bc2013-05-23 06:58:292059 // While handling an ime event, text input state and selection bounds updates
2060 // are ignored. These must explicitly be updated once finished handling the
2061 // ime event.
2062 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472063#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:002064 if (guard->show_virtual_keyboard())
2065 ShowVirtualKeyboard();
2066 else
2067 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:472068#endif
[email protected]66fca5bc2013-05-23 06:58:292069}
2070
[email protected]7c8873e2013-02-05 08:03:012071void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:162072#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492073 if (auto* plugin = GetFocusedPepperPluginInsideWidget()) {
ekaramad2a46d632016-07-19 13:33:092074 // TODO(kinaba) http://crbug.com/101101
2075 // Current Pepper IME API does not handle selection bounds. So we simply
2076 // use the caret position as an empty range for now. It will be updated
2077 // after Pepper API equips features related to surrounding text retrieval.
EhsanK22d482e2017-08-10 17:29:492078 blink::WebRect caret(plugin->GetCaretBounds());
Blink Reformat1c4d759e2017-04-09 16:34:542079 ConvertViewportToWindow(&caret);
ekaramad2a46d632016-07-19 13:33:092080 *focus = caret;
2081 *anchor = caret;
2082 return;
2083 }
2084#endif
[email protected]7c8873e2013-02-05 08:03:012085 WebRect focus_webrect;
2086 WebRect anchor_webrect;
Blink Reformat1c4d759e2017-04-09 16:34:542087 GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect);
2088 ConvertViewportToWindow(&focus_webrect);
2089 ConvertViewportToWindow(&anchor_webrect);
oshima33ec97cd2015-12-14 19:40:242090 *focus = focus_webrect;
2091 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322092}
2093
[email protected]e99ef6f2011-10-16 01:13:002094void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082095 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:212096 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:002097 return;
changwanf2a707b2015-10-30 08:22:162098 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292099 return;
[email protected]e99ef6f2011-10-16 01:13:002100
mohsenb0eeba72015-08-09 06:20:082101#if defined(USE_AURA)
2102 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2103 // Aura beucause composited selection updates are not working for webview tags
2104 // which regresses IME inside webview. Remove this when composited selection
2105 // updates are fixed for webviews. See, http://crbug.com/510568.
2106 bool send_ipc = true;
2107#else
jddukeacf809e2014-09-23 20:38:382108 // With composited selection updates, the selection bounds will be reported
2109 // directly by the compositor, in which case explicit IPC selection
2110 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082111 bool send_ipc =
Blink Reformat1c4d759e2017-04-09 16:34:542112 !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled();
mohsenb0eeba72015-08-09 06:20:082113#endif
2114 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382115 ViewHostMsg_SelectionBounds_Params params;
2116 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2117 if (selection_anchor_rect_ != params.anchor_rect ||
2118 selection_focus_rect_ != params.focus_rect) {
2119 selection_anchor_rect_ = params.anchor_rect;
2120 selection_focus_rect_ = params.focus_rect;
Blink Reformat1c4d759e2017-04-09 16:34:542121 GetWebWidget()->SelectionTextDirection(params.focus_dir,
lfg8ff33912016-09-13 20:59:212122 params.anchor_dir);
Blink Reformat1c4d759e2017-04-09 16:34:542123 params.is_anchor_first = GetWebWidget()->IsSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:382124 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2125 }
[email protected]58b48a0d2012-06-13 07:01:352126 }
jddukeacf809e2014-09-23 20:38:382127
nonafa291792016-08-10 02:36:182128 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002129}
2130
lfgb00fcad2016-07-14 14:16:332131void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2132 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
Blink Reformat1c4d759e2017-04-09 16:34:542133 ConvertViewportToWindow(&new_size_in_window);
lfgb00fcad2016-07-14 14:16:332134 if (size_.width() != new_size_in_window.width ||
2135 size_.height() != new_size_in_window.height) {
2136 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2137
2138 if (resizing_mode_selector_->is_synchronous_mode()) {
Blink Reformat1c4d759e2017-04-09 16:34:542139 gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(),
2140 size_.height());
lfgb00fcad2016-07-14 14:16:332141 view_screen_rect_ = new_pos;
2142 window_screen_rect_ = new_pos;
2143 }
2144
2145 AutoResizeCompositor();
2146
2147 if (!resizing_mode_selector_->is_synchronous_mode())
2148 need_update_rect_for_auto_resize_ = true;
2149 }
2150}
2151
[email protected]58b48a0d2012-06-13 07:01:352152void RenderWidget::GetCompositionCharacterBounds(
2153 std::vector<gfx::Rect>* bounds) {
2154 DCHECK(bounds);
2155 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092156
brettw4b461082016-11-19 18:55:162157#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492158 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092159 return;
2160#endif
2161
lfg8ff33912016-09-13 20:59:212162 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092163 return;
2164 blink::WebVector<blink::WebRect> bounds_from_blink;
Blink Reformat1c4d759e2017-04-09 16:34:542165 if (!GetWebWidget()->GetCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092166 return;
2167
2168 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
Blink Reformat1c4d759e2017-04-09 16:34:542169 ConvertViewportToWindow(&bounds_from_blink[i]);
ekaramad2a46d632016-07-19 13:33:092170 bounds->push_back(bounds_from_blink[i]);
2171 }
[email protected]58b48a0d2012-06-13 07:01:352172}
2173
[email protected]db4fc1e2013-09-06 20:01:512174void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162175#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492176 if (GetFocusedPepperPluginInsideWidget())
ekaramad2a46d632016-07-19 13:33:092177 return;
2178#endif
Blink Reformat1c4d759e2017-04-09 16:34:542179 WebRange web_range = GetWebWidget()->CompositionRange();
2180 if (web_range.IsNull()) {
nona2363a3d2016-11-09 03:26:212181 *range = gfx::Range::InvalidRange();
2182 return;
[email protected]88dbe32f2013-06-20 23:31:362183 }
Blink Reformat1c4d759e2017-04-09 16:34:542184 range->set_start(web_range.StartOffset());
2185 range->set_end(web_range.EndOffset());
[email protected]88dbe32f2013-06-20 23:31:362186}
2187
[email protected]501ea13d2013-07-09 17:03:292188bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512189 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292190 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082191 if (!range.IsValid())
2192 return false;
[email protected]501ea13d2013-07-09 17:03:292193 if (composition_range_ != range)
2194 return true;
2195 if (bounds.size() != composition_character_bounds_.size())
2196 return true;
2197 for (size_t i = 0; i < bounds.size(); ++i) {
2198 if (bounds[i] != composition_character_bounds_[i])
2199 return true;
2200 }
2201 return false;
2202}
[email protected]501ea13d2013-07-09 17:03:292203
[email protected]ad26ef42011-06-17 07:59:452204bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162205#if BUILDFLAG(ENABLE_PLUGINS)
EhsanK22d482e2017-08-10 17:29:492206 if (auto* plugin = GetFocusedPepperPluginInsideWidget())
2207 return plugin->IsPluginAcceptingCompositionEvents();
ekaramad2a46d632016-07-19 13:33:092208#endif
[email protected]ad26ef42011-06-17 07:59:452209 return true;
[email protected]56ea1a62011-05-30 07:05:572210}
2211
Blink Reformat1c4d759e2017-04-09 16:34:542212blink::WebScreenInfo RenderWidget::GetScreenInfo() {
ccameron2f451532016-09-07 21:49:272213 blink::WebScreenInfo web_screen_info;
Blink Reformat1c4d759e2017-04-09 16:34:542214 web_screen_info.device_scale_factor = screen_info_.device_scale_factor;
ccameronab0aab82017-06-24 17:21:542215 web_screen_info.color_space = screen_info_.color_space;
ccameron2f451532016-09-07 21:49:272216 web_screen_info.depth = screen_info_.depth;
Blink Reformat1c4d759e2017-04-09 16:34:542217 web_screen_info.depth_per_component = screen_info_.depth_per_component;
2218 web_screen_info.is_monochrome = screen_info_.is_monochrome;
ccameron2f451532016-09-07 21:49:272219 web_screen_info.rect = blink::WebRect(screen_info_.rect);
Blink Reformat1c4d759e2017-04-09 16:34:542220 web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect);
ccameron2f451532016-09-07 21:49:272221 switch (screen_info_.orientation_type) {
2222 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542223 web_screen_info.orientation_type =
2224 blink::kWebScreenOrientationPortraitPrimary;
ccameron2f451532016-09-07 21:49:272225 break;
2226 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542227 web_screen_info.orientation_type =
2228 blink::kWebScreenOrientationPortraitSecondary;
ccameron2f451532016-09-07 21:49:272229 break;
2230 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
Blink Reformat1c4d759e2017-04-09 16:34:542231 web_screen_info.orientation_type =
2232 blink::kWebScreenOrientationLandscapePrimary;
ccameron2f451532016-09-07 21:49:272233 break;
2234 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
Blink Reformat1c4d759e2017-04-09 16:34:542235 web_screen_info.orientation_type =
2236 blink::kWebScreenOrientationLandscapeSecondary;
ccameron2f451532016-09-07 21:49:272237 break;
2238 default:
Blink Reformat1c4d759e2017-04-09 16:34:542239 web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined;
ccameron2f451532016-09-07 21:49:272240 break;
2241 }
Blink Reformat1c4d759e2017-04-09 16:34:542242 web_screen_info.orientation_angle = screen_info_.orientation_angle;
ccameron2f451532016-09-07 21:49:272243 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282244}
2245
donnda070f3c2015-01-16 19:54:112246#if defined(OS_ANDROID)
Blink Reformat1c4d759e2017-04-09 16:34:542247void RenderWidget::ShowUnhandledTapUIIfNeeded(const WebPoint& tapped_position,
2248 const WebNode& tapped_node,
2249 bool page_changed) {
Blink Reformat1c4d759e2017-04-09 16:34:542250 bool should_trigger = !page_changed && tapped_node.IsTextNode() &&
2251 !tapped_node.IsContentEditable() &&
2252 !tapped_node.IsInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112253 if (should_trigger) {
2254 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2255 tapped_position.x, tapped_position.y));
2256 }
2257}
2258#endif
2259
Blink Reformat1c4d759e2017-04-09 16:34:542260void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event,
2261 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022262#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562263 if (event_cancelled)
2264 return;
Blink Reformat1c4d759e2017-04-09 16:34:542265 if (event.GetType() == WebInputEvent::kGestureTap) {
changwan75e3b2072017-01-16 02:55:002266 ShowVirtualKeyboard();
Blink Reformat1c4d759e2017-04-09 16:34:542267 } else if (event.GetType() == WebInputEvent::kGestureLongPress) {
lfg8ff33912016-09-13 20:59:212268 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352269 blink::WebInputMethodController* controller = GetInputMethodController();
Blink Reformat1c4d759e2017-04-09 16:34:542270 if (!controller || controller->TextInputInfo().value.IsEmpty())
changwan75e3b2072017-01-16 02:55:002271 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462272 else
changwan75e3b2072017-01-16 02:55:002273 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562274 }
ekaramada110f642016-12-21 19:47:282275// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2276// crbug/420130.
2277#if defined(OS_WIN)
Blink Reformat1c4d759e2017-04-09 16:34:542278 if (event.GetType() != blink::WebGestureEvent::kGestureTap)
ekaramada110f642016-12-21 19:47:282279 return;
2280
2281 // TODO(estade): hit test the event against focused node to make sure
2282 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352283 blink::WebInputMethodController* controller = GetInputMethodController();
2284 blink::WebTextInputType text_input_type =
Blink Reformat1c4d759e2017-04-09 16:34:542285 controller ? controller->TextInputType() : blink::kWebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282286
2287 Send(new ViewHostMsg_FocusedNodeTouched(
Blink Reformat1c4d759e2017-04-09 16:34:542288 routing_id_, text_input_type != blink::kWebTextInputTypeNone));
ekaramada110f642016-12-21 19:47:282289#endif
[email protected]c68c3e4e2013-01-24 00:36:562290#endif
2291}
2292
Blink Reformat1c4d759e2017-04-09 16:34:542293void RenderWidget::DidOverscroll(
bokane53a10f2016-04-13 23:48:312294 const blink::WebFloatSize& overscrollDelta,
2295 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422296 const blink::WebFloatPoint& position,
2297 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482298#if defined(OS_MACOSX)
2299 // On OSX the user can disable the elastic overscroll effect. If that's the
2300 // case, don't forward the overscroll notification.
2301 DCHECK(compositor_deps());
2302 if (!compositor_deps()->IsElasticOverscrollEnabled())
2303 return;
2304#endif
bokane53a10f2016-04-13 23:48:312305 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392306 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422307}
2308
[email protected]7912e822014-04-16 02:37:032309void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392310 if (!is_hidden())
Blink Reformat1c4d759e2017-04-09 16:34:542311 compositor_->SetVisible(true);
[email protected]7912e822014-04-16 02:37:032312}
2313
[email protected]24ed0432013-04-24 07:50:312314RenderWidgetCompositor* RenderWidget::compositor() const {
2315 return compositor_.get();
2316}
2317
fsamuel72464894f2015-12-15 06:59:312318void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392319 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372320}
[email protected]c3d45532011-10-07 19:20:402321
Blink Reformat1c4d759e2017-04-09 16:34:542322void RenderWidget::HasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112323 if (render_widget_scheduling_state_)
2324 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552325 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2326}
2327
Dave Tapuskadfe486c12017-06-09 16:53:132328void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) {
2329 if (input_event_queue_)
2330 input_event_queue_->SetNeedsLowLatency(needs_low_latency);
2331}
2332
xidachenfa0199e72017-05-11 11:34:262333void RenderWidget::SetTouchAction(cc::TouchAction touch_action) {
[email protected]5d0bbdfa92013-12-10 00:35:512334 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2335 // when blink is emulating touch with mouse).
Blink Reformat1c4d759e2017-04-09 16:34:542336 if (input_handler_->handling_event_type() != WebInputEvent::kTouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512337 return;
2338
xidachenfa0199e72017-05-11 11:34:262339 Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action));
[email protected]5d0bbdfa92013-12-10 00:35:512340}
2341
[email protected]e3244ed2014-06-20 20:04:272342void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2343 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162344}
2345
[email protected]e3244ed2014-06-20 20:04:272346void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2347 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162348}
2349
[email protected]de3c5d82014-05-28 22:12:592350void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2351 render_frames_.AddObserver(frame);
2352}
2353
2354void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2355 render_frames_.RemoveObserver(frame);
2356}
2357
lfg43e08e62016-02-03 18:51:372358void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2359 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2360 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2361}
2362
oshima50872a72016-03-04 13:26:182363float RenderWidget::GetOriginalDeviceScaleFactor() const {
2364 return
2365 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272366 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182367 device_scale_factor_;
2368}
2369
paulmeyer90f6c31d2016-11-12 00:17:592370gfx::Point RenderWidget::ConvertWindowPointToViewport(
2371 const gfx::Point& point) {
2372 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542373 ConvertWindowToViewport(&point_in_viewport);
paulmeyer90f6c31d2016-11-12 00:17:592374 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2375}
2376
Blink Reformat1c4d759e2017-04-09 16:34:542377bool RenderWidget::RequestPointerLock() {
lfgbee1e0a2016-06-08 21:24:212378 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2379}
2380
Blink Reformat1c4d759e2017-04-09 16:34:542381void RenderWidget::RequestPointerUnlock() {
lfgbee1e0a2016-06-08 21:24:212382 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2383}
2384
Blink Reformat1c4d759e2017-04-09 16:34:542385bool RenderWidget::IsPointerLocked() {
lfgbee1e0a2016-06-08 21:24:212386 return mouse_lock_dispatcher_->IsMouseLockedTo(
2387 webwidget_mouse_lock_target_.get());
2388}
2389
Blink Reformat1c4d759e2017-04-09 16:34:542390void RenderWidget::StartDragging(blink::WebReferrerPolicy policy,
paulmeyer6ef5a792016-11-08 20:33:582391 const WebDragData& data,
2392 WebDragOperationsMask mask,
2393 const WebImage& image,
2394 const WebPoint& webImageOffset) {
2395 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
Blink Reformat1c4d759e2017-04-09 16:34:542396 ConvertViewportToWindow(&offset_in_window);
paulmeyer6ef5a792016-11-08 20:33:582397 DropData drop_data(DropDataBuilder::Build(data));
2398 drop_data.referrer_policy = policy;
2399 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592400 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
Blink Reformat1c4d759e2017-04-09 16:34:542401 image.GetSkBitmap(), imageOffset,
paulmeyer6ef5a792016-11-08 20:33:582402 possible_drag_event_info_));
2403}
2404
kenrb5d78b842017-03-06 21:06:012405uint32_t RenderWidget::GetContentSourceId() {
2406 return current_content_source_id_;
2407}
2408
2409void RenderWidget::IncrementContentSourceId() {
2410 if (compositor_)
2411 compositor_->SetContentSourceId(++current_content_source_id_);
2412}
2413
lfg8ff33912016-09-13 20:59:212414blink::WebWidget* RenderWidget::GetWebWidget() const {
2415 return webwidget_internal_;
2416}
2417
ekaramad2daaf672016-11-10 20:29:012418blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2419 const {
Blink Reformat1c4d759e2017-04-09 16:34:542420 if (!GetWebWidget()->IsWebFrameWidget()) {
ekaramad5a9f52a2016-12-07 01:35:182421 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2422 // when the RenderWidget is swapped out. We should top sending IPCs from the
2423 // browser side (https://crbug.com/669219).
2424 // If there is no WebFrameWidget, then there will be no
2425 // InputMethodControllers for a WebLocalFrame.
2426 return nullptr;
2427 }
ekaramad2daaf672016-11-10 20:29:012428 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
Blink Reformat1c4d759e2017-04-09 16:34:542429 ->GetActiveWebInputMethodController();
ekaramad2daaf672016-11-10 20:29:012430}
2431
Dave Tapuska485aca92017-08-08 00:47:582432void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) {
2433 // Close the old binding if there was one.
2434 // A RenderWidgetHost should not need more than one channel.
2435 widget_binding_.Close();
2436 widget_binding_.Bind(std::move(request));
2437}
2438
EhsanK22d482e2017-08-10 17:29:492439#if BUILDFLAG(ENABLE_PLUGINS)
2440PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() {
2441 if (!GetWebWidget() || !GetWebWidget()->IsWebFrameWidget())
2442 return nullptr;
2443
2444 // Focused pepper instance might not always be in the focused frame. For
2445 // instance if a pepper instance and its embedder frame are focused an then
2446 // another frame takes focus using javascript, the embedder frame will no
2447 // longer be focused while the pepper instance is (the embedder frame's
2448 // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin
2449 // is fullscreen, clicking into the pepper will not refocus the embedder
2450 // frame. This is why we have to traverse the whole frame tree to find the
2451 // focused plugin.
2452 blink::WebFrame* current_frame =
2453 static_cast<blink::WebFrameWidget*>(GetWebWidget())->LocalRoot();
2454 while (current_frame) {
2455 RenderFrameImpl* render_frame =
2456 current_frame->IsWebLocalFrame()
2457 ? RenderFrameImpl::FromWebFrame(current_frame)
2458 : nullptr;
2459 if (render_frame && render_frame->focused_pepper_plugin())
2460 return render_frame->focused_pepper_plugin();
2461 current_frame = current_frame->TraverseNext();
2462 }
2463 return nullptr;
2464}
2465#endif
2466
[email protected]e9ff79c2012-10-19 21:31:262467} // namespace content