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