blob: 08d572b6e6b8eeca1cc24fe628da67457b757e6e [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"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.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"
[email protected]681ccff2013-03-18 06:13:5226#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3327#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3028#include "cc/output/output_surface.h"
dyenb52ecd962016-04-20 23:23:4429#include "cc/output/vulkan_in_process_context_provider.h"
fsamuel78f86e42016-01-20 04:10:2330#include "cc/scheduler/begin_frame_source.h"
[email protected]556fd292013-03-18 08:03:0431#include "cc/trees/layer_tree_host.h"
alexclarke7fa93942015-10-21 15:37:1132#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2133#include "components/scheduler/renderer/renderer_scheduler.h"
oshima750cb4342015-10-31 00:59:0134#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0935#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5936#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
fsamuelc28d985e2016-03-22 23:05:0237#include "content/common/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3538#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4439#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1540#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1541#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3842#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5043#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1244#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2945#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4246#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4047#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3948#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5149#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5950#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2951#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1152#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5953#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1154#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2855#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2956#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1357#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3258#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1659#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2760#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0561#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4462#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5563#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4464#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0965#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0466#include "content/renderer/resizing_mode_selector.h"
danakj6f4e1e22016-04-20 03:27:3467#include "gpu/command_buffer/client/shared_memory_limits.h"
[email protected]484955942010-08-19 16:13:1868#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4869#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1870#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3071#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1172#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3073#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1874#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3075#include "third_party/WebKit/public/platform/WebSize.h"
76#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4377#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5978#include "third_party/WebKit/public/web/WebFrameWidget.h"
79#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1180#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3181#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3182#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
83#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3884#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5985#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4186#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1387#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5088#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0989#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3290#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4891#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2792#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4193#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4894
[email protected]eeb93112013-05-01 19:41:1095#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1596#include <android/keycodes.h>
boliubee541f42015-11-05 00:52:5397#include "content/renderer/android/synchronous_compositor_filter.h"
98#include "content/renderer/android/synchronous_compositor_output_surface.h"
[email protected]eeb93112013-05-01 19:41:1099#endif
100
[email protected]661eb9d2009-02-03 02:11:48101#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:49102#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:52103#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:41104#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:48105#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:44106
penghuang28a5fa22015-12-02 17:58:19107#if defined(MOJO_SHELL_CLIENT)
108#include "content/public/common/mojo_shell_connection.h"
fsamuel2545ecc2015-12-05 00:44:46109#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:19110#endif
111
[email protected]2255a9332013-06-17 05:12:31112#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:29113
[email protected]180ef242013-11-07 06:50:46114using blink::WebCompositionUnderline;
115using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43116using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46117using blink::WebGestureEvent;
118using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49119using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46120using blink::WebKeyboardEvent;
121using blink::WebMouseEvent;
122using blink::WebMouseWheelEvent;
123using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11124using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46125using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11126using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46127using blink::WebPopupType;
128using blink::WebRange;
129using blink::WebRect;
130using blink::WebScreenInfo;
131using blink::WebSize;
132using blink::WebTextDirection;
133using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25134using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46135using blink::WebVector;
136using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26137
danakj365175c2016-02-06 00:37:37138#define STATIC_ASSERT_ENUM(a, b) \
139 static_assert(static_cast<int>(a) == static_cast<int>(b), \
140 "mismatching enums: " #a)
141
[email protected]6a4d7f62013-01-07 21:32:13142namespace {
[email protected]b256eca2013-07-11 10:57:40143
144typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
145
146class TextInputModeMapSingleton {
147 public:
148 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22149 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40150 }
[email protected]dd705d4d2013-11-27 08:14:41151 TextInputModeMapSingleton() {
152 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
153 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
154 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
155 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
156 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
157 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
158 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
159 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
160 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
161 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
162 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40163 }
[email protected]dd705d4d2013-11-27 08:14:41164 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40165 private:
[email protected]dd705d4d2013-11-27 08:14:41166 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40167
olli.raula36aa8be2015-09-10 11:14:22168 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40169
170 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
171};
172
[email protected]dd705d4d2013-11-27 08:14:41173ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40174 static TextInputModeMapSingleton* singleton =
175 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41176 TextInputModeMap::const_iterator it =
177 singleton->map().find(input_mode.utf8());
178 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40179 return ui::TEXT_INPUT_MODE_DEFAULT;
180 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13181}
[email protected]b256eca2013-07-11 10:57:40182
fsamuel72464894f2015-12-15 06:59:31183bool IsDateTimeInput(ui::TextInputType type) {
184 return type == ui::TEXT_INPUT_TYPE_DATE ||
185 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
186 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
187 type == ui::TEXT_INPUT_TYPE_MONTH ||
188 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK;
dtapuskae7473612015-12-04 14:23:06189}
190
fsamuele8326c742016-01-12 00:49:39191content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
192 content::RenderWidget* widget) {
193#if defined(MOJO_SHELL_CLIENT)
penghuang639a1042016-01-14 21:25:29194 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
195 if (content::MojoShellConnection::Get() &&
196 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39197 return content::RenderWidgetMusConnection::GetOrCreate(
198 widget->routing_id());
199 }
200#endif
201 // If we don't have a connection to the Mojo shell, then we want to route IPCs
202 // back to the browser process rather than Mus so we use the |widget| as the
203 // RenderWidgetInputHandlerDelegate.
204 return widget;
205}
206
danakje8ec797e2016-04-19 04:08:43207std::unique_ptr<content::WebGraphicsContext3DCommandBufferImpl>
208CreateOffscreenContext(scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
209 const GURL& url) {
210 DCHECK(gpu_channel_host);
211
212 // This is for an offscreen context for the compositor. So the default
213 // framebuffer doesn't need alpha, depth, stencil, antialiasing.
214 gpu::gles2::ContextCreationAttribHelper attributes;
215 attributes.alpha_size = -1;
216 attributes.depth_size = 0;
217 attributes.stencil_size = 0;
218 attributes.samples = 0;
219 attributes.sample_buffers = 0;
220 attributes.bind_generates_resource = false;
221 attributes.lose_context_when_out_of_memory = true;
222
danakje8ec797e2016-04-19 04:08:43223 bool share_resources = true;
224 bool automatic_flushes = false;
225
226 return base::WrapUnique(new content::WebGraphicsContext3DCommandBufferImpl(
227 gpu::kNullSurfaceHandle, url, gpu_channel_host.get(), attributes,
danakj6f4e1e22016-04-20 03:27:34228 gfx::PreferIntegratedGpu, share_resources, automatic_flushes, nullptr));
danakje8ec797e2016-04-19 04:08:43229}
230
[email protected]b256eca2013-07-11 10:57:40231} // namespace
232
[email protected]e9ff79c2012-10-19 21:31:26233namespace content {
[email protected]62cb33cae2009-03-27 23:30:22234
[email protected]b2e4c70132013-10-03 02:07:51235// RenderWidget ---------------------------------------------------------------
236
dcheng35d31c112015-07-22 00:17:36237RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
238 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46239 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04240 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03241 bool hidden,
242 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29243 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36244 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53245 webwidget_(nullptr),
avi40b5be7a2016-03-03 21:13:44246 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29247 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02248 top_controls_shrink_blink_size_(false),
249 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29250 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51251 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09252 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29253 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04254 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39255 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12256 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12257 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16258 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48259 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22260 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44261 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20262 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45263 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40264 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20265 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53266 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12267 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48268 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04269 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52270 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30271 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13272#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36273 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13274#endif
[email protected]b2e4c70132013-10-03 02:07:51275 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11276 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42277 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51278 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05279 if (!swapped_out)
280 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27281 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53282 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37283#if defined(OS_ANDROID)
284 text_input_info_history_.push_back(blink::WebTextInputInfo());
285#endif
alexclarke7fa93942015-10-21 15:37:11286
287 // In tests there may not be a RenderThreadImpl.
288 if (RenderThreadImpl::current()) {
289 render_widget_scheduling_state_ = RenderThreadImpl::current()
290 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32291 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11292 render_widget_scheduling_state_->SetHidden(is_hidden_);
293 }
initial.commit09911bf2008-07-26 23:55:29294}
295
296RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11297 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16298
[email protected]992db4c2011-05-12 15:37:15299 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02300 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15301 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29302}
303
[email protected]484955942010-08-19 16:13:18304// static
avi1023d012015-12-25 02:39:14305RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53306 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46307 blink::WebPopupType popup_type,
308 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29309 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36310 scoped_refptr<RenderWidget> widget(new RenderWidget(
311 compositor_deps, popup_type, screen_info, false, false, false));
312 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46313 return widget.get();
[email protected]a635f942012-12-07 10:34:29314 }
315 return NULL;
initial.commit09911bf2008-07-26 23:55:29316}
317
[email protected]484955942010-08-19 16:13:18318// static
kenrba7199832015-01-22 23:44:59319RenderWidget* RenderWidget::CreateForFrame(
320 int routing_id,
kenrba7199832015-01-22 23:44:59321 bool hidden,
322 const blink::WebScreenInfo& screen_info,
323 CompositorDependencies* compositor_deps,
324 blink::WebLocalFrame* frame) {
325 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55326 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
327 // same routing ID for both the view routing ID and the main frame widget
328 // routing ID. https://crbug.com/545684
329 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
330 if (view) {
avi8a45c1092016-03-01 16:12:34331 view->AttachWebFrameWidget(
332 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
333 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55334 }
dcheng35d31c112015-07-22 00:17:36335 scoped_refptr<RenderWidget> widget(
336 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
337 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39338 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20339 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59340 // DoInit increments the reference count on |widget|, keeping it alive after
341 // this function returns.
dcheng35d31c112015-07-22 00:17:36342 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59343 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
344 nullptr)) {
kenrba7199832015-01-22 23:44:59345 return widget.get();
346 }
347 return nullptr;
348}
349
350// static
lfgcaab5142016-02-26 19:06:52351blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08352 RenderWidget* render_widget,
353 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55354 if (!frame->parent()) {
355 // TODO(dcheng): The main frame widget currently has a special case.
356 // Eliminate this once WebView is no longer a WebWidget.
357 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
358 }
dchengda9b4bb2015-07-20 20:58:08359 return blink::WebFrameWidget::create(render_widget, frame);
360}
361
362// static
kenrba7199832015-01-22 23:44:59363blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18364 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46365 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18366 break;
[email protected]180ef242013-11-07 06:50:46367 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44368 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18369 default:
370 NOTREACHED();
371 }
372 return NULL;
373}
374
dchengda9b4bb2015-07-20 20:58:08375void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32376 OnClose();
kenrba7199832015-01-22 23:44:59377}
378
fsamuele8326c742016-01-12 00:49:39379void RenderWidget::SetRoutingID(int32_t routing_id) {
380 routing_id_ = routing_id;
381 input_handler_.reset(new RenderWidgetInputHandler(
382 GetRenderWidgetInputHandlerDelegate(this), this));
383}
384
avi1023d012015-12-25 02:39:14385bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39386 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05387 opener_id, RenderWidget::CreateWebWidget(this),
388 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39389 if (success) {
390 SetRoutingID(routing_id_);
391 return true;
392 }
393 return false;
[email protected]484955942010-08-19 16:13:18394}
395
avi1023d012015-12-25 02:39:14396bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06397 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18398 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29399 DCHECK(!webwidget_);
400
401 if (opener_id != MSG_ROUTING_NONE)
402 opener_id_ = opener_id;
403
[email protected]484955942010-08-19 16:13:18404 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29405
kenrba7199832015-01-22 23:44:59406 bool result = true;
407 if (create_widget_message)
408 result = RenderThread::Get()->Send(create_widget_message);
409
initial.commit09911bf2008-07-26 23:55:29410 if (result) {
[email protected]380244092011-10-07 17:26:27411 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29412 // Take a reference on behalf of the RenderThread. This will be balanced
413 // when we receive ViewMsg_Close.
414 AddRef();
[email protected]b2db9272014-01-10 17:42:00415 if (RenderThreadImpl::current()) {
416 RenderThreadImpl::current()->WidgetCreated();
417 if (is_hidden_)
418 RenderThreadImpl::current()->WidgetHidden();
419 }
fsamuele8326c742016-01-12 00:49:39420
[email protected]a635f942012-12-07 10:34:29421 return true;
initial.commit09911bf2008-07-26 23:55:29422 } else {
[email protected]a635f942012-12-07 10:34:29423 // The above Send can fail when the tab is closing.
424 return false;
initial.commit09911bf2008-07-26 23:55:29425 }
426}
427
[email protected]992db4c2011-05-12 15:37:15428void RenderWidget::SetSwappedOut(bool is_swapped_out) {
429 // We should only toggle between states.
430 DCHECK(is_swapped_out_ != is_swapped_out);
431 is_swapped_out_ = is_swapped_out;
432
433 // If we are swapping out, we will call ReleaseProcess, allowing the process
434 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52435 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15436 // If we are swapping in, we call AddRefProcess to prevent the process from
437 // exiting.
[email protected]949b6592014-08-20 13:17:52438 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15439 RenderProcess::current()->AddRefProcess();
440}
441
[email protected]949b6592014-08-20 13:17:52442void RenderWidget::WasSwappedOut() {
443 // If we have been swapped out and no one else is using this process,
444 // it's safe to exit now.
445 CHECK(is_swapped_out_);
446 RenderProcess::current()->ReleaseProcess();
447}
448
[email protected]b2e4c70132013-10-03 02:07:51449void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39450 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51451 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43452 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49453 popup_screen_origin_for_emulation_ = gfx::Point(
454 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
455 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56456 screen_info_ = emulator->original_screen_info();
457 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51458}
459
[email protected]2d6836f42014-07-02 17:25:31460gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
461 if (screen_metrics_emulator_)
462 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
463 return anchor;
464}
465
[email protected]53907862014-03-25 15:42:40466#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51467void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39468 ExternalPopupMenu* popup,
469 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49470 popup->SetOriginScaleAndOffsetForEmulation(
471 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51472}
[email protected]53907862014-03-25 15:42:40473#endif
[email protected]b2e4c70132013-10-03 02:07:51474
475void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
476 if (screen_metrics_emulator_)
477 screen_metrics_emulator_->OnShowContextMenu(params);
478}
479
[email protected]a95986a82010-12-24 06:19:28480bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
481 bool handled = true;
482 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15483 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22484 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
485 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22486 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
487 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15488 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
489 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35490 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
491 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28492 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28493 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20494 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
495 OnEnableDeviceEmulation)
496 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
497 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41498 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54499 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28500 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41501 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25502 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28503 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
504 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03505 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05506 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
lfg43e08e62016-02-03 18:51:37507 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
508 OnWaitNextFrameForTests)
[email protected]105dffb42013-02-20 03:46:21509#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37510 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39511 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
512 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51513 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21514#endif
dtrainor5ef644e2015-11-19 00:12:47515 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28516 IPC_MESSAGE_UNHANDLED(handled = false)
517 IPC_END_MESSAGE_MAP()
518 return handled;
519}
initial.commit09911bf2008-07-26 23:55:29520
521bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15522 // Don't send any messages after the browser has told us to close, and filter
523 // most outgoing messages while swapped out.
524 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26525 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11526 closing_) {
initial.commit09911bf2008-07-26 23:55:29527 delete message;
528 return false;
529 }
530
531 // If given a messsage without a routing ID, then assign our routing ID.
532 if (message->routing_id() == MSG_ROUTING_NONE)
533 message->set_routing_id(routing_id_);
534
[email protected]380244092011-10-07 17:26:27535 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44536}
537
bokanc007c3a2015-02-03 07:15:56538void RenderWidget::SetWindowRectSynchronously(
539 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39540 ResizeParams params;
541 params.screen_info = screen_info_;
542 params.new_size = new_window_rect.size();
543 params.physical_backing_size =
544 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
545 params.top_controls_shrink_blink_size = top_controls_shrink_blink_size_;
546 params.top_controls_height = top_controls_height_;
547 params.visible_viewport_size = new_window_rect.size();
548 params.resizer_rect = gfx::Rect();
549 params.is_fullscreen_granted = is_fullscreen_granted_;
550 params.display_mode = display_mode_;
551 params.needs_resize_ack = false;
552 Resize(params);
553
bokanc007c3a2015-02-03 07:15:56554 view_screen_rect_ = new_window_rect;
555 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02556 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56557 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02558}
559
initial.commit09911bf2008-07-26 23:55:29560void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32561 DCHECK(content::RenderThread::Get());
562 if (closing_)
563 return;
564 NotifyOnClose();
565 closing_ = true;
566
567 // Browser correspondence is no longer needed at this point.
568 if (routing_id_ != MSG_ROUTING_NONE) {
569 RenderThread::Get()->RemoveRoute(routing_id_);
570 SetHidden(false);
571 if (RenderThreadImpl::current())
572 RenderThreadImpl::current()->WidgetDestroyed();
573 }
574
575 if (for_oopif_) {
576 // Widgets for frames may be created and closed at any time while the frame
577 // is alive. However, the closing process must happen synchronously. Frame
578 // widget and frames hold pointers to each other. If Close() is deferred to
579 // the message loop like in the non-frame widget case, WebWidget::close()
580 // can end up accessing members of an already-deleted frame.
581 Close();
582 } else {
583 // If there is a Send call on the stack, then it could be dangerous to close
584 // now. Post a task that only gets invoked when there are no nested message
585 // loops.
586 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
587 FROM_HERE, base::Bind(&RenderWidget::Close, this));
588 }
589
590 // Balances the AddRef taken when we called AddRoute.
591 Release();
initial.commit09911bf2008-07-26 23:55:29592}
593
fsamuel664e8b62016-01-20 19:54:01594void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04595 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32596 return;
597
[email protected]b2e4c70132013-10-03 02:07:51598 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39599 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51600 return;
601 }
602
mfomitchev2600fd7c2016-02-17 20:53:39603 Resize(params);
initial.commit09911bf2008-07-26 23:55:29604}
605
dgozman9260b0a12015-03-16 13:45:20606void RenderWidget::OnEnableDeviceEmulation(
607 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39608 if (!screen_metrics_emulator_) {
609 ResizeParams resize_params;
610 resize_params.screen_info = screen_info_;
611 resize_params.new_size = size_;
612 resize_params.physical_backing_size = physical_backing_size_;
613 resize_params.visible_viewport_size = visible_viewport_size_;
614 resize_params.top_controls_shrink_blink_size =
615 top_controls_shrink_blink_size_;
616 resize_params.top_controls_height = top_controls_height_;
617 resize_params.resizer_rect = resizer_rect_;
618 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
619 resize_params.display_mode = display_mode_;
620 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
621 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18622 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39623 } else {
dgozman9260b0a12015-03-16 13:45:20624 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39625 }
dgozman9260b0a12015-03-16 13:45:20626}
627
628void RenderWidget::OnDisableDeviceEmulation() {
629 screen_metrics_emulator_.reset();
630}
631
noel89949e62014-09-30 01:12:41632void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
633 SetDeviceColorProfile(color_profile);
634}
635
[email protected]b5913d72012-02-07 22:26:54636void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01637 if (resizer_rect_ == resizer_rect)
638 return;
639 resizer_rect_ = resizer_rect;
640 if (webwidget_)
641 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54642}
643
initial.commit09911bf2008-07-26 23:55:29644void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31645 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29646 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03647 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59648 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
649 WasHidden());
initial.commit09911bf2008-07-26 23:55:29650}
651
[email protected]3399dd822014-08-09 11:14:24652void RenderWidget::OnWasShown(bool needs_repainting,
653 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41654 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29655 // During shutdown we can just ignore this message.
656 if (!webwidget_)
657 return;
658
659 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03660 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59661 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
662 WasShown());
initial.commit09911bf2008-07-26 23:55:29663
[email protected]8a23afb32014-04-30 22:40:23664 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29665 return;
initial.commit09911bf2008-07-26 23:55:29666
667 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24668 if (compositor_) {
669 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15670 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24671 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05672 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24673 }
jdduke491a3f0c2015-06-15 23:30:26674 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29675}
676
[email protected]53d3f302009-12-21 04:42:05677void RenderWidget::OnRequestMoveAck() {
678 DCHECK(pending_window_rect_count_);
679 pending_window_rect_count_--;
bokan71cb5b12016-04-27 03:45:22680 if (!pending_window_rect_count_)
681 view_screen_rect_ = pending_window_rect_;
[email protected]53d3f302009-12-21 04:42:05682}
683
[email protected]ed7defa2013-03-12 21:29:59684GURL RenderWidget::GetURLForGraphicsContext3D() {
685 return GURL();
[email protected]65225772011-05-12 21:10:24686}
687
fsamuel78f86e42016-01-20 04:10:23688void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10689 const ui::LatencyInfo& latency_info,
690 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23691 if (!input_event)
692 return;
dtapuska0bd451a2016-02-18 17:08:10693 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23694}
695
696void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
697 if (webwidget_)
698 webwidget_->setCursorVisibilityState(is_visible);
699}
700
701void RenderWidget::OnMouseCaptureLost() {
702 if (webwidget_)
703 webwidget_->mouseCaptureLost();
704}
705
706void RenderWidget::OnSetFocus(bool enable) {
707 if (webwidget_)
708 webwidget_->setFocus(enable);
709}
710
711///////////////////////////////////////////////////////////////////////////////
712// RenderWidgetCompositorDelegate
713
714void RenderWidget::ApplyViewportDeltas(
715 const gfx::Vector2dF& inner_delta,
716 const gfx::Vector2dF& outer_delta,
717 const gfx::Vector2dF& elastic_overscroll_delta,
718 float page_scale,
719 float top_controls_delta) {
720 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
721 elastic_overscroll_delta, page_scale,
722 top_controls_delta);
723}
724
725void RenderWidget::BeginMainFrame(double frame_time_sec) {
726 webwidget_->beginFrame(frame_time_sec);
727}
728
dchengcedca5612016-04-09 01:40:15729std::unique_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(
730 bool fallback) {
piman990d8ea2016-01-12 15:35:31731 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03732 // For widgets that are never visible, we don't start the compositor, so we
733 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39734 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19735
avi83883c82014-12-23 00:08:49736 const base::CommandLine& command_line =
737 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33738 bool use_software = fallback;
739 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
740 use_software = true;
741
penghuang28a5fa22015-12-02 17:58:19742#if defined(MOJO_SHELL_CLIENT)
rockot19c030e862016-02-26 05:46:58743 if (MojoShellConnection::Get() && !use_software &&
744 command_line.HasSwitch(switches::kUseMusInRenderer)) {
penghuang28a5fa22015-12-02 17:58:19745 RenderWidgetMusConnection* connection =
746 RenderWidgetMusConnection::GetOrCreate(routing_id());
747 return connection->CreateOutputSurface();
748 }
749#endif
750
penghuang346a46f92016-03-31 21:37:52751 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
piman990d8ea2016-01-12 15:35:31752 if (!use_software) {
753 CauseForGpuLaunch cause =
754 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
755 gpu_channel_host =
756 RenderThreadImpl::current()->EstablishGpuChannelSync(cause);
danakje8ec797e2016-04-19 04:08:43757 if (!gpu_channel_host) {
piman990d8ea2016-01-12 15:35:31758 // Cause the compositor to wait and try again.
759 return nullptr;
760 }
761 // We may get a valid channel, but with a software renderer. In that case,
762 // disable GPU compositing.
763 if (gpu_channel_host->gpu_info().software_rendering)
764 use_software = true;
765 }
766
dyen136e05c2016-04-06 22:28:27767 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider;
[email protected]0634cdd42013-08-16 00:46:09768 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17769 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33770 if (!use_software) {
dyenb52ecd962016-04-20 23:23:44771 if (command_line.HasSwitch(switches::kEnableVulkan)) {
772 vulkan_context_provider = cc::VulkanInProcessContextProvider::Create();
773 if (vulkan_context_provider) {
774 uint32_t output_surface_id = next_output_surface_id_++;
775 return base::WrapUnique(new DelegatedCompositorOutputSurface(
776 routing_id(), output_surface_id, context_provider,
777 worker_context_provider, vulkan_context_provider,
778 frame_swap_message_queue_));
779 }
dyen136e05c2016-04-06 22:28:27780 }
dyen136e05c2016-04-06 22:28:27781
danakj6f4e1e22016-04-20 03:27:34782 gpu::SharedMemoryLimits limits;
783 // The renderer compositor context doesn't do a lot of stuff, so we don't
784 // expect it to need a lot of space for commands or transfer. Raster and
785 // uploads happen on the worker context instead.
786 limits.command_buffer_size = 64 * 1024;
787 limits.start_transfer_buffer_size = 64 * 1024;
788 limits.min_transfer_buffer_size = 64 * 1024;
789
danakje8ec797e2016-04-19 04:08:43790 context_provider = new ContextProviderCommandBuffer(
791 CreateOffscreenContext(std::move(gpu_channel_host),
792 GetURLForGraphicsContext3D()),
danakj6f4e1e22016-04-20 03:27:34793 limits, RENDER_COMPOSITOR_CONTEXT);
revemand180dfc32015-09-24 00:19:43794 worker_context_provider =
795 RenderThreadImpl::current()->SharedWorkerContextProvider();
796 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17797 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34798 return nullptr;
vmiura78b69282015-02-14 00:01:17799 }
boliu853d46052015-10-13 20:20:06800
801#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:41802 if (RenderThreadImpl::current() &&
803 RenderThreadImpl::current()->sync_compositor_message_filter()) {
boliuf4e574852016-03-22 19:33:17804 uint32_t output_surface_id = next_output_surface_id_++;
dchengcedca5612016-04-09 01:40:15805 return base::WrapUnique(new SynchronousCompositorOutputSurface(
boliubee541f42015-11-05 00:52:53806 context_provider, worker_context_provider, routing_id(),
boliu66024c62016-04-20 04:00:41807 output_surface_id,
808 RenderThreadImpl::current()->sync_compositor_message_filter(),
boliubee541f42015-11-05 00:52:53809 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:06810 }
811#endif
[email protected]0634cdd42013-08-16 00:46:09812 }
[email protected]ebc0e1df2013-08-01 02:46:22813
avi1023d012015-12-25 02:39:14814 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:34815 // Composite-to-mailbox is currently used for layout tests in order to cause
816 // them to draw inside in the renderer to do the readback there. This should
817 // no longer be the case when crbug.com/311404 is fixed.
818 if (!RenderThreadImpl::current() ||
819 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:53820 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
dchengcedca5612016-04-09 01:40:15821 return base::WrapUnique(new DelegatedCompositorOutputSurface(
danakje8ec797e2016-04-19 04:08:43822 routing_id(), output_surface_id, std::move(context_provider),
823 std::move(worker_context_provider),
dyen136e05c2016-04-06 22:28:27824 vulkan_context_provider,
dyen136e05c2016-04-06 22:28:27825 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09826 }
piman8944e1c2015-09-22 21:10:34827
danakje8ec797e2016-04-19 04:08:43828 if (!context_provider) {
dchengcedca5612016-04-09 01:40:15829 std::unique_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:12830 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:09831
dchengcedca5612016-04-09 01:40:15832 return base::WrapUnique(new CompositorOutputSurface(
dyenb52ecd962016-04-20 23:23:44833 routing_id(), output_surface_id, nullptr, nullptr, nullptr,
dcheng07945f632015-12-26 07:59:32834 std::move(software_device), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:22835 }
[email protected]ed7defa2013-03-12 21:29:59836
dchengcedca5612016-04-09 01:40:15837 return base::WrapUnique(new MailboxOutputSurface(
danakje8ec797e2016-04-19 04:08:43838 routing_id(), output_surface_id, std::move(context_provider),
839 std::move(worker_context_provider), frame_swap_message_queue_,
840 cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:28841}
842
dchengcedca5612016-04-09 01:40:15843std::unique_ptr<cc::BeginFrameSource>
fsamuel78f86e42016-01-20 04:10:23844RenderWidget::CreateExternalBeginFrameSource() {
845 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
846}
847
848void RenderWidget::DidCommitAndDrawCompositorFrame() {
849 // NOTE: Tests may break if this event is renamed or moved. See
850 // tab_capture_performancetest.cc.
851 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
852 // Notify subclasses that we initiated the paint operation.
853 DidInitiatePaint();
854}
855
856void RenderWidget::DidCommitCompositorFrame() {
857 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
858 DidCommitCompositorFrame());
859 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
860 DidCommitCompositorFrame());
861#if defined(VIDEO_HOLE)
862 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
863 DidCommitCompositorFrame());
864#endif // defined(VIDEO_HOLE)
865 input_handler_->FlushPendingInputEventAck();
866}
867
868void RenderWidget::DidCompletePageScaleAnimation() {}
869
870void RenderWidget::DidCompleteSwapBuffers() {
871 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
872
873 // Notify subclasses threaded composited rendering was flushed to the screen.
874 DidFlushPaint();
875
pimanbfb2ceb2016-03-18 21:32:58876 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23877 return;
878 }
879
880 ViewHostMsg_UpdateRect_Params params;
881 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23882 params.flags = next_paint_flags_;
883
884 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
885 next_paint_flags_ = 0;
886 need_update_rect_for_auto_resize_ = false;
887}
888
889bool RenderWidget::ForOOPIF() const {
890 // TODO(simonhong): Remove this when we enable BeginFrame scheduling for
891 // OOPIF(crbug.com/471411).
892 return for_oopif_;
893}
894
895void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
896 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
897}
898
899bool RenderWidget::IsClosing() const {
900 return host_closing_;
901}
902
[email protected]4d7e46a2013-11-08 05:33:40903void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24904 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24905 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26906 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24907}
908
[email protected]4d7e46a2013-11-08 05:33:40909void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24910 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16911
[email protected]404939f2012-06-01 04:06:18912 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16913 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29914}
915
fsamuel78f86e42016-01-20 04:10:23916void RenderWidget::OnSwapBuffersPosted() {
917 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29918}
919
danakj53eccbc2016-03-02 22:51:07920void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23921 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29922}
923
fsamuel78f86e42016-01-20 04:10:23924void RenderWidget::UpdateVisualState() {
925 webwidget_->updateAllLifecyclePhases();
926}
927
928void RenderWidget::WillBeginCompositorFrame() {
929 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
930
931 // The UpdateTextInputState can result in further layout and possibly
932 // enable GPU acceleration so they need to be called before any painting
933 // is done.
934 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
935 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31936
937 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
938 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29939}
940
fsamuel72464894f2015-12-15 06:59:31941///////////////////////////////////////////////////////////////////////////////
942// RenderWidgetInputHandlerDelegate
943
avid7d6b2e2016-03-04 19:41:17944void RenderWidget::FocusChangeComplete() {
945 if (owner_delegate_)
946 owner_delegate_->RenderWidgetFocusChangeComplete();
947}
fsamuel72464894f2015-12-15 06:59:31948
949bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17950 if (owner_delegate_)
951 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
952
fsamuel72464894f2015-12-15 06:59:31953 return true;
954}
955
956void RenderWidget::ObserveWheelEventAndResult(
957 const blink::WebMouseWheelEvent& wheel_event,
958 const gfx::Vector2dF& wheel_unused_delta,
959 bool event_processed) {
960 if (!compositor_deps_->IsElasticOverscrollEnabled())
961 return;
962
963 cc::InputHandlerScrollResult scroll_result;
964 scroll_result.did_scroll = event_processed;
965 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
966 scroll_result.unused_scroll_delta = wheel_unused_delta;
967
968 RenderThreadImpl* render_thread = RenderThreadImpl::current();
969 InputHandlerManager* input_handler_manager =
970 render_thread ? render_thread->input_handler_manager() : NULL;
971 if (input_handler_manager) {
972 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
973 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:29974 }
fsamuel72464894f2015-12-15 06:59:31975}
976
dtapuska1827dd22016-03-11 15:24:59977void RenderWidget::ObserveGestureEventAndResult(
978 const blink::WebGestureEvent& gesture_event,
979 const gfx::Vector2dF& unused_delta,
980 bool event_processed) {
981 if (!compositor_deps_->IsElasticOverscrollEnabled())
982 return;
983
984 cc::InputHandlerScrollResult scroll_result;
985 scroll_result.did_scroll = event_processed;
986 scroll_result.did_overscroll_root = !unused_delta.IsZero();
987 scroll_result.unused_scroll_delta = unused_delta;
988
989 RenderThreadImpl* render_thread = RenderThreadImpl::current();
990 InputHandlerManager* input_handler_manager =
991 render_thread ? render_thread->input_handler_manager() : NULL;
992 if (input_handler_manager) {
993 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
994 routing_id_, gesture_event, scroll_result);
995 }
996}
997
avid7d6b2e2016-03-04 19:41:17998void RenderWidget::OnDidHandleKeyEvent() {
999 if (owner_delegate_)
1000 owner_delegate_->RenderWidgetDidHandleKeyEvent();
1001}
fsamuel72464894f2015-12-15 06:59:311002
1003void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
1004 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1005}
1006
dchengcedca5612016-04-09 01:40:151007void RenderWidget::OnInputEventAck(
1008 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:311009 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1010}
1011
dtapuska46616922016-03-17 22:52:011012void RenderWidget::NotifyInputEventHandled(
dtapuska0bd451a2016-02-18 17:08:101013 blink::WebInputEvent::Type handled_type) {
1014 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1015 InputHandlerManager* input_handler_manager =
1016 render_thread ? render_thread->input_handler_manager() : NULL;
1017 if (input_handler_manager) {
dtapuska46616922016-03-17 22:52:011018 input_handler_manager->NotifyInputEventHandledOnMainThread(routing_id_,
1019 handled_type);
dtapuska0bd451a2016-02-18 17:08:101020 }
1021}
1022
fsamuele8326c742016-01-12 00:49:391023void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1024 // Nothing to do here. RenderWidget created the |input_handler| and will take
1025 // ownership of it. We just verify here that we don't already have an input
1026 // handler.
1027 DCHECK(!input_handler_);
1028}
1029
fsamuel72464894f2015-12-15 06:59:311030void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1031 ChangeSource change_source) {
1032 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1033 if (ime_event_guard_) {
1034 // show_ime should still be effective even if it was set inside the IME
1035 // event guard.
1036 if (show_ime == ShowIme::IF_NEEDED) {
1037 ime_event_guard_->set_show_ime(true);
1038 }
1039 return;
1040 }
1041
1042 ui::TextInputType new_type = GetTextInputType();
1043 if (IsDateTimeInput(new_type))
1044 return; // Not considered as a text input field in WebKit/Chromium.
1045
1046 blink::WebTextInputInfo new_info;
1047 if (webwidget_)
1048 new_info = webwidget_->textInputInfo();
1049 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1050
1051 bool new_can_compose_inline = CanComposeInline();
1052
1053 // Only sends text input params if they are changed or if the ime should be
1054 // shown.
1055 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:391056 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:311057 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1058 text_input_info_ != new_info ||
1059 can_compose_inline_ != new_can_compose_inline)
1060#if defined(OS_ANDROID)
1061 || text_field_is_dirty_
1062#endif
1063 ) {
ekaramad9053e57b2016-04-26 20:00:381064 TextInputState params;
fsamuel72464894f2015-12-15 06:59:311065 params.type = new_type;
1066 params.mode = new_mode;
1067 params.flags = new_info.flags;
1068 params.value = new_info.value.utf8();
1069 params.selection_start = new_info.selectionStart;
1070 params.selection_end = new_info.selectionEnd;
1071 params.composition_start = new_info.compositionStart;
1072 params.composition_end = new_info.compositionEnd;
1073 params.can_compose_inline = new_can_compose_inline;
1074 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1075#if defined(USE_AURA)
1076 params.is_non_ime_change = true;
1077#endif
1078#if defined(OS_ANDROID)
1079 params.is_non_ime_change =
1080 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1081 if (params.is_non_ime_change)
1082 OnImeEventSentForAck(new_info);
1083 text_field_is_dirty_ = false;
1084#endif
1085 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1086
1087 text_input_info_ = new_info;
1088 text_input_type_ = new_type;
1089 text_input_mode_ = new_mode;
1090 can_compose_inline_ = new_can_compose_inline;
1091 text_input_flags_ = new_info.flags;
1092 }
1093}
1094
1095bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:171096 if (owner_delegate_)
1097 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
1098
fsamuel72464894f2015-12-15 06:59:311099 return false;
1100}
1101
1102bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
avid7d6b2e2016-03-04 19:41:171103 if (owner_delegate_)
1104 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1105
fsamuel72464894f2015-12-15 06:59:311106 return false;
[email protected]fd847792013-10-24 17:12:351107}
1108
initial.commit09911bf2008-07-26 23:55:291109///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391110// RenderWidgetScreenMetricsDelegate
1111
1112void RenderWidget::Redraw() {
1113 set_next_paint_is_resize_ack();
1114 if (compositor_)
1115 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1116}
1117
1118void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581119 bool orientation_changed =
1120 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
1121 screen_info_.orientationType != params.screen_info.orientationType;
1122
mfomitchev2600fd7c2016-02-17 20:53:391123 screen_info_ = params.screen_info;
1124 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
1125
1126 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1127 // A resize ack shouldn't be requested if we have not ACK'd the previous
1128 // one.
1129 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1130 }
1131
1132 // Ignore this during shutdown.
1133 if (!webwidget_)
1134 return;
1135
1136 if (compositor_)
1137 compositor_->setViewportSize(params.physical_backing_size);
1138
mfomitchev2600fd7c2016-02-17 20:53:391139 size_ = params.new_size;
1140 physical_backing_size_ = params.physical_backing_size;
1141
1142 top_controls_shrink_blink_size_ = params.top_controls_shrink_blink_size;
1143 top_controls_height_ = params.top_controls_height;
1144 visible_viewport_size_ = params.visible_viewport_size;
1145 resizer_rect_ = params.resizer_rect;
1146
1147 // NOTE: We may have entered fullscreen mode without changing our size.
1148 bool fullscreen_change =
1149 is_fullscreen_granted_ != params.is_fullscreen_granted;
1150 is_fullscreen_granted_ = params.is_fullscreen_granted;
1151 display_mode_ = params.display_mode;
1152
1153 webwidget_->setTopControlsHeight(params.top_controls_height,
1154 top_controls_shrink_blink_size_);
1155
bokan71cb5b12016-04-27 03:45:221156 gfx::Size new_widget_size = size_;
1157 if (IsUseZoomForDSFEnabled()) {
1158 new_widget_size = gfx::ScaleToCeiledSize(new_widget_size,
1159 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391160 }
bokan71cb5b12016-04-27 03:45:221161 // When resizing, we want to wait to paint before ACK'ing the resize. This
1162 // ensures that we only resize as fast as we can paint. We only need to
1163 // send an ACK if we are resized to a non-empty rect.
1164 webwidget_->resize(new_widget_size);
1165
mfomitchev2600fd7c2016-02-17 20:53:391166 WebSize visual_viewport_size;
1167
1168 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181169 visual_viewport_size = gfx::ScaleToCeiledSize(
1170 params.visible_viewport_size,
1171 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391172 } else {
1173 visual_viewport_size = visible_viewport_size_;
1174 }
1175
1176 webwidget()->resizeVisualViewport(visual_viewport_size);
1177
1178 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1179 // In this case there is no paint/composite and therefore no
1180 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1181 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1182 DCHECK(!params.needs_resize_ack);
1183 }
1184
1185 // Send the Resize_ACK flag once we paint again if requested.
1186 if (params.needs_resize_ack)
1187 set_next_paint_is_resize_ack();
1188
1189 if (fullscreen_change)
1190 DidToggleFullscreen();
1191
engedy6cb63c92016-02-23 14:14:581192 if (orientation_changed)
1193 OnOrientationChange();
1194
mfomitchev2600fd7c2016-02-17 20:53:391195 // If a resize ack is requested and it isn't set-up, then no more resizes will
1196 // come in and in general things will go wrong.
1197 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1198}
1199
1200void RenderWidget::SetScreenMetricsEmulationParameters(
1201 bool enabled,
1202 const blink::WebDeviceEmulationParams& params) {
1203 // This is only supported in RenderView.
1204 NOTREACHED();
1205}
1206
1207void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1208 const gfx::Rect& window_screen_rect) {
1209 view_screen_rect_ = view_screen_rect;
1210 window_screen_rect_ = window_screen_rect;
1211}
1212
1213///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461214// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291215
[email protected]244ac1892011-12-02 17:04:471216void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241217 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1218 convertViewportToWindow(&new_size_in_window);
1219 if (size_.width() != new_size_in_window.width ||
1220 size_.height() != new_size_in_window.height) {
1221 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581222
[email protected]5b45ad42013-10-25 00:42:041223 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241224 gfx::Rect new_pos(rootWindowRect().x,
1225 rootWindowRect().y,
1226 size_.width(),
1227 size_.height());
[email protected]eac2b362013-05-22 07:01:451228 view_screen_rect_ = new_pos;
1229 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031230 }
[email protected]20fbfc22013-05-08 20:50:581231
[email protected]eac2b362013-05-22 07:01:451232 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581233
[email protected]5b45ad42013-10-25 00:42:041234 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581235 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091236 }
[email protected]244ac1892011-12-02 17:04:471237}
1238
[email protected]3a1c8a8032013-03-18 22:35:321239void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401240 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051241 if (compositor_)
oshima750cb4342015-10-31 00:59:011242 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051243}
1244
[email protected]e195e582013-03-08 01:32:591245void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221246 DCHECK(!host_closing_);
1247
fsamuel78f86e42016-01-20 04:10:231248 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1249 compositor_deps_);
oshima750cb4342015-10-31 00:59:011250 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331251 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391252 // For background pages and certain tests, we don't want to trigger
1253 // OutputSurface creation.
1254 if (compositor_never_visible_ || !RenderThreadImpl::current())
1255 compositor_->SetNeverVisible();
1256
pimanc4af3072015-10-02 03:45:591257 StartCompositor();
[email protected]e195e582013-03-08 01:32:591258}
1259
ennef3c58142014-12-09 21:44:381260void RenderWidget::WillCloseLayerTreeView() {
1261 if (host_closing_)
1262 return;
1263
1264 // Prevent new compositors or output surfaces from being created.
1265 host_closing_ = true;
1266
[email protected]aeeedad2014-08-22 18:16:221267 // Always send this notification to prevent new layer tree views from
1268 // being created, even if one hasn't been created yet.
1269 if (webwidget_)
1270 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221271}
1272
[email protected]180ef242013-11-07 06:50:461273blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281274 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061275}
1276
dglazkovf0e1d6d2015-10-10 02:13:481277void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1278 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1279 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1280 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1281 }
dglazkov79c426102015-08-31 21:22:431282
dglazkovf0e1d6d2015-10-10 02:13:481283 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1284 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431285}
1286
jdduke491a3f0c2015-06-15 23:30:261287void RenderWidget::ScheduleComposite() {
1288 if (compositor_ &&
1289 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1290 compositor_->setNeedsAnimate();
1291 }
1292}
1293
1294void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1295 if (compositor_) {
1296 // Regardless of whether threaded compositing is enabled, always
1297 // use this mechanism to force the compositor to redraw. However,
1298 // the invalidation code path below is still needed for the
1299 // non-threaded case.
1300 compositor_->SetNeedsForcedRedraw();
1301 }
1302 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151303}
1304
[email protected]586871b2014-07-22 17:05:111305// static
dchengcedca5612016-04-09 01:40:151306std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111307 IPC::Message* msg,
1308 MessageDeliveryPolicy policy,
1309 FrameSwapMessageQueue* frame_swap_message_queue,
1310 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111311 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111312 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151313 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1314 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111315 &first_message_for_frame);
1316 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151317 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111318 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061319 return promise;
[email protected]586871b2014-07-22 17:05:111320 }
dcheng4b6b5ff2014-10-16 00:42:061321 return nullptr;
[email protected]586871b2014-07-22 17:05:111322}
1323
1324void RenderWidget::QueueMessage(IPC::Message* msg,
1325 MessageDeliveryPolicy policy) {
1326 // RenderThreadImpl::current() is NULL in some tests.
1327 if (!compositor_ || !RenderThreadImpl::current()) {
1328 Send(msg);
1329 return;
1330 }
1331
dchengcedca5612016-04-09 01:40:151332 std::unique_ptr<cc::SwapPromise> swap_promise =
1333 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111334 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111335 compositor_->GetSourceFrameNumber());
1336
1337 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321338 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351339 // Request a commit. This might either A) request a commit ahead of time
1340 // or B) request a commit which is not needed because there are not
1341 // pending updates. If B) then the commit will be skipped and the swap
1342 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1343 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1344 // can_cancel_commit is not unset.
1345 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111346 }
1347}
1348
[email protected]4873c7d2009-07-16 06:36:281349void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301350 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521351 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181352 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291353 // Only send a SetCursor message if we need to make a change.
1354 if (!current_cursor_.IsEqual(cursor)) {
1355 current_cursor_ = cursor;
1356 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1357 }
1358}
1359
1360// We are supposed to get a single call to Show for a newly created RenderWidget
1361// that was created via RenderWidget::CreateWebView. So, we wait until this
1362// point to dispatch the ShowWidget message.
1363//
1364// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281365// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291366//
[email protected]4873c7d2009-07-16 06:36:281367void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291368 DCHECK(!did_show_) << "received extraneous Show call";
1369 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1370 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1371
[email protected]8de12d942010-11-17 20:42:441372 if (did_show_)
1373 return;
1374
1375 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561376 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441377 // that's okay. It'll be ignored if as_popup is false, or the browser
1378 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561379 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1380 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291381}
1382
[email protected]4873c7d2009-07-16 06:36:281383void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291384}
1385
[email protected]2533ce12009-05-09 00:02:241386void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381387 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241388 Send(new ViewHostMsg_Close(routing_id_));
1389}
1390
dgozmancf9039cd2015-04-06 12:01:311391void RenderWidget::NotifyOnClose() {
1392 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1393}
1394
[email protected]4873c7d2009-07-16 06:36:281395void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081396 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321397 if (is_swapped_out_) {
1398 // This widget is currently swapped out, and the active widget is in a
1399 // different process. Have the browser route the close request to the
1400 // active widget instead, so that the correct unload handlers are run.
1401 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1402 return;
1403 }
1404
initial.commit09911bf2008-07-26 23:55:291405 // If a page calls window.close() twice, we'll end up here twice, but that's
1406 // OK. It is safe to send multiple Close messages.
1407
[email protected]2533ce12009-05-09 00:02:241408 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1409 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1410 // could be closed before the JS finishes executing. So instead, post a
1411 // message back to the message loop, which won't run until the JS is
1412 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081413 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211414 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291415}
1416
[email protected]9017d7852013-11-21 17:47:351417void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151418 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351419 const SyntheticGestureCompletionCallback& callback) {
1420 DCHECK(!callback.is_null());
1421
1422 pending_synthetic_gesture_callbacks_.push(callback);
1423
1424 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321425 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351426
1427 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1428}
1429
initial.commit09911bf2008-07-26 23:55:291430void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031431 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381432 WillCloseLayerTreeView();
1433 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291434 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281435 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291436 webwidget_ = NULL;
1437 }
1438}
1439
[email protected]4873c7d2009-07-16 06:36:281440WebRect RenderWidget::windowRect() {
1441 if (pending_window_rect_count_)
1442 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241443
[email protected]80ad8622012-11-07 16:33:031444 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291445}
1446
[email protected]180ef242013-11-07 06:50:461447void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301448 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541449 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301450}
1451
oshima33ec97cd2015-12-14 19:40:241452void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1453 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511454 if (popup_origin_scale_for_emulation_) {
1455 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561456 window_rect.x = popup_screen_origin_for_emulation_.x() +
1457 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1458 window_rect.y = popup_screen_origin_for_emulation_.y() +
1459 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511460 }
1461
[email protected]5b45ad42013-10-25 00:42:041462 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201463 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561464 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1465 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031466 } else {
bokanc007c3a2015-02-03 07:15:561467 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031468 }
initial.commit09911bf2008-07-26 23:55:291469 } else {
bokanc007c3a2015-02-03 07:15:561470 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291471 }
1472}
1473
[email protected]2533ce12009-05-09 00:02:241474void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1475 pending_window_rect_ = rect;
1476 pending_window_rect_count_++;
1477}
1478
[email protected]4873c7d2009-07-16 06:36:281479WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241480 if (pending_window_rect_count_) {
1481 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1482 // the RootWindowRect is probably going to return wrong results since the
1483 // browser may not have processed the Move yet. There isn't really anything
1484 // good to do in this case, and it shouldn't happen - since this size is
1485 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281486 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241487 }
1488
[email protected]80ad8622012-11-07 16:33:031489 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371490}
1491
[email protected]4873c7d2009-07-16 06:36:281492WebRect RenderWidget::windowResizerRect() {
1493 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191494}
1495
[email protected]fa7b1dc2010-06-23 17:53:041496void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261497 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041498 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071499 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041500 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131501 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281502 return;
[email protected]66fca5bc2013-05-23 06:58:291503 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361504 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041505 text, WebVector<WebCompositionUnderline>(underlines),
1506 selection_start, selection_end)) {
1507 // If we failed to set the composition text, then we need to let the browser
1508 // process to cancel the input method's ongoing composition session, to make
1509 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221510 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261511 }
[email protected]88dbe32f2013-06-20 23:31:361512 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041513}
1514
[email protected]fcf75d42013-12-03 20:11:261515void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511516 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021517 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131518 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041519 return;
[email protected]66fca5bc2013-05-23 06:58:291520 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391521 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021522 if (text.length())
1523 webwidget_->confirmComposition(text);
1524 else if (keep_selection)
1525 webwidget_->confirmComposition(WebWidget::KeepSelection);
1526 else
1527 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391528 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361529 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291530}
1531
oshimad5279032015-12-16 18:22:331532void RenderWidget::OnDeviceScaleFactorChanged() {
1533 if (!compositor_)
1534 return;
oshimad5279032015-12-16 18:22:331535 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181536 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331537 else
1538 compositor_->setDeviceScaleFactor(device_scale_factor_);
1539}
1540
[email protected]0bc1f572013-04-17 01:46:311541void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121542 // During shutdown we can just ignore this message.
1543 if (!webwidget_)
1544 return;
1545
[email protected]0bc1f572013-04-17 01:46:311546 // Even if the browser provides an empty damage rect, it's still expecting to
1547 // receive a repaint ack so just damage the entire widget bounds.
1548 if (size_to_paint.IsEmpty()) {
1549 size_to_paint = size_;
1550 }
1551
[email protected]ec7dc112008-08-06 05:30:121552 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051553 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311554 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121555}
1556
[email protected]79fa22e2013-08-23 15:18:121557void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351558 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1559
1560 pending_synthetic_gesture_callbacks_.front().Run();
1561 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271562}
1563
[email protected]4873c7d2009-07-16 06:36:281564void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111565 if (!webwidget_)
1566 return;
[email protected]4873c7d2009-07-16 06:36:281567 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111568}
1569
[email protected]80ad8622012-11-07 16:33:031570void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1571 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511572 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391573 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1574 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511575 } else {
mfomitchev2600fd7c2016-02-17 20:53:391576 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511577 }
[email protected]80ad8622012-11-07 16:33:031578 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1579}
1580
lfgdb5c4ed2016-03-04 23:09:071581void RenderWidget::OnUpdateWindowScreenRect(
1582 const gfx::Rect& window_screen_rect) {
1583 if (screen_metrics_emulator_) {
1584 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1585 } else {
1586 window_screen_rect_ = window_screen_rect;
1587 }
1588}
1589
kenrbb4e2a3b2015-05-14 15:05:051590void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1591 if (compositor_)
1592 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1593}
1594
dtrainor5ef644e2015-11-19 00:12:471595void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1596 if (compositor_)
1597 compositor_->OnHandleCompositorProto(proto);
1598}
1599
[email protected]adb362312014-06-28 06:04:241600void RenderWidget::showImeIfNeeded() {
1601 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131602}
1603
fsamuel72464894f2015-12-15 06:59:311604ui::TextInputType RenderWidget::GetTextInputType() {
1605 if (webwidget_)
1606 return WebKitToUiTextInputType(webwidget_->textInputType());
1607 return ui::TEXT_INPUT_TYPE_NONE;
1608}
1609
1610void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
fsamuel72464894f2015-12-15 06:59:311611 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1612 gfx::Range range = gfx::Range();
1613 if (should_update_range) {
1614 GetCompositionRange(&range);
1615 } else {
1616 range = composition_range_;
1617 }
1618 std::vector<gfx::Rect> character_bounds;
1619 GetCompositionCharacterBounds(&character_bounds);
1620
1621 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1622 return;
1623 composition_character_bounds_ = character_bounds;
1624 composition_range_ = range;
1625 Send(new InputHostMsg_ImeCompositionRangeChanged(
1626 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311627}
1628
oshimaf866dab2015-12-05 00:41:541629void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1630 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181631 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331632 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541633 // anchor element can be placed at half pixel.
1634 gfx::Rect window_rect =
1635 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1636 rect->x = window_rect.x();
1637 rect->y = window_rect.y();
1638 rect->width = window_rect.width();
1639 rect->height = window_rect.height();
1640 }
1641}
1642
oshimaa6985b62016-01-27 08:58:301643void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1644 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181645 rect->x *= GetOriginalDeviceScaleFactor();
1646 rect->y *= GetOriginalDeviceScaleFactor();
1647 rect->width *= GetOriginalDeviceScaleFactor();
1648 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301649 }
1650}
1651
[email protected]adb362312014-06-28 06:04:241652void RenderWidget::OnShowImeIfNeeded() {
1653#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311654 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241655#endif
rouslanf7ebd8832015-01-22 01:54:141656
1657// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1658// virtual keyboard.
1659#if !defined(OS_ANDROID)
1660 FocusChangeComplete();
1661#endif
[email protected]adb362312014-06-28 06:04:241662}
1663
1664#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371665void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1666 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131667}
1668
1669void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371670 DCHECK_GE(text_input_info_history_.size(), 1u);
1671 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511672}
changwan8c342742016-02-26 00:53:391673
1674void RenderWidget::OnRequestTextInputStateUpdate() {
1675 DCHECK(!ime_event_guard_);
1676 UpdateSelectionBounds();
1677 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1678}
[email protected]105dffb42013-02-20 03:46:211679#endif
1680
[email protected]0d1ebed12013-08-05 22:01:131681bool RenderWidget::ShouldHandleImeEvent() {
1682#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371683 if (!webwidget_)
1684 return false;
changwan8c342742016-02-26 00:53:391685 if (IsUsingImeThread())
1686 return true;
changwan3a841162015-08-11 02:53:371687
1688 // We cannot handle IME events if there is any chance that the event we are
1689 // receiving here from the browser is based on the state that is different
1690 // from our current one as indicated by |text_input_info_|.
1691 // The states the browser might be in are:
1692 // text_input_info_history_[0] - current state ack'd by browser
1693 // text_input_info_history_[1...N] - pending state changes
1694 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1695 if (text_input_info_history_[i] != text_input_info_)
1696 return false;
1697 }
1698 return true;
[email protected]0d1ebed12013-08-05 22:01:131699#else
1700 return !!webwidget_;
1701#endif
1702}
1703
[email protected]468ac582012-11-20 00:53:191704void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1705 if (device_scale_factor_ == device_scale_factor)
1706 return;
1707
1708 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331709
1710 OnDeviceScaleFactorChanged();
1711
jdduke491a3f0c2015-06-15 23:30:261712 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191713}
1714
[email protected]28ed6b32014-06-08 02:16:271715bool RenderWidget::SetDeviceColorProfile(
1716 const std::vector<char>& color_profile) {
1717 if (device_color_profile_ == color_profile)
1718 return false;
1719
1720 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271721
avi40b5be7a2016-03-03 21:13:441722 if (owner_delegate_)
1723 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1724
1725 return true;
noeldb4df152014-09-16 17:45:201726}
1727
[email protected]fcdc5642014-05-09 14:32:241728void RenderWidget::OnOrientationChange() {
1729}
1730
avib9dbd972016-03-08 18:19:321731void RenderWidget::DidInitiatePaint() {
1732 if (owner_delegate_)
1733 owner_delegate_->RenderWidgetDidCommitAndDrawCompositorFrame();
1734}
1735
1736void RenderWidget::DidFlushPaint() {
1737 if (owner_delegate_)
1738 owner_delegate_->RenderWidgetDidFlushPaint();
1739}
1740
[email protected]bee16aab2009-08-26 15:55:031741void RenderWidget::SetHidden(bool hidden) {
1742 if (is_hidden_ == hidden)
1743 return;
1744
jdduke8fac9d102014-12-20 02:40:131745 // The status has changed. Tell the RenderThread about it and ensure
1746 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031747 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391748 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131749
[email protected]bee16aab2009-08-26 15:55:031750 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001751 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031752 else
[email protected]b2db9272014-01-10 17:42:001753 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111754
1755 if (render_widget_scheduling_state_)
1756 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031757}
1758
[email protected]2b624c562011-10-27 22:58:261759void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261760 if (!webwidget_)
1761 return;
1762
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121763 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261764 webwidget_->didEnterFullScreen();
1765 } else {
1766 webwidget_->didExitFullScreen();
1767 }
[email protected]2b624c562011-10-27 22:58:261768}
1769
[email protected]674741932009-02-04 23:44:461770bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051771 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461772}
1773
[email protected]674741932009-02-04 23:44:461774void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051775 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461776}
1777
[email protected]674741932009-02-04 23:44:461778void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051779 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461780}
1781
changwan8c342742016-02-26 00:53:391782bool RenderWidget::IsUsingImeThread() {
1783#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121784 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391785#else
1786 return false;
1787#endif
1788}
1789
changwanf2a707b2015-10-30 08:22:161790void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1791 if (!ime_event_guard_)
1792 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291793}
1794
changwanf2a707b2015-10-30 08:22:161795void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1796 if (ime_event_guard_ != guard) {
1797#if defined(OS_ANDROID)
1798 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1799 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391800 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161801 // Therefore, we want to mark this text state update as 'from IME' only
1802 // when all the nested events are all originating from IME.
1803 ime_event_guard_->set_from_ime(
1804 ime_event_guard_->from_ime() && guard->from_ime());
1805#endif
1806 return;
1807 }
1808 ime_event_guard_ = nullptr;
1809
[email protected]66fca5bc2013-05-23 06:58:291810 // While handling an ime event, text input state and selection bounds updates
1811 // are ignored. These must explicitly be updated once finished handling the
1812 // ime event.
1813 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471814#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161815 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311816 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1817 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471818#endif
[email protected]66fca5bc2013-05-23 06:58:291819}
1820
[email protected]7c8873e2013-02-05 08:03:011821void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1822 WebRect focus_webrect;
1823 WebRect anchor_webrect;
1824 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241825 convertViewportToWindow(&focus_webrect);
1826 convertViewportToWindow(&anchor_webrect);
1827 *focus = focus_webrect;
1828 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321829}
1830
[email protected]e99ef6f2011-10-16 01:13:001831void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081832 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001833 if (!webwidget_)
1834 return;
changwanf2a707b2015-10-30 08:22:161835 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291836 return;
[email protected]e99ef6f2011-10-16 01:13:001837
mohsenb0eeba72015-08-09 06:20:081838#if defined(USE_AURA)
1839 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1840 // Aura beucause composited selection updates are not working for webview tags
1841 // which regresses IME inside webview. Remove this when composited selection
1842 // updates are fixed for webviews. See, http://crbug.com/510568.
1843 bool send_ipc = true;
1844#else
jddukeacf809e2014-09-23 20:38:381845 // With composited selection updates, the selection bounds will be reported
1846 // directly by the compositor, in which case explicit IPC selection
1847 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081848 bool send_ipc =
1849 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1850#endif
1851 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381852 ViewHostMsg_SelectionBounds_Params params;
1853 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1854 if (selection_anchor_rect_ != params.anchor_rect ||
1855 selection_focus_rect_ != params.focus_rect) {
1856 selection_anchor_rect_ = params.anchor_rect;
1857 selection_focus_rect_ = params.focus_rect;
1858 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1859 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1860 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1861 }
[email protected]58b48a0d2012-06-13 07:01:351862 }
jddukeacf809e2014-09-23 20:38:381863
[email protected]88dbe32f2013-06-20 23:31:361864 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001865}
1866
avi40b5be7a2016-03-03 21:13:441867void RenderWidget::SetDeviceColorProfileForTesting(
1868 const std::vector<char>& color_profile) {
1869 SetDeviceColorProfile(color_profile);
1870}
1871
1872void RenderWidget::ResetDeviceColorProfileForTesting() {
1873 std::vector<char> color_profile;
1874 color_profile.push_back('0');
1875 SetDeviceColorProfile(color_profile);
1876}
1877
[email protected]180ef242013-11-07 06:50:461878// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371879STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1880STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1881STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1882 ui::TEXT_INPUT_TYPE_PASSWORD);
1883STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1884STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1885STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1886STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1887 ui::TEXT_INPUT_TYPE_TELEPHONE);
1888STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1889STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1890STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1891 ui::TEXT_INPUT_TYPE_DATE_TIME);
1892STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1893 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1894STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1895STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1896STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1897STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1898 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1899STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1900 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1901STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1902 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451903
[email protected]5b739cb2012-08-21 20:35:211904ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461905 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211906 // Check the type is in the range representable by ui::TextInputType.
1907 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461908 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211909 return static_cast<ui::TextInputType>(type);
1910}
1911
[email protected]58b48a0d2012-06-13 07:01:351912void RenderWidget::GetCompositionCharacterBounds(
1913 std::vector<gfx::Rect>* bounds) {
1914 DCHECK(bounds);
1915 bounds->clear();
1916}
1917
[email protected]db4fc1e2013-09-06 20:01:511918void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361919 size_t location, length;
1920 if (webwidget_->compositionRange(&location, &length)) {
1921 range->set_start(location);
1922 range->set_end(location + length);
1923 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1924 range->set_start(location);
1925 range->set_end(location + length);
1926 } else {
[email protected]db4fc1e2013-09-06 20:01:511927 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361928 }
1929}
1930
[email protected]501ea13d2013-07-09 17:03:291931bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511932 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291933 const std::vector<gfx::Rect>& bounds) {
1934 if (composition_range_ != range)
1935 return true;
1936 if (bounds.size() != composition_character_bounds_.size())
1937 return true;
1938 for (size_t i = 0; i < bounds.size(); ++i) {
1939 if (bounds[i] != composition_character_bounds_[i])
1940 return true;
1941 }
1942 return false;
1943}
[email protected]501ea13d2013-07-09 17:03:291944
[email protected]ad26ef42011-06-17 07:59:451945bool RenderWidget::CanComposeInline() {
1946 return true;
[email protected]56ea1a62011-05-30 07:05:571947}
1948
[email protected]4873c7d2009-07-16 06:36:281949WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041950 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281951}
1952
[email protected]fa7b1dc2010-06-23 17:53:041953void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021954 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041955 // If the last text input type is not None, then we should finish any
1956 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451957 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041958 // If a composition text exists, then we need to let the browser process
1959 // to cancel the input method's ongoing composition session.
1960 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221961 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041962 }
[email protected]d4cff272011-05-02 15:46:011963
[email protected]88dbe32f2013-06-20 23:31:361964 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041965}
1966
donnda070f3c2015-01-16 19:54:111967#if defined(OS_ANDROID)
1968void RenderWidget::showUnhandledTapUIIfNeeded(
1969 const WebPoint& tapped_position,
1970 const WebNode& tapped_node,
1971 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391972 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111973 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371974 !tapped_node.isContentEditable() &&
1975 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111976 if (should_trigger) {
1977 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1978 tapped_position.x, tapped_position.y));
1979 }
1980}
1981#endif
1982
[email protected]c68c3e4e2013-01-24 00:36:561983void RenderWidget::didHandleGestureEvent(
1984 const WebGestureEvent& event,
1985 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021986#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561987 if (event_cancelled)
1988 return;
[email protected]07c70d22014-08-21 08:33:461989 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311990 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461991 } else if (event.type == WebInputEvent::GestureLongPress) {
1992 DCHECK(webwidget_);
1993 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311994 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461995 else
fsamuel72464894f2015-12-15 06:59:311996 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561997 }
1998#endif
1999}
2000
sataya.m582c9ce2015-06-09 08:03:422001void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312002 const blink::WebFloatSize& overscrollDelta,
2003 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422004 const blink::WebFloatPoint& position,
2005 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482006#if defined(OS_MACOSX)
2007 // On OSX the user can disable the elastic overscroll effect. If that's the
2008 // case, don't forward the overscroll notification.
2009 DCHECK(compositor_deps());
2010 if (!compositor_deps()->IsElasticOverscrollEnabled())
2011 return;
2012#endif
bokane53a10f2016-04-13 23:48:312013 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392014 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422015}
2016
[email protected]7912e822014-04-16 02:37:032017void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392018 if (!is_hidden())
2019 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032020}
2021
[email protected]24ed0432013-04-24 07:50:312022RenderWidgetCompositor* RenderWidget::compositor() const {
2023 return compositor_.get();
2024}
2025
fsamuel72464894f2015-12-15 06:59:312026void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392027 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372028}
[email protected]c3d45532011-10-07 19:20:402029
fsamuel72464894f2015-12-15 06:59:312030bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392031 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242032}
2033
fsamuel72464894f2015-12-15 06:59:312034void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392035 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312036}
2037
[email protected]ce6689f2013-03-29 12:52:552038void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112039 if (render_widget_scheduling_state_)
2040 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552041 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2042}
2043
danakj365175c2016-02-06 00:37:372044// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2045STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2046STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2047STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2048STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2049STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2050STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2051STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2052STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2053STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2054STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2055 TOUCH_ACTION_MANIPULATION);
2056STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2057 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2058STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172059
[email protected]5d0bbdfa92013-12-10 00:35:512060void RenderWidget::setTouchAction(
2061 blink::WebTouchAction web_touch_action) {
2062
2063 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2064 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392065 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512066 return;
2067
[email protected]a18f67a2013-12-20 19:44:362068 content::TouchAction content_touch_action =
2069 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512070 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2071}
2072
[email protected]90f24152014-04-09 12:41:362073void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2074#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392075 if (!IsUsingImeThread())
2076 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362077#endif
2078}
2079
[email protected]e3244ed2014-06-20 20:04:272080void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2081 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162082}
2083
[email protected]e3244ed2014-06-20 20:04:272084void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2085 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162086}
2087
[email protected]de3c5d82014-05-28 22:12:592088void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2089 render_frames_.AddObserver(frame);
2090}
2091
2092void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2093 render_frames_.RemoveObserver(frame);
2094}
2095
[email protected]a017938b2014-05-27 21:17:172096#if defined(VIDEO_HOLE)
2097void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2098 video_hole_frames_.AddObserver(frame);
2099}
2100
2101void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2102 video_hole_frames_.RemoveObserver(frame);
2103}
2104#endif // defined(VIDEO_HOLE)
2105
lfg43e08e62016-02-03 18:51:372106void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2107 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2108 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2109}
2110
oshima50872a72016-03-04 13:26:182111float RenderWidget::GetOriginalDeviceScaleFactor() const {
2112 return
2113 screen_metrics_emulator_ ?
2114 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2115 device_scale_factor_;
2116}
2117
[email protected]e9ff79c2012-10-19 21:31:262118} // namespace content