blob: d9dbe21ce1cbb745540202a7b985521962c3e388 [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]2847b222013-04-06 00:59:2439#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]36e5ff12013-06-11 12:19:2940#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5942#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2844#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2945#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1346#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3247#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2749#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0550#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4451#include "content/renderer/render_thread_impl.h"
tfarina556a7232014-10-05 01:02:0952#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0453#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1854#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4855#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1856#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3057#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4363#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5964#include "third_party/WebKit/public/web/WebFrameWidget.h"
65#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1166#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3167#include "third_party/WebKit/public/web/WebPagePopup.h"
68#include "third_party/WebKit/public/web/WebPopupMenu.h"
69#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
70#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3871#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5972#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4173#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1374#include "ui/base/ui_base_switches.h"
[email protected]de2cf8c2013-10-25 19:46:4675#include "ui/gfx/frame_time.h"
tfarina655f81d2014-12-23 02:38:5076#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0977#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3278#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4879#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2780#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4181#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4882
[email protected]eeb93112013-05-01 19:41:1083#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1584#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0785#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1086#endif
87
[email protected]661eb9d2009-02-03 02:11:4888#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4989#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5290#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4191#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4892#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4493
[email protected]2255a9332013-06-17 05:12:3194#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2995
[email protected]180ef242013-11-07 06:50:4696using blink::WebCompositionUnderline;
97using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4398using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4699using blink::WebGestureEvent;
100using blink::WebInputEvent;
101using blink::WebKeyboardEvent;
102using blink::WebMouseEvent;
103using blink::WebMouseWheelEvent;
104using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11105using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46106using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11107using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46108using blink::WebPopupMenu;
109using blink::WebPopupMenuInfo;
110using blink::WebPopupType;
111using blink::WebRange;
112using blink::WebRect;
113using blink::WebScreenInfo;
114using blink::WebSize;
115using blink::WebTextDirection;
116using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25117using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46118using blink::WebVector;
119using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26120
[email protected]6a4d7f62013-01-07 21:32:13121namespace {
[email protected]b256eca2013-07-11 10:57:40122
123typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
124
125class TextInputModeMapSingleton {
126 public:
127 static TextInputModeMapSingleton* GetInstance() {
128 return Singleton<TextInputModeMapSingleton>::get();
129 }
[email protected]dd705d4d2013-11-27 08:14:41130 TextInputModeMapSingleton() {
131 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
132 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
133 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
134 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
135 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
136 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
137 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
138 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
139 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
140 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
141 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40142 }
[email protected]dd705d4d2013-11-27 08:14:41143 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40144 private:
[email protected]dd705d4d2013-11-27 08:14:41145 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40146
147 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
148
149 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
150};
151
[email protected]dd705d4d2013-11-27 08:14:41152ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40153 static TextInputModeMapSingleton* singleton =
154 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41155 TextInputModeMap::const_iterator it =
156 singleton->map().find(input_mode.utf8());
157 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40158 return ui::TEXT_INPUT_MODE_DEFAULT;
159 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13160}
[email protected]b256eca2013-07-11 10:57:40161
[email protected]fd847792013-10-24 17:12:35162// TODO(brianderson): Replace the hard-coded threshold with a fraction of
163// the BeginMainFrame interval.
164// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
165// be spent in input hanlders before input starts getting throttled.
166const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
167
jdduke07788062014-12-05 03:16:30168int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
169 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
170 .ToInternalValue();
171}
172
173void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
174 UMA_HISTOGRAM_CUSTOM_COUNTS(
175 "Event.AggregatedLatency.Renderer2",
176 GetEventLatencyMicros(event, now),
177 1,
178 10000000,
179 100);
180
181#define CASE_TYPE(t) \
182 case WebInputEvent::t: \
183 UMA_HISTOGRAM_CUSTOM_COUNTS( \
184 "Event.Latency.Renderer2." #t, \
185 GetEventLatencyMicros(event, now), \
186 1, \
187 10000000, \
188 100); \
189 break;
190
191 switch(event.type) {
192 CASE_TYPE(Undefined);
193 CASE_TYPE(MouseDown);
194 CASE_TYPE(MouseUp);
195 CASE_TYPE(MouseMove);
196 CASE_TYPE(MouseEnter);
197 CASE_TYPE(MouseLeave);
198 CASE_TYPE(ContextMenu);
199 CASE_TYPE(MouseWheel);
200 CASE_TYPE(RawKeyDown);
201 CASE_TYPE(KeyDown);
202 CASE_TYPE(KeyUp);
203 CASE_TYPE(Char);
204 CASE_TYPE(GestureScrollBegin);
205 CASE_TYPE(GestureScrollEnd);
206 CASE_TYPE(GestureScrollUpdate);
207 CASE_TYPE(GestureFlingStart);
208 CASE_TYPE(GestureFlingCancel);
209 CASE_TYPE(GestureShowPress);
210 CASE_TYPE(GestureTap);
211 CASE_TYPE(GestureTapUnconfirmed);
212 CASE_TYPE(GestureTapDown);
213 CASE_TYPE(GestureTapCancel);
214 CASE_TYPE(GestureDoubleTap);
215 CASE_TYPE(GestureTwoFingerTap);
216 CASE_TYPE(GestureLongPress);
217 CASE_TYPE(GestureLongTap);
218 CASE_TYPE(GesturePinchBegin);
219 CASE_TYPE(GesturePinchEnd);
220 CASE_TYPE(GesturePinchUpdate);
221 CASE_TYPE(TouchStart);
222 CASE_TYPE(TouchMove);
223 CASE_TYPE(TouchEnd);
224 CASE_TYPE(TouchCancel);
225 default:
226 // Must include default to let blink::WebInputEvent add new event types
227 // before they're added here.
228 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
229 break;
230 }
231
232#undef CASE_TYPE
233}
234
[email protected]b256eca2013-07-11 10:57:40235} // namespace
236
[email protected]e9ff79c2012-10-19 21:31:26237namespace content {
[email protected]62cb33cae2009-03-27 23:30:22238
[email protected]b2e4c70132013-10-03 02:07:51239// RenderWidget::ScreenMetricsEmulator ----------------------------------------
240
241class RenderWidget::ScreenMetricsEmulator {
242 public:
243 ScreenMetricsEmulator(
244 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43245 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51246 virtual ~ScreenMetricsEmulator();
247
[email protected]19193682014-04-03 15:01:43248 // Scale and offset used to convert between host coordinates
249 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51250 float scale() { return scale_; }
[email protected]9a2d7ee32013-12-05 12:15:49251 gfx::Point offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43252 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51253 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56254 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51255
256 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43257 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51258
259 // The following methods alter handlers' behavior for messages related to
260 // widget size and position.
261 void OnResizeMessage(const ViewMsg_Resize_Params& params);
262 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
263 const gfx::Rect& window_screen_rect);
264 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31265 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51266
267 private:
[email protected]19193682014-04-03 15:01:43268 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02269 void Apply(bool top_controls_shrink_blink_size,
270 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44271 gfx::Rect resizer_rect,
272 bool is_fullscreen);
[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_;
[email protected]a179d3962013-11-12 14:44:40281 gfx::Point 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_,
310 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51311}
312
313RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
314 widget_->screen_info_ = original_screen_info_;
315
316 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
[email protected]7f99fc22013-11-08 14:05:58317 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f);
[email protected]b2e4c70132013-10-03 02:07:51318 widget_->view_screen_rect_ = original_view_screen_rect_;
319 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01320 widget_->Resize(original_size_,
321 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02322 widget_->top_controls_shrink_blink_size_,
323 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01324 original_visible_viewport_size_,
325 widget_->resizer_rect_,
326 widget_->is_fullscreen_,
327 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51328}
329
330void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43331 const WebDeviceEmulationParams& params) {
332 params_ = params;
333 Reapply();
334}
335
336void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02337 Apply(widget_->top_controls_shrink_blink_size_,
338 widget_->top_controls_height_,
339 widget_->resizer_rect_,
340 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51341}
342
[email protected]19193682014-04-03 15:01:43343void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02344 bool top_controls_shrink_blink_size,
345 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44346 gfx::Rect resizer_rect,
347 bool is_fullscreen) {
[email protected]92d13b72014-05-09 14:42:31348 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
349 if (!applied_widget_rect_.width())
350 applied_widget_rect_.set_width(original_size_.width());
351 if (!applied_widget_rect_.height())
352 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43353
[email protected]f442ee42014-05-14 11:53:12354 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02355 int original_width = std::max(original_size_.width(), 1);
356 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51357 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02358 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51359 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02360 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51361 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
362 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01363
364 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43365 offset_.set_x(
366 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01367 offset_.set_y(
[email protected]19193682014-04-03 15:01:43368 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51369 } else {
[email protected]0b3578c2014-06-20 18:29:02370 scale_ = params_.scale;
371 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01372 }
[email protected]7f0e8fa2014-03-26 12:32:01373
[email protected]19193682014-04-03 15:01:43374 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
375 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01376 widget_->screen_info_.rect = original_screen_info_.rect;
377 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
378 widget_->window_screen_rect_ = original_window_screen_rect_;
379 } else {
[email protected]19193682014-04-03 15:01:43380 applied_widget_rect_.set_origin(gfx::Point(0, 0));
381 widget_->screen_info_.rect = applied_widget_rect_;
382 widget_->screen_info_.availableRect = applied_widget_rect_;
383 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01384 }
[email protected]a179d3962013-11-12 14:44:40385
[email protected]19193682014-04-03 15:01:43386 float applied_device_scale_factor = params_.deviceScaleFactor ?
387 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01388 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51389
[email protected]7f99fc22013-11-08 14:05:58390 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51391 // - we keep the real device scale factor in compositor to produce sharp image
392 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58393 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51394 // root layer.
395 widget_->SetScreenMetricsEmulationParameters(
[email protected]a179d3962013-11-12 14:44:40396 original_screen_info_.deviceScaleFactor, offset_, scale_);
[email protected]b2e4c70132013-10-03 02:07:51397
[email protected]7f0e8fa2014-03-26 12:32:01398 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43399 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51400
401 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
402 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02403 widget_->Resize(applied_widget_rect_.size(),
404 physical_backing_size,
405 top_controls_shrink_blink_size,
406 top_controls_height,
407 applied_widget_rect_.size(),
408 resizer_rect,
409 is_fullscreen,
410 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51411}
412
413void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
414 const ViewMsg_Resize_Params& params) {
415 bool need_ack = params.new_size != original_size_ &&
416 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
417 original_size_ = params.new_size;
418 original_physical_backing_size_ = params.physical_backing_size;
419 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28420 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02421 Apply(params.top_controls_shrink_blink_size,
422 params.top_controls_height,
423 params.resizer_rect,
424 params.is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51425
426 if (need_ack) {
427 widget_->set_next_paint_is_resize_ack();
428 if (widget_->compositor_)
429 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
430 }
431}
432
433void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
434 const gfx::Rect& view_screen_rect,
435 const gfx::Rect& window_screen_rect) {
436 original_view_screen_rect_ = view_screen_rect;
437 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43438 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
439 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51440}
441
442void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
443 ContextMenuParams* params) {
444 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40445 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51446 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40447 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51448}
449
[email protected]2d6836f42014-07-02 17:25:31450gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
451 const gfx::Rect& anchor) {
452 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
453 scaled.set_x(scaled.x() + offset_.x());
454 scaled.set_y(scaled.y() + offset_.y());
455 return scaled;
456}
457
[email protected]b2e4c70132013-10-03 02:07:51458// RenderWidget ---------------------------------------------------------------
459
[email protected]180ef242013-11-07 06:50:46460RenderWidget::RenderWidget(blink::WebPopupType popup_type,
461 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04462 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03463 bool hidden,
464 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29465 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56466 surface_id_(0),
danakj6e3bf8012014-12-16 18:27:53467 compositor_deps_(nullptr),
468 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29469 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30470 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02471 top_controls_shrink_blink_size_(false),
472 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29473 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51474 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09475 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29476 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04477 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03478 never_visible_(never_visible),
[email protected]ee41e7d22011-10-14 19:34:09479 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29480 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49481 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50482 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19483 handling_event_type_(WebInputEvent::Undefined),
484 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48485 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22486 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44487 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04488 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45489 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40490 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20491 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53492 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12493 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48494 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12495 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04496 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52497 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43498 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30499 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13500#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36501 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13502 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10503 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13504#endif
[email protected]b2e4c70132013-10-03 02:07:51505 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11506 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42507 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51508 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
509 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05510 if (!swapped_out)
511 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27512 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53513 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29514}
515
516RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11517 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16518
[email protected]992db4c2011-05-12 15:37:15519 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02520 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15521 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29522}
523
[email protected]484955942010-08-19 16:13:18524// static
[email protected]8085dbc82008-09-26 22:53:44525RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53526 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46527 blink::WebPopupType popup_type,
528 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29529 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41530 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03531 new RenderWidget(popup_type, screen_info, false, false, false));
danakj6e3bf8012014-12-16 18:27:53532 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46533 return widget.get();
[email protected]a635f942012-12-07 10:34:29534 }
535 return NULL;
initial.commit09911bf2008-07-26 23:55:29536}
537
[email protected]484955942010-08-19 16:13:18538// static
kenrba7199832015-01-22 23:44:59539RenderWidget* RenderWidget::CreateForFrame(
540 int routing_id,
541 int surface_id,
542 bool hidden,
543 const blink::WebScreenInfo& screen_info,
544 CompositorDependencies* compositor_deps,
545 blink::WebLocalFrame* frame) {
546 CHECK_NE(routing_id, MSG_ROUTING_NONE);
547 scoped_refptr<RenderWidget> widget(new RenderWidget(
548 blink::WebPopupTypeNone, screen_info, false, hidden, false));
549 widget->routing_id_ = routing_id;
550 widget->surface_id_ = surface_id;
551 widget->compositor_deps_ = compositor_deps;
552 // DoInit increments the reference count on |widget|, keeping it alive after
553 // this function returns.
554 if (widget->DoInit(MSG_ROUTING_NONE, compositor_deps,
555 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
556 nullptr)) {
557 widget->CompleteInit();
558 return widget.get();
559 }
560 return nullptr;
561}
562
563// static
564blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18565 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46566 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18567 break;
[email protected]180ef242013-11-07 06:50:46568 case blink::WebPopupTypeSelect:
569 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18570 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46571 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44572 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18573 default:
574 NOTREACHED();
575 }
576 return NULL;
577}
578
kenrba7199832015-01-22 23:44:59579// static
580blink::WebWidget* RenderWidget::CreateWebFrameWidget(
581 RenderWidget* render_widget,
582 blink::WebLocalFrame* frame) {
583 return blink::WebFrameWidget::create(render_widget, frame);
584}
585
danakj6e3bf8012014-12-16 18:27:53586bool RenderWidget::Init(int32 opener_id,
587 CompositorDependencies* compositor_deps) {
588 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29589 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
590 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18591}
592
[email protected]a635f942012-12-07 10:34:29593bool RenderWidget::DoInit(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53594 CompositorDependencies* compositor_deps,
[email protected]6a8ddba52010-09-05 04:38:06595 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18596 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29597 DCHECK(!webwidget_);
598
599 if (opener_id != MSG_ROUTING_NONE)
600 opener_id_ = opener_id;
601
danakj6e3bf8012014-12-16 18:27:53602 compositor_deps_ = compositor_deps;
[email protected]484955942010-08-19 16:13:18603 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29604
kenrba7199832015-01-22 23:44:59605 bool result = true;
606 if (create_widget_message)
607 result = RenderThread::Get()->Send(create_widget_message);
608
initial.commit09911bf2008-07-26 23:55:29609 if (result) {
[email protected]380244092011-10-07 17:26:27610 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29611 // Take a reference on behalf of the RenderThread. This will be balanced
612 // when we receive ViewMsg_Close.
613 AddRef();
[email protected]b2db9272014-01-10 17:42:00614 if (RenderThreadImpl::current()) {
615 RenderThreadImpl::current()->WidgetCreated();
616 if (is_hidden_)
617 RenderThreadImpl::current()->WidgetHidden();
618 }
[email protected]a635f942012-12-07 10:34:29619 return true;
initial.commit09911bf2008-07-26 23:55:29620 } else {
[email protected]a635f942012-12-07 10:34:29621 // The above Send can fail when the tab is closing.
622 return false;
initial.commit09911bf2008-07-26 23:55:29623 }
624}
625
[email protected]fc4404d2012-11-07 19:53:30626// This is used to complete pending inits and non-pending inits.
627void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29628 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29629
[email protected]fc4404d2012-11-07 19:53:30630 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42631
[email protected]7912e822014-04-16 02:37:03632 if (compositor_)
633 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29634
[email protected]6de74452009-02-25 18:04:59635 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29636}
637
[email protected]992db4c2011-05-12 15:37:15638void RenderWidget::SetSwappedOut(bool is_swapped_out) {
639 // We should only toggle between states.
640 DCHECK(is_swapped_out_ != is_swapped_out);
641 is_swapped_out_ = is_swapped_out;
642
643 // If we are swapping out, we will call ReleaseProcess, allowing the process
644 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52645 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15646 // If we are swapping in, we call AddRefProcess to prevent the process from
647 // exiting.
[email protected]949b6592014-08-20 13:17:52648 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15649 RenderProcess::current()->AddRefProcess();
650}
651
[email protected]949b6592014-08-20 13:17:52652void RenderWidget::WasSwappedOut() {
653 // If we have been swapped out and no one else is using this process,
654 // it's safe to exit now.
655 CHECK(is_swapped_out_);
656 RenderProcess::current()->ReleaseProcess();
657}
658
[email protected]b2e4c70132013-10-03 02:07:51659void RenderWidget::EnableScreenMetricsEmulation(
[email protected]19193682014-04-03 15:01:43660 const WebDeviceEmulationParams& params) {
661 if (!screen_metrics_emulator_)
662 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
663 else
664 screen_metrics_emulator_->ChangeEmulationParams(params);
[email protected]b2e4c70132013-10-03 02:07:51665}
666
667void RenderWidget::DisableScreenMetricsEmulation() {
668 screen_metrics_emulator_.reset();
669}
670
671void 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(
[email protected]7f99fc22013-11-08 14:05:58689 float device_scale_factor,
690 const gfx::Point& root_layer_offset,
691 float root_layer_scale) {
[email protected]b2e4c70132013-10-03 02:07:51692 // This is only supported in RenderView.
693 NOTREACHED();
694}
695
[email protected]53907862014-03-25 15:42:40696#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51697void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
698 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49699 popup->SetOriginScaleAndOffsetForEmulation(
700 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51701}
[email protected]53907862014-03-25 15:42:40702#endif
[email protected]b2e4c70132013-10-03 02:07:51703
704void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
705 if (screen_metrics_emulator_)
706 screen_metrics_emulator_->OnShowContextMenu(params);
707}
708
[email protected]7d08a9352013-10-15 08:24:56709void RenderWidget::ScheduleCompositeWithForcedRedraw() {
710 if (compositor_) {
711 // Regardless of whether threaded compositing is enabled, always
712 // use this mechanism to force the compositor to redraw. However,
713 // the invalidation code path below is still needed for the
714 // non-threaded case.
715 compositor_->SetNeedsForcedRedraw();
716 }
[email protected]8b9e52b2014-01-17 16:35:31717 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56718}
719
[email protected]a95986a82010-12-24 06:19:28720bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
721 bool handled = true;
722 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15723 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22724 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
725 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22726 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
727 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15728 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
729 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35730 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
731 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28732 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
733 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
734 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
noel89949e62014-09-30 01:12:41735 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54736 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28737 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41738 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28739 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17740 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
741 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
742 OnCandidateWindowUpdated)
743 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25744 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28745 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
746 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03747 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21748#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51749 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13750 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21751#endif
[email protected]a95986a82010-12-24 06:19:28752 IPC_MESSAGE_UNHANDLED(handled = false)
753 IPC_END_MESSAGE_MAP()
754 return handled;
755}
initial.commit09911bf2008-07-26 23:55:29756
757bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15758 // Don't send any messages after the browser has told us to close, and filter
759 // most outgoing messages while swapped out.
760 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26761 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11762 closing_) {
initial.commit09911bf2008-07-26 23:55:29763 delete message;
764 return false;
765 }
766
767 // If given a messsage without a routing ID, then assign our routing ID.
768 if (message->routing_id() == MSG_ROUTING_NONE)
769 message->set_routing_id(routing_id_);
770
[email protected]380244092011-10-07 17:26:27771 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44772}
773
[email protected]61e2b3cc2012-03-02 16:13:34774void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44775 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02776 bool top_controls_shrink_blink_size,
777 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44778 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34779 const gfx::Rect& resizer_rect,
780 bool is_fullscreen,
781 ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56782 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48783 // A resize ack shouldn't be requested if we have not ACK'd the previous
784 // one.
785 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
786 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
787 }
initial.commit09911bf2008-07-26 23:55:29788
[email protected]61e2b3cc2012-03-02 16:13:34789 // Ignore this during shutdown.
790 if (!webwidget_)
791 return;
792
[email protected]d9083762013-03-24 01:36:40793 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44794 compositor_->setViewportSize(new_size, physical_backing_size);
dtrainorcb7779b82014-12-04 01:08:02795 compositor_->SetTopControlsShrinkBlinkSize(top_controls_shrink_blink_size);
796 compositor_->SetTopControlsHeight(top_controls_height);
[email protected]d9083762013-03-24 01:36:40797 }
[email protected]60d47ac2013-03-01 23:42:44798
[email protected]dade8992013-03-04 07:34:34799 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02800 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
801 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28802 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34803 resizer_rect_ = resizer_rect;
804
805 // NOTE: We may have entered fullscreen mode without changing our size.
806 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
807 if (fullscreen_change)
808 WillToggleFullscreen();
809 is_fullscreen_ = is_fullscreen;
810
dtrainorcb7779b82014-12-04 01:08:02811 webwidget_->setTopControlsLayoutHeight(top_controls_shrink_blink_size_
812 ? top_controls_height : 0.f);
bokan0c93cd82014-09-30 19:20:43813
[email protected]61e2b3cc2012-03-02 16:13:34814 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34815 size_ = new_size;
816
[email protected]61e2b3cc2012-03-02 16:13:34817 // When resizing, we want to wait to paint before ACK'ing the resize. This
818 // ensures that we only resize as fast as we can paint. We only need to
819 // send an ACK if we are resized to a non-empty rect.
820 webwidget_->resize(new_size);
[email protected]5b45ad42013-10-25 00:42:04821 } else if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]632c4382013-05-15 08:58:45822 resize_ack = NO_RESIZE_ACK;
823 }
824
[email protected]bb6378fe2014-04-28 21:19:44825 webwidget()->resizePinchViewport(gfx::Size(
826 visible_viewport_size.width(),
827 visible_viewport_size.height()));
828
[email protected]632c4382013-05-15 08:58:45829 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
830 // For empty size or empty physical_backing_size, there is no next paint
831 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35832 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34833 }
834
[email protected]20fbfc22013-05-08 20:50:58835 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45836 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58837 set_next_paint_is_resize_ack();
838
[email protected]61e2b3cc2012-03-02 16:13:34839 if (fullscreen_change)
840 DidToggleFullscreen();
841
842 // If a resize ack is requested and it isn't set-up, then no more resizes will
843 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45844 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29845}
846
bokanf0fd2412014-10-30 15:28:55847void RenderWidget::ResizeSynchronously(
848 const gfx::Rect& new_position,
849 const gfx::Size& visible_viewport_size) {
[email protected]587941d2014-08-22 01:40:01850 Resize(new_position.size(),
851 new_position.size(),
dtrainorcb7779b82014-12-04 01:08:02852 top_controls_shrink_blink_size_,
853 top_controls_height_,
bokanf0fd2412014-10-30 15:28:55854 visible_viewport_size,
[email protected]587941d2014-08-22 01:40:01855 gfx::Rect(),
856 is_fullscreen_,
857 NO_RESIZE_ACK);
[email protected]92650162013-10-30 03:31:02858 view_screen_rect_ = new_position;
859 window_screen_rect_ = new_position;
860 if (!did_show_)
861 initial_pos_ = new_position;
862}
863
initial.commit09911bf2008-07-26 23:55:29864void RenderWidget::OnClose() {
865 if (closing_)
866 return;
867 closing_ = true;
868
869 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03870 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]b2db9272014-01-10 17:42:00871 if (RenderThreadImpl::current())
872 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]380244092011-10-07 17:26:27873 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03874 SetHidden(false);
875 }
initial.commit09911bf2008-07-26 23:55:29876
initial.commit09911bf2008-07-26 23:55:29877 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25878 // now. Post a task that only gets invoked when there are no nested message
879 // loops.
alexclarkee19d4ef2015-01-09 17:45:40880 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29881 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25882
883 // Balances the AddRef taken when we called AddRoute.
884 Release();
initial.commit09911bf2008-07-26 23:55:29885}
886
[email protected]61e2b3cc2012-03-02 16:13:34887// Got a response from the browser after the renderer decided to create a new
888// view.
[email protected]fc4404d2012-11-07 19:53:30889void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34890 DCHECK(routing_id_ != MSG_ROUTING_NONE);
891
[email protected]fc4404d2012-11-07 19:53:30892 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34893}
894
[email protected]0fdd5012013-05-29 08:05:56895void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04896 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32897 return;
898
[email protected]b2e4c70132013-10-03 02:07:51899 if (screen_metrics_emulator_) {
900 screen_metrics_emulator_->OnResizeMessage(params);
901 return;
902 }
903
[email protected]fcdc5642014-05-09 14:32:24904 bool orientation_changed =
905 screen_info_.orientationAngle != params.screen_info.orientationAngle;
906
[email protected]0fdd5012013-05-29 08:05:56907 screen_info_ = params.screen_info;
908 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02909 Resize(params.new_size,
910 params.physical_backing_size,
911 params.top_controls_shrink_blink_size,
912 params.top_controls_height,
913 params.visible_viewport_size,
914 params.resizer_rect,
915 params.is_fullscreen,
916 SEND_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24917
918 if (orientation_changed)
919 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29920}
921
noel89949e62014-09-30 01:12:41922void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
923 SetDeviceColorProfile(color_profile);
924}
925
[email protected]b5913d72012-02-07 22:26:54926void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01927 if (resizer_rect_ == resizer_rect)
928 return;
929 resizer_rect_ = resizer_rect;
930 if (webwidget_)
931 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54932}
933
initial.commit09911bf2008-07-26 23:55:29934void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31935 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29936 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03937 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59938 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
939 WasHidden());
initial.commit09911bf2008-07-26 23:55:29940}
941
[email protected]3399dd822014-08-09 11:14:24942void RenderWidget::OnWasShown(bool needs_repainting,
943 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41944 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29945 // During shutdown we can just ignore this message.
946 if (!webwidget_)
947 return;
948
949 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03950 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59951 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
952 WasShown());
initial.commit09911bf2008-07-26 23:55:29953
[email protected]8a23afb32014-04-30 22:40:23954 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29955 return;
initial.commit09911bf2008-07-26 23:55:29956
957 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24958 if (compositor_) {
959 ui::LatencyInfo swap_latency_info(latency_info);
960 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
961 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05962 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24963 }
[email protected]aca33f4f2014-05-17 17:08:05964 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29965}
966
[email protected]53d3f302009-12-21 04:42:05967void RenderWidget::OnRequestMoveAck() {
968 DCHECK(pending_window_rect_count_);
969 pending_window_rect_count_--;
970}
971
[email protected]ed7defa2013-03-12 21:29:59972GURL RenderWidget::GetURLForGraphicsContext3D() {
973 return GURL();
[email protected]65225772011-05-12 21:10:24974}
975
[email protected]ebc0e1df2013-08-01 02:46:22976scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03977 // For widgets that are never visible, we don't start the compositor, so we
978 // never get a request for a cc::OutputSurface.
979 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19980
981#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01982 if (SynchronousCompositorFactory* factory =
983 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11984 return factory->CreateOutputSurface(routing_id(),
985 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19986 }
987#endif
988
avi83883c82014-12-23 00:08:49989 const base::CommandLine& command_line =
990 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33991 bool use_software = fallback;
992 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
993 use_software = true;
994
[email protected]0634cdd42013-08-16 00:46:09995 scoped_refptr<ContextProviderCommandBuffer> context_provider;
[email protected]e09994a2014-03-26 19:59:33996 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09997 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:13998 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:33999 if (!context_provider.get()) {
1000 // Cause the compositor to wait and try again.
1001 return scoped_ptr<cc::OutputSurface>();
1002 }
[email protected]0634cdd42013-08-16 00:46:091003 }
[email protected]ebc0e1df2013-08-01 02:46:221004
[email protected]b6eb8e332013-09-10 00:51:011005 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001006 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531007 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
[email protected]65a33ce2014-03-25 22:37:091008 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111009 new DelegatedCompositorOutputSurface(routing_id(),
1010 output_surface_id,
1011 context_provider,
1012 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091013 }
[email protected]0634cdd42013-08-16 00:46:091014 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091015 scoped_ptr<cc::SoftwareOutputDevice> software_device(
1016 new CompositorSoftwareOutputDevice());
1017
[email protected]586871b2014-07-22 17:05:111018 return scoped_ptr<cc::OutputSurface>(
1019 new CompositorOutputSurface(routing_id(),
1020 output_surface_id,
1021 NULL,
1022 software_device.Pass(),
1023 frame_swap_message_queue_,
1024 true));
[email protected]ebc0e1df2013-08-01 02:46:221025 }
[email protected]ed7defa2013-03-12 21:29:591026
[email protected]36e5ff12013-06-11 12:19:291027 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451028 // Composite-to-mailbox is currently used for layout tests in order to cause
1029 // them to draw inside in the renderer to do the readback there. This should
1030 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531031 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161032 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271033 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161034 format = cc::RGB_565;
[email protected]36e5ff12013-06-11 12:19:291035 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111036 new MailboxOutputSurface(routing_id(),
1037 output_surface_id,
1038 context_provider,
1039 scoped_ptr<cc::SoftwareOutputDevice>(),
1040 frame_swap_message_queue_,
1041 format));
[email protected]36e5ff12013-06-11 12:19:291042 }
[email protected]0634cdd42013-08-16 00:46:091043 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:291044 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111045 new CompositorOutputSurface(routing_id(),
1046 output_surface_id,
1047 context_provider,
1048 scoped_ptr<cc::SoftwareOutputDevice>(),
1049 frame_swap_message_queue_,
1050 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281051}
1052
[email protected]4d7e46a2013-11-08 05:33:401053void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241054 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241055 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311056 scheduleComposite();
[email protected]65225772011-05-12 21:10:241057}
1058
[email protected]4d7e46a2013-11-08 05:33:401059void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081060 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081061}
1062
[email protected]4d7e46a2013-11-08 05:33:401063void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241064 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161065
[email protected]404939f2012-06-01 04:06:181066 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161067 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291068}
1069
[email protected]180ef242013-11-07 06:50:461070void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351071 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091072 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191073 base::AutoReset<bool> handling_input_event_resetter(
1074 &handling_input_event_, true);
1075 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291076 return;
[email protected]c27dd4f2014-05-22 18:05:191077 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1078 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521079#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541080 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521081 // |AdapterInputConnection| generates input key events to make sure all JS
1082 // listeners that monitor KeyUp and KeyDown events receive the proper key
1083 // code. Since this input key event comes from IME, we need to set the
1084 // IME event guard here to make sure it does not interfere with other IME
1085 // events.
1086 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1087 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1088 const WebKeyboardEvent& key_event =
1089 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541090 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171091 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091092 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1093 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1094 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1095 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1096 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521097 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521098 }
1099#endif
initial.commit09911bf2008-07-26 23:55:291100
[email protected]8062ab262014-05-27 16:56:431101 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1102 &latency_info);
1103
[email protected]fd847792013-10-24 17:12:351104 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411105 if (base::TimeTicks::IsHighResolution())
1106 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351107
miletusfed8c43b2015-01-26 20:04:521108 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301109 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151110 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131111 TRACE_EVENT_FLOW_STEP0(
miletusfed8c43b2015-01-26 20:04:521112 "input,benchmark",
[email protected]15ba6dea2014-04-02 01:44:131113 "LatencyInfo.Flow",
1114 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1115 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101116
jdduke07788062014-12-05 03:16:301117 // If we don't have a high res timer, these metrics won't be accurate enough
1118 // to be worth collecting. Note that this does introduce some sampling bias.
1119 if (!start_time.is_null())
1120 LogInputEventLatencyUma(*input_event, start_time);
1121
[email protected]6be422b2013-12-08 06:47:311122 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351123 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311124 if (compositor_) {
1125 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351126 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1127 .Pass();
[email protected]6be422b2013-12-08 06:47:311128 }
[email protected]c2eaa8f2013-05-10 02:41:551129
[email protected]67bfb83f2011-09-22 03:36:371130 bool prevent_default = false;
1131 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261132 const WebMouseEvent& mouse_event =
1133 *static_cast<const WebMouseEvent*>(input_event);
1134 TRACE_EVENT2("renderer", "HandleMouseMove",
1135 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421136 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261137 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371138 }
1139
[email protected]cefe9b152014-03-27 18:16:151140 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421141 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151142#if defined(OS_ANDROID)
1143 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1144 // case it should behave like a select key (i.e. causing a click if a button
1145 // is focused). However, if a text field is focused (2), its intended
1146 // behavior is to just show the IME and don't propagate the key.
1147 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1148 // when clicked on an input text field and cause the form submit if clicked
1149 // when the submit button is focused, but not vice-versa.
1150 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1151 // but at this point we have to swallow the event for the scenario (2).
1152 const WebKeyboardEvent& key_event =
1153 *static_cast<const WebKeyboardEvent*>(input_event);
1154 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1155 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1156 OnShowImeIfNeeded();
1157 prevent_default = true;
1158 }
1159#endif
1160 }
[email protected]f56c7872013-06-18 12:31:571161
[email protected]41d86852012-11-07 12:23:241162 if (WebInputEvent::isGestureEventType(input_event->type)) {
1163 const WebGestureEvent& gesture_event =
1164 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421165 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241166 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1167 }
1168
[email protected]67bfb83f2011-09-22 03:36:371169 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121170 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1171 suppress_next_char_events_ = false;
1172 if (!processed && webwidget_)
1173 processed = webwidget_->handleInputEvent(*input_event);
1174 }
1175
1176 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1177 // it's not processed by webkit, then we need to suppress the upcoming Char
1178 // events.
1179 if (!processed && is_keyboard_shortcut)
1180 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291181
[email protected]3d5c243b2012-11-30 00:26:011182 InputEventAckState ack_result = processed ?
1183 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1184 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1185 const WebTouchEvent& touch_event =
1186 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251187 // Hit-test for all the pressed touch points. If there is a touch-handler
1188 // for any of the touch points, then the renderer should continue to receive
1189 // touch events.
1190 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1191 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1192 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271193 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391194 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251195 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1196 break;
1197 }
1198 }
[email protected]3d5c243b2012-11-30 00:26:011199 }
1200
ccamerond4ba47902014-12-17 07:20:311201 // Send mouse wheel events and their disposition to the compositor thread, so
1202 // that they can be used to produce the elastic overscroll effect on Mac.
1203 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311204 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311205 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1206 }
1207
[email protected]721e2302014-04-30 23:42:011208 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061209
charliea3be839702015-01-26 17:35:411210 // If we don't have a fast and accurate Now(), we assume the input handlers
1211 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301212 bool rate_limiting_wanted =
1213 input_event->type == WebInputEvent::MouseMove ||
1214 input_event->type == WebInputEvent::MouseWheel;
1215 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411216 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351217 total_input_handling_time_this_frame_ += (end_time - start_time);
1218 rate_limiting_wanted =
1219 total_input_handling_time_this_frame_.InMicroseconds() >
1220 kInputHandlingTimeThrottlingThresholdMicroseconds;
1221 }
1222
[email protected]7f19e9d2014-05-09 15:16:291223 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1224
[email protected]c27dd4f2014-05-22 18:05:191225 // Note that we can't use handling_event_type_ here since it will be overriden
1226 // by reentrant calls for events after the paused one.
1227 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1228 input_event->type == WebInputEvent::MouseMove;
1229 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561230 InputHostMsg_HandleInputEvent_ACK_Params ack;
1231 ack.type = input_event->type;
1232 ack.state = ack_result;
1233 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551234 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561235 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301236 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551237 // We want to rate limit the input events in this case, so we'll wait for
1238 // painting to finish before ACKing this message.
1239 TRACE_EVENT_INSTANT0("renderer",
1240 "RenderWidget::OnHandleInputEvent ack throttled",
1241 TRACE_EVENT_SCOPE_THREAD);
1242 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291243 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1244 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551245 // As two different kinds of events could cause us to postpone an ack
1246 // we send it now, if we have one pending. The Browser should never
1247 // send us the same kind of event we are delaying the ack for.
1248 Send(pending_input_event_ack_.release());
1249 }
1250 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291251 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1252 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551253 if (compositor_)
1254 compositor_->NotifyInputThrottledUntilCommit();
1255 } else {
1256 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171257 }
[email protected]12fbad812009-09-01 18:21:241258 }
[email protected]5fea4a52014-05-27 00:17:521259 if (input_event->type == WebInputEvent::MouseMove)
1260 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241261
[email protected]3306f262012-09-21 19:20:421262#if defined(OS_ANDROID)
1263 // Allow the IME to be shown when the focus changes as a consequence
1264 // of a processed touch end event.
1265 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361266 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021267#elif defined(USE_AURA)
1268 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1269 // change.
1270 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141271 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361272 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141273 }
[email protected]3306f262012-09-21 19:20:421274#endif
1275
[email protected]67bfb83f2011-09-22 03:36:371276 if (!prevent_default) {
1277 if (WebInputEvent::isKeyboardEventType(input_event->type))
1278 DidHandleKeyEvent();
1279 if (WebInputEvent::isMouseEventType(input_event->type))
1280 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241281 if (WebInputEvent::isTouchEventType(input_event->type))
1282 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371283 }
rouslanf7ebd8832015-01-22 01:54:141284
1285// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1286// virtual keyboard.
1287#if !defined(OS_ANDROID)
1288 // Virtual keyboard is not supported, so react to focus change immediately.
1289 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1290 input_event->type == WebInputEvent::MouseUp)) {
1291 FocusChangeComplete();
1292 }
1293#endif
initial.commit09911bf2008-07-26 23:55:291294}
1295
[email protected]34202de2013-05-06 23:36:221296void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1297 if (webwidget_)
1298 webwidget_->setCursorVisibilityState(is_visible);
1299}
1300
initial.commit09911bf2008-07-26 23:55:291301void RenderWidget::OnMouseCaptureLost() {
1302 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281303 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291304}
1305
1306void RenderWidget::OnSetFocus(bool enable) {
1307 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331308 if (webwidget_)
1309 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291310}
1311
1312void RenderWidget::ClearFocus() {
1313 // We may have got the focus from the browser before this gets processed, in
1314 // which case we do not want to unfocus ourself.
1315 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281316 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291317}
1318
[email protected]fd847792013-10-24 17:12:351319void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291320 if (pending_input_event_ack_) {
1321 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1322 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071323 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291324 }
[email protected]fd847792013-10-24 17:12:351325 total_input_handling_time_this_frame_ = base::TimeDelta();
1326}
1327
initial.commit09911bf2008-07-26 23:55:291328///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461329// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291330
[email protected]244ac1892011-12-02 17:04:471331void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091332 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451333 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581334
[email protected]5b45ad42013-10-25 00:42:041335 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451336 WebRect new_pos(rootWindowRect().x,
1337 rootWindowRect().y,
1338 new_size.width,
1339 new_size.height);
1340 view_screen_rect_ = new_pos;
1341 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031342 }
[email protected]20fbfc22013-05-08 20:50:581343
[email protected]eac2b362013-05-22 07:01:451344 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581345
[email protected]5b45ad42013-10-25 00:42:041346 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581347 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091348 }
[email protected]244ac1892011-12-02 17:04:471349}
1350
[email protected]3a1c8a8032013-03-18 22:35:321351void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051352 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1353 device_scale_factor_));
1354 if (compositor_)
1355 compositor_->setViewportSize(size_, physical_backing_size_);
1356}
1357
[email protected]e195e582013-03-08 01:32:591358void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221359 DCHECK(!host_closing_);
1360
danakj6e3bf8012014-12-16 18:27:531361 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591362 compositor_->setViewportSize(size_, physical_backing_size_);
1363 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031364 StartCompositor();
[email protected]e195e582013-03-08 01:32:591365}
1366
ennef3c58142014-12-09 21:44:381367void RenderWidget::WillCloseLayerTreeView() {
1368 if (host_closing_)
1369 return;
1370
1371 // Prevent new compositors or output surfaces from being created.
1372 host_closing_ = true;
1373
[email protected]aeeedad2014-08-22 18:16:221374 // Always send this notification to prevent new layer tree views from
1375 // being created, even if one hasn't been created yet.
1376 if (webwidget_)
1377 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221378}
1379
[email protected]180ef242013-11-07 06:50:461380blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281381 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061382}
1383
[email protected]9cd43a62012-03-26 08:03:561384void RenderWidget::willBeginCompositorFrame() {
1385 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371386
[email protected]abe8b3a2012-03-28 21:19:371387 // The following two can result in further layout and possibly
1388 // enable GPU acceleration so they need to be called before any painting
1389 // is done.
shuchen3517bb62014-10-15 03:55:571390 UpdateTextInputType();
1391#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361392 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571393#endif
[email protected]abe8b3a2012-03-28 21:19:371394 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561395}
1396
[email protected]3391a0772012-03-28 00:32:071397void RenderWidget::didBecomeReadyForAdditionalInput() {
1398 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351399 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071400}
1401
[email protected]6fceb912013-02-15 06:24:151402void RenderWidget::DidCommitCompositorFrame() {
[email protected]e3244ed2014-06-20 20:04:271403 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161404 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171405#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271406 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1407 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171408#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151409}
1410
[email protected]586871b2014-07-22 17:05:111411// static
1412scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1413 IPC::Message* msg,
1414 MessageDeliveryPolicy policy,
1415 FrameSwapMessageQueue* frame_swap_message_queue,
1416 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1417 bool commit_requested,
1418 int source_frame_number) {
1419 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1420 // No need for lock: this gets changed only on this thread.
1421 !commit_requested &&
1422 // No need for lock: Messages are only enqueued from this thread, if we
1423 // don't have any now, no other thread will add any.
1424 frame_swap_message_queue->Empty()) {
1425 sync_message_filter->Send(msg);
dcheng4b6b5ff2014-10-16 00:42:061426 return nullptr;
[email protected]586871b2014-07-22 17:05:111427 }
1428
1429 bool first_message_for_frame = false;
1430 frame_swap_message_queue->QueueMessageForFrame(policy,
1431 source_frame_number,
1432 make_scoped_ptr(msg),
1433 &first_message_for_frame);
1434 if (first_message_for_frame) {
1435 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1436 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061437 return promise;
[email protected]586871b2014-07-22 17:05:111438 }
dcheng4b6b5ff2014-10-16 00:42:061439 return nullptr;
[email protected]586871b2014-07-22 17:05:111440}
1441
1442void RenderWidget::QueueMessage(IPC::Message* msg,
1443 MessageDeliveryPolicy policy) {
1444 // RenderThreadImpl::current() is NULL in some tests.
1445 if (!compositor_ || !RenderThreadImpl::current()) {
1446 Send(msg);
1447 return;
1448 }
1449
1450 scoped_ptr<cc::SwapPromise> swap_promise =
1451 QueueMessageImpl(msg,
1452 policy,
dcheng58867a92014-08-26 02:50:221453 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111454 RenderThreadImpl::current()->sync_message_filter(),
igsolla70d74312015-01-13 11:17:071455 compositor_->BeginMainFrameRequested(),
[email protected]586871b2014-07-22 17:05:111456 compositor_->GetSourceFrameNumber());
1457
1458 if (swap_promise) {
1459 compositor_->QueueSwapPromise(swap_promise.Pass());
1460 compositor_->SetNeedsCommit();
1461 }
1462}
1463
[email protected]58264a32011-11-17 23:36:151464void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101465 // NOTE: Tests may break if this event is renamed or moved. See
1466 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501467 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161468 // Notify subclasses that we initiated the paint operation.
1469 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151470}
1471
1472void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181473 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1474
1475 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561476 DidFlushPaint();
1477
[email protected]ea3ee0a2012-05-15 03:43:091478 if (!next_paint_flags_ &&
1479 !need_update_rect_for_auto_resize_ &&
1480 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151481 return;
[email protected]ea3ee0a2012-05-15 03:43:091482 }
[email protected]58264a32011-11-17 23:36:151483
1484 ViewHostMsg_UpdateRect_Params params;
1485 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151486 params.plugin_window_moves.swap(plugin_window_moves_);
1487 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151488
1489 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1490 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091491 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151492}
1493
[email protected]8b9e52b2014-01-17 16:35:311494void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531495 if (compositor_ &&
1496 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221497 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311498 }
1499}
1500
[email protected]4873c7d2009-07-16 06:36:281501void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301502 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521503 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401504 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291505 // Only send a SetCursor message if we need to make a change.
1506 if (!current_cursor_.IsEqual(cursor)) {
1507 current_cursor_ = cursor;
1508 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1509 }
1510}
1511
1512// We are supposed to get a single call to Show for a newly created RenderWidget
1513// that was created via RenderWidget::CreateWebView. So, we wait until this
1514// point to dispatch the ShowWidget message.
1515//
1516// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281517// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291518//
[email protected]4873c7d2009-07-16 06:36:281519void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291520 DCHECK(!did_show_) << "received extraneous Show call";
1521 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1522 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1523
[email protected]8de12d942010-11-17 20:42:441524 if (did_show_)
1525 return;
1526
1527 did_show_ = true;
1528 // NOTE: initial_pos_ may still have its default values at this point, but
1529 // that's okay. It'll be ignored if as_popup is false, or the browser
1530 // process will impose a default position otherwise.
1531 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1532 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291533}
1534
[email protected]4873c7d2009-07-16 06:36:281535void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291536}
1537
[email protected]4873c7d2009-07-16 06:36:281538void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291539}
1540
[email protected]2533ce12009-05-09 00:02:241541void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381542 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241543 Send(new ViewHostMsg_Close(routing_id_));
1544}
1545
[email protected]4873c7d2009-07-16 06:36:281546void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321547 if (is_swapped_out_) {
1548 // This widget is currently swapped out, and the active widget is in a
1549 // different process. Have the browser route the close request to the
1550 // active widget instead, so that the correct unload handlers are run.
1551 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1552 return;
1553 }
1554
initial.commit09911bf2008-07-26 23:55:291555 // If a page calls window.close() twice, we'll end up here twice, but that's
1556 // OK. It is safe to send multiple Close messages.
1557
[email protected]2533ce12009-05-09 00:02:241558 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1559 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1560 // could be closed before the JS finishes executing. So instead, post a
1561 // message back to the message loop, which won't run until the JS is
1562 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401563 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211564 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291565}
1566
[email protected]9017d7852013-11-21 17:47:351567void RenderWidget::QueueSyntheticGesture(
1568 scoped_ptr<SyntheticGestureParams> gesture_params,
1569 const SyntheticGestureCompletionCallback& callback) {
1570 DCHECK(!callback.is_null());
1571
1572 pending_synthetic_gesture_callbacks_.push(callback);
1573
1574 SyntheticGesturePacket gesture_packet;
1575 gesture_packet.set_gesture_params(gesture_params.Pass());
1576
1577 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1578}
1579
initial.commit09911bf2008-07-26 23:55:291580void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031581 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381582 WillCloseLayerTreeView();
1583 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291584 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281585 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291586 webwidget_ = NULL;
1587 }
1588}
1589
[email protected]4873c7d2009-07-16 06:36:281590WebRect RenderWidget::windowRect() {
1591 if (pending_window_rect_count_)
1592 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241593
[email protected]80ad8622012-11-07 16:33:031594 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291595}
1596
[email protected]180ef242013-11-07 06:50:461597void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301598 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541599 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301600}
1601
[email protected]b2e4c70132013-10-03 02:07:511602void RenderWidget::setWindowRect(const WebRect& rect) {
1603 WebRect pos = rect;
1604 if (popup_origin_scale_for_emulation_) {
1605 float scale = popup_origin_scale_for_emulation_;
1606 pos.x = popup_screen_origin_for_emulation_.x() +
1607 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1608 pos.y = popup_screen_origin_for_emulation_.y() +
1609 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1610 }
1611
[email protected]5b45ad42013-10-25 00:42:041612 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201613 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031614 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1615 SetPendingWindowRect(pos);
1616 } else {
[email protected]ec951b9d2013-10-20 06:21:201617 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031618 }
initial.commit09911bf2008-07-26 23:55:291619 } else {
bokanf0fd2412014-10-30 15:28:551620 ResizeSynchronously(pos, visible_viewport_size_);
initial.commit09911bf2008-07-26 23:55:291621 }
1622}
1623
[email protected]2533ce12009-05-09 00:02:241624void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1625 pending_window_rect_ = rect;
1626 pending_window_rect_count_++;
1627}
1628
[email protected]4873c7d2009-07-16 06:36:281629WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241630 if (pending_window_rect_count_) {
1631 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1632 // the RootWindowRect is probably going to return wrong results since the
1633 // browser may not have processed the Move yet. There isn't really anything
1634 // good to do in this case, and it shouldn't happen - since this size is
1635 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281636 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241637 }
1638
[email protected]80ad8622012-11-07 16:33:031639 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371640}
1641
[email protected]4873c7d2009-07-16 06:36:281642WebRect RenderWidget::windowResizerRect() {
1643 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191644}
1645
[email protected]fa7b1dc2010-06-23 17:53:041646void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031647 // To prevent this renderer process from sending unnecessary IPC messages to
1648 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041649 // only during the input method attached to the browser process is active.
1650 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291651}
1652
[email protected]37a241c2013-12-03 03:16:171653void RenderWidget::OnCandidateWindowShown() {
1654 webwidget_->didShowCandidateWindow();
1655}
1656
1657void RenderWidget::OnCandidateWindowUpdated() {
1658 webwidget_->didUpdateCandidateWindow();
1659}
1660
1661void RenderWidget::OnCandidateWindowHidden() {
1662 webwidget_->didHideCandidateWindow();
1663}
1664
[email protected]fa7b1dc2010-06-23 17:53:041665void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261666 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041667 const std::vector<WebCompositionUnderline>& underlines,
1668 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131669 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281670 return;
[email protected]66fca5bc2013-05-23 06:58:291671 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361672 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041673 text, WebVector<WebCompositionUnderline>(underlines),
1674 selection_start, selection_end)) {
1675 // If we failed to set the composition text, then we need to let the browser
1676 // process to cancel the input method's ongoing composition session, to make
1677 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221678 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261679 }
[email protected]88dbe32f2013-06-20 23:31:361680 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041681}
1682
[email protected]fcf75d42013-12-03 20:11:261683void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511684 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021685 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131686 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041687 return;
[email protected]66fca5bc2013-05-23 06:58:291688 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041689 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021690 if (text.length())
1691 webwidget_->confirmComposition(text);
1692 else if (keep_selection)
1693 webwidget_->confirmComposition(WebWidget::KeepSelection);
1694 else
1695 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041696 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361697 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291698}
1699
[email protected]0bc1f572013-04-17 01:46:311700void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121701 // During shutdown we can just ignore this message.
1702 if (!webwidget_)
1703 return;
1704
[email protected]0bc1f572013-04-17 01:46:311705 // Even if the browser provides an empty damage rect, it's still expecting to
1706 // receive a repaint ack so just damage the entire widget bounds.
1707 if (size_to_paint.IsEmpty()) {
1708 size_to_paint = size_;
1709 }
1710
[email protected]ec7dc112008-08-06 05:30:121711 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051712 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311713 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121714}
1715
[email protected]79fa22e2013-08-23 15:18:121716void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351717 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1718
1719 pending_synthetic_gesture_callbacks_.front().Run();
1720 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271721}
1722
[email protected]4873c7d2009-07-16 06:36:281723void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111724 if (!webwidget_)
1725 return;
[email protected]4873c7d2009-07-16 06:36:281726 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111727}
1728
[email protected]80ad8622012-11-07 16:33:031729void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1730 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511731 if (screen_metrics_emulator_) {
1732 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1733 view_screen_rect, window_screen_rect);
1734 } else {
1735 view_screen_rect_ = view_screen_rect;
1736 window_screen_rect_ = window_screen_rect;
1737 }
[email protected]80ad8622012-11-07 16:33:031738 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1739}
1740
[email protected]adb362312014-06-28 06:04:241741void RenderWidget::showImeIfNeeded() {
1742 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131743}
1744
[email protected]adb362312014-06-28 06:04:241745void RenderWidget::OnShowImeIfNeeded() {
1746#if defined(OS_ANDROID) || defined(USE_AURA)
1747 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1748#endif
rouslanf7ebd8832015-01-22 01:54:141749
1750// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1751// virtual keyboard.
1752#if !defined(OS_ANDROID)
1753 FocusChangeComplete();
1754#endif
[email protected]adb362312014-06-28 06:04:241755}
1756
1757#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131758void RenderWidget::IncrementOutstandingImeEventAcks() {
1759 ++outstanding_ime_acks_;
1760}
1761
1762void RenderWidget::OnImeEventAck() {
1763 --outstanding_ime_acks_;
1764 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511765}
[email protected]105dffb42013-02-20 03:46:211766#endif
1767
[email protected]0d1ebed12013-08-05 22:01:131768bool RenderWidget::ShouldHandleImeEvent() {
1769#if defined(OS_ANDROID)
1770 return !!webwidget_ && outstanding_ime_acks_ == 0;
1771#else
1772 return !!webwidget_;
1773#endif
1774}
1775
[email protected]c27dd4f2014-05-22 18:05:191776bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1777 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521778 // If we pause multiple times during a single mouse move event, we should
1779 // only send ACK once.
1780 if (!ignore_ack_for_mouse_move_from_debugger_) {
1781 InputHostMsg_HandleInputEvent_ACK_Params ack;
1782 ack.type = handling_event_type_;
1783 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1784 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1785 }
[email protected]c27dd4f2014-05-22 18:05:191786 return true;
1787 }
1788 return false;
1789}
1790
1791void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1792 ignore_ack_for_mouse_move_from_debugger_ = true;
1793}
1794
[email protected]468ac582012-11-20 00:53:191795void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1796 if (device_scale_factor_ == device_scale_factor)
1797 return;
1798
1799 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051800 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191801}
1802
[email protected]28ed6b32014-06-08 02:16:271803bool RenderWidget::SetDeviceColorProfile(
1804 const std::vector<char>& color_profile) {
1805 if (device_color_profile_ == color_profile)
1806 return false;
1807
1808 device_color_profile_ = color_profile;
1809 return true;
1810}
1811
noeldb4df152014-09-16 17:45:201812void RenderWidget::ResetDeviceColorProfileForTesting() {
1813 if (!device_color_profile_.empty())
1814 device_color_profile_.clear();
1815 device_color_profile_.push_back('0');
1816}
1817
[email protected]fcdc5642014-05-09 14:32:241818void RenderWidget::OnOrientationChange() {
1819}
1820
[email protected]ceb36f7d2012-10-31 18:33:241821gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521822 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241823 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521824}
1825
[email protected]bee16aab2009-08-26 15:55:031826void RenderWidget::SetHidden(bool hidden) {
1827 if (is_hidden_ == hidden)
1828 return;
1829
jdduke8fac9d102014-12-20 02:40:131830 // The status has changed. Tell the RenderThread about it and ensure
1831 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031832 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131833 FlushPendingInputEventAck();
1834
[email protected]bee16aab2009-08-26 15:55:031835 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001836 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031837 else
[email protected]b2db9272014-01-10 17:42:001838 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031839}
1840
[email protected]2b624c562011-10-27 22:58:261841void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261842 if (!webwidget_)
1843 return;
1844
1845 if (is_fullscreen_) {
1846 webwidget_->willExitFullScreen();
1847 } else {
1848 webwidget_->willEnterFullScreen();
1849 }
[email protected]2b624c562011-10-27 22:58:261850}
1851
1852void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261853 if (!webwidget_)
1854 return;
1855
1856 if (is_fullscreen_) {
1857 webwidget_->didEnterFullScreen();
1858 } else {
1859 webwidget_->didExitFullScreen();
1860 }
[email protected]2b624c562011-10-27 22:58:261861}
1862
[email protected]674741932009-02-04 23:44:461863bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051864 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461865}
1866
[email protected]674741932009-02-04 23:44:461867void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051868 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461869}
1870
[email protected]674741932009-02-04 23:44:461871void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051872 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461873}
1874
[email protected]b18583c2012-12-18 06:55:271875static bool IsDateTimeInput(ui::TextInputType type) {
1876 return type == ui::TEXT_INPUT_TYPE_DATE ||
1877 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1878 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1879 type == ui::TEXT_INPUT_TYPE_MONTH ||
1880 type == ui::TEXT_INPUT_TYPE_TIME ||
1881 type == ui::TEXT_INPUT_TYPE_WEEK;
1882}
1883
[email protected]66fca5bc2013-05-23 06:58:291884
1885void RenderWidget::StartHandlingImeEvent() {
1886 DCHECK(!handling_ime_event_);
1887 handling_ime_event_ = true;
1888}
1889
1890void RenderWidget::FinishHandlingImeEvent() {
1891 DCHECK(handling_ime_event_);
1892 handling_ime_event_ = false;
1893 // While handling an ime event, text input state and selection bounds updates
1894 // are ignored. These must explicitly be updated once finished handling the
1895 // ime event.
1896 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471897#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361898 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471899#endif
[email protected]66fca5bc2013-05-23 06:58:291900}
1901
shuchen3517bb62014-10-15 03:55:571902void RenderWidget::UpdateTextInputType() {
1903 // On Windows, not only an IME but also an on-screen keyboard relies on the
1904 // latest TextInputType to optimize its layout and functionality. Thus
1905 // |input_method_is_active_| is no longer an appropriate condition to suppress
1906 // TextInputTypeChanged IPC on Windows.
1907 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1908 // on other platforms as well as Windows if the overhead is acceptable.
1909#if !defined(OS_WIN)
1910 if (!input_method_is_active_)
1911 return;
1912#endif
1913
1914 ui::TextInputType new_type = GetTextInputType();
1915 if (IsDateTimeInput(new_type))
1916 return; // Not considered as a text input field in WebKit/Chromium.
1917
1918 bool new_can_compose_inline = CanComposeInline();
1919
1920 blink::WebTextInputInfo new_info;
1921 if (webwidget_)
1922 new_info = webwidget_->textInputInfo();
1923 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201924 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571925
1926 if (text_input_type_ != new_type
1927 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201928 || text_input_mode_ != new_mode
1929 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571930 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1931 new_type,
1932 new_mode,
shuchen82ce8c52014-10-23 01:55:201933 new_can_compose_inline,
1934 new_flags));
shuchen3517bb62014-10-15 03:55:571935 text_input_type_ = new_type;
1936 can_compose_inline_ = new_can_compose_inline;
1937 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201938 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571939 }
1940}
1941
1942#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361943void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1944 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501945 if (handling_ime_event_)
1946 return;
[email protected]90f24152014-04-09 12:41:361947 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291948 return;
[email protected]ad26ef42011-06-17 07:59:451949 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271950 if (IsDateTimeInput(new_type))
1951 return; // Not considered as a text input field in WebKit/Chromium.
1952
[email protected]180ef242013-11-07 06:50:461953 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211954 if (webwidget_)
1955 new_info = webwidget_->textInputInfo();
1956
[email protected]ad26ef42011-06-17 07:59:451957 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211958
[email protected]3306f262012-09-21 19:20:421959 // Only sends text input params if they are changed or if the ime should be
1960 // shown.
[email protected]90f24152014-04-09 12:41:361961 if (show_ime == SHOW_IME_IF_NEEDED ||
1962 (text_input_type_ != new_type ||
1963 text_input_info_ != new_info ||
1964 can_compose_inline_ != new_can_compose_inline)
1965#if defined(OS_ANDROID)
1966 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021967#endif
[email protected]90f24152014-04-09 12:41:361968 ) {
1969 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211970 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401971 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211972 p.value = new_info.value.utf8();
1973 p.selection_start = new_info.selectionStart;
1974 p.selection_end = new_info.selectionEnd;
1975 p.composition_start = new_info.compositionStart;
1976 p.composition_end = new_info.compositionEnd;
1977 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361978 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1979#if defined(USE_AURA)
1980 p.is_non_ime_change = true;
1981#endif
[email protected]183e28d2014-01-20 18:18:021982#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361983 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1984 text_field_is_dirty_;
1985 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131986 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361987 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021988#endif
shuchen3517bb62014-10-15 03:55:571989#if defined(USE_AURA)
1990 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1991 new_type,
1992 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201993 new_can_compose_inline,
1994 new_info.flags));
shuchen3517bb62014-10-15 03:55:571995#endif
[email protected]5b739cb2012-08-21 20:35:211996 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1997
1998 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041999 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452000 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:202001 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:292002 }
initial.commit09911bf2008-07-26 23:55:292003}
shuchen3517bb62014-10-15 03:55:572004#endif
initial.commit09911bf2008-07-26 23:55:292005
[email protected]7c8873e2013-02-05 08:03:012006void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2007 WebRect focus_webrect;
2008 WebRect anchor_webrect;
2009 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2010 *focus = focus_webrect;
2011 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322012}
2013
[email protected]e99ef6f2011-10-16 01:13:002014void RenderWidget::UpdateSelectionBounds() {
2015 if (!webwidget_)
2016 return;
[email protected]66fca5bc2013-05-23 06:58:292017 if (handling_ime_event_)
2018 return;
[email protected]e99ef6f2011-10-16 01:13:002019
jddukeacf809e2014-09-23 20:38:382020 // With composited selection updates, the selection bounds will be reported
2021 // directly by the compositor, in which case explicit IPC selection
2022 // notifications should be suppressed.
2023 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
2024 ViewHostMsg_SelectionBounds_Params params;
2025 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2026 if (selection_anchor_rect_ != params.anchor_rect ||
2027 selection_focus_rect_ != params.focus_rect) {
2028 selection_anchor_rect_ = params.anchor_rect;
2029 selection_focus_rect_ = params.focus_rect;
2030 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2031 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2032 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2033 }
[email protected]58b48a0d2012-06-13 07:01:352034 }
jddukeacf809e2014-09-23 20:38:382035
[email protected]88dbe32f2013-06-20 23:31:362036 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002037}
2038
[email protected]180ef242013-11-07 06:50:462039// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172040#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2041 static_assert(int(blink::WebTextInputType##a) \
2042 == int(ui::TEXT_INPUT_TYPE_##b), \
2043 "mismatching enums: " #a)
2044
2045STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2046STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2047STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2048STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2049STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2050STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2051STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2052STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2053STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2054STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2055STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2056STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2057STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2058STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2059STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2060STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2061STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452062
[email protected]5b739cb2012-08-21 20:35:212063ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462064 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212065 // Check the type is in the range representable by ui::TextInputType.
2066 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462067 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212068 return static_cast<ui::TextInputType>(type);
2069}
2070
[email protected]ad26ef42011-06-17 07:59:452071ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272072 if (webwidget_)
2073 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452074 return ui::TEXT_INPUT_TYPE_NONE;
2075}
2076
[email protected]501ea13d2013-07-09 17:03:292077void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302078#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112079 // TODO(yukawa): Start sending character bounds when the browser side
2080 // implementation becomes ready (crbug.com/424866).
2081#else
[email protected]db4fc1e2013-09-06 20:01:512082 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292083 if (should_update_range) {
2084 GetCompositionRange(&range);
2085 } else {
2086 range = composition_range_;
2087 }
2088 std::vector<gfx::Rect> character_bounds;
2089 GetCompositionCharacterBounds(&character_bounds);
2090
2091 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2092 return;
2093 composition_character_bounds_ = character_bounds;
2094 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222095 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292096 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112097#endif
[email protected]501ea13d2013-07-09 17:03:292098}
2099
[email protected]58b48a0d2012-06-13 07:01:352100void RenderWidget::GetCompositionCharacterBounds(
2101 std::vector<gfx::Rect>* bounds) {
2102 DCHECK(bounds);
2103 bounds->clear();
2104}
2105
[email protected]db4fc1e2013-09-06 20:01:512106void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362107 size_t location, length;
2108 if (webwidget_->compositionRange(&location, &length)) {
2109 range->set_start(location);
2110 range->set_end(location + length);
2111 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2112 range->set_start(location);
2113 range->set_end(location + length);
2114 } else {
[email protected]db4fc1e2013-09-06 20:01:512115 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362116 }
2117}
2118
[email protected]501ea13d2013-07-09 17:03:292119bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512120 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292121 const std::vector<gfx::Rect>& bounds) {
2122 if (composition_range_ != range)
2123 return true;
2124 if (bounds.size() != composition_character_bounds_.size())
2125 return true;
2126 for (size_t i = 0; i < bounds.size(); ++i) {
2127 if (bounds[i] != composition_character_bounds_[i])
2128 return true;
2129 }
2130 return false;
2131}
[email protected]501ea13d2013-07-09 17:03:292132
[email protected]a4f0d882014-05-01 23:48:102133#if defined(OS_ANDROID)
2134void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2135 // If not initialized, default to white. Note that 0 is different from black
2136 // as black still has alpha 0xFF.
2137 if (!bg_color)
2138 bg_color = SK_ColorWHITE;
2139
2140 if (bg_color != body_background_color_) {
2141 body_background_color_ = bg_color;
2142 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2143 }
2144}
timav7a5032e2014-12-05 01:59:432145
2146bool RenderWidget::DoesRecordFullLayer() const {
2147 SynchronousCompositorFactory* synchronous_compositor_factory =
2148 SynchronousCompositorFactory::GetInstance();
2149
2150 // We assume that the absence of synchronous_compositor_factory
2151 // means we are in Chrome. In chrome, we want to clip, i.e.
2152 // *not* to record the full layer.
2153 if (!synchronous_compositor_factory)
2154 return false;
2155
2156 return synchronous_compositor_factory->RecordFullLayer();
2157}
[email protected]a4f0d882014-05-01 23:48:102158#endif
2159
[email protected]ad26ef42011-06-17 07:59:452160bool RenderWidget::CanComposeInline() {
2161 return true;
[email protected]56ea1a62011-05-30 07:05:572162}
2163
[email protected]4873c7d2009-07-16 06:36:282164WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042165 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282166}
2167
[email protected]f660d9c2012-06-06 18:31:212168float RenderWidget::deviceScaleFactor() {
2169 return device_scale_factor_;
2170}
2171
[email protected]fa7b1dc2010-06-23 17:53:042172void RenderWidget::resetInputMethod() {
2173 if (!input_method_is_active_)
2174 return;
2175
[email protected]0e45bd02013-07-12 20:20:022176 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042177 // If the last text input type is not None, then we should finish any
2178 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452179 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042180 // If a composition text exists, then we need to let the browser process
2181 // to cancel the input method's ongoing composition session.
2182 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222183 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042184 }
[email protected]d4cff272011-05-02 15:46:012185
[email protected]88dbe32f2013-06-20 23:31:362186 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042187}
2188
donnda070f3c2015-01-16 19:54:112189#if defined(OS_ANDROID)
2190void RenderWidget::showUnhandledTapUIIfNeeded(
2191 const WebPoint& tapped_position,
2192 const WebNode& tapped_node,
2193 bool page_changed) {
2194 DCHECK(handling_input_event_);
2195 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
2196 !tapped_node.isContentEditable();
2197 if (should_trigger) {
2198 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2199 tapped_position.x, tapped_position.y));
2200 }
2201}
2202#endif
2203
[email protected]c68c3e4e2013-01-24 00:36:562204void RenderWidget::didHandleGestureEvent(
2205 const WebGestureEvent& event,
2206 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022207#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562208 if (event_cancelled)
2209 return;
[email protected]07c70d22014-08-21 08:33:462210 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362211 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462212 } else if (event.type == WebInputEvent::GestureLongPress) {
2213 DCHECK(webwidget_);
2214 if (webwidget_->textInputInfo().value.isEmpty())
2215 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2216 else
2217 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562218 }
2219#endif
2220}
2221
[email protected]7912e822014-04-16 02:37:032222void RenderWidget::StartCompositor() {
2223 // For widgets that are never visible, we don't need the compositor to run
2224 // at all.
2225 if (never_visible_)
2226 return;
danakj6e3bf8012014-12-16 18:27:532227 // In tests without a RenderThreadImpl, don't set ready as this kicks
2228 // off creating output surfaces that the test can't create.
2229 if (!RenderThreadImpl::current())
2230 return;
danakj018271e32014-12-16 21:17:262231 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032232}
2233
[email protected]29e2fb42013-07-19 01:13:472234void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292235 size_t i = 0;
2236 for (; i < plugin_window_moves_.size(); ++i) {
2237 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582238 if (move.rects_valid) {
2239 plugin_window_moves_[i] = move;
2240 } else {
2241 plugin_window_moves_[i].visible = move.visible;
2242 }
initial.commit09911bf2008-07-26 23:55:292243 break;
2244 }
2245 }
2246
2247 if (i == plugin_window_moves_.size())
2248 plugin_window_moves_.push_back(move);
2249}
[email protected]268654772009-08-06 23:02:042250
2251void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2252 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2253 i != plugin_window_moves_.end(); ++i) {
2254 if (i->window == window) {
2255 plugin_window_moves_.erase(i);
2256 break;
2257 }
2258 }
2259}
[email protected]67bfb83f2011-09-22 03:36:372260
[email protected]63b465922012-09-06 02:04:522261
[email protected]24ed0432013-04-24 07:50:312262RenderWidgetCompositor* RenderWidget::compositor() const {
2263 return compositor_.get();
2264}
2265
[email protected]180ef242013-11-07 06:50:462266bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372267 return false;
2268}
[email protected]c3d45532011-10-07 19:20:402269
[email protected]41d86852012-11-07 12:23:242270bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462271 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242272 return false;
2273}
2274
ccamerona7644752014-12-30 01:16:312275void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312276 const blink::WebMouseWheelEvent& wheel_event,
2277 bool event_processed) {
ccamerona7644752014-12-30 01:16:312278 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312279 return;
2280
2281 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2282 // assume that an unprocessed event was entirely an overscroll, and that a
2283 // processed event was entirely scroll.
2284 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2285 // http://crbug.com/442859
2286 cc::InputHandlerScrollResult scroll_result;
2287 if (event_processed) {
2288 scroll_result.did_scroll = true;
2289 } else {
2290 scroll_result.did_overscroll_root = true;
2291 scroll_result.unused_scroll_delta =
2292 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2293 }
2294
2295 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2296 InputHandlerManager* input_handler_manager =
2297 render_thread ? render_thread->input_handler_manager() : NULL;
2298 if (input_handler_manager) {
2299 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2300 routing_id_, wheel_event, scroll_result);
2301 }
2302}
2303
[email protected]ce6689f2013-03-29 12:52:552304void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2305 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2306}
2307
mostynbe29b6882015-01-13 09:59:172308// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2309#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2310 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2311 "mismatching enums: " #a)
2312
[email protected]5d0bbdfa92013-12-10 00:35:512313void RenderWidget::setTouchAction(
2314 blink::WebTouchAction web_touch_action) {
2315
2316 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2317 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192318 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512319 return;
2320
[email protected]a18f67a2013-12-20 19:44:362321 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172322 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2323 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
2324 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
2325 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2326 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362327
2328 content::TouchAction content_touch_action =
2329 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512330 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2331}
2332
[email protected]90f24152014-04-09 12:41:362333void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2334#if defined(OS_ANDROID)
2335 text_field_is_dirty_ = true;
2336#endif
2337}
2338
[email protected]3d5c243b2012-11-30 00:26:012339bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2340 return true;
2341}
2342
[email protected]0634cdd42013-08-16 00:46:092343scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132344RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592345 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092346 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492347 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222348 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092349 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292350 if (!RenderThreadImpl::current())
2351 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402352 CauseForGpuLaunch cause =
2353 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292354 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402355 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222356 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292357 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592358
[email protected]828a3932014-04-02 14:43:132359 // Explicitly disable antialiasing for the compositor. As of the time of
2360 // this writing, the only platform that supported antialiasing for the
2361 // compositor was Mac OS X, because the on-screen OpenGL context creation
2362 // code paths on Windows and Linux didn't yet have multisampling support.
2363 // Mac OS X essentially always behaves as though it's rendering offscreen.
2364 // Multisampling has a heavy cost especially on devices with relatively low
2365 // fill rate like most notebooks, and the Mac implementation would need to
2366 // be optimized to resolve directly into the IOSurface shared between the
2367 // GPU and browser processes. For these reasons and to avoid platform
2368 // disparities we explicitly disable antialiasing.
2369 blink::WebGraphicsContext3D::Attributes attributes;
2370 attributes.antialias = false;
2371 attributes.shareResources = true;
2372 attributes.noAutomaticFlushes = true;
2373 attributes.depth = false;
2374 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132375 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292376 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012377#if defined(OS_ANDROID)
2378 // If we raster too fast we become upload bound, and pending
2379 // uploads consume memory. For maximum upload throughput, we would
2380 // want to allow for upload_throughput * pipeline_time of pending
2381 // uploads, after which we are just wasting memory. Since we don't
2382 // know our upload throughput yet, this just caps our memory usage.
2383 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272384 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032385 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012386 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032387 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012388 // Deadline to draw a frame to achieve 60 frames per second.
2389 const size_t kMillisecondsPerFrame = 16;
2390 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032391 size_t max_transfer_buffer_usage_mb =
2392 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2393 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012394 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2395 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292396 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032397 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012398#endif
[email protected]96ab016c2013-10-23 00:50:292399
[email protected]96ab016c2013-10-23 00:50:292400 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132401 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2402 GetURLForGraphicsContext3D(),
2403 gpu_channel_host.get(),
2404 attributes,
[email protected]828a3932014-04-02 14:43:132405 lose_context_when_out_of_memory,
2406 limits,
2407 NULL));
[email protected]0634cdd42013-08-16 00:46:092408 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592409}
2410
[email protected]e3244ed2014-06-20 20:04:272411void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2412 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162413}
2414
[email protected]e3244ed2014-06-20 20:04:272415void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2416 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162417}
2418
[email protected]de3c5d82014-05-28 22:12:592419void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2420 render_frames_.AddObserver(frame);
2421}
2422
2423void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2424 render_frames_.RemoveObserver(frame);
2425}
2426
[email protected]a017938b2014-05-27 21:17:172427#if defined(VIDEO_HOLE)
2428void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2429 video_hole_frames_.AddObserver(frame);
2430}
2431
2432void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2433 video_hole_frames_.RemoveObserver(frame);
2434}
2435#endif // defined(VIDEO_HOLE)
2436
[email protected]e9ff79c2012-10-19 21:31:262437} // namespace content