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