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