blob: 637ad27559b658c23c9a6c38d8edf55d9d4391b8 [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"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
24#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
danakj1120f4c2016-09-15 02:05:3226#include "cc/output/compositor_frame_sink.h"
jbroman6ccbc7d472016-07-27 04:45:4127#include "cc/output/copy_output_request.h"
fsamuel78f86e42016-01-20 04:10:2328#include "cc/scheduler/begin_frame_source.h"
oshima750cb4342015-10-31 00:59:0129#include "content/common/content_switches_internal.h"
paulmeyer6ef5a792016-11-08 20:33:5830#include "content/common/drag_event_source_info.h"
31#include "content/common/drag_messages.h"
[email protected]9017d7852013-11-21 17:47:3532#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1533#include "content/common/input_messages.h"
jcivelliae1560a2016-11-01 22:40:2334#include "content/common/render_message_filter.mojom.h"
[email protected]992db4c2011-05-12 15:37:1535#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3836#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5037#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1238#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2939#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4240#include "content/public/common/context_menu_params.h"
paulmeyer90f6c31d2016-11-12 00:17:5941#include "content/public/common/drop_data.h"
[email protected]953bd0062013-08-01 00:58:4042#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3943#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
paulmeyer6ef5a792016-11-08 20:33:5844#include "content/renderer/drop_data_builder.h"
[email protected]b2e4c70132013-10-03 02:07:5145#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1146#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1147#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2848#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2949#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1350#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3251#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1652#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2753#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0554#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4455#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5556#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4457#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0958#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0459#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4760#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1861#include "ipc/ipc_sync_message.h"
brettw4b461082016-11-19 18:55:1662#include "ppapi/features/features.h"
[email protected]661eb9d2009-02-03 02:11:4863#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1864#include "third_party/WebKit/public/platform/WebCursorInfo.h"
paulmeyer90f6c31d2016-11-12 00:17:5965#include "third_party/WebKit/public/platform/WebDragData.h"
66#include "third_party/WebKit/public/platform/WebDragOperation.h"
donnda070f3c2015-01-16 19:54:1167#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3068#include "third_party/WebKit/public/platform/WebRect.h"
69#include "third_party/WebKit/public/platform/WebSize.h"
70#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5171#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
72#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4373#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5974#include "third_party/WebKit/public/web/WebFrameWidget.h"
ekaramad2daaf672016-11-10 20:29:0175#include "third_party/WebKit/public/web/WebInputMethodController.h"
kenrba7199832015-01-22 23:44:5976#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1177#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3178#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3179#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
80#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3881#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5982#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0883#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4184#include "third_party/skia/include/core/SkShader.h"
paulmeyer90f6c31d2016-11-12 00:17:5985#include "ui/base/clipboard/clipboard.h"
[email protected]faec7b12012-06-19 14:42:1386#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5087#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0988#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3289#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4890#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2791#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4192#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4893
[email protected]eeb93112013-05-01 19:41:1094#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1595#include <android/keycodes.h>
[email protected]eeb93112013-05-01 19:41:1096#endif
97
[email protected]661eb9d2009-02-03 02:11:4898#if defined(OS_POSIX)
[email protected]d5282e72009-05-13 13:16:5299#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41100#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48101#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44102
sadrul943e3b32016-08-04 18:22:59103#if defined(USE_AURA)
bend32292b2016-10-07 00:21:58104#include "content/public/common/service_manager_connection.h"
fsamuel2545ecc2015-12-05 00:44:46105#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19106#endif
107
ekaramad330ba4232016-09-23 17:57:47108#if defined(OS_MACOSX)
109#include "content/renderer/text_input_client_observer.h"
110#endif
111
[email protected]180ef242013-11-07 06:50:46112using blink::WebCompositionUnderline;
113using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43114using blink::WebDeviceEmulationParams;
paulmeyer90f6c31d2016-11-12 00:17:59115using blink::WebDragOperation;
paulmeyer6ef5a792016-11-08 20:33:58116using blink::WebDragOperationsMask;
117using blink::WebDragData;
paulmeyer90f6c31d2016-11-12 00:17:59118using blink::WebFrameWidget;
[email protected]180ef242013-11-07 06:50:46119using blink::WebGestureEvent;
paulmeyer6ef5a792016-11-08 20:33:58120using blink::WebImage;
[email protected]180ef242013-11-07 06:50:46121using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49122using blink::WebInputEventResult;
ekaramad2daaf672016-11-10 20:29:01123using blink::WebInputMethodController;
[email protected]180ef242013-11-07 06:50:46124using blink::WebKeyboardEvent;
paulmeyer6ef5a792016-11-08 20:33:58125using blink::WebLocalFrame;
[email protected]180ef242013-11-07 06:50:46126using blink::WebMouseEvent;
127using blink::WebMouseWheelEvent;
128using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11129using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46130using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11131using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46132using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48133using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46134using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46135using blink::WebSize;
paulmeyer90f6c31d2016-11-12 00:17:59136using blink::WebString;
[email protected]180ef242013-11-07 06:50:46137using blink::WebTextDirection;
138using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25139using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46140using blink::WebVector;
141using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26142
paulmeyer90f6c31d2016-11-12 00:17:59143namespace content {
144
[email protected]6a4d7f62013-01-07 21:32:13145namespace {
[email protected]b256eca2013-07-11 10:57:40146
147typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
148
lfgbee1e0a2016-06-08 21:24:21149class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
150 public:
151 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
152 : webwidget_(webwidget) {}
153
154 void OnLockMouseACK(bool succeeded) override {
155 if (succeeded)
156 webwidget_->didAcquirePointerLock();
157 else
158 webwidget_->didNotAcquirePointerLock();
159 }
160
161 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
162
163 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
164 // The WebWidget handles mouse lock in Blink's handleInputEvent().
165 return false;
166 }
167
168 private:
169 blink::WebWidget* webwidget_;
170};
171
dglazkov97b6c2b2016-10-25 17:35:55172bool IsDateTimeInput(ui::TextInputType type) {
173 return type == ui::TEXT_INPUT_TYPE_DATE ||
174 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
175 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
176 type == ui::TEXT_INPUT_TYPE_MONTH ||
177 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
178}
179
fsamuele8326c742016-01-12 00:49:39180content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
181 content::RenderWidget* widget) {
sadrul943e3b32016-08-04 18:22:59182#if defined(USE_AURA)
penghuang639a1042016-01-14 21:25:29183 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
bend32292b2016-10-07 00:21:58184 if (content::ServiceManagerConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29185 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39186 return content::RenderWidgetMusConnection::GetOrCreate(
187 widget->routing_id());
188 }
189#endif
bend32292b2016-10-07 00:21:58190 // If we don't have a connection to the Service Manager, then we want to route
191 // IPCs back to the browser process rather than Mus so we use the |widget| as
192 // the RenderWidgetInputHandlerDelegate.
fsamuele8326c742016-01-12 00:49:39193 return widget;
194}
195
paulmeyer90f6c31d2016-11-12 00:17:59196WebDragData DropMetaDataToWebDragData(
197 const std::vector<DropData::Metadata>& drop_meta_data) {
198 std::vector<WebDragData::Item> item_list;
199 for (const auto& meta_data_item : drop_meta_data) {
200 if (meta_data_item.kind == DropData::Kind::STRING) {
201 WebDragData::Item item;
202 item.storageType = WebDragData::Item::StorageTypeString;
203 item.stringType = meta_data_item.mime_type;
204 // Have to pass a dummy URL here instead of an empty URL because the
205 // DropData received by browser_plugins goes through a round trip:
206 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData
207 // will contain an empty URL (which means no URL is dragged) if the URL in
208 // WebDragData is empty.
209 if (base::EqualsASCII(meta_data_item.mime_type,
210 ui::Clipboard::kMimeTypeURIList)) {
211 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder");
212 }
213 item_list.push_back(item);
214 continue;
215 }
216
217 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with
218 // just the mimetype. This is needed to drag files to WebView on Android
219 // platform.
220 if ((meta_data_item.kind == DropData::Kind::FILENAME) &&
221 !meta_data_item.filename.empty()) {
222 WebDragData::Item item;
223 item.storageType = WebDragData::Item::StorageTypeFilename;
224 item.filenameData = meta_data_item.filename.AsUTF16Unsafe();
225 item_list.push_back(item);
226 continue;
227 }
228
229 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) {
230 WebDragData::Item item;
231 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
232 item.fileSystemURL = meta_data_item.file_system_url;
233 item_list.push_back(item);
234 continue;
235 }
236 }
237
238 WebDragData result;
239 result.initialize();
240 result.setItems(item_list);
241 return result;
242}
243
244WebDragData DropDataToWebDragData(const DropData& drop_data) {
245 std::vector<WebDragData::Item> item_list;
246
247 // These fields are currently unused when dragging into WebKit.
248 DCHECK(drop_data.download_metadata.empty());
249 DCHECK(drop_data.file_contents.empty());
250 DCHECK(drop_data.file_description_filename.empty());
251
252 if (!drop_data.text.is_null()) {
253 WebDragData::Item item;
254 item.storageType = WebDragData::Item::StorageTypeString;
255 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText);
256 item.stringData = drop_data.text.string();
257 item_list.push_back(item);
258 }
259
260 if (!drop_data.url.is_empty()) {
261 WebDragData::Item item;
262 item.storageType = WebDragData::Item::StorageTypeString;
263 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList);
264 item.stringData = WebString::fromUTF8(drop_data.url.spec());
265 item.title = drop_data.url_title;
266 item_list.push_back(item);
267 }
268
269 if (!drop_data.html.is_null()) {
270 WebDragData::Item item;
271 item.storageType = WebDragData::Item::StorageTypeString;
272 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML);
273 item.stringData = drop_data.html.string();
274 item.baseURL = drop_data.html_base_url;
275 item_list.push_back(item);
276 }
277
278 for (std::vector<ui::FileInfo>::const_iterator it =
279 drop_data.filenames.begin();
280 it != drop_data.filenames.end();
281 ++it) {
282 WebDragData::Item item;
283 item.storageType = WebDragData::Item::StorageTypeFilename;
284 item.filenameData = it->path.AsUTF16Unsafe();
285 item.displayNameData = it->display_name.AsUTF16Unsafe();
286 item_list.push_back(item);
287 }
288
289 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it =
290 drop_data.file_system_files.begin();
291 it != drop_data.file_system_files.end();
292 ++it) {
293 WebDragData::Item item;
294 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
295 item.fileSystemURL = it->url;
296 item.fileSystemFileSize = it->size;
297 item_list.push_back(item);
298 }
299
300 for (std::map<base::string16, base::string16>::const_iterator it =
301 drop_data.custom_data.begin();
302 it != drop_data.custom_data.end();
303 ++it) {
304 WebDragData::Item item;
305 item.storageType = WebDragData::Item::StorageTypeString;
306 item.stringType = it->first;
307 item.stringData = it->second;
308 item_list.push_back(item);
309 }
310
311 WebDragData result;
312 result.initialize();
313 result.setItems(item_list);
314 result.setFilesystemId(drop_data.filesystem_id);
315 return result;
316}
317
lfg1568d112016-08-30 16:06:29318content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
319 nullptr;
320
321content::RenderWidget::RenderWidgetInitializedCallback
322 g_render_widget_initialized = nullptr;
323
dtapuskac4dd5be2016-10-25 15:11:10324ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) {
325 // Check the type is in the range representable by ui::TextInputType.
326 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX))
327 << "blink::WebTextInputType and ui::TextInputType not synchronized";
328 return static_cast<ui::TextInputType>(type);
329}
330
331ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) {
332 // Check the mode is in the range representable by ui::TextInputMode.
333 DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX))
334 << "blink::WebTextInputMode and ui::TextInputMode not synchronized";
335 return static_cast<ui::TextInputMode>(mode);
336}
337
[email protected]b256eca2013-07-11 10:57:40338} // namespace
339
[email protected]b2e4c70132013-10-03 02:07:51340// RenderWidget ---------------------------------------------------------------
341
nick8331f8ad2016-11-15 20:42:45342RenderWidget::RenderWidget(int32_t widget_routing_id,
343 CompositorDependencies* compositor_deps,
dcheng35d31c112015-07-22 00:17:36344 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27345 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04346 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03347 bool hidden,
348 bool never_visible)
nick8331f8ad2016-11-15 20:42:45349 : routing_id_(widget_routing_id),
dcheng35d31c112015-07-22 00:17:36350 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21351 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44352 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29353 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51354 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09355 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29356 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04357 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39358 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12359 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12360 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16361 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48362 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22363 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44364 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20365 for_oopif_(false),
dglazkov97b6c2b2016-10-25 17:35:55366 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40367 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20368 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53369 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18370 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12371 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48372 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04373 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27374 device_scale_factor_(screen_info_.device_scale_factor),
[email protected]0d1ebed12013-08-05 22:01:13375#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36376 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13377#endif
nonafa291792016-08-10 02:36:18378 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51379 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11380 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42381 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08382 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09383 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47384#if defined(OS_MACOSX)
385 text_input_client_observer_(new TextInputClientObserver(this)),
386#endif
ekaramad2a46d632016-07-19 13:33:09387 focused_pepper_plugin_(nullptr) {
nick8331f8ad2016-11-15 20:42:45388 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
[email protected]8b3f0eb2012-05-03 19:15:05389 if (!swapped_out)
390 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27391 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53392 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37393#if defined(OS_ANDROID)
394 text_input_info_history_.push_back(blink::WebTextInputInfo());
395#endif
alexclarke7fa93942015-10-21 15:37:11396
397 // In tests there may not be a RenderThreadImpl.
398 if (RenderThreadImpl::current()) {
399 render_widget_scheduling_state_ = RenderThreadImpl::current()
400 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32401 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11402 render_widget_scheduling_state_->SetHidden(is_hidden_);
403 }
initial.commit09911bf2008-07-26 23:55:29404}
405
406RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21407 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16408
[email protected]992db4c2011-05-12 15:37:15409 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02410 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15411 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29412}
413
[email protected]484955942010-08-19 16:13:18414// static
lfg1568d112016-08-30 16:06:29415void RenderWidget::InstallCreateHook(
416 CreateRenderWidgetFunction create_render_widget,
417 RenderWidgetInitializedCallback render_widget_initialized) {
418 CHECK(!g_create_render_widget && !g_render_widget_initialized);
419 g_create_render_widget = create_render_widget;
420 g_render_widget_initialized = render_widget_initialized;
421}
422
423// static
nickf7b38222016-11-22 21:59:35424RenderWidget* RenderWidget::CreateForPopup(
425 RenderViewImpl* opener,
426 CompositorDependencies* compositor_deps,
427 blink::WebPopupType popup_type,
428 const ScreenInfo& screen_info) {
nick4df698d82016-11-11 20:39:23429 // Do a synchronous IPC to obtain a routing ID.
430 int32_t routing_id = MSG_ROUTING_NONE;
431 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget(
nickf7b38222016-11-22 21:59:35432 opener->GetRoutingID(), popup_type, &routing_id)) {
nick4df698d82016-11-11 20:39:23433 return nullptr;
434 }
435
nick8331f8ad2016-11-15 20:42:45436 scoped_refptr<RenderWidget> widget(
437 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info,
438 false, false, false));
nickf7b38222016-11-22 21:59:35439 ShowCallback opener_callback =
440 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->AsWeakPtr());
441 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get()));
nick4df698d82016-11-11 20:39:23442 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference.
443 return widget.get();
initial.commit09911bf2008-07-26 23:55:29444}
445
[email protected]484955942010-08-19 16:13:18446// static
kenrba7199832015-01-22 23:44:59447RenderWidget* RenderWidget::CreateForFrame(
nick4df698d82016-11-11 20:39:23448 int widget_routing_id,
kenrba7199832015-01-22 23:44:59449 bool hidden,
ccameron2f451532016-09-07 21:49:27450 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59451 CompositorDependencies* compositor_deps,
452 blink::WebLocalFrame* frame) {
nick4df698d82016-11-11 20:39:23453 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55454 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
455 // same routing ID for both the view routing ID and the main frame widget
456 // routing ID. https://crbug.com/545684
nick4df698d82016-11-11 20:39:23457 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id);
dcheng3ce04b62015-10-26 23:30:55458 if (view) {
avi8a45c1092016-03-01 16:12:34459 view->AttachWebFrameWidget(
460 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
461 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55462 }
dcheng35d31c112015-07-22 00:17:36463 scoped_refptr<RenderWidget> widget(
lfg1568d112016-08-30 16:06:29464 g_create_render_widget
nick8331f8ad2016-11-15 20:42:45465 ? g_create_render_widget(widget_routing_id, compositor_deps,
466 blink::WebPopupTypeNone, screen_info, false,
467 hidden, false)
468 : new RenderWidget(widget_routing_id, compositor_deps,
469 blink::WebPopupTypeNone, screen_info, false,
470 hidden, false));
simonhong628f9812015-04-27 23:13:20471 widget->for_oopif_ = true;
nick4df698d82016-11-11 20:39:23472 // Init increments the reference count on |widget|, keeping it alive after
kenrba7199832015-01-22 23:44:59473 // this function returns.
nickf7b38222016-11-22 21:59:35474 widget->Init(RenderWidget::ShowCallback(),
nick4df698d82016-11-11 20:39:23475 RenderWidget::CreateWebFrameWidget(widget.get(), frame));
476
477 if (g_render_widget_initialized)
478 g_render_widget_initialized(widget.get());
479 return widget.get();
kenrba7199832015-01-22 23:44:59480}
481
482// static
lfgcaab5142016-02-26 19:06:52483blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08484 RenderWidget* render_widget,
485 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55486 if (!frame->parent()) {
487 // TODO(dcheng): The main frame widget currently has a special case.
488 // Eliminate this once WebView is no longer a WebWidget.
489 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
490 }
dchengda9b4bb2015-07-20 20:58:08491 return blink::WebFrameWidget::create(render_widget, frame);
492}
493
494// static
kenrba7199832015-01-22 23:44:59495blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18496 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46497 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18498 break;
[email protected]180ef242013-11-07 06:50:46499 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44500 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18501 default:
502 NOTREACHED();
503 }
504 return NULL;
505}
506
dchengda9b4bb2015-07-20 20:58:08507void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32508 OnClose();
kenrba7199832015-01-22 23:44:59509}
510
alexmos78c9c0d2016-10-14 18:57:03511void RenderWidget::SetSwappedOut(bool is_swapped_out) {
512 // We should only toggle between states.
513 DCHECK(is_swapped_out_ != is_swapped_out);
514 is_swapped_out_ = is_swapped_out;
515
516 // If we are swapping out, we will call ReleaseProcess, allowing the process
517 // to exit if all of its RenderViews are swapped out. We wait until the
518 // WasSwappedOut call to do this, to allow the unload handler to finish.
519 // If we are swapping in, we call AddRefProcess to prevent the process from
520 // exiting.
521 if (!is_swapped_out_)
522 RenderProcess::current()->AddRefProcess();
523}
524
nickf7b38222016-11-22 21:59:35525void RenderWidget::Init(const ShowCallback& show_callback,
526 WebWidget* web_widget) {
lfg8ff33912016-09-13 20:59:21527 DCHECK(!webwidget_internal_);
nick4df698d82016-11-11 20:39:23528 DCHECK_NE(routing_id_, MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29529
nick8331f8ad2016-11-15 20:42:45530 input_handler_.reset(new RenderWidgetInputHandler(
531 GetRenderWidgetInputHandlerDelegate(this), this));
532
nickf7b38222016-11-22 21:59:35533 show_callback_ = show_callback;
initial.commit09911bf2008-07-26 23:55:29534
lfg8ff33912016-09-13 20:59:21535 webwidget_internal_ = web_widget;
536 webwidget_mouse_lock_target_.reset(
537 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21538 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29539
nick4df698d82016-11-11 20:39:23540 RenderThread::Get()->AddRoute(routing_id_, this);
541 // Take a reference on behalf of the RenderThread. This will be balanced
542 // when we receive ViewMsg_Close.
543 AddRef();
544 if (RenderThreadImpl::current()) {
545 RenderThreadImpl::current()->WidgetCreated();
546 if (is_hidden_)
547 RenderThreadImpl::current()->WidgetHidden();
initial.commit09911bf2008-07-26 23:55:29548 }
549}
550
[email protected]949b6592014-08-20 13:17:52551void RenderWidget::WasSwappedOut() {
552 // If we have been swapped out and no one else is using this process,
553 // it's safe to exit now.
554 CHECK(is_swapped_out_);
555 RenderProcess::current()->ReleaseProcess();
556}
557
[email protected]b2e4c70132013-10-03 02:07:51558void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39559 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51560 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43561 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49562 popup_screen_origin_for_emulation_ = gfx::Point(
563 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
564 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56565 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27566 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51567}
568
[email protected]2d6836f42014-07-02 17:25:31569gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
570 if (screen_metrics_emulator_)
571 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
572 return anchor;
573}
574
haibinluc643d33c2016-06-03 02:22:34575#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51576void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39577 ExternalPopupMenu* popup,
578 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49579 popup->SetOriginScaleAndOffsetForEmulation(
580 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51581}
[email protected]53907862014-03-25 15:42:40582#endif
[email protected]b2e4c70132013-10-03 02:07:51583
584void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
585 if (screen_metrics_emulator_)
586 screen_metrics_emulator_->OnShowContextMenu(params);
587}
588
[email protected]a95986a82010-12-24 06:19:28589bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47590#if defined(OS_MACOSX)
591 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
592 return text_input_client_observer_->OnMessageReceived(message);
593#endif
lfgbee1e0a2016-06-08 21:24:21594 if (mouse_lock_dispatcher_ &&
595 mouse_lock_dispatcher_->OnMessageReceived(message))
596 return true;
597
[email protected]a95986a82010-12-24 06:19:28598 bool handled = true;
599 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15600 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22601 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
602 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22603 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29604 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
605 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
606 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15607 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46608 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
609 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15610 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35611 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
612 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28613 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28614 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20615 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
616 OnEnableDeviceEmulation)
617 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
618 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28619 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41620 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25621 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28622 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
623 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03624 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
lfg43e08e62016-02-03 18:51:37625 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
626 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18627 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
628 OnRequestCompositionUpdate)
paulmeyer90f6c31d2016-11-12 00:17:59629 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
630 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
631 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
632 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
633 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
paulmeyer8fc8ea92016-11-15 05:12:21634 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded)
635 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
636 OnDragSourceSystemDragEnded)
[email protected]105dffb42013-02-20 03:46:21637#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37638 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39639 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
640 OnRequestTextInputStateUpdate)
[email protected]105dffb42013-02-20 03:46:21641#endif
[email protected]a95986a82010-12-24 06:19:28642 IPC_MESSAGE_UNHANDLED(handled = false)
643 IPC_END_MESSAGE_MAP()
644 return handled;
645}
initial.commit09911bf2008-07-26 23:55:29646
647bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15648 // Don't send any messages after the browser has told us to close, and filter
649 // most outgoing messages while swapped out.
650 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26651 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11652 closing_) {
initial.commit09911bf2008-07-26 23:55:29653 delete message;
654 return false;
655 }
656
657 // If given a messsage without a routing ID, then assign our routing ID.
658 if (message->routing_id() == MSG_ROUTING_NONE)
659 message->set_routing_id(routing_id_);
660
[email protected]380244092011-10-07 17:26:27661 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44662}
663
dtapuska014ed082016-11-11 21:58:48664void RenderWidget::SendOrCrash(IPC::Message* message) {
665 bool result = Send(message);
666 CHECK(closing_ || result) << "Failed to send message";
667}
668
bokanc007c3a2015-02-03 07:15:56669void RenderWidget::SetWindowRectSynchronously(
670 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39671 ResizeParams params;
672 params.screen_info = screen_info_;
673 params.new_size = new_window_rect.size();
674 params.physical_backing_size =
675 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39676 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39677 params.is_fullscreen_granted = is_fullscreen_granted_;
678 params.display_mode = display_mode_;
679 params.needs_resize_ack = false;
680 Resize(params);
681
bokanc007c3a2015-02-03 07:15:56682 view_screen_rect_ = new_window_rect;
683 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02684 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56685 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02686}
687
initial.commit09911bf2008-07-26 23:55:29688void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32689 DCHECK(content::RenderThread::Get());
690 if (closing_)
691 return;
692 NotifyOnClose();
693 closing_ = true;
694
695 // Browser correspondence is no longer needed at this point.
696 if (routing_id_ != MSG_ROUTING_NONE) {
697 RenderThread::Get()->RemoveRoute(routing_id_);
698 SetHidden(false);
699 if (RenderThreadImpl::current())
700 RenderThreadImpl::current()->WidgetDestroyed();
701 }
702
703 if (for_oopif_) {
704 // Widgets for frames may be created and closed at any time while the frame
705 // is alive. However, the closing process must happen synchronously. Frame
706 // widget and frames hold pointers to each other. If Close() is deferred to
707 // the message loop like in the non-frame widget case, WebWidget::close()
708 // can end up accessing members of an already-deleted frame.
709 Close();
710 } else {
711 // If there is a Send call on the stack, then it could be dangerous to close
712 // now. Post a task that only gets invoked when there are no nested message
713 // loops.
714 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
715 FROM_HERE, base::Bind(&RenderWidget::Close, this));
716 }
717
718 // Balances the AddRef taken when we called AddRoute.
719 Release();
initial.commit09911bf2008-07-26 23:55:29720}
721
fsamuel664e8b62016-01-20 19:54:01722void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04723 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32724 return;
725
[email protected]b2e4c70132013-10-03 02:07:51726 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39727 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51728 return;
729 }
730
mfomitchev2600fd7c2016-02-17 20:53:39731 Resize(params);
initial.commit09911bf2008-07-26 23:55:29732}
733
dgozman9260b0a12015-03-16 13:45:20734void RenderWidget::OnEnableDeviceEmulation(
735 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39736 if (!screen_metrics_emulator_) {
737 ResizeParams resize_params;
738 resize_params.screen_info = screen_info_;
739 resize_params.new_size = size_;
740 resize_params.physical_backing_size = physical_backing_size_;
741 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39742 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
743 resize_params.display_mode = display_mode_;
744 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
745 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18746 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39747 } else {
dgozman9260b0a12015-03-16 13:45:20748 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39749 }
dgozman9260b0a12015-03-16 13:45:20750}
751
752void RenderWidget::OnDisableDeviceEmulation() {
753 screen_metrics_emulator_.reset();
754}
755
initial.commit09911bf2008-07-26 23:55:29756void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31757 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29758 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03759 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55760 for (auto& observer : render_frames_)
761 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29762}
763
[email protected]3399dd822014-08-09 11:14:24764void RenderWidget::OnWasShown(bool needs_repainting,
765 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41766 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29767 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21768 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29769 return;
770
771 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03772 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55773 for (auto& observer : render_frames_)
774 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29775
[email protected]8a23afb32014-04-30 22:40:23776 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29777 return;
initial.commit09911bf2008-07-26 23:55:29778
779 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24780 if (compositor_) {
781 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15782 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24783 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05784 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24785 }
jdduke491a3f0c2015-06-15 23:30:26786 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29787}
788
[email protected]53d3f302009-12-21 04:42:05789void RenderWidget::OnRequestMoveAck() {
790 DCHECK(pending_window_rect_count_);
791 pending_window_rect_count_--;
792}
793
[email protected]ed7defa2013-03-12 21:29:59794GURL RenderWidget::GetURLForGraphicsContext3D() {
795 return GURL();
[email protected]65225772011-05-12 21:10:24796}
797
fsamuel78f86e42016-01-20 04:10:23798void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10799 const ui::LatencyInfo& latency_info,
800 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23801 if (!input_event)
802 return;
dtapuska0bd451a2016-02-18 17:08:10803 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23804}
805
806void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21807 if (GetWebWidget())
808 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23809}
810
811void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21812 if (GetWebWidget())
813 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23814}
815
alexmos56567492016-09-13 00:52:46816void RenderWidget::OnSetEditCommandsForNextKeyEvent(
817 const EditCommands& edit_commands) {
818 edit_commands_ = edit_commands;
819}
820
fsamuel78f86e42016-01-20 04:10:23821void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08822 has_focus_ = enable;
823
lfg8ff33912016-09-13 20:59:21824 if (GetWebWidget())
825 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08826
ericwilligers88e69742016-10-17 19:29:55827 for (auto& observer : render_frames_)
828 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23829}
830
dtapuska3d5624d32016-08-30 04:34:00831void RenderWidget::SetNeedsMainFrame() {
832 RenderWidgetCompositor* rwc = compositor();
833 if (!rwc)
834 return;
835 rwc->setNeedsBeginFrame();
836}
837
fsamuel78f86e42016-01-20 04:10:23838///////////////////////////////////////////////////////////////////////////////
839// RenderWidgetCompositorDelegate
840
841void RenderWidget::ApplyViewportDeltas(
842 const gfx::Vector2dF& inner_delta,
843 const gfx::Vector2dF& outer_delta,
844 const gfx::Vector2dF& elastic_overscroll_delta,
845 float page_scale,
846 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21847 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
848 elastic_overscroll_delta, page_scale,
849 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23850}
851
852void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00853 RenderThreadImpl* render_thread = RenderThreadImpl::current();
854 // render_thread may be NULL in tests.
855 InputHandlerManager* input_handler_manager =
856 render_thread ? render_thread->input_handler_manager() : NULL;
857 if (input_handler_manager)
858 input_handler_manager->ProcessRafAlignedInputOnMainThread(routing_id_);
859
lfg8ff33912016-09-13 20:59:21860 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23861}
862
danakj1120f4c2016-09-15 02:05:32863std::unique_ptr<cc::CompositorFrameSink>
864RenderWidget::CreateCompositorFrameSink(bool fallback) {
lfg8ff33912016-09-13 20:59:21865 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03866 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32867 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39868 DCHECK(!compositor_never_visible_);
danakj1120f4c2016-09-15 02:05:32869 return RenderThreadImpl::current()->CreateCompositorFrameSink(
danakj83066a32016-06-21 02:34:49870 fallback, routing_id_, frame_swap_message_queue_,
871 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28872}
873
fsamuel78f86e42016-01-20 04:10:23874void RenderWidget::DidCommitAndDrawCompositorFrame() {
875 // NOTE: Tests may break if this event is renamed or moved. See
876 // tab_capture_performancetest.cc.
877 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08878
ericwilligers88e69742016-10-17 19:29:55879 for (auto& observer : render_frames_)
880 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08881
fsamuel78f86e42016-01-20 04:10:23882 // Notify subclasses that we initiated the paint operation.
883 DidInitiatePaint();
884}
885
886void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55887 for (auto& observer : render_frames_)
888 observer.DidCommitCompositorFrame();
889 for (auto& observer : render_frame_proxies_)
890 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23891}
892
893void RenderWidget::DidCompletePageScaleAnimation() {}
894
danakj6c872fc02016-10-22 04:29:49895void RenderWidget::DidReceiveCompositorFrameAck() {
896 TRACE_EVENT0("renderer", "RenderWidget::DidReceiveCompositorFrameAck");
fsamuel78f86e42016-01-20 04:10:23897
pimanbfb2ceb2016-03-18 21:32:58898 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23899 return;
900 }
901
902 ViewHostMsg_UpdateRect_Params params;
903 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23904 params.flags = next_paint_flags_;
905
906 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
907 next_paint_flags_ = 0;
908 need_update_rect_for_auto_resize_ = false;
909}
910
fsamuel78f86e42016-01-20 04:10:23911void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
912 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
913}
914
915bool RenderWidget::IsClosing() const {
916 return host_closing_;
917}
918
danakj53eccbc2016-03-02 22:51:07919void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23920 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29921}
922
fsamuel78f86e42016-01-20 04:10:23923void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21924 GetWebWidget()->updateAllLifecyclePhases();
fsamuel78f86e42016-01-20 04:10:23925}
926
927void RenderWidget::WillBeginCompositorFrame() {
928 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
929
dglazkov06854c5c2016-08-31 00:19:59930 // The UpdateTextInputState can result in further layout and possibly
931 // enable GPU acceleration so they need to be called before any painting
932 // is done.
933 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
934 UpdateSelectionBounds();
935
ericwilligers88e69742016-10-17 19:29:55936 for (auto& observer : render_frame_proxies_)
937 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:29938}
939
jbroman6ccbc7d472016-07-27 04:45:41940std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
941 std::unique_ptr<cc::CopyOutputRequest> request) {
942 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
943 routing_id_, std::move(request));
944}
945
fsamuel72464894f2015-12-15 06:59:31946///////////////////////////////////////////////////////////////////////////////
947// RenderWidgetInputHandlerDelegate
948
avid7d6b2e2016-03-04 19:41:17949void RenderWidget::FocusChangeComplete() {
950 if (owner_delegate_)
951 owner_delegate_->RenderWidgetFocusChangeComplete();
952}
fsamuel72464894f2015-12-15 06:59:31953
954bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17955 if (owner_delegate_)
956 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
957
fsamuel72464894f2015-12-15 06:59:31958 return true;
959}
960
dtapuska1827dd22016-03-11 15:24:59961void RenderWidget::ObserveGestureEventAndResult(
962 const blink::WebGestureEvent& gesture_event,
963 const gfx::Vector2dF& unused_delta,
964 bool event_processed) {
965 if (!compositor_deps_->IsElasticOverscrollEnabled())
966 return;
967
968 cc::InputHandlerScrollResult scroll_result;
969 scroll_result.did_scroll = event_processed;
970 scroll_result.did_overscroll_root = !unused_delta.IsZero();
971 scroll_result.unused_scroll_delta = unused_delta;
972
973 RenderThreadImpl* render_thread = RenderThreadImpl::current();
974 InputHandlerManager* input_handler_manager =
975 render_thread ? render_thread->input_handler_manager() : NULL;
976 if (input_handler_manager) {
977 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
978 routing_id_, gesture_event, scroll_result);
979 }
980}
981
avid7d6b2e2016-03-04 19:41:17982void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:46983 ClearEditCommands();
984}
985
986void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
987 const std::string& value) {
988 ClearEditCommands();
989 edit_commands_.emplace_back(name, value);
990}
991
992void RenderWidget::ClearEditCommands() {
993 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:17994}
fsamuel72464894f2015-12-15 06:59:31995
chongza8ba91fc2016-08-16 21:39:17996void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31997 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
998}
999
dchengcedca5612016-04-09 01:40:151000void RenderWidget::OnInputEventAck(
1001 std::unique_ptr<InputEventAck> input_event_ack) {
dtapuska014ed082016-11-11 21:58:481002 SendOrCrash(
1003 new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
fsamuel72464894f2015-12-15 06:59:311004}
1005
dtapuska46616922016-03-17 22:52:011006void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:071007 blink::WebInputEvent::Type handled_type,
1008 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:101009 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1010 InputHandlerManager* input_handler_manager =
1011 render_thread ? render_thread->input_handler_manager() : NULL;
1012 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:071013 input_handler_manager->NotifyInputEventHandledOnMainThread(
1014 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:101015 }
1016}
1017
fsamuele8326c742016-01-12 00:49:391018void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1019 // Nothing to do here. RenderWidget created the |input_handler| and will take
1020 // ownership of it. We just verify here that we don't already have an input
1021 // handler.
1022 DCHECK(!input_handler_);
1023}
1024
fsamuel72464894f2015-12-15 06:59:311025void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1026 ChangeSource change_source) {
1027 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1028 if (ime_event_guard_) {
1029 // show_ime should still be effective even if it was set inside the IME
1030 // event guard.
1031 if (show_ime == ShowIme::IF_NEEDED) {
1032 ime_event_guard_->set_show_ime(true);
1033 }
1034 return;
1035 }
1036
dglazkov97b6c2b2016-10-25 17:35:551037 ui::TextInputType new_type = GetTextInputType();
1038 if (IsDateTimeInput(new_type))
1039 return; // Not considered as a text input field in WebKit/Chromium.
fsamuel72464894f2015-12-15 06:59:311040
dglazkov97b6c2b2016-10-25 17:35:551041 blink::WebTextInputInfo new_info;
1042 if (GetWebWidget())
1043 new_info = GetWebWidget()->textInputInfo();
dtapuskac4dd5be2016-10-25 15:11:101044 const ui::TextInputMode new_mode =
1045 ConvertWebTextInputMode(new_info.inputMode);
fsamuel72464894f2015-12-15 06:59:311046
1047 bool new_can_compose_inline = CanComposeInline();
1048
1049 // Only sends text input params if they are changed or if the ime should be
1050 // shown.
1051 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:391052 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
dglazkov97b6c2b2016-10-25 17:35:551053 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1054 text_input_info_ != new_info ||
fsamuel72464894f2015-12-15 06:59:311055 can_compose_inline_ != new_can_compose_inline)
1056#if defined(OS_ANDROID)
1057 || text_field_is_dirty_
1058#endif
1059 ) {
ekaramad9053e57b2016-04-26 20:00:381060 TextInputState params;
dglazkov97b6c2b2016-10-25 17:35:551061 params.type = new_type;
fsamuel72464894f2015-12-15 06:59:311062 params.mode = new_mode;
1063 params.flags = new_info.flags;
1064 params.value = new_info.value.utf8();
1065 params.selection_start = new_info.selectionStart;
1066 params.selection_end = new_info.selectionEnd;
1067 params.composition_start = new_info.compositionStart;
1068 params.composition_end = new_info.compositionEnd;
1069 params.can_compose_inline = new_can_compose_inline;
1070 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1071#if defined(USE_AURA)
1072 params.is_non_ime_change = true;
1073#endif
1074#if defined(OS_ANDROID)
1075 params.is_non_ime_change =
1076 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
fsamuel72464894f2015-12-15 06:59:311077 if (params.is_non_ime_change)
1078 OnImeEventSentForAck(new_info);
1079 text_field_is_dirty_ = false;
1080#endif
1081 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1082
1083 text_input_info_ = new_info;
dglazkov97b6c2b2016-10-25 17:35:551084 text_input_type_ = new_type;
fsamuel72464894f2015-12-15 06:59:311085 text_input_mode_ = new_mode;
1086 can_compose_inline_ = new_can_compose_inline;
1087 text_input_flags_ = new_info.flags;
1088 }
1089}
1090
1091bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
paulmeyer6ef5a792016-11-08 20:33:581092 possible_drag_event_info_.event_source =
1093 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
1094 possible_drag_event_info_.event_location =
1095 gfx::Point(event.globalX, event.globalY);
avid7d6b2e2016-03-04 19:41:171096
fsamuel72464894f2015-12-15 06:59:311097 return false;
1098}
1099
1100bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551101 for (auto& observer : render_frames_)
1102 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081103
paulmeyer6ef5a792016-11-08 20:33:581104 possible_drag_event_info_.event_source =
1105 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
1106 possible_drag_event_info_.event_location =
1107 gfx::Point(event.globalX, event.globalY);
1108
avid7d6b2e2016-03-04 19:41:171109 if (owner_delegate_)
1110 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1111
fsamuel72464894f2015-12-15 06:59:311112 return false;
[email protected]fd847792013-10-24 17:12:351113}
1114
initial.commit09911bf2008-07-26 23:55:291115///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391116// RenderWidgetScreenMetricsDelegate
1117
1118void RenderWidget::Redraw() {
1119 set_next_paint_is_resize_ack();
1120 if (compositor_)
1121 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1122}
1123
bokanc63441c2016-04-27 15:49:121124void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211125 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121126}
1127
1128gfx::Size RenderWidget::GetSizeForWebWidget() const {
1129 if (IsUseZoomForDSFEnabled())
1130 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1131
1132 return size_;
1133}
1134
mfomitchev2600fd7c2016-02-17 20:53:391135void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581136 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271137 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1138 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581139
mfomitchev2600fd7c2016-02-17 20:53:391140 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581141
ccameron2f451532016-09-07 21:49:271142 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1143 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581144 OnDeviceScaleFactorChanged();
1145 ScheduleComposite();
1146 }
mfomitchev2600fd7c2016-02-17 20:53:391147
1148 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1149 // A resize ack shouldn't be requested if we have not ACK'd the previous
1150 // one.
1151 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1152 }
1153
1154 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211155 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391156 return;
1157
ianwene5fc5782016-08-18 04:05:151158 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391159 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151160 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameronf408cab2016-09-14 16:54:421161 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
ianwene5fc5782016-08-18 04:05:151162 }
mfomitchev2600fd7c2016-02-17 20:53:391163
mfomitchev2600fd7c2016-02-17 20:53:391164 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391165
1166 // NOTE: We may have entered fullscreen mode without changing our size.
1167 bool fullscreen_change =
1168 is_fullscreen_granted_ != params.is_fullscreen_granted;
1169 is_fullscreen_granted_ = params.is_fullscreen_granted;
1170 display_mode_ = params.display_mode;
1171
bokanc63441c2016-04-27 15:49:121172 size_ = params.new_size;
1173 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391174
bokanc63441c2016-04-27 15:49:121175 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221176
mfomitchev2600fd7c2016-02-17 20:53:391177 WebSize visual_viewport_size;
1178
1179 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181180 visual_viewport_size = gfx::ScaleToCeiledSize(
1181 params.visible_viewport_size,
1182 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391183 } else {
1184 visual_viewport_size = visible_viewport_size_;
1185 }
1186
lfg8ff33912016-09-13 20:59:211187 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391188
bokanc63441c2016-04-27 15:49:121189 // When resizing, we want to wait to paint before ACK'ing the resize. This
1190 // ensures that we only resize as fast as we can paint. We only need to
1191 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391192 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1193 // In this case there is no paint/composite and therefore no
1194 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1195 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1196 DCHECK(!params.needs_resize_ack);
1197 }
1198
1199 // Send the Resize_ACK flag once we paint again if requested.
1200 if (params.needs_resize_ack)
1201 set_next_paint_is_resize_ack();
1202
1203 if (fullscreen_change)
1204 DidToggleFullscreen();
1205
engedy6cb63c92016-02-23 14:14:581206 if (orientation_changed)
1207 OnOrientationChange();
1208
mfomitchev2600fd7c2016-02-17 20:53:391209 // If a resize ack is requested and it isn't set-up, then no more resizes will
1210 // come in and in general things will go wrong.
1211 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1212}
1213
1214void RenderWidget::SetScreenMetricsEmulationParameters(
1215 bool enabled,
1216 const blink::WebDeviceEmulationParams& params) {
1217 // This is only supported in RenderView.
1218 NOTREACHED();
1219}
1220
1221void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1222 const gfx::Rect& window_screen_rect) {
1223 view_screen_rect_ = view_screen_rect;
1224 window_screen_rect_ = window_screen_rect;
1225}
1226
1227///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461228// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291229
[email protected]3a1c8a8032013-03-18 22:35:321230void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401231 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051232 if (compositor_)
oshima750cb4342015-10-31 00:59:011233 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051234}
1235
[email protected]e195e582013-03-08 01:32:591236void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221237 DCHECK(!host_closing_);
1238
fsamuel78f86e42016-01-20 04:10:231239 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1240 compositor_deps_);
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_));
[email protected]e195e582013-03-08 01:32:591253}
1254
ennef3c58142014-12-09 21:44:381255void RenderWidget::WillCloseLayerTreeView() {
1256 if (host_closing_)
1257 return;
1258
1259 // Prevent new compositors or output surfaces from being created.
1260 host_closing_ = true;
1261
[email protected]aeeedad2014-08-22 18:16:221262 // Always send this notification to prevent new layer tree views from
1263 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211264 if (blink::WebWidget* widget = GetWebWidget())
1265 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221266}
1267
[email protected]180ef242013-11-07 06:50:461268blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281269 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061270}
1271
dglazkovf0e1d6d2015-10-10 02:13:481272void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1273 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1274 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1275 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1276 }
dglazkov79c426102015-08-31 21:22:431277
ericwilligers88e69742016-10-17 19:29:551278 for (auto& observer : render_frames_)
1279 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431280}
1281
jdduke491a3f0c2015-06-15 23:30:261282void RenderWidget::ScheduleComposite() {
1283 if (compositor_ &&
1284 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
skyostil32650d22016-09-26 16:58:231285 compositor_->setNeedsCompositorUpdate();
jdduke491a3f0c2015-06-15 23:30:261286 }
1287}
1288
1289void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1290 if (compositor_) {
1291 // Regardless of whether threaded compositing is enabled, always
1292 // use this mechanism to force the compositor to redraw. However,
1293 // the invalidation code path below is still needed for the
1294 // non-threaded case.
1295 compositor_->SetNeedsForcedRedraw();
1296 }
1297 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151298}
1299
[email protected]586871b2014-07-22 17:05:111300// static
dchengcedca5612016-04-09 01:40:151301std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111302 IPC::Message* msg,
1303 MessageDeliveryPolicy policy,
1304 FrameSwapMessageQueue* frame_swap_message_queue,
1305 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111306 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111307 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151308 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1309 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111310 &first_message_for_frame);
1311 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151312 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111313 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061314 return promise;
[email protected]586871b2014-07-22 17:05:111315 }
dcheng4b6b5ff2014-10-16 00:42:061316 return nullptr;
[email protected]586871b2014-07-22 17:05:111317}
1318
1319void RenderWidget::QueueMessage(IPC::Message* msg,
1320 MessageDeliveryPolicy policy) {
1321 // RenderThreadImpl::current() is NULL in some tests.
1322 if (!compositor_ || !RenderThreadImpl::current()) {
1323 Send(msg);
1324 return;
1325 }
1326
dchengcedca5612016-04-09 01:40:151327 std::unique_ptr<cc::SwapPromise> swap_promise =
1328 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111329 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111330 compositor_->GetSourceFrameNumber());
1331
1332 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321333 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351334 // Request a commit. This might either A) request a commit ahead of time
1335 // or B) request a commit which is not needed because there are not
1336 // pending updates. If B) then the commit will be skipped and the swap
1337 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1338 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1339 // can_cancel_commit is not unset.
1340 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111341 }
1342}
1343
[email protected]4873c7d2009-07-16 06:36:281344void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301345 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521346 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181347 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291348 // Only send a SetCursor message if we need to make a change.
1349 if (!current_cursor_.IsEqual(cursor)) {
1350 current_cursor_ = cursor;
1351 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1352 }
1353}
1354
1355// We are supposed to get a single call to Show for a newly created RenderWidget
1356// that was created via RenderWidget::CreateWebView. So, we wait until this
1357// point to dispatch the ShowWidget message.
1358//
1359// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281360// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291361//
nickf7b38222016-11-22 21:59:351362void RenderWidget::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291363 DCHECK(!did_show_) << "received extraneous Show call";
1364 DCHECK(routing_id_ != MSG_ROUTING_NONE);
nickf7b38222016-11-22 21:59:351365 DCHECK(!show_callback_.is_null());
initial.commit09911bf2008-07-26 23:55:291366
[email protected]8de12d942010-11-17 20:42:441367 if (did_show_)
1368 return;
1369
1370 did_show_ = true;
nickf7b38222016-11-22 21:59:351371
1372 // The opener is responsible for actually showing this widget.
1373 show_callback_.Run(this, policy, initial_rect_);
1374
bokanc007c3a2015-02-03 07:15:561375 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441376 // that's okay. It'll be ignored if as_popup is false, or the browser
1377 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561378 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291379}
1380
[email protected]2533ce12009-05-09 00:02:241381void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381382 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241383 Send(new ViewHostMsg_Close(routing_id_));
1384}
1385
dgozmancf9039cd2015-04-06 12:01:311386void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551387 for (auto& observer : render_frames_)
1388 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311389}
1390
[email protected]4873c7d2009-07-16 06:36:281391void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081392 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321393 if (is_swapped_out_) {
1394 // This widget is currently swapped out, and the active widget is in a
1395 // different process. Have the browser route the close request to the
1396 // active widget instead, so that the correct unload handlers are run.
1397 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1398 return;
1399 }
1400
initial.commit09911bf2008-07-26 23:55:291401 // If a page calls window.close() twice, we'll end up here twice, but that's
1402 // OK. It is safe to send multiple Close messages.
1403
[email protected]2533ce12009-05-09 00:02:241404 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1405 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1406 // could be closed before the JS finishes executing. So instead, post a
1407 // message back to the message loop, which won't run until the JS is
1408 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081409 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211410 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291411}
1412
[email protected]9017d7852013-11-21 17:47:351413void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151414 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351415 const SyntheticGestureCompletionCallback& callback) {
1416 DCHECK(!callback.is_null());
1417
1418 pending_synthetic_gesture_callbacks_.push(callback);
1419
1420 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321421 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351422
1423 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1424}
1425
initial.commit09911bf2008-07-26 23:55:291426void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031427 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381428 WillCloseLayerTreeView();
1429 compositor_.reset();
lfg8ff33912016-09-13 20:59:211430 if (webwidget_internal_) {
1431 webwidget_internal_->close();
1432 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291433 }
1434}
1435
bokan841fdc72016-10-06 00:16:351436void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1437 DCHECK(window_rect);
1438 float scale = popup_origin_scale_for_emulation_;
1439 if (!scale)
1440 return;
1441 window_rect->x =
1442 popup_view_origin_for_emulation_.x() +
1443 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1444 window_rect->y =
1445 popup_view_origin_for_emulation_.y() +
1446 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1447}
1448
1449void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1450 DCHECK(window_rect);
1451 float scale = popup_origin_scale_for_emulation_;
1452 if (!scale)
1453 return;
1454 window_rect->x =
1455 popup_screen_origin_for_emulation_.x() +
1456 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1457 window_rect->y =
1458 popup_screen_origin_for_emulation_.y() +
1459 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1460}
1461
[email protected]4873c7d2009-07-16 06:36:281462WebRect RenderWidget::windowRect() {
bokan841fdc72016-10-06 00:16:351463 WebRect rect;
bokan6b08cd22016-10-05 00:55:211464 if (pending_window_rect_count_) {
1465 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1466 // the RootWindowRect is probably going to return wrong results since the
1467 // browser may not have processed the Move yet. There isn't really anything
1468 // good to do in this case, and it shouldn't happen - since this size is
1469 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351470 rect = pending_window_rect_;
1471 } else {
1472 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211473 }
[email protected]2533ce12009-05-09 00:02:241474
bokan841fdc72016-10-06 00:16:351475 ScreenRectToEmulatedIfNeeded(&rect);
1476 return rect;
bokan6b08cd22016-10-05 00:55:211477}
1478
1479WebRect RenderWidget::viewRect() {
bokan841fdc72016-10-06 00:16:351480 WebRect rect = view_screen_rect_;
1481 ScreenRectToEmulatedIfNeeded(&rect);
1482 return rect;
initial.commit09911bf2008-07-26 23:55:291483}
1484
[email protected]180ef242013-11-07 06:50:461485void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301486 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541487 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301488}
1489
oshima33ec97cd2015-12-14 19:40:241490void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1491 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351492 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511493
[email protected]5b45ad42013-10-25 00:42:041494 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201495 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561496 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1497 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031498 } else {
bokanc007c3a2015-02-03 07:15:561499 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031500 }
initial.commit09911bf2008-07-26 23:55:291501 } else {
bokanc007c3a2015-02-03 07:15:561502 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291503 }
1504}
1505
[email protected]2533ce12009-05-09 00:02:241506void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1507 pending_window_rect_ = rect;
1508 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241509
bokan6b08cd22016-10-05 00:55:211510 // Popups don't get size updates back from the browser so just store the set
1511 // values.
1512 if (popup_type_ != blink::WebPopupTypeNone) {
1513 window_screen_rect_ = rect;
1514 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241515 }
[email protected]d4547452008-08-28 18:36:371516}
1517
[email protected]fa7b1dc2010-06-23 17:53:041518void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261519 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041520 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071521 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041522 int selection_start, int selection_end) {
brettw4b461082016-11-19 18:55:161523#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091524 if (focused_pepper_plugin_) {
1525 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1526 text, underlines, selection_start, selection_end);
1527 return;
1528 }
1529#endif
1530 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211531 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031532 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091533 }
1534
[email protected]0d1ebed12013-08-05 22:01:131535 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281536 return;
[email protected]66fca5bc2013-05-23 06:58:291537 ImeEventGuard guard(this);
ekaramad2daaf672016-11-10 20:29:011538 blink::WebInputMethodController* controller = GetInputMethodController();
1539 DCHECK(controller);
1540 if (!controller ||
1541 !controller->setComposition(
lfg8ff33912016-09-13 20:59:211542 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1543 selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041544 // If we failed to set the composition text, then we need to let the browser
1545 // process to cancel the input method's ongoing composition session, to make
1546 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221547 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261548 }
nonafa291792016-08-10 02:36:181549 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041550}
1551
aelias87b8f7c2016-09-14 03:19:291552void RenderWidget::OnImeCommitText(const base::string16& text,
1553 const gfx::Range& replacement_range,
1554 int relative_cursor_pos) {
brettw4b461082016-11-19 18:55:161555#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091556 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291557 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1558 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091559 return;
1560 }
1561#endif
1562 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211563 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031564 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091565 }
1566
[email protected]0d1ebed12013-08-05 22:01:131567 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041568 return;
[email protected]66fca5bc2013-05-23 06:58:291569 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391570 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011571 if (auto* controller = GetInputMethodController())
1572 controller->commitText(text, relative_cursor_pos);
aelias87b8f7c2016-09-14 03:19:291573 input_handler_->set_handling_input_event(false);
1574 UpdateCompositionInfo(false /* not an immediate request */);
1575}
1576
1577void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
brettw4b461082016-11-19 18:55:161578#if BUILDFLAG(ENABLE_PLUGINS)
aelias87b8f7c2016-09-14 03:19:291579 if (focused_pepper_plugin_) {
1580 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1581 keep_selection);
1582 return;
1583 }
1584#endif
1585
1586 if (!ShouldHandleImeEvent())
1587 return;
1588 ImeEventGuard guard(this);
1589 input_handler_->set_handling_input_event(true);
ekaramad2daaf672016-11-10 20:29:011590 if (auto* controller = GetInputMethodController()) {
1591 controller->finishComposingText(
1592 keep_selection ? WebInputMethodController::KeepSelection
1593 : WebInputMethodController::DoNotKeepSelection);
1594 }
fsamuele8326c742016-01-12 00:49:391595 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181596 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291597}
1598
oshimad5279032015-12-16 18:22:331599void RenderWidget::OnDeviceScaleFactorChanged() {
1600 if (!compositor_)
1601 return;
oshimad5279032015-12-16 18:22:331602 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181603 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331604 else
1605 compositor_->setDeviceScaleFactor(device_scale_factor_);
1606}
1607
[email protected]0bc1f572013-04-17 01:46:311608void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121609 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211610 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121611 return;
1612
[email protected]0bc1f572013-04-17 01:46:311613 // Even if the browser provides an empty damage rect, it's still expecting to
1614 // receive a repaint ack so just damage the entire widget bounds.
1615 if (size_to_paint.IsEmpty()) {
1616 size_to_paint = size_;
1617 }
1618
[email protected]ec7dc112008-08-06 05:30:121619 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051620 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311621 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121622}
1623
[email protected]79fa22e2013-08-23 15:18:121624void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351625 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1626
1627 pending_synthetic_gesture_callbacks_.front().Run();
1628 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271629}
1630
[email protected]4873c7d2009-07-16 06:36:281631void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211632 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111633 return;
lfg8ff33912016-09-13 20:59:211634 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111635}
1636
[email protected]80ad8622012-11-07 16:33:031637void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1638 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511639 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391640 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1641 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511642 } else {
mfomitchev2600fd7c2016-02-17 20:53:391643 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511644 }
[email protected]80ad8622012-11-07 16:33:031645 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1646}
1647
lfgdb5c4ed2016-03-04 23:09:071648void RenderWidget::OnUpdateWindowScreenRect(
1649 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211650 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071651 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211652 else
lfgdb5c4ed2016-03-04 23:09:071653 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071654}
1655
dtrainor5ef644e2015-11-19 00:12:471656void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1657 if (compositor_)
1658 compositor_->OnHandleCompositorProto(proto);
1659}
1660
paulmeyer90f6c31d2016-11-12 00:17:591661void RenderWidget::OnDragTargetDragEnter(
1662 const std::vector<DropData::Metadata>& drop_meta_data,
1663 const gfx::Point& client_point,
1664 const gfx::Point& screen_point,
1665 WebDragOperationsMask ops,
1666 int key_modifiers) {
1667 if (!GetWebWidget())
1668 return;
1669
1670 DCHECK(GetWebWidget()->isWebFrameWidget());
1671 WebDragOperation operation = static_cast<WebFrameWidget*>(GetWebWidget())->
1672 dragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data),
1673 client_point, screen_point, ops, key_modifiers);
1674
1675 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1676}
1677
1678void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point,
1679 const gfx::Point& screen_point,
1680 WebDragOperationsMask ops,
1681 int key_modifiers) {
1682 if (!GetWebWidget())
1683 return;
1684
1685 DCHECK(GetWebWidget()->isWebFrameWidget());
1686 WebDragOperation operation =
1687 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragOver(
1688 ConvertWindowPointToViewport(client_point),
1689 screen_point, ops, key_modifiers);
1690
1691 Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation));
1692}
1693
1694void RenderWidget::OnDragTargetDragLeave() {
1695 if (!GetWebWidget())
1696 return;
1697 DCHECK(GetWebWidget()->isWebFrameWidget());
1698 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragLeave();
1699}
1700
1701void RenderWidget::OnDragTargetDrop(const DropData& drop_data,
1702 const gfx::Point& client_point,
1703 const gfx::Point& screen_point,
1704 int key_modifiers) {
1705 if (!GetWebWidget())
1706 return;
1707
1708 DCHECK(GetWebWidget()->isWebFrameWidget());
1709 static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDrop(
1710 DropDataToWebDragData(drop_data),
1711 ConvertWindowPointToViewport(client_point),
1712 screen_point, key_modifiers);
1713}
1714
paulmeyer8fc8ea92016-11-15 05:12:211715void RenderWidget::OnDragSourceEnded(const gfx::Point& client_point,
1716 const gfx::Point& screen_point,
1717 WebDragOperation op) {
1718 if (!GetWebWidget())
1719 return;
1720
1721 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceEndedAt(
1722 ConvertWindowPointToViewport(client_point), screen_point, op);
1723}
1724
1725void RenderWidget::OnDragSourceSystemDragEnded() {
1726 if (!GetWebWidget())
1727 return;
1728
1729 static_cast<WebFrameWidget*>(GetWebWidget())->dragSourceSystemDragEnded();
1730}
1731
[email protected]adb362312014-06-28 06:04:241732void RenderWidget::showImeIfNeeded() {
boliu7b2be2f2016-11-04 04:58:311733#if defined(OS_ANDROID) || defined(USE_AURA)
1734 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
1735#endif
1736
1737// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1738// virtual keyboard.
1739#if !defined(OS_ANDROID)
1740 FocusChangeComplete();
1741#endif
[email protected]0d1ebed12013-08-05 22:01:131742}
1743
fsamuel72464894f2015-12-15 06:59:311744ui::TextInputType RenderWidget::GetTextInputType() {
brettw4b461082016-11-19 18:55:161745#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091746 if (focused_pepper_plugin_)
1747 return focused_pepper_plugin_->text_input_type();
1748#endif
lfg8ff33912016-09-13 20:59:211749 if (GetWebWidget())
dtapuskac4dd5be2016-10-25 15:11:101750 return ConvertWebTextInputType(GetWebWidget()->textInputType());
fsamuel72464894f2015-12-15 06:59:311751 return ui::TEXT_INPUT_TYPE_NONE;
1752}
1753
nonafa291792016-08-10 02:36:181754void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1755 if (!monitor_composition_info_ && !immediate_request)
1756 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591757
nonafa291792016-08-10 02:36:181758 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1759 gfx::Range range;
1760 std::vector<gfx::Rect> character_bounds;
1761
1762 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1763 // Composition information is only available on editable node.
1764 range = gfx::Range::InvalidRange();
1765 } else {
1766 GetCompositionRange(&range);
1767 GetCompositionCharacterBounds(&character_bounds);
1768 }
1769
1770 if (!immediate_request &&
1771 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311772 return;
nonafa291792016-08-10 02:36:181773 }
fsamuel72464894f2015-12-15 06:59:311774 composition_character_bounds_ = character_bounds;
1775 composition_range_ = range;
1776 Send(new InputHostMsg_ImeCompositionRangeChanged(
1777 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311778}
1779
oshimaf866dab2015-12-05 00:41:541780void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1781 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461782 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331783 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541784 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461785 gfx::Rect window_rect =
1786 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1787 rect->x = window_rect.x();
1788 rect->y = window_rect.y();
1789 rect->width = window_rect.width();
1790 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541791 }
1792}
1793
oshimaa6985b62016-01-27 08:58:301794void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1795 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181796 rect->x *= GetOriginalDeviceScaleFactor();
1797 rect->y *= GetOriginalDeviceScaleFactor();
1798 rect->width *= GetOriginalDeviceScaleFactor();
1799 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301800 }
1801}
1802
[email protected]adb362312014-06-28 06:04:241803#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371804void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1805 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131806}
1807
1808void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371809 DCHECK_GE(text_input_info_history_.size(), 1u);
1810 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511811}
changwan8c342742016-02-26 00:53:391812
1813void RenderWidget::OnRequestTextInputStateUpdate() {
1814 DCHECK(!ime_event_guard_);
1815 UpdateSelectionBounds();
1816 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1817}
[email protected]105dffb42013-02-20 03:46:211818#endif
1819
nonafa291792016-08-10 02:36:181820void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1821 bool monitor_request) {
1822 monitor_composition_info_ = monitor_request;
1823 if (!immediate_request)
1824 return;
1825 UpdateCompositionInfo(true /* immediate request */);
1826}
1827
[email protected]0d1ebed12013-08-05 22:01:131828bool RenderWidget::ShouldHandleImeEvent() {
1829#if defined(OS_ANDROID)
lfg8ff33912016-09-13 20:59:211830 if (!GetWebWidget())
changwan3a841162015-08-11 02:53:371831 return false;
changwan8c342742016-02-26 00:53:391832 if (IsUsingImeThread())
1833 return true;
changwan3a841162015-08-11 02:53:371834
1835 // We cannot handle IME events if there is any chance that the event we are
1836 // receiving here from the browser is based on the state that is different
1837 // from our current one as indicated by |text_input_info_|.
1838 // The states the browser might be in are:
1839 // text_input_info_history_[0] - current state ack'd by browser
1840 // text_input_info_history_[1...N] - pending state changes
1841 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1842 if (text_input_info_history_[i] != text_input_info_)
1843 return false;
1844 }
1845 return true;
[email protected]0d1ebed12013-08-05 22:01:131846#else
lfg8ff33912016-09-13 20:59:211847 return !!GetWebWidget();
[email protected]0d1ebed12013-08-05 22:01:131848#endif
1849}
1850
wjmaclean8a795f32016-08-11 23:49:581851void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191852 if (device_scale_factor_ == device_scale_factor)
1853 return;
1854
1855 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331856
1857 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261858 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581859
1860 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191861}
1862
[email protected]28ed6b32014-06-08 02:16:271863bool RenderWidget::SetDeviceColorProfile(
1864 const std::vector<char>& color_profile) {
1865 if (device_color_profile_ == color_profile)
1866 return false;
1867
1868 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271869
avi40b5be7a2016-03-03 21:13:441870 if (owner_delegate_)
1871 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1872
1873 return true;
noeldb4df152014-09-16 17:45:201874}
1875
[email protected]fcdc5642014-05-09 14:32:241876void RenderWidget::OnOrientationChange() {
1877}
1878
[email protected]bee16aab2009-08-26 15:55:031879void RenderWidget::SetHidden(bool hidden) {
1880 if (is_hidden_ == hidden)
1881 return;
1882
jdduke8fac9d102014-12-20 02:40:131883 // The status has changed. Tell the RenderThread about it and ensure
1884 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031885 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131886
[email protected]bee16aab2009-08-26 15:55:031887 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001888 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031889 else
[email protected]b2db9272014-01-10 17:42:001890 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111891
1892 if (render_widget_scheduling_state_)
1893 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031894}
1895
[email protected]2b624c562011-10-27 22:58:261896void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211897 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261898 return;
1899
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121900 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211901 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261902 } else {
lfg8ff33912016-09-13 20:59:211903 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261904 }
[email protected]2b624c562011-10-27 22:58:261905}
1906
[email protected]674741932009-02-04 23:44:461907bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051908 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461909}
1910
[email protected]674741932009-02-04 23:44:461911void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051912 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461913}
1914
[email protected]674741932009-02-04 23:44:461915void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051916 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461917}
1918
changwan8c342742016-02-26 00:53:391919bool RenderWidget::IsUsingImeThread() {
1920#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121921 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391922#else
1923 return false;
1924#endif
1925}
1926
changwanf2a707b2015-10-30 08:22:161927void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1928 if (!ime_event_guard_)
1929 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291930}
1931
changwanf2a707b2015-10-30 08:22:161932void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1933 if (ime_event_guard_ != guard) {
1934#if defined(OS_ANDROID)
1935 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1936 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391937 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161938 // Therefore, we want to mark this text state update as 'from IME' only
1939 // when all the nested events are all originating from IME.
1940 ime_event_guard_->set_from_ime(
1941 ime_event_guard_->from_ime() && guard->from_ime());
1942#endif
1943 return;
1944 }
1945 ime_event_guard_ = nullptr;
1946
[email protected]66fca5bc2013-05-23 06:58:291947 // While handling an ime event, text input state and selection bounds updates
1948 // are ignored. These must explicitly be updated once finished handling the
1949 // ime event.
1950 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471951#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161952 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311953 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1954 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471955#endif
[email protected]66fca5bc2013-05-23 06:58:291956}
1957
[email protected]7c8873e2013-02-05 08:03:011958void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
brettw4b461082016-11-19 18:55:161959#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:091960 if (focused_pepper_plugin_) {
1961 // TODO(kinaba) http://crbug.com/101101
1962 // Current Pepper IME API does not handle selection bounds. So we simply
1963 // use the caret position as an empty range for now. It will be updated
1964 // after Pepper API equips features related to surrounding text retrieval.
1965 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1966 convertViewportToWindow(&caret);
1967 *focus = caret;
1968 *anchor = caret;
1969 return;
1970 }
1971#endif
[email protected]7c8873e2013-02-05 08:03:011972 WebRect focus_webrect;
1973 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211974 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241975 convertViewportToWindow(&focus_webrect);
1976 convertViewportToWindow(&anchor_webrect);
1977 *focus = focus_webrect;
1978 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321979}
1980
[email protected]e99ef6f2011-10-16 01:13:001981void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081982 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211983 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001984 return;
changwanf2a707b2015-10-30 08:22:161985 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291986 return;
[email protected]e99ef6f2011-10-16 01:13:001987
mohsenb0eeba72015-08-09 06:20:081988#if defined(USE_AURA)
1989 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1990 // Aura beucause composited selection updates are not working for webview tags
1991 // which regresses IME inside webview. Remove this when composited selection
1992 // updates are fixed for webviews. See, http://crbug.com/510568.
1993 bool send_ipc = true;
1994#else
jddukeacf809e2014-09-23 20:38:381995 // With composited selection updates, the selection bounds will be reported
1996 // directly by the compositor, in which case explicit IPC selection
1997 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081998 bool send_ipc =
1999 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
2000#endif
2001 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382002 ViewHostMsg_SelectionBounds_Params params;
2003 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2004 if (selection_anchor_rect_ != params.anchor_rect ||
2005 selection_focus_rect_ != params.focus_rect) {
2006 selection_anchor_rect_ = params.anchor_rect;
2007 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:212008 GetWebWidget()->selectionTextDirection(params.focus_dir,
2009 params.anchor_dir);
2010 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:382011 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2012 }
[email protected]58b48a0d2012-06-13 07:01:352013 }
jddukeacf809e2014-09-23 20:38:382014
nonafa291792016-08-10 02:36:182015 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]e99ef6f2011-10-16 01:13:002016}
2017
avi40b5be7a2016-03-03 21:13:442018void RenderWidget::SetDeviceColorProfileForTesting(
2019 const std::vector<char>& color_profile) {
2020 SetDeviceColorProfile(color_profile);
2021}
2022
lfgb00fcad2016-07-14 14:16:332023void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
2024 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
2025 convertViewportToWindow(&new_size_in_window);
2026 if (size_.width() != new_size_in_window.width ||
2027 size_.height() != new_size_in_window.height) {
2028 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
2029
2030 if (resizing_mode_selector_->is_synchronous_mode()) {
bokan6b08cd22016-10-05 00:55:212031 gfx::Rect new_pos(windowRect().x, windowRect().y,
lfg0140a452016-07-19 19:15:052032 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:332033 view_screen_rect_ = new_pos;
2034 window_screen_rect_ = new_pos;
2035 }
2036
2037 AutoResizeCompositor();
2038
2039 if (!resizing_mode_selector_->is_synchronous_mode())
2040 need_update_rect_for_auto_resize_ = true;
2041 }
2042}
2043
[email protected]58b48a0d2012-06-13 07:01:352044void RenderWidget::GetCompositionCharacterBounds(
2045 std::vector<gfx::Rect>* bounds) {
2046 DCHECK(bounds);
2047 bounds->clear();
ekaramad2a46d632016-07-19 13:33:092048
brettw4b461082016-11-19 18:55:162049#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092050 if (focused_pepper_plugin_)
2051 return;
2052#endif
2053
lfg8ff33912016-09-13 20:59:212054 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:092055 return;
2056 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:212057 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:092058 return;
2059
2060 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
2061 convertViewportToWindow(&bounds_from_blink[i]);
2062 bounds->push_back(bounds_from_blink[i]);
2063 }
[email protected]58b48a0d2012-06-13 07:01:352064}
2065
[email protected]db4fc1e2013-09-06 20:01:512066void RenderWidget::GetCompositionRange(gfx::Range* range) {
brettw4b461082016-11-19 18:55:162067#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092068 if (focused_pepper_plugin_)
2069 return;
2070#endif
lfg8ff33912016-09-13 20:59:212071 WebRange web_range = GetWebWidget()->compositionRange();
nona2363a3d2016-11-09 03:26:212072 if (web_range.isNull()) {
2073 *range = gfx::Range::InvalidRange();
2074 return;
[email protected]88dbe32f2013-06-20 23:31:362075 }
nona2363a3d2016-11-09 03:26:212076 range->set_start(web_range.startOffset());
2077 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:362078}
2079
[email protected]501ea13d2013-07-09 17:03:292080bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512081 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292082 const std::vector<gfx::Rect>& bounds) {
2083 if (composition_range_ != range)
2084 return true;
2085 if (bounds.size() != composition_character_bounds_.size())
2086 return true;
2087 for (size_t i = 0; i < bounds.size(); ++i) {
2088 if (bounds[i] != composition_character_bounds_[i])
2089 return true;
2090 }
2091 return false;
2092}
[email protected]501ea13d2013-07-09 17:03:292093
[email protected]ad26ef42011-06-17 07:59:452094bool RenderWidget::CanComposeInline() {
brettw4b461082016-11-19 18:55:162095#if BUILDFLAG(ENABLE_PLUGINS)
ekaramad2a46d632016-07-19 13:33:092096 if (focused_pepper_plugin_)
2097 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
2098#endif
[email protected]ad26ef42011-06-17 07:59:452099 return true;
[email protected]56ea1a62011-05-30 07:05:572100}
2101
ccameron2f451532016-09-07 21:49:272102blink::WebScreenInfo RenderWidget::screenInfo() {
2103 blink::WebScreenInfo web_screen_info;
2104 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
2105 web_screen_info.depth = screen_info_.depth;
2106 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
2107 web_screen_info.isMonochrome = screen_info_.is_monochrome;
2108 web_screen_info.rect = blink::WebRect(screen_info_.rect);
2109 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
2110 switch (screen_info_.orientation_type) {
2111 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
2112 web_screen_info.orientationType =
2113 blink::WebScreenOrientationPortraitPrimary;
2114 break;
2115 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
2116 web_screen_info.orientationType =
2117 blink::WebScreenOrientationPortraitSecondary;
2118 break;
2119 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
2120 web_screen_info.orientationType =
2121 blink::WebScreenOrientationLandscapePrimary;
2122 break;
2123 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2124 web_screen_info.orientationType =
2125 blink::WebScreenOrientationLandscapeSecondary;
2126 break;
2127 default:
2128 web_screen_info.orientationType =
2129 blink::WebScreenOrientationUndefined;
2130 break;
2131 }
2132 web_screen_info.orientationAngle = screen_info_.orientation_angle;
2133 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282134}
2135
[email protected]fa7b1dc2010-06-23 17:53:042136void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022137 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042138 // If the last text input type is not None, then we should finish any
2139 // ongoing composition regardless of the new text input type.
dglazkov97b6c2b2016-10-25 17:35:552140 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042141 // If a composition text exists, then we need to let the browser process
2142 // to cancel the input method's ongoing composition session.
ekaramad2daaf672016-11-10 20:29:012143 blink::WebInputMethodController* controller = GetInputMethodController();
2144 if (controller &&
2145 controller->finishComposingText(
2146 WebInputMethodController::DoNotKeepSelection))
[email protected]a2214eb2014-06-23 18:31:222147 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042148 }
[email protected]d4cff272011-05-02 15:46:012149
nonafa291792016-08-10 02:36:182150 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:042151}
2152
donnda070f3c2015-01-16 19:54:112153#if defined(OS_ANDROID)
2154void RenderWidget::showUnhandledTapUIIfNeeded(
2155 const WebPoint& tapped_position,
2156 const WebNode& tapped_node,
2157 bool page_changed) {
fsamuele8326c742016-01-12 00:49:392158 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:112159 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372160 !tapped_node.isContentEditable() &&
2161 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112162 if (should_trigger) {
2163 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2164 tapped_position.x, tapped_position.y));
2165 }
2166}
2167#endif
2168
[email protected]c68c3e4e2013-01-24 00:36:562169void RenderWidget::didHandleGestureEvent(
2170 const WebGestureEvent& event,
2171 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022172#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562173 if (event_cancelled)
2174 return;
[email protected]07c70d22014-08-21 08:33:462175 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:312176 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462177 } else if (event.type == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:212178 DCHECK(GetWebWidget());
2179 if (GetWebWidget()->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:312180 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462181 else
fsamuel72464894f2015-12-15 06:59:312182 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562183 }
2184#endif
2185}
2186
sataya.m582c9ce2015-06-09 08:03:422187void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312188 const blink::WebFloatSize& overscrollDelta,
2189 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422190 const blink::WebFloatPoint& position,
2191 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482192#if defined(OS_MACOSX)
2193 // On OSX the user can disable the elastic overscroll effect. If that's the
2194 // case, don't forward the overscroll notification.
2195 DCHECK(compositor_deps());
2196 if (!compositor_deps()->IsElasticOverscrollEnabled())
2197 return;
2198#endif
bokane53a10f2016-04-13 23:48:312199 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392200 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422201}
2202
[email protected]7912e822014-04-16 02:37:032203void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392204 if (!is_hidden())
2205 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032206}
2207
[email protected]24ed0432013-04-24 07:50:312208RenderWidgetCompositor* RenderWidget::compositor() const {
2209 return compositor_.get();
2210}
2211
fsamuel72464894f2015-12-15 06:59:312212void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392213 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372214}
[email protected]c3d45532011-10-07 19:20:402215
[email protected]ce6689f2013-03-29 12:52:552216void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112217 if (render_widget_scheduling_state_)
2218 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552219 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2220}
2221
[email protected]5d0bbdfa92013-12-10 00:35:512222void RenderWidget::setTouchAction(
2223 blink::WebTouchAction web_touch_action) {
2224
2225 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2226 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392227 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512228 return;
2229
[email protected]a18f67a2013-12-20 19:44:362230 content::TouchAction content_touch_action =
2231 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512232 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2233}
2234
[email protected]90f24152014-04-09 12:41:362235void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2236#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392237 if (!IsUsingImeThread())
2238 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362239#endif
2240}
2241
[email protected]e3244ed2014-06-20 20:04:272242void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2243 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162244}
2245
[email protected]e3244ed2014-06-20 20:04:272246void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2247 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162248}
2249
[email protected]de3c5d82014-05-28 22:12:592250void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2251 render_frames_.AddObserver(frame);
2252}
2253
2254void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2255 render_frames_.RemoveObserver(frame);
2256}
2257
lfg43e08e62016-02-03 18:51:372258void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2259 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2260 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2261}
2262
oshima50872a72016-03-04 13:26:182263float RenderWidget::GetOriginalDeviceScaleFactor() const {
2264 return
2265 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272266 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182267 device_scale_factor_;
2268}
2269
paulmeyer90f6c31d2016-11-12 00:17:592270gfx::Point RenderWidget::ConvertWindowPointToViewport(
2271 const gfx::Point& point) {
2272 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0);
2273 convertWindowToViewport(&point_in_viewport);
2274 return gfx::Point(point_in_viewport.x, point_in_viewport.y);
2275}
2276
lfgbee1e0a2016-06-08 21:24:212277bool RenderWidget::requestPointerLock() {
2278 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2279}
2280
2281void RenderWidget::requestPointerUnlock() {
2282 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2283}
2284
2285bool RenderWidget::isPointerLocked() {
2286 return mouse_lock_dispatcher_->IsMouseLockedTo(
2287 webwidget_mouse_lock_target_.get());
2288}
2289
paulmeyer6ef5a792016-11-08 20:33:582290void RenderWidget::startDragging(blink::WebReferrerPolicy policy,
2291 const WebDragData& data,
2292 WebDragOperationsMask mask,
2293 const WebImage& image,
2294 const WebPoint& webImageOffset) {
2295 blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0);
2296 convertViewportToWindow(&offset_in_window);
2297 DropData drop_data(DropDataBuilder::Build(data));
2298 drop_data.referrer_policy = policy;
2299 gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y);
paulmeyer90f6c31d2016-11-12 00:17:592300 Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask,
paulmeyer6ef5a792016-11-08 20:33:582301 image.getSkBitmap(), imageOffset,
2302 possible_drag_event_info_));
2303}
2304
lfg8ff33912016-09-13 20:59:212305blink::WebWidget* RenderWidget::GetWebWidget() const {
2306 return webwidget_internal_;
2307}
2308
ekaramad2daaf672016-11-10 20:29:012309blink::WebInputMethodController* RenderWidget::GetInputMethodController()
2310 const {
2311 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is
2312 // always a WebFrameWidget.
2313 CHECK(GetWebWidget()->isWebFrameWidget());
2314 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
2315 ->getActiveWebInputMethodController();
2316}
2317
[email protected]e9ff79c2012-10-19 21:31:262318} // namespace content