blob: f371fbd89df2d275e0e97ad632c0045448f79fd1 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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 {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013class Window;
14}
15
16namespace gfx {
17class Rect;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000018class Size;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019}
20
21namespace ui {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010022class Event;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023}
24
25namespace ash {
26// We force at least this many DIPs for any window on the screen.
27const int kMinimumOnScreenArea = 10;
28
29namespace wm {
30
Torne (Richard Coles)68043e12013-09-26 13:24:57 +010031// Utility functions for window activation.
Torne (Richard Coles)58218062012-11-14 11:43:16 +000032ASH_EXPORT void ActivateWindow(aura::Window* window);
33ASH_EXPORT void DeactivateWindow(aura::Window* window);
34ASH_EXPORT bool IsActiveWindow(aura::Window* window);
35ASH_EXPORT aura::Window* GetActiveWindow();
36ASH_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.
43ASH_EXPORT aura::Window* GetActivatableWindow(aura::Window* window);
44
Torne (Richard Coles)68043e12013-09-26 13:24:57 +010045// TODO(oshima): remove this.
46ASH_EXPORT bool IsWindowMinimized(aura::Window* window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000047
48// Moves the window to the center of the display.
49ASH_EXPORT void CenterWindow(aura::Window* window);
50
Torne (Richard Coles)a1401312014-03-18 10:20:56 +000051// Returns the bounds of a left snapped window with default width in parent
52// coordinates.
53ASH_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.
58ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(
59 aura::Window* window);
60
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000061// Adjusts |bounds| so that the size does not exceed |max_size|.
62ASH_EXPORT void AdjustBoundsSmallerThan(const gfx::Size& max_size,
63 gfx::Rect* bounds);
64
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +010065// 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)2a99a7e2013-03-28 15:31:22 +000068ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility(
Torne (Richard Coles)3551c9c2013-08-23 16:39:15 +010069 const gfx::Rect& visible_area,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000070 gfx::Rect* bounds);
71
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +010072// 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)58218062012-11-14 11:43:16 +000075ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility(
Torne (Richard Coles)3551c9c2013-08-23 16:39:15 +010076 const gfx::Rect& visible_area,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000077 int min_width,
78 int min_height,
79 gfx::Rect* bounds);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000080
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010081// 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.
83ASH_EXPORT bool MoveWindowToEventRoot(aura::Window* window,
84 const ui::Event& event);
85
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +000086// Changes the parent of a |child| and all its transient children that are
87// themselves children of |old_parent| to |new_parent|.
88void ReparentChildWithTransientChildren(aura::Window* child,
89 aura::Window* old_parent,
90 aura::Window* new_parent);
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010091
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +000092// 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|.
95void ReparentTransientChildrenOfChild(aura::Window* child,
96 aura::Window* old_parent,
97 aura::Window* new_parent);
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010098
Torne (Richard Coles)58218062012-11-14 11:43:16 +000099} // namespace wm
100} // namespace ash
101
102#endif // ASH_WM_WINDOW_UTIL_H_