summaryrefslogtreecommitdiffstats
path: root/ui/aura_shell/workspace/workspace.h
blob: 8d454da28b6291700f75a7bda0f080fd50977d3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_
#define UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_

#include <vector>

#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "ui/aura_shell/aura_shell_export.h"
#include "ui/gfx/rect.h"

namespace aura {
class Window;
}

namespace aura_shell {
namespace internal {

class WorkspaceManager;
class WorkspaceTest;

// A workspace is a partial area of the entire desktop (viewport) that
// is visible to the user at a given time. The size of the workspace is
// generally the same as the size of the monitor, and the desktop can
// have multiple workspaces.
// A workspace contains a limited number of windows and the workspace
// manager may create a new workspace if there is not enough room for
// a new window.
class AURA_SHELL_EXPORT Workspace {
 public:
  explicit Workspace(WorkspaceManager* manager);
  virtual ~Workspace();

  // Specifies the direction to shift windows in |ShiftWindows()|.
  enum ShiftDirection {
    SHIFT_TO_RIGHT,
    SHIFT_TO_LEFT
  };

  //  Returns true if this workspace has no windows.
  bool is_empty() const { return windows_.empty(); }

  // Sets/gets bounds of this workspace.
  const gfx::Rect& bounds() { return bounds_; }
  void SetBounds(const gfx::Rect& bounds);

  // Returns the work area bounds of this workspace in viewport
  // coordinates.
  gfx::Rect GetWorkAreaBounds() const;

  // Adds the |window| at the position after the window |after|.  It
  // inserts at the end if |after| is NULL. Return true if the
  // |window| was successfully added to this workspace, or false if it
  // failed.
  bool AddWindowAfter(aura::Window* window, aura::Window* after);

  // Removes |window| from this workspace.
  void RemoveWindow(aura::Window* window);

  // Return true if this workspace has |window|.
  bool Contains(aura::Window* window) const;

  // Returns a window to rotate to based on |position|.
  aura::Window* FindRotateWindowForLocation(const gfx::Point& position);

  // Rotates the windows by removing |source| and inserting it to the
  // position that |target| was in. It re-layouts windows except for |source|.
  void RotateWindows(aura::Window* source, aura::Window* target);

  // Shift the windows in the workspace by inserting |window| until it
  // reaches |until|. If |direction| is |SHIFT_TO_RIGHT|, |insert| is
  // inserted at the position of |target| or at the beginning if
  // |target| is NULL. If |direction| is |SHIFT_TO_LEFT|, |insert| is
  // inserted after the position of |target|, or at the end if
  // |target| is NULL.  It returns the window that is overflowed by
  // shifting, or NULL if shifting stopped at |until|.
  aura::Window* ShiftWindows(aura::Window* insert,
                             aura::Window* until,
                             aura::Window* target,
                             ShiftDirection direction);

  // Activates this workspace.
  void Activate();

  // Layout windows. The workspace doesn't set bounds on |ignore| if it's
  // given. It still uses |ignore| window's bounds to calculate
  // bounds for other windows. Moving animation is applied to all
  // windows except for the window specified by |no_animation| and |ignore|.
  void Layout(aura::Window* ignore, aura::Window* no_animation);

  // Returns true if the workspace contains a fullscreen window.
  bool ContainsFullscreenWindow() const;

 private:
  FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, WorkspaceBasic);
  FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, RotateWindows);
  FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsSingle);
  FRIEND_TEST_ALL_PREFIXES(WorkspaceTest, ShiftWindowsMultiple);
  FRIEND_TEST_ALL_PREFIXES(WorkspaceManagerTest, RotateWindows);

  // Returns the index in layout order of |window| in this workspace.
  int GetIndexOf(aura::Window* window) const;

  // Returns true if the given |window| can be added to this workspace.
  bool CanAdd(aura::Window* window) const;

  // Moves |window| to the given point. It performs animation when
  // |animate| is true.
  void MoveWindowTo(aura::Window* window,
                    const gfx::Point& origin,
                    bool animate);

  // Returns the sum of all window's width.
  int GetTotalWindowsWidth() const;

  // Test only: Changes how may windows workspace can have.
  // Returns the current value so that it can be reverted back to
  // original value.
  static size_t SetMaxWindowsCount(size_t max);

  WorkspaceManager* workspace_manager_;

  gfx::Rect bounds_;

  // Windows in the workspace in layout order.
  std::vector<aura::Window*> windows_;

  DISALLOW_COPY_AND_ASSIGN(Workspace);
};

typedef std::vector<Workspace*> Workspaces;

}  // namespace internal
}  // namespace aura_shell

#endif  // UI_AURA_SHELL_WORKSPACE_WORKSPACE_H_