summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 21:29:37 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 21:29:37 +0000
commit8818cb9cad8062f289ebcb8ed538a22210d52f53 (patch)
treef3958fa26a0e7bd6920cdda28a2e74b970a9c773 /ash
parentde17e924a971f005ae8ddd5a884ab66b92b4136c (diff)
downloadchromium_src-8818cb9cad8062f289ebcb8ed538a22210d52f53.zip
chromium_src-8818cb9cad8062f289ebcb8ed538a22210d52f53.tar.gz
chromium_src-8818cb9cad8062f289ebcb8ed538a22210d52f53.tar.bz2
Minor refactoring of workspace code so that code for managed windows
can be centralized and not impact maximized/fullscreen code. BUG=111285 TEST=none R=oshima@chromium.org Review URL: https://chromiumcodereview.appspot.com/9375046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp4
-rw-r--r--ash/wm/workspace/managed_workspace.cc35
-rw-r--r--ash/wm/workspace/managed_workspace.h36
-rw-r--r--ash/wm/workspace/maximized_workspace.cc55
-rw-r--r--ash/wm/workspace/maximized_workspace.h38
-rw-r--r--ash/wm/workspace/workspace.cc70
-rw-r--r--ash/wm/workspace/workspace.h63
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc6
-rw-r--r--ash/wm/workspace/workspace_manager.cc110
-rw-r--r--ash/wm/workspace/workspace_manager.h12
-rw-r--r--ash/wm/workspace/workspace_manager_unittest.cc14
-rw-r--r--ash/wm/workspace_controller.h2
12 files changed, 282 insertions, 163 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 2d5bbe4..d979640 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -181,6 +181,10 @@
'wm/window_util.h',
'wm/workspace_controller.cc',
'wm/workspace_controller.h',
+ 'wm/workspace/managed_workspace.cc',
+ 'wm/workspace/managed_workspace.h',
+ 'wm/workspace/maximized_workspace.cc',
+ 'wm/workspace/maximized_workspace.h',
'wm/workspace/workspace.cc',
'wm/workspace/workspace.h',
'wm/workspace/workspace_event_filter.cc',
diff --git a/ash/wm/workspace/managed_workspace.cc b/ash/wm/workspace/managed_workspace.cc
new file mode 100644
index 0000000..9df095d
--- /dev/null
+++ b/ash/wm/workspace/managed_workspace.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 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.
+
+#include "ash/wm/workspace/managed_workspace.h"
+
+#include "ash/wm/window_util.h"
+
+namespace ash {
+namespace internal {
+
+ManagedWorkspace::ManagedWorkspace(WorkspaceManager* manager)
+ : Workspace(manager, TYPE_MANAGED) {
+}
+
+ManagedWorkspace::~ManagedWorkspace() {
+}
+
+bool ManagedWorkspace::CanAdd(aura::Window* window) const {
+ return !window_util::IsWindowFullscreen(window) &&
+ !window_util::IsWindowMaximized(window);
+}
+
+void ManagedWorkspace::OnWindowAddedAfter(aura::Window* window,
+ aura::Window* after) {
+}
+
+void ManagedWorkspace::OnWindowRemoved(aura::Window* window) {
+}
+
+void ManagedWorkspace::OnWorkspaceSizeChanged(const gfx::Rect& old_bounds) {
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/wm/workspace/managed_workspace.h b/ash/wm/workspace/managed_workspace.h
new file mode 100644
index 0000000..bf167ee
--- /dev/null
+++ b/ash/wm/workspace/managed_workspace.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 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_MANAGED_WORKSPACE_H_
+#define ASH_WM_WORKSPACE_MANAGED_WORKSPACE_H_
+
+#include "ash/wm/workspace/workspace.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+namespace internal {
+
+// ManagedWorkspace allows any non-maximized/fullscreen windows. It imposes
+// constraints on where the windows can be placed and how they can be resized.
+class ASH_EXPORT ManagedWorkspace : public Workspace {
+ public:
+ explicit ManagedWorkspace(WorkspaceManager* manager);
+ virtual ~ManagedWorkspace();
+
+ protected:
+ // Workspace overrides:
+ virtual bool CanAdd(aura::Window* window) const OVERRIDE;
+ virtual void OnWindowAddedAfter(aura::Window* window,
+ aura::Window* after) OVERRIDE;
+ virtual void OnWindowRemoved(aura::Window* window) OVERRIDE;
+ virtual void OnWorkspaceSizeChanged(const gfx::Rect& old_bounds) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ManagedWorkspace);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_WM_WORKPSACE_MANAGED_WORKSPACE_H_
diff --git a/ash/wm/workspace/maximized_workspace.cc b/ash/wm/workspace/maximized_workspace.cc
new file mode 100644
index 0000000..77b476f
--- /dev/null
+++ b/ash/wm/workspace/maximized_workspace.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2012 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.
+
+#include "ash/wm/workspace/maximized_workspace.h"
+
+#include "ash/wm/property_util.h"
+#include "ash/wm/window_util.h"
+#include "ash/wm/workspace/workspace_manager.h"
+#include "base/logging.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/base/ui_base_types.h"
+#include "ui/gfx/screen.h"
+
+namespace ash {
+namespace internal {
+
+MaximizedWorkspace::MaximizedWorkspace(WorkspaceManager* manager)
+ : Workspace(manager, TYPE_MAXIMIZED) {
+}
+
+MaximizedWorkspace::~MaximizedWorkspace() {
+}
+
+bool MaximizedWorkspace::CanAdd(aura::Window* window) const {
+ return is_empty() && (window_util::IsWindowFullscreen(window) ||
+ window_util::IsWindowMaximized(window));
+}
+
+void MaximizedWorkspace::OnWindowAddedAfter(aura::Window* window,
+ aura::Window* after) {
+ ResetWindowBounds(window);
+}
+
+void MaximizedWorkspace::OnWindowRemoved(aura::Window* window) {
+}
+
+void MaximizedWorkspace::OnWorkspaceSizeChanged(const gfx::Rect& old_bounds) {
+ for (size_t i = 0; i < windows().size(); ++i)
+ ResetWindowBounds(windows()[i]);
+}
+
+void MaximizedWorkspace::ResetWindowBounds(aura::Window* window) {
+ if (window_util::IsWindowFullscreen(window)) {
+ SetWindowBounds(window,
+ gfx::Screen::GetMonitorAreaNearestWindow(window));
+ } else {
+ SetWindowBounds(window, bounds());
+ }
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/wm/workspace/maximized_workspace.h b/ash/wm/workspace/maximized_workspace.h
new file mode 100644
index 0000000..5792a66
--- /dev/null
+++ b/ash/wm/workspace/maximized_workspace.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2012 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_MAXIMIZED_WORKSPACE_H_
+#define ASH_WM_WORKSPACE_MAXIMIZED_WORKSPACE_H_
+
+#include "ash/wm/workspace/workspace.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+namespace internal {
+
+// Workspace implementation that contains a single maximized or fullscreen
+// window.
+class ASH_EXPORT MaximizedWorkspace : public Workspace {
+ public:
+ explicit MaximizedWorkspace(WorkspaceManager* manager);
+ virtual ~MaximizedWorkspace();
+
+ protected:
+ // Workspace overrides:
+ virtual bool CanAdd(aura::Window* window) const OVERRIDE;
+ virtual void OnWindowAddedAfter(aura::Window* window,
+ aura::Window* after) OVERRIDE;
+ virtual void OnWindowRemoved(aura::Window* window) OVERRIDE;
+ virtual void OnWorkspaceSizeChanged(const gfx::Rect& old_bounds) OVERRIDE;
+
+ private:
+ void ResetWindowBounds(aura::Window* window);
+
+ DISALLOW_COPY_AND_ASSIGN(MaximizedWorkspace);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_WM_WORKSPACE_MAXIMIZED_WORKSPACE_H_
diff --git a/ash/wm/workspace/workspace.cc b/ash/wm/workspace/workspace.cc
index 3f5ebbe..3744a59 100644
--- a/ash/wm/workspace/workspace.cc
+++ b/ash/wm/workspace/workspace.cc
@@ -18,10 +18,9 @@
namespace ash {
namespace internal {
-Workspace::Workspace(WorkspaceManager* manager)
- : type_(TYPE_NORMAL),
+Workspace::Workspace(WorkspaceManager* manager, Type type)
+ : type_(type),
workspace_manager_(manager) {
- workspace_manager_->AddWorkspace(this);
}
Workspace::~Workspace() {
@@ -30,32 +29,11 @@ Workspace::~Workspace() {
// static
Workspace::Type Workspace::TypeForWindow(aura::Window* window) {
- if (window_util::GetOpenWindowSplit(window))
- return TYPE_SPLIT;
if (window_util::IsWindowMaximized(window) ||
window_util::IsWindowFullscreen(window)) {
return TYPE_MAXIMIZED;
}
- return TYPE_NORMAL;
-}
-
-void Workspace::SetType(Type type) {
- // Can only change the type when there are no windows, or the type of window
- // matches the type changing to. We need only check the first window as CanAdd
- // only allows new windows if the type matches.
- DCHECK(windows_.empty() || TypeForWindow(windows_[0]) == type);
- type_ = type;
-}
-
-void Workspace::WorkspaceSizeChanged() {
- if (!windows_.empty()) {
- // TODO: need to handle size changing.
- NOTIMPLEMENTED();
- }
-}
-
-gfx::Rect Workspace::GetWorkAreaBounds() const {
- return workspace_manager_->GetWorkAreaBounds();
+ return TYPE_MANAGED;
}
bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) {
@@ -69,21 +47,14 @@ bool Workspace::AddWindowAfter(aura::Window* window, aura::Window* after) {
windows_.push_back(window);
else
windows_.insert(++i, window);
-
- if (type_ == TYPE_MAXIMIZED) {
- workspace_manager_->SetWindowBounds(window, GetWorkAreaBounds());
- } else if (type_ == TYPE_SPLIT) {
- // TODO: this needs to adjust bounds appropriately.
- workspace_manager_->SetWindowBounds(window, GetWorkAreaBounds());
- }
-
+ OnWindowAddedAfter(window, after);
return true;
}
void Workspace::RemoveWindow(aura::Window* window) {
DCHECK(Contains(window));
windows_.erase(std::find(windows_.begin(), windows_.end(), window));
- // TODO: this needs to adjust things.
+ OnWindowRemoved(window);
}
bool Workspace::Contains(aura::Window* window) const {
@@ -94,27 +65,24 @@ void Workspace::Activate() {
workspace_manager_->SetActiveWorkspace(this);
}
-bool Workspace::ContainsFullscreenWindow() const {
- for (aura::Window::Windows::const_iterator i = windows_.begin();
- i != windows_.end();
- ++i) {
- aura::Window* w = *i;
- if (w->IsVisible() &&
- w->GetIntProperty(aura::client::kShowStateKey) ==
- ui::SHOW_STATE_FULLSCREEN)
- return true;
- }
- return false;
+void Workspace::SetBounds(const gfx::Rect& bounds) {
+ if (bounds_ == bounds)
+ return;
+
+ gfx::Rect old_bounds = bounds_;
+ bounds_ = bounds;
+ // Don't send size change for transition from empty -> not empty. That only
+ // happens when we're first created.
+ if (!old_bounds.IsEmpty())
+ OnWorkspaceSizeChanged(old_bounds);
}
-int Workspace::GetIndexOf(aura::Window* window) const {
- aura::Window::Windows::const_iterator i =
- std::find(windows_.begin(), windows_.end(), window);
- return i == windows_.end() ? -1 : i - windows_.begin();
+void Workspace::SetWindowBounds(aura::Window* window, const gfx::Rect& bounds) {
+ workspace_manager_->SetWindowBounds(window, bounds);
}
-bool Workspace::CanAdd(aura::Window* window) const {
- return TypeForWindow(window) == type_;
+void Workspace::SetIgnoredWindow(aura::Window* window) {
+ workspace_manager_->set_ignored_window(window);
}
} // namespace internal
diff --git a/ash/wm/workspace/workspace.h b/ash/wm/workspace/workspace.h
index 5441d5b..36ca39ff 100644
--- a/ash/wm/workspace/workspace.h
+++ b/ash/wm/workspace/workspace.h
@@ -7,9 +7,8 @@
#include <vector>
-#include "base/basictypes.h"
-#include "base/gtest_prod_util.h"
#include "ash/ash_export.h"
+#include "base/basictypes.h"
#include "ui/gfx/rect.h"
namespace aura {
@@ -20,7 +19,6 @@ namespace ash {
namespace internal {
class WorkspaceManager;
-class WorkspaceTest;
// A workspace contains a number of windows. The number of windows a Workspace
// may contain is dictated by the type. Typically only one workspace is visible
@@ -33,28 +31,16 @@ class ASH_EXPORT Workspace {
// The workspace holds a single maximized or full screen window.
TYPE_MAXIMIZED,
- // Workspace contains multiple windows that are split (also known as
- // co-maximized).
- TYPE_SPLIT,
-
- // Workspace contains non-maximized windows that can be moved in anyway.
- TYPE_NORMAL,
+ // Workspace contains non-maximized windows.
+ TYPE_MANAGED,
};
- // Specifies the direction to shift windows in |ShiftWindows()|.
- enum ShiftDirection {
- SHIFT_TO_RIGHT,
- SHIFT_TO_LEFT
- };
-
- explicit Workspace(WorkspaceManager* manager);
+ Workspace(WorkspaceManager* manager, Type type);
virtual ~Workspace();
// Returns the type of workspace that can contain |window|.
static Type TypeForWindow(aura::Window* window);
- // The type of this Workspace.
- void SetType(Type type);
Type type() const { return type_; }
// Returns true if this workspace has no windows.
@@ -62,11 +48,8 @@ class ASH_EXPORT Workspace {
size_t num_windows() const { return windows_.size(); }
const std::vector<aura::Window*>& windows() const { return windows_; }
- // Invoked when the size of the workspace changes.
- void WorkspaceSizeChanged();
-
// Returns the work area bounds of this workspace in viewport coordinates.
- gfx::Rect GetWorkAreaBounds() const;
+ const gfx::Rect& bounds() const { return bounds_; }
// Adds the |window| at the position after the window |after|. It
// inserts at the end if |after| is NULL. Return true if the
@@ -83,29 +66,41 @@ class ASH_EXPORT Workspace {
// Activates this workspace.
void Activate();
- // Returns true if the workspace contains a fullscreen window.
- bool ContainsFullscreenWindow() const;
+ // Sets the bounds of the workspace.
+ void SetBounds(const gfx::Rect& bounds);
- 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);
+ protected:
+ // Sets the bounds of the specified window.
+ void SetWindowBounds(aura::Window* window, const gfx::Rect& bounds);
- // Returns the index in layout order of |window| in this workspace.
- int GetIndexOf(aura::Window* window) const;
+ // Sets the ignore window. See WorkspaceManager::set_ignored_window() for
+ // details.
+ void SetIgnoredWindow(aura::Window* window);
// Returns true if the given |window| can be added to this workspace.
- bool CanAdd(aura::Window* window) const;
+ virtual bool CanAdd(aura::Window* window) const = 0;
+
+ // Invoked from AddWindowAfter().
+ virtual void OnWindowAddedAfter(aura::Window* window,
+ aura::Window* after) = 0;
+
+ // Invoked from RemoveWindow().
+ virtual void OnWindowRemoved(aura::Window* window) = 0;
- Type type_;
+ // Invoked when the size of the workspace changes. |old_bounds| is the
+ // previous bounds.
+ virtual void OnWorkspaceSizeChanged(const gfx::Rect& old_bounds) = 0;
+
+ private:
+ const Type type_;
WorkspaceManager* workspace_manager_;
// Windows in the workspace in layout order.
std::vector<aura::Window*> windows_;
+ gfx::Rect bounds_;
+
DISALLOW_COPY_AND_ASSIGN(Workspace);
};
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index e876d96..d9995d8c 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -75,10 +75,10 @@ void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
workspace_manager_->AddWindow(child);
} else if (window_util::IsWindowMaximized(child) ||
workspace_manager_->ShouldMaximize(child)) {
- if (!GetRestoreBounds(child))
- SetRestoreBounds(child, child->GetTargetBounds());
- if (!window_util::IsWindowMaximized(child))
+ if (!window_util::IsWindowMaximized(child)) {
+ SetRestoreBoundsIfNotSet(child);
window_util::MaximizeWindow(child);
+ }
SetChildBoundsDirect(child,
gfx::Screen::GetMonitorWorkAreaNearestWindow(child));
} else if (window_util::IsWindowFullscreen(child)) {
diff --git a/ash/wm/workspace/workspace_manager.cc b/ash/wm/workspace/workspace_manager.cc
index 78cd418..3be76c8 100644
--- a/ash/wm/workspace/workspace_manager.cc
+++ b/ash/wm/workspace/workspace_manager.cc
@@ -8,7 +8,8 @@
#include "ash/wm/property_util.h"
#include "ash/wm/window_util.h"
-#include "ash/wm/workspace/workspace.h"
+#include "ash/wm/workspace/managed_workspace.h"
+#include "ash/wm/workspace/maximized_workspace.h"
#include "base/auto_reset.h"
#include "base/logging.h"
#include "base/stl_util.h"
@@ -114,6 +115,11 @@ void WorkspaceManager::AddWindow(aura::Window* window) {
if (FindBy(window))
return; // Already know about this window.
+ if (!window_util::IsWindowMaximized(window) &&
+ !window_util::IsWindowFullscreen(window)) {
+ SetRestoreBounds(window, window->bounds());
+ }
+
if (!window->GetProperty(aura::client::kShowStateKey)) {
if (ShouldMaximize(window)) {
window->SetIntProperty(aura::client::kShowStateKey,
@@ -138,41 +144,18 @@ void WorkspaceManager::AddWindow(aura::Window* window) {
Workspace* workspace = NULL;
Workspace::Type type_for_window = Workspace::TypeForWindow(window);
switch (type_for_window) {
- case Workspace::TYPE_SPLIT:
- // Splits either go in current workspace (if maximized or split). If the
- // current workspace isn't split/maximized, then create a maximized
- // workspace.
- workspace = GetActiveWorkspace();
- if (workspace &&
- (workspace->type() == Workspace::TYPE_SPLIT ||
- workspace->type() == Workspace::TYPE_MAXIMIZED)) {
- // TODO: this needs to reset bounds of any existing windows in
- // workspace.
- workspace->SetType(Workspace::TYPE_SPLIT);
- } else {
- type_for_window = Workspace::TYPE_MAXIMIZED;
- workspace = NULL;
- }
- break;
-
- case Workspace::TYPE_NORMAL:
+ case Workspace::TYPE_MANAGED:
// All normal windows go in the same workspace.
- workspace = GetNormalWorkspace();
+ workspace = GetManagedWorkspace();
break;
case Workspace::TYPE_MAXIMIZED:
// All maximized windows go in their own workspace.
break;
-
- default:
- NOTREACHED();
- break;
}
- if (!workspace) {
- workspace = new Workspace(this);
- workspace->SetType(type_for_window);
- }
+ if (!workspace)
+ workspace = CreateWorkspace(type_for_window);
workspace->AddWindowAfter(window, NULL);
workspace->Activate();
}
@@ -209,7 +192,7 @@ void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) {
workspace_size_ = workspace_size;
for (Workspaces::const_iterator i = workspaces_.begin();
i != workspaces_.end(); ++i) {
- (*i)->WorkspaceSizeChanged();
+ (*i)->SetBounds(GetWorkAreaBounds());
}
}
@@ -247,6 +230,7 @@ void WorkspaceManager::OnWindowPropertyChanged(aura::Window* window,
void WorkspaceManager::AddWorkspace(Workspace* workspace) {
DCHECK(std::find(workspaces_.begin(), workspaces_.end(),
workspace) == workspaces_.end());
+ workspace->SetBounds(GetWorkAreaBounds());
if (active_workspace_) {
// New workspaces go right after current workspace.
Workspaces::iterator i = std::find(workspaces_.begin(), workspaces_.end(),
@@ -323,15 +307,12 @@ void WorkspaceManager::SetWindowBounds(aura::Window* window,
}
void WorkspaceManager::SetWindowBoundsFromRestoreBounds(aura::Window* window) {
- Workspace* workspace = FindBy(window);
- DCHECK(workspace);
const gfx::Rect* restore = GetRestoreBounds(window);
gfx::Rect bounds;
- if (restore) {
- bounds = restore->AdjustToFit(workspace->GetWorkAreaBounds());
- } else {
- bounds = window->bounds().AdjustToFit(workspace->GetWorkAreaBounds());
- }
+ if (restore)
+ bounds = restore->AdjustToFit(GetWorkAreaBounds());
+ else
+ bounds = window->bounds().AdjustToFit(GetWorkAreaBounds());
SetWindowBounds(window, AlignRectToGrid(bounds, grid_size_));
ash::ClearRestoreBounds(window);
}
@@ -346,49 +327,52 @@ void WorkspaceManager::SetFullScreenOrMaximizedBounds(aura::Window* window) {
}
void WorkspaceManager::OnTypeOfWorkspacedNeededChanged(aura::Window* window) {
- // TODO: needs to handle transitioning to split.
DCHECK(IsManagedWindow(window));
Workspace* current_workspace = FindBy(window);
DCHECK(current_workspace);
+ Workspace* new_workspace = NULL;
if (Workspace::TypeForWindow(window) == Workspace::TYPE_MAXIMIZED) {
- // Unmaximized -> maximized; create a new workspace (unless current only has
- // one window).
- if (current_workspace->num_windows() != 1) {
- current_workspace->RemoveWindow(window);
- Workspace* workspace = new Workspace(this);
- workspace->SetType(Workspace::TYPE_MAXIMIZED);
- workspace->AddWindowAfter(window, NULL);
- current_workspace = workspace;
- } else {
- current_workspace->SetType(Workspace::TYPE_MAXIMIZED);
- }
+ // Unmaximized -> maximized; create a new workspace.
+ SetRestoreBounds(window, window->bounds());
+ current_workspace->RemoveWindow(window);
+ new_workspace = CreateWorkspace(Workspace::TYPE_MAXIMIZED);
+ new_workspace->AddWindowAfter(window, NULL);
SetFullScreenOrMaximizedBounds(window);
} else {
- // Maximized -> unmaximized; move window to unmaximized workspace (or reuse
- // current if there isn't one).
+ // Maximized -> unmaximized; move window to unmaximized workspace.
window_util::SetOpenWindowSplit(window, false);
- Workspace* workspace = GetNormalWorkspace();
- if (workspace) {
- current_workspace->RemoveWindow(window);
- DCHECK(current_workspace->is_empty());
- workspace->AddWindowAfter(window, NULL);
- delete current_workspace;
- current_workspace = workspace;
- } else {
- current_workspace->SetType(Workspace::TYPE_NORMAL);
- }
+ new_workspace = GetManagedWorkspace();
+ current_workspace->RemoveWindow(window);
+ if (!new_workspace)
+ new_workspace = CreateWorkspace(Workspace::TYPE_MANAGED);
SetWindowBoundsFromRestoreBounds(window);
+ new_workspace->AddWindowAfter(window, NULL);
+ }
+ SetActiveWorkspace(new_workspace);
+ if (current_workspace->is_empty()) {
+ // Delete at the end so that we don't attempt to switch to another
+ // workspace in RemoveWorkspace().
+ delete current_workspace;
}
- SetActiveWorkspace(current_workspace);
}
-Workspace* WorkspaceManager::GetNormalWorkspace() {
+Workspace* WorkspaceManager::GetManagedWorkspace() {
for (size_t i = 0; i < workspaces_.size(); ++i) {
- if (workspaces_[i]->type() == Workspace::TYPE_NORMAL)
+ if (workspaces_[i]->type() == Workspace::TYPE_MANAGED)
return workspaces_[i];
}
return NULL;
}
+Workspace* WorkspaceManager::CreateWorkspace(Workspace::Type type) {
+ Workspace* workspace = NULL;
+ if (type == Workspace::TYPE_MAXIMIZED)
+ workspace = new MaximizedWorkspace(this);
+ else
+ workspace = new ManagedWorkspace(this);
+ AddWorkspace(workspace);
+ return workspace;
+}
+
} // namespace internal
} // namespace ash
diff --git a/ash/wm/workspace/workspace_manager.h b/ash/wm/workspace/workspace_manager.h
index b081cb2..5f72bc6 100644
--- a/ash/wm/workspace/workspace_manager.h
+++ b/ash/wm/workspace/workspace_manager.h
@@ -7,9 +7,10 @@
#include <vector>
+#include "ash/ash_export.h"
+#include "ash/wm/workspace/workspace.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "ash/ash_export.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/size.h"
@@ -25,7 +26,7 @@ class Rect;
namespace ash {
namespace internal {
-class Workspace;
+
class WorkspaceManagerTest;
// WorkspaceManager manages multiple workspaces in the desktop.
@@ -137,9 +138,12 @@ class ASH_EXPORT WorkspaceManager : public aura::WindowObserver{
// Invoked when the type of workspace needed for |window| changes.
void OnTypeOfWorkspacedNeededChanged(aura::Window* window);
- // Returns the Workspace whose type is TYPE_NORMAL, or NULL if there isn't
+ // Returns the Workspace whose type is TYPE_MANAGED, or NULL if there isn't
// one.
- Workspace* GetNormalWorkspace();
+ Workspace* GetManagedWorkspace();
+
+ // Creates a new workspace of the specified type.
+ Workspace* CreateWorkspace(Workspace::Type type);
aura::Window* contents_view_;
diff --git a/ash/wm/workspace/workspace_manager_unittest.cc b/ash/wm/workspace/workspace_manager_unittest.cc
index 2c736cc..e6eff25 100644
--- a/ash/wm/workspace/workspace_manager_unittest.cc
+++ b/ash/wm/workspace/workspace_manager_unittest.cc
@@ -116,7 +116,7 @@ TEST_F(WorkspaceManagerTest, AddNormalWindowWhenEmpty) {
// Should be 1 workspace, TYPE_NORNMAL with w1.
ASSERT_EQ(1u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(1u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
}
@@ -152,7 +152,7 @@ TEST_F(WorkspaceManagerTest, SingleMaximizeWindow) {
// Should be 1 workspace, TYPE_NORMAL with w1.
ASSERT_EQ(1u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(1u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
EXPECT_EQ(250, w1->bounds().width());
@@ -170,7 +170,7 @@ TEST_F(WorkspaceManagerTest, CloseLastWindowInWorkspace) {
// Should be 2 workspaces, TYPE_NORMAL with w1, and TYPE_MAXIMIZED with w2.
ASSERT_EQ(2u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(1u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
@@ -186,7 +186,7 @@ TEST_F(WorkspaceManagerTest, CloseLastWindowInWorkspace) {
// Should have one workspace, TYPE_NORMAL with w1.
ASSERT_EQ(1u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(1u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
EXPECT_TRUE(w1->layer()->visible());
@@ -230,7 +230,7 @@ TEST_F(WorkspaceManagerTest, MaximizeWithNormalWindow) {
// Should now be two workspaces.
ASSERT_EQ(2u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(1u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
EXPECT_EQ(Workspace::TYPE_MAXIMIZED, workspaces()[1]->type());
@@ -249,7 +249,7 @@ TEST_F(WorkspaceManagerTest, MaximizeWithNormalWindow) {
// Restore w2, which should then go back to one workspace.
w2->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
ASSERT_EQ(1u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(2u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
EXPECT_EQ(w2.get(), workspaces()[0]->windows()[1]);
@@ -383,7 +383,7 @@ TEST_F(WorkspaceManagerTest, SingleFullscreenWindow) {
// Should be 1 workspace, TYPE_NORMAL with w1.
ASSERT_EQ(1u, workspaces().size());
- EXPECT_EQ(Workspace::TYPE_NORMAL, workspaces()[0]->type());
+ EXPECT_EQ(Workspace::TYPE_MANAGED, workspaces()[0]->type());
ASSERT_EQ(1u, workspaces()[0]->windows().size());
EXPECT_EQ(w1.get(), workspaces()[0]->windows()[0]);
EXPECT_EQ(250, w1->bounds().width());
diff --git a/ash/wm/workspace_controller.h b/ash/wm/workspace_controller.h
index d79680b..b6998c5 100644
--- a/ash/wm/workspace_controller.h
+++ b/ash/wm/workspace_controller.h
@@ -84,7 +84,7 @@ class ASH_EXPORT WorkspaceController :
// Owned by the window its attached to.
WorkspaceLayoutManager* layout_manager_;
- // Owned the window set on.
+ // Owned by |viewport_|.
WorkspaceEventFilter* event_filter_;
#if !defined(OS_MACOSX)