blob: 3d64c0dfc65acd2296bdaa3bef200b8325972f98 [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"
changwan7ded3752016-03-09 23:25:1241#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2942#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4243#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5944#include "content/public/common/drop_data.h"
[email protected]953bd0062013-08-01 00:58:4045#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3946#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5847#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5148#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1149#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1150#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2851#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2952#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1353#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3254#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1655#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2756#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0557#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4458#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5559#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4460#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0961#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0462#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4763#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1864#include "ipc/ipc_sync_message.h"
brettw4b461082016-11-19 18:55:1665#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4866#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1867#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5968#include "third_party/WebKit/public/platform/WebDragData.h"
69#include "third_party/WebKit/public/platform/WebDragOperation.h"
dtapuskaa794bd0812017-01-06 15:22:5570#include "third_party/WebKit/public/platform/WebMouseEvent.h"
donnda070f3c2015-01-16 19:54:1171#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3072#include "third_party/WebKit/public/platform/WebRect.h"
73#include "third_party/WebKit/public/platform/WebSize.h"
74#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5175#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
76#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4377#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5978#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0179#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5980#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1181#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3182#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3183#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
84#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3885#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5986#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0887#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4188#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5989#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:1390#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5091#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0992#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3293#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4894#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2795#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4196#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4897
[email protected]eeb93112013-05-01 19:41:1098#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1599#include <android/keycodes.h>
wjmaclean1d970622017-01-21 22:28:24100#include "base/time/time.h"
[email protected]eeb93112013-05-01 19:41:10101#endif
102
[email protected]661eb9d2009-02-03 02:11:48103#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:52104#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41105#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48106#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44107
sadrul943e3b32016-08-04 18:22:59108#if defined(USE_AURA)
sadrul602ce1362017-01-26 06:41:10109#include "content/renderer/mus/renderer_window_tree_client.h"
penghuang28a5fa22015-12-02 17:58:19110#endif
111
ekaramad330ba4232016-09-23 17:57:47112#if defined(OS_MACOSX)
113#include "content/renderer/text_input_client_observer.h"
114#endif
115
[email protected]180ef242013-11-07 06:50:46116using blink::WebCompositionUnderline;
117using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43118using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59119using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58120using blink::WebDragOperationsMask;
121using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59122using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46123using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58124using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46125using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49126using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01127using blink::WebInputMethodController;
paulmeyer6ef5a792016-11-08 20:33:58128using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46129using blink::WebMouseEvent;
130using blink::WebMouseWheelEvent;
131using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11132using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46133using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11134using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46135using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48136using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46137using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46138using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59139using blink::WebString;
[email protected]180ef242013-11-07 06:50:46140using blink::WebTextDirection;
141using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25142using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46143using blink::WebVector;
144using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26145
paulmeyer90f6c31d2016-11-12 00:17:59146namespace content {
147
[email protected]6a4d7f62013-01-07 21:32:13148namespace {
[email protected]b256eca2013-07-11 10:57:40149
150typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
151
lfgbee1e0a2016-06-08 21:24:21152class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
153 public:
154 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
155 : webwidget_(webwidget) {}
156
157 void OnLockMouseACK(bool succeeded) override {
158 if (succeeded)
159 webwidget_->didAcquirePointerLock();
160 else
161 webwidget_->didNotAcquirePointerLock();
162 }
163
164 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
165
166 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
167 // The WebWidget handles mouse lock in Blink's handleInputEvent().
168 return false;
169 }
170
171 private:
172 blink::WebWidget* webwidget_;
173};
174
dglazkov97b6c2b2016-10-25 17:35:55175bool IsDateTimeInput(ui::TextInputType type) {
176 return type == ui::TEXT_INPUT_TYPE_DATE ||
177 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
178 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
179 type == ui::TEXT_INPUT_TYPE_MONTH ||
180 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
181}
182
paulmeyer90f6c31d2016-11-12 00:17:59183WebDragData DropMetaDataToWebDragData(
184 const std::vector<DropData::Metadata>& drop_meta_data) {
185 std::vector<WebDragData::Item> item_list;
186 for (const auto& meta_data_item : drop_meta_data) {
187 if (meta_data_item.kind == DropData::Kind::STRING) {
188 WebDragData::Item item;
189 item.storageType = WebDragData::Item::StorageTypeString;
190 item.stringType = meta_data_item.mime_type;
191 // Have to pass a dummy URL here instead of an empty URL because the
192 // DropData received by browser_plugins goes through a round trip:
193 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
194 // will contain an empty URL (which means no URL is dragged) if the URL in
195 // WebDragData is empty.
196 if (base::EqualsASCII(meta_data_item.mime_type,
197 ui::Clipboard::kMimeTypeURIList)) {
198 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder");
199 }
200 item_list.push_back(item);
201 continue;
202 }
203
204 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
205 // just the mimetype. This is needed to drag files to WebView on Android
206 // platform.
207 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
208 !meta_data_item.filename.empty()) {
209 WebDragData::Item item;
210 item.storageType = WebDragData::Item::StorageTypeFilename;
211 item.filenameData = meta_data_item.filename.AsUTF16Unsafe();
212 item_list.push_back(item);
213 continue;
214 }
215
216 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
217 WebDragData::Item item;
218 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
219 item.fileSystemURL = meta_data_item.file_system_url;
220 item_list.push_back(item);
221 continue;
222 }
223 }
224
225 WebDragData result;
226 result.initialize();
227 result.setItems(item_list);
228 return result;
229}
230
231WebDragData DropDataToWebDragData(const DropData& drop_data) {
232 std::vector<WebDragData::Item> item_list;
233
234 // These fields are currently unused when dragging into WebKit.
235 DCHECK(drop_data.download_metadata.empty());
236 DCHECK(drop_data.file_contents.empty());
237 DCHECK(drop_data.file_description_filename.empty());
238
239 if (!drop_data.text.is_null()) {
240 WebDragData::Item item;
241 item.storageType = WebDragData::Item::StorageTypeString;
242 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
243 item.stringData = drop_data.text.string();
244 item_list.push_back(item);
245 }
246
247 if (!drop_data.url.is_empty()) {
248 WebDragData::Item item;
249 item.storageType = WebDragData::Item::StorageTypeString;
250 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
251 item.stringData = WebString::fromUTF8(drop_data.url.spec());
252 item.title = drop_data.url_title;
253 item_list.push_back(item);
254 }
255
256 if (!drop_data.html.is_null()) {
257 WebDragData::Item item;
258 item.storageType = WebDragData::Item::StorageTypeString;
259 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
260 item.stringData = drop_data.html.string();
261 item.baseURL = drop_data.html_base_url;
262 item_list.push_back(item);
263 }
264
265 for (std::vector<ui::FileInfo>::const_iterator it =
266 drop_data.filenames.begin();
267 it != drop_data.filenames.end();
268 ++it) {
269 WebDragData::Item item;
270 item.storageType = WebDragData::Item::StorageTypeFilename;
271 item.filenameData = it->path.AsUTF16Unsafe();
272 item.displayNameData = it->display_name.AsUTF16Unsafe();
273 item_list.push_back(item);
274 }
275
276 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
277 drop_data.file_system_files.begin();
278 it != drop_data.file_system_files.end();
279 ++it) {
280 WebDragData::Item item;
281 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
282 item.fileSystemURL = it->url;
283 item.fileSystemFileSize = it->size;
hironoda08349d2016-12-14 07:36:16284 item.fileSystemId = blink::WebString::fromASCII(it->filesystem_id);
paulmeyer90f6c31d2016-11-12 00:17:59285 item_list.push_back(item);
286 }
287
288 for (std::map<base::string16, base::string16>::const_iterator it =
289 drop_data.custom_data.begin();
290 it != drop_data.custom_data.end();
291 ++it) {
292 WebDragData::Item item;
293 item.storageType = WebDragData::Item::StorageTypeString;
294 item.stringType = it->first;
295 item.stringData = it->second;
296 item_list.push_back(item);
297 }
298
299 WebDragData result;
300 result.initialize();
301 result.setItems(item_list);
302 result.setFilesystemId(drop_data.filesystem_id);
303 return result;
304}
305
lfg1568d112016-08-30 16:06:29306content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
307 nullptr;
308
309content::RenderWidget::RenderWidgetInitializedCallback
310 g_render_widget_initialized = nullptr;
311
dtapuskac4dd5be2016-10-25 15:11:10312ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
313 // Check the type is in the range representable by ui::TextInputType.
314 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
315 << "blink::WebTextInputType and ui::TextInputType not synchronized";
316 return static_cast<ui::TextInputType>(type);
317}
318
319ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
320 // Check the mode is in the range representable by ui::TextInputMode.
321 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
322 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
323 return static_cast<ui::TextInputMode>(mode);
324}
325
[email protected]b256eca2013-07-11 10:57:40326} // namespace
327
[email protected]b2e4c70132013-10-03 02:07:51328// RenderWidget ---------------------------------------------------------------
329
nick8331f8ad2016-11-15 20:42:45330RenderWidget::RenderWidget(int32_t widget_routing_id,
331 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36332 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27333 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04334 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03335 bool hidden,
336 bool never_visible)
nick8331f8ad2016-11-15 20:42:45337 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36338 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21339 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44340 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29341 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51342 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09343 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29344 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04345 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39346 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12347 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12348 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16349 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48350 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22351 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44352 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20353 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55354 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40355 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20356 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53357 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18358 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12359 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48360 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04361 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27362 device_scale_factor_(screen_info_.device_scale_factor),
nonafa291792016-08-10 02:36:18363 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51364 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11365 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42366 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08367 has_host_context_menu_location_(false),
wjmaclean1d970622017-01-21 22:28:24368 has_added_input_handler_(false),
ekaramad2a46d632016-07-19 13:33:09369 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47370#if defined(OS_MACOSX)
371 text_input_client_observer_(new TextInputClientObserver(this)),
372#endif
wjmaclean1d970622017-01-21 22:28:24373 focused_pepper_plugin_(nullptr),
374 weak_ptr_factory_(this) {
nick8331f8ad2016-11-15 20:42:45375 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05376 if (!swapped_out)
377 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27378 DCHECK(RenderThread::Get());
alexclarke7fa93942015-10-21 15:37:11379
380 // In tests there may not be a RenderThreadImpl.
381 if (RenderThreadImpl::current()) {
382 render_widget_scheduling_state_ = RenderThreadImpl::current()
383 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32384 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11385 render_widget_scheduling_state_->SetHidden(is_hidden_);
386 }
sadrul602ce1362017-01-26 06:41:10387#if defined(USE_AURA)
388 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
389 switches::kUseMusInRenderer)) {
390 RendererWindowTreeClient::Create(routing_id_);
391 }
392#endif
initial.commit09911bf2008-07-26 23:55:29393}
394
395RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21396 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16397
[email protected]992db4c2011-05-12 15:37:15398 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02399 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15400 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29401}
402
[email protected]484955942010-08-19 16:13:18403// static
lfg1568d112016-08-30 16:06:29404void RenderWidget::InstallCreateHook(
405 CreateRenderWidgetFunction create_render_widget,
406 RenderWidgetInitializedCallback render_widget_initialized) {
407 CHECK(!g_create_render_widget && !g_render_widget_initialized);
408 g_create_render_widget = create_render_widget;
409 g_render_widget_initialized = render_widget_initialized;
410}
411
412// static
nickf7b38222016-11-22 21:59:35413RenderWidget* RenderWidget::CreateForPopup(
414 RenderViewImpl* opener,
415 CompositorDependencies* compositor_deps,
416 blink::WebPopupType popup_type,
417 const ScreenInfo& screen_info) {
nick4df698d82016-11-11 20:39:23418 // Do a synchronous IPC to obtain a routing ID.
419 int32_t routing_id = MSG_ROUTING_NONE;
420 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
nickf7b38222016-11-22 21:59:35421 opener->GetRoutingID(), popup_type, &routing_id)) {
nick4df698d82016-11-11 20:39:23422 return nullptr;
423 }
424
nick8331f8ad2016-11-15 20:42:45425 scoped_refptr<RenderWidget> widget(
426 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
427 false, false, false));
nickf7b38222016-11-22 21:59:35428 ShowCallback opener_callback =
wjmaclean1d970622017-01-21 22:28:24429 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr());
nickf7b38222016-11-22 21:59:35430 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23431 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
432 return widget.get();
initial.commit09911bf2008-07-26 23:55:29433}
434
[email protected]484955942010-08-19 16:13:18435// static
kenrba7199832015-01-22 23:44:59436RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23437 int widget_routing_id,
kenrba7199832015-01-22 23:44:59438 bool hidden,
ccameron2f451532016-09-07 21:49:27439 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59440 CompositorDependencies* compositor_deps,
441 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23442 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55443 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
444 // same routing ID for both the view routing ID and the main frame widget
445 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23446 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55447 if (view) {
avi8a45c1092016-03-01 16:12:34448 view->AttachWebFrameWidget(
449 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
450 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55451 }
dcheng35d31c112015-07-22 00:17:36452 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29453 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45454 ? g_create_render_widget(widget_routing_id, compositor_deps,
455 blink::WebPopupTypeNone, screen_info, false,
456 hidden, false)
457 : new RenderWidget(widget_routing_id, compositor_deps,
458 blink::WebPopupTypeNone, screen_info, false,
459 hidden, false));
simonhong628f9812015-04-27 23:13:20460 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23461 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59462 // this function returns.
nickf7b38222016-11-22 21:59:35463 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23464 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
465
466 if (g_render_widget_initialized)
467 g_render_widget_initialized(widget.get());
468 return widget.get();
kenrba7199832015-01-22 23:44:59469}
470
471// static
lfgcaab5142016-02-26 19:06:52472blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08473 RenderWidget* render_widget,
474 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55475 if (!frame->parent()) {
476 // TODO(dcheng): The main frame widget currently has a special case.
477 // Eliminate this once WebView is no longer a WebWidget.
478 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
479 }
dchengda9b4bb2015-07-20 20:58:08480 return blink::WebFrameWidget::create(render_widget, frame);
481}
482
483// static
kenrba7199832015-01-22 23:44:59484blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18485 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46486 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18487 break;
[email protected]180ef242013-11-07 06:50:46488 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44489 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18490 default:
491 NOTREACHED();
492 }
493 return NULL;
494}
495
dchengda9b4bb2015-07-20 20:58:08496void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32497 OnClose();
kenrba7199832015-01-22 23:44:59498}
499
alexmos78c9c0d2016-10-14 18:57:03500void RenderWidget::SetSwappedOut(bool is_swapped_out) {
501 // We should only toggle between states.
502 DCHECK(is_swapped_out_ != is_swapped_out);
503 is_swapped_out_ = is_swapped_out;
504
505 // If we are swapping out, we will call ReleaseProcess, allowing the process
506 // to exit if all of its RenderViews are swapped out. We wait until the
507 // WasSwappedOut call to do this, to allow the unload handler to finish.
508 // If we are swapping in, we call AddRefProcess to prevent the process from
509 // exiting.
510 if (!is_swapped_out_)
511 RenderProcess::current()->AddRefProcess();
512}
513
nickf7b38222016-11-22 21:59:35514void RenderWidget::Init(const ShowCallback& show_callback,
515 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21516 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23517 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29518
sadrul9fe48922017-01-23 18:59:49519 input_handler_ = base::MakeUnique<RenderWidgetInputHandler>(this, this);
nick8331f8ad2016-11-15 20:42:45520
nickf7b38222016-11-22 21:59:35521 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29522
lfg8ff33912016-09-13 20:59:21523 webwidget_internal_ = web_widget;
524 webwidget_mouse_lock_target_.reset(
525 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21526 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29527
nick4df698d82016-11-11 20:39:23528 RenderThread::Get()->AddRoute(routing_id_, this);
529 // Take a reference on behalf of the RenderThread. This will be balanced
530 // when we receive ViewMsg_Close.
531 AddRef();
532 if (RenderThreadImpl::current()) {
533 RenderThreadImpl::current()->WidgetCreated();
534 if (is_hidden_)
535 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29536 }
537}
538
[email protected]949b6592014-08-20 13:17:52539void RenderWidget::WasSwappedOut() {
540 // If we have been swapped out and no one else is using this process,
541 // it's safe to exit now.
542 CHECK(is_swapped_out_);
543 RenderProcess::current()->ReleaseProcess();
544}
545
[email protected]b2e4c70132013-10-03 02:07:51546void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39547 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51548 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43549 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49550 popup_screen_origin_for_emulation_ = gfx::Point(
551 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
552 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56553 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27554 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51555}
556
[email protected]2d6836f42014-07-02 17:25:31557gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
558 if (screen_metrics_emulator_)
559 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
560 return anchor;
561}
562
haibinluc643d33c2016-06-03 02:22:34563#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51564void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39565 ExternalPopupMenu* popup,
566 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49567 popup->SetOriginScaleAndOffsetForEmulation(
568 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51569}
[email protected]53907862014-03-25 15:42:40570#endif
[email protected]b2e4c70132013-10-03 02:07:51571
572void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
573 if (screen_metrics_emulator_)
574 screen_metrics_emulator_->OnShowContextMenu(params);
575}
576
[email protected]a95986a82010-12-24 06:19:28577bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47578#if defined(OS_MACOSX)
579 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
580 return text_input_client_observer_->OnMessageReceived(message);
581#endif
lfgbee1e0a2016-06-08 21:24:21582 if (mouse_lock_dispatcher_ &&
583 mouse_lock_dispatcher_->OnMessageReceived(message))
584 return true;
585
[email protected]a95986a82010-12-24 06:19:28586 bool handled = true;
587 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15588 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22589 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
590 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22591 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29592 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
593 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
594 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15595 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46596 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
597 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15598 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35599 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
600 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28601 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28602 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20603 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
604 OnEnableDeviceEmulation)
605 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
606 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28607 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41608 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25609 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28610 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
611 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03612 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbea731792017-01-13 15:10:48613 IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection,
614 OnSetViewportIntersection)
lfg43e08e62016-02-03 18:51:37615 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
616 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18617 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
618 OnRequestCompositionUpdate)
paulmeyer90f6c31d2016-11-12 00:17:59619 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
620 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
621 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
622 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21623 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
624 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
625 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21626#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:39627 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
628 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21629#endif
[email protected]a95986a82010-12-24 06:19:28630 IPC_MESSAGE_UNHANDLED(handled = false)
631 IPC_END_MESSAGE_MAP()
632 return handled;
633}
initial.commit09911bf2008-07-26 23:55:29634
635bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15636 // Don't send any messages after the browser has told us to close, and filter
637 // most outgoing messages while swapped out.
638 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26639 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11640 closing_) {
initial.commit09911bf2008-07-26 23:55:29641 delete message;
642 return false;
643 }
644
645 // If given a messsage without a routing ID, then assign our routing ID.
646 if (message->routing_id() == MSG_ROUTING_NONE)
647 message->set_routing_id(routing_id_);
648
[email protected]380244092011-10-07 17:26:27649 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44650}
651
dtapuska014ed082016-11-11 21:58:48652void RenderWidget::SendOrCrash(IPC::Message* message) {
653 bool result = Send(message);
654 CHECK(closing_ || result) << "Failed to send message";
655}
656
ekaramad5aff1942017-01-06 01:26:35657bool RenderWidget::ShouldHandleImeEvents() const {
658 return GetWebWidget()->isWebFrameWidget() && has_focus_;
659}
660
bokanc007c3a2015-02-03 07:15:56661void RenderWidget::SetWindowRectSynchronously(
662 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39663 ResizeParams params;
664 params.screen_info = screen_info_;
665 params.new_size = new_window_rect.size();
666 params.physical_backing_size =
667 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39668 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39669 params.is_fullscreen_granted = is_fullscreen_granted_;
670 params.display_mode = display_mode_;
671 params.needs_resize_ack = false;
672 Resize(params);
673
bokanc007c3a2015-02-03 07:15:56674 view_screen_rect_ = new_window_rect;
675 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02676 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56677 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02678}
679
initial.commit09911bf2008-07-26 23:55:29680void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32681 DCHECK(content::RenderThread::Get());
682 if (closing_)
683 return;
684 NotifyOnClose();
685 closing_ = true;
686
687 // Browser correspondence is no longer needed at this point.
688 if (routing_id_ != MSG_ROUTING_NONE) {
689 RenderThread::Get()->RemoveRoute(routing_id_);
690 SetHidden(false);
691 if (RenderThreadImpl::current())
692 RenderThreadImpl::current()->WidgetDestroyed();
693 }
694
695 if (for_oopif_) {
696 // Widgets for frames may be created and closed at any time while the frame
697 // is alive. However, the closing process must happen synchronously. Frame
698 // widget and frames hold pointers to each other. If Close() is deferred to
699 // the message loop like in the non-frame widget case, WebWidget::close()
700 // can end up accessing members of an already-deleted frame.
701 Close();
702 } else {
703 // If there is a Send call on the stack, then it could be dangerous to close
704 // now. Post a task that only gets invoked when there are no nested message
705 // loops.
706 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
707 FROM_HERE, base::Bind(&RenderWidget::Close, this));
708 }
709
710 // Balances the AddRef taken when we called AddRoute.
711 Release();
initial.commit09911bf2008-07-26 23:55:29712}
713
fsamuel664e8b62016-01-20 19:54:01714void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04715 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32716 return;
717
[email protected]b2e4c70132013-10-03 02:07:51718 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39719 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51720 return;
721 }
722
mfomitchev2600fd7c2016-02-17 20:53:39723 Resize(params);
initial.commit09911bf2008-07-26 23:55:29724}
725
dgozman9260b0a12015-03-16 13:45:20726void RenderWidget::OnEnableDeviceEmulation(
727 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39728 if (!screen_metrics_emulator_) {
729 ResizeParams resize_params;
730 resize_params.screen_info = screen_info_;
731 resize_params.new_size = size_;
732 resize_params.physical_backing_size = physical_backing_size_;
733 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39734 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
735 resize_params.display_mode = display_mode_;
736 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
737 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18738 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39739 } else {
dgozman9260b0a12015-03-16 13:45:20740 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39741 }
dgozman9260b0a12015-03-16 13:45:20742}
743
744void RenderWidget::OnDisableDeviceEmulation() {
745 screen_metrics_emulator_.reset();
746}
747
initial.commit09911bf2008-07-26 23:55:29748void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31749 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29750 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03751 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55752 for (auto& observer : render_frames_)
753 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29754}
755
[email protected]3399dd822014-08-09 11:14:24756void RenderWidget::OnWasShown(bool needs_repainting,
757 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41758 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29759 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21760 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29761 return;
762
763 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03764 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55765 for (auto& observer : render_frames_)
766 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29767
[email protected]8a23afb32014-04-30 22:40:23768 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29769 return;
initial.commit09911bf2008-07-26 23:55:29770
771 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24772 if (compositor_) {
773 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15774 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24775 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05776 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24777 }
jdduke491a3f0c2015-06-15 23:30:26778 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29779}
780
[email protected]53d3f302009-12-21 04:42:05781void RenderWidget::OnRequestMoveAck() {
782 DCHECK(pending_window_rect_count_);
783 pending_window_rect_count_--;
784}
785
[email protected]ed7defa2013-03-12 21:29:59786GURL RenderWidget::GetURLForGraphicsContext3D() {
787 return GURL();
[email protected]65225772011-05-12 21:10:24788}
789
nzolghadr5d8596502017-01-23 22:59:35790void RenderWidget::OnHandleInputEvent(
791 const blink::WebInputEvent* input_event,
792 const std::vector<const blink::WebInputEvent*>& coalesced_events,
793 const ui::LatencyInfo& latency_info,
794 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23795 if (!input_event)
796 return;
nzolghadr5d8596502017-01-23 22:59:35797
798 input_handler_->HandleInputEvent(
799 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
800 latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23801}
802
803void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21804 if (GetWebWidget())
805 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23806}
807
808void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21809 if (GetWebWidget())
810 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23811}
812
alexmos56567492016-09-13 00:52:46813void RenderWidget::OnSetEditCommandsForNextKeyEvent(
814 const EditCommands& edit_commands) {
815 edit_commands_ = edit_commands;
816}
817
fsamuel78f86e42016-01-20 04:10:23818void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08819 has_focus_ = enable;
820
lfg8ff33912016-09-13 20:59:21821 if (GetWebWidget())
822 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08823
ericwilligers88e69742016-10-17 19:29:55824 for (auto& observer : render_frames_)
825 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23826}
827
dtapuska3d5624d32016-08-30 04:34:00828void RenderWidget::SetNeedsMainFrame() {
829 RenderWidgetCompositor* rwc = compositor();
830 if (!rwc)
831 return;
832 rwc->setNeedsBeginFrame();
833}
834
fsamuel78f86e42016-01-20 04:10:23835///////////////////////////////////////////////////////////////////////////////
836// RenderWidgetCompositorDelegate
837
838void RenderWidget::ApplyViewportDeltas(
839 const gfx::Vector2dF& inner_delta,
840 const gfx::Vector2dF& outer_delta,
841 const gfx::Vector2dF& elastic_overscroll_delta,
842 float page_scale,
843 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21844 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
845 elastic_overscroll_delta, page_scale,
846 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23847}
848
849void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00850 RenderThreadImpl* render_thread = RenderThreadImpl::current();
851 // render_thread may be NULL in tests.
852 InputHandlerManager* input_handler_manager =
853 render_thread ? render_thread->input_handler_manager() : NULL;
854 if (input_handler_manager)
855 input_handler_manager->ProcessRafAlignedInputOnMainThread(routing_id_);
856
lfg8ff33912016-09-13 20:59:21857 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23858}
859
danakj1120f4c2016-09-15 02:05:32860std::unique_ptr<cc::CompositorFrameSink>
samansd5db2502017-01-13 23:18:27861RenderWidget::CreateCompositorFrameSink(const cc::FrameSinkId& frame_sink_id,
862 bool fallback) {
lfg8ff33912016-09-13 20:59:21863 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03864 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32865 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39866 DCHECK(!compositor_never_visible_);
danakj1120f4c2016-09-15 02:05:32867 return RenderThreadImpl::current()->CreateCompositorFrameSink(
samansd5db2502017-01-13 23:18:27868 frame_sink_id, fallback, routing_id_, frame_swap_message_queue_,
danakj83066a32016-06-21 02:34:49869 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28870}
871
fsamuel78f86e42016-01-20 04:10:23872void RenderWidget::DidCommitAndDrawCompositorFrame() {
873 // NOTE: Tests may break if this event is renamed or moved. See
874 // tab_capture_performancetest.cc.
875 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08876
ericwilligers88e69742016-10-17 19:29:55877 for (auto& observer : render_frames_)
878 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08879
fsamuel78f86e42016-01-20 04:10:23880 // Notify subclasses that we initiated the paint operation.
881 DidInitiatePaint();
882}
883
884void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55885 for (auto& observer : render_frames_)
886 observer.DidCommitCompositorFrame();
887 for (auto& observer : render_frame_proxies_)
888 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23889}
890
891void RenderWidget::DidCompletePageScaleAnimation() {}
892
danakj6c872fc02016-10-22 04:29:49893void RenderWidget::DidReceiveCompositorFrameAck() {
894 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23895
pimanbfb2ceb2016-03-18 21:32:58896 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23897 return;
898 }
899
900 ViewHostMsg_UpdateRect_Params params;
901 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23902 params.flags = next_paint_flags_;
903
904 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
905 next_paint_flags_ = 0;
906 need_update_rect_for_auto_resize_ = false;
907}
908
fsamuel78f86e42016-01-20 04:10:23909bool RenderWidget::IsClosing() const {
910 return host_closing_;
911}
912
danakj53eccbc2016-03-02 22:51:07913void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23914 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29915}
916
fsamuel78f86e42016-01-20 04:10:23917void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21918 GetWebWidget()->updateAllLifecyclePhases();
fsamuel78f86e42016-01-20 04:10:23919}
920
921void RenderWidget::WillBeginCompositorFrame() {
922 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
923
dglazkov06854c5c2016-08-31 00:19:59924 // The UpdateTextInputState can result in further layout and possibly
925 // enable GPU acceleration so they need to be called before any painting
926 // is done.
changwan75e3b2072017-01-16 02:55:00927 UpdateTextInputState();
dglazkov06854c5c2016-08-31 00:19:59928 UpdateSelectionBounds();
929
ericwilligers88e69742016-10-17 19:29:55930 for (auto& observer : render_frame_proxies_)
931 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:29932}
933
jbroman6ccbc7d472016-07-27 04:45:41934std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
935 std::unique_ptr<cc::CopyOutputRequest> request) {
936 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
937 routing_id_, std::move(request));
938}
939
fsamuel72464894f2015-12-15 06:59:31940///////////////////////////////////////////////////////////////////////////////
941// RenderWidgetInputHandlerDelegate
942
avid7d6b2e2016-03-04 19:41:17943void RenderWidget::FocusChangeComplete() {
944 if (owner_delegate_)
945 owner_delegate_->RenderWidgetFocusChangeComplete();
946}
fsamuel72464894f2015-12-15 06:59:31947
948bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17949 if (owner_delegate_)
950 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
951
fsamuel72464894f2015-12-15 06:59:31952 return true;
953}
954
dtapuska1827dd22016-03-11 15:24:59955void RenderWidget::ObserveGestureEventAndResult(
956 const blink::WebGestureEvent& gesture_event,
957 const gfx::Vector2dF& unused_delta,
958 bool event_processed) {
959 if (!compositor_deps_->IsElasticOverscrollEnabled())
960 return;
961
962 cc::InputHandlerScrollResult scroll_result;
963 scroll_result.did_scroll = event_processed;
964 scroll_result.did_overscroll_root = !unused_delta.IsZero();
965 scroll_result.unused_scroll_delta = unused_delta;
966
967 RenderThreadImpl* render_thread = RenderThreadImpl::current();
968 InputHandlerManager* input_handler_manager =
969 render_thread ? render_thread->input_handler_manager() : NULL;
970 if (input_handler_manager) {
971 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
972 routing_id_, gesture_event, scroll_result);
973 }
974}
975
avid7d6b2e2016-03-04 19:41:17976void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:46977 ClearEditCommands();
978}
979
980void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
981 const std::string& value) {
982 ClearEditCommands();
983 edit_commands_.emplace_back(name, value);
984}
985
986void RenderWidget::ClearEditCommands() {
987 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:17988}
fsamuel72464894f2015-12-15 06:59:31989
chongza8ba91fc2016-08-16 21:39:17990void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31991 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
992}
993
dchengcedca5612016-04-09 01:40:15994void RenderWidget::OnInputEventAck(
995 std::unique_ptr<InputEventAck> input_event_ack) {
dtapuska014ed082016-11-11 21:58:48996 SendOrCrash(
997 new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
fsamuel72464894f2015-12-15 06:59:31998}
999
dtapuska46616922016-03-17 22:52:011000void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:071001 blink::WebInputEvent::Type handled_type,
1002 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:101003 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1004 InputHandlerManager* input_handler_manager =
1005 render_thread ? render_thread->input_handler_manager() : NULL;
1006 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:071007 input_handler_manager->NotifyInputEventHandledOnMainThread(
1008 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:101009 }
1010}
1011
fsamuele8326c742016-01-12 00:49:391012void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1013 // Nothing to do here. RenderWidget created the |input_handler| and will take
1014 // ownership of it. We just verify here that we don't already have an input
1015 // handler.
1016 DCHECK(!input_handler_);
1017}
1018
changwan75e3b2072017-01-16 02:55:001019void RenderWidget::ShowVirtualKeyboard() {
1020 UpdateTextInputStateInternal(true, false);
1021}
1022
1023void RenderWidget::UpdateTextInputState() {
1024 UpdateTextInputStateInternal(false, false);
1025}
1026
1027void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard,
1028 bool reply_to_request) {
fsamuel72464894f2015-12-15 06:59:311029 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwan75e3b2072017-01-16 02:55:001030
fsamuel72464894f2015-12-15 06:59:311031 if (ime_event_guard_) {
changwan75e3b2072017-01-16 02:55:001032 DCHECK(!reply_to_request);
1033 // show_virtual_keyboard should still be effective even if it was set inside
1034 // the IME
fsamuel72464894f2015-12-15 06:59:311035 // event guard.
changwan75e3b2072017-01-16 02:55:001036 if (show_virtual_keyboard)
1037 ime_event_guard_->set_show_virtual_keyboard(true);
fsamuel72464894f2015-12-15 06:59:311038 return;
1039 }
1040
dglazkov97b6c2b2016-10-25 17:35:551041 ui::TextInputType new_type = GetTextInputType();
1042 if (IsDateTimeInput(new_type))
1043 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311044
dglazkov97b6c2b2016-10-25 17:35:551045 blink::WebTextInputInfo new_info;
ekaramad5aff1942017-01-06 01:26:351046 if (auto* controller = GetInputMethodController())
1047 new_info = controller->textInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101048 const ui::TextInputMode new_mode =
1049 ConvertWebTextInputMode(new_info.inputMode);
fsamuel72464894f2015-12-15 06:59:311050
1051 bool new_can_compose_inline = CanComposeInline();
1052
1053 // Only sends text input params if they are changed or if the ime should be
1054 // shown.
changwan75e3b2072017-01-16 02:55:001055 if (show_virtual_keyboard || reply_to_request ||
changwan38c3eb612016-12-09 01:45:561056 text_input_type_ != new_type || text_input_mode_ != new_mode ||
1057 text_input_info_ != new_info ||
1058 can_compose_inline_ != new_can_compose_inline) {
ekaramad9053e57b2016-04-26 20:00:381059 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551060 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311061 params.mode = new_mode;
1062 params.flags = new_info.flags;
1063 params.value = new_info.value.utf8();
1064 params.selection_start = new_info.selectionStart;
1065 params.selection_end = new_info.selectionEnd;
1066 params.composition_start = new_info.compositionStart;
1067 params.composition_end = new_info.compositionEnd;
1068 params.can_compose_inline = new_can_compose_inline;
changwan75e3b2072017-01-16 02:55:001069 // TODO(changwan): change instances of show_ime_if_needed to
1070 // show_virtual_keyboard.
1071 params.show_ime_if_needed = show_virtual_keyboard;
1072 params.reply_to_request = reply_to_request;
fsamuel72464894f2015-12-15 06:59:311073 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1074
1075 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551076 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311077 text_input_mode_ = new_mode;
1078 can_compose_inline_ = new_can_compose_inline;
1079 text_input_flags_ = new_info.flags;
1080 }
1081}
1082
1083bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581084 possible_drag_event_info_.event_source =
1085 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1086 possible_drag_event_info_.event_location =
1087 gfx::Point(event.globalX, event.globalY);
avid7d6b2e2016-03-04 19:41:171088
fsamuel72464894f2015-12-15 06:59:311089 return false;
1090}
1091
1092bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551093 for (auto& observer : render_frames_)
1094 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081095
paulmeyer6ef5a792016-11-08 20:33:581096 possible_drag_event_info_.event_source =
1097 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1098 possible_drag_event_info_.event_location =
1099 gfx::Point(event.globalX, event.globalY);
1100
avid7d6b2e2016-03-04 19:41:171101 if (owner_delegate_)
1102 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1103
fsamuel72464894f2015-12-15 06:59:311104 return false;
[email protected]fd847792013-10-24 17:12:351105}
1106
initial.commit09911bf2008-07-26 23:55:291107///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391108// RenderWidgetScreenMetricsDelegate
1109
1110void RenderWidget::Redraw() {
1111 set_next_paint_is_resize_ack();
1112 if (compositor_)
1113 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1114}
1115
bokanc63441c2016-04-27 15:49:121116void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211117 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121118}
1119
1120gfx::Size RenderWidget::GetSizeForWebWidget() const {
1121 if (IsUseZoomForDSFEnabled())
1122 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1123
1124 return size_;
1125}
1126
mfomitchev2600fd7c2016-02-17 20:53:391127void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581128 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271129 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1130 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581131
mfomitchev2600fd7c2016-02-17 20:53:391132 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581133
ccameron2f451532016-09-07 21:49:271134 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1135 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581136 OnDeviceScaleFactorChanged();
1137 ScheduleComposite();
1138 }
mfomitchev2600fd7c2016-02-17 20:53:391139
1140 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1141 // A resize ack shouldn't be requested if we have not ACK'd the previous
1142 // one.
1143 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1144 }
1145
1146 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211147 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391148 return;
1149
ianwene5fc5782016-08-18 04:05:151150 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391151 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151152 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameronf408cab2016-09-14 16:54:421153 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
ianwene5fc5782016-08-18 04:05:151154 }
mfomitchev2600fd7c2016-02-17 20:53:391155
mfomitchev2600fd7c2016-02-17 20:53:391156 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391157
1158 // NOTE: We may have entered fullscreen mode without changing our size.
1159 bool fullscreen_change =
1160 is_fullscreen_granted_ != params.is_fullscreen_granted;
1161 is_fullscreen_granted_ = params.is_fullscreen_granted;
1162 display_mode_ = params.display_mode;
1163
bokanc63441c2016-04-27 15:49:121164 size_ = params.new_size;
1165 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391166
bokanc63441c2016-04-27 15:49:121167 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221168
mfomitchev2600fd7c2016-02-17 20:53:391169 WebSize visual_viewport_size;
1170
1171 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181172 visual_viewport_size = gfx::ScaleToCeiledSize(
1173 params.visible_viewport_size,
1174 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391175 } else {
1176 visual_viewport_size = visible_viewport_size_;
1177 }
1178
lfg8ff33912016-09-13 20:59:211179 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391180
bokanc63441c2016-04-27 15:49:121181 // When resizing, we want to wait to paint before ACK'ing the resize. This
1182 // ensures that we only resize as fast as we can paint. We only need to
1183 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391184 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1185 // In this case there is no paint/composite and therefore no
1186 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1187 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1188 DCHECK(!params.needs_resize_ack);
1189 }
1190
1191 // Send the Resize_ACK flag once we paint again if requested.
1192 if (params.needs_resize_ack)
1193 set_next_paint_is_resize_ack();
1194
1195 if (fullscreen_change)
1196 DidToggleFullscreen();
1197
engedy6cb63c92016-02-23 14:14:581198 if (orientation_changed)
1199 OnOrientationChange();
1200
mfomitchev2600fd7c2016-02-17 20:53:391201 // If a resize ack is requested and it isn't set-up, then no more resizes will
1202 // come in and in general things will go wrong.
1203 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1204}
1205
1206void RenderWidget::SetScreenMetricsEmulationParameters(
1207 bool enabled,
1208 const blink::WebDeviceEmulationParams& params) {
1209 // This is only supported in RenderView.
1210 NOTREACHED();
1211}
1212
1213void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1214 const gfx::Rect& window_screen_rect) {
1215 view_screen_rect_ = view_screen_rect;
1216 window_screen_rect_ = window_screen_rect;
1217}
1218
1219///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461220// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291221
[email protected]3a1c8a8032013-03-18 22:35:321222void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401223 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051224 if (compositor_)
oshima750cb4342015-10-31 00:59:011225 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051226}
1227
loyso50b51c22017-01-10 07:18:371228blink::WebLayerTreeView* RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221229 DCHECK(!host_closing_);
1230
loyso6e6efc42017-01-21 02:23:031231 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
1232 auto animation_host = cc::AnimationHost::CreateMainInstance();
1233
1234 auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost(
1235 compositor_.get(), compositor_.get(), animation_host.get(),
1236 compositor_deps_, device_scale_factor_, screen_info_);
1237 compositor_->Initialize(std::move(layer_tree_host),
1238 std::move(animation_host));
1239
wjmaclean1d970622017-01-21 22:28:241240 compositor_->SetIsForOopif(for_oopif_);
oshima750cb4342015-10-31 00:59:011241 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331242 OnDeviceScaleFactorChanged();
ccameronf408cab2016-09-14 16:54:421243 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
sievers71c62dd52015-10-07 01:44:391244 // For background pages and certain tests, we don't want to trigger
danakj1120f4c2016-09-15 02:05:321245 // CompositorFrameSink creation.
sievers71c62dd52015-10-07 01:44:391246 if (compositor_never_visible_ || !RenderThreadImpl::current())
1247 compositor_->SetNeverVisible();
1248
pimanc4af3072015-10-02 03:45:591249 StartCompositor();
staraz067f58242016-11-07 21:06:411250 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1251 compositor_->SetFrameSinkId(
1252 cc::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
loyso50b51c22017-01-10 07:18:371253
wjmaclean1d970622017-01-21 22:28:241254 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1255 // render_thread may be NULL in tests.
1256 InputHandlerManager* input_handler_manager =
1257 render_thread ? render_thread->input_handler_manager() : NULL;
1258 if (input_handler_manager) {
1259 input_handler_manager->AddInputHandler(
1260 routing_id_, compositor()->GetInputHandler(),
1261 weak_ptr_factory_.GetWeakPtr(),
1262 compositor_deps_->IsScrollAnimatorEnabled());
1263 has_added_input_handler_ = true;
1264 }
1265
loyso50b51c22017-01-10 07:18:371266 return compositor_.get();
[email protected]e195e582013-03-08 01:32:591267}
1268
ennef3c58142014-12-09 21:44:381269void RenderWidget::WillCloseLayerTreeView() {
1270 if (host_closing_)
1271 return;
1272
1273 // Prevent new compositors or output surfaces from being created.
1274 host_closing_ = true;
1275
[email protected]aeeedad2014-08-22 18:16:221276 // Always send this notification to prevent new layer tree views from
1277 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211278 if (blink::WebWidget* widget = GetWebWidget())
1279 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221280}
1281
dglazkovf0e1d6d2015-10-10 02:13:481282void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1283 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1284 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1285 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1286 }
dglazkov79c426102015-08-31 21:22:431287
ericwilligers88e69742016-10-17 19:29:551288 for (auto& observer : render_frames_)
1289 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431290}
1291
jdduke491a3f0c2015-06-15 23:30:261292void RenderWidget::ScheduleComposite() {
1293 if (compositor_ &&
1294 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
skyostil32650d22016-09-26 16:58:231295 compositor_->setNeedsCompositorUpdate();
jdduke491a3f0c2015-06-15 23:30:261296 }
1297}
1298
1299void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1300 if (compositor_) {
1301 // Regardless of whether threaded compositing is enabled, always
1302 // use this mechanism to force the compositor to redraw. However,
1303 // the invalidation code path below is still needed for the
1304 // non-threaded case.
1305 compositor_->SetNeedsForcedRedraw();
1306 }
1307 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151308}
1309
[email protected]586871b2014-07-22 17:05:111310// static
dchengcedca5612016-04-09 01:40:151311std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111312 IPC::Message* msg,
1313 MessageDeliveryPolicy policy,
1314 FrameSwapMessageQueue* frame_swap_message_queue,
1315 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111316 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111317 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151318 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1319 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111320 &first_message_for_frame);
1321 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151322 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111323 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061324 return promise;
[email protected]586871b2014-07-22 17:05:111325 }
dcheng4b6b5ff2014-10-16 00:42:061326 return nullptr;
[email protected]586871b2014-07-22 17:05:111327}
1328
1329void RenderWidget::QueueMessage(IPC::Message* msg,
1330 MessageDeliveryPolicy policy) {
1331 // RenderThreadImpl::current() is NULL in some tests.
1332 if (!compositor_ || !RenderThreadImpl::current()) {
1333 Send(msg);
1334 return;
1335 }
1336
dchengcedca5612016-04-09 01:40:151337 std::unique_ptr<cc::SwapPromise> swap_promise =
1338 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111339 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111340 compositor_->GetSourceFrameNumber());
1341
1342 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321343 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351344 // Request a commit. This might either A) request a commit ahead of time
1345 // or B) request a commit which is not needed because there are not
1346 // pending updates. If B) then the commit will be skipped and the swap
1347 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1348 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1349 // can_cancel_commit is not unset.
1350 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111351 }
1352}
1353
[email protected]4873c7d2009-07-16 06:36:281354void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301355 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521356 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181357 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291358 // Only send a SetCursor message if we need to make a change.
1359 if (!current_cursor_.IsEqual(cursor)) {
1360 current_cursor_ = cursor;
1361 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1362 }
1363}
1364
1365// We are supposed to get a single call to Show for a newly created RenderWidget
1366// that was created via RenderWidget::CreateWebView. So, we wait until this
1367// point to dispatch the ShowWidget message.
1368//
1369// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281370// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291371//
nickf7b38222016-11-22 21:59:351372void RenderWidget::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291373 DCHECK(!did_show_) << "received extraneous Show call";
1374 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351375 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291376
[email protected]8de12d942010-11-17 20:42:441377 if (did_show_)
1378 return;
1379
1380 did_show_ = true;
nickf7b38222016-11-22 21:59:351381
1382 // The opener is responsible for actually showing this widget.
1383 show_callback_.Run(this, policy, initial_rect_);
nick5ae4d2d2017-01-06 01:18:351384 show_callback_.Reset();
nickf7b38222016-11-22 21:59:351385
bokanc007c3a2015-02-03 07:15:561386 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441387 // that's okay. It'll be ignored if as_popup is false, or the browser
1388 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561389 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291390}
1391
[email protected]2533ce12009-05-09 00:02:241392void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381393 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241394 Send(new ViewHostMsg_Close(routing_id_));
1395}
1396
dgozmancf9039cd2015-04-06 12:01:311397void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551398 for (auto& observer : render_frames_)
1399 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311400}
1401
[email protected]4873c7d2009-07-16 06:36:281402void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081403 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321404 if (is_swapped_out_) {
1405 // This widget is currently swapped out, and the active widget is in a
1406 // different process. Have the browser route the close request to the
1407 // active widget instead, so that the correct unload handlers are run.
1408 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1409 return;
1410 }
1411
initial.commit09911bf2008-07-26 23:55:291412 // If a page calls window.close() twice, we'll end up here twice, but that's
1413 // OK. It is safe to send multiple Close messages.
1414
[email protected]2533ce12009-05-09 00:02:241415 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1416 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1417 // could be closed before the JS finishes executing. So instead, post a
1418 // message back to the message loop, which won't run until the JS is
1419 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081420 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211421 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291422}
1423
[email protected]9017d7852013-11-21 17:47:351424void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151425 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351426 const SyntheticGestureCompletionCallback& callback) {
1427 DCHECK(!callback.is_null());
1428
1429 pending_synthetic_gesture_callbacks_.push(callback);
1430
1431 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321432 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351433
1434 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1435}
1436
initial.commit09911bf2008-07-26 23:55:291437void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031438 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381439 WillCloseLayerTreeView();
1440 compositor_.reset();
lfg8ff33912016-09-13 20:59:211441 if (webwidget_internal_) {
1442 webwidget_internal_->close();
1443 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291444 }
1445}
1446
bokan841fdc72016-10-06 00:16:351447void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1448 DCHECK(window_rect);
1449 float scale = popup_origin_scale_for_emulation_;
1450 if (!scale)
1451 return;
1452 window_rect->x =
1453 popup_view_origin_for_emulation_.x() +
1454 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1455 window_rect->y =
1456 popup_view_origin_for_emulation_.y() +
1457 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1458}
1459
1460void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1461 DCHECK(window_rect);
1462 float scale = popup_origin_scale_for_emulation_;
1463 if (!scale)
1464 return;
1465 window_rect->x =
1466 popup_screen_origin_for_emulation_.x() +
1467 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1468 window_rect->y =
1469 popup_screen_origin_for_emulation_.y() +
1470 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1471}
1472
[email protected]4873c7d2009-07-16 06:36:281473WebRect RenderWidget::windowRect() {
bokan841fdc72016-10-06 00:16:351474 WebRect rect;
bokan6b08cd22016-10-05 00:55:211475 if (pending_window_rect_count_) {
1476 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1477 // the RootWindowRect is probably going to return wrong results since the
1478 // browser may not have processed the Move yet. There isn't really anything
1479 // good to do in this case, and it shouldn't happen - since this size is
1480 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351481 rect = pending_window_rect_;
1482 } else {
1483 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211484 }
[email protected]2533ce12009-05-09 00:02:241485
bokan841fdc72016-10-06 00:16:351486 ScreenRectToEmulatedIfNeeded(&rect);
1487 return rect;
bokan6b08cd22016-10-05 00:55:211488}
1489
1490WebRect RenderWidget::viewRect() {
bokan841fdc72016-10-06 00:16:351491 WebRect rect = view_screen_rect_;
1492 ScreenRectToEmulatedIfNeeded(&rect);
1493 return rect;
initial.commit09911bf2008-07-26 23:55:291494}
1495
[email protected]180ef242013-11-07 06:50:461496void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301497 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541498 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301499}
1500
oshima33ec97cd2015-12-14 19:40:241501void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1502 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351503 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511504
[email protected]5b45ad42013-10-25 00:42:041505 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201506 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561507 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1508 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031509 } else {
bokanc007c3a2015-02-03 07:15:561510 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031511 }
initial.commit09911bf2008-07-26 23:55:291512 } else {
bokanc007c3a2015-02-03 07:15:561513 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291514 }
1515}
1516
[email protected]2533ce12009-05-09 00:02:241517void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1518 pending_window_rect_ = rect;
1519 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241520
bokan6b08cd22016-10-05 00:55:211521 // Popups don't get size updates back from the browser so just store the set
1522 // values.
1523 if (popup_type_ != blink::WebPopupTypeNone) {
1524 window_screen_rect_ = rect;
1525 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241526 }
[email protected]d4547452008-08-28 18:36:371527}
1528
[email protected]fa7b1dc2010-06-23 17:53:041529void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261530 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041531 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071532 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041533 int selection_start, int selection_end) {
ekaramad5aff1942017-01-06 01:26:351534 if (!ShouldHandleImeEvents())
1535 return;
1536
brettw4b461082016-11-19 18:55:161537#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091538 if (focused_pepper_plugin_) {
1539 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1540 text, underlines, selection_start, selection_end);
1541 return;
1542 }
1543#endif
1544 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211545 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031546 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091547 }
1548
changwan38c3eb612016-12-09 01:45:561549 if (!GetWebWidget())
[email protected]4873c7d2009-07-16 06:36:281550 return;
[email protected]66fca5bc2013-05-23 06:58:291551 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011552 blink::WebInputMethodController* controller = GetInputMethodController();
ekaramad2daaf672016-11-10 20:29:011553 if (!controller ||
1554 !controller->setComposition(
lfg8ff33912016-09-13 20:59:211555 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1556 selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041557 // If we failed to set the composition text, then we need to let the browser
1558 // process to cancel the input method's ongoing composition session, to make
1559 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221560 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261561 }
nonafa291792016-08-10 02:36:181562 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041563}
1564
rlanday7efe2302017-01-11 00:14:281565void RenderWidget::OnImeCommitText(
1566 const base::string16& text,
1567 const std::vector<WebCompositionUnderline>& underlines,
1568 const gfx::Range& replacement_range,
1569 int relative_cursor_pos) {
ekaramad5aff1942017-01-06 01:26:351570 if (!ShouldHandleImeEvents())
1571 return;
1572
brettw4b461082016-11-19 18:55:161573#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091574 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291575 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1576 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091577 return;
1578 }
1579#endif
1580 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211581 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031582 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091583 }
1584
changwan38c3eb612016-12-09 01:45:561585 if (!GetWebWidget())
[email protected]d0be63772011-12-20 23:18:041586 return;
[email protected]66fca5bc2013-05-23 06:58:291587 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391588 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011589 if (auto* controller = GetInputMethodController())
rlanday7efe2302017-01-11 00:14:281590 controller->commitText(text, WebVector<WebCompositionUnderline>(underlines),
1591 relative_cursor_pos);
aelias87b8f7c2016-09-14 03:19:291592 input_handler_->set_handling_input_event(false);
1593 UpdateCompositionInfo(false /* not an immediate request */);
1594}
1595
1596void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
ekaramad5aff1942017-01-06 01:26:351597 if (!ShouldHandleImeEvents())
1598 return;
1599
brettw4b461082016-11-19 18:55:161600#if BUILDFLAG(ENABLE_PLUGINS)
aelias87b8f7c2016-09-14 03:19:291601 if (focused_pepper_plugin_) {
1602 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1603 keep_selection);
1604 return;
1605 }
1606#endif
1607
changwan38c3eb612016-12-09 01:45:561608 if (!GetWebWidget())
aelias87b8f7c2016-09-14 03:19:291609 return;
1610 ImeEventGuard guard(this);
1611 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011612 if (auto* controller = GetInputMethodController()) {
1613 controller->finishComposingText(
1614 keep_selection ? WebInputMethodController::KeepSelection
1615 : WebInputMethodController::DoNotKeepSelection);
1616 }
fsamuele8326c742016-01-12 00:49:391617 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181618 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291619}
1620
oshimad5279032015-12-16 18:22:331621void RenderWidget::OnDeviceScaleFactorChanged() {
1622 if (!compositor_)
1623 return;
oshimad5279032015-12-16 18:22:331624 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181625 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331626 else
1627 compositor_->setDeviceScaleFactor(device_scale_factor_);
1628}
1629
[email protected]0bc1f572013-04-17 01:46:311630void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121631 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211632 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121633 return;
1634
[email protected]0bc1f572013-04-17 01:46:311635 // Even if the browser provides an empty damage rect, it's still expecting to
1636 // receive a repaint ack so just damage the entire widget bounds.
1637 if (size_to_paint.IsEmpty()) {
1638 size_to_paint = size_;
1639 }
1640
[email protected]ec7dc112008-08-06 05:30:121641 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051642 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311643 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121644}
1645
[email protected]79fa22e2013-08-23 15:18:121646void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351647 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1648
1649 pending_synthetic_gesture_callbacks_.front().Run();
1650 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271651}
1652
[email protected]4873c7d2009-07-16 06:36:281653void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211654 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111655 return;
lfg8ff33912016-09-13 20:59:211656 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111657}
1658
[email protected]80ad8622012-11-07 16:33:031659void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1660 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511661 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391662 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1663 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511664 } else {
mfomitchev2600fd7c2016-02-17 20:53:391665 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511666 }
[email protected]80ad8622012-11-07 16:33:031667 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1668}
1669
lfgdb5c4ed2016-03-04 23:09:071670void RenderWidget::OnUpdateWindowScreenRect(
1671 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211672 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071673 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211674 else
lfgdb5c4ed2016-03-04 23:09:071675 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071676}
1677
kenrbea731792017-01-13 15:10:481678void RenderWidget::OnSetViewportIntersection(
1679 const gfx::Rect& viewport_intersection) {
1680 if (GetWebWidget() && GetWebWidget()->isWebFrameWidget()) {
1681 DCHECK(popup_type_ == WebPopupType::WebPopupTypeNone);
1682 static_cast<WebFrameWidget*>(GetWebWidget())
1683 ->setRemoteViewportIntersection(viewport_intersection);
1684 }
1685}
1686
paulmeyer90f6c31d2016-11-12 00:17:591687void RenderWidget::OnDragTargetDragEnter(
1688 const std::vector<DropData::Metadata>& drop_meta_data,
1689 const gfx::Point& client_point,
1690 const gfx::Point& screen_point,
1691 WebDragOperationsMask ops,
1692 int key_modifiers) {
1693 if (!GetWebWidget())
1694 return;
1695
1696 DCHECK(GetWebWidget()->isWebFrameWidget());
1697 WebDragOperation operation = static_cast<WebFrameWidget*>(GetWebWidget())->
1698 dragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1699 client_point, screen_point, ops, key_modifiers);
1700
1701 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1702}
1703
1704void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1705 const gfx::Point& screen_point,
1706 WebDragOperationsMask ops,
1707 int key_modifiers) {
1708 if (!GetWebWidget())
1709 return;
1710
1711 DCHECK(GetWebWidget()->isWebFrameWidget());
1712 WebDragOperation operation =
1713 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragOver(
1714 ConvertWindowPointToViewport(client_point),
1715 screen_point, ops, key_modifiers);
1716
1717 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1718}
1719
1720void RenderWidget::OnDragTargetDragLeave() {
1721 if (!GetWebWidget())
1722 return;
1723 DCHECK(GetWebWidget()->isWebFrameWidget());
1724 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragLeave();
1725}
1726
1727void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1728 const gfx::Point& client_point,
1729 const gfx::Point& screen_point,
1730 int key_modifiers) {
1731 if (!GetWebWidget())
1732 return;
1733
1734 DCHECK(GetWebWidget()->isWebFrameWidget());
1735 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDrop(
1736 DropDataToWebDragData(drop_data),
1737 ConvertWindowPointToViewport(client_point),
1738 screen_point, key_modifiers);
1739}
1740
paulmeyer8fc8ea92016-11-15 05:12:211741void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1742 const gfx::Point& screen_point,
1743 WebDragOperation op) {
1744 if (!GetWebWidget())
1745 return;
1746
1747 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceEndedAt(
1748 ConvertWindowPointToViewport(client_point), screen_point, op);
1749}
1750
1751void RenderWidget::OnDragSourceSystemDragEnded() {
1752 if (!GetWebWidget())
1753 return;
1754
1755 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded();
1756}
1757
lukasza86f05da2017-01-24 21:23:261758void RenderWidget::showVirtualKeyboardOnElementFocus() {
changwan75e3b2072017-01-16 02:55:001759 ShowVirtualKeyboard();
boliu7b2be2f2016-11-04 04:58:311760
1761// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1762// virtual keyboard.
1763#if !defined(OS_ANDROID)
1764 FocusChangeComplete();
1765#endif
[email protected]0d1ebed12013-08-05 22:01:131766}
1767
fsamuel72464894f2015-12-15 06:59:311768ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161769#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091770 if (focused_pepper_plugin_)
1771 return focused_pepper_plugin_->text_input_type();
1772#endif
ekaramad5aff1942017-01-06 01:26:351773 if (auto* controller = GetInputMethodController())
1774 return ConvertWebTextInputType(controller->textInputType());
fsamuel72464894f2015-12-15 06:59:311775 return ui::TEXT_INPUT_TYPE_NONE;
1776}
1777
nonafa291792016-08-10 02:36:181778void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1779 if (!monitor_composition_info_ && !immediate_request)
1780 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591781
nonafa291792016-08-10 02:36:181782 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1783 gfx::Range range;
1784 std::vector<gfx::Rect> character_bounds;
1785
1786 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1787 // Composition information is only available on editable node.
1788 range = gfx::Range::InvalidRange();
1789 } else {
1790 GetCompositionRange(&range);
1791 GetCompositionCharacterBounds(&character_bounds);
1792 }
1793
1794 if (!immediate_request &&
1795 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311796 return;
nonafa291792016-08-10 02:36:181797 }
fsamuel72464894f2015-12-15 06:59:311798 composition_character_bounds_ = character_bounds;
1799 composition_range_ = range;
1800 Send(new InputHostMsg_ImeCompositionRangeChanged(
1801 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311802}
1803
oshimaf866dab2015-12-05 00:41:541804void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1805 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461806 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331807 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541808 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461809 gfx::Rect window_rect =
1810 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1811 rect->x = window_rect.x();
1812 rect->y = window_rect.y();
1813 rect->width = window_rect.width();
1814 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541815 }
1816}
1817
oshimaa6985b62016-01-27 08:58:301818void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1819 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181820 rect->x *= GetOriginalDeviceScaleFactor();
1821 rect->y *= GetOriginalDeviceScaleFactor();
1822 rect->width *= GetOriginalDeviceScaleFactor();
1823 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301824 }
1825}
1826
[email protected]adb362312014-06-28 06:04:241827#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:391828void RenderWidget::OnRequestTextInputStateUpdate() {
1829 DCHECK(!ime_event_guard_);
1830 UpdateSelectionBounds();
changwan75e3b2072017-01-16 02:55:001831 UpdateTextInputStateInternal(false, true /* reply_to_request */);
changwan8c342742016-02-26 00:53:391832}
[email protected]105dffb42013-02-20 03:46:211833#endif
1834
nonafa291792016-08-10 02:36:181835void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1836 bool monitor_request) {
1837 monitor_composition_info_ = monitor_request;
1838 if (!immediate_request)
1839 return;
1840 UpdateCompositionInfo(true /* immediate request */);
1841}
1842
wjmaclean8a795f32016-08-11 23:49:581843void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191844 if (device_scale_factor_ == device_scale_factor)
1845 return;
1846
1847 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331848
1849 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261850 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581851
1852 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191853}
1854
[email protected]fcdc5642014-05-09 14:32:241855void RenderWidget::OnOrientationChange() {
1856}
1857
[email protected]bee16aab2009-08-26 15:55:031858void RenderWidget::SetHidden(bool hidden) {
1859 if (is_hidden_ == hidden)
1860 return;
1861
jdduke8fac9d102014-12-20 02:40:131862 // The status has changed. Tell the RenderThread about it and ensure
1863 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031864 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131865
[email protected]bee16aab2009-08-26 15:55:031866 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001867 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031868 else
[email protected]b2db9272014-01-10 17:42:001869 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111870
1871 if (render_widget_scheduling_state_)
1872 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031873}
1874
[email protected]2b624c562011-10-27 22:58:261875void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211876 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261877 return;
1878
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121879 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211880 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261881 } else {
lfg8ff33912016-09-13 20:59:211882 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261883 }
[email protected]2b624c562011-10-27 22:58:261884}
1885
[email protected]674741932009-02-04 23:44:461886bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051887 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461888}
1889
[email protected]674741932009-02-04 23:44:461890void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051891 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461892}
1893
[email protected]674741932009-02-04 23:44:461894void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051895 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461896}
1897
changwanf2a707b2015-10-30 08:22:161898void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1899 if (!ime_event_guard_)
1900 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291901}
1902
changwanf2a707b2015-10-30 08:22:161903void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1904 if (ime_event_guard_ != guard) {
changwan75e3b2072017-01-16 02:55:001905 DCHECK(!ime_event_guard_->reply_to_request());
changwanf2a707b2015-10-30 08:22:161906 return;
1907 }
1908 ime_event_guard_ = nullptr;
1909
[email protected]66fca5bc2013-05-23 06:58:291910 // While handling an ime event, text input state and selection bounds updates
1911 // are ignored. These must explicitly be updated once finished handling the
1912 // ime event.
1913 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471914#if defined(OS_ANDROID)
changwan75e3b2072017-01-16 02:55:001915 if (guard->show_virtual_keyboard())
1916 ShowVirtualKeyboard();
1917 else
1918 UpdateTextInputState();
[email protected]cb9e2632013-06-18 11:26:471919#endif
[email protected]66fca5bc2013-05-23 06:58:291920}
1921
[email protected]7c8873e2013-02-05 08:03:011922void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:161923#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091924 if (focused_pepper_plugin_) {
1925 // TODO(kinaba) http://crbug.com/101101
1926 // Current Pepper IME API does not handle selection bounds. So we simply
1927 // use the caret position as an empty range for now. It will be updated
1928 // after Pepper API equips features related to surrounding text retrieval.
1929 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1930 convertViewportToWindow(&caret);
1931 *focus = caret;
1932 *anchor = caret;
1933 return;
1934 }
1935#endif
[email protected]7c8873e2013-02-05 08:03:011936 WebRect focus_webrect;
1937 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211938 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241939 convertViewportToWindow(&focus_webrect);
1940 convertViewportToWindow(&anchor_webrect);
1941 *focus = focus_webrect;
1942 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321943}
1944
[email protected]e99ef6f2011-10-16 01:13:001945void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081946 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211947 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001948 return;
changwanf2a707b2015-10-30 08:22:161949 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291950 return;
[email protected]e99ef6f2011-10-16 01:13:001951
mohsenb0eeba72015-08-09 06:20:081952#if defined(USE_AURA)
1953 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1954 // Aura beucause composited selection updates are not working for webview tags
1955 // which regresses IME inside webview. Remove this when composited selection
1956 // updates are fixed for webviews. See, http://crbug.com/510568.
1957 bool send_ipc = true;
1958#else
jddukeacf809e2014-09-23 20:38:381959 // With composited selection updates, the selection bounds will be reported
1960 // directly by the compositor, in which case explicit IPC selection
1961 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081962 bool send_ipc =
1963 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1964#endif
1965 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381966 ViewHostMsg_SelectionBounds_Params params;
1967 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1968 if (selection_anchor_rect_ != params.anchor_rect ||
1969 selection_focus_rect_ != params.focus_rect) {
1970 selection_anchor_rect_ = params.anchor_rect;
1971 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:211972 GetWebWidget()->selectionTextDirection(params.focus_dir,
1973 params.anchor_dir);
1974 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:381975 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1976 }
[email protected]58b48a0d2012-06-13 07:01:351977 }
jddukeacf809e2014-09-23 20:38:381978
nonafa291792016-08-10 02:36:181979 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:001980}
1981
engedy8d0ed9b2017-01-02 20:05:481982void RenderWidget::SetDeviceColorProfileForTesting(
ccameronc21ca23b2017-01-20 03:34:011983 const gfx::ICCProfile& color_profile) {
ccameron84456c62017-01-13 21:57:471984 if (owner_delegate_)
1985 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
avi40b5be7a2016-03-03 21:13:441986}
1987
lfgb00fcad2016-07-14 14:16:331988void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1989 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1990 convertViewportToWindow(&new_size_in_window);
1991 if (size_.width() != new_size_in_window.width ||
1992 size_.height() != new_size_in_window.height) {
1993 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1994
1995 if (resizing_mode_selector_->is_synchronous_mode()) {
bokan6b08cd22016-10-05 00:55:211996 gfx::Rect new_pos(windowRect().x, windowRect().y,
lfg0140a452016-07-19 19:15:051997 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:331998 view_screen_rect_ = new_pos;
1999 window_screen_rect_ = new_pos;
2000 }
2001
2002 AutoResizeCompositor();
2003
2004 if (!resizing_mode_selector_->is_synchronous_mode())
2005 need_update_rect_for_auto_resize_ = true;
2006 }
2007}
2008
[email protected]58b48a0d2012-06-13 07:01:352009void RenderWidget::GetCompositionCharacterBounds(
2010 std::vector<gfx::Rect>* bounds) {
2011 DCHECK(bounds);
2012 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092013
brettw4b461082016-11-19 18:55:162014#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092015 if (focused_pepper_plugin_)
2016 return;
2017#endif
2018
lfg8ff33912016-09-13 20:59:212019 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092020 return;
2021 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:212022 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092023 return;
2024
2025 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
2026 convertViewportToWindow(&bounds_from_blink[i]);
2027 bounds->push_back(bounds_from_blink[i]);
2028 }
[email protected]58b48a0d2012-06-13 07:01:352029}
2030
[email protected]db4fc1e2013-09-06 20:01:512031void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162032#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092033 if (focused_pepper_plugin_)
2034 return;
2035#endif
lfg8ff33912016-09-13 20:59:212036 WebRange web_range = GetWebWidget()->compositionRange();
nona2363a3d2016-11-09 03:26:212037 if (web_range.isNull()) {
2038 *range = gfx::Range::InvalidRange();
2039 return;
[email protected]88dbe32f2013-06-20 23:31:362040 }
nona2363a3d2016-11-09 03:26:212041 range->set_start(web_range.startOffset());
2042 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:362043}
2044
[email protected]501ea13d2013-07-09 17:03:292045bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512046 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292047 const std::vector<gfx::Rect>& bounds) {
changwan2418e1b2016-12-12 12:43:082048 if (!range.IsValid())
2049 return false;
[email protected]501ea13d2013-07-09 17:03:292050 if (composition_range_ != range)
2051 return true;
2052 if (bounds.size() != composition_character_bounds_.size())
2053 return true;
2054 for (size_t i = 0; i < bounds.size(); ++i) {
2055 if (bounds[i] != composition_character_bounds_[i])
2056 return true;
2057 }
2058 return false;
2059}
[email protected]501ea13d2013-07-09 17:03:292060
[email protected]ad26ef42011-06-17 07:59:452061bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162062#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092063 if (focused_pepper_plugin_)
2064 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
2065#endif
[email protected]ad26ef42011-06-17 07:59:452066 return true;
[email protected]56ea1a62011-05-30 07:05:572067}
2068
ccameron2f451532016-09-07 21:49:272069blink::WebScreenInfo RenderWidget::screenInfo() {
2070 blink::WebScreenInfo web_screen_info;
2071 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
2072 web_screen_info.depth = screen_info_.depth;
2073 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
2074 web_screen_info.isMonochrome = screen_info_.is_monochrome;
2075 web_screen_info.rect = blink::WebRect(screen_info_.rect);
2076 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
2077 switch (screen_info_.orientation_type) {
2078 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2079 web_screen_info.orientationType =
2080 blink::WebScreenOrientationPortraitPrimary;
2081 break;
2082 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2083 web_screen_info.orientationType =
2084 blink::WebScreenOrientationPortraitSecondary;
2085 break;
2086 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2087 web_screen_info.orientationType =
2088 blink::WebScreenOrientationLandscapePrimary;
2089 break;
2090 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2091 web_screen_info.orientationType =
2092 blink::WebScreenOrientationLandscapeSecondary;
2093 break;
2094 default:
2095 web_screen_info.orientationType =
2096 blink::WebScreenOrientationUndefined;
2097 break;
2098 }
2099 web_screen_info.orientationAngle = screen_info_.orientation_angle;
2100 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282101}
2102
[email protected]fa7b1dc2010-06-23 17:53:042103void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022104 ImeEventGuard guard(this);
changwan2418e1b2016-12-12 12:43:082105 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:012106
nonafa291792016-08-10 02:36:182107 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:042108}
2109
donnda070f3c2015-01-16 19:54:112110#if defined(OS_ANDROID)
2111void RenderWidget::showUnhandledTapUIIfNeeded(
2112 const WebPoint& tapped_position,
2113 const WebNode& tapped_node,
2114 bool page_changed) {
fsamuele8326c742016-01-12 00:49:392115 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:112116 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372117 !tapped_node.isContentEditable() &&
2118 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112119 if (should_trigger) {
2120 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2121 tapped_position.x, tapped_position.y));
2122 }
2123}
2124#endif
2125
[email protected]c68c3e4e2013-01-24 00:36:562126void RenderWidget::didHandleGestureEvent(
2127 const WebGestureEvent& event,
2128 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022129#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562130 if (event_cancelled)
2131 return;
dtapuska8c4dae12017-01-13 00:23:062132 if (event.type() == WebInputEvent::GestureTap) {
changwan75e3b2072017-01-16 02:55:002133 ShowVirtualKeyboard();
dtapuska8c4dae12017-01-13 00:23:062134 } else if (event.type() == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:212135 DCHECK(GetWebWidget());
ekaramad5aff1942017-01-06 01:26:352136 blink::WebInputMethodController* controller = GetInputMethodController();
2137 if (!controller || controller->textInputInfo().value.isEmpty())
changwan75e3b2072017-01-16 02:55:002138 UpdateTextInputState();
[email protected]07c70d22014-08-21 08:33:462139 else
changwan75e3b2072017-01-16 02:55:002140 ShowVirtualKeyboard();
[email protected]c68c3e4e2013-01-24 00:36:562141 }
ekaramada110f642016-12-21 19:47:282142// TODO(ananta): Piggyback off existing IPCs to communicate this information,
2143// crbug/420130.
2144#if defined(OS_WIN)
dtapuska8c4dae12017-01-13 00:23:062145 if (event.type() != blink::WebGestureEvent::GestureTap)
ekaramada110f642016-12-21 19:47:282146 return;
2147
2148 // TODO(estade): hit test the event against focused node to make sure
2149 // the tap actually hit the focused node.
ekaramad5aff1942017-01-06 01:26:352150 blink::WebInputMethodController* controller = GetInputMethodController();
2151 blink::WebTextInputType text_input_type =
2152 controller ? controller->textInputType() : blink::WebTextInputTypeNone;
ekaramada110f642016-12-21 19:47:282153
2154 Send(new ViewHostMsg_FocusedNodeTouched(
2155 routing_id_, text_input_type != blink::WebTextInputTypeNone));
2156#endif
[email protected]c68c3e4e2013-01-24 00:36:562157#endif
2158}
2159
sataya.m582c9ce2015-06-09 08:03:422160void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312161 const blink::WebFloatSize& overscrollDelta,
2162 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422163 const blink::WebFloatPoint& position,
2164 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482165#if defined(OS_MACOSX)
2166 // On OSX the user can disable the elastic overscroll effect. If that's the
2167 // case, don't forward the overscroll notification.
2168 DCHECK(compositor_deps());
2169 if (!compositor_deps()->IsElasticOverscrollEnabled())
2170 return;
2171#endif
bokane53a10f2016-04-13 23:48:312172 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392173 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422174}
2175
[email protected]7912e822014-04-16 02:37:032176void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392177 if (!is_hidden())
2178 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032179}
2180
[email protected]24ed0432013-04-24 07:50:312181RenderWidgetCompositor* RenderWidget::compositor() const {
2182 return compositor_.get();
2183}
2184
fsamuel72464894f2015-12-15 06:59:312185void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392186 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372187}
[email protected]c3d45532011-10-07 19:20:402188
[email protected]ce6689f2013-03-29 12:52:552189void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112190 if (render_widget_scheduling_state_)
2191 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552192 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2193}
2194
[email protected]5d0bbdfa92013-12-10 00:35:512195void RenderWidget::setTouchAction(
2196 blink::WebTouchAction web_touch_action) {
[email protected]5d0bbdfa92013-12-10 00:35:512197 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2198 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392199 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512200 return;
2201
[email protected]a18f67a2013-12-20 19:44:362202 content::TouchAction content_touch_action =
2203 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512204 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2205}
2206
[email protected]e3244ed2014-06-20 20:04:272207void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2208 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162209}
2210
[email protected]e3244ed2014-06-20 20:04:272211void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2212 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162213}
2214
[email protected]de3c5d82014-05-28 22:12:592215void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2216 render_frames_.AddObserver(frame);
2217}
2218
2219void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2220 render_frames_.RemoveObserver(frame);
2221}
2222
lfg43e08e62016-02-03 18:51:372223void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2224 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2225 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2226}
2227
oshima50872a72016-03-04 13:26:182228float RenderWidget::GetOriginalDeviceScaleFactor() const {
2229 return
2230 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272231 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182232 device_scale_factor_;
2233}
2234
paulmeyer90f6c31d2016-11-12 00:17:592235gfx::Point RenderWidget::ConvertWindowPointToViewport(
2236 const gfx::Point& point) {
2237 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
2238 convertWindowToViewport(&point_in_viewport);
2239 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2240}
2241
lfgbee1e0a2016-06-08 21:24:212242bool RenderWidget::requestPointerLock() {
2243 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2244}
2245
2246void RenderWidget::requestPointerUnlock() {
2247 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2248}
2249
2250bool RenderWidget::isPointerLocked() {
2251 return mouse_lock_dispatcher_->IsMouseLockedTo(
2252 webwidget_mouse_lock_target_.get());
2253}
2254
paulmeyer6ef5a792016-11-08 20:33:582255void RenderWidget::startDragging(blink::WebReferrerPolicy policy,
2256 const WebDragData& data,
2257 WebDragOperationsMask mask,
2258 const WebImage& image,
2259 const WebPoint& webImageOffset) {
2260 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
2261 convertViewportToWindow(&offset_in_window);
2262 DropData drop_data(DropDataBuilder::Build(data));
2263 drop_data.referrer_policy = policy;
2264 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592265 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
paulmeyer6ef5a792016-11-08 20:33:582266 image.getSkBitmap(), imageOffset,
2267 possible_drag_event_info_));
2268}
2269
lfg8ff33912016-09-13 20:59:212270blink::WebWidget* RenderWidget::GetWebWidget() const {
2271 return webwidget_internal_;
2272}
2273
ekaramad2daaf672016-11-10 20:29:012274blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2275 const {
ekaramad5a9f52a2016-12-07 01:35:182276 if (!GetWebWidget()->isWebFrameWidget()) {
2277 // TODO(ekaramad): We should not get here in response to IME IPC or updates
2278 // when the RenderWidget is swapped out. We should top sending IPCs from the
2279 // browser side (https://crbug.com/669219).
2280 // If there is no WebFrameWidget, then there will be no
2281 // InputMethodControllers for a WebLocalFrame.
2282 return nullptr;
2283 }
ekaramad2daaf672016-11-10 20:29:012284 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
2285 ->getActiveWebInputMethodController();
2286}
2287
[email protected]e9ff79c2012-10-19 21:31:262288} // namespace content