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