| 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_COMMON_WM_WINDOW_H_ | |
| 6 #define ASH_COMMON_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/window_observer.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 #include "ui/wm/public/window_types.h" | |
| 22 | |
| 23 namespace display { | |
| 24 class Display; | |
| 25 } | |
| 26 | |
| 27 namespace gfx { | |
| 28 class Point; | |
| 29 class Rect; | |
| 30 class Size; | |
| 31 class Transform; | |
| 32 } | |
| 33 | |
| 34 namespace ui { | |
| 35 class EventHandler; | |
| 36 class Layer; | |
| 37 } | |
| 38 | |
| 39 namespace views { | |
| 40 class View; | |
| 41 class Widget; | |
| 42 } | |
| 43 | |
| 44 namespace ash { | |
| 45 | |
| 46 class ImmersiveFullscreenController; | |
| 47 class RootWindowController; | |
| 48 class WmLayoutManager; | |
| 49 class WmShell; | |
| 50 class WmTransientWindowObserver; | |
| 51 class WmWindowTestApi; | |
| 52 enum class WmWindowProperty; | |
| 53 | |
| 54 namespace wm { | |
| 55 class WindowState; | |
| 56 } | |
| 57 | |
| 58 // WmWindow abstracts away differences between ash running in classic mode | |
| 59 // and ash running with aura-mus. | |
| 60 // | |
| 61 // WmWindow is tied to the life of the underlying aura::Window. Use the | |
| 62 // static Get() function to obtain a WmWindow from an aura::Window. | |
| 63 class ASH_EXPORT WmWindow : public aura::WindowObserver, | |
| 64 public ::wm::TransientWindowObserver { | |
| 65 public: | |
| 66 // See comments in SetBoundsInScreen(). | |
| 67 enum class BoundsInScreenBehavior { | |
| 68 USE_LOCAL_COORDINATES, | |
| 69 USE_SCREEN_COORDINATES, | |
| 70 }; | |
| 71 | |
| 72 using Windows = std::vector<WmWindow*>; | |
| 73 | |
| 74 // NOTE: this class is owned by the corresponding window. You shouldn't delete | |
| 75 // TODO(sky): friend deleter and make private. | |
| 76 ~WmWindow() override; | |
| 77 | |
| 78 // Returns a WmWindow for an aura::Window, creating if necessary. |window| may | |
| 79 // be null, in which case null is returned. | |
| 80 static WmWindow* Get(aura::Window* window) { | |
| 81 return const_cast<WmWindow*>(Get(const_cast<const aura::Window*>(window))); | |
| 82 } | |
| 83 static const WmWindow* Get(const aura::Window* window); | |
| 84 | |
| 85 static std::vector<WmWindow*> FromAuraWindows( | |
| 86 const std::vector<aura::Window*>& aura_windows); | |
| 87 static std::vector<aura::Window*> ToAuraWindows( | |
| 88 const std::vector<WmWindow*>& windows); | |
| 89 | |
| 90 // Convenience for wm_window->aura_window(). Returns null if |wm_window| is | |
| 91 // null. | |
| 92 static aura::Window* GetAuraWindow(WmWindow* wm_window) { | |
| 93 return const_cast<aura::Window*>( | |
| 94 GetAuraWindow(const_cast<const WmWindow*>(wm_window))); | |
| 95 } | |
| 96 static const aura::Window* GetAuraWindow(const WmWindow* wm_window); | |
| 97 | |
| 98 aura::Window* aura_window() { return window_; } | |
| 99 const aura::Window* aura_window() const { return window_; } | |
| 100 | |
| 101 // See description of |children_use_extended_hit_region_|. | |
| 102 bool ShouldUseExtendedHitRegion() const; | |
| 103 | |
| 104 void Destroy(); | |
| 105 | |
| 106 WmWindow* GetRootWindow() { | |
| 107 return const_cast<WmWindow*>( | |
| 108 const_cast<const WmWindow*>(this)->GetRootWindow()); | |
| 109 } | |
| 110 const WmWindow* GetRootWindow() const; | |
| 111 RootWindowController* GetRootWindowController(); | |
| 112 | |
| 113 // TODO(sky): fix constness. | |
| 114 WmShell* GetShell() const; | |
| 115 | |
| 116 // Used for debugging. | |
| 117 void SetName(const char* name); | |
| 118 std::string GetName() const; | |
| 119 | |
| 120 void SetTitle(const base::string16& title); | |
| 121 base::string16 GetTitle() const; | |
| 122 | |
| 123 // See shell_window_ids.h for list of known ids. | |
| 124 void SetShellWindowId(int id); | |
| 125 int GetShellWindowId() const; | |
| 126 WmWindow* GetChildByShellWindowId(int id); | |
| 127 | |
| 128 ui::wm::WindowType GetType() const; | |
| 129 int GetAppType() const; | |
| 130 void SetAppType(int app_type) const; | |
| 131 | |
| 132 ui::Layer* GetLayer(); | |
| 133 | |
| 134 // TODO(sky): these are temporary until GetLayer() always returns non-null. | |
| 135 bool GetLayerTargetVisibility(); | |
| 136 bool GetLayerVisible(); | |
| 137 | |
| 138 display::Display GetDisplayNearestWindow(); | |
| 139 | |
| 140 bool HasNonClientArea(); | |
| 141 int GetNonClientComponent(const gfx::Point& location); | |
| 142 gfx::Point ConvertPointToTarget(const WmWindow* target, | |
| 143 const gfx::Point& point) const; | |
| 144 | |
| 145 gfx::Point ConvertPointToScreen(const gfx::Point& point) const; | |
| 146 gfx::Point ConvertPointFromScreen(const gfx::Point& point) const; | |
| 147 gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const; | |
| 148 gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const; | |
| 149 | |
| 150 gfx::Size GetMinimumSize() const; | |
| 151 gfx::Size GetMaximumSize() const; | |
| 152 | |
| 153 // Returns the visibility requested by this window. IsVisible() takes into | |
| 154 // account the visibility of the layer and ancestors, where as this tracks | |
| 155 // whether Show() without a Hide() has been invoked. | |
| 156 bool GetTargetVisibility() const; | |
| 157 | |
| 158 bool IsVisible() const; | |
| 159 | |
| 160 void SetOpacity(float opacity); | |
| 161 float GetTargetOpacity() const; | |
| 162 | |
| 163 gfx::Rect GetMinimizeAnimationTargetBoundsInScreen() const; | |
| 164 | |
| 165 void SetTransform(const gfx::Transform& transform); | |
| 166 gfx::Transform GetTargetTransform() const; | |
| 167 | |
| 168 bool IsSystemModal() const; | |
| 169 | |
| 170 wm::WindowState* GetWindowState() { | |
| 171 return const_cast<wm::WindowState*>( | |
| 172 const_cast<const WmWindow*>(this)->GetWindowState()); | |
| 173 } | |
| 174 const wm::WindowState* GetWindowState() const; | |
| 175 | |
| 176 // The implementation of this matches aura::Window::GetToplevelWindow(). | |
| 177 WmWindow* GetToplevelWindow(); | |
| 178 | |
| 179 // The implementation of this matches | |
| 180 // aura::client::ActivationClient::GetToplevelWindow(). | |
| 181 WmWindow* GetToplevelWindowForFocus(); | |
| 182 | |
| 183 // See aura::client::ParentWindowWithContext() for details of what this does. | |
| 184 void SetParentUsingContext(WmWindow* context, const gfx::Rect& screen_bounds); | |
| 185 void AddChild(WmWindow* window); | |
| 186 void RemoveChild(WmWindow* child); | |
| 187 | |
| 188 WmWindow* GetParent() { | |
| 189 return const_cast<WmWindow*>( | |
| 190 const_cast<const WmWindow*>(this)->GetParent()); | |
| 191 } | |
| 192 const WmWindow* GetParent() const; | |
| 193 | |
| 194 WmWindow* GetTransientParent() { | |
| 195 return const_cast<WmWindow*>( | |
| 196 const_cast<const WmWindow*>(this)->GetTransientParent()); | |
| 197 } | |
| 198 const WmWindow* GetTransientParent() const; | |
| 199 std::vector<WmWindow*> GetTransientChildren(); | |
| 200 | |
| 201 // Moves this to the display where |event| occurred; returns true if moved. | |
| 202 bool MoveToEventRoot(const ui::Event& event); | |
| 203 | |
| 204 void SetLayoutManager(std::unique_ptr<WmLayoutManager> layout_manager); | |
| 205 WmLayoutManager* GetLayoutManager(); | |
| 206 | |
| 207 // See wm::SetWindowVisibilityChangesAnimated() for details on what this | |
| 208 // does. | |
| 209 void SetVisibilityChangesAnimated(); | |
| 210 // |type| is WindowVisibilityAnimationType. Has to be an int to match aura. | |
| 211 void SetVisibilityAnimationType(int type); | |
| 212 void SetVisibilityAnimationDuration(base::TimeDelta delta); | |
| 213 void SetVisibilityAnimationTransition( | |
| 214 ::wm::WindowVisibilityAnimationTransition transition); | |
| 215 void Animate(::wm::WindowAnimationType type); | |
| 216 void StopAnimatingProperty( | |
| 217 ui::LayerAnimationElement::AnimatableProperty property); | |
| 218 void SetChildWindowVisibilityChangesAnimated(); | |
| 219 | |
| 220 // See description in ui::Layer. | |
| 221 void SetMasksToBounds(bool value); | |
| 222 void SetBounds(const gfx::Rect& bounds); | |
| 223 void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | |
| 224 base::TimeDelta delta); | |
| 225 // Sets the bounds in such a way that LayoutManagers are circumvented. | |
| 226 void SetBoundsDirect(const gfx::Rect& bounds); | |
| 227 void SetBoundsDirectAnimated(const gfx::Rect& bounds); | |
| 228 void SetBoundsDirectCrossFade(const gfx::Rect& bounds); | |
| 229 | |
| 230 // Sets the bounds in two distinct ways. The exact behavior is dictated by | |
| 231 // the value of BoundsInScreenBehavior set on the parent: | |
| 232 // | |
| 233 // USE_LOCAL_COORDINATES: the bounds are applied as is to the window. In other | |
| 234 // words this behaves the same as if SetBounds(bounds_in_screen) was used. | |
| 235 // This is the default. | |
| 236 // USE_SCREEN_COORDINATES: the bounds are actual screen bounds and converted | |
| 237 // from the display. In this case the window may move to a different | |
| 238 // display if allowed (see SetLockedToRoot()). | |
| 239 void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | |
| 240 const display::Display& dst_display); | |
| 241 gfx::Rect GetBoundsInScreen() const; | |
| 242 const gfx::Rect& GetBounds() const; | |
| 243 gfx::Rect GetTargetBounds(); | |
| 244 void ClearRestoreBounds(); | |
| 245 void SetRestoreBoundsInScreen(const gfx::Rect& bounds); | |
| 246 gfx::Rect GetRestoreBoundsInScreen() const; | |
| 247 | |
| 248 bool Contains(const WmWindow* other) const; | |
| 249 | |
| 250 void SetShowState(ui::WindowShowState show_state); | |
| 251 ui::WindowShowState GetShowState() const; | |
| 252 | |
| 253 void SetPreMinimizedShowState(ui::WindowShowState show_state); | |
| 254 ui::WindowShowState GetPreMinimizedShowState() const; | |
| 255 void SetPreFullscreenShowState(ui::WindowShowState show_state); | |
| 256 | |
| 257 // Sets the restore bounds and show state overrides. These values take | |
| 258 // precedence over the restore bounds and restore show state (if set). | |
| 259 // If |bounds_override| is empty the values are cleared. | |
| 260 void SetRestoreOverrides(const gfx::Rect& bounds_override, | |
| 261 ui::WindowShowState window_state_override); | |
| 262 | |
| 263 // If |value| is true the window can not be moved to another root, regardless | |
| 264 // of the bounds set on it. | |
| 265 void SetLockedToRoot(bool value); | |
| 266 bool IsLockedToRoot() const; | |
| 267 | |
| 268 void SetCapture(); | |
| 269 bool HasCapture(); | |
| 270 void ReleaseCapture(); | |
| 271 | |
| 272 bool HasRestoreBounds() const; | |
| 273 bool CanMaximize() const; | |
| 274 bool CanMinimize() const; | |
| 275 bool CanResize() const; | |
| 276 bool CanActivate() const; | |
| 277 | |
| 278 void StackChildAtTop(WmWindow* child); | |
| 279 void StackChildAtBottom(WmWindow* child); | |
| 280 void StackChildAbove(WmWindow* child, WmWindow* target); | |
| 281 void StackChildBelow(WmWindow* child, WmWindow* target); | |
| 282 | |
| 283 // See ScreenPinningController::SetPinnedWindow() for details. | |
| 284 void SetPinned(bool trusted); | |
| 285 | |
| 286 void SetAlwaysOnTop(bool value); | |
| 287 bool IsAlwaysOnTop() const; | |
| 288 | |
| 289 void Hide(); | |
| 290 void Show(); | |
| 291 | |
| 292 // Returns the widget associated with this window, or null if not associated | |
| 293 // with a widget. Only ash system UI widgets are returned, not widgets created | |
| 294 // by the mus window manager code to show a non-client frame. | |
| 295 views::Widget* GetInternalWidget(); | |
| 296 | |
| 297 // Requests the window to close and destroy itself. This is intended to | |
| 298 // forward to an associated widget. | |
| 299 void CloseWidget(); | |
| 300 | |
| 301 void SetFocused(); | |
| 302 bool IsFocused() const; | |
| 303 | |
| 304 bool IsActive() const; | |
| 305 void Activate(); | |
| 306 void Deactivate(); | |
| 307 | |
| 308 void SetFullscreen(bool fullscreen); | |
| 309 | |
| 310 void Maximize(); | |
| 311 void Minimize(); | |
| 312 void Unminimize(); | |
| 313 | |
| 314 std::vector<WmWindow*> GetChildren(); | |
| 315 | |
| 316 // Shows/hides the resize shadow. |component| is the component to show the | |
| 317 // shadow for (one of the constants in ui/base/hit_test.h). | |
| 318 void ShowResizeShadow(int component); | |
| 319 void HideResizeShadow(); | |
| 320 | |
| 321 // Installs a resize handler on the window that makes it easier to resize | |
| 322 // the window. See ResizeHandleWindowTargeter for the specifics. | |
| 323 void InstallResizeHandleWindowTargeter( | |
| 324 ImmersiveFullscreenController* immersive_fullscreen_controller); | |
| 325 | |
| 326 // See description in SetBoundsInScreen(). | |
| 327 void SetBoundsInScreenBehaviorForChildren(BoundsInScreenBehavior behavior); | |
| 328 | |
| 329 // See description of SnapToPixelBoundaryIfNecessary(). | |
| 330 void SetSnapsChildrenToPhysicalPixelBoundary(); | |
| 331 | |
| 332 // If an ancestor has been set to snap children to pixel boundaries, then | |
| 333 // snaps the layer associated with this window to the layer associated with | |
| 334 // the ancestor. | |
| 335 void SnapToPixelBoundaryIfNecessary(); | |
| 336 | |
| 337 // Makes the hit region for children slightly larger for easier resizing. | |
| 338 void SetChildrenUseExtendedHitRegion(); | |
| 339 | |
| 340 // Returns a View that renders the contents of this window's layers. | |
| 341 std::unique_ptr<views::View> CreateViewWithRecreatedLayers(); | |
| 342 | |
| 343 void AddTransientWindowObserver(WmTransientWindowObserver* observer); | |
| 344 void RemoveTransientWindowObserver(WmTransientWindowObserver* observer); | |
| 345 | |
| 346 // Adds or removes a handler to receive events targeted at this window, before | |
| 347 // this window handles the events itself; the handler does not recieve events | |
| 348 // from embedded windows. This only supports windows with internal widgets; | |
| 349 // see GetInternalWidget(). Ownership of the handler is not transferred. | |
| 350 // | |
| 351 // Also note that the target of these events is always an aura::Window. | |
| 352 void AddLimitedPreTargetHandler(ui::EventHandler* handler); | |
| 353 void RemoveLimitedPreTargetHandler(ui::EventHandler* handler); | |
| 354 | |
| 355 private: | |
| 356 friend class WmWindowTestApi; | |
| 357 | |
| 358 explicit WmWindow(aura::Window* window); | |
| 359 | |
| 360 // aura::WindowObserver: | |
| 361 void OnWindowPropertyChanged(aura::Window* window, | |
| 362 const void* key, | |
| 363 intptr_t old) override; | |
| 364 | |
| 365 // ::wm::TransientWindowObserver overrides: | |
| 366 void OnTransientChildAdded(aura::Window* window, | |
| 367 aura::Window* transient) override; | |
| 368 void OnTransientChildRemoved(aura::Window* window, | |
| 369 aura::Window* transient) override; | |
| 370 | |
| 371 aura::Window* window_; | |
| 372 | |
| 373 bool added_transient_observer_ = false; | |
| 374 base::ObserverList<WmTransientWindowObserver> transient_observers_; | |
| 375 | |
| 376 // If true child windows should get a slightly larger hit region to make | |
| 377 // resizing easier. | |
| 378 bool children_use_extended_hit_region_ = false; | |
| 379 | |
| 380 // Default value for |use_empty_minimum_size_for_testing_|. | |
| 381 static bool default_use_empty_minimum_size_for_testing_; | |
| 382 | |
| 383 // If true the minimum size is 0x0, default is minimum size comes from widget. | |
| 384 bool use_empty_minimum_size_for_testing_; | |
| 385 | |
| 386 DISALLOW_COPY_AND_ASSIGN(WmWindow); | |
| 387 }; | |
| 388 | |
| 389 } // namespace ash | |
| 390 | |
| 391 #endif // ASH_COMMON_WM_WINDOW_H_ | |
| OLD | NEW |