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