blob: 96f45382a67db75065565f6510f9be1853c12c65 [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"
[email protected]9c769d412014-03-20 18:27:3971#include "ui/gfx/point_conversions.h"
[email protected]a25e25b2012-09-28 14:32:3772#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3573#include "ui/gfx/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.
[email protected]dd32b1272013-05-04 14:17:11838 base::MessageLoop::current()->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
[email protected]b6eb8e332013-09-10 00:51:01947 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33948 bool use_software = fallback;
949 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
950 use_software = true;
951
[email protected]0634cdd42013-08-16 00:46:09952 scoped_refptr<ContextProviderCommandBuffer> context_provider;
[email protected]e09994a2014-03-26 19:59:33953 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09954 context_provider = ContextProviderCommandBuffer::Create(
[email protected]828a3932014-04-02 14:43:13955 CreateGraphicsContext3D(), "RenderCompositor");
[email protected]e09994a2014-03-26 19:59:33956 if (!context_provider.get()) {
957 // Cause the compositor to wait and try again.
958 return scoped_ptr<cc::OutputSurface>();
959 }
[email protected]0634cdd42013-08-16 00:46:09960 }
[email protected]ebc0e1df2013-08-01 02:46:22961
[email protected]b6eb8e332013-09-10 00:51:01962 uint32 output_surface_id = next_output_surface_id_++;
[email protected]50cf1992014-03-29 00:06:00963 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
danakj6e3bf8012014-12-16 18:27:53964 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
[email protected]65a33ce2014-03-25 22:37:09965 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11966 new DelegatedCompositorOutputSurface(routing_id(),
967 output_surface_id,
968 context_provider,
969 frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:09970 }
[email protected]0634cdd42013-08-16 00:46:09971 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:09972 scoped_ptr<cc::SoftwareOutputDevice> software_device(
973 new CompositorSoftwareOutputDevice());
974
[email protected]586871b2014-07-22 17:05:11975 return scoped_ptr<cc::OutputSurface>(
976 new CompositorOutputSurface(routing_id(),
977 output_surface_id,
978 NULL,
979 software_device.Pass(),
980 frame_swap_message_queue_,
981 true));
[email protected]ebc0e1df2013-08-01 02:46:22982 }
[email protected]ed7defa2013-03-12 21:29:59983
[email protected]36e5ff12013-06-11 12:19:29984 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
[email protected]758efb02014-04-05 07:53:45985 // Composite-to-mailbox is currently used for layout tests in order to cause
986 // them to draw inside in the renderer to do the readback there. This should
987 // no longer be the case when crbug.com/311404 is fixed.
danakj6e3bf8012014-12-16 18:27:53988 DCHECK(RenderThreadImpl::current()->layout_test_mode());
[email protected]186f09602013-09-24 07:13:16989 cc::ResourceFormat format = cc::RGBA_8888;
[email protected]35b4f0c2014-06-26 16:55:27990 if (base::SysInfo::IsLowEndDevice())
[email protected]186f09602013-09-24 07:13:16991 format = cc::RGB_565;
[email protected]36e5ff12013-06-11 12:19:29992 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:11993 new MailboxOutputSurface(routing_id(),
994 output_surface_id,
995 context_provider,
996 scoped_ptr<cc::SoftwareOutputDevice>(),
997 frame_swap_message_queue_,
998 format));
[email protected]36e5ff12013-06-11 12:19:29999 }
[email protected]0634cdd42013-08-16 00:46:091000 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:291001 return scoped_ptr<cc::OutputSurface>(
[email protected]586871b2014-07-22 17:05:111002 new CompositorOutputSurface(routing_id(),
1003 output_surface_id,
1004 context_provider,
1005 scoped_ptr<cc::SoftwareOutputDevice>(),
1006 frame_swap_message_queue_,
1007 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:281008}
1009
[email protected]4d7e46a2013-11-08 05:33:401010void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241011 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241012 // Schedule another frame so the compositor learns about it.
[email protected]8b9e52b2014-01-17 16:35:311013 scheduleComposite();
[email protected]65225772011-05-12 21:10:241014}
1015
[email protected]4d7e46a2013-11-08 05:33:401016void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081017 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081018}
1019
[email protected]4d7e46a2013-11-08 05:33:401020void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241021 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161022
[email protected]404939f2012-06-01 04:06:181023 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161024 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291025}
1026
[email protected]180ef242013-11-07 06:50:461027void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351028 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091029 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191030 base::AutoReset<bool> handling_input_event_resetter(
1031 &handling_input_event_, true);
1032 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291033 return;
[email protected]c27dd4f2014-05-22 18:05:191034 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1035 &handling_event_type_, input_event->type);
[email protected]25402eb2014-07-18 03:09:521036#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541037 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521038 // |AdapterInputConnection| generates input key events to make sure all JS
1039 // listeners that monitor KeyUp and KeyDown events receive the proper key
1040 // code. Since this input key event comes from IME, we need to set the
1041 // IME event guard here to make sure it does not interfere with other IME
1042 // events.
1043 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1044 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1045 const WebKeyboardEvent& key_event =
1046 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541047 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171048 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091049 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1050 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1051 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1052 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1053 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521054 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521055 }
1056#endif
initial.commit09911bf2008-07-26 23:55:291057
[email protected]8062ab262014-05-27 16:56:431058 base::AutoReset<const ui::LatencyInfo*> resetter(&current_event_latency_info_,
1059 &latency_info);
1060
[email protected]fd847792013-10-24 17:12:351061 base::TimeTicks start_time;
1062 if (base::TimeTicks::IsHighResNowFastAndReliable())
1063 start_time = base::TimeTicks::HighResNow();
1064
[email protected]b4841e1c2013-05-16 22:30:101065 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301066 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151067 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
[email protected]15ba6dea2014-04-02 01:44:131068 TRACE_EVENT_FLOW_STEP0(
1069 "input",
1070 "LatencyInfo.Flow",
1071 TRACE_ID_DONT_MANGLE(latency_info.trace_id),
1072 "HanldeInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101073
jdduke07788062014-12-05 03:16:301074 // If we don't have a high res timer, these metrics won't be accurate enough
1075 // to be worth collecting. Note that this does introduce some sampling bias.
1076 if (!start_time.is_null())
1077 LogInputEventLatencyUma(*input_event, start_time);
1078
[email protected]6be422b2013-12-08 06:47:311079 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351080 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311081 if (compositor_) {
1082 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351083 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1084 .Pass();
[email protected]6be422b2013-12-08 06:47:311085 }
[email protected]c2eaa8f2013-05-10 02:41:551086
[email protected]67bfb83f2011-09-22 03:36:371087 bool prevent_default = false;
1088 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261089 const WebMouseEvent& mouse_event =
1090 *static_cast<const WebMouseEvent*>(input_event);
1091 TRACE_EVENT2("renderer", "HandleMouseMove",
1092 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421093 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261094 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371095 }
1096
[email protected]cefe9b152014-03-27 18:16:151097 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421098 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151099#if defined(OS_ANDROID)
1100 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1101 // case it should behave like a select key (i.e. causing a click if a button
1102 // is focused). However, if a text field is focused (2), its intended
1103 // behavior is to just show the IME and don't propagate the key.
1104 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1105 // when clicked on an input text field and cause the form submit if clicked
1106 // when the submit button is focused, but not vice-versa.
1107 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1108 // but at this point we have to swallow the event for the scenario (2).
1109 const WebKeyboardEvent& key_event =
1110 *static_cast<const WebKeyboardEvent*>(input_event);
1111 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1112 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1113 OnShowImeIfNeeded();
1114 prevent_default = true;
1115 }
1116#endif
1117 }
[email protected]f56c7872013-06-18 12:31:571118
[email protected]41d86852012-11-07 12:23:241119 if (WebInputEvent::isGestureEventType(input_event->type)) {
1120 const WebGestureEvent& gesture_event =
1121 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421122 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241123 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1124 }
1125
[email protected]67bfb83f2011-09-22 03:36:371126 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121127 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1128 suppress_next_char_events_ = false;
1129 if (!processed && webwidget_)
1130 processed = webwidget_->handleInputEvent(*input_event);
1131 }
1132
1133 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1134 // it's not processed by webkit, then we need to suppress the upcoming Char
1135 // events.
1136 if (!processed && is_keyboard_shortcut)
1137 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291138
[email protected]3d5c243b2012-11-30 00:26:011139 InputEventAckState ack_result = processed ?
1140 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1141 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1142 const WebTouchEvent& touch_event =
1143 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251144 // Hit-test for all the pressed touch points. If there is a touch-handler
1145 // for any of the touch points, then the renderer should continue to receive
1146 // touch events.
1147 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1148 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1149 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271150 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391151 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251152 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1153 break;
1154 }
1155 }
[email protected]3d5c243b2012-11-30 00:26:011156 }
1157
[email protected]721e2302014-04-30 23:42:011158 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061159
[email protected]fd847792013-10-24 17:12:351160 // If we don't have a fast and accurate HighResNow, we assume the input
1161 // handlers are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301162 bool rate_limiting_wanted =
1163 input_event->type == WebInputEvent::MouseMove ||
1164 input_event->type == WebInputEvent::MouseWheel;
1165 if (rate_limiting_wanted && !start_time.is_null()) {
[email protected]fd847792013-10-24 17:12:351166 base::TimeTicks end_time = base::TimeTicks::HighResNow();
1167 total_input_handling_time_this_frame_ += (end_time - start_time);
1168 rate_limiting_wanted =
1169 total_input_handling_time_this_frame_.InMicroseconds() >
1170 kInputHandlingTimeThrottlingThresholdMicroseconds;
1171 }
1172
[email protected]7f19e9d2014-05-09 15:16:291173 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1174
[email protected]c27dd4f2014-05-22 18:05:191175 // Note that we can't use handling_event_type_ here since it will be overriden
1176 // by reentrant calls for events after the paused one.
1177 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1178 input_event->type == WebInputEvent::MouseMove;
1179 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561180 InputHostMsg_HandleInputEvent_ACK_Params ack;
1181 ack.type = input_event->type;
1182 ack.state = ack_result;
1183 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551184 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561185 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301186 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551187 // We want to rate limit the input events in this case, so we'll wait for
1188 // painting to finish before ACKing this message.
1189 TRACE_EVENT_INSTANT0("renderer",
1190 "RenderWidget::OnHandleInputEvent ack throttled",
1191 TRACE_EVENT_SCOPE_THREAD);
1192 if (pending_input_event_ack_) {
1193 // As two different kinds of events could cause us to postpone an ack
1194 // we send it now, if we have one pending. The Browser should never
1195 // send us the same kind of event we are delaying the ack for.
1196 Send(pending_input_event_ack_.release());
1197 }
1198 pending_input_event_ack_ = response.Pass();
1199 if (compositor_)
1200 compositor_->NotifyInputThrottledUntilCommit();
1201 } else {
1202 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171203 }
[email protected]12fbad812009-09-01 18:21:241204 }
[email protected]5fea4a52014-05-27 00:17:521205 if (input_event->type == WebInputEvent::MouseMove)
1206 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241207
[email protected]3306f262012-09-21 19:20:421208#if defined(OS_ANDROID)
1209 // Allow the IME to be shown when the focus changes as a consequence
1210 // of a processed touch end event.
1211 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361212 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021213#elif defined(USE_AURA)
1214 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1215 // change.
1216 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1217 input_event->type == WebInputEvent::MouseUp))
[email protected]90f24152014-04-09 12:41:361218 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
[email protected]3306f262012-09-21 19:20:421219#endif
1220
[email protected]67bfb83f2011-09-22 03:36:371221 if (!prevent_default) {
1222 if (WebInputEvent::isKeyboardEventType(input_event->type))
1223 DidHandleKeyEvent();
1224 if (WebInputEvent::isMouseEventType(input_event->type))
1225 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241226 if (WebInputEvent::isTouchEventType(input_event->type))
1227 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371228 }
initial.commit09911bf2008-07-26 23:55:291229}
1230
[email protected]34202de2013-05-06 23:36:221231void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1232 if (webwidget_)
1233 webwidget_->setCursorVisibilityState(is_visible);
1234}
1235
initial.commit09911bf2008-07-26 23:55:291236void RenderWidget::OnMouseCaptureLost() {
1237 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281238 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291239}
1240
1241void RenderWidget::OnSetFocus(bool enable) {
1242 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331243 if (webwidget_)
1244 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291245}
1246
1247void RenderWidget::ClearFocus() {
1248 // We may have got the focus from the browser before this gets processed, in
1249 // which case we do not want to unfocus ourself.
1250 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281251 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291252}
1253
[email protected]fd847792013-10-24 17:12:351254void RenderWidget::FlushPendingInputEventAck() {
[email protected]d8a8ecb2013-10-23 18:03:071255 if (pending_input_event_ack_)
1256 Send(pending_input_event_ack_.release());
[email protected]fd847792013-10-24 17:12:351257 total_input_handling_time_this_frame_ = base::TimeDelta();
1258}
1259
initial.commit09911bf2008-07-26 23:55:291260///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461261// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291262
[email protected]244ac1892011-12-02 17:04:471263void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091264 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451265 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581266
[email protected]5b45ad42013-10-25 00:42:041267 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451268 WebRect new_pos(rootWindowRect().x,
1269 rootWindowRect().y,
1270 new_size.width,
1271 new_size.height);
1272 view_screen_rect_ = new_pos;
1273 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031274 }
[email protected]20fbfc22013-05-08 20:50:581275
[email protected]eac2b362013-05-22 07:01:451276 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581277
[email protected]5b45ad42013-10-25 00:42:041278 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581279 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091280 }
[email protected]244ac1892011-12-02 17:04:471281}
1282
[email protected]3a1c8a8032013-03-18 22:35:321283void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051284 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1285 device_scale_factor_));
1286 if (compositor_)
1287 compositor_->setViewportSize(size_, physical_backing_size_);
1288}
1289
[email protected]e195e582013-03-08 01:32:591290void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221291 DCHECK(!host_closing_);
1292
danakj6e3bf8012014-12-16 18:27:531293 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591294 compositor_->setViewportSize(size_, physical_backing_size_);
1295 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031296 StartCompositor();
[email protected]e195e582013-03-08 01:32:591297}
1298
ennef3c58142014-12-09 21:44:381299void RenderWidget::WillCloseLayerTreeView() {
1300 if (host_closing_)
1301 return;
1302
1303 // Prevent new compositors or output surfaces from being created.
1304 host_closing_ = true;
1305
[email protected]aeeedad2014-08-22 18:16:221306 // Always send this notification to prevent new layer tree views from
1307 // being created, even if one hasn't been created yet.
1308 if (webwidget_)
1309 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221310}
1311
[email protected]180ef242013-11-07 06:50:461312blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281313 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061314}
1315
[email protected]9cd43a62012-03-26 08:03:561316void RenderWidget::willBeginCompositorFrame() {
1317 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371318
[email protected]abe8b3a2012-03-28 21:19:371319 // The following two can result in further layout and possibly
1320 // enable GPU acceleration so they need to be called before any painting
1321 // is done.
shuchen3517bb62014-10-15 03:55:571322 UpdateTextInputType();
1323#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361324 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571325#endif
[email protected]abe8b3a2012-03-28 21:19:371326 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561327}
1328
[email protected]3391a0772012-03-28 00:32:071329void RenderWidget::didBecomeReadyForAdditionalInput() {
1330 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351331 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071332}
1333
[email protected]6fceb912013-02-15 06:24:151334void RenderWidget::DidCommitCompositorFrame() {
[email protected]e3244ed2014-06-20 20:04:271335 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161336 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171337#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271338 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1339 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171340#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151341}
1342
[email protected]586871b2014-07-22 17:05:111343// static
1344scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1345 IPC::Message* msg,
1346 MessageDeliveryPolicy policy,
1347 FrameSwapMessageQueue* frame_swap_message_queue,
1348 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1349 bool commit_requested,
1350 int source_frame_number) {
1351 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1352 // No need for lock: this gets changed only on this thread.
1353 !commit_requested &&
1354 // No need for lock: Messages are only enqueued from this thread, if we
1355 // don't have any now, no other thread will add any.
1356 frame_swap_message_queue->Empty()) {
1357 sync_message_filter->Send(msg);
dcheng4b6b5ff2014-10-16 00:42:061358 return nullptr;
[email protected]586871b2014-07-22 17:05:111359 }
1360
1361 bool first_message_for_frame = false;
1362 frame_swap_message_queue->QueueMessageForFrame(policy,
1363 source_frame_number,
1364 make_scoped_ptr(msg),
1365 &first_message_for_frame);
1366 if (first_message_for_frame) {
1367 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1368 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061369 return promise;
[email protected]586871b2014-07-22 17:05:111370 }
dcheng4b6b5ff2014-10-16 00:42:061371 return nullptr;
[email protected]586871b2014-07-22 17:05:111372}
1373
1374void RenderWidget::QueueMessage(IPC::Message* msg,
1375 MessageDeliveryPolicy policy) {
1376 // RenderThreadImpl::current() is NULL in some tests.
1377 if (!compositor_ || !RenderThreadImpl::current()) {
1378 Send(msg);
1379 return;
1380 }
1381
1382 scoped_ptr<cc::SwapPromise> swap_promise =
1383 QueueMessageImpl(msg,
1384 policy,
dcheng58867a92014-08-26 02:50:221385 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111386 RenderThreadImpl::current()->sync_message_filter(),
1387 compositor_->commitRequested(),
1388 compositor_->GetSourceFrameNumber());
1389
1390 if (swap_promise) {
1391 compositor_->QueueSwapPromise(swap_promise.Pass());
1392 compositor_->SetNeedsCommit();
1393 }
1394}
1395
[email protected]58264a32011-11-17 23:36:151396void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101397 // NOTE: Tests may break if this event is renamed or moved. See
1398 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501399 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161400 // Notify subclasses that we initiated the paint operation.
1401 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151402}
1403
1404void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181405 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1406
1407 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561408 DidFlushPaint();
1409
[email protected]ea3ee0a2012-05-15 03:43:091410 if (!next_paint_flags_ &&
1411 !need_update_rect_for_auto_resize_ &&
1412 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151413 return;
[email protected]ea3ee0a2012-05-15 03:43:091414 }
[email protected]58264a32011-11-17 23:36:151415
1416 ViewHostMsg_UpdateRect_Params params;
1417 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151418 params.plugin_window_moves.swap(plugin_window_moves_);
1419 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151420
1421 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1422 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091423 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151424}
1425
[email protected]8b9e52b2014-01-17 16:35:311426void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531427 if (compositor_ &&
1428 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221429 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311430 }
1431}
1432
[email protected]4873c7d2009-07-16 06:36:281433void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301434 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521435 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401436 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291437 // Only send a SetCursor message if we need to make a change.
1438 if (!current_cursor_.IsEqual(cursor)) {
1439 current_cursor_ = cursor;
1440 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1441 }
1442}
1443
1444// We are supposed to get a single call to Show for a newly created RenderWidget
1445// that was created via RenderWidget::CreateWebView. So, we wait until this
1446// point to dispatch the ShowWidget message.
1447//
1448// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281449// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291450//
[email protected]4873c7d2009-07-16 06:36:281451void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291452 DCHECK(!did_show_) << "received extraneous Show call";
1453 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1454 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1455
[email protected]8de12d942010-11-17 20:42:441456 if (did_show_)
1457 return;
1458
1459 did_show_ = true;
1460 // NOTE: initial_pos_ may still have its default values at this point, but
1461 // that's okay. It'll be ignored if as_popup is false, or the browser
1462 // process will impose a default position otherwise.
1463 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1464 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291465}
1466
[email protected]4873c7d2009-07-16 06:36:281467void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291468}
1469
[email protected]4873c7d2009-07-16 06:36:281470void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291471}
1472
[email protected]2533ce12009-05-09 00:02:241473void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381474 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241475 Send(new ViewHostMsg_Close(routing_id_));
1476}
1477
[email protected]4873c7d2009-07-16 06:36:281478void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321479 if (is_swapped_out_) {
1480 // This widget is currently swapped out, and the active widget is in a
1481 // different process. Have the browser route the close request to the
1482 // active widget instead, so that the correct unload handlers are run.
1483 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1484 return;
1485 }
1486
initial.commit09911bf2008-07-26 23:55:291487 // If a page calls window.close() twice, we'll end up here twice, but that's
1488 // OK. It is safe to send multiple Close messages.
1489
[email protected]2533ce12009-05-09 00:02:241490 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1491 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1492 // could be closed before the JS finishes executing. So instead, post a
1493 // message back to the message loop, which won't run until the JS is
1494 // complete, and then the Close message can be sent.
ennef3c58142014-12-09 21:44:381495 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211496 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291497}
1498
[email protected]9017d7852013-11-21 17:47:351499void RenderWidget::QueueSyntheticGesture(
1500 scoped_ptr<SyntheticGestureParams> gesture_params,
1501 const SyntheticGestureCompletionCallback& callback) {
1502 DCHECK(!callback.is_null());
1503
1504 pending_synthetic_gesture_callbacks_.push(callback);
1505
1506 SyntheticGesturePacket gesture_packet;
1507 gesture_packet.set_gesture_params(gesture_params.Pass());
1508
1509 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1510}
1511
initial.commit09911bf2008-07-26 23:55:291512void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031513 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381514 WillCloseLayerTreeView();
1515 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291516 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281517 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291518 webwidget_ = NULL;
1519 }
1520}
1521
[email protected]4873c7d2009-07-16 06:36:281522WebRect RenderWidget::windowRect() {
1523 if (pending_window_rect_count_)
1524 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241525
[email protected]80ad8622012-11-07 16:33:031526 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291527}
1528
[email protected]180ef242013-11-07 06:50:461529void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301530 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541531 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301532}
1533
[email protected]b2e4c70132013-10-03 02:07:511534void RenderWidget::setWindowRect(const WebRect& rect) {
1535 WebRect pos = rect;
1536 if (popup_origin_scale_for_emulation_) {
1537 float scale = popup_origin_scale_for_emulation_;
1538 pos.x = popup_screen_origin_for_emulation_.x() +
1539 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1540 pos.y = popup_screen_origin_for_emulation_.y() +
1541 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1542 }
1543
[email protected]5b45ad42013-10-25 00:42:041544 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201545 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031546 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1547 SetPendingWindowRect(pos);
1548 } else {
[email protected]ec951b9d2013-10-20 06:21:201549 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031550 }
initial.commit09911bf2008-07-26 23:55:291551 } else {
bokanf0fd2412014-10-30 15:28:551552 ResizeSynchronously(pos, visible_viewport_size_);
initial.commit09911bf2008-07-26 23:55:291553 }
1554}
1555
[email protected]2533ce12009-05-09 00:02:241556void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1557 pending_window_rect_ = rect;
1558 pending_window_rect_count_++;
1559}
1560
[email protected]4873c7d2009-07-16 06:36:281561WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241562 if (pending_window_rect_count_) {
1563 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1564 // the RootWindowRect is probably going to return wrong results since the
1565 // browser may not have processed the Move yet. There isn't really anything
1566 // good to do in this case, and it shouldn't happen - since this size is
1567 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281568 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241569 }
1570
[email protected]80ad8622012-11-07 16:33:031571 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371572}
1573
[email protected]4873c7d2009-07-16 06:36:281574WebRect RenderWidget::windowResizerRect() {
1575 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191576}
1577
[email protected]fa7b1dc2010-06-23 17:53:041578void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031579 // To prevent this renderer process from sending unnecessary IPC messages to
1580 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041581 // only during the input method attached to the browser process is active.
1582 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291583}
1584
[email protected]37a241c2013-12-03 03:16:171585void RenderWidget::OnCandidateWindowShown() {
1586 webwidget_->didShowCandidateWindow();
1587}
1588
1589void RenderWidget::OnCandidateWindowUpdated() {
1590 webwidget_->didUpdateCandidateWindow();
1591}
1592
1593void RenderWidget::OnCandidateWindowHidden() {
1594 webwidget_->didHideCandidateWindow();
1595}
1596
[email protected]fa7b1dc2010-06-23 17:53:041597void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261598 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041599 const std::vector<WebCompositionUnderline>& underlines,
1600 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131601 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281602 return;
[email protected]66fca5bc2013-05-23 06:58:291603 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361604 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041605 text, WebVector<WebCompositionUnderline>(underlines),
1606 selection_start, selection_end)) {
1607 // If we failed to set the composition text, then we need to let the browser
1608 // process to cancel the input method's ongoing composition session, to make
1609 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221610 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261611 }
[email protected]88dbe32f2013-06-20 23:31:361612 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041613}
1614
[email protected]fcf75d42013-12-03 20:11:261615void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511616 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021617 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131618 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041619 return;
[email protected]66fca5bc2013-05-23 06:58:291620 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041621 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021622 if (text.length())
1623 webwidget_->confirmComposition(text);
1624 else if (keep_selection)
1625 webwidget_->confirmComposition(WebWidget::KeepSelection);
1626 else
1627 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041628 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361629 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291630}
1631
[email protected]0bc1f572013-04-17 01:46:311632void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121633 // During shutdown we can just ignore this message.
1634 if (!webwidget_)
1635 return;
1636
[email protected]0bc1f572013-04-17 01:46:311637 // Even if the browser provides an empty damage rect, it's still expecting to
1638 // receive a repaint ack so just damage the entire widget bounds.
1639 if (size_to_paint.IsEmpty()) {
1640 size_to_paint = size_;
1641 }
1642
[email protected]ec7dc112008-08-06 05:30:121643 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051644 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311645 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121646}
1647
[email protected]79fa22e2013-08-23 15:18:121648void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351649 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1650
1651 pending_synthetic_gesture_callbacks_.front().Run();
1652 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271653}
1654
[email protected]4873c7d2009-07-16 06:36:281655void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111656 if (!webwidget_)
1657 return;
[email protected]4873c7d2009-07-16 06:36:281658 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111659}
1660
[email protected]80ad8622012-11-07 16:33:031661void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1662 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511663 if (screen_metrics_emulator_) {
1664 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1665 view_screen_rect, window_screen_rect);
1666 } else {
1667 view_screen_rect_ = view_screen_rect;
1668 window_screen_rect_ = window_screen_rect;
1669 }
[email protected]80ad8622012-11-07 16:33:031670 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1671}
1672
[email protected]adb362312014-06-28 06:04:241673void RenderWidget::showImeIfNeeded() {
1674 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131675}
1676
[email protected]adb362312014-06-28 06:04:241677void RenderWidget::OnShowImeIfNeeded() {
1678#if defined(OS_ANDROID) || defined(USE_AURA)
1679 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1680#endif
1681}
1682
1683#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131684void RenderWidget::IncrementOutstandingImeEventAcks() {
1685 ++outstanding_ime_acks_;
1686}
1687
1688void RenderWidget::OnImeEventAck() {
1689 --outstanding_ime_acks_;
1690 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511691}
[email protected]105dffb42013-02-20 03:46:211692#endif
1693
[email protected]0d1ebed12013-08-05 22:01:131694bool RenderWidget::ShouldHandleImeEvent() {
1695#if defined(OS_ANDROID)
1696 return !!webwidget_ && outstanding_ime_acks_ == 0;
1697#else
1698 return !!webwidget_;
1699#endif
1700}
1701
[email protected]c27dd4f2014-05-22 18:05:191702bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1703 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521704 // If we pause multiple times during a single mouse move event, we should
1705 // only send ACK once.
1706 if (!ignore_ack_for_mouse_move_from_debugger_) {
1707 InputHostMsg_HandleInputEvent_ACK_Params ack;
1708 ack.type = handling_event_type_;
1709 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1710 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1711 }
[email protected]c27dd4f2014-05-22 18:05:191712 return true;
1713 }
1714 return false;
1715}
1716
1717void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1718 ignore_ack_for_mouse_move_from_debugger_ = true;
1719}
1720
[email protected]468ac582012-11-20 00:53:191721void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1722 if (device_scale_factor_ == device_scale_factor)
1723 return;
1724
1725 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051726 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191727}
1728
[email protected]28ed6b32014-06-08 02:16:271729bool RenderWidget::SetDeviceColorProfile(
1730 const std::vector<char>& color_profile) {
1731 if (device_color_profile_ == color_profile)
1732 return false;
1733
1734 device_color_profile_ = color_profile;
1735 return true;
1736}
1737
noeldb4df152014-09-16 17:45:201738void RenderWidget::ResetDeviceColorProfileForTesting() {
1739 if (!device_color_profile_.empty())
1740 device_color_profile_.clear();
1741 device_color_profile_.push_back('0');
1742}
1743
[email protected]fcdc5642014-05-09 14:32:241744void RenderWidget::OnOrientationChange() {
1745}
1746
[email protected]ceb36f7d2012-10-31 18:33:241747gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521748 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241749 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521750}
1751
[email protected]bee16aab2009-08-26 15:55:031752void RenderWidget::SetHidden(bool hidden) {
1753 if (is_hidden_ == hidden)
1754 return;
1755
1756 // The status has changed. Tell the RenderThread about it.
1757 is_hidden_ = hidden;
1758 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001759 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031760 else
[email protected]b2db9272014-01-10 17:42:001761 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031762}
1763
[email protected]2b624c562011-10-27 22:58:261764void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261765 if (!webwidget_)
1766 return;
1767
1768 if (is_fullscreen_) {
1769 webwidget_->willExitFullScreen();
1770 } else {
1771 webwidget_->willEnterFullScreen();
1772 }
[email protected]2b624c562011-10-27 22:58:261773}
1774
1775void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261776 if (!webwidget_)
1777 return;
1778
1779 if (is_fullscreen_) {
1780 webwidget_->didEnterFullScreen();
1781 } else {
1782 webwidget_->didExitFullScreen();
1783 }
[email protected]2b624c562011-10-27 22:58:261784}
1785
[email protected]674741932009-02-04 23:44:461786bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051787 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461788}
1789
[email protected]674741932009-02-04 23:44:461790void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051791 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461792}
1793
[email protected]674741932009-02-04 23:44:461794void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051795 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461796}
1797
[email protected]b18583c2012-12-18 06:55:271798static bool IsDateTimeInput(ui::TextInputType type) {
1799 return type == ui::TEXT_INPUT_TYPE_DATE ||
1800 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1801 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1802 type == ui::TEXT_INPUT_TYPE_MONTH ||
1803 type == ui::TEXT_INPUT_TYPE_TIME ||
1804 type == ui::TEXT_INPUT_TYPE_WEEK;
1805}
1806
[email protected]66fca5bc2013-05-23 06:58:291807
1808void RenderWidget::StartHandlingImeEvent() {
1809 DCHECK(!handling_ime_event_);
1810 handling_ime_event_ = true;
1811}
1812
1813void RenderWidget::FinishHandlingImeEvent() {
1814 DCHECK(handling_ime_event_);
1815 handling_ime_event_ = false;
1816 // While handling an ime event, text input state and selection bounds updates
1817 // are ignored. These must explicitly be updated once finished handling the
1818 // ime event.
1819 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471820#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361821 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471822#endif
[email protected]66fca5bc2013-05-23 06:58:291823}
1824
shuchen3517bb62014-10-15 03:55:571825void RenderWidget::UpdateTextInputType() {
1826 // On Windows, not only an IME but also an on-screen keyboard relies on the
1827 // latest TextInputType to optimize its layout and functionality. Thus
1828 // |input_method_is_active_| is no longer an appropriate condition to suppress
1829 // TextInputTypeChanged IPC on Windows.
1830 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1831 // on other platforms as well as Windows if the overhead is acceptable.
1832#if !defined(OS_WIN)
1833 if (!input_method_is_active_)
1834 return;
1835#endif
1836
1837 ui::TextInputType new_type = GetTextInputType();
1838 if (IsDateTimeInput(new_type))
1839 return; // Not considered as a text input field in WebKit/Chromium.
1840
1841 bool new_can_compose_inline = CanComposeInline();
1842
1843 blink::WebTextInputInfo new_info;
1844 if (webwidget_)
1845 new_info = webwidget_->textInputInfo();
1846 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201847 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571848
1849 if (text_input_type_ != new_type
1850 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201851 || text_input_mode_ != new_mode
1852 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571853 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1854 new_type,
1855 new_mode,
shuchen82ce8c52014-10-23 01:55:201856 new_can_compose_inline,
1857 new_flags));
shuchen3517bb62014-10-15 03:55:571858 text_input_type_ = new_type;
1859 can_compose_inline_ = new_can_compose_inline;
1860 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201861 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571862 }
1863}
1864
1865#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361866void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1867 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501868 if (handling_ime_event_)
1869 return;
[email protected]90f24152014-04-09 12:41:361870 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291871 return;
[email protected]ad26ef42011-06-17 07:59:451872 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271873 if (IsDateTimeInput(new_type))
1874 return; // Not considered as a text input field in WebKit/Chromium.
1875
[email protected]180ef242013-11-07 06:50:461876 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211877 if (webwidget_)
1878 new_info = webwidget_->textInputInfo();
1879
[email protected]ad26ef42011-06-17 07:59:451880 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211881
[email protected]3306f262012-09-21 19:20:421882 // Only sends text input params if they are changed or if the ime should be
1883 // shown.
[email protected]90f24152014-04-09 12:41:361884 if (show_ime == SHOW_IME_IF_NEEDED ||
1885 (text_input_type_ != new_type ||
1886 text_input_info_ != new_info ||
1887 can_compose_inline_ != new_can_compose_inline)
1888#if defined(OS_ANDROID)
1889 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021890#endif
[email protected]90f24152014-04-09 12:41:361891 ) {
1892 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211893 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401894 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211895 p.value = new_info.value.utf8();
1896 p.selection_start = new_info.selectionStart;
1897 p.selection_end = new_info.selectionEnd;
1898 p.composition_start = new_info.compositionStart;
1899 p.composition_end = new_info.compositionEnd;
1900 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361901 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1902#if defined(USE_AURA)
1903 p.is_non_ime_change = true;
1904#endif
[email protected]183e28d2014-01-20 18:18:021905#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361906 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1907 text_field_is_dirty_;
1908 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131909 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361910 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021911#endif
shuchen3517bb62014-10-15 03:55:571912#if defined(USE_AURA)
1913 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1914 new_type,
1915 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201916 new_can_compose_inline,
1917 new_info.flags));
shuchen3517bb62014-10-15 03:55:571918#endif
[email protected]5b739cb2012-08-21 20:35:211919 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1920
1921 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041922 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451923 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201924 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291925 }
initial.commit09911bf2008-07-26 23:55:291926}
shuchen3517bb62014-10-15 03:55:571927#endif
initial.commit09911bf2008-07-26 23:55:291928
[email protected]7c8873e2013-02-05 08:03:011929void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1930 WebRect focus_webrect;
1931 WebRect anchor_webrect;
1932 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1933 *focus = focus_webrect;
1934 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321935}
1936
[email protected]e99ef6f2011-10-16 01:13:001937void RenderWidget::UpdateSelectionBounds() {
1938 if (!webwidget_)
1939 return;
[email protected]66fca5bc2013-05-23 06:58:291940 if (handling_ime_event_)
1941 return;
[email protected]e99ef6f2011-10-16 01:13:001942
jddukeacf809e2014-09-23 20:38:381943 // With composited selection updates, the selection bounds will be reported
1944 // directly by the compositor, in which case explicit IPC selection
1945 // notifications should be suppressed.
1946 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
1947 ViewHostMsg_SelectionBounds_Params params;
1948 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1949 if (selection_anchor_rect_ != params.anchor_rect ||
1950 selection_focus_rect_ != params.focus_rect) {
1951 selection_anchor_rect_ = params.anchor_rect;
1952 selection_focus_rect_ = params.focus_rect;
1953 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1954 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1955 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1956 }
[email protected]58b48a0d2012-06-13 07:01:351957 }
jddukeacf809e2014-09-23 20:38:381958
[email protected]88dbe32f2013-06-20 23:31:361959 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001960}
1961
[email protected]180ef242013-11-07 06:50:461962// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1963COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \
[email protected]ad26ef42011-06-17 07:59:451964 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461965COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \
[email protected]ad26ef42011-06-17 07:59:451966 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461967COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \
[email protected]ad26ef42011-06-17 07:59:451968 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461969COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \
[email protected]caf38ed2011-07-28 13:15:181970 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461971COMPILE_ASSERT(int(blink::WebTextInputTypeEmail) == \
[email protected]caf38ed2011-07-28 13:15:181972 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461973COMPILE_ASSERT(int(blink::WebTextInputTypeNumber) == \
[email protected]caf38ed2011-07-28 13:15:181974 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461975COMPILE_ASSERT(int(blink::WebTextInputTypeTelephone) == \
[email protected]caf38ed2011-07-28 13:15:181976 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461977COMPILE_ASSERT(int(blink::WebTextInputTypeURL) == \
[email protected]caf38ed2011-07-28 13:15:181978 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461979COMPILE_ASSERT(int(blink::WebTextInputTypeDate) == \
[email protected]feb8cf752012-06-08 04:48:001980 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461981COMPILE_ASSERT(int(blink::WebTextInputTypeDateTime) == \
[email protected]feb8cf752012-06-08 04:48:001982 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461983COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeLocal) == \
[email protected]feb8cf752012-06-08 04:48:001984 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461985COMPILE_ASSERT(int(blink::WebTextInputTypeMonth) == \
[email protected]feb8cf752012-06-08 04:48:001986 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461987COMPILE_ASSERT(int(blink::WebTextInputTypeTime) == \
[email protected]feb8cf752012-06-08 04:48:001988 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461989COMPILE_ASSERT(int(blink::WebTextInputTypeWeek) == \
[email protected]feb8cf752012-06-08 04:48:001990 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461991COMPILE_ASSERT(int(blink::WebTextInputTypeTextArea) == \
[email protected]2a9893672012-11-09 20:33:011992 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461993COMPILE_ASSERT(int(blink::WebTextInputTypeContentEditable) == \
[email protected]2a9893672012-11-09 20:33:011994 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461995COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeField) == \
[email protected]8b4992e2013-03-01 15:42:151996 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:451997
[email protected]5b739cb2012-08-21 20:35:211998ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:461999 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212000 // Check the type is in the range representable by ui::TextInputType.
2001 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462002 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212003 return static_cast<ui::TextInputType>(type);
2004}
2005
[email protected]ad26ef42011-06-17 07:59:452006ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272007 if (webwidget_)
2008 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452009 return ui::TEXT_INPUT_TYPE_NONE;
2010}
2011
[email protected]501ea13d2013-07-09 17:03:292012void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302013#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112014 // TODO(yukawa): Start sending character bounds when the browser side
2015 // implementation becomes ready (crbug.com/424866).
2016#else
[email protected]db4fc1e2013-09-06 20:01:512017 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292018 if (should_update_range) {
2019 GetCompositionRange(&range);
2020 } else {
2021 range = composition_range_;
2022 }
2023 std::vector<gfx::Rect> character_bounds;
2024 GetCompositionCharacterBounds(&character_bounds);
2025
2026 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2027 return;
2028 composition_character_bounds_ = character_bounds;
2029 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222030 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292031 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112032#endif
[email protected]501ea13d2013-07-09 17:03:292033}
2034
[email protected]58b48a0d2012-06-13 07:01:352035void RenderWidget::GetCompositionCharacterBounds(
2036 std::vector<gfx::Rect>* bounds) {
2037 DCHECK(bounds);
2038 bounds->clear();
2039}
2040
[email protected]db4fc1e2013-09-06 20:01:512041void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362042 size_t location, length;
2043 if (webwidget_->compositionRange(&location, &length)) {
2044 range->set_start(location);
2045 range->set_end(location + length);
2046 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2047 range->set_start(location);
2048 range->set_end(location + length);
2049 } else {
[email protected]db4fc1e2013-09-06 20:01:512050 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362051 }
2052}
2053
[email protected]501ea13d2013-07-09 17:03:292054bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512055 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292056 const std::vector<gfx::Rect>& bounds) {
2057 if (composition_range_ != range)
2058 return true;
2059 if (bounds.size() != composition_character_bounds_.size())
2060 return true;
2061 for (size_t i = 0; i < bounds.size(); ++i) {
2062 if (bounds[i] != composition_character_bounds_[i])
2063 return true;
2064 }
2065 return false;
2066}
[email protected]501ea13d2013-07-09 17:03:292067
[email protected]a4f0d882014-05-01 23:48:102068#if defined(OS_ANDROID)
2069void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2070 // If not initialized, default to white. Note that 0 is different from black
2071 // as black still has alpha 0xFF.
2072 if (!bg_color)
2073 bg_color = SK_ColorWHITE;
2074
2075 if (bg_color != body_background_color_) {
2076 body_background_color_ = bg_color;
2077 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2078 }
2079}
timav7a5032e2014-12-05 01:59:432080
2081bool RenderWidget::DoesRecordFullLayer() const {
2082 SynchronousCompositorFactory* synchronous_compositor_factory =
2083 SynchronousCompositorFactory::GetInstance();
2084
2085 // We assume that the absence of synchronous_compositor_factory
2086 // means we are in Chrome. In chrome, we want to clip, i.e.
2087 // *not* to record the full layer.
2088 if (!synchronous_compositor_factory)
2089 return false;
2090
2091 return synchronous_compositor_factory->RecordFullLayer();
2092}
[email protected]a4f0d882014-05-01 23:48:102093#endif
2094
[email protected]ad26ef42011-06-17 07:59:452095bool RenderWidget::CanComposeInline() {
2096 return true;
[email protected]56ea1a62011-05-30 07:05:572097}
2098
[email protected]4873c7d2009-07-16 06:36:282099WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042100 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282101}
2102
[email protected]f660d9c2012-06-06 18:31:212103float RenderWidget::deviceScaleFactor() {
2104 return device_scale_factor_;
2105}
2106
[email protected]fa7b1dc2010-06-23 17:53:042107void RenderWidget::resetInputMethod() {
2108 if (!input_method_is_active_)
2109 return;
2110
[email protected]0e45bd02013-07-12 20:20:022111 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042112 // If the last text input type is not None, then we should finish any
2113 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452114 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042115 // If a composition text exists, then we need to let the browser process
2116 // to cancel the input method's ongoing composition session.
2117 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222118 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042119 }
[email protected]d4cff272011-05-02 15:46:012120
[email protected]88dbe32f2013-06-20 23:31:362121 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042122}
2123
[email protected]c68c3e4e2013-01-24 00:36:562124void RenderWidget::didHandleGestureEvent(
2125 const WebGestureEvent& event,
2126 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022127#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562128 if (event_cancelled)
2129 return;
[email protected]07c70d22014-08-21 08:33:462130 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362131 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462132 } else if (event.type == WebInputEvent::GestureLongPress) {
2133 DCHECK(webwidget_);
2134 if (webwidget_->textInputInfo().value.isEmpty())
2135 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2136 else
2137 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562138 }
2139#endif
2140}
2141
[email protected]7912e822014-04-16 02:37:032142void RenderWidget::StartCompositor() {
2143 // For widgets that are never visible, we don't need the compositor to run
2144 // at all.
2145 if (never_visible_)
2146 return;
danakj6e3bf8012014-12-16 18:27:532147 // In tests without a RenderThreadImpl, don't set ready as this kicks
2148 // off creating output surfaces that the test can't create.
2149 if (!RenderThreadImpl::current())
2150 return;
danakj018271e32014-12-16 21:17:262151 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032152}
2153
[email protected]29e2fb42013-07-19 01:13:472154void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292155 size_t i = 0;
2156 for (; i < plugin_window_moves_.size(); ++i) {
2157 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582158 if (move.rects_valid) {
2159 plugin_window_moves_[i] = move;
2160 } else {
2161 plugin_window_moves_[i].visible = move.visible;
2162 }
initial.commit09911bf2008-07-26 23:55:292163 break;
2164 }
2165 }
2166
2167 if (i == plugin_window_moves_.size())
2168 plugin_window_moves_.push_back(move);
2169}
[email protected]268654772009-08-06 23:02:042170
2171void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2172 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2173 i != plugin_window_moves_.end(); ++i) {
2174 if (i->window == window) {
2175 plugin_window_moves_.erase(i);
2176 break;
2177 }
2178 }
2179}
[email protected]67bfb83f2011-09-22 03:36:372180
[email protected]63b465922012-09-06 02:04:522181
[email protected]24ed0432013-04-24 07:50:312182RenderWidgetCompositor* RenderWidget::compositor() const {
2183 return compositor_.get();
2184}
2185
[email protected]180ef242013-11-07 06:50:462186bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372187 return false;
2188}
[email protected]c3d45532011-10-07 19:20:402189
[email protected]41d86852012-11-07 12:23:242190bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462191 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242192 return false;
2193}
2194
[email protected]ce6689f2013-03-29 12:52:552195void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2196 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2197}
2198
[email protected]5d0bbdfa92013-12-10 00:35:512199void RenderWidget::setTouchAction(
2200 blink::WebTouchAction web_touch_action) {
2201
2202 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2203 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192204 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512205 return;
2206
[email protected]a18f67a2013-12-20 19:44:362207 // Verify the same values are used by the types so we can cast between them.
2208 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) ==
2209 blink::WebTouchActionAuto,
2210 enum_values_must_match_for_touch_action);
2211 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) ==
2212 blink::WebTouchActionNone,
2213 enum_values_must_match_for_touch_action);
2214 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) ==
2215 blink::WebTouchActionPanX,
2216 enum_values_must_match_for_touch_action);
2217 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_Y) ==
2218 blink::WebTouchActionPanY,
2219 enum_values_must_match_for_touch_action);
[email protected]2bd73272014-03-13 19:36:112220 COMPILE_ASSERT(
2221 static_cast<blink::WebTouchAction>(TOUCH_ACTION_PINCH_ZOOM) ==
2222 blink::WebTouchActionPinchZoom,
2223 enum_values_must_match_for_touch_action);
[email protected]a18f67a2013-12-20 19:44:362224
2225 content::TouchAction content_touch_action =
2226 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512227 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2228}
2229
[email protected]90f24152014-04-09 12:41:362230void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2231#if defined(OS_ANDROID)
2232 text_field_is_dirty_ = true;
2233#endif
2234}
2235
[email protected]3d5c243b2012-11-30 00:26:012236bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2237 return true;
2238}
2239
[email protected]0634cdd42013-08-16 00:46:092240scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132241RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592242 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092243 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ebc0e1df2013-08-01 02:46:222244 if (CommandLine::ForCurrentProcess()->HasSwitch(
2245 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092246 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292247 if (!RenderThreadImpl::current())
2248 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402249 CauseForGpuLaunch cause =
2250 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292251 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402252 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222253 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292254 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592255
[email protected]828a3932014-04-02 14:43:132256 // Explicitly disable antialiasing for the compositor. As of the time of
2257 // this writing, the only platform that supported antialiasing for the
2258 // compositor was Mac OS X, because the on-screen OpenGL context creation
2259 // code paths on Windows and Linux didn't yet have multisampling support.
2260 // Mac OS X essentially always behaves as though it's rendering offscreen.
2261 // Multisampling has a heavy cost especially on devices with relatively low
2262 // fill rate like most notebooks, and the Mac implementation would need to
2263 // be optimized to resolve directly into the IOSurface shared between the
2264 // GPU and browser processes. For these reasons and to avoid platform
2265 // disparities we explicitly disable antialiasing.
2266 blink::WebGraphicsContext3D::Attributes attributes;
2267 attributes.antialias = false;
2268 attributes.shareResources = true;
2269 attributes.noAutomaticFlushes = true;
2270 attributes.depth = false;
2271 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132272 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292273 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012274#if defined(OS_ANDROID)
2275 // If we raster too fast we become upload bound, and pending
2276 // uploads consume memory. For maximum upload throughput, we would
2277 // want to allow for upload_throughput * pipeline_time of pending
2278 // uploads, after which we are just wasting memory. Since we don't
2279 // know our upload throughput yet, this just caps our memory usage.
2280 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272281 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032282 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012283 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032284 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012285 // Deadline to draw a frame to achieve 60 frames per second.
2286 const size_t kMillisecondsPerFrame = 16;
2287 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032288 size_t max_transfer_buffer_usage_mb =
2289 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2290 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012291 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2292 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292293 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032294 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012295#endif
[email protected]96ab016c2013-10-23 00:50:292296
[email protected]96ab016c2013-10-23 00:50:292297 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132298 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2299 GetURLForGraphicsContext3D(),
2300 gpu_channel_host.get(),
2301 attributes,
[email protected]828a3932014-04-02 14:43:132302 lose_context_when_out_of_memory,
2303 limits,
2304 NULL));
[email protected]0634cdd42013-08-16 00:46:092305 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592306}
2307
[email protected]e3244ed2014-06-20 20:04:272308void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2309 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162310}
2311
[email protected]e3244ed2014-06-20 20:04:272312void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2313 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162314}
2315
[email protected]de3c5d82014-05-28 22:12:592316void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2317 render_frames_.AddObserver(frame);
2318}
2319
2320void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2321 render_frames_.RemoveObserver(frame);
2322}
2323
[email protected]a017938b2014-05-27 21:17:172324#if defined(VIDEO_HOLE)
2325void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2326 video_hole_frames_.AddObserver(frame);
2327}
2328
2329void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2330 video_hole_frames_.RemoveObserver(frame);
2331}
2332#endif // defined(VIDEO_HOLE)
2333
[email protected]e9ff79c2012-10-19 21:31:262334} // namespace content