blob: 345b9e140d3f58a5ef43eb887f3bac6eeca98a8e [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]c27dd4f2014-05-22 18:05:197#include "base/auto_reset.h"
[email protected]32876ae2011-11-15 22:25:218#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:009#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]b256eca2013-07-11 10:57:4012#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3013#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3814#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2115#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0016#include "base/strings/utf_string_conversions.h"
[email protected]35b4f0c2014-06-26 16:55:2717#include "base/sys_info.h"
primiano9e38d552015-01-28 04:18:0118#include "base/trace_event/trace_event.h"
19#include "base/trace_event/trace_event_synthetic_delay.h"
[email protected]661eb9d2009-02-03 02:11:4820#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5221#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3322#include "cc/debug/benchmark_instrumentation.h"
[email protected]7f0d825f2013-03-18 07:24:3023#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0424#include "cc/trees/layer_tree_host.h"
alexclarke7819e2552015-06-03 11:17:2125#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4726#include "content/child/npapi/webplugin.h"
[email protected]0634cdd42013-08-16 00:46:0927#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5928#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2929#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3530#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4431#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1532#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1533#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5034#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2935#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4236#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4037#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5138#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5939#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2940#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1141#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5942#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2844#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2945#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1346#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3247#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1648#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2749#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0550#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4451#include "content/renderer/render_thread_impl.h"
tfarina556a7232014-10-05 01:02:0952#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0453#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1854#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4855#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1856#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3057#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1158#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3059#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1860#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3061#include "third_party/WebKit/public/platform/WebSize.h"
62#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4363#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5964#include "third_party/WebKit/public/web/WebFrameWidget.h"
65#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1166#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3167#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3168#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
69#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3870#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5971#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4172#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1373#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5074#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0975#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3276#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4877#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2778#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4179#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4880
[email protected]eeb93112013-05-01 19:41:1081#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1582#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0783#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1084#endif
85
[email protected]661eb9d2009-02-03 02:11:4886#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4987#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5288#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4189#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4890#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4491
[email protected]2255a9332013-06-17 05:12:3192#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2993
[email protected]180ef242013-11-07 06:50:4694using blink::WebCompositionUnderline;
95using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4396using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:4697using blink::WebGestureEvent;
98using blink::WebInputEvent;
99using blink::WebKeyboardEvent;
100using blink::WebMouseEvent;
101using blink::WebMouseWheelEvent;
102using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11103using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46104using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11105using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46106using blink::WebPopupType;
107using blink::WebRange;
108using blink::WebRect;
109using blink::WebScreenInfo;
110using blink::WebSize;
111using blink::WebTextDirection;
112using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25113using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46114using blink::WebVector;
115using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26116
[email protected]6a4d7f62013-01-07 21:32:13117namespace {
[email protected]b256eca2013-07-11 10:57:40118
119typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
120
121class TextInputModeMapSingleton {
122 public:
123 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22124 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40125 }
[email protected]dd705d4d2013-11-27 08:14:41126 TextInputModeMapSingleton() {
127 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
128 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
129 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
130 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
131 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
132 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
133 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
134 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
135 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
136 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
137 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40138 }
[email protected]dd705d4d2013-11-27 08:14:41139 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40140 private:
[email protected]dd705d4d2013-11-27 08:14:41141 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40142
olli.raula36aa8be2015-09-10 11:14:22143 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40144
145 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
146};
147
[email protected]dd705d4d2013-11-27 08:14:41148ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40149 static TextInputModeMapSingleton* singleton =
150 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41151 TextInputModeMap::const_iterator it =
152 singleton->map().find(input_mode.utf8());
153 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40154 return ui::TEXT_INPUT_MODE_DEFAULT;
155 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13156}
[email protected]b256eca2013-07-11 10:57:40157
[email protected]fd847792013-10-24 17:12:35158// TODO(brianderson): Replace the hard-coded threshold with a fraction of
159// the BeginMainFrame interval.
160// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
161// be spent in input hanlders before input starts getting throttled.
162const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
163
miletus14a25642015-08-13 19:23:23164int64 GetEventLatencyMicros(double event_timestamp, base::TimeTicks now) {
165 return (now - base::TimeDelta::FromSecondsD(event_timestamp))
jdduke07788062014-12-05 03:16:30166 .ToInternalValue();
167}
168
miletus14a25642015-08-13 19:23:23169void LogInputEventLatencyUmaImpl(WebInputEvent::Type event_type,
170 double event_timestamp,
171 base::TimeTicks now) {
172 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.AggregatedLatency.Renderer2",
173 GetEventLatencyMicros(event_timestamp, now), 1,
174 10000000, 100);
jdduke07788062014-12-05 03:16:30175
miletus14a25642015-08-13 19:23:23176#define CASE_TYPE(t) \
177 case WebInputEvent::t: \
178 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer2." #t, \
179 GetEventLatencyMicros(event_timestamp, now), \
180 1, 10000000, 100); \
181 break;
jdduke07788062014-12-05 03:16:30182
miletus14a25642015-08-13 19:23:23183 switch (event_type) {
jdduke07788062014-12-05 03:16:30184 CASE_TYPE(Undefined);
185 CASE_TYPE(MouseDown);
186 CASE_TYPE(MouseUp);
187 CASE_TYPE(MouseMove);
188 CASE_TYPE(MouseEnter);
189 CASE_TYPE(MouseLeave);
190 CASE_TYPE(ContextMenu);
191 CASE_TYPE(MouseWheel);
192 CASE_TYPE(RawKeyDown);
193 CASE_TYPE(KeyDown);
194 CASE_TYPE(KeyUp);
195 CASE_TYPE(Char);
196 CASE_TYPE(GestureScrollBegin);
197 CASE_TYPE(GestureScrollEnd);
198 CASE_TYPE(GestureScrollUpdate);
199 CASE_TYPE(GestureFlingStart);
200 CASE_TYPE(GestureFlingCancel);
201 CASE_TYPE(GestureShowPress);
202 CASE_TYPE(GestureTap);
203 CASE_TYPE(GestureTapUnconfirmed);
204 CASE_TYPE(GestureTapDown);
205 CASE_TYPE(GestureTapCancel);
206 CASE_TYPE(GestureDoubleTap);
207 CASE_TYPE(GestureTwoFingerTap);
208 CASE_TYPE(GestureLongPress);
209 CASE_TYPE(GestureLongTap);
210 CASE_TYPE(GesturePinchBegin);
211 CASE_TYPE(GesturePinchEnd);
212 CASE_TYPE(GesturePinchUpdate);
213 CASE_TYPE(TouchStart);
214 CASE_TYPE(TouchMove);
215 CASE_TYPE(TouchEnd);
216 CASE_TYPE(TouchCancel);
217 default:
218 // Must include default to let blink::WebInputEvent add new event types
219 // before they're added here.
miletus14a25642015-08-13 19:23:23220 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event_type;
jdduke07788062014-12-05 03:16:30221 break;
222 }
223
224#undef CASE_TYPE
225}
226
miletus14a25642015-08-13 19:23:23227void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now,
228 const ui::LatencyInfo& latency_info) {
229 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now);
230 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) {
231 LogInputEventLatencyUmaImpl(
232 event.type,
233 latency_info.timestamps_of_coalesced_events()[i],
234 now);
235 }
236}
237
[email protected]b256eca2013-07-11 10:57:40238} // namespace
239
[email protected]e9ff79c2012-10-19 21:31:26240namespace content {
[email protected]62cb33cae2009-03-27 23:30:22241
[email protected]b2e4c70132013-10-03 02:07:51242// RenderWidget::ScreenMetricsEmulator ----------------------------------------
243
244class RenderWidget::ScreenMetricsEmulator {
245 public:
246 ScreenMetricsEmulator(
247 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43248 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51249 virtual ~ScreenMetricsEmulator();
250
[email protected]19193682014-04-03 15:01:43251 // Scale and offset used to convert between host coordinates
252 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51253 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20254 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43255 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51256 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56257 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51258
259 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43260 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51261
262 // The following methods alter handlers' behavior for messages related to
263 // widget size and position.
264 void OnResizeMessage(const ViewMsg_Resize_Params& params);
265 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
266 const gfx::Rect& window_screen_rect);
267 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31268 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51269
270 private:
[email protected]19193682014-04-03 15:01:43271 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02272 void Apply(bool top_controls_shrink_blink_size,
273 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44274 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12275 bool is_fullscreen_granted,
276 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51277
278 RenderWidget* widget_;
279
[email protected]7f99fc22013-11-08 14:05:58280 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43281 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51282
[email protected]a179d3962013-11-12 14:44:40283 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51284 float scale_;
dgozman9260b0a12015-03-16 13:45:20285 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51286
[email protected]19193682014-04-03 15:01:43287 // Widget rect as passed to webwidget.
288 gfx::Rect applied_widget_rect_;
289
[email protected]b2e4c70132013-10-03 02:07:51290 // Original values to restore back after emulation ends.
291 gfx::Size original_size_;
292 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28293 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46294 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51295 gfx::Rect original_view_screen_rect_;
296 gfx::Rect original_window_screen_rect_;
297};
298
299RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
300 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43301 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51302 : widget_(widget),
[email protected]19193682014-04-03 15:01:43303 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51304 scale_(1.f) {
305 original_size_ = widget_->size_;
306 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28307 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51308 original_screen_info_ = widget_->screen_info_;
309 original_view_screen_rect_ = widget_->view_screen_rect_;
310 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02311 Apply(widget_->top_controls_shrink_blink_size_,
312 widget_->top_controls_height_,
313 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12314 widget_->is_fullscreen_granted_,
315 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51316}
317
318RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
319 widget_->screen_info_ = original_screen_info_;
320
321 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20322 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51323 widget_->view_screen_rect_ = original_view_screen_rect_;
324 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01325 widget_->Resize(original_size_,
326 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02327 widget_->top_controls_shrink_blink_size_,
328 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01329 original_visible_viewport_size_,
330 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12331 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12332 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01333 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51334}
335
336void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43337 const WebDeviceEmulationParams& params) {
338 params_ = params;
339 Reapply();
340}
341
342void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02343 Apply(widget_->top_controls_shrink_blink_size_,
344 widget_->top_controls_height_,
345 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12346 widget_->is_fullscreen_granted_,
347 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51348}
349
[email protected]19193682014-04-03 15:01:43350void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02351 bool top_controls_shrink_blink_size,
352 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44353 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12354 bool is_fullscreen_granted,
355 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31356 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
357 if (!applied_widget_rect_.width())
358 applied_widget_rect_.set_width(original_size_.width());
359 if (!applied_widget_rect_.height())
360 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43361
[email protected]f442ee42014-05-14 11:53:12362 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02363 int original_width = std::max(original_size_.width(), 1);
364 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51365 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02366 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51367 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02368 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51369 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
370 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01371
372 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43373 offset_.set_x(
374 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01375 offset_.set_y(
[email protected]19193682014-04-03 15:01:43376 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51377 } else {
[email protected]0b3578c2014-06-20 18:29:02378 scale_ = params_.scale;
379 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01380 }
[email protected]7f0e8fa2014-03-26 12:32:01381
[email protected]19193682014-04-03 15:01:43382 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
383 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01384 widget_->screen_info_.rect = original_screen_info_.rect;
385 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
386 widget_->window_screen_rect_ = original_window_screen_rect_;
387 } else {
dgozmanf28ccbe2015-06-24 08:50:49388 applied_widget_rect_.set_origin(params_.viewPosition);
389 gfx::Rect screen_rect = applied_widget_rect_;
390 if (!params_.screenSize.isEmpty()) {
391 screen_rect =
392 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
393 }
394 widget_->screen_info_.rect = screen_rect;
395 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43396 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01397 }
[email protected]a179d3962013-11-12 14:44:40398
[email protected]19193682014-04-03 15:01:43399 float applied_device_scale_factor = params_.deviceScaleFactor ?
400 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01401 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51402
[email protected]7f99fc22013-11-08 14:05:58403 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51404 // - we keep the real device scale factor in compositor to produce sharp image
405 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58406 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51407 // root layer.
dgozman9260b0a12015-03-16 13:45:20408 blink::WebDeviceEmulationParams modified_params = params_;
409 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
410 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
411 modified_params.scale = scale_;
412 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51413
[email protected]7f0e8fa2014-03-26 12:32:01414 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43415 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51416
danakjddaec912015-09-25 19:38:40417 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
418 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02419 widget_->Resize(applied_widget_rect_.size(),
420 physical_backing_size,
421 top_controls_shrink_blink_size,
422 top_controls_height,
423 applied_widget_rect_.size(),
424 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12425 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12426 display_mode,
dtrainorcb7779b82014-12-04 01:08:02427 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51428}
429
430void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
431 const ViewMsg_Resize_Params& params) {
432 bool need_ack = params.new_size != original_size_ &&
433 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
434 original_size_ = params.new_size;
435 original_physical_backing_size_ = params.physical_backing_size;
436 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28437 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02438 Apply(params.top_controls_shrink_blink_size,
439 params.top_controls_height,
440 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12441 params.is_fullscreen_granted,
442 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51443
444 if (need_ack) {
445 widget_->set_next_paint_is_resize_ack();
446 if (widget_->compositor_)
447 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
448 }
449}
450
451void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
452 const gfx::Rect& view_screen_rect,
453 const gfx::Rect& window_screen_rect) {
454 original_view_screen_rect_ = view_screen_rect;
455 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43456 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
457 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51458}
459
460void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
461 ContextMenuParams* params) {
462 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40463 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51464 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40465 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51466}
467
[email protected]2d6836f42014-07-02 17:25:31468gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
469 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56470 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31471 scaled.set_x(scaled.x() + offset_.x());
472 scaled.set_y(scaled.y() + offset_.y());
473 return scaled;
474}
475
[email protected]b2e4c70132013-10-03 02:07:51476// RenderWidget ---------------------------------------------------------------
477
dcheng35d31c112015-07-22 00:17:36478RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
479 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46480 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04481 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03482 bool hidden,
483 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29484 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36485 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53486 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29487 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02488 top_controls_shrink_blink_size_(false),
489 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29490 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51491 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09492 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29493 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04494 is_hidden_(hidden),
[email protected]7912e822014-04-16 02:37:03495 never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12496 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12497 display_mode_(blink::WebDisplayModeUndefined),
initial.commit09911bf2008-07-26 23:55:29498 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49499 handling_input_event_(false),
jddukec05612b2015-06-25 23:13:18500 handling_event_overscroll_(nullptr),
[email protected]e8f775f2013-02-14 21:00:50501 handling_ime_event_(false),
[email protected]c27dd4f2014-05-22 18:05:19502 handling_event_type_(WebInputEvent::Undefined),
503 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48504 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22505 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44506 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20507 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45508 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40509 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20510 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53511 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12512 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48513 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12514 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04515 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52516 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30517 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13518#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36519 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13520#endif
[email protected]b2e4c70132013-10-03 02:07:51521 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11522 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42523 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51524 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
525 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05526 if (!swapped_out)
527 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27528 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53529 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37530#if defined(OS_ANDROID)
531 text_input_info_history_.push_back(blink::WebTextInputInfo());
532#endif
initial.commit09911bf2008-07-26 23:55:29533}
534
535RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11536 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16537
[email protected]992db4c2011-05-12 15:37:15538 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02539 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15540 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29541}
542
[email protected]484955942010-08-19 16:13:18543// static
[email protected]8085dbc82008-09-26 22:53:44544RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53545 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46546 blink::WebPopupType popup_type,
547 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29548 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36549 scoped_refptr<RenderWidget> widget(new RenderWidget(
550 compositor_deps, popup_type, screen_info, false, false, false));
551 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46552 return widget.get();
[email protected]a635f942012-12-07 10:34:29553 }
554 return NULL;
initial.commit09911bf2008-07-26 23:55:29555}
556
[email protected]484955942010-08-19 16:13:18557// static
kenrba7199832015-01-22 23:44:59558RenderWidget* RenderWidget::CreateForFrame(
559 int routing_id,
kenrba7199832015-01-22 23:44:59560 bool hidden,
561 const blink::WebScreenInfo& screen_info,
562 CompositorDependencies* compositor_deps,
563 blink::WebLocalFrame* frame) {
564 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36565 scoped_refptr<RenderWidget> widget(
566 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
567 false, hidden, false));
kenrba7199832015-01-22 23:44:59568 widget->routing_id_ = routing_id;
simonhong628f9812015-04-27 23:13:20569 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59570 // DoInit increments the reference count on |widget|, keeping it alive after
571 // this function returns.
dcheng35d31c112015-07-22 00:17:36572 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59573 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
574 nullptr)) {
kenrba7199832015-01-22 23:44:59575 return widget.get();
576 }
577 return nullptr;
578}
579
580// static
dchengda9b4bb2015-07-20 20:58:08581blink::WebWidget* RenderWidget::CreateWebFrameWidget(
582 RenderWidget* render_widget,
583 blink::WebLocalFrame* frame) {
584 return blink::WebFrameWidget::create(render_widget, frame);
585}
586
587// static
kenrba7199832015-01-22 23:44:59588blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18589 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46590 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18591 break;
[email protected]180ef242013-11-07 06:50:46592 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44593 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18594 default:
595 NOTREACHED();
596 }
597 return NULL;
598}
599
dchengda9b4bb2015-07-20 20:58:08600void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32601 OnClose();
kenrba7199832015-01-22 23:44:59602}
603
dcheng35d31c112015-07-22 00:17:36604bool RenderWidget::Init(int32 opener_id) {
piman5d36dae2015-09-24 22:47:05605 return DoInit(
606 opener_id, RenderWidget::CreateWebWidget(this),
607 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
[email protected]484955942010-08-19 16:13:18608}
609
[email protected]a635f942012-12-07 10:34:29610bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06611 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18612 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29613 DCHECK(!webwidget_);
614
615 if (opener_id != MSG_ROUTING_NONE)
616 opener_id_ = opener_id;
617
[email protected]484955942010-08-19 16:13:18618 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29619
kenrba7199832015-01-22 23:44:59620 bool result = true;
621 if (create_widget_message)
622 result = RenderThread::Get()->Send(create_widget_message);
623
initial.commit09911bf2008-07-26 23:55:29624 if (result) {
[email protected]380244092011-10-07 17:26:27625 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29626 // Take a reference on behalf of the RenderThread. This will be balanced
627 // when we receive ViewMsg_Close.
628 AddRef();
[email protected]b2db9272014-01-10 17:42:00629 if (RenderThreadImpl::current()) {
630 RenderThreadImpl::current()->WidgetCreated();
631 if (is_hidden_)
632 RenderThreadImpl::current()->WidgetHidden();
633 }
[email protected]a635f942012-12-07 10:34:29634 return true;
initial.commit09911bf2008-07-26 23:55:29635 } else {
[email protected]a635f942012-12-07 10:34:29636 // The above Send can fail when the tab is closing.
637 return false;
initial.commit09911bf2008-07-26 23:55:29638 }
639}
640
[email protected]992db4c2011-05-12 15:37:15641void RenderWidget::SetSwappedOut(bool is_swapped_out) {
642 // We should only toggle between states.
643 DCHECK(is_swapped_out_ != is_swapped_out);
644 is_swapped_out_ = is_swapped_out;
645
646 // If we are swapping out, we will call ReleaseProcess, allowing the process
647 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52648 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15649 // If we are swapping in, we call AddRefProcess to prevent the process from
650 // exiting.
[email protected]949b6592014-08-20 13:17:52651 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15652 RenderProcess::current()->AddRefProcess();
653}
654
[email protected]949b6592014-08-20 13:17:52655void RenderWidget::WasSwappedOut() {
656 // If we have been swapped out and no one else is using this process,
657 // it's safe to exit now.
658 CHECK(is_swapped_out_);
659 RenderProcess::current()->ReleaseProcess();
660}
661
[email protected]b2e4c70132013-10-03 02:07:51662void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
663 ScreenMetricsEmulator* emulator) {
664 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43665 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49666 popup_screen_origin_for_emulation_ = gfx::Point(
667 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
668 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56669 screen_info_ = emulator->original_screen_info();
670 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51671}
672
[email protected]2d6836f42014-07-02 17:25:31673gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
674 if (screen_metrics_emulator_)
675 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
676 return anchor;
677}
678
[email protected]b2e4c70132013-10-03 02:07:51679void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20680 bool enabled,
681 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51682 // This is only supported in RenderView.
683 NOTREACHED();
684}
685
[email protected]53907862014-03-25 15:42:40686#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51687void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
688 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49689 popup->SetOriginScaleAndOffsetForEmulation(
690 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51691}
[email protected]53907862014-03-25 15:42:40692#endif
[email protected]b2e4c70132013-10-03 02:07:51693
694void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
695 if (screen_metrics_emulator_)
696 screen_metrics_emulator_->OnShowContextMenu(params);
697}
698
[email protected]a95986a82010-12-24 06:19:28699bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
700 bool handled = true;
701 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15702 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22703 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
704 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22705 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
706 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15707 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
708 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35709 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
710 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28711 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28712 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20713 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
714 OnEnableDeviceEmulation)
715 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
716 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41717 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54718 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28719 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41720 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25721 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28722 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
723 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03724 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05725 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21726#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37727 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51728 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21729#endif
[email protected]a95986a82010-12-24 06:19:28730 IPC_MESSAGE_UNHANDLED(handled = false)
731 IPC_END_MESSAGE_MAP()
732 return handled;
733}
initial.commit09911bf2008-07-26 23:55:29734
735bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15736 // Don't send any messages after the browser has told us to close, and filter
737 // most outgoing messages while swapped out.
738 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26739 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11740 closing_) {
initial.commit09911bf2008-07-26 23:55:29741 delete message;
742 return false;
743 }
744
745 // If given a messsage without a routing ID, then assign our routing ID.
746 if (message->routing_id() == MSG_ROUTING_NONE)
747 message->set_routing_id(routing_id_);
748
[email protected]380244092011-10-07 17:26:27749 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44750}
751
[email protected]61e2b3cc2012-03-02 16:13:34752void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44753 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02754 bool top_controls_shrink_blink_size,
755 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44756 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34757 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12758 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12759 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58760 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56761 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48762 // A resize ack shouldn't be requested if we have not ACK'd the previous
763 // one.
764 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
765 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
766 }
initial.commit09911bf2008-07-26 23:55:29767
[email protected]61e2b3cc2012-03-02 16:13:34768 // Ignore this during shutdown.
769 if (!webwidget_)
770 return;
771
[email protected]d9083762013-03-24 01:36:40772 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44773 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40774 }
[email protected]60d47ac2013-03-01 23:42:44775
[email protected]dade8992013-03-04 07:34:34776 physical_backing_size_ = physical_backing_size;
dtrainorcb7779b82014-12-04 01:08:02777 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
778 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28779 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34780 resizer_rect_ = resizer_rect;
781
782 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12783 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12784 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12785 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34786
aelias6004fe02015-02-07 21:43:01787 webwidget_->setTopControlsHeight(top_controls_height,
788 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43789
[email protected]61e2b3cc2012-03-02 16:13:34790 if (size_ != new_size) {
[email protected]61e2b3cc2012-03-02 16:13:34791 size_ = new_size;
792
[email protected]61e2b3cc2012-03-02 16:13:34793 // When resizing, we want to wait to paint before ACK'ing the resize. This
794 // ensures that we only resize as fast as we can paint. We only need to
795 // send an ACK if we are resized to a non-empty rect.
796 webwidget_->resize(new_size);
[email protected]632c4382013-05-15 08:58:45797 }
798
[email protected]bb6378fe2014-04-28 21:19:44799 webwidget()->resizePinchViewport(gfx::Size(
800 visible_viewport_size.width(),
801 visible_viewport_size.height()));
802
[email protected]632c4382013-05-15 08:58:45803 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58804 // In this case there is no paint/composite and therefore no
805 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
806 // ack through a fake ViewHostMsg_UpdateRect or a different message.
807 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34808 }
809
[email protected]20fbfc22013-05-08 20:50:58810 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45811 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58812 set_next_paint_is_resize_ack();
813
[email protected]61e2b3cc2012-03-02 16:13:34814 if (fullscreen_change)
815 DidToggleFullscreen();
816
817 // If a resize ack is requested and it isn't set-up, then no more resizes will
818 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45819 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29820}
821
bokanc007c3a2015-02-03 07:15:56822void RenderWidget::SetWindowRectSynchronously(
823 const gfx::Rect& new_window_rect) {
824 Resize(new_window_rect.size(),
825 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02826 top_controls_shrink_blink_size_,
827 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56828 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01829 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12830 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12831 display_mode_,
[email protected]587941d2014-08-22 01:40:01832 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56833 view_screen_rect_ = new_window_rect;
834 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02835 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56836 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02837}
838
initial.commit09911bf2008-07-26 23:55:29839void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32840 DCHECK(content::RenderThread::Get());
841 if (closing_)
842 return;
843 NotifyOnClose();
844 closing_ = true;
845
846 // Browser correspondence is no longer needed at this point.
847 if (routing_id_ != MSG_ROUTING_NONE) {
848 RenderThread::Get()->RemoveRoute(routing_id_);
849 SetHidden(false);
850 if (RenderThreadImpl::current())
851 RenderThreadImpl::current()->WidgetDestroyed();
852 }
853
854 if (for_oopif_) {
855 // Widgets for frames may be created and closed at any time while the frame
856 // is alive. However, the closing process must happen synchronously. Frame
857 // widget and frames hold pointers to each other. If Close() is deferred to
858 // the message loop like in the non-frame widget case, WebWidget::close()
859 // can end up accessing members of an already-deleted frame.
860 Close();
861 } else {
862 // If there is a Send call on the stack, then it could be dangerous to close
863 // now. Post a task that only gets invoked when there are no nested message
864 // loops.
865 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
866 FROM_HERE, base::Bind(&RenderWidget::Close, this));
867 }
868
869 // Balances the AddRef taken when we called AddRoute.
870 Release();
initial.commit09911bf2008-07-26 23:55:29871}
872
[email protected]0fdd5012013-05-29 08:05:56873void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04874 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32875 return;
876
[email protected]b2e4c70132013-10-03 02:07:51877 if (screen_metrics_emulator_) {
878 screen_metrics_emulator_->OnResizeMessage(params);
879 return;
880 }
881
[email protected]fcdc5642014-05-09 14:32:24882 bool orientation_changed =
883 screen_info_.orientationAngle != params.screen_info.orientationAngle;
884
[email protected]0fdd5012013-05-29 08:05:56885 screen_info_ = params.screen_info;
886 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02887 Resize(params.new_size,
888 params.physical_backing_size,
889 params.top_controls_shrink_blink_size,
890 params.top_controls_height,
891 params.visible_viewport_size,
892 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12893 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12894 params.display_mode,
sievers4e33dae2015-02-25 20:43:58895 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24896
897 if (orientation_changed)
898 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29899}
900
dgozman9260b0a12015-03-16 13:45:20901void RenderWidget::OnEnableDeviceEmulation(
902 const blink::WebDeviceEmulationParams& params) {
903 if (!screen_metrics_emulator_)
904 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
905 else
906 screen_metrics_emulator_->ChangeEmulationParams(params);
907}
908
909void RenderWidget::OnDisableDeviceEmulation() {
910 screen_metrics_emulator_.reset();
911}
912
noel89949e62014-09-30 01:12:41913void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
914 SetDeviceColorProfile(color_profile);
915}
916
[email protected]b5913d72012-02-07 22:26:54917void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01918 if (resizer_rect_ == resizer_rect)
919 return;
920 resizer_rect_ = resizer_rect;
921 if (webwidget_)
922 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54923}
924
initial.commit09911bf2008-07-26 23:55:29925void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31926 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29927 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03928 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59929 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
930 WasHidden());
initial.commit09911bf2008-07-26 23:55:29931}
932
[email protected]3399dd822014-08-09 11:14:24933void RenderWidget::OnWasShown(bool needs_repainting,
934 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41935 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29936 // During shutdown we can just ignore this message.
937 if (!webwidget_)
938 return;
939
940 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03941 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59942 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
943 WasShown());
initial.commit09911bf2008-07-26 23:55:29944
[email protected]8a23afb32014-04-30 22:40:23945 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29946 return;
initial.commit09911bf2008-07-26 23:55:29947
948 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24949 if (compositor_) {
950 ui::LatencyInfo swap_latency_info(latency_info);
951 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
952 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05953 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24954 }
jdduke491a3f0c2015-06-15 23:30:26955 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29956}
957
[email protected]53d3f302009-12-21 04:42:05958void RenderWidget::OnRequestMoveAck() {
959 DCHECK(pending_window_rect_count_);
960 pending_window_rect_count_--;
961}
962
[email protected]ed7defa2013-03-12 21:29:59963GURL RenderWidget::GetURLForGraphicsContext3D() {
964 return GURL();
[email protected]65225772011-05-12 21:10:24965}
966
[email protected]ebc0e1df2013-08-01 02:46:22967scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:03968 // For widgets that are never visible, we don't start the compositor, so we
969 // never get a request for a cc::OutputSurface.
970 DCHECK(!never_visible_);
[email protected]a1811b8912013-05-09 15:35:19971
972#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01973 if (SynchronousCompositorFactory* factory =
974 SynchronousCompositorFactory::GetInstance()) {
piman5d36dae2015-09-24 22:47:05975 return factory->CreateOutputSurface(routing_id(),
[email protected]586871b2014-07-22 17:05:11976 frame_swap_message_queue_);
[email protected]a1811b8912013-05-09 15:35:19977 }
978#endif
979
avi83883c82014-12-23 00:08:49980 const base::CommandLine& command_line =
981 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:33982 bool use_software = fallback;
983 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
984 use_software = true;
985
[email protected]0634cdd42013-08-16 00:46:09986 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:17987 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:33988 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:09989 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:01990 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:33991 if (!context_provider.get()) {
992 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34993 return nullptr;
[email protected]e09994a2014-03-26 19:59:33994 }
revemand180dfc32015-09-24 00:19:43995 worker_context_provider =
996 RenderThreadImpl::current()->SharedWorkerContextProvider();
997 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:17998 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:34999 return nullptr;
vmiura78b69282015-02-14 00:01:171000 }
[email protected]0634cdd42013-08-16 00:46:091001 }
[email protected]ebc0e1df2013-08-01 02:46:221002
[email protected]b6eb8e332013-09-10 00:51:011003 uint32 output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:341004 // Composite-to-mailbox is currently used for layout tests in order to cause
1005 // them to draw inside in the renderer to do the readback there. This should
1006 // no longer be the case when crbug.com/311404 is fixed.
1007 if (!RenderThreadImpl::current() ||
1008 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:531009 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:341010 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171011 routing_id(), output_surface_id, context_provider,
1012 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091013 }
piman8944e1c2015-09-22 21:10:341014
[email protected]0634cdd42013-08-16 00:46:091015 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091016 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121017 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091018
piman8944e1c2015-09-22 21:10:341019 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291020 routing_id(), output_surface_id, nullptr, nullptr,
1021 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221022 }
[email protected]ed7defa2013-03-12 21:29:591023
piman8944e1c2015-09-22 21:10:341024 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171025 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341026 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281027}
1028
[email protected]4d7e46a2013-11-08 05:33:401029void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241030 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241031 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261032 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241033}
1034
[email protected]4d7e46a2013-11-08 05:33:401035void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081036 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081037}
1038
[email protected]4d7e46a2013-11-08 05:33:401039void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241040 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161041
[email protected]404939f2012-06-01 04:06:181042 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161043 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291044}
1045
[email protected]180ef242013-11-07 06:50:461046void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
[email protected]205294b2014-03-18 20:48:351047 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091048 bool is_keyboard_shortcut) {
[email protected]c27dd4f2014-05-22 18:05:191049 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291050 return;
jddukec05612b2015-06-25 23:13:181051 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1052 true);
[email protected]c27dd4f2014-05-22 18:05:191053 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1054 &handling_event_type_, input_event->type);
jddukec05612b2015-06-25 23:13:181055
1056 // Calls into |didOverscroll()| while handling this event will populate
1057 // |event_overscroll|, which in turn will be bundled with the event ack.
1058 scoped_ptr<DidOverscrollParams> event_overscroll;
1059 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1060 handling_event_overscroll_resetter(&handling_event_overscroll_,
1061 &event_overscroll);
1062
[email protected]25402eb2014-07-18 03:09:521063#if defined(OS_ANDROID)
bcwhited21e6ff2014-09-05 18:48:541064 // On Android, when a key is pressed or sent from the Keyboard using IME,
[email protected]25402eb2014-07-18 03:09:521065 // |AdapterInputConnection| generates input key events to make sure all JS
1066 // listeners that monitor KeyUp and KeyDown events receive the proper key
1067 // code. Since this input key event comes from IME, we need to set the
1068 // IME event guard here to make sure it does not interfere with other IME
1069 // events.
1070 scoped_ptr<ImeEventGuard> ime_event_guard_maybe;
1071 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1072 const WebKeyboardEvent& key_event =
1073 *static_cast<const WebKeyboardEvent*>(input_event);
bcwhited21e6ff2014-09-05 18:48:541074 // Some keys are special and it's essential that no events get blocked.
bcwhite5752e442014-10-07 00:05:171075 if (key_event.nativeKeyCode != AKEYCODE_TAB &&
bcwhite796d5ac2014-11-22 02:32:091076 key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER &&
1077 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT &&
1078 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT &&
1079 key_event.nativeKeyCode != AKEYCODE_DPAD_UP &&
1080 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN)
[email protected]25402eb2014-07-18 03:09:521081 ime_event_guard_maybe.reset(new ImeEventGuard(this));
[email protected]25402eb2014-07-18 03:09:521082 }
1083#endif
initial.commit09911bf2008-07-26 23:55:291084
[email protected]fd847792013-10-24 17:12:351085 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411086 if (base::TimeTicks::IsHighResolution())
1087 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351088
miletusfed8c43b2015-01-26 20:04:521089 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301090 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151091 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
yuhaoz8df9334c2015-08-18 17:48:511092 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1093 "LatencyInfo.Flow",
1094 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
1095 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1096 "step", "HandleInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101097
jdduke07788062014-12-05 03:16:301098 // If we don't have a high res timer, these metrics won't be accurate enough
1099 // to be worth collecting. Note that this does introduce some sampling bias.
1100 if (!start_time.is_null())
miletus14a25642015-08-13 19:23:231101 LogInputEventLatencyUma(*input_event, start_time, latency_info);
jdduke07788062014-12-05 03:16:301102
[email protected]6be422b2013-12-08 06:47:311103 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351104 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311105 if (compositor_) {
1106 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351107 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1108 .Pass();
[email protected]6be422b2013-12-08 06:47:311109 }
[email protected]c2eaa8f2013-05-10 02:41:551110
[email protected]67bfb83f2011-09-22 03:36:371111 bool prevent_default = false;
1112 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261113 const WebMouseEvent& mouse_event =
1114 *static_cast<const WebMouseEvent*>(input_event);
1115 TRACE_EVENT2("renderer", "HandleMouseMove",
1116 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421117 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261118 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371119 }
1120
[email protected]cefe9b152014-03-27 18:16:151121 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421122 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151123#if defined(OS_ANDROID)
1124 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1125 // case it should behave like a select key (i.e. causing a click if a button
1126 // is focused). However, if a text field is focused (2), its intended
1127 // behavior is to just show the IME and don't propagate the key.
1128 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1129 // when clicked on an input text field and cause the form submit if clicked
1130 // when the submit button is focused, but not vice-versa.
1131 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1132 // but at this point we have to swallow the event for the scenario (2).
1133 const WebKeyboardEvent& key_event =
1134 *static_cast<const WebKeyboardEvent*>(input_event);
1135 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1136 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1137 OnShowImeIfNeeded();
1138 prevent_default = true;
1139 }
1140#endif
1141 }
[email protected]f56c7872013-06-18 12:31:571142
[email protected]41d86852012-11-07 12:23:241143 if (WebInputEvent::isGestureEventType(input_event->type)) {
1144 const WebGestureEvent& gesture_event =
1145 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421146 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241147 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1148 }
1149
[email protected]67bfb83f2011-09-22 03:36:371150 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121151 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1152 suppress_next_char_events_ = false;
1153 if (!processed && webwidget_)
1154 processed = webwidget_->handleInputEvent(*input_event);
1155 }
1156
1157 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1158 // it's not processed by webkit, then we need to suppress the upcoming Char
1159 // events.
1160 if (!processed && is_keyboard_shortcut)
1161 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291162
[email protected]3d5c243b2012-11-30 00:26:011163 InputEventAckState ack_result = processed ?
1164 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1165 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1166 const WebTouchEvent& touch_event =
1167 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251168 // Hit-test for all the pressed touch points. If there is a touch-handler
1169 // for any of the touch points, then the renderer should continue to receive
1170 // touch events.
1171 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1172 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1173 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271174 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391175 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251176 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1177 break;
1178 }
1179 }
[email protected]3d5c243b2012-11-30 00:26:011180 }
1181
ccamerond4ba47902014-12-17 07:20:311182 // Send mouse wheel events and their disposition to the compositor thread, so
1183 // that they can be used to produce the elastic overscroll effect on Mac.
1184 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311185 ObserveWheelEventAndResult(
sataya.mf405d0e2015-07-07 16:51:111186 static_cast<const WebMouseWheelEvent&>(*input_event),
1187 event_overscroll ? event_overscroll->latest_overscroll_delta
1188 : gfx::Vector2dF(),
1189 processed);
ccamerond4ba47902014-12-17 07:20:311190 }
1191
[email protected]721e2302014-04-30 23:42:011192 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061193
charliea3be839702015-01-26 17:35:411194 // If we don't have a fast and accurate Now(), we assume the input handlers
1195 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301196 bool rate_limiting_wanted =
1197 input_event->type == WebInputEvent::MouseMove ||
1198 input_event->type == WebInputEvent::MouseWheel;
1199 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411200 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351201 total_input_handling_time_this_frame_ += (end_time - start_time);
1202 rate_limiting_wanted =
1203 total_input_handling_time_this_frame_.InMicroseconds() >
1204 kInputHandlingTimeThrottlingThresholdMicroseconds;
1205 }
1206
[email protected]7f19e9d2014-05-09 15:16:291207 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1208
[email protected]c27dd4f2014-05-22 18:05:191209 // Note that we can't use handling_event_type_ here since it will be overriden
1210 // by reentrant calls for events after the paused one.
1211 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1212 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101213 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1214 !no_ack) {
1215 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
jddukec05612b2015-06-25 23:13:181216 event_overscroll.Pass(),
lanweif1a22832015-05-19 17:24:101217 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551218 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561219 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301220 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551221 // We want to rate limit the input events in this case, so we'll wait for
1222 // painting to finish before ACKing this message.
1223 TRACE_EVENT_INSTANT0("renderer",
1224 "RenderWidget::OnHandleInputEvent ack throttled",
1225 TRACE_EVENT_SCOPE_THREAD);
1226 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291227 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1228 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551229 // As two different kinds of events could cause us to postpone an ack
1230 // we send it now, if we have one pending. The Browser should never
1231 // send us the same kind of event we are delaying the ack for.
1232 Send(pending_input_event_ack_.release());
1233 }
1234 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291235 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1236 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551237 if (compositor_)
1238 compositor_->NotifyInputThrottledUntilCommit();
1239 } else {
1240 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171241 }
jddukec05612b2015-06-25 23:13:181242 } else {
1243 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
[email protected]12fbad812009-09-01 18:21:241244 }
alexclarke7819e2552015-06-03 11:17:211245 if (!no_ack && RenderThreadImpl::current()) {
1246 RenderThreadImpl::current()
1247 ->GetRendererScheduler()
1248 ->DidHandleInputEventOnMainThread(*input_event);
1249 }
[email protected]5fea4a52014-05-27 00:17:521250 if (input_event->type == WebInputEvent::MouseMove)
1251 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241252
[email protected]3306f262012-09-21 19:20:421253#if defined(OS_ANDROID)
1254 // Allow the IME to be shown when the focus changes as a consequence
1255 // of a processed touch end event.
1256 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361257 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021258#elif defined(USE_AURA)
1259 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1260 // change.
1261 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141262 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361263 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141264 }
[email protected]3306f262012-09-21 19:20:421265#endif
1266
[email protected]67bfb83f2011-09-22 03:36:371267 if (!prevent_default) {
1268 if (WebInputEvent::isKeyboardEventType(input_event->type))
1269 DidHandleKeyEvent();
[email protected]67bfb83f2011-09-22 03:36:371270 }
rouslanf7ebd8832015-01-22 01:54:141271
1272// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1273// virtual keyboard.
1274#if !defined(OS_ANDROID)
1275 // Virtual keyboard is not supported, so react to focus change immediately.
1276 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1277 input_event->type == WebInputEvent::MouseUp)) {
1278 FocusChangeComplete();
1279 }
1280#endif
initial.commit09911bf2008-07-26 23:55:291281}
1282
[email protected]34202de2013-05-06 23:36:221283void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1284 if (webwidget_)
1285 webwidget_->setCursorVisibilityState(is_visible);
1286}
1287
initial.commit09911bf2008-07-26 23:55:291288void RenderWidget::OnMouseCaptureLost() {
1289 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281290 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291291}
1292
1293void RenderWidget::OnSetFocus(bool enable) {
1294 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331295 if (webwidget_)
1296 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291297}
1298
[email protected]fd847792013-10-24 17:12:351299void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291300 if (pending_input_event_ack_) {
1301 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1302 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071303 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291304 }
[email protected]fd847792013-10-24 17:12:351305 total_input_handling_time_this_frame_ = base::TimeDelta();
1306}
1307
initial.commit09911bf2008-07-26 23:55:291308///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461309// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291310
[email protected]244ac1892011-12-02 17:04:471311void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091312 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451313 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581314
[email protected]5b45ad42013-10-25 00:42:041315 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451316 WebRect new_pos(rootWindowRect().x,
1317 rootWindowRect().y,
1318 new_size.width,
1319 new_size.height);
1320 view_screen_rect_ = new_pos;
1321 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031322 }
[email protected]20fbfc22013-05-08 20:50:581323
[email protected]eac2b362013-05-22 07:01:451324 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581325
[email protected]5b45ad42013-10-25 00:42:041326 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581327 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091328 }
[email protected]244ac1892011-12-02 17:04:471329}
1330
[email protected]3a1c8a8032013-03-18 22:35:321331void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401332 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051333 if (compositor_)
1334 compositor_->setViewportSize(size_, physical_backing_size_);
1335}
1336
[email protected]e195e582013-03-08 01:32:591337void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221338 DCHECK(!host_closing_);
1339
danakj6e3bf8012014-12-16 18:27:531340 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
[email protected]e195e582013-03-08 01:32:591341 compositor_->setViewportSize(size_, physical_backing_size_);
pimanc4af3072015-10-02 03:45:591342 StartCompositor();
[email protected]e195e582013-03-08 01:32:591343}
1344
ennef3c58142014-12-09 21:44:381345void RenderWidget::WillCloseLayerTreeView() {
1346 if (host_closing_)
1347 return;
1348
1349 // Prevent new compositors or output surfaces from being created.
1350 host_closing_ = true;
1351
[email protected]aeeedad2014-08-22 18:16:221352 // Always send this notification to prevent new layer tree views from
1353 // being created, even if one hasn't been created yet.
1354 if (webwidget_)
1355 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221356}
1357
[email protected]180ef242013-11-07 06:50:461358blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281359 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061360}
1361
dglazkov79c426102015-08-31 21:22:431362void RenderWidget::didFirstVisuallyNonEmptyLayout() {
dglazkov79c426102015-08-31 21:22:431363 QueueMessage(
1364 new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1365 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1366}
1367
1368void RenderWidget::didFirstLayoutAfterFinishedParsing() {
1369 // TODO(dglazkov): Use this hook to drive CapturePageInfo.
1370}
1371
jdduke491a3f0c2015-06-15 23:30:261372void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561373 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371374
shuchen913f8b622015-07-31 13:22:431375 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371376 // enable GPU acceleration so they need to be called before any painting
1377 // is done.
[email protected]90f24152014-04-09 12:41:361378 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371379 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561380}
1381
[email protected]6fceb912013-02-15 06:24:151382void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441383 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1384 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271385 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161386 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171387#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271388 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1389 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171390#endif // defined(VIDEO_HOLE)
jdduke491a3f0c2015-06-15 23:30:261391 FlushPendingInputEventAck();
1392}
1393
1394void RenderWidget::DidCommitAndDrawCompositorFrame() {
1395 // NOTE: Tests may break if this event is renamed or moved. See
1396 // tab_capture_performancetest.cc.
1397 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1398 // Notify subclasses that we initiated the paint operation.
1399 DidInitiatePaint();
1400}
1401
1402void RenderWidget::DidCompleteSwapBuffers() {
1403 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1404
1405 // Notify subclasses threaded composited rendering was flushed to the screen.
1406 DidFlushPaint();
1407
1408 if (!next_paint_flags_ &&
1409 !need_update_rect_for_auto_resize_ &&
1410 !plugin_window_moves_.size()) {
1411 return;
1412 }
1413
1414 ViewHostMsg_UpdateRect_Params params;
1415 params.view_size = size_;
1416 params.plugin_window_moves.swap(plugin_window_moves_);
1417 params.flags = next_paint_flags_;
1418
1419 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1420 next_paint_flags_ = 0;
1421 need_update_rect_for_auto_resize_ = false;
1422}
1423
1424void RenderWidget::ScheduleComposite() {
1425 if (compositor_ &&
1426 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1427 compositor_->setNeedsAnimate();
1428 }
1429}
1430
1431void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1432 if (compositor_) {
1433 // Regardless of whether threaded compositing is enabled, always
1434 // use this mechanism to force the compositor to redraw. However,
1435 // the invalidation code path below is still needed for the
1436 // non-threaded case.
1437 compositor_->SetNeedsForcedRedraw();
1438 }
1439 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151440}
1441
[email protected]586871b2014-07-22 17:05:111442// static
1443scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1444 IPC::Message* msg,
1445 MessageDeliveryPolicy policy,
1446 FrameSwapMessageQueue* frame_swap_message_queue,
1447 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111448 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111449 bool first_message_for_frame = false;
1450 frame_swap_message_queue->QueueMessageForFrame(policy,
1451 source_frame_number,
1452 make_scoped_ptr(msg),
1453 &first_message_for_frame);
1454 if (first_message_for_frame) {
1455 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1456 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061457 return promise;
[email protected]586871b2014-07-22 17:05:111458 }
dcheng4b6b5ff2014-10-16 00:42:061459 return nullptr;
[email protected]586871b2014-07-22 17:05:111460}
1461
1462void RenderWidget::QueueMessage(IPC::Message* msg,
1463 MessageDeliveryPolicy policy) {
1464 // RenderThreadImpl::current() is NULL in some tests.
1465 if (!compositor_ || !RenderThreadImpl::current()) {
1466 Send(msg);
1467 return;
1468 }
1469
1470 scoped_ptr<cc::SwapPromise> swap_promise =
1471 QueueMessageImpl(msg,
1472 policy,
dcheng58867a92014-08-26 02:50:221473 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111474 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111475 compositor_->GetSourceFrameNumber());
1476
1477 if (swap_promise) {
1478 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351479 // Request a commit. This might either A) request a commit ahead of time
1480 // or B) request a commit which is not needed because there are not
1481 // pending updates. If B) then the commit will be skipped and the swap
1482 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1483 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1484 // can_cancel_commit is not unset.
1485 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111486 }
1487}
1488
[email protected]4873c7d2009-07-16 06:36:281489void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301490 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521491 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401492 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291493 // Only send a SetCursor message if we need to make a change.
1494 if (!current_cursor_.IsEqual(cursor)) {
1495 current_cursor_ = cursor;
1496 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1497 }
1498}
1499
1500// We are supposed to get a single call to Show for a newly created RenderWidget
1501// that was created via RenderWidget::CreateWebView. So, we wait until this
1502// point to dispatch the ShowWidget message.
1503//
1504// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281505// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291506//
[email protected]4873c7d2009-07-16 06:36:281507void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291508 DCHECK(!did_show_) << "received extraneous Show call";
1509 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1510 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1511
[email protected]8de12d942010-11-17 20:42:441512 if (did_show_)
1513 return;
1514
1515 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561516 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441517 // that's okay. It'll be ignored if as_popup is false, or the browser
1518 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561519 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1520 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291521}
1522
[email protected]4873c7d2009-07-16 06:36:281523void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291524}
1525
[email protected]4873c7d2009-07-16 06:36:281526void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291527}
1528
[email protected]2533ce12009-05-09 00:02:241529void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381530 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241531 Send(new ViewHostMsg_Close(routing_id_));
1532}
1533
dgozmancf9039cd2015-04-06 12:01:311534void RenderWidget::NotifyOnClose() {
1535 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1536}
1537
[email protected]4873c7d2009-07-16 06:36:281538void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081539 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321540 if (is_swapped_out_) {
1541 // This widget is currently swapped out, and the active widget is in a
1542 // different process. Have the browser route the close request to the
1543 // active widget instead, so that the correct unload handlers are run.
1544 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1545 return;
1546 }
1547
initial.commit09911bf2008-07-26 23:55:291548 // If a page calls window.close() twice, we'll end up here twice, but that's
1549 // OK. It is safe to send multiple Close messages.
1550
[email protected]2533ce12009-05-09 00:02:241551 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1552 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1553 // could be closed before the JS finishes executing. So instead, post a
1554 // message back to the message loop, which won't run until the JS is
1555 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081556 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211557 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291558}
1559
[email protected]9017d7852013-11-21 17:47:351560void RenderWidget::QueueSyntheticGesture(
1561 scoped_ptr<SyntheticGestureParams> gesture_params,
1562 const SyntheticGestureCompletionCallback& callback) {
1563 DCHECK(!callback.is_null());
1564
1565 pending_synthetic_gesture_callbacks_.push(callback);
1566
1567 SyntheticGesturePacket gesture_packet;
1568 gesture_packet.set_gesture_params(gesture_params.Pass());
1569
1570 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1571}
1572
initial.commit09911bf2008-07-26 23:55:291573void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031574 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381575 WillCloseLayerTreeView();
1576 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291577 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281578 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291579 webwidget_ = NULL;
1580 }
1581}
1582
[email protected]4873c7d2009-07-16 06:36:281583WebRect RenderWidget::windowRect() {
1584 if (pending_window_rect_count_)
1585 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241586
[email protected]80ad8622012-11-07 16:33:031587 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291588}
1589
[email protected]180ef242013-11-07 06:50:461590void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301591 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541592 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301593}
1594
[email protected]b2e4c70132013-10-03 02:07:511595void RenderWidget::setWindowRect(const WebRect& rect) {
bokanc007c3a2015-02-03 07:15:561596 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511597 if (popup_origin_scale_for_emulation_) {
1598 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561599 window_rect.x = popup_screen_origin_for_emulation_.x() +
1600 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1601 window_rect.y = popup_screen_origin_for_emulation_.y() +
1602 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511603 }
1604
[email protected]5b45ad42013-10-25 00:42:041605 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201606 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561607 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1608 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031609 } else {
bokanc007c3a2015-02-03 07:15:561610 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031611 }
initial.commit09911bf2008-07-26 23:55:291612 } else {
bokanc007c3a2015-02-03 07:15:561613 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291614 }
1615}
1616
[email protected]2533ce12009-05-09 00:02:241617void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1618 pending_window_rect_ = rect;
1619 pending_window_rect_count_++;
1620}
1621
[email protected]4873c7d2009-07-16 06:36:281622WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241623 if (pending_window_rect_count_) {
1624 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1625 // the RootWindowRect is probably going to return wrong results since the
1626 // browser may not have processed the Move yet. There isn't really anything
1627 // good to do in this case, and it shouldn't happen - since this size is
1628 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281629 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241630 }
1631
[email protected]80ad8622012-11-07 16:33:031632 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371633}
1634
[email protected]4873c7d2009-07-16 06:36:281635WebRect RenderWidget::windowResizerRect() {
1636 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191637}
1638
[email protected]fa7b1dc2010-06-23 17:53:041639void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261640 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041641 const std::vector<WebCompositionUnderline>& underlines,
1642 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131643 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281644 return;
[email protected]66fca5bc2013-05-23 06:58:291645 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361646 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041647 text, WebVector<WebCompositionUnderline>(underlines),
1648 selection_start, selection_end)) {
1649 // If we failed to set the composition text, then we need to let the browser
1650 // process to cancel the input method's ongoing composition session, to make
1651 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221652 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261653 }
[email protected]88dbe32f2013-06-20 23:31:361654 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041655}
1656
[email protected]fcf75d42013-12-03 20:11:261657void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511658 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021659 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131660 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041661 return;
[email protected]66fca5bc2013-05-23 06:58:291662 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041663 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021664 if (text.length())
1665 webwidget_->confirmComposition(text);
1666 else if (keep_selection)
1667 webwidget_->confirmComposition(WebWidget::KeepSelection);
1668 else
1669 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041670 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361671 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291672}
1673
[email protected]0bc1f572013-04-17 01:46:311674void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121675 // During shutdown we can just ignore this message.
1676 if (!webwidget_)
1677 return;
1678
[email protected]0bc1f572013-04-17 01:46:311679 // Even if the browser provides an empty damage rect, it's still expecting to
1680 // receive a repaint ack so just damage the entire widget bounds.
1681 if (size_to_paint.IsEmpty()) {
1682 size_to_paint = size_;
1683 }
1684
[email protected]ec7dc112008-08-06 05:30:121685 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051686 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311687 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121688}
1689
[email protected]79fa22e2013-08-23 15:18:121690void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351691 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1692
1693 pending_synthetic_gesture_callbacks_.front().Run();
1694 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271695}
1696
[email protected]4873c7d2009-07-16 06:36:281697void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111698 if (!webwidget_)
1699 return;
[email protected]4873c7d2009-07-16 06:36:281700 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111701}
1702
[email protected]80ad8622012-11-07 16:33:031703void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1704 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511705 if (screen_metrics_emulator_) {
1706 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1707 view_screen_rect, window_screen_rect);
1708 } else {
1709 view_screen_rect_ = view_screen_rect;
1710 window_screen_rect_ = window_screen_rect;
1711 }
[email protected]80ad8622012-11-07 16:33:031712 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1713}
1714
kenrbb4e2a3b2015-05-14 15:05:051715void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1716 if (compositor_)
1717 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1718}
1719
[email protected]adb362312014-06-28 06:04:241720void RenderWidget::showImeIfNeeded() {
1721 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131722}
1723
[email protected]adb362312014-06-28 06:04:241724void RenderWidget::OnShowImeIfNeeded() {
1725#if defined(OS_ANDROID) || defined(USE_AURA)
1726 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1727#endif
rouslanf7ebd8832015-01-22 01:54:141728
1729// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1730// virtual keyboard.
1731#if !defined(OS_ANDROID)
1732 FocusChangeComplete();
1733#endif
[email protected]adb362312014-06-28 06:04:241734}
1735
1736#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371737void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1738 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131739}
1740
1741void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371742 DCHECK_GE(text_input_info_history_.size(), 1u);
1743 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511744}
[email protected]105dffb42013-02-20 03:46:211745#endif
1746
[email protected]0d1ebed12013-08-05 22:01:131747bool RenderWidget::ShouldHandleImeEvent() {
1748#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371749 if (!webwidget_)
1750 return false;
1751
1752 // We cannot handle IME events if there is any chance that the event we are
1753 // receiving here from the browser is based on the state that is different
1754 // from our current one as indicated by |text_input_info_|.
1755 // The states the browser might be in are:
1756 // text_input_info_history_[0] - current state ack'd by browser
1757 // text_input_info_history_[1...N] - pending state changes
1758 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1759 if (text_input_info_history_[i] != text_input_info_)
1760 return false;
1761 }
1762 return true;
[email protected]0d1ebed12013-08-05 22:01:131763#else
1764 return !!webwidget_;
1765#endif
1766}
1767
[email protected]c27dd4f2014-05-22 18:05:191768bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1769 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521770 // If we pause multiple times during a single mouse move event, we should
1771 // only send ACK once.
1772 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101773 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521774 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021775 return true;
[email protected]5fea4a52014-05-27 00:17:521776 }
[email protected]c27dd4f2014-05-22 18:05:191777 }
1778 return false;
1779}
1780
1781void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1782 ignore_ack_for_mouse_move_from_debugger_ = true;
1783}
1784
[email protected]468ac582012-11-20 00:53:191785void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1786 if (device_scale_factor_ == device_scale_factor)
1787 return;
1788
1789 device_scale_factor_ = device_scale_factor;
jdduke491a3f0c2015-06-15 23:30:261790 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191791}
1792
[email protected]28ed6b32014-06-08 02:16:271793bool RenderWidget::SetDeviceColorProfile(
1794 const std::vector<char>& color_profile) {
1795 if (device_color_profile_ == color_profile)
1796 return false;
1797
1798 device_color_profile_ = color_profile;
1799 return true;
1800}
1801
noeldb4df152014-09-16 17:45:201802void RenderWidget::ResetDeviceColorProfileForTesting() {
1803 if (!device_color_profile_.empty())
1804 device_color_profile_.clear();
1805 device_color_profile_.push_back('0');
1806}
1807
[email protected]fcdc5642014-05-09 14:32:241808void RenderWidget::OnOrientationChange() {
1809}
1810
[email protected]ceb36f7d2012-10-31 18:33:241811gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521812 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241813 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521814}
1815
[email protected]bee16aab2009-08-26 15:55:031816void RenderWidget::SetHidden(bool hidden) {
1817 if (is_hidden_ == hidden)
1818 return;
1819
jdduke8fac9d102014-12-20 02:40:131820 // The status has changed. Tell the RenderThread about it and ensure
1821 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031822 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131823 FlushPendingInputEventAck();
1824
[email protected]bee16aab2009-08-26 15:55:031825 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001826 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031827 else
[email protected]b2db9272014-01-10 17:42:001828 RenderThreadImpl::current()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031829}
1830
[email protected]2b624c562011-10-27 22:58:261831void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261832 if (!webwidget_)
1833 return;
1834
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121835 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261836 webwidget_->didEnterFullScreen();
1837 } else {
1838 webwidget_->didExitFullScreen();
1839 }
[email protected]2b624c562011-10-27 22:58:261840}
1841
[email protected]674741932009-02-04 23:44:461842bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051843 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461844}
1845
[email protected]674741932009-02-04 23:44:461846void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051847 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461848}
1849
[email protected]674741932009-02-04 23:44:461850void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051851 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461852}
1853
[email protected]b18583c2012-12-18 06:55:271854static bool IsDateTimeInput(ui::TextInputType type) {
1855 return type == ui::TEXT_INPUT_TYPE_DATE ||
1856 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1857 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1858 type == ui::TEXT_INPUT_TYPE_MONTH ||
1859 type == ui::TEXT_INPUT_TYPE_TIME ||
1860 type == ui::TEXT_INPUT_TYPE_WEEK;
1861}
1862
[email protected]66fca5bc2013-05-23 06:58:291863
1864void RenderWidget::StartHandlingImeEvent() {
1865 DCHECK(!handling_ime_event_);
1866 handling_ime_event_ = true;
1867}
1868
1869void RenderWidget::FinishHandlingImeEvent() {
1870 DCHECK(handling_ime_event_);
1871 handling_ime_event_ = false;
1872 // While handling an ime event, text input state and selection bounds updates
1873 // are ignored. These must explicitly be updated once finished handling the
1874 // ime event.
1875 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471876#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:361877 UpdateTextInputState(NO_SHOW_IME, FROM_IME);
[email protected]cb9e2632013-06-18 11:26:471878#endif
[email protected]66fca5bc2013-05-23 06:58:291879}
1880
[email protected]90f24152014-04-09 12:41:361881void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1882 ChangeSource change_source) {
jdduke1aebad8e2015-07-22 23:25:081883 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
[email protected]e8f775f2013-02-14 21:00:501884 if (handling_ime_event_)
1885 return;
[email protected]ad26ef42011-06-17 07:59:451886 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271887 if (IsDateTimeInput(new_type))
1888 return; // Not considered as a text input field in WebKit/Chromium.
1889
[email protected]180ef242013-11-07 06:50:461890 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211891 if (webwidget_)
1892 new_info = webwidget_->textInputInfo();
shuchen913f8b622015-07-31 13:22:431893 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
[email protected]5b739cb2012-08-21 20:35:211894
[email protected]ad26ef42011-06-17 07:59:451895 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211896
[email protected]3306f262012-09-21 19:20:421897 // Only sends text input params if they are changed or if the ime should be
1898 // shown.
[email protected]90f24152014-04-09 12:41:361899 if (show_ime == SHOW_IME_IF_NEEDED ||
1900 (text_input_type_ != new_type ||
shuchen913f8b622015-07-31 13:22:431901 text_input_mode_ != new_mode ||
[email protected]90f24152014-04-09 12:41:361902 text_input_info_ != new_info ||
1903 can_compose_inline_ != new_can_compose_inline)
1904#if defined(OS_ANDROID)
1905 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021906#endif
[email protected]90f24152014-04-09 12:41:361907 ) {
shuchen913f8b622015-07-31 13:22:431908 ViewHostMsg_TextInputState_Params params;
1909 params.type = new_type;
1910 params.mode = new_mode;
1911 params.flags = new_info.flags;
1912 params.value = new_info.value.utf8();
1913 params.selection_start = new_info.selectionStart;
1914 params.selection_end = new_info.selectionEnd;
1915 params.composition_start = new_info.compositionStart;
1916 params.composition_end = new_info.compositionEnd;
1917 params.can_compose_inline = new_can_compose_inline;
1918 params.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
[email protected]90f24152014-04-09 12:41:361919#if defined(USE_AURA)
shuchen913f8b622015-07-31 13:22:431920 params.is_non_ime_change = true;
[email protected]90f24152014-04-09 12:41:361921#endif
[email protected]183e28d2014-01-20 18:18:021922#if defined(OS_ANDROID)
shuchen913f8b622015-07-31 13:22:431923 params.is_non_ime_change = (change_source == FROM_NON_IME) ||
[email protected]90f24152014-04-09 12:41:361924 text_field_is_dirty_;
shuchen913f8b622015-07-31 13:22:431925 if (params.is_non_ime_change)
changwan3a841162015-08-11 02:53:371926 OnImeEventSentForAck(new_info);
[email protected]90f24152014-04-09 12:41:361927 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021928#endif
shuchen913f8b622015-07-31 13:22:431929 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
[email protected]5b739cb2012-08-21 20:35:211930
1931 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041932 text_input_type_ = new_type;
shuchen913f8b622015-07-31 13:22:431933 text_input_mode_ = new_mode;
[email protected]ad26ef42011-06-17 07:59:451934 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201935 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291936 }
initial.commit09911bf2008-07-26 23:55:291937}
1938
[email protected]7c8873e2013-02-05 08:03:011939void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1940 WebRect focus_webrect;
1941 WebRect anchor_webrect;
1942 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
1943 *focus = focus_webrect;
1944 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:321945}
1946
[email protected]e99ef6f2011-10-16 01:13:001947void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:081948 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:001949 if (!webwidget_)
1950 return;
[email protected]66fca5bc2013-05-23 06:58:291951 if (handling_ime_event_)
1952 return;
[email protected]e99ef6f2011-10-16 01:13:001953
mohsenb0eeba72015-08-09 06:20:081954#if defined(USE_AURA)
1955 // TODO(mohsen): For now, always send explicit selection IPC notifications for
1956 // Aura beucause composited selection updates are not working for webview tags
1957 // which regresses IME inside webview. Remove this when composited selection
1958 // updates are fixed for webviews. See, http://crbug.com/510568.
1959 bool send_ipc = true;
1960#else
jddukeacf809e2014-09-23 20:38:381961 // With composited selection updates, the selection bounds will be reported
1962 // directly by the compositor, in which case explicit IPC selection
1963 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:081964 bool send_ipc =
1965 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
1966#endif
1967 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:381968 ViewHostMsg_SelectionBounds_Params params;
1969 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
1970 if (selection_anchor_rect_ != params.anchor_rect ||
1971 selection_focus_rect_ != params.focus_rect) {
1972 selection_anchor_rect_ = params.anchor_rect;
1973 selection_focus_rect_ = params.focus_rect;
1974 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
1975 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
1976 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
1977 }
[email protected]58b48a0d2012-06-13 07:01:351978 }
jddukeacf809e2014-09-23 20:38:381979
[email protected]88dbe32f2013-06-20 23:31:361980 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:001981}
1982
[email protected]180ef242013-11-07 06:50:461983// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:171984#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
1985 static_assert(int(blink::WebTextInputType##a) \
1986 == int(ui::TEXT_INPUT_TYPE_##b), \
1987 "mismatching enums: " #a)
1988
1989STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
1990STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
1991STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
1992STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
1993STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
1994STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
1995STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
1996STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
1997STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
1998STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
1999STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2000STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2001STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2002STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2003STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2004STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2005STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452006
[email protected]5b739cb2012-08-21 20:35:212007ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462008 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212009 // Check the type is in the range representable by ui::TextInputType.
2010 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462011 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212012 return static_cast<ui::TextInputType>(type);
2013}
2014
[email protected]ad26ef42011-06-17 07:59:452015ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272016 if (webwidget_)
jdduke3bf083fe2015-09-29 23:40:532017 return WebKitToUiTextInputType(webwidget_->textInputType());
[email protected]ad26ef42011-06-17 07:59:452018 return ui::TEXT_INPUT_TYPE_NONE;
2019}
2020
[email protected]501ea13d2013-07-09 17:03:292021void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302022#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112023 // TODO(yukawa): Start sending character bounds when the browser side
2024 // implementation becomes ready (crbug.com/424866).
2025#else
jdduke1aebad8e2015-07-22 23:25:082026 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
[email protected]db4fc1e2013-09-06 20:01:512027 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292028 if (should_update_range) {
2029 GetCompositionRange(&range);
2030 } else {
2031 range = composition_range_;
2032 }
2033 std::vector<gfx::Rect> character_bounds;
2034 GetCompositionCharacterBounds(&character_bounds);
2035
2036 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2037 return;
2038 composition_character_bounds_ = character_bounds;
2039 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222040 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292041 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112042#endif
[email protected]501ea13d2013-07-09 17:03:292043}
2044
[email protected]58b48a0d2012-06-13 07:01:352045void RenderWidget::GetCompositionCharacterBounds(
2046 std::vector<gfx::Rect>* bounds) {
2047 DCHECK(bounds);
2048 bounds->clear();
2049}
2050
[email protected]db4fc1e2013-09-06 20:01:512051void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362052 size_t location, length;
2053 if (webwidget_->compositionRange(&location, &length)) {
2054 range->set_start(location);
2055 range->set_end(location + length);
2056 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2057 range->set_start(location);
2058 range->set_end(location + length);
2059 } else {
[email protected]db4fc1e2013-09-06 20:01:512060 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362061 }
2062}
2063
[email protected]501ea13d2013-07-09 17:03:292064bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512065 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292066 const std::vector<gfx::Rect>& bounds) {
2067 if (composition_range_ != range)
2068 return true;
2069 if (bounds.size() != composition_character_bounds_.size())
2070 return true;
2071 for (size_t i = 0; i < bounds.size(); ++i) {
2072 if (bounds[i] != composition_character_bounds_[i])
2073 return true;
2074 }
2075 return false;
2076}
[email protected]501ea13d2013-07-09 17:03:292077
[email protected]a4f0d882014-05-01 23:48:102078#if defined(OS_ANDROID)
timav7a5032e2014-12-05 01:59:432079bool RenderWidget::DoesRecordFullLayer() const {
boliu15ca2652015-09-04 23:33:402080 return false;
timav7a5032e2014-12-05 01:59:432081}
[email protected]a4f0d882014-05-01 23:48:102082#endif
2083
[email protected]ad26ef42011-06-17 07:59:452084bool RenderWidget::CanComposeInline() {
2085 return true;
[email protected]56ea1a62011-05-30 07:05:572086}
2087
[email protected]4873c7d2009-07-16 06:36:282088WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042089 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282090}
2091
[email protected]f660d9c2012-06-06 18:31:212092float RenderWidget::deviceScaleFactor() {
2093 return device_scale_factor_;
2094}
2095
[email protected]fa7b1dc2010-06-23 17:53:042096void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022097 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042098 // If the last text input type is not None, then we should finish any
2099 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452100 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042101 // If a composition text exists, then we need to let the browser process
2102 // to cancel the input method's ongoing composition session.
2103 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222104 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042105 }
[email protected]d4cff272011-05-02 15:46:012106
[email protected]88dbe32f2013-06-20 23:31:362107 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042108}
2109
donnda070f3c2015-01-16 19:54:112110#if defined(OS_ANDROID)
2111void RenderWidget::showUnhandledTapUIIfNeeded(
2112 const WebPoint& tapped_position,
2113 const WebNode& tapped_node,
2114 bool page_changed) {
2115 DCHECK(handling_input_event_);
2116 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372117 !tapped_node.isContentEditable() &&
2118 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112119 if (should_trigger) {
2120 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2121 tapped_position.x, tapped_position.y));
2122 }
2123}
2124#endif
2125
[email protected]c68c3e4e2013-01-24 00:36:562126void RenderWidget::didHandleGestureEvent(
2127 const WebGestureEvent& event,
2128 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022129#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562130 if (event_cancelled)
2131 return;
[email protected]07c70d22014-08-21 08:33:462132 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362133 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462134 } else if (event.type == WebInputEvent::GestureLongPress) {
2135 DCHECK(webwidget_);
2136 if (webwidget_->textInputInfo().value.isEmpty())
2137 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2138 else
2139 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562140 }
2141#endif
2142}
2143
sataya.m582c9ce2015-06-09 08:03:422144void RenderWidget::didOverscroll(
2145 const blink::WebFloatSize& unusedDelta,
2146 const blink::WebFloatSize& accumulatedRootOverScroll,
2147 const blink::WebFloatPoint& position,
2148 const blink::WebFloatSize& velocity) {
2149 DidOverscrollParams params;
sataya.m582c9ce2015-06-09 08:03:422150 params.accumulated_overscroll = gfx::Vector2dF(
2151 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2152 params.latest_overscroll_delta =
2153 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
sataya.ma5cc13a2015-06-13 11:06:022154 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2155 // fixed.
sataya.m582c9ce2015-06-09 08:03:422156 params.current_fling_velocity =
sataya.ma5cc13a2015-06-13 11:06:022157 gfx::Vector2dF(-velocity.width, -velocity.height);
sataya.m582c9ce2015-06-09 08:03:422158 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
jddukec05612b2015-06-25 23:13:182159
2160 // If we're currently handling an event, stash the overscroll data such that
2161 // it can be bundled in the event ack.
2162 if (handling_event_overscroll_) {
2163 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2164 return;
2165 }
2166
sataya.m582c9ce2015-06-09 08:03:422167 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2168}
2169
[email protected]7912e822014-04-16 02:37:032170void RenderWidget::StartCompositor() {
2171 // For widgets that are never visible, we don't need the compositor to run
2172 // at all.
2173 if (never_visible_)
2174 return;
danakj6e3bf8012014-12-16 18:27:532175 // In tests without a RenderThreadImpl, don't set ready as this kicks
2176 // off creating output surfaces that the test can't create.
2177 if (!RenderThreadImpl::current())
2178 return;
danakj018271e32014-12-16 21:17:262179 compositor_->StartCompositor();
[email protected]7912e822014-04-16 02:37:032180}
2181
[email protected]29e2fb42013-07-19 01:13:472182void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292183 size_t i = 0;
2184 for (; i < plugin_window_moves_.size(); ++i) {
2185 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582186 if (move.rects_valid) {
2187 plugin_window_moves_[i] = move;
2188 } else {
2189 plugin_window_moves_[i].visible = move.visible;
2190 }
initial.commit09911bf2008-07-26 23:55:292191 break;
2192 }
2193 }
2194
2195 if (i == plugin_window_moves_.size())
2196 plugin_window_moves_.push_back(move);
2197}
[email protected]268654772009-08-06 23:02:042198
2199void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2200 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2201 i != plugin_window_moves_.end(); ++i) {
2202 if (i->window == window) {
2203 plugin_window_moves_.erase(i);
2204 break;
2205 }
2206 }
2207}
[email protected]67bfb83f2011-09-22 03:36:372208
[email protected]63b465922012-09-06 02:04:522209
[email protected]24ed0432013-04-24 07:50:312210RenderWidgetCompositor* RenderWidget::compositor() const {
2211 return compositor_.get();
2212}
2213
[email protected]180ef242013-11-07 06:50:462214bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372215 return false;
2216}
[email protected]c3d45532011-10-07 19:20:402217
[email protected]41d86852012-11-07 12:23:242218bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462219 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242220 return false;
2221}
2222
ccamerona7644752014-12-30 01:16:312223void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312224 const blink::WebMouseWheelEvent& wheel_event,
sataya.mf405d0e2015-07-07 16:51:112225 const gfx::Vector2dF& wheel_unused_delta,
ccamerond4ba47902014-12-17 07:20:312226 bool event_processed) {
ccamerona7644752014-12-30 01:16:312227 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312228 return;
2229
ccamerond4ba47902014-12-17 07:20:312230 cc::InputHandlerScrollResult scroll_result;
sataya.mf405d0e2015-07-07 16:51:112231 scroll_result.did_scroll = event_processed;
2232 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
2233 scroll_result.unused_scroll_delta = wheel_unused_delta;
ccamerond4ba47902014-12-17 07:20:312234
2235 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2236 InputHandlerManager* input_handler_manager =
2237 render_thread ? render_thread->input_handler_manager() : NULL;
2238 if (input_handler_manager) {
2239 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2240 routing_id_, wheel_event, scroll_result);
2241 }
2242}
2243
[email protected]ce6689f2013-03-29 12:52:552244void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2245 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2246}
2247
mostynbe29b6882015-01-13 09:59:172248// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2249#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2250 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2251 "mismatching enums: " #a)
2252
dtapuskaa98ac8d72015-05-08 19:29:092253inline content::TouchAction& operator|=(content::TouchAction& a,
2254 content::TouchAction b) {
2255 a = static_cast<content::TouchAction>(static_cast<int>(a) |
2256 static_cast<int>(b));
2257 return a;
2258}
2259
[email protected]5d0bbdfa92013-12-10 00:35:512260void RenderWidget::setTouchAction(
2261 blink::WebTouchAction web_touch_action) {
2262
2263 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2264 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192265 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512266 return;
2267
dtapuskaa98ac8d72015-05-08 19:29:092268 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172269 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
2270 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092271 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2272 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172273 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092274 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2275 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172276 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
2277 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
[email protected]a18f67a2013-12-20 19:44:362278
2279 content::TouchAction content_touch_action =
2280 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512281 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2282}
2283
[email protected]90f24152014-04-09 12:41:362284void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2285#if defined(OS_ANDROID)
2286 text_field_is_dirty_ = true;
2287#endif
2288}
2289
[email protected]3d5c243b2012-11-30 00:26:012290bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2291 return true;
2292}
2293
[email protected]0634cdd42013-08-16 00:46:092294scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012295RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592296 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092297 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492298 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222299 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092300 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292301 if (!RenderThreadImpl::current())
2302 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402303 CauseForGpuLaunch cause =
2304 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292305 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402306 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222307 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292308 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592309
[email protected]828a3932014-04-02 14:43:132310 // Explicitly disable antialiasing for the compositor. As of the time of
2311 // this writing, the only platform that supported antialiasing for the
2312 // compositor was Mac OS X, because the on-screen OpenGL context creation
2313 // code paths on Windows and Linux didn't yet have multisampling support.
2314 // Mac OS X essentially always behaves as though it's rendering offscreen.
2315 // Multisampling has a heavy cost especially on devices with relatively low
2316 // fill rate like most notebooks, and the Mac implementation would need to
2317 // be optimized to resolve directly into the IOSurface shared between the
2318 // GPU and browser processes. For these reasons and to avoid platform
2319 // disparities we explicitly disable antialiasing.
2320 blink::WebGraphicsContext3D::Attributes attributes;
2321 attributes.antialias = false;
2322 attributes.shareResources = true;
2323 attributes.noAutomaticFlushes = true;
2324 attributes.depth = false;
2325 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132326 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292327 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012328#if defined(OS_ANDROID)
2329 // If we raster too fast we become upload bound, and pending
2330 // uploads consume memory. For maximum upload throughput, we would
2331 // want to allow for upload_throughput * pipeline_time of pending
2332 // uploads, after which we are just wasting memory. Since we don't
2333 // know our upload throughput yet, this just caps our memory usage.
2334 size_t divider = 1;
[email protected]35b4f0c2014-06-26 16:55:272335 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032336 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012337 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032338 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012339 // Deadline to draw a frame to achieve 60 frames per second.
2340 const size_t kMillisecondsPerFrame = 16;
2341 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032342 size_t max_transfer_buffer_usage_mb =
2343 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2344 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012345 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2346 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292347 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032348 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012349#endif
jbauman00ca2dc2015-08-10 23:21:152350 if (compositor) {
jbauman5e420d32015-08-05 09:33:012351 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152352 limits.start_transfer_buffer_size = 64 * 1024;
2353 limits.min_transfer_buffer_size = 64 * 1024;
2354 }
[email protected]96ab016c2013-10-23 00:50:292355
piman5d36dae2015-09-24 22:47:052356 // TODO(piman): we still need to create a View command buffer until
2357 // crbug.com/526196 is fixed. The surface_id doesn't matter, it just needs to
2358 // be !0.
2359 const int32 kDummySurfaceId = 1;
[email protected]96ab016c2013-10-23 00:50:292360 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
piman5d36dae2015-09-24 22:47:052361 new WebGraphicsContext3DCommandBufferImpl(
2362 kDummySurfaceId, GetURLForGraphicsContext3D(),
2363 gpu_channel_host.get(), attributes, lose_context_when_out_of_memory,
2364 limits, NULL));
[email protected]0634cdd42013-08-16 00:46:092365 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592366}
2367
[email protected]e3244ed2014-06-20 20:04:272368void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2369 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162370}
2371
[email protected]e3244ed2014-06-20 20:04:272372void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2373 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162374}
2375
[email protected]de3c5d82014-05-28 22:12:592376void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2377 render_frames_.AddObserver(frame);
2378}
2379
2380void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2381 render_frames_.RemoveObserver(frame);
2382}
2383
[email protected]a017938b2014-05-27 21:17:172384#if defined(VIDEO_HOLE)
2385void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2386 video_hole_frames_.AddObserver(frame);
2387}
2388
2389void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2390 video_hole_frames_.RemoveObserver(frame);
2391}
2392#endif // defined(VIDEO_HOLE)
2393
[email protected]e9ff79c2012-10-19 21:31:262394} // namespace content