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