summaryrefslogtreecommitdiffstats
path: root/ash/wm/workspace/workspace_manager.h
blob: 99560e94643da9e141158b32ca069d9814e4fd0e (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
// 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 ASH_WM_WORKSPACE_MANAGER_H_
#define ASH_WM_WORKSPACE_MANAGER_H_

#include <vector>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "ash/ash_export.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/size.h"

namespace aura {
class Window;
}

namespace gfx {
class Point;
class Rect;
}

namespace ash {
namespace internal {
class Workspace;
class WorkspaceObserver;

// WorkspaceManager manages multiple workspaces in the desktop.
class ASH_EXPORT WorkspaceManager {
 public:
  explicit WorkspaceManager(aura::Window* viewport);
  virtual ~WorkspaceManager();

  // Returns the Window this WorkspaceManager controls.
  aura::Window* contents_view() { return contents_view_; }

  // Create new workspace. Workspace objects are managed by
  // this WorkspaceManager. Deleting workspace will automatically
  // remove the workspace from the workspace_manager.
  Workspace* CreateWorkspace();

  // Returns the active workspace.
  Workspace* GetActiveWorkspace() const;

  // Returns the workspace that contanis the |window|.
  Workspace* FindBy(aura::Window* window) const;

  // Returns the window for rotate operation based on the |location|.
  aura::Window* FindRotateWindowForLocation(const gfx::Point& location);

  // Sets the bounds of all workspaces.
  void LayoutWorkspaces();

  // Returns the bounds in which a window can be moved/resized.
  gfx::Rect GetDragAreaBounds();

  // Turn on/off overview mode.
  void SetOverview(bool overview);
  bool is_overview() const { return is_overview_; }

  // Rotate windows by moving |source| window to the position of |target|.
  void RotateWindows(aura::Window* source, aura::Window* target);

  // Sets the size of a single workspace (all workspaces have the same size).
  void SetWorkspaceSize(const gfx::Size& workspace_size);

  // Adds/Removes workspace observer.
  void AddObserver(WorkspaceObserver* observer);
  void RemoveObserver(WorkspaceObserver* observer);

  // Returns true if this workspace manager is laying out windows.
  // When true, LayoutManager must give windows their requested bounds.
  bool layout_in_progress() const { return layout_in_progress_; }

  // Sets the |layout_in_progress_| flag.
  void set_layout_in_progress(bool layout_in_progress) {
    layout_in_progress_ = layout_in_progress;
  }

  // Sets/Returns the ignored window that the workspace manager does not
  // set bounds on.
  void set_ignored_window(aura::Window* ignored_window) {
    ignored_window_ = ignored_window;
  }
  aura::Window* ignored_window() { return ignored_window_; }

 private:
  friend class Workspace;

  void AddWorkspace(Workspace* workspace);
  void RemoveWorkspace(Workspace* workspace);

  // Sets the active workspace.
  void SetActiveWorkspace(Workspace* workspace);

  // Returns the bounds of the work are given |workspace_bounds|.
  gfx::Rect GetWorkAreaBounds(const gfx::Rect& workspace_bounds);

  // Returns the index of the workspace that contains the |window|.
  int GetWorkspaceIndexContaining(aura::Window* window) const;

  // Update contents_view size and move the viewport to the active workspace.
  void UpdateContentsView();

  aura::Window* contents_view_;

  Workspace* active_workspace_;

  std::vector<Workspace*> workspaces_;

  // The size of a single workspace. This is generally the same as the size of
  // monitor.
  gfx::Size workspace_size_;

  // True if the workspace manager is in overview mode.
  bool is_overview_;

  // True if this layout manager is laying out windows.
  bool layout_in_progress_;

  // The window that WorkspaceManager does not set the bounds on.
  aura::Window* ignored_window_;

  ObserverList<WorkspaceObserver> observers_;

  DISALLOW_COPY_AND_ASSIGN(WorkspaceManager);
};

}  // namespace internal
}  // namespace ash

#endif  // ASH_WM_WORKSPACE_MANAGER_H_