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