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