blob: 9f0ba3566e3cc780acac2f961c65b41f34f9c456 [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"
25#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4826#include "build/build_config.h"
loyso6e6efc42017-01-21 02:23:0327#include "cc/animation/animation_host.h"
danakj1120f4c2016-09-15 02:05:3228#include "cc/output/compositor_frame_sink.h"
jbroman6ccbc7d472016-07-27 04:45:4129#include "cc/output/copy_output_request.h"
fsamuel78f86e42016-01-20 04:10:2330#include "cc/scheduler/begin_frame_source.h"
loyso6e6efc42017-01-21 02:23:0331#include "cc/trees/layer_tree_host.h"
oshima750cb4342015-10-31 00:59:0132#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5833#include "content/common/drag_event_source_info.h"
34#include "content/common/drag_messages.h"
[email protected]9017d7852013-11-21 17:47:3535#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1536#include "content/common/input_messages.h"
jcivelliae1560a2016-11-01 22:40:2337#include "content/common/render_message_filter.mojom.h"
[email protected]992db4c2011-05-12 15:37:1538#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3839#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5040#include "content/common/view_messages.h"
mlamouriafca06dd2017-01-27 23:35:1841#include "content/public/common/content_client.h"
changwan7ded3752016-03-09 23:25:1242#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4244#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5945#include "content/public/common/drop_data.h"
mlamouriafca06dd2017-01-27 23:35:1846#include "content/public/renderer/content_renderer_client.h"
[email protected]953bd0062013-08-01 00:58:4047#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3948#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5849#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5150#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1151#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2853#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2954#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1355#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3256#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1657#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2758#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0559#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4460#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5561#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4462#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0963#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0464#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4765#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1866#include "ipc/ipc_sync_message.h"
brettw4b461082016-11-19 18:55:1667#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4868#include "skia/ext/platform_canvas.h"
kinukoa4293022017-01-27 06:43:2569#include "third_party/WebKit/public/platform/FilePathConversion.h"
[email protected]ec173b522013-11-14 11:01:1870#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5971#include "third_party/WebKit/public/platform/WebDragData.h"
72#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5573#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1174#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3075#include "third_party/WebKit/public/platform/WebRect.h"
76#include "third_party/WebKit/public/platform/WebSize.h"
77#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5178#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
79#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4380#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5981#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0182#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5983#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1184#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3185#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3186#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
87#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3888#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5989#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0890#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4191#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5992#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:1393#include "ui/base/ui_base_switches.h"
dtapuska97286c882017-02-24 23:14:4394#include "ui/events/base_event_utils.h"
tfarina655f81d2014-12-23 02:38:5095#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0996#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3297#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4898#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2799#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:41100#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:48101
[email protected]eeb93112013-05-01 19:41:10102#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:15103#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24104#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10105#endif
106
[email protected]661eb9d2009-02-03 02:11:48107#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52108#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41109#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48110#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44111
sadrul943e3b32016-08-04 18:22:59112#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10113#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19114#endif
115
ekaramad330ba4232016-09-23 17:57:47116#if defined(OS_MACOSX)
117#include "content/renderer/text_input_client_observer.h"
118#endif
119
[email protected]180ef242013-11-07 06:50:46120using blink::WebCompositionUnderline;
121using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43122using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59123using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58124using blink::WebDragOperationsMask;
125using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59126using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46127using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58128using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46129using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49130using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01131using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58132using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46133using blink::WebMouseEvent;
134using blink::WebMouseWheelEvent;
135using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11136using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46137using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11138using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46139using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48140using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46141using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46142using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59143using blink::WebString;
[email protected]180ef242013-11-07 06:50:46144using blink::WebTextDirection;
145using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25146using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46147using blink::WebVector;
148using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26149
paulmeyer90f6c31d2016-11-12 00:17:59150namespace content {
151
[email protected]6a4d7f62013-01-07 21:32:13152namespace {
[email protected]b256eca2013-07-11 10:57:40153
154typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
155
lfgbee1e0a2016-06-08 21:24:21156class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
157 public:
158 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
159 : webwidget_(webwidget) {}
160
161 void OnLockMouseACK(bool succeeded) override {
162 if (succeeded)
163 webwidget_->didAcquirePointerLock();
164 else
165 webwidget_->didNotAcquirePointerLock();
166 }
167
168 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
169
170 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
171 // The WebWidget handles mouse lock in Blink's handleInputEvent().
172 return false;
173 }
174
175 private:
176 blink::WebWidget* webwidget_;
177};
178
dglazkov97b6c2b2016-10-25 17:35:55179bool IsDateTimeInput(ui::TextInputType type) {
180 return type == ui::TEXT_INPUT_TYPE_DATE ||
181 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
182 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
183 type == ui::TEXT_INPUT_TYPE_MONTH ||
184 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
185}
186
paulmeyer90f6c31d2016-11-12 00:17:59187WebDragData DropMetaDataToWebDragData(
188 const std::vector<DropData::Metadata>& drop_meta_data) {
189 std::vector<WebDragData::Item> item_list;
190 for (const auto& meta_data_item : drop_meta_data) {
191 if (meta_data_item.kind == DropData::Kind::STRING) {
192 WebDragData::Item item;
193 item.storageType = WebDragData::Item::StorageTypeString;
kinukoa4293022017-01-27 06:43:25194 item.stringType = WebString::fromUTF16(meta_data_item.mime_type);
paulmeyer90f6c31d2016-11-12 00:17:59195 // Have to pass a dummy URL here instead of an empty URL because the
196 // DropData received by browser_plugins goes through a round trip:
197 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
198 // will contain an empty URL (which means no URL is dragged) if the URL in
199 // WebDragData is empty.
200 if (base::EqualsASCII(meta_data_item.mime_type,
201 ui::Clipboard::kMimeTypeURIList)) {
202 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder");
203 }
204 item_list.push_back(item);
205 continue;
206 }
207
208 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
209 // just the mimetype. This is needed to drag files to WebView on Android
210 // platform.
211 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
212 !meta_data_item.filename.empty()) {
213 WebDragData::Item item;
214 item.storageType = WebDragData::Item::StorageTypeFilename;
kinukoa4293022017-01-27 06:43:25215 item.filenameData = blink::FilePathToWebString(meta_data_item.filename);
paulmeyer90f6c31d2016-11-12 00:17:59216 item_list.push_back(item);
217 continue;
218 }
219
220 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
221 WebDragData::Item item;
222 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
223 item.fileSystemURL = meta_data_item.file_system_url;
224 item_list.push_back(item);
225 continue;
226 }
227 }
228
229 WebDragData result;
230 result.initialize();
231 result.setItems(item_list);
232 return result;
233}
234
235WebDragData DropDataToWebDragData(const DropData& drop_data) {
236 std::vector<WebDragData::Item> item_list;
237
238 // These fields are currently unused when dragging into WebKit.
239 DCHECK(drop_data.download_metadata.empty());
240 DCHECK(drop_data.file_contents.empty());
dcheng3dd85612017-02-08 10:46:23241 DCHECK(drop_data.file_contents_content_disposition.empty());
paulmeyer90f6c31d2016-11-12 00:17:59242
243 if (!drop_data.text.is_null()) {
244 WebDragData::Item item;
245 item.storageType = WebDragData::Item::StorageTypeString;
246 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
kinukoa4293022017-01-27 06:43:25247 item.stringData = WebString::fromUTF16(drop_data.text.string());
paulmeyer90f6c31d2016-11-12 00:17:59248 item_list.push_back(item);
249 }
250
251 if (!drop_data.url.is_empty()) {
252 WebDragData::Item item;
253 item.storageType = WebDragData::Item::StorageTypeString;
254 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
255 item.stringData = WebString::fromUTF8(drop_data.url.spec());
kinukoa4293022017-01-27 06:43:25256 item.title = WebString::fromUTF16(drop_data.url_title);
paulmeyer90f6c31d2016-11-12 00:17:59257 item_list.push_back(item);
258 }
259
260 if (!drop_data.html.is_null()) {
261 WebDragData::Item item;
262 item.storageType = WebDragData::Item::StorageTypeString;
263 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
kinukoa4293022017-01-27 06:43:25264 item.stringData = WebString::fromUTF16(drop_data.html.string());
paulmeyer90f6c31d2016-11-12 00:17:59265 item.baseURL = drop_data.html_base_url;
266 item_list.push_back(item);
267 }
268
269 for (std::vector<ui::FileInfo>::const_iterator it =
270 drop_data.filenames.begin();
271 it != drop_data.filenames.end();
272 ++it) {
273 WebDragData::Item item;
274 item.storageType = WebDragData::Item::StorageTypeFilename;
kinukoa4293022017-01-27 06:43:25275 item.filenameData = blink::FilePathToWebString(it->path);
276 item.displayNameData =
277 blink::FilePathToWebString(base::FilePath(it->display_name));
paulmeyer90f6c31d2016-11-12 00:17:59278 item_list.push_back(item);
279 }
280
281 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
282 drop_data.file_system_files.begin();
283 it != drop_data.file_system_files.end();
284 ++it) {
285 WebDragData::Item item;
286 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
287 item.fileSystemURL = it->url;
288 item.fileSystemFileSize = it->size;
hironoda08349d2016-12-14 07:36:16289 item.fileSystemId = blink::WebString::fromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59290 item_list.push_back(item);
291 }
292
293 for (std::map<base::string16, base::string16>::const_iterator it =
294 drop_data.custom_data.begin();
295 it != drop_data.custom_data.end();
296 ++it) {
297 WebDragData::Item item;
298 item.storageType = WebDragData::Item::StorageTypeString;
kinukoa4293022017-01-27 06:43:25299 item.stringType = WebString::fromUTF16(it->first);
300 item.stringData = WebString::fromUTF16(it->second);
paulmeyer90f6c31d2016-11-12 00:17:59301 item_list.push_back(item);
302 }
303
304 WebDragData result;
305 result.initialize();
306 result.setItems(item_list);
kinukoa4293022017-01-27 06:43:25307 result.setFilesystemId(WebString::fromUTF16(drop_data.filesystem_id));
paulmeyer90f6c31d2016-11-12 00:17:59308 return result;
309}
310
lfg1568d112016-08-30 16:06:29311content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
312 nullptr;
313
314content::RenderWidget::RenderWidgetInitializedCallback
315 g_render_widget_initialized = nullptr;
316
dtapuskac4dd5be2016-10-25 15:11:10317ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
318 // Check the type is in the range representable by ui::TextInputType.
319 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
320 << "blink::WebTextInputType and ui::TextInputType not synchronized";
321 return static_cast<ui::TextInputType>(type);
322}
323
324ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
325 // Check the mode is in the range representable by ui::TextInputMode.
326 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
327 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
328 return static_cast<ui::TextInputMode>(mode);
329}
330
[email protected]b256eca2013-07-11 10:57:40331} // namespace
332
[email protected]b2e4c70132013-10-03 02:07:51333// RenderWidget ---------------------------------------------------------------
334
nick8331f8ad2016-11-15 20:42:45335RenderWidget::RenderWidget(int32_t widget_routing_id,
336 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36337 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27338 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04339 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03340 bool hidden,
341 bool never_visible)
nick8331f8ad2016-11-15 20:42:45342 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36343 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21344 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44345 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29346 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51347 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09348 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29349 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04350 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39351 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12352 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12353 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16354 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48355 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22356 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44357 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20358 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55359 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40360 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20361 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53362 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18363 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12364 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48365 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04366 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27367 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18368 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51369 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11370 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42371 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08372 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24373 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09374 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47375#if defined(OS_MACOSX)
376 text_input_client_observer_(new TextInputClientObserver(this)),
377#endif
wjmaclean1d970622017-01-21 22:28:24378 focused_pepper_plugin_(nullptr),
tasakb95dbb50c2017-02-08 18:07:50379 time_to_first_active_paint_recorded_(true),
380 was_shown_time_(base::TimeTicks::Now()),
kenrb5d78b842017-03-06 21:06:01381 current_content_source_id_(0),
wjmaclean1d970622017-01-21 22:28:24382 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45383 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05384 if (!swapped_out)
385 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27386 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11387
388 // In tests there may not be a RenderThreadImpl.
389 if (RenderThreadImpl::current()) {
390 render_widget_scheduling_state_ = RenderThreadImpl::current()
391 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32392 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11393 render_widget_scheduling_state_->SetHidden(is_hidden_);
394 }
sadrul602ce1362017-01-26 06:41:10395#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14396 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
sadrul602ce1362017-01-26 06:41:10397#endif
initial.commit09911bf2008-07-26 23:55:29398}
399
400RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21401 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16402
[email protected]992db4c2011-05-12 15:37:15403 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02404 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15405 RenderProcess::current()->ReleaseProcess();
sadrul8185d972017-01-31 18:30:11406#if defined(USE_AURA)
fsamuel098eade2017-03-21 18:06:14407 // It is possible for a RenderWidget to be destroyed before it was embedded
408 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
409 // explicitly delete it here.
410 RendererWindowTreeClient::Destroy(routing_id_);
sadrul8185d972017-01-31 18:30:11411#endif
initial.commit09911bf2008-07-26 23:55:29412}
413
[email protected]484955942010-08-19 16:13:18414// static
lfg1568d112016-08-30 16:06:29415void RenderWidget::InstallCreateHook(
416 CreateRenderWidgetFunction create_render_widget,
417 RenderWidgetInitializedCallback render_widget_initialized) {
418 CHECK(!g_create_render_widget && !g_render_widget_initialized);
419 g_create_render_widget = create_render_widget;
420 g_render_widget_initialized = render_widget_initialized;
421}
422
423// static
nickf7b38222016-11-22 21:59:35424RenderWidget* RenderWidget::CreateForPopup(
425 RenderViewImpl* opener,
426 CompositorDependencies* compositor_deps,
427 blink::WebPopupType popup_type,
428 const ScreenInfo& screen_info) {
nick4df698d82016-11-11 20:39:23429 // Do a synchronous IPC to obtain a routing ID.
430 int32_t routing_id = MSG_ROUTING_NONE;
431 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
nickf7b38222016-11-22 21:59:35432 opener->GetRoutingID(), popup_type, &routing_id)) {
nick4df698d82016-11-11 20:39:23433 return nullptr;
434 }
435
nick8331f8ad2016-11-15 20:42:45436 scoped_refptr<RenderWidget> widget(
437 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
438 false, false, false));
nickf7b38222016-11-22 21:59:35439 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24440 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35441 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23442 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
443 return widget.get();
initial.commit09911bf2008-07-26 23:55:29444}
445
[email protected]484955942010-08-19 16:13:18446// static
kenrba7199832015-01-22 23:44:59447RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23448 int widget_routing_id,
kenrba7199832015-01-22 23:44:59449 bool hidden,
ccameron2f451532016-09-07 21:49:27450 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59451 CompositorDependencies* compositor_deps,
452 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23453 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55454 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
455 // same routing ID for both the view routing ID and the main frame widget
456 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23457 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55458 if (view) {
avi8a45c1092016-03-01 16:12:34459 view->AttachWebFrameWidget(
460 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
461 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55462 }
dcheng35d31c112015-07-22 00:17:36463 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29464 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45465 ? g_create_render_widget(widget_routing_id, compositor_deps,
466 blink::WebPopupTypeNone, screen_info, false,
467 hidden, false)
468 : new RenderWidget(widget_routing_id, compositor_deps,
469 blink::WebPopupTypeNone, screen_info, false,
470 hidden, false));
simonhong628f9812015-04-27 23:13:20471 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23472 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59473 // this function returns.
nickf7b38222016-11-22 21:59:35474 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23475 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
476
477 if (g_render_widget_initialized)
478 g_render_widget_initialized(widget.get());
479 return widget.get();
kenrba7199832015-01-22 23:44:59480}
481
482// static
lfgcaab5142016-02-26 19:06:52483blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08484 RenderWidget* render_widget,
485 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55486 if (!frame->parent()) {
487 // TODO(dcheng): The main frame widget currently has a special case.
488 // Eliminate this once WebView is no longer a WebWidget.
489 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
490 }
dchengda9b4bb2015-07-20 20:58:08491 return blink::WebFrameWidget::create(render_widget, frame);
492}
493
494// static
kenrba7199832015-01-22 23:44:59495blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18496 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46497 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18498 break;
[email protected]180ef242013-11-07 06:50:46499 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44500 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18501 default:
502 NOTREACHED();
503 }
504 return NULL;
505}
506
dchengda9b4bb2015-07-20 20:58:08507void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32508 OnClose();
kenrba7199832015-01-22 23:44:59509}
510
alexmos78c9c0d2016-10-14 18:57:03511void RenderWidget::SetSwappedOut(bool is_swapped_out) {
512 // We should only toggle between states.
513 DCHECK(is_swapped_out_ != is_swapped_out);
514 is_swapped_out_ = is_swapped_out;
515
516 // If we are swapping out, we will call ReleaseProcess, allowing the process
517 // to exit if all of its RenderViews are swapped out. We wait until the
518 // WasSwappedOut call to do this, to allow the unload handler to finish.
519 // If we are swapping in, we call AddRefProcess to prevent the process from
520 // exiting.
521 if (!is_swapped_out_)
522 RenderProcess::current()->AddRefProcess();
523}
524
nickf7b38222016-11-22 21:59:35525void RenderWidget::Init(const ShowCallback& show_callback,
526 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21527 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23528 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29529
sadrul9fe48922017-01-23 18:59:49530 input_handler_ = base::MakeUnique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45531
nickf7b38222016-11-22 21:59:35532 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29533
lfg8ff33912016-09-13 20:59:21534 webwidget_internal_ = web_widget;
535 webwidget_mouse_lock_target_.reset(
536 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21537 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29538
nick4df698d82016-11-11 20:39:23539 RenderThread::Get()->AddRoute(routing_id_, this);
540 // Take a reference on behalf of the RenderThread. This will be balanced
541 // when we receive ViewMsg_Close.
542 AddRef();
543 if (RenderThreadImpl::current()) {
544 RenderThreadImpl::current()->WidgetCreated();
545 if (is_hidden_)
546 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29547 }
548}
549
[email protected]949b6592014-08-20 13:17:52550void RenderWidget::WasSwappedOut() {
551 // If we have been swapped out and no one else is using this process,
552 // it's safe to exit now.
553 CHECK(is_swapped_out_);
554 RenderProcess::current()->ReleaseProcess();
555}
556
[email protected]b2e4c70132013-10-03 02:07:51557void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39558 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51559 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43560 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49561 popup_screen_origin_for_emulation_ = gfx::Point(
562 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
563 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56564 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27565 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51566}
567
[email protected]2d6836f42014-07-02 17:25:31568gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
569 if (screen_metrics_emulator_)
570 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
571 return anchor;
572}
573
thakis18e426412017-03-15 12:06:37574#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51575void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39576 ExternalPopupMenu* popup,
577 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49578 popup->SetOriginScaleAndOffsetForEmulation(
579 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51580}
[email protected]53907862014-03-25 15:42:40581#endif
[email protected]b2e4c70132013-10-03 02:07:51582
583void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
584 if (screen_metrics_emulator_)
585 screen_metrics_emulator_->OnShowContextMenu(params);
586}
587
[email protected]a95986a82010-12-24 06:19:28588bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47589#if defined(OS_MACOSX)
590 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
591 return text_input_client_observer_->OnMessageReceived(message);
592#endif
lfgbee1e0a2016-06-08 21:24:21593 if (mouse_lock_dispatcher_ &&
594 mouse_lock_dispatcher_->OnMessageReceived(message))
595 return true;
596
[email protected]a95986a82010-12-24 06:19:28597 bool handled = true;
598 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15599 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22600 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
601 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22602 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29603 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
604 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
605 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15606 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46607 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
608 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15609 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35610 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
611 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28612 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28613 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20614 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
615 OnEnableDeviceEmulation)
616 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
617 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28618 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41619 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25620 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28621 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
622 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03623 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48624 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
625 OnSetViewportIntersection)
lfg43e08e62016-02-03 18:51:37626 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
627 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18628 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
629 OnRequestCompositionUpdate)
paulmeyer90f6c31d2016-11-12 00:17:59630 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
631 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
632 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
633 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21634 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
635 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
636 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21637#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39638 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
639 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21640#endif
[email protected]a95986a82010-12-24 06:19:28641 IPC_MESSAGE_UNHANDLED(handled = false)
642 IPC_END_MESSAGE_MAP()
643 return handled;
644}
initial.commit09911bf2008-07-26 23:55:29645
646bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15647 // Don't send any messages after the browser has told us to close, and filter
648 // most outgoing messages while swapped out.
649 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26650 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11651 closing_) {
initial.commit09911bf2008-07-26 23:55:29652 delete message;
653 return false;
654 }
655
656 // If given a messsage without a routing ID, then assign our routing ID.
657 if (message->routing_id() == MSG_ROUTING_NONE)
658 message->set_routing_id(routing_id_);
659
[email protected]380244092011-10-07 17:26:27660 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44661}
662
dtapuska014ed082016-11-11 21:58:48663void RenderWidget::SendOrCrash(IPC::Message* message) {
664 bool result = Send(message);
665 CHECK(closing_ || result) << "Failed to send message";
666}
667
ekaramad5aff1942017-01-06 01:26:35668bool RenderWidget::ShouldHandleImeEvents() const {
ekaramadb6483a052017-02-10 02:23:26669 // TODO(ekaramad): We track page focus in all RenderViews on the page but the
670 // RenderWidgets corresponding to OOPIFs do not get the update. For now, this
671 // method returns true when the RenderWidget is for an OOPIF, i.e., IME events
672 // will be processed regardless of page focus. We should revisit this after
673 // page focus for OOPIFs has been fully resolved (https://crbug.com/689777).
674 return GetWebWidget() && GetWebWidget()->isWebFrameWidget() &&
675 (has_focus_ || for_oopif_);
ekaramad5aff1942017-01-06 01:26:35676}
677
bokanc007c3a2015-02-03 07:15:56678void RenderWidget::SetWindowRectSynchronously(
679 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39680 ResizeParams params;
681 params.screen_info = screen_info_;
682 params.new_size = new_window_rect.size();
683 params.physical_backing_size =
684 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39685 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39686 params.is_fullscreen_granted = is_fullscreen_granted_;
687 params.display_mode = display_mode_;
688 params.needs_resize_ack = false;
689 Resize(params);
690
bokanc007c3a2015-02-03 07:15:56691 view_screen_rect_ = new_window_rect;
692 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02693 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56694 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02695}
696
initial.commit09911bf2008-07-26 23:55:29697void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32698 DCHECK(content::RenderThread::Get());
699 if (closing_)
700 return;
701 NotifyOnClose();
702 closing_ = true;
703
704 // Browser correspondence is no longer needed at this point.
705 if (routing_id_ != MSG_ROUTING_NONE) {
706 RenderThread::Get()->RemoveRoute(routing_id_);
707 SetHidden(false);
708 if (RenderThreadImpl::current())
709 RenderThreadImpl::current()->WidgetDestroyed();
710 }
711
712 if (for_oopif_) {
713 // Widgets for frames may be created and closed at any time while the frame
714 // is alive. However, the closing process must happen synchronously. Frame
715 // widget and frames hold pointers to each other. If Close() is deferred to
716 // the message loop like in the non-frame widget case, WebWidget::close()
717 // can end up accessing members of an already-deleted frame.
718 Close();
719 } else {
720 // If there is a Send call on the stack, then it could be dangerous to close
721 // now. Post a task that only gets invoked when there are no nested message
722 // loops.
723 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
724 FROM_HERE, base::Bind(&RenderWidget::Close, this));
725 }
726
727 // Balances the AddRef taken when we called AddRoute.
728 Release();
initial.commit09911bf2008-07-26 23:55:29729}
730
fsamuel664e8b62016-01-20 19:54:01731void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04732 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32733 return;
734
[email protected]b2e4c70132013-10-03 02:07:51735 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39736 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51737 return;
738 }
739
mfomitchev2600fd7c2016-02-17 20:53:39740 Resize(params);
initial.commit09911bf2008-07-26 23:55:29741}
742
dgozman9260b0a12015-03-16 13:45:20743void RenderWidget::OnEnableDeviceEmulation(
744 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39745 if (!screen_metrics_emulator_) {
746 ResizeParams resize_params;
747 resize_params.screen_info = screen_info_;
748 resize_params.new_size = size_;
749 resize_params.physical_backing_size = physical_backing_size_;
750 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39751 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
752 resize_params.display_mode = display_mode_;
753 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
754 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18755 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39756 } else {
dgozman9260b0a12015-03-16 13:45:20757 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39758 }
dgozman9260b0a12015-03-16 13:45:20759}
760
761void RenderWidget::OnDisableDeviceEmulation() {
762 screen_metrics_emulator_.reset();
763}
764
initial.commit09911bf2008-07-26 23:55:29765void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31766 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29767 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03768 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55769 for (auto& observer : render_frames_)
770 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29771}
772
[email protected]3399dd822014-08-09 11:14:24773void RenderWidget::OnWasShown(bool needs_repainting,
774 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41775 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29776 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21777 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29778 return;
779
tasakb95dbb50c2017-02-08 18:07:50780 was_shown_time_ = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29781 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03782 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55783 for (auto& observer : render_frames_)
784 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29785
[email protected]8a23afb32014-04-30 22:40:23786 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29787 return;
initial.commit09911bf2008-07-26 23:55:29788
789 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24790 if (compositor_) {
791 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15792 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24793 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05794 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24795 }
jdduke491a3f0c2015-06-15 23:30:26796 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29797}
798
[email protected]53d3f302009-12-21 04:42:05799void RenderWidget::OnRequestMoveAck() {
800 DCHECK(pending_window_rect_count_);
801 pending_window_rect_count_--;
802}
803
[email protected]ed7defa2013-03-12 21:29:59804GURL RenderWidget::GetURLForGraphicsContext3D() {
805 return GURL();
[email protected]65225772011-05-12 21:10:24806}
807
nzolghadr5d8596502017-01-23 22:59:35808void RenderWidget::OnHandleInputEvent(
809 const blink::WebInputEvent* input_event,
810 const std::vector<const blink::WebInputEvent*>& coalesced_events,
811 const ui::LatencyInfo& latency_info,
812 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23813 if (!input_event)
814 return;
nzolghadr5d8596502017-01-23 22:59:35815
816 input_handler_->HandleInputEvent(
817 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
818 latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23819}
820
821void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21822 if (GetWebWidget())
823 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23824}
825
826void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21827 if (GetWebWidget())
828 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23829}
830
alexmos56567492016-09-13 00:52:46831void RenderWidget::OnSetEditCommandsForNextKeyEvent(
832 const EditCommands& edit_commands) {
833 edit_commands_ = edit_commands;
834}
835
fsamuel78f86e42016-01-20 04:10:23836void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08837 has_focus_ = enable;
838
lfg8ff33912016-09-13 20:59:21839 if (GetWebWidget())
840 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08841
ericwilligers88e69742016-10-17 19:29:55842 for (auto& observer : render_frames_)
843 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23844}
845
dtapuska3d5624d32016-08-30 04:34:00846void RenderWidget::SetNeedsMainFrame() {
847 RenderWidgetCompositor* rwc = compositor();
848 if (!rwc)
849 return;
850 rwc->setNeedsBeginFrame();
851}
852
fsamuel78f86e42016-01-20 04:10:23853///////////////////////////////////////////////////////////////////////////////
854// RenderWidgetCompositorDelegate
855
856void RenderWidget::ApplyViewportDeltas(
857 const gfx::Vector2dF& inner_delta,
858 const gfx::Vector2dF& outer_delta,
859 const gfx::Vector2dF& elastic_overscroll_delta,
860 float page_scale,
861 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21862 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
863 elastic_overscroll_delta, page_scale,
864 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23865}
866
867void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00868 RenderThreadImpl* render_thread = RenderThreadImpl::current();
869 // render_thread may be NULL in tests.
870 InputHandlerManager* input_handler_manager =
871 render_thread ? render_thread->input_handler_manager() : NULL;
872 if (input_handler_manager)
dtapuska97286c882017-02-24 23:14:43873 input_handler_manager->ProcessRafAlignedInputOnMainThread(
874 routing_id_, ui::EventTimeStampFromSeconds(frame_time_sec));
dtapuska3d5624d32016-08-30 04:34:00875
lfg8ff33912016-09-13 20:59:21876 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23877}
878
fsamuelcf3002e2017-03-20 23:13:47879void RenderWidget::RequestNewCompositorFrameSink(
880 bool fallback,
881 const CompositorFrameSinkCallback& callback) {
lfg8ff33912016-09-13 20:59:21882 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03883 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32884 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39885 DCHECK(!compositor_never_visible_);
fsamuelcf3002e2017-03-20 23:13:47886 RenderThreadImpl::current()->RequestNewCompositorFrameSink(
887 fallback, routing_id_, frame_swap_message_queue_,
888 GetURLForGraphicsContext3D(), callback);
[email protected]ba91a792013-02-06 09:48:28889}
890
fsamuel78f86e42016-01-20 04:10:23891void RenderWidget::DidCommitAndDrawCompositorFrame() {
892 // NOTE: Tests may break if this event is renamed or moved. See
893 // tab_capture_performancetest.cc.
894 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08895
ericwilligers88e69742016-10-17 19:29:55896 for (auto& observer : render_frames_)
897 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08898
fsamuel78f86e42016-01-20 04:10:23899 // Notify subclasses that we initiated the paint operation.
900 DidInitiatePaint();
901}
902
903void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55904 for (auto& observer : render_frames_)
905 observer.DidCommitCompositorFrame();
906 for (auto& observer : render_frame_proxies_)
907 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23908}
909
910void RenderWidget::DidCompletePageScaleAnimation() {}
911
danakj6c872fc02016-10-22 04:29:49912void RenderWidget::DidReceiveCompositorFrameAck() {
913 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23914
pimanbfb2ceb2016-03-18 21:32:58915 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23916 return;
917 }
918
919 ViewHostMsg_UpdateRect_Params params;
920 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23921 params.flags = next_paint_flags_;
922
923 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
924 next_paint_flags_ = 0;
925 need_update_rect_for_auto_resize_ = false;
926}
927
fsamuel78f86e42016-01-20 04:10:23928bool RenderWidget::IsClosing() const {
929 return host_closing_;
930}
931
danakj53eccbc2016-03-02 22:51:07932void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23933 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29934}
935
fsamuel78f86e42016-01-20 04:10:23936void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21937 GetWebWidget()->updateAllLifecyclePhases();
tasakb95dbb50c2017-02-08 18:07:50938
939 if (time_to_first_active_paint_recorded_)
940 return;
941
942 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
943 if (!render_thread_impl->NeedsToRecordFirstActivePaint())
944 return;
945
946 time_to_first_active_paint_recorded_ = true;
947 base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_;
948 UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint",
949 sample);
fsamuel78f86e42016-01-20 04:10:23950}
951
952void RenderWidget::WillBeginCompositorFrame() {
953 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
954
dglazkov06854c5c2016-08-31 00:19:59955 // The UpdateTextInputState can result in further layout and possibly
956 // enable GPU acceleration so they need to be called before any painting
957 // is done.
changwan75e3b2072017-01-16 02:55:00958 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:59959 UpdateSelectionBounds();
960
ericwilligers88e69742016-10-17 19:29:55961 for (auto& observer : render_frame_proxies_)
962 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:29963}
964
jbroman6ccbc7d472016-07-27 04:45:41965std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
966 std::unique_ptr<cc::CopyOutputRequest> request) {
967 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
968 routing_id_, std::move(request));
969}
970
fsamuel72464894f2015-12-15 06:59:31971///////////////////////////////////////////////////////////////////////////////
972// RenderWidgetInputHandlerDelegate
973
avid7d6b2e2016-03-04 19:41:17974void RenderWidget::FocusChangeComplete() {
975 if (owner_delegate_)
976 owner_delegate_->RenderWidgetFocusChangeComplete();
977}
fsamuel72464894f2015-12-15 06:59:31978
979bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17980 if (owner_delegate_)
981 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
982
fsamuel72464894f2015-12-15 06:59:31983 return true;
984}
985
dtapuska1827dd22016-03-11 15:24:59986void RenderWidget::ObserveGestureEventAndResult(
987 const blink::WebGestureEvent& gesture_event,
988 const gfx::Vector2dF& unused_delta,
989 bool event_processed) {
990 if (!compositor_deps_->IsElasticOverscrollEnabled())
991 return;
992
993 cc::InputHandlerScrollResult scroll_result;
994 scroll_result.did_scroll = event_processed;
995 scroll_result.did_overscroll_root = !unused_delta.IsZero();
996 scroll_result.unused_scroll_delta = unused_delta;
997
998 RenderThreadImpl* render_thread = RenderThreadImpl::current();
999 InputHandlerManager* input_handler_manager =
1000 render_thread ? render_thread->input_handler_manager() : NULL;
1001 if (input_handler_manager) {
1002 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
1003 routing_id_, gesture_event, scroll_result);
1004 }
1005}
1006
avid7d6b2e2016-03-04 19:41:171007void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:461008 ClearEditCommands();
1009}
1010
1011void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
1012 const std::string& value) {
1013 ClearEditCommands();
1014 edit_commands_.emplace_back(name, value);
1015}
1016
1017void RenderWidget::ClearEditCommands() {
1018 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:171019}
fsamuel72464894f2015-12-15 06:59:311020
chongza8ba91fc2016-08-16 21:39:171021void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:311022 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1023}
1024
dchengcedca5612016-04-09 01:40:151025void RenderWidget::OnInputEventAck(
1026 std::unique_ptr<InputEventAck> input_event_ack) {
dtapuska014ed082016-11-11 21:58:481027 SendOrCrash(
1028 new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
fsamuel72464894f2015-12-15 06:59:311029}
1030
dtapuska46616922016-03-17 22:52:011031void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:071032 blink::WebInputEvent::Type handled_type,
skyostilcff62882017-01-28 13:18:041033 blink::WebInputEventResult result,
dtapuskab08721e62016-06-29 03:35:071034 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:101035 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1036 InputHandlerManager* input_handler_manager =
1037 render_thread ? render_thread->input_handler_manager() : NULL;
1038 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:071039 input_handler_manager->NotifyInputEventHandledOnMainThread(
skyostilcff62882017-01-28 13:18:041040 routing_id_, handled_type, result, ack_result);
dtapuska0bd451a2016-02-18 17:08:101041 }
1042}
1043
fsamuele8326c742016-01-12 00:49:391044void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1045 // Nothing to do here. RenderWidget created the |input_handler| and will take
1046 // ownership of it. We just verify here that we don't already have an input
1047 // handler.
1048 DCHECK(!input_handler_);
1049}
1050
changwan75e3b2072017-01-16 02:55:001051void RenderWidget::ShowVirtualKeyboard() {
1052 UpdateTextInputStateInternal(true, false);
1053}
1054
changwan62f57292017-02-17 08:28:251055void RenderWidget::ClearTextInputState() {
1056 text_input_info_ = blink::WebTextInputInfo();
1057 text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE;
1058 text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT;
1059 can_compose_inline_ = false;
1060 text_input_flags_ = 0;
1061}
1062
changwan75e3b2072017-01-16 02:55:001063void RenderWidget::UpdateTextInputState() {
1064 UpdateTextInputStateInternal(false, false);
1065}
1066
1067void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1068 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311069 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001070
fsamuel72464894f2015-12-15 06:59:311071 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001072 DCHECK(!reply_to_request);
1073 // show_virtual_keyboard should still be effective even if it was set inside
1074 // the IME
fsamuel72464894f2015-12-15 06:59:311075 // event guard.
changwan75e3b2072017-01-16 02:55:001076 if (show_virtual_keyboard)
1077 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311078 return;
1079 }
1080
dglazkov97b6c2b2016-10-25 17:35:551081 ui::TextInputType new_type = GetTextInputType();
1082 if (IsDateTimeInput(new_type))
1083 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311084
dglazkov97b6c2b2016-10-25 17:35:551085 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351086 if (auto* controller = GetInputMethodController())
1087 new_info = controller->textInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101088 const ui::TextInputMode new_mode =
1089 ConvertWebTextInputMode(new_info.inputMode);
fsamuel72464894f2015-12-15 06:59:311090
1091 bool new_can_compose_inline = CanComposeInline();
1092
1093 // Only sends text input params if they are changed or if the ime should be
1094 // shown.
changwan75e3b2072017-01-16 02:55:001095 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561096 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1097 text_input_info_ != new_info ||
1098 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381099 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551100 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311101 params.mode = new_mode;
1102 params.flags = new_info.flags;
1103 params.value = new_info.value.utf8();
1104 params.selection_start = new_info.selectionStart;
1105 params.selection_end = new_info.selectionEnd;
1106 params.composition_start = new_info.compositionStart;
1107 params.composition_end = new_info.compositionEnd;
1108 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001109 // TODO(changwan): change instances of show_ime_if_needed to
1110 // show_virtual_keyboard.
1111 params.show_ime_if_needed = show_virtual_keyboard;
1112 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311113 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1114
1115 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551116 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311117 text_input_mode_ = new_mode;
1118 can_compose_inline_ = new_can_compose_inline;
1119 text_input_flags_ = new_info.flags;
1120 }
1121}
1122
1123bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581124 possible_drag_event_info_.event_source =
1125 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1126 possible_drag_event_info_.event_location =
1127 gfx::Point(event.globalX, event.globalY);
avid7d6b2e2016-03-04 19:41:171128
fsamuel72464894f2015-12-15 06:59:311129 return false;
1130}
1131
1132bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551133 for (auto& observer : render_frames_)
1134 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081135
paulmeyer6ef5a792016-11-08 20:33:581136 possible_drag_event_info_.event_source =
1137 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1138 possible_drag_event_info_.event_location =
1139 gfx::Point(event.globalX, event.globalY);
1140
avid7d6b2e2016-03-04 19:41:171141 if (owner_delegate_)
1142 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1143
fsamuel72464894f2015-12-15 06:59:311144 return false;
[email protected]fd847792013-10-24 17:12:351145}
1146
initial.commit09911bf2008-07-26 23:55:291147///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391148// RenderWidgetScreenMetricsDelegate
1149
1150void RenderWidget::Redraw() {
1151 set_next_paint_is_resize_ack();
1152 if (compositor_)
1153 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1154}
1155
bokanc63441c2016-04-27 15:49:121156void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211157 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121158}
1159
1160gfx::Size RenderWidget::GetSizeForWebWidget() const {
1161 if (IsUseZoomForDSFEnabled())
1162 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1163
1164 return size_;
1165}
1166
mfomitchev2600fd7c2016-02-17 20:53:391167void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581168 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271169 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1170 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581171
mfomitchev2600fd7c2016-02-17 20:53:391172 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581173
ccameron2f451532016-09-07 21:49:271174 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1175 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581176 OnDeviceScaleFactorChanged();
1177 ScheduleComposite();
1178 }
mfomitchev2600fd7c2016-02-17 20:53:391179
1180 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1181 // A resize ack shouldn't be requested if we have not ACK'd the previous
1182 // one.
1183 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1184 }
1185
1186 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211187 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391188 return;
1189
ianwene5fc5782016-08-18 04:05:151190 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391191 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151192 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameron24c87c32017-03-14 21:50:421193 compositor_->SetRasterColorSpace(
1194 screen_info_.icc_profile.GetParametricColorSpace());
ianwene5fc5782016-08-18 04:05:151195 }
mfomitchev2600fd7c2016-02-17 20:53:391196
mfomitchev2600fd7c2016-02-17 20:53:391197 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391198
1199 // NOTE: We may have entered fullscreen mode without changing our size.
1200 bool fullscreen_change =
1201 is_fullscreen_granted_ != params.is_fullscreen_granted;
1202 is_fullscreen_granted_ = params.is_fullscreen_granted;
1203 display_mode_ = params.display_mode;
1204
bokanc63441c2016-04-27 15:49:121205 size_ = params.new_size;
1206 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391207
bokanc63441c2016-04-27 15:49:121208 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221209
mfomitchev2600fd7c2016-02-17 20:53:391210 WebSize visual_viewport_size;
1211
1212 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181213 visual_viewport_size = gfx::ScaleToCeiledSize(
1214 params.visible_viewport_size,
1215 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391216 } else {
1217 visual_viewport_size = visible_viewport_size_;
1218 }
1219
lfg8ff33912016-09-13 20:59:211220 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391221
bokanc63441c2016-04-27 15:49:121222 // When resizing, we want to wait to paint before ACK'ing the resize. This
1223 // ensures that we only resize as fast as we can paint. We only need to
1224 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391225 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1226 // In this case there is no paint/composite and therefore no
1227 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1228 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1229 DCHECK(!params.needs_resize_ack);
1230 }
1231
1232 // Send the Resize_ACK flag once we paint again if requested.
1233 if (params.needs_resize_ack)
1234 set_next_paint_is_resize_ack();
1235
1236 if (fullscreen_change)
1237 DidToggleFullscreen();
1238
engedy6cb63c92016-02-23 14:14:581239 if (orientation_changed)
1240 OnOrientationChange();
1241
mfomitchev2600fd7c2016-02-17 20:53:391242 // If a resize ack is requested and it isn't set-up, then no more resizes will
1243 // come in and in general things will go wrong.
1244 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1245}
1246
1247void RenderWidget::SetScreenMetricsEmulationParameters(
1248 bool enabled,
1249 const blink::WebDeviceEmulationParams& params) {
1250 // This is only supported in RenderView.
1251 NOTREACHED();
1252}
1253
1254void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1255 const gfx::Rect& window_screen_rect) {
1256 view_screen_rect_ = view_screen_rect;
1257 window_screen_rect_ = window_screen_rect;
1258}
1259
1260///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461261// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291262
[email protected]3a1c8a8032013-03-18 22:35:321263void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401264 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051265 if (compositor_)
oshima750cb4342015-10-31 00:59:011266 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051267}
1268
loyso50b51c22017-01-10 07:18:371269blink::WebLayerTreeView* RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221270 DCHECK(!host_closing_);
1271
loyso6e6efc42017-01-21 02:23:031272 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1273 auto animation_host = cc::AnimationHost::CreateMainInstance();
1274
1275 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1276 compositor_.get(), compositor_.get(), animation_host.get(),
1277 compositor_deps_, device_scale_factor_, screen_info_);
1278 compositor_->Initialize(std::move(layer_tree_host),
1279 std::move(animation_host));
1280
wjmaclean1d970622017-01-21 22:28:241281 compositor_->SetIsForOopif(for_oopif_);
oshima750cb4342015-10-31 00:59:011282 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331283 OnDeviceScaleFactorChanged();
ccameron2c6d2702017-03-08 19:42:421284 compositor_->SetRasterColorSpace(screen_info_.icc_profile.GetColorSpace());
kenrb5d78b842017-03-06 21:06:011285 compositor_->SetContentSourceId(current_content_source_id_);
sievers71c62dd52015-10-07 01:44:391286 // For background pages and certain tests, we don't want to trigger
danakj1120f4c2016-09-15 02:05:321287 // CompositorFrameSink creation.
sievers71c62dd52015-10-07 01:44:391288 if (compositor_never_visible_ || !RenderThreadImpl::current())
1289 compositor_->SetNeverVisible();
1290
pimanc4af3072015-10-02 03:45:591291 StartCompositor();
staraz067f58242016-11-07 21:06:411292 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1293 compositor_->SetFrameSinkId(
1294 cc::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371295
wjmaclean1d970622017-01-21 22:28:241296 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1297 // render_thread may be NULL in tests.
1298 InputHandlerManager* input_handler_manager =
1299 render_thread ? render_thread->input_handler_manager() : NULL;
1300 if (input_handler_manager) {
1301 input_handler_manager->AddInputHandler(
1302 routing_id_, compositor()->GetInputHandler(),
1303 weak_ptr_factory_.GetWeakPtr(),
1304 compositor_deps_->IsScrollAnimatorEnabled());
1305 has_added_input_handler_ = true;
1306 }
1307
loyso50b51c22017-01-10 07:18:371308 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591309}
1310
ennef3c58142014-12-09 21:44:381311void RenderWidget::WillCloseLayerTreeView() {
1312 if (host_closing_)
1313 return;
1314
1315 // Prevent new compositors or output surfaces from being created.
1316 host_closing_ = true;
1317
[email protected]aeeedad2014-08-22 18:16:221318 // Always send this notification to prevent new layer tree views from
1319 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211320 if (blink::WebWidget* widget = GetWebWidget())
1321 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221322}
1323
dglazkovf0e1d6d2015-10-10 02:13:481324void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1325 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1326 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1327 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1328 }
dglazkov79c426102015-08-31 21:22:431329
ericwilligers88e69742016-10-17 19:29:551330 for (auto& observer : render_frames_)
1331 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431332}
1333
jdduke491a3f0c2015-06-15 23:30:261334void RenderWidget::ScheduleComposite() {
1335 if (compositor_ &&
1336 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
skyostil32650d22016-09-26 16:58:231337 compositor_->setNeedsCompositorUpdate();
jdduke491a3f0c2015-06-15 23:30:261338 }
1339}
1340
1341void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1342 if (compositor_) {
1343 // Regardless of whether threaded compositing is enabled, always
1344 // use this mechanism to force the compositor to redraw. However,
1345 // the invalidation code path below is still needed for the
1346 // non-threaded case.
1347 compositor_->SetNeedsForcedRedraw();
1348 }
1349 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151350}
1351
[email protected]586871b2014-07-22 17:05:111352// static
dchengcedca5612016-04-09 01:40:151353std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111354 IPC::Message* msg,
1355 MessageDeliveryPolicy policy,
1356 FrameSwapMessageQueue* frame_swap_message_queue,
1357 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111358 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111359 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151360 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1361 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111362 &first_message_for_frame);
1363 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151364 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111365 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061366 return promise;
[email protected]586871b2014-07-22 17:05:111367 }
dcheng4b6b5ff2014-10-16 00:42:061368 return nullptr;
[email protected]586871b2014-07-22 17:05:111369}
1370
1371void RenderWidget::QueueMessage(IPC::Message* msg,
1372 MessageDeliveryPolicy policy) {
1373 // RenderThreadImpl::current() is NULL in some tests.
1374 if (!compositor_ || !RenderThreadImpl::current()) {
1375 Send(msg);
1376 return;
1377 }
1378
dchengcedca5612016-04-09 01:40:151379 std::unique_ptr<cc::SwapPromise> swap_promise =
1380 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111381 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111382 compositor_->GetSourceFrameNumber());
1383
1384 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321385 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351386 // Request a commit. This might either A) request a commit ahead of time
1387 // or B) request a commit which is not needed because there are not
1388 // pending updates. If B) then the commit will be skipped and the swap
1389 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1390 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1391 // can_cancel_commit is not unset.
1392 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111393 }
1394}
1395
[email protected]4873c7d2009-07-16 06:36:281396void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301397 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521398 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181399 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291400 // Only send a SetCursor message if we need to make a change.
1401 if (!current_cursor_.IsEqual(cursor)) {
1402 current_cursor_ = cursor;
1403 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1404 }
1405}
1406
1407// We are supposed to get a single call to Show for a newly created RenderWidget
1408// that was created via RenderWidget::CreateWebView. So, we wait until this
1409// point to dispatch the ShowWidget message.
1410//
1411// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281412// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291413//
nickf7b38222016-11-22 21:59:351414void RenderWidget::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291415 DCHECK(!did_show_) << "received extraneous Show call";
1416 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351417 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291418
[email protected]8de12d942010-11-17 20:42:441419 if (did_show_)
1420 return;
1421
1422 did_show_ = true;
nickf7b38222016-11-22 21:59:351423
1424 // The opener is responsible for actually showing this widget.
1425 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351426 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351427
bokanc007c3a2015-02-03 07:15:561428 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441429 // that's okay. It'll be ignored if as_popup is false, or the browser
1430 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561431 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291432}
1433
[email protected]2533ce12009-05-09 00:02:241434void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381435 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241436 Send(new ViewHostMsg_Close(routing_id_));
1437}
1438
dgozmancf9039cd2015-04-06 12:01:311439void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551440 for (auto& observer : render_frames_)
1441 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311442}
1443
[email protected]4873c7d2009-07-16 06:36:281444void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081445 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321446 if (is_swapped_out_) {
1447 // This widget is currently swapped out, and the active widget is in a
1448 // different process. Have the browser route the close request to the
1449 // active widget instead, so that the correct unload handlers are run.
1450 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1451 return;
1452 }
1453
initial.commit09911bf2008-07-26 23:55:291454 // If a page calls window.close() twice, we'll end up here twice, but that's
1455 // OK. It is safe to send multiple Close messages.
1456
[email protected]2533ce12009-05-09 00:02:241457 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1458 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1459 // could be closed before the JS finishes executing. So instead, post a
1460 // message back to the message loop, which won't run until the JS is
1461 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081462 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211463 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291464}
1465
[email protected]9017d7852013-11-21 17:47:351466void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151467 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351468 const SyntheticGestureCompletionCallback& callback) {
1469 DCHECK(!callback.is_null());
1470
1471 pending_synthetic_gesture_callbacks_.push(callback);
1472
1473 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321474 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351475
1476 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1477}
1478
initial.commit09911bf2008-07-26 23:55:291479void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031480 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381481 WillCloseLayerTreeView();
1482 compositor_.reset();
lfg8ff33912016-09-13 20:59:211483 if (webwidget_internal_) {
1484 webwidget_internal_->close();
1485 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291486 }
1487}
1488
bokan841fdc72016-10-06 00:16:351489void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1490 DCHECK(window_rect);
1491 float scale = popup_origin_scale_for_emulation_;
1492 if (!scale)
1493 return;
1494 window_rect->x =
1495 popup_view_origin_for_emulation_.x() +
1496 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1497 window_rect->y =
1498 popup_view_origin_for_emulation_.y() +
1499 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1500}
1501
1502void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1503 DCHECK(window_rect);
1504 float scale = popup_origin_scale_for_emulation_;
1505 if (!scale)
1506 return;
1507 window_rect->x =
1508 popup_screen_origin_for_emulation_.x() +
1509 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1510 window_rect->y =
1511 popup_screen_origin_for_emulation_.y() +
1512 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1513}
1514
[email protected]4873c7d2009-07-16 06:36:281515WebRect RenderWidget::windowRect() {
bokan841fdc72016-10-06 00:16:351516 WebRect rect;
bokan6b08cd22016-10-05 00:55:211517 if (pending_window_rect_count_) {
1518 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1519 // the RootWindowRect is probably going to return wrong results since the
1520 // browser may not have processed the Move yet. There isn't really anything
1521 // good to do in this case, and it shouldn't happen - since this size is
1522 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351523 rect = pending_window_rect_;
1524 } else {
1525 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211526 }
[email protected]2533ce12009-05-09 00:02:241527
bokan841fdc72016-10-06 00:16:351528 ScreenRectToEmulatedIfNeeded(&rect);
1529 return rect;
bokan6b08cd22016-10-05 00:55:211530}
1531
1532WebRect RenderWidget::viewRect() {
bokan841fdc72016-10-06 00:16:351533 WebRect rect = view_screen_rect_;
1534 ScreenRectToEmulatedIfNeeded(&rect);
1535 return rect;
initial.commit09911bf2008-07-26 23:55:291536}
1537
[email protected]180ef242013-11-07 06:50:461538void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301539 WebTextDirection hint) {
kinukoa4293022017-01-27 06:43:251540 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.utf16(), hint));
[email protected]8a9d6ca32011-06-06 20:11:301541}
1542
oshima33ec97cd2015-12-14 19:40:241543void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1544 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351545 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511546
[email protected]5b45ad42013-10-25 00:42:041547 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201548 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561549 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1550 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031551 } else {
bokanc007c3a2015-02-03 07:15:561552 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031553 }
initial.commit09911bf2008-07-26 23:55:291554 } else {
bokanc007c3a2015-02-03 07:15:561555 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291556 }
1557}
1558
[email protected]2533ce12009-05-09 00:02:241559void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1560 pending_window_rect_ = rect;
1561 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241562
bokan6b08cd22016-10-05 00:55:211563 // Popups don't get size updates back from the browser so just store the set
1564 // values.
1565 if (popup_type_ != blink::WebPopupTypeNone) {
1566 window_screen_rect_ = rect;
1567 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241568 }
[email protected]d4547452008-08-28 18:36:371569}
1570
[email protected]fa7b1dc2010-06-23 17:53:041571void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261572 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041573 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071574 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041575 int selection_start, int selection_end) {
ekaramad5aff1942017-01-06 01:26:351576 if (!ShouldHandleImeEvents())
1577 return;
1578
brettw4b461082016-11-19 18:55:161579#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091580 if (focused_pepper_plugin_) {
1581 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1582 text, underlines, selection_start, selection_end);
1583 return;
1584 }
1585#endif
[email protected]66fca5bc2013-05-23 06:58:291586 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011587 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011588 if (!controller ||
1589 !controller->setComposition(
kinukoa4293022017-01-27 06:43:251590 WebString::fromUTF16(text),
ekaramadce32ef9f2017-02-09 17:33:561591 WebVector<WebCompositionUnderline>(underlines),
1592 replacement_range.IsValid()
1593 ? WebRange(replacement_range.start(), replacement_range.length())
1594 : WebRange(),
1595 selection_start, selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041596 // If we failed to set the composition text, then we need to let the browser
1597 // process to cancel the input method's ongoing composition session, to make
1598 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221599 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261600 }
nonafa291792016-08-10 02:36:181601 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041602}
1603
rlanday7efe2302017-01-11 00:14:281604void RenderWidget::OnImeCommitText(
1605 const base::string16& text,
1606 const std::vector<WebCompositionUnderline>& underlines,
1607 const gfx::Range& replacement_range,
1608 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351609 if (!ShouldHandleImeEvents())
1610 return;
1611
brettw4b461082016-11-19 18:55:161612#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091613 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291614 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1615 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091616 return;
1617 }
1618#endif
[email protected]66fca5bc2013-05-23 06:58:291619 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391620 input_handler_->set_handling_input_event(true);
ekaramadb6483a052017-02-10 02:23:261621 if (auto* controller = GetInputMethodController()) {
ekaramadce32ef9f2017-02-09 17:33:561622 controller->commitText(
1623 WebString::fromUTF16(text),
1624 WebVector<WebCompositionUnderline>(underlines),
1625 replacement_range.IsValid()
1626 ? WebRange(replacement_range.start(), replacement_range.length())
1627 : WebRange(),
1628 relative_cursor_pos);
ekaramadb6483a052017-02-10 02:23:261629 }
aelias87b8f7c2016-09-14 03:19:291630 input_handler_->set_handling_input_event(false);
1631 UpdateCompositionInfo(false /* not an immediate request */);
1632}
1633
1634void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351635 if (!ShouldHandleImeEvents())
1636 return;
1637
brettw4b461082016-11-19 18:55:161638#if BUILDFLAG(ENABLE_PLUGINS)
aelias87b8f7c2016-09-14 03:19:291639 if (focused_pepper_plugin_) {
1640 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1641 keep_selection);
1642 return;
1643 }
1644#endif
1645
changwan38c3eb612016-12-09 01:45:561646 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291647 return;
1648 ImeEventGuard guard(this);
1649 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011650 if (auto* controller = GetInputMethodController()) {
1651 controller->finishComposingText(
1652 keep_selection ? WebInputMethodController::KeepSelection
1653 : WebInputMethodController::DoNotKeepSelection);
1654 }
fsamuele8326c742016-01-12 00:49:391655 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181656 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291657}
1658
oshimad5279032015-12-16 18:22:331659void RenderWidget::OnDeviceScaleFactorChanged() {
1660 if (!compositor_)
1661 return;
oshimad5279032015-12-16 18:22:331662 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181663 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331664 else
1665 compositor_->setDeviceScaleFactor(device_scale_factor_);
1666}
1667
[email protected]0bc1f572013-04-17 01:46:311668void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121669 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211670 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121671 return;
1672
[email protected]0bc1f572013-04-17 01:46:311673 // Even if the browser provides an empty damage rect, it's still expecting to
1674 // receive a repaint ack so just damage the entire widget bounds.
1675 if (size_to_paint.IsEmpty()) {
1676 size_to_paint = size_;
1677 }
1678
[email protected]ec7dc112008-08-06 05:30:121679 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051680 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311681 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121682}
1683
[email protected]79fa22e2013-08-23 15:18:121684void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351685 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1686
1687 pending_synthetic_gesture_callbacks_.front().Run();
1688 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271689}
1690
[email protected]4873c7d2009-07-16 06:36:281691void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211692 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111693 return;
lfg8ff33912016-09-13 20:59:211694 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111695}
1696
[email protected]80ad8622012-11-07 16:33:031697void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1698 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511699 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391700 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1701 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511702 } else {
mfomitchev2600fd7c2016-02-17 20:53:391703 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511704 }
[email protected]80ad8622012-11-07 16:33:031705 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1706}
1707
lfgdb5c4ed2016-03-04 23:09:071708void RenderWidget::OnUpdateWindowScreenRect(
1709 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211710 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071711 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211712 else
lfgdb5c4ed2016-03-04 23:09:071713 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071714}
1715
kenrbea731792017-01-13 15:10:481716void RenderWidget::OnSetViewportIntersection(
1717 const gfx::Rect& viewport_intersection) {
1718 if (GetWebWidget() && GetWebWidget()->isWebFrameWidget()) {
1719 DCHECK(popup_type_ == WebPopupType::WebPopupTypeNone);
1720 static_cast<WebFrameWidget*>(GetWebWidget())
1721 ->setRemoteViewportIntersection(viewport_intersection);
1722 }
1723}
1724
paulmeyer90f6c31d2016-11-12 00:17:591725void RenderWidget::OnDragTargetDragEnter(
1726 const std::vector<DropData::Metadata>& drop_meta_data,
1727 const gfx::Point& client_point,
1728 const gfx::Point& screen_point,
1729 WebDragOperationsMask ops,
1730 int key_modifiers) {
1731 if (!GetWebWidget())
1732 return;
1733
1734 DCHECK(GetWebWidget()->isWebFrameWidget());
1735 WebDragOperation operation = static_cast<WebFrameWidget*>(GetWebWidget())->
1736 dragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1737 client_point, screen_point, ops, key_modifiers);
1738
1739 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1740}
1741
1742void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1743 const gfx::Point& screen_point,
1744 WebDragOperationsMask ops,
1745 int key_modifiers) {
1746 if (!GetWebWidget())
1747 return;
1748
1749 DCHECK(GetWebWidget()->isWebFrameWidget());
1750 WebDragOperation operation =
1751 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragOver(
1752 ConvertWindowPointToViewport(client_point),
1753 screen_point, ops, key_modifiers);
1754
1755 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1756}
1757
kenrb07c272802017-02-07 23:48:171758void RenderWidget::OnDragTargetDragLeave(const gfx::Point& client_point,
1759 const gfx::Point& screen_point) {
paulmeyer90f6c31d2016-11-12 00:17:591760 if (!GetWebWidget())
1761 return;
1762 DCHECK(GetWebWidget()->isWebFrameWidget());
kenrb07c272802017-02-07 23:48:171763 static_cast<WebFrameWidget*>(GetWebWidget())
1764 ->dragTargetDragLeave(ConvertWindowPointToViewport(client_point),
1765 screen_point);
paulmeyer90f6c31d2016-11-12 00:17:591766}
1767
1768void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1769 const gfx::Point& client_point,
1770 const gfx::Point& screen_point,
1771 int key_modifiers) {
1772 if (!GetWebWidget())
1773 return;
1774
1775 DCHECK(GetWebWidget()->isWebFrameWidget());
1776 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDrop(
1777 DropDataToWebDragData(drop_data),
1778 ConvertWindowPointToViewport(client_point),
1779 screen_point, key_modifiers);
1780}
1781
paulmeyer8fc8ea92016-11-15 05:12:211782void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1783 const gfx::Point& screen_point,
1784 WebDragOperation op) {
1785 if (!GetWebWidget())
1786 return;
1787
1788 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceEndedAt(
1789 ConvertWindowPointToViewport(client_point), screen_point, op);
1790}
1791
1792void RenderWidget::OnDragSourceSystemDragEnded() {
1793 if (!GetWebWidget())
1794 return;
1795
1796 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded();
1797}
1798
lukasza86f05da2017-01-24 21:23:261799void RenderWidget::showVirtualKeyboardOnElementFocus() {
okaa398f50b2017-03-21 06:30:261800#if defined(OS_CHROMEOS)
1801 // On ChromeOS, virtual keyboard is triggered only when users leave the
1802 // mouse button or the finger and a text input element is focused at that
1803 // time. Focus event itself shouldn't trigger virtual keyboard.
1804 UpdateTextInputState();
1805#else
changwan75e3b2072017-01-16 02:55:001806 ShowVirtualKeyboard();
okaa398f50b2017-03-21 06:30:261807#endif
boliu7b2be2f2016-11-04 04:58:311808
1809// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1810// virtual keyboard.
1811#if !defined(OS_ANDROID)
1812 FocusChangeComplete();
1813#endif
[email protected]0d1ebed12013-08-05 22:01:131814}
1815
fsamuel72464894f2015-12-15 06:59:311816ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161817#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091818 if (focused_pepper_plugin_)
1819 return focused_pepper_plugin_->text_input_type();
1820#endif
ekaramad5aff1942017-01-06 01:26:351821 if (auto* controller = GetInputMethodController())
1822 return ConvertWebTextInputType(controller->textInputType());
fsamuel72464894f2015-12-15 06:59:311823 return ui::TEXT_INPUT_TYPE_NONE;
1824}
1825
nonafa291792016-08-10 02:36:181826void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1827 if (!monitor_composition_info_ && !immediate_request)
1828 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591829
nonafa291792016-08-10 02:36:181830 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1831 gfx::Range range;
1832 std::vector<gfx::Rect> character_bounds;
1833
1834 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1835 // Composition information is only available on editable node.
1836 range = gfx::Range::InvalidRange();
1837 } else {
1838 GetCompositionRange(&range);
1839 GetCompositionCharacterBounds(&character_bounds);
1840 }
1841
1842 if (!immediate_request &&
1843 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311844 return;
nonafa291792016-08-10 02:36:181845 }
fsamuel72464894f2015-12-15 06:59:311846 composition_character_bounds_ = character_bounds;
1847 composition_range_ = range;
1848 Send(new InputHostMsg_ImeCompositionRangeChanged(
1849 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311850}
1851
oshimaf866dab2015-12-05 00:41:541852void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1853 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461854 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331855 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541856 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461857 gfx::Rect window_rect =
1858 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1859 rect->x = window_rect.x();
1860 rect->y = window_rect.y();
1861 rect->width = window_rect.width();
1862 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541863 }
1864}
1865
oshimaa6985b62016-01-27 08:58:301866void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1867 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181868 rect->x *= GetOriginalDeviceScaleFactor();
1869 rect->y *= GetOriginalDeviceScaleFactor();
1870 rect->width *= GetOriginalDeviceScaleFactor();
1871 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301872 }
1873}
1874
[email protected]adb362312014-06-28 06:04:241875#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:391876void RenderWidget::OnRequestTextInputStateUpdate() {
1877 DCHECK(!ime_event_guard_);
1878 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:001879 UpdateTextInputStateInternal(false, true /* reply_to_request */);
changwan8c342742016-02-26 00:53:391880}
[email protected]105dffb42013-02-20 03:46:211881#endif
1882
nonafa291792016-08-10 02:36:181883void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1884 bool monitor_request) {
1885 monitor_composition_info_ = monitor_request;
1886 if (!immediate_request)
1887 return;
1888 UpdateCompositionInfo(true /* immediate request */);
1889}
1890
wjmaclean8a795f32016-08-11 23:49:581891void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191892 if (device_scale_factor_ == device_scale_factor)
1893 return;
1894
1895 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331896
1897 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261898 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581899
1900 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191901}
1902
[email protected]fcdc5642014-05-09 14:32:241903void RenderWidget::OnOrientationChange() {
1904}
1905
[email protected]bee16aab2009-08-26 15:55:031906void RenderWidget::SetHidden(bool hidden) {
1907 if (is_hidden_ == hidden)
1908 return;
1909
jdduke8fac9d102014-12-20 02:40:131910 // The status has changed. Tell the RenderThread about it and ensure
1911 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031912 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131913
tasakb95dbb50c2017-02-08 18:07:501914 if (is_hidden_) {
[email protected]b2db9272014-01-10 17:42:001915 RenderThreadImpl::current()->WidgetHidden();
tasakb95dbb50c2017-02-08 18:07:501916 time_to_first_active_paint_recorded_ = false;
1917 } else
[email protected]b2db9272014-01-10 17:42:001918 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111919
1920 if (render_widget_scheduling_state_)
1921 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031922}
1923
[email protected]2b624c562011-10-27 22:58:261924void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211925 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261926 return;
1927
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121928 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211929 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261930 } else {
lfg8ff33912016-09-13 20:59:211931 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261932 }
[email protected]2b624c562011-10-27 22:58:261933}
1934
[email protected]674741932009-02-04 23:44:461935bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051936 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461937}
1938
[email protected]674741932009-02-04 23:44:461939void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051940 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461941}
1942
[email protected]674741932009-02-04 23:44:461943void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051944 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461945}
1946
changwanf2a707b2015-10-30 08:22:161947void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1948 if (!ime_event_guard_)
1949 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291950}
1951
changwanf2a707b2015-10-30 08:22:161952void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1953 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:001954 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:161955 return;
1956 }
1957 ime_event_guard_ = nullptr;
1958
[email protected]66fca5bc2013-05-23 06:58:291959 // While handling an ime event, text input state and selection bounds updates
1960 // are ignored. These must explicitly be updated once finished handling the
1961 // ime event.
1962 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471963#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:001964 if (guard->show_virtual_keyboard())
1965 ShowVirtualKeyboard();
1966 else
1967 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:471968#endif
[email protected]66fca5bc2013-05-23 06:58:291969}
1970
[email protected]7c8873e2013-02-05 08:03:011971void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:161972#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091973 if (focused_pepper_plugin_) {
1974 // TODO(kinaba) http://crbug.com/101101
1975 // Current Pepper IME API does not handle selection bounds. So we simply
1976 // use the caret position as an empty range for now. It will be updated
1977 // after Pepper API equips features related to surrounding text retrieval.
1978 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1979 convertViewportToWindow(&caret);
1980 *focus = caret;
1981 *anchor = caret;
1982 return;
1983 }
1984#endif
[email protected]7c8873e2013-02-05 08:03:011985 WebRect focus_webrect;
1986 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211987 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241988 convertViewportToWindow(&focus_webrect);
1989 convertViewportToWindow(&anchor_webrect);
1990 *focus = focus_webrect;
1991 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321992}
1993
[email protected]e99ef6f2011-10-16 01:13:001994void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081995 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211996 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001997 return;
changwanf2a707b2015-10-30 08:22:161998 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291999 return;
[email protected]e99ef6f2011-10-16 01:13:002000
mohsenb0eeba72015-08-09 06:20:082001#if defined(USE_AURA)
2002 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2003 // Aura beucause composited selection updates are not working for webview tags
2004 // which regresses IME inside webview. Remove this when composited selection
2005 // updates are fixed for webviews. See, http://crbug.com/510568.
2006 bool send_ipc = true;
2007#else
jddukeacf809e2014-09-23 20:38:382008 // With composited selection updates, the selection bounds will be reported
2009 // directly by the compositor, in which case explicit IPC selection
2010 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082011 bool send_ipc =
2012 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
2013#endif
2014 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382015 ViewHostMsg_SelectionBounds_Params params;
2016 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2017 if (selection_anchor_rect_ != params.anchor_rect ||
2018 selection_focus_rect_ != params.focus_rect) {
2019 selection_anchor_rect_ = params.anchor_rect;
2020 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:212021 GetWebWidget()->selectionTextDirection(params.focus_dir,
2022 params.anchor_dir);
2023 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:382024 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2025 }
[email protected]58b48a0d2012-06-13 07:01:352026 }
jddukeacf809e2014-09-23 20:38:382027
nonafa291792016-08-10 02:36:182028 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002029}
2030
lfgb00fcad2016-07-14 14:16:332031void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2032 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
2033 convertViewportToWindow(&new_size_in_window);
2034 if (size_.width() != new_size_in_window.width ||
2035 size_.height() != new_size_in_window.height) {
2036 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2037
2038 if (resizing_mode_selector_->is_synchronous_mode()) {
bokan6b08cd22016-10-05 00:55:212039 gfx::Rect new_pos(windowRect().x, windowRect().y,
lfg0140a452016-07-19 19:15:052040 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:332041 view_screen_rect_ = new_pos;
2042 window_screen_rect_ = new_pos;
2043 }
2044
2045 AutoResizeCompositor();
2046
2047 if (!resizing_mode_selector_->is_synchronous_mode())
2048 need_update_rect_for_auto_resize_ = true;
2049 }
2050}
2051
[email protected]58b48a0d2012-06-13 07:01:352052void RenderWidget::GetCompositionCharacterBounds(
2053 std::vector<gfx::Rect>* bounds) {
2054 DCHECK(bounds);
2055 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092056
brettw4b461082016-11-19 18:55:162057#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092058 if (focused_pepper_plugin_)
2059 return;
2060#endif
2061
lfg8ff33912016-09-13 20:59:212062 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092063 return;
2064 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:212065 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092066 return;
2067
2068 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
2069 convertViewportToWindow(&bounds_from_blink[i]);
2070 bounds->push_back(bounds_from_blink[i]);
2071 }
[email protected]58b48a0d2012-06-13 07:01:352072}
2073
[email protected]db4fc1e2013-09-06 20:01:512074void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162075#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092076 if (focused_pepper_plugin_)
2077 return;
2078#endif
lfg8ff33912016-09-13 20:59:212079 WebRange web_range = GetWebWidget()->compositionRange();
nona2363a3d2016-11-09 03:26:212080 if (web_range.isNull()) {
2081 *range = gfx::Range::InvalidRange();
2082 return;
[email protected]88dbe32f2013-06-20 23:31:362083 }
nona2363a3d2016-11-09 03:26:212084 range->set_start(web_range.startOffset());
2085 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:362086}
2087
[email protected]501ea13d2013-07-09 17:03:292088bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512089 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292090 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082091 if (!range.IsValid())
2092 return false;
[email protected]501ea13d2013-07-09 17:03:292093 if (composition_range_ != range)
2094 return true;
2095 if (bounds.size() != composition_character_bounds_.size())
2096 return true;
2097 for (size_t i = 0; i < bounds.size(); ++i) {
2098 if (bounds[i] != composition_character_bounds_[i])
2099 return true;
2100 }
2101 return false;
2102}
[email protected]501ea13d2013-07-09 17:03:292103
[email protected]ad26ef42011-06-17 07:59:452104bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162105#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092106 if (focused_pepper_plugin_)
2107 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
2108#endif
[email protected]ad26ef42011-06-17 07:59:452109 return true;
[email protected]56ea1a62011-05-30 07:05:572110}
2111
ccameron2f451532016-09-07 21:49:272112blink::WebScreenInfo RenderWidget::screenInfo() {
2113 blink::WebScreenInfo web_screen_info;
2114 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
mlamouriafca06dd2017-01-27 23:35:182115 web_screen_info.iccProfile = screen_info_.icc_profile;
ccameron2f451532016-09-07 21:49:272116 web_screen_info.depth = screen_info_.depth;
2117 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
2118 web_screen_info.isMonochrome = screen_info_.is_monochrome;
2119 web_screen_info.rect = blink::WebRect(screen_info_.rect);
2120 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
2121 switch (screen_info_.orientation_type) {
2122 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2123 web_screen_info.orientationType =
2124 blink::WebScreenOrientationPortraitPrimary;
2125 break;
2126 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2127 web_screen_info.orientationType =
2128 blink::WebScreenOrientationPortraitSecondary;
2129 break;
2130 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2131 web_screen_info.orientationType =
2132 blink::WebScreenOrientationLandscapePrimary;
2133 break;
2134 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2135 web_screen_info.orientationType =
2136 blink::WebScreenOrientationLandscapeSecondary;
2137 break;
2138 default:
2139 web_screen_info.orientationType =
2140 blink::WebScreenOrientationUndefined;
2141 break;
2142 }
2143 web_screen_info.orientationAngle = screen_info_.orientation_angle;
2144 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282145}
2146
donnda070f3c2015-01-16 19:54:112147#if defined(OS_ANDROID)
2148void RenderWidget::showUnhandledTapUIIfNeeded(
2149 const WebPoint& tapped_position,
2150 const WebNode& tapped_node,
2151 bool page_changed) {
fsamuele8326c742016-01-12 00:49:392152 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:112153 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372154 !tapped_node.isContentEditable() &&
2155 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112156 if (should_trigger) {
2157 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2158 tapped_position.x, tapped_position.y));
2159 }
2160}
2161#endif
2162
[email protected]c68c3e4e2013-01-24 00:36:562163void RenderWidget::didHandleGestureEvent(
2164 const WebGestureEvent& event,
2165 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022166#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562167 if (event_cancelled)
2168 return;
dtapuska8c4dae12017-01-13 00:23:062169 if (event.type() == WebInputEvent::GestureTap) {
changwan75e3b2072017-01-16 02:55:002170 ShowVirtualKeyboard();
dtapuska8c4dae12017-01-13 00:23:062171 } else if (event.type() == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:212172 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352173 blink::WebInputMethodController* controller = GetInputMethodController();
2174 if (!controller || controller->textInputInfo().value.isEmpty())
changwan75e3b2072017-01-16 02:55:002175 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462176 else
changwan75e3b2072017-01-16 02:55:002177 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562178 }
ekaramada110f642016-12-21 19:47:282179// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2180// crbug/420130.
2181#if defined(OS_WIN)
dtapuska8c4dae12017-01-13 00:23:062182 if (event.type() != blink::WebGestureEvent::GestureTap)
ekaramada110f642016-12-21 19:47:282183 return;
2184
2185 // TODO(estade): hit test the event against focused node to make sure
2186 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352187 blink::WebInputMethodController* controller = GetInputMethodController();
2188 blink::WebTextInputType text_input_type =
2189 controller ? controller->textInputType() : blink::WebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282190
2191 Send(new ViewHostMsg_FocusedNodeTouched(
2192 routing_id_, text_input_type != blink::WebTextInputTypeNone));
2193#endif
[email protected]c68c3e4e2013-01-24 00:36:562194#endif
2195}
2196
sataya.m582c9ce2015-06-09 08:03:422197void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312198 const blink::WebFloatSize& overscrollDelta,
2199 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422200 const blink::WebFloatPoint& position,
2201 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482202#if defined(OS_MACOSX)
2203 // On OSX the user can disable the elastic overscroll effect. If that's the
2204 // case, don't forward the overscroll notification.
2205 DCHECK(compositor_deps());
2206 if (!compositor_deps()->IsElasticOverscrollEnabled())
2207 return;
2208#endif
bokane53a10f2016-04-13 23:48:312209 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392210 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422211}
2212
[email protected]7912e822014-04-16 02:37:032213void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392214 if (!is_hidden())
2215 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032216}
2217
[email protected]24ed0432013-04-24 07:50:312218RenderWidgetCompositor* RenderWidget::compositor() const {
2219 return compositor_.get();
2220}
2221
fsamuel72464894f2015-12-15 06:59:312222void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392223 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372224}
[email protected]c3d45532011-10-07 19:20:402225
[email protected]ce6689f2013-03-29 12:52:552226void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112227 if (render_widget_scheduling_state_)
2228 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552229 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2230}
2231
[email protected]5d0bbdfa92013-12-10 00:35:512232void RenderWidget::setTouchAction(
2233 blink::WebTouchAction web_touch_action) {
[email protected]5d0bbdfa92013-12-10 00:35:512234 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2235 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392236 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512237 return;
2238
[email protected]a18f67a2013-12-20 19:44:362239 content::TouchAction content_touch_action =
2240 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512241 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2242}
2243
[email protected]e3244ed2014-06-20 20:04:272244void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2245 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162246}
2247
[email protected]e3244ed2014-06-20 20:04:272248void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2249 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162250}
2251
[email protected]de3c5d82014-05-28 22:12:592252void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2253 render_frames_.AddObserver(frame);
2254}
2255
2256void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2257 render_frames_.RemoveObserver(frame);
2258}
2259
lfg43e08e62016-02-03 18:51:372260void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2261 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2262 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2263}
2264
oshima50872a72016-03-04 13:26:182265float RenderWidget::GetOriginalDeviceScaleFactor() const {
2266 return
2267 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272268 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182269 device_scale_factor_;
2270}
2271
paulmeyer90f6c31d2016-11-12 00:17:592272gfx::Point RenderWidget::ConvertWindowPointToViewport(
2273 const gfx::Point& point) {
2274 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
2275 convertWindowToViewport(&point_in_viewport);
2276 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2277}
2278
lfgbee1e0a2016-06-08 21:24:212279bool RenderWidget::requestPointerLock() {
2280 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2281}
2282
2283void RenderWidget::requestPointerUnlock() {
2284 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2285}
2286
2287bool RenderWidget::isPointerLocked() {
2288 return mouse_lock_dispatcher_->IsMouseLockedTo(
2289 webwidget_mouse_lock_target_.get());
2290}
2291
paulmeyer6ef5a792016-11-08 20:33:582292void RenderWidget::startDragging(blink::WebReferrerPolicy policy,
2293 const WebDragData& data,
2294 WebDragOperationsMask mask,
2295 const WebImage& image,
2296 const WebPoint& webImageOffset) {
2297 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
2298 convertViewportToWindow(&offset_in_window);
2299 DropData drop_data(DropDataBuilder::Build(data));
2300 drop_data.referrer_policy = policy;
2301 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592302 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
paulmeyer6ef5a792016-11-08 20:33:582303 image.getSkBitmap(), imageOffset,
2304 possible_drag_event_info_));
2305}
2306
kenrb5d78b842017-03-06 21:06:012307uint32_t RenderWidget::GetContentSourceId() {
2308 return current_content_source_id_;
2309}
2310
2311void RenderWidget::IncrementContentSourceId() {
2312 if (compositor_)
2313 compositor_->SetContentSourceId(++current_content_source_id_);
2314}
2315
lfg8ff33912016-09-13 20:59:212316blink::WebWidget* RenderWidget::GetWebWidget() const {
2317 return webwidget_internal_;
2318}
2319
ekaramad2daaf672016-11-10 20:29:012320blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2321 const {
ekaramad5a9f52a2016-12-07 01:35:182322 if (!GetWebWidget()->isWebFrameWidget()) {
2323 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2324 // when the RenderWidget is swapped out. We should top sending IPCs from the
2325 // browser side (https://crbug.com/669219).
2326 // If there is no WebFrameWidget, then there will be no
2327 // InputMethodControllers for a WebLocalFrame.
2328 return nullptr;
2329 }
ekaramad2daaf672016-11-10 20:29:012330 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
2331 ->getActiveWebInputMethodController();
2332}
2333
[email protected]e9ff79c2012-10-19 21:31:262334} // namespace content