blob: ad847c86a3ddd8b1054489ea31f3c3c236bdabe6 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
dchengcedca5612016-04-09 01:40:157#include <memory>
dcheng07945f632015-12-26 07:59:328#include <utility>
9
[email protected]c27dd4f2014-05-22 18:05:1910#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:2111#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:0012#include "base/command_line.h"
changwan7ded3752016-03-09 23:25:1213#include "base/feature_list.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
avi1023d012015-12-25 02:39:1415#include "base/macros.h"
dchengcedca5612016-04-09 01:40:1516#include "base/memory/ptr_util.h"
[email protected]b256eca2013-07-11 10:57:4017#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3018#include "base/message_loop/message_loop.h"
asvitkine8d51e9d2016-09-02 23:55:4319#include "base/metrics/histogram_macros.h"
[email protected]aa4117f2011-12-09 22:19:2120#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0021#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2722#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0123#include "base/trace_event/trace_event.h"
24#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4825#include "build/build_config.h"
danakj1120f4c2016-09-15 02:05:3226#include "cc/output/compositor_frame_sink.h"
jbroman6ccbc7d472016-07-27 04:45:4127#include "cc/output/copy_output_request.h"
fsamuel78f86e42016-01-20 04:10:2328#include "cc/scheduler/begin_frame_source.h"
oshima750cb4342015-10-31 00:59:0129#include "content/common/content_switches_internal.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]c084330e02013-04-27 01:08:1531#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1532#include "content/common/swapped_out_messages.h"
ekaramad9053e57b2016-04-26 20:00:3833#include "content/common/text_input_state.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
changwan7ded3752016-03-09 23:25:1235#include "content/public/common/content_features.h"
[email protected]c08950d22011-10-13 22:20:2936#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4237#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4038#include "content/renderer/cursor_utils.h"
mfomitchev2600fd7c2016-02-17 20:53:3939#include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
[email protected]b2e4c70132013-10-03 02:07:5140#include "content/renderer/external_popup_menu.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]586871b2014-07-22 17:05:1142#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2843#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2944#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1345#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3246#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1647#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2748#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0549#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4450#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5551#include "content/renderer/render_view_impl.h"
avi40b5be7a2016-03-03 21:13:4452#include "content/renderer/render_widget_owner_delegate.h"
tfarina556a7232014-10-05 01:02:0953#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0454#include "content/renderer/resizing_mode_selector.h"
ekaramad330ba4232016-09-23 17:57:4755#include "ipc/ipc_message_start.h"
[email protected]484955942010-08-19 16:13:1856#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4857#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1858#include "third_party/WebKit/public/platform/WebCursorInfo.h"
donnda070f3c2015-01-16 19:54:1159#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
skyostil529caa292016-08-10 17:44:5163#include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h"
64#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
[email protected]19193682014-04-03 15:01:4365#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5966#include "third_party/WebKit/public/web/WebFrameWidget.h"
67#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1168#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3169#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3170#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
71#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3872#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5973#include "third_party/WebKit/public/web/WebView.h"
lfge0c2792ec2016-05-11 18:52:0874#include "third_party/WebKit/public/web/WebWidget.h"
[email protected]d353541f2012-05-03 22:45:4175#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1376#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5077#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0978#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3279#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4880#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2781#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4883
[email protected]eeb93112013-05-01 19:41:1084#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1585#include <android/keycodes.h>
[email protected]eeb93112013-05-01 19:41:1086#endif
87
[email protected]661eb9d2009-02-03 02:11:4888#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4989#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5290#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4191#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4892#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4493
sadrul943e3b32016-08-04 18:22:5994#if defined(USE_AURA)
bend32292b2016-10-07 00:21:5895#include "content/public/common/service_manager_connection.h"
fsamuel2545ecc2015-12-05 00:44:4696#include "content/renderer/mus/render_widget_mus_connection.h"
penghuang28a5fa22015-12-02 17:58:1997#endif
98
ekaramad330ba4232016-09-23 17:57:4799#if defined(OS_MACOSX)
100#include "content/renderer/text_input_client_observer.h"
101#endif
102
[email protected]180ef242013-11-07 06:50:46103using blink::WebCompositionUnderline;
104using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:43105using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46106using blink::WebGestureEvent;
107using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:49108using blink::WebInputEventResult;
[email protected]180ef242013-11-07 06:50:46109using blink::WebKeyboardEvent;
110using blink::WebMouseEvent;
111using blink::WebMouseWheelEvent;
112using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11113using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46114using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11115using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46116using blink::WebPopupType;
dglazkove353a372016-09-01 01:33:48117using blink::WebRange;
[email protected]180ef242013-11-07 06:50:46118using blink::WebRect;
[email protected]180ef242013-11-07 06:50:46119using blink::WebSize;
120using blink::WebTextDirection;
121using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25122using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46123using blink::WebVector;
124using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26125
danakj365175c2016-02-06 00:37:37126#define STATIC_ASSERT_ENUM(a, b) \
127 static_assert(static_cast<int>(a) == static_cast<int>(b), \
128 "mismatching enums: " #a)
129
[email protected]6a4d7f62013-01-07 21:32:13130namespace {
[email protected]b256eca2013-07-11 10:57:40131
132typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
133
lfgbee1e0a2016-06-08 21:24:21134class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget {
135 public:
136 explicit WebWidgetLockTarget(blink::WebWidget* webwidget)
137 : webwidget_(webwidget) {}
138
139 void OnLockMouseACK(bool succeeded) override {
140 if (succeeded)
141 webwidget_->didAcquirePointerLock();
142 else
143 webwidget_->didNotAcquirePointerLock();
144 }
145
146 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); }
147
148 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override {
149 // The WebWidget handles mouse lock in Blink's handleInputEvent().
150 return false;
151 }
152
153 private:
154 blink::WebWidget* webwidget_;
155};
156
[email protected]b256eca2013-07-11 10:57:40157class TextInputModeMapSingleton {
158 public:
159 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22160 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40161 }
[email protected]dd705d4d2013-11-27 08:14:41162 TextInputModeMapSingleton() {
163 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
164 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
165 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
166 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
167 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
168 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
169 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
170 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
171 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
172 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
173 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40174 }
[email protected]dd705d4d2013-11-27 08:14:41175 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40176 private:
[email protected]dd705d4d2013-11-27 08:14:41177 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40178
olli.raula36aa8be2015-09-10 11:14:22179 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40180
181 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
182};
183
[email protected]dd705d4d2013-11-27 08:14:41184ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40185 static TextInputModeMapSingleton* singleton =
186 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41187 TextInputModeMap::const_iterator it =
188 singleton->map().find(input_mode.utf8());
189 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40190 return ui::TEXT_INPUT_MODE_DEFAULT;
191 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13192}
[email protected]b256eca2013-07-11 10:57:40193
fsamuele8326c742016-01-12 00:49:39194content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate(
195 content::RenderWidget* widget) {
sadrul943e3b32016-08-04 18:22:59196#if defined(USE_AURA)
penghuang639a1042016-01-14 21:25:29197 const base::CommandLine& cmdline = *base::CommandLine::ForCurrentProcess();
bend32292b2016-10-07 00:21:58198 if (content::ServiceManagerConnection::GetForProcess() &&
penghuang639a1042016-01-14 21:25:29199 cmdline.HasSwitch(switches::kUseMusInRenderer)) {
fsamuele8326c742016-01-12 00:49:39200 return content::RenderWidgetMusConnection::GetOrCreate(
201 widget->routing_id());
202 }
203#endif
bend32292b2016-10-07 00:21:58204 // If we don't have a connection to the Service Manager, then we want to route
205 // IPCs back to the browser process rather than Mus so we use the |widget| as
206 // the RenderWidgetInputHandlerDelegate.
fsamuele8326c742016-01-12 00:49:39207 return widget;
208}
209
lfg1568d112016-08-30 16:06:29210content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget =
211 nullptr;
212
213content::RenderWidget::RenderWidgetInitializedCallback
214 g_render_widget_initialized = nullptr;
215
[email protected]b256eca2013-07-11 10:57:40216} // namespace
217
[email protected]e9ff79c2012-10-19 21:31:26218namespace content {
[email protected]62cb33cae2009-03-27 23:30:22219
[email protected]b2e4c70132013-10-03 02:07:51220// RenderWidget ---------------------------------------------------------------
221
dcheng35d31c112015-07-22 00:17:36222RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
223 blink::WebPopupType popup_type,
ccameron2f451532016-09-07 21:49:27224 const ScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04225 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03226 bool hidden,
227 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29228 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36229 compositor_deps_(compositor_deps),
lfg8ff33912016-09-13 20:59:21230 webwidget_internal_(nullptr),
avi40b5be7a2016-03-03 21:13:44231 owner_delegate_(nullptr),
initial.commit09911bf2008-07-26 23:55:29232 opener_id_(MSG_ROUTING_NONE),
initial.commit09911bf2008-07-26 23:55:29233 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51234 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09235 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29236 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04237 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39238 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12239 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12240 display_mode_(blink::WebDisplayModeUndefined),
changwanf2a707b2015-10-30 08:22:16241 ime_event_guard_(nullptr),
changwan46620072016-09-21 03:05:41242 ime_in_batch_edit_(false),
[email protected]661eb9d2009-02-03 02:11:48243 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22244 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44245 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20246 for_oopif_(false),
[email protected]b256eca2013-07-11 10:57:40247 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20248 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53249 can_compose_inline_(true),
nonafa291792016-08-10 02:36:18250 composition_range_(gfx::Range::InvalidRange()),
[email protected]3e2b375b2010-04-07 17:03:12251 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48252 pending_window_rect_count_(0),
[email protected]842f10652012-06-06 01:54:04253 screen_info_(screen_info),
ccameron2f451532016-09-07 21:49:27254 device_scale_factor_(screen_info_.device_scale_factor),
[email protected]0d1ebed12013-08-05 22:01:13255#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36256 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13257#endif
nonafa291792016-08-10 02:36:18258 monitor_composition_info_(false),
[email protected]b2e4c70132013-10-03 02:07:51259 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11260 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42261 resizing_mode_selector_(new ResizingModeSelector()),
lfge0c2792ec2016-05-11 18:52:08262 has_host_context_menu_location_(false),
ekaramad2a46d632016-07-19 13:33:09263 has_focus_(false),
ekaramad330ba4232016-09-23 17:57:47264#if defined(OS_MACOSX)
265 text_input_client_observer_(new TextInputClientObserver(this)),
266#endif
ekaramad2a46d632016-07-19 13:33:09267 focused_pepper_plugin_(nullptr) {
[email protected]8b3f0eb2012-05-03 19:15:05268 if (!swapped_out)
269 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27270 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53271 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37272#if defined(OS_ANDROID)
273 text_input_info_history_.push_back(blink::WebTextInputInfo());
274#endif
alexclarke7fa93942015-10-21 15:37:11275
276 // In tests there may not be a RenderThreadImpl.
277 if (RenderThreadImpl::current()) {
278 render_widget_scheduling_state_ = RenderThreadImpl::current()
279 ->GetRendererScheduler()
dcheng07945f632015-12-26 07:59:32280 ->NewRenderWidgetSchedulingState();
alexclarke7fa93942015-10-21 15:37:11281 render_widget_scheduling_state_->SetHidden(is_hidden_);
282 }
initial.commit09911bf2008-07-26 23:55:29283}
284
285RenderWidget::~RenderWidget() {
lfg8ff33912016-09-13 20:59:21286 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16287
[email protected]992db4c2011-05-12 15:37:15288 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02289 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15290 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29291}
292
[email protected]484955942010-08-19 16:13:18293// static
lfg1568d112016-08-30 16:06:29294void RenderWidget::InstallCreateHook(
295 CreateRenderWidgetFunction create_render_widget,
296 RenderWidgetInitializedCallback render_widget_initialized) {
297 CHECK(!g_create_render_widget && !g_render_widget_initialized);
298 g_create_render_widget = create_render_widget;
299 g_render_widget_initialized = render_widget_initialized;
300}
301
302// 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,
ccameron2f451532016-09-07 21:49:27306 const ScreenInfo& 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,
ccameron2f451532016-09-07 21:49:27320 const ScreenInfo& screen_info,
kenrba7199832015-01-22 23:44:59321 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(
lfg1568d112016-08-30 16:06:29334 g_create_render_widget
335 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone,
336 screen_info, false, hidden, false)
337 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone,
338 screen_info, false, hidden, false));
fsamuele8326c742016-01-12 00:49:39339 widget->SetRoutingID(routing_id);
simonhong628f9812015-04-27 23:13:20340 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59341 // DoInit increments the reference count on |widget|, keeping it alive after
342 // this function returns.
dcheng35d31c112015-07-22 00:17:36343 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59344 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
345 nullptr)) {
lfg1568d112016-08-30 16:06:29346 if (g_render_widget_initialized)
347 g_render_widget_initialized(widget.get());
kenrba7199832015-01-22 23:44:59348 return widget.get();
349 }
350 return nullptr;
351}
352
353// static
lfgcaab5142016-02-26 19:06:52354blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
dchengda9b4bb2015-07-20 20:58:08355 RenderWidget* render_widget,
356 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55357 if (!frame->parent()) {
358 // TODO(dcheng): The main frame widget currently has a special case.
359 // Eliminate this once WebView is no longer a WebWidget.
360 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
361 }
dchengda9b4bb2015-07-20 20:58:08362 return blink::WebFrameWidget::create(render_widget, frame);
363}
364
365// static
kenrba7199832015-01-22 23:44:59366blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18367 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46368 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18369 break;
[email protected]180ef242013-11-07 06:50:46370 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44371 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18372 default:
373 NOTREACHED();
374 }
375 return NULL;
376}
377
dchengda9b4bb2015-07-20 20:58:08378void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32379 OnClose();
kenrba7199832015-01-22 23:44:59380}
381
fsamuele8326c742016-01-12 00:49:39382void RenderWidget::SetRoutingID(int32_t routing_id) {
383 routing_id_ = routing_id;
384 input_handler_.reset(new RenderWidgetInputHandler(
385 GetRenderWidgetInputHandlerDelegate(this), this));
386}
387
alexmos78c9c0d2016-10-14 18:57:03388void RenderWidget::SetSwappedOut(bool is_swapped_out) {
389 // We should only toggle between states.
390 DCHECK(is_swapped_out_ != is_swapped_out);
391 is_swapped_out_ = is_swapped_out;
392
393 // If we are swapping out, we will call ReleaseProcess, allowing the process
394 // to exit if all of its RenderViews are swapped out. We wait until the
395 // WasSwappedOut call to do this, to allow the unload handler to finish.
396 // If we are swapping in, we call AddRefProcess to prevent the process from
397 // exiting.
398 if (!is_swapped_out_)
399 RenderProcess::current()->AddRefProcess();
400}
401
avi1023d012015-12-25 02:39:14402bool RenderWidget::Init(int32_t opener_id) {
fsamuele8326c742016-01-12 00:49:39403 bool success = DoInit(
piman5d36dae2015-09-24 22:47:05404 opener_id, RenderWidget::CreateWebWidget(this),
405 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
fsamuele8326c742016-01-12 00:49:39406 if (success) {
407 SetRoutingID(routing_id_);
408 return true;
409 }
410 return false;
[email protected]484955942010-08-19 16:13:18411}
412
avi1023d012015-12-25 02:39:14413bool RenderWidget::DoInit(int32_t opener_id,
[email protected]6a8ddba52010-09-05 04:38:06414 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18415 IPC::SyncMessage* create_widget_message) {
lfg8ff33912016-09-13 20:59:21416 DCHECK(!webwidget_internal_);
initial.commit09911bf2008-07-26 23:55:29417
418 if (opener_id != MSG_ROUTING_NONE)
419 opener_id_ = opener_id;
420
lfg8ff33912016-09-13 20:59:21421 webwidget_internal_ = web_widget;
422 webwidget_mouse_lock_target_.reset(
423 new WebWidgetLockTarget(webwidget_internal_));
lfgbee1e0a2016-06-08 21:24:21424 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this));
initial.commit09911bf2008-07-26 23:55:29425
kenrba7199832015-01-22 23:44:59426 bool result = true;
427 if (create_widget_message)
428 result = RenderThread::Get()->Send(create_widget_message);
429
initial.commit09911bf2008-07-26 23:55:29430 if (result) {
[email protected]380244092011-10-07 17:26:27431 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29432 // Take a reference on behalf of the RenderThread. This will be balanced
433 // when we receive ViewMsg_Close.
434 AddRef();
[email protected]b2db9272014-01-10 17:42:00435 if (RenderThreadImpl::current()) {
436 RenderThreadImpl::current()->WidgetCreated();
437 if (is_hidden_)
438 RenderThreadImpl::current()->WidgetHidden();
439 }
fsamuele8326c742016-01-12 00:49:39440
[email protected]a635f942012-12-07 10:34:29441 return true;
initial.commit09911bf2008-07-26 23:55:29442 } else {
[email protected]a635f942012-12-07 10:34:29443 // The above Send can fail when the tab is closing.
444 return false;
initial.commit09911bf2008-07-26 23:55:29445 }
446}
447
[email protected]949b6592014-08-20 13:17:52448void RenderWidget::WasSwappedOut() {
449 // If we have been swapped out and no one else is using this process,
450 // it's safe to exit now.
451 CHECK(is_swapped_out_);
452 RenderProcess::current()->ReleaseProcess();
453}
454
[email protected]b2e4c70132013-10-03 02:07:51455void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39456 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]b2e4c70132013-10-03 02:07:51457 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43458 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49459 popup_screen_origin_for_emulation_ = gfx::Point(
460 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
461 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56462 screen_info_ = emulator->original_screen_info();
ccameron2f451532016-09-07 21:49:27463 device_scale_factor_ = screen_info_.device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51464}
465
[email protected]2d6836f42014-07-02 17:25:31466gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
467 if (screen_metrics_emulator_)
468 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
469 return anchor;
470}
471
haibinluc643d33c2016-06-03 02:22:34472#if defined(USE_EXTERNAL_POPUP_MENU)
[email protected]b2e4c70132013-10-03 02:07:51473void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
mfomitchev2600fd7c2016-02-17 20:53:39474 ExternalPopupMenu* popup,
475 RenderWidgetScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49476 popup->SetOriginScaleAndOffsetForEmulation(
477 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51478}
[email protected]53907862014-03-25 15:42:40479#endif
[email protected]b2e4c70132013-10-03 02:07:51480
481void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
482 if (screen_metrics_emulator_)
483 screen_metrics_emulator_->OnShowContextMenu(params);
484}
485
[email protected]a95986a82010-12-24 06:19:28486bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
ekaramad330ba4232016-09-23 17:57:47487#if defined(OS_MACOSX)
488 if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart)
489 return text_input_client_observer_->OnMessageReceived(message);
490#endif
lfgbee1e0a2016-06-08 21:24:21491 if (mouse_lock_dispatcher_ &&
492 mouse_lock_dispatcher_->OnMessageReceived(message))
493 return true;
494
[email protected]a95986a82010-12-24 06:19:28495 bool handled = true;
496 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15497 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22498 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
499 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22500 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
aelias87b8f7c2016-09-14 03:19:29501 IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText)
502 IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText,
503 OnImeFinishComposingText)
[email protected]c084330e02013-04-27 01:08:15504 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
alexmos56567492016-09-13 00:52:46505 IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent,
506 OnSetEditCommandsForNextKeyEvent)
[email protected]c084330e02013-04-27 01:08:15507 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35508 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
509 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28510 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28511 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20512 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
513 OnEnableDeviceEmulation)
514 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
515 OnDisableDeviceEmulation)
[email protected]a95986a82010-12-24 06:19:28516 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41517 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25518 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28519 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
520 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03521 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
fsamuele0f705b2016-10-01 14:07:14522 IPC_MESSAGE_HANDLER(ViewMsg_SetFrameSinkId, OnSetFrameSinkId)
lfg43e08e62016-02-03 18:51:37523 IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests,
524 OnWaitNextFrameForTests)
nonafa291792016-08-10 02:36:18525 IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate,
526 OnRequestCompositionUpdate)
[email protected]105dffb42013-02-20 03:46:21527#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37528 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
changwan8c342742016-02-26 00:53:39529 IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate,
530 OnRequestTextInputStateUpdate)
changwan46620072016-09-21 03:05:41531 IPC_MESSAGE_HANDLER(InputMsg_ImeBatchEdit,
532 OnImeBatchEdit)
[email protected]2384b6c2013-02-28 23:58:51533 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21534#endif
dtrainor5ef644e2015-11-19 00:12:47535 IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto)
[email protected]a95986a82010-12-24 06:19:28536 IPC_MESSAGE_UNHANDLED(handled = false)
537 IPC_END_MESSAGE_MAP()
538 return handled;
539}
initial.commit09911bf2008-07-26 23:55:29540
541bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15542 // Don't send any messages after the browser has told us to close, and filter
543 // most outgoing messages while swapped out.
544 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26545 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11546 closing_) {
initial.commit09911bf2008-07-26 23:55:29547 delete message;
548 return false;
549 }
550
551 // If given a messsage without a routing ID, then assign our routing ID.
552 if (message->routing_id() == MSG_ROUTING_NONE)
553 message->set_routing_id(routing_id_);
554
[email protected]380244092011-10-07 17:26:27555 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44556}
557
bokanc007c3a2015-02-03 07:15:56558void RenderWidget::SetWindowRectSynchronously(
559 const gfx::Rect& new_window_rect) {
mfomitchev2600fd7c2016-02-17 20:53:39560 ResizeParams params;
561 params.screen_info = screen_info_;
562 params.new_size = new_window_rect.size();
563 params.physical_backing_size =
564 gfx::ScaleToCeiledSize(new_window_rect.size(), device_scale_factor_);
mfomitchev2600fd7c2016-02-17 20:53:39565 params.visible_viewport_size = new_window_rect.size();
mfomitchev2600fd7c2016-02-17 20:53:39566 params.is_fullscreen_granted = is_fullscreen_granted_;
567 params.display_mode = display_mode_;
568 params.needs_resize_ack = false;
569 Resize(params);
570
bokanc007c3a2015-02-03 07:15:56571 view_screen_rect_ = new_window_rect;
572 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02573 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56574 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02575}
576
initial.commit09911bf2008-07-26 23:55:29577void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32578 DCHECK(content::RenderThread::Get());
579 if (closing_)
580 return;
581 NotifyOnClose();
582 closing_ = true;
583
584 // Browser correspondence is no longer needed at this point.
585 if (routing_id_ != MSG_ROUTING_NONE) {
586 RenderThread::Get()->RemoveRoute(routing_id_);
587 SetHidden(false);
588 if (RenderThreadImpl::current())
589 RenderThreadImpl::current()->WidgetDestroyed();
590 }
591
592 if (for_oopif_) {
593 // Widgets for frames may be created and closed at any time while the frame
594 // is alive. However, the closing process must happen synchronously. Frame
595 // widget and frames hold pointers to each other. If Close() is deferred to
596 // the message loop like in the non-frame widget case, WebWidget::close()
597 // can end up accessing members of an already-deleted frame.
598 Close();
599 } else {
600 // If there is a Send call on the stack, then it could be dangerous to close
601 // now. Post a task that only gets invoked when there are no nested message
602 // loops.
603 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
604 FROM_HERE, base::Bind(&RenderWidget::Close, this));
605 }
606
607 // Balances the AddRef taken when we called AddRoute.
608 Release();
initial.commit09911bf2008-07-26 23:55:29609}
610
fsamuel664e8b62016-01-20 19:54:01611void RenderWidget::OnResize(const ResizeParams& params) {
[email protected]5b45ad42013-10-25 00:42:04612 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32613 return;
614
[email protected]b2e4c70132013-10-03 02:07:51615 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:39616 screen_metrics_emulator_->OnResize(params);
[email protected]b2e4c70132013-10-03 02:07:51617 return;
618 }
619
mfomitchev2600fd7c2016-02-17 20:53:39620 Resize(params);
initial.commit09911bf2008-07-26 23:55:29621}
622
dgozman9260b0a12015-03-16 13:45:20623void RenderWidget::OnEnableDeviceEmulation(
624 const blink::WebDeviceEmulationParams& params) {
mfomitchev2600fd7c2016-02-17 20:53:39625 if (!screen_metrics_emulator_) {
626 ResizeParams resize_params;
627 resize_params.screen_info = screen_info_;
628 resize_params.new_size = size_;
629 resize_params.physical_backing_size = physical_backing_size_;
630 resize_params.visible_viewport_size = visible_viewport_size_;
mfomitchev2600fd7c2016-02-17 20:53:39631 resize_params.is_fullscreen_granted = is_fullscreen_granted_;
632 resize_params.display_mode = display_mode_;
633 screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator(
634 this, params, resize_params, view_screen_rect_, window_screen_rect_));
oshima50872a72016-03-04 13:26:18635 screen_metrics_emulator_->Apply();
mfomitchev2600fd7c2016-02-17 20:53:39636 } else {
dgozman9260b0a12015-03-16 13:45:20637 screen_metrics_emulator_->ChangeEmulationParams(params);
mfomitchev2600fd7c2016-02-17 20:53:39638 }
dgozman9260b0a12015-03-16 13:45:20639}
640
641void RenderWidget::OnDisableDeviceEmulation() {
642 screen_metrics_emulator_.reset();
643}
644
initial.commit09911bf2008-07-26 23:55:29645void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31646 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29647 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03648 SetHidden(true);
ericwilligers88e69742016-10-17 19:29:55649 for (auto& observer : render_frames_)
650 observer.WasHidden();
initial.commit09911bf2008-07-26 23:55:29651}
652
[email protected]3399dd822014-08-09 11:14:24653void RenderWidget::OnWasShown(bool needs_repainting,
654 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41655 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29656 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:21657 if (!GetWebWidget())
initial.commit09911bf2008-07-26 23:55:29658 return;
659
660 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03661 SetHidden(false);
ericwilligers88e69742016-10-17 19:29:55662 for (auto& observer : render_frames_)
663 observer.WasShown();
initial.commit09911bf2008-07-26 23:55:29664
[email protected]8a23afb32014-04-30 22:40:23665 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29666 return;
initial.commit09911bf2008-07-26 23:55:29667
668 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24669 if (compositor_) {
670 ui::LatencyInfo swap_latency_info(latency_info);
dchengcedca5612016-04-09 01:40:15671 std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
[email protected]3399dd822014-08-09 11:14:24672 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05673 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24674 }
jdduke491a3f0c2015-06-15 23:30:26675 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29676}
677
[email protected]53d3f302009-12-21 04:42:05678void RenderWidget::OnRequestMoveAck() {
679 DCHECK(pending_window_rect_count_);
680 pending_window_rect_count_--;
[email protected]53d3f302009-12-21 04:42:05681}
682
[email protected]ed7defa2013-03-12 21:29:59683GURL RenderWidget::GetURLForGraphicsContext3D() {
684 return GURL();
[email protected]65225772011-05-12 21:10:24685}
686
fsamuel78f86e42016-01-20 04:10:23687void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
dtapuska0bd451a2016-02-18 17:08:10688 const ui::LatencyInfo& latency_info,
689 InputEventDispatchType dispatch_type) {
fsamuel78f86e42016-01-20 04:10:23690 if (!input_event)
691 return;
dtapuska0bd451a2016-02-18 17:08:10692 input_handler_->HandleInputEvent(*input_event, latency_info, dispatch_type);
fsamuel78f86e42016-01-20 04:10:23693}
694
695void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
lfg8ff33912016-09-13 20:59:21696 if (GetWebWidget())
697 GetWebWidget()->setCursorVisibilityState(is_visible);
fsamuel78f86e42016-01-20 04:10:23698}
699
700void RenderWidget::OnMouseCaptureLost() {
lfg8ff33912016-09-13 20:59:21701 if (GetWebWidget())
702 GetWebWidget()->mouseCaptureLost();
fsamuel78f86e42016-01-20 04:10:23703}
704
alexmos56567492016-09-13 00:52:46705void RenderWidget::OnSetEditCommandsForNextKeyEvent(
706 const EditCommands& edit_commands) {
707 edit_commands_ = edit_commands;
708}
709
fsamuel78f86e42016-01-20 04:10:23710void RenderWidget::OnSetFocus(bool enable) {
lfge0c2792ec2016-05-11 18:52:08711 has_focus_ = enable;
712
lfg8ff33912016-09-13 20:59:21713 if (GetWebWidget())
714 GetWebWidget()->setFocus(enable);
lfge0c2792ec2016-05-11 18:52:08715
ericwilligers88e69742016-10-17 19:29:55716 for (auto& observer : render_frames_)
717 observer.RenderWidgetSetFocus(enable);
fsamuel78f86e42016-01-20 04:10:23718}
719
dtapuska3d5624d32016-08-30 04:34:00720void RenderWidget::SetNeedsMainFrame() {
721 RenderWidgetCompositor* rwc = compositor();
722 if (!rwc)
723 return;
724 rwc->setNeedsBeginFrame();
725}
726
fsamuel78f86e42016-01-20 04:10:23727///////////////////////////////////////////////////////////////////////////////
728// RenderWidgetCompositorDelegate
729
730void RenderWidget::ApplyViewportDeltas(
731 const gfx::Vector2dF& inner_delta,
732 const gfx::Vector2dF& outer_delta,
733 const gfx::Vector2dF& elastic_overscroll_delta,
734 float page_scale,
735 float top_controls_delta) {
lfg8ff33912016-09-13 20:59:21736 GetWebWidget()->applyViewportDeltas(inner_delta, outer_delta,
737 elastic_overscroll_delta, page_scale,
738 top_controls_delta);
fsamuel78f86e42016-01-20 04:10:23739}
740
741void RenderWidget::BeginMainFrame(double frame_time_sec) {
dtapuska3d5624d32016-08-30 04:34:00742 RenderThreadImpl* render_thread = RenderThreadImpl::current();
743 // render_thread may be NULL in tests.
744 InputHandlerManager* input_handler_manager =
745 render_thread ? render_thread->input_handler_manager() : NULL;
746 if (input_handler_manager)
747 input_handler_manager->ProcessRafAlignedInputOnMainThread(routing_id_);
748
lfg8ff33912016-09-13 20:59:21749 GetWebWidget()->beginFrame(frame_time_sec);
fsamuel78f86e42016-01-20 04:10:23750}
751
danakj1120f4c2016-09-15 02:05:32752std::unique_ptr<cc::CompositorFrameSink>
753RenderWidget::CreateCompositorFrameSink(bool fallback) {
lfg8ff33912016-09-13 20:59:21754 DCHECK(GetWebWidget());
[email protected]7912e822014-04-16 02:37:03755 // For widgets that are never visible, we don't start the compositor, so we
danakj1120f4c2016-09-15 02:05:32756 // never get a request for a cc::CompositorFrameSink.
sievers71c62dd52015-10-07 01:44:39757 DCHECK(!compositor_never_visible_);
danakj1120f4c2016-09-15 02:05:32758 return RenderThreadImpl::current()->CreateCompositorFrameSink(
danakj83066a32016-06-21 02:34:49759 fallback, routing_id_, frame_swap_message_queue_,
760 GetURLForGraphicsContext3D());
[email protected]ba91a792013-02-06 09:48:28761}
762
fsamuel78f86e42016-01-20 04:10:23763void RenderWidget::DidCommitAndDrawCompositorFrame() {
764 // NOTE: Tests may break if this event is renamed or moved. See
765 // tab_capture_performancetest.cc.
766 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
lfge0c2792ec2016-05-11 18:52:08767
ericwilligers88e69742016-10-17 19:29:55768 for (auto& observer : render_frames_)
769 observer.DidCommitAndDrawCompositorFrame();
lfge0c2792ec2016-05-11 18:52:08770
fsamuel78f86e42016-01-20 04:10:23771 // Notify subclasses that we initiated the paint operation.
772 DidInitiatePaint();
773}
774
775void RenderWidget::DidCommitCompositorFrame() {
ericwilligers88e69742016-10-17 19:29:55776 for (auto& observer : render_frames_)
777 observer.DidCommitCompositorFrame();
778 for (auto& observer : render_frame_proxies_)
779 observer.DidCommitCompositorFrame();
fsamuel78f86e42016-01-20 04:10:23780 input_handler_->FlushPendingInputEventAck();
781}
782
783void RenderWidget::DidCompletePageScaleAnimation() {}
784
785void RenderWidget::DidCompleteSwapBuffers() {
786 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
787
788 // Notify subclasses threaded composited rendering was flushed to the screen.
789 DidFlushPaint();
790
pimanbfb2ceb2016-03-18 21:32:58791 if (!next_paint_flags_ && !need_update_rect_for_auto_resize_) {
fsamuel78f86e42016-01-20 04:10:23792 return;
793 }
794
795 ViewHostMsg_UpdateRect_Params params;
796 params.view_size = size_;
fsamuel78f86e42016-01-20 04:10:23797 params.flags = next_paint_flags_;
798
799 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
800 next_paint_flags_ = 0;
801 need_update_rect_for_auto_resize_ = false;
802}
803
fsamuel78f86e42016-01-20 04:10:23804void RenderWidget::ForwardCompositorProto(const std::vector<uint8_t>& proto) {
805 Send(new ViewHostMsg_ForwardCompositorProto(routing_id_, proto));
806}
807
808bool RenderWidget::IsClosing() const {
809 return host_closing_;
810}
811
[email protected]4d7e46a2013-11-08 05:33:40812void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24813 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:24814 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:26815 ScheduleComposite();
[email protected]65225772011-05-12 21:10:24816}
817
[email protected]4d7e46a2013-11-08 05:33:40818void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24819 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16820
[email protected]404939f2012-06-01 04:06:18821 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16822 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:29823}
824
fsamuel78f86e42016-01-20 04:10:23825void RenderWidget::OnSwapBuffersPosted() {
826 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
initial.commit09911bf2008-07-26 23:55:29827}
828
danakj53eccbc2016-03-02 22:51:07829void RenderWidget::RequestScheduleAnimation() {
fsamuel78f86e42016-01-20 04:10:23830 scheduleAnimation();
initial.commit09911bf2008-07-26 23:55:29831}
832
fsamuel78f86e42016-01-20 04:10:23833void RenderWidget::UpdateVisualState() {
lfg8ff33912016-09-13 20:59:21834 GetWebWidget()->updateAllLifecyclePhases();
fsamuel78f86e42016-01-20 04:10:23835}
836
837void RenderWidget::WillBeginCompositorFrame() {
838 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
839
dglazkov06854c5c2016-08-31 00:19:59840 // The UpdateTextInputState can result in further layout and possibly
841 // enable GPU acceleration so they need to be called before any painting
842 // is done.
843 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
844 UpdateSelectionBounds();
845
ericwilligers88e69742016-10-17 19:29:55846 for (auto& observer : render_frame_proxies_)
847 observer.WillBeginCompositorFrame();
initial.commit09911bf2008-07-26 23:55:29848}
849
jbroman6ccbc7d472016-07-27 04:45:41850std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest(
851 std::unique_ptr<cc::CopyOutputRequest> request) {
852 return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest(
853 routing_id_, std::move(request));
854}
855
fsamuel72464894f2015-12-15 06:59:31856///////////////////////////////////////////////////////////////////////////////
857// RenderWidgetInputHandlerDelegate
858
avid7d6b2e2016-03-04 19:41:17859void RenderWidget::FocusChangeComplete() {
860 if (owner_delegate_)
861 owner_delegate_->RenderWidgetFocusChangeComplete();
862}
fsamuel72464894f2015-12-15 06:59:31863
864bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
avid7d6b2e2016-03-04 19:41:17865 if (owner_delegate_)
866 return owner_delegate_->DoesRenderWidgetHaveTouchEventHandlersAt(point);
867
fsamuel72464894f2015-12-15 06:59:31868 return true;
869}
870
dtapuska1827dd22016-03-11 15:24:59871void RenderWidget::ObserveGestureEventAndResult(
872 const blink::WebGestureEvent& gesture_event,
873 const gfx::Vector2dF& unused_delta,
874 bool event_processed) {
875 if (!compositor_deps_->IsElasticOverscrollEnabled())
876 return;
877
878 cc::InputHandlerScrollResult scroll_result;
879 scroll_result.did_scroll = event_processed;
880 scroll_result.did_overscroll_root = !unused_delta.IsZero();
881 scroll_result.unused_scroll_delta = unused_delta;
882
883 RenderThreadImpl* render_thread = RenderThreadImpl::current();
884 InputHandlerManager* input_handler_manager =
885 render_thread ? render_thread->input_handler_manager() : NULL;
886 if (input_handler_manager) {
887 input_handler_manager->ObserveGestureEventAndResultOnMainThread(
888 routing_id_, gesture_event, scroll_result);
889 }
890}
891
avid7d6b2e2016-03-04 19:41:17892void RenderWidget::OnDidHandleKeyEvent() {
alexmos56567492016-09-13 00:52:46893 ClearEditCommands();
894}
895
896void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name,
897 const std::string& value) {
898 ClearEditCommands();
899 edit_commands_.emplace_back(name, value);
900}
901
902void RenderWidget::ClearEditCommands() {
903 edit_commands_.clear();
avid7d6b2e2016-03-04 19:41:17904}
fsamuel72464894f2015-12-15 06:59:31905
chongza8ba91fc2016-08-16 21:39:17906void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
fsamuel72464894f2015-12-15 06:59:31907 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
908}
909
dchengcedca5612016-04-09 01:40:15910void RenderWidget::OnInputEventAck(
911 std::unique_ptr<InputEventAck> input_event_ack) {
fsamuel72464894f2015-12-15 06:59:31912 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
913}
914
dtapuska46616922016-03-17 22:52:01915void RenderWidget::NotifyInputEventHandled(
dtapuskab08721e62016-06-29 03:35:07916 blink::WebInputEvent::Type handled_type,
917 InputEventAckState ack_result) {
dtapuska0bd451a2016-02-18 17:08:10918 RenderThreadImpl* render_thread = RenderThreadImpl::current();
919 InputHandlerManager* input_handler_manager =
920 render_thread ? render_thread->input_handler_manager() : NULL;
921 if (input_handler_manager) {
dtapuskab08721e62016-06-29 03:35:07922 input_handler_manager->NotifyInputEventHandledOnMainThread(
923 routing_id_, handled_type, ack_result);
dtapuska0bd451a2016-02-18 17:08:10924 }
925}
926
fsamuele8326c742016-01-12 00:49:39927void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
928 // Nothing to do here. RenderWidget created the |input_handler| and will take
929 // ownership of it. We just verify here that we don't already have an input
930 // handler.
931 DCHECK(!input_handler_);
932}
933
fsamuel72464894f2015-12-15 06:59:31934void RenderWidget::UpdateTextInputState(ShowIme show_ime,
935 ChangeSource change_source) {
936 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
937 if (ime_event_guard_) {
938 // show_ime should still be effective even if it was set inside the IME
939 // event guard.
940 if (show_ime == ShowIme::IF_NEEDED) {
941 ime_event_guard_->set_show_ime(true);
942 }
943 return;
944 }
945
lfg8ff33912016-09-13 20:59:21946 if (!GetWebWidget())
dglazkov03c1f672016-08-30 23:18:28947 return;
fsamuel72464894f2015-12-15 06:59:31948
lfg8ff33912016-09-13 20:59:21949 blink::WebTextInputInfo new_info = GetWebWidget()->textInputInfo();
dglazkov03c1f672016-08-30 23:18:28950
fsamuel72464894f2015-12-15 06:59:31951 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
952
953 bool new_can_compose_inline = CanComposeInline();
954
955 // Only sends text input params if they are changed or if the ime should be
956 // shown.
957 if (show_ime == ShowIme::IF_NEEDED ||
changwan8c342742016-02-26 00:53:39958 (IsUsingImeThread() && change_source == ChangeSource::FROM_IME) ||
dglazkov03c1f672016-08-30 23:18:28959 (text_input_mode_ != new_mode || text_input_info_ != new_info ||
fsamuel72464894f2015-12-15 06:59:31960 can_compose_inline_ != new_can_compose_inline)
961#if defined(OS_ANDROID)
962 || text_field_is_dirty_
963#endif
964 ) {
ekaramad9053e57b2016-04-26 20:00:38965 TextInputState params;
dglazkov03c1f672016-08-30 23:18:28966 params.type = WebKitToUiTextInputType(new_info.type);
fsamuel72464894f2015-12-15 06:59:31967 params.mode = new_mode;
968 params.flags = new_info.flags;
969 params.value = new_info.value.utf8();
970 params.selection_start = new_info.selectionStart;
971 params.selection_end = new_info.selectionEnd;
972 params.composition_start = new_info.compositionStart;
973 params.composition_end = new_info.compositionEnd;
974 params.can_compose_inline = new_can_compose_inline;
975 params.show_ime_if_needed = (show_ime == ShowIme::IF_NEEDED);
976#if defined(USE_AURA)
977 params.is_non_ime_change = true;
978#endif
979#if defined(OS_ANDROID)
980 params.is_non_ime_change =
981 (change_source == ChangeSource::FROM_NON_IME) || text_field_is_dirty_;
changwan46620072016-09-21 03:05:41982 params.batch_edit = ime_in_batch_edit_;
fsamuel72464894f2015-12-15 06:59:31983 if (params.is_non_ime_change)
984 OnImeEventSentForAck(new_info);
985 text_field_is_dirty_ = false;
986#endif
987 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
988
989 text_input_info_ = new_info;
fsamuel72464894f2015-12-15 06:59:31990 text_input_mode_ = new_mode;
991 can_compose_inline_ = new_can_compose_inline;
992 text_input_flags_ = new_info.flags;
993 }
994}
995
996bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) {
avid7d6b2e2016-03-04 19:41:17997 if (owner_delegate_)
998 return owner_delegate_->RenderWidgetWillHandleGestureEvent(event);
999
fsamuel72464894f2015-12-15 06:59:311000 return false;
1001}
1002
1003bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
ericwilligers88e69742016-10-17 19:29:551004 for (auto& observer : render_frames_)
1005 observer.RenderWidgetWillHandleMouseEvent();
lfge0c2792ec2016-05-11 18:52:081006
avid7d6b2e2016-03-04 19:41:171007 if (owner_delegate_)
1008 return owner_delegate_->RenderWidgetWillHandleMouseEvent(event);
1009
fsamuel72464894f2015-12-15 06:59:311010 return false;
[email protected]fd847792013-10-24 17:12:351011}
1012
initial.commit09911bf2008-07-26 23:55:291013///////////////////////////////////////////////////////////////////////////////
mfomitchev2600fd7c2016-02-17 20:53:391014// RenderWidgetScreenMetricsDelegate
1015
1016void RenderWidget::Redraw() {
1017 set_next_paint_is_resize_ack();
1018 if (compositor_)
1019 compositor_->SetNeedsRedrawRect(gfx::Rect(size_));
1020}
1021
bokanc63441c2016-04-27 15:49:121022void RenderWidget::ResizeWebWidget() {
lfg8ff33912016-09-13 20:59:211023 GetWebWidget()->resize(GetSizeForWebWidget());
bokanc63441c2016-04-27 15:49:121024}
1025
1026gfx::Size RenderWidget::GetSizeForWebWidget() const {
1027 if (IsUseZoomForDSFEnabled())
1028 return gfx::ScaleToCeiledSize(size_, GetOriginalDeviceScaleFactor());
1029
1030 return size_;
1031}
1032
mfomitchev2600fd7c2016-02-17 20:53:391033void RenderWidget::Resize(const ResizeParams& params) {
engedy6cb63c92016-02-23 14:14:581034 bool orientation_changed =
ccameron2f451532016-09-07 21:49:271035 screen_info_.orientation_angle != params.screen_info.orientation_angle ||
1036 screen_info_.orientation_type != params.screen_info.orientation_type;
engedy6cb63c92016-02-23 14:14:581037
mfomitchev2600fd7c2016-02-17 20:53:391038 screen_info_ = params.screen_info;
wjmaclean8a795f32016-08-11 23:49:581039
ccameron2f451532016-09-07 21:49:271040 if (device_scale_factor_ != screen_info_.device_scale_factor) {
1041 device_scale_factor_ = screen_info_.device_scale_factor;
wjmaclean8a795f32016-08-11 23:49:581042 OnDeviceScaleFactorChanged();
1043 ScheduleComposite();
1044 }
mfomitchev2600fd7c2016-02-17 20:53:391045
1046 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
1047 // A resize ack shouldn't be requested if we have not ACK'd the previous
1048 // one.
1049 DCHECK(!params.needs_resize_ack || !next_paint_is_resize_ack());
1050 }
1051
1052 // Ignore this during shutdown.
lfg8ff33912016-09-13 20:59:211053 if (!GetWebWidget())
mfomitchev2600fd7c2016-02-17 20:53:391054 return;
1055
ianwene5fc5782016-08-18 04:05:151056 if (compositor_) {
mfomitchev2600fd7c2016-02-17 20:53:391057 compositor_->setViewportSize(params.physical_backing_size);
ianwene5fc5782016-08-18 04:05:151058 compositor_->setBottomControlsHeight(params.bottom_controls_height);
ccameronf408cab2016-09-14 16:54:421059 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
ianwene5fc5782016-08-18 04:05:151060 }
mfomitchev2600fd7c2016-02-17 20:53:391061
mfomitchev2600fd7c2016-02-17 20:53:391062 visible_viewport_size_ = params.visible_viewport_size;
mfomitchev2600fd7c2016-02-17 20:53:391063
1064 // NOTE: We may have entered fullscreen mode without changing our size.
1065 bool fullscreen_change =
1066 is_fullscreen_granted_ != params.is_fullscreen_granted;
1067 is_fullscreen_granted_ = params.is_fullscreen_granted;
1068 display_mode_ = params.display_mode;
1069
bokanc63441c2016-04-27 15:49:121070 size_ = params.new_size;
1071 physical_backing_size_ = params.physical_backing_size;
mfomitchev2600fd7c2016-02-17 20:53:391072
bokanc63441c2016-04-27 15:49:121073 ResizeWebWidget();
bokan71cb5b12016-04-27 03:45:221074
mfomitchev2600fd7c2016-02-17 20:53:391075 WebSize visual_viewport_size;
1076
1077 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181078 visual_viewport_size = gfx::ScaleToCeiledSize(
1079 params.visible_viewport_size,
1080 GetOriginalDeviceScaleFactor());
mfomitchev2600fd7c2016-02-17 20:53:391081 } else {
1082 visual_viewport_size = visible_viewport_size_;
1083 }
1084
lfg8ff33912016-09-13 20:59:211085 GetWebWidget()->resizeVisualViewport(visual_viewport_size);
mfomitchev2600fd7c2016-02-17 20:53:391086
bokanc63441c2016-04-27 15:49:121087 // When resizing, we want to wait to paint before ACK'ing the resize. This
1088 // ensures that we only resize as fast as we can paint. We only need to
1089 // send an ACK if we are resized to a non-empty rect.
mfomitchev2600fd7c2016-02-17 20:53:391090 if (params.new_size.IsEmpty() || params.physical_backing_size.IsEmpty()) {
1091 // In this case there is no paint/composite and therefore no
1092 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
1093 // ack through a fake ViewHostMsg_UpdateRect or a different message.
1094 DCHECK(!params.needs_resize_ack);
1095 }
1096
1097 // Send the Resize_ACK flag once we paint again if requested.
1098 if (params.needs_resize_ack)
1099 set_next_paint_is_resize_ack();
1100
1101 if (fullscreen_change)
1102 DidToggleFullscreen();
1103
engedy6cb63c92016-02-23 14:14:581104 if (orientation_changed)
1105 OnOrientationChange();
1106
mfomitchev2600fd7c2016-02-17 20:53:391107 // If a resize ack is requested and it isn't set-up, then no more resizes will
1108 // come in and in general things will go wrong.
1109 DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack());
1110}
1111
1112void RenderWidget::SetScreenMetricsEmulationParameters(
1113 bool enabled,
1114 const blink::WebDeviceEmulationParams& params) {
1115 // This is only supported in RenderView.
1116 NOTREACHED();
1117}
1118
1119void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect,
1120 const gfx::Rect& window_screen_rect) {
1121 view_screen_rect_ = view_screen_rect;
1122 window_screen_rect_ = window_screen_rect;
1123}
1124
1125///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461126// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291127
[email protected]3a1c8a8032013-03-18 22:35:321128void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401129 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051130 if (compositor_)
oshima750cb4342015-10-31 00:59:011131 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051132}
1133
[email protected]e195e582013-03-08 01:32:591134void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221135 DCHECK(!host_closing_);
1136
fsamuel78f86e42016-01-20 04:10:231137 compositor_ = RenderWidgetCompositor::Create(this, device_scale_factor_,
1138 compositor_deps_);
oshima750cb4342015-10-31 00:59:011139 compositor_->setViewportSize(physical_backing_size_);
oshimad5279032015-12-16 18:22:331140 OnDeviceScaleFactorChanged();
ccameronf408cab2016-09-14 16:54:421141 compositor_->SetDeviceColorSpace(screen_info_.icc_profile.GetColorSpace());
sievers71c62dd52015-10-07 01:44:391142 // For background pages and certain tests, we don't want to trigger
danakj1120f4c2016-09-15 02:05:321143 // CompositorFrameSink creation.
sievers71c62dd52015-10-07 01:44:391144 if (compositor_never_visible_ || !RenderThreadImpl::current())
1145 compositor_->SetNeverVisible();
1146
pimanc4af3072015-10-02 03:45:591147 StartCompositor();
[email protected]e195e582013-03-08 01:32:591148}
1149
ennef3c58142014-12-09 21:44:381150void RenderWidget::WillCloseLayerTreeView() {
1151 if (host_closing_)
1152 return;
1153
1154 // Prevent new compositors or output surfaces from being created.
1155 host_closing_ = true;
1156
[email protected]aeeedad2014-08-22 18:16:221157 // Always send this notification to prevent new layer tree views from
1158 // being created, even if one hasn't been created yet.
lfg8ff33912016-09-13 20:59:211159 if (blink::WebWidget* widget = GetWebWidget())
1160 widget->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221161}
1162
[email protected]180ef242013-11-07 06:50:461163blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281164 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061165}
1166
dglazkovf0e1d6d2015-10-10 02:13:481167void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1168 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1169 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1170 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1171 }
dglazkov79c426102015-08-31 21:22:431172
ericwilligers88e69742016-10-17 19:29:551173 for (auto& observer : render_frames_)
1174 observer.DidMeaningfulLayout(layout_type);
dglazkov79c426102015-08-31 21:22:431175}
1176
jdduke491a3f0c2015-06-15 23:30:261177void RenderWidget::ScheduleComposite() {
1178 if (compositor_ &&
1179 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
skyostil32650d22016-09-26 16:58:231180 compositor_->setNeedsCompositorUpdate();
jdduke491a3f0c2015-06-15 23:30:261181 }
1182}
1183
1184void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1185 if (compositor_) {
1186 // Regardless of whether threaded compositing is enabled, always
1187 // use this mechanism to force the compositor to redraw. However,
1188 // the invalidation code path below is still needed for the
1189 // non-threaded case.
1190 compositor_->SetNeedsForcedRedraw();
1191 }
1192 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151193}
1194
[email protected]586871b2014-07-22 17:05:111195// static
dchengcedca5612016-04-09 01:40:151196std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
[email protected]586871b2014-07-22 17:05:111197 IPC::Message* msg,
1198 MessageDeliveryPolicy policy,
1199 FrameSwapMessageQueue* frame_swap_message_queue,
1200 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111201 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111202 bool first_message_for_frame = false;
dchengcedca5612016-04-09 01:40:151203 frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number,
1204 base::WrapUnique(msg),
[email protected]586871b2014-07-22 17:05:111205 &first_message_for_frame);
1206 if (first_message_for_frame) {
dchengcedca5612016-04-09 01:40:151207 std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
[email protected]586871b2014-07-22 17:05:111208 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061209 return promise;
[email protected]586871b2014-07-22 17:05:111210 }
dcheng4b6b5ff2014-10-16 00:42:061211 return nullptr;
[email protected]586871b2014-07-22 17:05:111212}
1213
1214void RenderWidget::QueueMessage(IPC::Message* msg,
1215 MessageDeliveryPolicy policy) {
1216 // RenderThreadImpl::current() is NULL in some tests.
1217 if (!compositor_ || !RenderThreadImpl::current()) {
1218 Send(msg);
1219 return;
1220 }
1221
dchengcedca5612016-04-09 01:40:151222 std::unique_ptr<cc::SwapPromise> swap_promise =
1223 QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111224 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111225 compositor_->GetSourceFrameNumber());
1226
1227 if (swap_promise) {
dcheng07945f632015-12-26 07:59:321228 compositor_->QueueSwapPromise(std::move(swap_promise));
igsollaeab34cc2015-02-20 11:33:351229 // Request a commit. This might either A) request a commit ahead of time
1230 // or B) request a commit which is not needed because there are not
1231 // pending updates. If B) then the commit will be skipped and the swap
1232 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1233 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1234 // can_cancel_commit is not unset.
1235 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111236 }
1237}
1238
[email protected]4873c7d2009-07-16 06:36:281239void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301240 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521241 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181242 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291243 // Only send a SetCursor message if we need to make a change.
1244 if (!current_cursor_.IsEqual(cursor)) {
1245 current_cursor_ = cursor;
1246 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1247 }
1248}
1249
1250// We are supposed to get a single call to Show for a newly created RenderWidget
1251// that was created via RenderWidget::CreateWebView. So, we wait until this
1252// point to dispatch the ShowWidget message.
1253//
1254// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281255// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291256//
[email protected]4873c7d2009-07-16 06:36:281257void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291258 DCHECK(!did_show_) << "received extraneous Show call";
1259 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1260 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1261
[email protected]8de12d942010-11-17 20:42:441262 if (did_show_)
1263 return;
1264
1265 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561266 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441267 // that's okay. It'll be ignored if as_popup is false, or the browser
1268 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561269 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1270 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291271}
1272
[email protected]2533ce12009-05-09 00:02:241273void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381274 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241275 Send(new ViewHostMsg_Close(routing_id_));
1276}
1277
dgozmancf9039cd2015-04-06 12:01:311278void RenderWidget::NotifyOnClose() {
ericwilligers88e69742016-10-17 19:29:551279 for (auto& observer : render_frames_)
1280 observer.WidgetWillClose();
dgozmancf9039cd2015-04-06 12:01:311281}
1282
[email protected]4873c7d2009-07-16 06:36:281283void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081284 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321285 if (is_swapped_out_) {
1286 // This widget is currently swapped out, and the active widget is in a
1287 // different process. Have the browser route the close request to the
1288 // active widget instead, so that the correct unload handlers are run.
1289 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1290 return;
1291 }
1292
initial.commit09911bf2008-07-26 23:55:291293 // If a page calls window.close() twice, we'll end up here twice, but that's
1294 // OK. It is safe to send multiple Close messages.
1295
[email protected]2533ce12009-05-09 00:02:241296 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1297 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1298 // could be closed before the JS finishes executing. So instead, post a
1299 // message back to the message loop, which won't run until the JS is
1300 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081301 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211302 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291303}
1304
[email protected]9017d7852013-11-21 17:47:351305void RenderWidget::QueueSyntheticGesture(
dchengcedca5612016-04-09 01:40:151306 std::unique_ptr<SyntheticGestureParams> gesture_params,
[email protected]9017d7852013-11-21 17:47:351307 const SyntheticGestureCompletionCallback& callback) {
1308 DCHECK(!callback.is_null());
1309
1310 pending_synthetic_gesture_callbacks_.push(callback);
1311
1312 SyntheticGesturePacket gesture_packet;
dcheng07945f632015-12-26 07:59:321313 gesture_packet.set_gesture_params(std::move(gesture_params));
[email protected]9017d7852013-11-21 17:47:351314
1315 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1316}
1317
initial.commit09911bf2008-07-26 23:55:291318void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031319 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381320 WillCloseLayerTreeView();
1321 compositor_.reset();
lfg8ff33912016-09-13 20:59:211322 if (webwidget_internal_) {
1323 webwidget_internal_->close();
1324 webwidget_internal_ = nullptr;
initial.commit09911bf2008-07-26 23:55:291325 }
1326}
1327
bokan841fdc72016-10-06 00:16:351328void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const {
1329 DCHECK(window_rect);
1330 float scale = popup_origin_scale_for_emulation_;
1331 if (!scale)
1332 return;
1333 window_rect->x =
1334 popup_view_origin_for_emulation_.x() +
1335 (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale;
1336 window_rect->y =
1337 popup_view_origin_for_emulation_.y() +
1338 (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale;
1339}
1340
1341void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const {
1342 DCHECK(window_rect);
1343 float scale = popup_origin_scale_for_emulation_;
1344 if (!scale)
1345 return;
1346 window_rect->x =
1347 popup_screen_origin_for_emulation_.x() +
1348 (window_rect->x - popup_view_origin_for_emulation_.x()) * scale;
1349 window_rect->y =
1350 popup_screen_origin_for_emulation_.y() +
1351 (window_rect->y - popup_view_origin_for_emulation_.y()) * scale;
1352}
1353
[email protected]4873c7d2009-07-16 06:36:281354WebRect RenderWidget::windowRect() {
bokan841fdc72016-10-06 00:16:351355 WebRect rect;
bokan6b08cd22016-10-05 00:55:211356 if (pending_window_rect_count_) {
1357 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1358 // the RootWindowRect is probably going to return wrong results since the
1359 // browser may not have processed the Move yet. There isn't really anything
1360 // good to do in this case, and it shouldn't happen - since this size is
1361 // only really needed for windowToScreen, which is only used for Popups.
bokan841fdc72016-10-06 00:16:351362 rect = pending_window_rect_;
1363 } else {
1364 rect = window_screen_rect_;
bokan6b08cd22016-10-05 00:55:211365 }
[email protected]2533ce12009-05-09 00:02:241366
bokan841fdc72016-10-06 00:16:351367 ScreenRectToEmulatedIfNeeded(&rect);
1368 return rect;
bokan6b08cd22016-10-05 00:55:211369}
1370
1371WebRect RenderWidget::viewRect() {
bokan841fdc72016-10-06 00:16:351372 WebRect rect = view_screen_rect_;
1373 ScreenRectToEmulatedIfNeeded(&rect);
1374 return rect;
initial.commit09911bf2008-07-26 23:55:291375}
1376
[email protected]180ef242013-11-07 06:50:461377void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301378 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541379 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301380}
1381
oshima33ec97cd2015-12-14 19:40:241382void RenderWidget::setWindowRect(const WebRect& rect_in_screen) {
1383 WebRect window_rect = rect_in_screen;
bokan841fdc72016-10-06 00:16:351384 EmulatedToScreenRectIfNeeded(&window_rect);
[email protected]b2e4c70132013-10-03 02:07:511385
[email protected]5b45ad42013-10-25 00:42:041386 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201387 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561388 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1389 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031390 } else {
bokanc007c3a2015-02-03 07:15:561391 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031392 }
initial.commit09911bf2008-07-26 23:55:291393 } else {
bokanc007c3a2015-02-03 07:15:561394 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291395 }
1396}
1397
[email protected]2533ce12009-05-09 00:02:241398void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1399 pending_window_rect_ = rect;
1400 pending_window_rect_count_++;
[email protected]2533ce12009-05-09 00:02:241401
bokan6b08cd22016-10-05 00:55:211402 // Popups don't get size updates back from the browser so just store the set
1403 // values.
1404 if (popup_type_ != blink::WebPopupTypeNone) {
1405 window_screen_rect_ = rect;
1406 view_screen_rect_ = rect;
[email protected]2533ce12009-05-09 00:02:241407 }
[email protected]d4547452008-08-28 18:36:371408}
1409
[email protected]fa7b1dc2010-06-23 17:53:041410void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261411 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041412 const std::vector<WebCompositionUnderline>& underlines,
chongz7eb752802016-01-27 21:28:071413 const gfx::Range& replacement_range,
[email protected]fa7b1dc2010-06-23 17:53:041414 int selection_start, int selection_end) {
ekaramad2a46d632016-07-19 13:33:091415#if defined(ENABLE_PLUGINS)
1416 if (focused_pepper_plugin_) {
1417 focused_pepper_plugin_->render_frame()->OnImeSetComposition(
1418 text, underlines, selection_start, selection_end);
1419 return;
1420 }
1421#endif
1422 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211423 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031424 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091425 }
1426
[email protected]0d1ebed12013-08-05 22:01:131427 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281428 return;
[email protected]66fca5bc2013-05-23 06:58:291429 ImeEventGuard guard(this);
lfg8ff33912016-09-13 20:59:211430 if (!GetWebWidget()->setComposition(
1431 text, WebVector<WebCompositionUnderline>(underlines), selection_start,
1432 selection_end)) {
[email protected]fa7b1dc2010-06-23 17:53:041433 // If we failed to set the composition text, then we need to let the browser
1434 // process to cancel the input method's ongoing composition session, to make
1435 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221436 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261437 }
nonafa291792016-08-10 02:36:181438 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:041439}
1440
aelias87b8f7c2016-09-14 03:19:291441void RenderWidget::OnImeCommitText(const base::string16& text,
1442 const gfx::Range& replacement_range,
1443 int relative_cursor_pos) {
ekaramad2a46d632016-07-19 13:33:091444#if defined(ENABLE_PLUGINS)
1445 if (focused_pepper_plugin_) {
aelias87b8f7c2016-09-14 03:19:291446 focused_pepper_plugin_->render_frame()->OnImeCommitText(
1447 text, replacement_range, relative_cursor_pos);
ekaramad2a46d632016-07-19 13:33:091448 return;
1449 }
1450#endif
1451 if (replacement_range.IsValid()) {
lfg8ff33912016-09-13 20:59:211452 GetWebWidget()->applyReplacementRange(
dglazkov0d680e32016-09-02 21:34:031453 WebRange(replacement_range.start(), replacement_range.length()));
ekaramad2a46d632016-07-19 13:33:091454 }
1455
[email protected]0d1ebed12013-08-05 22:01:131456 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041457 return;
[email protected]66fca5bc2013-05-23 06:58:291458 ImeEventGuard guard(this);
fsamuele8326c742016-01-12 00:49:391459 input_handler_->set_handling_input_event(true);
aelias87b8f7c2016-09-14 03:19:291460 GetWebWidget()->commitText(text, relative_cursor_pos);
1461 input_handler_->set_handling_input_event(false);
1462 UpdateCompositionInfo(false /* not an immediate request */);
1463}
1464
1465void RenderWidget::OnImeFinishComposingText(bool keep_selection) {
1466#if defined(ENABLE_PLUGINS)
1467 if (focused_pepper_plugin_) {
1468 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText(
1469 keep_selection);
1470 return;
1471 }
1472#endif
1473
1474 if (!ShouldHandleImeEvent())
1475 return;
1476 ImeEventGuard guard(this);
1477 input_handler_->set_handling_input_event(true);
1478 GetWebWidget()->finishComposingText(keep_selection
1479 ? WebWidget::KeepSelection
1480 : WebWidget::DoNotKeepSelection);
fsamuele8326c742016-01-12 00:49:391481 input_handler_->set_handling_input_event(false);
nonafa291792016-08-10 02:36:181482 UpdateCompositionInfo(false /* not an immediate request */);
initial.commit09911bf2008-07-26 23:55:291483}
1484
oshimad5279032015-12-16 18:22:331485void RenderWidget::OnDeviceScaleFactorChanged() {
1486 if (!compositor_)
1487 return;
oshimad5279032015-12-16 18:22:331488 if (IsUseZoomForDSFEnabled())
oshima50872a72016-03-04 13:26:181489 compositor_->SetPaintedDeviceScaleFactor(GetOriginalDeviceScaleFactor());
oshimad5279032015-12-16 18:22:331490 else
1491 compositor_->setDeviceScaleFactor(device_scale_factor_);
1492}
1493
[email protected]0bc1f572013-04-17 01:46:311494void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121495 // During shutdown we can just ignore this message.
lfg8ff33912016-09-13 20:59:211496 if (!GetWebWidget())
[email protected]ec7dc112008-08-06 05:30:121497 return;
1498
[email protected]0bc1f572013-04-17 01:46:311499 // Even if the browser provides an empty damage rect, it's still expecting to
1500 // receive a repaint ack so just damage the entire widget bounds.
1501 if (size_to_paint.IsEmpty()) {
1502 size_to_paint = size_;
1503 }
1504
[email protected]ec7dc112008-08-06 05:30:121505 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051506 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311507 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121508}
1509
[email protected]79fa22e2013-08-23 15:18:121510void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351511 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1512
1513 pending_synthetic_gesture_callbacks_.front().Run();
1514 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271515}
1516
[email protected]4873c7d2009-07-16 06:36:281517void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
lfg8ff33912016-09-13 20:59:211518 if (!GetWebWidget())
[email protected]07f953332009-03-25 04:31:111519 return;
lfg8ff33912016-09-13 20:59:211520 GetWebWidget()->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111521}
1522
[email protected]80ad8622012-11-07 16:33:031523void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1524 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511525 if (screen_metrics_emulator_) {
mfomitchev2600fd7c2016-02-17 20:53:391526 screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect,
1527 window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511528 } else {
mfomitchev2600fd7c2016-02-17 20:53:391529 SetScreenRects(view_screen_rect, window_screen_rect);
[email protected]b2e4c70132013-10-03 02:07:511530 }
[email protected]80ad8622012-11-07 16:33:031531 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1532}
1533
lfgdb5c4ed2016-03-04 23:09:071534void RenderWidget::OnUpdateWindowScreenRect(
1535 const gfx::Rect& window_screen_rect) {
bokan6b08cd22016-10-05 00:55:211536 if (screen_metrics_emulator_)
lfgdb5c4ed2016-03-04 23:09:071537 screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect);
bokan6b08cd22016-10-05 00:55:211538 else
lfgdb5c4ed2016-03-04 23:09:071539 window_screen_rect_ = window_screen_rect;
lfgdb5c4ed2016-03-04 23:09:071540}
1541
fsamuele0f705b2016-10-01 14:07:141542void RenderWidget::OnSetFrameSinkId(const cc::FrameSinkId& frame_sink_id) {
kenrbb4e2a3b2015-05-14 15:05:051543 if (compositor_)
fsamuele0f705b2016-10-01 14:07:141544 compositor_->SetFrameSinkId(frame_sink_id);
kenrbb4e2a3b2015-05-14 15:05:051545}
1546
dtrainor5ef644e2015-11-19 00:12:471547void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) {
1548 if (compositor_)
1549 compositor_->OnHandleCompositorProto(proto);
1550}
1551
[email protected]adb362312014-06-28 06:04:241552void RenderWidget::showImeIfNeeded() {
1553 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131554}
1555
fsamuel72464894f2015-12-15 06:59:311556ui::TextInputType RenderWidget::GetTextInputType() {
ekaramad2a46d632016-07-19 13:33:091557#if defined(ENABLE_PLUGINS)
1558 if (focused_pepper_plugin_)
1559 return focused_pepper_plugin_->text_input_type();
1560#endif
lfg8ff33912016-09-13 20:59:211561 if (GetWebWidget())
1562 return WebKitToUiTextInputType(GetWebWidget()->textInputType());
fsamuel72464894f2015-12-15 06:59:311563 return ui::TEXT_INPUT_TYPE_NONE;
1564}
1565
nonafa291792016-08-10 02:36:181566void RenderWidget::UpdateCompositionInfo(bool immediate_request) {
1567 if (!monitor_composition_info_ && !immediate_request)
1568 return; // Do not calculate composition info if not requested.
nonadac0c7a2016-08-01 02:30:591569
nonafa291792016-08-10 02:36:181570 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
1571 gfx::Range range;
1572 std::vector<gfx::Rect> character_bounds;
1573
1574 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) {
1575 // Composition information is only available on editable node.
1576 range = gfx::Range::InvalidRange();
1577 } else {
1578 GetCompositionRange(&range);
1579 GetCompositionCharacterBounds(&character_bounds);
1580 }
1581
1582 if (!immediate_request &&
1583 !ShouldUpdateCompositionInfo(range, character_bounds)) {
fsamuel72464894f2015-12-15 06:59:311584 return;
nonafa291792016-08-10 02:36:181585 }
fsamuel72464894f2015-12-15 06:59:311586 composition_character_bounds_ = character_bounds;
1587 composition_range_ = range;
1588 Send(new InputHostMsg_ImeCompositionRangeChanged(
1589 routing_id(), composition_range_, composition_character_bounds_));
fsamuel72464894f2015-12-15 06:59:311590}
1591
oshimaf866dab2015-12-05 00:41:541592void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
1593 if (IsUseZoomForDSFEnabled()) {
lfg15b235a32016-08-25 17:45:461594 float reverse = 1 / GetOriginalDeviceScaleFactor();
oshimad5279032015-12-16 18:22:331595 // TODO(oshima): We may need to allow pixel precision here as the the
oshimaf866dab2015-12-05 00:41:541596 // anchor element can be placed at half pixel.
lfg15b235a32016-08-25 17:45:461597 gfx::Rect window_rect =
1598 gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse);
1599 rect->x = window_rect.x();
1600 rect->y = window_rect.y();
1601 rect->width = window_rect.width();
1602 rect->height = window_rect.height();
oshimaf866dab2015-12-05 00:41:541603 }
1604}
1605
oshimaa6985b62016-01-27 08:58:301606void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
1607 if (IsUseZoomForDSFEnabled()) {
oshima50872a72016-03-04 13:26:181608 rect->x *= GetOriginalDeviceScaleFactor();
1609 rect->y *= GetOriginalDeviceScaleFactor();
1610 rect->width *= GetOriginalDeviceScaleFactor();
1611 rect->height *= GetOriginalDeviceScaleFactor();
oshimaa6985b62016-01-27 08:58:301612 }
1613}
1614
[email protected]adb362312014-06-28 06:04:241615void RenderWidget::OnShowImeIfNeeded() {
1616#if defined(OS_ANDROID) || defined(USE_AURA)
fsamuel72464894f2015-12-15 06:59:311617 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]adb362312014-06-28 06:04:241618#endif
rouslanf7ebd8832015-01-22 01:54:141619
1620// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1621// virtual keyboard.
1622#if !defined(OS_ANDROID)
1623 FocusChangeComplete();
1624#endif
[email protected]adb362312014-06-28 06:04:241625}
1626
1627#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371628void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1629 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131630}
1631
1632void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371633 DCHECK_GE(text_input_info_history_.size(), 1u);
1634 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511635}
changwan8c342742016-02-26 00:53:391636
1637void RenderWidget::OnRequestTextInputStateUpdate() {
1638 DCHECK(!ime_event_guard_);
1639 UpdateSelectionBounds();
1640 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1641}
changwan46620072016-09-21 03:05:411642
1643void RenderWidget::OnImeBatchEdit(bool begin) {
1644 if (begin) {
1645 ime_in_batch_edit_ = true;
1646 return;
1647 }
1648 if (!ime_in_batch_edit_)
1649 return;
1650 ime_in_batch_edit_ = false;
1651 DCHECK(!ime_event_guard_);
1652 UpdateSelectionBounds();
1653 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_IME);
1654}
[email protected]105dffb42013-02-20 03:46:211655#endif
1656
nonafa291792016-08-10 02:36:181657void RenderWidget::OnRequestCompositionUpdate(bool immediate_request,
1658 bool monitor_request) {
1659 monitor_composition_info_ = monitor_request;
1660 if (!immediate_request)
1661 return;
1662 UpdateCompositionInfo(true /* immediate request */);
1663}
1664
[email protected]0d1ebed12013-08-05 22:01:131665bool RenderWidget::ShouldHandleImeEvent() {
1666#if defined(OS_ANDROID)
lfg8ff33912016-09-13 20:59:211667 if (!GetWebWidget())
changwan3a841162015-08-11 02:53:371668 return false;
changwan8c342742016-02-26 00:53:391669 if (IsUsingImeThread())
1670 return true;
changwan3a841162015-08-11 02:53:371671
1672 // We cannot handle IME events if there is any chance that the event we are
1673 // receiving here from the browser is based on the state that is different
1674 // from our current one as indicated by |text_input_info_|.
1675 // The states the browser might be in are:
1676 // text_input_info_history_[0] - current state ack'd by browser
1677 // text_input_info_history_[1...N] - pending state changes
1678 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1679 if (text_input_info_history_[i] != text_input_info_)
1680 return false;
1681 }
1682 return true;
[email protected]0d1ebed12013-08-05 22:01:131683#else
lfg8ff33912016-09-13 20:59:211684 return !!GetWebWidget();
[email protected]0d1ebed12013-08-05 22:01:131685#endif
1686}
1687
wjmaclean8a795f32016-08-11 23:49:581688void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) {
[email protected]468ac582012-11-20 00:53:191689 if (device_scale_factor_ == device_scale_factor)
1690 return;
1691
1692 device_scale_factor_ = device_scale_factor;
oshimad5279032015-12-16 18:22:331693
1694 OnDeviceScaleFactorChanged();
jdduke491a3f0c2015-06-15 23:30:261695 ScheduleComposite();
wjmaclean8a795f32016-08-11 23:49:581696
1697 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]468ac582012-11-20 00:53:191698}
1699
[email protected]28ed6b32014-06-08 02:16:271700bool RenderWidget::SetDeviceColorProfile(
1701 const std::vector<char>& color_profile) {
1702 if (device_color_profile_ == color_profile)
1703 return false;
1704
1705 device_color_profile_ = color_profile;
[email protected]28ed6b32014-06-08 02:16:271706
avi40b5be7a2016-03-03 21:13:441707 if (owner_delegate_)
1708 owner_delegate_->RenderWidgetDidSetColorProfile(color_profile);
1709
1710 return true;
noeldb4df152014-09-16 17:45:201711}
1712
[email protected]fcdc5642014-05-09 14:32:241713void RenderWidget::OnOrientationChange() {
1714}
1715
avib9dbd972016-03-08 18:19:321716void RenderWidget::DidFlushPaint() {
1717 if (owner_delegate_)
1718 owner_delegate_->RenderWidgetDidFlushPaint();
1719}
1720
[email protected]bee16aab2009-08-26 15:55:031721void RenderWidget::SetHidden(bool hidden) {
1722 if (is_hidden_ == hidden)
1723 return;
1724
jdduke8fac9d102014-12-20 02:40:131725 // The status has changed. Tell the RenderThread about it and ensure
1726 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031727 is_hidden_ = hidden;
fsamuele8326c742016-01-12 00:49:391728 input_handler_->FlushPendingInputEventAck();
jdduke8fac9d102014-12-20 02:40:131729
[email protected]bee16aab2009-08-26 15:55:031730 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001731 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031732 else
[email protected]b2db9272014-01-10 17:42:001733 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111734
1735 if (render_widget_scheduling_state_)
1736 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031737}
1738
[email protected]2b624c562011-10-27 22:58:261739void RenderWidget::DidToggleFullscreen() {
lfg8ff33912016-09-13 20:59:211740 if (!GetWebWidget())
[email protected]2b624c562011-10-27 22:58:261741 return;
1742
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121743 if (is_fullscreen_granted_) {
lfg8ff33912016-09-13 20:59:211744 GetWebWidget()->didEnterFullscreen();
[email protected]2b624c562011-10-27 22:58:261745 } else {
lfg8ff33912016-09-13 20:59:211746 GetWebWidget()->didExitFullscreen();
[email protected]2b624c562011-10-27 22:58:261747 }
[email protected]2b624c562011-10-27 22:58:261748}
1749
[email protected]674741932009-02-04 23:44:461750bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051751 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461752}
1753
[email protected]674741932009-02-04 23:44:461754void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051755 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461756}
1757
[email protected]674741932009-02-04 23:44:461758void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051759 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461760}
1761
changwan8c342742016-02-26 00:53:391762bool RenderWidget::IsUsingImeThread() {
1763#if defined(OS_ANDROID)
changwan7ded3752016-03-09 23:25:121764 return base::FeatureList::IsEnabled(features::kImeThread);
changwan8c342742016-02-26 00:53:391765#else
1766 return false;
1767#endif
1768}
1769
changwanf2a707b2015-10-30 08:22:161770void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1771 if (!ime_event_guard_)
1772 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291773}
1774
changwanf2a707b2015-10-30 08:22:161775void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1776 if (ime_event_guard_ != guard) {
1777#if defined(OS_ANDROID)
1778 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1779 // (e.g. long press gesture), we want to treat it as not-from-IME event
changwan8c342742016-02-26 00:53:391780 // so that ReplicaInputConnection can make changes to its Editable model.
changwanf2a707b2015-10-30 08:22:161781 // Therefore, we want to mark this text state update as 'from IME' only
1782 // when all the nested events are all originating from IME.
1783 ime_event_guard_->set_from_ime(
1784 ime_event_guard_->from_ime() && guard->from_ime());
1785#endif
1786 return;
1787 }
1788 ime_event_guard_ = nullptr;
1789
[email protected]66fca5bc2013-05-23 06:58:291790 // While handling an ime event, text input state and selection bounds updates
1791 // are ignored. These must explicitly be updated once finished handling the
1792 // ime event.
1793 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471794#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161795 UpdateTextInputState(
fsamuel72464894f2015-12-15 06:59:311796 guard->show_ime() ? ShowIme::IF_NEEDED : ShowIme::HIDE_IME,
1797 guard->from_ime() ? ChangeSource::FROM_IME : ChangeSource::FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471798#endif
[email protected]66fca5bc2013-05-23 06:58:291799}
1800
[email protected]7c8873e2013-02-05 08:03:011801void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
ekaramad2a46d632016-07-19 13:33:091802#if defined(ENABLE_PLUGINS)
1803 if (focused_pepper_plugin_) {
1804 // TODO(kinaba) http://crbug.com/101101
1805 // Current Pepper IME API does not handle selection bounds. So we simply
1806 // use the caret position as an empty range for now. It will be updated
1807 // after Pepper API equips features related to surrounding text retrieval.
1808 blink::WebRect caret(focused_pepper_plugin_->GetCaretBounds());
1809 convertViewportToWindow(&caret);
1810 *focus = caret;
1811 *anchor = caret;
1812 return;
1813 }
1814#endif
[email protected]7c8873e2013-02-05 08:03:011815 WebRect focus_webrect;
1816 WebRect anchor_webrect;
lfg8ff33912016-09-13 20:59:211817 GetWebWidget()->selectionBounds(focus_webrect, anchor_webrect);
oshima33ec97cd2015-12-14 19:40:241818 convertViewportToWindow(&focus_webrect);
1819 convertViewportToWindow(&anchor_webrect);
1820 *focus = focus_webrect;
1821 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321822}
1823
[email protected]e99ef6f2011-10-16 01:13:001824void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081825 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
lfg8ff33912016-09-13 20:59:211826 if (!GetWebWidget())
[email protected]e99ef6f2011-10-16 01:13:001827 return;
changwanf2a707b2015-10-30 08:22:161828 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:291829 return;
[email protected]e99ef6f2011-10-16 01:13:001830
mohsenb0eeba72015-08-09 06:20:081831#if defined(USE_AURA)
1832 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1833 // Aura beucause composited selection updates are not working for webview tags
1834 // which regresses IME inside webview. Remove this when composited selection
1835 // updates are fixed for webviews. See, http://crbug.com/510568.
1836 bool send_ipc = true;
1837#else
jddukeacf809e2014-09-23 20:38:381838 // With composited selection updates, the selection bounds will be reported
1839 // directly by the compositor, in which case explicit IPC selection
1840 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081841 bool send_ipc =
1842 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1843#endif
1844 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381845 ViewHostMsg_SelectionBounds_Params params;
1846 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1847 if (selection_anchor_rect_ != params.anchor_rect ||
1848 selection_focus_rect_ != params.focus_rect) {
1849 selection_anchor_rect_ = params.anchor_rect;
1850 selection_focus_rect_ = params.focus_rect;
lfg8ff33912016-09-13 20:59:211851 GetWebWidget()->selectionTextDirection(params.focus_dir,
1852 params.anchor_dir);
1853 params.is_anchor_first = GetWebWidget()->isSelectionAnchorFirst();
jddukeacf809e2014-09-23 20:38:381854 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1855 }
[email protected]58b48a0d2012-06-13 07:01:351856 }
jddukeacf809e2014-09-23 20:38:381857
nonafa291792016-08-10 02:36:181858 UpdateCompositionInfo(false /* not an immediate request */);
[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
lfgb00fcad2016-07-14 14:16:331866void RenderWidget::DidAutoResize(const gfx::Size& new_size) {
1867 WebRect new_size_in_window(0, 0, new_size.width(), new_size.height());
1868 convertViewportToWindow(&new_size_in_window);
1869 if (size_.width() != new_size_in_window.width ||
1870 size_.height() != new_size_in_window.height) {
1871 size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height);
1872
1873 if (resizing_mode_selector_->is_synchronous_mode()) {
bokan6b08cd22016-10-05 00:55:211874 gfx::Rect new_pos(windowRect().x, windowRect().y,
lfg0140a452016-07-19 19:15:051875 size_.width(), size_.height());
lfgb00fcad2016-07-14 14:16:331876 view_screen_rect_ = new_pos;
1877 window_screen_rect_ = new_pos;
1878 }
1879
1880 AutoResizeCompositor();
1881
1882 if (!resizing_mode_selector_->is_synchronous_mode())
1883 need_update_rect_for_auto_resize_ = true;
1884 }
1885}
1886
[email protected]180ef242013-11-07 06:50:461887// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
danakj365175c2016-02-06 00:37:371888STATIC_ASSERT_ENUM(blink::WebTextInputTypeNone, ui::TEXT_INPUT_TYPE_NONE);
1889STATIC_ASSERT_ENUM(blink::WebTextInputTypeText, ui::TEXT_INPUT_TYPE_TEXT);
1890STATIC_ASSERT_ENUM(blink::WebTextInputTypePassword,
1891 ui::TEXT_INPUT_TYPE_PASSWORD);
1892STATIC_ASSERT_ENUM(blink::WebTextInputTypeSearch, ui::TEXT_INPUT_TYPE_SEARCH);
1893STATIC_ASSERT_ENUM(blink::WebTextInputTypeEmail, ui::TEXT_INPUT_TYPE_EMAIL);
1894STATIC_ASSERT_ENUM(blink::WebTextInputTypeNumber, ui::TEXT_INPUT_TYPE_NUMBER);
1895STATIC_ASSERT_ENUM(blink::WebTextInputTypeTelephone,
1896 ui::TEXT_INPUT_TYPE_TELEPHONE);
1897STATIC_ASSERT_ENUM(blink::WebTextInputTypeURL, ui::TEXT_INPUT_TYPE_URL);
1898STATIC_ASSERT_ENUM(blink::WebTextInputTypeDate, ui::TEXT_INPUT_TYPE_DATE);
1899STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTime,
1900 ui::TEXT_INPUT_TYPE_DATE_TIME);
1901STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeLocal,
1902 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL);
1903STATIC_ASSERT_ENUM(blink::WebTextInputTypeMonth, ui::TEXT_INPUT_TYPE_MONTH);
1904STATIC_ASSERT_ENUM(blink::WebTextInputTypeTime, ui::TEXT_INPUT_TYPE_TIME);
1905STATIC_ASSERT_ENUM(blink::WebTextInputTypeWeek, ui::TEXT_INPUT_TYPE_WEEK);
1906STATIC_ASSERT_ENUM(blink::WebTextInputTypeTextArea,
1907 ui::TEXT_INPUT_TYPE_TEXT_AREA);
1908STATIC_ASSERT_ENUM(blink::WebTextInputTypeContentEditable,
1909 ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE);
1910STATIC_ASSERT_ENUM(blink::WebTextInputTypeDateTimeField,
1911 ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:451912
[email protected]5b739cb2012-08-21 20:35:211913ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461914 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:211915 // Check the type is in the range representable by ui::TextInputType.
1916 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:461917 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:211918 return static_cast<ui::TextInputType>(type);
1919}
1920
[email protected]58b48a0d2012-06-13 07:01:351921void RenderWidget::GetCompositionCharacterBounds(
1922 std::vector<gfx::Rect>* bounds) {
1923 DCHECK(bounds);
1924 bounds->clear();
ekaramad2a46d632016-07-19 13:33:091925
1926#if defined(ENABLE_PLUGINS)
1927 if (focused_pepper_plugin_)
1928 return;
1929#endif
1930
lfg8ff33912016-09-13 20:59:211931 if (!GetWebWidget())
ekaramad2a46d632016-07-19 13:33:091932 return;
1933 blink::WebVector<blink::WebRect> bounds_from_blink;
lfg8ff33912016-09-13 20:59:211934 if (!GetWebWidget()->getCompositionCharacterBounds(bounds_from_blink))
ekaramad2a46d632016-07-19 13:33:091935 return;
1936
1937 for (size_t i = 0; i < bounds_from_blink.size(); ++i) {
1938 convertViewportToWindow(&bounds_from_blink[i]);
1939 bounds->push_back(bounds_from_blink[i]);
1940 }
[email protected]58b48a0d2012-06-13 07:01:351941}
1942
[email protected]db4fc1e2013-09-06 20:01:511943void RenderWidget::GetCompositionRange(gfx::Range* range) {
ekaramad2a46d632016-07-19 13:33:091944#if defined(ENABLE_PLUGINS)
1945 if (focused_pepper_plugin_)
1946 return;
1947#endif
lfg8ff33912016-09-13 20:59:211948 WebRange web_range = GetWebWidget()->compositionRange();
dglazkov78a24b62016-09-02 21:34:531949 if (!web_range.isNull()) {
1950 range->set_start(web_range.startOffset());
1951 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361952 } else {
lfg8ff33912016-09-13 20:59:211953 web_range = GetWebWidget()->caretOrSelectionRange();
dglazkove353a372016-09-01 01:33:481954 range->set_start(web_range.startOffset());
1955 range->set_end(web_range.endOffset());
[email protected]88dbe32f2013-06-20 23:31:361956 }
1957}
1958
[email protected]501ea13d2013-07-09 17:03:291959bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:511960 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:291961 const std::vector<gfx::Rect>& bounds) {
1962 if (composition_range_ != range)
1963 return true;
1964 if (bounds.size() != composition_character_bounds_.size())
1965 return true;
1966 for (size_t i = 0; i < bounds.size(); ++i) {
1967 if (bounds[i] != composition_character_bounds_[i])
1968 return true;
1969 }
1970 return false;
1971}
[email protected]501ea13d2013-07-09 17:03:291972
[email protected]ad26ef42011-06-17 07:59:451973bool RenderWidget::CanComposeInline() {
ekaramad2a46d632016-07-19 13:33:091974#if defined(ENABLE_PLUGINS)
1975 if (focused_pepper_plugin_)
1976 return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents();
1977#endif
[email protected]ad26ef42011-06-17 07:59:451978 return true;
[email protected]56ea1a62011-05-30 07:05:571979}
1980
ccameron2f451532016-09-07 21:49:271981blink::WebScreenInfo RenderWidget::screenInfo() {
1982 blink::WebScreenInfo web_screen_info;
1983 web_screen_info.deviceScaleFactor = screen_info_.device_scale_factor;
1984 web_screen_info.depth = screen_info_.depth;
1985 web_screen_info.depthPerComponent = screen_info_.depth_per_component;
1986 web_screen_info.isMonochrome = screen_info_.is_monochrome;
1987 web_screen_info.rect = blink::WebRect(screen_info_.rect);
1988 web_screen_info.availableRect = blink::WebRect(screen_info_.available_rect);
1989 switch (screen_info_.orientation_type) {
1990 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
1991 web_screen_info.orientationType =
1992 blink::WebScreenOrientationPortraitPrimary;
1993 break;
1994 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
1995 web_screen_info.orientationType =
1996 blink::WebScreenOrientationPortraitSecondary;
1997 break;
1998 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY:
1999 web_screen_info.orientationType =
2000 blink::WebScreenOrientationLandscapePrimary;
2001 break;
2002 case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY:
2003 web_screen_info.orientationType =
2004 blink::WebScreenOrientationLandscapeSecondary;
2005 break;
2006 default:
2007 web_screen_info.orientationType =
2008 blink::WebScreenOrientationUndefined;
2009 break;
2010 }
2011 web_screen_info.orientationAngle = screen_info_.orientation_angle;
2012 return web_screen_info;
[email protected]4873c7d2009-07-16 06:36:282013}
2014
[email protected]fa7b1dc2010-06-23 17:53:042015void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022016 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042017 // If the last text input type is not None, then we should finish any
2018 // ongoing composition regardless of the new text input type.
dglazkov03c1f672016-08-30 23:18:282019 if (text_input_info_.type != blink::WebTextInputTypeNone) {
[email protected]fa7b1dc2010-06-23 17:53:042020 // If a composition text exists, then we need to let the browser process
2021 // to cancel the input method's ongoing composition session.
aelias87b8f7c2016-09-14 03:19:292022 if (GetWebWidget()->finishComposingText(WebWidget::DoNotKeepSelection))
[email protected]a2214eb2014-06-23 18:31:222023 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042024 }
[email protected]d4cff272011-05-02 15:46:012025
nonafa291792016-08-10 02:36:182026 UpdateCompositionInfo(false /* not an immediate request */);
[email protected]fa7b1dc2010-06-23 17:53:042027}
2028
donnda070f3c2015-01-16 19:54:112029#if defined(OS_ANDROID)
2030void RenderWidget::showUnhandledTapUIIfNeeded(
2031 const WebPoint& tapped_position,
2032 const WebNode& tapped_node,
2033 bool page_changed) {
fsamuele8326c742016-01-12 00:49:392034 DCHECK(input_handler_->handling_input_event());
donnda070f3c2015-01-16 19:54:112035 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372036 !tapped_node.isContentEditable() &&
2037 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112038 if (should_trigger) {
2039 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2040 tapped_position.x, tapped_position.y));
2041 }
2042}
2043#endif
2044
[email protected]c68c3e4e2013-01-24 00:36:562045void RenderWidget::didHandleGestureEvent(
2046 const WebGestureEvent& event,
2047 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022048#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562049 if (event_cancelled)
2050 return;
[email protected]07c70d22014-08-21 08:33:462051 if (event.type == WebInputEvent::GestureTap) {
fsamuel72464894f2015-12-15 06:59:312052 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462053 } else if (event.type == WebInputEvent::GestureLongPress) {
lfg8ff33912016-09-13 20:59:212054 DCHECK(GetWebWidget());
2055 if (GetWebWidget()->textInputInfo().value.isEmpty())
fsamuel72464894f2015-12-15 06:59:312056 UpdateTextInputState(ShowIme::HIDE_IME, ChangeSource::FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462057 else
fsamuel72464894f2015-12-15 06:59:312058 UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562059 }
2060#endif
2061}
2062
sataya.m582c9ce2015-06-09 08:03:422063void RenderWidget::didOverscroll(
bokane53a10f2016-04-13 23:48:312064 const blink::WebFloatSize& overscrollDelta,
2065 const blink::WebFloatSize& accumulatedOverscroll,
sataya.m582c9ce2015-06-09 08:03:422066 const blink::WebFloatPoint& position,
2067 const blink::WebFloatSize& velocity) {
bokan731ec382016-04-07 03:16:482068#if defined(OS_MACOSX)
2069 // On OSX the user can disable the elastic overscroll effect. If that's the
2070 // case, don't forward the overscroll notification.
2071 DCHECK(compositor_deps());
2072 if (!compositor_deps()->IsElasticOverscrollEnabled())
2073 return;
2074#endif
bokane53a10f2016-04-13 23:48:312075 input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll,
fsamuele8326c742016-01-12 00:49:392076 position, velocity);
sataya.m582c9ce2015-06-09 08:03:422077}
2078
[email protected]7912e822014-04-16 02:37:032079void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392080 if (!is_hidden())
2081 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032082}
2083
[email protected]24ed0432013-04-24 07:50:312084RenderWidgetCompositor* RenderWidget::compositor() const {
2085 return compositor_.get();
2086}
2087
fsamuel72464894f2015-12-15 06:59:312088void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) {
fsamuele8326c742016-01-12 00:49:392089 input_handler_->set_handling_input_event(handling_input_event);
[email protected]67bfb83f2011-09-22 03:36:372090}
[email protected]c3d45532011-10-07 19:20:402091
fsamuel72464894f2015-12-15 06:59:312092bool RenderWidget::SendAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392093 return input_handler_->SendAckForMouseMoveFromDebugger();
[email protected]41d86852012-11-07 12:23:242094}
2095
fsamuel72464894f2015-12-15 06:59:312096void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
fsamuele8326c742016-01-12 00:49:392097 input_handler_->IgnoreAckForMouseMoveFromDebugger();
ccamerond4ba47902014-12-17 07:20:312098}
2099
[email protected]ce6689f2013-03-29 12:52:552100void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112101 if (render_widget_scheduling_state_)
2102 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552103 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2104}
2105
danakj365175c2016-02-06 00:37:372106// Check blink::WebTouchAction and content::TouchAction is kept in sync.
2107STATIC_ASSERT_ENUM(blink::WebTouchActionNone, TOUCH_ACTION_NONE);
2108STATIC_ASSERT_ENUM(blink::WebTouchActionPanLeft, TOUCH_ACTION_PAN_LEFT);
2109STATIC_ASSERT_ENUM(blink::WebTouchActionPanRight, TOUCH_ACTION_PAN_RIGHT);
2110STATIC_ASSERT_ENUM(blink::WebTouchActionPanX, TOUCH_ACTION_PAN_X);
2111STATIC_ASSERT_ENUM(blink::WebTouchActionPanUp, TOUCH_ACTION_PAN_UP);
2112STATIC_ASSERT_ENUM(blink::WebTouchActionPanDown, TOUCH_ACTION_PAN_DOWN);
2113STATIC_ASSERT_ENUM(blink::WebTouchActionPanY, TOUCH_ACTION_PAN_Y);
2114STATIC_ASSERT_ENUM(blink::WebTouchActionPan, TOUCH_ACTION_PAN);
2115STATIC_ASSERT_ENUM(blink::WebTouchActionPinchZoom, TOUCH_ACTION_PINCH_ZOOM);
2116STATIC_ASSERT_ENUM(blink::WebTouchActionManipulation,
2117 TOUCH_ACTION_MANIPULATION);
2118STATIC_ASSERT_ENUM(blink::WebTouchActionDoubleTapZoom,
2119 TOUCH_ACTION_DOUBLE_TAP_ZOOM);
2120STATIC_ASSERT_ENUM(blink::WebTouchActionAuto, TOUCH_ACTION_AUTO);
mostynbe29b6882015-01-13 09:59:172121
[email protected]5d0bbdfa92013-12-10 00:35:512122void RenderWidget::setTouchAction(
2123 blink::WebTouchAction web_touch_action) {
2124
2125 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2126 // when blink is emulating touch with mouse).
fsamuele8326c742016-01-12 00:49:392127 if (input_handler_->handling_event_type() != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512128 return;
2129
[email protected]a18f67a2013-12-20 19:44:362130 content::TouchAction content_touch_action =
2131 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512132 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2133}
2134
[email protected]90f24152014-04-09 12:41:362135void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2136#if defined(OS_ANDROID)
changwan8c342742016-02-26 00:53:392137 if (!IsUsingImeThread())
2138 text_field_is_dirty_ = true;
[email protected]90f24152014-04-09 12:41:362139#endif
2140}
2141
[email protected]e3244ed2014-06-20 20:04:272142void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2143 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162144}
2145
[email protected]e3244ed2014-06-20 20:04:272146void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2147 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162148}
2149
[email protected]de3c5d82014-05-28 22:12:592150void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2151 render_frames_.AddObserver(frame);
2152}
2153
2154void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2155 render_frames_.RemoveObserver(frame);
2156}
2157
lfg43e08e62016-02-03 18:51:372158void RenderWidget::OnWaitNextFrameForTests(int routing_id) {
2159 QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id),
2160 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2161}
2162
oshima50872a72016-03-04 13:26:182163float RenderWidget::GetOriginalDeviceScaleFactor() const {
2164 return
2165 screen_metrics_emulator_ ?
ccameron2f451532016-09-07 21:49:272166 screen_metrics_emulator_->original_screen_info().device_scale_factor :
oshima50872a72016-03-04 13:26:182167 device_scale_factor_;
2168}
2169
lfgbee1e0a2016-06-08 21:24:212170bool RenderWidget::requestPointerLock() {
2171 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2172}
2173
2174void RenderWidget::requestPointerUnlock() {
2175 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2176}
2177
2178bool RenderWidget::isPointerLocked() {
2179 return mouse_lock_dispatcher_->IsMouseLockedTo(
2180 webwidget_mouse_lock_target_.get());
2181}
2182
lfg8ff33912016-09-13 20:59:212183blink::WebWidget* RenderWidget::GetWebWidget() const {
2184 return webwidget_internal_;
2185}
2186
[email protected]e9ff79c2012-10-19 21:31:262187} // namespace content