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