Home | History | Annotate | Download | only in wm
      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 RootWindow;
     14 class Window;
     15 }
     16 
     17 namespace gfx {
     18 class Rect;
     19 }
     20 
     21 namespace ui {
     22 class Event;
     23 class Layer;
     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 // Convenience setters/getters for |aura::client::kRootWindowActiveWindow|.
     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 // Returns true if |window| can be maximized.
     47 ASH_EXPORT bool CanMaximizeWindow(const aura::Window* window);
     48 
     49 // Returns true if |window| can be minimized.
     50 ASH_EXPORT bool CanMinimizeWindow(const aura::Window* window);
     51 
     52 // Returns true if |window| can be resized.
     53 ASH_EXPORT bool CanResizeWindow(const aura::Window* window);
     54 
     55 // Returns true if |window| can be snapped to the left or right.
     56 ASH_EXPORT bool CanSnapWindow(aura::Window* window);
     57 
     58 // Returns true if |window| is normal or default.
     59 ASH_EXPORT bool IsWindowNormal(const aura::Window* window);
     60 
     61 // Returns true if |state| is normal or default.
     62 ASH_EXPORT bool IsWindowStateNormal(const ui::WindowShowState state);
     63 
     64 // Returns true if |window| is in the maximized state.
     65 ASH_EXPORT bool IsWindowMaximized(const aura::Window* window);
     66 
     67 // Returns true if |window| is minimized.
     68 ASH_EXPORT bool IsWindowMinimized(const aura::Window* window);
     69 
     70 // Returns true if |window| is in the fullscreen state.
     71 ASH_EXPORT bool IsWindowFullscreen(const aura::Window* window);
     72 
     73 // Maximizes |window|, which must not be NULL.
     74 ASH_EXPORT void MaximizeWindow(aura::Window* window);
     75 
     76 // Minimizes |window|, which must not be NULL.
     77 ASH_EXPORT void MinimizeWindow(aura::Window* window);
     78 
     79 // Restores |window|, which must not be NULL.
     80 ASH_EXPORT void RestoreWindow(aura::Window* window);
     81 
     82 // Maximizes or restores |window| based on its state. |window| must not be NULL.
     83 ASH_EXPORT void ToggleMaximizedWindow(aura::Window* window);
     84 
     85 // Moves the window to the center of the display.
     86 ASH_EXPORT void CenterWindow(aura::Window* window);
     87 
     88 // Returns true if |window|'s position can automatically be managed.
     89 ASH_EXPORT bool IsWindowPositionManaged(const aura::Window* window);
     90 
     91 // Change the |window|'s position manageability to |managed|.
     92 ASH_EXPORT void SetWindowPositionManaged(aura::Window* window, bool managed);
     93 
     94 // Returns true if the user has changed the |window|'s position or size.
     95 ASH_EXPORT bool HasUserChangedWindowPositionOrSize(const aura::Window* window);
     96 
     97 // Marks a |window|'s coordinates to be changed by a user.
     98 ASH_EXPORT void SetUserHasChangedWindowPositionOrSize(aura::Window* window,
     99                                                       bool changed);
    100 
    101 // Get |window| bounds of the window before it was moved by the auto window
    102 // management. As long as it was not managed, it will return NULL.
    103 ASH_EXPORT const gfx::Rect* GetPreAutoManageWindowBounds(
    104     const aura::Window* window);
    105 
    106 // Remember the |bounds| of a |window| before an automated window management
    107 // operation takes place.
    108 ASH_EXPORT void SetPreAutoManageWindowBounds(aura::Window* window,
    109                                              const gfx::Rect& bounds);
    110 
    111 // Move the given bounds inside the given |visible_area|, including a
    112 // safety margin given by |kMinimumOnScreenArea|.
    113 ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility(
    114     const gfx::Rect& visible_area,
    115     gfx::Rect* bounds);
    116 
    117 // Move the given bounds inside the given |visible_area|, including a
    118 // safety margin given by |min_width| and |min_height|.
    119 ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility(
    120     const gfx::Rect& visible_area,
    121     int min_width,
    122     int min_height,
    123     gfx::Rect* bounds);
    124 
    125 // Moves |window| to the root window where the |event| occured if it is not
    126 // already in the same root window. Returns true if |window| was moved.
    127 ASH_EXPORT bool MoveWindowToEventRoot(aura::Window* window,
    128                                       const ui::Event& event);
    129 
    130 }  // namespace wm
    131 }  // namespace ash
    132 
    133 #endif  // ASH_WM_WINDOW_UTIL_H_
    134