[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" |
fdoray | a19b770 | 2016-12-23 14:19:31 | [diff] [blame] | 23 | #include "base/threading/thread_task_runner_handle.h" |
primiano | 9e38d55 | 2015-01-28 04:18:01 | [diff] [blame] | 24 | #include "base/trace_event/trace_event.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 25 | #include "build/build_config.h" |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 26 | #include "cc/animation/animation_host.h" |
xidachen | fa0199e7 | 2017-05-11 11:34:26 | [diff] [blame] | 27 | #include "cc/input/touch_action.h" |
danakj | ba65a091 | 2017-09-21 16:38:42 | [diff] [blame] | 28 | #include "cc/trees/layer_tree_frame_sink.h" |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 29 | #include "cc/trees/layer_tree_host.h" |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 30 | #include "components/viz/common/frame_sinks/begin_frame_source.h" |
danakj | f20f450 | 2017-09-26 17:13:31 | [diff] [blame] | 31 | #include "components/viz/common/frame_sinks/copy_output_request.h" |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 32 | #include "content/common/drag_event_source_info.h" |
| 33 | #include "content/common/drag_messages.h" |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 34 | #include "content/common/input_messages.h" |
jonross | a2ff4f8 | 2018-02-16 17:27:46 | [diff] [blame] | 35 | #include "content/common/render_frame_metadata.mojom.h" |
jcivelli | ae1560a | 2016-11-01 22:40:23 | [diff] [blame] | 36 | #include "content/common/render_message_filter.mojom.h" |
Nasko Oskov | f97e8b0 | 2017-07-25 02:45:42 | [diff] [blame] | 37 | #include "content/common/swapped_out_messages.h" |
ekaramad | 9053e57b | 2016-04-26 20:00:38 | [diff] [blame] | 38 | #include "content/common/text_input_state.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 39 | #include "content/common/view_messages.h" |
mlamouri | afca06dd | 2017-01-27 23:35:18 | [diff] [blame] | 40 | #include "content/public/common/content_client.h" |
changwan | 7ded375 | 2016-03-09 23:25:12 | [diff] [blame] | 41 | #include "content/public/common/content_features.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 42 | #include "content/public/common/content_switches.h" |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 43 | #include "content/public/common/context_menu_params.h" |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 44 | #include "content/public/common/drop_data.h" |
Khushal | 3e96e66 | 2017-10-30 23:16:50 | [diff] [blame] | 45 | #include "content/public/common/service_names.mojom.h" |
Jaebaek Seo | 655110e | 2017-12-19 23:27:39 | [diff] [blame] | 46 | #include "content/public/common/use_zoom_for_dsf_policy.h" |
mlamouri | afca06dd | 2017-01-27 23:35:18 | [diff] [blame] | 47 | #include "content/public/renderer/content_renderer_client.h" |
Saman Sami | d189e5dfd | 2017-12-20 22:55:31 | [diff] [blame] | 48 | #include "content/renderer/browser_plugin/browser_plugin.h" |
[email protected] | 953bd006 | 2013-08-01 00:58:40 | [diff] [blame] | 49 | #include "content/renderer/cursor_utils.h" |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 50 | #include "content/renderer/devtools/render_widget_screen_metrics_emulator.h" |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 51 | #include "content/renderer/drop_data_builder.h" |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 52 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 53 | #include "content/renderer/gpu/frame_swap_message_queue.h" |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 54 | #include "content/renderer/gpu/queue_message_swap_promise.h" |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 55 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 56 | #include "content/renderer/ime_event_guard.h" |
[email protected] | 7a72d45 | 2013-12-13 10:01:13 | [diff] [blame] | 57 | #include "content/renderer/input/input_handler_manager.h" |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 58 | #include "content/renderer/input/main_thread_event_queue.h" |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 59 | #include "content/renderer/input/widget_input_handler_manager.h" |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 60 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 61 | #include "content/renderer/render_frame_impl.h" |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 62 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 63 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 64 | #include "content/renderer/render_thread_impl.h" |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 65 | #include "content/renderer/render_view_impl.h" |
avi | 40b5be7a | 2016-03-03 21:13:44 | [diff] [blame] | 66 | #include "content/renderer/render_widget_owner_delegate.h" |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 67 | #include "content/renderer/renderer_blink_platform_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 68 | #include "content/renderer/resizing_mode_selector.h" |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 69 | #include "ipc/ipc_message_start.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 70 | #include "ipc/ipc_sync_message.h" |
Antoine Labour | e55c9ef8 | 2017-11-10 18:51:23 | [diff] [blame] | 71 | #include "ipc/ipc_sync_message_filter.h" |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 72 | #include "ppapi/features/features.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 73 | #include "skia/ext/platform_canvas.h" |
kinuko | a429302 | 2017-01-27 06:43:25 | [diff] [blame] | 74 | #include "third_party/WebKit/public/platform/FilePathConversion.h" |
[email protected] | ec173b52 | 2013-11-14 11:01:18 | [diff] [blame] | 75 | #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 76 | #include "third_party/WebKit/public/platform/WebDragData.h" |
| 77 | #include "third_party/WebKit/public/platform/WebDragOperation.h" |
dtapuska | a794bd081 | 2017-01-06 15:22:55 | [diff] [blame] | 78 | #include "third_party/WebKit/public/platform/WebMouseEvent.h" |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 79 | #include "third_party/WebKit/public/platform/WebPoint.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 80 | #include "third_party/WebKit/public/platform/WebRect.h" |
nverne | 61d2da87 | 2017-05-24 10:15:30 | [diff] [blame] | 81 | #include "third_party/WebKit/public/platform/WebRuntimeFeatures.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 82 | #include "third_party/WebKit/public/platform/WebSize.h" |
| 83 | #include "third_party/WebKit/public/platform/WebString.h" |
skyostil | 529caa29 | 2016-08-10 17:44:51 | [diff] [blame] | 84 | #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_scheduling_state.h" |
| 85 | #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h" |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 86 | #include "third_party/WebKit/public/web/WebAutofillClient.h" |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 87 | #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 88 | #include "third_party/WebKit/public/web/WebFrameWidget.h" |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 89 | #include "third_party/WebKit/public/web/WebInputMethodController.h" |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 90 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 91 | #include "third_party/WebKit/public/web/WebNode.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 92 | #include "third_party/WebKit/public/web/WebPagePopup.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 93 | #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" |
| 94 | #include "third_party/WebKit/public/web/WebRange.h" |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 95 | #include "third_party/WebKit/public/web/WebSettings.h" |
Donn Denman | 3c1267c6 | 2018-03-08 22:08:59 | [diff] [blame] | 96 | #include "third_party/WebKit/public/web/WebTappedInfo.h" |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 97 | #include "third_party/WebKit/public/web/WebView.h" |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 98 | #include "third_party/WebKit/public/web/WebWidget.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 99 | #include "third_party/skia/include/core/SkShader.h" |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 100 | #include "ui/base/clipboard/clipboard.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 101 | #include "ui/base/ui_base_features.h" |
dtapuska | 97286c88 | 2017-02-24 23:14:43 | [diff] [blame] | 102 | #include "ui/events/base_event_utils.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 103 | #include "ui/gfx/geometry/point_conversions.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 104 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 105 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 1835b9e | 2012-02-28 13:12:48 | [diff] [blame] | 106 | #include "ui/gfx/skia_util.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 107 | #include "ui/gl/gl_switches.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 108 | #include "ui/surface/transport_dib.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 109 | |
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 110 | #if defined(OS_ANDROID) |
[email protected] | cefe9b15 | 2014-03-27 18:16:15 | [diff] [blame] | 111 | #include <android/keycodes.h> |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 112 | #include "base/time/time.h" |
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 113 | #endif |
| 114 | |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 115 | #if defined(OS_POSIX) |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 116 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 117 | #include "third_party/skia/include/core/SkPixelRef.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 118 | #endif // defined(OS_POSIX) |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 119 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 120 | #if defined(USE_AURA) |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 121 | #include "content/renderer/mus/renderer_window_tree_client.h" |
penghuang | 28a5fa2 | 2015-12-02 17:58:19 | [diff] [blame] | 122 | #endif |
| 123 | |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 124 | #if defined(OS_MACOSX) |
| 125 | #include "content/renderer/text_input_client_observer.h" |
| 126 | #endif |
| 127 | |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 128 | using blink::WebImeTextSpan; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 129 | using blink::WebCursorInfo; |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 130 | using blink::WebDeviceEmulationParams; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 131 | using blink::WebDragOperation; |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 132 | using blink::WebDragOperationsMask; |
| 133 | using blink::WebDragData; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 134 | using blink::WebFrameWidget; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 135 | using blink::WebGestureEvent; |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 136 | using blink::WebImage; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 137 | using blink::WebInputEvent; |
dtapuska | 5d2e9c3 | 2015-12-03 16:39:49 | [diff] [blame] | 138 | using blink::WebInputEventResult; |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 139 | using blink::WebInputMethodController; |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 140 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 141 | using blink::WebMouseEvent; |
| 142 | using blink::WebMouseWheelEvent; |
| 143 | using blink::WebNavigationPolicy; |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 144 | using blink::WebNode; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 145 | using blink::WebPagePopup; |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 146 | using blink::WebPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 147 | using blink::WebPopupType; |
dglazkov | e353a37 | 2016-09-01 01:33:48 | [diff] [blame] | 148 | using blink::WebRange; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 149 | using blink::WebRect; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 150 | using blink::WebSize; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 151 | using blink::WebString; |
Donn Denman | 3c1267c6 | 2018-03-08 22:08:59 | [diff] [blame] | 152 | using blink::WebTappedInfo; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 153 | using blink::WebTextDirection; |
| 154 | using blink::WebTouchEvent; |
[email protected] | f8ed472 | 2013-12-03 03:27:25 | [diff] [blame] | 155 | using blink::WebTouchPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 156 | using blink::WebVector; |
| 157 | using blink::WebWidget; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 158 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 159 | namespace content { |
| 160 | |
[email protected] | 6a4d7f6 | 2013-01-07 21:32:13 | [diff] [blame] | 161 | namespace { |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 162 | |
| 163 | typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; |
| 164 | |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 165 | static const int kInvalidNextPreviousFlagsValue = -1; |
| 166 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 167 | class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget { |
| 168 | public: |
| 169 | explicit WebWidgetLockTarget(blink::WebWidget* webwidget) |
| 170 | : webwidget_(webwidget) {} |
| 171 | |
| 172 | void OnLockMouseACK(bool succeeded) override { |
| 173 | if (succeeded) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 174 | webwidget_->DidAcquirePointerLock(); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 175 | else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 176 | webwidget_->DidNotAcquirePointerLock(); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 177 | } |
| 178 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 179 | void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); } |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 180 | |
| 181 | bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { |
| 182 | // The WebWidget handles mouse lock in Blink's handleInputEvent(). |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | private: |
| 187 | blink::WebWidget* webwidget_; |
| 188 | }; |
| 189 | |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 190 | bool IsDateTimeInput(ui::TextInputType type) { |
| 191 | return type == ui::TEXT_INPUT_TYPE_DATE || |
| 192 | type == ui::TEXT_INPUT_TYPE_DATE_TIME || |
| 193 | type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || |
| 194 | type == ui::TEXT_INPUT_TYPE_MONTH || |
| 195 | type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK; |
| 196 | } |
| 197 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 198 | WebDragData DropMetaDataToWebDragData( |
| 199 | const std::vector<DropData::Metadata>& drop_meta_data) { |
| 200 | std::vector<WebDragData::Item> item_list; |
| 201 | for (const auto& meta_data_item : drop_meta_data) { |
| 202 | if (meta_data_item.kind == DropData::Kind::STRING) { |
| 203 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 204 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 205 | item.string_type = WebString::FromUTF16(meta_data_item.mime_type); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 206 | // Have to pass a dummy URL here instead of an empty URL because the |
| 207 | // DropData received by browser_plugins goes through a round trip: |
| 208 | // DropData::MetaData --> WebDragData-->DropData. In the end, DropData |
| 209 | // will contain an empty URL (which means no URL is dragged) if the URL in |
| 210 | // WebDragData is empty. |
| 211 | if (base::EqualsASCII(meta_data_item.mime_type, |
| 212 | ui::Clipboard::kMimeTypeURIList)) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 213 | item.string_data = WebString::FromUTF8("about:dragdrop-placeholder"); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 214 | } |
| 215 | item_list.push_back(item); |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | // TODO(hush): crbug.com/584789. Blink needs to support creating a file with |
| 220 | // just the mimetype. This is needed to drag files to WebView on Android |
| 221 | // platform. |
| 222 | if ((meta_data_item.kind == DropData::Kind::FILENAME) && |
| 223 | !meta_data_item.filename.empty()) { |
| 224 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 225 | item.storage_type = WebDragData::Item::kStorageTypeFilename; |
| 226 | item.filename_data = blink::FilePathToWebString(meta_data_item.filename); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 227 | item_list.push_back(item); |
| 228 | continue; |
| 229 | } |
| 230 | |
| 231 | if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { |
| 232 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 233 | item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile; |
| 234 | item.file_system_url = meta_data_item.file_system_url; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 235 | item_list.push_back(item); |
| 236 | continue; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | WebDragData result; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 241 | result.Initialize(); |
| 242 | result.SetItems(item_list); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 243 | return result; |
| 244 | } |
| 245 | |
| 246 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
| 247 | std::vector<WebDragData::Item> item_list; |
| 248 | |
| 249 | // These fields are currently unused when dragging into WebKit. |
| 250 | DCHECK(drop_data.download_metadata.empty()); |
| 251 | DCHECK(drop_data.file_contents.empty()); |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 252 | DCHECK(drop_data.file_contents_content_disposition.empty()); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 253 | |
| 254 | if (!drop_data.text.is_null()) { |
| 255 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 256 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 257 | item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText); |
| 258 | item.string_data = WebString::FromUTF16(drop_data.text.string()); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 259 | item_list.push_back(item); |
| 260 | } |
| 261 | |
| 262 | if (!drop_data.url.is_empty()) { |
| 263 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 264 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 265 | item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 266 | item.string_data = WebString::FromUTF8(drop_data.url.spec()); |
| 267 | item.title = WebString::FromUTF16(drop_data.url_title); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 268 | item_list.push_back(item); |
| 269 | } |
| 270 | |
| 271 | if (!drop_data.html.is_null()) { |
| 272 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 273 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 274 | item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 275 | item.string_data = WebString::FromUTF16(drop_data.html.string()); |
| 276 | item.base_url = drop_data.html_base_url; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 277 | item_list.push_back(item); |
| 278 | } |
| 279 | |
| 280 | for (std::vector<ui::FileInfo>::const_iterator it = |
| 281 | drop_data.filenames.begin(); |
| 282 | it != drop_data.filenames.end(); |
| 283 | ++it) { |
| 284 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 285 | item.storage_type = WebDragData::Item::kStorageTypeFilename; |
| 286 | item.filename_data = blink::FilePathToWebString(it->path); |
| 287 | item.display_name_data = |
kinuko | a429302 | 2017-01-27 06:43:25 | [diff] [blame] | 288 | blink::FilePathToWebString(base::FilePath(it->display_name)); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 289 | item_list.push_back(item); |
| 290 | } |
| 291 | |
| 292 | for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = |
| 293 | drop_data.file_system_files.begin(); |
| 294 | it != drop_data.file_system_files.end(); |
| 295 | ++it) { |
| 296 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 297 | item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile; |
| 298 | item.file_system_url = it->url; |
| 299 | item.file_system_file_size = it->size; |
| 300 | item.file_system_id = blink::WebString::FromASCII(it->filesystem_id); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 301 | item_list.push_back(item); |
| 302 | } |
| 303 | |
Stuart Langley | 4830039 | 2017-11-02 03:54:44 | [diff] [blame] | 304 | for (const auto& it : drop_data.custom_data) { |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 305 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 306 | item.storage_type = WebDragData::Item::kStorageTypeString; |
Stuart Langley | 4830039 | 2017-11-02 03:54:44 | [diff] [blame] | 307 | item.string_type = WebString::FromUTF16(it.first); |
| 308 | item.string_data = WebString::FromUTF16(it.second); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 309 | item_list.push_back(item); |
| 310 | } |
| 311 | |
| 312 | WebDragData result; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 313 | result.Initialize(); |
| 314 | result.SetItems(item_list); |
| 315 | result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id)); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 316 | return result; |
| 317 | } |
| 318 | |
lfg | 1568d11 | 2016-08-30 16:06:29 | [diff] [blame] | 319 | content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = |
| 320 | nullptr; |
| 321 | |
| 322 | content::RenderWidget::RenderWidgetInitializedCallback |
| 323 | g_render_widget_initialized = nullptr; |
| 324 | |
dtapuska | c4dd5be | 2016-10-25 15:11:10 | [diff] [blame] | 325 | ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { |
| 326 | // Check the type is in the range representable by ui::TextInputType. |
| 327 | DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) |
| 328 | << "blink::WebTextInputType and ui::TextInputType not synchronized"; |
| 329 | return static_cast<ui::TextInputType>(type); |
| 330 | } |
| 331 | |
| 332 | ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) { |
| 333 | // Check the mode is in the range representable by ui::TextInputMode. |
| 334 | DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX)) |
| 335 | << "blink::WebTextInputMode and ui::TextInputMode not synchronized"; |
| 336 | return static_cast<ui::TextInputMode>(mode); |
| 337 | } |
| 338 | |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 339 | // Returns true if the device scale is high enough that losing subpixel |
| 340 | // antialiasing won't have a noticeable effect on text quality. |
| 341 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 342 | #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 343 | // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to |
| 344 | // composite all scrollers so that we get animated overlay scrollbars. |
| 345 | return true; |
| 346 | #else |
| 347 | // 1.5 is a common touchscreen tablet device scale factor. For such |
| 348 | // devices main thread antialiasing is a heavy burden. |
| 349 | return device_scale_factor >= 1.5f; |
| 350 | #endif |
| 351 | } |
| 352 | |
| 353 | static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps, |
| 354 | float device_scale_factor) { |
| 355 | const base::CommandLine& command_line = |
| 356 | *base::CommandLine::ForCurrentProcess(); |
| 357 | if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText)) |
| 358 | return false; |
| 359 | if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText)) |
| 360 | return true; |
| 361 | if (!compositor_deps->IsLcdTextEnabled()) |
| 362 | return true; |
| 363 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 364 | } |
| 365 | |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 366 | } // namespace |
| 367 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 368 | // RenderWidget --------------------------------------------------------------- |
| 369 | |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 370 | RenderWidget::RenderWidget( |
| 371 | int32_t widget_routing_id, |
| 372 | CompositorDependencies* compositor_deps, |
| 373 | blink::WebPopupType popup_type, |
| 374 | const ScreenInfo& screen_info, |
| 375 | bool swapped_out, |
| 376 | bool hidden, |
| 377 | bool never_visible, |
| 378 | scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 379 | mojom::WidgetRequest widget_request) |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 380 | : routing_id_(widget_routing_id), |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 381 | compositor_deps_(compositor_deps), |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 382 | webwidget_internal_(nullptr), |
avi | 40b5be7a | 2016-03-03 21:13:44 | [diff] [blame] | 383 | owner_delegate_(nullptr), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 384 | next_paint_flags_(0), |
[email protected] | 847a258 | 2013-03-09 02:29:51 | [diff] [blame] | 385 | auto_resize_mode_(false), |
Fady Samuel | d10aadd8 | 2017-11-03 18:23:57 | [diff] [blame] | 386 | need_resize_ack_for_auto_resize_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 387 | did_show_(false), |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 388 | is_hidden_(hidden), |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 389 | compositor_never_visible_(never_visible), |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 390 | is_fullscreen_granted_(false), |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 391 | display_mode_(blink::kWebDisplayModeUndefined), |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 392 | ime_event_guard_(nullptr), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 393 | closing_(false), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 394 | host_closing_(false), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 395 | is_swapped_out_(swapped_out), |
simonhong | 628f981 | 2015-04-27 23:13:20 | [diff] [blame] | 396 | for_oopif_(false), |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 397 | text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 398 | text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 399 | text_input_flags_(0), |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 400 | next_previous_flags_(kInvalidNextPreviousFlagsValue), |
[email protected] | 86ba5fcb | 2013-09-04 00:36:53 | [diff] [blame] | 401 | can_compose_inline_(true), |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 402 | composition_range_(gfx::Range::InvalidRange()), |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 403 | popup_type_(popup_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 404 | pending_window_rect_count_(0), |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 405 | screen_info_(screen_info), |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 406 | monitor_composition_info_(false), |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 407 | popup_origin_scale_for_emulation_(0.f), |
samans | 26510e44 | 2017-06-01 22:29:12 | [diff] [blame] | 408 | frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)), |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 409 | resizing_mode_selector_(new ResizingModeSelector()), |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 410 | has_host_context_menu_location_(false), |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 411 | has_added_input_handler_(false), |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 412 | has_focus_(false), |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 413 | #if defined(OS_MACOSX) |
| 414 | text_input_client_observer_(new TextInputClientObserver(this)), |
| 415 | #endif |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 416 | first_update_visual_state_after_hidden_(false), |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 417 | was_shown_time_(base::TimeTicks::Now()), |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 418 | current_content_source_id_(0), |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 419 | widget_binding_(this, std::move(widget_request)), |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 420 | task_runner_(task_runner), |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 421 | weak_ptr_factory_(this) { |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 422 | DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
[email protected] | 8b3f0eb | 2012-05-03 19:15:05 | [diff] [blame] | 423 | if (!swapped_out) |
| 424 | RenderProcess::current()->AddRefProcess(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 425 | DCHECK(RenderThread::Get()); |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 426 | |
| 427 | // In tests there may not be a RenderThreadImpl. |
| 428 | if (RenderThreadImpl::current()) { |
| 429 | render_widget_scheduling_state_ = RenderThreadImpl::current() |
| 430 | ->GetRendererScheduler() |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 431 | ->NewRenderWidgetSchedulingState(); |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 432 | render_widget_scheduling_state_->SetHidden(is_hidden_); |
| 433 | } |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 434 | #if defined(USE_AURA) |
fsamuel | 098eade | 2017-03-21 18:06:14 | [diff] [blame] | 435 | RendererWindowTreeClient::CreateIfNecessary(routing_id_); |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 436 | if (features::IsMusEnabled()) |
Scott Violet | 1098538e | 2017-10-05 19:23:33 | [diff] [blame] | 437 | RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_); |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 438 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | RenderWidget::~RenderWidget() { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 442 | DCHECK(!webwidget_internal_) << "Leaking our WebWidget!"; |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 443 | |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 444 | if (input_event_queue_) |
| 445 | input_event_queue_->ClearClient(); |
| 446 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 447 | // If we are swapped out, we have released already. |
[email protected] | d2e2f9ee | 2013-08-21 11:02:02 | [diff] [blame] | 448 | if (!is_swapped_out_ && RenderProcess::current()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 449 | RenderProcess::current()->ReleaseProcess(); |
sadrul | 8185d97 | 2017-01-31 18:30:11 | [diff] [blame] | 450 | #if defined(USE_AURA) |
fsamuel | 098eade | 2017-03-21 18:06:14 | [diff] [blame] | 451 | // It is possible for a RenderWidget to be destroyed before it was embedded |
| 452 | // in a mus window. The RendererWindowTreeClient will leak in such cases. So |
| 453 | // explicitly delete it here. |
| 454 | RendererWindowTreeClient::Destroy(routing_id_); |
sadrul | 8185d97 | 2017-01-31 18:30:11 | [diff] [blame] | 455 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 456 | } |
| 457 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 458 | // static |
lfg | 1568d11 | 2016-08-30 16:06:29 | [diff] [blame] | 459 | void RenderWidget::InstallCreateHook( |
| 460 | CreateRenderWidgetFunction create_render_widget, |
| 461 | RenderWidgetInitializedCallback render_widget_initialized) { |
| 462 | CHECK(!g_create_render_widget && !g_render_widget_initialized); |
| 463 | g_create_render_widget = create_render_widget; |
| 464 | g_render_widget_initialized = render_widget_initialized; |
| 465 | } |
| 466 | |
| 467 | // static |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 468 | RenderWidget* RenderWidget::CreateForPopup( |
| 469 | RenderViewImpl* opener, |
| 470 | CompositorDependencies* compositor_deps, |
| 471 | blink::WebPopupType popup_type, |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 472 | const ScreenInfo& screen_info, |
| 473 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 474 | mojom::WidgetPtr widget_channel; |
| 475 | mojom::WidgetRequest widget_channel_request = |
| 476 | mojo::MakeRequest(&widget_channel); |
| 477 | |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 478 | // Do a synchronous IPC to obtain a routing ID. |
| 479 | int32_t routing_id = MSG_ROUTING_NONE; |
| 480 | if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget( |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 481 | opener->GetRoutingID(), popup_type, std::move(widget_channel), |
| 482 | &routing_id)) { |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 483 | return nullptr; |
| 484 | } |
| 485 | |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 486 | scoped_refptr<RenderWidget> widget(new RenderWidget( |
| 487 | routing_id, compositor_deps, popup_type, screen_info, false, false, false, |
| 488 | task_runner, std::move(widget_channel_request))); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 489 | ShowCallback opener_callback = |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 490 | base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->GetWeakPtr()); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 491 | widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get())); |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 492 | DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. |
| 493 | return widget.get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 494 | } |
| 495 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 496 | // static |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 497 | RenderWidget* RenderWidget::CreateForFrame( |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 498 | int widget_routing_id, |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 499 | bool hidden, |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 500 | const ScreenInfo& screen_info, |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 501 | CompositorDependencies* compositor_deps, |
| 502 | blink::WebLocalFrame* frame) { |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 503 | CHECK_NE(widget_routing_id, MSG_ROUTING_NONE); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 504 | // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the |
| 505 | // same routing ID for both the view routing ID and the main frame widget |
| 506 | // routing ID. https://crbug.com/545684 |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 507 | RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 508 | if (view) { |
avi | 8a45c109 | 2016-03-01 16:12:34 | [diff] [blame] | 509 | view->AttachWebFrameWidget( |
| 510 | RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); |
Lucas Furukawa Gadani | 6ccadf7 | 2018-02-13 10:29:10 | [diff] [blame] | 511 | view->GetWidget()->UpdateWebViewWithDeviceScaleFactor(); |
avi | 8a45c109 | 2016-03-01 16:12:34 | [diff] [blame] | 512 | return view->GetWidget(); |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 513 | } |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 514 | scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 515 | frame->GetTaskRunner(blink::TaskType::kUnthrottled); |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 516 | scoped_refptr<RenderWidget> widget( |
lfg | 1568d11 | 2016-08-30 16:06:29 | [diff] [blame] | 517 | g_create_render_widget |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 518 | ? g_create_render_widget(widget_routing_id, compositor_deps, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 519 | blink::kWebPopupTypeNone, screen_info, false, |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 520 | hidden, false) |
| 521 | : new RenderWidget(widget_routing_id, compositor_deps, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 522 | blink::kWebPopupTypeNone, screen_info, false, |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 523 | hidden, false, task_runner)); |
simonhong | 628f981 | 2015-04-27 23:13:20 | [diff] [blame] | 524 | widget->for_oopif_ = true; |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 525 | // Init increments the reference count on |widget|, keeping it alive after |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 526 | // this function returns. |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 527 | widget->Init(RenderWidget::ShowCallback(), |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 528 | RenderWidget::CreateWebFrameWidget(widget.get(), frame)); |
Lucas Furukawa Gadani | 6ccadf7 | 2018-02-13 10:29:10 | [diff] [blame] | 529 | widget->UpdateWebViewWithDeviceScaleFactor(); |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 530 | |
| 531 | if (g_render_widget_initialized) |
| 532 | g_render_widget_initialized(widget.get()); |
| 533 | return widget.get(); |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | // static |
lfg | caab514 | 2016-02-26 19:06:52 | [diff] [blame] | 537 | blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 538 | RenderWidget* render_widget, |
| 539 | blink::WebLocalFrame* frame) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 540 | return blink::WebFrameWidget::Create(render_widget, frame); |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | // static |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 544 | blink::WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 545 | switch (render_widget->popup_type_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 546 | case blink::kWebPopupTypeNone: // Nothing to create. |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 547 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 548 | case blink::kWebPopupTypePage: |
| 549 | return WebPagePopup::Create(render_widget); |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 550 | default: |
| 551 | NOTREACHED(); |
| 552 | } |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 553 | return nullptr; |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 554 | } |
| 555 | |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 556 | void RenderWidget::CloseForFrame() { |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 557 | OnClose(); |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 558 | } |
| 559 | |
alexmos | 78c9c0d | 2016-10-14 18:57:03 | [diff] [blame] | 560 | void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 561 | // We should only toggle between states. |
| 562 | DCHECK(is_swapped_out_ != is_swapped_out); |
| 563 | is_swapped_out_ = is_swapped_out; |
| 564 | |
| 565 | // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 566 | // to exit if all of its RenderViews are swapped out. We wait until the |
| 567 | // WasSwappedOut call to do this, to allow the unload handler to finish. |
| 568 | // If we are swapping in, we call AddRefProcess to prevent the process from |
| 569 | // exiting. |
| 570 | if (!is_swapped_out_) |
| 571 | RenderProcess::current()->AddRefProcess(); |
| 572 | } |
| 573 | |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 574 | void RenderWidget::Init(const ShowCallback& show_callback, |
| 575 | WebWidget* web_widget) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 576 | DCHECK(!webwidget_internal_); |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 577 | DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 578 | |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 579 | input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this); |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 580 | |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 581 | if (base::FeatureList::IsEnabled(features::kMojoInputMessages)) { |
| 582 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 583 | |
Dave Tapuska | 525eb15e | 2017-08-17 21:05:50 | [diff] [blame] | 584 | widget_input_handler_manager_ = WidgetInputHandlerManager::Create( |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 585 | weak_ptr_factory_.GetWeakPtr(), |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 586 | render_thread_impl && compositor_ |
| 587 | ? render_thread_impl->compositor_task_runner() |
| 588 | : nullptr, |
| 589 | render_thread_impl ? render_thread_impl->GetRendererScheduler() |
| 590 | : nullptr); |
| 591 | } |
| 592 | |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 593 | show_callback_ = show_callback; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 594 | |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 595 | webwidget_internal_ = web_widget; |
| 596 | webwidget_mouse_lock_target_.reset( |
| 597 | new WebWidgetLockTarget(webwidget_internal_)); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 598 | mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 599 | |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 600 | RenderThread::Get()->AddRoute(routing_id_, this); |
| 601 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 602 | // when we receive ViewMsg_Close. |
| 603 | AddRef(); |
| 604 | if (RenderThreadImpl::current()) { |
| 605 | RenderThreadImpl::current()->WidgetCreated(); |
| 606 | if (is_hidden_) |
| 607 | RenderThreadImpl::current()->WidgetHidden(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
[email protected] | 949b659 | 2014-08-20 13:17:52 | [diff] [blame] | 611 | void RenderWidget::WasSwappedOut() { |
| 612 | // If we have been swapped out and no one else is using this process, |
| 613 | // it's safe to exit now. |
| 614 | CHECK(is_swapped_out_); |
| 615 | RenderProcess::current()->ReleaseProcess(); |
| 616 | } |
| 617 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 618 | void RenderWidget::SetPopupOriginAdjustmentsForEmulation( |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 619 | RenderWidgetScreenMetricsEmulator* emulator) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 620 | popup_origin_scale_for_emulation_ = emulator->scale(); |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 621 | popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin(); |
Pavel Feldman | cc099f7 | 2017-07-20 23:09:00 | [diff] [blame] | 622 | popup_screen_origin_for_emulation_ = |
Lei Zhang | 9b359d3 | 2017-11-28 00:57:02 | [diff] [blame] | 623 | emulator->original_screen_rect().origin(); |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 624 | UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 625 | emulator->original_screen_info()); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 626 | } |
| 627 | |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 628 | gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) { |
| 629 | if (screen_metrics_emulator_) |
| 630 | return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor); |
| 631 | return anchor; |
| 632 | } |
| 633 | |
thakis | 18e42641 | 2017-03-15 12:06:37 | [diff] [blame] | 634 | #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 635 | void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation( |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 636 | ExternalPopupMenu* popup, |
| 637 | RenderWidgetScreenMetricsEmulator* emulator) { |
Pavel Feldman | cc099f7 | 2017-07-20 23:09:00 | [diff] [blame] | 638 | popup->SetOriginScaleForEmulation(emulator->scale()); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 639 | } |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 640 | #endif |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 641 | |
Fady Samuel | 69b33b5 | 2017-11-08 22:01:52 | [diff] [blame] | 642 | void RenderWidget::SetLocalSurfaceIdForAutoResize( |
| 643 | uint64_t sequence_number, |
| 644 | const content::ScreenInfo& screen_info, |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 645 | uint32_t content_source_id, |
Fady Samuel | 69b33b5 | 2017-11-08 22:01:52 | [diff] [blame] | 646 | const viz::LocalSurfaceId& local_surface_id) { |
Fady Samuel | a41e9d4 | 2018-03-01 21:31:58 | [diff] [blame] | 647 | DCHECK(!size_.IsEmpty()); |
| 648 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 649 | // If the given LocalSurfaceId was generated before navigation, don't use it. |
| 650 | // We should receive a new LocalSurfaceId later. |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 651 | viz::LocalSurfaceId new_local_surface_id = |
| 652 | content_source_id != current_content_source_id_ ? viz::LocalSurfaceId() |
| 653 | : local_surface_id; |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 654 | // TODO(ccameron): If there is a meaningful distinction between |size_| and |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 655 | // |compositor_viewport_pixel_size_| is it okay to ignore that distinction |
| 656 | // here, and assume that |compositor_viewport_pixel_size_| is just |size_| in |
| 657 | // pixels? Also note that the computation of |
| 658 | // |new_compositor_viewport_pixel_size| does not appear to take into account |
| 659 | // device emulation. |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 660 | float new_device_scale_factor = screen_info.device_scale_factor; |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 661 | gfx::Size new_compositor_viewport_pixel_size = |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 662 | gfx::ScaleToCeiledSize(size_, new_device_scale_factor); |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 663 | UpdateSurfaceAndScreenInfo(new_local_surface_id, |
| 664 | new_compositor_viewport_pixel_size, screen_info); |
Fady Samuel | 69b33b5 | 2017-11-08 22:01:52 | [diff] [blame] | 665 | } |
| 666 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 667 | void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { |
| 668 | if (screen_metrics_emulator_) |
| 669 | screen_metrics_emulator_->OnShowContextMenu(params); |
| 670 | } |
| 671 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 672 | bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 673 | #if defined(OS_MACOSX) |
| 674 | if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart) |
| 675 | return text_input_client_observer_->OnMessageReceived(message); |
| 676 | #endif |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 677 | if (mouse_lock_dispatcher_ && |
| 678 | mouse_lock_dispatcher_->OnMessageReceived(message)) |
| 679 | return true; |
| 680 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 681 | bool handled = true; |
| 682 | IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 683 | IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) |
[email protected] | 34202de | 2013-05-06 23:36:22 | [diff] [blame] | 684 | IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, |
| 685 | OnCursorVisibilityChange) |
[email protected] | a2214eb | 2014-06-23 18:31:22 | [diff] [blame] | 686 | IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 687 | IPC_MESSAGE_HANDLER(InputMsg_ImeCommitText, OnImeCommitText) |
| 688 | IPC_MESSAGE_HANDLER(InputMsg_ImeFinishComposingText, |
| 689 | OnImeFinishComposingText) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 690 | IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 691 | IPC_MESSAGE_HANDLER(InputMsg_SetEditCommandsForNextKeyEvent, |
| 692 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | c084330e0 | 2013-04-27 01:08:15 | [diff] [blame] | 693 | IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) |
wjmaclean | ee244e0 | 2017-05-26 21:06:07 | [diff] [blame] | 694 | IPC_MESSAGE_HANDLER(ViewMsg_ShowContextMenu, OnShowContextMenu) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 695 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 696 | IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 697 | IPC_MESSAGE_HANDLER(ViewMsg_SetLocalSurfaceIdForAutoResize, |
| 698 | OnSetLocalSurfaceIdForAutoResize) |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 699 | IPC_MESSAGE_HANDLER(ViewMsg_EnableDeviceEmulation, |
| 700 | OnEnableDeviceEmulation) |
| 701 | IPC_MESSAGE_HANDLER(ViewMsg_DisableDeviceEmulation, |
| 702 | OnDisableDeviceEmulation) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 703 | IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 704 | IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
[email protected] | 3d9ec505 | 2013-01-02 22:05:25 | [diff] [blame] | 705 | IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 706 | IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 707 | IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 708 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 709 | IPC_MESSAGE_HANDLER(ViewMsg_SetViewportIntersection, |
| 710 | OnSetViewportIntersection) |
kenrb | 0432378 | 2017-06-23 01:23:32 | [diff] [blame] | 711 | IPC_MESSAGE_HANDLER(ViewMsg_SetIsInert, OnSetIsInert) |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 712 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateRenderThrottlingStatus, |
| 713 | OnUpdateRenderThrottlingStatus) |
lfg | 43e08e6 | 2016-02-03 18:51:37 | [diff] [blame] | 714 | IPC_MESSAGE_HANDLER(ViewMsg_WaitForNextFrameForTests, |
| 715 | OnWaitNextFrameForTests) |
ekaramad | c9b70a7 | 2017-03-23 16:14:23 | [diff] [blame] | 716 | IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdates, |
| 717 | OnRequestCompositionUpdates) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 718 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 719 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 720 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 721 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 722 | IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) |
| 723 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 724 | OnDragSourceSystemDragEnded) |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 725 | #if defined(OS_ANDROID) |
changwan | 8c34274 | 2016-02-26 00:53:39 | [diff] [blame] | 726 | IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, |
| 727 | OnRequestTextInputStateUpdate) |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 728 | #endif |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 729 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 730 | IPC_END_MESSAGE_MAP() |
| 731 | return handled; |
| 732 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 733 | |
| 734 | bool RenderWidget::Send(IPC::Message* message) { |
Nasko Oskov | f97e8b0 | 2017-07-25 02:45:42 | [diff] [blame] | 735 | // Don't send any messages after the browser has told us to close, and filter |
| 736 | // most outgoing messages while swapped out. |
| 737 | if ((is_swapped_out_ && |
| 738 | !SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
| 739 | closing_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 740 | delete message; |
| 741 | return false; |
| 742 | } |
| 743 | |
| 744 | // If given a messsage without a routing ID, then assign our routing ID. |
| 745 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 746 | message->set_routing_id(routing_id_); |
| 747 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 748 | return RenderThread::Get()->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 749 | } |
| 750 | |
dtapuska | 014ed08 | 2016-11-11 21:58:48 | [diff] [blame] | 751 | void RenderWidget::SendOrCrash(IPC::Message* message) { |
| 752 | bool result = Send(message); |
| 753 | CHECK(closing_ || result) << "Failed to send message"; |
| 754 | } |
| 755 | |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 756 | bool RenderWidget::ShouldHandleImeEvents() const { |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 757 | // TODO(ekaramad): We track page focus in all RenderViews on the page but the |
| 758 | // RenderWidgets corresponding to OOPIFs do not get the update. For now, this |
| 759 | // method returns true when the RenderWidget is for an OOPIF, i.e., IME events |
| 760 | // will be processed regardless of page focus. We should revisit this after |
| 761 | // page focus for OOPIFs has been fully resolved (https://crbug.com/689777). |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 762 | return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() && |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 763 | (has_focus_ || for_oopif_); |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 764 | } |
| 765 | |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 766 | void RenderWidget::SetWindowRectSynchronously( |
| 767 | const gfx::Rect& new_window_rect) { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 768 | ResizeParams params; |
| 769 | params.screen_info = screen_info_; |
| 770 | params.new_size = new_window_rect.size(); |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 771 | params.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize( |
| 772 | new_window_rect.size(), GetWebScreenInfo().device_scale_factor); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 773 | params.visible_viewport_size = new_window_rect.size(); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 774 | params.is_fullscreen_granted = is_fullscreen_granted_; |
| 775 | params.display_mode = display_mode_; |
| 776 | params.needs_resize_ack = false; |
| 777 | Resize(params); |
| 778 | |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 779 | view_screen_rect_ = new_window_rect; |
| 780 | window_screen_rect_ = new_window_rect; |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 781 | if (!did_show_) |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 782 | initial_rect_ = new_window_rect; |
[email protected] | 9265016 | 2013-10-30 03:31:02 | [diff] [blame] | 783 | } |
| 784 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 785 | void RenderWidget::OnClose() { |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 786 | DCHECK(content::RenderThread::Get()); |
| 787 | if (closing_) |
| 788 | return; |
| 789 | NotifyOnClose(); |
| 790 | closing_ = true; |
| 791 | |
| 792 | // Browser correspondence is no longer needed at this point. |
| 793 | if (routing_id_ != MSG_ROUTING_NONE) { |
| 794 | RenderThread::Get()->RemoveRoute(routing_id_); |
| 795 | SetHidden(false); |
| 796 | if (RenderThreadImpl::current()) |
| 797 | RenderThreadImpl::current()->WidgetDestroyed(); |
| 798 | } |
| 799 | |
| 800 | if (for_oopif_) { |
| 801 | // Widgets for frames may be created and closed at any time while the frame |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 802 | // is alive. However, WebWidget must be closed synchronously because frame |
| 803 | // widgets and frames hold pointers to each other. The deferred call to |
| 804 | // Close() will complete cleanup and release |this|, but CloseWebWidget() |
| 805 | // prevents Close() from attempting to access members of an |
| 806 | // already-deleted frame. |
| 807 | CloseWebWidget(); |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 808 | } |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 809 | // If there is a Send call on the stack, then it could be dangerous to close |
| 810 | // now. Post a task that only gets invoked when there are no nested message |
| 811 | // loops. |
| 812 | task_runner_->PostNonNestableTask(FROM_HERE, |
| 813 | base::BindOnce(&RenderWidget::Close, this)); |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 814 | |
| 815 | // Balances the AddRef taken when we called AddRoute. |
| 816 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 817 | } |
| 818 | |
fsamuel | 664e8b6 | 2016-01-20 19:54:01 | [diff] [blame] | 819 | void RenderWidget::OnResize(const ResizeParams& params) { |
EhsanK | bd2cea99 | 2017-11-23 18:49:08 | [diff] [blame] | 820 | gfx::Size old_visible_viewport_size = visible_viewport_size_; |
| 821 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 822 | if (resizing_mode_selector_->ShouldAbortOnResize(this, params)) |
[email protected] | 03e8867 | 2013-10-22 21:31:32 | [diff] [blame] | 823 | return; |
| 824 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 825 | if (screen_metrics_emulator_) { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 826 | screen_metrics_emulator_->OnResize(params); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 827 | return; |
| 828 | } |
| 829 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 830 | Resize(params); |
EhsanK | bd2cea99 | 2017-11-23 18:49:08 | [diff] [blame] | 831 | |
| 832 | if (old_visible_viewport_size != visible_viewport_size_) { |
| 833 | for (auto& render_frame : render_frames_) |
| 834 | render_frame.DidChangeVisibleViewport(); |
| 835 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 836 | } |
| 837 | |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 838 | void RenderWidget::OnSetLocalSurfaceIdForAutoResize( |
| 839 | uint64_t sequence_number, |
Fady Samuel | 69b33b5 | 2017-11-08 22:01:52 | [diff] [blame] | 840 | const gfx::Size& min_size, |
| 841 | const gfx::Size& max_size, |
| 842 | const content::ScreenInfo& screen_info, |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 843 | uint32_t content_source_id, |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 844 | const viz::LocalSurfaceId& local_surface_id) { |
Fady Samuel | 1ee6fb5c | 2018-02-16 03:27:46 | [diff] [blame] | 845 | if (!auto_resize_mode_ || resize_or_repaint_ack_num_ != sequence_number) { |
| 846 | DidResizeOrRepaintAck(); |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 847 | return; |
Fady Samuel | 1ee6fb5c | 2018-02-16 03:27:46 | [diff] [blame] | 848 | } |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 849 | // TODO(ccameron): This does not appear to interact correctly with device |
| 850 | // emulation (compare with the intercepting of ScreenInfo in OnResize). |
Fady Samuel | 69b33b5 | 2017-11-08 22:01:52 | [diff] [blame] | 851 | SetLocalSurfaceIdForAutoResize(sequence_number, screen_info, |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 852 | content_source_id, local_surface_id); |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 853 | } |
| 854 | |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 855 | void RenderWidget::OnEnableDeviceEmulation( |
Lei Zhang | 9b359d3 | 2017-11-28 00:57:02 | [diff] [blame] | 856 | const blink::WebDeviceEmulationParams& params) { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 857 | if (!screen_metrics_emulator_) { |
| 858 | ResizeParams resize_params; |
| 859 | resize_params.screen_info = screen_info_; |
| 860 | resize_params.new_size = size_; |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 861 | resize_params.compositor_viewport_pixel_size = |
| 862 | compositor_viewport_pixel_size_; |
Fady Samuel | a41e9d4 | 2018-03-01 21:31:58 | [diff] [blame] | 863 | resize_params.local_surface_id = local_surface_id_; |
| 864 | resize_params.content_source_id = current_content_source_id_; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 865 | resize_params.visible_viewport_size = visible_viewport_size_; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 866 | resize_params.is_fullscreen_granted = is_fullscreen_granted_; |
| 867 | resize_params.display_mode = display_mode_; |
| 868 | screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator( |
| 869 | this, params, resize_params, view_screen_rect_, window_screen_rect_)); |
oshima | 50872a7 | 2016-03-04 13:26:18 | [diff] [blame] | 870 | screen_metrics_emulator_->Apply(); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 871 | } else { |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 872 | screen_metrics_emulator_->ChangeEmulationParams(params); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 873 | } |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | void RenderWidget::OnDisableDeviceEmulation() { |
| 877 | screen_metrics_emulator_.reset(); |
| 878 | } |
| 879 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 880 | void RenderWidget::OnWasHidden() { |
[email protected] | 9c3085f | 2011-06-09 02:10:31 | [diff] [blame] | 881 | TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 882 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 883 | SetHidden(true); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 884 | for (auto& observer : render_frames_) |
| 885 | observer.WasHidden(); |
Saman Sami | 58ed439 | 2018-01-31 20:54:19 | [diff] [blame] | 886 | |
| 887 | // Ack the resize if we have to, so that the next time we're visible we get a |
| 888 | // fresh ResizeParams right away; otherwise we'll start painting based on a |
| 889 | // stale ResizeParams. |
| 890 | DidResizeOrRepaintAck(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 891 | } |
| 892 | |
Saman Sami | d709592b | 2018-02-03 00:38:10 | [diff] [blame] | 893 | void RenderWidget::OnWasShown(bool needs_repainting, |
| 894 | const ui::LatencyInfo& latency_info) { |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 895 | TRACE_EVENT0("renderer", "RenderWidget::OnWasShown"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 896 | // During shutdown we can just ignore this message. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 897 | if (!GetWebWidget()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 898 | return; |
| 899 | |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 900 | was_shown_time_ = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 901 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 902 | SetHidden(false); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 903 | for (auto& observer : render_frames_) |
| 904 | observer.WasShown(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 905 | |
[email protected] | 8a23afb3 | 2014-04-30 22:40:23 | [diff] [blame] | 906 | if (!needs_repainting) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 907 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 908 | |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 909 | if (compositor_) { |
| 910 | ui::LatencyInfo swap_latency_info(latency_info); |
danakj | 87fbafb | 2017-04-04 16:54:11 | [diff] [blame] | 911 | std::unique_ptr<cc::SwapPromiseMonitor> latency_info_swap_promise_monitor = |
| 912 | compositor_->CreateLatencyInfoSwapPromiseMonitor(&swap_latency_info); |
| 913 | // Force this SwapPromiseMonitor to trigger and insert a SwapPromise. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 914 | compositor_->SetNeedsBeginFrame(); |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 915 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 916 | } |
| 917 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 918 | void RenderWidget::OnRequestMoveAck() { |
| 919 | DCHECK(pending_window_rect_count_); |
| 920 | pending_window_rect_count_--; |
| 921 | } |
| 922 | |
[email protected] | ed7defa | 2013-03-12 21:29:59 | [diff] [blame] | 923 | GURL RenderWidget::GetURLForGraphicsContext3D() { |
| 924 | return GURL(); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 925 | } |
| 926 | |
nzolghadr | 5d859650 | 2017-01-23 22:59:35 | [diff] [blame] | 927 | void RenderWidget::OnHandleInputEvent( |
| 928 | const blink::WebInputEvent* input_event, |
| 929 | const std::vector<const blink::WebInputEvent*>& coalesced_events, |
| 930 | const ui::LatencyInfo& latency_info, |
| 931 | InputEventDispatchType dispatch_type) { |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 932 | if (!input_event) |
| 933 | return; |
nzolghadr | 5d859650 | 2017-01-23 22:59:35 | [diff] [blame] | 934 | |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 935 | HandledEventCallback callback; |
| 936 | if (dispatch_type == DISPATCH_TYPE_BLOCKING) { |
| 937 | callback = base::Bind( |
| 938 | &RenderWidget::SendInputEventAck, this, input_event->GetType(), |
| 939 | ui::WebInputEventTraits::GetUniqueTouchEventId(*input_event)); |
| 940 | } |
nzolghadr | 5d859650 | 2017-01-23 22:59:35 | [diff] [blame] | 941 | input_handler_->HandleInputEvent( |
| 942 | blink::WebCoalescedInputEvent(*input_event, coalesced_events), |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 943 | latency_info, std::move(callback)); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 944 | } |
| 945 | |
Sadrul Habib Chowdhury | 6539b73 | 2018-01-05 21:53:27 | [diff] [blame] | 946 | viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::Point& point) { |
| 947 | return input_handler_->GetFrameSinkIdAtPoint(point); |
Navid Zolghadr | 0d86e5f | 2017-10-23 18:09:22 | [diff] [blame] | 948 | } |
| 949 | |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 950 | void RenderWidget::HandleInputEvent( |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 951 | const blink::WebCoalescedInputEvent& input_event, |
| 952 | const ui::LatencyInfo& latency_info, |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 953 | HandledEventCallback callback) { |
| 954 | input_handler_->HandleInputEvent(input_event, latency_info, |
| 955 | std::move(callback)); |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 956 | } |
| 957 | |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 958 | void RenderWidget::SendInputEventAck( |
| 959 | blink::WebInputEvent::Type type, |
| 960 | uint32_t touch_event_id, |
| 961 | InputEventAckState ack_state, |
| 962 | const ui::LatencyInfo& latency_info, |
Dave Tapuska | b28a108 | 2017-08-30 15:37:26 | [diff] [blame] | 963 | std::unique_ptr<ui::DidOverscrollParams> overscroll_params, |
| 964 | base::Optional<cc::TouchAction> touch_action) { |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 965 | InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_state, |
Dave Tapuska | b28a108 | 2017-08-30 15:37:26 | [diff] [blame] | 966 | latency_info, std::move(overscroll_params), touch_event_id, |
| 967 | touch_action); |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 968 | Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack)); |
| 969 | } |
| 970 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 971 | scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() { |
| 972 | return input_event_queue_; |
| 973 | } |
| 974 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 975 | void RenderWidget::OnCursorVisibilityChange(bool is_visible) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 976 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 977 | GetWebWidget()->SetCursorVisibilityState(is_visible); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | void RenderWidget::OnMouseCaptureLost() { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 981 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 982 | GetWebWidget()->MouseCaptureLost(); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 983 | } |
| 984 | |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 985 | void RenderWidget::OnSetEditCommandsForNextKeyEvent( |
| 986 | const EditCommands& edit_commands) { |
| 987 | edit_commands_ = edit_commands; |
| 988 | } |
| 989 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 990 | void RenderWidget::OnSetFocus(bool enable) { |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 991 | has_focus_ = enable; |
| 992 | |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 993 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 994 | GetWebWidget()->SetFocus(enable); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 995 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 996 | for (auto& observer : render_frames_) |
| 997 | observer.RenderWidgetSetFocus(enable); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 998 | } |
| 999 | |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 1000 | void RenderWidget::SetNeedsMainFrame() { |
| 1001 | RenderWidgetCompositor* rwc = compositor(); |
| 1002 | if (!rwc) |
| 1003 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1004 | rwc->SetNeedsBeginFrame(); |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 1005 | } |
| 1006 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1007 | /////////////////////////////////////////////////////////////////////////////// |
| 1008 | // RenderWidgetCompositorDelegate |
| 1009 | |
| 1010 | void RenderWidget::ApplyViewportDeltas( |
| 1011 | const gfx::Vector2dF& inner_delta, |
| 1012 | const gfx::Vector2dF& outer_delta, |
| 1013 | const gfx::Vector2dF& elastic_overscroll_delta, |
| 1014 | float page_scale, |
| 1015 | float top_controls_delta) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1016 | if (!GetWebWidget()) |
| 1017 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1018 | GetWebWidget()->ApplyViewportDeltas(inner_delta, outer_delta, |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1019 | elastic_overscroll_delta, page_scale, |
| 1020 | top_controls_delta); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1021 | } |
| 1022 | |
sahel | 1b47fda7 | 2017-03-28 17:03:07 | [diff] [blame] | 1023 | void RenderWidget::RecordWheelAndTouchScrollingCount( |
| 1024 | bool has_scrolled_by_wheel, |
| 1025 | bool has_scrolled_by_touch) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1026 | if (!GetWebWidget()) |
| 1027 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1028 | GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel, |
sahel | 1b47fda7 | 2017-03-28 17:03:07 | [diff] [blame] | 1029 | has_scrolled_by_touch); |
| 1030 | } |
| 1031 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1032 | void RenderWidget::BeginMainFrame(double frame_time_sec) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1033 | if (!GetWebWidget()) |
| 1034 | return; |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 1035 | if (input_event_queue_) { |
| 1036 | input_event_queue_->DispatchRafAlignedInput( |
| 1037 | ui::EventTimeStampFromSeconds(frame_time_sec)); |
| 1038 | } |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 1039 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1040 | GetWebWidget()->BeginFrame(frame_time_sec); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1041 | } |
| 1042 | |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1043 | void RenderWidget::RequestNewLayerTreeFrameSink( |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1044 | const LayerTreeFrameSinkCallback& callback) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1045 | DCHECK(GetWebWidget()); |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 1046 | // For widgets that are never visible, we don't start the compositor, so we |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1047 | // never get a request for a cc::LayerTreeFrameSink. |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 1048 | DCHECK(!compositor_never_visible_); |
jonross | a2ff4f8 | 2018-02-16 17:27:46 | [diff] [blame] | 1049 | |
| 1050 | // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which |
| 1051 | // would then handle binding. |
| 1052 | mojom::RenderFrameMetadataObserverPtr ptr; |
| 1053 | mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr); |
| 1054 | mojom::RenderFrameMetadataObserverClientPtrInfo client_info; |
| 1055 | mojom::RenderFrameMetadataObserverClientRequest client_request = |
| 1056 | mojo::MakeRequest(&client_info); |
| 1057 | compositor_->CreateRenderFrameObserver(std::move(request), |
| 1058 | std::move(client_info)); |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1059 | RenderThreadImpl::current()->RequestNewLayerTreeFrameSink( |
danakj | ab9ef4d | 2017-10-31 23:38:33 | [diff] [blame] | 1060 | routing_id_, frame_swap_message_queue_, GetURLForGraphicsContext3D(), |
jonross | a2ff4f8 | 2018-02-16 17:27:46 | [diff] [blame] | 1061 | callback, std::move(client_request), std::move(ptr)); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 1062 | } |
| 1063 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1064 | void RenderWidget::DidCommitAndDrawCompositorFrame() { |
| 1065 | // NOTE: Tests may break if this event is renamed or moved. See |
| 1066 | // tab_capture_performancetest.cc. |
| 1067 | TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame"); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 1068 | |
Saman Sami | 766e0b0 | 2018-01-31 17:19:20 | [diff] [blame] | 1069 | // If we haven't commited yet, then this method was called as a response to a |
| 1070 | // previous commit and should not be used to ack the resize. |
| 1071 | if (did_commit_after_resize_) |
| 1072 | DidResizeOrRepaintAck(); |
Saman Sami | 9ee04be | 2018-01-25 01:31:25 | [diff] [blame] | 1073 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1074 | for (auto& observer : render_frames_) |
| 1075 | observer.DidCommitAndDrawCompositorFrame(); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 1076 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1077 | // Notify subclasses that we initiated the paint operation. |
| 1078 | DidInitiatePaint(); |
| 1079 | } |
| 1080 | |
Saman Sami | 766e0b0 | 2018-01-31 17:19:20 | [diff] [blame] | 1081 | void RenderWidget::DidCommitCompositorFrame() { |
| 1082 | did_commit_after_resize_ = true; |
| 1083 | } |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1084 | |
| 1085 | void RenderWidget::DidCompletePageScaleAnimation() {} |
| 1086 | |
danakj | 6c872fc0 | 2016-10-22 04:29:49 | [diff] [blame] | 1087 | void RenderWidget::DidReceiveCompositorFrameAck() { |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1088 | } |
| 1089 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1090 | bool RenderWidget::IsClosing() const { |
| 1091 | return host_closing_; |
| 1092 | } |
| 1093 | |
danakj | 53eccbc | 2016-03-02 22:51:07 | [diff] [blame] | 1094 | void RenderWidget::RequestScheduleAnimation() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1095 | ScheduleAnimation(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1096 | } |
| 1097 | |
Eric Seckler | 8af8c0e5 | 2018-01-17 23:45:53 | [diff] [blame] | 1098 | void RenderWidget::UpdateVisualState(VisualStateUpdate requested_update) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1099 | if (!GetWebWidget()) |
| 1100 | return; |
| 1101 | |
Eric Seckler | 8af8c0e5 | 2018-01-17 23:45:53 | [diff] [blame] | 1102 | bool pre_paint_only = requested_update == VisualStateUpdate::kPrePaint; |
| 1103 | WebWidget::LifecycleUpdate lifecycle_update = |
| 1104 | pre_paint_only ? WebWidget::LifecycleUpdate::kPrePaint |
| 1105 | : WebWidget::LifecycleUpdate::kAll; |
| 1106 | |
| 1107 | GetWebWidget()->UpdateLifecycle(lifecycle_update); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1108 | GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false); |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1109 | |
Eric Seckler | 8af8c0e5 | 2018-01-17 23:45:53 | [diff] [blame] | 1110 | if (first_update_visual_state_after_hidden_ && !pre_paint_only) { |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 1111 | RecordTimeToFirstActivePaint(); |
| 1112 | first_update_visual_state_after_hidden_ = false; |
| 1113 | } |
| 1114 | } |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1115 | |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 1116 | void RenderWidget::RecordTimeToFirstActivePaint() { |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1117 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1118 | base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_; |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 1119 | if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) { |
| 1120 | UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint", |
| 1121 | sample); |
| 1122 | } |
| 1123 | if (render_thread_impl->NeedsToRecordFirstActivePaint( |
| 1124 | TTFAP_5MIN_AFTER_BACKGROUNDED)) { |
| 1125 | UMA_HISTOGRAM_TIMES( |
| 1126 | "PurgeAndSuspend.Experimental.TimeToFirstActivePaint." |
| 1127 | "AfterBackgrounded.5min", |
| 1128 | sample); |
| 1129 | } |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | void RenderWidget::WillBeginCompositorFrame() { |
| 1133 | TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
| 1134 | |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1135 | if (!GetWebWidget()) |
| 1136 | return; |
| 1137 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1138 | GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true); |
alancutter | 317a8e0 | 2017-04-05 10:09:29 | [diff] [blame] | 1139 | |
dglazkov | 06854c5c | 2016-08-31 00:19:59 | [diff] [blame] | 1140 | // The UpdateTextInputState can result in further layout and possibly |
| 1141 | // enable GPU acceleration so they need to be called before any painting |
| 1142 | // is done. |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1143 | UpdateTextInputState(); |
dglazkov | 06854c5c | 2016-08-31 00:19:59 | [diff] [blame] | 1144 | UpdateSelectionBounds(); |
| 1145 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1146 | for (auto& observer : render_frame_proxies_) |
| 1147 | observer.WillBeginCompositorFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1148 | } |
| 1149 | |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 1150 | std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 1151 | std::unique_ptr<viz::CopyOutputRequest> request) { |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 1152 | return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest( |
| 1153 | routing_id_, std::move(request)); |
| 1154 | } |
| 1155 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1156 | /////////////////////////////////////////////////////////////////////////////// |
| 1157 | // RenderWidgetInputHandlerDelegate |
| 1158 | |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1159 | void RenderWidget::FocusChangeComplete() { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1160 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 1161 | if (!frame_widget) |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 1162 | return; |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1163 | |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 1164 | blink::WebLocalFrame* focused = |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1165 | frame_widget->LocalRoot()->View()->FocusedFrame(); |
| 1166 | |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 1167 | if (focused && focused->AutofillClient()) |
| 1168 | focused->AutofillClient()->DidCompleteFocusChangeInFrame(); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1169 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1170 | |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1171 | void RenderWidget::ObserveGestureEventAndResult( |
| 1172 | const blink::WebGestureEvent& gesture_event, |
| 1173 | const gfx::Vector2dF& unused_delta, |
Sandra Sun | ac5cdd83 | 2017-12-11 03:27:13 | [diff] [blame] | 1174 | const cc::OverscrollBehavior& overscroll_behavior, |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1175 | bool event_processed) { |
| 1176 | if (!compositor_deps_->IsElasticOverscrollEnabled()) |
| 1177 | return; |
| 1178 | |
| 1179 | cc::InputHandlerScrollResult scroll_result; |
| 1180 | scroll_result.did_scroll = event_processed; |
| 1181 | scroll_result.did_overscroll_root = !unused_delta.IsZero(); |
| 1182 | scroll_result.unused_scroll_delta = unused_delta; |
Sandra Sun | ac5cdd83 | 2017-12-11 03:27:13 | [diff] [blame] | 1183 | scroll_result.overscroll_behavior = overscroll_behavior; |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1184 | |
| 1185 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 1186 | InputHandlerManager* input_handler_manager = |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 1187 | render_thread ? render_thread->input_handler_manager() : nullptr; |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1188 | if (input_handler_manager) { |
| 1189 | input_handler_manager->ObserveGestureEventAndResultOnMainThread( |
| 1190 | routing_id_, gesture_event, scroll_result); |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 1191 | } else if (widget_input_handler_manager_) { |
| 1192 | widget_input_handler_manager_->ObserveGestureEventOnMainThread( |
| 1193 | gesture_event, scroll_result); |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1197 | void RenderWidget::OnDidHandleKeyEvent() { |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 1198 | ClearEditCommands(); |
| 1199 | } |
| 1200 | |
| 1201 | void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name, |
| 1202 | const std::string& value) { |
| 1203 | ClearEditCommands(); |
| 1204 | edit_commands_.emplace_back(name, value); |
| 1205 | } |
| 1206 | |
| 1207 | void RenderWidget::ClearEditCommands() { |
| 1208 | edit_commands_.clear(); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1209 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1210 | |
chongz | a8ba91fc | 2016-08-16 21:39:17 | [diff] [blame] | 1211 | void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) { |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 1212 | if (widget_input_handler_manager_) { |
Dave Tapuska | 84c09050 | 2017-11-28 18:10:05 | [diff] [blame] | 1213 | if (mojom::WidgetInputHandlerHost* host = |
| 1214 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 1215 | host->DidOverscroll(params); |
| 1216 | } |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 1217 | } else { |
| 1218 | Send(new InputHostMsg_DidOverscroll(routing_id_, params)); |
| 1219 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1220 | } |
| 1221 | |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 1222 | void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { |
| 1223 | // Nothing to do here. RenderWidget created the |input_handler| and will take |
| 1224 | // ownership of it. We just verify here that we don't already have an input |
| 1225 | // handler. |
| 1226 | DCHECK(!input_handler_); |
| 1227 | } |
| 1228 | |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1229 | void RenderWidget::ShowVirtualKeyboard() { |
| 1230 | UpdateTextInputStateInternal(true, false); |
| 1231 | } |
| 1232 | |
changwan | 62f5729 | 2017-02-17 08:28:25 | [diff] [blame] | 1233 | void RenderWidget::ClearTextInputState() { |
| 1234 | text_input_info_ = blink::WebTextInputInfo(); |
| 1235 | text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE; |
| 1236 | text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT; |
| 1237 | can_compose_inline_ = false; |
| 1238 | text_input_flags_ = 0; |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1239 | next_previous_flags_ = kInvalidNextPreviousFlagsValue; |
changwan | 62f5729 | 2017-02-17 08:28:25 | [diff] [blame] | 1240 | } |
| 1241 | |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1242 | void RenderWidget::UpdateTextInputState() { |
| 1243 | UpdateTextInputStateInternal(false, false); |
| 1244 | } |
| 1245 | |
| 1246 | void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard, |
| 1247 | bool reply_to_request) { |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1248 | TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1249 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1250 | if (ime_event_guard_) { |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1251 | DCHECK(!reply_to_request); |
| 1252 | // show_virtual_keyboard should still be effective even if it was set inside |
| 1253 | // the IME |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1254 | // event guard. |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1255 | if (show_virtual_keyboard) |
| 1256 | ime_event_guard_->set_show_virtual_keyboard(true); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1257 | return; |
| 1258 | } |
| 1259 | |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1260 | ui::TextInputType new_type = GetTextInputType(); |
| 1261 | if (IsDateTimeInput(new_type)) |
| 1262 | return; // Not considered as a text input field in WebKit/Chromium. |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1263 | |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1264 | blink::WebTextInputInfo new_info; |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1265 | if (auto* controller = GetInputMethodController()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1266 | new_info = controller->TextInputInfo(); |
dtapuska | c4dd5be | 2016-10-25 15:11:10 | [diff] [blame] | 1267 | const ui::TextInputMode new_mode = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1268 | ConvertWebTextInputMode(new_info.input_mode); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1269 | |
| 1270 | bool new_can_compose_inline = CanComposeInline(); |
| 1271 | |
| 1272 | // Only sends text input params if they are changed or if the ime should be |
| 1273 | // shown. |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1274 | if (show_virtual_keyboard || reply_to_request || |
changwan | 38c3eb61 | 2016-12-09 01:45:56 | [diff] [blame] | 1275 | text_input_type_ != new_type || text_input_mode_ != new_mode || |
| 1276 | text_input_info_ != new_info || |
| 1277 | can_compose_inline_ != new_can_compose_inline) { |
ekaramad | 9053e57b | 2016-04-26 20:00:38 | [diff] [blame] | 1278 | TextInputState params; |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1279 | params.type = new_type; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1280 | params.mode = new_mode; |
| 1281 | params.flags = new_info.flags; |
AJITH KUMAR V | 9e7b557 | 2017-11-14 00:54:21 | [diff] [blame] | 1282 | #if defined(OS_ANDROID) |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1283 | if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) { |
| 1284 | // Due to a focus change, values will be reset by the frame. |
| 1285 | // That case we only need fresh NEXT/PREVIOUS information. |
| 1286 | // Also we won't send ViewHostMsg_TextInputStateChanged if next/previous |
| 1287 | // focusable status is changed. |
| 1288 | if (auto* controller = GetInputMethodController()) { |
| 1289 | next_previous_flags_ = |
| 1290 | controller->ComputeWebTextInputNextPreviousFlags(); |
| 1291 | } else { |
| 1292 | // For safety in case GetInputMethodController() is null, because -1 is |
| 1293 | // invalid value to send to browser process. |
| 1294 | next_previous_flags_ = 0; |
| 1295 | } |
| 1296 | } |
AJITH KUMAR V | 9e7b557 | 2017-11-14 00:54:21 | [diff] [blame] | 1297 | #else |
| 1298 | next_previous_flags_ = 0; |
| 1299 | #endif |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1300 | params.flags |= next_previous_flags_; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1301 | params.value = new_info.value.Utf8(); |
| 1302 | params.selection_start = new_info.selection_start; |
| 1303 | params.selection_end = new_info.selection_end; |
| 1304 | params.composition_start = new_info.composition_start; |
| 1305 | params.composition_end = new_info.composition_end; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1306 | params.can_compose_inline = new_can_compose_inline; |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1307 | // TODO(changwan): change instances of show_ime_if_needed to |
| 1308 | // show_virtual_keyboard. |
| 1309 | params.show_ime_if_needed = show_virtual_keyboard; |
| 1310 | params.reply_to_request = reply_to_request; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1311 | Send(new ViewHostMsg_TextInputStateChanged(routing_id(), params)); |
| 1312 | |
| 1313 | text_input_info_ = new_info; |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1314 | text_input_type_ = new_type; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1315 | text_input_mode_ = new_mode; |
| 1316 | can_compose_inline_ = new_can_compose_inline; |
| 1317 | text_input_flags_ = new_info.flags; |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 1322 | possible_drag_event_info_.event_source = |
| 1323 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 1324 | possible_drag_event_info_.event_location = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1325 | gfx::Point(event.global_x, event.global_y); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1326 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1327 | return false; |
| 1328 | } |
| 1329 | |
| 1330 | bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1331 | for (auto& observer : render_frames_) |
| 1332 | observer.RenderWidgetWillHandleMouseEvent(); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 1333 | |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 1334 | possible_drag_event_info_.event_source = |
| 1335 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 1336 | possible_drag_event_info_.event_location = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1337 | gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y); |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 1338 | |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1339 | if (owner_delegate_) |
| 1340 | return owner_delegate_->RenderWidgetWillHandleMouseEvent(event); |
| 1341 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1342 | return false; |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1343 | } |
| 1344 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1345 | /////////////////////////////////////////////////////////////////////////////// |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1346 | // RenderWidgetScreenMetricsDelegate |
| 1347 | |
| 1348 | void RenderWidget::Redraw() { |
| 1349 | set_next_paint_is_resize_ack(); |
| 1350 | if (compositor_) |
| 1351 | compositor_->SetNeedsRedrawRect(gfx::Rect(size_)); |
| 1352 | } |
| 1353 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1354 | void RenderWidget::ResizeWebWidget() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1355 | GetWebWidget()->Resize(GetSizeForWebWidget()); |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | gfx::Size RenderWidget::GetSizeForWebWidget() const { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1359 | if (IsUseZoomForDSFEnabled()) { |
| 1360 | return gfx::ScaleToCeiledSize(size_, |
| 1361 | GetOriginalScreenInfo().device_scale_factor); |
| 1362 | } |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1363 | |
| 1364 | return size_; |
| 1365 | } |
| 1366 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1367 | void RenderWidget::Resize(const ResizeParams& params) { |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1368 | // The content_source_id that the browser sends us should never be larger than |
| 1369 | // |current_content_source_id_|. |
| 1370 | DCHECK_GE(1u << 30, current_content_source_id_ - params.content_source_id); |
| 1371 | |
Saman Sami | 766e0b0 | 2018-01-31 17:19:20 | [diff] [blame] | 1372 | // If this resize needs to be acked, make sure we ack it only after we commit. |
| 1373 | // It is possible to get DidCommitAndDraw calls that belong to the previous |
| 1374 | // commit, in which case we should not ack this resize. |
| 1375 | if (params.needs_resize_ack) |
| 1376 | did_commit_after_resize_ = false; |
| 1377 | |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1378 | // Inform the rendering thread of the color space indicate the presence of HDR |
| 1379 | // capabilities. |
Miguel Casas | 5e101805 | 2018-01-09 19:17:36 | [diff] [blame] | 1380 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 1381 | if (render_thread) |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1382 | render_thread->SetRenderingColorSpace(params.screen_info.color_space); |
Miguel Casas | 5e101805 | 2018-01-09 19:17:36 | [diff] [blame] | 1383 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1384 | if (resizing_mode_selector_->NeverUsesSynchronousResize()) { |
| 1385 | // A resize ack shouldn't be requested if we have not ACK'd the previous |
| 1386 | // one. |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1387 | DCHECK(!compositor_ || !params.needs_resize_ack || |
| 1388 | !next_paint_is_resize_ack()); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | // Ignore this during shutdown. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1392 | if (!GetWebWidget()) |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1393 | return; |
| 1394 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1395 | // If the content_source_id of ResizeParams doesn't match |
| 1396 | // |current_content_source_id_|, then the given LocalSurfaceId was generated |
| 1397 | // before the navigation. Continue with the resize but don't use the |
| 1398 | // LocalSurfaceId until the right one comes. |
Fady Samuel | a41e9d4 | 2018-03-01 21:31:58 | [diff] [blame] | 1399 | viz::LocalSurfaceId new_local_surface_id; |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1400 | if (params.local_surface_id && |
| 1401 | params.content_source_id == current_content_source_id_) { |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1402 | new_local_surface_id = *params.local_surface_id; |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1403 | } |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1404 | UpdateSurfaceAndScreenInfo(new_local_surface_id, |
| 1405 | params.compositor_viewport_pixel_size, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1406 | params.screen_info); |
ianwen | e5fc578 | 2016-08-18 04:05:15 | [diff] [blame] | 1407 | if (compositor_) { |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 1408 | // If surface synchronization is enabled, then this will use the provided |
fsamuel | ca02c4e | 2017-05-09 13:34:14 | [diff] [blame] | 1409 | // |local_surface_id_| to submit the next generated CompositorFrame. |
| 1410 | // If the ID is not valid, then the compositor will defer commits until |
| 1411 | // it receives a valid surface ID. This is a no-op if surface |
| 1412 | // synchronization is disabled. |
Fady Samuel | 2bb0229 | 2017-10-17 23:59:15 | [diff] [blame] | 1413 | DCHECK(!compositor_->IsSurfaceSynchronizationEnabled() || |
Fady Samuel | a41e9d4 | 2018-03-01 21:31:58 | [diff] [blame] | 1414 | !params.needs_resize_ack || !params.local_surface_id || |
| 1415 | params.local_surface_id->is_valid()); |
Sadrul Habib Chowdhury | 04d5dd4d | 2017-08-10 01:59:27 | [diff] [blame] | 1416 | compositor_->SetBrowserControlsHeight( |
| 1417 | params.top_controls_height, params.bottom_controls_height, |
| 1418 | params.browser_controls_shrink_blink_size); |
| 1419 | compositor_->SetRasterColorSpace( |
| 1420 | screen_info_.color_space.GetRasterColorSpace()); |
ianwen | e5fc578 | 2016-08-18 04:05:15 | [diff] [blame] | 1421 | } |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1422 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1423 | visible_viewport_size_ = params.visible_viewport_size; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1424 | |
| 1425 | // NOTE: We may have entered fullscreen mode without changing our size. |
| 1426 | bool fullscreen_change = |
| 1427 | is_fullscreen_granted_ != params.is_fullscreen_granted; |
| 1428 | is_fullscreen_granted_ = params.is_fullscreen_granted; |
| 1429 | display_mode_ = params.display_mode; |
| 1430 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1431 | size_ = params.new_size; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1432 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1433 | ResizeWebWidget(); |
bokan | 71cb5b1 | 2016-04-27 03:45:22 | [diff] [blame] | 1434 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1435 | WebSize visual_viewport_size; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1436 | if (IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1437 | visual_viewport_size = |
| 1438 | gfx::ScaleToCeiledSize(params.visible_viewport_size, |
| 1439 | GetOriginalScreenInfo().device_scale_factor); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1440 | } else { |
| 1441 | visual_viewport_size = visible_viewport_size_; |
| 1442 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1443 | GetWebWidget()->ResizeVisualViewport(visual_viewport_size); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1444 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1445 | // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 1446 | // ensures that we only resize as fast as we can paint. We only need to |
| 1447 | // send an ACK if we are resized to a non-empty rect. |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1448 | if (params.new_size.IsEmpty() || |
| 1449 | params.compositor_viewport_pixel_size.IsEmpty()) { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1450 | // In this case there is no paint/composite and therefore no |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 1451 | // ViewHostMsg_ResizeOrRepaint_ACK to send the resize ack with. We'd need to |
| 1452 | // send the ack through a fake ViewHostMsg_ResizeOrRepaint_ACK or a |
| 1453 | // different message. |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1454 | DCHECK(!params.needs_resize_ack); |
| 1455 | } |
| 1456 | |
| 1457 | // Send the Resize_ACK flag once we paint again if requested. |
| 1458 | if (params.needs_resize_ack) |
| 1459 | set_next_paint_is_resize_ack(); |
| 1460 | |
| 1461 | if (fullscreen_change) |
| 1462 | DidToggleFullscreen(); |
| 1463 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1464 | // If a resize ack is requested and it isn't set-up, then no more resizes will |
| 1465 | // come in and in general things will go wrong. |
| 1466 | DCHECK(!params.needs_resize_ack || next_paint_is_resize_ack()); |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1467 | |
| 1468 | // If this resize was initiated before navigation and surface synchronization |
| 1469 | // is on, it is not expected to be acked. |
| 1470 | if (compositor_ && compositor_->IsSurfaceSynchronizationEnabled() && |
| 1471 | params.needs_resize_ack && !local_surface_id_.is_valid()) { |
| 1472 | DCHECK_NE(params.content_source_id, current_content_source_id_); |
| 1473 | reset_next_paint_is_resize_ack(); |
| 1474 | } |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | void RenderWidget::SetScreenMetricsEmulationParameters( |
| 1478 | bool enabled, |
| 1479 | const blink::WebDeviceEmulationParams& params) { |
| 1480 | // This is only supported in RenderView. |
| 1481 | NOTREACHED(); |
| 1482 | } |
| 1483 | |
| 1484 | void RenderWidget::SetScreenRects(const gfx::Rect& view_screen_rect, |
| 1485 | const gfx::Rect& window_screen_rect) { |
| 1486 | view_screen_rect_ = view_screen_rect; |
| 1487 | window_screen_rect_ = window_screen_rect; |
| 1488 | } |
| 1489 | |
| 1490 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1491 | // WebWidgetClient |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1493 | blink::WebLayerTreeView* RenderWidget::InitializeLayerTreeView() { |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1494 | DCHECK(!host_closing_); |
| 1495 | |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 1496 | compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); |
| 1497 | auto animation_host = cc::AnimationHost::CreateMainInstance(); |
| 1498 | |
wjmaclean | a755e30 | 2017-04-20 00:43:16 | [diff] [blame] | 1499 | // Oopif status must be set before the LayerTreeHost is created. |
| 1500 | compositor_->SetIsForOopif(for_oopif_); |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 1501 | auto layer_tree_host = RenderWidgetCompositor::CreateLayerTreeHost( |
| 1502 | compositor_.get(), compositor_.get(), animation_host.get(), |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1503 | compositor_deps_, screen_info_); |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 1504 | compositor_->Initialize(std::move(layer_tree_host), |
| 1505 | std::move(animation_host)); |
| 1506 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 1507 | // We can get into this state if surface synchronization is on and the last |
| 1508 | // resize was initiated before navigation, in which case we don't have to ack |
| 1509 | // it. |
| 1510 | if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ && |
| 1511 | next_paint_is_resize_ack() && !local_surface_id_.is_valid()) { |
| 1512 | reset_next_paint_is_resize_ack(); |
| 1513 | } |
| 1514 | |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1515 | UpdateSurfaceAndScreenInfo(local_surface_id_, compositor_viewport_pixel_size_, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1516 | screen_info_); |
ccameron | 0191299 | 2017-05-23 07:34:03 | [diff] [blame] | 1517 | compositor_->SetRasterColorSpace( |
Christopher Cameron | a1ea2b7 | 2017-08-02 01:59:09 | [diff] [blame] | 1518 | screen_info_.color_space.GetRasterColorSpace()); |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 1519 | compositor_->SetContentSourceId(current_content_source_id_); |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 1520 | // For background pages and certain tests, we don't want to trigger |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 1521 | // LayerTreeFrameSink creation. |
dtapuska | b08611f | 2017-04-24 16:10:22 | [diff] [blame] | 1522 | bool should_generate_frame_sink = |
| 1523 | !compositor_never_visible_ && RenderThreadImpl::current(); |
| 1524 | if (!should_generate_frame_sink) |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 1525 | compositor_->SetNeverVisible(); |
| 1526 | |
piman | c4af307 | 2015-10-02 03:45:59 | [diff] [blame] | 1527 | StartCompositor(); |
staraz | 067f5824 | 2016-11-07 21:06:41 | [diff] [blame] | 1528 | DCHECK_NE(MSG_ROUTING_NONE, routing_id_); |
| 1529 | compositor_->SetFrameSinkId( |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 1530 | viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_)); |
loyso | 50b51c2 | 2017-01-10 07:18:37 | [diff] [blame] | 1531 | |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 1532 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 1533 | if (render_thread) { |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 1534 | input_event_queue_ = new MainThreadEventQueue( |
Alexander Timin | bb0860d | 2018-01-29 13:27:16 | [diff] [blame] | 1535 | this, render_thread->GetRendererScheduler()->InputTaskRunner(), |
dtapuska | b08611f | 2017-04-24 16:10:22 | [diff] [blame] | 1536 | render_thread->GetRendererScheduler(), should_generate_frame_sink); |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 1537 | |
| 1538 | InputHandlerManager* input_handler_manager = |
| 1539 | render_thread->input_handler_manager(); |
| 1540 | if (input_handler_manager) { |
| 1541 | input_handler_manager->AddInputHandler( |
| 1542 | routing_id_, compositor()->GetInputHandler(), input_event_queue_, |
| 1543 | weak_ptr_factory_.GetWeakPtr(), |
| 1544 | compositor_deps_->IsScrollAnimatorEnabled()); |
| 1545 | has_added_input_handler_ = true; |
| 1546 | } |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 1547 | } |
| 1548 | |
Khushal | 3e96e66 | 2017-10-30 23:16:50 | [diff] [blame] | 1549 | UpdateURLForCompositorUkm(); |
| 1550 | |
loyso | 50b51c2 | 2017-01-10 07:18:37 | [diff] [blame] | 1551 | return compositor_.get(); |
[email protected] | e195e58 | 2013-03-08 01:32:59 | [diff] [blame] | 1552 | } |
| 1553 | |
Chris Harrelson | d7ab99b | 2018-01-24 17:51:36 | [diff] [blame] | 1554 | void RenderWidget::IntrinsicSizingInfoChanged( |
| 1555 | const blink::WebIntrinsicSizingInfo& sizing_info) { |
| 1556 | Send(new ViewHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info)); |
| 1557 | } |
| 1558 | |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1559 | void RenderWidget::WillCloseLayerTreeView() { |
| 1560 | if (host_closing_) |
| 1561 | return; |
| 1562 | |
| 1563 | // Prevent new compositors or output surfaces from being created. |
| 1564 | host_closing_ = true; |
| 1565 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1566 | // Always send this notification to prevent new layer tree views from |
| 1567 | // being created, even if one hasn't been created yet. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1568 | if (blink::WebWidget* widget = GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1569 | widget->WillCloseLayerTreeView(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1570 | } |
| 1571 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1572 | void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) { |
| 1573 | if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) { |
dglazkov | f0e1d6d | 2015-10-10 02:13:48 | [diff] [blame] | 1574 | QueueMessage(new ViewHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_), |
| 1575 | MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
| 1576 | } |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 1577 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1578 | for (auto& observer : render_frames_) |
| 1579 | observer.DidMeaningfulLayout(layout_type); |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 1580 | } |
| 1581 | |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1582 | // static |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1583 | std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1584 | IPC::Message* msg, |
| 1585 | MessageDeliveryPolicy policy, |
| 1586 | FrameSwapMessageQueue* frame_swap_message_queue, |
| 1587 | scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1588 | int source_frame_number) { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1589 | bool first_message_for_frame = false; |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1590 | frame_swap_message_queue->QueueMessageForFrame(policy, source_frame_number, |
| 1591 | base::WrapUnique(msg), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1592 | &first_message_for_frame); |
| 1593 | if (first_message_for_frame) { |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1594 | std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1595 | sync_message_filter, frame_swap_message_queue, source_frame_number)); |
dcheng | 4b6b5ff | 2014-10-16 00:42:06 | [diff] [blame] | 1596 | return promise; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1597 | } |
dcheng | 4b6b5ff | 2014-10-16 00:42:06 | [diff] [blame] | 1598 | return nullptr; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | void RenderWidget::QueueMessage(IPC::Message* msg, |
| 1602 | MessageDeliveryPolicy policy) { |
| 1603 | // RenderThreadImpl::current() is NULL in some tests. |
| 1604 | if (!compositor_ || !RenderThreadImpl::current()) { |
| 1605 | Send(msg); |
| 1606 | return; |
| 1607 | } |
| 1608 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1609 | std::unique_ptr<cc::SwapPromise> swap_promise = |
| 1610 | QueueMessageImpl(msg, policy, frame_swap_message_queue_.get(), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1611 | RenderThreadImpl::current()->sync_message_filter(), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1612 | compositor_->GetSourceFrameNumber()); |
| 1613 | |
Ken Buchanan | ce710eb | 2017-08-30 23:46:52 | [diff] [blame] | 1614 | if (swap_promise) |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 1615 | compositor_->QueueSwapPromise(std::move(swap_promise)); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1616 | } |
| 1617 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1618 | void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 1619 | // TODO(darin): Eliminate this temporary. |
[email protected] | 9ec8771 | 2013-05-24 23:23:52 | [diff] [blame] | 1620 | WebCursor cursor; |
tfarina | 75a0abf | 2015-10-06 15:07:18 | [diff] [blame] | 1621 | InitializeCursorFromWebCursorInfo(&cursor, cursor_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1622 | // Only send a SetCursor message if we need to make a change. |
| 1623 | if (!current_cursor_.IsEqual(cursor)) { |
| 1624 | current_cursor_ = cursor; |
| 1625 | Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| 1626 | } |
| 1627 | } |
| 1628 | |
aelias | 5971e47d | 2017-06-16 02:39:38 | [diff] [blame] | 1629 | void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) { |
| 1630 | Send(new ViewHostMsg_AutoscrollStart(routing_id_, point)); |
| 1631 | } |
| 1632 | |
| 1633 | void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) { |
| 1634 | Send(new ViewHostMsg_AutoscrollFling(routing_id_, velocity)); |
| 1635 | } |
| 1636 | |
| 1637 | void RenderWidget::AutoscrollEnd() { |
| 1638 | Send(new ViewHostMsg_AutoscrollEnd(routing_id_)); |
| 1639 | } |
| 1640 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1641 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 1642 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 1643 | // point to dispatch the ShowWidget message. |
| 1644 | // |
| 1645 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1646 | // created RenderWidget (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1647 | // |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1648 | void RenderWidget::Show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1649 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1650 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1651 | DCHECK(!show_callback_.is_null()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1652 | |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1653 | if (did_show_) |
| 1654 | return; |
| 1655 | |
| 1656 | did_show_ = true; |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1657 | |
| 1658 | // The opener is responsible for actually showing this widget. |
| 1659 | show_callback_.Run(this, policy, initial_rect_); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 1660 | show_callback_.Reset(); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1661 | |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1662 | // NOTE: initial_rect_ may still have its default values at this point, but |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1663 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 1664 | // process will impose a default position otherwise. |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1665 | SetPendingWindowRect(initial_rect_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1666 | } |
| 1667 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1668 | void RenderWidget::DoDeferredClose() { |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1669 | WillCloseLayerTreeView(); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1670 | Send(new ViewHostMsg_Close(routing_id_)); |
| 1671 | } |
| 1672 | |
dgozman | cf9039cd | 2015-04-06 12:01:31 | [diff] [blame] | 1673 | void RenderWidget::NotifyOnClose() { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1674 | for (auto& observer : render_frames_) |
| 1675 | observer.WidgetWillClose(); |
dgozman | cf9039cd | 2015-04-06 12:01:31 | [diff] [blame] | 1676 | } |
| 1677 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1678 | void RenderWidget::CloseWidgetSoon() { |
skyostil | ed8969c | 2015-07-20 16:57:08 | [diff] [blame] | 1679 | DCHECK(content::RenderThread::Get()); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 1680 | if (is_swapped_out_) { |
| 1681 | // This widget is currently swapped out, and the active widget is in a |
| 1682 | // different process. Have the browser route the close request to the |
| 1683 | // active widget instead, so that the correct unload handlers are run. |
| 1684 | Send(new ViewHostMsg_RouteCloseEvent(routing_id_)); |
| 1685 | return; |
| 1686 | } |
| 1687 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1688 | // If a page calls window.close() twice, we'll end up here twice, but that's |
| 1689 | // OK. It is safe to send multiple Close messages. |
| 1690 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1691 | // Ask the RenderWidgetHost to initiate close. We could be called from deep |
| 1692 | // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
| 1693 | // could be closed before the JS finishes executing. So instead, post a |
| 1694 | // message back to the message loop, which won't run until the JS is |
| 1695 | // complete, and then the Close message can be sent. |
Hajime Hoshi | abb3c8f | 2017-12-04 18:41:39 | [diff] [blame] | 1696 | task_runner_->PostTask(FROM_HERE, |
| 1697 | base::BindOnce(&RenderWidget::DoDeferredClose, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void RenderWidget::Close() { |
[email protected] | 404630b | 2014-07-03 19:33:03 | [diff] [blame] | 1701 | screen_metrics_emulator_.reset(); |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1702 | CloseWebWidget(); |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1703 | compositor_.reset(); |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | void RenderWidget::CloseWebWidget() { |
| 1707 | WillCloseLayerTreeView(); |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1708 | if (webwidget_internal_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1709 | webwidget_internal_->Close(); |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1710 | webwidget_internal_ = nullptr; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1714 | void RenderWidget::UpdateWebViewWithDeviceScaleFactor() { |
| 1715 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 1716 | blink::WebFrame* current_frame = |
| 1717 | frame_widget ? frame_widget->LocalRoot() : nullptr; |
| 1718 | blink::WebView* webview = current_frame ? current_frame->View() : nullptr; |
| 1719 | if (webview) { |
| 1720 | if (IsUseZoomForDSFEnabled()) |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1721 | webview->SetZoomFactorForDeviceScaleFactor( |
| 1722 | GetWebScreenInfo().device_scale_factor); |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1723 | else |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1724 | webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor); |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1725 | |
| 1726 | webview->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1727 | PreferCompositingToLCDText(compositor_deps_, |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1728 | GetWebScreenInfo().device_scale_factor)); |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1732 | blink::WebFrameWidget* RenderWidget::GetFrameWidget() const { |
| 1733 | blink::WebWidget* web_widget = GetWebWidget(); |
| 1734 | if (!web_widget) |
| 1735 | return nullptr; |
| 1736 | |
| 1737 | if (!web_widget->IsWebFrameWidget()) { |
| 1738 | // TODO(ekaramad): This should not happen. If we have a WebWidget and we |
| 1739 | // need a WebFrameWidget then we should be getting a WebFrameWidget. But |
| 1740 | // unfortunately this does not seem to be the case in some scenarios -- |
| 1741 | // specifically when a RenderViewImpl swaps out during navigation the |
| 1742 | // WebViewImpl loses its WebViewFrameWidget but sometimes we receive IPCs |
| 1743 | // which are destined for WebFrameWidget (https://crbug.com/669219). |
| 1744 | return nullptr; |
| 1745 | } |
| 1746 | |
| 1747 | return static_cast<blink::WebFrameWidget*>(web_widget); |
| 1748 | } |
| 1749 | |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1750 | void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const { |
| 1751 | DCHECK(window_rect); |
| 1752 | float scale = popup_origin_scale_for_emulation_; |
| 1753 | if (!scale) |
| 1754 | return; |
| 1755 | window_rect->x = |
| 1756 | popup_view_origin_for_emulation_.x() + |
| 1757 | (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale; |
| 1758 | window_rect->y = |
| 1759 | popup_view_origin_for_emulation_.y() + |
| 1760 | (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale; |
| 1761 | } |
| 1762 | |
| 1763 | void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const { |
| 1764 | DCHECK(window_rect); |
| 1765 | float scale = popup_origin_scale_for_emulation_; |
| 1766 | if (!scale) |
| 1767 | return; |
| 1768 | window_rect->x = |
| 1769 | popup_screen_origin_for_emulation_.x() + |
| 1770 | (window_rect->x - popup_view_origin_for_emulation_.x()) * scale; |
| 1771 | window_rect->y = |
| 1772 | popup_screen_origin_for_emulation_.y() + |
| 1773 | (window_rect->y - popup_view_origin_for_emulation_.y()) * scale; |
| 1774 | } |
| 1775 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1776 | WebRect RenderWidget::WindowRect() { |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1777 | WebRect rect; |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1778 | if (pending_window_rect_count_) { |
| 1779 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 1780 | // the RootWindowRect is probably going to return wrong results since the |
| 1781 | // browser may not have processed the Move yet. There isn't really anything |
| 1782 | // good to do in this case, and it shouldn't happen - since this size is |
| 1783 | // only really needed for windowToScreen, which is only used for Popups. |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1784 | rect = pending_window_rect_; |
| 1785 | } else { |
| 1786 | rect = window_screen_rect_; |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1787 | } |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1788 | |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1789 | ScreenRectToEmulatedIfNeeded(&rect); |
| 1790 | return rect; |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1791 | } |
| 1792 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1793 | WebRect RenderWidget::ViewRect() { |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1794 | WebRect rect = view_screen_rect_; |
| 1795 | ScreenRectToEmulatedIfNeeded(&rect); |
| 1796 | return rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1797 | } |
| 1798 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1799 | void RenderWidget::SetToolTipText(const blink::WebString& text, |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1800 | WebTextDirection hint) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1801 | Send(new ViewHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint)); |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1802 | } |
| 1803 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1804 | void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) { |
oshima | 33ec97cd | 2015-12-14 19:40:24 | [diff] [blame] | 1805 | WebRect window_rect = rect_in_screen; |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1806 | EmulatedToScreenRectIfNeeded(&window_rect); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1807 | |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 1808 | if (!resizing_mode_selector_->is_synchronous_mode()) { |
[email protected] | ec951b9d | 2013-10-20 06:21:20 | [diff] [blame] | 1809 | if (did_show_) { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1810 | Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); |
| 1811 | SetPendingWindowRect(window_rect); |
[email protected] | 8be1c58 | 2013-03-06 00:55:03 | [diff] [blame] | 1812 | } else { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1813 | initial_rect_ = window_rect; |
[email protected] | 8be1c58 | 2013-03-06 00:55:03 | [diff] [blame] | 1814 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1815 | } else { |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1816 | SetWindowRectSynchronously(window_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1820 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 1821 | pending_window_rect_ = rect; |
| 1822 | pending_window_rect_count_++; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1823 | |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1824 | // Popups don't get size updates back from the browser so just store the set |
| 1825 | // values. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1826 | if (popup_type_ != blink::kWebPopupTypeNone) { |
| 1827 | window_screen_rect_ = rect; |
| 1828 | view_screen_rect_ = rect; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1829 | } |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 1830 | } |
| 1831 | |
wjmaclean | ee244e0 | 2017-05-26 21:06:07 | [diff] [blame] | 1832 | void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type, |
| 1833 | const gfx::Point& location) { |
wjmaclean | ee244e0 | 2017-05-26 21:06:07 | [diff] [blame] | 1834 | has_host_context_menu_location_ = true; |
| 1835 | host_context_menu_location_ = location; |
| 1836 | if (GetWebWidget()) { |
| 1837 | GetWebWidget()->ShowContextMenu( |
| 1838 | static_cast<blink::WebMenuSourceType>(source_type)); |
| 1839 | } |
| 1840 | has_host_context_menu_location_ = false; |
| 1841 | } |
| 1842 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1843 | void RenderWidget::OnImeSetComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1844 | const base::string16& text, |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1845 | const std::vector<WebImeTextSpan>& ime_text_spans, |
chongz | 7eb75280 | 2016-01-27 21:28:07 | [diff] [blame] | 1846 | const gfx::Range& replacement_range, |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1847 | int selection_start, |
| 1848 | int selection_end) { |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1849 | if (!ShouldHandleImeEvents()) |
| 1850 | return; |
| 1851 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1852 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1853 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1854 | plugin->render_frame()->OnImeSetComposition(text, ime_text_spans, |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1855 | selection_start, selection_end); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 1856 | return; |
| 1857 | } |
| 1858 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1859 | ImeEventGuard guard(this); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1860 | blink::WebInputMethodController* controller = GetInputMethodController(); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1861 | if (!controller || |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1862 | !controller->SetComposition( |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1863 | WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans), |
ekaramad | ce32ef9f | 2017-02-09 17:33:56 | [diff] [blame] | 1864 | replacement_range.IsValid() |
| 1865 | ? WebRange(replacement_range.start(), replacement_range.length()) |
| 1866 | : WebRange(), |
| 1867 | selection_start, selection_end)) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1868 | // If we failed to set the composition text, then we need to let the browser |
| 1869 | // process to cancel the input method's ongoing composition session, to make |
| 1870 | // sure we are in a consistent state. |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 1871 | if (widget_input_handler_manager_) { |
Dave Tapuska | 84c09050 | 2017-11-28 18:10:05 | [diff] [blame] | 1872 | if (mojom::WidgetInputHandlerHost* host = |
| 1873 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 1874 | host->ImeCancelComposition(); |
| 1875 | } |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 1876 | } else { |
| 1877 | Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1878 | } |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame] | 1879 | } |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 1880 | UpdateCompositionInfo(false /* not an immediate request */); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1881 | } |
| 1882 | |
rlanday | 7efe230 | 2017-01-11 00:14:28 | [diff] [blame] | 1883 | void RenderWidget::OnImeCommitText( |
| 1884 | const base::string16& text, |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1885 | const std::vector<WebImeTextSpan>& ime_text_spans, |
rlanday | 7efe230 | 2017-01-11 00:14:28 | [diff] [blame] | 1886 | const gfx::Range& replacement_range, |
| 1887 | int relative_cursor_pos) { |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1888 | if (!ShouldHandleImeEvents()) |
| 1889 | return; |
| 1890 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1891 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1892 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
| 1893 | plugin->render_frame()->OnImeCommitText(text, replacement_range, |
| 1894 | relative_cursor_pos); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 1895 | return; |
| 1896 | } |
| 1897 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1898 | ImeEventGuard guard(this); |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 1899 | input_handler_->set_handling_input_event(true); |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 1900 | if (auto* controller = GetInputMethodController()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1901 | controller->CommitText( |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1902 | WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans), |
ekaramad | ce32ef9f | 2017-02-09 17:33:56 | [diff] [blame] | 1903 | replacement_range.IsValid() |
| 1904 | ? WebRange(replacement_range.start(), replacement_range.length()) |
| 1905 | : WebRange(), |
| 1906 | relative_cursor_pos); |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 1907 | } |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 1908 | input_handler_->set_handling_input_event(false); |
| 1909 | UpdateCompositionInfo(false /* not an immediate request */); |
| 1910 | } |
| 1911 | |
| 1912 | void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1913 | if (!ShouldHandleImeEvents()) |
| 1914 | return; |
| 1915 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1916 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1917 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
| 1918 | plugin->render_frame()->OnImeFinishComposingText(keep_selection); |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 1919 | return; |
| 1920 | } |
| 1921 | #endif |
| 1922 | |
changwan | 38c3eb61 | 2016-12-09 01:45:56 | [diff] [blame] | 1923 | if (!GetWebWidget()) |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 1924 | return; |
| 1925 | ImeEventGuard guard(this); |
| 1926 | input_handler_->set_handling_input_event(true); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1927 | if (auto* controller = GetInputMethodController()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1928 | controller->FinishComposingText( |
| 1929 | keep_selection ? WebInputMethodController::kKeepSelection |
| 1930 | : WebInputMethodController::kDoNotKeepSelection); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1931 | } |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 1932 | input_handler_->set_handling_input_event(false); |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 1933 | UpdateCompositionInfo(false /* not an immediate request */); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1934 | } |
| 1935 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1936 | void RenderWidget::UpdateSurfaceAndScreenInfo( |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1937 | viz::LocalSurfaceId new_local_surface_id, |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1938 | const gfx::Size& new_compositor_viewport_pixel_size, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1939 | const ScreenInfo& new_screen_info) { |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1940 | bool orientation_changed = |
| 1941 | screen_info_.orientation_angle != new_screen_info.orientation_angle || |
| 1942 | screen_info_.orientation_type != new_screen_info.orientation_type; |
| 1943 | bool web_device_scale_factor_changed = |
| 1944 | screen_info_.device_scale_factor != new_screen_info.device_scale_factor; |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1945 | ScreenInfo previous_original_screen_info = GetOriginalScreenInfo(); |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1946 | |
| 1947 | local_surface_id_ = new_local_surface_id; |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1948 | compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size; |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1949 | screen_info_ = new_screen_info; |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1950 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1951 | if (compositor_) { |
| 1952 | // Note carefully that the DSF specified in |new_screen_info| is not the |
| 1953 | // DSF used by the compositor during device emulation! |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1954 | compositor_->SetViewportSizeAndScale( |
| 1955 | compositor_viewport_pixel_size_, |
| 1956 | GetOriginalScreenInfo().device_scale_factor, local_surface_id_); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1957 | } |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1958 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1959 | if (orientation_changed) |
| 1960 | OnOrientationChange(); |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1961 | |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1962 | if (previous_original_screen_info != GetOriginalScreenInfo()) { |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1963 | for (auto& observer : render_frame_proxies_) |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1964 | observer.OnScreenInfoChanged(GetOriginalScreenInfo()); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1965 | |
| 1966 | // Notify all embedded BrowserPlugins of the updated ScreenInfo. |
| 1967 | for (auto& observer : browser_plugins_) |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 1968 | observer.ScreenInfoChanged(GetOriginalScreenInfo()); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | if (web_device_scale_factor_changed) |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1972 | UpdateWebViewWithDeviceScaleFactor(); |
oshima | d527903 | 2015-12-16 18:22:33 | [diff] [blame] | 1973 | } |
| 1974 | |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 1975 | void RenderWidget::OnRepaint(gfx::Size size_to_paint) { |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1976 | // During shutdown we can just ignore this message. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1977 | if (!GetWebWidget()) |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1978 | return; |
| 1979 | |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 1980 | // Even if the browser provides an empty damage rect, it's still expecting to |
| 1981 | // receive a repaint ack so just damage the entire widget bounds. |
| 1982 | if (size_to_paint.IsEmpty()) { |
| 1983 | size_to_paint = size_; |
| 1984 | } |
| 1985 | |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1986 | set_next_paint_is_repaint_ack(); |
[email protected] | aca33f4f | 2014-05-17 17:08:05 | [diff] [blame] | 1987 | if (compositor_) |
[email protected] | 0bc1f57 | 2013-04-17 01:46:31 | [diff] [blame] | 1988 | compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint)); |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1989 | } |
| 1990 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1991 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 1992 | if (auto* frame = GetFocusedWebLocalFrameInWidget()) |
| 1993 | frame->SetTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1994 | } |
| 1995 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1996 | void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect, |
| 1997 | const gfx::Rect& window_screen_rect) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1998 | if (screen_metrics_emulator_) { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1999 | screen_metrics_emulator_->OnUpdateScreenRects(view_screen_rect, |
| 2000 | window_screen_rect); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 2001 | } else { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 2002 | SetScreenRects(view_screen_rect, window_screen_rect); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 2003 | } |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 2004 | Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id())); |
| 2005 | } |
| 2006 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 2007 | void RenderWidget::OnUpdateWindowScreenRect( |
| 2008 | const gfx::Rect& window_screen_rect) { |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 2009 | if (screen_metrics_emulator_) |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 2010 | screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect); |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 2011 | else |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 2012 | window_screen_rect_ = window_screen_rect; |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 2013 | } |
| 2014 | |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 2015 | void RenderWidget::OnSetViewportIntersection( |
| 2016 | const gfx::Rect& viewport_intersection) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2017 | if (auto* frame_widget = GetFrameWidget()) { |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2018 | DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone); |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2019 | frame_widget->SetRemoteViewportIntersection(viewport_intersection); |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 2020 | } |
| 2021 | } |
| 2022 | |
kenrb | 0432378 | 2017-06-23 01:23:32 | [diff] [blame] | 2023 | void RenderWidget::OnSetIsInert(bool inert) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2024 | if (auto* frame_widget = GetFrameWidget()) { |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2025 | DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone); |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2026 | frame_widget->SetIsInert(inert); |
kenrb | 0432378 | 2017-06-23 01:23:32 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2030 | void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled, |
| 2031 | bool subtree_throttled) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2032 | if (auto* frame_widget = GetFrameWidget()) { |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2033 | DCHECK_EQ(popup_type_, WebPopupType::kWebPopupTypeNone); |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2034 | frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled); |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2038 | void RenderWidget::OnDragTargetDragEnter( |
| 2039 | const std::vector<DropData::Metadata>& drop_meta_data, |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2040 | const gfx::PointF& client_point, |
| 2041 | const gfx::PointF& screen_point, |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2042 | WebDragOperationsMask ops, |
| 2043 | int key_modifiers) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2044 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2045 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2046 | return; |
| 2047 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2048 | WebDragOperation operation = frame_widget->DragTargetDragEnter( |
| 2049 | DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point, |
| 2050 | ops, key_modifiers); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2051 | |
| 2052 | Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation)); |
| 2053 | } |
| 2054 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2055 | void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point, |
| 2056 | const gfx::PointF& screen_point, |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2057 | WebDragOperationsMask ops, |
| 2058 | int key_modifiers) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2059 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2060 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2061 | return; |
| 2062 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2063 | WebDragOperation operation = frame_widget->DragTargetDragOver( |
| 2064 | ConvertWindowPointToViewport(client_point), screen_point, ops, |
| 2065 | key_modifiers); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2066 | |
| 2067 | Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation)); |
| 2068 | } |
| 2069 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2070 | void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point, |
| 2071 | const gfx::PointF& screen_point) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2072 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2073 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2074 | return; |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2075 | |
| 2076 | frame_widget |
| 2077 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2078 | ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point), |
kenrb | 07c27280 | 2017-02-07 23:48:17 | [diff] [blame] | 2079 | screen_point); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | void RenderWidget::OnDragTargetDrop(const DropData& drop_data, |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2083 | const gfx::PointF& client_point, |
| 2084 | const gfx::PointF& screen_point, |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2085 | int key_modifiers) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2086 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2087 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2088 | return; |
| 2089 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2090 | frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data), |
| 2091 | ConvertWindowPointToViewport(client_point), |
| 2092 | screen_point, key_modifiers); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2093 | } |
| 2094 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2095 | void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point, |
| 2096 | const gfx::PointF& screen_point, |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2097 | WebDragOperation op) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2098 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2099 | if (!frame_widget) |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2100 | return; |
| 2101 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2102 | frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point), |
| 2103 | screen_point, op); |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | void RenderWidget::OnDragSourceSystemDragEnded() { |
| 2107 | if (!GetWebWidget()) |
| 2108 | return; |
| 2109 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2110 | static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded(); |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2111 | } |
| 2112 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2113 | void RenderWidget::ShowVirtualKeyboardOnElementFocus() { |
oka | a398f50b | 2017-03-21 06:30:26 | [diff] [blame] | 2114 | #if defined(OS_CHROMEOS) |
| 2115 | // On ChromeOS, virtual keyboard is triggered only when users leave the |
| 2116 | // mouse button or the finger and a text input element is focused at that |
| 2117 | // time. Focus event itself shouldn't trigger virtual keyboard. |
| 2118 | UpdateTextInputState(); |
| 2119 | #else |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2120 | ShowVirtualKeyboard(); |
oka | a398f50b | 2017-03-21 06:30:26 | [diff] [blame] | 2121 | #endif |
boliu | 7b2be2f | 2016-11-04 04:58:31 | [diff] [blame] | 2122 | |
| 2123 | // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
| 2124 | // virtual keyboard. |
| 2125 | #if !defined(OS_ANDROID) |
| 2126 | FocusChangeComplete(); |
| 2127 | #endif |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 2128 | } |
| 2129 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2130 | ui::TextInputType RenderWidget::GetTextInputType() { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2131 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2132 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) |
| 2133 | return plugin->text_input_type(); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2134 | #endif |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 2135 | if (auto* controller = GetInputMethodController()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2136 | return ConvertWebTextInputType(controller->TextInputType()); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2137 | return ui::TEXT_INPUT_TYPE_NONE; |
| 2138 | } |
| 2139 | |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2140 | void RenderWidget::UpdateCompositionInfo(bool immediate_request) { |
| 2141 | if (!monitor_composition_info_ && !immediate_request) |
| 2142 | return; // Do not calculate composition info if not requested. |
nona | dac0c7a | 2016-08-01 02:30:59 | [diff] [blame] | 2143 | |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2144 | TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
| 2145 | gfx::Range range; |
| 2146 | std::vector<gfx::Rect> character_bounds; |
| 2147 | |
| 2148 | if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 2149 | // Composition information is only available on editable node. |
| 2150 | range = gfx::Range::InvalidRange(); |
| 2151 | } else { |
| 2152 | GetCompositionRange(&range); |
| 2153 | GetCompositionCharacterBounds(&character_bounds); |
| 2154 | } |
| 2155 | |
| 2156 | if (!immediate_request && |
| 2157 | !ShouldUpdateCompositionInfo(range, character_bounds)) { |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2158 | return; |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2159 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2160 | composition_character_bounds_ = character_bounds; |
| 2161 | composition_range_ = range; |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 2162 | if (widget_input_handler_manager_) { |
Dave Tapuska | 84c09050 | 2017-11-28 18:10:05 | [diff] [blame] | 2163 | if (mojom::WidgetInputHandlerHost* host = |
| 2164 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 2165 | host->ImeCompositionRangeChanged(composition_range_, |
| 2166 | composition_character_bounds_); |
| 2167 | } |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 2168 | } else { |
| 2169 | Send(new InputHostMsg_ImeCompositionRangeChanged( |
| 2170 | routing_id(), composition_range_, composition_character_bounds_)); |
| 2171 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2172 | } |
| 2173 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2174 | void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) { |
oshima | f866dab | 2015-12-05 00:41:54 | [diff] [blame] | 2175 | if (IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2176 | float reverse = 1 / GetOriginalScreenInfo().device_scale_factor; |
oshima | d527903 | 2015-12-16 18:22:33 | [diff] [blame] | 2177 | // TODO(oshima): We may need to allow pixel precision here as the the |
oshima | f866dab | 2015-12-05 00:41:54 | [diff] [blame] | 2178 | // anchor element can be placed at half pixel. |
lfg | 15b235a3 | 2016-08-25 17:45:46 | [diff] [blame] | 2179 | gfx::Rect window_rect = |
| 2180 | gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse); |
| 2181 | rect->x = window_rect.x(); |
| 2182 | rect->y = window_rect.y(); |
| 2183 | rect->width = window_rect.width(); |
| 2184 | rect->height = window_rect.height(); |
oshima | f866dab | 2015-12-05 00:41:54 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2188 | void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) { |
oshima | a6985b6 | 2016-01-27 08:58:30 | [diff] [blame] | 2189 | if (IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2190 | rect->x *= GetOriginalScreenInfo().device_scale_factor; |
| 2191 | rect->y *= GetOriginalScreenInfo().device_scale_factor; |
| 2192 | rect->width *= GetOriginalScreenInfo().device_scale_factor; |
| 2193 | rect->height *= GetOriginalScreenInfo().device_scale_factor; |
oshima | a6985b6 | 2016-01-27 08:58:30 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
changwan | 8c34274 | 2016-02-26 00:53:39 | [diff] [blame] | 2197 | void RenderWidget::OnRequestTextInputStateUpdate() { |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 2198 | #if defined(OS_ANDROID) |
changwan | 8c34274 | 2016-02-26 00:53:39 | [diff] [blame] | 2199 | DCHECK(!ime_event_guard_); |
| 2200 | UpdateSelectionBounds(); |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2201 | UpdateTextInputStateInternal(false, true /* reply_to_request */); |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 2202 | #endif |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 2203 | } |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 2204 | |
ekaramad | c9b70a7 | 2017-03-23 16:14:23 | [diff] [blame] | 2205 | void RenderWidget::OnRequestCompositionUpdates(bool immediate_request, |
| 2206 | bool monitor_updates) { |
| 2207 | monitor_composition_info_ = monitor_updates; |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2208 | if (!immediate_request) |
| 2209 | return; |
| 2210 | UpdateCompositionInfo(true /* immediate request */); |
| 2211 | } |
| 2212 | |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 2213 | void RenderWidget::OnOrientationChange() { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2214 | if (auto* frame_widget = GetFrameWidget()) { |
Alex Moshchuk | 0b409c4 | 2017-09-13 02:09:00 | [diff] [blame] | 2215 | // LocalRoot() might return null for provisional main frames. In this case, |
| 2216 | // the frame hasn't committed a navigation and is not swapped into the tree |
| 2217 | // yet, so it doesn't make sense to send orientation change events to it. |
| 2218 | // |
| 2219 | // TODO(https://crbug.com/578349): This check should be cleaned up |
| 2220 | // once provisional frames are gone. |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2221 | if (frame_widget->LocalRoot()) |
| 2222 | frame_widget->LocalRoot()->SendOrientationChangeEvent(); |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 2223 | } |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 2224 | } |
| 2225 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 2226 | void RenderWidget::SetHidden(bool hidden) { |
| 2227 | if (is_hidden_ == hidden) |
| 2228 | return; |
| 2229 | |
jdduke | 8fac9d10 | 2014-12-20 02:40:13 | [diff] [blame] | 2230 | // The status has changed. Tell the RenderThread about it and ensure |
| 2231 | // throttled acks are released in case frame production ceases. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 2232 | is_hidden_ = hidden; |
jdduke | 8fac9d10 | 2014-12-20 02:40:13 | [diff] [blame] | 2233 | |
Scott Violet | 1098538e | 2017-10-05 19:23:33 | [diff] [blame] | 2234 | #if defined(USE_AURA) |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 2235 | if (features::IsMusEnabled()) |
Scott Violet | 1098538e | 2017-10-05 19:23:33 | [diff] [blame] | 2236 | RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden); |
| 2237 | #endif |
| 2238 | |
Saman Sami | 58ed439 | 2018-01-31 20:54:19 | [diff] [blame] | 2239 | // RenderThreadImpl::current() could be null in tests. |
| 2240 | if (RenderThreadImpl::current()) { |
| 2241 | if (is_hidden_) { |
| 2242 | RenderThreadImpl::current()->WidgetHidden(); |
| 2243 | first_update_visual_state_after_hidden_ = true; |
| 2244 | } else { |
| 2245 | RenderThreadImpl::current()->WidgetRestored(); |
| 2246 | } |
Lei Zhang | 9b359d3 | 2017-11-28 00:57:02 | [diff] [blame] | 2247 | } |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 2248 | |
| 2249 | if (render_widget_scheduling_state_) |
| 2250 | render_widget_scheduling_state_->SetHidden(hidden); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 2251 | } |
| 2252 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2253 | void RenderWidget::DidToggleFullscreen() { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2254 | if (!GetWebWidget()) |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2255 | return; |
| 2256 | |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 2257 | if (is_fullscreen_granted_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2258 | GetWebWidget()->DidEnterFullscreen(); |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2259 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2260 | GetWebWidget()->DidExitFullscreen(); |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2261 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2262 | } |
| 2263 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 2264 | bool RenderWidget::next_paint_is_resize_ack() const { |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 2265 | return ViewHostMsg_ResizeOrRepaint_ACK_Flags::is_resize_ack( |
| 2266 | next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 2267 | } |
| 2268 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 2269 | void RenderWidget::set_next_paint_is_resize_ack() { |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 2270 | next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 2271 | } |
| 2272 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 2273 | void RenderWidget::set_next_paint_is_repaint_ack() { |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 2274 | next_paint_flags_ |= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_REPAINT_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 2275 | } |
| 2276 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 2277 | void RenderWidget::reset_next_paint_is_resize_ack() { |
| 2278 | DCHECK(next_paint_is_resize_ack()); |
| 2279 | next_paint_flags_ ^= ViewHostMsg_ResizeOrRepaint_ACK_Flags::IS_RESIZE_ACK; |
| 2280 | } |
| 2281 | |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2282 | void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
| 2283 | if (!ime_event_guard_) |
| 2284 | ime_event_guard_ = guard; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2285 | } |
| 2286 | |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2287 | void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
| 2288 | if (ime_event_guard_ != guard) { |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2289 | DCHECK(!ime_event_guard_->reply_to_request()); |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2290 | return; |
| 2291 | } |
| 2292 | ime_event_guard_ = nullptr; |
| 2293 | |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2294 | // While handling an ime event, text input state and selection bounds updates |
| 2295 | // are ignored. These must explicitly be updated once finished handling the |
| 2296 | // ime event. |
| 2297 | UpdateSelectionBounds(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2298 | #if defined(OS_ANDROID) |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2299 | if (guard->show_virtual_keyboard()) |
| 2300 | ShowVirtualKeyboard(); |
| 2301 | else |
| 2302 | UpdateTextInputState(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2303 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2304 | } |
| 2305 | |
[email protected] | 7c8873e | 2013-02-05 08:03:01 | [diff] [blame] | 2306 | void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2307 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2308 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2309 | // TODO(kinaba) http://crbug.com/101101 |
| 2310 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 2311 | // use the caret position as an empty range for now. It will be updated |
| 2312 | // after Pepper API equips features related to surrounding text retrieval. |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2313 | blink::WebRect caret(plugin->GetCaretBounds()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2314 | ConvertViewportToWindow(&caret); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2315 | *focus = caret; |
| 2316 | *anchor = caret; |
| 2317 | return; |
| 2318 | } |
| 2319 | #endif |
[email protected] | 7c8873e | 2013-02-05 08:03:01 | [diff] [blame] | 2320 | WebRect focus_webrect; |
| 2321 | WebRect anchor_webrect; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2322 | GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect); |
| 2323 | ConvertViewportToWindow(&focus_webrect); |
| 2324 | ConvertViewportToWindow(&anchor_webrect); |
oshima | 33ec97cd | 2015-12-14 19:40:24 | [diff] [blame] | 2325 | *focus = focus_webrect; |
| 2326 | *anchor = anchor_webrect; |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 2327 | } |
| 2328 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2329 | void RenderWidget::UpdateSelectionBounds() { |
jdduke | 1aebad8e | 2015-07-22 23:25:08 | [diff] [blame] | 2330 | TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2331 | if (!GetWebWidget()) |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2332 | return; |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2333 | if (ime_event_guard_) |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2334 | return; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2335 | |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 2336 | #if defined(USE_AURA) |
| 2337 | // TODO(mohsen): For now, always send explicit selection IPC notifications for |
| 2338 | // Aura beucause composited selection updates are not working for webview tags |
| 2339 | // which regresses IME inside webview. Remove this when composited selection |
| 2340 | // updates are fixed for webviews. See, http://crbug.com/510568. |
| 2341 | bool send_ipc = true; |
| 2342 | #else |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2343 | // With composited selection updates, the selection bounds will be reported |
| 2344 | // directly by the compositor, in which case explicit IPC selection |
| 2345 | // notifications should be suppressed. |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 2346 | bool send_ipc = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2347 | !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled(); |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 2348 | #endif |
| 2349 | if (send_ipc) { |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2350 | ViewHostMsg_SelectionBounds_Params params; |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 2351 | params.is_anchor_first = false; |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2352 | GetSelectionBounds(¶ms.anchor_rect, ¶ms.focus_rect); |
| 2353 | if (selection_anchor_rect_ != params.anchor_rect || |
| 2354 | selection_focus_rect_ != params.focus_rect) { |
| 2355 | selection_anchor_rect_ = params.anchor_rect; |
| 2356 | selection_focus_rect_ = params.focus_rect; |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 2357 | if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) { |
| 2358 | focused_frame->SelectionTextDirection(params.focus_dir, |
| 2359 | params.anchor_dir); |
| 2360 | params.is_anchor_first = focused_frame->IsSelectionAnchorFirst(); |
| 2361 | } |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2362 | Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params)); |
| 2363 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2364 | } |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2365 | |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2366 | UpdateCompositionInfo(false /* not an immediate request */); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2367 | } |
| 2368 | |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2369 | void RenderWidget::DidAutoResize(const gfx::Size& new_size) { |
| 2370 | WebRect new_size_in_window(0, 0, new_size.width(), new_size.height()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2371 | ConvertViewportToWindow(&new_size_in_window); |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2372 | if (size_.width() != new_size_in_window.width || |
| 2373 | size_.height() != new_size_in_window.height) { |
| 2374 | size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height); |
| 2375 | |
| 2376 | if (resizing_mode_selector_->is_synchronous_mode()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2377 | gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(), |
| 2378 | size_.height()); |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2379 | view_screen_rect_ = new_pos; |
| 2380 | window_screen_rect_ = new_pos; |
| 2381 | } |
| 2382 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2383 | // TODO(ccameron): Note that this destroys any information differentiating |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 2384 | // |size_| from |compositor_viewport_pixel_size_|. Also note that the |
| 2385 | // calculation of |new_compositor_viewport_pixel_size| does not appear to |
| 2386 | // take into account device emulation. |
| 2387 | gfx::Size new_compositor_viewport_pixel_size = |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2388 | gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor); |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 2389 | UpdateSurfaceAndScreenInfo(viz::LocalSurfaceId(), |
| 2390 | new_compositor_viewport_pixel_size, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2391 | screen_info_); |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2392 | |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2393 | if (!resizing_mode_selector_->is_synchronous_mode()) { |
Fady Samuel | d10aadd8 | 2017-11-03 18:23:57 | [diff] [blame] | 2394 | need_resize_ack_for_auto_resize_ = true; |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2395 | // If surface synchronization is off, then ResizeAcks go to the browser in |
| 2396 | // response to a DidReceiveCompositorFrame. With surface synchronization |
| 2397 | // on, that notification will not arrive here because the compositor is |
| 2398 | // deferring commits and thus submission of CompositorFrames. |
| 2399 | if (!size_.IsEmpty() && compositor_ && |
Fady Samuel | 1ee6fb5c | 2018-02-16 03:27:46 | [diff] [blame] | 2400 | compositor_->IsSurfaceSynchronizationEnabled() && |
| 2401 | !auto_resize_ack_callback_.callback()) { |
| 2402 | auto_resize_ack_callback_.Reset( |
| 2403 | base::BindOnce(&RenderWidget::DidResizeOrRepaintAck, |
| 2404 | weak_ptr_factory_.GetWeakPtr())); |
| 2405 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 2406 | FROM_HERE, auto_resize_ack_callback_.callback()); |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2407 | } |
| 2408 | } |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2412 | void RenderWidget::GetCompositionCharacterBounds( |
| 2413 | std::vector<gfx::Rect>* bounds) { |
| 2414 | DCHECK(bounds); |
| 2415 | bounds->clear(); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2416 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2417 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2418 | if (GetFocusedPepperPluginInsideWidget()) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2419 | return; |
| 2420 | #endif |
| 2421 | |
Ehsan Karamad | 4975af6d | 2018-02-09 16:58:16 | [diff] [blame] | 2422 | blink::WebInputMethodController* controller = GetInputMethodController(); |
| 2423 | if (!controller) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2424 | return; |
| 2425 | blink::WebVector<blink::WebRect> bounds_from_blink; |
Ehsan Karamad | 4975af6d | 2018-02-09 16:58:16 | [diff] [blame] | 2426 | if (!controller->GetCompositionCharacterBounds(bounds_from_blink)) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2427 | return; |
| 2428 | |
| 2429 | for (size_t i = 0; i < bounds_from_blink.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2430 | ConvertViewportToWindow(&bounds_from_blink[i]); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2431 | bounds->push_back(bounds_from_blink[i]); |
| 2432 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2433 | } |
| 2434 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2435 | void RenderWidget::GetCompositionRange(gfx::Range* range) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2436 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2437 | if (GetFocusedPepperPluginInsideWidget()) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2438 | return; |
| 2439 | #endif |
EhsanK | cdee7b7 | 2017-11-08 21:30:09 | [diff] [blame] | 2440 | blink::WebInputMethodController* controller = GetInputMethodController(); |
| 2441 | WebRange web_range = controller ? controller->CompositionRange() : WebRange(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2442 | if (web_range.IsNull()) { |
nona | 2363a3d | 2016-11-09 03:26:21 | [diff] [blame] | 2443 | *range = gfx::Range::InvalidRange(); |
| 2444 | return; |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2445 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2446 | range->set_start(web_range.StartOffset()); |
| 2447 | range->set_end(web_range.EndOffset()); |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2448 | } |
| 2449 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2450 | bool RenderWidget::ShouldUpdateCompositionInfo( |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2451 | const gfx::Range& range, |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2452 | const std::vector<gfx::Rect>& bounds) { |
changwan | 2418e1b | 2016-12-12 12:43:08 | [diff] [blame] | 2453 | if (!range.IsValid()) |
| 2454 | return false; |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2455 | if (composition_range_ != range) |
| 2456 | return true; |
| 2457 | if (bounds.size() != composition_character_bounds_.size()) |
| 2458 | return true; |
| 2459 | for (size_t i = 0; i < bounds.size(); ++i) { |
| 2460 | if (bounds[i] != composition_character_bounds_[i]) |
| 2461 | return true; |
| 2462 | } |
| 2463 | return false; |
| 2464 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2465 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2466 | bool RenderWidget::CanComposeInline() { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2467 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2468 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) |
| 2469 | return plugin->IsPluginAcceptingCompositionEvents(); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2470 | #endif |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2471 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 2472 | } |
| 2473 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2474 | blink::WebScreenInfo RenderWidget::GetScreenInfo() { |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2475 | blink::WebScreenInfo web_screen_info; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2476 | web_screen_info.device_scale_factor = screen_info_.device_scale_factor; |
ccameron | ab0aab8 | 2017-06-24 17:21:54 | [diff] [blame] | 2477 | web_screen_info.color_space = screen_info_.color_space; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2478 | web_screen_info.depth = screen_info_.depth; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2479 | web_screen_info.depth_per_component = screen_info_.depth_per_component; |
| 2480 | web_screen_info.is_monochrome = screen_info_.is_monochrome; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2481 | web_screen_info.rect = blink::WebRect(screen_info_.rect); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2482 | web_screen_info.available_rect = blink::WebRect(screen_info_.available_rect); |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2483 | switch (screen_info_.orientation_type) { |
| 2484 | case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2485 | web_screen_info.orientation_type = |
| 2486 | blink::kWebScreenOrientationPortraitPrimary; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2487 | break; |
| 2488 | case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2489 | web_screen_info.orientation_type = |
| 2490 | blink::kWebScreenOrientationPortraitSecondary; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2491 | break; |
| 2492 | case SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2493 | web_screen_info.orientation_type = |
| 2494 | blink::kWebScreenOrientationLandscapePrimary; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2495 | break; |
| 2496 | case SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2497 | web_screen_info.orientation_type = |
| 2498 | blink::kWebScreenOrientationLandscapeSecondary; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2499 | break; |
| 2500 | default: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2501 | web_screen_info.orientation_type = blink::kWebScreenOrientationUndefined; |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2502 | break; |
| 2503 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2504 | web_screen_info.orientation_angle = screen_info_.orientation_angle; |
Fady Samuel | 85a1bf7 | 2017-10-27 14:30:20 | [diff] [blame] | 2505 | |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 2506 | return web_screen_info; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2507 | } |
| 2508 | |
Donn Denman | 3c1267c6 | 2018-03-08 22:08:59 | [diff] [blame] | 2509 | #if defined(OS_ANDROID) |
| 2510 | void RenderWidget::ShowUnhandledTapUIIfNeeded( |
| 2511 | const WebTappedInfo& tapped_info) { |
| 2512 | // Unpack tapped_info. TODO(donnd): inline unpacking. |
| 2513 | bool page_changed = tapped_info.PageChanged(); |
| 2514 | const WebNode& tapped_node = tapped_info.GetNode(); |
| 2515 | const WebPoint& tapped_position = tapped_info.Position(); |
| 2516 | bool should_trigger = !page_changed && tapped_node.IsTextNode() && |
| 2517 | !tapped_node.IsContentEditable() && |
| 2518 | !tapped_node.IsInsideFocusableElementOrARIAWidget(); |
| 2519 | if (should_trigger) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2520 | float x_px = |
| 2521 | IsUseZoomForDSFEnabled() |
| 2522 | ? tapped_position.x |
| 2523 | : tapped_position.x * GetWebScreenInfo().device_scale_factor; |
| 2524 | float y_px = |
| 2525 | IsUseZoomForDSFEnabled() |
| 2526 | ? tapped_position.y |
| 2527 | : tapped_position.y * GetWebScreenInfo().device_scale_factor; |
Donn Denman | 3c1267c6 | 2018-03-08 22:08:59 | [diff] [blame] | 2528 | Send(new ViewHostMsg_ShowUnhandledTapUIIfNeeded(routing_id_, x_px, y_px)); |
| 2529 | } |
| 2530 | } |
| 2531 | #endif |
| 2532 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2533 | void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event, |
| 2534 | bool event_cancelled) { |
[email protected] | 183e28d | 2014-01-20 18:18:02 | [diff] [blame] | 2535 | #if defined(OS_ANDROID) || defined(USE_AURA) |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2536 | if (event_cancelled) |
| 2537 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2538 | if (event.GetType() == WebInputEvent::kGestureTap) { |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2539 | ShowVirtualKeyboard(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2540 | } else if (event.GetType() == WebInputEvent::kGestureLongPress) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2541 | DCHECK(GetWebWidget()); |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 2542 | blink::WebInputMethodController* controller = GetInputMethodController(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2543 | if (!controller || controller->TextInputInfo().value.IsEmpty()) |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2544 | UpdateTextInputState(); |
[email protected] | 07c70d2 | 2014-08-21 08:33:46 | [diff] [blame] | 2545 | else |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2546 | ShowVirtualKeyboard(); |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2547 | } |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2548 | // TODO(ananta): Piggyback off existing IPCs to communicate this information, |
| 2549 | // crbug/420130. |
| 2550 | #if defined(OS_WIN) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2551 | if (event.GetType() != blink::WebGestureEvent::kGestureTap) |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2552 | return; |
| 2553 | |
| 2554 | // TODO(estade): hit test the event against focused node to make sure |
| 2555 | // the tap actually hit the focused node. |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 2556 | blink::WebInputMethodController* controller = GetInputMethodController(); |
| 2557 | blink::WebTextInputType text_input_type = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2558 | controller ? controller->TextInputType() : blink::kWebTextInputTypeNone; |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2559 | |
| 2560 | Send(new ViewHostMsg_FocusedNodeTouched( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2561 | routing_id_, text_input_type != blink::kWebTextInputTypeNone)); |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2562 | #endif |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2563 | #endif |
| 2564 | } |
| 2565 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2566 | void RenderWidget::DidOverscroll( |
bokan | e53a10f | 2016-04-13 23:48:31 | [diff] [blame] | 2567 | const blink::WebFloatSize& overscrollDelta, |
| 2568 | const blink::WebFloatSize& accumulatedOverscroll, |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2569 | const blink::WebFloatPoint& position, |
sunyunjia | bbea8a9 | 2017-08-31 11:18:54 | [diff] [blame] | 2570 | const blink::WebFloatSize& velocity, |
Sandra Sun | 2288e853 | 2017-11-30 22:50:16 | [diff] [blame] | 2571 | const blink::WebOverscrollBehavior& behavior) { |
bokan | 731ec38 | 2016-04-07 03:16:48 | [diff] [blame] | 2572 | #if defined(OS_MACOSX) |
| 2573 | // On OSX the user can disable the elastic overscroll effect. If that's the |
| 2574 | // case, don't forward the overscroll notification. |
| 2575 | DCHECK(compositor_deps()); |
| 2576 | if (!compositor_deps()->IsElasticOverscrollEnabled()) |
| 2577 | return; |
| 2578 | #endif |
bokan | e53a10f | 2016-04-13 23:48:31 | [diff] [blame] | 2579 | input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll, |
sunyunjia | bbea8a9 | 2017-08-31 11:18:54 | [diff] [blame] | 2580 | position, velocity, behavior); |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2581 | } |
| 2582 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 2583 | void RenderWidget::StartCompositor() { |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 2584 | if (!is_hidden()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2585 | compositor_->SetVisible(true); |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 2586 | } |
| 2587 | |
[email protected] | 24ed043 | 2013-04-24 07:50:31 | [diff] [blame] | 2588 | RenderWidgetCompositor* RenderWidget::compositor() const { |
| 2589 | return compositor_.get(); |
| 2590 | } |
| 2591 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2592 | void RenderWidget::SetHandlingInputEventForTesting(bool handling_input_event) { |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 2593 | input_handler_->set_handling_input_event(handling_input_event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 2594 | } |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 2595 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2596 | void RenderWidget::HasTouchEventHandlers(bool has_handlers) { |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 2597 | if (render_widget_scheduling_state_) |
| 2598 | render_widget_scheduling_state_->SetHasTouchHandler(has_handlers); |
[email protected] | ce6689f | 2013-03-29 12:52:55 | [diff] [blame] | 2599 | Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
| 2600 | } |
| 2601 | |
Dave Tapuska | dfe486c1 | 2017-06-09 16:53:13 | [diff] [blame] | 2602 | void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) { |
| 2603 | if (input_event_queue_) |
| 2604 | input_event_queue_->SetNeedsLowLatency(needs_low_latency); |
| 2605 | } |
| 2606 | |
Dave Tapuska | bafc2ba3 | 2017-11-28 01:54:37 | [diff] [blame] | 2607 | void RenderWidget::RequestUnbufferedInputEvents() { |
| 2608 | if (input_event_queue_) |
| 2609 | input_event_queue_->RequestUnbufferedInputEvents(); |
| 2610 | } |
| 2611 | |
xidachen | fa0199e7 | 2017-05-11 11:34:26 | [diff] [blame] | 2612 | void RenderWidget::SetTouchAction(cc::TouchAction touch_action) { |
Dave Tapuska | b28a108 | 2017-08-30 15:37:26 | [diff] [blame] | 2613 | if (!input_handler_->ProcessTouchAction(touch_action)) |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2614 | return; |
| 2615 | |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 2616 | if (widget_input_handler_manager_) { |
| 2617 | widget_input_handler_manager_->ProcessTouchAction(touch_action); |
| 2618 | } else { |
| 2619 | Send(new InputHostMsg_SetTouchAction(routing_id_, touch_action)); |
| 2620 | } |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2621 | } |
| 2622 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 2623 | void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2624 | render_frame_proxies_.AddObserver(proxy); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 2625 | } |
| 2626 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 2627 | void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2628 | render_frame_proxies_.RemoveObserver(proxy); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 2629 | } |
| 2630 | |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 2631 | void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { |
| 2632 | render_frames_.AddObserver(frame); |
| 2633 | } |
| 2634 | |
| 2635 | void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { |
| 2636 | render_frames_.RemoveObserver(frame); |
| 2637 | } |
| 2638 | |
Saman Sami | d189e5dfd | 2017-12-20 22:55:31 | [diff] [blame] | 2639 | void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) { |
| 2640 | browser_plugins_.AddObserver(browser_plugin); |
| 2641 | } |
| 2642 | |
| 2643 | void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) { |
| 2644 | browser_plugins_.RemoveObserver(browser_plugin); |
| 2645 | } |
| 2646 | |
lfg | 43e08e6 | 2016-02-03 18:51:37 | [diff] [blame] | 2647 | void RenderWidget::OnWaitNextFrameForTests(int routing_id) { |
| 2648 | QueueMessage(new ViewHostMsg_WaitForNextFrameForTests_ACK(routing_id), |
| 2649 | MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
| 2650 | } |
| 2651 | |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2652 | const ScreenInfo& RenderWidget::GetWebScreenInfo() const { |
| 2653 | return screen_info_; |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2654 | } |
| 2655 | |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2656 | const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const { |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2657 | return screen_metrics_emulator_ |
| 2658 | ? screen_metrics_emulator_->original_screen_info() |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame^] | 2659 | : screen_info_; |
oshima | 50872a7 | 2016-03-04 13:26:18 | [diff] [blame] | 2660 | } |
| 2661 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2662 | gfx::PointF RenderWidget::ConvertWindowPointToViewport( |
| 2663 | const gfx::PointF& point) { |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2664 | blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2665 | ConvertWindowToViewport(&point_in_viewport); |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2666 | return gfx::PointF(point_in_viewport.x, point_in_viewport.y); |
| 2667 | } |
| 2668 | |
| 2669 | gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) { |
| 2670 | return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point))); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2671 | } |
| 2672 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2673 | bool RenderWidget::RequestPointerLock() { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2674 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2675 | } |
| 2676 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2677 | void RenderWidget::RequestPointerUnlock() { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2678 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2679 | } |
| 2680 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2681 | bool RenderWidget::IsPointerLocked() { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2682 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2683 | webwidget_mouse_lock_target_.get()); |
| 2684 | } |
| 2685 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2686 | void RenderWidget::StartDragging(blink::WebReferrerPolicy policy, |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 2687 | const WebDragData& data, |
| 2688 | WebDragOperationsMask mask, |
| 2689 | const WebImage& image, |
| 2690 | const WebPoint& webImageOffset) { |
| 2691 | blink::WebRect offset_in_window(webImageOffset.x, webImageOffset.y, 0, 0); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2692 | ConvertViewportToWindow(&offset_in_window); |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 2693 | DropData drop_data(DropDataBuilder::Build(data)); |
| 2694 | drop_data.referrer_policy = policy; |
| 2695 | gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2696 | Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2697 | image.GetSkBitmap(), imageOffset, |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 2698 | possible_drag_event_info_)); |
| 2699 | } |
| 2700 | |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 2701 | uint32_t RenderWidget::GetContentSourceId() { |
| 2702 | return current_content_source_id_; |
| 2703 | } |
| 2704 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 2705 | void RenderWidget::DidNavigate() { |
| 2706 | if (!compositor_) |
| 2707 | return; |
| 2708 | compositor_->SetContentSourceId(++current_content_source_id_); |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 2709 | |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 2710 | UpdateSurfaceAndScreenInfo(viz::LocalSurfaceId(), |
| 2711 | compositor_viewport_pixel_size_, screen_info_); |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 2712 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 2713 | // If surface synchronization is on, navigation implicitly acks any resize |
| 2714 | // that has happened so far so we can get the next ResizeParams containing the |
| 2715 | // LocalSurfaceId that should be used after navigation. |
| 2716 | if (compositor_->IsSurfaceSynchronizationEnabled() && !auto_resize_mode_ && |
| 2717 | next_paint_is_resize_ack()) { |
| 2718 | reset_next_paint_is_resize_ack(); |
| 2719 | } |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 2720 | } |
| 2721 | |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2722 | blink::WebWidget* RenderWidget::GetWebWidget() const { |
| 2723 | return webwidget_internal_; |
| 2724 | } |
| 2725 | |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 2726 | blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
| 2727 | const { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2728 | if (auto* frame_widget = GetFrameWidget()) |
| 2729 | return frame_widget->GetActiveWebInputMethodController(); |
| 2730 | |
| 2731 | return nullptr; |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 2732 | } |
| 2733 | |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 2734 | void RenderWidget::SetupWidgetInputHandler( |
| 2735 | mojom::WidgetInputHandlerRequest request, |
| 2736 | mojom::WidgetInputHandlerHostPtr host) { |
Dave Tapuska | b66c28f | 2017-11-15 17:18:47 | [diff] [blame] | 2737 | widget_input_handler_manager_->AddInterface(std::move(request), |
| 2738 | std::move(host)); |
Dave Tapuska | 525eb15e | 2017-08-17 21:05:50 | [diff] [blame] | 2739 | } |
| 2740 | |
Dave Tapuska | 485aca9 | 2017-08-08 00:47:58 | [diff] [blame] | 2741 | void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) { |
| 2742 | // Close the old binding if there was one. |
| 2743 | // A RenderWidgetHost should not need more than one channel. |
| 2744 | widget_binding_.Close(); |
| 2745 | widget_binding_.Bind(std::move(request)); |
| 2746 | } |
| 2747 | |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 2748 | void RenderWidget::DidResizeOrRepaintAck() { |
Fady Samuel | d10aadd8 | 2017-11-03 18:23:57 | [diff] [blame] | 2749 | if (!next_paint_flags_ && !need_resize_ack_for_auto_resize_) |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2750 | return; |
| 2751 | |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 2752 | ViewHostMsg_ResizeOrRepaint_ACK_Params params; |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2753 | params.view_size = size_; |
| 2754 | params.flags = next_paint_flags_; |
| 2755 | params.sequence_number = ++resize_or_repaint_ack_num_; |
| 2756 | |
Fady Samuel | cc3e3b4a | 2017-10-03 02:09:21 | [diff] [blame] | 2757 | Send(new ViewHostMsg_ResizeOrRepaint_ACK(routing_id_, params)); |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2758 | next_paint_flags_ = 0; |
Fady Samuel | d10aadd8 | 2017-11-03 18:23:57 | [diff] [blame] | 2759 | need_resize_ack_for_auto_resize_ = false; |
Fady Samuel | 319e429c | 2017-10-02 18:31:55 | [diff] [blame] | 2760 | } |
| 2761 | |
Khushal | 3e96e66 | 2017-10-30 23:16:50 | [diff] [blame] | 2762 | void RenderWidget::UpdateURLForCompositorUkm() { |
| 2763 | DCHECK(compositor_); |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2764 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2765 | if (!frame_widget) |
Khushal | 3e96e66 | 2017-10-30 23:16:50 | [diff] [blame] | 2766 | return; |
| 2767 | |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2768 | auto* render_frame = RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot()); |
Khushal | 3e96e66 | 2017-10-30 23:16:50 | [diff] [blame] | 2769 | if (!render_frame->IsMainFrame()) |
| 2770 | return; |
| 2771 | |
| 2772 | compositor_->SetURLForUkm(render_frame->GetWebFrame()->GetDocument().Url()); |
| 2773 | } |
| 2774 | |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 2775 | blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2776 | if (auto* frame_widget = GetFrameWidget()) |
| 2777 | return frame_widget->FocusedWebLocalFrameInWidget(); |
| 2778 | return nullptr; |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 2779 | } |
| 2780 | |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2781 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 2782 | PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2783 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2784 | if (!frame_widget) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2785 | return nullptr; |
| 2786 | |
| 2787 | // Focused pepper instance might not always be in the focused frame. For |
| 2788 | // instance if a pepper instance and its embedder frame are focused an then |
| 2789 | // another frame takes focus using javascript, the embedder frame will no |
| 2790 | // longer be focused while the pepper instance is (the embedder frame's |
| 2791 | // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin |
| 2792 | // is fullscreen, clicking into the pepper will not refocus the embedder |
| 2793 | // frame. This is why we have to traverse the whole frame tree to find the |
| 2794 | // focused plugin. |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2795 | blink::WebFrame* current_frame = frame_widget->LocalRoot(); |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2796 | while (current_frame) { |
| 2797 | RenderFrameImpl* render_frame = |
| 2798 | current_frame->IsWebLocalFrame() |
| 2799 | ? RenderFrameImpl::FromWebFrame(current_frame) |
| 2800 | : nullptr; |
| 2801 | if (render_frame && render_frame->focused_pepper_plugin()) |
| 2802 | return render_frame->focused_pepper_plugin(); |
| 2803 | current_frame = current_frame->TraverseNext(); |
| 2804 | } |
| 2805 | return nullptr; |
| 2806 | } |
| 2807 | #endif |
| 2808 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 2809 | } // namespace content |