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