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