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