| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_WM_WINDOW_H_ | |
| 6 #define ASH_WM_WINDOW_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "ash/ash_export.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/strings/string16.h" | |
| 15 #include "base/time/time.h" | |
| 16 #include "ui/aura/client/window_types.h" | |
| 17 #include "ui/base/ui_base_types.h" | |
| 18 #include "ui/compositor/layer_animation_element.h" | |
| 19 #include "ui/wm/core/transient_window_observer.h" | |
| 20 #include "ui/wm/core/window_animations.h" | |
| 21 | |
| 22 namespace display { | |
| 23 class Display; | |
| 24 } | |
| 25 | |
| 26 namespace gfx { | |
| 27 class Point; | |
| 28 class Rect; | |
| 29 class Size; | |
| 30 class Transform; | |
| 31 } | |
| 32 | |
| 33 namespace ui { | |
| 34 class Layer; | |
| 35 } | |
| 36 | |
| 37 namespace ash { | |
| 38 | |
| 39 class RootWindowController; | |
| 40 class WmTransientWindowObserver; | |
| 41 enum class WmWindowProperty; | |
| 42 | |
| 43 namespace wm { | |
| 44 class WindowState; | |
| 45 } | |
| 46 | |
| 47 // WmWindow abstracts away differences between ash running in classic mode | |
| 48 // and ash running with aura-mus. | |
| 49 // | |
| 50 // WmWindow is tied to the life of the underlying aura::Window. Use the | |
| 51 // static Get() function to obtain a WmWindow from an aura::Window. | |
| 52 class ASH_EXPORT WmWindow : public ::wm::TransientWindowObserver { | |
| 53 public: | |
| 54 // See comments in SetBoundsInScreen(). | |
| 55 enum class BoundsInScreenBehavior { | |
| 56 USE_LOCAL_COORDINATES, | |
| 57 USE_SCREEN_COORDINATES, | |
| 58 }; | |
| 59 | |
| 60 using Windows = std::vector<WmWindow*>; | |
| 61 | |
| 62 // NOTE: this class is owned by the corresponding window. You shouldn't delete | |
| 63 // TODO(sky): friend deleter and make private. | |
| 64 ~WmWindow() override; | |
| 65 | |
| 66 // Returns a WmWindow for an aura::Window, creating if necessary. |window| may | |
| 67 // be null, in which case null is returned. | |
| 68 static WmWindow* Get(aura::Window* window) { | |
| 69 return const_cast<WmWindow*>(Get(const_cast<const aura::Window*>(window))); | |
| 70 } | |
| 71 static const WmWindow* Get(const aura::Window* window); | |
| 72 | |
| 73 static std::vector<WmWindow*> FromAuraWindows( | |
| 74 const std::vector<aura::Window*>& aura_windows); | |
| 75 static std::vector<aura::Window*> ToAuraWindows( | |
| 76 const std::vector<WmWindow*>& windows); | |
| 77 | |
| 78 // Convenience for wm_window->aura_window(). Returns null if |wm_window| is | |
| 79 // null. | |
| 80 static aura::Window* GetAuraWindow(WmWindow* wm_window) { | |
| 81 return const_cast<aura::Window*>( | |
| 82 GetAuraWindow(const_cast<const WmWindow*>(wm_window))); | |
| 83 } | |
| 84 static const aura::Window* GetAuraWindow(const WmWindow* wm_window); | |
| 85 | |
| 86 aura::Window* aura_window() { return window_; } | |
| 87 const aura::Window* aura_window() const { return window_; } | |
| 88 | |
| 89 void Destroy(); | |
| 90 | |
| 91 WmWindow* GetRootWindow() { | |
| 92 return const_cast<WmWindow*>( | |
| 93 const_cast<const WmWindow*>(this)->GetRootWindow()); | |
| 94 } | |
| 95 const WmWindow* GetRootWindow() const; | |
| 96 RootWindowController* GetRootWindowController(); | |
| 97 | |
| 98 // See shell_window_ids.h for list of known ids. | |
| 99 WmWindow* GetChildByShellWindowId(int id); | |
| 100 | |
| 101 aura::client::WindowType GetType() const; | |
| 102 int GetAppType() const; | |
| 103 void SetAppType(int app_type) const; | |
| 104 | |
| 105 ui::Layer* GetLayer(); | |
| 106 | |
| 107 // TODO(sky): these are temporary until GetLayer() always returns non-null. | |
| 108 bool GetLayerTargetVisibility(); | |
| 109 bool GetLayerVisible(); | |
| 110 | |
| 111 display::Display GetDisplayNearestWindow(); | |
| 112 | |
| 113 bool HasNonClientArea(); | |
| 114 int GetNonClientComponent(const gfx::Point& location); | |
| 115 gfx::Point ConvertPointToTarget(const WmWindow* target, | |
| 116 const gfx::Point& point) const; | |
| 117 | |
| 118 gfx::Point ConvertPointToScreen(const gfx::Point& point) const; | |
| 119 gfx::Point ConvertPointFromScreen(const gfx::Point& point) const; | |
| 120 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const; | |
| 121 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const; | |
| 122 | |
| 123 gfx::Size GetMinimumSize() const; | |
| 124 gfx::Size GetMaximumSize() const; | |
| 125 | |
| 126 // Returns the visibility requested by this window. IsVisible() takes into | |
| 127 // account the visibility of the layer and ancestors, where as this tracks | |
| 128 // whether Show() without a Hide() has been invoked. | |
| 129 bool GetTargetVisibility() const; | |
| 130 | |
| 131 bool IsVisible() const; | |
| 132 | |
| 133 void SetOpacity(float opacity); | |
| 134 float GetTargetOpacity() const; | |
| 135 | |
| 136 gfx::Rect GetMinimizeAnimationTargetBoundsInScreen() const; | |
| 137 | |
| 138 void SetTransform(const gfx::Transform& transform); | |
| 139 gfx::Transform GetTargetTransform() const; | |
| 140 | |
| 141 bool IsSystemModal() const; | |
| 142 | |
| 143 wm::WindowState* GetWindowState() { | |
| 144 return const_cast<wm::WindowState*>( | |
| 145 const_cast<const WmWindow*>(this)->GetWindowState()); | |
| 146 } | |
| 147 const wm::WindowState* GetWindowState() const; | |
| 148 | |
| 149 // The implementation of this matches aura::Window::GetToplevelWindow(). | |
| 150 WmWindow* GetToplevelWindow(); | |
| 151 | |
| 152 // The implementation of this matches | |
| 153 // wm::ActivationClient::GetToplevelWindow(). | |
| 154 WmWindow* GetToplevelWindowForFocus(); | |
| 155 | |
| 156 // See aura::client::ParentWindowWithContext() for details of what this does. | |
| 157 void SetParentUsingContext(WmWindow* context, const gfx::Rect& screen_bounds); | |
| 158 void AddChild(WmWindow* window); | |
| 159 void RemoveChild(WmWindow* child); | |
| 160 | |
| 161 WmWindow* GetParent() { | |
| 162 return const_cast<WmWindow*>( | |
| 163 const_cast<const WmWindow*>(this)->GetParent()); | |
| 164 } | |
| 165 const WmWindow* GetParent() const; | |
| 166 | |
| 167 WmWindow* GetTransientParent() { | |
| 168 return const_cast<WmWindow*>( | |
| 169 const_cast<const WmWindow*>(this)->GetTransientParent()); | |
| 170 } | |
| 171 const WmWindow* GetTransientParent() const; | |
| 172 std::vector<WmWindow*> GetTransientChildren(); | |
| 173 | |
| 174 // Moves this to the display where |event| occurred; returns true if moved. | |
| 175 bool MoveToEventRoot(const ui::Event& event); | |
| 176 | |
| 177 // See wm::SetWindowVisibilityChangesAnimated() for details on what this | |
| 178 // does. | |
| 179 void SetVisibilityChangesAnimated(); | |
| 180 // |type| is WindowVisibilityAnimationType. Has to be an int to match aura. | |
| 181 void SetVisibilityAnimationType(int type); | |
| 182 void SetVisibilityAnimationDuration(base::TimeDelta delta); | |
| 183 void SetVisibilityAnimationTransition( | |
| 184 ::wm::WindowVisibilityAnimationTransition transition); | |
| 185 void Animate(::wm::WindowAnimationType type); | |
| 186 void StopAnimatingProperty( | |
| 187 ui::LayerAnimationElement::AnimatableProperty property); | |
| 188 void SetChildWindowVisibilityChangesAnimated(); | |
| 189 | |
| 190 // See description in ui::Layer. | |
| 191 void SetMasksToBounds(bool value); | |
| 192 void SetBounds(const gfx::Rect& bounds); | |
| 193 void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | |
| 194 base::TimeDelta delta); | |
| 195 | |
| 196 // Sets the bounds in two distinct ways. The exact behavior is dictated by | |
| 197 // the value of BoundsInScreenBehavior set on the parent: | |
| 198 // | |
| 199 // USE_LOCAL_COORDINATES: the bounds are applied as is to the window. In other | |
| 200 // words this behaves the same as if SetBounds(bounds_in_screen) was used. | |
| 201 // This is the default. | |
| 202 // USE_SCREEN_COORDINATES: the bounds are actual screen bounds and converted | |
| 203 // from the display. In this case the window may move to a different | |
| 204 // display if allowed (see SetLockedToRoot()). | |
| 205 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | |
| 206 const display::Display& dst_display); | |
| 207 gfx::Rect GetBoundsInScreen() const; | |
| 208 const gfx::Rect& GetBounds() const; | |
| 209 gfx::Rect GetTargetBounds(); | |
| 210 void ClearRestoreBounds(); | |
| 211 void SetRestoreBoundsInScreen(const gfx::Rect& bounds); | |
| 212 gfx::Rect GetRestoreBoundsInScreen() const; | |
| 213 | |
| 214 bool Contains(const WmWindow* other) const; | |
| 215 | |
| 216 void SetShowState(ui::WindowShowState show_state); | |
| 217 ui::WindowShowState GetShowState() const; | |
| 218 | |
| 219 void SetPreFullscreenShowState(ui::WindowShowState show_state); | |
| 220 | |
| 221 // If |value| is true the window can not be moved to another root, regardless | |
| 222 // of the bounds set on it. | |
| 223 void SetLockedToRoot(bool value); | |
| 224 bool IsLockedToRoot() const; | |
| 225 | |
| 226 void SetCapture(); | |
| 227 bool HasCapture(); | |
| 228 void ReleaseCapture(); | |
| 229 | |
| 230 bool HasRestoreBounds() const; | |
| 231 bool CanMaximize() const; | |
| 232 bool CanMinimize() const; | |
| 233 bool CanResize() const; | |
| 234 bool CanActivate() const; | |
| 235 | |
| 236 void StackChildAtTop(WmWindow* child); | |
| 237 void StackChildAtBottom(WmWindow* child); | |
| 238 void StackChildAbove(WmWindow* child, WmWindow* target); | |
| 239 void StackChildBelow(WmWindow* child, WmWindow* target); | |
| 240 | |
| 241 void SetAlwaysOnTop(bool value); | |
| 242 bool IsAlwaysOnTop() const; | |
| 243 | |
| 244 void Hide(); | |
| 245 void Show(); | |
| 246 | |
| 247 void SetFocused(); | |
| 248 bool IsFocused() const; | |
| 249 | |
| 250 bool IsActive() const; | |
| 251 void Activate(); | |
| 252 void Deactivate(); | |
| 253 | |
| 254 void SetFullscreen(bool fullscreen); | |
| 255 | |
| 256 void Maximize(); | |
| 257 void Minimize(); | |
| 258 void Unminimize(); | |
| 259 | |
| 260 std::vector<WmWindow*> GetChildren(); | |
| 261 | |
| 262 // See description in SetBoundsInScreen(). | |
| 263 void SetBoundsInScreenBehaviorForChildren(BoundsInScreenBehavior behavior); | |
| 264 | |
| 265 // See description of SnapToPixelBoundaryIfNecessary(). | |
| 266 void SetSnapsChildrenToPhysicalPixelBoundary(); | |
| 267 | |
| 268 // If an ancestor has been set to snap children to pixel boundaries, then | |
| 269 // snaps the layer associated with this window to the layer associated with | |
| 270 // the ancestor. | |
| 271 void SnapToPixelBoundaryIfNecessary(); | |
| 272 | |
| 273 void AddTransientWindowObserver(WmTransientWindowObserver* observer); | |
| 274 void RemoveTransientWindowObserver(WmTransientWindowObserver* observer); | |
| 275 | |
| 276 private: | |
| 277 explicit WmWindow(aura::Window* window); | |
| 278 | |
| 279 // ::wm::TransientWindowObserver overrides: | |
| 280 void OnTransientChildAdded(aura::Window* window, | |
| 281 aura::Window* transient) override; | |
| 282 void OnTransientChildRemoved(aura::Window* window, | |
| 283 aura::Window* transient) override; | |
| 284 | |
| 285 aura::Window* window_; | |
| 286 | |
| 287 bool added_transient_observer_ = false; | |
| 288 base::ObserverList<WmTransientWindowObserver> transient_observers_; | |
| 289 | |
| 290 DISALLOW_COPY_AND_ASSIGN(WmWindow); | |
| 291 }; | |
| 292 | |
| 293 } // namespace ash | |
| 294 | |
| 295 #endif // ASH_WM_WINDOW_H_ | |
| OLD | NEW |