blob: 791943acaa955fb56bec231f3b6276f05bb572f6 [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
ccamerond4ba47902014-12-17 07:20:311158 // Send mouse wheel events and their disposition to the compositor thread, so
1159 // that they can be used to produce the elastic overscroll effect on Mac.
1160 if (input_event->type == WebInputEvent::MouseWheel) {
1161 ObserveWheelEventOnAndResult(
1162 static_cast<const WebMouseWheelEvent&>(*input_event), processed);
1163 }
1164
[email protected]721e2302014-04-30 23:42:011165 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061166
[email protected]fd847792013-10-24 17:12:351167 // If we don't have a fast and accurate HighResNow, we assume the input
1168 // handlers are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301169 bool rate_limiting_wanted =
1170 input_event->type == WebInputEvent::MouseMove ||
1171 input_event->type == WebInputEvent::MouseWheel;
1172 if (rate_limiting_wanted && !start_time.is_null()) {
[email protected]fd847792013-10-24 17:12:351173 base::TimeTicks end_time = base::TimeTicks::HighResNow();
1174 total_input_handling_time_this_frame_ += (end_time - start_time);
1175 rate_limiting_wanted =
1176 total_input_handling_time_this_frame_.InMicroseconds() >
1177 kInputHandlingTimeThrottlingThresholdMicroseconds;
1178 }
1179
[email protected]7f19e9d2014-05-09 15:16:291180 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1181
[email protected]c27dd4f2014-05-22 18:05:191182 // Note that we can't use handling_event_type_ here since it will be overriden
1183 // by reentrant calls for events after the paused one.
1184 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1185 input_event->type == WebInputEvent::MouseMove;
1186 if (!WebInputEventTraits::IgnoresAckDisposition(*input_event) && !no_ack) {
[email protected]8e431f2032014-05-20 02:34:561187 InputHostMsg_HandleInputEvent_ACK_Params ack;
1188 ack.type = input_event->type;
1189 ack.state = ack_result;
1190 ack.latency = swap_latency_info;
[email protected]34afe102013-12-13 17:24:551191 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561192 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301193 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551194 // We want to rate limit the input events in this case, so we'll wait for
1195 // painting to finish before ACKing this message.
1196 TRACE_EVENT_INSTANT0("renderer",
1197 "RenderWidget::OnHandleInputEvent ack throttled",
1198 TRACE_EVENT_SCOPE_THREAD);
1199 if (pending_input_event_ack_) {
1200 // As two different kinds of events could cause us to postpone an ack
1201 // we send it now, if we have one pending. The Browser should never
1202 // send us the same kind of event we are delaying the ack for.
1203 Send(pending_input_event_ack_.release());
1204 }
1205 pending_input_event_ack_ = response.Pass();
1206 if (compositor_)
1207 compositor_->NotifyInputThrottledUntilCommit();
1208 } else {
1209 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171210 }
[email protected]12fbad812009-09-01 18:21:241211 }
[email protected]5fea4a52014-05-27 00:17:521212 if (input_event->type == WebInputEvent::MouseMove)
1213 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241214
[email protected]3306f262012-09-21 19:20:421215#if defined(OS_ANDROID)
1216 // Allow the IME to be shown when the focus changes as a consequence
1217 // of a processed touch end event.
1218 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361219 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021220#elif defined(USE_AURA)
1221 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1222 // change.
1223 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1224 input_event->type == WebInputEvent::MouseUp))
[email protected]90f24152014-04-09 12:41:361225 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
[email protected]3306f262012-09-21 19:20:421226#endif
1227
[email protected]67bfb83f2011-09-22 03:36:371228 if (!prevent_default) {
1229 if (WebInputEvent::isKeyboardEventType(input_event->type))
1230 DidHandleKeyEvent();
1231 if (WebInputEvent::isMouseEventType(input_event->type))
1232 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241233 if (WebInputEvent::isTouchEventType(input_event->type))
1234 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371235 }
initial.commit09911bf2008-07-26 23:55:291236}
1237
[email protected]34202de2013-05-06 23:36:221238void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1239 if (webwidget_)
1240 webwidget_->setCursorVisibilityState(is_visible);
1241}
1242
initial.commit09911bf2008-07-26 23:55:291243void RenderWidget::OnMouseCaptureLost() {
1244 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281245 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291246}
1247
1248void RenderWidget::OnSetFocus(bool enable) {
1249 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331250 if (webwidget_)
1251 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291252}
1253
1254void RenderWidget::ClearFocus() {
1255 // We may have got the focus from the browser before this gets processed, in
1256 // which case we do not want to unfocus ourself.
1257 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281258 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291259}
1260
[email protected]fd847792013-10-24 17:12:351261void RenderWidget::FlushPendingInputEventAck() {
[email protected]d8a8ecb2013-10-23 18:03:071262 if (pending_input_event_ack_)
1263 Send(pending_input_event_ack_.release());
[email protected]fd847792013-10-24 17:12:351264 total_input_handling_time_this_frame_ = base::TimeDelta();
1265}
1266
initial.commit09911bf2008-07-26 23:55:291267///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461268// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291269
[email protected]244ac1892011-12-02 17:04:471270void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091271 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451272 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581273
[email protected]5b45ad42013-10-25 00:42:041274 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451275 WebRect new_pos(rootWindowRect().x,
1276 rootWindowRect().y,
1277 new_size.width,
1278 new_size.height);
1279 view_screen_rect_ = new_pos;
1280 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031281 }
[email protected]20fbfc22013-05-08 20:50:581282
[email protected]eac2b362013-05-22 07:01:451283 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581284
[email protected]5b45ad42013-10-25 00:42:041285 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581286 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091287 }
[email protected]244ac1892011-12-02 17:04:471288}
1289
[email protected]3a1c8a8032013-03-18 22:35:321290void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051291 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1292 device_scale_factor_));
1293 if (compositor_)
1294 compositor_->setViewportSize(size_, physical_backing_size_);
1295}
1296
[email protected]e195e582013-03-08 01:32:591297void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221298 DCHECK(!host_closing_);
1299
danakj6e3bf8012014-12-16 18:27:531300 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591301 compositor_->setViewportSize(size_, physical_backing_size_);
1302 if (init_complete_)
[email protected]7912e822014-04-16 02:37:031303 StartCompositor();
[email protected]e195e582013-03-08 01:32:591304}
1305
ennef3c58142014-12-09 21:44:381306void RenderWidget::WillCloseLayerTreeView() {
1307 if (host_closing_)
1308 return;
1309
1310 // Prevent new compositors or output surfaces from being created.
1311 host_closing_ = true;
1312
[email protected]aeeedad2014-08-22 18:16:221313 // Always send this notification to prevent new layer tree views from
1314 // being created, even if one hasn't been created yet.
1315 if (webwidget_)
1316 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221317}
1318
[email protected]180ef242013-11-07 06:50:461319blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281320 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061321}
1322
[email protected]9cd43a62012-03-26 08:03:561323void RenderWidget::willBeginCompositorFrame() {
1324 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371325
[email protected]abe8b3a2012-03-28 21:19:371326 // The following two can result in further layout and possibly
1327 // enable GPU acceleration so they need to be called before any painting
1328 // is done.
shuchen3517bb62014-10-15 03:55:571329 UpdateTextInputType();
1330#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361331 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
shuchen3517bb62014-10-15 03:55:571332#endif
[email protected]abe8b3a2012-03-28 21:19:371333 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561334}
1335
[email protected]3391a0772012-03-28 00:32:071336void RenderWidget::didBecomeReadyForAdditionalInput() {
1337 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]fd847792013-10-24 17:12:351338 FlushPendingInputEventAck();
[email protected]3391a0772012-03-28 00:32:071339}
1340
[email protected]6fceb912013-02-15 06:24:151341void RenderWidget::DidCommitCompositorFrame() {
[email protected]e3244ed2014-06-20 20:04:271342 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161343 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171344#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271345 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1346 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171347#endif // defined(VIDEO_HOLE)
[email protected]6fceb912013-02-15 06:24:151348}
1349
[email protected]586871b2014-07-22 17:05:111350// static
1351scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1352 IPC::Message* msg,
1353 MessageDeliveryPolicy policy,
1354 FrameSwapMessageQueue* frame_swap_message_queue,
1355 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1356 bool commit_requested,
1357 int source_frame_number) {
1358 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1359 // No need for lock: this gets changed only on this thread.
1360 !commit_requested &&
1361 // No need for lock: Messages are only enqueued from this thread, if we
1362 // don't have any now, no other thread will add any.
1363 frame_swap_message_queue->Empty()) {
1364 sync_message_filter->Send(msg);
dcheng4b6b5ff2014-10-16 00:42:061365 return nullptr;
[email protected]586871b2014-07-22 17:05:111366 }
1367
1368 bool first_message_for_frame = false;
1369 frame_swap_message_queue->QueueMessageForFrame(policy,
1370 source_frame_number,
1371 make_scoped_ptr(msg),
1372 &first_message_for_frame);
1373 if (first_message_for_frame) {
1374 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1375 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061376 return promise;
[email protected]586871b2014-07-22 17:05:111377 }
dcheng4b6b5ff2014-10-16 00:42:061378 return nullptr;
[email protected]586871b2014-07-22 17:05:111379}
1380
1381void RenderWidget::QueueMessage(IPC::Message* msg,
1382 MessageDeliveryPolicy policy) {
1383 // RenderThreadImpl::current() is NULL in some tests.
1384 if (!compositor_ || !RenderThreadImpl::current()) {
1385 Send(msg);
1386 return;
1387 }
1388
1389 scoped_ptr<cc::SwapPromise> swap_promise =
1390 QueueMessageImpl(msg,
1391 policy,
dcheng58867a92014-08-26 02:50:221392 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111393 RenderThreadImpl::current()->sync_message_filter(),
1394 compositor_->commitRequested(),
1395 compositor_->GetSourceFrameNumber());
1396
1397 if (swap_promise) {
1398 compositor_->QueueSwapPromise(swap_promise.Pass());
1399 compositor_->SetNeedsCommit();
1400 }
1401}
1402
[email protected]58264a32011-11-17 23:36:151403void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]5889c10d2014-06-11 01:42:101404 // NOTE: Tests may break if this event is renamed or moved. See
1405 // tab_capture_performancetest.cc.
[email protected]b5db7eb2011-11-29 09:11:501406 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]29ed96a2012-02-04 18:12:161407 // Notify subclasses that we initiated the paint operation.
1408 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151409}
1410
1411void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181412 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1413
1414 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561415 DidFlushPaint();
1416
[email protected]ea3ee0a2012-05-15 03:43:091417 if (!next_paint_flags_ &&
1418 !need_update_rect_for_auto_resize_ &&
1419 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151420 return;
[email protected]ea3ee0a2012-05-15 03:43:091421 }
[email protected]58264a32011-11-17 23:36:151422
1423 ViewHostMsg_UpdateRect_Params params;
1424 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151425 params.plugin_window_moves.swap(plugin_window_moves_);
1426 params.flags = next_paint_flags_;
[email protected]58264a32011-11-17 23:36:151427
1428 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1429 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091430 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151431}
1432
[email protected]8b9e52b2014-01-17 16:35:311433void RenderWidget::scheduleComposite() {
danakj6e3bf8012014-12-16 18:27:531434 if (compositor_ &&
1435 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
[email protected]e221f9f2014-05-13 02:47:221436 compositor_->setNeedsAnimate();
[email protected]8b9e52b2014-01-17 16:35:311437 }
1438}
1439
[email protected]4873c7d2009-07-16 06:36:281440void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301441 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521442 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401443 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291444 // Only send a SetCursor message if we need to make a change.
1445 if (!current_cursor_.IsEqual(cursor)) {
1446 current_cursor_ = cursor;
1447 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1448 }
1449}
1450
1451// We are supposed to get a single call to Show for a newly created RenderWidget
1452// that was created via RenderWidget::CreateWebView. So, we wait until this
1453// point to dispatch the ShowWidget message.
1454//
1455// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281456// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291457//
[email protected]4873c7d2009-07-16 06:36:281458void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291459 DCHECK(!did_show_) << "received extraneous Show call";
1460 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1461 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1462
[email protected]8de12d942010-11-17 20:42:441463 if (did_show_)
1464 return;
1465
1466 did_show_ = true;
1467 // NOTE: initial_pos_ may still have its default values at this point, but
1468 // that's okay. It'll be ignored if as_popup is false, or the browser
1469 // process will impose a default position otherwise.
1470 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1471 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291472}
1473
[email protected]4873c7d2009-07-16 06:36:281474void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291475}
1476
[email protected]4873c7d2009-07-16 06:36:281477void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291478}
1479
[email protected]2533ce12009-05-09 00:02:241480void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381481 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241482 Send(new ViewHostMsg_Close(routing_id_));
1483}
1484
[email protected]4873c7d2009-07-16 06:36:281485void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321486 if (is_swapped_out_) {
1487 // This widget is currently swapped out, and the active widget is in a
1488 // different process. Have the browser route the close request to the
1489 // active widget instead, so that the correct unload handlers are run.
1490 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1491 return;
1492 }
1493
initial.commit09911bf2008-07-26 23:55:291494 // If a page calls window.close() twice, we'll end up here twice, but that's
1495 // OK. It is safe to send multiple Close messages.
1496
[email protected]2533ce12009-05-09 00:02:241497 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1498 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1499 // could be closed before the JS finishes executing. So instead, post a
1500 // message back to the message loop, which won't run until the JS is
1501 // complete, and then the Close message can be sent.
ennef3c58142014-12-09 21:44:381502 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211503 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291504}
1505
[email protected]9017d7852013-11-21 17:47:351506void RenderWidget::QueueSyntheticGesture(
1507 scoped_ptr<SyntheticGestureParams> gesture_params,
1508 const SyntheticGestureCompletionCallback& callback) {
1509 DCHECK(!callback.is_null());
1510
1511 pending_synthetic_gesture_callbacks_.push(callback);
1512
1513 SyntheticGesturePacket gesture_packet;
1514 gesture_packet.set_gesture_params(gesture_params.Pass());
1515
1516 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1517}
1518
initial.commit09911bf2008-07-26 23:55:291519void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031520 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381521 WillCloseLayerTreeView();
1522 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291523 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281524 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291525 webwidget_ = NULL;
1526 }
1527}
1528
[email protected]4873c7d2009-07-16 06:36:281529WebRect RenderWidget::windowRect() {
1530 if (pending_window_rect_count_)
1531 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241532
[email protected]80ad8622012-11-07 16:33:031533 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291534}
1535
[email protected]180ef242013-11-07 06:50:461536void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301537 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541538 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301539}
1540
[email protected]b2e4c70132013-10-03 02:07:511541void RenderWidget::setWindowRect(const WebRect& rect) {
1542 WebRect pos = rect;
1543 if (popup_origin_scale_for_emulation_) {
1544 float scale = popup_origin_scale_for_emulation_;
1545 pos.x = popup_screen_origin_for_emulation_.x() +
1546 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1547 pos.y = popup_screen_origin_for_emulation_.y() +
1548 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1549 }
1550
[email protected]5b45ad42013-10-25 00:42:041551 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201552 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031553 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1554 SetPendingWindowRect(pos);
1555 } else {
[email protected]ec951b9d2013-10-20 06:21:201556 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031557 }
initial.commit09911bf2008-07-26 23:55:291558 } else {
bokanf0fd2412014-10-30 15:28:551559 ResizeSynchronously(pos, visible_viewport_size_);
initial.commit09911bf2008-07-26 23:55:291560 }
1561}
1562
[email protected]2533ce12009-05-09 00:02:241563void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1564 pending_window_rect_ = rect;
1565 pending_window_rect_count_++;
1566}
1567
[email protected]4873c7d2009-07-16 06:36:281568WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241569 if (pending_window_rect_count_) {
1570 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1571 // the RootWindowRect is probably going to return wrong results since the
1572 // browser may not have processed the Move yet. There isn't really anything
1573 // good to do in this case, and it shouldn't happen - since this size is
1574 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281575 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241576 }
1577
[email protected]80ad8622012-11-07 16:33:031578 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371579}
1580
[email protected]4873c7d2009-07-16 06:36:281581WebRect RenderWidget::windowResizerRect() {
1582 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191583}
1584
[email protected]fa7b1dc2010-06-23 17:53:041585void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031586 // To prevent this renderer process from sending unnecessary IPC messages to
1587 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041588 // only during the input method attached to the browser process is active.
1589 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291590}
1591
[email protected]37a241c2013-12-03 03:16:171592void RenderWidget::OnCandidateWindowShown() {
1593 webwidget_->didShowCandidateWindow();
1594}
1595
1596void RenderWidget::OnCandidateWindowUpdated() {
1597 webwidget_->didUpdateCandidateWindow();
1598}
1599
1600void RenderWidget::OnCandidateWindowHidden() {
1601 webwidget_->didHideCandidateWindow();
1602}
1603
[email protected]fa7b1dc2010-06-23 17:53:041604void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261605 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041606 const std::vector<WebCompositionUnderline>& underlines,
1607 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131608 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281609 return;
[email protected]66fca5bc2013-05-23 06:58:291610 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361611 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041612 text, WebVector<WebCompositionUnderline>(underlines),
1613 selection_start, selection_end)) {
1614 // If we failed to set the composition text, then we need to let the browser
1615 // process to cancel the input method's ongoing composition session, to make
1616 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221617 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261618 }
[email protected]88dbe32f2013-06-20 23:31:361619 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041620}
1621
[email protected]fcf75d42013-12-03 20:11:261622void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511623 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021624 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131625 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041626 return;
[email protected]66fca5bc2013-05-23 06:58:291627 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041628 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021629 if (text.length())
1630 webwidget_->confirmComposition(text);
1631 else if (keep_selection)
1632 webwidget_->confirmComposition(WebWidget::KeepSelection);
1633 else
1634 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041635 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361636 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291637}
1638
[email protected]0bc1f572013-04-17 01:46:311639void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121640 // During shutdown we can just ignore this message.
1641 if (!webwidget_)
1642 return;
1643
[email protected]0bc1f572013-04-17 01:46:311644 // Even if the browser provides an empty damage rect, it's still expecting to
1645 // receive a repaint ack so just damage the entire widget bounds.
1646 if (size_to_paint.IsEmpty()) {
1647 size_to_paint = size_;
1648 }
1649
[email protected]ec7dc112008-08-06 05:30:121650 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051651 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311652 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121653}
1654
[email protected]79fa22e2013-08-23 15:18:121655void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351656 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1657
1658 pending_synthetic_gesture_callbacks_.front().Run();
1659 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271660}
1661
[email protected]4873c7d2009-07-16 06:36:281662void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111663 if (!webwidget_)
1664 return;
[email protected]4873c7d2009-07-16 06:36:281665 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111666}
1667
[email protected]80ad8622012-11-07 16:33:031668void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1669 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511670 if (screen_metrics_emulator_) {
1671 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1672 view_screen_rect, window_screen_rect);
1673 } else {
1674 view_screen_rect_ = view_screen_rect;
1675 window_screen_rect_ = window_screen_rect;
1676 }
[email protected]80ad8622012-11-07 16:33:031677 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1678}
1679
[email protected]adb362312014-06-28 06:04:241680void RenderWidget::showImeIfNeeded() {
1681 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131682}
1683
[email protected]adb362312014-06-28 06:04:241684void RenderWidget::OnShowImeIfNeeded() {
1685#if defined(OS_ANDROID) || defined(USE_AURA)
1686 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1687#endif
1688}
1689
1690#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131691void RenderWidget::IncrementOutstandingImeEventAcks() {
1692 ++outstanding_ime_acks_;
1693}
1694
1695void RenderWidget::OnImeEventAck() {
1696 --outstanding_ime_acks_;
1697 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:511698}
[email protected]105dffb42013-02-20 03:46:211699#endif
1700
[email protected]0d1ebed12013-08-05 22:01:131701bool RenderWidget::ShouldHandleImeEvent() {
1702#if defined(OS_ANDROID)
1703 return !!webwidget_ && outstanding_ime_acks_ == 0;
1704#else
1705 return !!webwidget_;
1706#endif
1707}
1708
[email protected]c27dd4f2014-05-22 18:05:191709bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1710 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521711 // If we pause multiple times during a single mouse move event, we should
1712 // only send ACK once.
1713 if (!ignore_ack_for_mouse_move_from_debugger_) {
1714 InputHostMsg_HandleInputEvent_ACK_Params ack;
1715 ack.type = handling_event_type_;
1716 ack.state = INPUT_EVENT_ACK_STATE_CONSUMED;
1717 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
1718 }
[email protected]c27dd4f2014-05-22 18:05:191719 return true;
1720 }
1721 return false;
1722}
1723
1724void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1725 ignore_ack_for_mouse_move_from_debugger_ = true;
1726}
1727
[email protected]468ac582012-11-20 00:53:191728void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1729 if (device_scale_factor_ == device_scale_factor)
1730 return;
1731
1732 device_scale_factor_ = device_scale_factor;
[email protected]aca33f4f2014-05-17 17:08:051733 scheduleComposite();
[email protected]468ac582012-11-20 00:53:191734}
1735
[email protected]28ed6b32014-06-08 02:16:271736bool RenderWidget::SetDeviceColorProfile(
1737 const std::vector<char>& color_profile) {
1738 if (device_color_profile_ == color_profile)
1739 return false;
1740
1741 device_color_profile_ = color_profile;
1742 return true;
1743}
1744
noeldb4df152014-09-16 17:45:201745void RenderWidget::ResetDeviceColorProfileForTesting() {
1746 if (!device_color_profile_.empty())
1747 device_color_profile_.clear();
1748 device_color_profile_.push_back('0');
1749}
1750
[email protected]fcdc5642014-05-09 14:32:241751void RenderWidget::OnOrientationChange() {
1752}
1753
[email protected]ceb36f7d2012-10-31 18:33:241754gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521755 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241756 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521757}
1758
[email protected]bee16aab2009-08-26 15:55:031759void RenderWidget::SetHidden(bool hidden) {
1760 if (is_hidden_ == hidden)
1761 return;
1762
1763 // The status has changed. Tell the RenderThread about it.
1764 is_hidden_ = hidden;
1765 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001766 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031767 else
[email protected]b2db9272014-01-10 17:42:001768 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031769}
1770
[email protected]2b624c562011-10-27 22:58:261771void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261772 if (!webwidget_)
1773 return;
1774
1775 if (is_fullscreen_) {
1776 webwidget_->willExitFullScreen();
1777 } else {
1778 webwidget_->willEnterFullScreen();
1779 }
[email protected]2b624c562011-10-27 22:58:261780}
1781
1782void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261783 if (!webwidget_)
1784 return;
1785
1786 if (is_fullscreen_) {
1787 webwidget_->didEnterFullScreen();
1788 } else {
1789 webwidget_->didExitFullScreen();
1790 }
[email protected]2b624c562011-10-27 22:58:261791}
1792
[email protected]674741932009-02-04 23:44:461793bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051794 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461795}
1796
[email protected]674741932009-02-04 23:44:461797void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051798 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461799}
1800
[email protected]674741932009-02-04 23:44:461801void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051802 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461803}
1804
[email protected]b18583c2012-12-18 06:55:271805static bool IsDateTimeInput(ui::TextInputType type) {
1806 return type == ui::TEXT_INPUT_TYPE_DATE ||
1807 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1808 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1809 type == ui::TEXT_INPUT_TYPE_MONTH ||
1810 type == ui::TEXT_INPUT_TYPE_TIME ||
1811 type == ui::TEXT_INPUT_TYPE_WEEK;
1812}
1813
[email protected]66fca5bc2013-05-23 06:58:291814
1815void RenderWidget::StartHandlingImeEvent() {
1816 DCHECK(!handling_ime_event_);
1817 handling_ime_event_ = true;
1818}
1819
1820void RenderWidget::FinishHandlingImeEvent() {
1821 DCHECK(handling_ime_event_);
1822 handling_ime_event_ = false;
1823 // While handling an ime event, text input state and selection bounds updates
1824 // are ignored. These must explicitly be updated once finished handling the
1825 // ime event.
1826 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471827#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361828 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471829#endif
[email protected]66fca5bc2013-05-23 06:58:291830}
1831
shuchen3517bb62014-10-15 03:55:571832void RenderWidget::UpdateTextInputType() {
1833 // On Windows, not only an IME but also an on-screen keyboard relies on the
1834 // latest TextInputType to optimize its layout and functionality. Thus
1835 // |input_method_is_active_| is no longer an appropriate condition to suppress
1836 // TextInputTypeChanged IPC on Windows.
1837 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
1838 // on other platforms as well as Windows if the overhead is acceptable.
1839#if !defined(OS_WIN)
1840 if (!input_method_is_active_)
1841 return;
1842#endif
1843
1844 ui::TextInputType new_type = GetTextInputType();
1845 if (IsDateTimeInput(new_type))
1846 return; // Not considered as a text input field in WebKit/Chromium.
1847
1848 bool new_can_compose_inline = CanComposeInline();
1849
1850 blink::WebTextInputInfo new_info;
1851 if (webwidget_)
1852 new_info = webwidget_->textInputInfo();
1853 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
shuchen82ce8c52014-10-23 01:55:201854 int new_flags = new_info.flags;
shuchen3517bb62014-10-15 03:55:571855
1856 if (text_input_type_ != new_type
1857 || can_compose_inline_ != new_can_compose_inline
shuchen82ce8c52014-10-23 01:55:201858 || text_input_mode_ != new_mode
1859 || text_input_flags_ != new_flags) {
shuchen3517bb62014-10-15 03:55:571860 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1861 new_type,
1862 new_mode,
shuchen82ce8c52014-10-23 01:55:201863 new_can_compose_inline,
1864 new_flags));
shuchen3517bb62014-10-15 03:55:571865 text_input_type_ = new_type;
1866 can_compose_inline_ = new_can_compose_inline;
1867 text_input_mode_ = new_mode;
shuchen82ce8c52014-10-23 01:55:201868 text_input_flags_ = new_flags;
shuchen3517bb62014-10-15 03:55:571869 }
1870}
1871
1872#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]90f24152014-04-09 12:41:361873void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1874 ChangeSource change_source) {
[email protected]e8f775f2013-02-14 21:00:501875 if (handling_ime_event_)
1876 return;
[email protected]90f24152014-04-09 12:41:361877 if (show_ime == NO_SHOW_IME && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:291878 return;
[email protected]ad26ef42011-06-17 07:59:451879 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271880 if (IsDateTimeInput(new_type))
1881 return; // Not considered as a text input field in WebKit/Chromium.
1882
[email protected]180ef242013-11-07 06:50:461883 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211884 if (webwidget_)
1885 new_info = webwidget_->textInputInfo();
1886
[email protected]ad26ef42011-06-17 07:59:451887 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211888
[email protected]3306f262012-09-21 19:20:421889 // Only sends text input params if they are changed or if the ime should be
1890 // shown.
[email protected]90f24152014-04-09 12:41:361891 if (show_ime == SHOW_IME_IF_NEEDED ||
1892 (text_input_type_ != new_type ||
1893 text_input_info_ != new_info ||
1894 can_compose_inline_ != new_can_compose_inline)
1895#if defined(OS_ANDROID)
1896 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021897#endif
[email protected]90f24152014-04-09 12:41:361898 ) {
1899 ViewHostMsg_TextInputState_Params p;
[email protected]5b739cb2012-08-21 20:35:211900 p.type = new_type;
[email protected]68e815ac2014-08-11 16:42:401901 p.flags = new_info.flags;
[email protected]5b739cb2012-08-21 20:35:211902 p.value = new_info.value.utf8();
1903 p.selection_start = new_info.selectionStart;
1904 p.selection_end = new_info.selectionEnd;
1905 p.composition_start = new_info.compositionStart;
1906 p.composition_end = new_info.compositionEnd;
1907 p.can_compose_inline = new_can_compose_inline;
[email protected]90f24152014-04-09 12:41:361908 p.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
1909#if defined(USE_AURA)
1910 p.is_non_ime_change = true;
1911#endif
[email protected]183e28d2014-01-20 18:18:021912#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361913 p.is_non_ime_change = (change_source == FROM_NON_IME) ||
1914 text_field_is_dirty_;
1915 if (p.is_non_ime_change)
[email protected]0d1ebed12013-08-05 22:01:131916 IncrementOutstandingImeEventAcks();
[email protected]90f24152014-04-09 12:41:361917 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021918#endif
shuchen3517bb62014-10-15 03:55:571919#if defined(USE_AURA)
1920 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
1921 new_type,
1922 text_input_mode_,
shuchen82ce8c52014-10-23 01:55:201923 new_can_compose_inline,
1924 new_info.flags));
shuchen3517bb62014-10-15 03:55:571925#endif
[email protected]5b739cb2012-08-21 20:35:211926 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
1927
1928 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041929 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:451930 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201931 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291932 }
initial.commit09911bf2008-07-26 23:55:291933}
shuchen3517bb62014-10-15 03:55:571934#endif
initial.commit09911bf2008-07-26 23:55:291935
[email protected]7c8873e2013-02-05 08:03:011936void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1937 WebRect focus_webrect;
1938 WebRect anchor_webrect;
1939 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1940 *focus = focus_webrect;
1941 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321942}
1943
[email protected]e99ef6f2011-10-16 01:13:001944void RenderWidget::UpdateSelectionBounds() {
1945 if (!webwidget_)
1946 return;
[email protected]66fca5bc2013-05-23 06:58:291947 if (handling_ime_event_)
1948 return;
[email protected]e99ef6f2011-10-16 01:13:001949
jddukeacf809e2014-09-23 20:38:381950 // With composited selection updates, the selection bounds will be reported
1951 // directly by the compositor, in which case explicit IPC selection
1952 // notifications should be suppressed.
1953 if (!blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled()) {
1954 ViewHostMsg_SelectionBounds_Params params;
1955 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1956 if (selection_anchor_rect_ != params.anchor_rect ||
1957 selection_focus_rect_ != params.focus_rect) {
1958 selection_anchor_rect_ = params.anchor_rect;
1959 selection_focus_rect_ = params.focus_rect;
1960 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1961 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1962 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1963 }
[email protected]58b48a0d2012-06-13 07:01:351964 }
jddukeacf809e2014-09-23 20:38:381965
[email protected]88dbe32f2013-06-20 23:31:361966 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001967}
1968
[email protected]180ef242013-11-07 06:50:461969// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
1970COMPILE_ASSERT(int(blink::WebTextInputTypeNone) == \
[email protected]ad26ef42011-06-17 07:59:451971 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461972COMPILE_ASSERT(int(blink::WebTextInputTypeText) == \
[email protected]ad26ef42011-06-17 07:59:451973 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461974COMPILE_ASSERT(int(blink::WebTextInputTypePassword) == \
[email protected]ad26ef42011-06-17 07:59:451975 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461976COMPILE_ASSERT(int(blink::WebTextInputTypeSearch) == \
[email protected]caf38ed2011-07-28 13:15:181977 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461978COMPILE_ASSERT(int(blink::WebTextInputTypeEmail) == \
[email protected]caf38ed2011-07-28 13:15:181979 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461980COMPILE_ASSERT(int(blink::WebTextInputTypeNumber) == \
[email protected]caf38ed2011-07-28 13:15:181981 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461982COMPILE_ASSERT(int(blink::WebTextInputTypeTelephone) == \
[email protected]caf38ed2011-07-28 13:15:181983 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461984COMPILE_ASSERT(int(blink::WebTextInputTypeURL) == \
[email protected]caf38ed2011-07-28 13:15:181985 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]180ef242013-11-07 06:50:461986COMPILE_ASSERT(int(blink::WebTextInputTypeDate) == \
[email protected]feb8cf752012-06-08 04:48:001987 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461988COMPILE_ASSERT(int(blink::WebTextInputTypeDateTime) == \
[email protected]feb8cf752012-06-08 04:48:001989 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461990COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeLocal) == \
[email protected]feb8cf752012-06-08 04:48:001991 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461992COMPILE_ASSERT(int(blink::WebTextInputTypeMonth) == \
[email protected]feb8cf752012-06-08 04:48:001993 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461994COMPILE_ASSERT(int(blink::WebTextInputTypeTime) == \
[email protected]feb8cf752012-06-08 04:48:001995 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461996COMPILE_ASSERT(int(blink::WebTextInputTypeWeek) == \
[email protected]feb8cf752012-06-08 04:48:001997 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]180ef242013-11-07 06:50:461998COMPILE_ASSERT(int(blink::WebTextInputTypeTextArea) == \
[email protected]2a9893672012-11-09 20:33:011999 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
[email protected]180ef242013-11-07 06:50:462000COMPILE_ASSERT(int(blink::WebTextInputTypeContentEditable) == \
[email protected]2a9893672012-11-09 20:33:012001 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]180ef242013-11-07 06:50:462002COMPILE_ASSERT(int(blink::WebTextInputTypeDateTimeField) == \
[email protected]8b4992e2013-03-01 15:42:152003 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452004
[email protected]5b739cb2012-08-21 20:35:212005ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462006 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212007 // Check the type is in the range representable by ui::TextInputType.
2008 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462009 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212010 return static_cast<ui::TextInputType>(type);
2011}
2012
[email protected]ad26ef42011-06-17 07:59:452013ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272014 if (webwidget_)
2015 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452016 return ui::TEXT_INPUT_TYPE_NONE;
2017}
2018
[email protected]501ea13d2013-07-09 17:03:292019void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302020#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112021 // TODO(yukawa): Start sending character bounds when the browser side
2022 // implementation becomes ready (crbug.com/424866).
2023#else
[email protected]db4fc1e2013-09-06 20:01:512024 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292025 if (should_update_range) {
2026 GetCompositionRange(&range);
2027 } else {
2028 range = composition_range_;
2029 }
2030 std::vector<gfx::Rect> character_bounds;
2031 GetCompositionCharacterBounds(&character_bounds);
2032
2033 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2034 return;
2035 composition_character_bounds_ = character_bounds;
2036 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222037 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292038 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112039#endif
[email protected]501ea13d2013-07-09 17:03:292040}
2041
[email protected]58b48a0d2012-06-13 07:01:352042void RenderWidget::GetCompositionCharacterBounds(
2043 std::vector<gfx::Rect>* bounds) {
2044 DCHECK(bounds);
2045 bounds->clear();
2046}
2047
[email protected]db4fc1e2013-09-06 20:01:512048void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362049 size_t location, length;
2050 if (webwidget_->compositionRange(&location, &length)) {
2051 range->set_start(location);
2052 range->set_end(location + length);
2053 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2054 range->set_start(location);
2055 range->set_end(location + length);
2056 } else {
[email protected]db4fc1e2013-09-06 20:01:512057 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362058 }
2059}
2060
[email protected]501ea13d2013-07-09 17:03:292061bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512062 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292063 const std::vector<gfx::Rect>& bounds) {
2064 if (composition_range_ != range)
2065 return true;
2066 if (bounds.size() != composition_character_bounds_.size())
2067 return true;
2068 for (size_t i = 0; i < bounds.size(); ++i) {
2069 if (bounds[i] != composition_character_bounds_[i])
2070 return true;
2071 }
2072 return false;
2073}
[email protected]501ea13d2013-07-09 17:03:292074
[email protected]a4f0d882014-05-01 23:48:102075#if defined(OS_ANDROID)
2076void RenderWidget::DidChangeBodyBackgroundColor(SkColor bg_color) {
2077 // If not initialized, default to white. Note that 0 is different from black
2078 // as black still has alpha 0xFF.
2079 if (!bg_color)
2080 bg_color = SK_ColorWHITE;
2081
2082 if (bg_color != body_background_color_) {
2083 body_background_color_ = bg_color;
2084 Send(new ViewHostMsg_DidChangeBodyBackgroundColor(routing_id(), bg_color));
2085 }
2086}
timav7a5032e2014-12-05 01:59:432087
2088bool RenderWidget::DoesRecordFullLayer() const {
2089 SynchronousCompositorFactory* synchronous_compositor_factory =
2090 SynchronousCompositorFactory::GetInstance();
2091
2092 // We assume that the absence of synchronous_compositor_factory
2093 // means we are in Chrome. In chrome, we want to clip, i.e.
2094 // *not* to record the full layer.
2095 if (!synchronous_compositor_factory)
2096 return false;
2097
2098 return synchronous_compositor_factory->RecordFullLayer();
2099}
[email protected]a4f0d882014-05-01 23:48:102100#endif
2101
[email protected]ad26ef42011-06-17 07:59:452102bool RenderWidget::CanComposeInline() {
2103 return true;
[email protected]56ea1a62011-05-30 07:05:572104}
2105
[email protected]4873c7d2009-07-16 06:36:282106WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042107 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282108}
2109
[email protected]f660d9c2012-06-06 18:31:212110float RenderWidget::deviceScaleFactor() {
2111 return device_scale_factor_;
2112}
2113
[email protected]fa7b1dc2010-06-23 17:53:042114void RenderWidget::resetInputMethod() {
2115 if (!input_method_is_active_)
2116 return;
2117
[email protected]0e45bd02013-07-12 20:20:022118 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042119 // If the last text input type is not None, then we should finish any
2120 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452121 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042122 // If a composition text exists, then we need to let the browser process
2123 // to cancel the input method's ongoing composition session.
2124 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222125 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042126 }
[email protected]d4cff272011-05-02 15:46:012127
[email protected]88dbe32f2013-06-20 23:31:362128 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042129}
2130
[email protected]c68c3e4e2013-01-24 00:36:562131void RenderWidget::didHandleGestureEvent(
2132 const WebGestureEvent& event,
2133 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022134#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562135 if (event_cancelled)
2136 return;
[email protected]07c70d22014-08-21 08:33:462137 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362138 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462139 } else if (event.type == WebInputEvent::GestureLongPress) {
2140 DCHECK(webwidget_);
2141 if (webwidget_->textInputInfo().value.isEmpty())
2142 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2143 else
2144 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562145 }
2146#endif
2147}
2148
[email protected]7912e822014-04-16 02:37:032149void RenderWidget::StartCompositor() {
2150 // For widgets that are never visible, we don't need the compositor to run
2151 // at all.
2152 if (never_visible_)
2153 return;
danakj6e3bf8012014-12-16 18:27:532154 // In tests without a RenderThreadImpl, don't set ready as this kicks
2155 // off creating output surfaces that the test can't create.
2156 if (!RenderThreadImpl::current())
2157 return;
danakj018271e32014-12-16 21:17:262158 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032159}
2160
[email protected]29e2fb42013-07-19 01:13:472161void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292162 size_t i = 0;
2163 for (; i < plugin_window_moves_.size(); ++i) {
2164 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582165 if (move.rects_valid) {
2166 plugin_window_moves_[i] = move;
2167 } else {
2168 plugin_window_moves_[i].visible = move.visible;
2169 }
initial.commit09911bf2008-07-26 23:55:292170 break;
2171 }
2172 }
2173
2174 if (i == plugin_window_moves_.size())
2175 plugin_window_moves_.push_back(move);
2176}
[email protected]268654772009-08-06 23:02:042177
2178void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2179 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2180 i != plugin_window_moves_.end(); ++i) {
2181 if (i->window == window) {
2182 plugin_window_moves_.erase(i);
2183 break;
2184 }
2185 }
2186}
[email protected]67bfb83f2011-09-22 03:36:372187
[email protected]63b465922012-09-06 02:04:522188
[email protected]24ed0432013-04-24 07:50:312189RenderWidgetCompositor* RenderWidget::compositor() const {
2190 return compositor_.get();
2191}
2192
[email protected]180ef242013-11-07 06:50:462193bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372194 return false;
2195}
[email protected]c3d45532011-10-07 19:20:402196
[email protected]41d86852012-11-07 12:23:242197bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462198 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242199 return false;
2200}
2201
ccamerond4ba47902014-12-17 07:20:312202void RenderWidget::ObserveWheelEventOnAndResult(
2203 const blink::WebMouseWheelEvent& wheel_event,
2204 bool event_processed) {
2205 bool observe_wheel_event = false;
2206#if defined(OS_MACOSX)
2207 observe_wheel_event = CommandLine::ForCurrentProcess()->HasSwitch(
2208 switches::kEnableThreadedEventHandlingMac);
2209#endif
2210 if (!observe_wheel_event)
2211 return;
2212
2213 // Blink does not accurately compute scroll bubbling or overscroll. For now,
2214 // assume that an unprocessed event was entirely an overscroll, and that a
2215 // processed event was entirely scroll.
2216 // TODO(ccameron): Retrieve an accurate scroll result from Blink.
2217 // http://crbug.com/442859
2218 cc::InputHandlerScrollResult scroll_result;
2219 if (event_processed) {
2220 scroll_result.did_scroll = true;
2221 } else {
2222 scroll_result.did_overscroll_root = true;
2223 scroll_result.unused_scroll_delta =
2224 gfx::Vector2dF(-wheel_event.deltaX, -wheel_event.deltaY);
2225 }
2226
2227 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2228 InputHandlerManager* input_handler_manager =
2229 render_thread ? render_thread->input_handler_manager() : NULL;
2230 if (input_handler_manager) {
2231 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2232 routing_id_, wheel_event, scroll_result);
2233 }
2234}
2235
[email protected]ce6689f2013-03-29 12:52:552236void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2237 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2238}
2239
[email protected]5d0bbdfa92013-12-10 00:35:512240void RenderWidget::setTouchAction(
2241 blink::WebTouchAction web_touch_action) {
2242
2243 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2244 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192245 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512246 return;
2247
[email protected]a18f67a2013-12-20 19:44:362248 // Verify the same values are used by the types so we can cast between them.
2249 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_AUTO) ==
2250 blink::WebTouchActionAuto,
2251 enum_values_must_match_for_touch_action);
2252 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_NONE) ==
2253 blink::WebTouchActionNone,
2254 enum_values_must_match_for_touch_action);
2255 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_X) ==
2256 blink::WebTouchActionPanX,
2257 enum_values_must_match_for_touch_action);
2258 COMPILE_ASSERT(static_cast<blink::WebTouchAction>(TOUCH_ACTION_PAN_Y) ==
2259 blink::WebTouchActionPanY,
2260 enum_values_must_match_for_touch_action);
[email protected]2bd73272014-03-13 19:36:112261 COMPILE_ASSERT(
2262 static_cast<blink::WebTouchAction>(TOUCH_ACTION_PINCH_ZOOM) ==
2263 blink::WebTouchActionPinchZoom,
2264 enum_values_must_match_for_touch_action);
[email protected]a18f67a2013-12-20 19:44:362265
2266 content::TouchAction content_touch_action =
2267 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512268 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2269}
2270
[email protected]90f24152014-04-09 12:41:362271void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2272#if defined(OS_ANDROID)
2273 text_field_is_dirty_ = true;
2274#endif
2275}
2276
[email protected]3d5c243b2012-11-30 00:26:012277bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2278 return true;
2279}
2280
[email protected]0634cdd42013-08-16 00:46:092281scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
[email protected]828a3932014-04-02 14:43:132282RenderWidget::CreateGraphicsContext3D() {
[email protected]ed7defa2013-03-12 21:29:592283 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092284 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ebc0e1df2013-08-01 02:46:222285 if (CommandLine::ForCurrentProcess()->HasSwitch(
2286 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092287 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292288 if (!RenderThreadImpl::current())
2289 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402290 CauseForGpuLaunch cause =
2291 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292292 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402293 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222294 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292295 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592296
[email protected]828a3932014-04-02 14:43:132297 // Explicitly disable antialiasing for the compositor. As of the time of
2298 // this writing, the only platform that supported antialiasing for the
2299 // compositor was Mac OS X, because the on-screen OpenGL context creation
2300 // code paths on Windows and Linux didn't yet have multisampling support.
2301 // Mac OS X essentially always behaves as though it's rendering offscreen.
2302 // Multisampling has a heavy cost especially on devices with relatively low
2303 // fill rate like most notebooks, and the Mac implementation would need to
2304 // be optimized to resolve directly into the IOSurface shared between the
2305 // GPU and browser processes. For these reasons and to avoid platform
2306 // disparities we explicitly disable antialiasing.
2307 blink::WebGraphicsContext3D::Attributes attributes;
2308 attributes.antialias = false;
2309 attributes.shareResources = true;
2310 attributes.noAutomaticFlushes = true;
2311 attributes.depth = false;
2312 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132313 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292314 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012315#if defined(OS_ANDROID)
2316 // If we raster too fast we become upload bound, and pending
2317 // uploads consume memory. For maximum upload throughput, we would
2318 // want to allow for upload_throughput * pipeline_time of pending
2319 // uploads, after which we are just wasting memory. Since we don't
2320 // know our upload throughput yet, this just caps our memory usage.
2321 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272322 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032323 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012324 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032325 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012326 // Deadline to draw a frame to achieve 60 frames per second.
2327 const size_t kMillisecondsPerFrame = 16;
2328 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032329 size_t max_transfer_buffer_usage_mb =
2330 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2331 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012332 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2333 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292334 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032335 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012336#endif
[email protected]96ab016c2013-10-23 00:50:292337
[email protected]96ab016c2013-10-23 00:50:292338 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
[email protected]828a3932014-04-02 14:43:132339 new WebGraphicsContext3DCommandBufferImpl(surface_id(),
2340 GetURLForGraphicsContext3D(),
2341 gpu_channel_host.get(),
2342 attributes,
[email protected]828a3932014-04-02 14:43:132343 lose_context_when_out_of_memory,
2344 limits,
2345 NULL));
[email protected]0634cdd42013-08-16 00:46:092346 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592347}
2348
[email protected]e3244ed2014-06-20 20:04:272349void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2350 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162351}
2352
[email protected]e3244ed2014-06-20 20:04:272353void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2354 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162355}
2356
[email protected]de3c5d82014-05-28 22:12:592357void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2358 render_frames_.AddObserver(frame);
2359}
2360
2361void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2362 render_frames_.RemoveObserver(frame);
2363}
2364
[email protected]a017938b2014-05-27 21:17:172365#if defined(VIDEO_HOLE)
2366void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2367 video_hole_frames_.AddObserver(frame);
2368}
2369
2370void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2371 video_hole_frames_.RemoveObserver(frame);
2372}
2373#endif // defined(VIDEO_HOLE)
2374
[email protected]e9ff79c2012-10-19 21:31:262375} // namespace content