blob: 10eff2c6a1c5844034937991ca8ab73a7b6c907b [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"
alexclarke7fa93942015-10-21 15:37:1125#include "components/scheduler/renderer/render_widget_scheduling_state.h"
alexclarke7819e2552015-06-03 11:17:2126#include "components/scheduler/renderer/renderer_scheduler.h"
[email protected]29e2fb42013-07-19 01:13:4727#include "content/child/npapi/webplugin.h"
oshima750cb4342015-10-31 00:59:0128#include "content/common/content_switches_internal.h"
[email protected]0634cdd42013-08-16 00:46:0929#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5930#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]96ab016c2013-10-23 00:50:2931#include "content/common/gpu/gpu_process_launch_causes.h"
[email protected]9017d7852013-11-21 17:47:3532#include "content/common/input/synthetic_gesture_packet.h"
[email protected]8e299aa2013-10-16 18:17:4433#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1534#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1535#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5036#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2937#include "content/public/common/content_switches.h"
[email protected]a09d53ce2014-01-31 00:46:4238#include "content/public/common/context_menu_params.h"
[email protected]953bd0062013-08-01 00:58:4039#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5140#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5941#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]36e5ff12013-06-11 12:19:2942#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]586871b2014-07-22 17:05:1143#include "content/renderer/gpu/frame_swap_message_queue.h"
[email protected]ed7defa2013-03-12 21:29:5944#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]586871b2014-07-22 17:05:1145#include "content/renderer/gpu/queue_message_swap_promise.h"
[email protected]ba91a792013-02-06 09:48:2846#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2947#include "content/renderer/ime_event_guard.h"
[email protected]7a72d452013-12-13 10:01:1348#include "content/renderer/input/input_handler_manager.h"
[email protected]adab2332013-07-25 18:04:3249#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]bffc8302014-01-23 20:52:1650#include "content/renderer/render_frame_impl.h"
[email protected]e3244ed2014-06-20 20:04:2751#include "content/renderer/render_frame_proxy.h"
[email protected]8704f89b2011-04-15 00:30:0552#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4453#include "content/renderer/render_thread_impl.h"
dcheng3ce04b62015-10-26 23:30:5554#include "content/renderer/render_view_impl.h"
tfarina556a7232014-10-05 01:02:0955#include "content/renderer/renderer_blink_platform_impl.h"
[email protected]5b45ad42013-10-25 00:42:0456#include "content/renderer/resizing_mode_selector.h"
[email protected]484955942010-08-19 16:13:1857#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4858#include "skia/ext/platform_canvas.h"
[email protected]ec173b522013-11-14 11:01:1859#include "third_party/WebKit/public/platform/WebCursorInfo.h"
[email protected]aaf68892013-07-18 00:11:3060#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
donnda070f3c2015-01-16 19:54:1161#include "third_party/WebKit/public/platform/WebPoint.h"
[email protected]aaf68892013-07-18 00:11:3062#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]ec173b522013-11-14 11:01:1863#include "third_party/WebKit/public/platform/WebScreenInfo.h"
[email protected]aaf68892013-07-18 00:11:3064#include "third_party/WebKit/public/platform/WebSize.h"
65#include "third_party/WebKit/public/platform/WebString.h"
[email protected]19193682014-04-03 15:01:4366#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
kenrba7199832015-01-22 23:44:5967#include "third_party/WebKit/public/web/WebFrameWidget.h"
68#include "third_party/WebKit/public/web/WebLocalFrame.h"
donnda070f3c2015-01-16 19:54:1169#include "third_party/WebKit/public/web/WebNode.h"
[email protected]2255a9332013-06-17 05:12:3170#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]2255a9332013-06-17 05:12:3171#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
72#include "third_party/WebKit/public/web/WebRange.h"
jddukeacf809e2014-09-23 20:38:3873#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
kenrba7199832015-01-22 23:44:5974#include "third_party/WebKit/public/web/WebView.h"
[email protected]d353541f2012-05-03 22:45:4175#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1376#include "ui/base/ui_base_switches.h"
tfarina655f81d2014-12-23 02:38:5077#include "ui/gfx/geometry/point_conversions.h"
tfarina3b0452d2014-12-31 15:20:0978#include "ui/gfx/geometry/rect_conversions.h"
tfarinaebe974f02015-01-03 04:25:3279#include "ui/gfx/geometry/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4880#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2781#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4182#include "ui/surface/transport_dib.h"
[email protected]661eb9d2009-02-03 02:11:4883
[email protected]eeb93112013-05-01 19:41:1084#if defined(OS_ANDROID)
[email protected]cefe9b152014-03-27 18:16:1585#include <android/keycodes.h>
[email protected]913d99a2013-05-31 07:16:0786#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1087#endif
88
[email protected]661eb9d2009-02-03 02:11:4889#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4990#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5291#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4192#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4893#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4494
[email protected]2255a9332013-06-17 05:12:3195#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2996
[email protected]180ef242013-11-07 06:50:4697using blink::WebCompositionUnderline;
98using blink::WebCursorInfo;
[email protected]19193682014-04-03 15:01:4399using blink::WebDeviceEmulationParams;
[email protected]180ef242013-11-07 06:50:46100using blink::WebGestureEvent;
101using blink::WebInputEvent;
102using blink::WebKeyboardEvent;
103using blink::WebMouseEvent;
104using blink::WebMouseWheelEvent;
105using blink::WebNavigationPolicy;
donnda070f3c2015-01-16 19:54:11106using blink::WebNode;
[email protected]180ef242013-11-07 06:50:46107using blink::WebPagePopup;
donnda070f3c2015-01-16 19:54:11108using blink::WebPoint;
[email protected]180ef242013-11-07 06:50:46109using blink::WebPopupType;
110using blink::WebRange;
111using blink::WebRect;
112using blink::WebScreenInfo;
113using blink::WebSize;
114using blink::WebTextDirection;
115using blink::WebTouchEvent;
[email protected]f8ed4722013-12-03 03:27:25116using blink::WebTouchPoint;
[email protected]180ef242013-11-07 06:50:46117using blink::WebVector;
118using blink::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26119
[email protected]6a4d7f62013-01-07 21:32:13120namespace {
[email protected]b256eca2013-07-11 10:57:40121
122typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
123
124class TextInputModeMapSingleton {
125 public:
126 static TextInputModeMapSingleton* GetInstance() {
olli.raula36aa8be2015-09-10 11:14:22127 return base::Singleton<TextInputModeMapSingleton>::get();
[email protected]b256eca2013-07-11 10:57:40128 }
[email protected]dd705d4d2013-11-27 08:14:41129 TextInputModeMapSingleton() {
130 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
131 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN;
132 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
133 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
134 map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
135 map_["kana"] = ui::TEXT_INPUT_MODE_KANA;
136 map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
137 map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
138 map_["tel"] = ui::TEXT_INPUT_MODE_TEL;
139 map_["email"] = ui::TEXT_INPUT_MODE_EMAIL;
140 map_["url"] = ui::TEXT_INPUT_MODE_URL;
[email protected]b256eca2013-07-11 10:57:40141 }
[email protected]dd705d4d2013-11-27 08:14:41142 const TextInputModeMap& map() const { return map_; }
[email protected]b256eca2013-07-11 10:57:40143 private:
[email protected]dd705d4d2013-11-27 08:14:41144 TextInputModeMap map_;
[email protected]b256eca2013-07-11 10:57:40145
olli.raula36aa8be2015-09-10 11:14:22146 friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>;
[email protected]b256eca2013-07-11 10:57:40147
148 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
149};
150
[email protected]dd705d4d2013-11-27 08:14:41151ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) {
[email protected]b256eca2013-07-11 10:57:40152 static TextInputModeMapSingleton* singleton =
153 TextInputModeMapSingleton::GetInstance();
[email protected]dd705d4d2013-11-27 08:14:41154 TextInputModeMap::const_iterator it =
155 singleton->map().find(input_mode.utf8());
156 if (it == singleton->map().end())
[email protected]b256eca2013-07-11 10:57:40157 return ui::TEXT_INPUT_MODE_DEFAULT;
158 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13159}
[email protected]b256eca2013-07-11 10:57:40160
[email protected]fd847792013-10-24 17:12:35161// TODO(brianderson): Replace the hard-coded threshold with a fraction of
162// the BeginMainFrame interval.
163// 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to
164// be spent in input hanlders before input starts getting throttled.
165const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166;
166
miletus14a25642015-08-13 19:23:23167int64 GetEventLatencyMicros(double event_timestamp, base::TimeTicks now) {
168 return (now - base::TimeDelta::FromSecondsD(event_timestamp))
jdduke07788062014-12-05 03:16:30169 .ToInternalValue();
170}
171
miletus14a25642015-08-13 19:23:23172void LogInputEventLatencyUmaImpl(WebInputEvent::Type event_type,
173 double event_timestamp,
174 base::TimeTicks now) {
175 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.AggregatedLatency.Renderer2",
176 GetEventLatencyMicros(event_timestamp, now), 1,
177 10000000, 100);
jdduke07788062014-12-05 03:16:30178
miletus14a25642015-08-13 19:23:23179#define CASE_TYPE(t) \
180 case WebInputEvent::t: \
181 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer2." #t, \
182 GetEventLatencyMicros(event_timestamp, now), \
183 1, 10000000, 100); \
184 break;
jdduke07788062014-12-05 03:16:30185
miletus14a25642015-08-13 19:23:23186 switch (event_type) {
jdduke07788062014-12-05 03:16:30187 CASE_TYPE(Undefined);
188 CASE_TYPE(MouseDown);
189 CASE_TYPE(MouseUp);
190 CASE_TYPE(MouseMove);
191 CASE_TYPE(MouseEnter);
192 CASE_TYPE(MouseLeave);
193 CASE_TYPE(ContextMenu);
194 CASE_TYPE(MouseWheel);
195 CASE_TYPE(RawKeyDown);
196 CASE_TYPE(KeyDown);
197 CASE_TYPE(KeyUp);
198 CASE_TYPE(Char);
199 CASE_TYPE(GestureScrollBegin);
200 CASE_TYPE(GestureScrollEnd);
201 CASE_TYPE(GestureScrollUpdate);
202 CASE_TYPE(GestureFlingStart);
203 CASE_TYPE(GestureFlingCancel);
204 CASE_TYPE(GestureShowPress);
205 CASE_TYPE(GestureTap);
206 CASE_TYPE(GestureTapUnconfirmed);
207 CASE_TYPE(GestureTapDown);
208 CASE_TYPE(GestureTapCancel);
209 CASE_TYPE(GestureDoubleTap);
210 CASE_TYPE(GestureTwoFingerTap);
211 CASE_TYPE(GestureLongPress);
212 CASE_TYPE(GestureLongTap);
213 CASE_TYPE(GesturePinchBegin);
214 CASE_TYPE(GesturePinchEnd);
215 CASE_TYPE(GesturePinchUpdate);
216 CASE_TYPE(TouchStart);
217 CASE_TYPE(TouchMove);
218 CASE_TYPE(TouchEnd);
219 CASE_TYPE(TouchCancel);
220 default:
221 // Must include default to let blink::WebInputEvent add new event types
222 // before they're added here.
miletus14a25642015-08-13 19:23:23223 DLOG(WARNING) << "Unhandled WebInputEvent type: " << event_type;
jdduke07788062014-12-05 03:16:30224 break;
225 }
226
227#undef CASE_TYPE
228}
229
miletus14a25642015-08-13 19:23:23230void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now,
231 const ui::LatencyInfo& latency_info) {
232 LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now);
233 for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) {
234 LogInputEventLatencyUmaImpl(
235 event.type,
236 latency_info.timestamps_of_coalesced_events()[i],
237 now);
238 }
239}
240
[email protected]b256eca2013-07-11 10:57:40241} // namespace
242
[email protected]e9ff79c2012-10-19 21:31:26243namespace content {
[email protected]62cb33cae2009-03-27 23:30:22244
[email protected]b2e4c70132013-10-03 02:07:51245// RenderWidget::ScreenMetricsEmulator ----------------------------------------
246
247class RenderWidget::ScreenMetricsEmulator {
248 public:
249 ScreenMetricsEmulator(
250 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43251 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51252 virtual ~ScreenMetricsEmulator();
253
[email protected]19193682014-04-03 15:01:43254 // Scale and offset used to convert between host coordinates
255 // and webwidget coordinates.
[email protected]b2e4c70132013-10-03 02:07:51256 float scale() { return scale_; }
dgozman9260b0a12015-03-16 13:45:20257 gfx::PointF offset() { return offset_; }
[email protected]19193682014-04-03 15:01:43258 gfx::Rect applied_widget_rect() const { return applied_widget_rect_; }
[email protected]b2e4c70132013-10-03 02:07:51259 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
[email protected]5f75aa42014-04-01 23:00:56260 const WebScreenInfo& original_screen_info() { return original_screen_info_; }
[email protected]b2e4c70132013-10-03 02:07:51261
262 void ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43263 const WebDeviceEmulationParams& params);
[email protected]b2e4c70132013-10-03 02:07:51264
265 // The following methods alter handlers' behavior for messages related to
266 // widget size and position.
267 void OnResizeMessage(const ViewMsg_Resize_Params& params);
268 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
269 const gfx::Rect& window_screen_rect);
270 void OnShowContextMenu(ContextMenuParams* params);
[email protected]2d6836f42014-07-02 17:25:31271 gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
[email protected]b2e4c70132013-10-03 02:07:51272
273 private:
[email protected]19193682014-04-03 15:01:43274 void Reapply();
dtrainorcb7779b82014-12-04 01:08:02275 void Apply(bool top_controls_shrink_blink_size,
276 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44277 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12278 bool is_fullscreen_granted,
279 blink::WebDisplayMode display_mode);
[email protected]b2e4c70132013-10-03 02:07:51280
281 RenderWidget* widget_;
282
[email protected]7f99fc22013-11-08 14:05:58283 // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
[email protected]19193682014-04-03 15:01:43284 WebDeviceEmulationParams params_;
[email protected]b2e4c70132013-10-03 02:07:51285
[email protected]a179d3962013-11-12 14:44:40286 // The computed scale and offset used to fit widget into browser window.
[email protected]b2e4c70132013-10-03 02:07:51287 float scale_;
dgozman9260b0a12015-03-16 13:45:20288 gfx::PointF offset_;
[email protected]b2e4c70132013-10-03 02:07:51289
[email protected]19193682014-04-03 15:01:43290 // Widget rect as passed to webwidget.
291 gfx::Rect applied_widget_rect_;
292
[email protected]b2e4c70132013-10-03 02:07:51293 // Original values to restore back after emulation ends.
294 gfx::Size original_size_;
295 gfx::Size original_physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28296 gfx::Size original_visible_viewport_size_;
[email protected]180ef242013-11-07 06:50:46297 blink::WebScreenInfo original_screen_info_;
[email protected]b2e4c70132013-10-03 02:07:51298 gfx::Rect original_view_screen_rect_;
299 gfx::Rect original_window_screen_rect_;
300};
301
302RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
303 RenderWidget* widget,
[email protected]19193682014-04-03 15:01:43304 const WebDeviceEmulationParams& params)
[email protected]b2e4c70132013-10-03 02:07:51305 : widget_(widget),
[email protected]19193682014-04-03 15:01:43306 params_(params),
[email protected]b2e4c70132013-10-03 02:07:51307 scale_(1.f) {
308 original_size_ = widget_->size_;
309 original_physical_backing_size_ = widget_->physical_backing_size_;
[email protected]6949e0d22014-06-02 22:39:28310 original_visible_viewport_size_ = widget_->visible_viewport_size_;
[email protected]b2e4c70132013-10-03 02:07:51311 original_screen_info_ = widget_->screen_info_;
312 original_view_screen_rect_ = widget_->view_screen_rect_;
313 original_window_screen_rect_ = widget_->window_screen_rect_;
dtrainorcb7779b82014-12-04 01:08:02314 Apply(widget_->top_controls_shrink_blink_size_,
315 widget_->top_controls_height_,
316 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12317 widget_->is_fullscreen_granted_,
318 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51319}
320
321RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
322 widget_->screen_info_ = original_screen_info_;
323
324 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
dgozman9260b0a12015-03-16 13:45:20325 widget_->SetScreenMetricsEmulationParameters(false, params_);
[email protected]b2e4c70132013-10-03 02:07:51326 widget_->view_screen_rect_ = original_view_screen_rect_;
327 widget_->window_screen_rect_ = original_window_screen_rect_;
[email protected]587941d2014-08-22 01:40:01328 widget_->Resize(original_size_,
329 original_physical_backing_size_,
dtrainorcb7779b82014-12-04 01:08:02330 widget_->top_controls_shrink_blink_size_,
331 widget_->top_controls_height_,
[email protected]587941d2014-08-22 01:40:01332 original_visible_viewport_size_,
333 widget_->resizer_rect_,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12334 widget_->is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12335 widget_->display_mode_,
[email protected]587941d2014-08-22 01:40:01336 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51337}
338
339void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
[email protected]19193682014-04-03 15:01:43340 const WebDeviceEmulationParams& params) {
341 params_ = params;
342 Reapply();
343}
344
345void RenderWidget::ScreenMetricsEmulator::Reapply() {
dtrainorcb7779b82014-12-04 01:08:02346 Apply(widget_->top_controls_shrink_blink_size_,
347 widget_->top_controls_height_,
348 widget_->resizer_rect_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12349 widget_->is_fullscreen_granted_,
350 widget_->display_mode_);
[email protected]b2e4c70132013-10-03 02:07:51351}
352
[email protected]19193682014-04-03 15:01:43353void RenderWidget::ScreenMetricsEmulator::Apply(
dtrainorcb7779b82014-12-04 01:08:02354 bool top_controls_shrink_blink_size,
355 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44356 gfx::Rect resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12357 bool is_fullscreen_granted,
358 blink::WebDisplayMode display_mode) {
[email protected]92d13b72014-05-09 14:42:31359 applied_widget_rect_.set_size(gfx::Size(params_.viewSize));
360 if (!applied_widget_rect_.width())
361 applied_widget_rect_.set_width(original_size_.width());
362 if (!applied_widget_rect_.height())
363 applied_widget_rect_.set_height(original_size_.height());
[email protected]19193682014-04-03 15:01:43364
[email protected]f442ee42014-05-14 11:53:12365 if (params_.fitToView && !original_size_.IsEmpty()) {
[email protected]0b3578c2014-06-20 18:29:02366 int original_width = std::max(original_size_.width(), 1);
367 int original_height = std::max(original_size_.height(), 1);
[email protected]b2e4c70132013-10-03 02:07:51368 float width_ratio =
[email protected]0b3578c2014-06-20 18:29:02369 static_cast<float>(applied_widget_rect_.width()) / original_width;
[email protected]b2e4c70132013-10-03 02:07:51370 float height_ratio =
[email protected]0b3578c2014-06-20 18:29:02371 static_cast<float>(applied_widget_rect_.height()) / original_height;
[email protected]b2e4c70132013-10-03 02:07:51372 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
373 scale_ = 1.f / ratio;
[email protected]7f0e8fa2014-03-26 12:32:01374
375 // Center emulated view inside available view space.
[email protected]19193682014-04-03 15:01:43376 offset_.set_x(
377 (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2);
[email protected]7f0e8fa2014-03-26 12:32:01378 offset_.set_y(
[email protected]19193682014-04-03 15:01:43379 (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2);
[email protected]b2e4c70132013-10-03 02:07:51380 } else {
[email protected]0b3578c2014-06-20 18:29:02381 scale_ = params_.scale;
382 offset_.SetPoint(params_.offset.x, params_.offset.y);
[email protected]7f0e8fa2014-03-26 12:32:01383 }
[email protected]7f0e8fa2014-03-26 12:32:01384
[email protected]19193682014-04-03 15:01:43385 if (params_.screenPosition == WebDeviceEmulationParams::Desktop) {
386 applied_widget_rect_.set_origin(original_view_screen_rect_.origin());
[email protected]7f0e8fa2014-03-26 12:32:01387 widget_->screen_info_.rect = original_screen_info_.rect;
388 widget_->screen_info_.availableRect = original_screen_info_.availableRect;
389 widget_->window_screen_rect_ = original_window_screen_rect_;
390 } else {
dgozmanf28ccbe2015-06-24 08:50:49391 applied_widget_rect_.set_origin(params_.viewPosition);
392 gfx::Rect screen_rect = applied_widget_rect_;
393 if (!params_.screenSize.isEmpty()) {
394 screen_rect =
395 gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height);
396 }
397 widget_->screen_info_.rect = screen_rect;
398 widget_->screen_info_.availableRect = screen_rect;
[email protected]19193682014-04-03 15:01:43399 widget_->window_screen_rect_ = applied_widget_rect_;
[email protected]7f0e8fa2014-03-26 12:32:01400 }
[email protected]a179d3962013-11-12 14:44:40401
[email protected]19193682014-04-03 15:01:43402 float applied_device_scale_factor = params_.deviceScaleFactor ?
403 params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor;
[email protected]7f0e8fa2014-03-26 12:32:01404 widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor;
[email protected]b2e4c70132013-10-03 02:07:51405
[email protected]7f99fc22013-11-08 14:05:58406 // Pass three emulation parameters to the blink side:
[email protected]b2e4c70132013-10-03 02:07:51407 // - we keep the real device scale factor in compositor to produce sharp image
408 // even when emulating different scale factor;
[email protected]7f99fc22013-11-08 14:05:58409 // - in order to fit into view, WebView applies offset and scale to the
[email protected]b2e4c70132013-10-03 02:07:51410 // root layer.
dgozman9260b0a12015-03-16 13:45:20411 blink::WebDeviceEmulationParams modified_params = params_;
412 modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor;
413 modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y());
414 modified_params.scale = scale_;
415 widget_->SetScreenMetricsEmulationParameters(true, modified_params);
[email protected]b2e4c70132013-10-03 02:07:51416
[email protected]7f0e8fa2014-03-26 12:32:01417 widget_->SetDeviceScaleFactor(applied_device_scale_factor);
[email protected]19193682014-04-03 15:01:43418 widget_->view_screen_rect_ = applied_widget_rect_;
[email protected]b2e4c70132013-10-03 02:07:51419
danakjddaec912015-09-25 19:38:40420 gfx::Size physical_backing_size = gfx::ScaleToCeiledSize(
421 original_size_, original_screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02422 widget_->Resize(applied_widget_rect_.size(),
423 physical_backing_size,
424 top_controls_shrink_blink_size,
425 top_controls_height,
426 applied_widget_rect_.size(),
427 resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12428 is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12429 display_mode,
dtrainorcb7779b82014-12-04 01:08:02430 NO_RESIZE_ACK);
[email protected]b2e4c70132013-10-03 02:07:51431}
432
433void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
434 const ViewMsg_Resize_Params& params) {
435 bool need_ack = params.new_size != original_size_ &&
436 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
437 original_size_ = params.new_size;
438 original_physical_backing_size_ = params.physical_backing_size;
439 original_screen_info_ = params.screen_info;
[email protected]6949e0d22014-06-02 22:39:28440 original_visible_viewport_size_ = params.visible_viewport_size;
dtrainorcb7779b82014-12-04 01:08:02441 Apply(params.top_controls_shrink_blink_size,
442 params.top_controls_height,
443 params.resizer_rect,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12444 params.is_fullscreen_granted,
445 params.display_mode);
[email protected]b2e4c70132013-10-03 02:07:51446
447 if (need_ack) {
448 widget_->set_next_paint_is_resize_ack();
449 if (widget_->compositor_)
450 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
451 }
452}
453
454void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
455 const gfx::Rect& view_screen_rect,
456 const gfx::Rect& window_screen_rect) {
457 original_view_screen_rect_ = view_screen_rect;
458 original_window_screen_rect_ = window_screen_rect;
[email protected]19193682014-04-03 15:01:43459 if (params_.screenPosition == WebDeviceEmulationParams::Desktop)
460 Reapply();
[email protected]b2e4c70132013-10-03 02:07:51461}
462
463void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
464 ContextMenuParams* params) {
465 params->x *= scale_;
[email protected]a179d3962013-11-12 14:44:40466 params->x += offset_.x();
[email protected]b2e4c70132013-10-03 02:07:51467 params->y *= scale_;
[email protected]a179d3962013-11-12 14:44:40468 params->y += offset_.y();
[email protected]b2e4c70132013-10-03 02:07:51469}
470
[email protected]2d6836f42014-07-02 17:25:31471gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor(
472 const gfx::Rect& anchor) {
danakj4606f6332015-08-31 23:56:56473 gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_);
[email protected]2d6836f42014-07-02 17:25:31474 scaled.set_x(scaled.x() + offset_.x());
475 scaled.set_y(scaled.y() + offset_.y());
476 return scaled;
477}
478
[email protected]b2e4c70132013-10-03 02:07:51479// RenderWidget ---------------------------------------------------------------
480
dcheng35d31c112015-07-22 00:17:36481RenderWidget::RenderWidget(CompositorDependencies* compositor_deps,
482 blink::WebPopupType popup_type,
[email protected]180ef242013-11-07 06:50:46483 const blink::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04484 bool swapped_out,
[email protected]7912e822014-04-16 02:37:03485 bool hidden,
486 bool never_visible)
initial.commit09911bf2008-07-26 23:55:29487 : routing_id_(MSG_ROUTING_NONE),
dcheng35d31c112015-07-22 00:17:36488 compositor_deps_(compositor_deps),
danakj6e3bf8012014-12-16 18:27:53489 webwidget_(nullptr),
initial.commit09911bf2008-07-26 23:55:29490 opener_id_(MSG_ROUTING_NONE),
dtrainorcb7779b82014-12-04 01:08:02491 top_controls_shrink_blink_size_(false),
492 top_controls_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29493 next_paint_flags_(0),
[email protected]847a2582013-03-09 02:29:51494 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09495 need_update_rect_for_auto_resize_(false),
initial.commit09911bf2008-07-26 23:55:29496 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04497 is_hidden_(hidden),
sievers71c62dd52015-10-07 01:44:39498 compositor_never_visible_(never_visible),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12499 is_fullscreen_granted_(false),
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12500 display_mode_(blink::WebDisplayModeUndefined),
[email protected]5dd768212009-08-13 23:34:49501 handling_input_event_(false),
jddukec05612b2015-06-25 23:13:18502 handling_event_overscroll_(nullptr),
changwanf2a707b2015-10-30 08:22:16503 ime_event_guard_(nullptr),
[email protected]c27dd4f2014-05-22 18:05:19504 handling_event_type_(WebInputEvent::Undefined),
505 ignore_ack_for_mouse_move_from_debugger_(false),
[email protected]661eb9d2009-02-03 02:11:48506 closing_(false),
[email protected]aeeedad2014-08-22 18:16:22507 host_closing_(false),
[email protected]14392a52012-05-02 20:28:44508 is_swapped_out_(swapped_out),
simonhong628f9812015-04-27 23:13:20509 for_oopif_(false),
[email protected]ad26ef42011-06-17 07:59:45510 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40511 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
shuchen82ce8c52014-10-23 01:55:20512 text_input_flags_(0),
[email protected]86ba5fcb2013-09-04 00:36:53513 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12514 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48515 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12516 suppress_next_char_events_(false),
[email protected]842f10652012-06-06 01:54:04517 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52518 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]53b4cc12013-07-18 23:02:30519 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13520#if defined(OS_ANDROID)
[email protected]90f24152014-04-09 12:41:36521 text_field_is_dirty_(false),
[email protected]0d1ebed12013-08-05 22:01:13522#endif
[email protected]b2e4c70132013-10-03 02:07:51523 popup_origin_scale_for_emulation_(0.f),
[email protected]586871b2014-07-22 17:05:11524 frame_swap_message_queue_(new FrameSwapMessageQueue()),
[email protected]a09d53ce2014-01-31 00:46:42525 resizing_mode_selector_(new ResizingModeSelector()),
[email protected]be1af0662014-07-29 19:55:51526 context_menu_source_type_(ui::MENU_SOURCE_MOUSE),
527 has_host_context_menu_location_(false) {
[email protected]8b3f0eb2012-05-03 19:15:05528 if (!swapped_out)
529 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27530 DCHECK(RenderThread::Get());
[email protected]3079c28a2014-06-24 03:38:53531 device_color_profile_.push_back('0');
changwan3a841162015-08-11 02:53:37532#if defined(OS_ANDROID)
533 text_input_info_history_.push_back(blink::WebTextInputInfo());
534#endif
alexclarke7fa93942015-10-21 15:37:11535
536 // In tests there may not be a RenderThreadImpl.
537 if (RenderThreadImpl::current()) {
538 render_widget_scheduling_state_ = RenderThreadImpl::current()
539 ->GetRendererScheduler()
540 ->NewRenderWidgetSchedulingState()
541 .Pass();
542 render_widget_scheduling_state_->SetHidden(is_hidden_);
543 }
initial.commit09911bf2008-07-26 23:55:29544}
545
546RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11547 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]bffc8302014-01-23 20:52:16548
[email protected]992db4c2011-05-12 15:37:15549 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02550 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15551 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29552}
553
[email protected]484955942010-08-19 16:13:18554// static
[email protected]8085dbc82008-09-26 22:53:44555RenderWidget* RenderWidget::Create(int32 opener_id,
danakj6e3bf8012014-12-16 18:27:53556 CompositorDependencies* compositor_deps,
[email protected]180ef242013-11-07 06:50:46557 blink::WebPopupType popup_type,
558 const blink::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29559 DCHECK(opener_id != MSG_ROUTING_NONE);
dcheng35d31c112015-07-22 00:17:36560 scoped_refptr<RenderWidget> widget(new RenderWidget(
561 compositor_deps, popup_type, screen_info, false, false, false));
562 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46563 return widget.get();
[email protected]a635f942012-12-07 10:34:29564 }
565 return NULL;
initial.commit09911bf2008-07-26 23:55:29566}
567
[email protected]484955942010-08-19 16:13:18568// static
kenrba7199832015-01-22 23:44:59569RenderWidget* RenderWidget::CreateForFrame(
570 int routing_id,
kenrba7199832015-01-22 23:44:59571 bool hidden,
572 const blink::WebScreenInfo& screen_info,
573 CompositorDependencies* compositor_deps,
574 blink::WebLocalFrame* frame) {
575 CHECK_NE(routing_id, MSG_ROUTING_NONE);
dcheng3ce04b62015-10-26 23:30:55576 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the
577 // same routing ID for both the view routing ID and the main frame widget
578 // routing ID. https://crbug.com/545684
579 RenderViewImpl* view = RenderViewImpl::FromRoutingID(routing_id);
580 if (view) {
581 view->AttachWebFrameWidget(RenderWidget::CreateWebFrameWidget(view, frame));
582 return view;
583 }
dcheng35d31c112015-07-22 00:17:36584 scoped_refptr<RenderWidget> widget(
585 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
586 false, hidden, false));
kenrba7199832015-01-22 23:44:59587 widget->routing_id_ = routing_id;
simonhong628f9812015-04-27 23:13:20588 widget->for_oopif_ = true;
kenrba7199832015-01-22 23:44:59589 // DoInit increments the reference count on |widget|, keeping it alive after
590 // this function returns.
dcheng35d31c112015-07-22 00:17:36591 if (widget->DoInit(MSG_ROUTING_NONE,
kenrba7199832015-01-22 23:44:59592 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
593 nullptr)) {
kenrba7199832015-01-22 23:44:59594 return widget.get();
595 }
596 return nullptr;
597}
598
599// static
dchengda9b4bb2015-07-20 20:58:08600blink::WebWidget* RenderWidget::CreateWebFrameWidget(
601 RenderWidget* render_widget,
602 blink::WebLocalFrame* frame) {
dcheng3ce04b62015-10-26 23:30:55603 if (!frame->parent()) {
604 // TODO(dcheng): The main frame widget currently has a special case.
605 // Eliminate this once WebView is no longer a WebWidget.
606 return blink::WebFrameWidget::create(render_widget, frame->view(), frame);
607 }
dchengda9b4bb2015-07-20 20:58:08608 return blink::WebFrameWidget::create(render_widget, frame);
609}
610
611// static
kenrba7199832015-01-22 23:44:59612blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
[email protected]484955942010-08-19 16:13:18613 switch (render_widget->popup_type_) {
[email protected]180ef242013-11-07 06:50:46614 case blink::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18615 break;
[email protected]180ef242013-11-07 06:50:46616 case blink::WebPopupTypePage:
[email protected]a7547fb2012-03-08 04:43:44617 return WebPagePopup::create(render_widget);
[email protected]484955942010-08-19 16:13:18618 default:
619 NOTREACHED();
620 }
621 return NULL;
622}
623
dchengda9b4bb2015-07-20 20:58:08624void RenderWidget::CloseForFrame() {
dchengd96a27a2015-07-24 20:17:32625 OnClose();
kenrba7199832015-01-22 23:44:59626}
627
dcheng35d31c112015-07-22 00:17:36628bool RenderWidget::Init(int32 opener_id) {
piman5d36dae2015-09-24 22:47:05629 return DoInit(
630 opener_id, RenderWidget::CreateWebWidget(this),
631 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_));
[email protected]484955942010-08-19 16:13:18632}
633
[email protected]a635f942012-12-07 10:34:29634bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06635 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18636 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29637 DCHECK(!webwidget_);
638
639 if (opener_id != MSG_ROUTING_NONE)
640 opener_id_ = opener_id;
641
[email protected]484955942010-08-19 16:13:18642 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29643
kenrba7199832015-01-22 23:44:59644 bool result = true;
645 if (create_widget_message)
646 result = RenderThread::Get()->Send(create_widget_message);
647
initial.commit09911bf2008-07-26 23:55:29648 if (result) {
[email protected]380244092011-10-07 17:26:27649 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29650 // Take a reference on behalf of the RenderThread. This will be balanced
651 // when we receive ViewMsg_Close.
652 AddRef();
[email protected]b2db9272014-01-10 17:42:00653 if (RenderThreadImpl::current()) {
654 RenderThreadImpl::current()->WidgetCreated();
655 if (is_hidden_)
656 RenderThreadImpl::current()->WidgetHidden();
657 }
[email protected]a635f942012-12-07 10:34:29658 return true;
initial.commit09911bf2008-07-26 23:55:29659 } else {
[email protected]a635f942012-12-07 10:34:29660 // The above Send can fail when the tab is closing.
661 return false;
initial.commit09911bf2008-07-26 23:55:29662 }
663}
664
[email protected]992db4c2011-05-12 15:37:15665void RenderWidget::SetSwappedOut(bool is_swapped_out) {
666 // We should only toggle between states.
667 DCHECK(is_swapped_out_ != is_swapped_out);
668 is_swapped_out_ = is_swapped_out;
669
670 // If we are swapping out, we will call ReleaseProcess, allowing the process
671 // to exit if all of its RenderViews are swapped out. We wait until the
[email protected]949b6592014-08-20 13:17:52672 // WasSwappedOut call to do this, to allow the unload handler to finish.
[email protected]992db4c2011-05-12 15:37:15673 // If we are swapping in, we call AddRefProcess to prevent the process from
674 // exiting.
[email protected]949b6592014-08-20 13:17:52675 if (!is_swapped_out_)
[email protected]992db4c2011-05-12 15:37:15676 RenderProcess::current()->AddRefProcess();
677}
678
[email protected]949b6592014-08-20 13:17:52679void RenderWidget::WasSwappedOut() {
680 // If we have been swapped out and no one else is using this process,
681 // it's safe to exit now.
682 CHECK(is_swapped_out_);
683 RenderProcess::current()->ReleaseProcess();
684}
685
[email protected]b2e4c70132013-10-03 02:07:51686void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
687 ScreenMetricsEmulator* emulator) {
688 popup_origin_scale_for_emulation_ = emulator->scale();
[email protected]19193682014-04-03 15:01:43689 popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin();
[email protected]9a2d7ee32013-12-05 12:15:49690 popup_screen_origin_for_emulation_ = gfx::Point(
691 emulator->original_screen_rect().origin().x() + emulator->offset().x(),
692 emulator->original_screen_rect().origin().y() + emulator->offset().y());
[email protected]5f75aa42014-04-01 23:00:56693 screen_info_ = emulator->original_screen_info();
694 device_scale_factor_ = screen_info_.deviceScaleFactor;
[email protected]b2e4c70132013-10-03 02:07:51695}
696
[email protected]2d6836f42014-07-02 17:25:31697gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) {
698 if (screen_metrics_emulator_)
699 return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor);
700 return anchor;
701}
702
[email protected]b2e4c70132013-10-03 02:07:51703void RenderWidget::SetScreenMetricsEmulationParameters(
dgozman9260b0a12015-03-16 13:45:20704 bool enabled,
705 const blink::WebDeviceEmulationParams& params) {
[email protected]b2e4c70132013-10-03 02:07:51706 // This is only supported in RenderView.
707 NOTREACHED();
708}
709
[email protected]53907862014-03-25 15:42:40710#if defined(OS_MACOSX) || defined(OS_ANDROID)
[email protected]b2e4c70132013-10-03 02:07:51711void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
712 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
[email protected]9a2d7ee32013-12-05 12:15:49713 popup->SetOriginScaleAndOffsetForEmulation(
714 emulator->scale(), emulator->offset());
[email protected]b2e4c70132013-10-03 02:07:51715}
[email protected]53907862014-03-25 15:42:40716#endif
[email protected]b2e4c70132013-10-03 02:07:51717
718void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
719 if (screen_metrics_emulator_)
720 screen_metrics_emulator_->OnShowContextMenu(params);
721}
722
[email protected]a95986a82010-12-24 06:19:28723bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
724 bool handled = true;
725 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15726 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22727 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
728 OnCursorVisibilityChange)
[email protected]a2214eb2014-06-23 18:31:22729 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
730 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]c084330e02013-04-27 01:08:15731 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
732 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]9017d7852013-11-21 17:47:35733 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
734 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28735 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
[email protected]a95986a82010-12-24 06:19:28736 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
dgozman9260b0a12015-03-16 13:45:20737 IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation,
738 OnEnableDeviceEmulation)
739 IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation,
740 OnDisableDeviceEmulation)
noel89949e62014-09-30 01:12:41741 IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile)
[email protected]b5913d72012-02-07 22:26:54742 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28743 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41744 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]3d9ec5052013-01-02 22:05:25745 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]a95986a82010-12-24 06:19:28746 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
747 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03748 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
kenrbb4e2a3b2015-05-14 15:05:05749 IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace)
[email protected]105dffb42013-02-20 03:46:21750#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:37751 IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck)
[email protected]2384b6c2013-02-28 23:58:51752 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21753#endif
[email protected]a95986a82010-12-24 06:19:28754 IPC_MESSAGE_UNHANDLED(handled = false)
755 IPC_END_MESSAGE_MAP()
756 return handled;
757}
initial.commit09911bf2008-07-26 23:55:29758
759bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15760 // Don't send any messages after the browser has told us to close, and filter
761 // most outgoing messages while swapped out.
762 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26763 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11764 closing_) {
initial.commit09911bf2008-07-26 23:55:29765 delete message;
766 return false;
767 }
768
769 // If given a messsage without a routing ID, then assign our routing ID.
770 if (message->routing_id() == MSG_ROUTING_NONE)
771 message->set_routing_id(routing_id_);
772
[email protected]380244092011-10-07 17:26:27773 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44774}
775
[email protected]61e2b3cc2012-03-02 16:13:34776void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44777 const gfx::Size& physical_backing_size,
dtrainorcb7779b82014-12-04 01:08:02778 bool top_controls_shrink_blink_size,
779 float top_controls_height,
[email protected]bb6378fe2014-04-28 21:19:44780 const gfx::Size& visible_viewport_size,
[email protected]61e2b3cc2012-03-02 16:13:34781 const gfx::Rect& resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12782 bool is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12783 blink::WebDisplayMode display_mode,
sievers4e33dae2015-02-25 20:43:58784 const ResizeAck resize_ack) {
[email protected]f7c1f092013-11-05 20:20:56785 if (resizing_mode_selector_->NeverUsesSynchronousResize()) {
[email protected]1c0008842013-06-06 08:35:48786 // A resize ack shouldn't be requested if we have not ACK'd the previous
787 // one.
788 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
789 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
790 }
initial.commit09911bf2008-07-26 23:55:29791
[email protected]61e2b3cc2012-03-02 16:13:34792 // Ignore this during shutdown.
793 if (!webwidget_)
794 return;
795
oshima750cb4342015-10-31 00:59:01796 if (compositor_)
797 compositor_->setViewportSize(physical_backing_size);
[email protected]60d47ac2013-03-01 23:42:44798
oshima750cb4342015-10-31 00:59:01799 bool resized = size_ != new_size ||
800 physical_backing_size_ != physical_backing_size;
801
802 size_ = new_size;
[email protected]dade8992013-03-04 07:34:34803 physical_backing_size_ = physical_backing_size;
oshima750cb4342015-10-31 00:59:01804
dtrainorcb7779b82014-12-04 01:08:02805 top_controls_shrink_blink_size_ = top_controls_shrink_blink_size;
806 top_controls_height_ = top_controls_height;
[email protected]39244e72014-05-14 04:20:28807 visible_viewport_size_ = visible_viewport_size;
[email protected]61e2b3cc2012-03-02 16:13:34808 resizer_rect_ = resizer_rect;
809
810 // NOTE: We may have entered fullscreen mode without changing our size.
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12811 bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted;
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12812 is_fullscreen_granted_ = is_fullscreen_granted;
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12813 display_mode_ = display_mode;
[email protected]61e2b3cc2012-03-02 16:13:34814
aelias6004fe02015-02-07 21:43:01815 webwidget_->setTopControlsHeight(top_controls_height,
816 top_controls_shrink_blink_size_);
bokan0c93cd82014-09-30 19:20:43817
oshima750cb4342015-10-31 00:59:01818 if (resized) {
819 gfx::Size new_widget_size =
820 IsUseZoomForDSFEnabled() ? physical_backing_size_ : size_;
[email protected]61e2b3cc2012-03-02 16:13:34821 // When resizing, we want to wait to paint before ACK'ing the resize. This
822 // ensures that we only resize as fast as we can paint. We only need to
823 // send an ACK if we are resized to a non-empty rect.
oshima750cb4342015-10-31 00:59:01824 webwidget_->resize(new_widget_size);
825 }
826 WebSize pinch_viewport_size;
827
828 if (IsUseZoomForDSFEnabled()) {
829 gfx::SizeF scaled_visible_viewport_size =
830 gfx::ScaleSize(gfx::SizeF(visible_viewport_size), device_scale_factor_);
831 pinch_viewport_size = gfx::ToCeiledSize(scaled_visible_viewport_size);
832 } else {
833 pinch_viewport_size = visible_viewport_size_;
[email protected]632c4382013-05-15 08:58:45834 }
835
oshima750cb4342015-10-31 00:59:01836 webwidget()->resizePinchViewport(pinch_viewport_size);
[email protected]bb6378fe2014-04-28 21:19:44837
[email protected]632c4382013-05-15 08:58:45838 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
sievers4e33dae2015-02-25 20:43:58839 // In this case there is no paint/composite and therefore no
840 // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the
841 // ack through a fake ViewHostMsg_UpdateRect or a different message.
842 DCHECK_EQ(resize_ack, NO_RESIZE_ACK);
[email protected]61e2b3cc2012-03-02 16:13:34843 }
844
[email protected]20fbfc22013-05-08 20:50:58845 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45846 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58847 set_next_paint_is_resize_ack();
848
[email protected]61e2b3cc2012-03-02 16:13:34849 if (fullscreen_change)
850 DidToggleFullscreen();
851
852 // If a resize ack is requested and it isn't set-up, then no more resizes will
853 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45854 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29855}
856
bokanc007c3a2015-02-03 07:15:56857void RenderWidget::SetWindowRectSynchronously(
858 const gfx::Rect& new_window_rect) {
859 Resize(new_window_rect.size(),
860 new_window_rect.size(),
dtrainorcb7779b82014-12-04 01:08:02861 top_controls_shrink_blink_size_,
862 top_controls_height_,
bokanc007c3a2015-02-03 07:15:56863 new_window_rect.size(),
[email protected]587941d2014-08-22 01:40:01864 gfx::Rect(),
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12865 is_fullscreen_granted_,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12866 display_mode_,
[email protected]587941d2014-08-22 01:40:01867 NO_RESIZE_ACK);
bokanc007c3a2015-02-03 07:15:56868 view_screen_rect_ = new_window_rect;
869 window_screen_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02870 if (!did_show_)
bokanc007c3a2015-02-03 07:15:56871 initial_rect_ = new_window_rect;
[email protected]92650162013-10-30 03:31:02872}
873
initial.commit09911bf2008-07-26 23:55:29874void RenderWidget::OnClose() {
dchengd96a27a2015-07-24 20:17:32875 DCHECK(content::RenderThread::Get());
876 if (closing_)
877 return;
878 NotifyOnClose();
879 closing_ = true;
880
881 // Browser correspondence is no longer needed at this point.
882 if (routing_id_ != MSG_ROUTING_NONE) {
883 RenderThread::Get()->RemoveRoute(routing_id_);
884 SetHidden(false);
885 if (RenderThreadImpl::current())
886 RenderThreadImpl::current()->WidgetDestroyed();
887 }
888
889 if (for_oopif_) {
890 // Widgets for frames may be created and closed at any time while the frame
891 // is alive. However, the closing process must happen synchronously. Frame
892 // widget and frames hold pointers to each other. If Close() is deferred to
893 // the message loop like in the non-frame widget case, WebWidget::close()
894 // can end up accessing members of an already-deleted frame.
895 Close();
896 } else {
897 // If there is a Send call on the stack, then it could be dangerous to close
898 // now. Post a task that only gets invoked when there are no nested message
899 // loops.
900 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
901 FROM_HERE, base::Bind(&RenderWidget::Close, this));
902 }
903
904 // Balances the AddRef taken when we called AddRoute.
905 Release();
initial.commit09911bf2008-07-26 23:55:29906}
907
[email protected]0fdd5012013-05-29 08:05:56908void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]5b45ad42013-10-25 00:42:04909 if (resizing_mode_selector_->ShouldAbortOnResize(this, params))
[email protected]03e88672013-10-22 21:31:32910 return;
911
[email protected]b2e4c70132013-10-03 02:07:51912 if (screen_metrics_emulator_) {
913 screen_metrics_emulator_->OnResizeMessage(params);
914 return;
915 }
916
[email protected]fcdc5642014-05-09 14:32:24917 bool orientation_changed =
918 screen_info_.orientationAngle != params.screen_info.orientationAngle;
919
[email protected]0fdd5012013-05-29 08:05:56920 screen_info_ = params.screen_info;
921 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
dtrainorcb7779b82014-12-04 01:08:02922 Resize(params.new_size,
923 params.physical_backing_size,
924 params.top_controls_shrink_blink_size,
925 params.top_controls_height,
926 params.visible_viewport_size,
927 params.resizer_rect,
mikhail.pozdnyakovf2c902a2015-04-14 08:09:12928 params.is_fullscreen_granted,
mikhail.pozdnyakovc0e251b2015-04-15 06:51:12929 params.display_mode,
sievers4e33dae2015-02-25 20:43:58930 params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK);
[email protected]fcdc5642014-05-09 14:32:24931
932 if (orientation_changed)
933 OnOrientationChange();
initial.commit09911bf2008-07-26 23:55:29934}
935
dgozman9260b0a12015-03-16 13:45:20936void RenderWidget::OnEnableDeviceEmulation(
937 const blink::WebDeviceEmulationParams& params) {
938 if (!screen_metrics_emulator_)
939 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params));
940 else
941 screen_metrics_emulator_->ChangeEmulationParams(params);
942}
943
944void RenderWidget::OnDisableDeviceEmulation() {
945 screen_metrics_emulator_.reset();
946}
947
noel89949e62014-09-30 01:12:41948void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) {
949 SetDeviceColorProfile(color_profile);
950}
951
[email protected]b5913d72012-02-07 22:26:54952void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
[email protected]721e2302014-04-30 23:42:01953 if (resizer_rect_ == resizer_rect)
954 return;
955 resizer_rect_ = resizer_rect;
956 if (webwidget_)
957 webwidget_->didChangeWindowResizerRect();
[email protected]b5913d72012-02-07 22:26:54958}
959
initial.commit09911bf2008-07-26 23:55:29960void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31961 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29962 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03963 SetHidden(true);
[email protected]de3c5d82014-05-28 22:12:59964 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
965 WasHidden());
initial.commit09911bf2008-07-26 23:55:29966}
967
[email protected]3399dd822014-08-09 11:14:24968void RenderWidget::OnWasShown(bool needs_repainting,
969 const ui::LatencyInfo& latency_info) {
[email protected]9e2e4632012-07-27 16:38:41970 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29971 // During shutdown we can just ignore this message.
972 if (!webwidget_)
973 return;
974
975 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03976 SetHidden(false);
[email protected]de3c5d82014-05-28 22:12:59977 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
978 WasShown());
initial.commit09911bf2008-07-26 23:55:29979
[email protected]8a23afb32014-04-30 22:40:23980 if (!needs_repainting)
initial.commit09911bf2008-07-26 23:55:29981 return;
initial.commit09911bf2008-07-26 23:55:29982
983 // Generate a full repaint.
[email protected]3399dd822014-08-09 11:14:24984 if (compositor_) {
985 ui::LatencyInfo swap_latency_info(latency_info);
986 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor(
987 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info));
[email protected]aca33f4f2014-05-17 17:08:05988 compositor_->SetNeedsForcedRedraw();
[email protected]3399dd822014-08-09 11:14:24989 }
jdduke491a3f0c2015-06-15 23:30:26990 ScheduleComposite();
initial.commit09911bf2008-07-26 23:55:29991}
992
[email protected]53d3f302009-12-21 04:42:05993void RenderWidget::OnRequestMoveAck() {
994 DCHECK(pending_window_rect_count_);
995 pending_window_rect_count_--;
996}
997
[email protected]ed7defa2013-03-12 21:29:59998GURL RenderWidget::GetURLForGraphicsContext3D() {
999 return GURL();
[email protected]65225772011-05-12 21:10:241000}
1001
[email protected]ebc0e1df2013-08-01 02:46:221002scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]7912e822014-04-16 02:37:031003 // For widgets that are never visible, we don't start the compositor, so we
1004 // never get a request for a cc::OutputSurface.
sievers71c62dd52015-10-07 01:44:391005 DCHECK(!compositor_never_visible_);
[email protected]a1811b8912013-05-09 15:35:191006
avi83883c82014-12-23 00:08:491007 const base::CommandLine& command_line =
1008 *base::CommandLine::ForCurrentProcess();
[email protected]e09994a2014-03-26 19:59:331009 bool use_software = fallback;
1010 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
1011 use_software = true;
1012
[email protected]0634cdd42013-08-16 00:46:091013 scoped_refptr<ContextProviderCommandBuffer> context_provider;
vmiura78b69282015-02-14 00:01:171014 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider;
[email protected]e09994a2014-03-26 19:59:331015 if (!use_software) {
[email protected]0634cdd42013-08-16 00:46:091016 context_provider = ContextProviderCommandBuffer::Create(
jbauman5e420d32015-08-05 09:33:011017 CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT);
[email protected]e09994a2014-03-26 19:59:331018 if (!context_provider.get()) {
1019 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341020 return nullptr;
[email protected]e09994a2014-03-26 19:59:331021 }
revemand180dfc32015-09-24 00:19:431022 worker_context_provider =
1023 RenderThreadImpl::current()->SharedWorkerContextProvider();
1024 if (!worker_context_provider) {
vmiura78b69282015-02-14 00:01:171025 // Cause the compositor to wait and try again.
piman8944e1c2015-09-22 21:10:341026 return nullptr;
vmiura78b69282015-02-14 00:01:171027 }
boliu853d46052015-10-13 20:20:061028
1029#if defined(OS_ANDROID)
1030 if (SynchronousCompositorFactory* factory =
1031 SynchronousCompositorFactory::GetInstance()) {
1032 return factory->CreateOutputSurface(
1033 routing_id(), frame_swap_message_queue_, context_provider,
1034 worker_context_provider);
1035 }
1036#endif
[email protected]0634cdd42013-08-16 00:46:091037 }
[email protected]ebc0e1df2013-08-01 02:46:221038
[email protected]b6eb8e332013-09-10 00:51:011039 uint32 output_surface_id = next_output_surface_id_++;
piman8944e1c2015-09-22 21:10:341040 // Composite-to-mailbox is currently used for layout tests in order to cause
1041 // them to draw inside in the renderer to do the readback there. This should
1042 // no longer be the case when crbug.com/311404 is fixed.
1043 if (!RenderThreadImpl::current() ||
1044 !RenderThreadImpl::current()->layout_test_mode()) {
danakj6e3bf8012014-12-16 18:27:531045 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner());
piman8944e1c2015-09-22 21:10:341046 return make_scoped_ptr(new DelegatedCompositorOutputSurface(
vmiura78b69282015-02-14 00:01:171047 routing_id(), output_surface_id, context_provider,
1048 worker_context_provider, frame_swap_message_queue_));
[email protected]65a33ce2014-03-25 22:37:091049 }
piman8944e1c2015-09-22 21:10:341050
[email protected]0634cdd42013-08-16 00:46:091051 if (!context_provider.get()) {
[email protected]0634cdd42013-08-16 00:46:091052 scoped_ptr<cc::SoftwareOutputDevice> software_device(
jbauman7e15c6a2015-05-11 23:43:121053 new cc::SoftwareOutputDevice());
[email protected]0634cdd42013-08-16 00:46:091054
piman8944e1c2015-09-22 21:10:341055 return make_scoped_ptr(new CompositorOutputSurface(
caseqff9c74c2015-02-10 14:56:291056 routing_id(), output_surface_id, nullptr, nullptr,
1057 software_device.Pass(), frame_swap_message_queue_, true));
[email protected]ebc0e1df2013-08-01 02:46:221058 }
[email protected]ed7defa2013-03-12 21:29:591059
piman8944e1c2015-09-22 21:10:341060 return make_scoped_ptr(new MailboxOutputSurface(
vmiura78b69282015-02-14 00:01:171061 routing_id(), output_surface_id, context_provider,
piman8944e1c2015-09-22 21:10:341062 worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888));
[email protected]ba91a792013-02-06 09:48:281063}
1064
[email protected]4d7e46a2013-11-08 05:33:401065void RenderWidget::OnSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:241066 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]65225772011-05-12 21:10:241067 // Schedule another frame so the compositor learns about it.
jdduke491a3f0c2015-06-15 23:30:261068 ScheduleComposite();
[email protected]65225772011-05-12 21:10:241069}
1070
[email protected]4d7e46a2013-11-08 05:33:401071void RenderWidget::OnSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081072 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]37a6f302011-07-11 23:43:081073}
1074
[email protected]4d7e46a2013-11-08 05:33:401075void RenderWidget::OnSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241076 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161077
[email protected]404939f2012-06-01 04:06:181078 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161079 DidFlushPaint();
initial.commit09911bf2008-07-26 23:55:291080}
1081
[email protected]180ef242013-11-07 06:50:461082void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event,
jdduke0cf1e662015-10-15 22:43:281083 const ui::LatencyInfo& latency_info) {
[email protected]c27dd4f2014-05-22 18:05:191084 if (!input_event)
initial.commit09911bf2008-07-26 23:55:291085 return;
jddukec05612b2015-06-25 23:13:181086 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
1087 true);
[email protected]c27dd4f2014-05-22 18:05:191088 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter(
1089 &handling_event_type_, input_event->type);
jddukec05612b2015-06-25 23:13:181090
1091 // Calls into |didOverscroll()| while handling this event will populate
1092 // |event_overscroll|, which in turn will be bundled with the event ack.
1093 scoped_ptr<DidOverscrollParams> event_overscroll;
1094 base::AutoReset<scoped_ptr<DidOverscrollParams>*>
1095 handling_event_overscroll_resetter(&handling_event_overscroll_,
1096 &event_overscroll);
1097
[email protected]25402eb2014-07-18 03:09:521098#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161099 const bool is_keyboard_event =
1100 WebInputEvent::isKeyboardEventType(input_event->type);
1101
1102 // For non-keyboard events, we want the change source to be FROM_NON_IME.
1103 ImeEventGuard guard(this, false, is_keyboard_event);
[email protected]25402eb2014-07-18 03:09:521104#endif
initial.commit09911bf2008-07-26 23:55:291105
[email protected]fd847792013-10-24 17:12:351106 base::TimeTicks start_time;
charliea3be839702015-01-26 17:35:411107 if (base::TimeTicks::IsHighResolution())
1108 start_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351109
miletusfed8c43b2015-01-26 20:04:521110 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent",
jdduke07788062014-12-05 03:16:301111 "event", WebInputEventTraits::GetName(input_event->type));
[email protected]b2e92592014-01-10 15:47:151112 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent");
yuhaoz8df9334c2015-08-18 17:48:511113 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1114 "LatencyInfo.Flow",
1115 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
1116 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1117 "step", "HandleInputEventMain");
[email protected]b4841e1c2013-05-16 22:30:101118
jdduke07788062014-12-05 03:16:301119 // If we don't have a high res timer, these metrics won't be accurate enough
1120 // to be worth collecting. Note that this does introduce some sampling bias.
1121 if (!start_time.is_null())
miletus14a25642015-08-13 19:23:231122 LogInputEventLatencyUma(*input_event, start_time, latency_info);
jdduke07788062014-12-05 03:16:301123
[email protected]6be422b2013-12-08 06:47:311124 scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor;
[email protected]205294b2014-03-18 20:48:351125 ui::LatencyInfo swap_latency_info(latency_info);
[email protected]6be422b2013-12-08 06:47:311126 if (compositor_) {
1127 latency_info_swap_promise_monitor =
[email protected]205294b2014-03-18 20:48:351128 compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)
1129 .Pass();
[email protected]6be422b2013-12-08 06:47:311130 }
[email protected]c2eaa8f2013-05-10 02:41:551131
[email protected]67bfb83f2011-09-22 03:36:371132 bool prevent_default = false;
1133 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261134 const WebMouseEvent& mouse_event =
1135 *static_cast<const WebMouseEvent*>(input_event);
1136 TRACE_EVENT2("renderer", "HandleMouseMove",
1137 "x", mouse_event.x, "y", mouse_event.y);
[email protected]a09d53ce2014-01-31 00:46:421138 context_menu_source_type_ = ui::MENU_SOURCE_MOUSE;
[email protected]936c6f52011-12-13 01:35:261139 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371140 }
1141
[email protected]cefe9b152014-03-27 18:16:151142 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
[email protected]a09d53ce2014-01-31 00:46:421143 context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD;
[email protected]cefe9b152014-03-27 18:16:151144#if defined(OS_ANDROID)
1145 // The DPAD_CENTER key on Android has a dual semantic: (1) in the general
1146 // case it should behave like a select key (i.e. causing a click if a button
1147 // is focused). However, if a text field is focused (2), its intended
1148 // behavior is to just show the IME and don't propagate the key.
1149 // A typical use case is a web form: the DPAD_CENTER should bring up the IME
1150 // when clicked on an input text field and cause the form submit if clicked
1151 // when the submit button is focused, but not vice-versa.
1152 // The UI layer takes care of translating DPAD_CENTER into a RETURN key,
1153 // but at this point we have to swallow the event for the scenario (2).
1154 const WebKeyboardEvent& key_event =
1155 *static_cast<const WebKeyboardEvent*>(input_event);
1156 if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER &&
1157 GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
1158 OnShowImeIfNeeded();
1159 prevent_default = true;
1160 }
1161#endif
1162 }
[email protected]f56c7872013-06-18 12:31:571163
[email protected]41d86852012-11-07 12:23:241164 if (WebInputEvent::isGestureEventType(input_event->type)) {
1165 const WebGestureEvent& gesture_event =
1166 *static_cast<const WebGestureEvent*>(input_event);
[email protected]a09d53ce2014-01-31 00:46:421167 context_menu_source_type_ = ui::MENU_SOURCE_TOUCH;
[email protected]41d86852012-11-07 12:23:241168 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1169 }
1170
[email protected]67bfb83f2011-09-22 03:36:371171 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121172 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1173 suppress_next_char_events_ = false;
1174 if (!processed && webwidget_)
1175 processed = webwidget_->handleInputEvent(*input_event);
1176 }
1177
1178 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1179 // it's not processed by webkit, then we need to suppress the upcoming Char
1180 // events.
jdduke0cf1e662015-10-15 22:43:281181 bool is_keyboard_shortcut =
1182 input_event->type == WebInputEvent::RawKeyDown &&
1183 static_cast<const WebKeyboardEvent*>(input_event)->isBrowserShortcut;
[email protected]b68a0e52011-12-08 15:11:121184 if (!processed && is_keyboard_shortcut)
1185 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291186
[email protected]3d5c243b2012-11-30 00:26:011187 InputEventAckState ack_result = processed ?
1188 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1189 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1190 const WebTouchEvent& touch_event =
1191 *static_cast<const WebTouchEvent*>(input_event);
[email protected]f8ed4722013-12-03 03:27:251192 // Hit-test for all the pressed touch points. If there is a touch-handler
1193 // for any of the touch points, then the renderer should continue to receive
1194 // touch events.
1195 ack_result = INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1196 for (size_t i = 0; i < touch_event.touchesLength; ++i) {
1197 if (touch_event.touches[i].state == WebTouchPoint::StatePressed &&
[email protected]a66e18e2014-01-29 20:58:271198 HasTouchEventHandlersAt(
[email protected]9c769d412014-03-20 18:27:391199 gfx::ToFlooredPoint(touch_event.touches[i].position))) {
[email protected]f8ed4722013-12-03 03:27:251200 ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1201 break;
1202 }
1203 }
[email protected]3d5c243b2012-11-30 00:26:011204 }
1205
ccamerond4ba47902014-12-17 07:20:311206 // Send mouse wheel events and their disposition to the compositor thread, so
1207 // that they can be used to produce the elastic overscroll effect on Mac.
1208 if (input_event->type == WebInputEvent::MouseWheel) {
ccamerona7644752014-12-30 01:16:311209 ObserveWheelEventAndResult(
sataya.mf405d0e2015-07-07 16:51:111210 static_cast<const WebMouseWheelEvent&>(*input_event),
1211 event_overscroll ? event_overscroll->latest_overscroll_delta
1212 : gfx::Vector2dF(),
1213 processed);
ccamerond4ba47902014-12-17 07:20:311214 }
1215
[email protected]721e2302014-04-30 23:42:011216 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested();
[email protected]8926c602013-01-23 05:32:061217
charliea3be839702015-01-26 17:35:411218 // If we don't have a fast and accurate Now(), we assume the input handlers
1219 // are heavy and rate limit them.
jdduke07788062014-12-05 03:16:301220 bool rate_limiting_wanted =
1221 input_event->type == WebInputEvent::MouseMove ||
1222 input_event->type == WebInputEvent::MouseWheel;
1223 if (rate_limiting_wanted && !start_time.is_null()) {
charliea3be839702015-01-26 17:35:411224 base::TimeTicks end_time = base::TimeTicks::Now();
[email protected]fd847792013-10-24 17:12:351225 total_input_handling_time_this_frame_ += (end_time - start_time);
1226 rate_limiting_wanted =
1227 total_input_handling_time_this_frame_.InMicroseconds() >
1228 kInputHandlingTimeThrottlingThresholdMicroseconds;
1229 }
1230
[email protected]7f19e9d2014-05-09 15:16:291231 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent");
1232
[email protected]c27dd4f2014-05-22 18:05:191233 // Note that we can't use handling_event_type_ here since it will be overriden
1234 // by reentrant calls for events after the paused one.
1235 bool no_ack = ignore_ack_for_mouse_move_from_debugger_ &&
1236 input_event->type == WebInputEvent::MouseMove;
lanweif1a22832015-05-19 17:24:101237 if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) &&
1238 !no_ack) {
1239 InputEventAck ack(input_event->type, ack_result, swap_latency_info,
jddukec05612b2015-06-25 23:13:181240 event_overscroll.Pass(),
lanweif1a22832015-05-19 17:24:101241 WebInputEventTraits::GetUniqueTouchEventId(*input_event));
[email protected]34afe102013-12-13 17:24:551242 scoped_ptr<IPC::Message> response(
[email protected]8e431f2032014-05-20 02:34:561243 new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
jdduke07788062014-12-05 03:16:301244 if (rate_limiting_wanted && frame_pending && !is_hidden_) {
[email protected]34afe102013-12-13 17:24:551245 // We want to rate limit the input events in this case, so we'll wait for
1246 // painting to finish before ACKing this message.
1247 TRACE_EVENT_INSTANT0("renderer",
1248 "RenderWidget::OnHandleInputEvent ack throttled",
1249 TRACE_EVENT_SCOPE_THREAD);
1250 if (pending_input_event_ack_) {
jddukefffb67c2015-01-07 22:32:291251 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1252 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551253 // As two different kinds of events could cause us to postpone an ack
1254 // we send it now, if we have one pending. The Browser should never
1255 // send us the same kind of event we are delaying the ack for.
1256 Send(pending_input_event_ack_.release());
1257 }
1258 pending_input_event_ack_ = response.Pass();
jddukefffb67c2015-01-07 22:32:291259 TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck",
1260 pending_input_event_ack_.get());
[email protected]34afe102013-12-13 17:24:551261 if (compositor_)
1262 compositor_->NotifyInputThrottledUntilCommit();
1263 } else {
1264 Send(response.release());
[email protected]353a34c2010-05-28 23:35:171265 }
jddukec05612b2015-06-25 23:13:181266 } else {
1267 DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event";
[email protected]12fbad812009-09-01 18:21:241268 }
alexclarke7819e2552015-06-03 11:17:211269 if (!no_ack && RenderThreadImpl::current()) {
1270 RenderThreadImpl::current()
1271 ->GetRendererScheduler()
1272 ->DidHandleInputEventOnMainThread(*input_event);
1273 }
[email protected]5fea4a52014-05-27 00:17:521274 if (input_event->type == WebInputEvent::MouseMove)
1275 ignore_ack_for_mouse_move_from_debugger_ = false;
[email protected]12fbad812009-09-01 18:21:241276
[email protected]3306f262012-09-21 19:20:421277#if defined(OS_ANDROID)
1278 // Allow the IME to be shown when the focus changes as a consequence
1279 // of a processed touch end event.
1280 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]90f24152014-04-09 12:41:361281 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]183e28d2014-01-20 18:18:021282#elif defined(USE_AURA)
1283 // Show the virtual keyboard if enabled and a user gesture triggers a focus
1284 // change.
1285 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
rouslanf7ebd8832015-01-22 01:54:141286 input_event->type == WebInputEvent::MouseUp)) {
[email protected]90f24152014-04-09 12:41:361287 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME);
rouslanf7ebd8832015-01-22 01:54:141288 }
[email protected]3306f262012-09-21 19:20:421289#endif
1290
[email protected]67bfb83f2011-09-22 03:36:371291 if (!prevent_default) {
1292 if (WebInputEvent::isKeyboardEventType(input_event->type))
1293 DidHandleKeyEvent();
[email protected]67bfb83f2011-09-22 03:36:371294 }
rouslanf7ebd8832015-01-22 01:54:141295
1296// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1297// virtual keyboard.
1298#if !defined(OS_ANDROID)
1299 // Virtual keyboard is not supported, so react to focus change immediately.
1300 if (processed && (input_event->type == WebInputEvent::TouchEnd ||
1301 input_event->type == WebInputEvent::MouseUp)) {
1302 FocusChangeComplete();
1303 }
1304#endif
initial.commit09911bf2008-07-26 23:55:291305}
1306
[email protected]34202de2013-05-06 23:36:221307void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1308 if (webwidget_)
1309 webwidget_->setCursorVisibilityState(is_visible);
1310}
1311
initial.commit09911bf2008-07-26 23:55:291312void RenderWidget::OnMouseCaptureLost() {
1313 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281314 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291315}
1316
1317void RenderWidget::OnSetFocus(bool enable) {
[email protected]9d166af2010-03-02 22:04:331318 if (webwidget_)
1319 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291320}
1321
[email protected]fd847792013-10-24 17:12:351322void RenderWidget::FlushPendingInputEventAck() {
jddukefffb67c2015-01-07 22:32:291323 if (pending_input_event_ack_) {
1324 TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck",
1325 pending_input_event_ack_.get());
[email protected]d8a8ecb2013-10-23 18:03:071326 Send(pending_input_event_ack_.release());
jddukefffb67c2015-01-07 22:32:291327 }
[email protected]fd847792013-10-24 17:12:351328 total_input_handling_time_this_frame_ = base::TimeDelta();
1329}
1330
initial.commit09911bf2008-07-26 23:55:291331///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461332// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291333
[email protected]244ac1892011-12-02 17:04:471334void RenderWidget::didAutoResize(const WebSize& new_size) {
oshima750cb4342015-10-31 00:59:011335 // TODO(oshima): support UseZoomForDSFEnabled()
[email protected]ea3ee0a2012-05-15 03:43:091336 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451337 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581338
[email protected]5b45ad42013-10-25 00:42:041339 if (resizing_mode_selector_->is_synchronous_mode()) {
[email protected]eac2b362013-05-22 07:01:451340 WebRect new_pos(rootWindowRect().x,
1341 rootWindowRect().y,
1342 new_size.width,
1343 new_size.height);
1344 view_screen_rect_ = new_pos;
1345 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031346 }
[email protected]20fbfc22013-05-08 20:50:581347
[email protected]eac2b362013-05-22 07:01:451348 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581349
[email protected]5b45ad42013-10-25 00:42:041350 if (!resizing_mode_selector_->is_synchronous_mode())
[email protected]20fbfc22013-05-08 20:50:581351 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091352 }
[email protected]244ac1892011-12-02 17:04:471353}
1354
[email protected]3a1c8a8032013-03-18 22:35:321355void RenderWidget::AutoResizeCompositor() {
danakjddaec912015-09-25 19:38:401356 physical_backing_size_ = gfx::ScaleToCeiledSize(size_, device_scale_factor_);
[email protected]97e1bf72013-03-06 14:06:051357 if (compositor_)
oshima750cb4342015-10-31 00:59:011358 compositor_->setViewportSize(physical_backing_size_);
[email protected]97e1bf72013-03-06 14:06:051359}
1360
[email protected]e195e582013-03-08 01:32:591361void RenderWidget::initializeLayerTreeView() {
[email protected]aeeedad2014-08-22 18:16:221362 DCHECK(!host_closing_);
1363
danakj6e3bf8012014-12-16 18:27:531364 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_);
oshima750cb4342015-10-31 00:59:011365 compositor_->setViewportSize(physical_backing_size_);
sievers71c62dd52015-10-07 01:44:391366
1367 // For background pages and certain tests, we don't want to trigger
1368 // OutputSurface creation.
1369 if (compositor_never_visible_ || !RenderThreadImpl::current())
1370 compositor_->SetNeverVisible();
1371
pimanc4af3072015-10-02 03:45:591372 StartCompositor();
[email protected]e195e582013-03-08 01:32:591373}
1374
ennef3c58142014-12-09 21:44:381375void RenderWidget::WillCloseLayerTreeView() {
1376 if (host_closing_)
1377 return;
1378
1379 // Prevent new compositors or output surfaces from being created.
1380 host_closing_ = true;
1381
[email protected]aeeedad2014-08-22 18:16:221382 // Always send this notification to prevent new layer tree views from
1383 // being created, even if one hasn't been created yet.
1384 if (webwidget_)
1385 webwidget_->willCloseLayerTreeView();
[email protected]aeeedad2014-08-22 18:16:221386}
1387
[email protected]180ef242013-11-07 06:50:461388blink::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281389 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061390}
1391
dglazkovf0e1d6d2015-10-10 02:13:481392void RenderWidget::didMeaningfulLayout(blink::WebMeaningfulLayout layout_type) {
1393 if (layout_type == blink::WebMeaningfulLayout::VisuallyNonEmpty) {
1394 QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_),
1395 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
1396 }
dglazkov79c426102015-08-31 21:22:431397
dglazkovf0e1d6d2015-10-10 02:13:481398 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1399 DidMeaningfulLayout(layout_type));
dglazkov79c426102015-08-31 21:22:431400}
1401
jdduke491a3f0c2015-06-15 23:30:261402void RenderWidget::WillBeginCompositorFrame() {
[email protected]9cd43a62012-03-26 08:03:561403 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371404
shuchen913f8b622015-07-31 13:22:431405 // The UpdateTextInputState can result in further layout and possibly
[email protected]abe8b3a2012-03-28 21:19:371406 // enable GPU acceleration so they need to be called before any painting
1407 // is done.
[email protected]90f24152014-04-09 12:41:361408 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
[email protected]abe8b3a2012-03-28 21:19:371409 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561410}
1411
[email protected]6fceb912013-02-15 06:24:151412void RenderWidget::DidCommitCompositorFrame() {
fsamuel2e9413d2015-02-25 01:25:441413 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_,
1414 DidCommitCompositorFrame());
[email protected]e3244ed2014-06-20 20:04:271415 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
[email protected]bffc8302014-01-23 20:52:161416 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171417#if defined(VIDEO_HOLE)
[email protected]e3244ed2014-06-20 20:04:271418 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1419 DidCommitCompositorFrame());
[email protected]a017938b2014-05-27 21:17:171420#endif // defined(VIDEO_HOLE)
jdduke491a3f0c2015-06-15 23:30:261421 FlushPendingInputEventAck();
1422}
1423
1424void RenderWidget::DidCommitAndDrawCompositorFrame() {
1425 // NOTE: Tests may break if this event is renamed or moved. See
1426 // tab_capture_performancetest.cc.
1427 TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame");
1428 // Notify subclasses that we initiated the paint operation.
1429 DidInitiatePaint();
1430}
1431
1432void RenderWidget::DidCompleteSwapBuffers() {
1433 TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers");
1434
1435 // Notify subclasses threaded composited rendering was flushed to the screen.
1436 DidFlushPaint();
1437
1438 if (!next_paint_flags_ &&
1439 !need_update_rect_for_auto_resize_ &&
1440 !plugin_window_moves_.size()) {
1441 return;
1442 }
1443
1444 ViewHostMsg_UpdateRect_Params params;
1445 params.view_size = size_;
1446 params.plugin_window_moves.swap(plugin_window_moves_);
1447 params.flags = next_paint_flags_;
1448
1449 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1450 next_paint_flags_ = 0;
1451 need_update_rect_for_auto_resize_ = false;
1452}
1453
1454void RenderWidget::ScheduleComposite() {
1455 if (compositor_ &&
1456 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) {
1457 compositor_->setNeedsAnimate();
1458 }
1459}
1460
1461void RenderWidget::ScheduleCompositeWithForcedRedraw() {
1462 if (compositor_) {
1463 // Regardless of whether threaded compositing is enabled, always
1464 // use this mechanism to force the compositor to redraw. However,
1465 // the invalidation code path below is still needed for the
1466 // non-threaded case.
1467 compositor_->SetNeedsForcedRedraw();
1468 }
1469 ScheduleComposite();
[email protected]6fceb912013-02-15 06:24:151470}
1471
[email protected]586871b2014-07-22 17:05:111472// static
1473scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1474 IPC::Message* msg,
1475 MessageDeliveryPolicy policy,
1476 FrameSwapMessageQueue* frame_swap_message_queue,
1477 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
[email protected]586871b2014-07-22 17:05:111478 int source_frame_number) {
[email protected]586871b2014-07-22 17:05:111479 bool first_message_for_frame = false;
1480 frame_swap_message_queue->QueueMessageForFrame(policy,
1481 source_frame_number,
1482 make_scoped_ptr(msg),
1483 &first_message_for_frame);
1484 if (first_message_for_frame) {
1485 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1486 sync_message_filter, frame_swap_message_queue, source_frame_number));
dcheng4b6b5ff2014-10-16 00:42:061487 return promise;
[email protected]586871b2014-07-22 17:05:111488 }
dcheng4b6b5ff2014-10-16 00:42:061489 return nullptr;
[email protected]586871b2014-07-22 17:05:111490}
1491
1492void RenderWidget::QueueMessage(IPC::Message* msg,
1493 MessageDeliveryPolicy policy) {
1494 // RenderThreadImpl::current() is NULL in some tests.
1495 if (!compositor_ || !RenderThreadImpl::current()) {
1496 Send(msg);
1497 return;
1498 }
1499
1500 scoped_ptr<cc::SwapPromise> swap_promise =
1501 QueueMessageImpl(msg,
1502 policy,
dcheng58867a92014-08-26 02:50:221503 frame_swap_message_queue_.get(),
[email protected]586871b2014-07-22 17:05:111504 RenderThreadImpl::current()->sync_message_filter(),
[email protected]586871b2014-07-22 17:05:111505 compositor_->GetSourceFrameNumber());
1506
1507 if (swap_promise) {
1508 compositor_->QueueSwapPromise(swap_promise.Pass());
igsollaeab34cc2015-02-20 11:33:351509 // Request a commit. This might either A) request a commit ahead of time
1510 // or B) request a commit which is not needed because there are not
1511 // pending updates. If B) then the commit will be skipped and the swap
1512 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we
1513 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that
1514 // can_cancel_commit is not unset.
1515 compositor_->SetNeedsUpdateLayers();
[email protected]586871b2014-07-22 17:05:111516 }
1517}
1518
[email protected]4873c7d2009-07-16 06:36:281519void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301520 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521521 WebCursor cursor;
tfarina75a0abf2015-10-06 15:07:181522 InitializeCursorFromWebCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291523 // Only send a SetCursor message if we need to make a change.
1524 if (!current_cursor_.IsEqual(cursor)) {
1525 current_cursor_ = cursor;
1526 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1527 }
1528}
1529
1530// We are supposed to get a single call to Show for a newly created RenderWidget
1531// that was created via RenderWidget::CreateWebView. So, we wait until this
1532// point to dispatch the ShowWidget message.
1533//
1534// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281535// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291536//
[email protected]4873c7d2009-07-16 06:36:281537void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291538 DCHECK(!did_show_) << "received extraneous Show call";
1539 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1540 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1541
[email protected]8de12d942010-11-17 20:42:441542 if (did_show_)
1543 return;
1544
1545 did_show_ = true;
bokanc007c3a2015-02-03 07:15:561546 // NOTE: initial_rect_ may still have its default values at this point, but
[email protected]8de12d942010-11-17 20:42:441547 // that's okay. It'll be ignored if as_popup is false, or the browser
1548 // process will impose a default position otherwise.
bokanc007c3a2015-02-03 07:15:561549 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_));
1550 SetPendingWindowRect(initial_rect_);
initial.commit09911bf2008-07-26 23:55:291551}
1552
[email protected]4873c7d2009-07-16 06:36:281553void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291554}
1555
[email protected]2533ce12009-05-09 00:02:241556void RenderWidget::DoDeferredClose() {
ennef3c58142014-12-09 21:44:381557 WillCloseLayerTreeView();
[email protected]2533ce12009-05-09 00:02:241558 Send(new ViewHostMsg_Close(routing_id_));
1559}
1560
dgozmancf9039cd2015-04-06 12:01:311561void RenderWidget::NotifyOnClose() {
1562 FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose());
1563}
1564
[email protected]4873c7d2009-07-16 06:36:281565void RenderWidget::closeWidgetSoon() {
skyostiled8969c2015-07-20 16:57:081566 DCHECK(content::RenderThread::Get());
[email protected]e1c3a552012-05-04 20:51:321567 if (is_swapped_out_) {
1568 // This widget is currently swapped out, and the active widget is in a
1569 // different process. Have the browser route the close request to the
1570 // active widget instead, so that the correct unload handlers are run.
1571 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1572 return;
1573 }
1574
initial.commit09911bf2008-07-26 23:55:291575 // If a page calls window.close() twice, we'll end up here twice, but that's
1576 // OK. It is safe to send multiple Close messages.
1577
[email protected]2533ce12009-05-09 00:02:241578 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1579 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1580 // could be closed before the JS finishes executing. So instead, post a
1581 // message back to the message loop, which won't run until the JS is
1582 // complete, and then the Close message can be sent.
skyostiled8969c2015-07-20 16:57:081583 base::ThreadTaskRunnerHandle::Get()->PostTask(
[email protected]32876ae2011-11-15 22:25:211584 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291585}
1586
[email protected]9017d7852013-11-21 17:47:351587void RenderWidget::QueueSyntheticGesture(
1588 scoped_ptr<SyntheticGestureParams> gesture_params,
1589 const SyntheticGestureCompletionCallback& callback) {
1590 DCHECK(!callback.is_null());
1591
1592 pending_synthetic_gesture_callbacks_.push(callback);
1593
1594 SyntheticGesturePacket gesture_packet;
1595 gesture_packet.set_gesture_params(gesture_params.Pass());
1596
1597 Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet));
1598}
1599
initial.commit09911bf2008-07-26 23:55:291600void RenderWidget::Close() {
[email protected]404630b2014-07-03 19:33:031601 screen_metrics_emulator_.reset();
ennef3c58142014-12-09 21:44:381602 WillCloseLayerTreeView();
1603 compositor_.reset();
initial.commit09911bf2008-07-26 23:55:291604 if (webwidget_) {
[email protected]4873c7d2009-07-16 06:36:281605 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291606 webwidget_ = NULL;
1607 }
1608}
1609
[email protected]4873c7d2009-07-16 06:36:281610WebRect RenderWidget::windowRect() {
1611 if (pending_window_rect_count_)
1612 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241613
[email protected]80ad8622012-11-07 16:33:031614 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291615}
1616
[email protected]180ef242013-11-07 06:50:461617void RenderWidget::setToolTipText(const blink::WebString& text,
[email protected]8a9d6ca32011-06-06 20:11:301618 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541619 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301620}
1621
[email protected]b2e4c70132013-10-03 02:07:511622void RenderWidget::setWindowRect(const WebRect& rect) {
oshima750cb4342015-10-31 00:59:011623 // TODO(oshima): Scale back to DIP coordinates.
bokanc007c3a2015-02-03 07:15:561624 WebRect window_rect = rect;
[email protected]b2e4c70132013-10-03 02:07:511625 if (popup_origin_scale_for_emulation_) {
1626 float scale = popup_origin_scale_for_emulation_;
bokanc007c3a2015-02-03 07:15:561627 window_rect.x = popup_screen_origin_for_emulation_.x() +
1628 (window_rect.x - popup_view_origin_for_emulation_.x()) * scale;
1629 window_rect.y = popup_screen_origin_for_emulation_.y() +
1630 (window_rect.y - popup_view_origin_for_emulation_.y()) * scale;
[email protected]b2e4c70132013-10-03 02:07:511631 }
1632
[email protected]5b45ad42013-10-25 00:42:041633 if (!resizing_mode_selector_->is_synchronous_mode()) {
[email protected]ec951b9d2013-10-20 06:21:201634 if (did_show_) {
bokanc007c3a2015-02-03 07:15:561635 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect));
1636 SetPendingWindowRect(window_rect);
[email protected]8be1c582013-03-06 00:55:031637 } else {
bokanc007c3a2015-02-03 07:15:561638 initial_rect_ = window_rect;
[email protected]8be1c582013-03-06 00:55:031639 }
initial.commit09911bf2008-07-26 23:55:291640 } else {
bokanc007c3a2015-02-03 07:15:561641 SetWindowRectSynchronously(window_rect);
initial.commit09911bf2008-07-26 23:55:291642 }
1643}
1644
[email protected]2533ce12009-05-09 00:02:241645void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1646 pending_window_rect_ = rect;
1647 pending_window_rect_count_++;
1648}
1649
[email protected]4873c7d2009-07-16 06:36:281650WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241651 if (pending_window_rect_count_) {
1652 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1653 // the RootWindowRect is probably going to return wrong results since the
1654 // browser may not have processed the Move yet. There isn't really anything
1655 // good to do in this case, and it shouldn't happen - since this size is
1656 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281657 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241658 }
1659
[email protected]80ad8622012-11-07 16:33:031660 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371661}
1662
[email protected]4873c7d2009-07-16 06:36:281663WebRect RenderWidget::windowResizerRect() {
1664 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191665}
1666
[email protected]fa7b1dc2010-06-23 17:53:041667void RenderWidget::OnImeSetComposition(
[email protected]fcf75d42013-12-03 20:11:261668 const base::string16& text,
[email protected]fa7b1dc2010-06-23 17:53:041669 const std::vector<WebCompositionUnderline>& underlines,
1670 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:131671 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:281672 return;
[email protected]66fca5bc2013-05-23 06:58:291673 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361674 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041675 text, WebVector<WebCompositionUnderline>(underlines),
1676 selection_start, selection_end)) {
1677 // If we failed to set the composition text, then we need to let the browser
1678 // process to cancel the input method's ongoing composition session, to make
1679 // sure we are in a consistent state.
[email protected]a2214eb2014-06-23 18:31:221680 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:261681 }
[email protected]88dbe32f2013-06-20 23:31:361682 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041683}
1684
[email protected]fcf75d42013-12-03 20:11:261685void RenderWidget::OnImeConfirmComposition(const base::string16& text,
[email protected]db4fc1e2013-09-06 20:01:511686 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:021687 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:131688 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:041689 return;
[email protected]66fca5bc2013-05-23 06:58:291690 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041691 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:021692 if (text.length())
1693 webwidget_->confirmComposition(text);
1694 else if (keep_selection)
1695 webwidget_->confirmComposition(WebWidget::KeepSelection);
1696 else
1697 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:041698 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361699 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291700}
1701
[email protected]0bc1f572013-04-17 01:46:311702void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121703 // During shutdown we can just ignore this message.
1704 if (!webwidget_)
1705 return;
1706
[email protected]0bc1f572013-04-17 01:46:311707 // Even if the browser provides an empty damage rect, it's still expecting to
1708 // receive a repaint ack so just damage the entire widget bounds.
1709 if (size_to_paint.IsEmpty()) {
1710 size_to_paint = size_;
1711 }
1712
[email protected]ec7dc112008-08-06 05:30:121713 set_next_paint_is_repaint_ack();
[email protected]aca33f4f2014-05-17 17:08:051714 if (compositor_)
[email protected]0bc1f572013-04-17 01:46:311715 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]ec7dc112008-08-06 05:30:121716}
1717
[email protected]79fa22e2013-08-23 15:18:121718void RenderWidget::OnSyntheticGestureCompleted() {
[email protected]9017d7852013-11-21 17:47:351719 DCHECK(!pending_synthetic_gesture_callbacks_.empty());
1720
1721 pending_synthetic_gesture_callbacks_.front().Run();
1722 pending_synthetic_gesture_callbacks_.pop();
[email protected]0e241b4b2012-08-18 09:06:271723}
1724
[email protected]4873c7d2009-07-16 06:36:281725void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111726 if (!webwidget_)
1727 return;
[email protected]4873c7d2009-07-16 06:36:281728 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111729}
1730
[email protected]80ad8622012-11-07 16:33:031731void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1732 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:511733 if (screen_metrics_emulator_) {
1734 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
1735 view_screen_rect, window_screen_rect);
1736 } else {
1737 view_screen_rect_ = view_screen_rect;
1738 window_screen_rect_ = window_screen_rect;
1739 }
[email protected]80ad8622012-11-07 16:33:031740 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1741}
1742
kenrbb4e2a3b2015-05-14 15:05:051743void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) {
1744 if (compositor_)
1745 compositor_->SetSurfaceIdNamespace(surface_id_namespace);
1746}
1747
[email protected]adb362312014-06-28 06:04:241748void RenderWidget::showImeIfNeeded() {
1749 OnShowImeIfNeeded();
[email protected]0d1ebed12013-08-05 22:01:131750}
1751
[email protected]adb362312014-06-28 06:04:241752void RenderWidget::OnShowImeIfNeeded() {
1753#if defined(OS_ANDROID) || defined(USE_AURA)
1754 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
1755#endif
rouslanf7ebd8832015-01-22 01:54:141756
1757// TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with
1758// virtual keyboard.
1759#if !defined(OS_ANDROID)
1760 FocusChangeComplete();
1761#endif
[email protected]adb362312014-06-28 06:04:241762}
1763
1764#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371765void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) {
1766 text_input_info_history_.push_back(info);
[email protected]0d1ebed12013-08-05 22:01:131767}
1768
1769void RenderWidget::OnImeEventAck() {
changwan3a841162015-08-11 02:53:371770 DCHECK_GE(text_input_info_history_.size(), 1u);
1771 text_input_info_history_.pop_front();
[email protected]2384b6c2013-02-28 23:58:511772}
[email protected]105dffb42013-02-20 03:46:211773#endif
1774
[email protected]0d1ebed12013-08-05 22:01:131775bool RenderWidget::ShouldHandleImeEvent() {
1776#if defined(OS_ANDROID)
changwan3a841162015-08-11 02:53:371777 if (!webwidget_)
1778 return false;
1779
1780 // We cannot handle IME events if there is any chance that the event we are
1781 // receiving here from the browser is based on the state that is different
1782 // from our current one as indicated by |text_input_info_|.
1783 // The states the browser might be in are:
1784 // text_input_info_history_[0] - current state ack'd by browser
1785 // text_input_info_history_[1...N] - pending state changes
1786 for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) {
1787 if (text_input_info_history_[i] != text_input_info_)
1788 return false;
1789 }
1790 return true;
[email protected]0d1ebed12013-08-05 22:01:131791#else
1792 return !!webwidget_;
1793#endif
1794}
1795
[email protected]c27dd4f2014-05-22 18:05:191796bool RenderWidget::SendAckForMouseMoveFromDebugger() {
1797 if (handling_event_type_ == WebInputEvent::MouseMove) {
[email protected]5fea4a52014-05-27 00:17:521798 // If we pause multiple times during a single mouse move event, we should
1799 // only send ACK once.
1800 if (!ignore_ack_for_mouse_move_from_debugger_) {
lanweif1a22832015-05-19 17:24:101801 InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED);
[email protected]5fea4a52014-05-27 00:17:521802 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
dgozmanb739185d2015-04-10 15:04:021803 return true;
[email protected]5fea4a52014-05-27 00:17:521804 }
[email protected]c27dd4f2014-05-22 18:05:191805 }
1806 return false;
1807}
1808
1809void RenderWidget::IgnoreAckForMouseMoveFromDebugger() {
1810 ignore_ack_for_mouse_move_from_debugger_ = true;
1811}
1812
[email protected]468ac582012-11-20 00:53:191813void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1814 if (device_scale_factor_ == device_scale_factor)
1815 return;
1816
1817 device_scale_factor_ = device_scale_factor;
jdduke491a3f0c2015-06-15 23:30:261818 ScheduleComposite();
[email protected]468ac582012-11-20 00:53:191819}
1820
[email protected]28ed6b32014-06-08 02:16:271821bool RenderWidget::SetDeviceColorProfile(
1822 const std::vector<char>& color_profile) {
1823 if (device_color_profile_ == color_profile)
1824 return false;
1825
1826 device_color_profile_ = color_profile;
1827 return true;
1828}
1829
noeldb4df152014-09-16 17:45:201830void RenderWidget::ResetDeviceColorProfileForTesting() {
1831 if (!device_color_profile_.empty())
1832 device_color_profile_.clear();
1833 device_color_profile_.push_back('0');
1834}
1835
[email protected]fcdc5642014-05-09 14:32:241836void RenderWidget::OnOrientationChange() {
1837}
1838
[email protected]ceb36f7d2012-10-31 18:33:241839gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521840 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241841 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521842}
1843
[email protected]bee16aab2009-08-26 15:55:031844void RenderWidget::SetHidden(bool hidden) {
1845 if (is_hidden_ == hidden)
1846 return;
1847
jdduke8fac9d102014-12-20 02:40:131848 // The status has changed. Tell the RenderThread about it and ensure
1849 // throttled acks are released in case frame production ceases.
[email protected]bee16aab2009-08-26 15:55:031850 is_hidden_ = hidden;
jdduke8fac9d102014-12-20 02:40:131851 FlushPendingInputEventAck();
1852
[email protected]bee16aab2009-08-26 15:55:031853 if (is_hidden_)
[email protected]b2db9272014-01-10 17:42:001854 RenderThreadImpl::current()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031855 else
[email protected]b2db9272014-01-10 17:42:001856 RenderThreadImpl::current()->WidgetRestored();
alexclarke7fa93942015-10-21 15:37:111857
1858 if (render_widget_scheduling_state_)
1859 render_widget_scheduling_state_->SetHidden(hidden);
[email protected]bee16aab2009-08-26 15:55:031860}
1861
[email protected]2b624c562011-10-27 22:58:261862void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261863 if (!webwidget_)
1864 return;
1865
mikhail.pozdnyakovf2c902a2015-04-14 08:09:121866 if (is_fullscreen_granted_) {
[email protected]2b624c562011-10-27 22:58:261867 webwidget_->didEnterFullScreen();
1868 } else {
1869 webwidget_->didExitFullScreen();
1870 }
[email protected]2b624c562011-10-27 22:58:261871}
1872
[email protected]674741932009-02-04 23:44:461873bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:051874 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:461875}
1876
[email protected]674741932009-02-04 23:44:461877void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:051878 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:461879}
1880
[email protected]674741932009-02-04 23:44:461881void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:051882 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:461883}
1884
[email protected]b18583c2012-12-18 06:55:271885static bool IsDateTimeInput(ui::TextInputType type) {
1886 return type == ui::TEXT_INPUT_TYPE_DATE ||
1887 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
1888 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
1889 type == ui::TEXT_INPUT_TYPE_MONTH ||
1890 type == ui::TEXT_INPUT_TYPE_TIME ||
1891 type == ui::TEXT_INPUT_TYPE_WEEK;
1892}
1893
changwanf2a707b2015-10-30 08:22:161894void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) {
1895 if (!ime_event_guard_)
1896 ime_event_guard_ = guard;
[email protected]66fca5bc2013-05-23 06:58:291897}
1898
changwanf2a707b2015-10-30 08:22:161899void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) {
1900 if (ime_event_guard_ != guard) {
1901#if defined(OS_ANDROID)
1902 // In case a from-IME event (e.g. touch) ends up in not-from-IME event
1903 // (e.g. long press gesture), we want to treat it as not-from-IME event
1904 // so that AdapterInputConnection can make changes to its Editable model.
1905 // Therefore, we want to mark this text state update as 'from IME' only
1906 // when all the nested events are all originating from IME.
1907 ime_event_guard_->set_from_ime(
1908 ime_event_guard_->from_ime() && guard->from_ime());
1909#endif
1910 return;
1911 }
1912 ime_event_guard_ = nullptr;
1913
[email protected]66fca5bc2013-05-23 06:58:291914 // While handling an ime event, text input state and selection bounds updates
1915 // are ignored. These must explicitly be updated once finished handling the
1916 // ime event.
1917 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:471918#if defined(OS_ANDROID)
changwanf2a707b2015-10-30 08:22:161919 UpdateTextInputState(
1920 guard->show_ime() ? SHOW_IME_IF_NEEDED : NO_SHOW_IME,
1921 guard->from_ime() ? FROM_IME : FROM_NON_IME);
[email protected]cb9e2632013-06-18 11:26:471922#endif
[email protected]66fca5bc2013-05-23 06:58:291923}
1924
[email protected]90f24152014-04-09 12:41:361925void RenderWidget::UpdateTextInputState(ShowIme show_ime,
1926 ChangeSource change_source) {
jdduke1aebad8e2015-07-22 23:25:081927 TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState");
changwanf2a707b2015-10-30 08:22:161928 if (ime_event_guard_) {
1929 // show_ime should still be effective even if it was set inside the IME
1930 // event guard.
1931 if (show_ime == SHOW_IME_IF_NEEDED) {
1932 ime_event_guard_->set_show_ime(true);
1933 }
[email protected]e8f775f2013-02-14 21:00:501934 return;
changwanf2a707b2015-10-30 08:22:161935 }
1936
[email protected]ad26ef42011-06-17 07:59:451937 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:271938 if (IsDateTimeInput(new_type))
1939 return; // Not considered as a text input field in WebKit/Chromium.
1940
[email protected]180ef242013-11-07 06:50:461941 blink::WebTextInputInfo new_info;
[email protected]5b739cb2012-08-21 20:35:211942 if (webwidget_)
1943 new_info = webwidget_->textInputInfo();
shuchen913f8b622015-07-31 13:22:431944 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
[email protected]5b739cb2012-08-21 20:35:211945
[email protected]ad26ef42011-06-17 07:59:451946 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:211947
[email protected]3306f262012-09-21 19:20:421948 // Only sends text input params if they are changed or if the ime should be
1949 // shown.
[email protected]90f24152014-04-09 12:41:361950 if (show_ime == SHOW_IME_IF_NEEDED ||
1951 (text_input_type_ != new_type ||
shuchen913f8b622015-07-31 13:22:431952 text_input_mode_ != new_mode ||
[email protected]90f24152014-04-09 12:41:361953 text_input_info_ != new_info ||
1954 can_compose_inline_ != new_can_compose_inline)
1955#if defined(OS_ANDROID)
1956 || text_field_is_dirty_
[email protected]183e28d2014-01-20 18:18:021957#endif
[email protected]90f24152014-04-09 12:41:361958 ) {
shuchen913f8b622015-07-31 13:22:431959 ViewHostMsg_TextInputState_Params params;
1960 params.type = new_type;
1961 params.mode = new_mode;
1962 params.flags = new_info.flags;
1963 params.value = new_info.value.utf8();
1964 params.selection_start = new_info.selectionStart;
1965 params.selection_end = new_info.selectionEnd;
1966 params.composition_start = new_info.compositionStart;
1967 params.composition_end = new_info.compositionEnd;
1968 params.can_compose_inline = new_can_compose_inline;
1969 params.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
[email protected]90f24152014-04-09 12:41:361970#if defined(USE_AURA)
shuchen913f8b622015-07-31 13:22:431971 params.is_non_ime_change = true;
[email protected]90f24152014-04-09 12:41:361972#endif
[email protected]183e28d2014-01-20 18:18:021973#if defined(OS_ANDROID)
shuchen913f8b622015-07-31 13:22:431974 params.is_non_ime_change = (change_source == FROM_NON_IME) ||
[email protected]90f24152014-04-09 12:41:361975 text_field_is_dirty_;
shuchen913f8b622015-07-31 13:22:431976 if (params.is_non_ime_change)
changwan3a841162015-08-11 02:53:371977 OnImeEventSentForAck(new_info);
[email protected]90f24152014-04-09 12:41:361978 text_field_is_dirty_ = false;
[email protected]183e28d2014-01-20 18:18:021979#endif
shuchen913f8b622015-07-31 13:22:431980 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params));
[email protected]5b739cb2012-08-21 20:35:211981
1982 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:041983 text_input_type_ = new_type;
shuchen913f8b622015-07-31 13:22:431984 text_input_mode_ = new_mode;
[email protected]ad26ef42011-06-17 07:59:451985 can_compose_inline_ = new_can_compose_inline;
shuchen82ce8c52014-10-23 01:55:201986 text_input_flags_ = new_info.flags;
initial.commit09911bf2008-07-26 23:55:291987 }
initial.commit09911bf2008-07-26 23:55:291988}
1989
[email protected]7c8873e2013-02-05 08:03:011990void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
1991 WebRect focus_webrect;
1992 WebRect anchor_webrect;
1993 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
oshima750cb4342015-10-31 00:59:011994 if (IsUseZoomForDSFEnabled()) {
1995 float inverse_scale = 1.f / device_scale_factor_;
1996 gfx::RectF focus_rect(focus_webrect);
1997 *focus = gfx::ToEnclosingRect(gfx::ScaleRect(focus_rect, inverse_scale));
1998 gfx::RectF anchor_rect(anchor_webrect);
1999 *anchor = gfx::ToEnclosingRect(gfx::ScaleRect(anchor_rect, inverse_scale));
2000 } else {
2001 *focus = focus_webrect;
2002 *anchor = anchor_webrect;
2003 }
[email protected]73bf95812011-10-12 11:38:322004}
2005
[email protected]e99ef6f2011-10-16 01:13:002006void RenderWidget::UpdateSelectionBounds() {
jdduke1aebad8e2015-07-22 23:25:082007 TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds");
[email protected]e99ef6f2011-10-16 01:13:002008 if (!webwidget_)
2009 return;
changwanf2a707b2015-10-30 08:22:162010 if (ime_event_guard_)
[email protected]66fca5bc2013-05-23 06:58:292011 return;
[email protected]e99ef6f2011-10-16 01:13:002012
mohsenb0eeba72015-08-09 06:20:082013#if defined(USE_AURA)
2014 // TODO(mohsen): For now, always send explicit selection IPC notifications for
2015 // Aura beucause composited selection updates are not working for webview tags
2016 // which regresses IME inside webview. Remove this when composited selection
2017 // updates are fixed for webviews. See, http://crbug.com/510568.
2018 bool send_ipc = true;
2019#else
jddukeacf809e2014-09-23 20:38:382020 // With composited selection updates, the selection bounds will be reported
2021 // directly by the compositor, in which case explicit IPC selection
2022 // notifications should be suppressed.
mohsenb0eeba72015-08-09 06:20:082023 bool send_ipc =
2024 !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled();
2025#endif
2026 if (send_ipc) {
jddukeacf809e2014-09-23 20:38:382027 ViewHostMsg_SelectionBounds_Params params;
2028 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2029 if (selection_anchor_rect_ != params.anchor_rect ||
2030 selection_focus_rect_ != params.focus_rect) {
2031 selection_anchor_rect_ = params.anchor_rect;
2032 selection_focus_rect_ = params.focus_rect;
2033 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
2034 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
2035 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
2036 }
[email protected]58b48a0d2012-06-13 07:01:352037 }
jddukeacf809e2014-09-23 20:38:382038
[email protected]88dbe32f2013-06-20 23:31:362039 UpdateCompositionInfo(false);
[email protected]e99ef6f2011-10-16 01:13:002040}
2041
[email protected]180ef242013-11-07 06:50:462042// Check blink::WebTextInputType and ui::TextInputType is kept in sync.
mostynbe29b6882015-01-13 09:59:172043#define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \
2044 static_assert(int(blink::WebTextInputType##a) \
2045 == int(ui::TEXT_INPUT_TYPE_##b), \
2046 "mismatching enums: " #a)
2047
2048STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE);
2049STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT);
2050STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD);
2051STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH);
2052STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL);
2053STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER);
2054STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE);
2055STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL);
2056STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE);
2057STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME);
2058STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL);
2059STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH);
2060STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME);
2061STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK);
2062STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA);
2063STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE);
2064STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD);
[email protected]ad26ef42011-06-17 07:59:452065
[email protected]5b739cb2012-08-21 20:35:212066ui::TextInputType RenderWidget::WebKitToUiTextInputType(
[email protected]180ef242013-11-07 06:50:462067 blink::WebTextInputType type) {
[email protected]5b739cb2012-08-21 20:35:212068 // Check the type is in the range representable by ui::TextInputType.
2069 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
[email protected]180ef242013-11-07 06:50:462070 "blink::WebTextInputType and ui::TextInputType not synchronized";
[email protected]5b739cb2012-08-21 20:35:212071 return static_cast<ui::TextInputType>(type);
2072}
2073
[email protected]ad26ef42011-06-17 07:59:452074ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272075 if (webwidget_)
jdduke3bf083fe2015-09-29 23:40:532076 return WebKitToUiTextInputType(webwidget_->textInputType());
[email protected]ad26ef42011-06-17 07:59:452077 return ui::TEXT_INPUT_TYPE_NONE;
2078}
2079
[email protected]501ea13d2013-07-09 17:03:292080void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
yukawa5f21c6a2014-10-27 17:09:302081#if defined(OS_ANDROID)
yukawa6f899b22014-12-15 18:56:112082 // TODO(yukawa): Start sending character bounds when the browser side
2083 // implementation becomes ready (crbug.com/424866).
2084#else
jdduke1aebad8e2015-07-22 23:25:082085 TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo");
[email protected]db4fc1e2013-09-06 20:01:512086 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292087 if (should_update_range) {
2088 GetCompositionRange(&range);
2089 } else {
2090 range = composition_range_;
2091 }
2092 std::vector<gfx::Rect> character_bounds;
2093 GetCompositionCharacterBounds(&character_bounds);
2094
2095 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2096 return;
2097 composition_character_bounds_ = character_bounds;
2098 composition_range_ = range;
[email protected]a2214eb2014-06-23 18:31:222099 Send(new InputHostMsg_ImeCompositionRangeChanged(
[email protected]501ea13d2013-07-09 17:03:292100 routing_id(), composition_range_, composition_character_bounds_));
yukawa6f899b22014-12-15 18:56:112101#endif
[email protected]501ea13d2013-07-09 17:03:292102}
2103
[email protected]58b48a0d2012-06-13 07:01:352104void RenderWidget::GetCompositionCharacterBounds(
2105 std::vector<gfx::Rect>* bounds) {
2106 DCHECK(bounds);
2107 bounds->clear();
2108}
2109
[email protected]db4fc1e2013-09-06 20:01:512110void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362111 size_t location, length;
2112 if (webwidget_->compositionRange(&location, &length)) {
2113 range->set_start(location);
2114 range->set_end(location + length);
2115 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2116 range->set_start(location);
2117 range->set_end(location + length);
2118 } else {
[email protected]db4fc1e2013-09-06 20:01:512119 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362120 }
2121}
2122
[email protected]501ea13d2013-07-09 17:03:292123bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512124 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292125 const std::vector<gfx::Rect>& bounds) {
2126 if (composition_range_ != range)
2127 return true;
2128 if (bounds.size() != composition_character_bounds_.size())
2129 return true;
2130 for (size_t i = 0; i < bounds.size(); ++i) {
2131 if (bounds[i] != composition_character_bounds_[i])
2132 return true;
2133 }
2134 return false;
2135}
[email protected]501ea13d2013-07-09 17:03:292136
[email protected]a4f0d882014-05-01 23:48:102137#if defined(OS_ANDROID)
timav7a5032e2014-12-05 01:59:432138bool RenderWidget::DoesRecordFullLayer() const {
boliu15ca2652015-09-04 23:33:402139 return false;
timav7a5032e2014-12-05 01:59:432140}
[email protected]a4f0d882014-05-01 23:48:102141#endif
2142
[email protected]ad26ef42011-06-17 07:59:452143bool RenderWidget::CanComposeInline() {
2144 return true;
[email protected]56ea1a62011-05-30 07:05:572145}
2146
[email protected]4873c7d2009-07-16 06:36:282147WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042148 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282149}
2150
[email protected]fa7b1dc2010-06-23 17:53:042151void RenderWidget::resetInputMethod() {
[email protected]0e45bd02013-07-12 20:20:022152 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042153 // If the last text input type is not None, then we should finish any
2154 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452155 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042156 // If a composition text exists, then we need to let the browser process
2157 // to cancel the input method's ongoing composition session.
2158 if (webwidget_->confirmComposition())
[email protected]a2214eb2014-06-23 18:31:222159 Send(new InputHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042160 }
[email protected]d4cff272011-05-02 15:46:012161
[email protected]88dbe32f2013-06-20 23:31:362162 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042163}
2164
donnda070f3c2015-01-16 19:54:112165#if defined(OS_ANDROID)
2166void RenderWidget::showUnhandledTapUIIfNeeded(
2167 const WebPoint& tapped_position,
2168 const WebNode& tapped_node,
2169 bool page_changed) {
2170 DCHECK(handling_input_event_);
2171 bool should_trigger = !page_changed && tapped_node.isTextNode() &&
donnd57e54f52015-02-26 19:03:372172 !tapped_node.isContentEditable() &&
2173 !tapped_node.isInsideFocusableElementOrARIAWidget();
donnda070f3c2015-01-16 19:54:112174 if (should_trigger) {
2175 Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_,
2176 tapped_position.x, tapped_position.y));
2177 }
2178}
2179#endif
2180
[email protected]c68c3e4e2013-01-24 00:36:562181void RenderWidget::didHandleGestureEvent(
2182 const WebGestureEvent& event,
2183 bool event_cancelled) {
[email protected]183e28d2014-01-20 18:18:022184#if defined(OS_ANDROID) || defined(USE_AURA)
[email protected]c68c3e4e2013-01-24 00:36:562185 if (event_cancelled)
2186 return;
[email protected]07c70d22014-08-21 08:33:462187 if (event.type == WebInputEvent::GestureTap) {
[email protected]90f24152014-04-09 12:41:362188 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]07c70d22014-08-21 08:33:462189 } else if (event.type == WebInputEvent::GestureLongPress) {
2190 DCHECK(webwidget_);
2191 if (webwidget_->textInputInfo().value.isEmpty())
2192 UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME);
2193 else
2194 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME);
[email protected]c68c3e4e2013-01-24 00:36:562195 }
2196#endif
2197}
2198
sataya.m582c9ce2015-06-09 08:03:422199void RenderWidget::didOverscroll(
2200 const blink::WebFloatSize& unusedDelta,
2201 const blink::WebFloatSize& accumulatedRootOverScroll,
2202 const blink::WebFloatPoint& position,
2203 const blink::WebFloatSize& velocity) {
2204 DidOverscrollParams params;
sataya.m582c9ce2015-06-09 08:03:422205 params.accumulated_overscroll = gfx::Vector2dF(
2206 accumulatedRootOverScroll.width, accumulatedRootOverScroll.height);
2207 params.latest_overscroll_delta =
2208 gfx::Vector2dF(unusedDelta.width, unusedDelta.height);
sataya.ma5cc13a2015-06-13 11:06:022209 // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is
2210 // fixed.
sataya.m582c9ce2015-06-09 08:03:422211 params.current_fling_velocity =
sataya.ma5cc13a2015-06-13 11:06:022212 gfx::Vector2dF(-velocity.width, -velocity.height);
sataya.m582c9ce2015-06-09 08:03:422213 params.causal_event_viewport_point = gfx::PointF(position.x, position.y);
jddukec05612b2015-06-25 23:13:182214
2215 // If we're currently handling an event, stash the overscroll data such that
2216 // it can be bundled in the event ack.
2217 if (handling_event_overscroll_) {
2218 handling_event_overscroll_->reset(new DidOverscrollParams(params));
2219 return;
2220 }
2221
sataya.m582c9ce2015-06-09 08:03:422222 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
2223}
2224
[email protected]7912e822014-04-16 02:37:032225void RenderWidget::StartCompositor() {
sievers71c62dd52015-10-07 01:44:392226 if (!is_hidden())
2227 compositor_->setVisible(true);
[email protected]7912e822014-04-16 02:37:032228}
2229
[email protected]29e2fb42013-07-19 01:13:472230void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292231 size_t i = 0;
2232 for (; i < plugin_window_moves_.size(); ++i) {
2233 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582234 if (move.rects_valid) {
2235 plugin_window_moves_[i] = move;
2236 } else {
2237 plugin_window_moves_[i].visible = move.visible;
2238 }
initial.commit09911bf2008-07-26 23:55:292239 break;
2240 }
2241 }
2242
2243 if (i == plugin_window_moves_.size())
2244 plugin_window_moves_.push_back(move);
2245}
[email protected]268654772009-08-06 23:02:042246
2247void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2248 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2249 i != plugin_window_moves_.end(); ++i) {
2250 if (i->window == window) {
2251 plugin_window_moves_.erase(i);
2252 break;
2253 }
2254 }
2255}
[email protected]67bfb83f2011-09-22 03:36:372256
[email protected]63b465922012-09-06 02:04:522257
[email protected]24ed0432013-04-24 07:50:312258RenderWidgetCompositor* RenderWidget::compositor() const {
2259 return compositor_.get();
2260}
2261
[email protected]180ef242013-11-07 06:50:462262bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) {
[email protected]67bfb83f2011-09-22 03:36:372263 return false;
2264}
[email protected]c3d45532011-10-07 19:20:402265
[email protected]41d86852012-11-07 12:23:242266bool RenderWidget::WillHandleGestureEvent(
[email protected]180ef242013-11-07 06:50:462267 const blink::WebGestureEvent& event) {
[email protected]41d86852012-11-07 12:23:242268 return false;
2269}
2270
ccamerona7644752014-12-30 01:16:312271void RenderWidget::ObserveWheelEventAndResult(
ccamerond4ba47902014-12-17 07:20:312272 const blink::WebMouseWheelEvent& wheel_event,
sataya.mf405d0e2015-07-07 16:51:112273 const gfx::Vector2dF& wheel_unused_delta,
ccamerond4ba47902014-12-17 07:20:312274 bool event_processed) {
ccamerona7644752014-12-30 01:16:312275 if (!compositor_deps_->IsElasticOverscrollEnabled())
ccamerond4ba47902014-12-17 07:20:312276 return;
2277
ccamerond4ba47902014-12-17 07:20:312278 cc::InputHandlerScrollResult scroll_result;
sataya.mf405d0e2015-07-07 16:51:112279 scroll_result.did_scroll = event_processed;
2280 scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero();
2281 scroll_result.unused_scroll_delta = wheel_unused_delta;
ccamerond4ba47902014-12-17 07:20:312282
2283 RenderThreadImpl* render_thread = RenderThreadImpl::current();
2284 InputHandlerManager* input_handler_manager =
2285 render_thread ? render_thread->input_handler_manager() : NULL;
2286 if (input_handler_manager) {
2287 input_handler_manager->ObserveWheelEventAndResultOnMainThread(
2288 routing_id_, wheel_event, scroll_result);
2289 }
2290}
2291
[email protected]ce6689f2013-03-29 12:52:552292void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
alexclarke7fa93942015-10-21 15:37:112293 if (render_widget_scheduling_state_)
2294 render_widget_scheduling_state_->SetHasTouchHandler(has_handlers);
[email protected]ce6689f2013-03-29 12:52:552295 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2296}
2297
mostynbe29b6882015-01-13 09:59:172298// Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync
2299#define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \
2300 static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \
2301 "mismatching enums: " #a)
2302
[email protected]5d0bbdfa92013-12-10 00:35:512303void RenderWidget::setTouchAction(
2304 blink::WebTouchAction web_touch_action) {
2305
2306 // Ignore setTouchAction calls that result from synthetic touch events (eg.
2307 // when blink is emulating touch with mouse).
[email protected]c27dd4f2014-05-22 18:05:192308 if (handling_event_type_ != WebInputEvent::TouchStart)
[email protected]5d0bbdfa92013-12-10 00:35:512309 return;
2310
dtapuskaa98ac8d72015-05-08 19:29:092311 // Verify the same values are used by the types so we can cast between them.
mostynbe29b6882015-01-13 09:59:172312 STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE);
dtapuskaa98ac8d72015-05-08 19:29:092313 STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT);
2314 STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT);
mostynbe29b6882015-01-13 09:59:172315 STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X);
dtapuskaa98ac8d72015-05-08 19:29:092316 STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP);
2317 STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN);
mostynbe29b6882015-01-13 09:59:172318 STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y);
rbyersa8b478d2015-10-30 15:49:102319 STATIC_ASSERT_WTI_ENUM_MATCH(Pan, PAN);
mostynbe29b6882015-01-13 09:59:172320 STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM);
rbyersa8b478d2015-10-30 15:49:102321 STATIC_ASSERT_WTI_ENUM_MATCH(Manipulation, MANIPULATION);
2322 STATIC_ASSERT_WTI_ENUM_MATCH(DoubleTapZoom, DOUBLE_TAP_ZOOM);
2323 STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO);
[email protected]a18f67a2013-12-20 19:44:362324
2325 content::TouchAction content_touch_action =
2326 static_cast<content::TouchAction>(web_touch_action);
[email protected]5d0bbdfa92013-12-10 00:35:512327 Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action));
2328}
2329
[email protected]90f24152014-04-09 12:41:362330void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() {
2331#if defined(OS_ANDROID)
2332 text_field_is_dirty_ = true;
2333#endif
2334}
2335
[email protected]3d5c243b2012-11-30 00:26:012336bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2337 return true;
2338}
2339
[email protected]0634cdd42013-08-16 00:46:092340scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
jbauman5e420d32015-08-05 09:33:012341RenderWidget::CreateGraphicsContext3D(bool compositor) {
[email protected]ed7defa2013-03-12 21:29:592342 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092343 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
avi83883c82014-12-23 00:08:492344 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]ebc0e1df2013-08-01 02:46:222345 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092346 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]96ab016c2013-10-23 00:50:292347 if (!RenderThreadImpl::current())
2348 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]4d7e46a2013-11-08 05:33:402349 CauseForGpuLaunch cause =
2350 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
[email protected]96ab016c2013-10-23 00:50:292351 scoped_refptr<GpuChannelHost> gpu_channel_host(
[email protected]4d7e46a2013-11-08 05:33:402352 RenderThreadImpl::current()->EstablishGpuChannelSync(cause));
dcheng58867a92014-08-26 02:50:222353 if (!gpu_channel_host.get())
[email protected]96ab016c2013-10-23 00:50:292354 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ed7defa2013-03-12 21:29:592355
[email protected]828a3932014-04-02 14:43:132356 // Explicitly disable antialiasing for the compositor. As of the time of
2357 // this writing, the only platform that supported antialiasing for the
2358 // compositor was Mac OS X, because the on-screen OpenGL context creation
2359 // code paths on Windows and Linux didn't yet have multisampling support.
2360 // Mac OS X essentially always behaves as though it's rendering offscreen.
2361 // Multisampling has a heavy cost especially on devices with relatively low
2362 // fill rate like most notebooks, and the Mac implementation would need to
2363 // be optimized to resolve directly into the IOSurface shared between the
2364 // GPU and browser processes. For these reasons and to avoid platform
2365 // disparities we explicitly disable antialiasing.
2366 blink::WebGraphicsContext3D::Attributes attributes;
2367 attributes.antialias = false;
2368 attributes.shareResources = true;
2369 attributes.noAutomaticFlushes = true;
2370 attributes.depth = false;
2371 attributes.stencil = false;
[email protected]828a3932014-04-02 14:43:132372 bool lose_context_when_out_of_memory = true;
[email protected]96ab016c2013-10-23 00:50:292373 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits;
[email protected]b6eb8e332013-09-10 00:51:012374#if defined(OS_ANDROID)
boliu853d46052015-10-13 20:20:062375 bool using_synchronous_compositing =
2376 SynchronousCompositorFactory::GetInstance();
[email protected]b6eb8e332013-09-10 00:51:012377 // If we raster too fast we become upload bound, and pending
2378 // uploads consume memory. For maximum upload throughput, we would
2379 // want to allow for upload_throughput * pipeline_time of pending
2380 // uploads, after which we are just wasting memory. Since we don't
2381 // know our upload throughput yet, this just caps our memory usage.
boliu853d46052015-10-13 20:20:062382 // Synchronous compositor uses half because synchronous compositor
2383 // pipeline is only one frame deep. But twice of half for low end
2384 // because 16bit texture is not supported.
2385 size_t divider = using_synchronous_compositing ? 2 : 1;
[email protected]35b4f0c2014-06-26 16:55:272386 if (base::SysInfo::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032387 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012388 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032389 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012390 // Deadline to draw a frame to achieve 60 frames per second.
2391 const size_t kMillisecondsPerFrame = 16;
2392 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032393 size_t max_transfer_buffer_usage_mb =
2394 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2395 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012396 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2397 // to avoid unnecessarily stalling the compositor thread.
[email protected]96ab016c2013-10-23 00:50:292398 limits.mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032399 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012400#endif
jbauman00ca2dc2015-08-10 23:21:152401 if (compositor) {
jbauman5e420d32015-08-05 09:33:012402 limits.command_buffer_size = 64 * 1024;
jbauman00ca2dc2015-08-10 23:21:152403 limits.start_transfer_buffer_size = 64 * 1024;
2404 limits.min_transfer_buffer_size = 64 * 1024;
2405 }
[email protected]96ab016c2013-10-23 00:50:292406
[email protected]96ab016c2013-10-23 00:50:292407 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
piman5d36dae2015-09-24 22:47:052408 new WebGraphicsContext3DCommandBufferImpl(
piman08f75532015-10-05 18:58:012409 0, GetURLForGraphicsContext3D(), gpu_channel_host.get(), attributes,
2410 lose_context_when_out_of_memory, limits, NULL));
[email protected]0634cdd42013-08-16 00:46:092411 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592412}
2413
[email protected]e3244ed2014-06-20 20:04:272414void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) {
2415 render_frame_proxies_.AddObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162416}
2417
[email protected]e3244ed2014-06-20 20:04:272418void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) {
2419 render_frame_proxies_.RemoveObserver(proxy);
[email protected]bffc8302014-01-23 20:52:162420}
2421
[email protected]de3c5d82014-05-28 22:12:592422void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) {
2423 render_frames_.AddObserver(frame);
2424}
2425
2426void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) {
2427 render_frames_.RemoveObserver(frame);
2428}
2429
[email protected]a017938b2014-05-27 21:17:172430#if defined(VIDEO_HOLE)
2431void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2432 video_hole_frames_.AddObserver(frame);
2433}
2434
2435void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2436 video_hole_frames_.RemoveObserver(frame);
2437}
2438#endif // defined(VIDEO_HOLE)
2439
[email protected]e9ff79c2012-10-19 21:31:262440} // namespace content