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