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