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 { 13 class Window; 14 } 15 16 namespace gfx { 17 class Rect; 18 class Size; 19 } 20 21 namespace ui { 22 class Event; 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 31 // Utility functions for window activation. 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 45 // TODO(oshima): remove this. 46 ASH_EXPORT bool IsWindowMinimized(aura::Window* window); 47 48 // Moves the window to the center of the display. 49 ASH_EXPORT void CenterWindow(aura::Window* window); 50 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 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 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. 68 ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility( 69 const gfx::Rect& visible_area, 70 gfx::Rect* bounds); 71 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. 75 ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility( 76 const gfx::Rect& visible_area, 77 int min_width, 78 int min_height, 79 gfx::Rect* bounds); 80 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 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); 91 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); 98 99 } // namespace wm 100 } // namespace ash 101 102 #endif // ASH_WM_WINDOW_UTIL_H_ 103