diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 15:54:24 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-02 15:54:24 +0000 |
commit | 7eac87b87a4176b953a7d0506482d1f4685bd6a8 (patch) | |
tree | 6c0def1e2c2f50312ca05cfc09ff769c5a3e963c /ui | |
parent | 0656dcdfb8e4a2fbb1366a663ebea212a784c154 (diff) | |
download | chromium_src-7eac87b87a4176b953a7d0506482d1f4685bd6a8.zip chromium_src-7eac87b87a4176b953a7d0506482d1f4685bd6a8.tar.gz chromium_src-7eac87b87a4176b953a7d0506482d1f4685bd6a8.tar.bz2 |
Add WorkspaceObserver to observe changes in workspace state
Reduce dependencies amongst DCLM, ShowStateC, WorkspaceC and such.
I changed my mind and kept "WorkspaceController owns WorkspaceManager" as this seems to be better in long run. I decoupled DCLM from ShowStateC and WorkspaceC. I moved a layout_in_progress flag to WorkspaceManager as it really belongs there, and can reduce dependency.
BUG=84070
TEST=new test conditions for workspace observer are added to workspace_manager_unittests
Review URL: http://codereview.chromium.org/8430024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura_shell/aura_shell.gyp | 1 | ||||
-rw-r--r-- | ui/aura_shell/default_container_layout_manager.cc | 21 | ||||
-rw-r--r-- | ui/aura_shell/default_container_layout_manager.h | 18 | ||||
-rw-r--r-- | ui/aura_shell/default_container_layout_manager_unittest.cc | 13 | ||||
-rw-r--r-- | ui/aura_shell/shell.cc | 4 | ||||
-rw-r--r-- | ui/aura_shell/show_state_controller.cc | 9 | ||||
-rw-r--r-- | ui/aura_shell/show_state_controller.h | 8 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace.cc | 2 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace_controller.cc | 9 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace_controller.h | 10 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace_manager.cc | 35 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace_manager.h | 24 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace_manager_unittest.cc | 77 | ||||
-rw-r--r-- | ui/aura_shell/workspace/workspace_observer.h | 40 |
14 files changed, 207 insertions, 64 deletions
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index 4bf31bf..35d2efd7 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -76,6 +76,7 @@ 'workspace/workspace_controller.h', 'workspace/workspace_manager.cc', 'workspace/workspace_manager.h', + 'workspace/workspace_observer.h', ], }, { diff --git a/ui/aura_shell/default_container_layout_manager.cc b/ui/aura_shell/default_container_layout_manager.cc index d9658e0..d44eec5 100644 --- a/ui/aura_shell/default_container_layout_manager.cc +++ b/ui/aura_shell/default_container_layout_manager.cc @@ -4,7 +4,6 @@ #include "ui/aura_shell/default_container_layout_manager.h" -#include "base/auto_reset.h" #include "ui/aura/aura_constants.h" #include "ui/aura/desktop.h" #include "ui/aura/event.h" @@ -27,13 +26,10 @@ namespace internal { // DefaultContainerLayoutManager, public: DefaultContainerLayoutManager::DefaultContainerLayoutManager( - aura::Window* owner, WorkspaceManager* workspace_manager) - : owner_(owner), - workspace_manager_(workspace_manager), + : workspace_manager_(workspace_manager), drag_window_(NULL), - ignore_calculate_bounds_(false), - show_state_controller_(new ShowStateController(this)) { + show_state_controller_(new ShowStateController(workspace_manager)) { } DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} @@ -53,8 +49,6 @@ void DefaultContainerLayoutManager::CancelMoveOrResize( void DefaultContainerLayoutManager::ProcessMove( aura::Window* drag, aura::MouseEvent* event) { - AutoReset<bool> reset(&ignore_calculate_bounds_, true); - // TODO(oshima): Just zooming out may (and will) move/swap window without // a users's intent. We probably should scroll viewport, but that may not // be enough. See crbug.com/101826 for more discussion. @@ -63,7 +57,7 @@ void DefaultContainerLayoutManager::ProcessMove( gfx::Point point_in_owner = event->location(); aura::Window::ConvertPointToWindow( drag, - owner_, + workspace_manager_->viewport(), &point_in_owner); // TODO(oshima): We should support simply moving to another // workspace when the destination workspace has enough room to accomodate. @@ -77,7 +71,6 @@ void DefaultContainerLayoutManager::EndMove( aura::Window* drag, aura::MouseEvent* evnet) { // TODO(oshima): finish moving window between workspaces. - AutoReset<bool> reset(&ignore_calculate_bounds_, true); drag_window_ = NULL; Workspace* workspace = workspace_manager_->FindBy(drag); @@ -89,7 +82,6 @@ void DefaultContainerLayoutManager::EndMove( void DefaultContainerLayoutManager::EndResize( aura::Window* drag, aura::MouseEvent* evnet) { - AutoReset<bool> reset(&ignore_calculate_bounds_, true); drag_window_ = NULL; Workspace* workspace = workspace_manager_->GetActiveWorkspace(); if (workspace) @@ -113,8 +105,6 @@ void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) { child->AddObserver(show_state_controller_.get()); - AutoReset<bool> reset(&ignore_calculate_bounds_, true); - Workspace* workspace = workspace_manager_->GetActiveWorkspace(); if (workspace) { aura::Window* active = aura::Desktop::GetInstance()->active_window(); @@ -131,7 +121,6 @@ void DefaultContainerLayoutManager::OnWindowAdded(aura::Window* child) { } void DefaultContainerLayoutManager::OnWillRemoveWindow(aura::Window* child) { - AutoReset<bool> reset(&ignore_calculate_bounds_, true); child->RemoveObserver(show_state_controller_.get()); ClearRestoreBounds(child); @@ -156,7 +145,7 @@ void DefaultContainerLayoutManager::SetChildBounds( // First, calculate the adjusted bounds. if (child->type() != aura::WINDOW_TYPE_NORMAL || - ignore_calculate_bounds_ || + workspace_manager_->layout_in_progress() || child->transient_parent()) { // Use the requested bounds as is. } else if (drag_window_) { @@ -181,7 +170,7 @@ void DefaultContainerLayoutManager::SetChildBounds( show_state == ui::SHOW_STATE_FULLSCREEN) { // If the request is not from workspace manager, // remember the requested bounds. - if (!ignore_calculate_bounds_) + if (!workspace_manager_->layout_in_progress()) SetRestoreBounds(child, adjusted_bounds); Workspace* workspace = workspace_manager_->FindBy(child); diff --git a/ui/aura_shell/default_container_layout_manager.h b/ui/aura_shell/default_container_layout_manager.h index cd4421c..50336c3 100644 --- a/ui/aura_shell/default_container_layout_manager.h +++ b/ui/aura_shell/default_container_layout_manager.h @@ -31,8 +31,7 @@ class WorkspaceManager; class AURA_SHELL_EXPORT DefaultContainerLayoutManager : public aura::LayoutManager { public: - DefaultContainerLayoutManager(aura::Window* owner, - WorkspaceManager* workspace_manager); + explicit DefaultContainerLayoutManager(WorkspaceManager* workspace_manager); virtual ~DefaultContainerLayoutManager(); // Returns the workspace manager for this container. @@ -55,13 +54,6 @@ class AURA_SHELL_EXPORT DefaultContainerLayoutManager // Invoked when a user finished resizing window. void EndResize(aura::Window* drag, aura::MouseEvent* evnet); - // If true, |SetChildBounds| does not modify the requested bounds. - // Use in situations where you want to circumvent what - // SetChildBounds() would normally do. - void set_ignore_calculate_bounds(bool value) { - ignore_calculate_bounds_ = value; - } - // Overridden from aura::LayoutManager: virtual void OnWindowResized() OVERRIDE; virtual void OnWindowAdded(aura::Window* child) OVERRIDE; @@ -71,19 +63,13 @@ class AURA_SHELL_EXPORT DefaultContainerLayoutManager virtual void SetChildBounds(aura::Window* child, const gfx::Rect& requested_bounds) OVERRIDE; private: - aura::Window* owner_; - + // Owned by WorkspaceController. WorkspaceManager* workspace_manager_; // A window that are currently moved or resized. Used to put // different constraints on drag window. aura::Window* drag_window_; - // A flag to control layout behavior. This is set to true while - // workspace manager is laying out children and LayoutManager - // ignores bounds check. - bool ignore_calculate_bounds_; - scoped_ptr<ShowStateController> show_state_controller_; DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManager); diff --git a/ui/aura_shell/default_container_layout_manager_unittest.cc b/ui/aura_shell/default_container_layout_manager_unittest.cc index 765d167..bf145e6 100644 --- a/ui/aura_shell/default_container_layout_manager_unittest.cc +++ b/ui/aura_shell/default_container_layout_manager_unittest.cc @@ -28,7 +28,7 @@ using aura_shell::internal::DefaultContainerLayoutManager; class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { public: - DefaultContainerLayoutManagerTest() {} + DefaultContainerLayoutManagerTest() : layout_manager_(NULL) {} virtual ~DefaultContainerLayoutManagerTest() {} virtual void SetUp() OVERRIDE { @@ -37,7 +37,10 @@ class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { container_.reset( CreateTestWindow(gfx::Rect(0, 0, 500, 400), desktop)); workspace_controller_.reset( - new internal::WorkspaceController(container_.get())); + new aura_shell::internal::WorkspaceController(container_.get())); + layout_manager_ = new DefaultContainerLayoutManager( + workspace_controller_->workspace_manager()); + container_->SetLayoutManager(layout_manager_); desktop->SetHostSize(gfx::Size(500, 400)); } @@ -64,17 +67,19 @@ class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { aura::Window* container() { return container_.get(); } DefaultContainerLayoutManager* default_container_layout_manager() { - return workspace_controller_->layout_manager(); + return layout_manager_; } protected: aura_shell::internal::WorkspaceManager* workspace_manager() { - return workspace_controller_->layout_manager()->workspace_manager(); + return workspace_controller_->workspace_manager(); } private: scoped_ptr<aura::Window> container_; scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; + // LayoutManager is owned by |container|. + aura_shell::internal::DefaultContainerLayoutManager* layout_manager_; private: DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index 81f5a09..358f29b 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -11,6 +11,7 @@ #include "ui/aura/window.h" #include "ui/aura/window_types.h" #include "ui/aura_shell/default_container_event_filter.h" +#include "ui/aura_shell/default_container_layout_manager.h" #include "ui/aura_shell/desktop_layout_manager.h" #include "ui/aura_shell/launcher/launcher.h" #include "ui/aura_shell/shell_delegate.h" @@ -127,6 +128,9 @@ void Shell::Init() { workspace_controller_.reset( new internal::WorkspaceController(toplevel_container)); + toplevel_container->SetLayoutManager( + new internal::DefaultContainerLayoutManager( + workspace_controller_->workspace_manager())); // Force a layout. desktop_layout->OnWindowResized(); diff --git a/ui/aura_shell/show_state_controller.cc b/ui/aura_shell/show_state_controller.cc index 39e8c71..06f904a 100644 --- a/ui/aura_shell/show_state_controller.cc +++ b/ui/aura_shell/show_state_controller.cc @@ -6,7 +6,6 @@ #include "ui/aura/aura_constants.h" #include "ui/aura/window.h" -#include "ui/aura_shell/default_container_layout_manager.h" #include "ui/aura_shell/property_util.h" #include "ui/aura_shell/workspace/workspace.h" #include "ui/aura_shell/workspace/workspace_manager.h" @@ -16,8 +15,8 @@ namespace aura_shell { namespace internal { ShowStateController::ShowStateController( - DefaultContainerLayoutManager* layout_manager) - : layout_manager_(layout_manager) { + WorkspaceManager* workspace_manager) + : workspace_manager_(workspace_manager) { } ShowStateController::~ShowStateController() { @@ -41,9 +40,7 @@ void ShowStateController::OnPropertyChanged(aura::Window* window, SetRestoreBounds(window, window->GetTargetBounds()); } - layout_manager_->set_ignore_calculate_bounds(true); - layout_manager_->workspace_manager()->FindBy(window)->Layout(NULL, window); - layout_manager_->set_ignore_calculate_bounds(false); + workspace_manager_->FindBy(window)->Layout(NULL, window); } } // namespace internal diff --git a/ui/aura_shell/show_state_controller.h b/ui/aura_shell/show_state_controller.h index cd5fbea..45b2855 100644 --- a/ui/aura_shell/show_state_controller.h +++ b/ui/aura_shell/show_state_controller.h @@ -17,13 +17,13 @@ class Window; namespace aura_shell { namespace internal { -class DefaultContainerLayoutManager; +class WorkspaceManager; // ShowStateController controls the window's bounds when // the window's show state property has changed. class ShowStateController : public aura::WindowObserver { public: - explicit ShowStateController(DefaultContainerLayoutManager* layout_manager); + explicit ShowStateController(WorkspaceManager* layout_manager); virtual ~ShowStateController(); // Invoked when window proparty has changed. @@ -32,8 +32,8 @@ public: void* old) OVERRIDE; private: - // LayoutManager that downs this ShowStateController. - DefaultContainerLayoutManager* layout_manager_; + // |workspace_maanger_| is owned by |WorkspaceController|. + WorkspaceManager* workspace_manager_; DISALLOW_COPY_AND_ASSIGN(ShowStateController); }; diff --git a/ui/aura_shell/workspace/workspace.cc b/ui/aura_shell/workspace/workspace.cc index cf762f3..7c9245b 100644 --- a/ui/aura_shell/workspace/workspace.cc +++ b/ui/aura_shell/workspace/workspace.cc @@ -180,6 +180,7 @@ void Workspace::Activate() { } void Workspace::Layout(aura::Window* ignore, aura::Window* no_animation) { + workspace_manager_->set_layout_in_progress(true); gfx::Rect work_area = workspace_manager_->GetWorkAreaBounds(bounds_); int total_width = GetTotalWindowsWidth(); if (total_width < work_area.width()) { @@ -210,6 +211,7 @@ void Workspace::Layout(aura::Window* ignore, aura::Window* no_animation) { no_animation != windows_[1]); } } + workspace_manager_->set_layout_in_progress(false); } bool Workspace::ContainsFullscreenWindow() const { diff --git a/ui/aura_shell/workspace/workspace_controller.cc b/ui/aura_shell/workspace/workspace_controller.cc index e17228b..2c2a48f 100644 --- a/ui/aura_shell/workspace/workspace_controller.cc +++ b/ui/aura_shell/workspace/workspace_controller.cc @@ -13,11 +13,8 @@ namespace aura_shell { namespace internal { -WorkspaceController::WorkspaceController(aura::Window* window) - : workspace_manager_(new WorkspaceManager(window)), - layout_manager_(new internal::DefaultContainerLayoutManager( - window, workspace_manager_.get())) { - window->SetLayoutManager(layout_manager_); +WorkspaceController::WorkspaceController(aura::Window* viewport) + : workspace_manager_(new WorkspaceManager(viewport)) { aura::Desktop::GetInstance()->AddObserver(this); } @@ -30,9 +27,7 @@ void WorkspaceController::ToggleOverview() { } void WorkspaceController::OnDesktopResized(const gfx::Size& new_size) { - layout_manager_->set_ignore_calculate_bounds(true); workspace_manager_->SetWorkspaceSize(new_size); - layout_manager_->set_ignore_calculate_bounds(false); } void WorkspaceController::OnActiveWindowChanged(aura::Window* active) { diff --git a/ui/aura_shell/workspace/workspace_controller.h b/ui/aura_shell/workspace/workspace_controller.h index d928f96..5e9ff86 100644 --- a/ui/aura_shell/workspace/workspace_controller.h +++ b/ui/aura_shell/workspace/workspace_controller.h @@ -28,13 +28,14 @@ class WorkspaceManager; // events From DesktopObserver translating them to WorkspaceManager. class AURA_SHELL_EXPORT WorkspaceController : public aura::DesktopObserver { public: - explicit WorkspaceController(aura::Window* window); + explicit WorkspaceController(aura::Window* workspace_viewport); virtual ~WorkspaceController(); void ToggleOverview(); - internal::DefaultContainerLayoutManager* layout_manager() { - return layout_manager_; + // Returns the workspace manager that this controler owns. + WorkspaceManager* workspace_manager() { + return workspace_manager_.get(); } // DesktopObserver overrides: @@ -44,9 +45,6 @@ class AURA_SHELL_EXPORT WorkspaceController : public aura::DesktopObserver { private: scoped_ptr<WorkspaceManager> workspace_manager_; - // This is owned by the window it's installed on. - internal::DefaultContainerLayoutManager* layout_manager_; - DISALLOW_COPY_AND_ASSIGN(WorkspaceController); }; diff --git a/ui/aura_shell/workspace/workspace_manager.cc b/ui/aura_shell/workspace/workspace_manager.cc index aa777a4..ba4f214 100644 --- a/ui/aura_shell/workspace/workspace_manager.cc +++ b/ui/aura_shell/workspace/workspace_manager.cc @@ -13,6 +13,7 @@ #include "ui/aura/screen_aura.h" #include "ui/aura/window.h" #include "ui/aura_shell/workspace/workspace.h" +#include "ui/aura_shell/workspace/workspace_observer.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/gfx/screen.h" @@ -146,22 +147,25 @@ void WorkspaceManager::RotateWindows(aura::Window* source, workspaces_[source_ws_index]->RotateWindows(source, target); } else { aura::Window* insert = source; + aura::Window* target_to_insert = target; if (source_ws_index < target_ws_index) { for (int i = target_ws_index; i >= source_ws_index; --i) { insert = workspaces_[i]->ShiftWindows( - insert, source, target, Workspace::SHIFT_TO_LEFT); + insert, source, target_to_insert, Workspace::SHIFT_TO_LEFT); // |target| can only be in the 1st workspace. - target = NULL; + target_to_insert = NULL; } } else { for (int i = target_ws_index; i <= source_ws_index; ++i) { insert = workspaces_[i]->ShiftWindows( - insert, source, target, Workspace::SHIFT_TO_RIGHT); + insert, source, target_to_insert, Workspace::SHIFT_TO_RIGHT); // |target| can only be in the 1st workspace. - target = NULL; + target_to_insert = NULL; } } } + FOR_EACH_OBSERVER(WorkspaceObserver, observers_, + WindowMoved(this, source, target)); } void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) { @@ -171,6 +175,14 @@ void WorkspaceManager::SetWorkspaceSize(const gfx::Size& workspace_size) { LayoutWorkspaces(); } +void WorkspaceManager::AddObserver(WorkspaceObserver* observer) { + observers_.AddObserver(observer); +} + +void WorkspaceManager::RemoveObserver(WorkspaceObserver* observer) { + observers_.RemoveObserver(observer); +} + //////////////////////////////////////////////////////////////////////////////// // WorkspaceManager, private: @@ -187,19 +199,32 @@ void WorkspaceManager::RemoveWorkspace(Workspace* workspace) { workspaces_.end(), workspace); DCHECK(i != workspaces_.end()); - if (workspace == active_workspace_) + Workspace* old = NULL; + + if (workspace == active_workspace_) { + old = active_workspace_; active_workspace_ = NULL; + } workspaces_.erase(i); LayoutWorkspaces(); + + if (old) { + FOR_EACH_OBSERVER(WorkspaceObserver, observers_, + ActiveWorkspaceChanged(this, old)); + } } void WorkspaceManager::SetActiveWorkspace(Workspace* workspace) { DCHECK(std::find(workspaces_.begin(), workspaces_.end(), workspace) != workspaces_.end()); + Workspace* old = active_workspace_; active_workspace_ = workspace; is_overview_ = false; UpdateViewport(); + + FOR_EACH_OBSERVER(WorkspaceObserver, observers_, + ActiveWorkspaceChanged(this, old)); } gfx::Rect WorkspaceManager::GetWorkAreaBounds( diff --git a/ui/aura_shell/workspace/workspace_manager.h b/ui/aura_shell/workspace/workspace_manager.h index 28cbab5..4bdb17b 100644 --- a/ui/aura_shell/workspace/workspace_manager.h +++ b/ui/aura_shell/workspace/workspace_manager.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/observer_list.h" #include "ui/aura_shell/aura_shell_export.h" #include "ui/gfx/insets.h" #include "ui/gfx/size.h" @@ -25,6 +26,7 @@ class Rect; namespace aura_shell { namespace internal { class Workspace; +class WorkspaceObserver; // WorkspaceManager manages multiple workspaces in the desktop. class AURA_SHELL_EXPORT WorkspaceManager { @@ -32,6 +34,10 @@ class AURA_SHELL_EXPORT WorkspaceManager { explicit WorkspaceManager(aura::Window* viewport); virtual ~WorkspaceManager(); + // Returns the viewport window this WorkspaceManager layouts + // workspaces on. + aura::Window* viewport() { return viewport_; } + // Create new workspace. Workspace objects are managed by // this WorkspaceManager. Deleting workspace will automatically // remove the workspace from the workspace_manager. @@ -62,6 +68,19 @@ class AURA_SHELL_EXPORT WorkspaceManager { // 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; + } + private: friend class Workspace; @@ -93,6 +112,11 @@ class AURA_SHELL_EXPORT WorkspaceManager { // 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_; + + ObserverList<WorkspaceObserver> observers_; + DISALLOW_COPY_AND_ASSIGN(WorkspaceManager); }; diff --git a/ui/aura_shell/workspace/workspace_manager_unittest.cc b/ui/aura_shell/workspace/workspace_manager_unittest.cc index 30f7237..052a0c54 100644 --- a/ui/aura_shell/workspace/workspace_manager_unittest.cc +++ b/ui/aura_shell/workspace/workspace_manager_unittest.cc @@ -10,10 +10,67 @@ #include "ui/aura/window.h" #include "ui/aura_shell/workspace/workspace.h" #include "ui/aura_shell/workspace/workspace_manager.h" +#include "ui/aura_shell/workspace/workspace_observer.h" #include "ui/base/ui_base_types.h" +namespace { +using aura_shell::internal::Workspace; +using aura_shell::internal::WorkspaceManager; using aura::Window; +class TestWorkspaceObserver : public aura_shell::internal::WorkspaceObserver { + public: + explicit TestWorkspaceObserver(WorkspaceManager* manager) + : manager_(manager), + move_source_(NULL), + move_target_(NULL), + active_workspace_(NULL), + old_active_workspace_(NULL) { + manager_->AddObserver(this); + } + + virtual ~TestWorkspaceObserver() { + manager_->RemoveObserver(this); + } + + Window* move_source() { return move_source_; } + Window* move_target() { return move_target_; } + Workspace* active_workspace() { return active_workspace_; } + Workspace* old_active_workspace() { return old_active_workspace_; } + + // Resets the observer states. + void reset() { + active_workspace_ = NULL; + old_active_workspace_ = NULL; + move_source_ = NULL; + move_target_ = NULL; + } + + // Overridden from WorkspaceObserver: + virtual void WindowMoved(WorkspaceManager* manager, + Window* source, + Window* target) { + move_source_ = source; + move_target_ = target; + } + virtual void ActiveWorkspaceChanged(WorkspaceManager* manager, + Workspace* old) { + old_active_workspace_ = old; + active_workspace_ = manager->GetActiveWorkspace(); + } + + private: + WorkspaceManager* manager_; + Window* move_source_; + Window* move_target_; + Workspace* active_workspace_; + Workspace* old_active_workspace_; + + DISALLOW_COPY_AND_ASSIGN(TestWorkspaceObserver); +}; + +} // namespace + namespace aura_shell { namespace internal { @@ -173,6 +230,7 @@ TEST_F(WorkspaceManagerTest, DISABLED_Overview) { } TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) { + TestWorkspaceObserver observer(manager_.get()); Workspace* ws1 = manager_->CreateWorkspace(); Workspace* ws2 = manager_->CreateWorkspace(); EXPECT_EQ(NULL, manager_->GetActiveWorkspace()); @@ -180,14 +238,22 @@ TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) { // Activate ws1. ws1->Activate(); EXPECT_EQ(ws1, manager_->GetActiveWorkspace()); + EXPECT_EQ(NULL, observer.old_active_workspace()); + EXPECT_EQ(ws1, observer.active_workspace()); + observer.reset(); // Activate ws2. ws2->Activate(); EXPECT_EQ(ws2, manager_->GetActiveWorkspace()); + EXPECT_EQ(ws1, observer.old_active_workspace()); + EXPECT_EQ(ws2, observer.active_workspace()); + observer.reset(); // Deleting active workspace sets active workspace to NULL. delete ws2; EXPECT_EQ(NULL, manager_->GetActiveWorkspace()); + EXPECT_EQ(ws2, observer.old_active_workspace()); + EXPECT_EQ(NULL, observer.active_workspace()); manager_.reset(); } @@ -250,6 +316,7 @@ TEST_F(WorkspaceManagerTest, FindRotateWindow) { } TEST_F(WorkspaceManagerTest, RotateWindows) { + TestWorkspaceObserver observer(manager_.get()); Workspace* ws1 = manager_->CreateWorkspace(); Workspace* ws2 = manager_->CreateWorkspace(); @@ -267,6 +334,8 @@ TEST_F(WorkspaceManagerTest, RotateWindows) { // Rotate right most to left most. manager_->RotateWindows(w22.get(), w11.get()); + EXPECT_EQ(w22.get(), observer.move_source()); + EXPECT_EQ(w11.get(), observer.move_target()); EXPECT_EQ(0, ws1->GetIndexOf(w22.get())); EXPECT_EQ(0, ws2->GetIndexOf(w11.get())); @@ -277,24 +346,32 @@ TEST_F(WorkspaceManagerTest, RotateWindows) { EXPECT_EQ(0, ws1->GetIndexOf(w11.get())); EXPECT_EQ(0, ws2->GetIndexOf(w21.get())); EXPECT_EQ(1, ws2->GetIndexOf(w22.get())); + EXPECT_EQ(w22.get(), observer.move_source()); + EXPECT_EQ(w21.get(), observer.move_target()); // Rotate left most to 1st element in 2nd workspace. manager_->RotateWindows(w11.get(), w21.get()); EXPECT_EQ(0, ws1->GetIndexOf(w21.get())); EXPECT_EQ(0, ws2->GetIndexOf(w11.get())); EXPECT_EQ(1, ws2->GetIndexOf(w22.get())); + EXPECT_EQ(w11.get(), observer.move_source()); + EXPECT_EQ(w21.get(), observer.move_target()); // Rotate middle to right most. manager_->RotateWindows(w11.get(), w22.get()); EXPECT_EQ(0, ws1->GetIndexOf(w21.get())); EXPECT_EQ(0, ws2->GetIndexOf(w22.get())); EXPECT_EQ(1, ws2->GetIndexOf(w11.get())); + EXPECT_EQ(w11.get(), observer.move_source()); + EXPECT_EQ(w22.get(), observer.move_target()); // Rotate middle to left most. manager_->RotateWindows(w22.get(), w21.get()); EXPECT_EQ(0, ws1->GetIndexOf(w22.get())); EXPECT_EQ(0, ws2->GetIndexOf(w21.get())); EXPECT_EQ(1, ws2->GetIndexOf(w11.get())); + EXPECT_EQ(w22.get(), observer.move_source()); + EXPECT_EQ(w21.get(), observer.move_target()); // Reset now before windows are destroyed. manager_.reset(); diff --git a/ui/aura_shell/workspace/workspace_observer.h b/ui/aura_shell/workspace/workspace_observer.h new file mode 100644 index 0000000..e0387bb --- /dev/null +++ b/ui/aura_shell/workspace/workspace_observer.h @@ -0,0 +1,40 @@ +// 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_OBSERVER_H_ +#define UI_AURA_SHELL_WORKSPACE_WORKSPACE_OBSERVER_H_ +#pragma once + +#include "ui/aura_shell/aura_shell_export.h" + +namespace aura { +class Window; +} + +namespace aura_shell { +namespace internal { +class Workspace; +class WorkspaceManager; + +// A class to observe changes in workspace state. +class AURA_SHELL_EXPORT WorkspaceObserver { + public: + // Invoked when |start| window is moved and inserted + // at the |target| window's position by |WorkspaceManager::RotateWindow|. + virtual void WindowMoved(WorkspaceManager* manager, + aura::Window* source, + aura::Window* target) = 0; + + // Invoked when the active workspace changes. |old| is + // the old active workspace and can be NULL. + virtual void ActiveWorkspaceChanged(WorkspaceManager* manager, + Workspace* old) = 0; + protected: + virtual ~WorkspaceObserver() {} +}; + +} // namespace internal +} // namespace aura_shell + +#endif // UI_AURA_SHELL_WORKSPACE_WORKSPACE_OBSERVER_H_ |