[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 | |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 7 | #include <cmath> |
| 8 | #include <limits> |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 9 | #include <memory> |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 10 | #include <utility> |
| 11 | |
[email protected] | c27dd4f | 2014-05-22 18:05:19 | [diff] [blame] | 12 | #include "base/auto_reset.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 13 | #include "base/base_switches.h" |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 14 | #include "base/bind.h" |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 15 | #include "base/command_line.h" |
changwan | 7ded375 | 2016-03-09 23:25:12 | [diff] [blame] | 16 | #include "base/feature_list.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | #include "base/logging.h" |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 18 | #include "base/macros.h" |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 19 | #include "base/memory/ptr_util.h" |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 20 | #include "base/memory/singleton.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 21 | #include "base/metrics/histogram_macros.h" |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 22 | #include "base/stl_util.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 23 | #include "base/strings/string_number_conversions.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 24 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 35b4f0c | 2014-06-26 16:55:27 | [diff] [blame] | 25 | #include "base/sys_info.h" |
fdoray | a19b770 | 2016-12-23 14:19:31 | [diff] [blame] | 26 | #include "base/threading/thread_task_runner_handle.h" |
primiano | 9e38d55 | 2015-01-28 04:18:01 | [diff] [blame] | 27 | #include "base/trace_event/trace_event.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 28 | #include "build/build_config.h" |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 29 | #include "cc/animation/animation_host.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 30 | #include "cc/base/switches.h" |
xidachen | fa0199e7 | 2017-05-11 11:34:26 | [diff] [blame] | 31 | #include "cc/input/touch_action.h" |
danakj | ba65a091 | 2017-09-21 16:38:42 | [diff] [blame] | 32 | #include "cc/trees/layer_tree_frame_sink.h" |
loyso | 6e6efc4 | 2017-01-21 02:23:03 | [diff] [blame] | 33 | #include "cc/trees/layer_tree_host.h" |
danakj | 4c98765 | 2018-07-05 15:49:41 | [diff] [blame] | 34 | #include "cc/trees/ukm_manager.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 35 | #include "components/viz/common/features.h" |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 36 | #include "components/viz/common/frame_sinks/begin_frame_source.h" |
danakj | f20f450 | 2017-09-26 17:13:31 | [diff] [blame] | 37 | #include "components/viz/common/frame_sinks/copy_output_request.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 38 | #include "components/viz/common/switches.h" |
| 39 | #include "content/common/content_switches_internal.h" |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 40 | #include "content/common/drag_event_source_info.h" |
| 41 | #include "content/common/drag_messages.h" |
jonross | a2ff4f8 | 2018-02-16 17:27:46 | [diff] [blame] | 42 | #include "content/common/render_frame_metadata.mojom.h" |
jcivelli | ae1560a | 2016-11-01 22:40:23 | [diff] [blame] | 43 | #include "content/common/render_message_filter.mojom.h" |
Nasko Oskov | f97e8b0 | 2017-07-25 02:45:42 | [diff] [blame] | 44 | #include "content/common/swapped_out_messages.h" |
Sadrul Habib Chowdhury | 8bc43cc | 2018-06-06 01:48:03 | [diff] [blame] | 45 | #include "content/common/tab_switching_time_callback.h" |
ekaramad | 9053e57b | 2016-04-26 20:00:38 | [diff] [blame] | 46 | #include "content/common/text_input_state.h" |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 47 | #include "content/common/widget_messages.h" |
mlamouri | afca06dd | 2017-01-27 23:35:18 | [diff] [blame] | 48 | #include "content/public/common/content_client.h" |
changwan | 7ded375 | 2016-03-09 23:25:12 | [diff] [blame] | 49 | #include "content/public/common/content_features.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 50 | #include "content/public/common/content_switches.h" |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 51 | #include "content/public/common/context_menu_params.h" |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 52 | #include "content/public/common/drop_data.h" |
Khushal | 3e96e66 | 2017-10-30 23:16:50 | [diff] [blame] | 53 | #include "content/public/common/service_names.mojom.h" |
Jaebaek Seo | 655110e | 2017-12-19 23:27:39 | [diff] [blame] | 54 | #include "content/public/common/use_zoom_for_dsf_policy.h" |
mlamouri | afca06dd | 2017-01-27 23:35:18 | [diff] [blame] | 55 | #include "content/public/renderer/content_renderer_client.h" |
Saman Sami | d189e5dfd | 2017-12-20 22:55:31 | [diff] [blame] | 56 | #include "content/renderer/browser_plugin/browser_plugin.h" |
[email protected] | 953bd006 | 2013-08-01 00:58:40 | [diff] [blame] | 57 | #include "content/renderer/cursor_utils.h" |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 58 | #include "content/renderer/devtools/render_widget_screen_metrics_emulator.h" |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 59 | #include "content/renderer/drop_data_builder.h" |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 60 | #include "content/renderer/external_popup_menu.h" |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 61 | #include "content/renderer/gpu/frame_swap_message_queue.h" |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 62 | #include "content/renderer/gpu/layer_tree_view.h" |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 63 | #include "content/renderer/gpu/queue_message_swap_promise.h" |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 64 | #include "content/renderer/ime_event_guard.h" |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 65 | #include "content/renderer/input/main_thread_event_queue.h" |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 66 | #include "content/renderer/input/widget_input_handler_manager.h" |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 67 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 68 | #include "content/renderer/render_frame_impl.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 69 | #include "content/renderer/render_frame_metadata_observer_impl.h" |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 70 | #include "content/renderer/render_frame_proxy.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 71 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 72 | #include "content/renderer/render_thread_impl.h" |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 73 | #include "content/renderer/render_view_impl.h" |
avi | 40b5be7a | 2016-03-03 21:13:44 | [diff] [blame] | 74 | #include "content/renderer/render_widget_owner_delegate.h" |
tfarina | 556a723 | 2014-10-05 01:02:09 | [diff] [blame] | 75 | #include "content/renderer/renderer_blink_platform_impl.h" |
[email protected] | 5b45ad4 | 2013-10-25 00:42:04 | [diff] [blame] | 76 | #include "content/renderer/resizing_mode_selector.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 77 | #include "gpu/command_buffer/service/gpu_switches.h" |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 78 | #include "ipc/ipc_message_start.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 79 | #include "ipc/ipc_sync_message.h" |
Antoine Labour | e55c9ef8 | 2017-11-10 18:51:23 | [diff] [blame] | 80 | #include "ipc/ipc_sync_message_filter.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 81 | #include "media/base/media_switches.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 82 | #include "ppapi/buildflags/buildflags.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 83 | #include "skia/ext/platform_canvas.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 84 | #include "third_party/blink/public/platform/file_path_conversion.h" |
Hajime Hoshi | 315a61f | 2018-08-14 17:27:28 | [diff] [blame] | 85 | #include "third_party/blink/public/platform/platform.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 86 | #include "third_party/blink/public/platform/scheduler/web_render_widget_scheduling_state.h" |
Yuta Kitamura | deb91bb | 2018-05-29 05:53:20 | [diff] [blame] | 87 | #include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 88 | #include "third_party/blink/public/platform/web_cursor_info.h" |
| 89 | #include "third_party/blink/public/platform/web_drag_data.h" |
| 90 | #include "third_party/blink/public/platform/web_drag_operation.h" |
| 91 | #include "third_party/blink/public/platform/web_mouse_event.h" |
| 92 | #include "third_party/blink/public/platform/web_point.h" |
| 93 | #include "third_party/blink/public/platform/web_rect.h" |
| 94 | #include "third_party/blink/public/platform/web_runtime_features.h" |
| 95 | #include "third_party/blink/public/platform/web_size.h" |
| 96 | #include "third_party/blink/public/platform/web_string.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 97 | #include "third_party/blink/public/web/web_autofill_client.h" |
| 98 | #include "third_party/blink/public/web/web_device_emulation_params.h" |
| 99 | #include "third_party/blink/public/web/web_frame_widget.h" |
| 100 | #include "third_party/blink/public/web/web_input_method_controller.h" |
| 101 | #include "third_party/blink/public/web/web_local_frame.h" |
| 102 | #include "third_party/blink/public/web/web_node.h" |
| 103 | #include "third_party/blink/public/web/web_page_popup.h" |
| 104 | #include "third_party/blink/public/web/web_popup_menu_info.h" |
| 105 | #include "third_party/blink/public/web/web_range.h" |
| 106 | #include "third_party/blink/public/web/web_settings.h" |
| 107 | #include "third_party/blink/public/web/web_view.h" |
| 108 | #include "third_party/blink/public/web/web_widget.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 109 | #include "third_party/skia/include/core/SkShader.h" |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 110 | #include "ui/base/clipboard/clipboard.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 111 | #include "ui/base/ui_base_features.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 112 | #include "ui/base/ui_base_switches.h" |
dtapuska | 97286c88 | 2017-02-24 23:14:43 | [diff] [blame] | 113 | #include "ui/events/base_event_utils.h" |
tfarina | 655f81d | 2014-12-23 02:38:50 | [diff] [blame] | 114 | #include "ui/gfx/geometry/point_conversions.h" |
tfarina | 3b0452d | 2014-12-31 15:20:09 | [diff] [blame] | 115 | #include "ui/gfx/geometry/rect_conversions.h" |
tfarina | ebe974f0 | 2015-01-03 04:25:32 | [diff] [blame] | 116 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | 1835b9e | 2012-02-28 13:12:48 | [diff] [blame] | 117 | #include "ui/gfx/skia_util.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 118 | #include "ui/gfx/switches.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 119 | #include "ui/gl/gl_switches.h" |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 120 | #include "ui/native_theme/native_theme_features.h" |
| 121 | #include "ui/native_theme/overlay_scrollbar_constants_aura.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 122 | #include "ui/surface/transport_dib.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 123 | |
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 124 | #if defined(OS_ANDROID) |
[email protected] | cefe9b15 | 2014-03-27 18:16:15 | [diff] [blame] | 125 | #include <android/keycodes.h> |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 126 | #include "base/time/time.h" |
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 127 | #endif |
| 128 | |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 129 | #if defined(OS_POSIX) |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 130 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 131 | #include "third_party/skia/include/core/SkPixelRef.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 132 | #endif // defined(OS_POSIX) |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 133 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 134 | #if defined(USE_AURA) |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 135 | #include "content/renderer/mus/renderer_window_tree_client.h" |
penghuang | 28a5fa2 | 2015-12-02 17:58:19 | [diff] [blame] | 136 | #endif |
| 137 | |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 138 | #if defined(OS_MACOSX) |
| 139 | #include "content/renderer/text_input_client_observer.h" |
| 140 | #endif |
| 141 | |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 142 | using blink::WebImeTextSpan; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 143 | using blink::WebCursorInfo; |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 144 | using blink::WebDeviceEmulationParams; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 145 | using blink::WebDragOperation; |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 146 | using blink::WebDragOperationsMask; |
| 147 | using blink::WebDragData; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 148 | using blink::WebFrameWidget; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 149 | using blink::WebGestureEvent; |
| 150 | using blink::WebInputEvent; |
dtapuska | 5d2e9c3 | 2015-12-03 16:39:49 | [diff] [blame] | 151 | using blink::WebInputEventResult; |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 152 | using blink::WebInputMethodController; |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 153 | using blink::WebLocalFrame; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 154 | using blink::WebMouseEvent; |
| 155 | using blink::WebMouseWheelEvent; |
| 156 | using blink::WebNavigationPolicy; |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 157 | using blink::WebNode; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 158 | using blink::WebPagePopup; |
donnd | a070f3c | 2015-01-16 19:54:11 | [diff] [blame] | 159 | using blink::WebPoint; |
dglazkov | e353a37 | 2016-09-01 01:33:48 | [diff] [blame] | 160 | using blink::WebRange; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 161 | using blink::WebRect; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 162 | using blink::WebSize; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 163 | using blink::WebString; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 164 | using blink::WebTextDirection; |
| 165 | using blink::WebTouchEvent; |
[email protected] | f8ed472 | 2013-12-03 03:27:25 | [diff] [blame] | 166 | using blink::WebTouchPoint; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 167 | using blink::WebVector; |
| 168 | using blink::WebWidget; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 169 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 170 | namespace content { |
| 171 | |
[email protected] | 6a4d7f6 | 2013-01-07 21:32:13 | [diff] [blame] | 172 | namespace { |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 173 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 174 | using RoutingIDWidgetMap = std::map<int32_t, RenderWidget*>; |
| 175 | base::LazyInstance<RoutingIDWidgetMap>::Leaky g_routing_id_widget_map = |
| 176 | LAZY_INSTANCE_INITIALIZER; |
| 177 | |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 178 | const base::Feature kUnpremultiplyAndDitherLowBitDepthTiles = { |
| 179 | "UnpremultiplyAndDitherLowBitDepthTiles", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 180 | |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 181 | typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; |
| 182 | |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 183 | static const int kInvalidNextPreviousFlagsValue = -1; |
yiyix | 6b90ef5 | 2018-10-09 19:55:30 | [diff] [blame] | 184 | static const char* kOOPIF = "OOPIF"; |
| 185 | static const char* kRenderer = "Renderer"; |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 186 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 187 | class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget { |
| 188 | public: |
| 189 | explicit WebWidgetLockTarget(blink::WebWidget* webwidget) |
| 190 | : webwidget_(webwidget) {} |
| 191 | |
| 192 | void OnLockMouseACK(bool succeeded) override { |
| 193 | if (succeeded) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 194 | webwidget_->DidAcquirePointerLock(); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 195 | else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 196 | webwidget_->DidNotAcquirePointerLock(); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 197 | } |
| 198 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 199 | void OnMouseLockLost() override { webwidget_->DidLosePointerLock(); } |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 200 | |
| 201 | bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { |
| 202 | // The WebWidget handles mouse lock in Blink's handleInputEvent(). |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | private: |
| 207 | blink::WebWidget* webwidget_; |
| 208 | }; |
| 209 | |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 210 | bool IsDateTimeInput(ui::TextInputType type) { |
| 211 | return type == ui::TEXT_INPUT_TYPE_DATE || |
| 212 | type == ui::TEXT_INPUT_TYPE_DATE_TIME || |
| 213 | type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL || |
| 214 | type == ui::TEXT_INPUT_TYPE_MONTH || |
| 215 | type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK; |
| 216 | } |
| 217 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 218 | WebDragData DropMetaDataToWebDragData( |
| 219 | const std::vector<DropData::Metadata>& drop_meta_data) { |
| 220 | std::vector<WebDragData::Item> item_list; |
| 221 | for (const auto& meta_data_item : drop_meta_data) { |
| 222 | if (meta_data_item.kind == DropData::Kind::STRING) { |
| 223 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 224 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 225 | item.string_type = WebString::FromUTF16(meta_data_item.mime_type); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 226 | // Have to pass a dummy URL here instead of an empty URL because the |
| 227 | // DropData received by browser_plugins goes through a round trip: |
| 228 | // DropData::MetaData --> WebDragData-->DropData. In the end, DropData |
| 229 | // will contain an empty URL (which means no URL is dragged) if the URL in |
| 230 | // WebDragData is empty. |
| 231 | if (base::EqualsASCII(meta_data_item.mime_type, |
| 232 | ui::Clipboard::kMimeTypeURIList)) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 233 | item.string_data = WebString::FromUTF8("about:dragdrop-placeholder"); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 234 | } |
| 235 | item_list.push_back(item); |
| 236 | continue; |
| 237 | } |
| 238 | |
| 239 | // TODO(hush): crbug.com/584789. Blink needs to support creating a file with |
| 240 | // just the mimetype. This is needed to drag files to WebView on Android |
| 241 | // platform. |
| 242 | if ((meta_data_item.kind == DropData::Kind::FILENAME) && |
| 243 | !meta_data_item.filename.empty()) { |
| 244 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 245 | item.storage_type = WebDragData::Item::kStorageTypeFilename; |
| 246 | item.filename_data = blink::FilePathToWebString(meta_data_item.filename); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 247 | item_list.push_back(item); |
| 248 | continue; |
| 249 | } |
| 250 | |
| 251 | if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { |
| 252 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 253 | item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile; |
| 254 | item.file_system_url = meta_data_item.file_system_url; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 255 | item_list.push_back(item); |
| 256 | continue; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | WebDragData result; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 261 | result.Initialize(); |
| 262 | result.SetItems(item_list); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 263 | return result; |
| 264 | } |
| 265 | |
| 266 | WebDragData DropDataToWebDragData(const DropData& drop_data) { |
| 267 | std::vector<WebDragData::Item> item_list; |
| 268 | |
| 269 | // These fields are currently unused when dragging into WebKit. |
| 270 | DCHECK(drop_data.download_metadata.empty()); |
| 271 | DCHECK(drop_data.file_contents.empty()); |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 272 | DCHECK(drop_data.file_contents_content_disposition.empty()); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 273 | |
| 274 | if (!drop_data.text.is_null()) { |
| 275 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 276 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 277 | item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeText); |
| 278 | item.string_data = WebString::FromUTF16(drop_data.text.string()); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 279 | item_list.push_back(item); |
| 280 | } |
| 281 | |
| 282 | if (!drop_data.url.is_empty()) { |
| 283 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 284 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 285 | item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 286 | item.string_data = WebString::FromUTF8(drop_data.url.spec()); |
| 287 | item.title = WebString::FromUTF16(drop_data.url_title); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 288 | item_list.push_back(item); |
| 289 | } |
| 290 | |
| 291 | if (!drop_data.html.is_null()) { |
| 292 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 293 | item.storage_type = WebDragData::Item::kStorageTypeString; |
| 294 | item.string_type = WebString::FromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 295 | item.string_data = WebString::FromUTF16(drop_data.html.string()); |
| 296 | item.base_url = drop_data.html_base_url; |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 297 | item_list.push_back(item); |
| 298 | } |
| 299 | |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 300 | for (auto it = drop_data.filenames.begin(); it != drop_data.filenames.end(); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 301 | ++it) { |
| 302 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 303 | item.storage_type = WebDragData::Item::kStorageTypeFilename; |
| 304 | item.filename_data = blink::FilePathToWebString(it->path); |
| 305 | item.display_name_data = |
kinuko | a429302 | 2017-01-27 06:43:25 | [diff] [blame] | 306 | blink::FilePathToWebString(base::FilePath(it->display_name)); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 307 | item_list.push_back(item); |
| 308 | } |
| 309 | |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 310 | for (auto it = drop_data.file_system_files.begin(); |
| 311 | it != drop_data.file_system_files.end(); ++it) { |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 312 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 313 | item.storage_type = WebDragData::Item::kStorageTypeFileSystemFile; |
| 314 | item.file_system_url = it->url; |
| 315 | item.file_system_file_size = it->size; |
| 316 | item.file_system_id = blink::WebString::FromASCII(it->filesystem_id); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 317 | item_list.push_back(item); |
| 318 | } |
| 319 | |
Stuart Langley | 4830039 | 2017-11-02 03:54:44 | [diff] [blame] | 320 | for (const auto& it : drop_data.custom_data) { |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 321 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 322 | item.storage_type = WebDragData::Item::kStorageTypeString; |
Stuart Langley | 4830039 | 2017-11-02 03:54:44 | [diff] [blame] | 323 | item.string_type = WebString::FromUTF16(it.first); |
| 324 | item.string_data = WebString::FromUTF16(it.second); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 325 | item_list.push_back(item); |
| 326 | } |
| 327 | |
| 328 | WebDragData result; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 329 | result.Initialize(); |
| 330 | result.SetItems(item_list); |
| 331 | result.SetFilesystemId(WebString::FromUTF16(drop_data.filesystem_id)); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 332 | return result; |
| 333 | } |
| 334 | |
dtapuska | c4dd5be | 2016-10-25 15:11:10 | [diff] [blame] | 335 | ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { |
| 336 | // Check the type is in the range representable by ui::TextInputType. |
| 337 | DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) |
| 338 | << "blink::WebTextInputType and ui::TextInputType not synchronized"; |
| 339 | return static_cast<ui::TextInputType>(type); |
| 340 | } |
| 341 | |
| 342 | ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) { |
| 343 | // Check the mode is in the range representable by ui::TextInputMode. |
| 344 | DCHECK_LE(mode, static_cast<int>(ui::TEXT_INPUT_MODE_MAX)) |
| 345 | << "blink::WebTextInputMode and ui::TextInputMode not synchronized"; |
| 346 | return static_cast<ui::TextInputMode>(mode); |
| 347 | } |
| 348 | |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 349 | // Returns true if the device scale is high enough that losing subpixel |
| 350 | // antialiasing won't have a noticeable effect on text quality. |
| 351 | static bool DeviceScaleEnsuresTextQuality(float device_scale_factor) { |
| 352 | #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 353 | // On Android, we never have subpixel antialiasing. On Chrome OS we prefer to |
| 354 | // composite all scrollers so that we get animated overlay scrollbars. |
| 355 | return true; |
| 356 | #else |
| 357 | // 1.5 is a common touchscreen tablet device scale factor. For such |
| 358 | // devices main thread antialiasing is a heavy burden. |
| 359 | return device_scale_factor >= 1.5f; |
| 360 | #endif |
| 361 | } |
| 362 | |
| 363 | static bool PreferCompositingToLCDText(CompositorDependencies* compositor_deps, |
| 364 | float device_scale_factor) { |
| 365 | const base::CommandLine& command_line = |
| 366 | *base::CommandLine::ForCurrentProcess(); |
| 367 | if (command_line.HasSwitch(switches::kDisablePreferCompositingToLCDText)) |
| 368 | return false; |
| 369 | if (command_line.HasSwitch(switches::kEnablePreferCompositingToLCDText)) |
| 370 | return true; |
| 371 | if (!compositor_deps->IsLcdTextEnabled()) |
| 372 | return true; |
| 373 | return DeviceScaleEnsuresTextQuality(device_scale_factor); |
| 374 | } |
| 375 | |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 376 | } // namespace |
| 377 | |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 378 | // RenderWidget --------------------------------------------------------------- |
| 379 | |
danakj | 829cdd14 | 2018-09-14 21:13:27 | [diff] [blame] | 380 | RenderWidget::RenderWidget(int32_t widget_routing_id, |
| 381 | CompositorDependencies* compositor_deps, |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 382 | WidgetType widget_type, |
danakj | 829cdd14 | 2018-09-14 21:13:27 | [diff] [blame] | 383 | const ScreenInfo& screen_info, |
| 384 | blink::WebDisplayMode display_mode, |
| 385 | bool swapped_out, |
| 386 | bool hidden, |
| 387 | bool never_visible, |
| 388 | mojom::WidgetRequest widget_request) |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 389 | : routing_id_(widget_routing_id), |
dcheng | 35d31c11 | 2015-07-22 00:17:36 | [diff] [blame] | 390 | compositor_deps_(compositor_deps), |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 391 | webwidget_internal_(nullptr), |
avi | 40b5be7a | 2016-03-03 21:13:44 | [diff] [blame] | 392 | owner_delegate_(nullptr), |
[email protected] | 847a258 | 2013-03-09 02:29:51 | [diff] [blame] | 393 | auto_resize_mode_(false), |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 394 | is_hidden_(hidden), |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 395 | compositor_never_visible_(never_visible), |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 396 | is_fullscreen_granted_(false), |
danakj | 73dd303 | 2018-07-28 17:49:53 | [diff] [blame] | 397 | display_mode_(display_mode), |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 398 | ime_event_guard_(nullptr), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 399 | closing_(false), |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 400 | host_closing_(false), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 401 | is_swapped_out_(swapped_out), |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 402 | text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
[email protected] | b256eca | 2013-07-11 10:57:40 | [diff] [blame] | 403 | text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
shuchen | 82ce8c5 | 2014-10-23 01:55:20 | [diff] [blame] | 404 | text_input_flags_(0), |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 405 | next_previous_flags_(kInvalidNextPreviousFlagsValue), |
[email protected] | 86ba5fcb | 2013-09-04 00:36:53 | [diff] [blame] | 406 | can_compose_inline_(true), |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 407 | composition_range_(gfx::Range::InvalidRange()), |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 408 | widget_type_(widget_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 409 | pending_window_rect_count_(0), |
Scott Violet | ae08f33 | 2018-07-27 17:37:23 | [diff] [blame] | 410 | screen_info_(screen_info), |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 411 | monitor_composition_info_(false), |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 412 | popup_origin_scale_for_emulation_(0.f), |
samans | 26510e44 | 2017-06-01 22:29:12 | [diff] [blame] | 413 | frame_swap_message_queue_(new FrameSwapMessageQueue(routing_id_)), |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 414 | resizing_mode_selector_(new ResizingModeSelector()), |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 415 | has_host_context_menu_location_(false), |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 416 | has_focus_(false), |
Nicolas Pena | 75a35d66 | 2018-04-05 20:13:44 | [diff] [blame] | 417 | for_oopif_(false), |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 418 | #if defined(OS_MACOSX) |
| 419 | text_input_client_observer_(new TextInputClientObserver(this)), |
| 420 | #endif |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 421 | first_update_visual_state_after_hidden_(false), |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 422 | was_shown_time_(base::TimeTicks::Now()), |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 423 | current_content_source_id_(0), |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 424 | widget_binding_(this, std::move(widget_request)), |
wjmaclean | 1d97062 | 2017-01-21 22:28:24 | [diff] [blame] | 425 | weak_ptr_factory_(this) { |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 426 | DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 427 | DCHECK(RenderThread::Get()); |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 428 | |
| 429 | // In tests there may not be a RenderThreadImpl. |
| 430 | if (RenderThreadImpl::current()) { |
| 431 | render_widget_scheduling_state_ = RenderThreadImpl::current() |
Yuta Kitamura | 3331f5c | 2018-04-05 11:12:25 | [diff] [blame] | 432 | ->GetWebMainThreadScheduler() |
dcheng | 07945f63 | 2015-12-26 07:59:32 | [diff] [blame] | 433 | ->NewRenderWidgetSchedulingState(); |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 434 | render_widget_scheduling_state_->SetHidden(is_hidden_); |
| 435 | } |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 436 | #if defined(USE_AURA) |
fsamuel | 098eade | 2017-03-21 18:06:14 | [diff] [blame] | 437 | RendererWindowTreeClient::CreateIfNecessary(routing_id_); |
Scott Violet | e46b335 | 2018-09-22 00:37:07 | [diff] [blame] | 438 | if (features::IsMultiProcessMash()) |
Scott Violet | 1098538e | 2017-10-05 19:23:33 | [diff] [blame] | 439 | RendererWindowTreeClient::Get(routing_id_)->SetVisible(!is_hidden_); |
sadrul | 602ce136 | 2017-01-26 06:41:10 | [diff] [blame] | 440 | #endif |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 441 | |
| 442 | if (routing_id_ != MSG_ROUTING_NONE) |
| 443 | g_routing_id_widget_map.Get().emplace(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | RenderWidget::~RenderWidget() { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 447 | DCHECK(!webwidget_internal_) << "Leaking our WebWidget!"; |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 448 | // TODO(ajwong): Add in check that routing_id_ has been removed from |
| 449 | // g_routing_id_widget_map once the shutdown semantics for RenderWidget |
| 450 | // and RenderViewImpl are rationalized. Currently, too many unit and |
| 451 | // browser tests delete a RenderWidget without correclty going through |
| 452 | // the shutdown. https://crbug.com/545684 |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 453 | |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 454 | if (input_event_queue_) |
| 455 | input_event_queue_->ClearClient(); |
| 456 | |
sadrul | 8185d97 | 2017-01-31 18:30:11 | [diff] [blame] | 457 | #if defined(USE_AURA) |
fsamuel | 098eade | 2017-03-21 18:06:14 | [diff] [blame] | 458 | // It is possible for a RenderWidget to be destroyed before it was embedded |
| 459 | // in a mus window. The RendererWindowTreeClient will leak in such cases. So |
| 460 | // explicitly delete it here. |
| 461 | RendererWindowTreeClient::Destroy(routing_id_); |
sadrul | 8185d97 | 2017-01-31 18:30:11 | [diff] [blame] | 462 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 463 | } |
| 464 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 465 | // static |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 466 | RenderWidget* RenderWidget::FromRoutingID(int32_t routing_id) { |
| 467 | RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); |
jdoerrie | 5a73d0fa | 2018-10-02 23:54:05 | [diff] [blame] | 468 | auto it = widgets->find(routing_id); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 469 | return it == widgets->end() ? NULL : it->second; |
| 470 | } |
| 471 | |
danakj | 25ec6e2b | 2018-09-26 17:01:31 | [diff] [blame] | 472 | void RenderWidget::InitForPopup(ShowCallback show_callback, |
| 473 | blink::WebPagePopup* web_page_popup) { |
| 474 | // Init() increments the reference count on |this|, making it |
| 475 | // self-referencing. |
| 476 | Init(std::move(show_callback), web_page_popup); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | } |
| 478 | |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 479 | void RenderWidget::InitForChildLocalRoot( |
| 480 | blink::WebFrameWidget* web_frame_widget) { |
| 481 | for_oopif_ = true; |
| 482 | // Init() increments the reference count on |this|, making it |
| 483 | // self-referencing. |
| 484 | Init(base::NullCallback(), web_frame_widget); |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 485 | } |
| 486 | |
dcheng | da9b4bb | 2015-07-20 20:58:08 | [diff] [blame] | 487 | void RenderWidget::CloseForFrame() { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 488 | if (owner_delegate_) { |
| 489 | owner_delegate_->OverrideCloseForWidget(); |
| 490 | return; |
| 491 | } |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 492 | OnClose(); |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 493 | } |
| 494 | |
alexmos | 78c9c0d | 2016-10-14 18:57:03 | [diff] [blame] | 495 | void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 496 | // We should only toggle between states. |
| 497 | DCHECK(is_swapped_out_ != is_swapped_out); |
| 498 | is_swapped_out_ = is_swapped_out; |
alexmos | 78c9c0d | 2016-10-14 18:57:03 | [diff] [blame] | 499 | } |
| 500 | |
Scott Violet | ae08f33 | 2018-07-27 17:37:23 | [diff] [blame] | 501 | void RenderWidget::Init(ShowCallback show_callback, WebWidget* web_widget) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 502 | DCHECK(!webwidget_internal_); |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 503 | DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 504 | |
danakj | 17216f4d | 2018-10-16 22:57:32 | [diff] [blame] | 505 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
| 506 | |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 507 | input_handler_ = std::make_unique<RenderWidgetInputHandler>(this, this); |
nick | 8331f8ad | 2016-11-15 20:42:45 | [diff] [blame] | 508 | |
danakj | 17216f4d | 2018-10-16 22:57:32 | [diff] [blame] | 509 | LayerTreeView* layer_tree_view = InitializeLayerTreeView(); |
| 510 | web_widget->SetLayerTreeView(layer_tree_view); |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 511 | |
danakj | 31699d5b | 2018-09-18 15:39:17 | [diff] [blame] | 512 | blink::scheduler::WebThreadScheduler* main_thread_scheduler = nullptr; |
| 513 | if (render_thread_impl) |
| 514 | main_thread_scheduler = render_thread_impl->GetWebMainThreadScheduler(); |
Alexander Timin | 41e917d | 2018-07-02 16:25:35 | [diff] [blame] | 515 | blink::scheduler::WebThreadScheduler* compositor_thread_scheduler = |
| 516 | blink::scheduler::WebThreadScheduler::CompositorThreadScheduler(); |
danakj | 31699d5b | 2018-09-18 15:39:17 | [diff] [blame] | 517 | scoped_refptr<base::SingleThreadTaskRunner> compositor_input_task_runner; |
| 518 | // The |compositor_thread_scheduler| can be null in tests without a compositor |
| 519 | // thread. |
| 520 | if (compositor_thread_scheduler) { |
| 521 | // When the RenderWidget is for a frame (ie for a local root) then it uses |
danakj | bd33539 | 2018-10-10 20:17:04 | [diff] [blame] | 522 | // the compositor thread task runner. When it is for a popup or other such |
| 523 | // widgets, it does not. |
| 524 | // TODO(danakj): The |web_widget| given here should become a WebFrameWidget |
| 525 | // in the case the RenderWidget is for a RenderViewImpl, but currently the |
| 526 | // WebFrameWidget gets attached after RenderWidget init. So we have to check |
| 527 | // IsWebView() as well. |
| 528 | if (web_widget->IsWebFrameWidget() || web_widget->IsWebView()) { |
danakj | 31699d5b | 2018-09-18 15:39:17 | [diff] [blame] | 529 | compositor_input_task_runner = |
| 530 | compositor_thread_scheduler->InputTaskRunner(); |
| 531 | } |
| 532 | } |
Alexander Timin | 41e917d | 2018-07-02 16:25:35 | [diff] [blame] | 533 | |
Dave Tapuska | 04bc5ee9 | 2018-04-17 19:03:31 | [diff] [blame] | 534 | widget_input_handler_manager_ = WidgetInputHandlerManager::Create( |
danakj | 31699d5b | 2018-09-18 15:39:17 | [diff] [blame] | 535 | weak_ptr_factory_.GetWeakPtr(), std::move(compositor_input_task_runner), |
| 536 | main_thread_scheduler); |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 537 | |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 538 | show_callback_ = std::move(show_callback); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 539 | |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 540 | webwidget_internal_ = web_widget; |
| 541 | webwidget_mouse_lock_target_.reset( |
| 542 | new WebWidgetLockTarget(webwidget_internal_)); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 543 | mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 544 | |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 545 | RenderThread::Get()->AddRoute(routing_id_, this); |
| 546 | // Take a reference on behalf of the RenderThread. This will be balanced |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 547 | // when we receive WidgetMsg_Close. |
nick | 4df698d8 | 2016-11-11 20:39:23 | [diff] [blame] | 548 | AddRef(); |
| 549 | if (RenderThreadImpl::current()) { |
| 550 | RenderThreadImpl::current()->WidgetCreated(); |
| 551 | if (is_hidden_) |
| 552 | RenderThreadImpl::current()->WidgetHidden(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 556 | void RenderWidget::ApplyEmulatedScreenMetricsForPopupWidget( |
| 557 | RenderWidget* origin_widget) { |
| 558 | RenderWidgetScreenMetricsEmulator* emulator = |
| 559 | origin_widget->screen_metrics_emulator_.get(); |
| 560 | if (!emulator) |
| 561 | return; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 562 | popup_origin_scale_for_emulation_ = emulator->scale(); |
[email protected] | 1919368 | 2014-04-03 15:01:43 | [diff] [blame] | 563 | popup_view_origin_for_emulation_ = emulator->applied_widget_rect().origin(); |
Pavel Feldman | cc099f7 | 2017-07-20 23:09:00 | [diff] [blame] | 564 | popup_screen_origin_for_emulation_ = |
Lei Zhang | 9b359d3 | 2017-11-28 00:57:02 | [diff] [blame] | 565 | emulator->original_screen_rect().origin(); |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 566 | UpdateSurfaceAndScreenInfo( |
| 567 | local_surface_id_from_parent_, allocation_time_from_parent_, |
| 568 | compositor_viewport_pixel_size_, emulator->original_screen_info()); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 569 | } |
| 570 | |
[email protected] | 2d6836f4 | 2014-07-02 17:25:31 | [diff] [blame] | 571 | gfx::Rect RenderWidget::AdjustValidationMessageAnchor(const gfx::Rect& anchor) { |
| 572 | if (screen_metrics_emulator_) |
| 573 | return screen_metrics_emulator_->AdjustValidationMessageAnchor(anchor); |
| 574 | return anchor; |
| 575 | } |
| 576 | |
thakis | 18e42641 | 2017-03-15 12:06:37 | [diff] [blame] | 577 | #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 578 | void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation( |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 579 | ExternalPopupMenu* popup, |
| 580 | RenderWidgetScreenMetricsEmulator* emulator) { |
Pavel Feldman | cc099f7 | 2017-07-20 23:09:00 | [diff] [blame] | 581 | popup->SetOriginScaleForEmulation(emulator->scale()); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 582 | } |
[email protected] | 5390786 | 2014-03-25 15:42:40 | [diff] [blame] | 583 | #endif |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 584 | |
| 585 | void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { |
| 586 | if (screen_metrics_emulator_) |
| 587 | screen_metrics_emulator_->OnShowContextMenu(params); |
| 588 | } |
| 589 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 590 | bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
ekaramad | 330ba423 | 2016-09-23 17:57:47 | [diff] [blame] | 591 | #if defined(OS_MACOSX) |
| 592 | if (IPC_MESSAGE_CLASS(message) == TextInputClientMsgStart) |
| 593 | return text_input_client_observer_->OnMessageReceived(message); |
| 594 | #endif |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 595 | if (mouse_lock_dispatcher_ && |
| 596 | mouse_lock_dispatcher_->OnMessageReceived(message)) |
| 597 | return true; |
| 598 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 599 | bool handled = true; |
| 600 | IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 601 | IPC_MESSAGE_HANDLER(WidgetMsg_ShowContextMenu, OnShowContextMenu) |
| 602 | IPC_MESSAGE_HANDLER(WidgetMsg_Close, OnClose) |
| 603 | IPC_MESSAGE_HANDLER(WidgetMsg_SynchronizeVisualProperties, |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 604 | OnSynchronizeVisualProperties) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 605 | IPC_MESSAGE_HANDLER(WidgetMsg_EnableDeviceEmulation, |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 606 | OnEnableDeviceEmulation) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 607 | IPC_MESSAGE_HANDLER(WidgetMsg_DisableDeviceEmulation, |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 608 | OnDisableDeviceEmulation) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 609 | IPC_MESSAGE_HANDLER(WidgetMsg_WasHidden, OnWasHidden) |
| 610 | IPC_MESSAGE_HANDLER(WidgetMsg_WasShown, OnWasShown) |
| 611 | IPC_MESSAGE_HANDLER(WidgetMsg_SetActive, OnSetActive) |
| 612 | IPC_MESSAGE_HANDLER(WidgetMsg_SetBackgroundOpaque, OnSetBackgroundOpaque) |
| 613 | IPC_MESSAGE_HANDLER(WidgetMsg_SetTextDirection, OnSetTextDirection) |
| 614 | IPC_MESSAGE_HANDLER(WidgetMsg_SetBounds_ACK, OnRequestSetBoundsAck) |
| 615 | IPC_MESSAGE_HANDLER(WidgetMsg_UpdateScreenRects, OnUpdateScreenRects) |
| 616 | IPC_MESSAGE_HANDLER(WidgetMsg_ForceRedraw, OnForceRedraw) |
| 617 | IPC_MESSAGE_HANDLER(WidgetMsg_SetViewportIntersection, |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 618 | OnSetViewportIntersection) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 619 | IPC_MESSAGE_HANDLER(WidgetMsg_SetIsInert, OnSetIsInert) |
| 620 | IPC_MESSAGE_HANDLER(WidgetMsg_SetInheritedEffectiveTouchAction, |
sunxd | 540a996 | 2018-05-24 22:51:06 | [diff] [blame] | 621 | OnSetInheritedEffectiveTouchAction) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 622 | IPC_MESSAGE_HANDLER(WidgetMsg_UpdateRenderThrottlingStatus, |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 623 | OnUpdateRenderThrottlingStatus) |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 624 | IPC_MESSAGE_HANDLER(WidgetMsg_WaitForNextFrameForTests, |
lfg | 43e08e6 | 2016-02-03 18:51:37 | [diff] [blame] | 625 | OnWaitNextFrameForTests) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 626 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| 627 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| 628 | IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| 629 | IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 630 | IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) |
| 631 | IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 632 | OnDragSourceSystemDragEnded) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 633 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 634 | IPC_END_MESSAGE_MAP() |
| 635 | return handled; |
| 636 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 637 | |
| 638 | bool RenderWidget::Send(IPC::Message* message) { |
Nasko Oskov | f97e8b0 | 2017-07-25 02:45:42 | [diff] [blame] | 639 | // Don't send any messages after the browser has told us to close, and filter |
| 640 | // most outgoing messages while swapped out. |
| 641 | if ((is_swapped_out_ && |
| 642 | !SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
| 643 | closing_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 644 | delete message; |
| 645 | return false; |
| 646 | } |
| 647 | |
| 648 | // If given a messsage without a routing ID, then assign our routing ID. |
| 649 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 650 | message->set_routing_id(routing_id_); |
| 651 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 652 | return RenderThread::Get()->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 653 | } |
| 654 | |
dtapuska | 014ed08 | 2016-11-11 21:58:48 | [diff] [blame] | 655 | void RenderWidget::SendOrCrash(IPC::Message* message) { |
| 656 | bool result = Send(message); |
| 657 | CHECK(closing_ || result) << "Failed to send message"; |
| 658 | } |
| 659 | |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 660 | bool RenderWidget::ShouldHandleImeEvents() const { |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 661 | // TODO(ekaramad): We track page focus in all RenderViews on the page but the |
| 662 | // RenderWidgets corresponding to OOPIFs do not get the update. For now, this |
| 663 | // method returns true when the RenderWidget is for an OOPIF, i.e., IME events |
| 664 | // will be processed regardless of page focus. We should revisit this after |
| 665 | // page focus for OOPIFs has been fully resolved (https://crbug.com/689777). |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 666 | return GetWebWidget() && GetWebWidget()->IsWebFrameWidget() && |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 667 | (has_focus_ || for_oopif_); |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 668 | } |
| 669 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 670 | void RenderWidget::OnClose() { |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 671 | DCHECK(content::RenderThread::Get()); |
| 672 | if (closing_) |
| 673 | return; |
| 674 | NotifyOnClose(); |
| 675 | closing_ = true; |
| 676 | |
| 677 | // Browser correspondence is no longer needed at this point. |
| 678 | if (routing_id_ != MSG_ROUTING_NONE) { |
| 679 | RenderThread::Get()->RemoveRoute(routing_id_); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 680 | g_routing_id_widget_map.Get().erase(routing_id_); |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 681 | SetHidden(false); |
| 682 | if (RenderThreadImpl::current()) |
| 683 | RenderThreadImpl::current()->WidgetDestroyed(); |
| 684 | } |
| 685 | |
| 686 | if (for_oopif_) { |
| 687 | // Widgets for frames may be created and closed at any time while the frame |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 688 | // is alive. However, WebWidget must be closed synchronously because frame |
| 689 | // widgets and frames hold pointers to each other. The deferred call to |
| 690 | // Close() will complete cleanup and release |this|, but CloseWebWidget() |
| 691 | // prevents Close() from attempting to access members of an |
| 692 | // already-deleted frame. |
| 693 | CloseWebWidget(); |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 694 | } |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 695 | // If there is a Send call on the stack, then it could be dangerous to close |
| 696 | // now. Post a task that only gets invoked when there are no nested message |
| 697 | // loops. |
Hajime Hoshi | 315a61f | 2018-08-14 17:27:28 | [diff] [blame] | 698 | GetCleanupTaskRunner()->PostNonNestableTask( |
| 699 | FROM_HERE, base::BindOnce(&RenderWidget::Close, this)); |
dcheng | d96a27a | 2015-07-24 20:17:32 | [diff] [blame] | 700 | |
| 701 | // Balances the AddRef taken when we called AddRoute. |
| 702 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 703 | } |
| 704 | |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 705 | void RenderWidget::OnSynchronizeVisualProperties( |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 706 | const VisualProperties& original_params) { |
| 707 | TRACE_EVENT0("renderer", "RenderWidget::OnSynchronizeVisualProperties"); |
EhsanK | bd2cea99 | 2017-11-23 18:49:08 | [diff] [blame] | 708 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 709 | VisualProperties params = original_params; |
| 710 | if (owner_delegate_) { |
| 711 | owner_delegate_->ApplyNewSizeForWidget(size_, params.new_size); |
| 712 | |
| 713 | if (display_mode_ != params.display_mode) { |
| 714 | display_mode_ = params.display_mode; |
| 715 | owner_delegate_->ApplyNewDisplayModeForWidget(params.display_mode); |
| 716 | } |
| 717 | |
| 718 | bool auto_resize_mode_changed = |
| 719 | auto_resize_mode_ != params.auto_resize_enabled; |
| 720 | auto_resize_mode_ = params.auto_resize_enabled; |
| 721 | min_size_for_auto_resize_ = params.min_size_for_auto_resize; |
| 722 | max_size_for_auto_resize_ = params.max_size_for_auto_resize; |
| 723 | |
| 724 | if (auto_resize_mode_) { |
| 725 | gfx::Size min_auto_size = min_size_for_auto_resize_; |
| 726 | gfx::Size max_auto_size = max_size_for_auto_resize_; |
| 727 | if (compositor_deps_->IsUseZoomForDSFEnabled()) { |
| 728 | min_auto_size = gfx::ScaleToCeiledSize( |
| 729 | min_auto_size, params.screen_info.device_scale_factor); |
| 730 | max_auto_size = gfx::ScaleToCeiledSize( |
| 731 | max_auto_size, params.screen_info.device_scale_factor); |
| 732 | } |
| 733 | owner_delegate_->ApplyAutoResizeLimitsForWidget(min_auto_size, |
| 734 | max_auto_size); |
| 735 | } else if (auto_resize_mode_changed) { |
| 736 | owner_delegate_->DisableAutoResizeForWidget(); |
| 737 | if (params.new_size.IsEmpty()) |
| 738 | return; |
| 739 | } |
| 740 | |
| 741 | browser_controls_shrink_blink_size_ = |
| 742 | params.browser_controls_shrink_blink_size; |
| 743 | top_controls_height_ = params.top_controls_height; |
| 744 | bottom_controls_height_ = params.bottom_controls_height; |
| 745 | |
| 746 | // TODO(fsamuel): Modifies the |params| that are used for |
| 747 | // SynchronizeVisualProperties(), but does not used this modified |
| 748 | // device_scale_factor for the auto-resize values, which is probably a bug. |
| 749 | if (device_scale_factor_for_testing_) { |
| 750 | params.screen_info.device_scale_factor = |
| 751 | *device_scale_factor_for_testing_; |
| 752 | params.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize( |
| 753 | params.new_size, params.screen_info.device_scale_factor); |
| 754 | } |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 755 | } |
| 756 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 757 | if (!resizing_mode_selector_->ShouldAbortOnResize(this, params)) { |
| 758 | if (screen_metrics_emulator_) { |
| 759 | screen_metrics_emulator_->OnSynchronizeVisualProperties(params); |
| 760 | } else { |
| 761 | gfx::Size old_visible_viewport_size = visible_viewport_size_; |
| 762 | SynchronizeVisualProperties(params); |
| 763 | if (old_visible_viewport_size != visible_viewport_size_) { |
| 764 | for (auto& render_frame : render_frames_) |
| 765 | render_frame.DidChangeVisibleViewport(); |
| 766 | } |
| 767 | } |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 768 | } |
| 769 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 770 | if (owner_delegate_ && params.scroll_focused_node_into_view) |
| 771 | owner_delegate_->ScrollFocusedNodeIntoViewForWidget(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 772 | } |
| 773 | |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 774 | void RenderWidget::OnEnableDeviceEmulation( |
Lei Zhang | 9b359d3 | 2017-11-28 00:57:02 | [diff] [blame] | 775 | const blink::WebDeviceEmulationParams& params) { |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 776 | if (!screen_metrics_emulator_) { |
Fady Samuel | 4255c18 | 2018-05-24 20:42:36 | [diff] [blame] | 777 | VisualProperties visual_properties; |
| 778 | visual_properties.screen_info = screen_info_; |
| 779 | visual_properties.new_size = size_; |
| 780 | visual_properties.compositor_viewport_pixel_size = |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 781 | compositor_viewport_pixel_size_; |
Fady Samuel | 4255c18 | 2018-05-24 20:42:36 | [diff] [blame] | 782 | visual_properties.local_surface_id = local_surface_id_from_parent_; |
| 783 | visual_properties.visible_viewport_size = visible_viewport_size_; |
| 784 | visual_properties.is_fullscreen_granted = is_fullscreen_granted_; |
| 785 | visual_properties.display_mode = display_mode_; |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 786 | visual_properties.page_scale_factor = page_scale_factor_from_mainframe_; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 787 | screen_metrics_emulator_.reset(new RenderWidgetScreenMetricsEmulator( |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 788 | this, params, visual_properties, widget_screen_rect_, |
Fady Samuel | 4255c18 | 2018-05-24 20:42:36 | [diff] [blame] | 789 | window_screen_rect_)); |
oshima | 50872a7 | 2016-03-04 13:26:18 | [diff] [blame] | 790 | screen_metrics_emulator_->Apply(); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 791 | } else { |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 792 | screen_metrics_emulator_->ChangeEmulationParams(params); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 793 | } |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | void RenderWidget::OnDisableDeviceEmulation() { |
| 797 | screen_metrics_emulator_.reset(); |
| 798 | } |
| 799 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 800 | void RenderWidget::OnWasHidden() { |
[email protected] | 9c3085f | 2011-06-09 02:10:31 | [diff] [blame] | 801 | TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 802 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 803 | SetHidden(true); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 804 | for (auto& observer : render_frames_) |
| 805 | observer.WasHidden(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 806 | } |
| 807 | |
danakj | 1574cf4 | 2018-09-26 21:43:14 | [diff] [blame] | 808 | void RenderWidget::OnWasShown(base::TimeTicks show_request_timestamp) { |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 809 | TRACE_EVENT0("renderer", "RenderWidget::OnWasShown"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 810 | // During shutdown we can just ignore this message. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 811 | if (!GetWebWidget()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 812 | return; |
| 813 | |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 814 | was_shown_time_ = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 815 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 816 | SetHidden(false); |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 817 | for (auto& observer : render_frames_) |
| 818 | observer.WasShown(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 819 | |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 820 | if (layer_tree_view_ && !show_request_timestamp.is_null()) { |
| 821 | layer_tree_view_->layer_tree_host()->RequestPresentationTimeForNextFrame( |
Sadrul Habib Chowdhury | 8bc43cc | 2018-06-06 01:48:03 | [diff] [blame] | 822 | CreateTabSwitchingTimeRecorder(show_request_timestamp)); |
[email protected] | 3399dd82 | 2014-08-09 11:14:24 | [diff] [blame] | 823 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 824 | } |
| 825 | |
Avi Drissman | 014dec7 | 2018-06-07 02:34:01 | [diff] [blame] | 826 | void RenderWidget::OnRequestSetBoundsAck() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 827 | DCHECK(pending_window_rect_count_); |
| 828 | pending_window_rect_count_--; |
| 829 | } |
| 830 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 831 | void RenderWidget::OnForceRedraw(int snapshot_id) { |
| 832 | if (LayerTreeView* ltv = layer_tree_view()) { |
| 833 | ltv->layer_tree_host()->RequestPresentationTimeForNextFrame( |
| 834 | base::BindOnce(&RenderWidget::DidPresentForceDrawFrame, |
| 835 | weak_ptr_factory_.GetWeakPtr(), snapshot_id)); |
| 836 | ltv->SetNeedsForcedRedraw(); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | void RenderWidget::DidPresentForceDrawFrame( |
| 841 | int snapshot_id, |
| 842 | const gfx::PresentationFeedback& feedback) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 843 | Send(new WidgetHostMsg_ForceRedrawComplete(routing_id(), snapshot_id)); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 844 | } |
| 845 | |
Xianzhu Wang | f02017ac | 2018-10-17 01:47:33 | [diff] [blame] | 846 | viz::FrameSinkId RenderWidget::GetFrameSinkIdAtPoint(const gfx::PointF& point, |
Ken Buchanan | 44d7e2f | 2018-08-23 14:18:05 | [diff] [blame] | 847 | gfx::PointF* local_point) { |
| 848 | return input_handler_->GetFrameSinkIdAtPoint(point, local_point); |
Navid Zolghadr | 0d86e5f | 2017-10-23 18:09:22 | [diff] [blame] | 849 | } |
| 850 | |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 851 | void RenderWidget::HandleInputEvent( |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 852 | const blink::WebCoalescedInputEvent& input_event, |
| 853 | const ui::LatencyInfo& latency_info, |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 854 | HandledEventCallback callback) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 855 | if (owner_delegate_ && is_swapped_out_) { |
| 856 | std::move(callback).Run(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, latency_info, |
| 857 | nullptr, base::nullopt); |
| 858 | return; |
| 859 | } |
Dave Tapuska | ea83d3bd | 2017-06-13 16:14:55 | [diff] [blame] | 860 | input_handler_->HandleInputEvent(input_event, latency_info, |
| 861 | std::move(callback)); |
dtapuska | 9ec1a91 | 2017-04-21 15:18:31 | [diff] [blame] | 862 | } |
| 863 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 864 | scoped_refptr<MainThreadEventQueue> RenderWidget::GetInputEventQueue() { |
| 865 | return input_event_queue_; |
| 866 | } |
| 867 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 868 | void RenderWidget::OnCursorVisibilityChange(bool is_visible) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 869 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 870 | GetWebWidget()->SetCursorVisibilityState(is_visible); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void RenderWidget::OnMouseCaptureLost() { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 874 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 875 | GetWebWidget()->MouseCaptureLost(); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 876 | } |
| 877 | |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 878 | void RenderWidget::OnSetEditCommandsForNextKeyEvent( |
| 879 | const EditCommands& edit_commands) { |
| 880 | edit_commands_ = edit_commands; |
| 881 | } |
| 882 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 883 | void RenderWidget::OnSetActive(bool active) { |
| 884 | if (owner_delegate_) |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 885 | owner_delegate_->SetActiveForWidget(active); |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | void RenderWidget::OnSetBackgroundOpaque(bool opaque) { |
danakj | 0ba0e7b | 2018-09-25 19:37:13 | [diff] [blame] | 889 | // Background opaque-ness modification is only supported for the main frame. |
| 890 | // The |owner_delegate_| is used as proxy for this RenderWidget being attached |
| 891 | // to the main frame. |
| 892 | if (!owner_delegate_) |
| 893 | return; |
| 894 | |
| 895 | blink::WebWidget* web_widget = GetWebWidget(); |
| 896 | // This is true since we only do this for RenderWidgets attached to the main |
| 897 | // frame. |
| 898 | DCHECK(web_widget->IsWebFrameWidget()); |
| 899 | auto* web_frame_widget = static_cast<blink::WebFrameWidget*>(web_widget); |
| 900 | if (opaque) { |
| 901 | web_frame_widget->ClearBaseBackgroundColorOverride(); |
| 902 | web_frame_widget->ClearBackgroundColorOverride(); |
| 903 | } else { |
| 904 | web_frame_widget->SetBaseBackgroundColorOverride(SK_ColorTRANSPARENT); |
| 905 | web_frame_widget->SetBackgroundColorOverride(SK_ColorTRANSPARENT); |
| 906 | } |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 907 | } |
| 908 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 909 | void RenderWidget::OnSetFocus(bool enable) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 910 | if (owner_delegate_) |
| 911 | owner_delegate_->DidReceiveSetFocusEventForWidget(); |
| 912 | SetFocus(enable); |
| 913 | } |
| 914 | |
| 915 | void RenderWidget::SetFocus(bool enable) { |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 916 | has_focus_ = enable; |
| 917 | |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 918 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 919 | GetWebWidget()->SetFocus(enable); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 920 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 921 | for (auto& observer : render_frames_) |
| 922 | observer.RenderWidgetSetFocus(enable); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 923 | |
| 924 | if (owner_delegate_) |
| 925 | owner_delegate_->DidChangeFocusForWidget(); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 926 | } |
| 927 | |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 928 | void RenderWidget::SetNeedsMainFrame() { |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 929 | LayerTreeView* ltv = layer_tree_view(); |
| 930 | if (!ltv) |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 931 | return; |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 932 | ltv->SetNeedsBeginFrame(); |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 933 | } |
| 934 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 935 | /////////////////////////////////////////////////////////////////////////////// |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 936 | // LayerTreeViewDelegate |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 937 | |
David Bokan | c8e38d0 | 2018-10-08 21:56:01 | [diff] [blame] | 938 | void RenderWidget::ApplyViewportChanges( |
| 939 | const cc::ApplyViewportChangesArgs& args) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 940 | if (!GetWebWidget()) |
| 941 | return; |
David Bokan | c8e38d0 | 2018-10-08 21:56:01 | [diff] [blame] | 942 | GetWebWidget()->ApplyViewportChanges(args); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 943 | } |
| 944 | |
sahel | 1b47fda7 | 2017-03-28 17:03:07 | [diff] [blame] | 945 | void RenderWidget::RecordWheelAndTouchScrollingCount( |
| 946 | bool has_scrolled_by_wheel, |
| 947 | bool has_scrolled_by_touch) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 948 | if (!GetWebWidget()) |
| 949 | return; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 950 | GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel, |
sahel | 1b47fda7 | 2017-03-28 17:03:07 | [diff] [blame] | 951 | has_scrolled_by_touch); |
| 952 | } |
| 953 | |
Daniel Cheng | 224569ee | 2018-04-25 05:45:06 | [diff] [blame] | 954 | void RenderWidget::BeginMainFrame(base::TimeTicks frame_time) { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 955 | if (!GetWebWidget()) |
| 956 | return; |
Daniel Cheng | 224569ee | 2018-04-25 05:45:06 | [diff] [blame] | 957 | if (input_event_queue_) |
| 958 | input_event_queue_->DispatchRafAlignedInput(frame_time); |
dtapuska | 3d5624d3 | 2016-08-30 04:34:00 | [diff] [blame] | 959 | |
Daniel Cheng | 224569ee | 2018-04-25 05:45:06 | [diff] [blame] | 960 | GetWebWidget()->BeginFrame(frame_time); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 961 | } |
| 962 | |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 963 | void RenderWidget::RequestNewLayerTreeFrameSink( |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 964 | LayerTreeFrameSinkCallback callback) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 965 | DCHECK(GetWebWidget()); |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 966 | // For widgets that are never visible, we don't start the compositor, so we |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 967 | // never get a request for a cc::LayerTreeFrameSink. |
sievers | 71c62dd5 | 2015-10-07 01:44:39 | [diff] [blame] | 968 | DCHECK(!compositor_never_visible_); |
jonross | a2ff4f8 | 2018-02-16 17:27:46 | [diff] [blame] | 969 | |
| 970 | // TODO(jonross): have this generated by the LayerTreeFrameSink itself, which |
| 971 | // would then handle binding. |
| 972 | mojom::RenderFrameMetadataObserverPtr ptr; |
| 973 | mojom::RenderFrameMetadataObserverRequest request = mojo::MakeRequest(&ptr); |
| 974 | mojom::RenderFrameMetadataObserverClientPtrInfo client_info; |
| 975 | mojom::RenderFrameMetadataObserverClientRequest client_request = |
| 976 | mojo::MakeRequest(&client_info); |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 977 | auto render_frame_metadata_observer = |
| 978 | std::make_unique<RenderFrameMetadataObserverImpl>(std::move(request), |
| 979 | std::move(client_info)); |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 980 | layer_tree_view_->SetRenderFrameObserver( |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 981 | std::move(render_frame_metadata_observer)); |
danakj | efabf31 | 2018-10-05 19:03:07 | [diff] [blame] | 982 | GURL url = GetWebWidget()->GetURLForDebugTrace(); |
| 983 | // The |url| is not always available, fallback to a fixed string. |
| 984 | if (url.is_empty()) |
| 985 | url = GURL("chrome://gpu/RenderWidget::RequestNewLayerTreeFrameSink"); |
yiyix | 6b90ef5 | 2018-10-09 19:55:30 | [diff] [blame] | 986 | const char* client_name = for_oopif_ ? kOOPIF : kRenderer; |
danakj | c7afae5 | 2017-06-20 21:12:41 | [diff] [blame] | 987 | RenderThreadImpl::current()->RequestNewLayerTreeFrameSink( |
danakj | efabf31 | 2018-10-05 19:03:07 | [diff] [blame] | 988 | routing_id_, frame_swap_message_queue_, std::move(url), |
yiyix | 6b90ef5 | 2018-10-09 19:55:30 | [diff] [blame] | 989 | std::move(callback), std::move(client_request), std::move(ptr), |
| 990 | client_name); |
[email protected] | ba91a79 | 2013-02-06 09:48:28 | [diff] [blame] | 991 | } |
| 992 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 993 | void RenderWidget::DidCommitAndDrawCompositorFrame() { |
| 994 | // NOTE: Tests may break if this event is renamed or moved. See |
| 995 | // tab_capture_performancetest.cc. |
| 996 | TRACE_EVENT0("gpu", "RenderWidget::DidCommitAndDrawCompositorFrame"); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 997 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 998 | for (auto& observer : render_frames_) |
| 999 | observer.DidCommitAndDrawCompositorFrame(); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 1000 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1001 | // Notify subclasses that we initiated the paint operation. |
| 1002 | DidInitiatePaint(); |
Yiming Zhou | 0f8836c2 | 2018-09-13 22:22:11 | [diff] [blame] | 1003 | |
Albert J. Wong | fb64e14 | 2018-10-16 01:10:45 | [diff] [blame] | 1004 | Send(new WidgetHostMsg_DidCommitAndDrawCompositorFrame(routing_id_)); |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1005 | } |
| 1006 | |
Saman Sami | 766e0b0 | 2018-01-31 17:19:20 | [diff] [blame] | 1007 | void RenderWidget::DidCommitCompositorFrame() { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1008 | if (owner_delegate_) |
| 1009 | owner_delegate_->DidCommitCompositorFrameForWidget(); |
Saman Sami | 766e0b0 | 2018-01-31 17:19:20 | [diff] [blame] | 1010 | } |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1011 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1012 | void RenderWidget::DidCompletePageScaleAnimation() { |
| 1013 | if (owner_delegate_) |
| 1014 | owner_delegate_->DidCompletePageScaleAnimationForWidget(); |
| 1015 | } |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1016 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1017 | bool RenderWidget::IsClosing() const { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 1018 | // TODO(ajwong): There is oddly 2 closing states. This API is used by |
| 1019 | // LayerTreeView only as part of the LayerTreeViewDelegate interface and |
| 1020 | // is the guard against creating new compositor frames unnecessarily. |
| 1021 | // Historically, when RenderViewImpl and RenderWidget shared the same |
| 1022 | // routing id, it was possible for |closing_| to be true, |host_closing_| to |
| 1023 | // false, and for the code in |
| 1024 | // RenderThreadImpl::RequestNewLayerTreeFrameSink() to still look up a valid |
| 1025 | // RenderViewImpl from the routing id. This is actually a benign shutdown |
| 1026 | // race in Android that can be triggered in the SynchronouslyComposite path |
| 1027 | // via AwContentsGarbageCollectionTest#testCreateAndGcManyTimes. |
| 1028 | // |
| 1029 | // Once RenderViewImpl and RenderWidget are split, attempt to combine two |
| 1030 | // states so the shutdown logic is cleaner. |
| 1031 | // |
| 1032 | // http://crbug.com/545684 |
| 1033 | return host_closing_ || closing_; |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1034 | } |
| 1035 | |
danakj | 53eccbc | 2016-03-02 22:51:07 | [diff] [blame] | 1036 | void RenderWidget::RequestScheduleAnimation() { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1037 | if (owner_delegate_) { |
| 1038 | owner_delegate_->RequestScheduleAnimationForWidget(); |
| 1039 | return; |
| 1040 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1041 | ScheduleAnimation(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1042 | } |
| 1043 | |
Robert Flack | 3ef2ffb | 2018-09-06 20:38:20 | [diff] [blame] | 1044 | void RenderWidget::UpdateVisualState() { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1045 | if (!GetWebWidget()) |
| 1046 | return; |
| 1047 | |
Robert Flack | 3ef2ffb | 2018-09-06 20:38:20 | [diff] [blame] | 1048 | GetWebWidget()->UpdateLifecycle(WebWidget::LifecycleUpdate::kAll); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1049 | GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false); |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1050 | |
Robert Flack | 3ef2ffb | 2018-09-06 20:38:20 | [diff] [blame] | 1051 | if (first_update_visual_state_after_hidden_) { |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 1052 | RecordTimeToFirstActivePaint(); |
| 1053 | first_update_visual_state_after_hidden_ = false; |
| 1054 | } |
| 1055 | } |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1056 | |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 1057 | void RenderWidget::RecordTimeToFirstActivePaint() { |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1058 | RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); |
tasak | b95dbb50c | 2017-02-08 18:07:50 | [diff] [blame] | 1059 | base::TimeDelta sample = base::TimeTicks::Now() - was_shown_time_; |
Takashi SAKAMOTO | 870f626 | 2017-08-22 04:08:27 | [diff] [blame] | 1060 | if (render_thread_impl->NeedsToRecordFirstActivePaint(TTFAP_AFTER_PURGED)) { |
| 1061 | UMA_HISTOGRAM_TIMES("PurgeAndSuspend.Experimental.TimeToFirstActivePaint", |
| 1062 | sample); |
| 1063 | } |
| 1064 | if (render_thread_impl->NeedsToRecordFirstActivePaint( |
| 1065 | TTFAP_5MIN_AFTER_BACKGROUNDED)) { |
| 1066 | UMA_HISTOGRAM_TIMES( |
| 1067 | "PurgeAndSuspend.Experimental.TimeToFirstActivePaint." |
| 1068 | "AfterBackgrounded.5min", |
| 1069 | sample); |
| 1070 | } |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1071 | } |
| 1072 | |
Stephen Chenney | 9879a5c | 2018-09-26 14:21:42 | [diff] [blame] | 1073 | void RenderWidget::RecordEndOfFrameMetrics(base::TimeTicks frame_begin_time) { |
| 1074 | if (!GetWebWidget()) |
| 1075 | return; |
| 1076 | |
| 1077 | GetWebWidget()->RecordEndOfFrameMetrics(frame_begin_time); |
| 1078 | } |
| 1079 | |
fsamuel | 78f86e4 | 2016-01-20 04:10:23 | [diff] [blame] | 1080 | void RenderWidget::WillBeginCompositorFrame() { |
| 1081 | TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
| 1082 | |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1083 | if (!GetWebWidget()) |
| 1084 | return; |
| 1085 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1086 | GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(true); |
alancutter | 317a8e0 | 2017-04-05 10:09:29 | [diff] [blame] | 1087 | |
dglazkov | 06854c5c | 2016-08-31 00:19:59 | [diff] [blame] | 1088 | // The UpdateTextInputState can result in further layout and possibly |
| 1089 | // enable GPU acceleration so they need to be called before any painting |
| 1090 | // is done. |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1091 | UpdateTextInputState(); |
dglazkov | 06854c5c | 2016-08-31 00:19:59 | [diff] [blame] | 1092 | UpdateSelectionBounds(); |
| 1093 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1094 | for (auto& observer : render_frame_proxies_) |
| 1095 | observer.WillBeginCompositorFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1096 | } |
| 1097 | |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 1098 | std::unique_ptr<cc::SwapPromise> RenderWidget::RequestCopyOfOutputForLayoutTest( |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 1099 | std::unique_ptr<viz::CopyOutputRequest> request) { |
jbroman | 6ccbc7d47 | 2016-07-27 04:45:41 | [diff] [blame] | 1100 | return RenderThreadImpl::current()->RequestCopyOfOutputForLayoutTest( |
| 1101 | routing_id_, std::move(request)); |
| 1102 | } |
| 1103 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1104 | /////////////////////////////////////////////////////////////////////////////// |
| 1105 | // RenderWidgetInputHandlerDelegate |
| 1106 | |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1107 | void RenderWidget::FocusChangeComplete() { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1108 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 1109 | if (!frame_widget) |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 1110 | return; |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1111 | |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 1112 | blink::WebLocalFrame* focused = |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1113 | frame_widget->LocalRoot()->View()->FocusedFrame(); |
| 1114 | |
ekaramad | 27ca69b1 | 2017-04-20 18:34:29 | [diff] [blame] | 1115 | if (focused && focused->AutofillClient()) |
| 1116 | focused->AutofillClient()->DidCompleteFocusChangeInFrame(); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1117 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1118 | |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1119 | void RenderWidget::ObserveGestureEventAndResult( |
| 1120 | const blink::WebGestureEvent& gesture_event, |
| 1121 | const gfx::Vector2dF& unused_delta, |
Sandra Sun | ac5cdd83 | 2017-12-11 03:27:13 | [diff] [blame] | 1122 | const cc::OverscrollBehavior& overscroll_behavior, |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1123 | bool event_processed) { |
| 1124 | if (!compositor_deps_->IsElasticOverscrollEnabled()) |
| 1125 | return; |
| 1126 | |
| 1127 | cc::InputHandlerScrollResult scroll_result; |
| 1128 | scroll_result.did_scroll = event_processed; |
| 1129 | scroll_result.did_overscroll_root = !unused_delta.IsZero(); |
| 1130 | scroll_result.unused_scroll_delta = unused_delta; |
Sandra Sun | ac5cdd83 | 2017-12-11 03:27:13 | [diff] [blame] | 1131 | scroll_result.overscroll_behavior = overscroll_behavior; |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1132 | |
Dave Tapuska | 04bc5ee9 | 2018-04-17 19:03:31 | [diff] [blame] | 1133 | widget_input_handler_manager_->ObserveGestureEventOnMainThread(gesture_event, |
| 1134 | scroll_result); |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 1135 | } |
| 1136 | |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1137 | void RenderWidget::OnDidHandleKeyEvent() { |
alexmos | 5656749 | 2016-09-13 00:52:46 | [diff] [blame] | 1138 | ClearEditCommands(); |
| 1139 | } |
| 1140 | |
| 1141 | void RenderWidget::SetEditCommandForNextKeyEvent(const std::string& name, |
| 1142 | const std::string& value) { |
| 1143 | ClearEditCommands(); |
| 1144 | edit_commands_.emplace_back(name, value); |
| 1145 | } |
| 1146 | |
| 1147 | void RenderWidget::ClearEditCommands() { |
| 1148 | edit_commands_.clear(); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1149 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1150 | |
chongz | a8ba91fc | 2016-08-16 21:39:17 | [diff] [blame] | 1151 | void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) { |
Dave Tapuska | 04bc5ee9 | 2018-04-17 19:03:31 | [diff] [blame] | 1152 | if (mojom::WidgetInputHandlerHost* host = |
| 1153 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 1154 | host->DidOverscroll(params); |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 1155 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1156 | } |
| 1157 | |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 1158 | void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { |
| 1159 | // Nothing to do here. RenderWidget created the |input_handler| and will take |
| 1160 | // ownership of it. We just verify here that we don't already have an input |
| 1161 | // handler. |
| 1162 | DCHECK(!input_handler_); |
| 1163 | } |
| 1164 | |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1165 | void RenderWidget::ShowVirtualKeyboard() { |
| 1166 | UpdateTextInputStateInternal(true, false); |
| 1167 | } |
| 1168 | |
changwan | 62f5729 | 2017-02-17 08:28:25 | [diff] [blame] | 1169 | void RenderWidget::ClearTextInputState() { |
| 1170 | text_input_info_ = blink::WebTextInputInfo(); |
| 1171 | text_input_type_ = ui::TextInputType::TEXT_INPUT_TYPE_NONE; |
| 1172 | text_input_mode_ = ui::TextInputMode::TEXT_INPUT_MODE_DEFAULT; |
| 1173 | can_compose_inline_ = false; |
| 1174 | text_input_flags_ = 0; |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1175 | next_previous_flags_ = kInvalidNextPreviousFlagsValue; |
changwan | 62f5729 | 2017-02-17 08:28:25 | [diff] [blame] | 1176 | } |
| 1177 | |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1178 | void RenderWidget::UpdateTextInputState() { |
| 1179 | UpdateTextInputStateInternal(false, false); |
| 1180 | } |
| 1181 | |
| 1182 | void RenderWidget::UpdateTextInputStateInternal(bool show_virtual_keyboard, |
| 1183 | bool reply_to_request) { |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1184 | TRACE_EVENT0("renderer", "RenderWidget::UpdateTextInputState"); |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1185 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1186 | if (ime_event_guard_) { |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1187 | DCHECK(!reply_to_request); |
| 1188 | // show_virtual_keyboard should still be effective even if it was set inside |
| 1189 | // the IME |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1190 | // event guard. |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1191 | if (show_virtual_keyboard) |
| 1192 | ime_event_guard_->set_show_virtual_keyboard(true); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1193 | return; |
| 1194 | } |
| 1195 | |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1196 | ui::TextInputType new_type = GetTextInputType(); |
| 1197 | if (IsDateTimeInput(new_type)) |
| 1198 | return; // Not considered as a text input field in WebKit/Chromium. |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1199 | |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1200 | blink::WebTextInputInfo new_info; |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1201 | if (auto* controller = GetInputMethodController()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1202 | new_info = controller->TextInputInfo(); |
dtapuska | c4dd5be | 2016-10-25 15:11:10 | [diff] [blame] | 1203 | const ui::TextInputMode new_mode = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1204 | ConvertWebTextInputMode(new_info.input_mode); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1205 | |
| 1206 | bool new_can_compose_inline = CanComposeInline(); |
| 1207 | |
| 1208 | // Only sends text input params if they are changed or if the ime should be |
| 1209 | // shown. |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1210 | if (show_virtual_keyboard || reply_to_request || |
changwan | 38c3eb61 | 2016-12-09 01:45:56 | [diff] [blame] | 1211 | text_input_type_ != new_type || text_input_mode_ != new_mode || |
| 1212 | text_input_info_ != new_info || |
| 1213 | can_compose_inline_ != new_can_compose_inline) { |
ekaramad | 9053e57b | 2016-04-26 20:00:38 | [diff] [blame] | 1214 | TextInputState params; |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1215 | params.type = new_type; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1216 | params.mode = new_mode; |
| 1217 | params.flags = new_info.flags; |
AJITH KUMAR V | 9e7b557 | 2017-11-14 00:54:21 | [diff] [blame] | 1218 | #if defined(OS_ANDROID) |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1219 | if (next_previous_flags_ == kInvalidNextPreviousFlagsValue) { |
| 1220 | // Due to a focus change, values will be reset by the frame. |
| 1221 | // That case we only need fresh NEXT/PREVIOUS information. |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1222 | // Also we won't send WidgetHostMsg_TextInputStateChanged if next/previous |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1223 | // focusable status is changed. |
| 1224 | if (auto* controller = GetInputMethodController()) { |
| 1225 | next_previous_flags_ = |
| 1226 | controller->ComputeWebTextInputNextPreviousFlags(); |
| 1227 | } else { |
| 1228 | // For safety in case GetInputMethodController() is null, because -1 is |
| 1229 | // invalid value to send to browser process. |
| 1230 | next_previous_flags_ = 0; |
| 1231 | } |
| 1232 | } |
AJITH KUMAR V | 9e7b557 | 2017-11-14 00:54:21 | [diff] [blame] | 1233 | #else |
| 1234 | next_previous_flags_ = 0; |
| 1235 | #endif |
AJITH KUMAR V | 041c0b0 | 2017-08-08 10:39:20 | [diff] [blame] | 1236 | params.flags |= next_previous_flags_; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1237 | params.value = new_info.value.Utf8(); |
| 1238 | params.selection_start = new_info.selection_start; |
| 1239 | params.selection_end = new_info.selection_end; |
| 1240 | params.composition_start = new_info.composition_start; |
| 1241 | params.composition_end = new_info.composition_end; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1242 | params.can_compose_inline = new_can_compose_inline; |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 1243 | // TODO(changwan): change instances of show_ime_if_needed to |
| 1244 | // show_virtual_keyboard. |
| 1245 | params.show_ime_if_needed = show_virtual_keyboard; |
| 1246 | params.reply_to_request = reply_to_request; |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1247 | Send(new WidgetHostMsg_TextInputStateChanged(routing_id(), params)); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1248 | |
| 1249 | text_input_info_ = new_info; |
dglazkov | 97b6c2b | 2016-10-25 17:35:55 | [diff] [blame] | 1250 | text_input_type_ = new_type; |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1251 | text_input_mode_ = new_mode; |
| 1252 | can_compose_inline_ = new_can_compose_inline; |
| 1253 | text_input_flags_ = new_info.flags; |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | bool RenderWidget::WillHandleGestureEvent(const blink::WebGestureEvent& event) { |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 1258 | possible_drag_event_info_.event_source = |
| 1259 | ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH; |
| 1260 | possible_drag_event_info_.event_location = |
Ella Ge | 1116059d | 2018-03-21 02:06:13 | [diff] [blame] | 1261 | gfx::ToFlooredPoint(event.PositionInScreen()); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1262 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1263 | return false; |
| 1264 | } |
| 1265 | |
| 1266 | bool RenderWidget::WillHandleMouseEvent(const blink::WebMouseEvent& event) { |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1267 | for (auto& observer : render_frames_) |
| 1268 | observer.RenderWidgetWillHandleMouseEvent(); |
lfg | e0c2792ec | 2016-05-11 18:52:08 | [diff] [blame] | 1269 | |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 1270 | possible_drag_event_info_.event_source = |
| 1271 | ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE; |
| 1272 | possible_drag_event_info_.event_location = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1273 | gfx::Point(event.PositionInScreen().x, event.PositionInScreen().y); |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 1274 | |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1275 | if (owner_delegate_) |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1276 | return owner_delegate_->RenderWidgetWillHandleMouseEventForWidget(event); |
avi | d7d6b2e | 2016-03-04 19:41:17 | [diff] [blame] | 1277 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 1278 | return false; |
[email protected] | fd84779 | 2013-10-24 17:12:35 | [diff] [blame] | 1279 | } |
| 1280 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1281 | /////////////////////////////////////////////////////////////////////////////// |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1282 | // RenderWidgetScreenMetricsDelegate |
| 1283 | |
| 1284 | void RenderWidget::Redraw() { |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1285 | if (layer_tree_view_) |
| 1286 | layer_tree_view_->SetNeedsRedrawRect(gfx::Rect(size_)); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1287 | } |
| 1288 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1289 | void RenderWidget::ResizeWebWidget() { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1290 | gfx::Size size = GetSizeForWebWidget(); |
| 1291 | if (owner_delegate_) { |
| 1292 | owner_delegate_->ResizeWebWidgetForWidget( |
| 1293 | size, top_controls_height_, bottom_controls_height_, |
| 1294 | browser_controls_shrink_blink_size_); |
| 1295 | return; |
| 1296 | } |
| 1297 | GetWebWidget()->Resize(size); |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | gfx::Size RenderWidget::GetSizeForWebWidget() const { |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 1301 | if (compositor_deps_->IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1302 | return gfx::ScaleToCeiledSize(size_, |
| 1303 | GetOriginalScreenInfo().device_scale_factor); |
| 1304 | } |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1305 | |
| 1306 | return size_; |
| 1307 | } |
| 1308 | |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1309 | void RenderWidget::UpdateZoom(double zoom_level) { |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1310 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 1311 | if (!frame_widget) |
| 1312 | return; |
| 1313 | RenderFrameImpl* render_frame = |
| 1314 | RenderFrameImpl::FromWebFrame(frame_widget->LocalRoot()); |
| 1315 | |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1316 | // Return early if zoom level is unchanged. |
| 1317 | if (render_frame->GetZoomLevel() == zoom_level) { |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1318 | return; |
| 1319 | } |
| 1320 | |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1321 | render_frame->SetZoomLevel(zoom_level); |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1322 | |
| 1323 | for (auto& observer : render_frame_proxies_) |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1324 | observer.OnZoomLevelChanged(zoom_level); |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1325 | |
| 1326 | for (auto& plugin : browser_plugins_) |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1327 | plugin.OnZoomLevelChanged(zoom_level); |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1328 | } |
| 1329 | |
Fady Samuel | 799e7219 | 2018-04-25 21:16:57 | [diff] [blame] | 1330 | void RenderWidget::SynchronizeVisualProperties(const VisualProperties& params) { |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1331 | // Inform the rendering thread of the color space indicate the presence of HDR |
| 1332 | // capabilities. |
Miguel Casas | 5e101805 | 2018-01-09 19:17:36 | [diff] [blame] | 1333 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 1334 | if (render_thread) |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1335 | render_thread->SetRenderingColorSpace(params.screen_info.color_space); |
Miguel Casas | 5e101805 | 2018-01-09 19:17:36 | [diff] [blame] | 1336 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1337 | // Ignore this during shutdown. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1338 | if (!GetWebWidget()) |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1339 | return; |
| 1340 | |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 1341 | // Only propagate the external PSF to non-main-frames. |
| 1342 | if (!owner_delegate_) |
| 1343 | layer_tree_view_->SetExternalPageScaleFactor(params.page_scale_factor); |
| 1344 | |
Fady Samuel | e62be40 | 2018-03-29 03:19:53 | [diff] [blame] | 1345 | gfx::Size new_compositor_viewport_pixel_size = |
| 1346 | params.auto_resize_enabled |
| 1347 | ? gfx::ScaleToCeiledSize(size_, |
| 1348 | params.screen_info.device_scale_factor) |
| 1349 | : params.compositor_viewport_pixel_size; |
Fady Samuel | 4392abb | 2018-05-10 21:01:21 | [diff] [blame] | 1350 | UpdateSurfaceAndScreenInfo( |
| 1351 | params.local_surface_id.value_or(viz::LocalSurfaceId()), |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 1352 | params.local_surface_id_allocation_time.value_or(base::TimeTicks()), |
Fady Samuel | 4392abb | 2018-05-10 21:01:21 | [diff] [blame] | 1353 | new_compositor_viewport_pixel_size, params.screen_info); |
Vladimir Levin | 98d76dad | 2018-04-21 00:21:29 | [diff] [blame] | 1354 | UpdateCaptureSequenceNumber(params.capture_sequence_number); |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1355 | if (layer_tree_view_) { |
| 1356 | layer_tree_view_->SetBrowserControlsHeight( |
Sadrul Habib Chowdhury | 04d5dd4d | 2017-08-10 01:59:27 | [diff] [blame] | 1357 | params.top_controls_height, params.bottom_controls_height, |
| 1358 | params.browser_controls_shrink_blink_size); |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1359 | layer_tree_view_->SetRasterColorSpace( |
Sadrul Habib Chowdhury | 04d5dd4d | 2017-08-10 01:59:27 | [diff] [blame] | 1360 | screen_info_.color_space.GetRasterColorSpace()); |
ianwen | e5fc578 | 2016-08-18 04:05:15 | [diff] [blame] | 1361 | } |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1362 | |
akaba | 3483d8f | 2018-07-10 21:43:09 | [diff] [blame] | 1363 | UpdateZoom(params.zoom_level); |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1364 | |
Fady Samuel | e62be40 | 2018-03-29 03:19:53 | [diff] [blame] | 1365 | if (params.auto_resize_enabled) |
| 1366 | return; |
| 1367 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1368 | visible_viewport_size_ = params.visible_viewport_size; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1369 | |
| 1370 | // NOTE: We may have entered fullscreen mode without changing our size. |
| 1371 | bool fullscreen_change = |
| 1372 | is_fullscreen_granted_ != params.is_fullscreen_granted; |
| 1373 | is_fullscreen_granted_ = params.is_fullscreen_granted; |
| 1374 | display_mode_ = params.display_mode; |
| 1375 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1376 | size_ = params.new_size; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1377 | |
bokan | c63441c | 2016-04-27 15:49:12 | [diff] [blame] | 1378 | ResizeWebWidget(); |
bokan | 71cb5b1 | 2016-04-27 03:45:22 | [diff] [blame] | 1379 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1380 | WebSize visual_viewport_size; |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 1381 | if (compositor_deps_->IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1382 | visual_viewport_size = |
| 1383 | gfx::ScaleToCeiledSize(params.visible_viewport_size, |
| 1384 | GetOriginalScreenInfo().device_scale_factor); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1385 | } else { |
| 1386 | visual_viewport_size = visible_viewport_size_; |
| 1387 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1388 | GetWebWidget()->ResizeVisualViewport(visual_viewport_size); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1389 | |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1390 | if (fullscreen_change) |
| 1391 | DidToggleFullscreen(); |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 1392 | |
| 1393 | if (!owner_delegate_) { |
| 1394 | // Make sure that page scale factor changes propagating down from the main |
| 1395 | // frame are relayed to nested OOPIFs/non-main-frames. |
| 1396 | page_scale_factor_from_mainframe_ = params.page_scale_factor; |
| 1397 | for (auto& observer : render_frame_proxies_) |
| 1398 | observer.OnPageScaleFactorChanged(params.page_scale_factor); |
| 1399 | } |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | void RenderWidget::SetScreenMetricsEmulationParameters( |
| 1403 | bool enabled, |
| 1404 | const blink::WebDeviceEmulationParams& params) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1405 | // This is only supported in RenderView, which has an |owner_delegate_|. |
| 1406 | DCHECK(owner_delegate_); |
| 1407 | owner_delegate_->SetScreenMetricsEmulationParametersForWidget(enabled, |
| 1408 | params); |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1409 | } |
| 1410 | |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1411 | void RenderWidget::SetScreenRects(const gfx::Rect& widget_screen_rect, |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1412 | const gfx::Rect& window_screen_rect) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1413 | widget_screen_rect_ = widget_screen_rect; |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1414 | window_screen_rect_ = window_screen_rect; |
| 1415 | } |
| 1416 | |
| 1417 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1418 | // WebWidgetClient |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1419 | |
Chris Harrelson | d7ab99b | 2018-01-24 17:51:36 | [diff] [blame] | 1420 | void RenderWidget::IntrinsicSizingInfoChanged( |
| 1421 | const blink::WebIntrinsicSizingInfo& sizing_info) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1422 | Send(new WidgetHostMsg_IntrinsicSizingInfoChanged(routing_id_, sizing_info)); |
Chris Harrelson | d7ab99b | 2018-01-24 17:51:36 | [diff] [blame] | 1423 | } |
| 1424 | |
enne | f3c5814 | 2014-12-09 21:44:38 | [diff] [blame] | 1425 | void RenderWidget::WillCloseLayerTreeView() { |
| 1426 | if (host_closing_) |
| 1427 | return; |
| 1428 | |
| 1429 | // Prevent new compositors or output surfaces from being created. |
| 1430 | host_closing_ = true; |
| 1431 | |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1432 | // Always send this notification to prevent new layer tree views from |
| 1433 | // being created, even if one hasn't been created yet. |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1434 | if (blink::WebWidget* widget = GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1435 | widget->WillCloseLayerTreeView(); |
[email protected] | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 1436 | } |
| 1437 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1438 | void RenderWidget::DidMeaningfulLayout(blink::WebMeaningfulLayout layout_type) { |
| 1439 | if (layout_type == blink::WebMeaningfulLayout::kVisuallyNonEmpty) { |
Albert J. Wong | fb64e14 | 2018-10-16 01:10:45 | [diff] [blame] | 1440 | QueueMessage(new WidgetHostMsg_DidFirstVisuallyNonEmptyPaint(routing_id_)); |
dglazkov | f0e1d6d | 2015-10-10 02:13:48 | [diff] [blame] | 1441 | } |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 1442 | |
ericwilligers | 88e6974 | 2016-10-17 19:29:55 | [diff] [blame] | 1443 | for (auto& observer : render_frames_) |
| 1444 | observer.DidMeaningfulLayout(layout_type); |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 1445 | } |
| 1446 | |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1447 | // static |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1448 | std::unique_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1449 | IPC::Message* msg, |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1450 | FrameSwapMessageQueue* frame_swap_message_queue, |
| 1451 | scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1452 | int source_frame_number) { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1453 | bool first_message_for_frame = false; |
Sadrul Habib Chowdhury | 4e0335cf | 2018-07-31 20:08:49 | [diff] [blame] | 1454 | frame_swap_message_queue->QueueMessageForFrame( |
| 1455 | source_frame_number, base::WrapUnique(msg), &first_message_for_frame); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1456 | if (first_message_for_frame) { |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1457 | std::unique_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1458 | sync_message_filter, frame_swap_message_queue, source_frame_number)); |
dcheng | 4b6b5ff | 2014-10-16 00:42:06 | [diff] [blame] | 1459 | return promise; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1460 | } |
dcheng | 4b6b5ff | 2014-10-16 00:42:06 | [diff] [blame] | 1461 | return nullptr; |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1462 | } |
| 1463 | |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 1464 | void RenderWidget::SetHandlingInputEvent(bool handling_input_event) { |
| 1465 | input_handler_->set_handling_input_event(handling_input_event); |
| 1466 | } |
| 1467 | |
Sadrul Habib Chowdhury | 4e0335cf | 2018-07-31 20:08:49 | [diff] [blame] | 1468 | void RenderWidget::QueueMessage(IPC::Message* msg) { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1469 | // RenderThreadImpl::current() is NULL in some tests. |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1470 | if (!layer_tree_view_ || !RenderThreadImpl::current()) { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1471 | Send(msg); |
| 1472 | return; |
| 1473 | } |
| 1474 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 1475 | std::unique_ptr<cc::SwapPromise> swap_promise = |
Sadrul Habib Chowdhury | 4e0335cf | 2018-07-31 20:08:49 | [diff] [blame] | 1476 | QueueMessageImpl(msg, frame_swap_message_queue_.get(), |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1477 | RenderThreadImpl::current()->sync_message_filter(), |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1478 | layer_tree_view_->GetSourceFrameNumber()); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1479 | |
Ken Buchanan | ce710eb | 2017-08-30 23:46:52 | [diff] [blame] | 1480 | if (swap_promise) |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1481 | layer_tree_view_->QueueSwapPromise(std::move(swap_promise)); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 1482 | } |
| 1483 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1484 | void RenderWidget::DidChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 1485 | // TODO(darin): Eliminate this temporary. |
[email protected] | 9ec8771 | 2013-05-24 23:23:52 | [diff] [blame] | 1486 | WebCursor cursor; |
tfarina | 75a0abf | 2015-10-06 15:07:18 | [diff] [blame] | 1487 | InitializeCursorFromWebCursorInfo(&cursor, cursor_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1488 | // Only send a SetCursor message if we need to make a change. |
| 1489 | if (!current_cursor_.IsEqual(cursor)) { |
| 1490 | current_cursor_ = cursor; |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1491 | Send(new WidgetHostMsg_SetCursor(routing_id_, cursor)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
aelias | 5971e47d | 2017-06-16 02:39:38 | [diff] [blame] | 1495 | void RenderWidget::AutoscrollStart(const blink::WebFloatPoint& point) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1496 | Send(new WidgetHostMsg_AutoscrollStart(routing_id_, point)); |
aelias | 5971e47d | 2017-06-16 02:39:38 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | void RenderWidget::AutoscrollFling(const blink::WebFloatSize& velocity) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1500 | Send(new WidgetHostMsg_AutoscrollFling(routing_id_, velocity)); |
aelias | 5971e47d | 2017-06-16 02:39:38 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | void RenderWidget::AutoscrollEnd() { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1504 | Send(new WidgetHostMsg_AutoscrollEnd(routing_id_)); |
aelias | 5971e47d | 2017-06-16 02:39:38 | [diff] [blame] | 1505 | } |
| 1506 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1507 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 1508 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 1509 | // point to dispatch the ShowWidget message. |
| 1510 | // |
| 1511 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1512 | // created RenderWidget (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1513 | // |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1514 | void RenderWidget::Show(WebNavigationPolicy policy) { |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1515 | if (!show_callback_) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1516 | if (owner_delegate_) { |
| 1517 | // When SupportsMultipleWindows is disabled, popups are reusing |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1518 | // the view's RenderWidget. In some scenarios, this makes blink to call |
| 1519 | // Show() twice. But otherwise, if it is enabled, we should not visit |
| 1520 | // Show() more than once. |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1521 | DCHECK(!owner_delegate_->SupportsMultipleWindowsForWidget()); |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1522 | return; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1523 | } else { |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1524 | NOTREACHED() << "received extraneous Show call"; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1525 | } |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1526 | } |
| 1527 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1528 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1529 | |
| 1530 | // The opener is responsible for actually showing this widget. |
danakj | df1ceb7 | 2018-07-18 20:02:25 | [diff] [blame] | 1531 | std::move(show_callback_).Run(this, policy, initial_rect_); |
nick | f7b3822 | 2016-11-22 21:59:35 | [diff] [blame] | 1532 | |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1533 | // NOTE: initial_rect_ may still have its default values at this point, but |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1534 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 1535 | // process will impose a default position otherwise. |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1536 | SetPendingWindowRect(initial_rect_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1537 | } |
| 1538 | |
danakj | 17216f4d | 2018-10-16 22:57:32 | [diff] [blame] | 1539 | LayerTreeView* RenderWidget::InitializeLayerTreeView() { |
| 1540 | TRACE_EVENT0("blink", "RenderWidget::InitializeLayerTreeView"); |
| 1541 | DCHECK(!host_closing_); |
| 1542 | |
| 1543 | layer_tree_view_ = std::make_unique<LayerTreeView>( |
| 1544 | this, compositor_deps_->GetCompositorMainThreadTaskRunner(), |
| 1545 | compositor_deps_->GetCompositorImplThreadTaskRunner(), |
| 1546 | compositor_deps_->GetTaskGraphRunner(), |
| 1547 | compositor_deps_->GetWebMainThreadScheduler()); |
| 1548 | layer_tree_view_->Initialize( |
| 1549 | GenerateLayerTreeSettings(compositor_deps_, for_oopif_, |
| 1550 | screen_info_.rect.size(), |
| 1551 | screen_info_.device_scale_factor), |
| 1552 | compositor_deps_->CreateUkmRecorderFactory()); |
| 1553 | |
| 1554 | UpdateSurfaceAndScreenInfo(local_surface_id_from_parent_, |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 1555 | allocation_time_from_parent_, |
danakj | 17216f4d | 2018-10-16 22:57:32 | [diff] [blame] | 1556 | compositor_viewport_pixel_size_, screen_info_); |
| 1557 | layer_tree_view_->SetRasterColorSpace( |
| 1558 | screen_info_.color_space.GetRasterColorSpace()); |
| 1559 | layer_tree_view_->SetContentSourceId(current_content_source_id_); |
| 1560 | // For background pages and certain tests, we don't want to trigger |
| 1561 | // LayerTreeFrameSink creation. |
| 1562 | bool should_generate_frame_sink = |
| 1563 | !compositor_never_visible_ && RenderThreadImpl::current(); |
Dale Curtis | e690192 | 2018-10-24 20:11:12 | [diff] [blame] | 1564 | if (!should_generate_frame_sink) |
danakj | 17216f4d | 2018-10-16 22:57:32 | [diff] [blame] | 1565 | layer_tree_view_->SetNeverVisible(); |
| 1566 | |
Dale Curtis | e690192 | 2018-10-24 20:11:12 | [diff] [blame] | 1567 | StartCompositor(); |
danakj | 17216f4d | 2018-10-16 22:57:32 | [diff] [blame] | 1568 | DCHECK_NE(MSG_ROUTING_NONE, routing_id_); |
| 1569 | layer_tree_view_->SetFrameSinkId( |
| 1570 | viz::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_)); |
| 1571 | |
| 1572 | RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 1573 | if (render_thread) { |
| 1574 | input_event_queue_ = base::MakeRefCounted<MainThreadEventQueue>( |
| 1575 | this, render_thread->GetWebMainThreadScheduler()->InputTaskRunner(), |
| 1576 | render_thread->GetWebMainThreadScheduler(), should_generate_frame_sink); |
| 1577 | } |
| 1578 | |
| 1579 | return layer_tree_view_.get(); |
| 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(); |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1584 | Send(new WidgetHostMsg_Close(routing_id_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 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. |
Albert J. Wong | fb64e14 | 2018-10-16 01:10:45 | [diff] [blame] | 1598 | Send(new WidgetHostMsg_RouteCloseEvent(routing_id_)); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 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 | 315a61f | 2018-08-14 17:27:28 | [diff] [blame] | 1610 | GetCleanupTaskRunner()->PostTask( |
| 1611 | FROM_HERE, base::BindOnce(&RenderWidget::DoDeferredClose, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | void RenderWidget::Close() { |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1615 | CloseWebWidget(); |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1616 | layer_tree_view_.reset(); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1617 | if (owner_delegate_) |
| 1618 | owner_delegate_->DidCloseWidget(); |
Albert J. Wong | d593de53 | 2018-09-06 05:42:15 | [diff] [blame] | 1619 | // Note the ACK is a control message going to the RenderProcessHost. |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1620 | RenderThread::Get()->Send(new WidgetHostMsg_Close_ACK(routing_id())); |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | void RenderWidget::CloseWebWidget() { |
danakj | 35314ab | 2018-10-19 16:37:34 | [diff] [blame] | 1624 | // If the browser has not sent OnDisableDeviceEmulation, we have an emulator |
| 1625 | // hanging out still. Destroying it must happen *after* the IPC route is |
| 1626 | // removed so that another IPC does not arrive and re-create the emulator |
| 1627 | // during closing. |
| 1628 | // |
| 1629 | // This destruction is normally part of an IPC and expects objects to be alive |
| 1630 | // that would be alive while the IPC route is active such as the |
| 1631 | // |layer_tree_view_|. So we ensure that it is the first thing to be |
| 1632 | // destroyed here before deleting things from the RenderWidget or the |
| 1633 | // |owner_delegate_|. |
| 1634 | // |
| 1635 | // TODO(danakj): The emulator could reset to non-emulated values in an |
| 1636 | // explicit method call (instead of in the destructor) that occurs when |
| 1637 | // emulation is disabled, but does not need to occur during RenderWidget |
| 1638 | // closing. Then we would not have to destroy this so carefully. |
| 1639 | screen_metrics_emulator_.reset(); |
| 1640 | |
Ken Buchanan | ed449bb | 2018-02-01 21:02:05 | [diff] [blame] | 1641 | WillCloseLayerTreeView(); |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1642 | if (webwidget_internal_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1643 | webwidget_internal_->Close(); |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 1644 | webwidget_internal_ = nullptr; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1648 | void RenderWidget::UpdateWebViewWithDeviceScaleFactor() { |
| 1649 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 1650 | blink::WebFrame* current_frame = |
| 1651 | frame_widget ? frame_widget->LocalRoot() : nullptr; |
| 1652 | blink::WebView* webview = current_frame ? current_frame->View() : nullptr; |
| 1653 | if (webview) { |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 1654 | if (compositor_deps_->IsUseZoomForDSFEnabled()) |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1655 | webview->SetZoomFactorForDeviceScaleFactor( |
| 1656 | GetWebScreenInfo().device_scale_factor); |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1657 | else |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1658 | webview->SetDeviceScaleFactor(GetWebScreenInfo().device_scale_factor); |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1659 | |
| 1660 | webview->GetSettings()->SetPreferCompositingToLCDTextEnabled( |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1661 | PreferCompositingToLCDText(compositor_deps_, |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1662 | GetWebScreenInfo().device_scale_factor)); |
Mitsuru Oshima | 3c07b33 | 2018-02-06 04:56:50 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 1666 | blink::WebFrameWidget* RenderWidget::GetFrameWidget() const { |
| 1667 | blink::WebWidget* web_widget = GetWebWidget(); |
| 1668 | if (!web_widget) |
| 1669 | return nullptr; |
| 1670 | |
| 1671 | if (!web_widget->IsWebFrameWidget()) { |
| 1672 | // TODO(ekaramad): This should not happen. If we have a WebWidget and we |
| 1673 | // need a WebFrameWidget then we should be getting a WebFrameWidget. But |
| 1674 | // unfortunately this does not seem to be the case in some scenarios -- |
| 1675 | // specifically when a RenderViewImpl swaps out during navigation the |
| 1676 | // WebViewImpl loses its WebViewFrameWidget but sometimes we receive IPCs |
| 1677 | // which are destined for WebFrameWidget (https://crbug.com/669219). |
| 1678 | return nullptr; |
| 1679 | } |
| 1680 | |
| 1681 | return static_cast<blink::WebFrameWidget*>(web_widget); |
| 1682 | } |
| 1683 | |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1684 | void RenderWidget::ScreenRectToEmulatedIfNeeded(WebRect* window_rect) const { |
| 1685 | DCHECK(window_rect); |
| 1686 | float scale = popup_origin_scale_for_emulation_; |
| 1687 | if (!scale) |
| 1688 | return; |
| 1689 | window_rect->x = |
| 1690 | popup_view_origin_for_emulation_.x() + |
| 1691 | (window_rect->x - popup_screen_origin_for_emulation_.x()) / scale; |
| 1692 | window_rect->y = |
| 1693 | popup_view_origin_for_emulation_.y() + |
| 1694 | (window_rect->y - popup_screen_origin_for_emulation_.y()) / scale; |
| 1695 | } |
| 1696 | |
| 1697 | void RenderWidget::EmulatedToScreenRectIfNeeded(WebRect* window_rect) const { |
| 1698 | DCHECK(window_rect); |
| 1699 | float scale = popup_origin_scale_for_emulation_; |
| 1700 | if (!scale) |
| 1701 | return; |
| 1702 | window_rect->x = |
| 1703 | popup_screen_origin_for_emulation_.x() + |
| 1704 | (window_rect->x - popup_view_origin_for_emulation_.x()) * scale; |
| 1705 | window_rect->y = |
| 1706 | popup_screen_origin_for_emulation_.y() + |
| 1707 | (window_rect->y - popup_view_origin_for_emulation_.y()) * scale; |
| 1708 | } |
| 1709 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1710 | WebRect RenderWidget::WindowRect() { |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1711 | WebRect rect; |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1712 | if (pending_window_rect_count_) { |
| 1713 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 1714 | // the RootWindowRect is probably going to return wrong results since the |
| 1715 | // browser may not have processed the Move yet. There isn't really anything |
| 1716 | // good to do in this case, and it shouldn't happen - since this size is |
| 1717 | // only really needed for windowToScreen, which is only used for Popups. |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1718 | rect = pending_window_rect_; |
| 1719 | } else { |
| 1720 | rect = window_screen_rect_; |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1721 | } |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1722 | |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1723 | ScreenRectToEmulatedIfNeeded(&rect); |
| 1724 | return rect; |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1725 | } |
| 1726 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1727 | WebRect RenderWidget::ViewRect() { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1728 | WebRect rect = widget_screen_rect_; |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1729 | ScreenRectToEmulatedIfNeeded(&rect); |
| 1730 | return rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1731 | } |
| 1732 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1733 | void RenderWidget::SetToolTipText(const blink::WebString& text, |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1734 | WebTextDirection hint) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1735 | Send(new WidgetHostMsg_SetTooltipText(routing_id_, text.Utf16(), hint)); |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1736 | } |
| 1737 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1738 | void RenderWidget::SetWindowRect(const WebRect& rect_in_screen) { |
danakj | 81d601e6 | 2018-10-09 22:15:05 | [diff] [blame] | 1739 | // This path is for the renderer to change the on-screen position/size of |
| 1740 | // the widget by changing its window rect. This is not possible for |
| 1741 | // RenderWidgets whose position/size are controlled by layout from another |
| 1742 | // frame tree (ie. child local root frames, informed by |for_oopif_|), as |
| 1743 | // the window rect can only be set by the browser. |
| 1744 | if (for_oopif_) |
| 1745 | return; |
| 1746 | |
oshima | 33ec97cd | 2015-12-14 19:40:24 | [diff] [blame] | 1747 | WebRect window_rect = rect_in_screen; |
bokan | 841fdc7 | 2016-10-06 00:16:35 | [diff] [blame] | 1748 | EmulatedToScreenRectIfNeeded(&window_rect); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1749 | |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1750 | if (resizing_mode_selector_->is_synchronous_mode()) { |
| 1751 | // This is a layout-test-only path. At one point, it was planned to be |
| 1752 | // removed. See https://crbug.com/309760. |
bokan | c007c3a | 2015-02-03 07:15:56 | [diff] [blame] | 1753 | SetWindowRectSynchronously(window_rect); |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1754 | return; |
| 1755 | } |
| 1756 | |
| 1757 | if (show_callback_) { |
| 1758 | // The widget is not shown yet. Delay the |window_rect| being sent to the |
| 1759 | // browser until Show() is called so it can be sent with that IPC, once the |
| 1760 | // browser is ready for the info. |
| 1761 | initial_rect_ = window_rect; |
| 1762 | } else { |
| 1763 | Send(new WidgetHostMsg_RequestSetBounds(routing_id_, window_rect)); |
| 1764 | SetPendingWindowRect(window_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1768 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 1769 | pending_window_rect_ = rect; |
| 1770 | pending_window_rect_count_++; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1771 | |
bokan | 6b08cd2 | 2016-10-05 00:55:21 | [diff] [blame] | 1772 | // Popups don't get size updates back from the browser so just store the set |
| 1773 | // values. |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 1774 | if (widget_type_ != WidgetType::kFrame) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1775 | window_screen_rect_ = rect; |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1776 | widget_screen_rect_ = rect; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1777 | } |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 1778 | } |
| 1779 | |
wjmaclean | ee244e0 | 2017-05-26 21:06:07 | [diff] [blame] | 1780 | void RenderWidget::OnShowContextMenu(ui::MenuSourceType source_type, |
| 1781 | const gfx::Point& location) { |
wjmaclean | ee244e0 | 2017-05-26 21:06:07 | [diff] [blame] | 1782 | has_host_context_menu_location_ = true; |
| 1783 | host_context_menu_location_ = location; |
| 1784 | if (GetWebWidget()) { |
| 1785 | GetWebWidget()->ShowContextMenu( |
| 1786 | static_cast<blink::WebMenuSourceType>(source_type)); |
| 1787 | } |
| 1788 | has_host_context_menu_location_ = false; |
| 1789 | } |
| 1790 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1791 | void RenderWidget::OnImeSetComposition( |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1792 | const base::string16& text, |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1793 | const std::vector<WebImeTextSpan>& ime_text_spans, |
chongz | 7eb75280 | 2016-01-27 21:28:07 | [diff] [blame] | 1794 | const gfx::Range& replacement_range, |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1795 | int selection_start, |
| 1796 | int selection_end) { |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1797 | if (!ShouldHandleImeEvents()) |
| 1798 | return; |
| 1799 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1800 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1801 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1802 | plugin->render_frame()->OnImeSetComposition(text, ime_text_spans, |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1803 | selection_start, selection_end); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 1804 | return; |
| 1805 | } |
| 1806 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1807 | ImeEventGuard guard(this); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1808 | blink::WebInputMethodController* controller = GetInputMethodController(); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1809 | if (!controller || |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1810 | !controller->SetComposition( |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1811 | WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans), |
ekaramad | ce32ef9f | 2017-02-09 17:33:56 | [diff] [blame] | 1812 | replacement_range.IsValid() |
| 1813 | ? WebRange(replacement_range.start(), replacement_range.length()) |
| 1814 | : WebRange(), |
| 1815 | selection_start, selection_end)) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1816 | // If we failed to set the composition text, then we need to let the browser |
| 1817 | // process to cancel the input method's ongoing composition session, to make |
| 1818 | // sure we are in a consistent state. |
Dave Tapuska | 04bc5ee9 | 2018-04-17 19:03:31 | [diff] [blame] | 1819 | if (mojom::WidgetInputHandlerHost* host = |
| 1820 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 1821 | host->ImeCancelComposition(); |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 1822 | } |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame] | 1823 | } |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 1824 | UpdateCompositionInfo(false /* not an immediate request */); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1825 | } |
| 1826 | |
rlanday | 7efe230 | 2017-01-11 00:14:28 | [diff] [blame] | 1827 | void RenderWidget::OnImeCommitText( |
| 1828 | const base::string16& text, |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1829 | const std::vector<WebImeTextSpan>& ime_text_spans, |
rlanday | 7efe230 | 2017-01-11 00:14:28 | [diff] [blame] | 1830 | const gfx::Range& replacement_range, |
| 1831 | int relative_cursor_pos) { |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1832 | if (!ShouldHandleImeEvents()) |
| 1833 | return; |
| 1834 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1835 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1836 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
| 1837 | plugin->render_frame()->OnImeCommitText(text, replacement_range, |
| 1838 | relative_cursor_pos); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 1839 | return; |
| 1840 | } |
| 1841 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 1842 | ImeEventGuard guard(this); |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 1843 | input_handler_->set_handling_input_event(true); |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 1844 | if (auto* controller = GetInputMethodController()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1845 | controller->CommitText( |
Ryan Landay | 9e42fd74 | 2017-08-12 01:59:11 | [diff] [blame] | 1846 | WebString::FromUTF16(text), WebVector<WebImeTextSpan>(ime_text_spans), |
ekaramad | ce32ef9f | 2017-02-09 17:33:56 | [diff] [blame] | 1847 | replacement_range.IsValid() |
| 1848 | ? WebRange(replacement_range.start(), replacement_range.length()) |
| 1849 | : WebRange(), |
| 1850 | relative_cursor_pos); |
ekaramad | b6483a05 | 2017-02-10 02:23:26 | [diff] [blame] | 1851 | } |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 1852 | input_handler_->set_handling_input_event(false); |
| 1853 | UpdateCompositionInfo(false /* not an immediate request */); |
| 1854 | } |
| 1855 | |
| 1856 | void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 1857 | if (!ShouldHandleImeEvents()) |
| 1858 | return; |
| 1859 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1860 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 1861 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
| 1862 | plugin->render_frame()->OnImeFinishComposingText(keep_selection); |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 1863 | return; |
| 1864 | } |
| 1865 | #endif |
| 1866 | |
changwan | 38c3eb61 | 2016-12-09 01:45:56 | [diff] [blame] | 1867 | if (!GetWebWidget()) |
aelias | 87b8f7c | 2016-09-14 03:19:29 | [diff] [blame] | 1868 | return; |
| 1869 | ImeEventGuard guard(this); |
| 1870 | input_handler_->set_handling_input_event(true); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1871 | if (auto* controller = GetInputMethodController()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1872 | controller->FinishComposingText( |
| 1873 | keep_selection ? WebInputMethodController::kKeepSelection |
| 1874 | : WebInputMethodController::kDoNotKeepSelection); |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 1875 | } |
fsamuel | e8326c74 | 2016-01-12 00:49:39 | [diff] [blame] | 1876 | input_handler_->set_handling_input_event(false); |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 1877 | UpdateCompositionInfo(false /* not an immediate request */); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1878 | } |
| 1879 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1880 | void RenderWidget::UpdateSurfaceAndScreenInfo( |
Fady Samuel | 4392abb | 2018-05-10 21:01:21 | [diff] [blame] | 1881 | const viz::LocalSurfaceId& new_local_surface_id, |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 1882 | base::TimeTicks new_allocation_time_, |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1883 | const gfx::Size& new_compositor_viewport_pixel_size, |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1884 | const ScreenInfo& new_screen_info) { |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1885 | bool orientation_changed = |
| 1886 | screen_info_.orientation_angle != new_screen_info.orientation_angle || |
| 1887 | screen_info_.orientation_type != new_screen_info.orientation_type; |
| 1888 | bool web_device_scale_factor_changed = |
| 1889 | screen_info_.device_scale_factor != new_screen_info.device_scale_factor; |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1890 | ScreenInfo previous_original_screen_info = GetOriginalScreenInfo(); |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1891 | |
Fady Samuel | 4255c18 | 2018-05-24 20:42:36 | [diff] [blame] | 1892 | local_surface_id_from_parent_ = new_local_surface_id; |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 1893 | allocation_time_from_parent_ = new_allocation_time_; |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 1894 | compositor_viewport_pixel_size_ = new_compositor_viewport_pixel_size; |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1895 | screen_info_ = new_screen_info; |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1896 | |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1897 | if (layer_tree_view_) { |
| 1898 | layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect()); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1899 | // Note carefully that the DSF specified in |new_screen_info| is not the |
| 1900 | // DSF used by the compositor during device emulation! |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1901 | layer_tree_view_->SetViewportSizeAndScale( |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1902 | compositor_viewport_pixel_size_, |
Fady Samuel | 4255c18 | 2018-05-24 20:42:36 | [diff] [blame] | 1903 | GetOriginalScreenInfo().device_scale_factor, |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 1904 | local_surface_id_from_parent_, allocation_time_from_parent_); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1905 | } |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1906 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1907 | if (orientation_changed) |
| 1908 | OnOrientationChange(); |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1909 | |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1910 | if (previous_original_screen_info != GetOriginalScreenInfo()) { |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1911 | for (auto& observer : render_frame_proxies_) |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1912 | observer.OnScreenInfoChanged(GetOriginalScreenInfo()); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1913 | |
| 1914 | // Notify all embedded BrowserPlugins of the updated ScreenInfo. |
| 1915 | for (auto& observer : browser_plugins_) |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 1916 | observer.ScreenInfoChanged(GetOriginalScreenInfo()); |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | if (web_device_scale_factor_changed) |
Christopher Cameron | be7ecea | 2018-02-27 00:47:19 | [diff] [blame] | 1920 | UpdateWebViewWithDeviceScaleFactor(); |
oshima | d527903 | 2015-12-16 18:22:33 | [diff] [blame] | 1921 | } |
| 1922 | |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1923 | void RenderWidget::SetWindowRectSynchronously( |
| 1924 | const gfx::Rect& new_window_rect) { |
| 1925 | VisualProperties visual_properties; |
| 1926 | visual_properties.screen_info = screen_info_; |
| 1927 | visual_properties.new_size = new_window_rect.size(); |
| 1928 | visual_properties.compositor_viewport_pixel_size = gfx::ScaleToCeiledSize( |
| 1929 | new_window_rect.size(), GetWebScreenInfo().device_scale_factor); |
| 1930 | visual_properties.visible_viewport_size = new_window_rect.size(); |
| 1931 | visual_properties.is_fullscreen_granted = is_fullscreen_granted_; |
| 1932 | visual_properties.display_mode = display_mode_; |
| 1933 | visual_properties.local_surface_id = local_surface_id_from_parent_; |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 1934 | visual_properties.page_scale_factor = page_scale_factor_from_mainframe_; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1935 | // We are resizing the window from the renderer, so allocate a new |
| 1936 | // viz::LocalSurfaceId to avoid surface invariants violations in tests. |
| 1937 | if (layer_tree_view_) |
| 1938 | layer_tree_view_->RequestNewLocalSurfaceId(); |
| 1939 | SynchronizeVisualProperties(visual_properties); |
| 1940 | |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1941 | widget_screen_rect_ = new_window_rect; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1942 | window_screen_rect_ = new_window_rect; |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1943 | if (show_callback_) { |
| 1944 | // Tests may call here directly to control the window rect. If |
| 1945 | // Show() did not happen yet, the rect is stored to be passed to the |
| 1946 | // browser when the RenderWidget requests Show(). |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1947 | initial_rect_ = new_window_rect; |
danakj | 65f423b7 | 2018-10-10 17:21:20 | [diff] [blame] | 1948 | } |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 1949 | } |
| 1950 | |
Vladimir Levin | 98d76dad | 2018-04-21 00:21:29 | [diff] [blame] | 1951 | void RenderWidget::UpdateCaptureSequenceNumber( |
| 1952 | uint32_t capture_sequence_number) { |
| 1953 | if (capture_sequence_number == last_capture_sequence_number_) |
| 1954 | return; |
| 1955 | last_capture_sequence_number_ = capture_sequence_number; |
| 1956 | |
| 1957 | // Notify observers of the new capture sequence number. |
| 1958 | for (auto& observer : render_frame_proxies_) |
| 1959 | observer.UpdateCaptureSequenceNumber(capture_sequence_number); |
| 1960 | for (auto& observer : browser_plugins_) |
| 1961 | observer.UpdateCaptureSequenceNumber(capture_sequence_number); |
| 1962 | } |
| 1963 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1964 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 1965 | if (auto* frame = GetFocusedWebLocalFrameInWidget()) |
| 1966 | frame->SetTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1967 | } |
| 1968 | |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1969 | void RenderWidget::OnUpdateScreenRects(const gfx::Rect& widget_screen_rect, |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1970 | const gfx::Rect& window_screen_rect) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1971 | if (screen_metrics_emulator_) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1972 | screen_metrics_emulator_->OnUpdateScreenRects(widget_screen_rect, |
mfomitchev | 2600fd7c | 2016-02-17 20:53:39 | [diff] [blame] | 1973 | window_screen_rect); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1974 | } else { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1975 | SetScreenRects(widget_screen_rect, window_screen_rect); |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 1976 | } |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 1977 | Send(new WidgetHostMsg_UpdateScreenRects_ACK(routing_id())); |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1978 | } |
| 1979 | |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 1980 | void RenderWidget::OnSetViewportIntersection( |
Ken Buchanan | b2c9e26 | 2018-03-10 16:53:31 | [diff] [blame] | 1981 | const gfx::Rect& viewport_intersection, |
Stefan Zager | 54e2583 | 2018-08-14 22:15:31 | [diff] [blame] | 1982 | const gfx::Rect& compositor_visible_rect, |
| 1983 | bool occluded_or_obscured) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 1984 | if (auto* frame_widget = GetFrameWidget()) { |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 1985 | DCHECK_EQ(widget_type_, WidgetType::kFrame); |
Ken Buchanan | b2c9e26 | 2018-03-10 16:53:31 | [diff] [blame] | 1986 | compositor_visible_rect_ = compositor_visible_rect; |
Stefan Zager | 54e2583 | 2018-08-14 22:15:31 | [diff] [blame] | 1987 | frame_widget->SetRemoteViewportIntersection(viewport_intersection, |
| 1988 | occluded_or_obscured); |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 1989 | layer_tree_view_->SetViewportVisibleRect(ViewportVisibleRect()); |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 1990 | } |
| 1991 | } |
| 1992 | |
kenrb | 0432378 | 2017-06-23 01:23:32 | [diff] [blame] | 1993 | void RenderWidget::OnSetIsInert(bool inert) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 1994 | if (auto* frame_widget = GetFrameWidget()) { |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 1995 | DCHECK_EQ(widget_type_, WidgetType::kFrame); |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 1996 | frame_widget->SetIsInert(inert); |
kenrb | 0432378 | 2017-06-23 01:23:32 | [diff] [blame] | 1997 | } |
| 1998 | } |
| 1999 | |
sunxd | 540a996 | 2018-05-24 22:51:06 | [diff] [blame] | 2000 | void RenderWidget::OnSetInheritedEffectiveTouchAction( |
| 2001 | cc::TouchAction touch_action) { |
| 2002 | if (auto* frame_widget = GetFrameWidget()) { |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 2003 | DCHECK_EQ(widget_type_, WidgetType::kFrame); |
sunxd | 540a996 | 2018-05-24 22:51:06 | [diff] [blame] | 2004 | frame_widget->SetInheritedEffectiveTouchAction(touch_action); |
| 2005 | } |
| 2006 | } |
| 2007 | |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2008 | void RenderWidget::OnUpdateRenderThrottlingStatus(bool is_throttled, |
| 2009 | bool subtree_throttled) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2010 | if (auto* frame_widget = GetFrameWidget()) { |
danakj | 6a81659 | 2018-09-25 18:30:56 | [diff] [blame] | 2011 | DCHECK_EQ(widget_type_, WidgetType::kFrame); |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2012 | frame_widget->UpdateRenderThrottlingStatus(is_throttled, subtree_throttled); |
Ken Buchanan | 8a319fb | 2017-11-15 18:37:12 | [diff] [blame] | 2013 | } |
| 2014 | } |
| 2015 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2016 | void RenderWidget::OnDragTargetDragEnter( |
| 2017 | const std::vector<DropData::Metadata>& drop_meta_data, |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2018 | const gfx::PointF& client_point, |
| 2019 | const gfx::PointF& screen_point, |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2020 | WebDragOperationsMask ops, |
| 2021 | int key_modifiers) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2022 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2023 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2024 | return; |
| 2025 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2026 | WebDragOperation operation = frame_widget->DragTargetDragEnter( |
| 2027 | DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point, |
| 2028 | ops, key_modifiers); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2029 | |
| 2030 | Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation)); |
| 2031 | } |
| 2032 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2033 | void RenderWidget::OnDragTargetDragOver(const gfx::PointF& client_point, |
| 2034 | const gfx::PointF& screen_point, |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2035 | WebDragOperationsMask ops, |
| 2036 | int key_modifiers) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2037 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2038 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2039 | return; |
| 2040 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2041 | WebDragOperation operation = frame_widget->DragTargetDragOver( |
| 2042 | ConvertWindowPointToViewport(client_point), screen_point, ops, |
| 2043 | key_modifiers); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2044 | |
| 2045 | Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation)); |
| 2046 | } |
| 2047 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2048 | void RenderWidget::OnDragTargetDragLeave(const gfx::PointF& client_point, |
| 2049 | const gfx::PointF& screen_point) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2050 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2051 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2052 | return; |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2053 | |
| 2054 | frame_widget |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2055 | ->DragTargetDragLeave(ConvertWindowPointToViewport(client_point), |
kenrb | 07c27280 | 2017-02-07 23:48:17 | [diff] [blame] | 2056 | screen_point); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | void RenderWidget::OnDragTargetDrop(const DropData& drop_data, |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2060 | const gfx::PointF& client_point, |
| 2061 | const gfx::PointF& screen_point, |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2062 | int key_modifiers) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2063 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2064 | if (!frame_widget) |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2065 | return; |
| 2066 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2067 | frame_widget->DragTargetDrop(DropDataToWebDragData(drop_data), |
| 2068 | ConvertWindowPointToViewport(client_point), |
| 2069 | screen_point, key_modifiers); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2070 | } |
| 2071 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2072 | void RenderWidget::OnDragSourceEnded(const gfx::PointF& client_point, |
| 2073 | const gfx::PointF& screen_point, |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2074 | WebDragOperation op) { |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2075 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 2076 | if (!frame_widget) |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2077 | return; |
| 2078 | |
Ehsan Karamad | f3ca2a8 | 2018-01-20 01:05:25 | [diff] [blame] | 2079 | frame_widget->DragSourceEndedAt(ConvertWindowPointToViewport(client_point), |
| 2080 | screen_point, op); |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | void RenderWidget::OnDragSourceSystemDragEnded() { |
| 2084 | if (!GetWebWidget()) |
| 2085 | return; |
| 2086 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2087 | static_cast<WebFrameWidget*>(GetWebWidget())->DragSourceSystemDragEnded(); |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2088 | } |
| 2089 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2090 | void RenderWidget::ShowVirtualKeyboardOnElementFocus() { |
oka | a398f50b | 2017-03-21 06:30:26 | [diff] [blame] | 2091 | #if defined(OS_CHROMEOS) |
| 2092 | // On ChromeOS, virtual keyboard is triggered only when users leave the |
| 2093 | // mouse button or the finger and a text input element is focused at that |
| 2094 | // time. Focus event itself shouldn't trigger virtual keyboard. |
| 2095 | UpdateTextInputState(); |
| 2096 | #else |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2097 | ShowVirtualKeyboard(); |
oka | a398f50b | 2017-03-21 06:30:26 | [diff] [blame] | 2098 | #endif |
boliu | 7b2be2f | 2016-11-04 04:58:31 | [diff] [blame] | 2099 | |
| 2100 | // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
| 2101 | // virtual keyboard. |
| 2102 | #if !defined(OS_ANDROID) |
| 2103 | FocusChangeComplete(); |
| 2104 | #endif |
[email protected] | 0d1ebed1 | 2013-08-05 22:01:13 | [diff] [blame] | 2105 | } |
| 2106 | |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2107 | ui::TextInputType RenderWidget::GetTextInputType() { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2108 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2109 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) |
| 2110 | return plugin->text_input_type(); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2111 | #endif |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 2112 | if (auto* controller = GetInputMethodController()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2113 | return ConvertWebTextInputType(controller->TextInputType()); |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2114 | return ui::TEXT_INPUT_TYPE_NONE; |
| 2115 | } |
| 2116 | |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2117 | void RenderWidget::UpdateCompositionInfo(bool immediate_request) { |
| 2118 | if (!monitor_composition_info_ && !immediate_request) |
| 2119 | return; // Do not calculate composition info if not requested. |
nona | dac0c7a | 2016-08-01 02:30:59 | [diff] [blame] | 2120 | |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2121 | TRACE_EVENT0("renderer", "RenderWidget::UpdateCompositionInfo"); |
| 2122 | gfx::Range range; |
| 2123 | std::vector<gfx::Rect> character_bounds; |
| 2124 | |
| 2125 | if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 2126 | // Composition information is only available on editable node. |
| 2127 | range = gfx::Range::InvalidRange(); |
| 2128 | } else { |
| 2129 | GetCompositionRange(&range); |
| 2130 | GetCompositionCharacterBounds(&character_bounds); |
| 2131 | } |
| 2132 | |
| 2133 | if (!immediate_request && |
| 2134 | !ShouldUpdateCompositionInfo(range, character_bounds)) { |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2135 | return; |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2136 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2137 | composition_character_bounds_ = character_bounds; |
| 2138 | composition_range_ = range; |
Dave Tapuska | 04bc5ee9 | 2018-04-17 19:03:31 | [diff] [blame] | 2139 | if (mojom::WidgetInputHandlerHost* host = |
| 2140 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 2141 | host->ImeCompositionRangeChanged(composition_range_, |
| 2142 | composition_character_bounds_); |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 2143 | } |
fsamuel | 72464894f | 2015-12-15 06:59:31 | [diff] [blame] | 2144 | } |
| 2145 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2146 | void RenderWidget::ConvertViewportToWindow(blink::WebRect* rect) { |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 2147 | if (compositor_deps_->IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2148 | float reverse = 1 / GetOriginalScreenInfo().device_scale_factor; |
oshima | d527903 | 2015-12-16 18:22:33 | [diff] [blame] | 2149 | // TODO(oshima): We may need to allow pixel precision here as the the |
oshima | f866dab | 2015-12-05 00:41:54 | [diff] [blame] | 2150 | // anchor element can be placed at half pixel. |
lfg | 15b235a3 | 2016-08-25 17:45:46 | [diff] [blame] | 2151 | gfx::Rect window_rect = |
| 2152 | gfx::ScaleToEnclosedRect(gfx::Rect(*rect), reverse); |
| 2153 | rect->x = window_rect.x(); |
| 2154 | rect->y = window_rect.y(); |
| 2155 | rect->width = window_rect.width(); |
| 2156 | rect->height = window_rect.height(); |
oshima | f866dab | 2015-12-05 00:41:54 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2160 | void RenderWidget::ConvertWindowToViewport(blink::WebFloatRect* rect) { |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 2161 | if (compositor_deps_->IsUseZoomForDSFEnabled()) { |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2162 | rect->x *= GetOriginalScreenInfo().device_scale_factor; |
| 2163 | rect->y *= GetOriginalScreenInfo().device_scale_factor; |
| 2164 | rect->width *= GetOriginalScreenInfo().device_scale_factor; |
| 2165 | rect->height *= GetOriginalScreenInfo().device_scale_factor; |
oshima | a6985b6 | 2016-01-27 08:58:30 | [diff] [blame] | 2166 | } |
| 2167 | } |
| 2168 | |
changwan | 8c34274 | 2016-02-26 00:53:39 | [diff] [blame] | 2169 | void RenderWidget::OnRequestTextInputStateUpdate() { |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 2170 | #if defined(OS_ANDROID) |
changwan | 8c34274 | 2016-02-26 00:53:39 | [diff] [blame] | 2171 | DCHECK(!ime_event_guard_); |
| 2172 | UpdateSelectionBounds(); |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2173 | UpdateTextInputStateInternal(false, true /* reply_to_request */); |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 2174 | #endif |
Dave Tapuska | 9db8084 | 2017-07-24 17:24:26 | [diff] [blame] | 2175 | } |
[email protected] | 105dffb4 | 2013-02-20 03:46:21 | [diff] [blame] | 2176 | |
ekaramad | c9b70a7 | 2017-03-23 16:14:23 | [diff] [blame] | 2177 | void RenderWidget::OnRequestCompositionUpdates(bool immediate_request, |
| 2178 | bool monitor_updates) { |
| 2179 | monitor_composition_info_ = monitor_updates; |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2180 | if (!immediate_request) |
| 2181 | return; |
| 2182 | UpdateCompositionInfo(true /* immediate request */); |
| 2183 | } |
| 2184 | |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 2185 | void RenderWidget::OnOrientationChange() { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2186 | if (auto* frame_widget = GetFrameWidget()) { |
Alex Moshchuk | 0b409c4 | 2017-09-13 02:09:00 | [diff] [blame] | 2187 | // LocalRoot() might return null for provisional main frames. In this case, |
| 2188 | // the frame hasn't committed a navigation and is not swapped into the tree |
| 2189 | // yet, so it doesn't make sense to send orientation change events to it. |
| 2190 | // |
| 2191 | // TODO(https://crbug.com/578349): This check should be cleaned up |
| 2192 | // once provisional frames are gone. |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 2193 | if (frame_widget->LocalRoot()) |
| 2194 | frame_widget->LocalRoot()->SendOrientationChangeEvent(); |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 2195 | } |
[email protected] | fcdc564 | 2014-05-09 14:32:24 | [diff] [blame] | 2196 | } |
| 2197 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 2198 | void RenderWidget::SetHidden(bool hidden) { |
| 2199 | if (is_hidden_ == hidden) |
| 2200 | return; |
| 2201 | |
jdduke | 8fac9d10 | 2014-12-20 02:40:13 | [diff] [blame] | 2202 | // The status has changed. Tell the RenderThread about it and ensure |
| 2203 | // throttled acks are released in case frame production ceases. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 2204 | is_hidden_ = hidden; |
jdduke | 8fac9d10 | 2014-12-20 02:40:13 | [diff] [blame] | 2205 | |
Scott Violet | 1098538e | 2017-10-05 19:23:33 | [diff] [blame] | 2206 | #if defined(USE_AURA) |
Scott Violet | e46b335 | 2018-09-22 00:37:07 | [diff] [blame] | 2207 | if (features::IsMultiProcessMash()) |
Scott Violet | 1098538e | 2017-10-05 19:23:33 | [diff] [blame] | 2208 | RendererWindowTreeClient::Get(routing_id_)->SetVisible(!hidden); |
| 2209 | #endif |
| 2210 | |
Saman Sami | 58ed439 | 2018-01-31 20:54:19 | [diff] [blame] | 2211 | // RenderThreadImpl::current() could be null in tests. |
| 2212 | if (RenderThreadImpl::current()) { |
| 2213 | if (is_hidden_) { |
| 2214 | RenderThreadImpl::current()->WidgetHidden(); |
| 2215 | first_update_visual_state_after_hidden_ = true; |
| 2216 | } else { |
| 2217 | RenderThreadImpl::current()->WidgetRestored(); |
| 2218 | } |
Lei Zhang | 9b359d3 | 2017-11-28 00:57:02 | [diff] [blame] | 2219 | } |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 2220 | |
| 2221 | if (render_widget_scheduling_state_) |
| 2222 | render_widget_scheduling_state_->SetHidden(hidden); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 2223 | } |
| 2224 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2225 | void RenderWidget::DidToggleFullscreen() { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2226 | if (!GetWebWidget()) |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2227 | return; |
| 2228 | |
mikhail.pozdnyakov | f2c902a | 2015-04-14 08:09:12 | [diff] [blame] | 2229 | if (is_fullscreen_granted_) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2230 | GetWebWidget()->DidEnterFullscreen(); |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2231 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2232 | GetWebWidget()->DidExitFullscreen(); |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2233 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 2234 | } |
| 2235 | |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2236 | void RenderWidget::OnImeEventGuardStart(ImeEventGuard* guard) { |
| 2237 | if (!ime_event_guard_) |
| 2238 | ime_event_guard_ = guard; |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2239 | } |
| 2240 | |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2241 | void RenderWidget::OnImeEventGuardFinish(ImeEventGuard* guard) { |
Jeremy Roman | 0b261f4 | 2018-08-28 15:36:01 | [diff] [blame] | 2242 | if (ime_event_guard_ != guard) |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2243 | return; |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2244 | ime_event_guard_ = nullptr; |
| 2245 | |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2246 | // While handling an ime event, text input state and selection bounds updates |
| 2247 | // are ignored. These must explicitly be updated once finished handling the |
| 2248 | // ime event. |
| 2249 | UpdateSelectionBounds(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2250 | #if defined(OS_ANDROID) |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2251 | if (guard->show_virtual_keyboard()) |
| 2252 | ShowVirtualKeyboard(); |
| 2253 | else |
| 2254 | UpdateTextInputState(); |
[email protected] | cb9e263 | 2013-06-18 11:26:47 | [diff] [blame] | 2255 | #endif |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2256 | } |
| 2257 | |
[email protected] | 7c8873e | 2013-02-05 08:03:01 | [diff] [blame] | 2258 | void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2259 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2260 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) { |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2261 | // TODO(kinaba) http://crbug.com/101101 |
| 2262 | // Current Pepper IME API does not handle selection bounds. So we simply |
| 2263 | // use the caret position as an empty range for now. It will be updated |
| 2264 | // after Pepper API equips features related to surrounding text retrieval. |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2265 | blink::WebRect caret(plugin->GetCaretBounds()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2266 | ConvertViewportToWindow(&caret); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2267 | *focus = caret; |
| 2268 | *anchor = caret; |
| 2269 | return; |
| 2270 | } |
| 2271 | #endif |
[email protected] | 7c8873e | 2013-02-05 08:03:01 | [diff] [blame] | 2272 | WebRect focus_webrect; |
| 2273 | WebRect anchor_webrect; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2274 | GetWebWidget()->SelectionBounds(focus_webrect, anchor_webrect); |
| 2275 | ConvertViewportToWindow(&focus_webrect); |
| 2276 | ConvertViewportToWindow(&anchor_webrect); |
oshima | 33ec97cd | 2015-12-14 19:40:24 | [diff] [blame] | 2277 | *focus = focus_webrect; |
| 2278 | *anchor = anchor_webrect; |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 2279 | } |
| 2280 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2281 | void RenderWidget::UpdateSelectionBounds() { |
jdduke | 1aebad8e | 2015-07-22 23:25:08 | [diff] [blame] | 2282 | TRACE_EVENT0("renderer", "RenderWidget::UpdateSelectionBounds"); |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2283 | if (!GetWebWidget()) |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2284 | return; |
changwan | f2a707b | 2015-10-30 08:22:16 | [diff] [blame] | 2285 | if (ime_event_guard_) |
[email protected] | 66fca5bc | 2013-05-23 06:58:29 | [diff] [blame] | 2286 | return; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2287 | |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 2288 | #if defined(USE_AURA) |
| 2289 | // TODO(mohsen): For now, always send explicit selection IPC notifications for |
| 2290 | // Aura beucause composited selection updates are not working for webview tags |
| 2291 | // which regresses IME inside webview. Remove this when composited selection |
| 2292 | // updates are fixed for webviews. See, http://crbug.com/510568. |
| 2293 | bool send_ipc = true; |
| 2294 | #else |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2295 | // With composited selection updates, the selection bounds will be reported |
| 2296 | // directly by the compositor, in which case explicit IPC selection |
| 2297 | // notifications should be suppressed. |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 2298 | bool send_ipc = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2299 | !blink::WebRuntimeFeatures::IsCompositedSelectionUpdateEnabled(); |
mohsen | b0eeba7 | 2015-08-09 06:20:08 | [diff] [blame] | 2300 | #endif |
| 2301 | if (send_ipc) { |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 2302 | WidgetHostMsg_SelectionBounds_Params params; |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 2303 | params.is_anchor_first = false; |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2304 | GetSelectionBounds(¶ms.anchor_rect, ¶ms.focus_rect); |
| 2305 | if (selection_anchor_rect_ != params.anchor_rect || |
| 2306 | selection_focus_rect_ != params.focus_rect) { |
| 2307 | selection_anchor_rect_ = params.anchor_rect; |
| 2308 | selection_focus_rect_ = params.focus_rect; |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 2309 | if (auto* focused_frame = GetFocusedWebLocalFrameInWidget()) { |
| 2310 | focused_frame->SelectionTextDirection(params.focus_dir, |
| 2311 | params.anchor_dir); |
| 2312 | params.is_anchor_first = focused_frame->IsSelectionAnchorFirst(); |
| 2313 | } |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 2314 | Send(new WidgetHostMsg_SelectionBoundsChanged(routing_id_, params)); |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2315 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2316 | } |
jdduke | acf809e | 2014-09-23 20:38:38 | [diff] [blame] | 2317 | |
nona | fa29179 | 2016-08-10 02:36:18 | [diff] [blame] | 2318 | UpdateCompositionInfo(false /* not an immediate request */); |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 2319 | } |
| 2320 | |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2321 | void RenderWidget::DidAutoResize(const gfx::Size& new_size) { |
| 2322 | WebRect new_size_in_window(0, 0, new_size.width(), new_size.height()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2323 | ConvertViewportToWindow(&new_size_in_window); |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2324 | if (size_.width() != new_size_in_window.width || |
| 2325 | size_.height() != new_size_in_window.height) { |
| 2326 | size_ = gfx::Size(new_size_in_window.width, new_size_in_window.height); |
| 2327 | |
| 2328 | if (resizing_mode_selector_->is_synchronous_mode()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2329 | gfx::Rect new_pos(WindowRect().x, WindowRect().y, size_.width(), |
| 2330 | size_.height()); |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 2331 | widget_screen_rect_ = new_pos; |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2332 | window_screen_rect_ = new_pos; |
| 2333 | } |
| 2334 | |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2335 | // TODO(ccameron): Note that this destroys any information differentiating |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 2336 | // |size_| from |compositor_viewport_pixel_size_|. Also note that the |
| 2337 | // calculation of |new_compositor_viewport_pixel_size| does not appear to |
| 2338 | // take into account device emulation. |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 2339 | if (layer_tree_view_) |
| 2340 | layer_tree_view_->RequestNewLocalSurfaceId(); |
Christopher Cameron | aad15a0d | 2018-03-09 03:47:33 | [diff] [blame] | 2341 | gfx::Size new_compositor_viewport_pixel_size = |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2342 | gfx::ScaleToCeiledSize(size_, GetWebScreenInfo().device_scale_factor); |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 2343 | UpdateSurfaceAndScreenInfo( |
| 2344 | local_surface_id_from_parent_, allocation_time_from_parent_, |
| 2345 | new_compositor_viewport_pixel_size, screen_info_); |
lfg | b00fcad | 2016-07-14 14:16:33 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2349 | void RenderWidget::GetCompositionCharacterBounds( |
| 2350 | std::vector<gfx::Rect>* bounds) { |
| 2351 | DCHECK(bounds); |
| 2352 | bounds->clear(); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2353 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2354 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2355 | if (GetFocusedPepperPluginInsideWidget()) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2356 | return; |
| 2357 | #endif |
| 2358 | |
Ehsan Karamad | 4975af6d | 2018-02-09 16:58:16 | [diff] [blame] | 2359 | blink::WebInputMethodController* controller = GetInputMethodController(); |
| 2360 | if (!controller) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2361 | return; |
| 2362 | blink::WebVector<blink::WebRect> bounds_from_blink; |
Ehsan Karamad | 4975af6d | 2018-02-09 16:58:16 | [diff] [blame] | 2363 | if (!controller->GetCompositionCharacterBounds(bounds_from_blink)) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2364 | return; |
| 2365 | |
| 2366 | for (size_t i = 0; i < bounds_from_blink.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2367 | ConvertViewportToWindow(&bounds_from_blink[i]); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2368 | bounds->push_back(bounds_from_blink[i]); |
| 2369 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 2370 | } |
| 2371 | |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2372 | void RenderWidget::GetCompositionRange(gfx::Range* range) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2373 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2374 | if (GetFocusedPepperPluginInsideWidget()) |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2375 | return; |
| 2376 | #endif |
EhsanK | cdee7b7 | 2017-11-08 21:30:09 | [diff] [blame] | 2377 | blink::WebInputMethodController* controller = GetInputMethodController(); |
| 2378 | WebRange web_range = controller ? controller->CompositionRange() : WebRange(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2379 | if (web_range.IsNull()) { |
nona | 2363a3d | 2016-11-09 03:26:21 | [diff] [blame] | 2380 | *range = gfx::Range::InvalidRange(); |
| 2381 | return; |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2382 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2383 | range->set_start(web_range.StartOffset()); |
| 2384 | range->set_end(web_range.EndOffset()); |
[email protected] | 88dbe32f | 2013-06-20 23:31:36 | [diff] [blame] | 2385 | } |
| 2386 | |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2387 | bool RenderWidget::ShouldUpdateCompositionInfo( |
[email protected] | db4fc1e | 2013-09-06 20:01:51 | [diff] [blame] | 2388 | const gfx::Range& range, |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2389 | const std::vector<gfx::Rect>& bounds) { |
changwan | 2418e1b | 2016-12-12 12:43:08 | [diff] [blame] | 2390 | if (!range.IsValid()) |
| 2391 | return false; |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2392 | if (composition_range_ != range) |
| 2393 | return true; |
| 2394 | if (bounds.size() != composition_character_bounds_.size()) |
| 2395 | return true; |
| 2396 | for (size_t i = 0; i < bounds.size(); ++i) { |
| 2397 | if (bounds[i] != composition_character_bounds_[i]) |
| 2398 | return true; |
| 2399 | } |
| 2400 | return false; |
| 2401 | } |
[email protected] | 501ea13d | 2013-07-09 17:03:29 | [diff] [blame] | 2402 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2403 | bool RenderWidget::CanComposeInline() { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2404 | #if BUILDFLAG(ENABLE_PLUGINS) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 2405 | if (auto* plugin = GetFocusedPepperPluginInsideWidget()) |
| 2406 | return plugin->IsPluginAcceptingCompositionEvents(); |
ekaramad | 2a46d63 | 2016-07-19 13:33:09 | [diff] [blame] | 2407 | #endif |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 2408 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 2409 | } |
| 2410 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2411 | void RenderWidget::DidHandleGestureEvent(const WebGestureEvent& event, |
| 2412 | bool event_cancelled) { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2413 | if (event_cancelled) { |
| 2414 | // The |owner_delegate_| doesn't need to hear about cancelled events. |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2415 | return; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | #if defined(OS_ANDROID) || defined(USE_AURA) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2419 | if (event.GetType() == WebInputEvent::kGestureTap) { |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2420 | ShowVirtualKeyboard(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2421 | } else if (event.GetType() == WebInputEvent::kGestureLongPress) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 2422 | DCHECK(GetWebWidget()); |
ekaramad | 5aff194 | 2017-01-06 01:26:35 | [diff] [blame] | 2423 | blink::WebInputMethodController* controller = GetInputMethodController(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2424 | if (!controller || controller->TextInputInfo().value.IsEmpty()) |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2425 | UpdateTextInputState(); |
[email protected] | 07c70d2 | 2014-08-21 08:33:46 | [diff] [blame] | 2426 | else |
changwan | 75e3b207 | 2017-01-16 02:55:00 | [diff] [blame] | 2427 | ShowVirtualKeyboard(); |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2428 | } |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2429 | // TODO(ananta): Piggyback off existing IPCs to communicate this information, |
| 2430 | // crbug/420130. |
| 2431 | #if defined(OS_WIN) |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2432 | if (event.GetType() == blink::WebGestureEvent::kGestureTap) { |
| 2433 | // TODO(estade): hit test the event against focused node to make sure |
| 2434 | // the tap actually hit the focused node. |
| 2435 | blink::WebInputMethodController* controller = GetInputMethodController(); |
| 2436 | blink::WebTextInputType text_input_type = |
| 2437 | controller ? controller->TextInputType() : blink::kWebTextInputTypeNone; |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2438 | |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 2439 | Send(new WidgetHostMsg_FocusedNodeTouched( |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2440 | routing_id_, text_input_type != blink::kWebTextInputTypeNone)); |
| 2441 | } |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 2442 | #endif |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2443 | #endif |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 2444 | |
| 2445 | // The |owner_delegate_| gets to respond to handling gestures last. |
| 2446 | if (owner_delegate_) |
| 2447 | owner_delegate_->DidHandleGestureEventForWidget(event); |
[email protected] | c68c3e4e | 2013-01-24 00:36:56 | [diff] [blame] | 2448 | } |
| 2449 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2450 | void RenderWidget::DidOverscroll( |
bokan | e53a10f | 2016-04-13 23:48:31 | [diff] [blame] | 2451 | const blink::WebFloatSize& overscrollDelta, |
| 2452 | const blink::WebFloatSize& accumulatedOverscroll, |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2453 | const blink::WebFloatPoint& position, |
sunyunjia | bbea8a9 | 2017-08-31 11:18:54 | [diff] [blame] | 2454 | const blink::WebFloatSize& velocity, |
danakj | e819b62 | 2018-05-01 20:27:14 | [diff] [blame] | 2455 | const cc::OverscrollBehavior& behavior) { |
bokan | 731ec38 | 2016-04-07 03:16:48 | [diff] [blame] | 2456 | #if defined(OS_MACOSX) |
| 2457 | // On OSX the user can disable the elastic overscroll effect. If that's the |
| 2458 | // case, don't forward the overscroll notification. |
| 2459 | DCHECK(compositor_deps()); |
| 2460 | if (!compositor_deps()->IsElasticOverscrollEnabled()) |
| 2461 | return; |
| 2462 | #endif |
bokan | e53a10f | 2016-04-13 23:48:31 | [diff] [blame] | 2463 | input_handler_->DidOverscrollFromBlink(overscrollDelta, accumulatedOverscroll, |
sunyunjia | bbea8a9 | 2017-08-31 11:18:54 | [diff] [blame] | 2464 | position, velocity, behavior); |
sataya.m | 582c9ce | 2015-06-09 08:03:42 | [diff] [blame] | 2465 | } |
| 2466 | |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 2467 | // static |
| 2468 | cc::LayerTreeSettings RenderWidget::GenerateLayerTreeSettings( |
| 2469 | CompositorDependencies* compositor_deps, |
| 2470 | bool is_for_subframe, |
| 2471 | const gfx::Size& initial_screen_size, |
| 2472 | float initial_device_scale_factor) { |
| 2473 | const bool is_threaded = |
| 2474 | !!compositor_deps->GetCompositorImplThreadTaskRunner(); |
| 2475 | |
| 2476 | const base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess(); |
| 2477 | cc::LayerTreeSettings settings; |
| 2478 | |
| 2479 | settings.resource_settings.use_r16_texture = |
| 2480 | base::FeatureList::IsEnabled(media::kUseR16Texture); |
| 2481 | |
| 2482 | settings.commit_to_active_tree = !is_threaded; |
| 2483 | settings.is_layer_tree_for_subframe = is_for_subframe; |
| 2484 | |
| 2485 | // For web contents, layer transforms should scale up the contents of layers |
| 2486 | // to keep content always crisp when possible. |
| 2487 | settings.layer_transforms_should_scale_layer_contents = true; |
| 2488 | |
| 2489 | settings.main_frame_before_activation_enabled = |
| 2490 | cmd.HasSwitch(cc::switches::kEnableMainFrameBeforeActivation); |
| 2491 | |
| 2492 | // Checkerimaging is not supported for synchronous single-threaded mode, which |
| 2493 | // is what the renderer uses if its not threaded. |
| 2494 | settings.enable_checker_imaging = |
| 2495 | !cmd.HasSwitch(cc::switches::kDisableCheckerImaging) && is_threaded; |
| 2496 | |
| 2497 | #if defined(OS_ANDROID) |
| 2498 | // We can use a more aggressive limit on Android since decodes tend to take |
| 2499 | // longer on these devices. |
| 2500 | settings.min_image_bytes_to_checker = 512 * 1024; // 512kB |
| 2501 | |
| 2502 | // Re-rasterization of checker-imaged content with software raster can be too |
| 2503 | // costly on Android. |
| 2504 | settings.only_checker_images_with_gpu_raster = true; |
| 2505 | #endif |
| 2506 | |
| 2507 | auto switch_value_as_int = [](const base::CommandLine& command_line, |
| 2508 | const std::string& switch_string, int min_value, |
| 2509 | int max_value, int* result) { |
| 2510 | std::string string_value = command_line.GetSwitchValueASCII(switch_string); |
| 2511 | int int_value; |
| 2512 | if (base::StringToInt(string_value, &int_value) && int_value >= min_value && |
| 2513 | int_value <= max_value) { |
| 2514 | *result = int_value; |
| 2515 | return true; |
| 2516 | } else { |
| 2517 | LOG(WARNING) << "Failed to parse switch " << switch_string << ": " |
| 2518 | << string_value; |
| 2519 | return false; |
| 2520 | } |
| 2521 | }; |
| 2522 | |
| 2523 | int default_tile_size = 256; |
| 2524 | #if defined(OS_ANDROID) |
| 2525 | const gfx::Size screen_size = |
| 2526 | gfx::ScaleToFlooredSize(initial_screen_size, initial_device_scale_factor); |
| 2527 | int display_width = screen_size.width(); |
| 2528 | int display_height = screen_size.height(); |
| 2529 | int numTiles = (display_width * display_height) / (256 * 256); |
| 2530 | if (numTiles > 16) |
| 2531 | default_tile_size = 384; |
| 2532 | if (numTiles >= 40) |
| 2533 | default_tile_size = 512; |
| 2534 | |
| 2535 | // Adjust for some resolutions that barely straddle an extra |
| 2536 | // tile when in portrait mode. This helps worst case scroll/raster |
| 2537 | // by not needing a full extra tile for each row. |
| 2538 | constexpr int tolerance = 10; // To avoid rounding errors. |
| 2539 | int portrait_width = std::min(display_width, display_height); |
| 2540 | if (default_tile_size == 256 && std::abs(portrait_width - 768) < tolerance) |
| 2541 | default_tile_size += 32; |
| 2542 | if (default_tile_size == 384 && std::abs(portrait_width - 1200) < tolerance) |
| 2543 | default_tile_size += 32; |
| 2544 | #elif defined(OS_CHROMEOS) || defined(OS_MACOSX) |
| 2545 | // Use 512 for high DPI (dsf=2.0f) devices. |
| 2546 | if (initial_device_scale_factor >= 2.0f) |
| 2547 | default_tile_size = 512; |
| 2548 | #endif |
| 2549 | |
| 2550 | // TODO(danakj): This should not be a setting O_O; it should change when the |
| 2551 | // device scale factor on LayerTreeHost changes. |
| 2552 | settings.default_tile_size = gfx::Size(default_tile_size, default_tile_size); |
| 2553 | if (cmd.HasSwitch(switches::kDefaultTileWidth)) { |
| 2554 | int tile_width = 0; |
| 2555 | switch_value_as_int(cmd, switches::kDefaultTileWidth, 1, |
| 2556 | std::numeric_limits<int>::max(), &tile_width); |
| 2557 | settings.default_tile_size.set_width(tile_width); |
| 2558 | } |
| 2559 | if (cmd.HasSwitch(switches::kDefaultTileHeight)) { |
| 2560 | int tile_height = 0; |
| 2561 | switch_value_as_int(cmd, switches::kDefaultTileHeight, 1, |
| 2562 | std::numeric_limits<int>::max(), &tile_height); |
| 2563 | settings.default_tile_size.set_height(tile_height); |
| 2564 | } |
| 2565 | |
| 2566 | int max_untiled_layer_width = settings.max_untiled_layer_size.width(); |
| 2567 | if (cmd.HasSwitch(switches::kMaxUntiledLayerWidth)) { |
| 2568 | switch_value_as_int(cmd, switches::kMaxUntiledLayerWidth, 1, |
| 2569 | std::numeric_limits<int>::max(), |
| 2570 | &max_untiled_layer_width); |
| 2571 | } |
| 2572 | int max_untiled_layer_height = settings.max_untiled_layer_size.height(); |
| 2573 | if (cmd.HasSwitch(switches::kMaxUntiledLayerHeight)) { |
| 2574 | switch_value_as_int(cmd, switches::kMaxUntiledLayerHeight, 1, |
| 2575 | std::numeric_limits<int>::max(), |
| 2576 | &max_untiled_layer_height); |
| 2577 | } |
| 2578 | |
| 2579 | settings.max_untiled_layer_size = |
| 2580 | gfx::Size(max_untiled_layer_width, max_untiled_layer_height); |
| 2581 | |
| 2582 | settings.gpu_rasterization_msaa_sample_count = |
| 2583 | compositor_deps->GetGpuRasterizationMSAASampleCount(); |
| 2584 | settings.gpu_rasterization_forced = |
| 2585 | compositor_deps->IsGpuRasterizationForced(); |
| 2586 | |
| 2587 | settings.can_use_lcd_text = compositor_deps->IsLcdTextEnabled(); |
| 2588 | settings.use_zero_copy = compositor_deps->IsZeroCopyEnabled(); |
| 2589 | settings.use_partial_raster = compositor_deps->IsPartialRasterEnabled(); |
| 2590 | settings.enable_elastic_overscroll = |
| 2591 | compositor_deps->IsElasticOverscrollEnabled(); |
| 2592 | settings.resource_settings.use_gpu_memory_buffer_resources = |
| 2593 | compositor_deps->IsGpuMemoryBufferCompositorResourcesEnabled(); |
| 2594 | settings.use_painted_device_scale_factor = |
| 2595 | compositor_deps->IsUseZoomForDSFEnabled(); |
| 2596 | |
| 2597 | // Build LayerTreeSettings from command line args. |
| 2598 | if (cmd.HasSwitch(cc::switches::kBrowserControlsShowThreshold)) { |
| 2599 | std::string top_threshold_str = |
| 2600 | cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsShowThreshold); |
| 2601 | double show_threshold; |
| 2602 | if (base::StringToDouble(top_threshold_str, &show_threshold) && |
| 2603 | show_threshold >= 0.f && show_threshold <= 1.f) |
| 2604 | settings.top_controls_show_threshold = show_threshold; |
| 2605 | } |
| 2606 | |
| 2607 | if (cmd.HasSwitch(cc::switches::kBrowserControlsHideThreshold)) { |
| 2608 | std::string top_threshold_str = |
| 2609 | cmd.GetSwitchValueASCII(cc::switches::kBrowserControlsHideThreshold); |
| 2610 | double hide_threshold; |
| 2611 | if (base::StringToDouble(top_threshold_str, &hide_threshold) && |
| 2612 | hide_threshold >= 0.f && hide_threshold <= 1.f) |
| 2613 | settings.top_controls_hide_threshold = hide_threshold; |
| 2614 | } |
| 2615 | |
Philip Rogers | fc2f116 | 2018-10-17 18:28:31 | [diff] [blame] | 2616 | // Blink sends cc a layer list and property trees when either Blink Gen |
| 2617 | // Property Trees or Slimming Paint V2 are enabled. |
| 2618 | settings.use_layer_lists = |
| 2619 | blink::WebRuntimeFeatures::IsBlinkGenPropertyTreesEnabled() || |
| 2620 | blink::WebRuntimeFeatures::IsSlimmingPaintV2Enabled(); |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 2621 | |
David Bokan | 163b6a7 | 2018-10-25 22:03:49 | [diff] [blame] | 2622 | // Blink currently doesn't support setting fractional scroll offsets so CC |
| 2623 | // must send integer values. We plan to eventually make Blink use fractional |
| 2624 | // offsets internally: https://crbug.com/414283. |
| 2625 | settings.commit_fractional_scroll_deltas = |
| 2626 | blink::WebRuntimeFeatures::IsFractionalScrollOffsetsEnabled(); |
| 2627 | |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 2628 | // The means the renderer compositor has 2 possible modes: |
| 2629 | // - Threaded compositing with a scheduler. |
| 2630 | // - Single threaded compositing without a scheduler (for layout tests only). |
| 2631 | // Using the scheduler in layout tests introduces additional composite steps |
| 2632 | // that create flakiness. |
| 2633 | settings.single_thread_proxy_scheduler = false; |
| 2634 | |
| 2635 | // These flags should be mirrored by UI versions in ui/compositor/. |
| 2636 | if (cmd.HasSwitch(cc::switches::kShowCompositedLayerBorders)) |
| 2637 | settings.initial_debug_state.show_debug_borders.set(); |
| 2638 | settings.initial_debug_state.show_layer_animation_bounds_rects = |
| 2639 | cmd.HasSwitch(cc::switches::kShowLayerAnimationBounds); |
| 2640 | settings.initial_debug_state.show_paint_rects = |
| 2641 | cmd.HasSwitch(switches::kShowPaintRects); |
| 2642 | settings.initial_debug_state.show_property_changed_rects = |
| 2643 | cmd.HasSwitch(cc::switches::kShowPropertyChangedRects); |
| 2644 | settings.initial_debug_state.show_surface_damage_rects = |
| 2645 | cmd.HasSwitch(cc::switches::kShowSurfaceDamageRects); |
| 2646 | settings.initial_debug_state.show_screen_space_rects = |
| 2647 | cmd.HasSwitch(cc::switches::kShowScreenSpaceRects); |
| 2648 | |
| 2649 | settings.initial_debug_state.SetRecordRenderingStats( |
| 2650 | cmd.HasSwitch(cc::switches::kEnableGpuBenchmarking)); |
| 2651 | settings.enable_surface_synchronization = |
| 2652 | features::IsSurfaceSynchronizationEnabled(); |
| 2653 | settings.build_hit_test_data = features::IsVizHitTestingSurfaceLayerEnabled(); |
| 2654 | |
| 2655 | if (cmd.HasSwitch(cc::switches::kSlowDownRasterScaleFactor)) { |
| 2656 | const int kMinSlowDownScaleFactor = 0; |
| 2657 | const int kMaxSlowDownScaleFactor = INT_MAX; |
| 2658 | switch_value_as_int( |
| 2659 | cmd, cc::switches::kSlowDownRasterScaleFactor, kMinSlowDownScaleFactor, |
| 2660 | kMaxSlowDownScaleFactor, |
| 2661 | &settings.initial_debug_state.slow_down_raster_scale_factor); |
| 2662 | } |
| 2663 | |
| 2664 | // This is default overlay scrollbar settings for Android and DevTools mobile |
| 2665 | // emulator. Aura Overlay Scrollbar will override below. |
| 2666 | settings.scrollbar_animator = cc::LayerTreeSettings::ANDROID_OVERLAY; |
| 2667 | settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128); |
| 2668 | settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(300); |
| 2669 | settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300); |
| 2670 | |
| 2671 | #if defined(OS_ANDROID) |
| 2672 | bool using_synchronous_compositor = |
| 2673 | compositor_deps->UsingSynchronousCompositing(); |
| 2674 | bool using_low_memory_policy = base::SysInfo::IsLowEndDevice(); |
| 2675 | |
| 2676 | settings.use_stream_video_draw_quad = true; |
| 2677 | settings.using_synchronous_renderer_compositor = using_synchronous_compositor; |
| 2678 | if (using_synchronous_compositor) { |
| 2679 | // Android WebView uses system scrollbars, so make ours invisible. |
| 2680 | // http://crbug.com/677348: This can't be done using hide_scrollbars |
| 2681 | // setting because supporting -webkit custom scrollbars is still desired |
| 2682 | // on sublayers. |
| 2683 | settings.scrollbar_animator = cc::LayerTreeSettings::NO_ANIMATOR; |
| 2684 | settings.solid_color_scrollbar_color = SK_ColorTRANSPARENT; |
| 2685 | |
| 2686 | settings.enable_early_damage_check = |
| 2687 | cmd.HasSwitch(cc::switches::kCheckDamageEarly); |
| 2688 | } |
| 2689 | // Android WebView handles root layer flings itself. |
| 2690 | settings.ignore_root_layer_flings = using_synchronous_compositor; |
| 2691 | // Memory policy on Android WebView does not depend on whether device is |
| 2692 | // low end, so always use default policy. |
| 2693 | if (using_low_memory_policy && !using_synchronous_compositor) { |
| 2694 | // On low-end we want to be very carefull about killing other |
| 2695 | // apps. So initially we use 50% more memory to avoid flickering |
| 2696 | // or raster-on-demand. |
| 2697 | settings.max_memory_for_prepaint_percentage = 67; |
| 2698 | } else { |
| 2699 | // On other devices we have increased memory excessively to avoid |
| 2700 | // raster-on-demand already, so now we reserve 50% _only_ to avoid |
| 2701 | // raster-on-demand, and use 50% of the memory otherwise. |
| 2702 | settings.max_memory_for_prepaint_percentage = 50; |
| 2703 | } |
| 2704 | |
| 2705 | // TODO(danakj): Only do this on low end devices. |
| 2706 | settings.create_low_res_tiling = true; |
| 2707 | |
| 2708 | #else // defined(OS_ANDROID) |
| 2709 | bool using_synchronous_compositor = false; // Only for Android WebView. |
| 2710 | // On desktop, we never use the low memory policy unless we are simulating |
| 2711 | // low-end mode via a switch. |
| 2712 | bool using_low_memory_policy = |
| 2713 | cmd.HasSwitch(switches::kEnableLowEndDeviceMode); |
| 2714 | |
| 2715 | if (ui::IsOverlayScrollbarEnabled()) { |
| 2716 | settings.scrollbar_animator = cc::LayerTreeSettings::AURA_OVERLAY; |
| 2717 | settings.scrollbar_fade_delay = ui::kOverlayScrollbarFadeDelay; |
| 2718 | settings.scrollbar_fade_duration = ui::kOverlayScrollbarFadeDuration; |
| 2719 | settings.scrollbar_thinning_duration = |
| 2720 | ui::kOverlayScrollbarThinningDuration; |
| 2721 | settings.scrollbar_flash_after_any_scroll_update = |
| 2722 | ui::OverlayScrollbarFlashAfterAnyScrollUpdate(); |
| 2723 | settings.scrollbar_flash_when_mouse_enter = |
| 2724 | ui::OverlayScrollbarFlashWhenMouseEnter(); |
| 2725 | } |
| 2726 | |
| 2727 | // On desktop, if there's over 4GB of memory on the machine, increase the |
| 2728 | // working set size to 256MB for both gpu and software. |
| 2729 | const int kImageDecodeMemoryThresholdMB = 4 * 1024; |
| 2730 | if (base::SysInfo::AmountOfPhysicalMemoryMB() >= |
| 2731 | kImageDecodeMemoryThresholdMB) { |
| 2732 | settings.decoded_image_working_set_budget_bytes = 256 * 1024 * 1024; |
| 2733 | } else { |
| 2734 | // This is the default, but recorded here as well. |
| 2735 | settings.decoded_image_working_set_budget_bytes = 128 * 1024 * 1024; |
| 2736 | } |
| 2737 | #endif // defined(OS_ANDROID) |
| 2738 | |
| 2739 | if (using_low_memory_policy) { |
| 2740 | // RGBA_4444 textures are only enabled: |
| 2741 | // - If the user hasn't explicitly disabled them |
| 2742 | // - If system ram is <= 512MB (1GB devices are sometimes low-end). |
| 2743 | // - If we are not running in a WebView, where 4444 isn't supported. |
| 2744 | if (!cmd.HasSwitch(switches::kDisableRGBA4444Textures) && |
| 2745 | base::SysInfo::AmountOfPhysicalMemoryMB() <= 512 && |
| 2746 | !using_synchronous_compositor) { |
| 2747 | settings.use_rgba_4444 = viz::RGBA_4444; |
| 2748 | |
| 2749 | // If we are going to unpremultiply and dither these tiles, we need to |
| 2750 | // allocate an additional RGBA_8888 intermediate for each tile |
| 2751 | // rasterization when rastering to RGBA_4444 to allow for dithering. |
| 2752 | // Setting a reasonable sized max tile size allows this intermediate to |
| 2753 | // be consistently reused. |
| 2754 | if (base::FeatureList::IsEnabled( |
| 2755 | kUnpremultiplyAndDitherLowBitDepthTiles)) { |
| 2756 | settings.max_gpu_raster_tile_size = gfx::Size(512, 256); |
| 2757 | settings.unpremultiply_and_dither_low_bit_depth_tiles = true; |
| 2758 | } |
| 2759 | } |
| 2760 | } |
| 2761 | |
| 2762 | if (cmd.HasSwitch(switches::kEnableLowResTiling)) |
| 2763 | settings.create_low_res_tiling = true; |
| 2764 | if (cmd.HasSwitch(switches::kDisableLowResTiling)) |
| 2765 | settings.create_low_res_tiling = false; |
| 2766 | |
| 2767 | if (cmd.HasSwitch(switches::kEnableRGBA4444Textures) && |
| 2768 | !cmd.HasSwitch(switches::kDisableRGBA4444Textures)) { |
| 2769 | settings.use_rgba_4444 = true; |
| 2770 | } |
| 2771 | |
| 2772 | settings.max_staging_buffer_usage_in_bytes = 32 * 1024 * 1024; // 32MB |
| 2773 | // Use 1/4th of staging buffers on low-end devices. |
| 2774 | if (base::SysInfo::IsLowEndDevice()) |
| 2775 | settings.max_staging_buffer_usage_in_bytes /= 4; |
| 2776 | |
| 2777 | cc::ManagedMemoryPolicy defaults = settings.memory_policy; |
| 2778 | settings.memory_policy = GetGpuMemoryPolicy(defaults, initial_screen_size, |
| 2779 | initial_device_scale_factor); |
| 2780 | |
| 2781 | settings.disallow_non_exact_resource_reuse = |
| 2782 | cmd.HasSwitch(switches::kDisallowNonExactResourceReuse); |
| 2783 | #if defined(OS_ANDROID) |
| 2784 | // TODO(crbug.com/746931): This feature appears to be causing visual |
| 2785 | // corruption on certain android devices. Will investigate and re-enable. |
| 2786 | settings.disallow_non_exact_resource_reuse = true; |
| 2787 | #endif |
| 2788 | |
| 2789 | if (cmd.HasSwitch(switches::kRunAllCompositorStagesBeforeDraw)) { |
| 2790 | settings.wait_for_all_pipeline_stages_before_draw = true; |
| 2791 | settings.enable_latency_recovery = false; |
| 2792 | } |
| 2793 | |
| 2794 | settings.enable_image_animation_resync = |
| 2795 | !cmd.HasSwitch(switches::kDisableImageAnimationResync); |
| 2796 | |
| 2797 | settings.always_request_presentation_time = |
| 2798 | cmd.HasSwitch(cc::switches::kAlwaysRequestPresentationTime); |
Karolina Soltys | 4d60b40 | 2018-10-01 19:28:20 | [diff] [blame] | 2799 | |
| 2800 | settings.send_compositor_frame_ack = false; |
| 2801 | |
danakj | 4b34721 | 2018-07-04 17:55:17 | [diff] [blame] | 2802 | return settings; |
| 2803 | } |
| 2804 | |
| 2805 | // static |
| 2806 | cc::ManagedMemoryPolicy RenderWidget::GetGpuMemoryPolicy( |
| 2807 | const cc::ManagedMemoryPolicy& default_policy, |
| 2808 | const gfx::Size& initial_screen_size, |
| 2809 | float initial_device_scale_factor) { |
| 2810 | cc::ManagedMemoryPolicy actual = default_policy; |
| 2811 | actual.bytes_limit_when_visible = 0; |
| 2812 | |
| 2813 | // If the value was overridden on the command line, use the specified value. |
| 2814 | static bool client_hard_limit_bytes_overridden = |
| 2815 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2816 | switches::kForceGpuMemAvailableMb); |
| 2817 | if (client_hard_limit_bytes_overridden) { |
| 2818 | if (base::StringToSizeT( |
| 2819 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 2820 | switches::kForceGpuMemAvailableMb), |
| 2821 | &actual.bytes_limit_when_visible)) |
| 2822 | actual.bytes_limit_when_visible *= 1024 * 1024; |
| 2823 | return actual; |
| 2824 | } |
| 2825 | |
| 2826 | #if defined(OS_ANDROID) |
| 2827 | // We can't query available GPU memory from the system on Android. |
| 2828 | // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports |
| 2829 | // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports |
| 2830 | // 128MB java heap size). First we estimate physical memory using both. |
| 2831 | size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB(); |
| 2832 | size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB(); |
| 2833 | size_t physical_memory_mb = 0; |
| 2834 | if (base::SysInfo::IsLowEndDevice()) { |
| 2835 | // TODO(crbug.com/742534): The code below appears to no longer work. |
| 2836 | // |dalvik_mb| no longer follows the expected heuristic pattern, causing us |
| 2837 | // to over-estimate memory on low-end devices. This entire section probably |
| 2838 | // needs to be re-written, but for now we can address the low-end Android |
| 2839 | // issues by ignoring |dalvik_mb|. |
| 2840 | physical_memory_mb = physical_mb; |
| 2841 | } else if (dalvik_mb >= 256) { |
| 2842 | physical_memory_mb = dalvik_mb * 4; |
| 2843 | } else { |
| 2844 | physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3); |
| 2845 | } |
| 2846 | |
| 2847 | // Now we take a default of 1/8th of memory on high-memory devices, |
| 2848 | // and gradually scale that back for low-memory devices (to be nicer |
| 2849 | // to other apps so they don't get killed). Examples: |
| 2850 | // Nexus 4/10(2GB) 256MB (normally 128MB) |
| 2851 | // Droid Razr M(1GB) 114MB (normally 57MB) |
| 2852 | // Galaxy Nexus(1GB) 100MB (normally 50MB) |
| 2853 | // Xoom(1GB) 100MB (normally 50MB) |
| 2854 | // Nexus S(low-end) 8MB (normally 8MB) |
| 2855 | // Note that the compositor now uses only some of this memory for |
| 2856 | // pre-painting and uses the rest only for 'emergencies'. |
| 2857 | if (actual.bytes_limit_when_visible == 0) { |
| 2858 | // NOTE: Non-low-end devices use only 50% of these limits, |
| 2859 | // except during 'emergencies' where 100% can be used. |
| 2860 | if (physical_memory_mb >= 1536) |
| 2861 | actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB |
| 2862 | else if (physical_memory_mb >= 1152) |
| 2863 | actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB |
| 2864 | else if (physical_memory_mb >= 768) |
| 2865 | actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB |
| 2866 | else if (physical_memory_mb >= 513) |
| 2867 | actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB |
| 2868 | else |
| 2869 | // Devices with this little RAM have very little headroom so we hardcode |
| 2870 | // the limit rather than relying on the heuristics above. (They also use |
| 2871 | // 4444 textures so we can use a lower limit.) |
| 2872 | actual.bytes_limit_when_visible = 8; |
| 2873 | |
| 2874 | actual.bytes_limit_when_visible = |
| 2875 | actual.bytes_limit_when_visible * 1024 * 1024; |
| 2876 | // Clamp the observed value to a specific range on Android. |
| 2877 | actual.bytes_limit_when_visible = std::max( |
| 2878 | actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024)); |
| 2879 | actual.bytes_limit_when_visible = |
| 2880 | std::min(actual.bytes_limit_when_visible, |
| 2881 | static_cast<size_t>(256 * 1024 * 1024)); |
| 2882 | } |
| 2883 | actual.priority_cutoff_when_visible = |
| 2884 | gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING; |
| 2885 | #else |
| 2886 | // Ignore what the system said and give all clients the same maximum |
| 2887 | // allocation on desktop platforms. |
| 2888 | actual.bytes_limit_when_visible = 512 * 1024 * 1024; |
| 2889 | actual.priority_cutoff_when_visible = |
| 2890 | gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 2891 | |
| 2892 | // For large monitors (4k), double the tile memory to avoid frequent out of |
| 2893 | // memory problems. 4k could mean a screen width of anywhere from 3840 to 4096 |
| 2894 | // (see https://en.wikipedia.org/wiki/4K_resolution). We use 3500 as a proxy |
| 2895 | // for "large enough". |
| 2896 | static const int kLargeDisplayThreshold = 3500; |
| 2897 | int display_width = |
| 2898 | std::round(initial_screen_size.width() * initial_device_scale_factor); |
| 2899 | if (display_width >= kLargeDisplayThreshold) |
| 2900 | actual.bytes_limit_when_visible *= 2; |
| 2901 | #endif |
| 2902 | return actual; |
| 2903 | } |
| 2904 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 2905 | void RenderWidget::StartCompositor() { |
Dale Curtis | e690192 | 2018-10-24 20:11:12 | [diff] [blame] | 2906 | if (!is_hidden()) |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 2907 | layer_tree_view_->SetVisible(true); |
[email protected] | 24ed043 | 2013-04-24 07:50:31 | [diff] [blame] | 2908 | } |
| 2909 | |
Navid Zolghadr | 8fdb6114e | 2018-08-29 19:00:54 | [diff] [blame] | 2910 | void RenderWidget::HasPointerRawMoveEventHandlers(bool has_handlers) { |
| 2911 | if (input_event_queue_) |
| 2912 | input_event_queue_->HasPointerRawMoveEventHandlers(has_handlers); |
| 2913 | } |
| 2914 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2915 | void RenderWidget::HasTouchEventHandlers(bool has_handlers) { |
W. James MacLean | 662d538 | 2018-03-29 18:33:08 | [diff] [blame] | 2916 | if (has_touch_handlers_ && *has_touch_handlers_ == has_handlers) |
| 2917 | return; |
| 2918 | |
| 2919 | has_touch_handlers_ = has_handlers; |
alexclarke | 7fa9394 | 2015-10-21 15:37:11 | [diff] [blame] | 2920 | if (render_widget_scheduling_state_) |
| 2921 | render_widget_scheduling_state_->SetHasTouchHandler(has_handlers); |
Albert J. Wong | eb28e7e | 2018-10-12 00:57:43 | [diff] [blame] | 2922 | Send(new WidgetHostMsg_HasTouchEventHandlers(routing_id_, has_handlers)); |
[email protected] | ce6689f | 2013-03-29 12:52:55 | [diff] [blame] | 2923 | } |
| 2924 | |
Dave Tapuska | dfe486c1 | 2017-06-09 16:53:13 | [diff] [blame] | 2925 | void RenderWidget::SetNeedsLowLatencyInput(bool needs_low_latency) { |
| 2926 | if (input_event_queue_) |
| 2927 | input_event_queue_->SetNeedsLowLatency(needs_low_latency); |
| 2928 | } |
| 2929 | |
Dave Tapuska | bafc2ba3 | 2017-11-28 01:54:37 | [diff] [blame] | 2930 | void RenderWidget::RequestUnbufferedInputEvents() { |
| 2931 | if (input_event_queue_) |
| 2932 | input_event_queue_->RequestUnbufferedInputEvents(); |
| 2933 | } |
| 2934 | |
xidachen | fa0199e7 | 2017-05-11 11:34:26 | [diff] [blame] | 2935 | void RenderWidget::SetTouchAction(cc::TouchAction touch_action) { |
Dave Tapuska | b28a108 | 2017-08-30 15:37:26 | [diff] [blame] | 2936 | if (!input_handler_->ProcessTouchAction(touch_action)) |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2937 | return; |
| 2938 | |
Dave Tapuska | 04bc5ee9 | 2018-04-17 19:03:31 | [diff] [blame] | 2939 | widget_input_handler_manager_->ProcessTouchAction(touch_action); |
[email protected] | 5d0bbdfa9 | 2013-12-10 00:35:51 | [diff] [blame] | 2940 | } |
| 2941 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 2942 | void RenderWidget::RegisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2943 | render_frame_proxies_.AddObserver(proxy); |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 2944 | // During initial page load, the main frame may have received page |
| 2945 | // scale factor information before the sub-frame proxies were registered, so |
| 2946 | // make sure we pass the page scale factor along here. |
| 2947 | proxy->OnPageScaleFactorChanged(page_scale_factor_from_mainframe_); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 2948 | } |
| 2949 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 2950 | void RenderWidget::UnregisterRenderFrameProxy(RenderFrameProxy* proxy) { |
| 2951 | render_frame_proxies_.RemoveObserver(proxy); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 2952 | } |
| 2953 | |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 2954 | void RenderWidget::RegisterRenderFrame(RenderFrameImpl* frame) { |
| 2955 | render_frames_.AddObserver(frame); |
| 2956 | } |
| 2957 | |
| 2958 | void RenderWidget::UnregisterRenderFrame(RenderFrameImpl* frame) { |
| 2959 | render_frames_.RemoveObserver(frame); |
| 2960 | } |
| 2961 | |
Saman Sami | d189e5dfd | 2017-12-20 22:55:31 | [diff] [blame] | 2962 | void RenderWidget::RegisterBrowserPlugin(BrowserPlugin* browser_plugin) { |
| 2963 | browser_plugins_.AddObserver(browser_plugin); |
Saman Sami | 50d1e0c | 2018-03-13 20:03:49 | [diff] [blame] | 2964 | browser_plugin->ScreenInfoChanged(GetOriginalScreenInfo()); |
Saman Sami | d189e5dfd | 2017-12-20 22:55:31 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | void RenderWidget::UnregisterBrowserPlugin(BrowserPlugin* browser_plugin) { |
| 2968 | browser_plugins_.RemoveObserver(browser_plugin); |
| 2969 | } |
| 2970 | |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 2971 | void RenderWidget::OnWaitNextFrameForTests( |
| 2972 | int main_frame_thread_observer_routing_id) { |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 2973 | // Sends an ACK to the browser process during the next compositor frame. |
Albert J. Wong | 3c93c18 | 2018-09-27 17:29:43 | [diff] [blame] | 2974 | QueueMessage(new WidgetHostMsg_WaitForNextFrameForTests_ACK( |
| 2975 | main_frame_thread_observer_routing_id)); |
lfg | 43e08e6 | 2016-02-03 18:51:37 | [diff] [blame] | 2976 | } |
| 2977 | |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2978 | const ScreenInfo& RenderWidget::GetWebScreenInfo() const { |
| 2979 | return screen_info_; |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2980 | } |
| 2981 | |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2982 | const ScreenInfo& RenderWidget::GetOriginalScreenInfo() const { |
Christopher Cameron | e9a30c1 | 2018-03-07 08:23:38 | [diff] [blame] | 2983 | return screen_metrics_emulator_ |
| 2984 | ? screen_metrics_emulator_->original_screen_info() |
Fady Samuel | a863f15 | 2018-03-09 16:10:03 | [diff] [blame] | 2985 | : screen_info_; |
oshima | 50872a7 | 2016-03-04 13:26:18 | [diff] [blame] | 2986 | } |
| 2987 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2988 | gfx::PointF RenderWidget::ConvertWindowPointToViewport( |
| 2989 | const gfx::PointF& point) { |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2990 | blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2991 | ConvertWindowToViewport(&point_in_viewport); |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2992 | return gfx::PointF(point_in_viewport.x, point_in_viewport.y); |
| 2993 | } |
| 2994 | |
| 2995 | gfx::Point RenderWidget::ConvertWindowPointToViewport(const gfx::Point& point) { |
| 2996 | return gfx::ToRoundedPoint(ConvertWindowPointToViewport(gfx::PointF(point))); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2997 | } |
| 2998 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2999 | bool RenderWidget::RequestPointerLock() { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3000 | return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 3001 | } |
| 3002 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 3003 | void RenderWidget::RequestPointerUnlock() { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3004 | mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 3005 | } |
| 3006 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 3007 | bool RenderWidget::IsPointerLocked() { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3008 | return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 3009 | webwidget_mouse_lock_target_.get()); |
| 3010 | } |
| 3011 | |
Richard Li | 49fe04d | 2018-10-21 09:07:19 | [diff] [blame] | 3012 | void RenderWidget::StartDragging(network::mojom::ReferrerPolicy policy, |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 3013 | const WebDragData& data, |
| 3014 | WebDragOperationsMask mask, |
danakj | 0c75ad8 | 2018-07-10 19:50:12 | [diff] [blame] | 3015 | const SkBitmap& drag_image, |
| 3016 | const WebPoint& web_image_offset) { |
| 3017 | blink::WebRect offset_in_window(web_image_offset.x, web_image_offset.y, 0, 0); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 3018 | ConvertViewportToWindow(&offset_in_window); |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 3019 | DropData drop_data(DropDataBuilder::Build(data)); |
| 3020 | drop_data.referrer_policy = policy; |
danakj | 0c75ad8 | 2018-07-10 19:50:12 | [diff] [blame] | 3021 | gfx::Vector2d image_offset(offset_in_window.x, offset_in_window.y); |
| 3022 | Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, drag_image, |
| 3023 | image_offset, possible_drag_event_info_)); |
paulmeyer | 6ef5a79 | 2016-11-08 20:33:58 | [diff] [blame] | 3024 | } |
| 3025 | |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 3026 | uint32_t RenderWidget::GetContentSourceId() { |
| 3027 | return current_content_source_id_; |
| 3028 | } |
| 3029 | |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 3030 | void RenderWidget::DidNavigate() { |
Saman Sami | 26a1fcd | 2018-04-10 17:12:21 | [diff] [blame] | 3031 | ++current_content_source_id_; |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 3032 | if (!layer_tree_view_) |
Saman Sami | f773134 | 2018-01-24 22:18:44 | [diff] [blame] | 3033 | return; |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 3034 | layer_tree_view_->SetContentSourceId(current_content_source_id_); |
| 3035 | layer_tree_view_->ClearCachesOnNextCommit(); |
kenrb | 5d78b84 | 2017-03-06 21:06:01 | [diff] [blame] | 3036 | } |
| 3037 | |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 3038 | blink::WebWidget* RenderWidget::GetWebWidget() const { |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 3039 | if (owner_delegate_) { |
| 3040 | blink::WebWidget* delegate_widget = |
| 3041 | owner_delegate_->GetWebWidgetForWidget(); |
| 3042 | if (delegate_widget) |
| 3043 | return delegate_widget; |
| 3044 | } |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 3045 | return webwidget_internal_; |
| 3046 | } |
| 3047 | |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 3048 | blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
| 3049 | const { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 3050 | if (auto* frame_widget = GetFrameWidget()) |
| 3051 | return frame_widget->GetActiveWebInputMethodController(); |
| 3052 | |
| 3053 | return nullptr; |
ekaramad | 2daaf67 | 2016-11-10 20:29:01 | [diff] [blame] | 3054 | } |
| 3055 | |
Dave Tapuska | 139a72f | 2017-09-06 21:57:03 | [diff] [blame] | 3056 | void RenderWidget::SetupWidgetInputHandler( |
| 3057 | mojom::WidgetInputHandlerRequest request, |
| 3058 | mojom::WidgetInputHandlerHostPtr host) { |
Dave Tapuska | b66c28f | 2017-11-15 17:18:47 | [diff] [blame] | 3059 | widget_input_handler_manager_->AddInterface(std::move(request), |
| 3060 | std::move(host)); |
Dave Tapuska | 525eb15e | 2017-08-17 21:05:50 | [diff] [blame] | 3061 | } |
| 3062 | |
Dave Tapuska | 485aca9 | 2017-08-08 00:47:58 | [diff] [blame] | 3063 | void RenderWidget::SetWidgetBinding(mojom::WidgetRequest request) { |
| 3064 | // Close the old binding if there was one. |
| 3065 | // A RenderWidgetHost should not need more than one channel. |
| 3066 | widget_binding_.Close(); |
| 3067 | widget_binding_.Bind(std::move(request)); |
| 3068 | } |
| 3069 | |
Ken Buchanan | 94c0beb6 | 2018-06-22 19:56:24 | [diff] [blame] | 3070 | void RenderWidget::SetMouseCapture(bool capture) { |
| 3071 | if (mojom::WidgetInputHandlerHost* host = |
| 3072 | widget_input_handler_manager_->GetWidgetInputHandlerHost()) { |
| 3073 | host->SetMouseCapture(capture); |
| 3074 | } |
| 3075 | } |
| 3076 | |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 3077 | void RenderWidget::SetWindowScreenRect(const gfx::Rect& window_screen_rect) { |
| 3078 | if (screen_metrics_emulator_) |
| 3079 | screen_metrics_emulator_->OnUpdateWindowScreenRect(window_screen_rect); |
| 3080 | else |
| 3081 | window_screen_rect_ = window_screen_rect; |
| 3082 | } |
| 3083 | |
Fady Samuel | ca9ecb7 | 2018-05-05 05:59:27 | [diff] [blame] | 3084 | bool RenderWidget::IsSurfaceSynchronizationEnabled() const { |
danakj | a6c1001 | 2018-07-06 14:25:36 | [diff] [blame] | 3085 | return layer_tree_view_ && |
| 3086 | layer_tree_view_->IsSurfaceSynchronizationEnabled(); |
Fady Samuel | ca9ecb7 | 2018-05-05 05:59:27 | [diff] [blame] | 3087 | } |
| 3088 | |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 3089 | void RenderWidget::PageScaleFactorChanged(float page_scale_factor) { |
| 3090 | // Only the main frame pulls page scale information from the layer tree host. |
| 3091 | // Pages scale is shared with non-mainframe widgets via the IPC for |
| 3092 | // OnSynchronizeVisualProperties. |
| 3093 | if (!owner_delegate_) |
| 3094 | return; |
| 3095 | |
| 3096 | page_scale_factor_from_mainframe_ = page_scale_factor; |
| 3097 | for (auto& observer : render_frame_proxies_) |
| 3098 | observer.OnPageScaleFactorChanged(page_scale_factor); |
| 3099 | } |
| 3100 | |
danakj | 5380269 | 2018-07-25 21:46:44 | [diff] [blame] | 3101 | void RenderWidget::UseSynchronousResizeModeForTesting(bool enable) { |
| 3102 | resizing_mode_selector_->set_is_synchronous_mode(enable); |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | void RenderWidget::SetDeviceScaleFactorForTesting(float factor) { |
| 3106 | device_scale_factor_for_testing_ = factor; |
| 3107 | |
| 3108 | VisualProperties visual_properties; |
| 3109 | visual_properties.screen_info = screen_info_; |
| 3110 | visual_properties.screen_info.device_scale_factor = factor; |
| 3111 | visual_properties.new_size = size(); |
| 3112 | visual_properties.visible_viewport_size = visible_viewport_size_; |
| 3113 | visual_properties.compositor_viewport_pixel_size = |
| 3114 | gfx::ScaleToCeiledSize(size(), factor); |
| 3115 | visual_properties.browser_controls_shrink_blink_size = false; |
| 3116 | visual_properties.top_controls_height = 0.f; |
| 3117 | visual_properties.is_fullscreen_granted = is_fullscreen_granted_; |
| 3118 | visual_properties.display_mode = display_mode_; |
| 3119 | visual_properties.local_surface_id = local_surface_id_from_parent_; |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 3120 | visual_properties.page_scale_factor = page_scale_factor_from_mainframe_; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 3121 | // We are changing the device scale factor from the renderer, so allocate a |
| 3122 | // new viz::LocalSurfaceId to avoid surface invariants violations in tests. |
| 3123 | if (layer_tree_view_) |
| 3124 | layer_tree_view_->RequestNewLocalSurfaceId(); |
| 3125 | |
| 3126 | OnSynchronizeVisualProperties(visual_properties); |
| 3127 | } |
| 3128 | |
| 3129 | void RenderWidget::SetDeviceColorSpaceForTesting( |
| 3130 | const gfx::ColorSpace& color_space) { |
| 3131 | VisualProperties visual_properties; |
| 3132 | visual_properties.screen_info = screen_info_; |
| 3133 | visual_properties.screen_info.color_space = color_space; |
| 3134 | visual_properties.new_size = size(); |
| 3135 | visual_properties.visible_viewport_size = visible_viewport_size_; |
| 3136 | visual_properties.compositor_viewport_pixel_size = |
| 3137 | compositor_viewport_pixel_size_; |
| 3138 | visual_properties.browser_controls_shrink_blink_size = false; |
| 3139 | visual_properties.top_controls_height = 0.f; |
| 3140 | visual_properties.is_fullscreen_granted = is_fullscreen_granted_; |
| 3141 | visual_properties.display_mode = display_mode_; |
| 3142 | visual_properties.local_surface_id = local_surface_id_from_parent_; |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 3143 | visual_properties.page_scale_factor = page_scale_factor_from_mainframe_; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 3144 | // We are changing the device color space from the renderer, so allocate a |
| 3145 | // new viz::LocalSurfaceId to avoid surface invariants violations in tests. |
| 3146 | if (layer_tree_view_) |
| 3147 | layer_tree_view_->RequestNewLocalSurfaceId(); |
| 3148 | OnSynchronizeVisualProperties(visual_properties); |
| 3149 | } |
| 3150 | |
| 3151 | void RenderWidget::SetWindowRectSynchronouslyForTesting( |
| 3152 | const gfx::Rect& new_window_rect) { |
| 3153 | SetWindowRectSynchronously(new_window_rect); |
| 3154 | } |
| 3155 | |
| 3156 | void RenderWidget::EnableAutoResizeForTesting(const gfx::Size& min_size, |
| 3157 | const gfx::Size& max_size) { |
| 3158 | VisualProperties visual_properties; |
| 3159 | visual_properties.auto_resize_enabled = true; |
| 3160 | visual_properties.min_size_for_auto_resize = min_size; |
| 3161 | visual_properties.max_size_for_auto_resize = max_size; |
| 3162 | visual_properties.local_surface_id = base::Optional<viz::LocalSurfaceId>( |
| 3163 | viz::LocalSurfaceId(1, 1, base::UnguessableToken::Create())); |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 3164 | visual_properties.page_scale_factor = page_scale_factor_from_mainframe_; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 3165 | OnSynchronizeVisualProperties(visual_properties); |
| 3166 | } |
| 3167 | |
| 3168 | void RenderWidget::DisableAutoResizeForTesting(const gfx::Size& new_size) { |
| 3169 | if (!auto_resize_mode_) |
| 3170 | return; |
| 3171 | |
| 3172 | VisualProperties visual_properties; |
| 3173 | visual_properties.auto_resize_enabled = false; |
| 3174 | visual_properties.screen_info = screen_info_; |
| 3175 | visual_properties.new_size = new_size; |
| 3176 | visual_properties.compositor_viewport_pixel_size = |
| 3177 | compositor_viewport_pixel_size_; |
| 3178 | visual_properties.browser_controls_shrink_blink_size = |
| 3179 | browser_controls_shrink_blink_size_; |
| 3180 | visual_properties.top_controls_height = top_controls_height_; |
| 3181 | visual_properties.visible_viewport_size = visible_viewport_size_; |
| 3182 | visual_properties.is_fullscreen_granted = is_fullscreen_granted_; |
| 3183 | visual_properties.display_mode = display_mode_; |
W. James MacLean | 2a90bff | 2018-11-05 20:52:47 | [diff] [blame^] | 3184 | visual_properties.page_scale_factor = page_scale_factor_from_mainframe_; |
danakj | a2c9d0a9 | 2018-07-25 20:01:18 | [diff] [blame] | 3185 | OnSynchronizeVisualProperties(visual_properties); |
| 3186 | } |
| 3187 | |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 3188 | blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 3189 | if (auto* frame_widget = GetFrameWidget()) |
| 3190 | return frame_widget->FocusedWebLocalFrameInWidget(); |
| 3191 | return nullptr; |
EhsanK | 955ba58 | 2017-11-30 21:14:40 | [diff] [blame] | 3192 | } |
| 3193 | |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 3194 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 3195 | PepperPluginInstanceImpl* RenderWidget::GetFocusedPepperPluginInsideWidget() { |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 3196 | blink::WebFrameWidget* frame_widget = GetFrameWidget(); |
| 3197 | if (!frame_widget) |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 3198 | return nullptr; |
| 3199 | |
| 3200 | // Focused pepper instance might not always be in the focused frame. For |
| 3201 | // instance if a pepper instance and its embedder frame are focused an then |
| 3202 | // another frame takes focus using javascript, the embedder frame will no |
| 3203 | // longer be focused while the pepper instance is (the embedder frame's |
| 3204 | // |focused_pepper_plugin_| is not nullptr). Especially, if the pepper plugin |
| 3205 | // is fullscreen, clicking into the pepper will not refocus the embedder |
| 3206 | // frame. This is why we have to traverse the whole frame tree to find the |
| 3207 | // focused plugin. |
Ehsan Karamad | 655d7b8a | 2018-01-12 18:38:38 | [diff] [blame] | 3208 | blink::WebFrame* current_frame = frame_widget->LocalRoot(); |
EhsanK | 22d482e | 2017-08-10 17:29:49 | [diff] [blame] | 3209 | while (current_frame) { |
| 3210 | RenderFrameImpl* render_frame = |
| 3211 | current_frame->IsWebLocalFrame() |
| 3212 | ? RenderFrameImpl::FromWebFrame(current_frame) |
| 3213 | : nullptr; |
| 3214 | if (render_frame && render_frame->focused_pepper_plugin()) |
| 3215 | return render_frame->focused_pepper_plugin(); |
| 3216 | current_frame = current_frame->TraverseNext(); |
| 3217 | } |
| 3218 | return nullptr; |
| 3219 | } |
| 3220 | #endif |
| 3221 | |
Ken Buchanan | b2c9e26 | 2018-03-10 16:53:31 | [diff] [blame] | 3222 | gfx::Rect RenderWidget::ViewportVisibleRect() { |
| 3223 | return for_oopif_ ? compositor_visible_rect_ |
| 3224 | : gfx::Rect(compositor_viewport_pixel_size_); |
| 3225 | } |
| 3226 | |
Hajime Hoshi | 315a61f | 2018-08-14 17:27:28 | [diff] [blame] | 3227 | // static |
| 3228 | scoped_refptr<base::SingleThreadTaskRunner> |
| 3229 | RenderWidget::GetCleanupTaskRunner() { |
| 3230 | return RenderThreadImpl::current_blink_platform_impl() |
| 3231 | ->main_thread_scheduler() |
| 3232 | ->CleanupTaskRunner(); |
| 3233 | } |
| 3234 | |
Saman Sami | 50d1e0c | 2018-03-13 20:03:49 | [diff] [blame] | 3235 | base::WeakPtr<RenderWidget> RenderWidget::AsWeakPtr() { |
| 3236 | return weak_ptr_factory_.GetWeakPtr(); |
| 3237 | } |
| 3238 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 3239 | } // namespace content |