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
12namespace aura {
13class Window;
14}
15
16namespace gfx {
17class Point;
18class Rect;
19class Size;
20}
21
22namespace ui {
23class Event;
24}
25
26namespace ash {
27// We force at least this many DIPs for any window on the screen.
28const int kMinimumOnScreenArea = 10;
29
30namespace wm {
31
32// Utility functions for window activation.
33ASH_EXPORT void ActivateWindow(aura::Window* window);
34ASH_EXPORT void DeactivateWindow(aura::Window* window);
35ASH_EXPORT bool IsActiveWindow(aura::Window* window);
36ASH_EXPORT aura::Window* GetActiveWindow();
37ASH_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.
44ASH_EXPORT aura::Window* GetActivatableWindow(aura::Window* window);
45
46// TODO(oshima): remove this.
47ASH_EXPORT bool IsWindowMinimized(aura::Window* window);
48
49// Moves the window to the center of the display.
50ASH_EXPORT void CenterWindow(aura::Window* window);
51
52// Returns the bounds of a left snapped window with default width in parent
53// coordinates.
54ASH_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.
59ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(
60    aura::Window* window);
61
62// Adjusts |bounds| so that the size does not exceed |max_size|.
63ASH_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.
69ASH_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.
76ASH_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.
84ASH_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|.
89void 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|.
96void 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.
101void SnapWindowToPixelBoundary(aura::Window* window);
102
103// Mark the container window so that InstallSnapLayoutManagerToContainers
104// installs the SnapToPixelLayoutManager.
105ASH_EXPORT void SetSnapsChildrenToPhysicalPixelBoundary(
106    aura::Window* container);
107
108// Traverse the |container| tree and installs SnapToPixelLayoutManager.
109void InstallSnapLayoutManagerToContainers(aura::Window* container);
110
111}  // namespace wm
112}  // namespace ash
113
114#endif  // ASH_WM_WINDOW_UTIL_H_
115