blob: 38071275a8949875094bd2b556dacbb1547659e0 [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),
initial.commit09911bf2008-07-26 23:55:29248 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51249 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09250 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29251 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04252 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39253 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12254 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12255 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16256 ime_event_guard_(nullptr),
[email protected]661eb9d2009-02-03 02:11:48257 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22258 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44259 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20260 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45261 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40262 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20263 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53264 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12265 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48266 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04267 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52268 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30269 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13270#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36271 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13272#endif
[email protected]b2e4c70132013-10-03 02:07:51273 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11274 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42275 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51276 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05277 if (!swapped_out)
278 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27279 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53280 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37281#if defined(OS_ANDROID)
282 text_input_info_history_.push_back(blink::WebTextInputInfo());
283#endif
alexclarke7fa93942015-10-21 15:37:11284
285 // In tests there may not be a RenderThreadImpl.
286 if (RenderThreadImpl::current()) {
287 render_widget_scheduling_state_ = RenderThreadImpl::current()
288 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32289 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11290 render_widget_scheduling_state_->SetHidden(is_hidden_);
291 }
initial.commit09911bf2008-07-26 23:55:29292}
293
294RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11295 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16296
[email protected]992db4c2011-05-12 15:37:15297 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02298 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15299 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29300}
301
[email protected]484955942010-08-19 16:13:18302// static
avi1023d012015-12-25 02:39:14303RenderWidget* RenderWidget::Create(int32_t opener_id,
danakj6e3bf8012014-12-16 18:27:53304 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46305 blink::WebPopupType popup_type,
306 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29307 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36308 scoped_refptr<RenderWidget> widget(new RenderWidget(
309 compositor_deps, popup_type, screen_info, false, false, false));
310 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46311 return widget.get();
[email protected]a635f942012-12-07 10:34:29312 }
313 return NULL;
initial.commit09911bf2008-07-26 23:55:29314}
315
[email protected]484955942010-08-19 16:13:18316// static
kenrba7199832015-01-22 23:44:59317RenderWidget* RenderWidget::CreateForFrame(
318 int routing_id,
kenrba7199832015-01-22 23:44:59319 bool hidden,
320 const blink::WebScreenInfo& screen_info,
321 CompositorDependencies* compositor_deps,
322 blink::WebLocalFrame* frame) {
323 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55324 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
325 // same routing ID for both the view routing ID and the main frame widget
326 // routing ID. https://crbug.com/545684
327 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
328 if (view) {
avi8a45c1092016-03-01 16:12:34329 view->AttachWebFrameWidget(
330 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame));
331 return view->GetWidget();
dcheng3ce04b62015-10-26 23:30:55332 }
dcheng35d31c112015-07-22 00:17:36333 scoped_refptr<RenderWidget> widget(
334 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
335 false, hidden, false));
fsamuele8326c742016-01-12 00:49:39336 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20337 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59338 // DoInit increments the reference count on |widget|, keeping it alive after
339 // this function returns.
dcheng35d31c112015-07-22 00:17:36340 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59341 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
342 nullptr)) {
kenrba7199832015-01-22 23:44:59343 return widget.get();
344 }
345 return nullptr;
346}
347
348// static
lfgcaab5142016-02-26 19:06:52349blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08350 RenderWidget* render_widget,
351 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55352 if (!frame->parent()) {
353 // TODO(dcheng): The main frame widget currently has a special case.
354 // Eliminate this once WebView is no longer a WebWidget.
355 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
356 }
dchengda9b4bb2015-07-20 20:58:08357 return blink::WebFrameWidget::create(render_widget, frame);
358}
359
360// static
kenrba7199832015-01-22 23:44:59361blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18362 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46363 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18364 break;
[email protected]180ef242013-11-07 06:50:46365 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44366 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18367 default:
368 NOTREACHED();
369 }
370 return NULL;
371}
372
dchengda9b4bb2015-07-20 20:58:08373void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32374 OnClose();
kenrba7199832015-01-22 23:44:59375}
376
fsamuele8326c742016-01-12 00:49:39377void RenderWidget::SetRoutingID(int32_t routing_id) {
378 routing_id_ = routing_id;
379 input_handler_.reset(new RenderWidgetInputHandler(
380 GetRenderWidgetInputHandlerDelegate(this), this));
381}
382
avi1023d012015-12-25 02:39:14383bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39384 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05385 opener_id, RenderWidget::CreateWebWidget(this),
386 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39387 if (success) {
388 SetRoutingID(routing_id_);
389 return true;
390 }
391 return false;
[email protected]484955942010-08-19 16:13:18392}
393
avi1023d012015-12-25 02:39:14394bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06395 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18396 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29397 DCHECK(!webwidget_);
398
399 if (opener_id != MSG_ROUTING_NONE)
400 opener_id_ = opener_id;
401
[email protected]484955942010-08-19 16:13:18402 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29403
kenrba7199832015-01-22 23:44:59404 bool result = true;
405 if (create_widget_message)
406 result = RenderThread::Get()->Send(create_widget_message);
407
initial.commit09911bf2008-07-26 23:55:29408 if (result) {
[email protected]380244092011-10-07 17:26:27409 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29410 // Take a reference on behalf of the RenderThread. This will be balanced
411 // when we receive ViewMsg_Close.
412 AddRef();
[email protected]b2db9272014-01-10 17:42:00413 if (RenderThreadImpl::current()) {
414 RenderThreadImpl::current()->WidgetCreated();
415 if (is_hidden_)
416 RenderThreadImpl::current()->WidgetHidden();
417 }
fsamuele8326c742016-01-12 00:49:39418
[email protected]a635f942012-12-07 10:34:29419 return true;
initial.commit09911bf2008-07-26 23:55:29420 } else {
[email protected]a635f942012-12-07 10:34:29421 // The above Send can fail when the tab is closing.
422 return false;
initial.commit09911bf2008-07-26 23:55:29423 }
424}
425
[email protected]992db4c2011-05-12 15:37:15426void RenderWidget::SetSwappedOut(bool is_swapped_out) {
427 // We should only toggle between states.
428 DCHECK(is_swapped_out_ != is_swapped_out);
429 is_swapped_out_ = is_swapped_out;
430
431 // If we are swapping out, we will call ReleaseProcess, allowing the process
432 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52433 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15434 // If we are swapping in, we call AddRefProcess to prevent the process from
435 // exiting.
[email protected]949b6592014-08-20 13:17:52436 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15437 RenderProcess::current()->AddRefProcess();
438}
439
[email protected]949b6592014-08-20 13:17:52440void RenderWidget::WasSwappedOut() {
441 // If we have been swapped out and no one else is using this process,
442 // it's safe to exit now.
443 CHECK(is_swapped_out_);
444 RenderProcess::current()->ReleaseProcess();
445}
446
[email protected]b2e4c70132013-10-03 02:07:51447void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39448 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51449 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43450 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49451 popup_screen_origin_for_emulation_ = gfx::Point(
452 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
453 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56454 screen_info_ = emulator->original_screen_info();
455 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51456}
457
[email protected]2d6836f42014-07-02 17:25:31458gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
459 if (screen_metrics_emulator_)
460 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
461 return anchor;
462}
463
[email protected]53907862014-03-25 15:42:40464#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51465void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39466 ExternalPopupMenu* popup,
467 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49468 popup->SetOriginScaleAndOffsetForEmulation(
469 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51470}
[email protected]53907862014-03-25 15:42:40471#endif
[email protected]b2e4c70132013-10-03 02:07:51472
473void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
474 if (screen_metrics_emulator_)
475 screen_metrics_emulator_->OnShowContextMenu(params);
476}
477
[email protected]a95986a82010-12-24 06:19:28478bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
479 bool handled = true;
480 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15481 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22482 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
483 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22484 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
485 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15486 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
487 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35488 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
489 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28490 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28491 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20492 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
493 OnEnableDeviceEmulation)
494 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
495 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41496 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54497 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28498 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41499 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25500 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28501 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
502 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03503 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05504 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
lfg43e08e62016-02-03 18:51:37505 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
506 OnWaitNextFrameForTests)
[email protected]105dffb42013-02-20 03:46:21507#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37508 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39509 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
510 OnRequestTextInputStateUpdate)
[email protected]2384b6c2013-02-28 23:58:51511 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21512#endif
dtrainor5ef644e2015-11-19 00:12:47513 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28514 IPC_MESSAGE_UNHANDLED(handled = false)
515 IPC_END_MESSAGE_MAP()
516 return handled;
517}
initial.commit09911bf2008-07-26 23:55:29518
519bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15520 // Don't send any messages after the browser has told us to close, and filter
521 // most outgoing messages while swapped out.
522 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26523 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11524 closing_) {
initial.commit09911bf2008-07-26 23:55:29525 delete message;
526 return false;
527 }
528
529 // If given a messsage without a routing ID, then assign our routing ID.
530 if (message->routing_id() == MSG_ROUTING_NONE)
531 message->set_routing_id(routing_id_);
532
[email protected]380244092011-10-07 17:26:27533 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44534}
535
bokanc007c3a2015-02-03 07:15:56536void RenderWidget::SetWindowRectSynchronously(
537 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39538 ResizeParams params;
539 params.screen_info = screen_info_;
540 params.new_size = new_window_rect.size();
541 params.physical_backing_size =
542 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39543 params.visible_viewport_size = new_window_rect.size();
544 params.resizer_rect = gfx::Rect();
545 params.is_fullscreen_granted = is_fullscreen_granted_;
546 params.display_mode = display_mode_;
547 params.needs_resize_ack = false;
548 Resize(params);
549
bokanc007c3a2015-02-03 07:15:56550 view_screen_rect_ = new_window_rect;
551 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02552 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56553 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02554}
555
initial.commit09911bf2008-07-26 23:55:29556void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32557 DCHECK(content::RenderThread::Get());
558 if (closing_)
559 return;
560 NotifyOnClose();
561 closing_ = true;
562
563 // Browser correspondence is no longer needed at this point.
564 if (routing_id_ != MSG_ROUTING_NONE) {
565 RenderThread::Get()->RemoveRoute(routing_id_);
566 SetHidden(false);
567 if (RenderThreadImpl::current())
568 RenderThreadImpl::current()->WidgetDestroyed();
569 }
570
571 if (for_oopif_) {
572 // Widgets for frames may be created and closed at any time while the frame
573 // is alive. However, the closing process must happen synchronously. Frame
574 // widget and frames hold pointers to each other. If Close() is deferred to
575 // the message loop like in the non-frame widget case, WebWidget::close()
576 // can end up accessing members of an already-deleted frame.
577 Close();
578 } else {
579 // If there is a Send call on the stack, then it could be dangerous to close
580 // now. Post a task that only gets invoked when there are no nested message
581 // loops.
582 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
583 FROM_HERE, base::Bind(&RenderWidget::Close, this));
584 }
585
586 // Balances the AddRef taken when we called AddRoute.
587 Release();
initial.commit09911bf2008-07-26 23:55:29588}
589
fsamuel664e8b62016-01-20 19:54:01590void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04591 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32592 return;
593
[email protected]b2e4c70132013-10-03 02:07:51594 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39595 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51596 return;
597 }
598
mfomitchev2600fd7c2016-02-17 20:53:39599 Resize(params);
initial.commit09911bf2008-07-26 23:55:29600}
601
dgozman9260b0a12015-03-16 13:45:20602void RenderWidget::OnEnableDeviceEmulation(
603 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39604 if (!screen_metrics_emulator_) {
605 ResizeParams resize_params;
606 resize_params.screen_info = screen_info_;
607 resize_params.new_size = size_;
608 resize_params.physical_backing_size = physical_backing_size_;
609 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39610 resize_params.resizer_rect = resizer_rect_;
611 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
612 resize_params.display_mode = display_mode_;
613 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
614 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18615 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39616 } else {
dgozman9260b0a12015-03-16 13:45:20617 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39618 }
dgozman9260b0a12015-03-16 13:45:20619}
620
621void RenderWidget::OnDisableDeviceEmulation() {
622 screen_metrics_emulator_.reset();
623}
624
noel89949e62014-09-30 01:12:41625void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
626 SetDeviceColorProfile(color_profile);
627}
628
[email protected]b5913d72012-02-07 22:26:54629void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01630 if (resizer_rect_ == resizer_rect)
631 return;
632 resizer_rect_ = resizer_rect;
633 if (webwidget_)
634 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54635}
636
initial.commit09911bf2008-07-26 23:55:29637void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31638 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29639 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03640 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59641 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
642 WasHidden());
initial.commit09911bf2008-07-26 23:55:29643}
644
[email protected]3399dd822014-08-09 11:14:24645void RenderWidget::OnWasShown(bool needs_repainting,
646 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41647 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29648 // During shutdown we can just ignore this message.
649 if (!webwidget_)
650 return;
651
652 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03653 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59654 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
655 WasShown());
initial.commit09911bf2008-07-26 23:55:29656
[email protected]8a23afb32014-04-30 22:40:23657 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29658 return;
initial.commit09911bf2008-07-26 23:55:29659
660 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24661 if (compositor_) {
662 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15663 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24664 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05665 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24666 }
jdduke491a3f0c2015-06-15 23:30:26667 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29668}
669
[email protected]53d3f302009-12-21 04:42:05670void RenderWidget::OnRequestMoveAck() {
671 DCHECK(pending_window_rect_count_);
672 pending_window_rect_count_--;
bokan71cb5b12016-04-27 03:45:22673 if (!pending_window_rect_count_)
674 view_screen_rect_ = pending_window_rect_;
[email protected]53d3f302009-12-21 04:42:05675}
676
[email protected]ed7defa2013-03-12 21:29:59677GURL RenderWidget::GetURLForGraphicsContext3D() {
678 return GURL();
[email protected]65225772011-05-12 21:10:24679}
680
fsamuel78f86e42016-01-20 04:10:23681void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10682 const ui::LatencyInfo& latency_info,
683 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23684 if (!input_event)
685 return;
dtapuska0bd451a2016-02-18 17:08:10686 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23687}
688
689void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
690 if (webwidget_)
691 webwidget_->setCursorVisibilityState(is_visible);
692}
693
694void RenderWidget::OnMouseCaptureLost() {
695 if (webwidget_)
696 webwidget_->mouseCaptureLost();
697}
698
699void RenderWidget::OnSetFocus(bool enable) {
700 if (webwidget_)
701 webwidget_->setFocus(enable);
702}
703
704///////////////////////////////////////////////////////////////////////////////
705// RenderWidgetCompositorDelegate
706
707void RenderWidget::ApplyViewportDeltas(
708 const gfx::Vector2dF& inner_delta,
709 const gfx::Vector2dF& outer_delta,
710 const gfx::Vector2dF& elastic_overscroll_delta,
711 float page_scale,
712 float top_controls_delta) {
713 webwidget_->applyViewportDeltas(inner_delta, outer_delta,
714 elastic_overscroll_delta, page_scale,
715 top_controls_delta);
716}
717
718void RenderWidget::BeginMainFrame(double frame_time_sec) {
719 webwidget_->beginFrame(frame_time_sec);
720}
721
dchengcedca5612016-04-09 01:40:15722std::unique_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(
723 bool fallback) {
piman990d8ea2016-01-12 15:35:31724 DCHECK(webwidget_);
[email protected]7912e822014-04-16 02:37:03725 // For widgets that are never visible, we don't start the compositor, so we
726 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:39727 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:19728
avi83883c82014-12-23 00:08:49729 const base::CommandLine& command_line =
730 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33731 bool use_software = fallback;
732 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
733 use_software = true;
734
penghuang28a5fa22015-12-02 17:58:19735#if defined(MOJO_SHELL_CLIENT)
rockot19c030e862016-02-26 05:46:58736 if (MojoShellConnection::Get() && !use_software &&
737 command_line.HasSwitch(switches::kUseMusInRenderer)) {
penghuang28a5fa22015-12-02 17:58:19738 RenderWidgetMusConnection* connection =
739 RenderWidgetMusConnection::GetOrCreate(routing_id());
740 return connection->CreateOutputSurface();
741 }
742#endif
743
penghuang346a46f92016-03-31 21:37:52744 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host;
piman990d8ea2016-01-12 15:35:31745 if (!use_software) {
746 CauseForGpuLaunch cause =
747 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
748 gpu_channel_host =
749 RenderThreadImpl::current()->EstablishGpuChannelSync(cause);
danakje8ec797e2016-04-19 04:08:43750 if (!gpu_channel_host) {
piman990d8ea2016-01-12 15:35:31751 // Cause the compositor to wait and try again.
752 return nullptr;
753 }
754 // We may get a valid channel, but with a software renderer. In that case,
755 // disable GPU compositing.
756 if (gpu_channel_host->gpu_info().software_rendering)
757 use_software = true;
758 }
759
dyen136e05c2016-04-06 22:28:27760 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider;
[email protected]0634cdd42013-08-16 00:46:09761 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17762 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33763 if (!use_software) {
dyenb52ecd962016-04-20 23:23:44764 if (command_line.HasSwitch(switches::kEnableVulkan)) {
765 vulkan_context_provider = cc::VulkanInProcessContextProvider::Create();
766 if (vulkan_context_provider) {
767 uint32_t output_surface_id = next_output_surface_id_++;
768 return base::WrapUnique(new DelegatedCompositorOutputSurface(
769 routing_id(), output_surface_id, context_provider,
770 worker_context_provider, vulkan_context_provider,
771 frame_swap_message_queue_));
772 }
dyen136e05c2016-04-06 22:28:27773 }
dyen136e05c2016-04-06 22:28:27774
danakj6f4e1e22016-04-20 03:27:34775 gpu::SharedMemoryLimits limits;
776 // The renderer compositor context doesn't do a lot of stuff, so we don't
777 // expect it to need a lot of space for commands or transfer. Raster and
778 // uploads happen on the worker context instead.
779 limits.command_buffer_size = 64 * 1024;
780 limits.start_transfer_buffer_size = 64 * 1024;
781 limits.min_transfer_buffer_size = 64 * 1024;
782
danakje8ec797e2016-04-19 04:08:43783 context_provider = new ContextProviderCommandBuffer(
784 CreateOffscreenContext(std::move(gpu_channel_host),
785 GetURLForGraphicsContext3D()),
danakj6f4e1e22016-04-20 03:27:34786 limits, RENDER_COMPOSITOR_CONTEXT);
revemand180dfc32015-09-24 00:19:43787 worker_context_provider =
788 RenderThreadImpl::current()->SharedWorkerContextProvider();
789 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17790 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34791 return nullptr;
vmiura78b69282015-02-14 00:01:17792 }
boliu853d46052015-10-13 20:20:06793
794#if defined(OS_ANDROID)
boliu66024c62016-04-20 04:00:41795 if (RenderThreadImpl::current() &&
796 RenderThreadImpl::current()->sync_compositor_message_filter()) {
boliuf4e574852016-03-22 19:33:17797 uint32_t output_surface_id = next_output_surface_id_++;
dchengcedca5612016-04-09 01:40:15798 return base::WrapUnique(new SynchronousCompositorOutputSurface(
boliubee541f42015-11-05 00:52:53799 context_provider, worker_context_provider, routing_id(),
boliu66024c62016-04-20 04:00:41800 output_surface_id,
801 RenderThreadImpl::current()->sync_compositor_message_filter(),
boliubee541f42015-11-05 00:52:53802 frame_swap_message_queue_));
boliu853d46052015-10-13 20:20:06803 }
804#endif
[email protected]0634cdd42013-08-16 00:46:09805 }
[email protected]ebc0e1df2013-08-01 02:46:22806
avi1023d012015-12-25 02:39:14807 uint32_t output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:34808 // Composite-to-mailbox is currently used for layout tests in order to cause
809 // them to draw inside in the renderer to do the readback there. This should
810 // no longer be the case when crbug.com/311404 is fixed.
811 if (!RenderThreadImpl::current() ||
812 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:53813 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
dchengcedca5612016-04-09 01:40:15814 return base::WrapUnique(new DelegatedCompositorOutputSurface(
danakje8ec797e2016-04-19 04:08:43815 routing_id(), output_surface_id, std::move(context_provider),
816 std::move(worker_context_provider),
dyen136e05c2016-04-06 22:28:27817 vulkan_context_provider,
dyen136e05c2016-04-06 22:28:27818 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09819 }
piman8944e1c2015-09-22 21:10:34820
danakje8ec797e2016-04-19 04:08:43821 if (!context_provider) {
dchengcedca5612016-04-09 01:40:15822 std::unique_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:12823 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:09824
dchengcedca5612016-04-09 01:40:15825 return base::WrapUnique(new CompositorOutputSurface(
dyenb52ecd962016-04-20 23:23:44826 routing_id(), output_surface_id, nullptr, nullptr, nullptr,
dcheng07945f632015-12-26 07:59:32827 std::move(software_device), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:22828 }
[email protected]ed7defa2013-03-12 21:29:59829
dchengcedca5612016-04-09 01:40:15830 return base::WrapUnique(new MailboxOutputSurface(
danakje8ec797e2016-04-19 04:08:43831 routing_id(), output_surface_id, std::move(context_provider),
832 std::move(worker_context_provider), frame_swap_message_queue_,
833 cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:28834}
835
dchengcedca5612016-04-09 01:40:15836std::unique_ptr<cc::BeginFrameSource>
fsamuel78f86e42016-01-20 04:10:23837RenderWidget::CreateExternalBeginFrameSource() {
838 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_);
839}
840
841void RenderWidget::DidCommitAndDrawCompositorFrame() {
842 // NOTE: Tests may break if this event is renamed or moved. See
843 // tab_capture_performancetest.cc.
844 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
845 // Notify subclasses that we initiated the paint operation.
846 DidInitiatePaint();
847}
848
849void RenderWidget::DidCommitCompositorFrame() {
850 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
851 DidCommitCompositorFrame());
852 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
853 DidCommitCompositorFrame());
854#if defined(VIDEO_HOLE)
855 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
856 DidCommitCompositorFrame());
857#endif // defined(VIDEO_HOLE)
858 input_handler_->FlushPendingInputEventAck();
859}
860
861void RenderWidget::DidCompletePageScaleAnimation() {}
862
863void RenderWidget::DidCompleteSwapBuffers() {
864 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
865
866 // Notify subclasses threaded composited rendering was flushed to the screen.
867 DidFlushPaint();
868
pimanbfb2ceb2016-03-18 21:32:58869 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23870 return;
871 }
872
873 ViewHostMsg_UpdateRect_Params params;
874 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23875 params.flags = next_paint_flags_;
876
877 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
878 next_paint_flags_ = 0;
879 need_update_rect_for_auto_resize_ = false;
880}
881
882bool RenderWidget::ForOOPIF() const {
883 // TODO(simonhong): Remove this when we enable BeginFrame scheduling for
884 // OOPIF(crbug.com/471411).
885 return for_oopif_;
886}
887
888void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
889 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
890}
891
892bool RenderWidget::IsClosing() const {
893 return host_closing_;
894}
895
[email protected]4d7e46a2013-11-08 05:33:40896void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24897 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24898 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26899 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24900}
901
[email protected]4d7e46a2013-11-08 05:33:40902void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24903 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16904
[email protected]404939f2012-06-01 04:06:18905 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16906 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29907}
908
fsamuel78f86e42016-01-20 04:10:23909void RenderWidget::OnSwapBuffersPosted() {
910 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29911}
912
danakj53eccbc2016-03-02 22:51:07913void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23914 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29915}
916
fsamuel78f86e42016-01-20 04:10:23917void RenderWidget::UpdateVisualState() {
918 webwidget_->updateAllLifecyclePhases();
919}
920
921void RenderWidget::WillBeginCompositorFrame() {
922 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
923
924 // The UpdateTextInputState can result in further layout and possibly
925 // enable GPU acceleration so they need to be called before any painting
926 // is done.
927 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
928 UpdateSelectionBounds();
lfge6119aac2016-01-27 02:14:31929
930 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
931 WillBeginCompositorFrame());
initial.commit09911bf2008-07-26 23:55:29932}
933
fsamuel72464894f2015-12-15 06:59:31934///////////////////////////////////////////////////////////////////////////////
935// RenderWidgetInputHandlerDelegate
936
avid7d6b2e2016-03-04 19:41:17937void RenderWidget::FocusChangeComplete() {
938 if (owner_delegate_)
939 owner_delegate_->RenderWidgetFocusChangeComplete();
940}
fsamuel72464894f2015-12-15 06:59:31941
942bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17943 if (owner_delegate_)
944 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
945
fsamuel72464894f2015-12-15 06:59:31946 return true;
947}
948
949void RenderWidget::ObserveWheelEventAndResult(
950 const blink::WebMouseWheelEvent& wheel_event,
951 const gfx::Vector2dF& wheel_unused_delta,
952 bool event_processed) {
953 if (!compositor_deps_->IsElasticOverscrollEnabled())
954 return;
955
956 cc::InputHandlerScrollResult scroll_result;
957 scroll_result.did_scroll = event_processed;
958 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
959 scroll_result.unused_scroll_delta = wheel_unused_delta;
960
961 RenderThreadImpl* render_thread = RenderThreadImpl::current();
962 InputHandlerManager* input_handler_manager =
963 render_thread ? render_thread->input_handler_manager() : NULL;
964 if (input_handler_manager) {
965 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
966 routing_id_, wheel_event, scroll_result);
jddukefffb67c2015-01-07 22:32:29967 }
fsamuel72464894f2015-12-15 06:59:31968}
969
dtapuska1827dd22016-03-11 15:24:59970void RenderWidget::ObserveGestureEventAndResult(
971 const blink::WebGestureEvent& gesture_event,
972 const gfx::Vector2dF& unused_delta,
973 bool event_processed) {
974 if (!compositor_deps_->IsElasticOverscrollEnabled())
975 return;
976
977 cc::InputHandlerScrollResult scroll_result;
978 scroll_result.did_scroll = event_processed;
979 scroll_result.did_overscroll_root = !unused_delta.IsZero();
980 scroll_result.unused_scroll_delta = unused_delta;
981
982 RenderThreadImpl* render_thread = RenderThreadImpl::current();
983 InputHandlerManager* input_handler_manager =
984 render_thread ? render_thread->input_handler_manager() : NULL;
985 if (input_handler_manager) {
986 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
987 routing_id_, gesture_event, scroll_result);
988 }
989}
990
avid7d6b2e2016-03-04 19:41:17991void RenderWidget::OnDidHandleKeyEvent() {
992 if (owner_delegate_)
993 owner_delegate_->RenderWidgetDidHandleKeyEvent();
994}
fsamuel72464894f2015-12-15 06:59:31995
996void RenderWidget::OnDidOverscroll(const DidOverscrollParams& params) {
997 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
998}
999
dchengcedca5612016-04-09 01:40:151000void RenderWidget::OnInputEventAck(
1001 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:311002 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1003}
1004
dtapuska46616922016-03-17 22:52:011005void RenderWidget::NotifyInputEventHandled(
dtapuska0bd451a2016-02-18 17:08:101006 blink::WebInputEvent::Type handled_type) {
1007 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1008 InputHandlerManager* input_handler_manager =
1009 render_thread ? render_thread->input_handler_manager() : NULL;
1010 if (input_handler_manager) {
dtapuska46616922016-03-17 22:52:011011 input_handler_manager->NotifyInputEventHandledOnMainThread(routing_id_,
1012 handled_type);
dtapuska0bd451a2016-02-18 17:08:101013 }
1014}
1015
fsamuele8326c742016-01-12 00:49:391016void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1017 // Nothing to do here. RenderWidget created the |input_handler| and will take
1018 // ownership of it. We just verify here that we don't already have an input
1019 // handler.
1020 DCHECK(!input_handler_);
1021}
1022
fsamuel72464894f2015-12-15 06:59:311023void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1024 ChangeSource change_source) {
1025 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
1026 if (ime_event_guard_) {
1027 // show_ime should still be effective even if it was set inside the IME
1028 // event guard.
1029 if (show_ime == ShowIme::IF_NEEDED) {
1030 ime_event_guard_->set_show_ime(true);
1031 }
1032 return;
1033 }
1034
1035 ui::TextInputType new_type = GetTextInputType();
1036 if (IsDateTimeInput(new_type))
1037 return; // Not considered as a text input field in WebKit/Chromium.
1038
1039 blink::WebTextInputInfo new_info;
1040 if (webwidget_)
1041 new_info = webwidget_->textInputInfo();
1042 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
1043
1044 bool new_can_compose_inline = CanComposeInline();
1045
1046 // Only sends text input params if they are changed or if the ime should be
1047 // shown.
1048 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:391049 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
fsamuel72464894f2015-12-15 06:59:311050 (text_input_type_ != new_type || text_input_mode_ != new_mode ||
1051 text_input_info_ != new_info ||
1052 can_compose_inline_ != new_can_compose_inline)
1053#if defined(OS_ANDROID)
1054 || text_field_is_dirty_
1055#endif
1056 ) {
ekaramad9053e57b2016-04-26 20:00:381057 TextInputState params;
fsamuel72464894f2015-12-15 06:59:311058 params.type = new_type;
1059 params.mode = new_mode;
1060 params.flags = new_info.flags;
1061 params.value = new_info.value.utf8();
1062 params.selection_start = new_info.selectionStart;
1063 params.selection_end = new_info.selectionEnd;
1064 params.composition_start = new_info.compositionStart;
1065 params.composition_end = new_info.compositionEnd;
1066 params.can_compose_inline = new_can_compose_inline;
1067 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
1068#if defined(USE_AURA)
1069 params.is_non_ime_change = true;
1070#endif
1071#if defined(OS_ANDROID)
1072 params.is_non_ime_change =
1073 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
1074 if (params.is_non_ime_change)
1075 OnImeEventSentForAck(new_info);
1076 text_field_is_dirty_ = false;
1077#endif
1078 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
1079
1080 text_input_info_ = new_info;
1081 text_input_type_ = new_type;
1082 text_input_mode_ = new_mode;
1083 can_compose_inline_ = new_can_compose_inline;
1084 text_input_flags_ = new_info.flags;
1085 }
1086}
1087
1088bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:171089 if (owner_delegate_)
1090 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
1091
fsamuel72464894f2015-12-15 06:59:311092 return false;
1093}
1094
1095bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
avid7d6b2e2016-03-04 19:41:171096 if (owner_delegate_)
1097 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1098
fsamuel72464894f2015-12-15 06:59:311099 return false;
[email protected]fd847792013-10-24 17:12:351100}
1101
initial.commit09911bf2008-07-26 23:55:291102///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391103// RenderWidgetScreenMetricsDelegate
1104
1105void RenderWidget::Redraw() {
1106 set_next_paint_is_resize_ack();
1107 if (compositor_)
1108 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1109}
1110
bokanc63441c2016-04-27 15:49:121111void RenderWidget::ResizeWebWidget() {
1112 webwidget_->resize(GetSizeForWebWidget());
1113}
1114
1115gfx::Size RenderWidget::GetSizeForWebWidget() const {
1116 if (IsUseZoomForDSFEnabled())
1117 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1118
1119 return size_;
1120}
1121
mfomitchev2600fd7c2016-02-17 20:53:391122void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581123 bool orientation_changed =
1124 screen_info_.orientationAngle != params.screen_info.orientationAngle ||
1125 screen_info_.orientationType != params.screen_info.orientationType;
1126
mfomitchev2600fd7c2016-02-17 20:53:391127 screen_info_ = params.screen_info;
1128 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
1129
1130 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1131 // A resize ack shouldn't be requested if we have not ACK'd the previous
1132 // one.
1133 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1134 }
1135
1136 // Ignore this during shutdown.
1137 if (!webwidget_)
1138 return;
1139
1140 if (compositor_)
1141 compositor_->setViewportSize(params.physical_backing_size);
1142
mfomitchev2600fd7c2016-02-17 20:53:391143 visible_viewport_size_ = params.visible_viewport_size;
1144 resizer_rect_ = params.resizer_rect;
1145
1146 // NOTE: We may have entered fullscreen mode without changing our size.
1147 bool fullscreen_change =
1148 is_fullscreen_granted_ != params.is_fullscreen_granted;
1149 is_fullscreen_granted_ = params.is_fullscreen_granted;
1150 display_mode_ = params.display_mode;
1151
bokanc63441c2016-04-27 15:49:121152 size_ = params.new_size;
1153 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391154
bokanc63441c2016-04-27 15:49:121155 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221156
mfomitchev2600fd7c2016-02-17 20:53:391157 WebSize visual_viewport_size;
1158
1159 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181160 visual_viewport_size = gfx::ScaleToCeiledSize(
1161 params.visible_viewport_size,
1162 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391163 } else {
1164 visual_viewport_size = visible_viewport_size_;
1165 }
1166
1167 webwidget()->resizeVisualViewport(visual_viewport_size);
1168
bokanc63441c2016-04-27 15:49:121169 // When resizing, we want to wait to paint before ACK'ing the resize. This
1170 // ensures that we only resize as fast as we can paint. We only need to
1171 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391172 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1173 // In this case there is no paint/composite and therefore no
1174 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1175 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1176 DCHECK(!params.needs_resize_ack);
1177 }
1178
1179 // Send the Resize_ACK flag once we paint again if requested.
1180 if (params.needs_resize_ack)
1181 set_next_paint_is_resize_ack();
1182
1183 if (fullscreen_change)
1184 DidToggleFullscreen();
1185
engedy6cb63c92016-02-23 14:14:581186 if (orientation_changed)
1187 OnOrientationChange();
1188
mfomitchev2600fd7c2016-02-17 20:53:391189 // If a resize ack is requested and it isn't set-up, then no more resizes will
1190 // come in and in general things will go wrong.
1191 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1192}
1193
1194void RenderWidget::SetScreenMetricsEmulationParameters(
1195 bool enabled,
1196 const blink::WebDeviceEmulationParams& params) {
1197 // This is only supported in RenderView.
1198 NOTREACHED();
1199}
1200
1201void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1202 const gfx::Rect& window_screen_rect) {
1203 view_screen_rect_ = view_screen_rect;
1204 window_screen_rect_ = window_screen_rect;
1205}
1206
1207///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461208// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291209
[email protected]244ac1892011-12-02 17:04:471210void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima33ec97cd2015-12-14 19:40:241211 WebRect new_size_in_window(0, 0, new_size.width, new_size.height);
1212 convertViewportToWindow(&new_size_in_window);
1213 if (size_.width() != new_size_in_window.width ||
1214 size_.height() != new_size_in_window.height) {
1215 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
[email protected]20fbfc22013-05-08 20:50:581216
[email protected]5b45ad42013-10-25 00:42:041217 if (resizing_mode_selector_->is_synchronous_mode()) {
oshima33ec97cd2015-12-14 19:40:241218 gfx::Rect new_pos(rootWindowRect().x,
1219 rootWindowRect().y,
1220 size_.width(),
1221 size_.height());
[email protected]eac2b362013-05-22 07:01:451222 view_screen_rect_ = new_pos;
1223 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031224 }
[email protected]20fbfc22013-05-08 20:50:581225
[email protected]eac2b362013-05-22 07:01:451226 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581227
[email protected]5b45ad42013-10-25 00:42:041228 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581229 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091230 }
[email protected]244ac1892011-12-02 17:04:471231}
1232
[email protected]3a1c8a8032013-03-18 22:35:321233void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401234 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051235 if (compositor_)
oshima750cb4342015-10-31 00:59:011236 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051237}
1238
[email protected]e195e582013-03-08 01:32:591239void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221240 DCHECK(!host_closing_);
1241
fsamuel78f86e42016-01-20 04:10:231242 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1243 compositor_deps_);
oshima750cb4342015-10-31 00:59:011244 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331245 OnDeviceScaleFactorChanged();
sievers71c62dd52015-10-07 01:44:391246 // For background pages and certain tests, we don't want to trigger
1247 // OutputSurface creation.
1248 if (compositor_never_visible_ || !RenderThreadImpl::current())
1249 compositor_->SetNeverVisible();
1250
pimanc4af3072015-10-02 03:45:591251 StartCompositor();
[email protected]e195e582013-03-08 01:32:591252}
1253
ennef3c58142014-12-09 21:44:381254void RenderWidget::WillCloseLayerTreeView() {
1255 if (host_closing_)
1256 return;
1257
1258 // Prevent new compositors or output surfaces from being created.
1259 host_closing_ = true;
1260
[email protected]aeeedad2014-08-22 18:16:221261 // Always send this notification to prevent new layer tree views from
1262 // being created, even if one hasn't been created yet.
1263 if (webwidget_)
1264 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221265}
1266
[email protected]180ef242013-11-07 06:50:461267blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281268 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061269}
1270
dglazkovf0e1d6d2015-10-10 02:13:481271void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1272 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1273 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1274 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1275 }
dglazkov79c426102015-08-31 21:22:431276
dglazkovf0e1d6d2015-10-10 02:13:481277 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1278 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431279}
1280
jdduke491a3f0c2015-06-15 23:30:261281void RenderWidget::ScheduleComposite() {
1282 if (compositor_ &&
1283 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1284 compositor_->setNeedsAnimate();
1285 }
1286}
1287
1288void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1289 if (compositor_) {
1290 // Regardless of whether threaded compositing is enabled, always
1291 // use this mechanism to force the compositor to redraw. However,
1292 // the invalidation code path below is still needed for the
1293 // non-threaded case.
1294 compositor_->SetNeedsForcedRedraw();
1295 }
1296 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151297}
1298
[email protected]586871b2014-07-22 17:05:111299// static
dchengcedca5612016-04-09 01:40:151300std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111301 IPC::Message* msg,
1302 MessageDeliveryPolicy policy,
1303 FrameSwapMessageQueue* frame_swap_message_queue,
1304 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111305 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111306 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151307 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1308 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111309 &first_message_for_frame);
1310 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151311 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111312 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061313 return promise;
[email protected]586871b2014-07-22 17:05:111314 }
dcheng4b6b5ff2014-10-16 00:42:061315 return nullptr;
[email protected]586871b2014-07-22 17:05:111316}
1317
1318void RenderWidget::QueueMessage(IPC::Message* msg,
1319 MessageDeliveryPolicy policy) {
1320 // RenderThreadImpl::current() is NULL in some tests.
1321 if (!compositor_ || !RenderThreadImpl::current()) {
1322 Send(msg);
1323 return;
1324 }
1325
dchengcedca5612016-04-09 01:40:151326 std::unique_ptr<cc::SwapPromise> swap_promise =
1327 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111328 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111329 compositor_->GetSourceFrameNumber());
1330
1331 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321332 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351333 // Request a commit. This might either A) request a commit ahead of time
1334 // or B) request a commit which is not needed because there are not
1335 // pending updates. If B) then the commit will be skipped and the swap
1336 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1337 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1338 // can_cancel_commit is not unset.
1339 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111340 }
1341}
1342
[email protected]4873c7d2009-07-16 06:36:281343void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301344 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521345 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181346 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291347 // Only send a SetCursor message if we need to make a change.
1348 if (!current_cursor_.IsEqual(cursor)) {
1349 current_cursor_ = cursor;
1350 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1351 }
1352}
1353
1354// We are supposed to get a single call to Show for a newly created RenderWidget
1355// that was created via RenderWidget::CreateWebView. So, we wait until this
1356// point to dispatch the ShowWidget message.
1357//
1358// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281359// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291360//
[email protected]4873c7d2009-07-16 06:36:281361void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291362 DCHECK(!did_show_) << "received extraneous Show call";
1363 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1364 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1365
[email protected]8de12d942010-11-17 20:42:441366 if (did_show_)
1367 return;
1368
1369 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561370 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441371 // that's okay. It'll be ignored if as_popup is false, or the browser
1372 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561373 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1374 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291375}
1376
[email protected]4873c7d2009-07-16 06:36:281377void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291378}
1379
[email protected]2533ce12009-05-09 00:02:241380void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381381 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241382 Send(new ViewHostMsg_Close(routing_id_));
1383}
1384
dgozmancf9039cd2015-04-06 12:01:311385void RenderWidget::NotifyOnClose() {
1386 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1387}
1388
[email protected]4873c7d2009-07-16 06:36:281389void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081390 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321391 if (is_swapped_out_) {
1392 // This widget is currently swapped out, and the active widget is in a
1393 // different process. Have the browser route the close request to the
1394 // active widget instead, so that the correct unload handlers are run.
1395 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1396 return;
1397 }
1398
initial.commit09911bf2008-07-26 23:55:291399 // If a page calls window.close() twice, we'll end up here twice, but that's
1400 // OK. It is safe to send multiple Close messages.
1401
[email protected]2533ce12009-05-09 00:02:241402 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1403 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1404 // could be closed before the JS finishes executing. So instead, post a
1405 // message back to the message loop, which won't run until the JS is
1406 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081407 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211408 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291409}
1410
[email protected]9017d7852013-11-21 17:47:351411void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151412 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351413 const SyntheticGestureCompletionCallback& callback) {
1414 DCHECK(!callback.is_null());
1415
1416 pending_synthetic_gesture_callbacks_.push(callback);
1417
1418 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321419 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351420
1421 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1422}
1423
initial.commit09911bf2008-07-26 23:55:291424void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031425 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381426 WillCloseLayerTreeView();
1427 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291428 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281429 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291430 webwidget_ = NULL;
1431 }
1432}
1433
[email protected]4873c7d2009-07-16 06:36:281434WebRect RenderWidget::windowRect() {
1435 if (pending_window_rect_count_)
1436 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241437
[email protected]80ad8622012-11-07 16:33:031438 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291439}
1440
[email protected]180ef242013-11-07 06:50:461441void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301442 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541443 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301444}
1445
oshima33ec97cd2015-12-14 19:40:241446void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1447 WebRect window_rect = rect_in_screen;
[email protected]b2e4c70132013-10-03 02:07:511448 if (popup_origin_scale_for_emulation_) {
1449 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561450 window_rect.x = popup_screen_origin_for_emulation_.x() +
1451 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1452 window_rect.y = popup_screen_origin_for_emulation_.y() +
1453 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511454 }
1455
[email protected]5b45ad42013-10-25 00:42:041456 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201457 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561458 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1459 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031460 } else {
bokanc007c3a2015-02-03 07:15:561461 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031462 }
initial.commit09911bf2008-07-26 23:55:291463 } else {
bokanc007c3a2015-02-03 07:15:561464 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291465 }
1466}
1467
[email protected]2533ce12009-05-09 00:02:241468void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1469 pending_window_rect_ = rect;
1470 pending_window_rect_count_++;
1471}
1472
[email protected]4873c7d2009-07-16 06:36:281473WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241474 if (pending_window_rect_count_) {
1475 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1476 // the RootWindowRect is probably going to return wrong results since the
1477 // browser may not have processed the Move yet. There isn't really anything
1478 // good to do in this case, and it shouldn't happen - since this size is
1479 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281480 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241481 }
1482
[email protected]80ad8622012-11-07 16:33:031483 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371484}
1485
[email protected]4873c7d2009-07-16 06:36:281486WebRect RenderWidget::windowResizerRect() {
1487 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191488}
1489
[email protected]fa7b1dc2010-06-23 17:53:041490void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261491 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041492 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071493 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041494 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131495 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281496 return;
[email protected]66fca5bc2013-05-23 06:58:291497 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361498 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041499 text, WebVector<WebCompositionUnderline>(underlines),
1500 selection_start, selection_end)) {
1501 // If we failed to set the composition text, then we need to let the browser
1502 // process to cancel the input method's ongoing composition session, to make
1503 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221504 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261505 }
[email protected]88dbe32f2013-06-20 23:31:361506 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041507}
1508
[email protected]fcf75d42013-12-03 20:11:261509void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511510 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021511 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131512 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041513 return;
[email protected]66fca5bc2013-05-23 06:58:291514 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391515 input_handler_->set_handling_input_event(true);
[email protected]0e45bd02013-07-12 20:20:021516 if (text.length())
1517 webwidget_->confirmComposition(text);
1518 else if (keep_selection)
1519 webwidget_->confirmComposition(WebWidget::KeepSelection);
1520 else
1521 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391522 input_handler_->set_handling_input_event(false);
[email protected]88dbe32f2013-06-20 23:31:361523 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291524}
1525
oshimad5279032015-12-16 18:22:331526void RenderWidget::OnDeviceScaleFactorChanged() {
1527 if (!compositor_)
1528 return;
oshimad5279032015-12-16 18:22:331529 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181530 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331531 else
1532 compositor_->setDeviceScaleFactor(device_scale_factor_);
1533}
1534
[email protected]0bc1f572013-04-17 01:46:311535void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121536 // During shutdown we can just ignore this message.
1537 if (!webwidget_)
1538 return;
1539
[email protected]0bc1f572013-04-17 01:46:311540 // Even if the browser provides an empty damage rect, it's still expecting to
1541 // receive a repaint ack so just damage the entire widget bounds.
1542 if (size_to_paint.IsEmpty()) {
1543 size_to_paint = size_;
1544 }
1545
[email protected]ec7dc112008-08-06 05:30:121546 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051547 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311548 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121549}
1550
[email protected]79fa22e2013-08-23 15:18:121551void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351552 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1553
1554 pending_synthetic_gesture_callbacks_.front().Run();
1555 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271556}
1557
[email protected]4873c7d2009-07-16 06:36:281558void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111559 if (!webwidget_)
1560 return;
[email protected]4873c7d2009-07-16 06:36:281561 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111562}
1563
[email protected]80ad8622012-11-07 16:33:031564void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1565 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511566 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391567 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1568 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511569 } else {
mfomitchev2600fd7c2016-02-17 20:53:391570 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511571 }
[email protected]80ad8622012-11-07 16:33:031572 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1573}
1574
lfgdb5c4ed2016-03-04 23:09:071575void RenderWidget::OnUpdateWindowScreenRect(
1576 const gfx::Rect& window_screen_rect) {
1577 if (screen_metrics_emulator_) {
1578 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
1579 } else {
1580 window_screen_rect_ = window_screen_rect;
1581 }
1582}
1583
kenrbb4e2a3b2015-05-14 15:05:051584void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1585 if (compositor_)
1586 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1587}
1588
dtrainor5ef644e2015-11-19 00:12:471589void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1590 if (compositor_)
1591 compositor_->OnHandleCompositorProto(proto);
1592}
1593
[email protected]adb362312014-06-28 06:04:241594void RenderWidget::showImeIfNeeded() {
1595 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131596}
1597
fsamuel72464894f2015-12-15 06:59:311598ui::TextInputType RenderWidget::GetTextInputType() {
1599 if (webwidget_)
1600 return WebKitToUiTextInputType(webwidget_->textInputType());
1601 return ui::TEXT_INPUT_TYPE_NONE;
1602}
1603
1604void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
fsamuel72464894f2015-12-15 06:59:311605 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1606 gfx::Range range = gfx::Range();
1607 if (should_update_range) {
1608 GetCompositionRange(&range);
1609 } else {
1610 range = composition_range_;
1611 }
1612 std::vector<gfx::Rect> character_bounds;
1613 GetCompositionCharacterBounds(&character_bounds);
1614
1615 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1616 return;
1617 composition_character_bounds_ = character_bounds;
1618 composition_range_ = range;
1619 Send(new InputHostMsg_ImeCompositionRangeChanged(
1620 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311621}
1622
oshimaf866dab2015-12-05 00:41:541623void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1624 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181625 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331626 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541627 // anchor element can be placed at half pixel.
1628 gfx::Rect window_rect =
1629 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1630 rect->x = window_rect.x();
1631 rect->y = window_rect.y();
1632 rect->width = window_rect.width();
1633 rect->height = window_rect.height();
1634 }
1635}
1636
oshimaa6985b62016-01-27 08:58:301637void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1638 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181639 rect->x *= GetOriginalDeviceScaleFactor();
1640 rect->y *= GetOriginalDeviceScaleFactor();
1641 rect->width *= GetOriginalDeviceScaleFactor();
1642 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301643 }
1644}
1645
[email protected]adb362312014-06-28 06:04:241646void RenderWidget::OnShowImeIfNeeded() {
1647#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311648 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241649#endif
rouslanf7ebd8832015-01-22 01:54:141650
1651// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1652// virtual keyboard.
1653#if !defined(OS_ANDROID)
1654 FocusChangeComplete();
1655#endif
[email protected]adb362312014-06-28 06:04:241656}
1657
1658#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371659void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1660 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131661}
1662
1663void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371664 DCHECK_GE(text_input_info_history_.size(), 1u);
1665 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511666}
changwan8c342742016-02-26 00:53:391667
1668void RenderWidget::OnRequestTextInputStateUpdate() {
1669 DCHECK(!ime_event_guard_);
1670 UpdateSelectionBounds();
1671 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1672}
[email protected]105dffb42013-02-20 03:46:211673#endif
1674
[email protected]0d1ebed12013-08-05 22:01:131675bool RenderWidget::ShouldHandleImeEvent() {
1676#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371677 if (!webwidget_)
1678 return false;
changwan8c342742016-02-26 00:53:391679 if (IsUsingImeThread())
1680 return true;
changwan3a841162015-08-11 02:53:371681
1682 // We cannot handle IME events if there is any chance that the event we are
1683 // receiving here from the browser is based on the state that is different
1684 // from our current one as indicated by |text_input_info_|.
1685 // The states the browser might be in are:
1686 // text_input_info_history_[0] - current state ack'd by browser
1687 // text_input_info_history_[1...N] - pending state changes
1688 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1689 if (text_input_info_history_[i] != text_input_info_)
1690 return false;
1691 }
1692 return true;
[email protected]0d1ebed12013-08-05 22:01:131693#else
1694 return !!webwidget_;
1695#endif
1696}
1697
[email protected]468ac582012-11-20 00:53:191698void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1699 if (device_scale_factor_ == device_scale_factor)
1700 return;
1701
1702 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331703
1704 OnDeviceScaleFactorChanged();
1705
jdduke491a3f0c2015-06-15 23:30:261706 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191707}
1708
[email protected]28ed6b32014-06-08 02:16:271709bool RenderWidget::SetDeviceColorProfile(
1710 const std::vector<char>& color_profile) {
1711 if (device_color_profile_ == color_profile)
1712 return false;
1713
1714 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271715
avi40b5be7a2016-03-03 21:13:441716 if (owner_delegate_)
1717 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1718
1719 return true;
noeldb4df152014-09-16 17:45:201720}
1721
[email protected]fcdc5642014-05-09 14:32:241722void RenderWidget::OnOrientationChange() {
1723}
1724
avib9dbd972016-03-08 18:19:321725void RenderWidget::DidInitiatePaint() {
1726 if (owner_delegate_)
1727 owner_delegate_->RenderWidgetDidCommitAndDrawCompositorFrame();
1728}
1729
1730void RenderWidget::DidFlushPaint() {
1731 if (owner_delegate_)
1732 owner_delegate_->RenderWidgetDidFlushPaint();
1733}
1734
[email protected]bee16aab2009-08-26 15:55:031735void RenderWidget::SetHidden(bool hidden) {
1736 if (is_hidden_ == hidden)
1737 return;
1738
jdduke8fac9d102014-12-20 02:40:131739 // The status has changed. Tell the RenderThread about it and ensure
1740 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031741 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391742 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131743
[email protected]bee16aab2009-08-26 15:55:031744 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001745 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031746 else
[email protected]b2db9272014-01-10 17:42:001747 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111748
1749 if (render_widget_scheduling_state_)
1750 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031751}
1752
[email protected]2b624c562011-10-27 22:58:261753void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261754 if (!webwidget_)
1755 return;
1756
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121757 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261758 webwidget_->didEnterFullScreen();
1759 } else {
1760 webwidget_->didExitFullScreen();
1761 }
[email protected]2b624c562011-10-27 22:58:261762}
1763
[email protected]674741932009-02-04 23:44:461764bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051765 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461766}
1767
[email protected]674741932009-02-04 23:44:461768void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051769 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461770}
1771
[email protected]674741932009-02-04 23:44:461772void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051773 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461774}
1775
changwan8c342742016-02-26 00:53:391776bool RenderWidget::IsUsingImeThread() {
1777#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121778 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391779#else
1780 return false;
1781#endif
1782}
1783
changwanf2a707b2015-10-30 08:22:161784void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1785 if (!ime_event_guard_)
1786 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291787}
1788
changwanf2a707b2015-10-30 08:22:161789void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1790 if (ime_event_guard_ != guard) {
1791#if defined(OS_ANDROID)
1792 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1793 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391794 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161795 // Therefore, we want to mark this text state update as 'from IME' only
1796 // when all the nested events are all originating from IME.
1797 ime_event_guard_->set_from_ime(
1798 ime_event_guard_->from_ime() && guard->from_ime());
1799#endif
1800 return;
1801 }
1802 ime_event_guard_ = nullptr;
1803
[email protected]66fca5bc2013-05-23 06:58:291804 // While handling an ime event, text input state and selection bounds updates
1805 // are ignored. These must explicitly be updated once finished handling the
1806 // ime event.
1807 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471808#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161809 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311810 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1811 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471812#endif
[email protected]66fca5bc2013-05-23 06:58:291813}
1814
[email protected]7c8873e2013-02-05 08:03:011815void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1816 WebRect focus_webrect;
1817 WebRect anchor_webrect;
1818 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241819 convertViewportToWindow(&focus_webrect);
1820 convertViewportToWindow(&anchor_webrect);
1821 *focus = focus_webrect;
1822 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321823}
1824
[email protected]e99ef6f2011-10-16 01:13:001825void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081826 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001827 if (!webwidget_)
1828 return;
changwanf2a707b2015-10-30 08:22:161829 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291830 return;
[email protected]e99ef6f2011-10-16 01:13:001831
mohsenb0eeba72015-08-09 06:20:081832#if defined(USE_AURA)
1833 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1834 // Aura beucause composited selection updates are not working for webview tags
1835 // which regresses IME inside webview. Remove this when composited selection
1836 // updates are fixed for webviews. See, http://crbug.com/510568.
1837 bool send_ipc = true;
1838#else
jddukeacf809e2014-09-23 20:38:381839 // With composited selection updates, the selection bounds will be reported
1840 // directly by the compositor, in which case explicit IPC selection
1841 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081842 bool send_ipc =
1843 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1844#endif
1845 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381846 ViewHostMsg_SelectionBounds_Params params;
1847 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1848 if (selection_anchor_rect_ != params.anchor_rect ||
1849 selection_focus_rect_ != params.focus_rect) {
1850 selection_anchor_rect_ = params.anchor_rect;
1851 selection_focus_rect_ = params.focus_rect;
1852 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1853 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1854 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1855 }
[email protected]58b48a0d2012-06-13 07:01:351856 }
jddukeacf809e2014-09-23 20:38:381857
[email protected]88dbe32f2013-06-20 23:31:361858 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001859}
1860
avi40b5be7a2016-03-03 21:13:441861void RenderWidget::SetDeviceColorProfileForTesting(
1862 const std::vector<char>& color_profile) {
1863 SetDeviceColorProfile(color_profile);
1864}
1865
1866void RenderWidget::ResetDeviceColorProfileForTesting() {
1867 std::vector<char> color_profile;
1868 color_profile.push_back('0');
1869 SetDeviceColorProfile(color_profile);
1870}
1871
[email protected]180ef242013-11-07 06:50:461872// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371873STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1874STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1875STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1876 ui::TEXT_INPUT_TYPE_PASSWORD);
1877STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1878STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1879STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1880STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1881 ui::TEXT_INPUT_TYPE_TELEPHONE);
1882STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1883STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1884STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1885 ui::TEXT_INPUT_TYPE_DATE_TIME);
1886STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1887 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1888STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1889STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1890STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1891STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1892 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1893STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1894 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1895STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1896 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451897
[email protected]5b739cb2012-08-21 20:35:211898ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461899 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211900 // Check the type is in the range representable by ui::TextInputType.
1901 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461902 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211903 return static_cast<ui::TextInputType>(type);
1904}
1905
[email protected]58b48a0d2012-06-13 07:01:351906void RenderWidget::GetCompositionCharacterBounds(
1907 std::vector<gfx::Rect>* bounds) {
1908 DCHECK(bounds);
1909 bounds->clear();
1910}
1911
[email protected]db4fc1e2013-09-06 20:01:511912void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:361913 size_t location, length;
1914 if (webwidget_->compositionRange(&location, &length)) {
1915 range->set_start(location);
1916 range->set_end(location + length);
1917 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1918 range->set_start(location);
1919 range->set_end(location + length);
1920 } else {
[email protected]db4fc1e2013-09-06 20:01:511921 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:361922 }
1923}
1924
[email protected]501ea13d2013-07-09 17:03:291925bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511926 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291927 const std::vector<gfx::Rect>& bounds) {
1928 if (composition_range_ != range)
1929 return true;
1930 if (bounds.size() != composition_character_bounds_.size())
1931 return true;
1932 for (size_t i = 0; i < bounds.size(); ++i) {
1933 if (bounds[i] != composition_character_bounds_[i])
1934 return true;
1935 }
1936 return false;
1937}
[email protected]501ea13d2013-07-09 17:03:291938
[email protected]ad26ef42011-06-17 07:59:451939bool RenderWidget::CanComposeInline() {
1940 return true;
[email protected]56ea1a62011-05-30 07:05:571941}
1942
[email protected]4873c7d2009-07-16 06:36:281943WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:041944 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:281945}
1946
[email protected]fa7b1dc2010-06-23 17:53:041947void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:021948 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:041949 // If the last text input type is not None, then we should finish any
1950 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:451951 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:041952 // If a composition text exists, then we need to let the browser process
1953 // to cancel the input method's ongoing composition session.
1954 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:221955 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:041956 }
[email protected]d4cff272011-05-02 15:46:011957
[email protected]88dbe32f2013-06-20 23:31:361958 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041959}
1960
donnda070f3c2015-01-16 19:54:111961#if defined(OS_ANDROID)
1962void RenderWidget::showUnhandledTapUIIfNeeded(
1963 const WebPoint& tapped_position,
1964 const WebNode& tapped_node,
1965 bool page_changed) {
fsamuele8326c742016-01-12 00:49:391966 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:111967 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:371968 !tapped_node.isContentEditable() &&
1969 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:111970 if (should_trigger) {
1971 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
1972 tapped_position.x, tapped_position.y));
1973 }
1974}
1975#endif
1976
[email protected]c68c3e4e2013-01-24 00:36:561977void RenderWidget::didHandleGestureEvent(
1978 const WebGestureEvent& event,
1979 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:021980#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:561981 if (event_cancelled)
1982 return;
[email protected]07c70d22014-08-21 08:33:461983 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:311984 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461985 } else if (event.type == WebInputEvent::GestureLongPress) {
1986 DCHECK(webwidget_);
1987 if (webwidget_->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:311988 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:461989 else
fsamuel72464894f2015-12-15 06:59:311990 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:561991 }
1992#endif
1993}
1994
sataya.m582c9ce2015-06-09 08:03:421995void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:311996 const blink::WebFloatSize& overscrollDelta,
1997 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:421998 const blink::WebFloatPoint& position,
1999 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482000#if defined(OS_MACOSX)
2001 // On OSX the user can disable the elastic overscroll effect. If that's the
2002 // case, don't forward the overscroll notification.
2003 DCHECK(compositor_deps());
2004 if (!compositor_deps()->IsElasticOverscrollEnabled())
2005 return;
2006#endif
bokane53a10f2016-04-13 23:48:312007 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392008 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422009}
2010
[email protected]7912e822014-04-16 02:37:032011void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392012 if (!is_hidden())
2013 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032014}
2015
[email protected]24ed0432013-04-24 07:50:312016RenderWidgetCompositor* RenderWidget::compositor() const {
2017 return compositor_.get();
2018}
2019
fsamuel72464894f2015-12-15 06:59:312020void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392021 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372022}
[email protected]c3d45532011-10-07 19:20:402023
fsamuel72464894f2015-12-15 06:59:312024bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392025 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242026}
2027
fsamuel72464894f2015-12-15 06:59:312028void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392029 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312030}
2031
[email protected]ce6689f2013-03-29 12:52:552032void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112033 if (render_widget_scheduling_state_)
2034 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552035 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2036}
2037
danakj365175c2016-02-06 00:37:372038// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2039STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2040STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2041STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2042STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2043STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2044STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2045STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2046STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2047STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2048STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2049 TOUCH_ACTION_MANIPULATION);
2050STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2051 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2052STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172053
[email protected]5d0bbdfa92013-12-10 00:35:512054void RenderWidget::setTouchAction(
2055 blink::WebTouchAction web_touch_action) {
2056
2057 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2058 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392059 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512060 return;
2061
[email protected]a18f67a2013-12-20 19:44:362062 content::TouchAction content_touch_action =
2063 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512064 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2065}
2066
[email protected]90f24152014-04-09 12:41:362067void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2068#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392069 if (!IsUsingImeThread())
2070 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362071#endif
2072}
2073
[email protected]e3244ed2014-06-20 20:04:272074void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2075 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162076}
2077
[email protected]e3244ed2014-06-20 20:04:272078void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2079 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162080}
2081
[email protected]de3c5d82014-05-28 22:12:592082void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2083 render_frames_.AddObserver(frame);
2084}
2085
2086void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2087 render_frames_.RemoveObserver(frame);
2088}
2089
[email protected]a017938b2014-05-27 21:17:172090#if defined(VIDEO_HOLE)
2091void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2092 video_hole_frames_.AddObserver(frame);
2093}
2094
2095void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2096 video_hole_frames_.RemoveObserver(frame);
2097}
2098#endif // defined(VIDEO_HOLE)
2099
lfg43e08e62016-02-03 18:51:372100void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2101 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2102 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2103}
2104
oshima50872a72016-03-04 13:26:182105float RenderWidget::GetOriginalDeviceScaleFactor() const {
2106 return
2107 screen_metrics_emulator_ ?
2108 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2109 device_scale_factor_;
2110}
2111
[email protected]e9ff79c2012-10-19 21:31:262112} // namespace content