Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 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_UTIL_H_ |
| 6 | #define ASH_WM_WINDOW_UTIL_H_ |
| 7 | |
| 8 | #include "ash/ash_export.h" |
| 9 | #include "base/compiler_specific.h" |
| 10 | #include "ui/base/ui_base_types.h" |
| 11 | |
| 12 | namespace aura { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | class Window; |
| 14 | } |
| 15 | |
| 16 | namespace gfx { |
| 17 | class Rect; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 18 | class Size; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | namespace ui { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 22 | class Event; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | namespace ash { |
| 26 | // We force at least this many DIPs for any window on the screen. |
| 27 | const int kMinimumOnScreenArea = 10; |
| 28 | |
| 29 | namespace wm { |
| 30 | |
Torne (Richard Coles) | 68043e1 | 2013-09-26 13:24:57 +0100 | [diff] [blame] | 31 | // Utility functions for window activation. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 32 | ASH_EXPORT void ActivateWindow(aura::Window* window); |
| 33 | ASH_EXPORT void DeactivateWindow(aura::Window* window); |
| 34 | ASH_EXPORT bool IsActiveWindow(aura::Window* window); |
| 35 | ASH_EXPORT aura::Window* GetActiveWindow(); |
| 36 | ASH_EXPORT bool CanActivateWindow(aura::Window* window); |
| 37 | |
| 38 | // Retrieves the activatable window for |window|. If |window| is activatable, |
| 39 | // this will just return it, otherwise it will climb the parent/transient parent |
| 40 | // chain looking for a window that is activatable, per the ActivationController. |
| 41 | // If you're looking for a function to get the activatable "top level" window, |
| 42 | // this is probably what you're looking for. |
| 43 | ASH_EXPORT aura::Window* GetActivatableWindow(aura::Window* window); |
| 44 | |
Torne (Richard Coles) | 68043e1 | 2013-09-26 13:24:57 +0100 | [diff] [blame] | 45 | // TODO(oshima): remove this. |
| 46 | ASH_EXPORT bool IsWindowMinimized(aura::Window* window); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 47 | |
| 48 | // Moves the window to the center of the display. |
| 49 | ASH_EXPORT void CenterWindow(aura::Window* window); |
| 50 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 51 | // Returns the bounds of a left snapped window with default width in parent |
| 52 | // coordinates. |
| 53 | ASH_EXPORT gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent( |
| 54 | aura::Window* window); |
| 55 | |
| 56 | // Returns the bounds of a right snapped window with default width in parent |
| 57 | // coordinates. |
| 58 | ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent( |
| 59 | aura::Window* window); |
| 60 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 61 | // Adjusts |bounds| so that the size does not exceed |max_size|. |
| 62 | ASH_EXPORT void AdjustBoundsSmallerThan(const gfx::Size& max_size, |
| 63 | gfx::Rect* bounds); |
| 64 | |
Torne (Richard Coles) | 8bcbed8 | 2013-10-22 16:41:35 +0100 | [diff] [blame] | 65 | // Move the given bounds inside the given |visible_area| in parent coordinates, |
| 66 | // including a safety margin given by |kMinimumOnScreenArea|. |
| 67 | // This also ensures that the top of the bounds is visible. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 68 | ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility( |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 69 | const gfx::Rect& visible_area, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 70 | gfx::Rect* bounds); |
| 71 | |
Torne (Richard Coles) | 8bcbed8 | 2013-10-22 16:41:35 +0100 | [diff] [blame] | 72 | // Move the given bounds inside the given |visible_area| in parent coordinates, |
| 73 | // including a safety margin given by |min_width| and |min_height|. |
| 74 | // This also ensures that the top of the bounds is visible. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 75 | ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility( |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 76 | const gfx::Rect& visible_area, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 77 | int min_width, |
| 78 | int min_height, |
| 79 | gfx::Rect* bounds); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 80 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 81 | // Moves |window| to the root window where the |event| occured if it is not |
| 82 | // already in the same root window. Returns true if |window| was moved. |
| 83 | ASH_EXPORT bool MoveWindowToEventRoot(aura::Window* window, |
| 84 | const ui::Event& event); |
| 85 | |
Torne (Richard Coles) | a3f6a49 | 2013-12-18 16:25:09 +0000 | [diff] [blame] | 86 | // Changes the parent of a |child| and all its transient children that are |
| 87 | // themselves children of |old_parent| to |new_parent|. |
| 88 | void ReparentChildWithTransientChildren(aura::Window* child, |
| 89 | aura::Window* old_parent, |
| 90 | aura::Window* new_parent); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 91 | |
Torne (Richard Coles) | a3f6a49 | 2013-12-18 16:25:09 +0000 | [diff] [blame] | 92 | // Changes the parent of all transient children of a |child| to |new_parent|. |
| 93 | // Does not change parent of the transient children that are not themselves |
| 94 | // children of |old_parent|. |
| 95 | void ReparentTransientChildrenOfChild(aura::Window* child, |
| 96 | aura::Window* old_parent, |
| 97 | aura::Window* new_parent); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 98 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 99 | } // namespace wm |
| 100 | } // namespace ash |
| 101 | |
| 102 | #endif // ASH_WM_WINDOW_UTIL_H_ |