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