[email protected] | 5922cb2 | 2012-01-17 21:53:12 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e8cf733 | 2014-02-14 18:54:58 | [diff] [blame] | 5 | #ifndef UI_AURA_WINDOW_TREE_HOST_H_ |
| 6 | #define UI_AURA_WINDOW_TREE_HOST_H_ |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 7 | |
Scott Violet | 2784cad | 2017-12-05 20:39:26 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
sky | 631094cd | 2016-10-26 18:21:01 | [diff] [blame] | 10 | #include <memory> |
Gary Kacmarcik | 9c79e1fe | 2018-05-15 15:57:20 | [diff] [blame] | 11 | #include <string> |
[email protected] | 1266ba49 | 2012-05-16 23:29:48 | [diff] [blame] | 12 | |
Gary Kacmarcik | 9c79e1fe | 2018-05-15 15:57:20 | [diff] [blame] | 13 | #include "base/containers/flat_map.h" |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 14 | #include "base/containers/flat_set.h" |
avi | 4ca29411 | 2015-12-24 08:04:09 | [diff] [blame] | 15 | #include "base/macros.h" |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
Gabriel Charette | a92b763 | 2018-05-01 19:20:32 | [diff] [blame] | 17 | #include "base/observer_list.h" |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 18 | #include "base/optional.h" |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 19 | #include "base/time/time.h" |
Fady Samuel | 644df1d | 2017-07-13 01:13:02 | [diff] [blame] | 20 | #include "components/viz/common/surfaces/frame_sink_id.h" |
Sadrul Habib Chowdhury | 3c7fdca | 2018-04-18 05:08:40 | [diff] [blame] | 21 | #include "components/viz/common/surfaces/local_surface_id.h" |
[email protected] | 252f86be | 2012-09-27 20:35:03 | [diff] [blame] | 22 | #include "ui/aura/aura_export.h" |
Scott Violet | 3652916 | 2018-08-09 05:09:32 | [diff] [blame] | 23 | #include "ui/aura/window.h" |
[email protected] | c783955 | 2012-04-03 21:14:36 | [diff] [blame] | 24 | #include "ui/base/cursor/cursor.h" |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 25 | #include "ui/base/ime/input_method_delegate.h" |
Fady Samuel | d7625cc0 | 2017-10-13 05:25:18 | [diff] [blame] | 26 | #include "ui/compositor/compositor_observer.h" |
Christopher Cameron | 1f3a4e3e | 2017-07-18 06:16:01 | [diff] [blame] | 27 | #include "ui/display/display_observer.h" |
[email protected] | 8ecd5fa | 2014-04-24 23:04:03 | [diff] [blame] | 28 | #include "ui/events/event_source.h" |
Scott Violet | c730d60a | 2018-03-22 17:45:06 | [diff] [blame] | 29 | #include "ui/events/platform_event.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 30 | #include "ui/gfx/native_widget_types.h" |
| 31 | |
| 32 | namespace gfx { |
[email protected] | 896728e | 2011-10-14 00:41:26 | [diff] [blame] | 33 | class Point; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 34 | class Rect; |
| 35 | class Size; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 36 | class Transform; |
| 37 | } |
| 38 | |
| 39 | namespace ui { |
| 40 | class Compositor; |
Joe Downing | f18d97c | 2018-05-03 04:41:44 | [diff] [blame] | 41 | enum class DomCode; |
penghuang | 17134c6c | 2017-03-23 00:01:07 | [diff] [blame] | 42 | class EventSink; |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 43 | class InputMethod; |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 44 | class ViewProp; |
Sergey Ulanov | 528cf76e | 2018-06-20 22:49:08 | [diff] [blame] | 45 | struct PlatformWindowInitProperties; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | namespace aura { |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 49 | |
[email protected] | dc645d5 | 2014-04-28 14:42:55 | [diff] [blame] | 50 | namespace test { |
| 51 | class WindowTreeHostTestApi; |
| 52 | } |
| 53 | |
Xiyuan Xia | 82ceeef | 2018-09-14 20:50:50 | [diff] [blame] | 54 | class Env; |
| 55 | class ScopedKeyboardHook; |
[email protected] | 056ce05 | 2014-02-21 05:19:32 | [diff] [blame] | 56 | class WindowEventDispatcher; |
[email protected] | 2d6eb74 | 2014-03-05 18:59:03 | [diff] [blame] | 57 | class WindowTreeHostObserver; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 58 | |
[email protected] | 641dcfd | 2014-01-08 16:41:23 | [diff] [blame] | 59 | // WindowTreeHost bridges between a native window and the embedded RootWindow. |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 60 | // It provides the accelerated widget and maps events from the native os to |
| 61 | // aura. |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 62 | class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate, |
Christopher Cameron | 1f3a4e3e | 2017-07-18 06:16:01 | [diff] [blame] | 63 | public ui::EventSource, |
Fady Samuel | d7625cc0 | 2017-10-13 05:25:18 | [diff] [blame] | 64 | public display::DisplayObserver, |
| 65 | public ui::CompositorObserver { |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 66 | public: |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 67 | ~WindowTreeHost() override; |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 68 | |
Xiyuan Xia | 82ceeef | 2018-09-14 20:50:50 | [diff] [blame] | 69 | // Creates a new WindowTreeHost with the specified |properties| and an |
| 70 | // optional |env|. If |env| is null, the default Env::GetInstance() is used. |
Sergey Ulanov | 528cf76e | 2018-06-20 22:49:08 | [diff] [blame] | 71 | static std::unique_ptr<WindowTreeHost> Create( |
Xiyuan Xia | 82ceeef | 2018-09-14 20:50:50 | [diff] [blame] | 72 | ui::PlatformWindowInitProperties properties, |
| 73 | Env* env = nullptr); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 74 | |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 75 | // Returns the WindowTreeHost for the specified accelerated widget, or NULL |
| 76 | // if there is none associated. |
| 77 | static WindowTreeHost* GetForAcceleratedWidget(gfx::AcceleratedWidget widget); |
| 78 | |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 79 | void InitHost(); |
| 80 | |
[email protected] | a0695522 | 2014-03-10 22:47:32 | [diff] [blame] | 81 | void AddObserver(WindowTreeHostObserver* observer); |
| 82 | void RemoveObserver(WindowTreeHostObserver* observer); |
David Bienvenu | d0ddda3 | 2018-11-01 16:59:16 | [diff] [blame^] | 83 | bool HasObserver(const WindowTreeHostObserver* observer) const; |
[email protected] | a0695522 | 2014-03-10 22:47:32 | [diff] [blame] | 84 | |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 85 | Window* window() { return window_; } |
| 86 | const Window* window() const { return window_; } |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 87 | |
penghuang | 17134c6c | 2017-03-23 00:01:07 | [diff] [blame] | 88 | ui::EventSink* event_sink(); |
[email protected] | 2d6eb74 | 2014-03-05 18:59:03 | [diff] [blame] | 89 | |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 90 | WindowEventDispatcher* dispatcher() { |
| 91 | return const_cast<WindowEventDispatcher*>( |
| 92 | const_cast<const WindowTreeHost*>(this)->dispatcher()); |
| 93 | } |
| 94 | const WindowEventDispatcher* dispatcher() const { return dispatcher_.get(); } |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 95 | |
| 96 | ui::Compositor* compositor() { return compositor_.get(); } |
| 97 | |
[email protected] | f5c9dbc | 2014-04-11 08:13:45 | [diff] [blame] | 98 | // Gets/Sets the root window's transform. |
| 99 | virtual gfx::Transform GetRootTransform() const; |
| 100 | virtual void SetRootTransform(const gfx::Transform& transform); |
| 101 | virtual gfx::Transform GetInverseRootTransform() const; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 102 | |
Scott Violet | 215d2d4 | 2017-08-25 21:16:01 | [diff] [blame] | 103 | // These functions are used in event translation for translating the local |
Scott Violet | 64fde6f7 | 2017-09-13 18:07:44 | [diff] [blame] | 104 | // coordinates of LocatedEvents. Default implementation calls to non-local |
Scott Violet | 215d2d4 | 2017-08-25 21:16:01 | [diff] [blame] | 105 | // ones (e.g. GetRootTransform()). |
| 106 | virtual gfx::Transform GetRootTransformForLocalEventCoordinates() const; |
| 107 | virtual gfx::Transform GetInverseRootTransformForLocalEventCoordinates() |
| 108 | const; |
| 109 | |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 110 | // Updates the root window's size using |host_size_in_pixels|, current |
sky | f554cab | 2015-11-26 06:03:53 | [diff] [blame] | 111 | // transform and outsets. |
Sadrul Habib Chowdhury | a824472 | 2018-04-12 06:01:01 | [diff] [blame] | 112 | // TODO(ccameron): Make this function no longer public. The interaction |
| 113 | // between this call, GetBounds, and OnHostResizedInPixels is ambiguous and |
| 114 | // allows for inconsistencies. |
| 115 | void UpdateRootWindowSizeInPixels(); |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 116 | |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 117 | // Converts |point| from the root window's coordinate system to native |
| 118 | // screen's. |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 119 | void ConvertDIPToScreenInPixels(gfx::Point* point) const; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 120 | |
| 121 | // Converts |point| from native screen coordinate system to the root window's. |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 122 | void ConvertScreenInPixelsToDIP(gfx::Point* point) const; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 123 | |
| 124 | // Converts |point| from the root window's coordinate system to the |
| 125 | // host window's. |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame] | 126 | virtual void ConvertDIPToPixels(gfx::Point* point) const; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 127 | |
| 128 | // Converts |point| from the host window's coordinate system to the |
| 129 | // root window's. |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame] | 130 | virtual void ConvertPixelsToDIP(gfx::Point* point) const; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 131 | |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 132 | // Cursor. |
| 133 | // Sets the currently-displayed cursor. If the cursor was previously hidden |
| 134 | // via ShowCursor(false), it will remain hidden until ShowCursor(true) is |
| 135 | // called, at which point the cursor that was last set via SetCursor() will be |
| 136 | // used. |
| 137 | void SetCursor(gfx::NativeCursor cursor); |
| 138 | |
| 139 | // Invoked when the cursor's visibility has changed. |
| 140 | void OnCursorVisibilityChanged(bool visible); |
| 141 | |
| 142 | // Moves the cursor to the specified location relative to the root window. |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 143 | void MoveCursorToLocationInDIP(const gfx::Point& location_in_dip); |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 144 | |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 145 | // Moves the cursor to the |location_in_pixels| given in host coordinates. |
| 146 | void MoveCursorToLocationInPixels(const gfx::Point& location_in_pixels); |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 147 | |
| 148 | gfx::NativeCursor last_cursor() const { return last_cursor_; } |
| 149 | |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 150 | // Gets the InputMethod instance, if NULL, creates & owns it. |
| 151 | ui::InputMethod* GetInputMethod(); |
sky | cfaad89 | 2017-04-28 20:52:58 | [diff] [blame] | 152 | bool has_input_method() const { return input_method_ != nullptr; } |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 153 | |
| 154 | // Sets a shared unowned InputMethod. This is used when there is a singleton |
| 155 | // InputMethod shared between multiple WindowTreeHost instances. |
| 156 | // |
| 157 | // This is used for Ash only. There are 2 reasons: |
Darren Shen | 539c32a | 2018-07-03 05:27:43 | [diff] [blame] | 158 | // 1) ChromeOS virtual keyboard needs to receive ShowVirtualKeyboardIfEnabled |
| 159 | // notification from InputMethod. Multiple InputMethod instances makes it hard |
| 160 | // to register/unregister the observer for that notification. 2) For Ozone, |
| 161 | // there is no native focus state for the root window and WindowTreeHost. See |
| 162 | // DrmWindowHost::CanDispatchEvent, the key events always goes to the primary |
| 163 | // WindowTreeHost. And after InputMethod processed the key event and continue |
| 164 | // dispatching it, WindowTargeter::FindTargetForEvent may re-dispatch it to a |
| 165 | // different WindowTreeHost. So the singleton InputMethod can make sure the |
| 166 | // correct InputMethod instance processes the key event no matter which |
| 167 | // WindowTreeHost is the target for event. Please refer to the test: |
| 168 | // ExtendedDesktopTest.KeyEventsOnLockScreen. |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 169 | // |
| 170 | // TODO(shuchen): remove this method after above reasons become invalid. |
| 171 | // A possible solution is to make sure DrmWindowHost can find the correct |
| 172 | // WindowTreeHost to dispatch events. |
| 173 | void SetSharedInputMethod(ui::InputMethod* input_method); |
| 174 | |
| 175 | // Overridden from ui::internal::InputMethodDelegate: |
Scott Violet | ad6366d | 2018-09-27 21:33:19 | [diff] [blame] | 176 | ui::EventDispatchDetails DispatchKeyEventPostIME( |
| 177 | ui::KeyEvent* event, |
| 178 | base::OnceCallback<void(bool)> ack_callback) final; |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 179 | |
Scott Violet | 2784cad | 2017-12-05 20:39:26 | [diff] [blame] | 180 | // Returns the id of the display. Default implementation queries Screen. |
| 181 | virtual int64_t GetDisplayId(); |
| 182 | |
[email protected] | 8ecd5fa | 2014-04-24 23:04:03 | [diff] [blame] | 183 | // Returns the EventSource responsible for dispatching events to the window |
| 184 | // tree. |
| 185 | virtual ui::EventSource* GetEventSource() = 0; |
| 186 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 187 | // Returns the accelerated widget. |
| 188 | virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; |
| 189 | |
[email protected] | 641dcfd | 2014-01-08 16:41:23 | [diff] [blame] | 190 | // Shows the WindowTreeHost. |
jbauman | 8da589a | 2015-06-04 02:23:12 | [diff] [blame] | 191 | void Show(); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 192 | |
[email protected] | 641dcfd | 2014-01-08 16:41:23 | [diff] [blame] | 193 | // Hides the WindowTreeHost. |
jbauman | 8da589a | 2015-06-04 02:23:12 | [diff] [blame] | 194 | void Hide(); |
[email protected] | e46617f | 2012-08-17 22:43:46 | [diff] [blame] | 195 | |
Sadrul Habib Chowdhury | 3c7fdca | 2018-04-18 05:08:40 | [diff] [blame] | 196 | // Sets/Gets the bounds of the WindowTreeHost (in pixels). Note that a call to |
| 197 | // GetBoundsInPixels() immediately following a SetBoundsInPixels() can return |
| 198 | // the old bounds, because SetBoundsInPixels() can take effect asynchronously, |
| 199 | // depending on the platform. The |local_surface_id| takes effect when (and |
| 200 | // if) the new size is confirmed (potentially asynchronously) by the platform. |
| 201 | // If |local_surface_id| is invalid, then a new LocalSurfaceId is allocated |
| 202 | // when the size change takes effect. |
| 203 | virtual void SetBoundsInPixels( |
| 204 | const gfx::Rect& bounds_in_pixels, |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 205 | const viz::LocalSurfaceId& local_surface_id = viz::LocalSurfaceId(), |
| 206 | base::TimeTicks allocation_time = base::TimeTicks()) = 0; |
riajiang | dfdfc99e | 2016-11-29 05:37:47 | [diff] [blame] | 207 | virtual gfx::Rect GetBoundsInPixels() const = 0; |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 208 | |
[email protected] | 627a62f | 2012-02-14 22:59:14 | [diff] [blame] | 209 | // Sets the OS capture to the root window. |
[email protected] | 759017e0 | 2012-02-11 20:46:11 | [diff] [blame] | 210 | virtual void SetCapture() = 0; |
| 211 | |
[email protected] | 627a62f | 2012-02-14 22:59:14 | [diff] [blame] | 212 | // Releases OS capture of the root window. |
[email protected] | 759017e0 | 2012-02-11 20:46:11 | [diff] [blame] | 213 | virtual void ReleaseCapture() = 0; |
| 214 | |
Christopher Cameron | 7c4a857 | 2018-03-16 08:03:02 | [diff] [blame] | 215 | // Returns the device scale assumed by the WindowTreeHost (set during the |
| 216 | // most recent call to OnHostResizedInPixels). |
| 217 | float device_scale_factor() const { return device_scale_factor_; } |
| 218 | |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 219 | // Requests that |keys| be intercepted at the platform level and routed |
Joe Downing | f18d97c | 2018-05-03 04:41:44 | [diff] [blame] | 220 | // directly to the web content. If |codes| is empty, all keys will be |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 221 | // intercepted. Returns a ScopedKeyboardHook instance which stops capturing |
| 222 | // system key events when destroyed. |
| 223 | std::unique_ptr<ScopedKeyboardHook> CaptureSystemKeyEvents( |
Joe Downing | f18d97c | 2018-05-03 04:41:44 | [diff] [blame] | 224 | base::Optional<base::flat_set<ui::DomCode>> codes); |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 225 | |
Gary Kacmarcik | 9c79e1fe | 2018-05-15 15:57:20 | [diff] [blame] | 226 | // Returns a map of KeyboardEvent code to KeyboardEvent key values. |
| 227 | virtual base::flat_map<std::string, std::string> GetKeyboardLayoutMap() = 0; |
| 228 | |
Scott Violet | 6c77e2f6 | 2018-10-19 16:38:42 | [diff] [blame] | 229 | // Returns true if KeyEvents should be send to IME. This is called from |
| 230 | // WindowEventDispatcher during event dispatch. |
| 231 | virtual bool ShouldSendKeyEventToIme(); |
| 232 | |
David Bienvenu | d0ddda3 | 2018-11-01 16:59:16 | [diff] [blame^] | 233 | // Enables native window occlusion tracking for the native window this host |
| 234 | // represents. |
| 235 | virtual void EnableNativeWindowOcclusionTracking(); |
| 236 | |
| 237 | // Disables native window occlusion tracking for the native window this host |
| 238 | // represents. |
| 239 | virtual void DisableNativeWindowOcclusionTracking(); |
| 240 | |
| 241 | // Remembers the current occlusion state, and if it has changed, notifies |
| 242 | // observers of the change. |
| 243 | virtual void SetNativeWindowOcclusionState(Window::OcclusionState state); |
| 244 | |
[email protected] | 228f0f0 | 2013-11-15 05:58:36 | [diff] [blame] | 245 | protected: |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 246 | friend class ScopedKeyboardHook; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 247 | friend class TestScreen; // TODO(beng): see if we can remove/consolidate. |
| 248 | |
Scott Violet | 3652916 | 2018-08-09 05:09:32 | [diff] [blame] | 249 | explicit WindowTreeHost(std::unique_ptr<Window> window = nullptr); |
sky | 631094cd | 2016-10-26 18:21:01 | [diff] [blame] | 250 | |
[email protected] | c051d5a5 | 2014-01-08 23:54:51 | [diff] [blame] | 251 | void DestroyCompositor(); |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 252 | void DestroyDispatcher(); |
[email protected] | 228f0f0 | 2013-11-15 05:58:36 | [diff] [blame] | 253 | |
samans | 534dc4d | 2017-01-13 18:07:42 | [diff] [blame] | 254 | // If frame_sink_id is not passed in, one will be grabbed from |
Scott Violet | 2cc29e0 | 2018-05-31 22:59:33 | [diff] [blame] | 255 | // ContextFactoryPrivate. |are_events_in_pixels| indicates if events are |
| 256 | // received in pixels. If |are_events_in_pixels| is false, events are |
Scott Violet | 62d717bc | 2018-10-16 17:07:58 | [diff] [blame] | 257 | // received in DIPs. See Compositor() for details on |trace_environment_name|. |
samans | 534dc4d | 2017-01-13 18:07:42 | [diff] [blame] | 258 | void CreateCompositor( |
Tom Anderson | 1721ffa | 2017-08-09 05:55:24 | [diff] [blame] | 259 | const viz::FrameSinkId& frame_sink_id = viz::FrameSinkId(), |
Eric Seckler | 80a868a | 2017-10-10 22:57:44 | [diff] [blame] | 260 | bool force_software_compositor = false, |
Scott Violet | 2cc29e0 | 2018-05-31 22:59:33 | [diff] [blame] | 261 | bool external_begin_frames_enabled = false, |
Scott Violet | 62d717bc | 2018-10-16 17:07:58 | [diff] [blame] | 262 | bool are_events_in_pixels = true, |
| 263 | const char* trace_environment_name = nullptr); |
samans | 534dc4d | 2017-01-13 18:07:42 | [diff] [blame] | 264 | |
mfomitchev | 7028deb3 | 2016-12-12 04:15:29 | [diff] [blame] | 265 | void InitCompositor(); |
sievers | b2a31d337 | 2015-08-25 19:27:13 | [diff] [blame] | 266 | void OnAcceleratedWidgetAvailable(); |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 267 | |
[email protected] | 228f0f0 | 2013-11-15 05:58:36 | [diff] [blame] | 268 | // Returns the location of the RootWindow on native screen. |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 269 | virtual gfx::Point GetLocationOnScreenInPixels() const = 0; |
[email protected] | 228f0f0 | 2013-11-15 05:58:36 | [diff] [blame] | 270 | |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 271 | void OnHostMovedInPixels(const gfx::Point& new_location_in_pixels); |
Sadrul Habib Chowdhury | 3c7fdca | 2018-04-18 05:08:40 | [diff] [blame] | 272 | void OnHostResizedInPixels( |
| 273 | const gfx::Size& new_size_in_pixels, |
jonross | 180dc48 | 2018-10-23 21:22:09 | [diff] [blame] | 274 | const viz::LocalSurfaceId& local_surface_id = viz::LocalSurfaceId(), |
| 275 | base::TimeTicks new_allocation_time = base::TimeTicks()); |
thomasanderson | 06405c5 | 2016-05-03 22:52:22 | [diff] [blame] | 276 | void OnHostWorkspaceChanged(); |
Christopher Cameron | fd90d276 | 2017-09-22 08:11:33 | [diff] [blame] | 277 | void OnHostDisplayChanged(); |
[email protected] | 2d6eb74 | 2014-03-05 18:59:03 | [diff] [blame] | 278 | void OnHostCloseRequested(); |
[email protected] | d04aca19 | 2014-03-07 05:00:17 | [diff] [blame] | 279 | void OnHostLostWindowCapture(); |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 280 | |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 281 | // Sets the currently displayed cursor. |
| 282 | virtual void SetCursorNative(gfx::NativeCursor cursor) = 0; |
| 283 | |
| 284 | // Moves the cursor to the specified location relative to the root window. |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 285 | virtual void MoveCursorToScreenLocationInPixels( |
| 286 | const gfx::Point& location_in_pixels) = 0; |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 287 | |
Scott Violet | 17a6172 | 2017-06-19 17:54:31 | [diff] [blame] | 288 | // Called when the cursor visibility has changed. |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 289 | virtual void OnCursorVisibilityChangedNative(bool show) = 0; |
| 290 | |
jbauman | 8da589a | 2015-06-04 02:23:12 | [diff] [blame] | 291 | // Shows the WindowTreeHost. |
| 292 | virtual void ShowImpl() = 0; |
| 293 | |
| 294 | // Hides the WindowTreeHost. |
| 295 | virtual void HideImpl() = 0; |
| 296 | |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 297 | // Overridden from ui::EventSource: |
penghuang | 17134c6c | 2017-03-23 00:01:07 | [diff] [blame] | 298 | ui::EventSink* GetEventSink() override; |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 299 | |
Christopher Cameron | 1f3a4e3e | 2017-07-18 06:16:01 | [diff] [blame] | 300 | // display::DisplayObserver implementation. |
Christopher Cameron | 1f3a4e3e | 2017-07-18 06:16:01 | [diff] [blame] | 301 | void OnDisplayMetricsChanged(const display::Display& display, |
| 302 | uint32_t metrics) override; |
| 303 | |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 304 | // Begins capturing system key events. Returns true if successful. |
| 305 | virtual bool CaptureSystemKeyEventsImpl( |
Joe Downing | f18d97c | 2018-05-03 04:41:44 | [diff] [blame] | 306 | base::Optional<base::flat_set<ui::DomCode>> dom_codes) = 0; |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 307 | |
| 308 | // Stops capturing system keyboard events. |
| 309 | virtual void ReleaseSystemKeyEventCapture() = 0; |
| 310 | |
Joe Downing | f18d97c | 2018-05-03 04:41:44 | [diff] [blame] | 311 | // True if |dom_code| is reserved for an active KeyboardLock request. |
| 312 | virtual bool IsKeyLocked(ui::DomCode dom_code) = 0; |
Joe Downing | 87cdad6f | 2018-04-09 06:27:14 | [diff] [blame] | 313 | |
Sadrul Habib Chowdhury | 92bbab9 | 2018-04-11 19:23:20 | [diff] [blame] | 314 | virtual gfx::Rect GetTransformedRootWindowBoundsInPixels( |
| 315 | const gfx::Size& size_in_pixels) const; |
| 316 | |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 317 | const base::ObserverList<WindowTreeHostObserver>::Unchecked& observers() |
| 318 | const { |
Michael Wasserman | 625b738 | 2017-12-13 16:34:32 | [diff] [blame] | 319 | return observers_; |
| 320 | } |
| 321 | |
[email protected] | 228f0f0 | 2013-11-15 05:58:36 | [diff] [blame] | 322 | private: |
[email protected] | dc645d5 | 2014-04-28 14:42:55 | [diff] [blame] | 323 | friend class test::WindowTreeHostTestApi; |
| 324 | |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 325 | // Moves the cursor to the specified location. This method is internally used |
riajiang | 8077b13 | 2016-11-29 23:35:36 | [diff] [blame] | 326 | // by MoveCursorToLocationInDIP() and MoveCursorToLocationInPixels(). |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 327 | void MoveCursorToInternal(const gfx::Point& root_location, |
| 328 | const gfx::Point& host_location); |
| 329 | |
Fady Samuel | d7625cc0 | 2017-10-13 05:25:18 | [diff] [blame] | 330 | // Overrided from CompositorObserver: |
| 331 | void OnCompositingDidCommit(ui::Compositor* compositor) override; |
| 332 | void OnCompositingStarted(ui::Compositor* compositor, |
| 333 | base::TimeTicks start_time) override; |
| 334 | void OnCompositingEnded(ui::Compositor* compositor) override; |
Fady Samuel | d7625cc0 | 2017-10-13 05:25:18 | [diff] [blame] | 335 | void OnCompositingChildResizing(ui::Compositor* compositor) override; |
| 336 | void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 337 | |
joone.hur | 21f7c90c | 2016-05-12 16:25:15 | [diff] [blame] | 338 | // We don't use a std::unique_ptr for |window_| since we need this ptr to be |
| 339 | // valid during its deletion. (Window's dtor notifies observers that may |
| 340 | // attempt to reach back up to access this object which will be valid until |
| 341 | // the end of the dtor). |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 342 | Window* window_; // Owning. |
| 343 | |
David Bienvenu | d0ddda3 | 2018-11-01 16:59:16 | [diff] [blame^] | 344 | // Keeps track of the occlusion state of the host, and used to send |
| 345 | // notifications to observers when it changes. |
| 346 | Window::OcclusionState occlusion_state_; |
| 347 | |
Trent Apted | a250ec3ab | 2018-08-19 08:52:19 | [diff] [blame] | 348 | base::ObserverList<WindowTreeHostObserver>::Unchecked observers_; |
[email protected] | 2d6eb74 | 2014-03-05 18:59:03 | [diff] [blame] | 349 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 350 | std::unique_ptr<WindowEventDispatcher> dispatcher_; |
[email protected] | 2f262033 | 2014-02-28 10:07:38 | [diff] [blame] | 351 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 352 | std::unique_ptr<ui::Compositor> compositor_; |
[email protected] | 0a04ef1 | 2013-12-19 20:15:40 | [diff] [blame] | 353 | |
Christopher Cameron | fa89068 | 2018-03-12 20:29:31 | [diff] [blame] | 354 | // The device scale factor is snapshotted in OnHostResizedInPixels. |
| 355 | // TODO(ccameron): The size and location from OnHostResizedInPixels and |
| 356 | // OnHostMovedInPixels should be snapshotted here as well. |
| 357 | float device_scale_factor_ = 1.f; |
| 358 | |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 359 | // Last cursor set. Used for testing. |
| 360 | gfx::NativeCursor last_cursor_; |
[email protected] | dc645d5 | 2014-04-28 14:42:55 | [diff] [blame] | 361 | gfx::Point last_cursor_request_position_in_host_; |
[email protected] | 4c090d2 | 2014-02-16 04:21:54 | [diff] [blame] | 362 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 363 | std::unique_ptr<ui::ViewProp> prop_; |
[email protected] | 2374d181 | 2014-03-04 03:42:27 | [diff] [blame] | 364 | |
shuchen | 29f3c7a | 2015-06-10 07:48:28 | [diff] [blame] | 365 | // The InputMethod instance used to process key events. |
| 366 | // If owned it, it is created in GetInputMethod() method; |
| 367 | // If not owned it, it is passed in through SetSharedInputMethod() method. |
| 368 | ui::InputMethod* input_method_; |
| 369 | |
| 370 | // Whether the InputMethod instance is owned by this WindowTreeHost. |
| 371 | bool owned_input_method_; |
| 372 | |
Fady Samuel | 9f84513 | 2017-11-28 17:33:24 | [diff] [blame] | 373 | // Set to the time the synchronization event began. |
| 374 | base::TimeTicks synchronization_start_time_; |
| 375 | |
Fady Samuel | d7625cc0 | 2017-10-13 05:25:18 | [diff] [blame] | 376 | // Set to true if this WindowTreeHost is currently holding pointer moves. |
| 377 | bool holding_pointer_moves_ = false; |
| 378 | |
Joe Downing | a8e74ac | 2018-02-26 17:10:24 | [diff] [blame] | 379 | base::WeakPtrFactory<WindowTreeHost> weak_factory_; |
| 380 | |
[email protected] | 641dcfd | 2014-01-08 16:41:23 | [diff] [blame] | 381 | DISALLOW_COPY_AND_ASSIGN(WindowTreeHost); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | } // namespace aura |
| 385 | |
[email protected] | e8cf733 | 2014-02-14 18:54:58 | [diff] [blame] | 386 | #endif // UI_AURA_WINDOW_TREE_HOST_H_ |