blob: 0b8d2fff3b140a5c84568a477d7dee8ae028ff42 [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
[email protected]c27dd4f2014-05-22 18:05:197#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:218#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:009#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4012#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3013#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3814#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2115#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0016#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2717#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0118#include "base/trace_event/trace_event.h"
19#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4820#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5221#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3322#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3023#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_host.h"
[email protected]29e2fb42013-07-19 01:13:4725#include "content/child/npapi/webplugin.h"
[email protected]0634cdd42013-08-16 00:46:0926#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5927#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2928#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3529#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4430#include "content/common/input/web_input_event_traits.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"
[email protected]778574e2011-03-21 22:03:5033#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2934#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4235#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4036#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5137#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5938#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2939#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1140#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5941#include "content/renderer/gpu/mailbox_output_surface.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"
tfarina556a7232014-10-05 01:02:0951#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0452#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1853#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4854#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1855#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3056#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1157#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3058#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebSize.h"
61#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4362#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5963#include "third_party/WebKit/public/web/WebFrameWidget.h"
64#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1165#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3166#include "third_party/WebKit/public/web/WebPagePopup.h"
67#include "third_party/WebKit/public/web/WebPopupMenu.h"
68#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
69#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3870#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5971#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4172#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1373#include "ui/base/ui_base_switches.h"
[email protected]de2cf8c2013-10-25 19:46:4674#include "ui/gfx/frame_time.h"
tfarina655f81d2014-12-23 02:38:5075#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0976#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3277#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4878#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2779#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4881
[email protected]eeb93112013-05-01 19:41:1082#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1583#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0784#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1085#endif
86
[email protected]661eb9d2009-02-03 02:11:4887#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4988#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5289#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4190#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4891#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4492
[email protected]2255a9332013-06-17 05:12:3193#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2994
[email protected]180ef242013-11-07 06:50:4695using blink::WebCompositionUnderline;
96using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4397using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4698using blink::WebGestureEvent;
99using blink::WebInputEvent;
100using blink::WebKeyboardEvent;
101using blink::WebMouseEvent;
102using blink::WebMouseWheelEvent;
103using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11104using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46105using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11106using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46107using blink::WebPopupMenu;
108using blink::WebPopupMenuInfo;
109using blink::WebPopupType;
110using blink::WebRange;
111using blink::WebRect;
112using blink::WebScreenInfo;
113using blink::WebSize;
114using blink::WebTextDirection;
115using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25116using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46117using blink::WebVector;
118using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26119
[email protected]6a4d7f62013-01-07 21:32:13120namespace {
[email protected]b256eca2013-07-11 10:57:40121
122typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
123
124class TextInputModeMapSingleton {
125 public:
126 static TextInputModeMapSingleton* GetInstance() {
127 return Singleton<TextInputModeMapSingleton>::get();
128 }
[email protected]dd705d4d2013-11-27 08:14:41129 TextInputModeMapSingleton() {
130 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
131 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
132 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
133 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
134 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
135 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
136 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
137 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
138 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
139 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
140 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40141 }
[email protected]dd705d4d2013-11-27 08:14:41142 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40143 private:
[email protected]dd705d4d2013-11-27 08:14:41144 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40145
146 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
147
148 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
149};
150
[email protected]dd705d4d2013-11-27 08:14:41151ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40152 static TextInputModeMapSingleton* singleton =
153 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41154 TextInputModeMap::const_iterator it =
155 singleton->map().find(input_mode.utf8());
156 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40157 return ui::TEXT_INPUT_MODE_DEFAULT;
158 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13159}
[email protected]b256eca2013-07-11 10:57:40160
[email protected]fd847792013-10-24 17:12:35161// TODO(brianderson): Replace the hard-coded threshold with a fraction of
162// the BeginMainFrame interval.
163// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
164// be spent in input hanlders before input starts getting throttled.
165const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
166
jdduke07788062014-12-05 03:16:30167int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
168 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
169 .ToInternalValue();
170}
171
172void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
173 UMA_HISTOGRAM_CUSTOM_COUNTS(
174 "Event.AggregatedLatency.Renderer2",
175 GetEventLatencyMicros(event, now),
176 1,
177 10000000,
178 100);
179
180#define CASE_TYPE(t) \
181 case WebInputEvent::t: \
182 UMA_HISTOGRAM_CUSTOM_COUNTS( \
183 "Event.Latency.Renderer2." #t, \
184 GetEventLatencyMicros(event, now), \
185 1, \
186 10000000, \
187 100); \
188 break;
189
190 switch(event.type) {
191 CASE_TYPE(Undefined);
192 CASE_TYPE(MouseDown);
193 CASE_TYPE(MouseUp);
194 CASE_TYPE(MouseMove);
195 CASE_TYPE(MouseEnter);
196 CASE_TYPE(MouseLeave);
197 CASE_TYPE(ContextMenu);
198 CASE_TYPE(MouseWheel);
199 CASE_TYPE(RawKeyDown);
200 CASE_TYPE(KeyDown);
201 CASE_TYPE(KeyUp);
202 CASE_TYPE(Char);
203 CASE_TYPE(GestureScrollBegin);
204 CASE_TYPE(GestureScrollEnd);
205 CASE_TYPE(GestureScrollUpdate);
206 CASE_TYPE(GestureFlingStart);
207 CASE_TYPE(GestureFlingCancel);
208 CASE_TYPE(GestureShowPress);
209 CASE_TYPE(GestureTap);
210 CASE_TYPE(GestureTapUnconfirmed);
211 CASE_TYPE(GestureTapDown);
212 CASE_TYPE(GestureTapCancel);
213 CASE_TYPE(GestureDoubleTap);
214 CASE_TYPE(GestureTwoFingerTap);
215 CASE_TYPE(GestureLongPress);
216 CASE_TYPE(GestureLongTap);
217 CASE_TYPE(GesturePinchBegin);
218 CASE_TYPE(GesturePinchEnd);
219 CASE_TYPE(GesturePinchUpdate);
220 CASE_TYPE(TouchStart);
221 CASE_TYPE(TouchMove);
222 CASE_TYPE(TouchEnd);
223 CASE_TYPE(TouchCancel);
224 default:
225 // Must include default to let blink::WebInputEvent add new event types
226 // before they're added here.
227 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
228 break;
229 }
230
231#undef CASE_TYPE
232}
233
[email protected]b256eca2013-07-11 10:57:40234} // namespace
235
[email protected]e9ff79c2012-10-19 21:31:26236namespace content {
[email protected]62cb33cae2009-03-27 23:30:22237
[email protected]b2e4c70132013-10-03 02:07:51238// RenderWidget::ScreenMetricsEmulator ----------------------------------------
239
240class RenderWidget::ScreenMetricsEmulator {
241 public:
242 ScreenMetricsEmulator(
243 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43244 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51245 virtual ~ScreenMetricsEmulator();
246
[email protected]19193682014-04-03 15:01:43247 // Scale and offset used to convert between host coordinates
248 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51249 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20250 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43251 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51252 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56253 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51254
255 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43256 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51257
258 // The following methods alter handlers' behavior for messages related to
259 // widget size and position.
260 void OnResizeMessage(const ViewMsg_Resize_Params& params);
261 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
262 const gfx::Rect& window_screen_rect);
263 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31264 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51265
266 private:
[email protected]19193682014-04-03 15:01:43267 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02268 void Apply(bool top_controls_shrink_blink_size,
269 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44270 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12271 bool is_fullscreen_granted,
272 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51273
274 RenderWidget* widget_;
275
[email protected]7f99fc22013-11-08 14:05:58276 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43277 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51278
[email protected]a179d3962013-11-12 14:44:40279 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51280 float scale_;
dgozman9260b0a12015-03-16 13:45:20281 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51282
[email protected]19193682014-04-03 15:01:43283 // Widget rect as passed to webwidget.
284 gfx::Rect applied_widget_rect_;
285
[email protected]b2e4c70132013-10-03 02:07:51286 // Original values to restore back after emulation ends.
287 gfx::Size original_size_;
288 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28289 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46290 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51291 gfx::Rect original_view_screen_rect_;
292 gfx::Rect original_window_screen_rect_;
293};
294
295RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
296 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43297 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51298 : widget_(widget),
[email protected]19193682014-04-03 15:01:43299 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51300 scale_(1.f) {
301 original_size_ = widget_->size_;
302 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28303 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51304 original_screen_info_ = widget_->screen_info_;
305 original_view_screen_rect_ = widget_->view_screen_rect_;
306 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02307 Apply(widget_->top_controls_shrink_blink_size_,
308 widget_->top_controls_height_,
309 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12310 widget_->is_fullscreen_granted_,
311 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51312}
313
314RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
315 widget_->screen_info_ = original_screen_info_;
316
317 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20318 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51319 widget_->view_screen_rect_ = original_view_screen_rect_;
320 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01321 widget_->Resize(original_size_,
322 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02323 widget_->top_controls_shrink_blink_size_,
324 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01325 original_visible_viewport_size_,
326 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12327 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12328 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01329 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51330}
331
332void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43333 const WebDeviceEmulationParams& params) {
334 params_ = params;
335 Reapply();
336}
337
338void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02339 Apply(widget_->top_controls_shrink_blink_size_,
340 widget_->top_controls_height_,
341 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12342 widget_->is_fullscreen_granted_,
343 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51344}
345
[email protected]19193682014-04-03 15:01:43346void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02347 bool top_controls_shrink_blink_size,
348 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44349 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12350 bool is_fullscreen_granted,
351 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31352 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
353 if (!applied_widget_rect_.width())
354 applied_widget_rect_.set_width(original_size_.width());
355 if (!applied_widget_rect_.height())
356 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43357
[email protected]f442ee42014-05-14 11:53:12358 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02359 int original_width = std::max(original_size_.width(), 1);
360 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51361 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02362 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51363 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02364 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51365 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
366 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01367
368 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43369 offset_.set_x(
370 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01371 offset_.set_y(
[email protected]19193682014-04-03 15:01:43372 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51373 } else {
[email protected]0b3578c2014-06-20 18:29:02374 scale_ = params_.scale;
375 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01376 }
[email protected]7f0e8fa2014-03-26 12:32:01377
[email protected]19193682014-04-03 15:01:43378 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
379 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01380 widget_->screen_info_.rect = original_screen_info_.rect;
381 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
382 widget_->window_screen_rect_ = original_window_screen_rect_;
383 } else {
[email protected]19193682014-04-03 15:01:43384 applied_widget_rect_.set_origin(gfx::Point(0, 0));
385 widget_->screen_info_.rect = applied_widget_rect_;
386 widget_->screen_info_.availableRect = applied_widget_rect_;
387 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01388 }
[email protected]a179d3962013-11-12 14:44:40389
[email protected]19193682014-04-03 15:01:43390 float applied_device_scale_factor = params_.deviceScaleFactor ?
391 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01392 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51393
[email protected]7f99fc22013-11-08 14:05:58394 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51395 // - we keep the real device scale factor in compositor to produce sharp image
396 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58397 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51398 // root layer.
dgozman9260b0a12015-03-16 13:45:20399 blink::WebDeviceEmulationParams modified_params = params_;
400 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
401 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
402 modified_params.scale = scale_;
403 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51404
[email protected]7f0e8fa2014-03-26 12:32:01405 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43406 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51407
408 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
409 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02410 widget_->Resize(applied_widget_rect_.size(),
411 physical_backing_size,
412 top_controls_shrink_blink_size,
413 top_controls_height,
414 applied_widget_rect_.size(),
415 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12416 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12417 display_mode,
dtrainorcb7779b82014-12-04 01:08:02418 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51419}
420
421void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
422 const ViewMsg_Resize_Params& params) {
423 bool need_ack = params.new_size != original_size_ &&
424 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
425 original_size_ = params.new_size;
426 original_physical_backing_size_ = params.physical_backing_size;
427 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28428 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02429 Apply(params.top_controls_shrink_blink_size,
430 params.top_controls_height,
431 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12432 params.is_fullscreen_granted,
433 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51434
435 if (need_ack) {
436 widget_->set_next_paint_is_resize_ack();
437 if (widget_->compositor_)
438 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
439 }
440}
441
442void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
443 const gfx::Rect& view_screen_rect,
444 const gfx::Rect& window_screen_rect) {
445 original_view_screen_rect_ = view_screen_rect;
446 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43447 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
448 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51449}
450
451void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
452 ContextMenuParams* params) {
453 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40454 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51455 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40456 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51457}
458
[email protected]2d6836f42014-07-02 17:25:31459gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
460 const gfx::Rect& anchor) {
461 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
462 scaled.set_x(scaled.x() + offset_.x());
463 scaled.set_y(scaled.y() + offset_.y());
464 return scaled;
465}
466
[email protected]b2e4c70132013-10-03 02:07:51467// RenderWidget ---------------------------------------------------------------
468
[email protected]180ef242013-11-07 06:50:46469RenderWidget::RenderWidget(blink::WebPopupType popup_type,
470 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04471 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03472 bool hidden,
473 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29474 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56475 surface_id_(0),
danakj6e3bf8012014-12-16 18:27:53476 compositor_deps_(nullptr),
477 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29478 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30479 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02480 top_controls_shrink_blink_size_(false),
481 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29482 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51483 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09484 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29485 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04486 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03487 never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12488 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12489 display_mode_(blink::WebDisplayModeUndefined),
initial.commit09911bf2008-07-26 23:55:29490 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49491 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50492 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19493 handling_event_type_(WebInputEvent::Undefined),
494 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48495 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22496 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44497 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20498 for_oopif_(false),
[email protected]fa7b1dc2010-06-23 17:53:04499 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45500 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40501 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20502 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53503 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12504 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48505 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12506 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04507 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52508 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43509 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30510 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13511#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36512 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13513 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10514 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13515#endif
[email protected]b2e4c70132013-10-03 02:07:51516 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11517 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42518 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51519 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
520 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05521 if (!swapped_out)
522 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27523 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53524 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29525}
526
527RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11528 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16529
[email protected]992db4c2011-05-12 15:37:15530 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02531 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15532 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29533}
534
[email protected]484955942010-08-19 16:13:18535// static
[email protected]8085dbc82008-09-26 22:53:44536RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53537 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46538 blink::WebPopupType popup_type,
539 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29540 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41541 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03542 new RenderWidget(popup_type, screen_info, false, false, false));
danakj6e3bf8012014-12-16 18:27:53543 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46544 return widget.get();
[email protected]a635f942012-12-07 10:34:29545 }
546 return NULL;
initial.commit09911bf2008-07-26 23:55:29547}
548
[email protected]484955942010-08-19 16:13:18549// static
kenrba7199832015-01-22 23:44:59550RenderWidget* RenderWidget::CreateForFrame(
551 int routing_id,
552 int surface_id,
553 bool hidden,
554 const blink::WebScreenInfo& screen_info,
555 CompositorDependencies* compositor_deps,
556 blink::WebLocalFrame* frame) {
557 CHECK_NE(routing_id, MSG_ROUTING_NONE);
558 scoped_refptr<RenderWidget> widget(new RenderWidget(
559 blink::WebPopupTypeNone, screen_info, false, hidden, false));
560 widget->routing_id_ = routing_id;
561 widget->surface_id_ = surface_id;
562 widget->compositor_deps_ = compositor_deps;
simonhong628f9812015-04-27 23:13:20563 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59564 // DoInit increments the reference count on |widget|, keeping it alive after
565 // this function returns.
566 if (widget->DoInit(MSG_ROUTING_NONE, compositor_deps,
567 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
568 nullptr)) {
569 widget->CompleteInit();
570 return widget.get();
571 }
572 return nullptr;
573}
574
575// static
576blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18577 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46578 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18579 break;
[email protected]180ef242013-11-07 06:50:46580 case blink::WebPopupTypeSelect:
581 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18582 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46583 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44584 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18585 default:
586 NOTREACHED();
587 }
588 return NULL;
589}
590
kenrba7199832015-01-22 23:44:59591// static
592blink::WebWidget* RenderWidget::CreateWebFrameWidget(
593 RenderWidget* render_widget,
594 blink::WebLocalFrame* frame) {
595 return blink::WebFrameWidget::create(render_widget, frame);
596}
597
danakj6e3bf8012014-12-16 18:27:53598bool RenderWidget::Init(int32 opener_id,
599 CompositorDependencies* compositor_deps) {
600 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29601 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
602 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18603}
604
[email protected]a635f942012-12-07 10:34:29605bool RenderWidget::DoInit(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53606 CompositorDependencies* compositor_deps,
[email protected]6a8ddba52010-09-05 04:38:06607 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18608 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29609 DCHECK(!webwidget_);
610
611 if (opener_id != MSG_ROUTING_NONE)
612 opener_id_ = opener_id;
613
danakj6e3bf8012014-12-16 18:27:53614 compositor_deps_ = compositor_deps;
[email protected]484955942010-08-19 16:13:18615 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29616
kenrba7199832015-01-22 23:44:59617 bool result = true;
618 if (create_widget_message)
619 result = RenderThread::Get()->Send(create_widget_message);
620
initial.commit09911bf2008-07-26 23:55:29621 if (result) {
[email protected]380244092011-10-07 17:26:27622 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29623 // Take a reference on behalf of the RenderThread. This will be balanced
624 // when we receive ViewMsg_Close.
625 AddRef();
[email protected]b2db9272014-01-10 17:42:00626 if (RenderThreadImpl::current()) {
627 RenderThreadImpl::current()->WidgetCreated();
628 if (is_hidden_)
629 RenderThreadImpl::current()->WidgetHidden();
630 }
[email protected]a635f942012-12-07 10:34:29631 return true;
initial.commit09911bf2008-07-26 23:55:29632 } else {
[email protected]a635f942012-12-07 10:34:29633 // The above Send can fail when the tab is closing.
634 return false;
initial.commit09911bf2008-07-26 23:55:29635 }
636}
637
[email protected]fc4404d2012-11-07 19:53:30638// This is used to complete pending inits and non-pending inits.
639void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29640 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29641
[email protected]fc4404d2012-11-07 19:53:30642 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42643
[email protected]7912e822014-04-16 02:37:03644 if (compositor_)
645 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29646
[email protected]6de74452009-02-25 18:04:59647 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29648}
649
[email protected]992db4c2011-05-12 15:37:15650void RenderWidget::SetSwappedOut(bool is_swapped_out) {
651 // We should only toggle between states.
652 DCHECK(is_swapped_out_ != is_swapped_out);
653 is_swapped_out_ = is_swapped_out;
654
655 // If we are swapping out, we will call ReleaseProcess, allowing the process
656 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52657 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15658 // If we are swapping in, we call AddRefProcess to prevent the process from
659 // exiting.
[email protected]949b6592014-08-20 13:17:52660 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15661 RenderProcess::current()->AddRefProcess();
662}
663
[email protected]949b6592014-08-20 13:17:52664void RenderWidget::WasSwappedOut() {
665 // If we have been swapped out and no one else is using this process,
666 // it's safe to exit now.
667 CHECK(is_swapped_out_);
668 RenderProcess::current()->ReleaseProcess();
669}
670
[email protected]b2e4c70132013-10-03 02:07:51671void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
672 ScreenMetricsEmulator* emulator) {
673 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43674 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49675 popup_screen_origin_for_emulation_ = gfx::Point(
676 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
677 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56678 screen_info_ = emulator->original_screen_info();
679 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51680}
681
[email protected]2d6836f42014-07-02 17:25:31682gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
683 if (screen_metrics_emulator_)
684 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
685 return anchor;
686}
687
[email protected]b2e4c70132013-10-03 02:07:51688void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20689 bool enabled,
690 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51691 // This is only supported in RenderView.
692 NOTREACHED();
693}
694
[email protected]53907862014-03-25 15:42:40695#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51696void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
697 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49698 popup->SetOriginScaleAndOffsetForEmulation(
699 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51700}
[email protected]53907862014-03-25 15:42:40701#endif
[email protected]b2e4c70132013-10-03 02:07:51702
703void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
704 if (screen_metrics_emulator_)
705 screen_metrics_emulator_->OnShowContextMenu(params);
706}
707
[email protected]7d08a9352013-10-15 08:24:56708void RenderWidget::ScheduleCompositeWithForcedRedraw() {
709 if (compositor_) {
710 // Regardless of whether threaded compositing is enabled, always
711 // use this mechanism to force the compositor to redraw. However,
712 // the invalidation code path below is still needed for the
713 // non-threaded case.
714 compositor_->SetNeedsForcedRedraw();
715 }
[email protected]8b9e52b2014-01-17 16:35:31716 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56717}
718
[email protected]a95986a82010-12-24 06:19:28719bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
720 bool handled = true;
721 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15722 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22723 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
724 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22725 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
726 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15727 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
728 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35729 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
730 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28731 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
732 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
733 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20734 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
735 OnEnableDeviceEmulation)
736 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
737 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41738 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54739 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28740 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41741 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28742 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17743 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
744 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
745 OnCandidateWindowUpdated)
746 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25747 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28748 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
749 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03750 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21751#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51752 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13753 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21754#endif
[email protected]a95986a82010-12-24 06:19:28755 IPC_MESSAGE_UNHANDLED(handled = false)
756 IPC_END_MESSAGE_MAP()
757 return handled;
758}
initial.commit09911bf2008-07-26 23:55:29759
760bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15761 // Don't send any messages after the browser has told us to close, and filter
762 // most outgoing messages while swapped out.
763 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26764 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11765 closing_) {
initial.commit09911bf2008-07-26 23:55:29766 delete message;
767 return false;
768 }
769
770 // If given a messsage without a routing ID, then assign our routing ID.
771 if (message->routing_id() == MSG_ROUTING_NONE)
772 message->set_routing_id(routing_id_);
773
[email protected]380244092011-10-07 17:26:27774 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44775}
776
[email protected]61e2b3cc2012-03-02 16:13:34777void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44778 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02779 bool top_controls_shrink_blink_size,
780 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44781 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34782 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12783 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12784 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58785 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56786 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48787 // A resize ack shouldn't be requested if we have not ACK'd the previous
788 // one.
789 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
790 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
791 }
initial.commit09911bf2008-07-26 23:55:29792
[email protected]61e2b3cc2012-03-02 16:13:34793 // Ignore this during shutdown.
794 if (!webwidget_)
795 return;
796
[email protected]d9083762013-03-24 01:36:40797 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44798 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40799 }
[email protected]60d47ac2013-03-01 23:42:44800
[email protected]dade8992013-03-04 07:34:34801 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02802 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
803 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28804 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34805 resizer_rect_ = resizer_rect;
806
807 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12808 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
[email protected]61e2b3cc2012-03-02 16:13:34809 if (fullscreen_change)
810 WillToggleFullscreen();
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12811 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12812 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34813
aelias6004fe02015-02-07 21:43:01814 webwidget_->setTopControlsHeight(top_controls_height,
815 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43816
[email protected]61e2b3cc2012-03-02 16:13:34817 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34818 size_ = new_size;
819
[email protected]61e2b3cc2012-03-02 16:13:34820 // When resizing, we want to wait to paint before ACK'ing the resize. This
821 // ensures that we only resize as fast as we can paint. We only need to
822 // send an ACK if we are resized to a non-empty rect.
823 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45824 }
825
[email protected]bb6378fe2014-04-28 21:19:44826 webwidget()->resizePinchViewport(gfx::Size(
827 visible_viewport_size.width(),
828 visible_viewport_size.height()));
829
[email protected]632c4382013-05-15 08:58:45830 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58831 // In this case there is no paint/composite and therefore no
832 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
833 // ack through a fake ViewHostMsg_UpdateRect or a different message.
834 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34835 }
836
[email protected]20fbfc22013-05-08 20:50:58837 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45838 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58839 set_next_paint_is_resize_ack();
840
[email protected]61e2b3cc2012-03-02 16:13:34841 if (fullscreen_change)
842 DidToggleFullscreen();
843
844 // If a resize ack is requested and it isn't set-up, then no more resizes will
845 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45846 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29847}
848
bokanc007c3a2015-02-03 07:15:56849void RenderWidget::SetWindowRectSynchronously(
850 const gfx::Rect& new_window_rect) {
851 Resize(new_window_rect.size(),
852 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02853 top_controls_shrink_blink_size_,
854 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56855 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01856 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12857 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12858 display_mode_,
[email protected]587941d2014-08-22 01:40:01859 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56860 view_screen_rect_ = new_window_rect;
861 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02862 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56863 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02864}
865
initial.commit09911bf2008-07-26 23:55:29866void RenderWidget::OnClose() {
867 if (closing_)
868 return;
dgozmancf9039cd2015-04-06 12:01:31869 NotifyOnClose();
initial.commit09911bf2008-07-26 23:55:29870 closing_ = true;
871
872 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03873 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27874 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03875 SetHidden(false);
rmcilroyaa296052015-04-14 15:35:27876 if (RenderThreadImpl::current())
877 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]bee16aab2009-08-26 15:55:03878 }
initial.commit09911bf2008-07-26 23:55:29879
initial.commit09911bf2008-07-26 23:55:29880 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25881 // now. Post a task that only gets invoked when there are no nested message
882 // loops.
alexclarkee19d4ef2015-01-09 17:45:40883 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29884 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25885
886 // Balances the AddRef taken when we called AddRoute.
887 Release();
initial.commit09911bf2008-07-26 23:55:29888}
889
[email protected]61e2b3cc2012-03-02 16:13:34890// Got a response from the browser after the renderer decided to create a new
891// view.
[email protected]fc4404d2012-11-07 19:53:30892void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34893 DCHECK(routing_id_ != MSG_ROUTING_NONE);
894
[email protected]fc4404d2012-11-07 19:53:30895 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34896}
897
[email protected]0fdd5012013-05-29 08:05:56898void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04899 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32900 return;
901
[email protected]b2e4c70132013-10-03 02:07:51902 if (screen_metrics_emulator_) {
903 screen_metrics_emulator_->OnResizeMessage(params);
904 return;
905 }
906
[email protected]fcdc5642014-05-09 14:32:24907 bool orientation_changed =
908 screen_info_.orientationAngle != params.screen_info.orientationAngle;
909
[email protected]0fdd5012013-05-29 08:05:56910 screen_info_ = params.screen_info;
911 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02912 Resize(params.new_size,
913 params.physical_backing_size,
914 params.top_controls_shrink_blink_size,
915 params.top_controls_height,
916 params.visible_viewport_size,
917 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12918 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12919 params.display_mode,
sievers4e33dae2015-02-25 20:43:58920 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24921
922 if (orientation_changed)
923 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29924}
925
dgozman9260b0a12015-03-16 13:45:20926void RenderWidget::OnEnableDeviceEmulation(
927 const blink::WebDeviceEmulationParams& params) {
928 if (!screen_metrics_emulator_)
929 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
930 else
931 screen_metrics_emulator_->ChangeEmulationParams(params);
932}
933
934void RenderWidget::OnDisableDeviceEmulation() {
935 screen_metrics_emulator_.reset();
936}
937
noel89949e62014-09-30 01:12:41938void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
939 SetDeviceColorProfile(color_profile);
940}
941
[email protected]b5913d72012-02-07 22:26:54942void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01943 if (resizer_rect_ == resizer_rect)
944 return;
945 resizer_rect_ = resizer_rect;
946 if (webwidget_)
947 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54948}
949
initial.commit09911bf2008-07-26 23:55:29950void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31951 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29952 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03953 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59954 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
955 WasHidden());
initial.commit09911bf2008-07-26 23:55:29956}
957
[email protected]3399dd822014-08-09 11:14:24958void RenderWidget::OnWasShown(bool needs_repainting,
959 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41960 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29961 // During shutdown we can just ignore this message.
962 if (!webwidget_)
963 return;
964
965 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03966 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59967 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
968 WasShown());
initial.commit09911bf2008-07-26 23:55:29969
[email protected]8a23afb32014-04-30 22:40:23970 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29971 return;
initial.commit09911bf2008-07-26 23:55:29972
973 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24974 if (compositor_) {
975 ui::LatencyInfo swap_latency_info(latency_info);
976 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
977 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05978 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24979 }
[email protected]aca33f4f2014-05-17 17:08:05980 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29981}
982
[email protected]53d3f302009-12-21 04:42:05983void RenderWidget::OnRequestMoveAck() {
984 DCHECK(pending_window_rect_count_);
985 pending_window_rect_count_--;
986}
987
[email protected]ed7defa2013-03-12 21:29:59988GURL RenderWidget::GetURLForGraphicsContext3D() {
989 return GURL();
[email protected]65225772011-05-12 21:10:24990}
991
[email protected]ebc0e1df2013-08-01 02:46:22992scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03993 // For widgets that are never visible, we don't start the compositor, so we
994 // never get a request for a cc::OutputSurface.
995 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19996
997#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01998 if (SynchronousCompositorFactory* factory =
999 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:111000 return factory->CreateOutputSurface(routing_id(),
1001 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:191002 }
1003#endif
1004
avi83883c82014-12-23 00:08:491005 const base::CommandLine& command_line =
1006 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:331007 bool use_software = fallback;
1008 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1009 use_software = true;
1010
[email protected]0634cdd42013-08-16 00:46:091011 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171012 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331013 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091014 context_provider = ContextProviderCommandBuffer::Create(
sieversfbaa5dc2015-04-28 00:45:311015 CreateGraphicsContext3D(), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:331016 if (!context_provider.get()) {
1017 // Cause the compositor to wait and try again.
1018 return scoped_ptr<cc::OutputSurface>();
1019 }
vmiura78b69282015-02-14 00:01:171020
1021 worker_context_provider = ContextProviderCommandBuffer::Create(
sieversfbaa5dc2015-04-28 00:45:311022 CreateGraphicsContext3D(), RENDER_WORKER_CONTEXT);
vmiura78b69282015-02-14 00:01:171023 if (!worker_context_provider.get()) {
1024 // Cause the compositor to wait and try again.
1025 return scoped_ptr<cc::OutputSurface>();
1026 }
[email protected]0634cdd42013-08-16 00:46:091027 }
[email protected]ebc0e1df2013-08-01 02:46:221028
[email protected]b6eb8e332013-09-10 00:51:011029 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001030 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531031 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
caseqff9c74c2015-02-10 14:56:291032 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171033 routing_id(), output_surface_id, context_provider,
1034 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091035 }
[email protected]0634cdd42013-08-16 00:46:091036 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091037 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121038 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091039
caseqff9c74c2015-02-10 14:56:291040 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
1041 routing_id(), output_surface_id, nullptr, nullptr,
1042 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221043 }
[email protected]ed7defa2013-03-12 21:29:591044
[email protected]36e5ff12013-06-11 12:19:291045 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451046 // Composite-to-mailbox is currently used for layout tests in order to cause
1047 // them to draw inside in the renderer to do the readback there. This should
1048 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531049 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161050 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271051 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161052 format = cc::RGB_565;
caseqff9c74c2015-02-10 14:56:291053 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171054 routing_id(), output_surface_id, context_provider,
1055 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1056 frame_swap_message_queue_, format));
[email protected]36e5ff12013-06-11 12:19:291057 }
[email protected]0634cdd42013-08-16 00:46:091058 bool use_swap_compositor_frame_message = false;
caseqff9c74c2015-02-10 14:56:291059 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171060 routing_id(), output_surface_id, context_provider,
1061 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1062 frame_swap_message_queue_, use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281063}
1064
[email protected]4d7e46a2013-11-08 05:33:401065void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241066 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241067 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311068 scheduleComposite();
[email protected]65225772011-05-12 21:10:241069}
1070
[email protected]4d7e46a2013-11-08 05:33:401071void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081072 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081073}
1074
[email protected]4d7e46a2013-11-08 05:33:401075void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241076 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161077
[email protected]404939f2012-06-01 04:06:181078 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161079 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291080}
1081
[email protected]180ef242013-11-07 06:50:461082void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351083 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091084 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191085 base::AutoReset<bool> handling_input_event_resetter(
1086 &handling_input_event_, true);
1087 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291088 return;
[email protected]c27dd4f2014-05-22 18:05:191089 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1090 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521091#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541092 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521093 // |AdapterInputConnection| generates input key events to make sure all JS
1094 // listeners that monitor KeyUp and KeyDown events receive the proper key
1095 // code. Since this input key event comes from IME, we need to set the
1096 // IME event guard here to make sure it does not interfere with other IME
1097 // events.
1098 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1099 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1100 const WebKeyboardEvent& key_event =
1101 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541102 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171103 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091104 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1105 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1106 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1107 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1108 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521109 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521110 }
1111#endif
initial.commit09911bf2008-07-26 23:55:291112
[email protected]8062ab262014-05-27 16:56:431113 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1114 &latency_info);
1115
[email protected]fd847792013-10-24 17:12:351116 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411117 if (base::TimeTicks::IsHighResolution())
1118 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351119
miletusfed8c43b2015-01-26 20:04:521120 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301121 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151122 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131123 TRACE_EVENT_FLOW_STEP0(
miletusfed8c43b2015-01-26 20:04:521124 "input,benchmark",
[email protected]15ba6dea2014-04-02 01:44:131125 "LatencyInfo.Flow",
1126 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1127 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101128
jdduke07788062014-12-05 03:16:301129 // If we don't have a high res timer, these metrics won't be accurate enough
1130 // to be worth collecting. Note that this does introduce some sampling bias.
1131 if (!start_time.is_null())
1132 LogInputEventLatencyUma(*input_event, start_time);
1133
[email protected]6be422b2013-12-08 06:47:311134 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351135 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311136 if (compositor_) {
1137 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351138 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1139 .Pass();
[email protected]6be422b2013-12-08 06:47:311140 }
[email protected]c2eaa8f2013-05-10 02:41:551141
[email protected]67bfb83f2011-09-22 03:36:371142 bool prevent_default = false;
1143 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261144 const WebMouseEvent& mouse_event =
1145 *static_cast<const WebMouseEvent*>(input_event);
1146 TRACE_EVENT2("renderer", "HandleMouseMove",
1147 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421148 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261149 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371150 }
1151
[email protected]cefe9b152014-03-27 18:16:151152 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421153 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151154#if defined(OS_ANDROID)
1155 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1156 // case it should behave like a select key (i.e. causing a click if a button
1157 // is focused). However, if a text field is focused (2), its intended
1158 // behavior is to just show the IME and don't propagate the key.
1159 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1160 // when clicked on an input text field and cause the form submit if clicked
1161 // when the submit button is focused, but not vice-versa.
1162 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1163 // but at this point we have to swallow the event for the scenario (2).
1164 const WebKeyboardEvent& key_event =
1165 *static_cast<const WebKeyboardEvent*>(input_event);
1166 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1167 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1168 OnShowImeIfNeeded();
1169 prevent_default = true;
1170 }
1171#endif
1172 }
[email protected]f56c7872013-06-18 12:31:571173
[email protected]41d86852012-11-07 12:23:241174 if (WebInputEvent::isGestureEventType(input_event->type)) {
1175 const WebGestureEvent& gesture_event =
1176 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421177 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241178 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1179 }
1180
[email protected]67bfb83f2011-09-22 03:36:371181 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121182 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1183 suppress_next_char_events_ = false;
1184 if (!processed && webwidget_)
1185 processed = webwidget_->handleInputEvent(*input_event);
1186 }
1187
1188 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1189 // it's not processed by webkit, then we need to suppress the upcoming Char
1190 // events.
1191 if (!processed && is_keyboard_shortcut)
1192 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291193
[email protected]3d5c243b2012-11-30 00:26:011194 InputEventAckState ack_result = processed ?
1195 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1196 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1197 const WebTouchEvent& touch_event =
1198 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251199 // Hit-test for all the pressed touch points. If there is a touch-handler
1200 // for any of the touch points, then the renderer should continue to receive
1201 // touch events.
1202 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1203 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1204 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271205 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391206 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251207 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1208 break;
1209 }
1210 }
[email protected]3d5c243b2012-11-30 00:26:011211 }
1212
ccamerond4ba47902014-12-17 07:20:311213 // Send mouse wheel events and their disposition to the compositor thread, so
1214 // that they can be used to produce the elastic overscroll effect on Mac.
1215 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311216 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311217 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1218 }
1219
[email protected]721e2302014-04-30 23:42:011220 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061221
charliea3be839702015-01-26 17:35:411222 // If we don't have a fast and accurate Now(), we assume the input handlers
1223 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301224 bool rate_limiting_wanted =
1225 input_event->type == WebInputEvent::MouseMove ||
1226 input_event->type == WebInputEvent::MouseWheel;
1227 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411228 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351229 total_input_handling_time_this_frame_ += (end_time - start_time);
1230 rate_limiting_wanted =
1231 total_input_handling_time_this_frame_.InMicroseconds() >
1232 kInputHandlingTimeThrottlingThresholdMicroseconds;
1233 }
1234
[email protected]7f19e9d2014-05-09 15:16:291235 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1236
[email protected]c27dd4f2014-05-22 18:05:191237 // Note that we can't use handling_event_type_ here since it will be overriden
1238 // by reentrant calls for events after the paused one.
1239 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1240 input_event->type == WebInputEvent::MouseMove;
1241 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561242 InputHostMsg_HandleInputEvent_ACK_Params ack;
1243 ack.type = input_event->type;
1244 ack.state = ack_result;
1245 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551246 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561247 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301248 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551249 // We want to rate limit the input events in this case, so we'll wait for
1250 // painting to finish before ACKing this message.
1251 TRACE_EVENT_INSTANT0("renderer",
1252 "RenderWidget::OnHandleInputEvent ack throttled",
1253 TRACE_EVENT_SCOPE_THREAD);
1254 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291255 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1256 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551257 // As two different kinds of events could cause us to postpone an ack
1258 // we send it now, if we have one pending. The Browser should never
1259 // send us the same kind of event we are delaying the ack for.
1260 Send(pending_input_event_ack_.release());
1261 }
1262 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291263 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1264 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551265 if (compositor_)
1266 compositor_->NotifyInputThrottledUntilCommit();
1267 } else {
1268 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171269 }
[email protected]12fbad812009-09-01 18:21:241270 }
[email protected]5fea4a52014-05-27 00:17:521271 if (input_event->type == WebInputEvent::MouseMove)
1272 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241273
[email protected]3306f262012-09-21 19:20:421274#if defined(OS_ANDROID)
1275 // Allow the IME to be shown when the focus changes as a consequence
1276 // of a processed touch end event.
1277 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361278 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021279#elif defined(USE_AURA)
1280 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1281 // change.
1282 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141283 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361284 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141285 }
[email protected]3306f262012-09-21 19:20:421286#endif
1287
[email protected]67bfb83f2011-09-22 03:36:371288 if (!prevent_default) {
1289 if (WebInputEvent::isKeyboardEventType(input_event->type))
1290 DidHandleKeyEvent();
1291 if (WebInputEvent::isMouseEventType(input_event->type))
1292 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
1293 }
rouslanf7ebd8832015-01-22 01:54:141294
1295// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1296// virtual keyboard.
1297#if !defined(OS_ANDROID)
1298 // Virtual keyboard is not supported, so react to focus change immediately.
1299 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1300 input_event->type == WebInputEvent::MouseUp)) {
1301 FocusChangeComplete();
1302 }
1303#endif
initial.commit09911bf2008-07-26 23:55:291304}
1305
[email protected]34202de2013-05-06 23:36:221306void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1307 if (webwidget_)
1308 webwidget_->setCursorVisibilityState(is_visible);
1309}
1310
initial.commit09911bf2008-07-26 23:55:291311void RenderWidget::OnMouseCaptureLost() {
1312 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281313 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291314}
1315
1316void RenderWidget::OnSetFocus(bool enable) {
1317 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331318 if (webwidget_)
1319 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291320}
1321
1322void RenderWidget::ClearFocus() {
1323 // We may have got the focus from the browser before this gets processed, in
1324 // which case we do not want to unfocus ourself.
1325 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281326 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291327}
1328
[email protected]fd847792013-10-24 17:12:351329void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291330 if (pending_input_event_ack_) {
1331 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1332 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071333 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291334 }
[email protected]fd847792013-10-24 17:12:351335 total_input_handling_time_this_frame_ = base::TimeDelta();
1336}
1337
initial.commit09911bf2008-07-26 23:55:291338///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461339// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291340
[email protected]244ac1892011-12-02 17:04:471341void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091342 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451343 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581344
[email protected]5b45ad42013-10-25 00:42:041345 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451346 WebRect new_pos(rootWindowRect().x,
1347 rootWindowRect().y,
1348 new_size.width,
1349 new_size.height);
1350 view_screen_rect_ = new_pos;
1351 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031352 }
[email protected]20fbfc22013-05-08 20:50:581353
[email protected]eac2b362013-05-22 07:01:451354 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581355
[email protected]5b45ad42013-10-25 00:42:041356 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581357 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091358 }
[email protected]244ac1892011-12-02 17:04:471359}
1360
[email protected]3a1c8a8032013-03-18 22:35:321361void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051362 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1363 device_scale_factor_));
1364 if (compositor_)
1365 compositor_->setViewportSize(size_, physical_backing_size_);
1366}
1367
[email protected]e195e582013-03-08 01:32:591368void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221369 DCHECK(!host_closing_);
1370
danakj6e3bf8012014-12-16 18:27:531371 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591372 compositor_->setViewportSize(size_, physical_backing_size_);
1373 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031374 StartCompositor();
[email protected]e195e582013-03-08 01:32:591375}
1376
ennef3c58142014-12-09 21:44:381377void RenderWidget::WillCloseLayerTreeView() {
1378 if (host_closing_)
1379 return;
1380
1381 // Prevent new compositors or output surfaces from being created.
1382 host_closing_ = true;
1383
[email protected]aeeedad2014-08-22 18:16:221384 // Always send this notification to prevent new layer tree views from
1385 // being created, even if one hasn't been created yet.
1386 if (webwidget_)
1387 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221388}
1389
[email protected]180ef242013-11-07 06:50:461390blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281391 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061392}
1393
[email protected]9cd43a62012-03-26 08:03:561394void RenderWidget::willBeginCompositorFrame() {
1395 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371396
[email protected]abe8b3a2012-03-28 21:19:371397 // The following two can result in further layout and possibly
1398 // enable GPU acceleration so they need to be called before any painting
1399 // is done.
shuchen3517bb62014-10-15 03:55:571400 UpdateTextInputType();
1401#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361402 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571403#endif
[email protected]abe8b3a2012-03-28 21:19:371404 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561405}
1406
[email protected]3391a0772012-03-28 00:32:071407void RenderWidget::didBecomeReadyForAdditionalInput() {
1408 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351409 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071410}
1411
[email protected]6fceb912013-02-15 06:24:151412void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441413 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1414 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271415 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161416 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171417#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271418 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1419 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171420#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151421}
1422
[email protected]586871b2014-07-22 17:05:111423// static
1424scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1425 IPC::Message* msg,
1426 MessageDeliveryPolicy policy,
1427 FrameSwapMessageQueue* frame_swap_message_queue,
1428 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111429 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111430 bool first_message_for_frame = false;
1431 frame_swap_message_queue->QueueMessageForFrame(policy,
1432 source_frame_number,
1433 make_scoped_ptr(msg),
1434 &first_message_for_frame);
1435 if (first_message_for_frame) {
1436 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1437 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061438 return promise;
[email protected]586871b2014-07-22 17:05:111439 }
dcheng4b6b5ff2014-10-16 00:42:061440 return nullptr;
[email protected]586871b2014-07-22 17:05:111441}
1442
1443void RenderWidget::QueueMessage(IPC::Message* msg,
1444 MessageDeliveryPolicy policy) {
1445 // RenderThreadImpl::current() is NULL in some tests.
1446 if (!compositor_ || !RenderThreadImpl::current()) {
1447 Send(msg);
1448 return;
1449 }
1450
1451 scoped_ptr<cc::SwapPromise> swap_promise =
1452 QueueMessageImpl(msg,
1453 policy,
dcheng58867a92014-08-26 02:50:221454 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111455 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111456 compositor_->GetSourceFrameNumber());
1457
1458 if (swap_promise) {
1459 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351460 // Request a commit. This might either A) request a commit ahead of time
1461 // or B) request a commit which is not needed because there are not
1462 // pending updates. If B) then the commit will be skipped and the swap
1463 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1464 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1465 // can_cancel_commit is not unset.
1466 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111467 }
1468}
1469
[email protected]58264a32011-11-17 23:36:151470void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101471 // NOTE: Tests may break if this event is renamed or moved. See
1472 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501473 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161474 // Notify subclasses that we initiated the paint operation.
1475 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151476}
1477
1478void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181479 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1480
1481 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561482 DidFlushPaint();
1483
[email protected]ea3ee0a2012-05-15 03:43:091484 if (!next_paint_flags_ &&
1485 !need_update_rect_for_auto_resize_ &&
1486 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151487 return;
[email protected]ea3ee0a2012-05-15 03:43:091488 }
[email protected]58264a32011-11-17 23:36:151489
1490 ViewHostMsg_UpdateRect_Params params;
1491 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151492 params.plugin_window_moves.swap(plugin_window_moves_);
1493 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151494
1495 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1496 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091497 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151498}
1499
[email protected]8b9e52b2014-01-17 16:35:311500void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531501 if (compositor_ &&
1502 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221503 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311504 }
1505}
1506
[email protected]4873c7d2009-07-16 06:36:281507void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301508 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521509 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401510 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291511 // Only send a SetCursor message if we need to make a change.
1512 if (!current_cursor_.IsEqual(cursor)) {
1513 current_cursor_ = cursor;
1514 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1515 }
1516}
1517
1518// We are supposed to get a single call to Show for a newly created RenderWidget
1519// that was created via RenderWidget::CreateWebView. So, we wait until this
1520// point to dispatch the ShowWidget message.
1521//
1522// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281523// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291524//
[email protected]4873c7d2009-07-16 06:36:281525void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291526 DCHECK(!did_show_) << "received extraneous Show call";
1527 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1528 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1529
[email protected]8de12d942010-11-17 20:42:441530 if (did_show_)
1531 return;
1532
1533 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561534 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441535 // that's okay. It'll be ignored if as_popup is false, or the browser
1536 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561537 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1538 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291539}
1540
[email protected]4873c7d2009-07-16 06:36:281541void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291542}
1543
[email protected]4873c7d2009-07-16 06:36:281544void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291545}
1546
[email protected]2533ce12009-05-09 00:02:241547void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381548 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241549 Send(new ViewHostMsg_Close(routing_id_));
1550}
1551
dgozmancf9039cd2015-04-06 12:01:311552void RenderWidget::NotifyOnClose() {
1553 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1554}
1555
[email protected]4873c7d2009-07-16 06:36:281556void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321557 if (is_swapped_out_) {
1558 // This widget is currently swapped out, and the active widget is in a
1559 // different process. Have the browser route the close request to the
1560 // active widget instead, so that the correct unload handlers are run.
1561 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1562 return;
1563 }
1564
initial.commit09911bf2008-07-26 23:55:291565 // If a page calls window.close() twice, we'll end up here twice, but that's
1566 // OK. It is safe to send multiple Close messages.
1567
[email protected]2533ce12009-05-09 00:02:241568 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1569 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1570 // could be closed before the JS finishes executing. So instead, post a
1571 // message back to the message loop, which won't run until the JS is
1572 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401573 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211574 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291575}
1576
[email protected]9017d7852013-11-21 17:47:351577void RenderWidget::QueueSyntheticGesture(
1578 scoped_ptr<SyntheticGestureParams> gesture_params,
1579 const SyntheticGestureCompletionCallback& callback) {
1580 DCHECK(!callback.is_null());
1581
1582 pending_synthetic_gesture_callbacks_.push(callback);
1583
1584 SyntheticGesturePacket gesture_packet;
1585 gesture_packet.set_gesture_params(gesture_params.Pass());
1586
1587 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1588}
1589
initial.commit09911bf2008-07-26 23:55:291590void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031591 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381592 WillCloseLayerTreeView();
1593 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291594 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281595 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291596 webwidget_ = NULL;
1597 }
1598}
1599
[email protected]4873c7d2009-07-16 06:36:281600WebRect RenderWidget::windowRect() {
1601 if (pending_window_rect_count_)
1602 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241603
[email protected]80ad8622012-11-07 16:33:031604 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291605}
1606
[email protected]180ef242013-11-07 06:50:461607void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301608 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541609 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301610}
1611
[email protected]b2e4c70132013-10-03 02:07:511612void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561613 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511614 if (popup_origin_scale_for_emulation_) {
1615 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561616 window_rect.x = popup_screen_origin_for_emulation_.x() +
1617 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1618 window_rect.y = popup_screen_origin_for_emulation_.y() +
1619 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511620 }
1621
[email protected]5b45ad42013-10-25 00:42:041622 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201623 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561624 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1625 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031626 } else {
bokanc007c3a2015-02-03 07:15:561627 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031628 }
initial.commit09911bf2008-07-26 23:55:291629 } else {
bokanc007c3a2015-02-03 07:15:561630 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291631 }
1632}
1633
[email protected]2533ce12009-05-09 00:02:241634void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1635 pending_window_rect_ = rect;
1636 pending_window_rect_count_++;
1637}
1638
[email protected]4873c7d2009-07-16 06:36:281639WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241640 if (pending_window_rect_count_) {
1641 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1642 // the RootWindowRect is probably going to return wrong results since the
1643 // browser may not have processed the Move yet. There isn't really anything
1644 // good to do in this case, and it shouldn't happen - since this size is
1645 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281646 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241647 }
1648
[email protected]80ad8622012-11-07 16:33:031649 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371650}
1651
[email protected]4873c7d2009-07-16 06:36:281652WebRect RenderWidget::windowResizerRect() {
1653 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191654}
1655
[email protected]fa7b1dc2010-06-23 17:53:041656void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031657 // To prevent this renderer process from sending unnecessary IPC messages to
1658 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041659 // only during the input method attached to the browser process is active.
1660 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291661}
1662
[email protected]37a241c2013-12-03 03:16:171663void RenderWidget::OnCandidateWindowShown() {
1664 webwidget_->didShowCandidateWindow();
1665}
1666
1667void RenderWidget::OnCandidateWindowUpdated() {
1668 webwidget_->didUpdateCandidateWindow();
1669}
1670
1671void RenderWidget::OnCandidateWindowHidden() {
1672 webwidget_->didHideCandidateWindow();
1673}
1674
[email protected]fa7b1dc2010-06-23 17:53:041675void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261676 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041677 const std::vector<WebCompositionUnderline>& underlines,
1678 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131679 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281680 return;
[email protected]66fca5bc2013-05-23 06:58:291681 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361682 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041683 text, WebVector<WebCompositionUnderline>(underlines),
1684 selection_start, selection_end)) {
1685 // If we failed to set the composition text, then we need to let the browser
1686 // process to cancel the input method's ongoing composition session, to make
1687 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221688 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261689 }
[email protected]88dbe32f2013-06-20 23:31:361690 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041691}
1692
[email protected]fcf75d42013-12-03 20:11:261693void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511694 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021695 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131696 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041697 return;
[email protected]66fca5bc2013-05-23 06:58:291698 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041699 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021700 if (text.length())
1701 webwidget_->confirmComposition(text);
1702 else if (keep_selection)
1703 webwidget_->confirmComposition(WebWidget::KeepSelection);
1704 else
1705 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041706 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361707 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291708}
1709
[email protected]0bc1f572013-04-17 01:46:311710void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121711 // During shutdown we can just ignore this message.
1712 if (!webwidget_)
1713 return;
1714
[email protected]0bc1f572013-04-17 01:46:311715 // Even if the browser provides an empty damage rect, it's still expecting to
1716 // receive a repaint ack so just damage the entire widget bounds.
1717 if (size_to_paint.IsEmpty()) {
1718 size_to_paint = size_;
1719 }
1720
[email protected]ec7dc112008-08-06 05:30:121721 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051722 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311723 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121724}
1725
[email protected]79fa22e2013-08-23 15:18:121726void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351727 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1728
1729 pending_synthetic_gesture_callbacks_.front().Run();
1730 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271731}
1732
[email protected]4873c7d2009-07-16 06:36:281733void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111734 if (!webwidget_)
1735 return;
[email protected]4873c7d2009-07-16 06:36:281736 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111737}
1738
[email protected]80ad8622012-11-07 16:33:031739void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1740 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511741 if (screen_metrics_emulator_) {
1742 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1743 view_screen_rect, window_screen_rect);
1744 } else {
1745 view_screen_rect_ = view_screen_rect;
1746 window_screen_rect_ = window_screen_rect;
1747 }
[email protected]80ad8622012-11-07 16:33:031748 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1749}
1750
[email protected]adb362312014-06-28 06:04:241751void RenderWidget::showImeIfNeeded() {
1752 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131753}
1754
[email protected]adb362312014-06-28 06:04:241755void RenderWidget::OnShowImeIfNeeded() {
1756#if defined(OS_ANDROID) || defined(USE_AURA)
1757 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1758#endif
rouslanf7ebd8832015-01-22 01:54:141759
1760// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1761// virtual keyboard.
1762#if !defined(OS_ANDROID)
1763 FocusChangeComplete();
1764#endif
[email protected]adb362312014-06-28 06:04:241765}
1766
1767#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131768void RenderWidget::IncrementOutstandingImeEventAcks() {
1769 ++outstanding_ime_acks_;
1770}
1771
1772void RenderWidget::OnImeEventAck() {
1773 --outstanding_ime_acks_;
1774 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511775}
[email protected]105dffb42013-02-20 03:46:211776#endif
1777
[email protected]0d1ebed12013-08-05 22:01:131778bool RenderWidget::ShouldHandleImeEvent() {
1779#if defined(OS_ANDROID)
1780 return !!webwidget_ && outstanding_ime_acks_ == 0;
1781#else
1782 return !!webwidget_;
1783#endif
1784}
1785
[email protected]c27dd4f2014-05-22 18:05:191786bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1787 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521788 // If we pause multiple times during a single mouse move event, we should
1789 // only send ACK once.
1790 if (!ignore_ack_for_mouse_move_from_debugger_) {
1791 InputHostMsg_HandleInputEvent_ACK_Params ack;
1792 ack.type = handling_event_type_;
1793 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1794 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021795 return true;
[email protected]5fea4a52014-05-27 00:17:521796 }
[email protected]c27dd4f2014-05-22 18:05:191797 }
1798 return false;
1799}
1800
1801void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1802 ignore_ack_for_mouse_move_from_debugger_ = true;
1803}
1804
[email protected]468ac582012-11-20 00:53:191805void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1806 if (device_scale_factor_ == device_scale_factor)
1807 return;
1808
1809 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051810 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191811}
1812
[email protected]28ed6b32014-06-08 02:16:271813bool RenderWidget::SetDeviceColorProfile(
1814 const std::vector<char>& color_profile) {
1815 if (device_color_profile_ == color_profile)
1816 return false;
1817
1818 device_color_profile_ = color_profile;
1819 return true;
1820}
1821
noeldb4df152014-09-16 17:45:201822void RenderWidget::ResetDeviceColorProfileForTesting() {
1823 if (!device_color_profile_.empty())
1824 device_color_profile_.clear();
1825 device_color_profile_.push_back('0');
1826}
1827
[email protected]fcdc5642014-05-09 14:32:241828void RenderWidget::OnOrientationChange() {
1829}
1830
[email protected]ceb36f7d2012-10-31 18:33:241831gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521832 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241833 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521834}
1835
[email protected]bee16aab2009-08-26 15:55:031836void RenderWidget::SetHidden(bool hidden) {
1837 if (is_hidden_ == hidden)
1838 return;
1839
jdduke8fac9d102014-12-20 02:40:131840 // The status has changed. Tell the RenderThread about it and ensure
1841 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031842 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131843 FlushPendingInputEventAck();
1844
[email protected]bee16aab2009-08-26 15:55:031845 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001846 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031847 else
[email protected]b2db9272014-01-10 17:42:001848 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031849}
1850
[email protected]2b624c562011-10-27 22:58:261851void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261852 if (!webwidget_)
1853 return;
1854
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121855 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261856 webwidget_->willExitFullScreen();
1857 } else {
1858 webwidget_->willEnterFullScreen();
1859 }
[email protected]2b624c562011-10-27 22:58:261860}
1861
1862void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261863 if (!webwidget_)
1864 return;
1865
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121866 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261867 webwidget_->didEnterFullScreen();
1868 } else {
1869 webwidget_->didExitFullScreen();
1870 }
[email protected]2b624c562011-10-27 22:58:261871}
1872
[email protected]674741932009-02-04 23:44:461873bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051874 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461875}
1876
[email protected]674741932009-02-04 23:44:461877void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051878 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461879}
1880
[email protected]674741932009-02-04 23:44:461881void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051882 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461883}
1884
[email protected]b18583c2012-12-18 06:55:271885static bool IsDateTimeInput(ui::TextInputType type) {
1886 return type == ui::TEXT_INPUT_TYPE_DATE ||
1887 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1888 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1889 type == ui::TEXT_INPUT_TYPE_MONTH ||
1890 type == ui::TEXT_INPUT_TYPE_TIME ||
1891 type == ui::TEXT_INPUT_TYPE_WEEK;
1892}
1893
[email protected]66fca5bc2013-05-23 06:58:291894
1895void RenderWidget::StartHandlingImeEvent() {
1896 DCHECK(!handling_ime_event_);
1897 handling_ime_event_ = true;
1898}
1899
1900void RenderWidget::FinishHandlingImeEvent() {
1901 DCHECK(handling_ime_event_);
1902 handling_ime_event_ = false;
1903 // While handling an ime event, text input state and selection bounds updates
1904 // are ignored. These must explicitly be updated once finished handling the
1905 // ime event.
1906 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471907#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361908 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471909#endif
[email protected]66fca5bc2013-05-23 06:58:291910}
1911
shuchen3517bb62014-10-15 03:55:571912void RenderWidget::UpdateTextInputType() {
1913 // On Windows, not only an IME but also an on-screen keyboard relies on the
1914 // latest TextInputType to optimize its layout and functionality. Thus
1915 // |input_method_is_active_| is no longer an appropriate condition to suppress
1916 // TextInputTypeChanged IPC on Windows.
1917 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1918 // on other platforms as well as Windows if the overhead is acceptable.
1919#if !defined(OS_WIN)
1920 if (!input_method_is_active_)
1921 return;
1922#endif
1923
1924 ui::TextInputType new_type = GetTextInputType();
1925 if (IsDateTimeInput(new_type))
1926 return; // Not considered as a text input field in WebKit/Chromium.
1927
1928 bool new_can_compose_inline = CanComposeInline();
1929
1930 blink::WebTextInputInfo new_info;
1931 if (webwidget_)
1932 new_info = webwidget_->textInputInfo();
1933 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201934 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571935
1936 if (text_input_type_ != new_type
1937 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201938 || text_input_mode_ != new_mode
1939 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571940 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1941 new_type,
1942 new_mode,
shuchen82ce8c52014-10-23 01:55:201943 new_can_compose_inline,
1944 new_flags));
shuchen3517bb62014-10-15 03:55:571945 text_input_type_ = new_type;
1946 can_compose_inline_ = new_can_compose_inline;
1947 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201948 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571949 }
1950}
1951
1952#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361953void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1954 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501955 if (handling_ime_event_)
1956 return;
[email protected]90f24152014-04-09 12:41:361957 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291958 return;
[email protected]ad26ef42011-06-17 07:59:451959 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271960 if (IsDateTimeInput(new_type))
1961 return; // Not considered as a text input field in WebKit/Chromium.
1962
[email protected]180ef242013-11-07 06:50:461963 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211964 if (webwidget_)
1965 new_info = webwidget_->textInputInfo();
1966
[email protected]ad26ef42011-06-17 07:59:451967 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211968
[email protected]3306f262012-09-21 19:20:421969 // Only sends text input params if they are changed or if the ime should be
1970 // shown.
[email protected]90f24152014-04-09 12:41:361971 if (show_ime == SHOW_IME_IF_NEEDED ||
1972 (text_input_type_ != new_type ||
1973 text_input_info_ != new_info ||
1974 can_compose_inline_ != new_can_compose_inline)
1975#if defined(OS_ANDROID)
1976 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021977#endif
[email protected]90f24152014-04-09 12:41:361978 ) {
1979 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211980 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401981 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211982 p.value = new_info.value.utf8();
1983 p.selection_start = new_info.selectionStart;
1984 p.selection_end = new_info.selectionEnd;
1985 p.composition_start = new_info.compositionStart;
1986 p.composition_end = new_info.compositionEnd;
1987 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361988 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1989#if defined(USE_AURA)
1990 p.is_non_ime_change = true;
1991#endif
[email protected]183e28d2014-01-20 18:18:021992#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361993 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1994 text_field_is_dirty_;
1995 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131996 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361997 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021998#endif
shuchen3517bb62014-10-15 03:55:571999#if defined(USE_AURA)
2000 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
2001 new_type,
2002 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:202003 new_can_compose_inline,
2004 new_info.flags));
shuchen3517bb62014-10-15 03:55:572005#endif
[email protected]5b739cb2012-08-21 20:35:212006 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2007
2008 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042009 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452010 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:202011 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:292012 }
initial.commit09911bf2008-07-26 23:55:292013}
shuchen3517bb62014-10-15 03:55:572014#endif
initial.commit09911bf2008-07-26 23:55:292015
[email protected]7c8873e2013-02-05 08:03:012016void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2017 WebRect focus_webrect;
2018 WebRect anchor_webrect;
2019 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2020 *focus = focus_webrect;
2021 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322022}
2023
[email protected]e99ef6f2011-10-16 01:13:002024void RenderWidget::UpdateSelectionBounds() {
2025 if (!webwidget_)
2026 return;
[email protected]66fca5bc2013-05-23 06:58:292027 if (handling_ime_event_)
2028 return;
[email protected]e99ef6f2011-10-16 01:13:002029
jddukeacf809e2014-09-23 20:38:382030 // With composited selection updates, the selection bounds will be reported
2031 // directly by the compositor, in which case explicit IPC selection
2032 // notifications should be suppressed.
2033 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
2034 ViewHostMsg_SelectionBounds_Params params;
2035 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2036 if (selection_anchor_rect_ != params.anchor_rect ||
2037 selection_focus_rect_ != params.focus_rect) {
2038 selection_anchor_rect_ = params.anchor_rect;
2039 selection_focus_rect_ = params.focus_rect;
2040 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2041 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2042 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2043 }
[email protected]58b48a0d2012-06-13 07:01:352044 }
jddukeacf809e2014-09-23 20:38:382045
[email protected]88dbe32f2013-06-20 23:31:362046 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002047}
2048
[email protected]180ef242013-11-07 06:50:462049// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172050#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2051 static_assert(int(blink::WebTextInputType##a) \
2052 == int(ui::TEXT_INPUT_TYPE_##b), \
2053 "mismatching enums: " #a)
2054
2055STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2056STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2057STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2058STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2059STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2060STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2061STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2062STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2063STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2064STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2065STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2066STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2067STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2068STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2069STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2070STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2071STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452072
[email protected]5b739cb2012-08-21 20:35:212073ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462074 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212075 // Check the type is in the range representable by ui::TextInputType.
2076 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462077 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212078 return static_cast<ui::TextInputType>(type);
2079}
2080
[email protected]ad26ef42011-06-17 07:59:452081ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272082 if (webwidget_)
2083 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452084 return ui::TEXT_INPUT_TYPE_NONE;
2085}
2086
[email protected]501ea13d2013-07-09 17:03:292087void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302088#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112089 // TODO(yukawa): Start sending character bounds when the browser side
2090 // implementation becomes ready (crbug.com/424866).
2091#else
[email protected]db4fc1e2013-09-06 20:01:512092 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292093 if (should_update_range) {
2094 GetCompositionRange(&range);
2095 } else {
2096 range = composition_range_;
2097 }
2098 std::vector<gfx::Rect> character_bounds;
2099 GetCompositionCharacterBounds(&character_bounds);
2100
2101 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2102 return;
2103 composition_character_bounds_ = character_bounds;
2104 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222105 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292106 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112107#endif
[email protected]501ea13d2013-07-09 17:03:292108}
2109
[email protected]58b48a0d2012-06-13 07:01:352110void RenderWidget::GetCompositionCharacterBounds(
2111 std::vector<gfx::Rect>* bounds) {
2112 DCHECK(bounds);
2113 bounds->clear();
2114}
2115
[email protected]db4fc1e2013-09-06 20:01:512116void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362117 size_t location, length;
2118 if (webwidget_->compositionRange(&location, &length)) {
2119 range->set_start(location);
2120 range->set_end(location + length);
2121 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2122 range->set_start(location);
2123 range->set_end(location + length);
2124 } else {
[email protected]db4fc1e2013-09-06 20:01:512125 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362126 }
2127}
2128
[email protected]501ea13d2013-07-09 17:03:292129bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512130 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292131 const std::vector<gfx::Rect>& bounds) {
2132 if (composition_range_ != range)
2133 return true;
2134 if (bounds.size() != composition_character_bounds_.size())
2135 return true;
2136 for (size_t i = 0; i < bounds.size(); ++i) {
2137 if (bounds[i] != composition_character_bounds_[i])
2138 return true;
2139 }
2140 return false;
2141}
[email protected]501ea13d2013-07-09 17:03:292142
[email protected]a4f0d882014-05-01 23:48:102143#if defined(OS_ANDROID)
2144void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2145 // If not initialized, default to white. Note that 0 is different from black
2146 // as black still has alpha 0xFF.
2147 if (!bg_color)
2148 bg_color = SK_ColorWHITE;
2149
2150 if (bg_color != body_background_color_) {
2151 body_background_color_ = bg_color;
2152 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2153 }
2154}
timav7a5032e2014-12-05 01:59:432155
2156bool RenderWidget::DoesRecordFullLayer() const {
2157 SynchronousCompositorFactory* synchronous_compositor_factory =
2158 SynchronousCompositorFactory::GetInstance();
2159
2160 // We assume that the absence of synchronous_compositor_factory
2161 // means we are in Chrome. In chrome, we want to clip, i.e.
2162 // *not* to record the full layer.
2163 if (!synchronous_compositor_factory)
2164 return false;
2165
2166 return synchronous_compositor_factory->RecordFullLayer();
2167}
[email protected]a4f0d882014-05-01 23:48:102168#endif
2169
[email protected]ad26ef42011-06-17 07:59:452170bool RenderWidget::CanComposeInline() {
2171 return true;
[email protected]56ea1a62011-05-30 07:05:572172}
2173
[email protected]4873c7d2009-07-16 06:36:282174WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042175 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282176}
2177
[email protected]f660d9c2012-06-06 18:31:212178float RenderWidget::deviceScaleFactor() {
2179 return device_scale_factor_;
2180}
2181
[email protected]fa7b1dc2010-06-23 17:53:042182void RenderWidget::resetInputMethod() {
2183 if (!input_method_is_active_)
2184 return;
2185
[email protected]0e45bd02013-07-12 20:20:022186 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042187 // If the last text input type is not None, then we should finish any
2188 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452189 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042190 // If a composition text exists, then we need to let the browser process
2191 // to cancel the input method's ongoing composition session.
2192 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222193 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042194 }
[email protected]d4cff272011-05-02 15:46:012195
[email protected]88dbe32f2013-06-20 23:31:362196 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042197}
2198
donnda070f3c2015-01-16 19:54:112199#if defined(OS_ANDROID)
2200void RenderWidget::showUnhandledTapUIIfNeeded(
2201 const WebPoint& tapped_position,
2202 const WebNode& tapped_node,
2203 bool page_changed) {
2204 DCHECK(handling_input_event_);
2205 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372206 !tapped_node.isContentEditable() &&
2207 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112208 if (should_trigger) {
2209 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2210 tapped_position.x, tapped_position.y));
2211 }
2212}
2213#endif
2214
[email protected]c68c3e4e2013-01-24 00:36:562215void RenderWidget::didHandleGestureEvent(
2216 const WebGestureEvent& event,
2217 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022218#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562219 if (event_cancelled)
2220 return;
[email protected]07c70d22014-08-21 08:33:462221 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362222 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462223 } else if (event.type == WebInputEvent::GestureLongPress) {
2224 DCHECK(webwidget_);
2225 if (webwidget_->textInputInfo().value.isEmpty())
2226 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2227 else
2228 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562229 }
2230#endif
2231}
2232
[email protected]7912e822014-04-16 02:37:032233void RenderWidget::StartCompositor() {
2234 // For widgets that are never visible, we don't need the compositor to run
2235 // at all.
2236 if (never_visible_)
2237 return;
danakj6e3bf8012014-12-16 18:27:532238 // In tests without a RenderThreadImpl, don't set ready as this kicks
2239 // off creating output surfaces that the test can't create.
2240 if (!RenderThreadImpl::current())
2241 return;
danakj018271e32014-12-16 21:17:262242 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032243}
2244
[email protected]29e2fb42013-07-19 01:13:472245void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292246 size_t i = 0;
2247 for (; i < plugin_window_moves_.size(); ++i) {
2248 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582249 if (move.rects_valid) {
2250 plugin_window_moves_[i] = move;
2251 } else {
2252 plugin_window_moves_[i].visible = move.visible;
2253 }
initial.commit09911bf2008-07-26 23:55:292254 break;
2255 }
2256 }
2257
2258 if (i == plugin_window_moves_.size())
2259 plugin_window_moves_.push_back(move);
2260}
[email protected]268654772009-08-06 23:02:042261
2262void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2263 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2264 i != plugin_window_moves_.end(); ++i) {
2265 if (i->window == window) {
2266 plugin_window_moves_.erase(i);
2267 break;
2268 }
2269 }
2270}
[email protected]67bfb83f2011-09-22 03:36:372271
[email protected]63b465922012-09-06 02:04:522272
[email protected]24ed0432013-04-24 07:50:312273RenderWidgetCompositor* RenderWidget::compositor() const {
2274 return compositor_.get();
2275}
2276
[email protected]180ef242013-11-07 06:50:462277bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372278 return false;
2279}
[email protected]c3d45532011-10-07 19:20:402280
[email protected]41d86852012-11-07 12:23:242281bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462282 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242283 return false;
2284}
2285
ccamerona7644752014-12-30 01:16:312286void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312287 const blink::WebMouseWheelEvent& wheel_event,
2288 bool event_processed) {
ccamerona7644752014-12-30 01:16:312289 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312290 return;
2291
2292 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2293 // assume that an unprocessed event was entirely an overscroll, and that a
2294 // processed event was entirely scroll.
2295 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2296 // http://crbug.com/442859
2297 cc::InputHandlerScrollResult scroll_result;
2298 if (event_processed) {
2299 scroll_result.did_scroll = true;
2300 } else {
2301 scroll_result.did_overscroll_root = true;
2302 scroll_result.unused_scroll_delta =
2303 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2304 }
2305
2306 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2307 InputHandlerManager* input_handler_manager =
2308 render_thread ? render_thread->input_handler_manager() : NULL;
2309 if (input_handler_manager) {
2310 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2311 routing_id_, wheel_event, scroll_result);
2312 }
2313}
2314
[email protected]ce6689f2013-03-29 12:52:552315void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2316 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2317}
2318
mostynbe29b6882015-01-13 09:59:172319// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2320#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2321 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2322 "mismatching enums: " #a)
2323
dtapuskaa98ac8d72015-05-08 19:29:092324inline content::TouchAction& operator|=(content::TouchAction& a,
2325 content::TouchAction b) {
2326 a = static_cast<content::TouchAction>(static_cast<int>(a) |
2327 static_cast<int>(b));
2328 return a;
2329}
2330
[email protected]5d0bbdfa92013-12-10 00:35:512331void RenderWidget::setTouchAction(
2332 blink::WebTouchAction web_touch_action) {
2333
2334 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2335 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192336 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512337 return;
2338
dtapuskaa98ac8d72015-05-08 19:29:092339// TODO(dtapuska): A dependant change needs to land in blink to change
2340// the blink::WebTouchAction enum; in the meantime don't do
2341// a static cast between the values. (http://crbug.com/476556)
2342#if 0
2343 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172344 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2345 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092346 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2347 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172348 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092349 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2350 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172351 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2352 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362353
2354 content::TouchAction content_touch_action =
2355 static_cast<content::TouchAction>(web_touch_action);
dtapuskaa98ac8d72015-05-08 19:29:092356#else
2357 content::TouchAction content_touch_action = TOUCH_ACTION_AUTO;
2358 if (web_touch_action & blink::WebTouchActionNone)
2359 content_touch_action |= TOUCH_ACTION_NONE;
2360 if (web_touch_action & blink::WebTouchActionPanX)
2361 content_touch_action |= TOUCH_ACTION_PAN_X;
2362 if (web_touch_action & blink::WebTouchActionPanY)
2363 content_touch_action |= TOUCH_ACTION_PAN_Y;
2364 if (web_touch_action & blink::WebTouchActionPinchZoom)
2365 content_touch_action |= TOUCH_ACTION_PINCH_ZOOM;
2366
2367#endif
[email protected]5d0bbdfa92013-12-10 00:35:512368 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2369}
2370
[email protected]90f24152014-04-09 12:41:362371void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2372#if defined(OS_ANDROID)
2373 text_field_is_dirty_ = true;
2374#endif
2375}
2376
[email protected]3d5c243b2012-11-30 00:26:012377bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2378 return true;
2379}
2380
[email protected]0634cdd42013-08-16 00:46:092381scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132382RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592383 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092384 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492385 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222386 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092387 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292388 if (!RenderThreadImpl::current())
2389 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402390 CauseForGpuLaunch cause =
2391 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292392 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402393 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222394 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292395 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592396
[email protected]828a3932014-04-02 14:43:132397 // Explicitly disable antialiasing for the compositor. As of the time of
2398 // this writing, the only platform that supported antialiasing for the
2399 // compositor was Mac OS X, because the on-screen OpenGL context creation
2400 // code paths on Windows and Linux didn't yet have multisampling support.
2401 // Mac OS X essentially always behaves as though it's rendering offscreen.
2402 // Multisampling has a heavy cost especially on devices with relatively low
2403 // fill rate like most notebooks, and the Mac implementation would need to
2404 // be optimized to resolve directly into the IOSurface shared between the
2405 // GPU and browser processes. For these reasons and to avoid platform
2406 // disparities we explicitly disable antialiasing.
2407 blink::WebGraphicsContext3D::Attributes attributes;
2408 attributes.antialias = false;
2409 attributes.shareResources = true;
2410 attributes.noAutomaticFlushes = true;
2411 attributes.depth = false;
2412 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132413 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292414 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012415#if defined(OS_ANDROID)
2416 // If we raster too fast we become upload bound, and pending
2417 // uploads consume memory. For maximum upload throughput, we would
2418 // want to allow for upload_throughput * pipeline_time of pending
2419 // uploads, after which we are just wasting memory. Since we don't
2420 // know our upload throughput yet, this just caps our memory usage.
2421 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272422 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032423 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012424 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032425 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012426 // Deadline to draw a frame to achieve 60 frames per second.
2427 const size_t kMillisecondsPerFrame = 16;
2428 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032429 size_t max_transfer_buffer_usage_mb =
2430 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2431 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012432 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2433 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292434 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032435 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012436#endif
[email protected]96ab016c2013-10-23 00:50:292437
[email protected]96ab016c2013-10-23 00:50:292438 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132439 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2440 GetURLForGraphicsContext3D(),
2441 gpu_channel_host.get(),
2442 attributes,
[email protected]828a3932014-04-02 14:43:132443 lose_context_when_out_of_memory,
2444 limits,
2445 NULL));
[email protected]0634cdd42013-08-16 00:46:092446 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592447}
2448
[email protected]e3244ed2014-06-20 20:04:272449void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2450 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162451}
2452
[email protected]e3244ed2014-06-20 20:04:272453void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2454 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162455}
2456
[email protected]de3c5d82014-05-28 22:12:592457void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2458 render_frames_.AddObserver(frame);
2459}
2460
2461void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2462 render_frames_.RemoveObserver(frame);
2463}
2464
[email protected]a017938b2014-05-27 21:17:172465#if defined(VIDEO_HOLE)
2466void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2467 video_hole_frames_.AddObserver(frame);
2468}
2469
2470void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2471 video_hole_frames_.RemoveObserver(frame);
2472}
2473#endif // defined(VIDEO_HOLE)
2474
[email protected]e9ff79c2012-10-19 21:31:262475} // namespace content