• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Point;
18 class Rect;
19 class Size;
20 }
21 
22 namespace ui {
23 class Event;
24 }
25 
26 namespace ash {
27 // We force at least this many DIPs for any window on the screen.
28 const int kMinimumOnScreenArea = 10;
29 
30 namespace wm {
31 
32 // Utility functions for window activation.
33 ASH_EXPORT void ActivateWindow(aura::Window* window);
34 ASH_EXPORT void DeactivateWindow(aura::Window* window);
35 ASH_EXPORT bool IsActiveWindow(aura::Window* window);
36 ASH_EXPORT aura::Window* GetActiveWindow();
37 ASH_EXPORT bool CanActivateWindow(aura::Window* window);
38 
39 // Retrieves the activatable window for |window|. If |window| is activatable,
40 // this will just return it, otherwise it will climb the parent/transient parent
41 // chain looking for a window that is activatable, per the ActivationController.
42 // If you're looking for a function to get the activatable "top level" window,
43 // this is probably what you're looking for.
44 ASH_EXPORT aura::Window* GetActivatableWindow(aura::Window* window);
45 
46 // TODO(oshima): remove this.
47 ASH_EXPORT bool IsWindowMinimized(aura::Window* window);
48 
49 // Moves the window to the center of the display.
50 ASH_EXPORT void CenterWindow(aura::Window* window);
51 
52 // Returns the bounds of a left snapped window with default width in parent
53 // coordinates.
54 ASH_EXPORT gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(
55     aura::Window* window);
56 
57 // Returns the bounds of a right snapped window with default width in parent
58 // coordinates.
59 ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(
60     aura::Window* window);
61 
62 // Adjusts |bounds| so that the size does not exceed |max_size|.
63 ASH_EXPORT void AdjustBoundsSmallerThan(const gfx::Size& max_size,
64                                         gfx::Rect* bounds);
65 
66 // Move the given bounds inside the given |visible_area| in parent coordinates,
67 // including a safety margin given by |kMinimumOnScreenArea|.
68 // This also ensures that the top of the bounds is visible.
69 ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility(
70     const gfx::Rect& visible_area,
71     gfx::Rect* bounds);
72 
73 // Move the given bounds inside the given |visible_area| in parent coordinates,
74 // including a safety margin given by |min_width| and |min_height|.
75 // This also ensures that the top of the bounds is visible.
76 ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility(
77     const gfx::Rect& visible_area,
78     int min_width,
79     int min_height,
80     gfx::Rect* bounds);
81 
82 // Moves |window| to the root window where the |event| occured if it is not
83 // already in the same root window. Returns true if |window| was moved.
84 ASH_EXPORT bool MoveWindowToEventRoot(aura::Window* window,
85                                       const ui::Event& event);
86 
87 // Changes the parent of a |child| and all its transient children that are
88 // themselves children of |old_parent| to |new_parent|.
89 void ReparentChildWithTransientChildren(aura::Window* child,
90                                         aura::Window* old_parent,
91                                         aura::Window* new_parent);
92 
93 // Changes the parent of all transient children of a |child| to |new_parent|.
94 // Does not change parent of the transient children that are not themselves
95 // children of |old_parent|.
96 void ReparentTransientChildrenOfChild(aura::Window* child,
97                                       aura::Window* old_parent,
98                                       aura::Window* new_parent);
99 
100 // Snap the window's layer to physical pixel boundary.
101 void SnapWindowToPixelBoundary(aura::Window* window);
102 
103 // Mark the container window so that InstallSnapLayoutManagerToContainers
104 // installs the SnapToPixelLayoutManager.
105 ASH_EXPORT void SetSnapsChildrenToPhysicalPixelBoundary(
106     aura::Window* container);
107 
108 // Traverse the |container| tree and installs SnapToPixelLayoutManager.
109 void InstallSnapLayoutManagerToContainers(aura::Window* container);
110 
111 }  // namespace wm
112 }  // namespace ash
113 
114 #endif  // ASH_WM_WINDOW_UTIL_H_
115