blob: f3e5a62786140b62f69e66cc9cb1a0c6fa96fb85 [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"
[email protected]366ae242011-05-10 02:23:5810#include "base/debug/trace_event.h"
[email protected]b2e92592014-01-10 15:47:1511#include "base/debug/trace_event_synthetic_delay.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4014#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3015#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2117#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2719#include "base/sys_info.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"
[email protected]aaf68892013-07-18 00:11:3058#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebSize.h"
61#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4362#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
[email protected]2255a9332013-06-17 05:12:3163#include "third_party/WebKit/public/web/WebPagePopup.h"
64#include "third_party/WebKit/public/web/WebPopupMenu.h"
65#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
66#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3867#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
[email protected]d353541f2012-05-03 22:45:4168#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1369#include "ui/base/ui_base_switches.h"
[email protected]de2cf8c2013-10-25 19:46:4670#include "ui/gfx/frame_time.h"
tfarina655f81d2014-12-23 02:38:5071#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0972#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3273#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4874#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2775#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4176#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4877
[email protected]eeb93112013-05-01 19:41:1078#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1579#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0780#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1081#endif
82
[email protected]661eb9d2009-02-03 02:11:4883#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4984#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5285#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4186#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4887#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4488
[email protected]2255a9332013-06-17 05:12:3189#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2990
[email protected]180ef242013-11-07 06:50:4691using blink::WebCompositionUnderline;
92using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4393using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4694using blink::WebGestureEvent;
95using blink::WebInputEvent;
96using blink::WebKeyboardEvent;
97using blink::WebMouseEvent;
98using blink::WebMouseWheelEvent;
99using blink::WebNavigationPolicy;
100using blink::WebPagePopup;
101using blink::WebPopupMenu;
102using blink::WebPopupMenuInfo;
103using blink::WebPopupType;
104using blink::WebRange;
105using blink::WebRect;
106using blink::WebScreenInfo;
107using blink::WebSize;
108using blink::WebTextDirection;
109using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25110using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46111using blink::WebVector;
112using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26113
[email protected]6a4d7f62013-01-07 21:32:13114namespace {
[email protected]b256eca2013-07-11 10:57:40115
116typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
117
118class TextInputModeMapSingleton {
119 public:
120 static TextInputModeMapSingleton* GetInstance() {
121 return Singleton<TextInputModeMapSingleton>::get();
122 }
[email protected]dd705d4d2013-11-27 08:14:41123 TextInputModeMapSingleton() {
124 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
125 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
126 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
127 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
128 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
129 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
130 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
131 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
132 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
133 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
134 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40135 }
[email protected]dd705d4d2013-11-27 08:14:41136 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40137 private:
[email protected]dd705d4d2013-11-27 08:14:41138 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40139
140 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
141
142 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
143};
144
[email protected]dd705d4d2013-11-27 08:14:41145ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40146 static TextInputModeMapSingleton* singleton =
147 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41148 TextInputModeMap::const_iterator it =
149 singleton->map().find(input_mode.utf8());
150 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40151 return ui::TEXT_INPUT_MODE_DEFAULT;
152 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13153}
[email protected]b256eca2013-07-11 10:57:40154
[email protected]fd847792013-10-24 17:12:35155// TODO(brianderson): Replace the hard-coded threshold with a fraction of
156// the BeginMainFrame interval.
157// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
158// be spent in input hanlders before input starts getting throttled.
159const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
160
jdduke07788062014-12-05 03:16:30161int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) {
162 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds))
163 .ToInternalValue();
164}
165
166void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now) {
167 UMA_HISTOGRAM_CUSTOM_COUNTS(
168 "Event.AggregatedLatency.Renderer2",
169 GetEventLatencyMicros(event, now),
170 1,
171 10000000,
172 100);
173
174#define CASE_TYPE(t) \
175 case WebInputEvent::t: \
176 UMA_HISTOGRAM_CUSTOM_COUNTS( \
177 "Event.Latency.Renderer2." #t, \
178 GetEventLatencyMicros(event, now), \
179 1, \
180 10000000, \
181 100); \
182 break;
183
184 switch(event.type) {
185 CASE_TYPE(Undefined);
186 CASE_TYPE(MouseDown);
187 CASE_TYPE(MouseUp);
188 CASE_TYPE(MouseMove);
189 CASE_TYPE(MouseEnter);
190 CASE_TYPE(MouseLeave);
191 CASE_TYPE(ContextMenu);
192 CASE_TYPE(MouseWheel);
193 CASE_TYPE(RawKeyDown);
194 CASE_TYPE(KeyDown);
195 CASE_TYPE(KeyUp);
196 CASE_TYPE(Char);
197 CASE_TYPE(GestureScrollBegin);
198 CASE_TYPE(GestureScrollEnd);
199 CASE_TYPE(GestureScrollUpdate);
200 CASE_TYPE(GestureFlingStart);
201 CASE_TYPE(GestureFlingCancel);
202 CASE_TYPE(GestureShowPress);
203 CASE_TYPE(GestureTap);
204 CASE_TYPE(GestureTapUnconfirmed);
205 CASE_TYPE(GestureTapDown);
206 CASE_TYPE(GestureTapCancel);
207 CASE_TYPE(GestureDoubleTap);
208 CASE_TYPE(GestureTwoFingerTap);
209 CASE_TYPE(GestureLongPress);
210 CASE_TYPE(GestureLongTap);
211 CASE_TYPE(GesturePinchBegin);
212 CASE_TYPE(GesturePinchEnd);
213 CASE_TYPE(GesturePinchUpdate);
214 CASE_TYPE(TouchStart);
215 CASE_TYPE(TouchMove);
216 CASE_TYPE(TouchEnd);
217 CASE_TYPE(TouchCancel);
218 default:
219 // Must include default to let blink::WebInputEvent add new event types
220 // before they're added here.
221 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event.type;
222 break;
223 }
224
225#undef CASE_TYPE
226}
227
[email protected]b256eca2013-07-11 10:57:40228} // namespace
229
[email protected]e9ff79c2012-10-19 21:31:26230namespace content {
[email protected]62cb33cae2009-03-27 23:30:22231
[email protected]b2e4c70132013-10-03 02:07:51232// RenderWidget::ScreenMetricsEmulator ----------------------------------------
233
234class RenderWidget::ScreenMetricsEmulator {
235 public:
236 ScreenMetricsEmulator(
237 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43238 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51239 virtual ~ScreenMetricsEmulator();
240
[email protected]19193682014-04-03 15:01:43241 // Scale and offset used to convert between host coordinates
242 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51243 float scale() { return scale_; }
[email protected]9a2d7ee32013-12-05 12:15:49244 gfx::Point offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43245 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51246 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56247 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51248
249 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43250 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51251
252 // The following methods alter handlers' behavior for messages related to
253 // widget size and position.
254 void OnResizeMessage(const ViewMsg_Resize_Params& params);
255 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
256 const gfx::Rect& window_screen_rect);
257 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31258 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51259
260 private:
[email protected]19193682014-04-03 15:01:43261 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02262 void Apply(bool top_controls_shrink_blink_size,
263 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44264 gfx::Rect resizer_rect,
265 bool is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51266
267 RenderWidget* widget_;
268
[email protected]7f99fc22013-11-08 14:05:58269 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43270 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51271
[email protected]a179d3962013-11-12 14:44:40272 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51273 float scale_;
[email protected]a179d3962013-11-12 14:44:40274 gfx::Point offset_;
[email protected]b2e4c70132013-10-03 02:07:51275
[email protected]19193682014-04-03 15:01:43276 // Widget rect as passed to webwidget.
277 gfx::Rect applied_widget_rect_;
278
[email protected]b2e4c70132013-10-03 02:07:51279 // Original values to restore back after emulation ends.
280 gfx::Size original_size_;
281 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28282 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46283 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51284 gfx::Rect original_view_screen_rect_;
285 gfx::Rect original_window_screen_rect_;
286};
287
288RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
289 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43290 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51291 : widget_(widget),
[email protected]19193682014-04-03 15:01:43292 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51293 scale_(1.f) {
294 original_size_ = widget_->size_;
295 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28296 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51297 original_screen_info_ = widget_->screen_info_;
298 original_view_screen_rect_ = widget_->view_screen_rect_;
299 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02300 Apply(widget_->top_controls_shrink_blink_size_,
301 widget_->top_controls_height_,
302 widget_->resizer_rect_,
303 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51304}
305
306RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
307 widget_->screen_info_ = original_screen_info_;
308
309 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
[email protected]7f99fc22013-11-08 14:05:58310 widget_->SetScreenMetricsEmulationParameters(0.f, gfx::Point(), 1.f);
[email protected]b2e4c70132013-10-03 02:07:51311 widget_->view_screen_rect_ = original_view_screen_rect_;
312 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01313 widget_->Resize(original_size_,
314 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02315 widget_->top_controls_shrink_blink_size_,
316 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01317 original_visible_viewport_size_,
318 widget_->resizer_rect_,
319 widget_->is_fullscreen_,
320 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51321}
322
323void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43324 const WebDeviceEmulationParams& params) {
325 params_ = params;
326 Reapply();
327}
328
329void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02330 Apply(widget_->top_controls_shrink_blink_size_,
331 widget_->top_controls_height_,
332 widget_->resizer_rect_,
333 widget_->is_fullscreen_);
[email protected]b2e4c70132013-10-03 02:07:51334}
335
[email protected]19193682014-04-03 15:01:43336void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02337 bool top_controls_shrink_blink_size,
338 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44339 gfx::Rect resizer_rect,
340 bool is_fullscreen) {
[email protected]92d13b72014-05-09 14:42:31341 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
342 if (!applied_widget_rect_.width())
343 applied_widget_rect_.set_width(original_size_.width());
344 if (!applied_widget_rect_.height())
345 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43346
[email protected]f442ee42014-05-14 11:53:12347 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02348 int original_width = std::max(original_size_.width(), 1);
349 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51350 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02351 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51352 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02353 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51354 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
355 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01356
357 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43358 offset_.set_x(
359 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01360 offset_.set_y(
[email protected]19193682014-04-03 15:01:43361 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51362 } else {
[email protected]0b3578c2014-06-20 18:29:02363 scale_ = params_.scale;
364 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01365 }
[email protected]7f0e8fa2014-03-26 12:32:01366
[email protected]19193682014-04-03 15:01:43367 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
368 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01369 widget_->screen_info_.rect = original_screen_info_.rect;
370 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
371 widget_->window_screen_rect_ = original_window_screen_rect_;
372 } else {
[email protected]19193682014-04-03 15:01:43373 applied_widget_rect_.set_origin(gfx::Point(0, 0));
374 widget_->screen_info_.rect = applied_widget_rect_;
375 widget_->screen_info_.availableRect = applied_widget_rect_;
376 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01377 }
[email protected]a179d3962013-11-12 14:44:40378
[email protected]19193682014-04-03 15:01:43379 float applied_device_scale_factor = params_.deviceScaleFactor ?
380 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01381 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51382
[email protected]7f99fc22013-11-08 14:05:58383 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51384 // - we keep the real device scale factor in compositor to produce sharp image
385 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58386 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51387 // root layer.
388 widget_->SetScreenMetricsEmulationParameters(
[email protected]a179d3962013-11-12 14:44:40389 original_screen_info_.deviceScaleFactor, offset_, scale_);
[email protected]b2e4c70132013-10-03 02:07:51390
[email protected]7f0e8fa2014-03-26 12:32:01391 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43392 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51393
394 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
395 original_size_, original_screen_info_.deviceScaleFactor));
dtrainorcb7779b82014-12-04 01:08:02396 widget_->Resize(applied_widget_rect_.size(),
397 physical_backing_size,
398 top_controls_shrink_blink_size,
399 top_controls_height,
400 applied_widget_rect_.size(),
401 resizer_rect,
402 is_fullscreen,
403 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51404}
405
406void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
407 const ViewMsg_Resize_Params& params) {
408 bool need_ack = params.new_size != original_size_ &&
409 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
410 original_size_ = params.new_size;
411 original_physical_backing_size_ = params.physical_backing_size;
412 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28413 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02414 Apply(params.top_controls_shrink_blink_size,
415 params.top_controls_height,
416 params.resizer_rect,
417 params.is_fullscreen);
[email protected]b2e4c70132013-10-03 02:07:51418
419 if (need_ack) {
420 widget_->set_next_paint_is_resize_ack();
421 if (widget_->compositor_)
422 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
423 }
424}
425
426void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
427 const gfx::Rect& view_screen_rect,
428 const gfx::Rect& window_screen_rect) {
429 original_view_screen_rect_ = view_screen_rect;
430 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43431 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
432 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51433}
434
435void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
436 ContextMenuParams* params) {
437 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40438 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51439 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40440 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51441}
442
[email protected]2d6836f42014-07-02 17:25:31443gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
444 const gfx::Rect& anchor) {
445 gfx::Rect scaled = gfx::ToEnclosedRect(gfx::ScaleRect(anchor, scale_));
446 scaled.set_x(scaled.x() + offset_.x());
447 scaled.set_y(scaled.y() + offset_.y());
448 return scaled;
449}
450
[email protected]b2e4c70132013-10-03 02:07:51451// RenderWidget ---------------------------------------------------------------
452
[email protected]180ef242013-11-07 06:50:46453RenderWidget::RenderWidget(blink::WebPopupType popup_type,
454 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04455 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03456 bool hidden,
457 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29458 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56459 surface_id_(0),
danakj6e3bf8012014-12-16 18:27:53460 compositor_deps_(nullptr),
461 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29462 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30463 init_complete_(false),
dtrainorcb7779b82014-12-04 01:08:02464 top_controls_shrink_blink_size_(false),
465 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29466 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51467 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09468 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29469 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04470 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03471 never_visible_(never_visible),
[email protected]ee41e7d22011-10-14 19:34:09472 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29473 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49474 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50475 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19476 handling_event_type_(WebInputEvent::Undefined),
477 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48478 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22479 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44480 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04481 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45482 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40483 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20484 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53485 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12486 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48487 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12488 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04489 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52490 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]8062ab262014-05-27 16:56:43491 current_event_latency_info_(NULL),
[email protected]53b4cc12013-07-18 23:02:30492 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13493#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36494 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13495 outstanding_ime_acks_(0),
[email protected]a4f0d882014-05-01 23:48:10496 body_background_color_(SK_ColorWHITE),
[email protected]0d1ebed12013-08-05 22:01:13497#endif
[email protected]b2e4c70132013-10-03 02:07:51498 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11499 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42500 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51501 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
502 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05503 if (!swapped_out)
504 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27505 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53506 device_color_profile_.push_back('0');
initial.commit09911bf2008-07-26 23:55:29507}
508
509RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11510 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16511
[email protected]992db4c2011-05-12 15:37:15512 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02513 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15514 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29515}
516
[email protected]484955942010-08-19 16:13:18517// static
[email protected]8085dbc82008-09-26 22:53:44518RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53519 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46520 blink::WebPopupType popup_type,
521 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29522 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41523 scoped_refptr<RenderWidget> widget(
[email protected]7912e822014-04-16 02:37:03524 new RenderWidget(popup_type, screen_info, false, false, false));
danakj6e3bf8012014-12-16 18:27:53525 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46526 return widget.get();
[email protected]a635f942012-12-07 10:34:29527 }
528 return NULL;
initial.commit09911bf2008-07-26 23:55:29529}
530
[email protected]484955942010-08-19 16:13:18531// static
532WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
533 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46534 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18535 break;
[email protected]180ef242013-11-07 06:50:46536 case blink::WebPopupTypeSelect:
537 case blink::WebPopupTypeSuggestion:
[email protected]484955942010-08-19 16:13:18538 return WebPopupMenu::create(render_widget);
[email protected]180ef242013-11-07 06:50:46539 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44540 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18541 default:
542 NOTREACHED();
543 }
544 return NULL;
545}
546
danakj6e3bf8012014-12-16 18:27:53547bool RenderWidget::Init(int32 opener_id,
548 CompositorDependencies* compositor_deps) {
549 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this),
[email protected]a635f942012-12-07 10:34:29550 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
551 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18552}
553
[email protected]a635f942012-12-07 10:34:29554bool RenderWidget::DoInit(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53555 CompositorDependencies* compositor_deps,
[email protected]6a8ddba52010-09-05 04:38:06556 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18557 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29558 DCHECK(!webwidget_);
559
560 if (opener_id != MSG_ROUTING_NONE)
561 opener_id_ = opener_id;
562
danakj6e3bf8012014-12-16 18:27:53563 compositor_deps_ = compositor_deps;
[email protected]484955942010-08-19 16:13:18564 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29565
[email protected]380244092011-10-07 17:26:27566 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29567 if (result) {
[email protected]380244092011-10-07 17:26:27568 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29569 // Take a reference on behalf of the RenderThread. This will be balanced
570 // when we receive ViewMsg_Close.
571 AddRef();
[email protected]b2db9272014-01-10 17:42:00572 if (RenderThreadImpl::current()) {
573 RenderThreadImpl::current()->WidgetCreated();
574 if (is_hidden_)
575 RenderThreadImpl::current()->WidgetHidden();
576 }
[email protected]a635f942012-12-07 10:34:29577 return true;
initial.commit09911bf2008-07-26 23:55:29578 } else {
[email protected]a635f942012-12-07 10:34:29579 // The above Send can fail when the tab is closing.
580 return false;
initial.commit09911bf2008-07-26 23:55:29581 }
582}
583
[email protected]fc4404d2012-11-07 19:53:30584// This is used to complete pending inits and non-pending inits.
585void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29586 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29587
[email protected]fc4404d2012-11-07 19:53:30588 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42589
[email protected]7912e822014-04-16 02:37:03590 if (compositor_)
591 StartCompositor();
initial.commit09911bf2008-07-26 23:55:29592
[email protected]6de74452009-02-25 18:04:59593 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29594}
595
[email protected]992db4c2011-05-12 15:37:15596void RenderWidget::SetSwappedOut(bool is_swapped_out) {
597 // We should only toggle between states.
598 DCHECK(is_swapped_out_ != is_swapped_out);
599 is_swapped_out_ = is_swapped_out;
600
601 // If we are swapping out, we will call ReleaseProcess, allowing the process
602 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52603 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15604 // If we are swapping in, we call AddRefProcess to prevent the process from
605 // exiting.
[email protected]949b6592014-08-20 13:17:52606 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15607 RenderProcess::current()->AddRefProcess();
608}
609
[email protected]949b6592014-08-20 13:17:52610void RenderWidget::WasSwappedOut() {
611 // If we have been swapped out and no one else is using this process,
612 // it's safe to exit now.
613 CHECK(is_swapped_out_);
614 RenderProcess::current()->ReleaseProcess();
615}
616
[email protected]b2e4c70132013-10-03 02:07:51617void RenderWidget::EnableScreenMetricsEmulation(
[email protected]19193682014-04-03 15:01:43618 const WebDeviceEmulationParams& params) {
619 if (!screen_metrics_emulator_)
620 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
621 else
622 screen_metrics_emulator_->ChangeEmulationParams(params);
[email protected]b2e4c70132013-10-03 02:07:51623}
624
625void RenderWidget::DisableScreenMetricsEmulation() {
626 screen_metrics_emulator_.reset();
627}
628
629void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
630 ScreenMetricsEmulator* emulator) {
631 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43632 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49633 popup_screen_origin_for_emulation_ = gfx::Point(
634 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
635 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56636 screen_info_ = emulator->original_screen_info();
637 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51638}
639
[email protected]2d6836f42014-07-02 17:25:31640gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
641 if (screen_metrics_emulator_)
642 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
643 return anchor;
644}
645
[email protected]b2e4c70132013-10-03 02:07:51646void RenderWidget::SetScreenMetricsEmulationParameters(
[email protected]7f99fc22013-11-08 14:05:58647 float device_scale_factor,
648 const gfx::Point& root_layer_offset,
649 float root_layer_scale) {
[email protected]b2e4c70132013-10-03 02:07:51650 // This is only supported in RenderView.
651 NOTREACHED();
652}
653
[email protected]53907862014-03-25 15:42:40654#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51655void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
656 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49657 popup->SetOriginScaleAndOffsetForEmulation(
658 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51659}
[email protected]53907862014-03-25 15:42:40660#endif
[email protected]b2e4c70132013-10-03 02:07:51661
662void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
663 if (screen_metrics_emulator_)
664 screen_metrics_emulator_->OnShowContextMenu(params);
665}
666
[email protected]7d08a9352013-10-15 08:24:56667void RenderWidget::ScheduleCompositeWithForcedRedraw() {
668 if (compositor_) {
669 // Regardless of whether threaded compositing is enabled, always
670 // use this mechanism to force the compositor to redraw. However,
671 // the invalidation code path below is still needed for the
672 // non-threaded case.
673 compositor_->SetNeedsForcedRedraw();
674 }
[email protected]8b9e52b2014-01-17 16:35:31675 scheduleComposite();
[email protected]7d08a9352013-10-15 08:24:56676}
677
[email protected]a95986a82010-12-24 06:19:28678bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
679 bool handled = true;
680 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15681 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22682 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
683 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22684 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
685 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15686 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
687 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35688 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
689 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28690 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
691 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
692 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
noel89949e62014-09-30 01:12:41693 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54694 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28695 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41696 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]a95986a82010-12-24 06:19:28697 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
[email protected]37a241c2013-12-03 03:16:17698 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowShown, OnCandidateWindowShown)
699 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowUpdated,
700 OnCandidateWindowUpdated)
701 IPC_MESSAGE_HANDLER(ViewMsg_CandidateWindowHidden, OnCandidateWindowHidden)
[email protected]3d9ec5052013-01-02 22:05:25702 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28703 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
704 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03705 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21706#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51707 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13708 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21709#endif
[email protected]a95986a82010-12-24 06:19:28710 IPC_MESSAGE_UNHANDLED(handled = false)
711 IPC_END_MESSAGE_MAP()
712 return handled;
713}
initial.commit09911bf2008-07-26 23:55:29714
715bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15716 // Don't send any messages after the browser has told us to close, and filter
717 // most outgoing messages while swapped out.
718 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26719 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11720 closing_) {
initial.commit09911bf2008-07-26 23:55:29721 delete message;
722 return false;
723 }
724
725 // If given a messsage without a routing ID, then assign our routing ID.
726 if (message->routing_id() == MSG_ROUTING_NONE)
727 message->set_routing_id(routing_id_);
728
[email protected]380244092011-10-07 17:26:27729 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44730}
731
[email protected]61e2b3cc2012-03-02 16:13:34732void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44733 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02734 bool top_controls_shrink_blink_size,
735 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44736 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34737 const gfx::Rect& resizer_rect,
738 bool is_fullscreen,
739 ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56740 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48741 // A resize ack shouldn't be requested if we have not ACK'd the previous
742 // one.
743 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
744 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
745 }
initial.commit09911bf2008-07-26 23:55:29746
[email protected]61e2b3cc2012-03-02 16:13:34747 // Ignore this during shutdown.
748 if (!webwidget_)
749 return;
750
[email protected]d9083762013-03-24 01:36:40751 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44752 compositor_->setViewportSize(new_size, physical_backing_size);
dtrainorcb7779b82014-12-04 01:08:02753 compositor_->SetTopControlsShrinkBlinkSize(top_controls_shrink_blink_size);
754 compositor_->SetTopControlsHeight(top_controls_height);
[email protected]d9083762013-03-24 01:36:40755 }
[email protected]60d47ac2013-03-01 23:42:44756
[email protected]dade8992013-03-04 07:34:34757 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02758 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
759 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28760 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34761 resizer_rect_ = resizer_rect;
762
763 // NOTE: We may have entered fullscreen mode without changing our size.
764 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
765 if (fullscreen_change)
766 WillToggleFullscreen();
767 is_fullscreen_ = is_fullscreen;
768
dtrainorcb7779b82014-12-04 01:08:02769 webwidget_->setTopControlsLayoutHeight(top_controls_shrink_blink_size_
770 ? top_controls_height : 0.f);
bokan0c93cd82014-09-30 19:20:43771
[email protected]61e2b3cc2012-03-02 16:13:34772 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34773 size_ = new_size;
774
[email protected]61e2b3cc2012-03-02 16:13:34775 // When resizing, we want to wait to paint before ACK'ing the resize. This
776 // ensures that we only resize as fast as we can paint. We only need to
777 // send an ACK if we are resized to a non-empty rect.
778 webwidget_->resize(new_size);
[email protected]5b45ad42013-10-25 00:42:04779 } else if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]632c4382013-05-15 08:58:45780 resize_ack = NO_RESIZE_ACK;
781 }
782
[email protected]bb6378fe2014-04-28 21:19:44783 webwidget()->resizePinchViewport(gfx::Size(
784 visible_viewport_size.width(),
785 visible_viewport_size.height()));
786
[email protected]632c4382013-05-15 08:58:45787 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
788 // For empty size or empty physical_backing_size, there is no next paint
789 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35790 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34791 }
792
[email protected]20fbfc22013-05-08 20:50:58793 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45794 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58795 set_next_paint_is_resize_ack();
796
[email protected]61e2b3cc2012-03-02 16:13:34797 if (fullscreen_change)
798 DidToggleFullscreen();
799
800 // If a resize ack is requested and it isn't set-up, then no more resizes will
801 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45802 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29803}
804
bokanf0fd2412014-10-30 15:28:55805void RenderWidget::ResizeSynchronously(
806 const gfx::Rect& new_position,
807 const gfx::Size& visible_viewport_size) {
[email protected]587941d2014-08-22 01:40:01808 Resize(new_position.size(),
809 new_position.size(),
dtrainorcb7779b82014-12-04 01:08:02810 top_controls_shrink_blink_size_,
811 top_controls_height_,
bokanf0fd2412014-10-30 15:28:55812 visible_viewport_size,
[email protected]587941d2014-08-22 01:40:01813 gfx::Rect(),
814 is_fullscreen_,
815 NO_RESIZE_ACK);
[email protected]92650162013-10-30 03:31:02816 view_screen_rect_ = new_position;
817 window_screen_rect_ = new_position;
818 if (!did_show_)
819 initial_pos_ = new_position;
820}
821
initial.commit09911bf2008-07-26 23:55:29822void RenderWidget::OnClose() {
823 if (closing_)
824 return;
825 closing_ = true;
826
827 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03828 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]b2db9272014-01-10 17:42:00829 if (RenderThreadImpl::current())
830 RenderThreadImpl::current()->WidgetDestroyed();
[email protected]380244092011-10-07 17:26:27831 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03832 SetHidden(false);
833 }
initial.commit09911bf2008-07-26 23:55:29834
initial.commit09911bf2008-07-26 23:55:29835 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25836 // now. Post a task that only gets invoked when there are no nested message
837 // loops.
alexclarkee19d4ef2015-01-09 17:45:40838 RenderThread::Get()->GetTaskRunner()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29839 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25840
841 // Balances the AddRef taken when we called AddRoute.
842 Release();
initial.commit09911bf2008-07-26 23:55:29843}
844
[email protected]61e2b3cc2012-03-02 16:13:34845// Got a response from the browser after the renderer decided to create a new
846// view.
[email protected]fc4404d2012-11-07 19:53:30847void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34848 DCHECK(routing_id_ != MSG_ROUTING_NONE);
849
[email protected]fc4404d2012-11-07 19:53:30850 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34851}
852
[email protected]0fdd5012013-05-29 08:05:56853void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04854 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32855 return;
856
[email protected]b2e4c70132013-10-03 02:07:51857 if (screen_metrics_emulator_) {
858 screen_metrics_emulator_->OnResizeMessage(params);
859 return;
860 }
861
[email protected]fcdc5642014-05-09 14:32:24862 bool orientation_changed =
863 screen_info_.orientationAngle != params.screen_info.orientationAngle;
864
[email protected]0fdd5012013-05-29 08:05:56865 screen_info_ = params.screen_info;
866 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02867 Resize(params.new_size,
868 params.physical_backing_size,
869 params.top_controls_shrink_blink_size,
870 params.top_controls_height,
871 params.visible_viewport_size,
872 params.resizer_rect,
873 params.is_fullscreen,
874 SEND_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24875
876 if (orientation_changed)
877 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29878}
879
noel89949e62014-09-30 01:12:41880void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
881 SetDeviceColorProfile(color_profile);
882}
883
[email protected]b5913d72012-02-07 22:26:54884void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01885 if (resizer_rect_ == resizer_rect)
886 return;
887 resizer_rect_ = resizer_rect;
888 if (webwidget_)
889 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54890}
891
initial.commit09911bf2008-07-26 23:55:29892void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31893 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29894 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03895 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59896 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
897 WasHidden());
initial.commit09911bf2008-07-26 23:55:29898}
899
[email protected]3399dd822014-08-09 11:14:24900void RenderWidget::OnWasShown(bool needs_repainting,
901 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41902 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29903 // During shutdown we can just ignore this message.
904 if (!webwidget_)
905 return;
906
907 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03908 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59909 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
910 WasShown());
initial.commit09911bf2008-07-26 23:55:29911
[email protected]8a23afb32014-04-30 22:40:23912 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29913 return;
initial.commit09911bf2008-07-26 23:55:29914
915 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24916 if (compositor_) {
917 ui::LatencyInfo swap_latency_info(latency_info);
918 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
919 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05920 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24921 }
[email protected]aca33f4f2014-05-17 17:08:05922 scheduleComposite();
initial.commit09911bf2008-07-26 23:55:29923}
924
[email protected]53d3f302009-12-21 04:42:05925void RenderWidget::OnRequestMoveAck() {
926 DCHECK(pending_window_rect_count_);
927 pending_window_rect_count_--;
928}
929
[email protected]ed7defa2013-03-12 21:29:59930GURL RenderWidget::GetURLForGraphicsContext3D() {
931 return GURL();
[email protected]65225772011-05-12 21:10:24932}
933
[email protected]ebc0e1df2013-08-01 02:46:22934scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03935 // For widgets that are never visible, we don't start the compositor, so we
936 // never get a request for a cc::OutputSurface.
937 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19938
939#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01940 if (SynchronousCompositorFactory* factory =
941 SynchronousCompositorFactory::GetInstance()) {
[email protected]586871b2014-07-22 17:05:11942 return factory->CreateOutputSurface(routing_id(),
943 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19944 }
945#endif
946
avi83883c82014-12-23 00:08:49947 const base::CommandLine& command_line =
948 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33949 bool use_software = fallback;
950 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
951 use_software = true;
952
[email protected]0634cdd42013-08-16 00:46:09953 scoped_refptr<ContextProviderCommandBuffer> context_provider;
[email protected]e09994a2014-03-26 19:59:33954 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09955 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:13956 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:33957 if (!context_provider.get()) {
958 // Cause the compositor to wait and try again.
959 return scoped_ptr<cc::OutputSurface>();
960 }
[email protected]0634cdd42013-08-16 00:46:09961 }
[email protected]ebc0e1df2013-08-01 02:46:22962
[email protected]b6eb8e332013-09-10 00:51:01963 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:00964 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:53965 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
[email protected]65a33ce2014-03-25 22:37:09966 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11967 new DelegatedCompositorOutputSurface(routing_id(),
968 output_surface_id,
969 context_provider,
970 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09971 }
[email protected]0634cdd42013-08-16 00:46:09972 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09973 scoped_ptr<cc::SoftwareOutputDevice> software_device(
974 new CompositorSoftwareOutputDevice());
975
[email protected]586871b2014-07-22 17:05:11976 return scoped_ptr<cc::OutputSurface>(
977 new CompositorOutputSurface(routing_id(),
978 output_surface_id,
979 NULL,
980 software_device.Pass(),
981 frame_swap_message_queue_,
982 true));
[email protected]ebc0e1df2013-08-01 02:46:22983 }
[email protected]ed7defa2013-03-12 21:29:59984
[email protected]36e5ff12013-06-11 12:19:29985 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:45986 // Composite-to-mailbox is currently used for layout tests in order to cause
987 // them to draw inside in the renderer to do the readback there. This should
988 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:53989 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:16990 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:27991 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:16992 format = cc::RGB_565;
[email protected]36e5ff12013-06-11 12:19:29993 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11994 new MailboxOutputSurface(routing_id(),
995 output_surface_id,
996 context_provider,
997 scoped_ptr<cc::SoftwareOutputDevice>(),
998 frame_swap_message_queue_,
999 format));
[email protected]36e5ff12013-06-11 12:19:291000 }
[email protected]0634cdd42013-08-16 00:46:091001 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:291002 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111003 new CompositorOutputSurface(routing_id(),
1004 output_surface_id,
1005 context_provider,
1006 scoped_ptr<cc::SoftwareOutputDevice>(),
1007 frame_swap_message_queue_,
1008 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281009}
1010
[email protected]4d7e46a2013-11-08 05:33:401011void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241012 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241013 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311014 scheduleComposite();
[email protected]65225772011-05-12 21:10:241015}
1016
[email protected]4d7e46a2013-11-08 05:33:401017void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081018 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081019}
1020
[email protected]4d7e46a2013-11-08 05:33:401021void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241022 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161023
[email protected]404939f2012-06-01 04:06:181024 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161025 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291026}
1027
[email protected]180ef242013-11-07 06:50:461028void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351029 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091030 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191031 base::AutoReset<bool> handling_input_event_resetter(
1032 &handling_input_event_, true);
1033 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291034 return;
[email protected]c27dd4f2014-05-22 18:05:191035 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1036 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521037#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541038 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521039 // |AdapterInputConnection| generates input key events to make sure all JS
1040 // listeners that monitor KeyUp and KeyDown events receive the proper key
1041 // code. Since this input key event comes from IME, we need to set the
1042 // IME event guard here to make sure it does not interfere with other IME
1043 // events.
1044 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1045 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1046 const WebKeyboardEvent& key_event =
1047 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541048 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171049 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091050 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1051 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1052 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1053 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1054 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521055 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521056 }
1057#endif
initial.commit09911bf2008-07-26 23:55:291058
[email protected]8062ab262014-05-27 16:56:431059 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1060 &latency_info);
1061
[email protected]fd847792013-10-24 17:12:351062 base::TimeTicks start_time;
1063 if (base::TimeTicks::IsHighResNowFastAndReliable())
1064 start_time = base::TimeTicks::HighResNow();
1065
[email protected]b4841e1c2013-05-16 22:30:101066 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301067 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151068 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131069 TRACE_EVENT_FLOW_STEP0(
1070 "input",
1071 "LatencyInfo.Flow",
1072 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1073 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101074
jdduke07788062014-12-05 03:16:301075 // If we don't have a high res timer, these metrics won't be accurate enough
1076 // to be worth collecting. Note that this does introduce some sampling bias.
1077 if (!start_time.is_null())
1078 LogInputEventLatencyUma(*input_event, start_time);
1079
[email protected]6be422b2013-12-08 06:47:311080 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351081 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311082 if (compositor_) {
1083 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351084 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1085 .Pass();
[email protected]6be422b2013-12-08 06:47:311086 }
[email protected]c2eaa8f2013-05-10 02:41:551087
[email protected]67bfb83f2011-09-22 03:36:371088 bool prevent_default = false;
1089 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261090 const WebMouseEvent& mouse_event =
1091 *static_cast<const WebMouseEvent*>(input_event);
1092 TRACE_EVENT2("renderer", "HandleMouseMove",
1093 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421094 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261095 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371096 }
1097
[email protected]cefe9b152014-03-27 18:16:151098 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421099 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151100#if defined(OS_ANDROID)
1101 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1102 // case it should behave like a select key (i.e. causing a click if a button
1103 // is focused). However, if a text field is focused (2), its intended
1104 // behavior is to just show the IME and don't propagate the key.
1105 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1106 // when clicked on an input text field and cause the form submit if clicked
1107 // when the submit button is focused, but not vice-versa.
1108 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1109 // but at this point we have to swallow the event for the scenario (2).
1110 const WebKeyboardEvent& key_event =
1111 *static_cast<const WebKeyboardEvent*>(input_event);
1112 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1113 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1114 OnShowImeIfNeeded();
1115 prevent_default = true;
1116 }
1117#endif
1118 }
[email protected]f56c7872013-06-18 12:31:571119
[email protected]41d86852012-11-07 12:23:241120 if (WebInputEvent::isGestureEventType(input_event->type)) {
1121 const WebGestureEvent& gesture_event =
1122 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421123 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241124 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1125 }
1126
[email protected]67bfb83f2011-09-22 03:36:371127 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121128 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1129 suppress_next_char_events_ = false;
1130 if (!processed && webwidget_)
1131 processed = webwidget_->handleInputEvent(*input_event);
1132 }
1133
1134 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1135 // it's not processed by webkit, then we need to suppress the upcoming Char
1136 // events.
1137 if (!processed && is_keyboard_shortcut)
1138 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291139
[email protected]3d5c243b2012-11-30 00:26:011140 InputEventAckState ack_result = processed ?
1141 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1142 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1143 const WebTouchEvent& touch_event =
1144 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251145 // Hit-test for all the pressed touch points. If there is a touch-handler
1146 // for any of the touch points, then the renderer should continue to receive
1147 // touch events.
1148 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1149 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1150 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271151 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391152 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251153 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1154 break;
1155 }
1156 }
[email protected]3d5c243b2012-11-30 00:26:011157 }
1158
ccamerond4ba47902014-12-17 07:20:311159 // Send mouse wheel events and their disposition to the compositor thread, so
1160 // that they can be used to produce the elastic overscroll effect on Mac.
1161 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311162 ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:311163 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1164 }
1165
[email protected]721e2302014-04-30 23:42:011166 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061167
[email protected]fd847792013-10-24 17:12:351168 // If we don't have a fast and accurate HighResNow, we assume the input
1169 // handlers are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301170 bool rate_limiting_wanted =
1171 input_event->type == WebInputEvent::MouseMove ||
1172 input_event->type == WebInputEvent::MouseWheel;
1173 if (rate_limiting_wanted && !start_time.is_null()) {
[email protected]fd847792013-10-24 17:12:351174 base::TimeTicks end_time = base::TimeTicks::HighResNow();
1175 total_input_handling_time_this_frame_ += (end_time - start_time);
1176 rate_limiting_wanted =
1177 total_input_handling_time_this_frame_.InMicroseconds() >
1178 kInputHandlingTimeThrottlingThresholdMicroseconds;
1179 }
1180
[email protected]7f19e9d2014-05-09 15:16:291181 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1182
[email protected]c27dd4f2014-05-22 18:05:191183 // Note that we can't use handling_event_type_ here since it will be overriden
1184 // by reentrant calls for events after the paused one.
1185 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1186 input_event->type == WebInputEvent::MouseMove;
1187 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561188 InputHostMsg_HandleInputEvent_ACK_Params ack;
1189 ack.type = input_event->type;
1190 ack.state = ack_result;
1191 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551192 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561193 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301194 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551195 // We want to rate limit the input events in this case, so we'll wait for
1196 // painting to finish before ACKing this message.
1197 TRACE_EVENT_INSTANT0("renderer",
1198 "RenderWidget::OnHandleInputEvent ack throttled",
1199 TRACE_EVENT_SCOPE_THREAD);
1200 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291201 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1202 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551203 // As two different kinds of events could cause us to postpone an ack
1204 // we send it now, if we have one pending. The Browser should never
1205 // send us the same kind of event we are delaying the ack for.
1206 Send(pending_input_event_ack_.release());
1207 }
1208 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291209 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1210 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551211 if (compositor_)
1212 compositor_->NotifyInputThrottledUntilCommit();
1213 } else {
1214 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171215 }
[email protected]12fbad812009-09-01 18:21:241216 }
[email protected]5fea4a52014-05-27 00:17:521217 if (input_event->type == WebInputEvent::MouseMove)
1218 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241219
[email protected]3306f262012-09-21 19:20:421220#if defined(OS_ANDROID)
1221 // Allow the IME to be shown when the focus changes as a consequence
1222 // of a processed touch end event.
1223 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361224 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021225#elif defined(USE_AURA)
1226 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1227 // change.
1228 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1229 input_event->type == WebInputEvent::MouseUp))
[email protected]90f24152014-04-09 12:41:361230 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
[email protected]3306f262012-09-21 19:20:421231#endif
1232
[email protected]67bfb83f2011-09-22 03:36:371233 if (!prevent_default) {
1234 if (WebInputEvent::isKeyboardEventType(input_event->type))
1235 DidHandleKeyEvent();
1236 if (WebInputEvent::isMouseEventType(input_event->type))
1237 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241238 if (WebInputEvent::isTouchEventType(input_event->type))
1239 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371240 }
initial.commit09911bf2008-07-26 23:55:291241}
1242
[email protected]34202de2013-05-06 23:36:221243void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1244 if (webwidget_)
1245 webwidget_->setCursorVisibilityState(is_visible);
1246}
1247
initial.commit09911bf2008-07-26 23:55:291248void RenderWidget::OnMouseCaptureLost() {
1249 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281250 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291251}
1252
1253void RenderWidget::OnSetFocus(bool enable) {
1254 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331255 if (webwidget_)
1256 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291257}
1258
1259void RenderWidget::ClearFocus() {
1260 // We may have got the focus from the browser before this gets processed, in
1261 // which case we do not want to unfocus ourself.
1262 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281263 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291264}
1265
[email protected]fd847792013-10-24 17:12:351266void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291267 if (pending_input_event_ack_) {
1268 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1269 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071270 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291271 }
[email protected]fd847792013-10-24 17:12:351272 total_input_handling_time_this_frame_ = base::TimeDelta();
1273}
1274
initial.commit09911bf2008-07-26 23:55:291275///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461276// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291277
[email protected]244ac1892011-12-02 17:04:471278void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091279 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451280 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581281
[email protected]5b45ad42013-10-25 00:42:041282 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451283 WebRect new_pos(rootWindowRect().x,
1284 rootWindowRect().y,
1285 new_size.width,
1286 new_size.height);
1287 view_screen_rect_ = new_pos;
1288 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031289 }
[email protected]20fbfc22013-05-08 20:50:581290
[email protected]eac2b362013-05-22 07:01:451291 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581292
[email protected]5b45ad42013-10-25 00:42:041293 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581294 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091295 }
[email protected]244ac1892011-12-02 17:04:471296}
1297
[email protected]3a1c8a8032013-03-18 22:35:321298void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051299 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1300 device_scale_factor_));
1301 if (compositor_)
1302 compositor_->setViewportSize(size_, physical_backing_size_);
1303}
1304
[email protected]e195e582013-03-08 01:32:591305void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221306 DCHECK(!host_closing_);
1307
danakj6e3bf8012014-12-16 18:27:531308 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591309 compositor_->setViewportSize(size_, physical_backing_size_);
1310 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031311 StartCompositor();
[email protected]e195e582013-03-08 01:32:591312}
1313
ennef3c58142014-12-09 21:44:381314void RenderWidget::WillCloseLayerTreeView() {
1315 if (host_closing_)
1316 return;
1317
1318 // Prevent new compositors or output surfaces from being created.
1319 host_closing_ = true;
1320
[email protected]aeeedad2014-08-22 18:16:221321 // Always send this notification to prevent new layer tree views from
1322 // being created, even if one hasn't been created yet.
1323 if (webwidget_)
1324 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221325}
1326
[email protected]180ef242013-11-07 06:50:461327blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281328 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061329}
1330
[email protected]9cd43a62012-03-26 08:03:561331void RenderWidget::willBeginCompositorFrame() {
1332 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371333
[email protected]abe8b3a2012-03-28 21:19:371334 // The following two can result in further layout and possibly
1335 // enable GPU acceleration so they need to be called before any painting
1336 // is done.
shuchen3517bb62014-10-15 03:55:571337 UpdateTextInputType();
1338#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361339 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571340#endif
[email protected]abe8b3a2012-03-28 21:19:371341 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561342}
1343
[email protected]3391a0772012-03-28 00:32:071344void RenderWidget::didBecomeReadyForAdditionalInput() {
1345 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351346 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071347}
1348
[email protected]6fceb912013-02-15 06:24:151349void RenderWidget::DidCommitCompositorFrame() {
[email protected]e3244ed2014-06-20 20:04:271350 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161351 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171352#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271353 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1354 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171355#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151356}
1357
[email protected]586871b2014-07-22 17:05:111358// static
1359scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1360 IPC::Message* msg,
1361 MessageDeliveryPolicy policy,
1362 FrameSwapMessageQueue* frame_swap_message_queue,
1363 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1364 bool commit_requested,
1365 int source_frame_number) {
1366 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1367 // No need for lock: this gets changed only on this thread.
1368 !commit_requested &&
1369 // No need for lock: Messages are only enqueued from this thread, if we
1370 // don't have any now, no other thread will add any.
1371 frame_swap_message_queue->Empty()) {
1372 sync_message_filter->Send(msg);
dcheng4b6b5ff2014-10-16 00:42:061373 return nullptr;
[email protected]586871b2014-07-22 17:05:111374 }
1375
1376 bool first_message_for_frame = false;
1377 frame_swap_message_queue->QueueMessageForFrame(policy,
1378 source_frame_number,
1379 make_scoped_ptr(msg),
1380 &first_message_for_frame);
1381 if (first_message_for_frame) {
1382 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1383 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061384 return promise;
[email protected]586871b2014-07-22 17:05:111385 }
dcheng4b6b5ff2014-10-16 00:42:061386 return nullptr;
[email protected]586871b2014-07-22 17:05:111387}
1388
1389void RenderWidget::QueueMessage(IPC::Message* msg,
1390 MessageDeliveryPolicy policy) {
1391 // RenderThreadImpl::current() is NULL in some tests.
1392 if (!compositor_ || !RenderThreadImpl::current()) {
1393 Send(msg);
1394 return;
1395 }
1396
1397 scoped_ptr<cc::SwapPromise> swap_promise =
1398 QueueMessageImpl(msg,
1399 policy,
dcheng58867a92014-08-26 02:50:221400 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111401 RenderThreadImpl::current()->sync_message_filter(),
1402 compositor_->commitRequested(),
1403 compositor_->GetSourceFrameNumber());
1404
1405 if (swap_promise) {
1406 compositor_->QueueSwapPromise(swap_promise.Pass());
1407 compositor_->SetNeedsCommit();
1408 }
1409}
1410
[email protected]58264a32011-11-17 23:36:151411void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101412 // NOTE: Tests may break if this event is renamed or moved. See
1413 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501414 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161415 // Notify subclasses that we initiated the paint operation.
1416 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151417}
1418
1419void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181420 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1421
1422 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561423 DidFlushPaint();
1424
[email protected]ea3ee0a2012-05-15 03:43:091425 if (!next_paint_flags_ &&
1426 !need_update_rect_for_auto_resize_ &&
1427 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151428 return;
[email protected]ea3ee0a2012-05-15 03:43:091429 }
[email protected]58264a32011-11-17 23:36:151430
1431 ViewHostMsg_UpdateRect_Params params;
1432 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151433 params.plugin_window_moves.swap(plugin_window_moves_);
1434 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151435
1436 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1437 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091438 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151439}
1440
[email protected]8b9e52b2014-01-17 16:35:311441void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531442 if (compositor_ &&
1443 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221444 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311445 }
1446}
1447
[email protected]4873c7d2009-07-16 06:36:281448void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301449 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521450 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401451 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291452 // Only send a SetCursor message if we need to make a change.
1453 if (!current_cursor_.IsEqual(cursor)) {
1454 current_cursor_ = cursor;
1455 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1456 }
1457}
1458
1459// We are supposed to get a single call to Show for a newly created RenderWidget
1460// that was created via RenderWidget::CreateWebView. So, we wait until this
1461// point to dispatch the ShowWidget message.
1462//
1463// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281464// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291465//
[email protected]4873c7d2009-07-16 06:36:281466void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291467 DCHECK(!did_show_) << "received extraneous Show call";
1468 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1469 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1470
[email protected]8de12d942010-11-17 20:42:441471 if (did_show_)
1472 return;
1473
1474 did_show_ = true;
1475 // NOTE: initial_pos_ may still have its default values at this point, but
1476 // that's okay. It'll be ignored if as_popup is false, or the browser
1477 // process will impose a default position otherwise.
1478 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1479 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291480}
1481
[email protected]4873c7d2009-07-16 06:36:281482void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291483}
1484
[email protected]4873c7d2009-07-16 06:36:281485void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291486}
1487
[email protected]2533ce12009-05-09 00:02:241488void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381489 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241490 Send(new ViewHostMsg_Close(routing_id_));
1491}
1492
[email protected]4873c7d2009-07-16 06:36:281493void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321494 if (is_swapped_out_) {
1495 // This widget is currently swapped out, and the active widget is in a
1496 // different process. Have the browser route the close request to the
1497 // active widget instead, so that the correct unload handlers are run.
1498 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1499 return;
1500 }
1501
initial.commit09911bf2008-07-26 23:55:291502 // If a page calls window.close() twice, we'll end up here twice, but that's
1503 // OK. It is safe to send multiple Close messages.
1504
[email protected]2533ce12009-05-09 00:02:241505 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1506 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1507 // could be closed before the JS finishes executing. So instead, post a
1508 // message back to the message loop, which won't run until the JS is
1509 // complete, and then the Close message can be sent.
alexclarkee19d4ef2015-01-09 17:45:401510 RenderThread::Get()->GetTaskRunner()->PostTask(
[email protected]32876ae2011-11-15 22:25:211511 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291512}
1513
[email protected]9017d7852013-11-21 17:47:351514void RenderWidget::QueueSyntheticGesture(
1515 scoped_ptr<SyntheticGestureParams> gesture_params,
1516 const SyntheticGestureCompletionCallback& callback) {
1517 DCHECK(!callback.is_null());
1518
1519 pending_synthetic_gesture_callbacks_.push(callback);
1520
1521 SyntheticGesturePacket gesture_packet;
1522 gesture_packet.set_gesture_params(gesture_params.Pass());
1523
1524 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1525}
1526
initial.commit09911bf2008-07-26 23:55:291527void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031528 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381529 WillCloseLayerTreeView();
1530 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291531 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281532 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291533 webwidget_ = NULL;
1534 }
1535}
1536
[email protected]4873c7d2009-07-16 06:36:281537WebRect RenderWidget::windowRect() {
1538 if (pending_window_rect_count_)
1539 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241540
[email protected]80ad8622012-11-07 16:33:031541 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291542}
1543
[email protected]180ef242013-11-07 06:50:461544void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301545 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541546 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301547}
1548
[email protected]b2e4c70132013-10-03 02:07:511549void RenderWidget::setWindowRect(const WebRect& rect) {
1550 WebRect pos = rect;
1551 if (popup_origin_scale_for_emulation_) {
1552 float scale = popup_origin_scale_for_emulation_;
1553 pos.x = popup_screen_origin_for_emulation_.x() +
1554 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1555 pos.y = popup_screen_origin_for_emulation_.y() +
1556 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1557 }
1558
[email protected]5b45ad42013-10-25 00:42:041559 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201560 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031561 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1562 SetPendingWindowRect(pos);
1563 } else {
[email protected]ec951b9d2013-10-20 06:21:201564 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031565 }
initial.commit09911bf2008-07-26 23:55:291566 } else {
bokanf0fd2412014-10-30 15:28:551567 ResizeSynchronously(pos, visible_viewport_size_);
initial.commit09911bf2008-07-26 23:55:291568 }
1569}
1570
[email protected]2533ce12009-05-09 00:02:241571void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1572 pending_window_rect_ = rect;
1573 pending_window_rect_count_++;
1574}
1575
[email protected]4873c7d2009-07-16 06:36:281576WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241577 if (pending_window_rect_count_) {
1578 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1579 // the RootWindowRect is probably going to return wrong results since the
1580 // browser may not have processed the Move yet. There isn't really anything
1581 // good to do in this case, and it shouldn't happen - since this size is
1582 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281583 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241584 }
1585
[email protected]80ad8622012-11-07 16:33:031586 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371587}
1588
[email protected]4873c7d2009-07-16 06:36:281589WebRect RenderWidget::windowResizerRect() {
1590 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191591}
1592
[email protected]fa7b1dc2010-06-23 17:53:041593void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031594 // To prevent this renderer process from sending unnecessary IPC messages to
1595 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041596 // only during the input method attached to the browser process is active.
1597 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291598}
1599
[email protected]37a241c2013-12-03 03:16:171600void RenderWidget::OnCandidateWindowShown() {
1601 webwidget_->didShowCandidateWindow();
1602}
1603
1604void RenderWidget::OnCandidateWindowUpdated() {
1605 webwidget_->didUpdateCandidateWindow();
1606}
1607
1608void RenderWidget::OnCandidateWindowHidden() {
1609 webwidget_->didHideCandidateWindow();
1610}
1611
[email protected]fa7b1dc2010-06-23 17:53:041612void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261613 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041614 const std::vector<WebCompositionUnderline>& underlines,
1615 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131616 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281617 return;
[email protected]66fca5bc2013-05-23 06:58:291618 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361619 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041620 text, WebVector<WebCompositionUnderline>(underlines),
1621 selection_start, selection_end)) {
1622 // If we failed to set the composition text, then we need to let the browser
1623 // process to cancel the input method's ongoing composition session, to make
1624 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221625 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261626 }
[email protected]88dbe32f2013-06-20 23:31:361627 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041628}
1629
[email protected]fcf75d42013-12-03 20:11:261630void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511631 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021632 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131633 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041634 return;
[email protected]66fca5bc2013-05-23 06:58:291635 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041636 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021637 if (text.length())
1638 webwidget_->confirmComposition(text);
1639 else if (keep_selection)
1640 webwidget_->confirmComposition(WebWidget::KeepSelection);
1641 else
1642 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041643 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361644 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291645}
1646
[email protected]0bc1f572013-04-17 01:46:311647void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121648 // During shutdown we can just ignore this message.
1649 if (!webwidget_)
1650 return;
1651
[email protected]0bc1f572013-04-17 01:46:311652 // Even if the browser provides an empty damage rect, it's still expecting to
1653 // receive a repaint ack so just damage the entire widget bounds.
1654 if (size_to_paint.IsEmpty()) {
1655 size_to_paint = size_;
1656 }
1657
[email protected]ec7dc112008-08-06 05:30:121658 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051659 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311660 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121661}
1662
[email protected]79fa22e2013-08-23 15:18:121663void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351664 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1665
1666 pending_synthetic_gesture_callbacks_.front().Run();
1667 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271668}
1669
[email protected]4873c7d2009-07-16 06:36:281670void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111671 if (!webwidget_)
1672 return;
[email protected]4873c7d2009-07-16 06:36:281673 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111674}
1675
[email protected]80ad8622012-11-07 16:33:031676void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1677 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511678 if (screen_metrics_emulator_) {
1679 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1680 view_screen_rect, window_screen_rect);
1681 } else {
1682 view_screen_rect_ = view_screen_rect;
1683 window_screen_rect_ = window_screen_rect;
1684 }
[email protected]80ad8622012-11-07 16:33:031685 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1686}
1687
[email protected]adb362312014-06-28 06:04:241688void RenderWidget::showImeIfNeeded() {
1689 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131690}
1691
[email protected]adb362312014-06-28 06:04:241692void RenderWidget::OnShowImeIfNeeded() {
1693#if defined(OS_ANDROID) || defined(USE_AURA)
1694 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1695#endif
1696}
1697
1698#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131699void RenderWidget::IncrementOutstandingImeEventAcks() {
1700 ++outstanding_ime_acks_;
1701}
1702
1703void RenderWidget::OnImeEventAck() {
1704 --outstanding_ime_acks_;
1705 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511706}
[email protected]105dffb42013-02-20 03:46:211707#endif
1708
[email protected]0d1ebed12013-08-05 22:01:131709bool RenderWidget::ShouldHandleImeEvent() {
1710#if defined(OS_ANDROID)
1711 return !!webwidget_ && outstanding_ime_acks_ == 0;
1712#else
1713 return !!webwidget_;
1714#endif
1715}
1716
[email protected]c27dd4f2014-05-22 18:05:191717bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1718 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521719 // If we pause multiple times during a single mouse move event, we should
1720 // only send ACK once.
1721 if (!ignore_ack_for_mouse_move_from_debugger_) {
1722 InputHostMsg_HandleInputEvent_ACK_Params ack;
1723 ack.type = handling_event_type_;
1724 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1725 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1726 }
[email protected]c27dd4f2014-05-22 18:05:191727 return true;
1728 }
1729 return false;
1730}
1731
1732void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1733 ignore_ack_for_mouse_move_from_debugger_ = true;
1734}
1735
[email protected]468ac582012-11-20 00:53:191736void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1737 if (device_scale_factor_ == device_scale_factor)
1738 return;
1739
1740 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051741 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191742}
1743
[email protected]28ed6b32014-06-08 02:16:271744bool RenderWidget::SetDeviceColorProfile(
1745 const std::vector<char>& color_profile) {
1746 if (device_color_profile_ == color_profile)
1747 return false;
1748
1749 device_color_profile_ = color_profile;
1750 return true;
1751}
1752
noeldb4df152014-09-16 17:45:201753void RenderWidget::ResetDeviceColorProfileForTesting() {
1754 if (!device_color_profile_.empty())
1755 device_color_profile_.clear();
1756 device_color_profile_.push_back('0');
1757}
1758
[email protected]fcdc5642014-05-09 14:32:241759void RenderWidget::OnOrientationChange() {
1760}
1761
[email protected]ceb36f7d2012-10-31 18:33:241762gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521763 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241764 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521765}
1766
[email protected]bee16aab2009-08-26 15:55:031767void RenderWidget::SetHidden(bool hidden) {
1768 if (is_hidden_ == hidden)
1769 return;
1770
jdduke8fac9d102014-12-20 02:40:131771 // The status has changed. Tell the RenderThread about it and ensure
1772 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031773 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131774 FlushPendingInputEventAck();
1775
[email protected]bee16aab2009-08-26 15:55:031776 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001777 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031778 else
[email protected]b2db9272014-01-10 17:42:001779 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031780}
1781
[email protected]2b624c562011-10-27 22:58:261782void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261783 if (!webwidget_)
1784 return;
1785
1786 if (is_fullscreen_) {
1787 webwidget_->willExitFullScreen();
1788 } else {
1789 webwidget_->willEnterFullScreen();
1790 }
[email protected]2b624c562011-10-27 22:58:261791}
1792
1793void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261794 if (!webwidget_)
1795 return;
1796
1797 if (is_fullscreen_) {
1798 webwidget_->didEnterFullScreen();
1799 } else {
1800 webwidget_->didExitFullScreen();
1801 }
[email protected]2b624c562011-10-27 22:58:261802}
1803
[email protected]674741932009-02-04 23:44:461804bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051805 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461806}
1807
[email protected]674741932009-02-04 23:44:461808void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051809 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461810}
1811
[email protected]674741932009-02-04 23:44:461812void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051813 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461814}
1815
[email protected]b18583c2012-12-18 06:55:271816static bool IsDateTimeInput(ui::TextInputType type) {
1817 return type == ui::TEXT_INPUT_TYPE_DATE ||
1818 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1819 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1820 type == ui::TEXT_INPUT_TYPE_MONTH ||
1821 type == ui::TEXT_INPUT_TYPE_TIME ||
1822 type == ui::TEXT_INPUT_TYPE_WEEK;
1823}
1824
[email protected]66fca5bc2013-05-23 06:58:291825
1826void RenderWidget::StartHandlingImeEvent() {
1827 DCHECK(!handling_ime_event_);
1828 handling_ime_event_ = true;
1829}
1830
1831void RenderWidget::FinishHandlingImeEvent() {
1832 DCHECK(handling_ime_event_);
1833 handling_ime_event_ = false;
1834 // While handling an ime event, text input state and selection bounds updates
1835 // are ignored. These must explicitly be updated once finished handling the
1836 // ime event.
1837 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471838#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361839 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471840#endif
[email protected]66fca5bc2013-05-23 06:58:291841}
1842
shuchen3517bb62014-10-15 03:55:571843void RenderWidget::UpdateTextInputType() {
1844 // On Windows, not only an IME but also an on-screen keyboard relies on the
1845 // latest TextInputType to optimize its layout and functionality. Thus
1846 // |input_method_is_active_| is no longer an appropriate condition to suppress
1847 // TextInputTypeChanged IPC on Windows.
1848 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1849 // on other platforms as well as Windows if the overhead is acceptable.
1850#if !defined(OS_WIN)
1851 if (!input_method_is_active_)
1852 return;
1853#endif
1854
1855 ui::TextInputType new_type = GetTextInputType();
1856 if (IsDateTimeInput(new_type))
1857 return; // Not considered as a text input field in WebKit/Chromium.
1858
1859 bool new_can_compose_inline = CanComposeInline();
1860
1861 blink::WebTextInputInfo new_info;
1862 if (webwidget_)
1863 new_info = webwidget_->textInputInfo();
1864 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201865 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571866
1867 if (text_input_type_ != new_type
1868 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201869 || text_input_mode_ != new_mode
1870 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571871 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1872 new_type,
1873 new_mode,
shuchen82ce8c52014-10-23 01:55:201874 new_can_compose_inline,
1875 new_flags));
shuchen3517bb62014-10-15 03:55:571876 text_input_type_ = new_type;
1877 can_compose_inline_ = new_can_compose_inline;
1878 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201879 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571880 }
1881}
1882
1883#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361884void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1885 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501886 if (handling_ime_event_)
1887 return;
[email protected]90f24152014-04-09 12:41:361888 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291889 return;
[email protected]ad26ef42011-06-17 07:59:451890 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271891 if (IsDateTimeInput(new_type))
1892 return; // Not considered as a text input field in WebKit/Chromium.
1893
[email protected]180ef242013-11-07 06:50:461894 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211895 if (webwidget_)
1896 new_info = webwidget_->textInputInfo();
1897
[email protected]ad26ef42011-06-17 07:59:451898 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211899
[email protected]3306f262012-09-21 19:20:421900 // Only sends text input params if they are changed or if the ime should be
1901 // shown.
[email protected]90f24152014-04-09 12:41:361902 if (show_ime == SHOW_IME_IF_NEEDED ||
1903 (text_input_type_ != new_type ||
1904 text_input_info_ != new_info ||
1905 can_compose_inline_ != new_can_compose_inline)
1906#if defined(OS_ANDROID)
1907 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021908#endif
[email protected]90f24152014-04-09 12:41:361909 ) {
1910 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211911 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401912 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211913 p.value = new_info.value.utf8();
1914 p.selection_start = new_info.selectionStart;
1915 p.selection_end = new_info.selectionEnd;
1916 p.composition_start = new_info.compositionStart;
1917 p.composition_end = new_info.compositionEnd;
1918 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361919 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1920#if defined(USE_AURA)
1921 p.is_non_ime_change = true;
1922#endif
[email protected]183e28d2014-01-20 18:18:021923#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361924 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1925 text_field_is_dirty_;
1926 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131927 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361928 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021929#endif
shuchen3517bb62014-10-15 03:55:571930#if defined(USE_AURA)
1931 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1932 new_type,
1933 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201934 new_can_compose_inline,
1935 new_info.flags));
shuchen3517bb62014-10-15 03:55:571936#endif
[email protected]5b739cb2012-08-21 20:35:211937 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1938
1939 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041940 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451941 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201942 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291943 }
initial.commit09911bf2008-07-26 23:55:291944}
shuchen3517bb62014-10-15 03:55:571945#endif
initial.commit09911bf2008-07-26 23:55:291946
[email protected]7c8873e2013-02-05 08:03:011947void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1948 WebRect focus_webrect;
1949 WebRect anchor_webrect;
1950 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1951 *focus = focus_webrect;
1952 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321953}
1954
[email protected]e99ef6f2011-10-16 01:13:001955void RenderWidget::UpdateSelectionBounds() {
1956 if (!webwidget_)
1957 return;
[email protected]66fca5bc2013-05-23 06:58:291958 if (handling_ime_event_)
1959 return;
[email protected]e99ef6f2011-10-16 01:13:001960
jddukeacf809e2014-09-23 20:38:381961 // With composited selection updates, the selection bounds will be reported
1962 // directly by the compositor, in which case explicit IPC selection
1963 // notifications should be suppressed.
1964 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
1965 ViewHostMsg_SelectionBounds_Params params;
1966 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1967 if (selection_anchor_rect_ != params.anchor_rect ||
1968 selection_focus_rect_ != params.focus_rect) {
1969 selection_anchor_rect_ = params.anchor_rect;
1970 selection_focus_rect_ = params.focus_rect;
1971 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1972 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1973 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1974 }
[email protected]58b48a0d2012-06-13 07:01:351975 }
jddukeacf809e2014-09-23 20:38:381976
[email protected]88dbe32f2013-06-20 23:31:361977 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001978}
1979
[email protected]180ef242013-11-07 06:50:461980// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1981COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \
[email protected]ad26ef42011-06-17 07:59:451982 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461983COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \
[email protected]ad26ef42011-06-17 07:59:451984 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461985COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \
[email protected]ad26ef42011-06-17 07:59:451986 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461987COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \
[email protected]caf38ed2011-07-28 13:15:181988 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461989COMPILE_ASSERT(int(blink::WebTextInputTypeEmail) == \
[email protected]caf38ed2011-07-28 13:15:181990 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461991COMPILE_ASSERT(int(blink::WebTextInputTypeNumber) == \
[email protected]caf38ed2011-07-28 13:15:181992 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461993COMPILE_ASSERT(int(blink::WebTextInputTypeTelephone) == \
[email protected]caf38ed2011-07-28 13:15:181994 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461995COMPILE_ASSERT(int(blink::WebTextInputTypeURL) == \
[email protected]caf38ed2011-07-28 13:15:181996 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461997COMPILE_ASSERT(int(blink::WebTextInputTypeDate) == \
[email protected]feb8cf752012-06-08 04:48:001998 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461999COMPILE_ASSERT(int(blink::WebTextInputTypeDateTime) == \
[email protected]feb8cf752012-06-08 04:48:002000 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:462001COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeLocal) == \
[email protected]feb8cf752012-06-08 04:48:002002 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
[email protected]180ef242013-11-07 06:50:462003COMPILE_ASSERT(int(blink::WebTextInputTypeMonth) == \
[email protected]feb8cf752012-06-08 04:48:002004 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
[email protected]180ef242013-11-07 06:50:462005COMPILE_ASSERT(int(blink::WebTextInputTypeTime) == \
[email protected]feb8cf752012-06-08 04:48:002006 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:462007COMPILE_ASSERT(int(blink::WebTextInputTypeWeek) == \
[email protected]feb8cf752012-06-08 04:48:002008 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]180ef242013-11-07 06:50:462009COMPILE_ASSERT(int(blink::WebTextInputTypeTextArea) == \
[email protected]2a9893672012-11-09 20:33:012010 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
[email protected]180ef242013-11-07 06:50:462011COMPILE_ASSERT(int(blink::WebTextInputTypeContentEditable) == \
[email protected]2a9893672012-11-09 20:33:012012 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:462013COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeField) == \
[email protected]8b4992e2013-03-01 15:42:152014 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452015
[email protected]5b739cb2012-08-21 20:35:212016ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462017 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212018 // Check the type is in the range representable by ui::TextInputType.
2019 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462020 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212021 return static_cast<ui::TextInputType>(type);
2022}
2023
[email protected]ad26ef42011-06-17 07:59:452024ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272025 if (webwidget_)
2026 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452027 return ui::TEXT_INPUT_TYPE_NONE;
2028}
2029
[email protected]501ea13d2013-07-09 17:03:292030void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302031#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112032 // TODO(yukawa): Start sending character bounds when the browser side
2033 // implementation becomes ready (crbug.com/424866).
2034#else
[email protected]db4fc1e2013-09-06 20:01:512035 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292036 if (should_update_range) {
2037 GetCompositionRange(&range);
2038 } else {
2039 range = composition_range_;
2040 }
2041 std::vector<gfx::Rect> character_bounds;
2042 GetCompositionCharacterBounds(&character_bounds);
2043
2044 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2045 return;
2046 composition_character_bounds_ = character_bounds;
2047 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222048 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292049 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112050#endif
[email protected]501ea13d2013-07-09 17:03:292051}
2052
[email protected]58b48a0d2012-06-13 07:01:352053void RenderWidget::GetCompositionCharacterBounds(
2054 std::vector<gfx::Rect>* bounds) {
2055 DCHECK(bounds);
2056 bounds->clear();
2057}
2058
[email protected]db4fc1e2013-09-06 20:01:512059void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362060 size_t location, length;
2061 if (webwidget_->compositionRange(&location, &length)) {
2062 range->set_start(location);
2063 range->set_end(location + length);
2064 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2065 range->set_start(location);
2066 range->set_end(location + length);
2067 } else {
[email protected]db4fc1e2013-09-06 20:01:512068 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362069 }
2070}
2071
[email protected]501ea13d2013-07-09 17:03:292072bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512073 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292074 const std::vector<gfx::Rect>& bounds) {
2075 if (composition_range_ != range)
2076 return true;
2077 if (bounds.size() != composition_character_bounds_.size())
2078 return true;
2079 for (size_t i = 0; i < bounds.size(); ++i) {
2080 if (bounds[i] != composition_character_bounds_[i])
2081 return true;
2082 }
2083 return false;
2084}
[email protected]501ea13d2013-07-09 17:03:292085
[email protected]a4f0d882014-05-01 23:48:102086#if defined(OS_ANDROID)
2087void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2088 // If not initialized, default to white. Note that 0 is different from black
2089 // as black still has alpha 0xFF.
2090 if (!bg_color)
2091 bg_color = SK_ColorWHITE;
2092
2093 if (bg_color != body_background_color_) {
2094 body_background_color_ = bg_color;
2095 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2096 }
2097}
timav7a5032e2014-12-05 01:59:432098
2099bool RenderWidget::DoesRecordFullLayer() const {
2100 SynchronousCompositorFactory* synchronous_compositor_factory =
2101 SynchronousCompositorFactory::GetInstance();
2102
2103 // We assume that the absence of synchronous_compositor_factory
2104 // means we are in Chrome. In chrome, we want to clip, i.e.
2105 // *not* to record the full layer.
2106 if (!synchronous_compositor_factory)
2107 return false;
2108
2109 return synchronous_compositor_factory->RecordFullLayer();
2110}
[email protected]a4f0d882014-05-01 23:48:102111#endif
2112
[email protected]ad26ef42011-06-17 07:59:452113bool RenderWidget::CanComposeInline() {
2114 return true;
[email protected]56ea1a62011-05-30 07:05:572115}
2116
[email protected]4873c7d2009-07-16 06:36:282117WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042118 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282119}
2120
[email protected]f660d9c2012-06-06 18:31:212121float RenderWidget::deviceScaleFactor() {
2122 return device_scale_factor_;
2123}
2124
[email protected]fa7b1dc2010-06-23 17:53:042125void RenderWidget::resetInputMethod() {
2126 if (!input_method_is_active_)
2127 return;
2128
[email protected]0e45bd02013-07-12 20:20:022129 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042130 // If the last text input type is not None, then we should finish any
2131 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452132 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042133 // If a composition text exists, then we need to let the browser process
2134 // to cancel the input method's ongoing composition session.
2135 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222136 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042137 }
[email protected]d4cff272011-05-02 15:46:012138
[email protected]88dbe32f2013-06-20 23:31:362139 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042140}
2141
[email protected]c68c3e4e2013-01-24 00:36:562142void RenderWidget::didHandleGestureEvent(
2143 const WebGestureEvent& event,
2144 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022145#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562146 if (event_cancelled)
2147 return;
[email protected]07c70d22014-08-21 08:33:462148 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362149 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462150 } else if (event.type == WebInputEvent::GestureLongPress) {
2151 DCHECK(webwidget_);
2152 if (webwidget_->textInputInfo().value.isEmpty())
2153 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2154 else
2155 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562156 }
2157#endif
2158}
2159
[email protected]7912e822014-04-16 02:37:032160void RenderWidget::StartCompositor() {
2161 // For widgets that are never visible, we don't need the compositor to run
2162 // at all.
2163 if (never_visible_)
2164 return;
danakj6e3bf8012014-12-16 18:27:532165 // In tests without a RenderThreadImpl, don't set ready as this kicks
2166 // off creating output surfaces that the test can't create.
2167 if (!RenderThreadImpl::current())
2168 return;
danakj018271e32014-12-16 21:17:262169 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032170}
2171
[email protected]29e2fb42013-07-19 01:13:472172void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292173 size_t i = 0;
2174 for (; i < plugin_window_moves_.size(); ++i) {
2175 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582176 if (move.rects_valid) {
2177 plugin_window_moves_[i] = move;
2178 } else {
2179 plugin_window_moves_[i].visible = move.visible;
2180 }
initial.commit09911bf2008-07-26 23:55:292181 break;
2182 }
2183 }
2184
2185 if (i == plugin_window_moves_.size())
2186 plugin_window_moves_.push_back(move);
2187}
[email protected]268654772009-08-06 23:02:042188
2189void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2190 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2191 i != plugin_window_moves_.end(); ++i) {
2192 if (i->window == window) {
2193 plugin_window_moves_.erase(i);
2194 break;
2195 }
2196 }
2197}
[email protected]67bfb83f2011-09-22 03:36:372198
[email protected]63b465922012-09-06 02:04:522199
[email protected]24ed0432013-04-24 07:50:312200RenderWidgetCompositor* RenderWidget::compositor() const {
2201 return compositor_.get();
2202}
2203
[email protected]180ef242013-11-07 06:50:462204bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372205 return false;
2206}
[email protected]c3d45532011-10-07 19:20:402207
[email protected]41d86852012-11-07 12:23:242208bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462209 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242210 return false;
2211}
2212
ccamerona7644752014-12-30 01:16:312213void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312214 const blink::WebMouseWheelEvent& wheel_event,
2215 bool event_processed) {
ccamerona7644752014-12-30 01:16:312216 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312217 return;
2218
2219 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2220 // assume that an unprocessed event was entirely an overscroll, and that a
2221 // processed event was entirely scroll.
2222 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2223 // http://crbug.com/442859
2224 cc::InputHandlerScrollResult scroll_result;
2225 if (event_processed) {
2226 scroll_result.did_scroll = true;
2227 } else {
2228 scroll_result.did_overscroll_root = true;
2229 scroll_result.unused_scroll_delta =
2230 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2231 }
2232
2233 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2234 InputHandlerManager* input_handler_manager =
2235 render_thread ? render_thread->input_handler_manager() : NULL;
2236 if (input_handler_manager) {
2237 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2238 routing_id_, wheel_event, scroll_result);
2239 }
2240}
2241
[email protected]ce6689f2013-03-29 12:52:552242void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2243 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2244}
2245
[email protected]5d0bbdfa92013-12-10 00:35:512246void RenderWidget::setTouchAction(
2247 blink::WebTouchAction web_touch_action) {
2248
2249 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2250 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192251 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512252 return;
2253
[email protected]a18f67a2013-12-20 19:44:362254 // Verify the same values are used by the types so we can cast between them.
2255 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) ==
2256 blink::WebTouchActionAuto,
2257 enum_values_must_match_for_touch_action);
2258 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) ==
2259 blink::WebTouchActionNone,
2260 enum_values_must_match_for_touch_action);
2261 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) ==
2262 blink::WebTouchActionPanX,
2263 enum_values_must_match_for_touch_action);
2264 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_Y) ==
2265 blink::WebTouchActionPanY,
2266 enum_values_must_match_for_touch_action);
[email protected]2bd73272014-03-13 19:36:112267 COMPILE_ASSERT(
2268 static_cast<blink::WebTouchAction>(TOUCH_ACTION_PINCH_ZOOM) ==
2269 blink::WebTouchActionPinchZoom,
2270 enum_values_must_match_for_touch_action);
[email protected]a18f67a2013-12-20 19:44:362271
2272 content::TouchAction content_touch_action =
2273 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512274 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2275}
2276
[email protected]90f24152014-04-09 12:41:362277void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2278#if defined(OS_ANDROID)
2279 text_field_is_dirty_ = true;
2280#endif
2281}
2282
[email protected]3d5c243b2012-11-30 00:26:012283bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2284 return true;
2285}
2286
[email protected]0634cdd42013-08-16 00:46:092287scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132288RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592289 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092290 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492291 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222292 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092293 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292294 if (!RenderThreadImpl::current())
2295 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402296 CauseForGpuLaunch cause =
2297 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292298 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402299 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222300 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292301 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592302
[email protected]828a3932014-04-02 14:43:132303 // Explicitly disable antialiasing for the compositor. As of the time of
2304 // this writing, the only platform that supported antialiasing for the
2305 // compositor was Mac OS X, because the on-screen OpenGL context creation
2306 // code paths on Windows and Linux didn't yet have multisampling support.
2307 // Mac OS X essentially always behaves as though it's rendering offscreen.
2308 // Multisampling has a heavy cost especially on devices with relatively low
2309 // fill rate like most notebooks, and the Mac implementation would need to
2310 // be optimized to resolve directly into the IOSurface shared between the
2311 // GPU and browser processes. For these reasons and to avoid platform
2312 // disparities we explicitly disable antialiasing.
2313 blink::WebGraphicsContext3D::Attributes attributes;
2314 attributes.antialias = false;
2315 attributes.shareResources = true;
2316 attributes.noAutomaticFlushes = true;
2317 attributes.depth = false;
2318 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132319 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292320 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012321#if defined(OS_ANDROID)
2322 // If we raster too fast we become upload bound, and pending
2323 // uploads consume memory. For maximum upload throughput, we would
2324 // want to allow for upload_throughput * pipeline_time of pending
2325 // uploads, after which we are just wasting memory. Since we don't
2326 // know our upload throughput yet, this just caps our memory usage.
2327 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272328 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032329 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012330 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032331 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012332 // Deadline to draw a frame to achieve 60 frames per second.
2333 const size_t kMillisecondsPerFrame = 16;
2334 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032335 size_t max_transfer_buffer_usage_mb =
2336 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2337 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012338 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2339 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292340 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032341 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012342#endif
[email protected]96ab016c2013-10-23 00:50:292343
[email protected]96ab016c2013-10-23 00:50:292344 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132345 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2346 GetURLForGraphicsContext3D(),
2347 gpu_channel_host.get(),
2348 attributes,
[email protected]828a3932014-04-02 14:43:132349 lose_context_when_out_of_memory,
2350 limits,
2351 NULL));
[email protected]0634cdd42013-08-16 00:46:092352 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592353}
2354
[email protected]e3244ed2014-06-20 20:04:272355void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2356 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162357}
2358
[email protected]e3244ed2014-06-20 20:04:272359void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2360 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162361}
2362
[email protected]de3c5d82014-05-28 22:12:592363void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2364 render_frames_.AddObserver(frame);
2365}
2366
2367void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2368 render_frames_.RemoveObserver(frame);
2369}
2370
[email protected]a017938b2014-05-27 21:17:172371#if defined(VIDEO_HOLE)
2372void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2373 video_hole_frames_.AddObserver(frame);
2374}
2375
2376void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2377 video_hole_frames_.RemoveObserver(frame);
2378}
2379#endif // defined(VIDEO_HOLE)
2380
[email protected]e9ff79c2012-10-19 21:31:262381} // namespace content