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