blob: 49542c39ed32b1149bdb060f0e07bd7becc7599d [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,
sievers4e33dae2015-02-25 20:43:58781 const 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);
[email protected]d9083762013-03-24 01:36:40795 }
[email protected]60d47ac2013-03-01 23:42:44796
[email protected]dade8992013-03-04 07:34:34797 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02798 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
799 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28800 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34801 resizer_rect_ = resizer_rect;
802
803 // NOTE: We may have entered fullscreen mode without changing our size.
804 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
805 if (fullscreen_change)
806 WillToggleFullscreen();
807 is_fullscreen_ = is_fullscreen;
808
aelias6004fe02015-02-07 21:43:01809 webwidget_->setTopControlsHeight(top_controls_height,
810 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43811
[email protected]61e2b3cc2012-03-02 16:13:34812 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34813 size_ = new_size;
814
[email protected]61e2b3cc2012-03-02 16:13:34815 // When resizing, we want to wait to paint before ACK'ing the resize. This
816 // ensures that we only resize as fast as we can paint. We only need to
817 // send an ACK if we are resized to a non-empty rect.
818 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45819 }
820
[email protected]bb6378fe2014-04-28 21:19:44821 webwidget()->resizePinchViewport(gfx::Size(
822 visible_viewport_size.width(),
823 visible_viewport_size.height()));
824
[email protected]632c4382013-05-15 08:58:45825 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58826 // In this case there is no paint/composite and therefore no
827 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
828 // ack through a fake ViewHostMsg_UpdateRect or a different message.
829 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34830 }
831
[email protected]20fbfc22013-05-08 20:50:58832 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45833 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58834 set_next_paint_is_resize_ack();
835
[email protected]61e2b3cc2012-03-02 16:13:34836 if (fullscreen_change)
837 DidToggleFullscreen();
838
839 // If a resize ack is requested and it isn't set-up, then no more resizes will
840 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45841 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29842}
843
bokanc007c3a2015-02-03 07:15:56844void RenderWidget::SetWindowRectSynchronously(
845 const gfx::Rect& new_window_rect) {
846 Resize(new_window_rect.size(),
847 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02848 top_controls_shrink_blink_size_,
849 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56850 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01851 gfx::Rect(),
852 is_fullscreen_,
853 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56854 view_screen_rect_ = new_window_rect;
855 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02856 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56857 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02858}
859
initial.commit09911bf2008-07-26 23:55:29860void RenderWidget::OnClose() {
861 if (closing_)
862 return;
863 closing_ = true;
864
865 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03866 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]b2db9272014-01-10 17:42:00867 if (RenderThreadImpl::current())
868 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]380244092011-10-07 17:26:27869 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03870 SetHidden(false);
871 }
initial.commit09911bf2008-07-26 23:55:29872
initial.commit09911bf2008-07-26 23:55:29873 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25874 // now. Post a task that only gets invoked when there are no nested message
875 // loops.
alexclarkee19d4ef2015-01-09 17:45:40876 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29877 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25878
879 // Balances the AddRef taken when we called AddRoute.
880 Release();
initial.commit09911bf2008-07-26 23:55:29881}
882
[email protected]61e2b3cc2012-03-02 16:13:34883// Got a response from the browser after the renderer decided to create a new
884// view.
[email protected]fc4404d2012-11-07 19:53:30885void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34886 DCHECK(routing_id_ != MSG_ROUTING_NONE);
887
[email protected]fc4404d2012-11-07 19:53:30888 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34889}
890
[email protected]0fdd5012013-05-29 08:05:56891void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04892 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32893 return;
894
[email protected]b2e4c70132013-10-03 02:07:51895 if (screen_metrics_emulator_) {
896 screen_metrics_emulator_->OnResizeMessage(params);
897 return;
898 }
899
[email protected]fcdc5642014-05-09 14:32:24900 bool orientation_changed =
901 screen_info_.orientationAngle != params.screen_info.orientationAngle;
902
[email protected]0fdd5012013-05-29 08:05:56903 screen_info_ = params.screen_info;
904 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02905 Resize(params.new_size,
906 params.physical_backing_size,
907 params.top_controls_shrink_blink_size,
908 params.top_controls_height,
909 params.visible_viewport_size,
910 params.resizer_rect,
911 params.is_fullscreen,
sievers4e33dae2015-02-25 20:43:58912 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24913
914 if (orientation_changed)
915 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29916}
917
noel89949e62014-09-30 01:12:41918void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
919 SetDeviceColorProfile(color_profile);
920}
921
[email protected]b5913d72012-02-07 22:26:54922void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01923 if (resizer_rect_ == resizer_rect)
924 return;
925 resizer_rect_ = resizer_rect;
926 if (webwidget_)
927 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54928}
929
initial.commit09911bf2008-07-26 23:55:29930void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31931 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29932 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03933 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59934 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
935 WasHidden());
initial.commit09911bf2008-07-26 23:55:29936}
937
[email protected]3399dd822014-08-09 11:14:24938void RenderWidget::OnWasShown(bool needs_repainting,
939 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41940 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29941 // During shutdown we can just ignore this message.
942 if (!webwidget_)
943 return;
944
945 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03946 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59947 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
948 WasShown());
initial.commit09911bf2008-07-26 23:55:29949
[email protected]8a23afb32014-04-30 22:40:23950 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29951 return;
initial.commit09911bf2008-07-26 23:55:29952
953 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24954 if (compositor_) {
955 ui::LatencyInfo swap_latency_info(latency_info);
956 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
957 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05958 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24959 }
[email protected]aca33f4f2014-05-17 17:08:05960 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29961}
962
[email protected]53d3f302009-12-21 04:42:05963void RenderWidget::OnRequestMoveAck() {
964 DCHECK(pending_window_rect_count_);
965 pending_window_rect_count_--;
966}
967
[email protected]ed7defa2013-03-12 21:29:59968GURL RenderWidget::GetURLForGraphicsContext3D() {
969 return GURL();
[email protected]65225772011-05-12 21:10:24970}
971
[email protected]ebc0e1df2013-08-01 02:46:22972scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03973 // For widgets that are never visible, we don't start the compositor, so we
974 // never get a request for a cc::OutputSurface.
975 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19976
977#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01978 if (SynchronousCompositorFactory* factory =
979 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11980 return factory->CreateOutputSurface(routing_id(),
981 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19982 }
983#endif
984
avi83883c82014-12-23 00:08:49985 const base::CommandLine& command_line =
986 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33987 bool use_software = fallback;
988 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
989 use_software = true;
990
[email protected]0634cdd42013-08-16 00:46:09991 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17992 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33993 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09994 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:13995 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:33996 if (!context_provider.get()) {
997 // Cause the compositor to wait and try again.
998 return scoped_ptr<cc::OutputSurface>();
999 }
vmiura78b69282015-02-14 00:01:171000
1001 worker_context_provider = ContextProviderCommandBuffer::Create(
1002 CreateGraphicsContext3D(), "RenderWorker");
1003 if (!worker_context_provider.get()) {
1004 // Cause the compositor to wait and try again.
1005 return scoped_ptr<cc::OutputSurface>();
1006 }
[email protected]0634cdd42013-08-16 00:46:091007 }
[email protected]ebc0e1df2013-08-01 02:46:221008
[email protected]b6eb8e332013-09-10 00:51:011009 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:001010 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:531011 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
caseqff9c74c2015-02-10 14:56:291012 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171013 routing_id(), output_surface_id, context_provider,
1014 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091015 }
[email protected]0634cdd42013-08-16 00:46:091016 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091017 scoped_ptr<cc::SoftwareOutputDevice> software_device(
1018 new CompositorSoftwareOutputDevice());
1019
caseqff9c74c2015-02-10 14:56:291020 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
1021 routing_id(), output_surface_id, nullptr, nullptr,
1022 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221023 }
[email protected]ed7defa2013-03-12 21:29:591024
[email protected]36e5ff12013-06-11 12:19:291025 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:451026 // Composite-to-mailbox is currently used for layout tests in order to cause
1027 // them to draw inside in the renderer to do the readback there. This should
1028 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:531029 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:161030 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:271031 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:161032 format = cc::RGB_565;
caseqff9c74c2015-02-10 14:56:291033 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171034 routing_id(), output_surface_id, context_provider,
1035 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1036 frame_swap_message_queue_, format));
[email protected]36e5ff12013-06-11 12:19:291037 }
[email protected]0634cdd42013-08-16 00:46:091038 bool use_swap_compositor_frame_message = false;
caseqff9c74c2015-02-10 14:56:291039 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171040 routing_id(), output_surface_id, context_provider,
1041 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(),
1042 frame_swap_message_queue_, use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281043}
1044
[email protected]4d7e46a2013-11-08 05:33:401045void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241046 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241047 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311048 scheduleComposite();
[email protected]65225772011-05-12 21:10:241049}
1050
[email protected]4d7e46a2013-11-08 05:33:401051void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081052 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081053}
1054
[email protected]4d7e46a2013-11-08 05:33:401055void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241056 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161057
[email protected]404939f2012-06-01 04:06:181058 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161059 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291060}
1061
[email protected]180ef242013-11-07 06:50:461062void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351063 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091064 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191065 base::AutoReset<bool> handling_input_event_resetter(
1066 &handling_input_event_, true);
1067 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291068 return;
[email protected]c27dd4f2014-05-22 18:05:191069 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1070 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521071#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541072 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521073 // |AdapterInputConnection| generates input key events to make sure all JS
1074 // listeners that monitor KeyUp and KeyDown events receive the proper key
1075 // code. Since this input key event comes from IME, we need to set the
1076 // IME event guard here to make sure it does not interfere with other IME
1077 // events.
1078 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1079 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1080 const WebKeyboardEvent& key_event =
1081 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541082 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171083 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091084 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1085 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1086 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1087 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1088 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521089 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521090 }
1091#endif
initial.commit09911bf2008-07-26 23:55:291092
[email protected]8062ab262014-05-27 16:56:431093 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1094 &latency_info);
1095
[email protected]fd847792013-10-24 17:12:351096 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411097 if (base::TimeTicks::IsHighResolution())
1098 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351099
miletusfed8c43b2015-01-26 20:04:521100 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301101 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151102 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131103 TRACE_EVENT_FLOW_STEP0(
miletusfed8c43b2015-01-26 20:04:521104 "input,benchmark",
[email protected]15ba6dea2014-04-02 01:44:131105 "LatencyInfo.Flow",
1106 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1107 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101108
jdduke07788062014-12-05 03:16:301109 // If we don't have a high res timer, these metrics won't be accurate enough
1110 // to be worth collecting. Note that this does introduce some sampling bias.
1111 if (!start_time.is_null())
1112 LogInputEventLatencyUma(*input_event, start_time);
1113
[email protected]6be422b2013-12-08 06:47:311114 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351115 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311116 if (compositor_) {
1117 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351118 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1119 .Pass();
[email protected]6be422b2013-12-08 06:47:311120 }
[email protected]c2eaa8f2013-05-10 02:41:551121
[email protected]67bfb83f2011-09-22 03:36:371122 bool prevent_default = false;
1123 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261124 const WebMouseEvent& mouse_event =
1125 *static_cast<const WebMouseEvent*>(input_event);
1126 TRACE_EVENT2("renderer", "HandleMouseMove",
1127 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421128 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261129 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371130 }
1131
[email protected]cefe9b152014-03-27 18:16:151132 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421133 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151134#if defined(OS_ANDROID)
1135 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1136 // case it should behave like a select key (i.e. causing a click if a button
1137 // is focused). However, if a text field is focused (2), its intended
1138 // behavior is to just show the IME and don't propagate the key.
1139 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1140 // when clicked on an input text field and cause the form submit if clicked
1141 // when the submit button is focused, but not vice-versa.
1142 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1143 // but at this point we have to swallow the event for the scenario (2).
1144 const WebKeyboardEvent& key_event =
1145 *static_cast<const WebKeyboardEvent*>(input_event);
1146 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1147 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1148 OnShowImeIfNeeded();
1149 prevent_default = true;
1150 }
1151#endif
1152 }
[email protected]f56c7872013-06-18 12:31:571153
[email protected]41d86852012-11-07 12:23:241154 if (WebInputEvent::isGestureEventType(input_event->type)) {
1155 const WebGestureEvent& gesture_event =
1156 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421157 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241158 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1159 }
1160
[email protected]67bfb83f2011-09-22 03:36:371161 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121162 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1163 suppress_next_char_events_ = false;
1164 if (!processed && webwidget_)
1165 processed = webwidget_->handleInputEvent(*input_event);
1166 }
1167
1168 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1169 // it's not processed by webkit, then we need to suppress the upcoming Char
1170 // events.
1171 if (!processed && is_keyboard_shortcut)
1172 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291173
[email protected]3d5c243b2012-11-30 00:26:011174 InputEventAckState ack_result = processed ?
1175 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1176 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1177 const WebTouchEvent& touch_event =
1178 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251179 // Hit-test for all the pressed touch points. If there is a touch-handler
1180 // for any of the touch points, then the renderer should continue to receive
1181 // touch events.
1182 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1183 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1184 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271185 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391186 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251187 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1188 break;
1189 }
1190 }
[email protected]3d5c243b2012-11-30 00:26:011191 }
1192
ccamerond4ba47902014-12-17 07:20:311193 // Send mouse wheel events and their disposition to the compositor thread, so
1194 // that they can be used to produce the elastic overscroll effect on Mac.
1195 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311196 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311197 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1198 }
1199
[email protected]721e2302014-04-30 23:42:011200 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061201
charliea3be839702015-01-26 17:35:411202 // If we don't have a fast and accurate Now(), we assume the input handlers
1203 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301204 bool rate_limiting_wanted =
1205 input_event->type == WebInputEvent::MouseMove ||
1206 input_event->type == WebInputEvent::MouseWheel;
1207 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411208 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351209 total_input_handling_time_this_frame_ += (end_time - start_time);
1210 rate_limiting_wanted =
1211 total_input_handling_time_this_frame_.InMicroseconds() >
1212 kInputHandlingTimeThrottlingThresholdMicroseconds;
1213 }
1214
[email protected]7f19e9d2014-05-09 15:16:291215 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1216
[email protected]c27dd4f2014-05-22 18:05:191217 // Note that we can't use handling_event_type_ here since it will be overriden
1218 // by reentrant calls for events after the paused one.
1219 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1220 input_event->type == WebInputEvent::MouseMove;
1221 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561222 InputHostMsg_HandleInputEvent_ACK_Params ack;
1223 ack.type = input_event->type;
1224 ack.state = ack_result;
1225 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551226 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561227 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301228 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551229 // We want to rate limit the input events in this case, so we'll wait for
1230 // painting to finish before ACKing this message.
1231 TRACE_EVENT_INSTANT0("renderer",
1232 "RenderWidget::OnHandleInputEvent ack throttled",
1233 TRACE_EVENT_SCOPE_THREAD);
1234 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291235 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1236 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551237 // As two different kinds of events could cause us to postpone an ack
1238 // we send it now, if we have one pending. The Browser should never
1239 // send us the same kind of event we are delaying the ack for.
1240 Send(pending_input_event_ack_.release());
1241 }
1242 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291243 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1244 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551245 if (compositor_)
1246 compositor_->NotifyInputThrottledUntilCommit();
1247 } else {
1248 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171249 }
[email protected]12fbad812009-09-01 18:21:241250 }
[email protected]5fea4a52014-05-27 00:17:521251 if (input_event->type == WebInputEvent::MouseMove)
1252 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241253
[email protected]3306f262012-09-21 19:20:421254#if defined(OS_ANDROID)
1255 // Allow the IME to be shown when the focus changes as a consequence
1256 // of a processed touch end event.
1257 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361258 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021259#elif defined(USE_AURA)
1260 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1261 // change.
1262 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141263 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361264 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141265 }
[email protected]3306f262012-09-21 19:20:421266#endif
1267
[email protected]67bfb83f2011-09-22 03:36:371268 if (!prevent_default) {
1269 if (WebInputEvent::isKeyboardEventType(input_event->type))
1270 DidHandleKeyEvent();
1271 if (WebInputEvent::isMouseEventType(input_event->type))
1272 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241273 if (WebInputEvent::isTouchEventType(input_event->type))
1274 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371275 }
rouslanf7ebd8832015-01-22 01:54:141276
1277// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1278// virtual keyboard.
1279#if !defined(OS_ANDROID)
1280 // Virtual keyboard is not supported, so react to focus change immediately.
1281 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1282 input_event->type == WebInputEvent::MouseUp)) {
1283 FocusChangeComplete();
1284 }
1285#endif
initial.commit09911bf2008-07-26 23:55:291286}
1287
[email protected]34202de2013-05-06 23:36:221288void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1289 if (webwidget_)
1290 webwidget_->setCursorVisibilityState(is_visible);
1291}
1292
initial.commit09911bf2008-07-26 23:55:291293void RenderWidget::OnMouseCaptureLost() {
1294 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281295 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291296}
1297
1298void RenderWidget::OnSetFocus(bool enable) {
1299 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331300 if (webwidget_)
1301 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291302}
1303
1304void RenderWidget::ClearFocus() {
1305 // We may have got the focus from the browser before this gets processed, in
1306 // which case we do not want to unfocus ourself.
1307 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281308 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291309}
1310
[email protected]fd847792013-10-24 17:12:351311void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291312 if (pending_input_event_ack_) {
1313 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1314 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071315 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291316 }
[email protected]fd847792013-10-24 17:12:351317 total_input_handling_time_this_frame_ = base::TimeDelta();
1318}
1319
initial.commit09911bf2008-07-26 23:55:291320///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461321// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291322
[email protected]244ac1892011-12-02 17:04:471323void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091324 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451325 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581326
[email protected]5b45ad42013-10-25 00:42:041327 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451328 WebRect new_pos(rootWindowRect().x,
1329 rootWindowRect().y,
1330 new_size.width,
1331 new_size.height);
1332 view_screen_rect_ = new_pos;
1333 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031334 }
[email protected]20fbfc22013-05-08 20:50:581335
[email protected]eac2b362013-05-22 07:01:451336 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581337
[email protected]5b45ad42013-10-25 00:42:041338 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581339 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091340 }
[email protected]244ac1892011-12-02 17:04:471341}
1342
[email protected]3a1c8a8032013-03-18 22:35:321343void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051344 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1345 device_scale_factor_));
1346 if (compositor_)
1347 compositor_->setViewportSize(size_, physical_backing_size_);
1348}
1349
[email protected]e195e582013-03-08 01:32:591350void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221351 DCHECK(!host_closing_);
1352
danakj6e3bf8012014-12-16 18:27:531353 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591354 compositor_->setViewportSize(size_, physical_backing_size_);
1355 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031356 StartCompositor();
[email protected]e195e582013-03-08 01:32:591357}
1358
ennef3c58142014-12-09 21:44:381359void RenderWidget::WillCloseLayerTreeView() {
1360 if (host_closing_)
1361 return;
1362
1363 // Prevent new compositors or output surfaces from being created.
1364 host_closing_ = true;
1365
[email protected]aeeedad2014-08-22 18:16:221366 // Always send this notification to prevent new layer tree views from
1367 // being created, even if one hasn't been created yet.
1368 if (webwidget_)
1369 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221370}
1371
[email protected]180ef242013-11-07 06:50:461372blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281373 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061374}
1375
[email protected]9cd43a62012-03-26 08:03:561376void RenderWidget::willBeginCompositorFrame() {
1377 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371378
[email protected]abe8b3a2012-03-28 21:19:371379 // The following two can result in further layout and possibly
1380 // enable GPU acceleration so they need to be called before any painting
1381 // is done.
shuchen3517bb62014-10-15 03:55:571382 UpdateTextInputType();
1383#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361384 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571385#endif
[email protected]abe8b3a2012-03-28 21:19:371386 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561387}
1388
[email protected]3391a0772012-03-28 00:32:071389void RenderWidget::didBecomeReadyForAdditionalInput() {
1390 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351391 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071392}
1393
[email protected]6fceb912013-02-15 06:24:151394void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441395 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1396 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271397 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161398 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171399#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271400 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1401 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171402#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151403}
1404
[email protected]586871b2014-07-22 17:05:111405// static
1406scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1407 IPC::Message* msg,
1408 MessageDeliveryPolicy policy,
1409 FrameSwapMessageQueue* frame_swap_message_queue,
1410 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111411 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111412 bool first_message_for_frame = false;
1413 frame_swap_message_queue->QueueMessageForFrame(policy,
1414 source_frame_number,
1415 make_scoped_ptr(msg),
1416 &first_message_for_frame);
1417 if (first_message_for_frame) {
1418 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1419 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061420 return promise;
[email protected]586871b2014-07-22 17:05:111421 }
dcheng4b6b5ff2014-10-16 00:42:061422 return nullptr;
[email protected]586871b2014-07-22 17:05:111423}
1424
1425void RenderWidget::QueueMessage(IPC::Message* msg,
1426 MessageDeliveryPolicy policy) {
1427 // RenderThreadImpl::current() is NULL in some tests.
1428 if (!compositor_ || !RenderThreadImpl::current()) {
1429 Send(msg);
1430 return;
1431 }
1432
1433 scoped_ptr<cc::SwapPromise> swap_promise =
1434 QueueMessageImpl(msg,
1435 policy,
dcheng58867a92014-08-26 02:50:221436 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111437 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111438 compositor_->GetSourceFrameNumber());
1439
1440 if (swap_promise) {
1441 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351442 // Request a commit. This might either A) request a commit ahead of time
1443 // or B) request a commit which is not needed because there are not
1444 // pending updates. If B) then the commit will be skipped and the swap
1445 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1446 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1447 // can_cancel_commit is not unset.
1448 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111449 }
1450}
1451
[email protected]58264a32011-11-17 23:36:151452void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101453 // NOTE: Tests may break if this event is renamed or moved. See
1454 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501455 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161456 // Notify subclasses that we initiated the paint operation.
1457 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151458}
1459
1460void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181461 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1462
1463 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561464 DidFlushPaint();
1465
[email protected]ea3ee0a2012-05-15 03:43:091466 if (!next_paint_flags_ &&
1467 !need_update_rect_for_auto_resize_ &&
1468 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151469 return;
[email protected]ea3ee0a2012-05-15 03:43:091470 }
[email protected]58264a32011-11-17 23:36:151471
1472 ViewHostMsg_UpdateRect_Params params;
1473 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151474 params.plugin_window_moves.swap(plugin_window_moves_);
1475 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151476
1477 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1478 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091479 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151480}
1481
[email protected]8b9e52b2014-01-17 16:35:311482void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531483 if (compositor_ &&
1484 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221485 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311486 }
1487}
1488
[email protected]4873c7d2009-07-16 06:36:281489void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301490 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521491 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401492 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291493 // Only send a SetCursor message if we need to make a change.
1494 if (!current_cursor_.IsEqual(cursor)) {
1495 current_cursor_ = cursor;
1496 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1497 }
1498}
1499
1500// We are supposed to get a single call to Show for a newly created RenderWidget
1501// that was created via RenderWidget::CreateWebView. So, we wait until this
1502// point to dispatch the ShowWidget message.
1503//
1504// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281505// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291506//
[email protected]4873c7d2009-07-16 06:36:281507void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291508 DCHECK(!did_show_) << "received extraneous Show call";
1509 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1510 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1511
[email protected]8de12d942010-11-17 20:42:441512 if (did_show_)
1513 return;
1514
1515 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561516 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441517 // that's okay. It'll be ignored if as_popup is false, or the browser
1518 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561519 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1520 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291521}
1522
[email protected]4873c7d2009-07-16 06:36:281523void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291524}
1525
[email protected]4873c7d2009-07-16 06:36:281526void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291527}
1528
[email protected]2533ce12009-05-09 00:02:241529void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381530 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241531 Send(new ViewHostMsg_Close(routing_id_));
1532}
1533
[email protected]4873c7d2009-07-16 06:36:281534void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321535 if (is_swapped_out_) {
1536 // This widget is currently swapped out, and the active widget is in a
1537 // different process. Have the browser route the close request to the
1538 // active widget instead, so that the correct unload handlers are run.
1539 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1540 return;
1541 }
1542
initial.commit09911bf2008-07-26 23:55:291543 // If a page calls window.close() twice, we'll end up here twice, but that's
1544 // OK. It is safe to send multiple Close messages.
1545
[email protected]2533ce12009-05-09 00:02:241546 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1547 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1548 // could be closed before the JS finishes executing. So instead, post a
1549 // message back to the message loop, which won't run until the JS is
1550 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401551 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211552 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291553}
1554
[email protected]9017d7852013-11-21 17:47:351555void RenderWidget::QueueSyntheticGesture(
1556 scoped_ptr<SyntheticGestureParams> gesture_params,
1557 const SyntheticGestureCompletionCallback& callback) {
1558 DCHECK(!callback.is_null());
1559
1560 pending_synthetic_gesture_callbacks_.push(callback);
1561
1562 SyntheticGesturePacket gesture_packet;
1563 gesture_packet.set_gesture_params(gesture_params.Pass());
1564
1565 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1566}
1567
initial.commit09911bf2008-07-26 23:55:291568void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031569 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381570 WillCloseLayerTreeView();
1571 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291572 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281573 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291574 webwidget_ = NULL;
1575 }
1576}
1577
[email protected]4873c7d2009-07-16 06:36:281578WebRect RenderWidget::windowRect() {
1579 if (pending_window_rect_count_)
1580 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241581
[email protected]80ad8622012-11-07 16:33:031582 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291583}
1584
[email protected]180ef242013-11-07 06:50:461585void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301586 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541587 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301588}
1589
[email protected]b2e4c70132013-10-03 02:07:511590void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561591 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511592 if (popup_origin_scale_for_emulation_) {
1593 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561594 window_rect.x = popup_screen_origin_for_emulation_.x() +
1595 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1596 window_rect.y = popup_screen_origin_for_emulation_.y() +
1597 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511598 }
1599
[email protected]5b45ad42013-10-25 00:42:041600 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201601 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561602 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1603 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031604 } else {
bokanc007c3a2015-02-03 07:15:561605 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031606 }
initial.commit09911bf2008-07-26 23:55:291607 } else {
bokanc007c3a2015-02-03 07:15:561608 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291609 }
1610}
1611
[email protected]2533ce12009-05-09 00:02:241612void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1613 pending_window_rect_ = rect;
1614 pending_window_rect_count_++;
1615}
1616
[email protected]4873c7d2009-07-16 06:36:281617WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241618 if (pending_window_rect_count_) {
1619 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1620 // the RootWindowRect is probably going to return wrong results since the
1621 // browser may not have processed the Move yet. There isn't really anything
1622 // good to do in this case, and it shouldn't happen - since this size is
1623 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281624 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241625 }
1626
[email protected]80ad8622012-11-07 16:33:031627 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371628}
1629
[email protected]4873c7d2009-07-16 06:36:281630WebRect RenderWidget::windowResizerRect() {
1631 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191632}
1633
[email protected]fa7b1dc2010-06-23 17:53:041634void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031635 // To prevent this renderer process from sending unnecessary IPC messages to
1636 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041637 // only during the input method attached to the browser process is active.
1638 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291639}
1640
[email protected]37a241c2013-12-03 03:16:171641void RenderWidget::OnCandidateWindowShown() {
1642 webwidget_->didShowCandidateWindow();
1643}
1644
1645void RenderWidget::OnCandidateWindowUpdated() {
1646 webwidget_->didUpdateCandidateWindow();
1647}
1648
1649void RenderWidget::OnCandidateWindowHidden() {
1650 webwidget_->didHideCandidateWindow();
1651}
1652
[email protected]fa7b1dc2010-06-23 17:53:041653void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261654 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041655 const std::vector<WebCompositionUnderline>& underlines,
1656 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131657 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281658 return;
[email protected]66fca5bc2013-05-23 06:58:291659 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361660 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041661 text, WebVector<WebCompositionUnderline>(underlines),
1662 selection_start, selection_end)) {
1663 // If we failed to set the composition text, then we need to let the browser
1664 // process to cancel the input method's ongoing composition session, to make
1665 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221666 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261667 }
[email protected]88dbe32f2013-06-20 23:31:361668 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041669}
1670
[email protected]fcf75d42013-12-03 20:11:261671void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511672 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021673 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131674 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041675 return;
[email protected]66fca5bc2013-05-23 06:58:291676 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041677 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021678 if (text.length())
1679 webwidget_->confirmComposition(text);
1680 else if (keep_selection)
1681 webwidget_->confirmComposition(WebWidget::KeepSelection);
1682 else
1683 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041684 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361685 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291686}
1687
[email protected]0bc1f572013-04-17 01:46:311688void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121689 // During shutdown we can just ignore this message.
1690 if (!webwidget_)
1691 return;
1692
[email protected]0bc1f572013-04-17 01:46:311693 // Even if the browser provides an empty damage rect, it's still expecting to
1694 // receive a repaint ack so just damage the entire widget bounds.
1695 if (size_to_paint.IsEmpty()) {
1696 size_to_paint = size_;
1697 }
1698
[email protected]ec7dc112008-08-06 05:30:121699 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051700 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311701 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121702}
1703
[email protected]79fa22e2013-08-23 15:18:121704void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351705 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1706
1707 pending_synthetic_gesture_callbacks_.front().Run();
1708 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271709}
1710
[email protected]4873c7d2009-07-16 06:36:281711void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111712 if (!webwidget_)
1713 return;
[email protected]4873c7d2009-07-16 06:36:281714 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111715}
1716
[email protected]80ad8622012-11-07 16:33:031717void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1718 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511719 if (screen_metrics_emulator_) {
1720 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1721 view_screen_rect, window_screen_rect);
1722 } else {
1723 view_screen_rect_ = view_screen_rect;
1724 window_screen_rect_ = window_screen_rect;
1725 }
[email protected]80ad8622012-11-07 16:33:031726 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1727}
1728
[email protected]adb362312014-06-28 06:04:241729void RenderWidget::showImeIfNeeded() {
1730 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131731}
1732
[email protected]adb362312014-06-28 06:04:241733void RenderWidget::OnShowImeIfNeeded() {
1734#if defined(OS_ANDROID) || defined(USE_AURA)
1735 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1736#endif
rouslanf7ebd8832015-01-22 01:54:141737
1738// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1739// virtual keyboard.
1740#if !defined(OS_ANDROID)
1741 FocusChangeComplete();
1742#endif
[email protected]adb362312014-06-28 06:04:241743}
1744
1745#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131746void RenderWidget::IncrementOutstandingImeEventAcks() {
1747 ++outstanding_ime_acks_;
1748}
1749
1750void RenderWidget::OnImeEventAck() {
1751 --outstanding_ime_acks_;
1752 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511753}
[email protected]105dffb42013-02-20 03:46:211754#endif
1755
[email protected]0d1ebed12013-08-05 22:01:131756bool RenderWidget::ShouldHandleImeEvent() {
1757#if defined(OS_ANDROID)
1758 return !!webwidget_ && outstanding_ime_acks_ == 0;
1759#else
1760 return !!webwidget_;
1761#endif
1762}
1763
[email protected]c27dd4f2014-05-22 18:05:191764bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1765 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521766 // If we pause multiple times during a single mouse move event, we should
1767 // only send ACK once.
1768 if (!ignore_ack_for_mouse_move_from_debugger_) {
1769 InputHostMsg_HandleInputEvent_ACK_Params ack;
1770 ack.type = handling_event_type_;
1771 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1772 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1773 }
[email protected]c27dd4f2014-05-22 18:05:191774 return true;
1775 }
1776 return false;
1777}
1778
1779void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1780 ignore_ack_for_mouse_move_from_debugger_ = true;
1781}
1782
[email protected]468ac582012-11-20 00:53:191783void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1784 if (device_scale_factor_ == device_scale_factor)
1785 return;
1786
1787 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051788 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191789}
1790
[email protected]28ed6b32014-06-08 02:16:271791bool RenderWidget::SetDeviceColorProfile(
1792 const std::vector<char>& color_profile) {
1793 if (device_color_profile_ == color_profile)
1794 return false;
1795
1796 device_color_profile_ = color_profile;
1797 return true;
1798}
1799
noeldb4df152014-09-16 17:45:201800void RenderWidget::ResetDeviceColorProfileForTesting() {
1801 if (!device_color_profile_.empty())
1802 device_color_profile_.clear();
1803 device_color_profile_.push_back('0');
1804}
1805
[email protected]fcdc5642014-05-09 14:32:241806void RenderWidget::OnOrientationChange() {
1807}
1808
[email protected]ceb36f7d2012-10-31 18:33:241809gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521810 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241811 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521812}
1813
[email protected]bee16aab2009-08-26 15:55:031814void RenderWidget::SetHidden(bool hidden) {
1815 if (is_hidden_ == hidden)
1816 return;
1817
jdduke8fac9d102014-12-20 02:40:131818 // The status has changed. Tell the RenderThread about it and ensure
1819 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031820 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131821 FlushPendingInputEventAck();
1822
[email protected]bee16aab2009-08-26 15:55:031823 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001824 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031825 else
[email protected]b2db9272014-01-10 17:42:001826 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031827}
1828
[email protected]2b624c562011-10-27 22:58:261829void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261830 if (!webwidget_)
1831 return;
1832
1833 if (is_fullscreen_) {
1834 webwidget_->willExitFullScreen();
1835 } else {
1836 webwidget_->willEnterFullScreen();
1837 }
[email protected]2b624c562011-10-27 22:58:261838}
1839
1840void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261841 if (!webwidget_)
1842 return;
1843
1844 if (is_fullscreen_) {
1845 webwidget_->didEnterFullScreen();
1846 } else {
1847 webwidget_->didExitFullScreen();
1848 }
[email protected]2b624c562011-10-27 22:58:261849}
1850
[email protected]674741932009-02-04 23:44:461851bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051852 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461853}
1854
[email protected]674741932009-02-04 23:44:461855void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051856 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461857}
1858
[email protected]674741932009-02-04 23:44:461859void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051860 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461861}
1862
[email protected]b18583c2012-12-18 06:55:271863static bool IsDateTimeInput(ui::TextInputType type) {
1864 return type == ui::TEXT_INPUT_TYPE_DATE ||
1865 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1866 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1867 type == ui::TEXT_INPUT_TYPE_MONTH ||
1868 type == ui::TEXT_INPUT_TYPE_TIME ||
1869 type == ui::TEXT_INPUT_TYPE_WEEK;
1870}
1871
[email protected]66fca5bc2013-05-23 06:58:291872
1873void RenderWidget::StartHandlingImeEvent() {
1874 DCHECK(!handling_ime_event_);
1875 handling_ime_event_ = true;
1876}
1877
1878void RenderWidget::FinishHandlingImeEvent() {
1879 DCHECK(handling_ime_event_);
1880 handling_ime_event_ = false;
1881 // While handling an ime event, text input state and selection bounds updates
1882 // are ignored. These must explicitly be updated once finished handling the
1883 // ime event.
1884 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471885#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361886 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471887#endif
[email protected]66fca5bc2013-05-23 06:58:291888}
1889
shuchen3517bb62014-10-15 03:55:571890void RenderWidget::UpdateTextInputType() {
1891 // On Windows, not only an IME but also an on-screen keyboard relies on the
1892 // latest TextInputType to optimize its layout and functionality. Thus
1893 // |input_method_is_active_| is no longer an appropriate condition to suppress
1894 // TextInputTypeChanged IPC on Windows.
1895 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1896 // on other platforms as well as Windows if the overhead is acceptable.
1897#if !defined(OS_WIN)
1898 if (!input_method_is_active_)
1899 return;
1900#endif
1901
1902 ui::TextInputType new_type = GetTextInputType();
1903 if (IsDateTimeInput(new_type))
1904 return; // Not considered as a text input field in WebKit/Chromium.
1905
1906 bool new_can_compose_inline = CanComposeInline();
1907
1908 blink::WebTextInputInfo new_info;
1909 if (webwidget_)
1910 new_info = webwidget_->textInputInfo();
1911 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201912 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571913
1914 if (text_input_type_ != new_type
1915 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201916 || text_input_mode_ != new_mode
1917 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571918 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1919 new_type,
1920 new_mode,
shuchen82ce8c52014-10-23 01:55:201921 new_can_compose_inline,
1922 new_flags));
shuchen3517bb62014-10-15 03:55:571923 text_input_type_ = new_type;
1924 can_compose_inline_ = new_can_compose_inline;
1925 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201926 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571927 }
1928}
1929
1930#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361931void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1932 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501933 if (handling_ime_event_)
1934 return;
[email protected]90f24152014-04-09 12:41:361935 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291936 return;
[email protected]ad26ef42011-06-17 07:59:451937 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271938 if (IsDateTimeInput(new_type))
1939 return; // Not considered as a text input field in WebKit/Chromium.
1940
[email protected]180ef242013-11-07 06:50:461941 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211942 if (webwidget_)
1943 new_info = webwidget_->textInputInfo();
1944
[email protected]ad26ef42011-06-17 07:59:451945 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211946
[email protected]3306f262012-09-21 19:20:421947 // Only sends text input params if they are changed or if the ime should be
1948 // shown.
[email protected]90f24152014-04-09 12:41:361949 if (show_ime == SHOW_IME_IF_NEEDED ||
1950 (text_input_type_ != new_type ||
1951 text_input_info_ != new_info ||
1952 can_compose_inline_ != new_can_compose_inline)
1953#if defined(OS_ANDROID)
1954 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021955#endif
[email protected]90f24152014-04-09 12:41:361956 ) {
1957 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211958 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401959 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211960 p.value = new_info.value.utf8();
1961 p.selection_start = new_info.selectionStart;
1962 p.selection_end = new_info.selectionEnd;
1963 p.composition_start = new_info.compositionStart;
1964 p.composition_end = new_info.compositionEnd;
1965 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361966 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1967#if defined(USE_AURA)
1968 p.is_non_ime_change = true;
1969#endif
[email protected]183e28d2014-01-20 18:18:021970#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361971 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1972 text_field_is_dirty_;
1973 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131974 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361975 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021976#endif
shuchen3517bb62014-10-15 03:55:571977#if defined(USE_AURA)
1978 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1979 new_type,
1980 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201981 new_can_compose_inline,
1982 new_info.flags));
shuchen3517bb62014-10-15 03:55:571983#endif
[email protected]5b739cb2012-08-21 20:35:211984 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1985
1986 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041987 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451988 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201989 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291990 }
initial.commit09911bf2008-07-26 23:55:291991}
shuchen3517bb62014-10-15 03:55:571992#endif
initial.commit09911bf2008-07-26 23:55:291993
[email protected]7c8873e2013-02-05 08:03:011994void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1995 WebRect focus_webrect;
1996 WebRect anchor_webrect;
1997 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1998 *focus = focus_webrect;
1999 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322000}
2001
[email protected]e99ef6f2011-10-16 01:13:002002void RenderWidget::UpdateSelectionBounds() {
2003 if (!webwidget_)
2004 return;
[email protected]66fca5bc2013-05-23 06:58:292005 if (handling_ime_event_)
2006 return;
[email protected]e99ef6f2011-10-16 01:13:002007
jddukeacf809e2014-09-23 20:38:382008 // With composited selection updates, the selection bounds will be reported
2009 // directly by the compositor, in which case explicit IPC selection
2010 // notifications should be suppressed.
2011 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
2012 ViewHostMsg_SelectionBounds_Params params;
2013 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2014 if (selection_anchor_rect_ != params.anchor_rect ||
2015 selection_focus_rect_ != params.focus_rect) {
2016 selection_anchor_rect_ = params.anchor_rect;
2017 selection_focus_rect_ = params.focus_rect;
2018 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2019 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2020 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2021 }
[email protected]58b48a0d2012-06-13 07:01:352022 }
jddukeacf809e2014-09-23 20:38:382023
[email protected]88dbe32f2013-06-20 23:31:362024 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002025}
2026
[email protected]180ef242013-11-07 06:50:462027// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172028#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2029 static_assert(int(blink::WebTextInputType##a) \
2030 == int(ui::TEXT_INPUT_TYPE_##b), \
2031 "mismatching enums: " #a)
2032
2033STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2034STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2035STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2036STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2037STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2038STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2039STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2040STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2041STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2042STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2043STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2044STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2045STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2046STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2047STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2048STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2049STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452050
[email protected]5b739cb2012-08-21 20:35:212051ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462052 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212053 // Check the type is in the range representable by ui::TextInputType.
2054 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462055 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212056 return static_cast<ui::TextInputType>(type);
2057}
2058
[email protected]ad26ef42011-06-17 07:59:452059ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272060 if (webwidget_)
2061 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452062 return ui::TEXT_INPUT_TYPE_NONE;
2063}
2064
[email protected]501ea13d2013-07-09 17:03:292065void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302066#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112067 // TODO(yukawa): Start sending character bounds when the browser side
2068 // implementation becomes ready (crbug.com/424866).
2069#else
[email protected]db4fc1e2013-09-06 20:01:512070 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292071 if (should_update_range) {
2072 GetCompositionRange(&range);
2073 } else {
2074 range = composition_range_;
2075 }
2076 std::vector<gfx::Rect> character_bounds;
2077 GetCompositionCharacterBounds(&character_bounds);
2078
2079 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2080 return;
2081 composition_character_bounds_ = character_bounds;
2082 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222083 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292084 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112085#endif
[email protected]501ea13d2013-07-09 17:03:292086}
2087
[email protected]58b48a0d2012-06-13 07:01:352088void RenderWidget::GetCompositionCharacterBounds(
2089 std::vector<gfx::Rect>* bounds) {
2090 DCHECK(bounds);
2091 bounds->clear();
2092}
2093
[email protected]db4fc1e2013-09-06 20:01:512094void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362095 size_t location, length;
2096 if (webwidget_->compositionRange(&location, &length)) {
2097 range->set_start(location);
2098 range->set_end(location + length);
2099 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2100 range->set_start(location);
2101 range->set_end(location + length);
2102 } else {
[email protected]db4fc1e2013-09-06 20:01:512103 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362104 }
2105}
2106
[email protected]501ea13d2013-07-09 17:03:292107bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512108 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292109 const std::vector<gfx::Rect>& bounds) {
2110 if (composition_range_ != range)
2111 return true;
2112 if (bounds.size() != composition_character_bounds_.size())
2113 return true;
2114 for (size_t i = 0; i < bounds.size(); ++i) {
2115 if (bounds[i] != composition_character_bounds_[i])
2116 return true;
2117 }
2118 return false;
2119}
[email protected]501ea13d2013-07-09 17:03:292120
[email protected]a4f0d882014-05-01 23:48:102121#if defined(OS_ANDROID)
2122void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2123 // If not initialized, default to white. Note that 0 is different from black
2124 // as black still has alpha 0xFF.
2125 if (!bg_color)
2126 bg_color = SK_ColorWHITE;
2127
2128 if (bg_color != body_background_color_) {
2129 body_background_color_ = bg_color;
2130 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2131 }
2132}
timav7a5032e2014-12-05 01:59:432133
2134bool RenderWidget::DoesRecordFullLayer() const {
2135 SynchronousCompositorFactory* synchronous_compositor_factory =
2136 SynchronousCompositorFactory::GetInstance();
2137
2138 // We assume that the absence of synchronous_compositor_factory
2139 // means we are in Chrome. In chrome, we want to clip, i.e.
2140 // *not* to record the full layer.
2141 if (!synchronous_compositor_factory)
2142 return false;
2143
2144 return synchronous_compositor_factory->RecordFullLayer();
2145}
[email protected]a4f0d882014-05-01 23:48:102146#endif
2147
[email protected]ad26ef42011-06-17 07:59:452148bool RenderWidget::CanComposeInline() {
2149 return true;
[email protected]56ea1a62011-05-30 07:05:572150}
2151
[email protected]4873c7d2009-07-16 06:36:282152WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042153 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282154}
2155
[email protected]f660d9c2012-06-06 18:31:212156float RenderWidget::deviceScaleFactor() {
2157 return device_scale_factor_;
2158}
2159
[email protected]fa7b1dc2010-06-23 17:53:042160void RenderWidget::resetInputMethod() {
2161 if (!input_method_is_active_)
2162 return;
2163
[email protected]0e45bd02013-07-12 20:20:022164 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042165 // If the last text input type is not None, then we should finish any
2166 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452167 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042168 // If a composition text exists, then we need to let the browser process
2169 // to cancel the input method's ongoing composition session.
2170 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222171 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042172 }
[email protected]d4cff272011-05-02 15:46:012173
[email protected]88dbe32f2013-06-20 23:31:362174 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042175}
2176
donnda070f3c2015-01-16 19:54:112177#if defined(OS_ANDROID)
2178void RenderWidget::showUnhandledTapUIIfNeeded(
2179 const WebPoint& tapped_position,
2180 const WebNode& tapped_node,
2181 bool page_changed) {
2182 DCHECK(handling_input_event_);
2183 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
2184 !tapped_node.isContentEditable();
2185 if (should_trigger) {
2186 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2187 tapped_position.x, tapped_position.y));
2188 }
2189}
2190#endif
2191
[email protected]c68c3e4e2013-01-24 00:36:562192void RenderWidget::didHandleGestureEvent(
2193 const WebGestureEvent& event,
2194 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022195#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562196 if (event_cancelled)
2197 return;
[email protected]07c70d22014-08-21 08:33:462198 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362199 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462200 } else if (event.type == WebInputEvent::GestureLongPress) {
2201 DCHECK(webwidget_);
2202 if (webwidget_->textInputInfo().value.isEmpty())
2203 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2204 else
2205 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562206 }
2207#endif
2208}
2209
[email protected]7912e822014-04-16 02:37:032210void RenderWidget::StartCompositor() {
2211 // For widgets that are never visible, we don't need the compositor to run
2212 // at all.
2213 if (never_visible_)
2214 return;
danakj6e3bf8012014-12-16 18:27:532215 // In tests without a RenderThreadImpl, don't set ready as this kicks
2216 // off creating output surfaces that the test can't create.
2217 if (!RenderThreadImpl::current())
2218 return;
danakj018271e32014-12-16 21:17:262219 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032220}
2221
[email protected]29e2fb42013-07-19 01:13:472222void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292223 size_t i = 0;
2224 for (; i < plugin_window_moves_.size(); ++i) {
2225 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582226 if (move.rects_valid) {
2227 plugin_window_moves_[i] = move;
2228 } else {
2229 plugin_window_moves_[i].visible = move.visible;
2230 }
initial.commit09911bf2008-07-26 23:55:292231 break;
2232 }
2233 }
2234
2235 if (i == plugin_window_moves_.size())
2236 plugin_window_moves_.push_back(move);
2237}
[email protected]268654772009-08-06 23:02:042238
2239void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2240 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2241 i != plugin_window_moves_.end(); ++i) {
2242 if (i->window == window) {
2243 plugin_window_moves_.erase(i);
2244 break;
2245 }
2246 }
2247}
[email protected]67bfb83f2011-09-22 03:36:372248
[email protected]63b465922012-09-06 02:04:522249
[email protected]24ed0432013-04-24 07:50:312250RenderWidgetCompositor* RenderWidget::compositor() const {
2251 return compositor_.get();
2252}
2253
[email protected]180ef242013-11-07 06:50:462254bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372255 return false;
2256}
[email protected]c3d45532011-10-07 19:20:402257
[email protected]41d86852012-11-07 12:23:242258bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462259 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242260 return false;
2261}
2262
ccamerona7644752014-12-30 01:16:312263void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312264 const blink::WebMouseWheelEvent& wheel_event,
2265 bool event_processed) {
ccamerona7644752014-12-30 01:16:312266 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312267 return;
2268
2269 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2270 // assume that an unprocessed event was entirely an overscroll, and that a
2271 // processed event was entirely scroll.
2272 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2273 // http://crbug.com/442859
2274 cc::InputHandlerScrollResult scroll_result;
2275 if (event_processed) {
2276 scroll_result.did_scroll = true;
2277 } else {
2278 scroll_result.did_overscroll_root = true;
2279 scroll_result.unused_scroll_delta =
2280 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2281 }
2282
2283 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2284 InputHandlerManager* input_handler_manager =
2285 render_thread ? render_thread->input_handler_manager() : NULL;
2286 if (input_handler_manager) {
2287 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2288 routing_id_, wheel_event, scroll_result);
2289 }
2290}
2291
[email protected]ce6689f2013-03-29 12:52:552292void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2293 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2294}
2295
mostynbe29b6882015-01-13 09:59:172296// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2297#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2298 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2299 "mismatching enums: " #a)
2300
[email protected]5d0bbdfa92013-12-10 00:35:512301void RenderWidget::setTouchAction(
2302 blink::WebTouchAction web_touch_action) {
2303
2304 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2305 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192306 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512307 return;
2308
[email protected]a18f67a2013-12-20 19:44:362309 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172310 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2311 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
2312 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
2313 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2314 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362315
2316 content::TouchAction content_touch_action =
2317 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512318 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2319}
2320
[email protected]90f24152014-04-09 12:41:362321void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2322#if defined(OS_ANDROID)
2323 text_field_is_dirty_ = true;
2324#endif
2325}
2326
[email protected]3d5c243b2012-11-30 00:26:012327bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2328 return true;
2329}
2330
[email protected]0634cdd42013-08-16 00:46:092331scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132332RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592333 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092334 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492335 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222336 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092337 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292338 if (!RenderThreadImpl::current())
2339 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402340 CauseForGpuLaunch cause =
2341 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292342 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402343 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222344 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292345 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592346
[email protected]828a3932014-04-02 14:43:132347 // Explicitly disable antialiasing for the compositor. As of the time of
2348 // this writing, the only platform that supported antialiasing for the
2349 // compositor was Mac OS X, because the on-screen OpenGL context creation
2350 // code paths on Windows and Linux didn't yet have multisampling support.
2351 // Mac OS X essentially always behaves as though it's rendering offscreen.
2352 // Multisampling has a heavy cost especially on devices with relatively low
2353 // fill rate like most notebooks, and the Mac implementation would need to
2354 // be optimized to resolve directly into the IOSurface shared between the
2355 // GPU and browser processes. For these reasons and to avoid platform
2356 // disparities we explicitly disable antialiasing.
2357 blink::WebGraphicsContext3D::Attributes attributes;
2358 attributes.antialias = false;
2359 attributes.shareResources = true;
2360 attributes.noAutomaticFlushes = true;
2361 attributes.depth = false;
2362 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132363 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292364 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012365#if defined(OS_ANDROID)
2366 // If we raster too fast we become upload bound, and pending
2367 // uploads consume memory. For maximum upload throughput, we would
2368 // want to allow for upload_throughput * pipeline_time of pending
2369 // uploads, after which we are just wasting memory. Since we don't
2370 // know our upload throughput yet, this just caps our memory usage.
2371 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272372 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032373 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012374 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032375 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012376 // Deadline to draw a frame to achieve 60 frames per second.
2377 const size_t kMillisecondsPerFrame = 16;
2378 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032379 size_t max_transfer_buffer_usage_mb =
2380 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2381 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012382 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2383 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292384 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032385 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012386#endif
[email protected]96ab016c2013-10-23 00:50:292387
[email protected]96ab016c2013-10-23 00:50:292388 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132389 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2390 GetURLForGraphicsContext3D(),
2391 gpu_channel_host.get(),
2392 attributes,
[email protected]828a3932014-04-02 14:43:132393 lose_context_when_out_of_memory,
2394 limits,
2395 NULL));
[email protected]0634cdd42013-08-16 00:46:092396 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592397}
2398
[email protected]e3244ed2014-06-20 20:04:272399void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2400 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162401}
2402
[email protected]e3244ed2014-06-20 20:04:272403void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2404 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162405}
2406
[email protected]de3c5d82014-05-28 22:12:592407void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2408 render_frames_.AddObserver(frame);
2409}
2410
2411void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2412 render_frames_.RemoveObserver(frame);
2413}
2414
[email protected]a017938b2014-05-27 21:17:172415#if defined(VIDEO_HOLE)
2416void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2417 video_hole_frames_.AddObserver(frame);
2418}
2419
2420void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2421 video_hole_frames_.RemoveObserver(frame);
2422}
2423#endif // defined(VIDEO_HOLE)
2424
[email protected]e9ff79c2012-10-19 21:31:262425} // namespace content