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