[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 5 | #include "content/renderer/render_widget.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 7 | #include "base/auto_reset.h" |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 8 | #include "base/bind.h" |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 9 | #include "base/command_line.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 12 | #include "base/memory/singleton.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 13 | #include "base/message_loop/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 14 | #include "base/metrics/histogram.h" |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 15 | #include "base/stl_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 35b4f0c | 2014-06-26 16:55:27 | [diff] [blame] | 17 | #include "base/sys_info.h" |
primiano | 9e38d55 | 2015-01-28 04:18:01 | [diff] [blame] | 18 | #include "base/trace_event/trace_event.h" |
| 19 | #include "base/trace_event/trace_event_synthetic_delay.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 20 | #include "build/build_config.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 21 | #include "cc/base/switches.h" |
[email protected] | adbe30f | 2013-10-11 21:12:33 | [diff] [blame] | 22 | #include "cc/debug/benchmark_instrumentation.h" |
[email protected] | 7f0d825f | 2013-03-18 07:24:30 | [diff] [blame] | 23 | #include "cc/output/output_surface.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 24 | #include "cc/trees/layer_tree_host.h" |
alexclarke | 7819e255 | 2015-06-03 11:17:21 | [diff] [blame] | 25 | #include "components/scheduler/renderer/renderer_scheduler.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 26 | #include "content/child/npapi/webplugin.h" |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 27 | #include "content/common/gpu/client/context_provider_command_buffer.h" |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 28 | #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 29 | #include "content/common/gpu/gpu_process_launch_causes.h" |
[email protected] | 9017d785 | 2013-11-21 17:47:35 | [diff] [blame] | 30 | #include "content/common/input/synthetic_gesture_packet.h" |
[email protected] | 8e299aa | 2013-10-16 18:17:44 | [diff] [blame] | 31 | #include "content/common/input/web_input_event_traits.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 32 | #include "content/common/input_messages.h" |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 33 | #include "content/common/swapped_out_messages.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 34 | #include "content/common/view_messages.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 35 | #include "content/public/common/content_switches.h" |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 36 | #include "content/public/common/context_menu_params.h" |
[email protected] | 953bd006 | 2013-08-01 00:58:40 | [diff] [blame] | 37 | #include "content/renderer/cursor_utils.h" |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 38 | #include "content/renderer/external_popup_menu.h" |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 39 | #include "content/renderer/gpu/compositor_output_surface.h" |
[email protected] | 36e5ff1 | 2013-06-11 12:19:29 | [diff] [blame] | 40 | #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 41 | #include "content/renderer/gpu/frame_swap_message_queue.h" |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 42 | #include "content/renderer/gpu/mailbox_output_surface.h" |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 43 | #include "content/renderer/gpu/queue_message_swap_promise.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 44 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 45 | #include "content/renderer/ime_event_guard.h" |
[email protected] | 7a72d45 | 2013-12-13 10:01:13 | [diff] [blame] | 46 | #include "content/renderer/input/input_handler_manager.h" |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 47 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 48 | #include "content/renderer/render_frame_impl.h" |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 49 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 50 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 51 | #include "content/renderer/render_thread_impl.h" |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 52 | #include "content/renderer/renderer_blink_platform_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 53 | #include "content/renderer/resizing_mode_selector.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 54 | #include "ipc/ipc_sync_message.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 55 | #include "skia/ext/platform_canvas.h" |
[email protected] | ec173b52 | 2013-11-14 11:01:18 | [diff] [blame] | 56 | #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 57 | #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 58 | #include "third_party/WebKit/public/platform/WebPoint.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 59 | #include "third_party/WebKit/public/platform/WebRect.h" |
[email protected] | ec173b52 | 2013-11-14 11:01:18 | [diff] [blame] | 60 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 61 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 62 | #include "third_party/WebKit/public/platform/WebString.h" |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 63 | #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 64 | #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 65 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 66 | #include "third_party/WebKit/public/web/WebNode.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 67 | #include "third_party/WebKit/public/web/WebPagePopup.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 68 | #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" |
| 69 | #include "third_party/WebKit/public/web/WebRange.h" |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 70 | #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 71 | #include "third_party/WebKit/public/web/WebView.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 72 | #include "third_party/skia/include/core/SkShader.h" |
[email protected] | faec7b1 | 2012-06-19 14:42:13 | [diff] [blame] | 73 | #include "ui/base/ui_base_switches.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 74 | #include "ui/gfx/geometry/point_conversions.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 75 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 76 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 1835b9e | 2012-02-28 13:12:48 | [diff] [blame] | 77 | #include "ui/gfx/skia_util.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 78 | #include "ui/gl/gl_switches.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 79 | #include "ui/surface/transport_dib.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 80 | |
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 81 | #if defined(OS_ANDROID) |
[email protected] | cefe9b15 | 2014-03-27 18:16:15 | [diff] [blame] | 82 | #include <android/keycodes.h> |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 83 | #include "content/renderer/android/synchronous_compositor_factory.h" |
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 84 | #endif |
| 85 | |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 86 | #if defined(OS_POSIX) |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 87 | #include "ipc/ipc_channel_posix.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 88 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 89 | #include "third_party/skia/include/core/SkPixelRef.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 90 | #endif // defined(OS_POSIX) |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 91 | |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 92 | #include "third_party/WebKit/public/web/WebWidget.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 94 | using blink::WebCompositionUnderline; |
| 95 | using blink::WebCursorInfo; |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 96 | using blink::WebDeviceEmulationParams; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 97 | using blink::WebGestureEvent; |
| 98 | using blink::WebInputEvent; |
| 99 | using blink::WebKeyboardEvent; |
| 100 | using blink::WebMouseEvent; |
| 101 | using blink::WebMouseWheelEvent; |
| 102 | using blink::WebNavigationPolicy; |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 103 | using blink::WebNode; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 104 | using blink::WebPagePopup; |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 105 | using blink::WebPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 106 | using blink::WebPopupType; |
| 107 | using blink::WebRange; |
| 108 | using blink::WebRect; |
| 109 | using blink::WebScreenInfo; |
| 110 | using blink::WebSize; |
| 111 | using blink::WebTextDirection; |
| 112 | using blink::WebTouchEvent; |
[email protected] | f8ed472 | 2013-12-03 03:27:25 | [diff] [blame] | 113 | using blink::WebTouchPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 114 | using blink::WebVector; |
| 115 | using blink::WebWidget; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 116 | |
[email protected] | 6a4d7f6 | 2013-01-07 21:32:13 | [diff] [blame] | 117 | namespace { |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 118 | |
| 119 | typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; |
| 120 | |
| 121 | class TextInputModeMapSingleton { |
| 122 | public: |
| 123 | static TextInputModeMapSingleton* GetInstance() { |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 124 | return base::Singleton<TextInputModeMapSingleton>::get(); |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 125 | } |
[email protected] | dd705d4d | 2013-11-27 08:14:41 | [diff] [blame] | 126 | TextInputModeMapSingleton() { |
| 127 | map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM; |
| 128 | map_["latin"] = ui::TEXT_INPUT_MODE_LATIN; |
| 129 | map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME; |
| 130 | map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE; |
| 131 | map_["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN; |
| 132 | map_["kana"] = ui::TEXT_INPUT_MODE_KANA; |
| 133 | map_["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA; |
| 134 | map_["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC; |
| 135 | map_["tel"] = ui::TEXT_INPUT_MODE_TEL; |
| 136 | map_["email"] = ui::TEXT_INPUT_MODE_EMAIL; |
| 137 | map_["url"] = ui::TEXT_INPUT_MODE_URL; |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 138 | } |
[email protected] | dd705d4d | 2013-11-27 08:14:41 | [diff] [blame] | 139 | const TextInputModeMap& map() const { return map_; } |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 140 | private: |
[email protected] | dd705d4d | 2013-11-27 08:14:41 | [diff] [blame] | 141 | TextInputModeMap map_; |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 142 | |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 143 | friend struct base::DefaultSingletonTraits<TextInputModeMapSingleton>; |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 144 | |
| 145 | DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton); |
| 146 | }; |
| 147 | |
[email protected] | dd705d4d | 2013-11-27 08:14:41 | [diff] [blame] | 148 | ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 149 | static TextInputModeMapSingleton* singleton = |
| 150 | TextInputModeMapSingleton::GetInstance(); |
[email protected] | dd705d4d | 2013-11-27 08:14:41 | [diff] [blame] | 151 | TextInputModeMap::const_iterator it = |
| 152 | singleton->map().find(input_mode.utf8()); |
| 153 | if (it == singleton->map().end()) |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 154 | return ui::TEXT_INPUT_MODE_DEFAULT; |
| 155 | return it->second; |
[email protected] | 6a4d7f6 | 2013-01-07 21:32:13 | [diff] [blame] | 156 | } |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 157 | |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 158 | // TODO(brianderson): Replace the hard-coded threshold with a fraction of |
| 159 | // the BeginMainFrame interval. |
| 160 | // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to |
| 161 | // be spent in input hanlders before input starts getting throttled. |
| 162 | const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; |
| 163 | |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 164 | int64 GetEventLatencyMicros(double event_timestamp, base::TimeTicks now) { |
| 165 | return (now - base::TimeDelta::FromSecondsD(event_timestamp)) |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 166 | .ToInternalValue(); |
| 167 | } |
| 168 | |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 169 | void LogInputEventLatencyUmaImpl(WebInputEvent::Type event_type, |
| 170 | double event_timestamp, |
| 171 | base::TimeTicks now) { |
| 172 | UMA_HISTOGRAM_CUSTOM_COUNTS("Event.AggregatedLatency.Renderer2", |
| 173 | GetEventLatencyMicros(event_timestamp, now), 1, |
| 174 | 10000000, 100); |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 175 | |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 176 | #define CASE_TYPE(t) \ |
| 177 | case WebInputEvent::t: \ |
| 178 | UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer2." #t, \ |
| 179 | GetEventLatencyMicros(event_timestamp, now), \ |
| 180 | 1, 10000000, 100); \ |
| 181 | break; |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 182 | |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 183 | switch (event_type) { |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 184 | CASE_TYPE(Undefined); |
| 185 | CASE_TYPE(MouseDown); |
| 186 | CASE_TYPE(MouseUp); |
| 187 | CASE_TYPE(MouseMove); |
| 188 | CASE_TYPE(MouseEnter); |
| 189 | CASE_TYPE(MouseLeave); |
| 190 | CASE_TYPE(ContextMenu); |
| 191 | CASE_TYPE(MouseWheel); |
| 192 | CASE_TYPE(RawKeyDown); |
| 193 | CASE_TYPE(KeyDown); |
| 194 | CASE_TYPE(KeyUp); |
| 195 | CASE_TYPE(Char); |
| 196 | CASE_TYPE(GestureScrollBegin); |
| 197 | CASE_TYPE(GestureScrollEnd); |
| 198 | CASE_TYPE(GestureScrollUpdate); |
| 199 | CASE_TYPE(GestureFlingStart); |
| 200 | CASE_TYPE(GestureFlingCancel); |
| 201 | CASE_TYPE(GestureShowPress); |
| 202 | CASE_TYPE(GestureTap); |
| 203 | CASE_TYPE(GestureTapUnconfirmed); |
| 204 | CASE_TYPE(GestureTapDown); |
| 205 | CASE_TYPE(GestureTapCancel); |
| 206 | CASE_TYPE(GestureDoubleTap); |
| 207 | CASE_TYPE(GestureTwoFingerTap); |
| 208 | CASE_TYPE(GestureLongPress); |
| 209 | CASE_TYPE(GestureLongTap); |
| 210 | CASE_TYPE(GesturePinchBegin); |
| 211 | CASE_TYPE(GesturePinchEnd); |
| 212 | CASE_TYPE(GesturePinchUpdate); |
| 213 | CASE_TYPE(TouchStart); |
| 214 | CASE_TYPE(TouchMove); |
| 215 | CASE_TYPE(TouchEnd); |
| 216 | CASE_TYPE(TouchCancel); |
| 217 | default: |
| 218 | // Must include default to let blink::WebInputEvent add new event types |
| 219 | // before they're added here. |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 220 | DLOG(WARNING) << "Unhandled WebInputEvent type: " << event_type; |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 221 | break; |
| 222 | } |
| 223 | |
| 224 | #undef CASE_TYPE |
| 225 | } |
| 226 | |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 227 | void LogInputEventLatencyUma(const WebInputEvent& event, base::TimeTicks now, |
| 228 | const ui::LatencyInfo& latency_info) { |
| 229 | LogInputEventLatencyUmaImpl(event.type, event.timeStampSeconds, now); |
| 230 | for (size_t i = 0; i < latency_info.coalesced_events_size(); i++) { |
| 231 | LogInputEventLatencyUmaImpl( |
| 232 | event.type, |
| 233 | latency_info.timestamps_of_coalesced_events()[i], |
| 234 | now); |
| 235 | } |
| 236 | } |
| 237 | |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 238 | } // namespace |
| 239 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 240 | namespace content { |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 241 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 242 | // RenderWidget::ScreenMetricsEmulator ---------------------------------------- |
| 243 | |
| 244 | class RenderWidget::ScreenMetricsEmulator { |
| 245 | public: |
| 246 | ScreenMetricsEmulator( |
| 247 | RenderWidget* widget, |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 248 | const WebDeviceEmulationParams& params); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 249 | virtual ~ScreenMetricsEmulator(); |
| 250 | |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 251 | // Scale and offset used to convert between host coordinates |
| 252 | // and webwidget coordinates. |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 253 | float scale() { return scale_; } |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 254 | gfx::PointF offset() { return offset_; } |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 255 | gfx::Rect applied_widget_rect() const { return applied_widget_rect_; } |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 256 | gfx::Rect original_screen_rect() const { return original_view_screen_rect_; } |
[email protected] | 5f75aa4 | 2014-04-01 23:00:56 | [diff] [blame] | 257 | const WebScreenInfo& original_screen_info() { return original_screen_info_; } |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 258 | |
| 259 | void ChangeEmulationParams( |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 260 | const WebDeviceEmulationParams& params); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 261 | |
| 262 | // The following methods alter handlers' behavior for messages related to |
| 263 | // widget size and position. |
| 264 | void OnResizeMessage(const ViewMsg_Resize_Params& params); |
| 265 | void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect, |
| 266 | const gfx::Rect& window_screen_rect); |
| 267 | void OnShowContextMenu(ContextMenuParams* params); |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 268 | gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 269 | |
| 270 | private: |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 271 | void Reapply(); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 272 | void Apply(bool top_controls_shrink_blink_size, |
| 273 | float top_controls_height, |
[email protected] | bb6378fe | 2014-04-28 21:19:44 | [diff] [blame] | 274 | gfx::Rect resizer_rect, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 275 | bool is_fullscreen_granted, |
| 276 | blink::WebDisplayMode display_mode); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 277 | |
| 278 | RenderWidget* widget_; |
| 279 | |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 280 | // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation. |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 281 | WebDeviceEmulationParams params_; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 282 | |
[email protected] | a179d396 | 2013-11-12 14:44:40 | [diff] [blame] | 283 | // The computed scale and offset used to fit widget into browser window. |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 284 | float scale_; |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 285 | gfx::PointF offset_; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 286 | |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 287 | // Widget rect as passed to webwidget. |
| 288 | gfx::Rect applied_widget_rect_; |
| 289 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 290 | // Original values to restore back after emulation ends. |
| 291 | gfx::Size original_size_; |
| 292 | gfx::Size original_physical_backing_size_; |
[email protected] | 6949e0d2 | 2014-06-02 22:39:28 | [diff] [blame] | 293 | gfx::Size original_visible_viewport_size_; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 294 | blink::WebScreenInfo original_screen_info_; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 295 | gfx::Rect original_view_screen_rect_; |
| 296 | gfx::Rect original_window_screen_rect_; |
| 297 | }; |
| 298 | |
| 299 | RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator( |
| 300 | RenderWidget* widget, |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 301 | const WebDeviceEmulationParams& params) |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 302 | : widget_(widget), |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 303 | params_(params), |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 304 | scale_(1.f) { |
| 305 | original_size_ = widget_->size_; |
| 306 | original_physical_backing_size_ = widget_->physical_backing_size_; |
[email protected] | 6949e0d2 | 2014-06-02 22:39:28 | [diff] [blame] | 307 | original_visible_viewport_size_ = widget_->visible_viewport_size_; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 308 | original_screen_info_ = widget_->screen_info_; |
| 309 | original_view_screen_rect_ = widget_->view_screen_rect_; |
| 310 | original_window_screen_rect_ = widget_->window_screen_rect_; |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 311 | Apply(widget_->top_controls_shrink_blink_size_, |
| 312 | widget_->top_controls_height_, |
| 313 | widget_->resizer_rect_, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 314 | widget_->is_fullscreen_granted_, |
| 315 | widget_->display_mode_); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() { |
| 319 | widget_->screen_info_ = original_screen_info_; |
| 320 | |
| 321 | widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor); |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 322 | widget_->SetScreenMetricsEmulationParameters(false, params_); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 323 | widget_->view_screen_rect_ = original_view_screen_rect_; |
| 324 | widget_->window_screen_rect_ = original_window_screen_rect_; |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 325 | widget_->Resize(original_size_, |
| 326 | original_physical_backing_size_, |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 327 | widget_->top_controls_shrink_blink_size_, |
| 328 | widget_->top_controls_height_, |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 329 | original_visible_viewport_size_, |
| 330 | widget_->resizer_rect_, |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 331 | widget_->is_fullscreen_granted_, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 332 | widget_->display_mode_, |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 333 | NO_RESIZE_ACK); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams( |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 337 | const WebDeviceEmulationParams& params) { |
| 338 | params_ = params; |
| 339 | Reapply(); |
| 340 | } |
| 341 | |
| 342 | void RenderWidget::ScreenMetricsEmulator::Reapply() { |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 343 | Apply(widget_->top_controls_shrink_blink_size_, |
| 344 | widget_->top_controls_height_, |
| 345 | widget_->resizer_rect_, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 346 | widget_->is_fullscreen_granted_, |
| 347 | widget_->display_mode_); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 348 | } |
| 349 | |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 350 | void RenderWidget::ScreenMetricsEmulator::Apply( |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 351 | bool top_controls_shrink_blink_size, |
| 352 | float top_controls_height, |
[email protected] | bb6378fe | 2014-04-28 21:19:44 | [diff] [blame] | 353 | gfx::Rect resizer_rect, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 354 | bool is_fullscreen_granted, |
| 355 | blink::WebDisplayMode display_mode) { |
[email protected] | 92d13b7 | 2014-05-09 14:42:31 | [diff] [blame] | 356 | applied_widget_rect_.set_size(gfx::Size(params_.viewSize)); |
| 357 | if (!applied_widget_rect_.width()) |
| 358 | applied_widget_rect_.set_width(original_size_.width()); |
| 359 | if (!applied_widget_rect_.height()) |
| 360 | applied_widget_rect_.set_height(original_size_.height()); |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 361 | |
[email protected] | f442ee4 | 2014-05-14 11:53:12 | [diff] [blame] | 362 | if (params_.fitToView && !original_size_.IsEmpty()) { |
[email protected] | 0b3578c | 2014-06-20 18:29:02 | [diff] [blame] | 363 | int original_width = std::max(original_size_.width(), 1); |
| 364 | int original_height = std::max(original_size_.height(), 1); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 365 | float width_ratio = |
[email protected] | 0b3578c | 2014-06-20 18:29:02 | [diff] [blame] | 366 | static_cast<float>(applied_widget_rect_.width()) / original_width; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 367 | float height_ratio = |
[email protected] | 0b3578c | 2014-06-20 18:29:02 | [diff] [blame] | 368 | static_cast<float>(applied_widget_rect_.height()) / original_height; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 369 | float ratio = std::max(1.0f, std::max(width_ratio, height_ratio)); |
| 370 | scale_ = 1.f / ratio; |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 371 | |
| 372 | // Center emulated view inside available view space. |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 373 | offset_.set_x( |
| 374 | (original_size_.width() - scale_ * applied_widget_rect_.width()) / 2); |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 375 | offset_.set_y( |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 376 | (original_size_.height() - scale_ * applied_widget_rect_.height()) / 2); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 377 | } else { |
[email protected] | 0b3578c | 2014-06-20 18:29:02 | [diff] [blame] | 378 | scale_ = params_.scale; |
| 379 | offset_.SetPoint(params_.offset.x, params_.offset.y); |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 380 | } |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 381 | |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 382 | if (params_.screenPosition == WebDeviceEmulationParams::Desktop) { |
| 383 | applied_widget_rect_.set_origin(original_view_screen_rect_.origin()); |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 384 | widget_->screen_info_.rect = original_screen_info_.rect; |
| 385 | widget_->screen_info_.availableRect = original_screen_info_.availableRect; |
| 386 | widget_->window_screen_rect_ = original_window_screen_rect_; |
| 387 | } else { |
dgozman | f28ccbe | 2015-06-24 08:50:49 | [diff] [blame] | 388 | applied_widget_rect_.set_origin(params_.viewPosition); |
| 389 | gfx::Rect screen_rect = applied_widget_rect_; |
| 390 | if (!params_.screenSize.isEmpty()) { |
| 391 | screen_rect = |
| 392 | gfx::Rect(0, 0, params_.screenSize.width, params_.screenSize.height); |
| 393 | } |
| 394 | widget_->screen_info_.rect = screen_rect; |
| 395 | widget_->screen_info_.availableRect = screen_rect; |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 396 | widget_->window_screen_rect_ = applied_widget_rect_; |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 397 | } |
[email protected] | a179d396 | 2013-11-12 14:44:40 | [diff] [blame] | 398 | |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 399 | float applied_device_scale_factor = params_.deviceScaleFactor ? |
| 400 | params_.deviceScaleFactor : original_screen_info_.deviceScaleFactor; |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 401 | widget_->screen_info_.deviceScaleFactor = applied_device_scale_factor; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 402 | |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 403 | // Pass three emulation parameters to the blink side: |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 404 | // - we keep the real device scale factor in compositor to produce sharp image |
| 405 | // even when emulating different scale factor; |
[email protected] | 7f99fc2 | 2013-11-08 14:05:58 | [diff] [blame] | 406 | // - in order to fit into view, WebView applies offset and scale to the |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 407 | // root layer. |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 408 | blink::WebDeviceEmulationParams modified_params = params_; |
| 409 | modified_params.deviceScaleFactor = original_screen_info_.deviceScaleFactor; |
| 410 | modified_params.offset = blink::WebFloatPoint(offset_.x(), offset_.y()); |
| 411 | modified_params.scale = scale_; |
| 412 | widget_->SetScreenMetricsEmulationParameters(true, modified_params); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 413 | |
[email protected] | 7f0e8fa | 2014-03-26 12:32:01 | [diff] [blame] | 414 | widget_->SetDeviceScaleFactor(applied_device_scale_factor); |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 415 | widget_->view_screen_rect_ = applied_widget_rect_; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 416 | |
| 417 | gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize( |
| 418 | original_size_, original_screen_info_.deviceScaleFactor)); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 419 | widget_->Resize(applied_widget_rect_.size(), |
| 420 | physical_backing_size, |
| 421 | top_controls_shrink_blink_size, |
| 422 | top_controls_height, |
| 423 | applied_widget_rect_.size(), |
| 424 | resizer_rect, |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 425 | is_fullscreen_granted, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 426 | display_mode, |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 427 | NO_RESIZE_ACK); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void RenderWidget::ScreenMetricsEmulator::OnResizeMessage( |
| 431 | const ViewMsg_Resize_Params& params) { |
| 432 | bool need_ack = params.new_size != original_size_ && |
| 433 | !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty(); |
| 434 | original_size_ = params.new_size; |
| 435 | original_physical_backing_size_ = params.physical_backing_size; |
| 436 | original_screen_info_ = params.screen_info; |
[email protected] | 6949e0d2 | 2014-06-02 22:39:28 | [diff] [blame] | 437 | original_visible_viewport_size_ = params.visible_viewport_size; |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 438 | Apply(params.top_controls_shrink_blink_size, |
| 439 | params.top_controls_height, |
| 440 | params.resizer_rect, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 441 | params.is_fullscreen_granted, |
| 442 | params.display_mode); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 443 | |
| 444 | if (need_ack) { |
| 445 | widget_->set_next_paint_is_resize_ack(); |
| 446 | if (widget_->compositor_) |
| 447 | widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_)); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage( |
| 452 | const gfx::Rect& view_screen_rect, |
| 453 | const gfx::Rect& window_screen_rect) { |
| 454 | original_view_screen_rect_ = view_screen_rect; |
| 455 | original_window_screen_rect_ = window_screen_rect; |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 456 | if (params_.screenPosition == WebDeviceEmulationParams::Desktop) |
| 457 | Reapply(); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu( |
| 461 | ContextMenuParams* params) { |
| 462 | params->x *= scale_; |
[email protected] | a179d396 | 2013-11-12 14:44:40 | [diff] [blame] | 463 | params->x += offset_.x(); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 464 | params->y *= scale_; |
[email protected] | a179d396 | 2013-11-12 14:44:40 | [diff] [blame] | 465 | params->y += offset_.y(); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 466 | } |
| 467 | |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 468 | gfx::Rect RenderWidget::ScreenMetricsEmulator::AdjustValidationMessageAnchor( |
| 469 | const gfx::Rect& anchor) { |
danakj | 4606f633 | 2015-08-31 23:56:56 | [diff] [blame] | 470 | gfx::Rect scaled = gfx::ScaleToEnclosedRect(anchor, scale_); |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 471 | scaled.set_x(scaled.x() + offset_.x()); |
| 472 | scaled.set_y(scaled.y() + offset_.y()); |
| 473 | return scaled; |
| 474 | } |
| 475 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 476 | // RenderWidget --------------------------------------------------------------- |
| 477 | |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 478 | RenderWidget::RenderWidget(CompositorDependencies* compositor_deps, |
| 479 | blink::WebPopupType popup_type, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 480 | const blink::WebScreenInfo& screen_info, |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 481 | bool swapped_out, |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 482 | bool hidden, |
| 483 | bool never_visible) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 484 | : routing_id_(MSG_ROUTING_NONE), |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 485 | compositor_deps_(compositor_deps), |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 486 | webwidget_(nullptr), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 487 | opener_id_(MSG_ROUTING_NONE), |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 488 | init_complete_(false), |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 489 | top_controls_shrink_blink_size_(false), |
| 490 | top_controls_height_(0.f), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 491 | next_paint_flags_(0), |
[email protected] | 847a258 | 2013-03-09 02:29:51 | [diff] [blame] | 492 | auto_resize_mode_(false), |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 493 | need_update_rect_for_auto_resize_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 494 | did_show_(false), |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 495 | is_hidden_(hidden), |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 496 | never_visible_(never_visible), |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 497 | is_fullscreen_granted_(false), |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 498 | display_mode_(blink::WebDisplayModeUndefined), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 499 | has_focus_(false), |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 500 | handling_input_event_(false), |
jdduke | c05612b | 2015-06-25 23:13:18 | [diff] [blame] | 501 | handling_event_overscroll_(nullptr), |
[email protected] | e8f775f | 2013-02-14 21:00:50 | [diff] [blame] | 502 | handling_ime_event_(false), |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 503 | handling_event_type_(WebInputEvent::Undefined), |
| 504 | ignore_ack_for_mouse_move_from_debugger_(false), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 505 | closing_(false), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 506 | host_closing_(false), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 507 | is_swapped_out_(swapped_out), |
simonhong | 628f981 | 2015-04-27 23:13:20 | [diff] [blame] | 508 | for_oopif_(false), |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 509 | text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 510 | text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 511 | text_input_flags_(0), |
[email protected] | 86ba5fcb | 2013-09-04 00:36:53 | [diff] [blame] | 512 | can_compose_inline_(true), |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 513 | popup_type_(popup_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 514 | pending_window_rect_count_(0), |
[email protected] | b68a0e5 | 2011-12-08 15:11:12 | [diff] [blame] | 515 | suppress_next_char_events_(false), |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 516 | screen_info_(screen_info), |
[email protected] | 3d77947 | 2012-11-15 20:49:52 | [diff] [blame] | 517 | device_scale_factor_(screen_info_.deviceScaleFactor), |
[email protected] | 53b4cc1 | 2013-07-18 23:02:30 | [diff] [blame] | 518 | next_output_surface_id_(0), |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 519 | #if defined(OS_ANDROID) |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 520 | text_field_is_dirty_(false), |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 521 | #endif |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 522 | popup_origin_scale_for_emulation_(0.f), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 523 | frame_swap_message_queue_(new FrameSwapMessageQueue()), |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 524 | resizing_mode_selector_(new ResizingModeSelector()), |
[email protected] | be1af066 | 2014-07-29 19:55:51 | [diff] [blame] | 525 | context_menu_source_type_(ui::MENU_SOURCE_MOUSE), |
| 526 | has_host_context_menu_location_(false) { |
[email protected] | 8b3f0eb | 2012-05-03 19:15:05 | [diff] [blame] | 527 | if (!swapped_out) |
| 528 | RenderProcess::current()->AddRefProcess(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 529 | DCHECK(RenderThread::Get()); |
[email protected] | 3079c28a | 2014-06-24 03:38:53 | [diff] [blame] | 530 | device_color_profile_.push_back('0'); |
changwan | 3a84116 | 2015-08-11 02:53:37 | [diff] [blame] | 531 | #if defined(OS_ANDROID) |
| 532 | text_input_info_history_.push_back(blink::WebTextInputInfo()); |
| 533 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | RenderWidget::~RenderWidget() { |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 537 | DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 538 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 539 | // If we are swapped out, we have released already. |
[email protected] | d2e2f9ee | 2013-08-21 11:02:02 | [diff] [blame] | 540 | if (!is_swapped_out_ && RenderProcess::current()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 541 | RenderProcess::current()->ReleaseProcess(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 542 | } |
| 543 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 544 | // static |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 545 | RenderWidget* RenderWidget::Create(int32 opener_id, |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 546 | CompositorDependencies* compositor_deps, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 547 | blink::WebPopupType popup_type, |
| 548 | const blink::WebScreenInfo& screen_info) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 549 | DCHECK(opener_id != MSG_ROUTING_NONE); |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 550 | scoped_refptr<RenderWidget> widget(new RenderWidget( |
| 551 | compositor_deps, popup_type, screen_info, false, false, false)); |
| 552 | if (widget->Init(opener_id)) { // adds reference on success. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 553 | return widget.get(); |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 554 | } |
| 555 | return NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 556 | } |
| 557 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 558 | // static |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 559 | RenderWidget* RenderWidget::CreateForFrame( |
| 560 | int routing_id, |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 561 | bool hidden, |
| 562 | const blink::WebScreenInfo& screen_info, |
| 563 | CompositorDependencies* compositor_deps, |
| 564 | blink::WebLocalFrame* frame) { |
| 565 | CHECK_NE(routing_id, MSG_ROUTING_NONE); |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 566 | scoped_refptr<RenderWidget> widget( |
| 567 | new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info, |
| 568 | false, hidden, false)); |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 569 | widget->routing_id_ = routing_id; |
simonhong | 628f981 | 2015-04-27 23:13:20 | [diff] [blame] | 570 | widget->for_oopif_ = true; |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 571 | // DoInit increments the reference count on |widget|, keeping it alive after |
| 572 | // this function returns. |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 573 | if (widget->DoInit(MSG_ROUTING_NONE, |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 574 | RenderWidget::CreateWebFrameWidget(widget.get(), frame), |
| 575 | nullptr)) { |
| 576 | widget->CompleteInit(); |
| 577 | return widget.get(); |
| 578 | } |
| 579 | return nullptr; |
| 580 | } |
| 581 | |
| 582 | // static |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 583 | blink::WebWidget* RenderWidget::CreateWebFrameWidget( |
| 584 | RenderWidget* render_widget, |
| 585 | blink::WebLocalFrame* frame) { |
| 586 | return blink::WebFrameWidget::create(render_widget, frame); |
| 587 | } |
| 588 | |
| 589 | // static |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 590 | blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 591 | switch (render_widget->popup_type_) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 592 | case blink::WebPopupTypeNone: // Nothing to create. |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 593 | break; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 594 | case blink::WebPopupTypePage: |
[email protected] | a7547fb | 2012-03-08 04:43:44 | [diff] [blame] | 595 | return WebPagePopup::create(render_widget); |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 596 | default: |
| 597 | NOTREACHED(); |
| 598 | } |
| 599 | return NULL; |
| 600 | } |
| 601 | |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 602 | void RenderWidget::CloseForFrame() { |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 603 | OnClose(); |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 604 | } |
| 605 | |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 606 | bool RenderWidget::Init(int32 opener_id) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame^] | 607 | return DoInit( |
| 608 | opener_id, RenderWidget::CreateWebWidget(this), |
| 609 | new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 610 | } |
| 611 | |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 612 | bool RenderWidget::DoInit(int32 opener_id, |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 613 | WebWidget* web_widget, |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 614 | IPC::SyncMessage* create_widget_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 615 | DCHECK(!webwidget_); |
| 616 | |
| 617 | if (opener_id != MSG_ROUTING_NONE) |
| 618 | opener_id_ = opener_id; |
| 619 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 620 | webwidget_ = web_widget; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 621 | |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 622 | bool result = true; |
| 623 | if (create_widget_message) |
| 624 | result = RenderThread::Get()->Send(create_widget_message); |
| 625 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 626 | if (result) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 627 | RenderThread::Get()->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 628 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 629 | // when we receive ViewMsg_Close. |
| 630 | AddRef(); |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 631 | if (RenderThreadImpl::current()) { |
| 632 | RenderThreadImpl::current()->WidgetCreated(); |
| 633 | if (is_hidden_) |
| 634 | RenderThreadImpl::current()->WidgetHidden(); |
| 635 | } |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 636 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 637 | } else { |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 638 | // The above Send can fail when the tab is closing. |
| 639 | return false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 643 | // This is used to complete pending inits and non-pending inits. |
| 644 | void RenderWidget::CompleteInit() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 645 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 646 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 647 | init_complete_ = true; |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 648 | |
piman | 4db52c1 | 2015-09-24 21:12:29 | [diff] [blame] | 649 | // TODO(piman): do we still need the 2-stage initialization? crbug.com/535339 |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 650 | if (compositor_) |
| 651 | StartCompositor(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 652 | |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 653 | Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 656 | void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 657 | // We should only toggle between states. |
| 658 | DCHECK(is_swapped_out_ != is_swapped_out); |
| 659 | is_swapped_out_ = is_swapped_out; |
| 660 | |
| 661 | // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 662 | // to exit if all of its RenderViews are swapped out. We wait until the |
[email protected] | 949b659 | 2014-08-20 13:17:52 | [diff] [blame] | 663 | // WasSwappedOut call to do this, to allow the unload handler to finish. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 664 | // If we are swapping in, we call AddRefProcess to prevent the process from |
| 665 | // exiting. |
[email protected] | 949b659 | 2014-08-20 13:17:52 | [diff] [blame] | 666 | if (!is_swapped_out_) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 667 | RenderProcess::current()->AddRefProcess(); |
| 668 | } |
| 669 | |
[email protected] | 949b659 | 2014-08-20 13:17:52 | [diff] [blame] | 670 | void RenderWidget::WasSwappedOut() { |
| 671 | // If we have been swapped out and no one else is using this process, |
| 672 | // it's safe to exit now. |
| 673 | CHECK(is_swapped_out_); |
| 674 | RenderProcess::current()->ReleaseProcess(); |
| 675 | } |
| 676 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 677 | void RenderWidget::SetPopupOriginAdjustmentsForEmulation( |
| 678 | ScreenMetricsEmulator* emulator) { |
| 679 | popup_origin_scale_for_emulation_ = emulator->scale(); |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 680 | popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin(); |
[email protected] | 9a2d7ee3 | 2013-12-05 12:15:49 | [diff] [blame] | 681 | popup_screen_origin_for_emulation_ = gfx::Point( |
| 682 | emulator->original_screen_rect().origin().x() + emulator->offset().x(), |
| 683 | emulator->original_screen_rect().origin().y() + emulator->offset().y()); |
[email protected] | 5f75aa4 | 2014-04-01 23:00:56 | [diff] [blame] | 684 | screen_info_ = emulator->original_screen_info(); |
| 685 | device_scale_factor_ = screen_info_.deviceScaleFactor; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 686 | } |
| 687 | |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 688 | gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) { |
| 689 | if (screen_metrics_emulator_) |
| 690 | return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor); |
| 691 | return anchor; |
| 692 | } |
| 693 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 694 | void RenderWidget::SetScreenMetricsEmulationParameters( |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 695 | bool enabled, |
| 696 | const blink::WebDeviceEmulationParams& params) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 697 | // This is only supported in RenderView. |
| 698 | NOTREACHED(); |
| 699 | } |
| 700 | |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 701 | #if defined(OS_MACOSX) || defined(OS_ANDROID) |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 702 | void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation( |
| 703 | ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) { |
[email protected] | 9a2d7ee3 | 2013-12-05 12:15:49 | [diff] [blame] | 704 | popup->SetOriginScaleAndOffsetForEmulation( |
| 705 | emulator->scale(), emulator->offset()); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 706 | } |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 707 | #endif |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 708 | |
| 709 | void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { |
| 710 | if (screen_metrics_emulator_) |
| 711 | screen_metrics_emulator_->OnShowContextMenu(params); |
| 712 | } |
| 713 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 714 | bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| 715 | bool handled = true; |
| 716 | IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 717 | IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) |
[email protected] | 34202de | 2013-05-06 23:36:22 | [diff] [blame] | 718 | IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, |
| 719 | OnCursorVisibilityChange) |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 720 | IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) |
| 721 | IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 722 | IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 723 | IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) |
[email protected] | 9017d785 | 2013-11-21 17:47:35 | [diff] [blame] | 724 | IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, |
| 725 | OnSyntheticGestureCompleted) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 726 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 727 | IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 728 | IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 729 | IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation, |
| 730 | OnEnableDeviceEmulation) |
| 731 | IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation, |
| 732 | OnDisableDeviceEmulation) |
noel | 89949e6 | 2014-09-30 01:12:41 | [diff] [blame] | 733 | IPC_MESSAGE_HANDLER(ViewMsg_ColorProfile, OnColorProfile) |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 734 | IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 735 | IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 736 | IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 737 | IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 738 | IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 739 | IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 740 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
kenrb | b4e2a3b | 2015-05-14 15:05:05 | [diff] [blame] | 741 | IPC_MESSAGE_HANDLER(ViewMsg_SetSurfaceIdNamespace, OnSetSurfaceIdNamespace) |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 742 | #if defined(OS_ANDROID) |
changwan | 3a84116 | 2015-08-11 02:53:37 | [diff] [blame] | 743 | IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) |
[email protected] | 2384b6c | 2013-02-28 23:58:51 | [diff] [blame] | 744 | IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 745 | #endif |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 746 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 747 | IPC_END_MESSAGE_MAP() |
| 748 | return handled; |
| 749 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 750 | |
| 751 | bool RenderWidget::Send(IPC::Message* message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 752 | // Don't send any messages after the browser has told us to close, and filter |
| 753 | // most outgoing messages while swapped out. |
| 754 | if ((is_swapped_out_ && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 755 | !SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
[email protected] | c6c921e9 | 2012-05-10 23:31:11 | [diff] [blame] | 756 | closing_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 757 | delete message; |
| 758 | return false; |
| 759 | } |
| 760 | |
| 761 | // If given a messsage without a routing ID, then assign our routing ID. |
| 762 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 763 | message->set_routing_id(routing_id_); |
| 764 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 765 | return RenderThread::Get()->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 766 | } |
| 767 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 768 | void RenderWidget::Resize(const gfx::Size& new_size, |
[email protected] | 60d47ac | 2013-03-01 23:42:44 | [diff] [blame] | 769 | const gfx::Size& physical_backing_size, |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 770 | bool top_controls_shrink_blink_size, |
| 771 | float top_controls_height, |
[email protected] | bb6378fe | 2014-04-28 21:19:44 | [diff] [blame] | 772 | const gfx::Size& visible_viewport_size, |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 773 | const gfx::Rect& resizer_rect, |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 774 | bool is_fullscreen_granted, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 775 | blink::WebDisplayMode display_mode, |
sievers | 4e33dae | 2015-02-25 20:43:58 | [diff] [blame] | 776 | const ResizeAck resize_ack) { |
[email protected] | f7c1f09 | 2013-11-05 20:20:56 | [diff] [blame] | 777 | if (resizing_mode_selector_->NeverUsesSynchronousResize()) { |
[email protected] | 1c000884 | 2013-06-06 08:35:48 | [diff] [blame] | 778 | // A resize ack shouldn't be requested if we have not ACK'd the previous |
| 779 | // one. |
| 780 | DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); |
| 781 | DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); |
| 782 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 783 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 784 | // Ignore this during shutdown. |
| 785 | if (!webwidget_) |
| 786 | return; |
| 787 | |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 788 | if (compositor_) { |
[email protected] | 60d47ac | 2013-03-01 23:42:44 | [diff] [blame] | 789 | compositor_->setViewportSize(new_size, physical_backing_size); |
[email protected] | d908376 | 2013-03-24 01:36:40 | [diff] [blame] | 790 | } |
[email protected] | 60d47ac | 2013-03-01 23:42:44 | [diff] [blame] | 791 | |
[email protected] | dade899 | 2013-03-04 07:34:34 | [diff] [blame] | 792 | physical_backing_size_ = physical_backing_size; |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 793 | top_controls_shrink_blink_size_ = top_controls_shrink_blink_size; |
| 794 | top_controls_height_ = top_controls_height; |
[email protected] | 39244e7 | 2014-05-14 04:20:28 | [diff] [blame] | 795 | visible_viewport_size_ = visible_viewport_size; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 796 | resizer_rect_ = resizer_rect; |
| 797 | |
| 798 | // NOTE: We may have entered fullscreen mode without changing our size. |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 799 | bool fullscreen_change = is_fullscreen_granted_ != is_fullscreen_granted; |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 800 | is_fullscreen_granted_ = is_fullscreen_granted; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 801 | display_mode_ = display_mode; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 802 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 803 | webwidget_->setTopControlsHeight(top_controls_height, |
| 804 | top_controls_shrink_blink_size_); |
bokan | 0c93cd8 | 2014-09-30 19:20:43 | [diff] [blame] | 805 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 806 | if (size_ != new_size) { |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 807 | size_ = new_size; |
| 808 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 809 | // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 810 | // ensures that we only resize as fast as we can paint. We only need to |
| 811 | // send an ACK if we are resized to a non-empty rect. |
| 812 | webwidget_->resize(new_size); |
[email protected] | 632c438 | 2013-05-15 08:58:45 | [diff] [blame] | 813 | } |
| 814 | |
[email protected] | bb6378fe | 2014-04-28 21:19:44 | [diff] [blame] | 815 | webwidget()->resizePinchViewport(gfx::Size( |
| 816 | visible_viewport_size.width(), |
| 817 | visible_viewport_size.height())); |
| 818 | |
[email protected] | 632c438 | 2013-05-15 08:58:45 | [diff] [blame] | 819 | if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) { |
sievers | 4e33dae | 2015-02-25 20:43:58 | [diff] [blame] | 820 | // In this case there is no paint/composite and therefore no |
| 821 | // ViewHostMsg_UpdateRect to send the resize ack with. We'd need to send the |
| 822 | // ack through a fake ViewHostMsg_UpdateRect or a different message. |
| 823 | DCHECK_EQ(resize_ack, NO_RESIZE_ACK); |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | 20fbfc2 | 2013-05-08 20:50:58 | [diff] [blame] | 826 | // Send the Resize_ACK flag once we paint again if requested. |
[email protected] | 632c438 | 2013-05-15 08:58:45 | [diff] [blame] | 827 | if (resize_ack == SEND_RESIZE_ACK) |
[email protected] | 20fbfc2 | 2013-05-08 20:50:58 | [diff] [blame] | 828 | set_next_paint_is_resize_ack(); |
| 829 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 830 | if (fullscreen_change) |
| 831 | DidToggleFullscreen(); |
| 832 | |
| 833 | // If a resize ack is requested and it isn't set-up, then no more resizes will |
| 834 | // come in and in general things will go wrong. |
[email protected] | 632c438 | 2013-05-15 08:58:45 | [diff] [blame] | 835 | DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 836 | } |
| 837 | |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 838 | void RenderWidget::SetWindowRectSynchronously( |
| 839 | const gfx::Rect& new_window_rect) { |
| 840 | Resize(new_window_rect.size(), |
| 841 | new_window_rect.size(), |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 842 | top_controls_shrink_blink_size_, |
| 843 | top_controls_height_, |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 844 | new_window_rect.size(), |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 845 | gfx::Rect(), |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 846 | is_fullscreen_granted_, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 847 | display_mode_, |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 848 | NO_RESIZE_ACK); |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 849 | view_screen_rect_ = new_window_rect; |
| 850 | window_screen_rect_ = new_window_rect; |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 851 | if (!did_show_) |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 852 | initial_rect_ = new_window_rect; |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 853 | } |
| 854 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 855 | void RenderWidget::OnClose() { |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 856 | DCHECK(content::RenderThread::Get()); |
| 857 | if (closing_) |
| 858 | return; |
| 859 | NotifyOnClose(); |
| 860 | closing_ = true; |
| 861 | |
| 862 | // Browser correspondence is no longer needed at this point. |
| 863 | if (routing_id_ != MSG_ROUTING_NONE) { |
| 864 | RenderThread::Get()->RemoveRoute(routing_id_); |
| 865 | SetHidden(false); |
| 866 | if (RenderThreadImpl::current()) |
| 867 | RenderThreadImpl::current()->WidgetDestroyed(); |
| 868 | } |
| 869 | |
| 870 | if (for_oopif_) { |
| 871 | // Widgets for frames may be created and closed at any time while the frame |
| 872 | // is alive. However, the closing process must happen synchronously. Frame |
| 873 | // widget and frames hold pointers to each other. If Close() is deferred to |
| 874 | // the message loop like in the non-frame widget case, WebWidget::close() |
| 875 | // can end up accessing members of an already-deleted frame. |
| 876 | Close(); |
| 877 | } else { |
| 878 | // If there is a Send call on the stack, then it could be dangerous to close |
| 879 | // now. Post a task that only gets invoked when there are no nested message |
| 880 | // loops. |
| 881 | base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( |
| 882 | FROM_HERE, base::Bind(&RenderWidget::Close, this)); |
| 883 | } |
| 884 | |
| 885 | // Balances the AddRef taken when we called AddRoute. |
| 886 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 887 | } |
| 888 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 889 | // Got a response from the browser after the renderer decided to create a new |
| 890 | // view. |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 891 | void RenderWidget::OnCreatingNewAck() { |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 892 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 893 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 894 | CompleteInit(); |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 895 | } |
| 896 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 897 | void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) { |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 898 | if (resizing_mode_selector_->ShouldAbortOnResize(this, params)) |
[email protected] | 03e8867 | 2013-10-22 21:31:32 | [diff] [blame] | 899 | return; |
| 900 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 901 | if (screen_metrics_emulator_) { |
| 902 | screen_metrics_emulator_->OnResizeMessage(params); |
| 903 | return; |
| 904 | } |
| 905 | |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 906 | bool orientation_changed = |
| 907 | screen_info_.orientationAngle != params.screen_info.orientationAngle; |
| 908 | |
[email protected] | 0fdd501 | 2013-05-29 08:05:56 | [diff] [blame] | 909 | screen_info_ = params.screen_info; |
| 910 | SetDeviceScaleFactor(screen_info_.deviceScaleFactor); |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 911 | Resize(params.new_size, |
| 912 | params.physical_backing_size, |
| 913 | params.top_controls_shrink_blink_size, |
| 914 | params.top_controls_height, |
| 915 | params.visible_viewport_size, |
| 916 | params.resizer_rect, |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 917 | params.is_fullscreen_granted, |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 918 | params.display_mode, |
sievers | 4e33dae | 2015-02-25 20:43:58 | [diff] [blame] | 919 | params.needs_resize_ack ? SEND_RESIZE_ACK : NO_RESIZE_ACK); |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 920 | |
| 921 | if (orientation_changed) |
| 922 | OnOrientationChange(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 923 | } |
| 924 | |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 925 | void RenderWidget::OnEnableDeviceEmulation( |
| 926 | const blink::WebDeviceEmulationParams& params) { |
| 927 | if (!screen_metrics_emulator_) |
| 928 | screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this, params)); |
| 929 | else |
| 930 | screen_metrics_emulator_->ChangeEmulationParams(params); |
| 931 | } |
| 932 | |
| 933 | void RenderWidget::OnDisableDeviceEmulation() { |
| 934 | screen_metrics_emulator_.reset(); |
| 935 | } |
| 936 | |
noel | 89949e6 | 2014-09-30 01:12:41 | [diff] [blame] | 937 | void RenderWidget::OnColorProfile(const std::vector<char>& color_profile) { |
| 938 | SetDeviceColorProfile(color_profile); |
| 939 | } |
| 940 | |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 941 | void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { |
[email protected] | 721e230 | 2014-04-30 23:42:01 | [diff] [blame] | 942 | if (resizer_rect_ == resizer_rect) |
| 943 | return; |
| 944 | resizer_rect_ = resizer_rect; |
| 945 | if (webwidget_) |
| 946 | webwidget_->didChangeWindowResizerRect(); |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 947 | } |
| 948 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 949 | void RenderWidget::OnWasHidden() { |
[email protected] | 9c3085f | 2011-06-09 02:10:31 | [diff] [blame] | 950 | TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 951 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 952 | SetHidden(true); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 953 | FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, |
| 954 | WasHidden()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 955 | } |
| 956 | |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 957 | void RenderWidget::OnWasShown(bool needs_repainting, |
| 958 | const ui::LatencyInfo& latency_info) { |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 959 | TRACE_EVENT0("renderer", "RenderWidget::OnWasShown"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 960 | // During shutdown we can just ignore this message. |
| 961 | if (!webwidget_) |
| 962 | return; |
| 963 | |
| 964 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 965 | SetHidden(false); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 966 | FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, |
| 967 | WasShown()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 968 | |
[email protected] | 8a23afb3 | 2014-04-30 22:40:23 | [diff] [blame] | 969 | if (!needs_repainting) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 970 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 971 | |
| 972 | // Generate a full repaint. |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 973 | if (compositor_) { |
| 974 | ui::LatencyInfo swap_latency_info(latency_info); |
| 975 | scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor( |
| 976 | compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info)); |
[email protected] | aca33f4f | 2014-05-17 17:08:05 | [diff] [blame] | 977 | compositor_->SetNeedsForcedRedraw(); |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 978 | } |
jdduke | 491a3f0c | 2015-06-15 23:30:26 | [diff] [blame] | 979 | ScheduleComposite(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 982 | void RenderWidget::OnRequestMoveAck() { |
| 983 | DCHECK(pending_window_rect_count_); |
| 984 | pending_window_rect_count_--; |
| 985 | } |
| 986 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 987 | GURL RenderWidget::GetURLForGraphicsContext3D() { |
| 988 | return GURL(); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 989 | } |
| 990 | |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 991 | scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 992 | // For widgets that are never visible, we don't start the compositor, so we |
| 993 | // never get a request for a cc::OutputSurface. |
| 994 | DCHECK(!never_visible_); |
[email protected] | a1811b891 | 2013-05-09 15:35:19 | [diff] [blame] | 995 | |
| 996 | #if defined(OS_ANDROID) |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 997 | if (SynchronousCompositorFactory* factory = |
| 998 | SynchronousCompositorFactory::GetInstance()) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame^] | 999 | return factory->CreateOutputSurface(routing_id(), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1000 | frame_swap_message_queue_); |
[email protected] | a1811b891 | 2013-05-09 15:35:19 | [diff] [blame] | 1001 | } |
| 1002 | #endif |
| 1003 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 1004 | const base::CommandLine& command_line = |
| 1005 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | e09994a | 2014-03-26 19:59:33 | [diff] [blame] | 1006 | bool use_software = fallback; |
| 1007 | if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
| 1008 | use_software = true; |
| 1009 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1010 | scoped_refptr<ContextProviderCommandBuffer> context_provider; |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 1011 | scoped_refptr<ContextProviderCommandBuffer> worker_context_provider; |
[email protected] | e09994a | 2014-03-26 19:59:33 | [diff] [blame] | 1012 | if (!use_software) { |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1013 | context_provider = ContextProviderCommandBuffer::Create( |
jbauman | 5e420d3 | 2015-08-05 09:33:01 | [diff] [blame] | 1014 | CreateGraphicsContext3D(true), RENDER_COMPOSITOR_CONTEXT); |
[email protected] | e09994a | 2014-03-26 19:59:33 | [diff] [blame] | 1015 | if (!context_provider.get()) { |
| 1016 | // Cause the compositor to wait and try again. |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1017 | return nullptr; |
[email protected] | e09994a | 2014-03-26 19:59:33 | [diff] [blame] | 1018 | } |
reveman | d180dfc3 | 2015-09-24 00:19:43 | [diff] [blame] | 1019 | worker_context_provider = |
| 1020 | RenderThreadImpl::current()->SharedWorkerContextProvider(); |
| 1021 | if (!worker_context_provider) { |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 1022 | // Cause the compositor to wait and try again. |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1023 | return nullptr; |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 1024 | } |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1025 | } |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 1026 | |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 1027 | uint32 output_surface_id = next_output_surface_id_++; |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1028 | // Composite-to-mailbox is currently used for layout tests in order to cause |
| 1029 | // them to draw inside in the renderer to do the readback there. This should |
| 1030 | // no longer be the case when crbug.com/311404 is fixed. |
| 1031 | if (!RenderThreadImpl::current() || |
| 1032 | !RenderThreadImpl::current()->layout_test_mode()) { |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1033 | DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner()); |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1034 | return make_scoped_ptr(new DelegatedCompositorOutputSurface( |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 1035 | routing_id(), output_surface_id, context_provider, |
| 1036 | worker_context_provider, frame_swap_message_queue_)); |
[email protected] | 65a33ce | 2014-03-25 22:37:09 | [diff] [blame] | 1037 | } |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1038 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1039 | if (!context_provider.get()) { |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1040 | scoped_ptr<cc::SoftwareOutputDevice> software_device( |
jbauman | 7e15c6a | 2015-05-11 23:43:12 | [diff] [blame] | 1041 | new cc::SoftwareOutputDevice()); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 1042 | |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1043 | return make_scoped_ptr(new CompositorOutputSurface( |
caseq | ff9c74c | 2015-02-10 14:56:29 | [diff] [blame] | 1044 | routing_id(), output_surface_id, nullptr, nullptr, |
| 1045 | software_device.Pass(), frame_swap_message_queue_, true)); |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 1046 | } |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 1047 | |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1048 | return make_scoped_ptr(new MailboxOutputSurface( |
vmiura | 78b6928 | 2015-02-14 00:01:17 | [diff] [blame] | 1049 | routing_id(), output_surface_id, context_provider, |
piman | 8944e1c | 2015-09-22 21:10:34 | [diff] [blame] | 1050 | worker_context_provider, frame_swap_message_queue_, cc::RGBA_8888)); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 1051 | } |
| 1052 | |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 1053 | void RenderWidget::OnSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1054 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1055 | // Schedule another frame so the compositor learns about it. |
jdduke | 491a3f0c | 2015-06-15 23:30:26 | [diff] [blame] | 1056 | ScheduleComposite(); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1057 | } |
| 1058 | |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 1059 | void RenderWidget::OnSwapBuffersPosted() { |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 1060 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 1061 | } |
| 1062 | |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 1063 | void RenderWidget::OnSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1064 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 1065 | |
[email protected] | 404939f | 2012-06-01 04:06:18 | [diff] [blame] | 1066 | // Notify subclasses that composited rendering was flushed to the screen. |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 1067 | DidFlushPaint(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1068 | } |
| 1069 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1070 | void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, |
[email protected] | 205294b | 2014-03-18 20:48:35 | [diff] [blame] | 1071 | const ui::LatencyInfo& latency_info, |
[email protected] | 0dea165 | 2012-12-14 00:09:09 | [diff] [blame] | 1072 | bool is_keyboard_shortcut) { |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 1073 | if (!input_event) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1074 | return; |
jdduke | c05612b | 2015-06-25 23:13:18 | [diff] [blame] | 1075 | base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_, |
| 1076 | true); |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 1077 | base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( |
| 1078 | &handling_event_type_, input_event->type); |
jdduke | c05612b | 2015-06-25 23:13:18 | [diff] [blame] | 1079 | |
| 1080 | // Calls into |didOverscroll()| while handling this event will populate |
| 1081 | // |event_overscroll|, which in turn will be bundled with the event ack. |
| 1082 | scoped_ptr<DidOverscrollParams> event_overscroll; |
| 1083 | base::AutoReset<scoped_ptr<DidOverscrollParams>*> |
| 1084 | handling_event_overscroll_resetter(&handling_event_overscroll_, |
| 1085 | &event_overscroll); |
| 1086 | |
[email protected] | 25402eb | 2014-07-18 03:09:52 | [diff] [blame] | 1087 | #if defined(OS_ANDROID) |
bcwhite | d21e6ff | 2014-09-05 18:48:54 | [diff] [blame] | 1088 | // On Android, when a key is pressed or sent from the Keyboard using IME, |
[email protected] | 25402eb | 2014-07-18 03:09:52 | [diff] [blame] | 1089 | // |AdapterInputConnection| generates input key events to make sure all JS |
| 1090 | // listeners that monitor KeyUp and KeyDown events receive the proper key |
| 1091 | // code. Since this input key event comes from IME, we need to set the |
| 1092 | // IME event guard here to make sure it does not interfere with other IME |
| 1093 | // events. |
| 1094 | scoped_ptr<ImeEventGuard> ime_event_guard_maybe; |
| 1095 | if (WebInputEvent::isKeyboardEventType(input_event->type)) { |
| 1096 | const WebKeyboardEvent& key_event = |
| 1097 | *static_cast<const WebKeyboardEvent*>(input_event); |
bcwhite | d21e6ff | 2014-09-05 18:48:54 | [diff] [blame] | 1098 | // Some keys are special and it's essential that no events get blocked. |
bcwhite | 5752e44 | 2014-10-07 00:05:17 | [diff] [blame] | 1099 | if (key_event.nativeKeyCode != AKEYCODE_TAB && |
bcwhite | 796d5ac | 2014-11-22 02:32:09 | [diff] [blame] | 1100 | key_event.nativeKeyCode != AKEYCODE_DPAD_CENTER && |
| 1101 | key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT && |
| 1102 | key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT && |
| 1103 | key_event.nativeKeyCode != AKEYCODE_DPAD_UP && |
| 1104 | key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN) |
[email protected] | 25402eb | 2014-07-18 03:09:52 | [diff] [blame] | 1105 | ime_event_guard_maybe.reset(new ImeEventGuard(this)); |
[email protected] | 25402eb | 2014-07-18 03:09:52 | [diff] [blame] | 1106 | } |
| 1107 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1108 | |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1109 | base::TimeTicks start_time; |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 1110 | if (base::TimeTicks::IsHighResolution()) |
| 1111 | start_time = base::TimeTicks::Now(); |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1112 | |
miletus | fed8c43b | 2015-01-26 20:04:52 | [diff] [blame] | 1113 | TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 1114 | "event", WebInputEventTraits::GetName(input_event->type)); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 1115 | TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); |
yuhaoz | 8df9334c | 2015-08-18 17:48:51 | [diff] [blame] | 1116 | TRACE_EVENT_WITH_FLOW1("input,benchmark", |
| 1117 | "LatencyInfo.Flow", |
| 1118 | TRACE_ID_DONT_MANGLE(latency_info.trace_id()), |
| 1119 | TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 1120 | "step", "HandleInputEventMain"); |
[email protected] | b4841e1c | 2013-05-16 22:30:10 | [diff] [blame] | 1121 | |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 1122 | // If we don't have a high res timer, these metrics won't be accurate enough |
| 1123 | // to be worth collecting. Note that this does introduce some sampling bias. |
| 1124 | if (!start_time.is_null()) |
miletus | 14a2564 | 2015-08-13 19:23:23 | [diff] [blame] | 1125 | LogInputEventLatencyUma(*input_event, start_time, latency_info); |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 1126 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1127 | scoped_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor; |
[email protected] | 205294b | 2014-03-18 20:48:35 | [diff] [blame] | 1128 | ui::LatencyInfo swap_latency_info(latency_info); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1129 | if (compositor_) { |
| 1130 | latency_info_swap_promise_monitor = |
[email protected] | 205294b | 2014-03-18 20:48:35 | [diff] [blame] | 1131 | compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info) |
| 1132 | .Pass(); |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 1133 | } |
[email protected] | c2eaa8f | 2013-05-10 02:41:55 | [diff] [blame] | 1134 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1135 | bool prevent_default = false; |
| 1136 | if (WebInputEvent::isMouseEventType(input_event->type)) { |
[email protected] | 936c6f5 | 2011-12-13 01:35:26 | [diff] [blame] | 1137 | const WebMouseEvent& mouse_event = |
| 1138 | *static_cast<const WebMouseEvent*>(input_event); |
| 1139 | TRACE_EVENT2("renderer", "HandleMouseMove", |
| 1140 | "x", mouse_event.x, "y", mouse_event.y); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 1141 | context_menu_source_type_ = ui::MENU_SOURCE_MOUSE; |
[email protected] | 936c6f5 | 2011-12-13 01:35:26 | [diff] [blame] | 1142 | prevent_default = WillHandleMouseEvent(mouse_event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1143 | } |
| 1144 | |
[email protected] | cefe9b15 | 2014-03-27 18:16:15 | [diff] [blame] | 1145 | if (WebInputEvent::isKeyboardEventType(input_event->type)) { |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 1146 | context_menu_source_type_ = ui::MENU_SOURCE_KEYBOARD; |
[email protected] | cefe9b15 | 2014-03-27 18:16:15 | [diff] [blame] | 1147 | #if defined(OS_ANDROID) |
| 1148 | // The DPAD_CENTER key on Android has a dual semantic: (1) in the general |
| 1149 | // case it should behave like a select key (i.e. causing a click if a button |
| 1150 | // is focused). However, if a text field is focused (2), its intended |
| 1151 | // behavior is to just show the IME and don't propagate the key. |
| 1152 | // A typical use case is a web form: the DPAD_CENTER should bring up the IME |
| 1153 | // when clicked on an input text field and cause the form submit if clicked |
| 1154 | // when the submit button is focused, but not vice-versa. |
| 1155 | // The UI layer takes care of translating DPAD_CENTER into a RETURN key, |
| 1156 | // but at this point we have to swallow the event for the scenario (2). |
| 1157 | const WebKeyboardEvent& key_event = |
| 1158 | *static_cast<const WebKeyboardEvent*>(input_event); |
| 1159 | if (key_event.nativeKeyCode == AKEYCODE_DPAD_CENTER && |
| 1160 | GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { |
| 1161 | OnShowImeIfNeeded(); |
| 1162 | prevent_default = true; |
| 1163 | } |
| 1164 | #endif |
| 1165 | } |
[email protected] | f56c787 | 2013-06-18 12:31:57 | [diff] [blame] | 1166 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 1167 | if (WebInputEvent::isGestureEventType(input_event->type)) { |
| 1168 | const WebGestureEvent& gesture_event = |
| 1169 | *static_cast<const WebGestureEvent*>(input_event); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 1170 | context_menu_source_type_ = ui::MENU_SOURCE_TOUCH; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 1171 | prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); |
| 1172 | } |
| 1173 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1174 | bool processed = prevent_default; |
[email protected] | b68a0e5 | 2011-12-08 15:11:12 | [diff] [blame] | 1175 | if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
| 1176 | suppress_next_char_events_ = false; |
| 1177 | if (!processed && webwidget_) |
| 1178 | processed = webwidget_->handleInputEvent(*input_event); |
| 1179 | } |
| 1180 | |
| 1181 | // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
| 1182 | // it's not processed by webkit, then we need to suppress the upcoming Char |
| 1183 | // events. |
| 1184 | if (!processed && is_keyboard_shortcut) |
| 1185 | suppress_next_char_events_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1186 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 1187 | 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] | f8ed472 | 2013-12-03 03:27:25 | [diff] [blame] | 1192 | // 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] | a66e18e | 2014-01-29 20:58:27 | [diff] [blame] | 1198 | HasTouchEventHandlersAt( |
[email protected] | 9c769d41 | 2014-03-20 18:27:39 | [diff] [blame] | 1199 | gfx::ToFlooredPoint(touch_event.touches[i].position))) { |
[email protected] | f8ed472 | 2013-12-03 03:27:25 | [diff] [blame] | 1200 | ack_result = INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 1201 | break; |
| 1202 | } |
| 1203 | } |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 1204 | } |
| 1205 | |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 1206 | // 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) { |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 1209 | ObserveWheelEventAndResult( |
sataya.m | f405d0e | 2015-07-07 16:51:11 | [diff] [blame] | 1210 | static_cast<const WebMouseWheelEvent&>(*input_event), |
| 1211 | event_overscroll ? event_overscroll->latest_overscroll_delta |
| 1212 | : gfx::Vector2dF(), |
| 1213 | processed); |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 1214 | } |
| 1215 | |
[email protected] | 721e230 | 2014-04-30 23:42:01 | [diff] [blame] | 1216 | bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested(); |
[email protected] | 8926c60 | 2013-01-23 05:32:06 | [diff] [blame] | 1217 | |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 1218 | // If we don't have a fast and accurate Now(), we assume the input handlers |
| 1219 | // are heavy and rate limit them. |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 1220 | 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()) { |
charliea | 3be83970 | 2015-01-26 17:35:41 | [diff] [blame] | 1224 | base::TimeTicks end_time = base::TimeTicks::Now(); |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1225 | 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] | 7f19e9d | 2014-05-09 15:16:29 | [diff] [blame] | 1231 | TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); |
| 1232 | |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 1233 | // 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; |
lanwei | f1a2283 | 2015-05-19 17:24:10 | [diff] [blame] | 1237 | if (WebInputEventTraits::WillReceiveAckFromRenderer(*input_event) && |
| 1238 | !no_ack) { |
| 1239 | InputEventAck ack(input_event->type, ack_result, swap_latency_info, |
jdduke | c05612b | 2015-06-25 23:13:18 | [diff] [blame] | 1240 | event_overscroll.Pass(), |
lanwei | f1a2283 | 2015-05-19 17:24:10 | [diff] [blame] | 1241 | WebInputEventTraits::GetUniqueTouchEventId(*input_event)); |
[email protected] | 34afe10 | 2013-12-13 17:24:55 | [diff] [blame] | 1242 | scoped_ptr<IPC::Message> response( |
[email protected] | 8e431f203 | 2014-05-20 02:34:56 | [diff] [blame] | 1243 | new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack)); |
jdduke | 0778806 | 2014-12-05 03:16:30 | [diff] [blame] | 1244 | if (rate_limiting_wanted && frame_pending && !is_hidden_) { |
[email protected] | 34afe10 | 2013-12-13 17:24:55 | [diff] [blame] | 1245 | // 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_) { |
jdduke | fffb67c | 2015-01-07 22:32:29 | [diff] [blame] | 1251 | TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck", |
| 1252 | pending_input_event_ack_.get()); |
[email protected] | 34afe10 | 2013-12-13 17:24:55 | [diff] [blame] | 1253 | // 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(); |
jdduke | fffb67c | 2015-01-07 22:32:29 | [diff] [blame] | 1259 | TRACE_EVENT_ASYNC_BEGIN0("input", "RenderWidget::ThrottledInputEventAck", |
| 1260 | pending_input_event_ack_.get()); |
[email protected] | 34afe10 | 2013-12-13 17:24:55 | [diff] [blame] | 1261 | if (compositor_) |
| 1262 | compositor_->NotifyInputThrottledUntilCommit(); |
| 1263 | } else { |
| 1264 | Send(response.release()); |
[email protected] | 353a34c | 2010-05-28 23:35:17 | [diff] [blame] | 1265 | } |
jdduke | c05612b | 2015-06-25 23:13:18 | [diff] [blame] | 1266 | } else { |
| 1267 | DCHECK(!event_overscroll) << "Unexpected overscroll for un-acked event"; |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 1268 | } |
alexclarke | 7819e255 | 2015-06-03 11:17:21 | [diff] [blame] | 1269 | if (!no_ack && RenderThreadImpl::current()) { |
| 1270 | RenderThreadImpl::current() |
| 1271 | ->GetRendererScheduler() |
| 1272 | ->DidHandleInputEventOnMainThread(*input_event); |
| 1273 | } |
[email protected] | 5fea4a5 | 2014-05-27 00:17:52 | [diff] [blame] | 1274 | if (input_event->type == WebInputEvent::MouseMove) |
| 1275 | ignore_ack_for_mouse_move_from_debugger_ = false; |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 1276 | |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1277 | #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] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1281 | UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 1282 | #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 || |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1286 | input_event->type == WebInputEvent::MouseUp)) { |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1287 | UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_IME); |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1288 | } |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1289 | #endif |
| 1290 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1291 | if (!prevent_default) { |
| 1292 | if (WebInputEvent::isKeyboardEventType(input_event->type)) |
| 1293 | DidHandleKeyEvent(); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1294 | } |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1295 | |
| 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.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1305 | } |
| 1306 | |
[email protected] | 34202de | 2013-05-06 23:36:22 | [diff] [blame] | 1307 | void RenderWidget::OnCursorVisibilityChange(bool is_visible) { |
| 1308 | if (webwidget_) |
| 1309 | webwidget_->setCursorVisibilityState(is_visible); |
| 1310 | } |
| 1311 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1312 | void RenderWidget::OnMouseCaptureLost() { |
| 1313 | if (webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1314 | webwidget_->mouseCaptureLost(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | void RenderWidget::OnSetFocus(bool enable) { |
| 1318 | has_focus_ = enable; |
[email protected] | 9d166af | 2010-03-02 22:04:33 | [diff] [blame] | 1319 | if (webwidget_) |
| 1320 | webwidget_->setFocus(enable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | void RenderWidget::ClearFocus() { |
| 1324 | // We may have got the focus from the browser before this gets processed, in |
| 1325 | // which case we do not want to unfocus ourself. |
| 1326 | if (!has_focus_ && webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1327 | webwidget_->setFocus(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1328 | } |
| 1329 | |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1330 | void RenderWidget::FlushPendingInputEventAck() { |
jdduke | fffb67c | 2015-01-07 22:32:29 | [diff] [blame] | 1331 | if (pending_input_event_ack_) { |
| 1332 | TRACE_EVENT_ASYNC_END0("input", "RenderWidget::ThrottledInputEventAck", |
| 1333 | pending_input_event_ack_.get()); |
[email protected] | d8a8ecb | 2013-10-23 18:03:07 | [diff] [blame] | 1334 | Send(pending_input_event_ack_.release()); |
jdduke | fffb67c | 2015-01-07 22:32:29 | [diff] [blame] | 1335 | } |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1336 | total_input_handling_time_this_frame_ = base::TimeDelta(); |
| 1337 | } |
| 1338 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1339 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1340 | // WebWidgetClient |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1341 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1342 | void RenderWidget::didAutoResize(const WebSize& new_size) { |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1343 | if (size_.width() != new_size.width || size_.height() != new_size.height) { |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 1344 | size_ = new_size; |
[email protected] | 20fbfc2 | 2013-05-08 20:50:58 | [diff] [blame] | 1345 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 1346 | if (resizing_mode_selector_->is_synchronous_mode()) { |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 1347 | WebRect new_pos(rootWindowRect().x, |
| 1348 | rootWindowRect().y, |
| 1349 | new_size.width, |
| 1350 | new_size.height); |
| 1351 | view_screen_rect_ = new_pos; |
| 1352 | window_screen_rect_ = new_pos; |
[email protected] | 8be1c58 | 2013-03-06 00:55:03 | [diff] [blame] | 1353 | } |
[email protected] | 20fbfc2 | 2013-05-08 20:50:58 | [diff] [blame] | 1354 | |
[email protected] | eac2b36 | 2013-05-22 07:01:45 | [diff] [blame] | 1355 | AutoResizeCompositor(); |
[email protected] | 20fbfc2 | 2013-05-08 20:50:58 | [diff] [blame] | 1356 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 1357 | if (!resizing_mode_selector_->is_synchronous_mode()) |
[email protected] | 20fbfc2 | 2013-05-08 20:50:58 | [diff] [blame] | 1358 | need_update_rect_for_auto_resize_ = true; |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1359 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1360 | } |
| 1361 | |
[email protected] | 3a1c8a803 | 2013-03-18 22:35:32 | [diff] [blame] | 1362 | void RenderWidget::AutoResizeCompositor() { |
[email protected] | 97e1bf7 | 2013-03-06 14:06:05 | [diff] [blame] | 1363 | physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, |
| 1364 | device_scale_factor_)); |
| 1365 | if (compositor_) |
| 1366 | compositor_->setViewportSize(size_, physical_backing_size_); |
| 1367 | } |
| 1368 | |
[email protected] | e195e58 | 2013-03-08 01:32:59 | [diff] [blame] | 1369 | void RenderWidget::initializeLayerTreeView() { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1370 | DCHECK(!host_closing_); |
| 1371 | |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 1372 | compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); |
[email protected] | e195e58 | 2013-03-08 01:32:59 | [diff] [blame] | 1373 | compositor_->setViewportSize(size_, physical_backing_size_); |
| 1374 | if (init_complete_) |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 1375 | StartCompositor(); |
[email protected] | e195e58 | 2013-03-08 01:32:59 | [diff] [blame] | 1376 | } |
| 1377 | |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1378 | void RenderWidget::WillCloseLayerTreeView() { |
| 1379 | if (host_closing_) |
| 1380 | return; |
| 1381 | |
| 1382 | // Prevent new compositors or output surfaces from being created. |
| 1383 | host_closing_ = true; |
| 1384 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1385 | // Always send this notification to prevent new layer tree views from |
| 1386 | // being created, even if one hasn't been created yet. |
| 1387 | if (webwidget_) |
| 1388 | webwidget_->willCloseLayerTreeView(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1389 | } |
| 1390 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1391 | blink::WebLayerTreeView* RenderWidget::layerTreeView() { |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 1392 | return compositor_.get(); |
[email protected] | 8926c60 | 2013-01-23 05:32:06 | [diff] [blame] | 1393 | } |
| 1394 | |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 1395 | void RenderWidget::didFirstVisuallyNonEmptyLayout() { |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 1396 | QueueMessage( |
| 1397 | new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_), |
| 1398 | MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
| 1399 | } |
| 1400 | |
| 1401 | void RenderWidget::didFirstLayoutAfterFinishedParsing() { |
| 1402 | // TODO(dglazkov): Use this hook to drive CapturePageInfo. |
| 1403 | } |
| 1404 | |
jdduke | 491a3f0c | 2015-06-15 23:30:26 | [diff] [blame] | 1405 | void RenderWidget::WillBeginCompositorFrame() { |
[email protected] | 9cd43a6 | 2012-03-26 08:03:56 | [diff] [blame] | 1406 | TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
[email protected] | abe8b3a | 2012-03-28 21:19:37 | [diff] [blame] | 1407 | |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1408 | // The UpdateTextInputState can result in further layout and possibly |
[email protected] | abe8b3a | 2012-03-28 21:19:37 | [diff] [blame] | 1409 | // enable GPU acceleration so they need to be called before any painting |
| 1410 | // is done. |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1411 | UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME); |
[email protected] | abe8b3a | 2012-03-28 21:19:37 | [diff] [blame] | 1412 | UpdateSelectionBounds(); |
[email protected] | 9cd43a6 | 2012-03-26 08:03:56 | [diff] [blame] | 1413 | } |
| 1414 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 1415 | void RenderWidget::DidCommitCompositorFrame() { |
fsamuel | 2e9413d | 2015-02-25 01:25:44 | [diff] [blame] | 1416 | FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, |
| 1417 | DidCommitCompositorFrame()); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 1418 | FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 1419 | DidCommitCompositorFrame()); |
[email protected] | a017938b | 2014-05-27 21:17:17 | [diff] [blame] | 1420 | #if defined(VIDEO_HOLE) |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 1421 | FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, |
| 1422 | DidCommitCompositorFrame()); |
[email protected] | a017938b | 2014-05-27 21:17:17 | [diff] [blame] | 1423 | #endif // defined(VIDEO_HOLE) |
jdduke | 491a3f0c | 2015-06-15 23:30:26 | [diff] [blame] | 1424 | FlushPendingInputEventAck(); |
| 1425 | } |
| 1426 | |
| 1427 | void RenderWidget::DidCommitAndDrawCompositorFrame() { |
| 1428 | // NOTE: Tests may break if this event is renamed or moved. See |
| 1429 | // tab_capture_performancetest.cc. |
| 1430 | TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame"); |
| 1431 | // Notify subclasses that we initiated the paint operation. |
| 1432 | DidInitiatePaint(); |
| 1433 | } |
| 1434 | |
| 1435 | void RenderWidget::DidCompleteSwapBuffers() { |
| 1436 | TRACE_EVENT0("renderer", "RenderWidget::DidCompleteSwapBuffers"); |
| 1437 | |
| 1438 | // Notify subclasses threaded composited rendering was flushed to the screen. |
| 1439 | DidFlushPaint(); |
| 1440 | |
| 1441 | if (!next_paint_flags_ && |
| 1442 | !need_update_rect_for_auto_resize_ && |
| 1443 | !plugin_window_moves_.size()) { |
| 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | ViewHostMsg_UpdateRect_Params params; |
| 1448 | params.view_size = size_; |
| 1449 | params.plugin_window_moves.swap(plugin_window_moves_); |
| 1450 | params.flags = next_paint_flags_; |
| 1451 | |
| 1452 | Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
| 1453 | next_paint_flags_ = 0; |
| 1454 | need_update_rect_for_auto_resize_ = false; |
| 1455 | } |
| 1456 | |
| 1457 | void RenderWidget::ScheduleComposite() { |
| 1458 | if (compositor_ && |
| 1459 | compositor_deps_->GetCompositorImplThreadTaskRunner().get()) { |
| 1460 | compositor_->setNeedsAnimate(); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | void RenderWidget::ScheduleCompositeWithForcedRedraw() { |
| 1465 | if (compositor_) { |
| 1466 | // Regardless of whether threaded compositing is enabled, always |
| 1467 | // use this mechanism to force the compositor to redraw. However, |
| 1468 | // the invalidation code path below is still needed for the |
| 1469 | // non-threaded case. |
| 1470 | compositor_->SetNeedsForcedRedraw(); |
| 1471 | } |
| 1472 | ScheduleComposite(); |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 1473 | } |
| 1474 | |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1475 | // static |
| 1476 | scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( |
| 1477 | IPC::Message* msg, |
| 1478 | MessageDeliveryPolicy policy, |
| 1479 | FrameSwapMessageQueue* frame_swap_message_queue, |
| 1480 | scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1481 | int source_frame_number) { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1482 | bool first_message_for_frame = false; |
| 1483 | frame_swap_message_queue->QueueMessageForFrame(policy, |
| 1484 | source_frame_number, |
| 1485 | make_scoped_ptr(msg), |
| 1486 | &first_message_for_frame); |
| 1487 | if (first_message_for_frame) { |
| 1488 | scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
| 1489 | sync_message_filter, frame_swap_message_queue, source_frame_number)); |
dcheng | 4b6b5ff | 2014-10-16 00:42:06 | [diff] [blame] | 1490 | return promise; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1491 | } |
dcheng | 4b6b5ff | 2014-10-16 00:42:06 | [diff] [blame] | 1492 | return nullptr; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | void RenderWidget::QueueMessage(IPC::Message* msg, |
| 1496 | MessageDeliveryPolicy policy) { |
| 1497 | // RenderThreadImpl::current() is NULL in some tests. |
| 1498 | if (!compositor_ || !RenderThreadImpl::current()) { |
| 1499 | Send(msg); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
| 1503 | scoped_ptr<cc::SwapPromise> swap_promise = |
| 1504 | QueueMessageImpl(msg, |
| 1505 | policy, |
dcheng | 58867a9 | 2014-08-26 02:50:22 | [diff] [blame] | 1506 | frame_swap_message_queue_.get(), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1507 | RenderThreadImpl::current()->sync_message_filter(), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1508 | compositor_->GetSourceFrameNumber()); |
| 1509 | |
| 1510 | if (swap_promise) { |
| 1511 | compositor_->QueueSwapPromise(swap_promise.Pass()); |
igsolla | eab34cc | 2015-02-20 11:33:35 | [diff] [blame] | 1512 | // Request a commit. This might either A) request a commit ahead of time |
| 1513 | // or B) request a commit which is not needed because there are not |
| 1514 | // pending updates. If B) then the commit will be skipped and the swap |
| 1515 | // promises will be broken (see EarlyOut_NoUpdates). To achieve that we |
| 1516 | // call SetNeedsUpdateLayers instead of SetNeedsCommit so that |
| 1517 | // can_cancel_commit is not unset. |
| 1518 | compositor_->SetNeedsUpdateLayers(); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1522 | void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 1523 | // TODO(darin): Eliminate this temporary. |
[email protected] | 9ec8771 | 2013-05-24 23:23:52 | [diff] [blame] | 1524 | WebCursor cursor; |
[email protected] | 953bd006 | 2013-08-01 00:58:40 | [diff] [blame] | 1525 | InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1526 | // Only send a SetCursor message if we need to make a change. |
| 1527 | if (!current_cursor_.IsEqual(cursor)) { |
| 1528 | current_cursor_ = cursor; |
| 1529 | Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 1534 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 1535 | // point to dispatch the ShowWidget message. |
| 1536 | // |
| 1537 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1538 | // created RenderWidget (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1539 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1540 | void RenderWidget::show(WebNavigationPolicy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1541 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1542 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 1543 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1544 | |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1545 | if (did_show_) |
| 1546 | return; |
| 1547 | |
| 1548 | did_show_ = true; |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1549 | // NOTE: initial_rect_ may still have its default values at this point, but |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1550 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 1551 | // process will impose a default position otherwise. |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1552 | Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_)); |
| 1553 | SetPendingWindowRect(initial_rect_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1554 | } |
| 1555 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1556 | void RenderWidget::didFocus() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1557 | } |
| 1558 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1559 | void RenderWidget::didBlur() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1560 | } |
| 1561 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1562 | void RenderWidget::DoDeferredClose() { |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1563 | WillCloseLayerTreeView(); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1564 | Send(new ViewHostMsg_Close(routing_id_)); |
| 1565 | } |
| 1566 | |
dgozman | cf9039cd | 2015-04-06 12:01:31 | [diff] [blame] | 1567 | void RenderWidget::NotifyOnClose() { |
| 1568 | FOR_EACH_OBSERVER(RenderFrameImpl, render_frames_, WidgetWillClose()); |
| 1569 | } |
| 1570 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1571 | void RenderWidget::closeWidgetSoon() { |
skyostil | ed8969c | 2015-07-20 16:57:08 | [diff] [blame] | 1572 | DCHECK(content::RenderThread::Get()); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 1573 | if (is_swapped_out_) { |
| 1574 | // This widget is currently swapped out, and the active widget is in a |
| 1575 | // different process. Have the browser route the close request to the |
| 1576 | // active widget instead, so that the correct unload handlers are run. |
| 1577 | Send(new ViewHostMsg_RouteCloseEvent(routing_id_)); |
| 1578 | return; |
| 1579 | } |
| 1580 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1581 | // If a page calls window.close() twice, we'll end up here twice, but that's |
| 1582 | // OK. It is safe to send multiple Close messages. |
| 1583 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1584 | // Ask the RenderWidgetHost to initiate close. We could be called from deep |
| 1585 | // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
| 1586 | // could be closed before the JS finishes executing. So instead, post a |
| 1587 | // message back to the message loop, which won't run until the JS is |
| 1588 | // complete, and then the Close message can be sent. |
skyostil | ed8969c | 2015-07-20 16:57:08 | [diff] [blame] | 1589 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 1590 | FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1591 | } |
| 1592 | |
[email protected] | 9017d785 | 2013-11-21 17:47:35 | [diff] [blame] | 1593 | void RenderWidget::QueueSyntheticGesture( |
| 1594 | scoped_ptr<SyntheticGestureParams> gesture_params, |
| 1595 | const SyntheticGestureCompletionCallback& callback) { |
| 1596 | DCHECK(!callback.is_null()); |
| 1597 | |
| 1598 | pending_synthetic_gesture_callbacks_.push(callback); |
| 1599 | |
| 1600 | SyntheticGesturePacket gesture_packet; |
| 1601 | gesture_packet.set_gesture_params(gesture_params.Pass()); |
| 1602 | |
| 1603 | Send(new InputHostMsg_QueueSyntheticGesture(routing_id_, gesture_packet)); |
| 1604 | } |
| 1605 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1606 | void RenderWidget::Close() { |
[email protected] | 404630b | 2014-07-03 19:33:03 | [diff] [blame] | 1607 | screen_metrics_emulator_.reset(); |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1608 | WillCloseLayerTreeView(); |
| 1609 | compositor_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1610 | if (webwidget_) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1611 | webwidget_->close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1612 | webwidget_ = NULL; |
| 1613 | } |
| 1614 | } |
| 1615 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1616 | WebRect RenderWidget::windowRect() { |
| 1617 | if (pending_window_rect_count_) |
| 1618 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1619 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1620 | return view_screen_rect_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1621 | } |
| 1622 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1623 | void RenderWidget::setToolTipText(const blink::WebString& text, |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1624 | WebTextDirection hint) { |
[email protected] | 5a395b7 | 2011-08-08 19:13:54 | [diff] [blame] | 1625 | Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1626 | } |
| 1627 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1628 | void RenderWidget::setWindowRect(const WebRect& rect) { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1629 | WebRect window_rect = rect; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1630 | if (popup_origin_scale_for_emulation_) { |
| 1631 | float scale = popup_origin_scale_for_emulation_; |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1632 | window_rect.x = popup_screen_origin_for_emulation_.x() + |
| 1633 | (window_rect.x - popup_view_origin_for_emulation_.x()) * scale; |
| 1634 | window_rect.y = popup_screen_origin_for_emulation_.y() + |
| 1635 | (window_rect.y - popup_view_origin_for_emulation_.y()) * scale; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1636 | } |
| 1637 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 1638 | if (!resizing_mode_selector_->is_synchronous_mode()) { |
[email protected] | ec951b9d | 2013-10-20 06:21:20 | [diff] [blame] | 1639 | if (did_show_) { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1640 | Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); |
| 1641 | SetPendingWindowRect(window_rect); |
[email protected] | 8be1c58 | 2013-03-06 00:55:03 | [diff] [blame] | 1642 | } else { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1643 | initial_rect_ = window_rect; |
[email protected] | 8be1c58 | 2013-03-06 00:55:03 | [diff] [blame] | 1644 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1645 | } else { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1646 | SetWindowRectSynchronously(window_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1647 | } |
| 1648 | } |
| 1649 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1650 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 1651 | pending_window_rect_ = rect; |
| 1652 | pending_window_rect_count_++; |
| 1653 | } |
| 1654 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1655 | WebRect RenderWidget::rootWindowRect() { |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1656 | if (pending_window_rect_count_) { |
| 1657 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 1658 | // the RootWindowRect is probably going to return wrong results since the |
| 1659 | // browser may not have processed the Move yet. There isn't really anything |
| 1660 | // good to do in this case, and it shouldn't happen - since this size is |
| 1661 | // only really needed for windowToScreen, which is only used for Popups. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1662 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1663 | } |
| 1664 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1665 | return window_screen_rect_; |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 1666 | } |
| 1667 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1668 | WebRect RenderWidget::windowResizerRect() { |
| 1669 | return resizer_rect_; |
[email protected] | c04b636 | 2008-11-21 18:54:19 | [diff] [blame] | 1670 | } |
| 1671 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1672 | void RenderWidget::OnImeSetComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1673 | const base::string16& text, |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1674 | const std::vector<WebCompositionUnderline>& underlines, |
| 1675 | int selection_start, int selection_end) { |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1676 | if (!ShouldHandleImeEvent()) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1677 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1678 | ImeEventGuard guard(this); |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 1679 | if (!webwidget_->setComposition( |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1680 | text, WebVector<WebCompositionUnderline>(underlines), |
| 1681 | selection_start, selection_end)) { |
| 1682 | // If we failed to set the composition text, then we need to let the browser |
| 1683 | // process to cancel the input method's ongoing composition session, to make |
| 1684 | // sure we are in a consistent state. |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 1685 | Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame] | 1686 | } |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 1687 | UpdateCompositionInfo(true); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1688 | } |
| 1689 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1690 | void RenderWidget::OnImeConfirmComposition(const base::string16& text, |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 1691 | const gfx::Range& replacement_range, |
[email protected] | 0e45bd0 | 2013-07-12 20:20:02 | [diff] [blame] | 1692 | bool keep_selection) { |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1693 | if (!ShouldHandleImeEvent()) |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1694 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1695 | ImeEventGuard guard(this); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1696 | handling_input_event_ = true; |
[email protected] | 0e45bd0 | 2013-07-12 20:20:02 | [diff] [blame] | 1697 | if (text.length()) |
| 1698 | webwidget_->confirmComposition(text); |
| 1699 | else if (keep_selection) |
| 1700 | webwidget_->confirmComposition(WebWidget::KeepSelection); |
| 1701 | else |
| 1702 | webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1703 | handling_input_event_ = false; |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 1704 | UpdateCompositionInfo(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1705 | } |
| 1706 | |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 1707 | void RenderWidget::OnRepaint(gfx::Size size_to_paint) { |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1708 | // During shutdown we can just ignore this message. |
| 1709 | if (!webwidget_) |
| 1710 | return; |
| 1711 | |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 1712 | // Even if the browser provides an empty damage rect, it's still expecting to |
| 1713 | // receive a repaint ack so just damage the entire widget bounds. |
| 1714 | if (size_to_paint.IsEmpty()) { |
| 1715 | size_to_paint = size_; |
| 1716 | } |
| 1717 | |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1718 | set_next_paint_is_repaint_ack(); |
[email protected] | aca33f4f | 2014-05-17 17:08:05 | [diff] [blame] | 1719 | if (compositor_) |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 1720 | compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint)); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1721 | } |
| 1722 | |
[email protected] | 79fa22e | 2013-08-23 15:18:12 | [diff] [blame] | 1723 | void RenderWidget::OnSyntheticGestureCompleted() { |
[email protected] | 9017d785 | 2013-11-21 17:47:35 | [diff] [blame] | 1724 | DCHECK(!pending_synthetic_gesture_callbacks_.empty()); |
| 1725 | |
| 1726 | pending_synthetic_gesture_callbacks_.front().Run(); |
| 1727 | pending_synthetic_gesture_callbacks_.pop(); |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 1728 | } |
| 1729 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1730 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1731 | if (!webwidget_) |
| 1732 | return; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1733 | webwidget_->setTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1734 | } |
| 1735 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1736 | void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect, |
| 1737 | const gfx::Rect& window_screen_rect) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1738 | if (screen_metrics_emulator_) { |
| 1739 | screen_metrics_emulator_->OnUpdateScreenRectsMessage( |
| 1740 | view_screen_rect, window_screen_rect); |
| 1741 | } else { |
| 1742 | view_screen_rect_ = view_screen_rect; |
| 1743 | window_screen_rect_ = window_screen_rect; |
| 1744 | } |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1745 | Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id())); |
| 1746 | } |
| 1747 | |
kenrb | b4e2a3b | 2015-05-14 15:05:05 | [diff] [blame] | 1748 | void RenderWidget::OnSetSurfaceIdNamespace(uint32_t surface_id_namespace) { |
| 1749 | if (compositor_) |
| 1750 | compositor_->SetSurfaceIdNamespace(surface_id_namespace); |
| 1751 | } |
| 1752 | |
[email protected] | adb36231 | 2014-06-28 06:04:24 | [diff] [blame] | 1753 | void RenderWidget::showImeIfNeeded() { |
| 1754 | OnShowImeIfNeeded(); |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1755 | } |
| 1756 | |
[email protected] | adb36231 | 2014-06-28 06:04:24 | [diff] [blame] | 1757 | void RenderWidget::OnShowImeIfNeeded() { |
| 1758 | #if defined(OS_ANDROID) || defined(USE_AURA) |
| 1759 | UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
| 1760 | #endif |
rouslan | f7ebd883 | 2015-01-22 01:54:14 | [diff] [blame] | 1761 | |
| 1762 | // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
| 1763 | // virtual keyboard. |
| 1764 | #if !defined(OS_ANDROID) |
| 1765 | FocusChangeComplete(); |
| 1766 | #endif |
[email protected] | adb36231 | 2014-06-28 06:04:24 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | #if defined(OS_ANDROID) |
changwan | 3a84116 | 2015-08-11 02:53:37 | [diff] [blame] | 1770 | void RenderWidget::OnImeEventSentForAck(const blink::WebTextInputInfo& info) { |
| 1771 | text_input_info_history_.push_back(info); |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | void RenderWidget::OnImeEventAck() { |
changwan | 3a84116 | 2015-08-11 02:53:37 | [diff] [blame] | 1775 | DCHECK_GE(text_input_info_history_.size(), 1u); |
| 1776 | text_input_info_history_.pop_front(); |
[email protected] | 2384b6c | 2013-02-28 23:58:51 | [diff] [blame] | 1777 | } |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 1778 | #endif |
| 1779 | |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1780 | bool RenderWidget::ShouldHandleImeEvent() { |
| 1781 | #if defined(OS_ANDROID) |
changwan | 3a84116 | 2015-08-11 02:53:37 | [diff] [blame] | 1782 | if (!webwidget_) |
| 1783 | return false; |
| 1784 | |
| 1785 | // We cannot handle IME events if there is any chance that the event we are |
| 1786 | // receiving here from the browser is based on the state that is different |
| 1787 | // from our current one as indicated by |text_input_info_|. |
| 1788 | // The states the browser might be in are: |
| 1789 | // text_input_info_history_[0] - current state ack'd by browser |
| 1790 | // text_input_info_history_[1...N] - pending state changes |
| 1791 | for (size_t i = 0u; i < text_input_info_history_.size() - 1u; ++i) { |
| 1792 | if (text_input_info_history_[i] != text_input_info_) |
| 1793 | return false; |
| 1794 | } |
| 1795 | return true; |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 1796 | #else |
| 1797 | return !!webwidget_; |
| 1798 | #endif |
| 1799 | } |
| 1800 | |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 1801 | bool RenderWidget::SendAckForMouseMoveFromDebugger() { |
| 1802 | if (handling_event_type_ == WebInputEvent::MouseMove) { |
[email protected] | 5fea4a5 | 2014-05-27 00:17:52 | [diff] [blame] | 1803 | // If we pause multiple times during a single mouse move event, we should |
| 1804 | // only send ACK once. |
| 1805 | if (!ignore_ack_for_mouse_move_from_debugger_) { |
lanwei | f1a2283 | 2015-05-19 17:24:10 | [diff] [blame] | 1806 | InputEventAck ack(handling_event_type_, INPUT_EVENT_ACK_STATE_CONSUMED); |
[email protected] | 5fea4a5 | 2014-05-27 00:17:52 | [diff] [blame] | 1807 | Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack)); |
dgozman | b739185d | 2015-04-10 15:04:02 | [diff] [blame] | 1808 | return true; |
[email protected] | 5fea4a5 | 2014-05-27 00:17:52 | [diff] [blame] | 1809 | } |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 1810 | } |
| 1811 | return false; |
| 1812 | } |
| 1813 | |
| 1814 | void RenderWidget::IgnoreAckForMouseMoveFromDebugger() { |
| 1815 | ignore_ack_for_mouse_move_from_debugger_ = true; |
| 1816 | } |
| 1817 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 1818 | void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
| 1819 | if (device_scale_factor_ == device_scale_factor) |
| 1820 | return; |
| 1821 | |
| 1822 | device_scale_factor_ = device_scale_factor; |
jdduke | 491a3f0c | 2015-06-15 23:30:26 | [diff] [blame] | 1823 | ScheduleComposite(); |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 1824 | } |
| 1825 | |
[email protected] | 28ed6b3 | 2014-06-08 02:16:27 | [diff] [blame] | 1826 | bool RenderWidget::SetDeviceColorProfile( |
| 1827 | const std::vector<char>& color_profile) { |
| 1828 | if (device_color_profile_ == color_profile) |
| 1829 | return false; |
| 1830 | |
| 1831 | device_color_profile_ = color_profile; |
| 1832 | return true; |
| 1833 | } |
| 1834 | |
noel | db4df15 | 2014-09-16 17:45:20 | [diff] [blame] | 1835 | void RenderWidget::ResetDeviceColorProfileForTesting() { |
| 1836 | if (!device_color_profile_.empty()) |
| 1837 | device_color_profile_.clear(); |
| 1838 | device_color_profile_.push_back('0'); |
| 1839 | } |
| 1840 | |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 1841 | void RenderWidget::OnOrientationChange() { |
| 1842 | } |
| 1843 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1844 | gfx::Vector2d RenderWidget::GetScrollOffset() { |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 1845 | // Bare RenderWidgets don't support scroll offset. |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1846 | return gfx::Vector2d(); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 1847 | } |
| 1848 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1849 | void RenderWidget::SetHidden(bool hidden) { |
| 1850 | if (is_hidden_ == hidden) |
| 1851 | return; |
| 1852 | |
jdduke | 8fac9d10 | 2014-12-20 02:40:13 | [diff] [blame] | 1853 | // The status has changed. Tell the RenderThread about it and ensure |
| 1854 | // throttled acks are released in case frame production ceases. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1855 | is_hidden_ = hidden; |
jdduke | 8fac9d10 | 2014-12-20 02:40:13 | [diff] [blame] | 1856 | FlushPendingInputEventAck(); |
| 1857 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1858 | if (is_hidden_) |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 1859 | RenderThreadImpl::current()->WidgetHidden(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1860 | else |
[email protected] | b2db927 | 2014-01-10 17:42:00 | [diff] [blame] | 1861 | RenderThreadImpl::current()->WidgetRestored(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1862 | } |
| 1863 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1864 | void RenderWidget::DidToggleFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1865 | if (!webwidget_) |
| 1866 | return; |
| 1867 | |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 1868 | if (is_fullscreen_granted_) { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1869 | webwidget_->didEnterFullScreen(); |
| 1870 | } else { |
| 1871 | webwidget_->didExitFullScreen(); |
| 1872 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1873 | } |
| 1874 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1875 | bool RenderWidget::next_paint_is_resize_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1876 | return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1877 | } |
| 1878 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1879 | void RenderWidget::set_next_paint_is_resize_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1880 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1881 | } |
| 1882 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1883 | void RenderWidget::set_next_paint_is_repaint_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1884 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1885 | } |
| 1886 | |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 1887 | static bool IsDateTimeInput(ui::TextInputType type) { |
| 1888 | return type == ui::TEXT_INPUT_TYPE_DATE || |
| 1889 | type == ui::TEXT_INPUT_TYPE_DATE_TIME || |
| 1890 | type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || |
| 1891 | type == ui::TEXT_INPUT_TYPE_MONTH || |
| 1892 | type == ui::TEXT_INPUT_TYPE_TIME || |
| 1893 | type == ui::TEXT_INPUT_TYPE_WEEK; |
| 1894 | } |
| 1895 | |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1896 | |
| 1897 | void RenderWidget::StartHandlingImeEvent() { |
| 1898 | DCHECK(!handling_ime_event_); |
| 1899 | handling_ime_event_ = true; |
| 1900 | } |
| 1901 | |
| 1902 | void RenderWidget::FinishHandlingImeEvent() { |
| 1903 | DCHECK(handling_ime_event_); |
| 1904 | handling_ime_event_ = false; |
| 1905 | // While handling an ime event, text input state and selection bounds updates |
| 1906 | // are ignored. These must explicitly be updated once finished handling the |
| 1907 | // ime event. |
| 1908 | UpdateSelectionBounds(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 1909 | #if defined(OS_ANDROID) |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1910 | UpdateTextInputState(NO_SHOW_IME, FROM_IME); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 1911 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1912 | } |
| 1913 | |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1914 | void RenderWidget::UpdateTextInputState(ShowIme show_ime, |
| 1915 | ChangeSource change_source) { |
jdduke | 1aebad8e | 2015-07-22 23:25:08 | [diff] [blame] | 1916 | TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
[email protected] | e8f775f | 2013-02-14 21:00:50 | [diff] [blame] | 1917 | if (handling_ime_event_) |
| 1918 | return; |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1919 | ui::TextInputType new_type = GetTextInputType(); |
[email protected] | b18583c | 2012-12-18 06:55:27 | [diff] [blame] | 1920 | if (IsDateTimeInput(new_type)) |
| 1921 | return; // Not considered as a text input field in WebKit/Chromium. |
| 1922 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1923 | blink::WebTextInputInfo new_info; |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1924 | if (webwidget_) |
| 1925 | new_info = webwidget_->textInputInfo(); |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1926 | const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode); |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1927 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1928 | bool new_can_compose_inline = CanComposeInline(); |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1929 | |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1930 | // Only sends text input params if they are changed or if the ime should be |
| 1931 | // shown. |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1932 | if (show_ime == SHOW_IME_IF_NEEDED || |
| 1933 | (text_input_type_ != new_type || |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1934 | text_input_mode_ != new_mode || |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1935 | text_input_info_ != new_info || |
| 1936 | can_compose_inline_ != new_can_compose_inline) |
| 1937 | #if defined(OS_ANDROID) |
| 1938 | || text_field_is_dirty_ |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 1939 | #endif |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1940 | ) { |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1941 | ViewHostMsg_TextInputState_Params params; |
| 1942 | params.type = new_type; |
| 1943 | params.mode = new_mode; |
| 1944 | params.flags = new_info.flags; |
| 1945 | params.value = new_info.value.utf8(); |
| 1946 | params.selection_start = new_info.selectionStart; |
| 1947 | params.selection_end = new_info.selectionEnd; |
| 1948 | params.composition_start = new_info.compositionStart; |
| 1949 | params.composition_end = new_info.compositionEnd; |
| 1950 | params.can_compose_inline = new_can_compose_inline; |
| 1951 | params.show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED); |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1952 | #if defined(USE_AURA) |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1953 | params.is_non_ime_change = true; |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1954 | #endif |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 1955 | #if defined(OS_ANDROID) |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1956 | params.is_non_ime_change = (change_source == FROM_NON_IME) || |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1957 | text_field_is_dirty_; |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1958 | if (params.is_non_ime_change) |
changwan | 3a84116 | 2015-08-11 02:53:37 | [diff] [blame] | 1959 | OnImeEventSentForAck(new_info); |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 1960 | text_field_is_dirty_ = false; |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 1961 | #endif |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1962 | Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1963 | |
| 1964 | text_input_info_ = new_info; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1965 | text_input_type_ = new_type; |
shuchen | 913f8b62 | 2015-07-31 13:22:43 | [diff] [blame] | 1966 | text_input_mode_ = new_mode; |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1967 | can_compose_inline_ = new_can_compose_inline; |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 1968 | text_input_flags_ = new_info.flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1969 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1970 | } |
| 1971 | |
[email protected] | 7c8873e | 2013-02-05 08:03:01 | [diff] [blame] | 1972 | void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
| 1973 | WebRect focus_webrect; |
| 1974 | WebRect anchor_webrect; |
| 1975 | webwidget_->selectionBounds(focus_webrect, anchor_webrect); |
| 1976 | *focus = focus_webrect; |
| 1977 | *anchor = anchor_webrect; |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 1978 | } |
| 1979 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1980 | void RenderWidget::UpdateSelectionBounds() { |
jdduke | 1aebad8e | 2015-07-22 23:25:08 | [diff] [blame] | 1981 | TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1982 | if (!webwidget_) |
| 1983 | return; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1984 | if (handling_ime_event_) |
| 1985 | return; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1986 | |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 1987 | #if defined(USE_AURA) |
| 1988 | // TODO(mohsen): For now, always send explicit selection IPC notifications for |
| 1989 | // Aura beucause composited selection updates are not working for webview tags |
| 1990 | // which regresses IME inside webview. Remove this when composited selection |
| 1991 | // updates are fixed for webviews. See, http://crbug.com/510568. |
| 1992 | bool send_ipc = true; |
| 1993 | #else |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 1994 | // With composited selection updates, the selection bounds will be reported |
| 1995 | // directly by the compositor, in which case explicit IPC selection |
| 1996 | // notifications should be suppressed. |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 1997 | bool send_ipc = |
| 1998 | !blink::WebRuntimeFeatures::isCompositedSelectionUpdateEnabled(); |
| 1999 | #endif |
| 2000 | if (send_ipc) { |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2001 | ViewHostMsg_SelectionBounds_Params params; |
| 2002 | GetSelectionBounds(¶ms.anchor_rect, ¶ms.focus_rect); |
| 2003 | if (selection_anchor_rect_ != params.anchor_rect || |
| 2004 | selection_focus_rect_ != params.focus_rect) { |
| 2005 | selection_anchor_rect_ = params.anchor_rect; |
| 2006 | selection_focus_rect_ = params.focus_rect; |
| 2007 | webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir); |
| 2008 | params.is_anchor_first = webwidget_->isSelectionAnchorFirst(); |
| 2009 | Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
| 2010 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2011 | } |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2012 | |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2013 | UpdateCompositionInfo(false); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2014 | } |
| 2015 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2016 | // Check blink::WebTextInputType and ui::TextInputType is kept in sync. |
mostynb | e29b688 | 2015-01-13 09:59:17 | [diff] [blame] | 2017 | #define STATIC_ASSERT_WTIT_ENUM_MATCH(a, b) \ |
| 2018 | static_assert(int(blink::WebTextInputType##a) \ |
| 2019 | == int(ui::TEXT_INPUT_TYPE_##b), \ |
| 2020 | "mismatching enums: " #a) |
| 2021 | |
| 2022 | STATIC_ASSERT_WTIT_ENUM_MATCH(None, NONE); |
| 2023 | STATIC_ASSERT_WTIT_ENUM_MATCH(Text, TEXT); |
| 2024 | STATIC_ASSERT_WTIT_ENUM_MATCH(Password, PASSWORD); |
| 2025 | STATIC_ASSERT_WTIT_ENUM_MATCH(Search, SEARCH); |
| 2026 | STATIC_ASSERT_WTIT_ENUM_MATCH(Email, EMAIL); |
| 2027 | STATIC_ASSERT_WTIT_ENUM_MATCH(Number, NUMBER); |
| 2028 | STATIC_ASSERT_WTIT_ENUM_MATCH(Telephone, TELEPHONE); |
| 2029 | STATIC_ASSERT_WTIT_ENUM_MATCH(URL, URL); |
| 2030 | STATIC_ASSERT_WTIT_ENUM_MATCH(Date, DATE); |
| 2031 | STATIC_ASSERT_WTIT_ENUM_MATCH(DateTime, DATE_TIME); |
| 2032 | STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeLocal, DATE_TIME_LOCAL); |
| 2033 | STATIC_ASSERT_WTIT_ENUM_MATCH(Month, MONTH); |
| 2034 | STATIC_ASSERT_WTIT_ENUM_MATCH(Time, TIME); |
| 2035 | STATIC_ASSERT_WTIT_ENUM_MATCH(Week, WEEK); |
| 2036 | STATIC_ASSERT_WTIT_ENUM_MATCH(TextArea, TEXT_AREA); |
| 2037 | STATIC_ASSERT_WTIT_ENUM_MATCH(ContentEditable, CONTENT_EDITABLE); |
| 2038 | STATIC_ASSERT_WTIT_ENUM_MATCH(DateTimeField, DATE_TIME_FIELD); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2039 | |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 2040 | ui::TextInputType RenderWidget::WebKitToUiTextInputType( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2041 | blink::WebTextInputType type) { |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 2042 | // Check the type is in the range representable by ui::TextInputType. |
| 2043 | DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2044 | "blink::WebTextInputType and ui::TextInputType not synchronized"; |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 2045 | return static_cast<ui::TextInputType>(type); |
| 2046 | } |
| 2047 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2048 | ui::TextInputType RenderWidget::GetTextInputType() { |
[email protected] | 8969bb3f | 2012-11-30 21:49:27 | [diff] [blame] | 2049 | if (webwidget_) |
| 2050 | return WebKitToUiTextInputType(webwidget_->textInputInfo().type); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2051 | return ui::TEXT_INPUT_TYPE_NONE; |
| 2052 | } |
| 2053 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2054 | void RenderWidget::UpdateCompositionInfo(bool should_update_range) { |
yukawa | 5f21c6a | 2014-10-27 17:09:30 | [diff] [blame] | 2055 | #if defined(OS_ANDROID) |
yukawa | 6f899b2 | 2014-12-15 18:56:11 | [diff] [blame] | 2056 | // TODO(yukawa): Start sending character bounds when the browser side |
| 2057 | // implementation becomes ready (crbug.com/424866). |
| 2058 | #else |
jdduke | 1aebad8e | 2015-07-22 23:25:08 | [diff] [blame] | 2059 | TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2060 | gfx::Range range = gfx::Range(); |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2061 | if (should_update_range) { |
| 2062 | GetCompositionRange(&range); |
| 2063 | } else { |
| 2064 | range = composition_range_; |
| 2065 | } |
| 2066 | std::vector<gfx::Rect> character_bounds; |
| 2067 | GetCompositionCharacterBounds(&character_bounds); |
| 2068 | |
| 2069 | if (!ShouldUpdateCompositionInfo(range, character_bounds)) |
| 2070 | return; |
| 2071 | composition_character_bounds_ = character_bounds; |
| 2072 | composition_range_ = range; |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 2073 | Send(new InputHostMsg_ImeCompositionRangeChanged( |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2074 | routing_id(), composition_range_, composition_character_bounds_)); |
yukawa | 6f899b2 | 2014-12-15 18:56:11 | [diff] [blame] | 2075 | #endif |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2076 | } |
| 2077 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2078 | void RenderWidget::GetCompositionCharacterBounds( |
| 2079 | std::vector<gfx::Rect>* bounds) { |
| 2080 | DCHECK(bounds); |
| 2081 | bounds->clear(); |
| 2082 | } |
| 2083 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2084 | void RenderWidget::GetCompositionRange(gfx::Range* range) { |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2085 | size_t location, length; |
| 2086 | if (webwidget_->compositionRange(&location, &length)) { |
| 2087 | range->set_start(location); |
| 2088 | range->set_end(location + length); |
| 2089 | } else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 2090 | range->set_start(location); |
| 2091 | range->set_end(location + length); |
| 2092 | } else { |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2093 | *range = gfx::Range::InvalidRange(); |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2097 | bool RenderWidget::ShouldUpdateCompositionInfo( |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2098 | const gfx::Range& range, |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2099 | const std::vector<gfx::Rect>& bounds) { |
| 2100 | if (composition_range_ != range) |
| 2101 | return true; |
| 2102 | if (bounds.size() != composition_character_bounds_.size()) |
| 2103 | return true; |
| 2104 | for (size_t i = 0; i < bounds.size(); ++i) { |
| 2105 | if (bounds[i] != composition_character_bounds_[i]) |
| 2106 | return true; |
| 2107 | } |
| 2108 | return false; |
| 2109 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2110 | |
[email protected] | a4f0d88 | 2014-05-01 23:48:10 | [diff] [blame] | 2111 | #if defined(OS_ANDROID) |
timav | 7a5032e | 2014-12-05 01:59:43 | [diff] [blame] | 2112 | bool RenderWidget::DoesRecordFullLayer() const { |
boliu | 15ca265 | 2015-09-04 23:33:40 | [diff] [blame] | 2113 | return false; |
timav | 7a5032e | 2014-12-05 01:59:43 | [diff] [blame] | 2114 | } |
[email protected] | a4f0d88 | 2014-05-01 23:48:10 | [diff] [blame] | 2115 | #endif |
| 2116 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2117 | bool RenderWidget::CanComposeInline() { |
| 2118 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 2119 | } |
| 2120 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2121 | WebScreenInfo RenderWidget::screenInfo() { |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 2122 | return screen_info_; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2123 | } |
| 2124 | |
[email protected] | f660d9c | 2012-06-06 18:31:21 | [diff] [blame] | 2125 | float RenderWidget::deviceScaleFactor() { |
| 2126 | return device_scale_factor_; |
| 2127 | } |
| 2128 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 2129 | void RenderWidget::resetInputMethod() { |
[email protected] | 0e45bd0 | 2013-07-12 20:20:02 | [diff] [blame] | 2130 | ImeEventGuard guard(this); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 2131 | // If the last text input type is not None, then we should finish any |
| 2132 | // ongoing composition regardless of the new text input type. |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2133 | if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 2134 | // If a composition text exists, then we need to let the browser process |
| 2135 | // to cancel the input method's ongoing composition session. |
| 2136 | if (webwidget_->confirmComposition()) |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 2137 | Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 2138 | } |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 2139 | |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2140 | UpdateCompositionInfo(true); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 2141 | } |
| 2142 | |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 2143 | #if defined(OS_ANDROID) |
| 2144 | void RenderWidget::showUnhandledTapUIIfNeeded( |
| 2145 | const WebPoint& tapped_position, |
| 2146 | const WebNode& tapped_node, |
| 2147 | bool page_changed) { |
| 2148 | DCHECK(handling_input_event_); |
| 2149 | bool should_trigger = !page_changed && tapped_node.isTextNode() && |
donnd | 57e54f5 | 2015-02-26 19:03:37 | [diff] [blame] | 2150 | !tapped_node.isContentEditable() && |
| 2151 | !tapped_node.isInsideFocusableElementOrARIAWidget(); |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 2152 | if (should_trigger) { |
| 2153 | Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_, |
| 2154 | tapped_position.x, tapped_position.y)); |
| 2155 | } |
| 2156 | } |
| 2157 | #endif |
| 2158 | |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2159 | void RenderWidget::didHandleGestureEvent( |
| 2160 | const WebGestureEvent& event, |
| 2161 | bool event_cancelled) { |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 2162 | #if defined(OS_ANDROID) || defined(USE_AURA) |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2163 | if (event_cancelled) |
| 2164 | return; |
[email protected] | 07c70d2 | 2014-08-21 08:33:46 | [diff] [blame] | 2165 | if (event.type == WebInputEvent::GestureTap) { |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 2166 | UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
[email protected] | 07c70d2 | 2014-08-21 08:33:46 | [diff] [blame] | 2167 | } else if (event.type == WebInputEvent::GestureLongPress) { |
| 2168 | DCHECK(webwidget_); |
| 2169 | if (webwidget_->textInputInfo().value.isEmpty()) |
| 2170 | UpdateTextInputState(NO_SHOW_IME, FROM_NON_IME); |
| 2171 | else |
| 2172 | UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2173 | } |
| 2174 | #endif |
| 2175 | } |
| 2176 | |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2177 | void RenderWidget::didOverscroll( |
| 2178 | const blink::WebFloatSize& unusedDelta, |
| 2179 | const blink::WebFloatSize& accumulatedRootOverScroll, |
| 2180 | const blink::WebFloatPoint& position, |
| 2181 | const blink::WebFloatSize& velocity) { |
| 2182 | DidOverscrollParams params; |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2183 | params.accumulated_overscroll = gfx::Vector2dF( |
| 2184 | accumulatedRootOverScroll.width, accumulatedRootOverScroll.height); |
| 2185 | params.latest_overscroll_delta = |
| 2186 | gfx::Vector2dF(unusedDelta.width, unusedDelta.height); |
sataya.m | a5cc13a | 2015-06-13 11:06:02 | [diff] [blame] | 2187 | // TODO(sataya.m): don't negate velocity once http://crbug.com/499743 is |
| 2188 | // fixed. |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2189 | params.current_fling_velocity = |
sataya.m | a5cc13a | 2015-06-13 11:06:02 | [diff] [blame] | 2190 | gfx::Vector2dF(-velocity.width, -velocity.height); |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2191 | params.causal_event_viewport_point = gfx::PointF(position.x, position.y); |
jdduke | c05612b | 2015-06-25 23:13:18 | [diff] [blame] | 2192 | |
| 2193 | // If we're currently handling an event, stash the overscroll data such that |
| 2194 | // it can be bundled in the event ack. |
| 2195 | if (handling_event_overscroll_) { |
| 2196 | handling_event_overscroll_->reset(new DidOverscrollParams(params)); |
| 2197 | return; |
| 2198 | } |
| 2199 | |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2200 | Send(new InputHostMsg_DidOverscroll(routing_id_, params)); |
| 2201 | } |
| 2202 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 2203 | void RenderWidget::StartCompositor() { |
| 2204 | // For widgets that are never visible, we don't need the compositor to run |
| 2205 | // at all. |
| 2206 | if (never_visible_) |
| 2207 | return; |
danakj | 6e3bf801 | 2014-12-16 18:27:53 | [diff] [blame] | 2208 | // In tests without a RenderThreadImpl, don't set ready as this kicks |
| 2209 | // off creating output surfaces that the test can't create. |
| 2210 | if (!RenderThreadImpl::current()) |
| 2211 | return; |
danakj | 018271e3 | 2014-12-16 21:17:26 | [diff] [blame] | 2212 | compositor_->StartCompositor(); |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 2213 | } |
| 2214 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 2215 | void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2216 | size_t i = 0; |
| 2217 | for (; i < plugin_window_moves_.size(); ++i) { |
| 2218 | if (plugin_window_moves_[i].window == move.window) { |
[email protected] | 16f89d0 | 2009-08-26 17:17:58 | [diff] [blame] | 2219 | if (move.rects_valid) { |
| 2220 | plugin_window_moves_[i] = move; |
| 2221 | } else { |
| 2222 | plugin_window_moves_[i].visible = move.visible; |
| 2223 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2224 | break; |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | if (i == plugin_window_moves_.size()) |
| 2229 | plugin_window_moves_.push_back(move); |
| 2230 | } |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame] | 2231 | |
| 2232 | void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 2233 | for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 2234 | i != plugin_window_moves_.end(); ++i) { |
| 2235 | if (i->window == window) { |
| 2236 | plugin_window_moves_.erase(i); |
| 2237 | break; |
| 2238 | } |
| 2239 | } |
| 2240 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 2241 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 2242 | |
[email protected] | 24ed043 | 2013-04-24 07:50:31 | [diff] [blame] | 2243 | RenderWidgetCompositor* RenderWidget::compositor() const { |
| 2244 | return compositor_.get(); |
| 2245 | } |
| 2246 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2247 | bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 2248 | return false; |
| 2249 | } |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 2250 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2251 | bool RenderWidget::WillHandleGestureEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2252 | const blink::WebGestureEvent& event) { |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 2253 | return false; |
| 2254 | } |
| 2255 | |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 2256 | void RenderWidget::ObserveWheelEventAndResult( |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 2257 | const blink::WebMouseWheelEvent& wheel_event, |
sataya.m | f405d0e | 2015-07-07 16:51:11 | [diff] [blame] | 2258 | const gfx::Vector2dF& wheel_unused_delta, |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 2259 | bool event_processed) { |
ccameron | a764475 | 2014-12-30 01:16:31 | [diff] [blame] | 2260 | if (!compositor_deps_->IsElasticOverscrollEnabled()) |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 2261 | return; |
| 2262 | |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 2263 | cc::InputHandlerScrollResult scroll_result; |
sataya.m | f405d0e | 2015-07-07 16:51:11 | [diff] [blame] | 2264 | scroll_result.did_scroll = event_processed; |
| 2265 | scroll_result.did_overscroll_root = !wheel_unused_delta.IsZero(); |
| 2266 | scroll_result.unused_scroll_delta = wheel_unused_delta; |
ccameron | d4ba4790 | 2014-12-17 07:20:31 | [diff] [blame] | 2267 | |
| 2268 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 2269 | InputHandlerManager* input_handler_manager = |
| 2270 | render_thread ? render_thread->input_handler_manager() : NULL; |
| 2271 | if (input_handler_manager) { |
| 2272 | input_handler_manager->ObserveWheelEventAndResultOnMainThread( |
| 2273 | routing_id_, wheel_event, scroll_result); |
| 2274 | } |
| 2275 | } |
| 2276 | |
[email protected] | ce6689f | 2013-03-29 12:52:55 | [diff] [blame] | 2277 | void RenderWidget::hasTouchEventHandlers(bool has_handlers) { |
| 2278 | Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| 2279 | } |
| 2280 | |
mostynb | e29b688 | 2015-01-13 09:59:17 | [diff] [blame] | 2281 | // Check blink::WebTouchAction and blink::WebTouchActionAuto is kept in sync |
| 2282 | #define STATIC_ASSERT_WTI_ENUM_MATCH(a, b) \ |
| 2283 | static_assert(int(blink::WebTouchAction##a) == int(TOUCH_ACTION_##b), \ |
| 2284 | "mismatching enums: " #a) |
| 2285 | |
dtapuska | a98ac8d7 | 2015-05-08 19:29:09 | [diff] [blame] | 2286 | inline content::TouchAction& operator|=(content::TouchAction& a, |
| 2287 | content::TouchAction b) { |
| 2288 | a = static_cast<content::TouchAction>(static_cast<int>(a) | |
| 2289 | static_cast<int>(b)); |
| 2290 | return a; |
| 2291 | } |
| 2292 | |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2293 | void RenderWidget::setTouchAction( |
| 2294 | blink::WebTouchAction web_touch_action) { |
| 2295 | |
| 2296 | // Ignore setTouchAction calls that result from synthetic touch events (eg. |
| 2297 | // when blink is emulating touch with mouse). |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 2298 | if (handling_event_type_ != WebInputEvent::TouchStart) |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2299 | return; |
| 2300 | |
dtapuska | a98ac8d7 | 2015-05-08 19:29:09 | [diff] [blame] | 2301 | // Verify the same values are used by the types so we can cast between them. |
mostynb | e29b688 | 2015-01-13 09:59:17 | [diff] [blame] | 2302 | STATIC_ASSERT_WTI_ENUM_MATCH(Auto, AUTO); |
| 2303 | STATIC_ASSERT_WTI_ENUM_MATCH(None, NONE); |
dtapuska | a98ac8d7 | 2015-05-08 19:29:09 | [diff] [blame] | 2304 | STATIC_ASSERT_WTI_ENUM_MATCH(PanLeft, PAN_LEFT); |
| 2305 | STATIC_ASSERT_WTI_ENUM_MATCH(PanRight, PAN_RIGHT); |
mostynb | e29b688 | 2015-01-13 09:59:17 | [diff] [blame] | 2306 | STATIC_ASSERT_WTI_ENUM_MATCH(PanX, PAN_X); |
dtapuska | a98ac8d7 | 2015-05-08 19:29:09 | [diff] [blame] | 2307 | STATIC_ASSERT_WTI_ENUM_MATCH(PanUp, PAN_UP); |
| 2308 | STATIC_ASSERT_WTI_ENUM_MATCH(PanDown, PAN_DOWN); |
mostynb | e29b688 | 2015-01-13 09:59:17 | [diff] [blame] | 2309 | STATIC_ASSERT_WTI_ENUM_MATCH(PanY, PAN_Y); |
| 2310 | STATIC_ASSERT_WTI_ENUM_MATCH(PinchZoom, PINCH_ZOOM); |
[email protected] | a18f67a | 2013-12-20 19:44:36 | [diff] [blame] | 2311 | |
| 2312 | content::TouchAction content_touch_action = |
| 2313 | static_cast<content::TouchAction>(web_touch_action); |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2314 | Send(new InputHostMsg_SetTouchAction(routing_id_, content_touch_action)); |
| 2315 | } |
| 2316 | |
[email protected] | 90f2415 | 2014-04-09 12:41:36 | [diff] [blame] | 2317 | void RenderWidget::didUpdateTextOfFocusedElementByNonUserInput() { |
| 2318 | #if defined(OS_ANDROID) |
| 2319 | text_field_is_dirty_ = true; |
| 2320 | #endif |
| 2321 | } |
| 2322 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 2323 | bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 2324 | return true; |
| 2325 | } |
| 2326 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 2327 | scoped_ptr<WebGraphicsContext3DCommandBufferImpl> |
jbauman | 5e420d3 | 2015-08-05 09:33:01 | [diff] [blame] | 2328 | RenderWidget::CreateGraphicsContext3D(bool compositor) { |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 2329 | if (!webwidget_) |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 2330 | return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 2331 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | ebc0e1df | 2013-08-01 02:46:22 | [diff] [blame] | 2332 | switches::kDisableGpuCompositing)) |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 2333 | return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2334 | if (!RenderThreadImpl::current()) |
| 2335 | return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 2336 | CauseForGpuLaunch cause = |
| 2337 | CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2338 | scoped_refptr<GpuChannelHost> gpu_channel_host( |
[email protected] | 4d7e46a | 2013-11-08 05:33:40 | [diff] [blame] | 2339 | RenderThreadImpl::current()->EstablishGpuChannelSync(cause)); |
dcheng | 58867a9 | 2014-08-26 02:50:22 | [diff] [blame] | 2340 | if (!gpu_channel_host.get()) |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2341 | return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 2342 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2343 | // Explicitly disable antialiasing for the compositor. As of the time of |
| 2344 | // this writing, the only platform that supported antialiasing for the |
| 2345 | // compositor was Mac OS X, because the on-screen OpenGL context creation |
| 2346 | // code paths on Windows and Linux didn't yet have multisampling support. |
| 2347 | // Mac OS X essentially always behaves as though it's rendering offscreen. |
| 2348 | // Multisampling has a heavy cost especially on devices with relatively low |
| 2349 | // fill rate like most notebooks, and the Mac implementation would need to |
| 2350 | // be optimized to resolve directly into the IOSurface shared between the |
| 2351 | // GPU and browser processes. For these reasons and to avoid platform |
| 2352 | // disparities we explicitly disable antialiasing. |
| 2353 | blink::WebGraphicsContext3D::Attributes attributes; |
| 2354 | attributes.antialias = false; |
| 2355 | attributes.shareResources = true; |
| 2356 | attributes.noAutomaticFlushes = true; |
| 2357 | attributes.depth = false; |
| 2358 | attributes.stencil = false; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2359 | bool lose_context_when_out_of_memory = true; |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2360 | WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits limits; |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 2361 | #if defined(OS_ANDROID) |
| 2362 | // If we raster too fast we become upload bound, and pending |
| 2363 | // uploads consume memory. For maximum upload throughput, we would |
| 2364 | // want to allow for upload_throughput * pipeline_time of pending |
| 2365 | // uploads, after which we are just wasting memory. Since we don't |
| 2366 | // know our upload throughput yet, this just caps our memory usage. |
| 2367 | size_t divider = 1; |
[email protected] | 35b4f0c | 2014-06-26 16:55:27 | [diff] [blame] | 2368 | if (base::SysInfo::IsLowEndDevice()) |
[email protected] | 657be32 | 2013-09-20 08:50:03 | [diff] [blame] | 2369 | divider = 6; |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 2370 | // For reference Nexus10 can upload 1MB in about 2.5ms. |
[email protected] | 657be32 | 2013-09-20 08:50:03 | [diff] [blame] | 2371 | const double max_mb_uploaded_per_ms = 2.0 / (5 * divider); |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 2372 | // Deadline to draw a frame to achieve 60 frames per second. |
| 2373 | const size_t kMillisecondsPerFrame = 16; |
| 2374 | // Assuming a two frame deep pipeline between the CPU and the GPU. |
[email protected] | 657be32 | 2013-09-20 08:50:03 | [diff] [blame] | 2375 | size_t max_transfer_buffer_usage_mb = |
| 2376 | static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms); |
| 2377 | static const size_t kBytesPerMegabyte = 1024 * 1024; |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 2378 | // We keep the MappedMemoryReclaimLimit the same as the upload limit |
| 2379 | // to avoid unnecessarily stalling the compositor thread. |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2380 | limits.mapped_memory_reclaim_limit = |
[email protected] | 657be32 | 2013-09-20 08:50:03 | [diff] [blame] | 2381 | max_transfer_buffer_usage_mb * kBytesPerMegabyte; |
[email protected] | b6eb8e33 | 2013-09-10 00:51:01 | [diff] [blame] | 2382 | #endif |
jbauman | 00ca2dc | 2015-08-10 23:21:15 | [diff] [blame] | 2383 | if (compositor) { |
jbauman | 5e420d3 | 2015-08-05 09:33:01 | [diff] [blame] | 2384 | limits.command_buffer_size = 64 * 1024; |
jbauman | 00ca2dc | 2015-08-10 23:21:15 | [diff] [blame] | 2385 | limits.start_transfer_buffer_size = 64 * 1024; |
| 2386 | limits.min_transfer_buffer_size = 64 * 1024; |
| 2387 | } |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2388 | |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame^] | 2389 | // TODO(piman): we still need to create a View command buffer until |
| 2390 | // crbug.com/526196 is fixed. The surface_id doesn't matter, it just needs to |
| 2391 | // be !0. |
| 2392 | const int32 kDummySurfaceId = 1; |
[email protected] | 96ab016c | 2013-10-23 00:50:29 | [diff] [blame] | 2393 | scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame^] | 2394 | new WebGraphicsContext3DCommandBufferImpl( |
| 2395 | kDummySurfaceId, GetURLForGraphicsContext3D(), |
| 2396 | gpu_channel_host.get(), attributes, lose_context_when_out_of_memory, |
| 2397 | limits, NULL)); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 2398 | return context.Pass(); |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 2399 | } |
| 2400 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 2401 | void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2402 | render_frame_proxies_.AddObserver(proxy); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 2403 | } |
| 2404 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 2405 | void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2406 | render_frame_proxies_.RemoveObserver(proxy); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 2407 | } |
| 2408 | |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 2409 | void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { |
| 2410 | render_frames_.AddObserver(frame); |
| 2411 | } |
| 2412 | |
| 2413 | void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { |
| 2414 | render_frames_.RemoveObserver(frame); |
| 2415 | } |
| 2416 | |
[email protected] | a017938b | 2014-05-27 21:17:17 | [diff] [blame] | 2417 | #if defined(VIDEO_HOLE) |
| 2418 | void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2419 | video_hole_frames_.AddObserver(frame); |
| 2420 | } |
| 2421 | |
| 2422 | void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2423 | video_hole_frames_.RemoveObserver(frame); |
| 2424 | } |
| 2425 | #endif // defined(VIDEO_HOLE) |
| 2426 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2427 | } // namespace content |