summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-31 07:10:59 +0000
committerflackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-31 07:10:59 +0000
commit66c5c4115cac0daefab5f0a29d18d400419af52c (patch)
tree485685bb836a5d93f647bd097bf11f6bfe1e2d71
parent2a52ec073d609dbdea90618d9e0eae73e7bf56bb (diff)
downloadchromium_src-66c5c4115cac0daefab5f0a29d18d400419af52c.zip
chromium_src-66c5c4115cac0daefab5f0a29d18d400419af52c.tar.gz
chromium_src-66c5c4115cac0daefab5f0a29d18d400419af52c.tar.bz2
Refactor most recently used window tracking into a separate class.
BUG=263477 TEST=None Review URL: https://chromiumcodereview.appspot.com/20708005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214609 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/focus_cycler.cc3
-rw-r--r--ash/shelf/shelf_layout_manager.cc4
-rw-r--r--ash/shell.cc7
-rw-r--r--ash/shell.h5
-rw-r--r--ash/wm/mru_window_tracker.cc226
-rw-r--r--ash/wm/mru_window_tracker.h88
-rw-r--r--ash/wm/window_cycle_controller.cc176
-rw-r--r--ash/wm/window_cycle_controller.h54
-rw-r--r--ash/wm/window_cycle_list.cc4
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_private_api.cc4
-rw-r--r--chrome/browser/ui/ash/window_positioner.cc4
-rw-r--r--chrome/browser/ui/window_sizer/window_sizer_ash.cc4
13 files changed, 347 insertions, 234 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index c0bcecb..56eb480 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -418,6 +418,8 @@
'wm/lock_state_observer.h',
'wm/maximize_bubble_controller.cc',
'wm/maximize_bubble_controller.h',
+ 'wm/mru_window_tracker.cc',
+ 'wm/mru_window_tracker.h',
'wm/overlay_event_filter.cc',
'wm/overlay_event_filter.h',
'wm/panels/panel_frame_view.cc',
diff --git a/ash/focus_cycler.cc b/ash/focus_cycler.cc
index 81611dc..c83db87 100644
--- a/ash/focus_cycler.cc
+++ b/ash/focus_cycler.cc
@@ -5,6 +5,7 @@
#include "ash/focus_cycler.h"
#include "ash/shell.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/activation_client.h"
@@ -18,7 +19,7 @@ namespace ash {
namespace {
bool HasFocusableWindow() {
- return !WindowCycleController::BuildWindowList(NULL, false).empty();
+ return !MruWindowTracker::BuildWindowList(false).empty();
}
} // namespace
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index 46fb536..17ef7e4 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -23,8 +23,8 @@
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
#include "ash/wm/gestures/shelf_gesture_handler.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/property_util.h"
-#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/workspace_animations.h"
@@ -940,7 +940,7 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
return SHELF_AUTO_HIDE_SHOWN;
const std::vector<aura::Window*> windows =
- ash::WindowCycleController::BuildWindowList(NULL, false);
+ ash::MruWindowTracker::BuildWindowList(false);
// Process the window list and check if there are any visible windows.
for (size_t i = 0; i < windows.size(); ++i) {
diff --git a/ash/shell.cc b/ash/shell.cc
index 0f641454..0fe57d5 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -51,6 +51,7 @@
#include "ash/wm/event_rewriter_event_filter.h"
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/lock_state_controller_impl2.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overlay_event_filter.h"
#include "ash/wm/power_button_controller.h"
#include "ash/wm/property_util.h"
@@ -310,6 +311,7 @@ Shell::~Shell() {
power_button_controller_.reset();
lock_state_controller_.reset();
+ mru_window_tracker_.reset();
// This also deletes all RootWindows. Note that we invoke Shutdown() on
// DisplayController before resetting |display_controller_|, since destruction
@@ -566,13 +568,14 @@ void Shell::Init() {
magnification_controller_.reset(
MagnificationController::CreateInstance());
+ mru_window_tracker_.reset(new MruWindowTracker(activation_client_));
partial_magnification_controller_.reset(
new PartialMagnificationController());
high_contrast_controller_.reset(new HighContrastController);
video_detector_.reset(new VideoDetector);
- window_cycle_controller_.reset(new WindowCycleController(activation_client_));
+ window_cycle_controller_.reset(new WindowCycleController());
tooltip_controller_.reset(new views::corewm::TooltipController(
gfx::SCREEN_TYPE_ALTERNATE));
@@ -931,7 +934,7 @@ void Shell::InitRootWindowController(
controller->Init(first_run_after_boot);
- window_cycle_controller_->OnRootWindowAdded(root_window);
+ mru_window_tracker_->OnRootWindowAdded(root_window);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ash/shell.h b/ash/shell.h
index 7f31c8d..7dd3595 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -80,6 +80,7 @@ class Launcher;
class LauncherDelegate;
class LauncherModel;
class MagnificationController;
+class MruWindowTracker;
class NestedDispatcherController;
class PartialMagnificationController;
class PowerButtonController;
@@ -311,6 +312,9 @@ class ASH_EXPORT Shell
LockStateController* lock_state_controller() {
return lock_state_controller_.get();
}
+ MruWindowTracker* mru_window_tracker() {
+ return mru_window_tracker_.get();
+ }
UserActivityDetector* user_activity_detector() {
return user_activity_detector_.get();
}
@@ -545,6 +549,7 @@ class ASH_EXPORT Shell
scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
scoped_ptr<PowerButtonController> power_button_controller_;
scoped_ptr<LockStateController> lock_state_controller_;
+ scoped_ptr<MruWindowTracker> mru_window_tracker_;
scoped_ptr<UserActivityDetector> user_activity_detector_;
scoped_ptr<VideoDetector> video_detector_;
scoped_ptr<WindowCycleController> window_cycle_controller_;
diff --git a/ash/wm/mru_window_tracker.cc b/ash/wm/mru_window_tracker.cc
new file mode 100644
index 0000000..d129c47
--- /dev/null
+++ b/ash/wm/mru_window_tracker.cc
@@ -0,0 +1,226 @@
+// Copyright 2013 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/mru_window_tracker.h"
+
+#include <algorithm>
+
+#include "ash/session_state_delegate.h"
+#include "ash/shell.h"
+#include "ash/shell_window_ids.h"
+#include "ash/wm/activation_controller.h"
+#include "ash/wm/window_cycle_list.h"
+#include "ash/wm/window_util.h"
+#include "ash/wm/workspace_controller.h"
+#include "ui/aura/root_window.h"
+#include "ui/base/events/event.h"
+#include "ui/base/events/event_handler.h"
+
+namespace ash {
+
+namespace {
+
+// List of containers whose children we will allow switching to.
+const int kContainerIds[] = {
+ internal::kShellWindowId_DefaultContainer,
+ internal::kShellWindowId_AlwaysOnTopContainer
+};
+
+// Adds all the children of |window| to |windows|.
+void AddAllChildren(aura::Window* window,
+ MruWindowTracker::WindowList* windows) {
+ const MruWindowTracker::WindowList& children(window->children());
+ windows->insert(windows->end(), children.begin(), children.end());
+}
+
+// Adds all the children of all of |window|s children to |windows|.
+void AddWorkspaceChildren(aura::Window* window,
+ MruWindowTracker::WindowList* windows) {
+ for (size_t i = 0; i < window->children().size(); ++i)
+ AddAllChildren(window->children()[i], windows);
+}
+
+// Adds the windows that can be cycled through for the specified window id to
+// |windows|.
+void AddTrackedWindows(aura::RootWindow* root,
+ int container_id,
+ MruWindowTracker::WindowList* windows) {
+ aura::Window* container = Shell::GetContainer(root, container_id);
+ if (container_id == internal::kShellWindowId_DefaultContainer)
+ AddWorkspaceChildren(container, windows);
+ else
+ AddAllChildren(container, windows);
+}
+
+// Returns a list of windows ordered by their stacking order.
+// If |mru_windows| is passed, these windows are moved to the front of the list.
+// If |top_most_at_end|, the list is returned in descending (bottom-most / least
+// recently used) order.
+MruWindowTracker::WindowList BuildWindowListInternal(
+ const std::list<aura::Window*>* mru_windows,
+ bool top_most_at_end) {
+ MruWindowTracker::WindowList windows;
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
+
+ aura::RootWindow* active_root = Shell::GetActiveRootWindow();
+ for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter) {
+ if (*iter == active_root)
+ continue;
+ for (size_t i = 0; i < arraysize(kContainerIds); ++i)
+ AddTrackedWindows(*iter, kContainerIds[i], &windows);
+ }
+
+ // Add windows in the active root windows last so that the topmost window
+ // in the active root window becomes the front of the list.
+ for (size_t i = 0; i < arraysize(kContainerIds); ++i)
+ AddTrackedWindows(active_root, kContainerIds[i], &windows);
+
+ // Removes unfocusable windows.
+ MruWindowTracker::WindowList::iterator last =
+ std::remove_if(
+ windows.begin(),
+ windows.end(),
+ std::not1(std::ptr_fun(ash::wm::CanActivateWindow)));
+ windows.erase(last, windows.end());
+
+ // Put the windows in the mru_windows list at the head, if it's available.
+ if (mru_windows) {
+ // Iterate through the list backwards, so that we can move each window to
+ // the front of the windows list as we find them.
+ for (std::list<aura::Window*>::const_reverse_iterator ix =
+ mru_windows->rbegin();
+ ix != mru_windows->rend(); ++ix) {
+ MruWindowTracker::WindowList::iterator window =
+ std::find(windows.begin(), windows.end(), *ix);
+ if (window != windows.end()) {
+ windows.erase(window);
+ windows.push_back(*ix);
+ }
+ }
+ }
+
+ // Window cycling expects the topmost window at the front of the list.
+ if (!top_most_at_end)
+ std::reverse(windows.begin(), windows.end());
+
+ return windows;
+}
+
+} // namespace
+
+//////////////////////////////////////////////////////////////////////////////
+// MruWindowTracker, public:
+
+MruWindowTracker::MruWindowTracker(
+ aura::client::ActivationClient* activation_client)
+ : activation_client_(activation_client),
+ ignore_window_activations_(false) {
+ activation_client_->AddObserver(this);
+}
+
+MruWindowTracker::~MruWindowTracker() {
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
+ for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter) {
+ for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
+ aura::Window* container = Shell::GetContainer(*iter, kContainerIds[i]);
+ if (container)
+ container->RemoveObserver(this);
+ }
+ aura::Window* default_container =
+ Shell::GetContainer(*iter, internal::kShellWindowId_DefaultContainer);
+ if (default_container) {
+ for (size_t i = 0; i < default_container->children().size(); ++i) {
+ aura::Window* workspace_window = default_container->children()[i];
+ DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer,
+ workspace_window->id());
+ workspace_window->RemoveObserver(this);
+ }
+ }
+ }
+
+ activation_client_->RemoveObserver(this);
+}
+
+// static
+MruWindowTracker::WindowList MruWindowTracker::BuildWindowList(
+ bool top_most_at_end) {
+ return BuildWindowListInternal(NULL, top_most_at_end);
+}
+
+MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() {
+ return BuildWindowListInternal(&mru_windows_, false);
+}
+
+void MruWindowTracker::OnRootWindowAdded(aura::RootWindow* root_window) {
+ for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
+ aura::Window* container =
+ Shell::GetContainer(root_window, kContainerIds[i]);
+ container->AddObserver(this);
+ }
+
+ aura::Window* default_container =
+ Shell::GetContainer(root_window,
+ internal::kShellWindowId_DefaultContainer);
+ for (size_t i = 0; i < default_container->children().size(); ++i) {
+ aura::Window* workspace_window = default_container->children()[i];
+ DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer,
+ workspace_window->id());
+ workspace_window->AddObserver(this);
+ }
+}
+
+void MruWindowTracker::SetIgnoreActivations(bool ignore) {
+ ignore_window_activations_ = ignore;
+
+ // If no longer ignoring window activations, move currently active window
+ // to front.
+ if (!ignore) {
+ aura::Window* active_window = wm::GetActiveWindow();
+ mru_windows_.remove(active_window);
+ mru_windows_.push_front(active_window);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// MruWindowTracker, private:
+
+// static
+bool MruWindowTracker::IsTrackedContainer(aura::Window* window) {
+ if (!window)
+ return false;
+ for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
+ if (window->id() == kContainerIds[i]) {
+ return true;
+ }
+ }
+ return window->id() == internal::kShellWindowId_WorkspaceContainer;
+}
+
+void MruWindowTracker::OnWindowActivated(aura::Window* gained_active,
+ aura::Window* lost_active) {
+ if (gained_active && !ignore_window_activations_ &&
+ IsTrackedContainer(gained_active->parent())) {
+ mru_windows_.remove(gained_active);
+ mru_windows_.push_front(gained_active);
+ }
+}
+
+void MruWindowTracker::OnWindowAdded(aura::Window* window) {
+ if (window->id() == internal::kShellWindowId_WorkspaceContainer)
+ window->AddObserver(this);
+}
+
+void MruWindowTracker::OnWillRemoveWindow(aura::Window* window) {
+ mru_windows_.remove(window);
+ if (window->id() == internal::kShellWindowId_WorkspaceContainer)
+ window->RemoveObserver(this);
+}
+
+void MruWindowTracker::OnWindowDestroying(aura::Window* window) {
+ window->RemoveObserver(this);
+}
+
+} // namespace ash
diff --git a/ash/wm/mru_window_tracker.h b/ash/wm/mru_window_tracker.h
new file mode 100644
index 0000000..fadfdb9
--- /dev/null
+++ b/ash/wm/mru_window_tracker.h
@@ -0,0 +1,88 @@
+// Copyright 2013 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_MRU_WINDOW_TRACKER_H_
+#define ASH_WM_MRU_WINDOW_TRACKER_H_
+
+#include <list>
+#include <vector>
+
+#include "ash/ash_export.h"
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/client/activation_change_observer.h"
+#include "ui/aura/window_observer.h"
+
+namespace aura {
+class RootWindow;
+class Window;
+namespace client {
+class ActivationClient;
+}
+}
+
+namespace ash {
+
+// Maintains a most recently used list of windows. This is used for window
+// cycling using Alt+Tab and overview mode.
+class ASH_EXPORT MruWindowTracker
+ : public aura::client::ActivationChangeObserver,
+ public aura::WindowObserver {
+ public:
+ typedef std::vector<aura::Window*> WindowList;
+
+ explicit MruWindowTracker(
+ aura::client::ActivationClient* activation_client);
+ virtual ~MruWindowTracker();
+
+ // Set up the observers to handle window changes for the containers we care
+ // about. Called when a new root window is added.
+ void OnRootWindowAdded(aura::RootWindow* root_window);
+
+ // Returns the set of windows which can be cycled through. This method creates
+ // the vector based on the current set of windows across all valid root
+ // windows. As a result it is not necessarily the same as the set of
+ // windows being iterated over.
+ // If |top_most_at_end| the window list will return in ascending (lowest
+ // window in stacking order first) order instead of the default descending
+ // (top most window first) order.
+ static WindowList BuildWindowList(bool top_most_at_end);
+
+ // Returns the set of windows which can be cycled through using the tracked
+ // list of most recently used windows.
+ WindowList BuildMruWindowList();
+
+ // Starts or stops ignoring window activations. If no longer ignoring
+ // activations the currently active window is moved to the front of the
+ // MRU window list. Used by WindowCycleList to avoid adding all cycled
+ // windows to the front of the MRU window list.
+ void SetIgnoreActivations(bool ignore);
+
+ private:
+ // Checks if the window represents a container whose children we track.
+ static bool IsTrackedContainer(aura::Window* window);
+
+ // Overridden from aura::client::ActivationChangeObserver:
+ virtual void OnWindowActivated(aura::Window* gained_active,
+ aura::Window* lost_active) OVERRIDE;
+
+ // Overridden from WindowObserver:
+ virtual void OnWindowAdded(aura::Window* window) OVERRIDE;
+ virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
+ virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
+
+ // List of windows that have been activated in containers that we cycle
+ // through, sorted by most recently used.
+ std::list<aura::Window*> mru_windows_;
+
+ aura::client::ActivationClient* activation_client_;
+
+ bool ignore_window_activations_;
+
+ DISALLOW_COPY_AND_ASSIGN(MruWindowTracker);
+};
+
+} // namespace ash
+
+#endif // ASH_WM_MRU_WINDOW_TRACKER_H_
diff --git a/ash/wm/window_cycle_controller.cc b/ash/wm/window_cycle_controller.cc
index 89af6c1..413d0da 100644
--- a/ash/wm/window_cycle_controller.cc
+++ b/ash/wm/window_cycle_controller.cc
@@ -9,7 +9,7 @@
#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
-#include "ash/wm/activation_controller.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_cycle_list.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.h"
@@ -21,12 +21,6 @@ namespace ash {
namespace {
-// List of containers whose children we will cycle through.
-const int kContainerIds[] = {
- internal::kShellWindowId_DefaultContainer,
- internal::kShellWindowId_AlwaysOnTopContainer
-};
-
// Filter to watch for the termination of a keyboard gesture to cycle through
// multiple windows.
class WindowCycleEventFilter : public ui::EventHandler {
@@ -56,65 +50,15 @@ void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) {
}
}
-// Adds all the children of |window| to |windows|.
-void AddAllChildren(aura::Window* window,
- WindowCycleList::WindowList* windows) {
- const WindowCycleList::WindowList& children(window->children());
- windows->insert(windows->end(), children.begin(), children.end());
-}
-
-// Adds all the children of all of |window|s children to |windows|.
-void AddWorkspaceChildren(aura::Window* window,
- WindowCycleList::WindowList* windows) {
- for (size_t i = 0; i < window->children().size(); ++i)
- AddAllChildren(window->children()[i], windows);
-}
-
-// Adds the windows that can be cycled through for the specified window id to
-// |windows|.
-void AddCycleWindows(aura::RootWindow* root,
- int container_id,
- WindowCycleList::WindowList* windows) {
- aura::Window* container = Shell::GetContainer(root, container_id);
- if (container_id == internal::kShellWindowId_DefaultContainer)
- AddWorkspaceChildren(container, windows);
- else
- AddAllChildren(container, windows);
-}
-
} // namespace
//////////////////////////////////////////////////////////////////////////////
// WindowCycleController, public:
-WindowCycleController::WindowCycleController(
- aura::client::ActivationClient* activation_client)
- : activation_client_(activation_client) {
- activation_client_->AddObserver(this);
+WindowCycleController::WindowCycleController() {
}
WindowCycleController::~WindowCycleController() {
- Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
- for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter) {
- for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
- aura::Window* container = Shell::GetContainer(*iter, kContainerIds[i]);
- if (container)
- container->RemoveObserver(this);
- }
- aura::Window* default_container =
- Shell::GetContainer(*iter, internal::kShellWindowId_DefaultContainer);
- if (default_container) {
- for (size_t i = 0; i < default_container->children().size(); ++i) {
- aura::Window* workspace_window = default_container->children()[i];
- DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer,
- workspace_window->id());
- workspace_window->RemoveObserver(this);
- }
- }
- }
-
- activation_client_->RemoveObserver(this);
StopCycling();
}
@@ -156,7 +100,7 @@ void WindowCycleController::HandleLinearCycleWindow() {
// Use the reversed list of windows to prevent a 2-cycle of the most recent
// windows occurring.
- WindowCycleList cycle_list(BuildWindowList(NULL,true));
+ WindowCycleList cycle_list(MruWindowTracker::BuildWindowList(true));
cycle_list.Step(WindowCycleList::FORWARD);
}
@@ -164,81 +108,12 @@ void WindowCycleController::AltKeyReleased() {
StopCycling();
}
-// static
-std::vector<aura::Window*> WindowCycleController::BuildWindowList(
- const std::list<aura::Window*>* mru_windows,
- bool top_most_at_end) {
- WindowCycleList::WindowList windows;
- Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
-
- aura::RootWindow* active_root = Shell::GetActiveRootWindow();
- for (Shell::RootWindowList::const_iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter) {
- if (*iter == active_root)
- continue;
- for (size_t i = 0; i < arraysize(kContainerIds); ++i)
- AddCycleWindows(*iter, kContainerIds[i], &windows);
- }
-
- // Add windows in the active root windows last so that the topmost window
- // in the active root window becomes the front of the list.
- for (size_t i = 0; i < arraysize(kContainerIds); ++i)
- AddCycleWindows(active_root, kContainerIds[i], &windows);
-
- // Removes unfocusable windows.
- WindowCycleList::WindowList::iterator last =
- std::remove_if(
- windows.begin(),
- windows.end(),
- std::not1(std::ptr_fun(ash::wm::CanActivateWindow)));
- windows.erase(last, windows.end());
-
- // Put the windows in the mru_windows list at the head, if it's available.
- if (mru_windows) {
- // Iterate through the list backwards, so that we can move each window to
- // the front of the windows list as we find them.
- for (std::list<aura::Window*>::const_reverse_iterator ix =
- mru_windows->rbegin();
- ix != mru_windows->rend(); ++ix) {
- WindowCycleList::WindowList::iterator window =
- std::find(windows.begin(), windows.end(), *ix);
- if (window != windows.end()) {
- windows.erase(window);
- windows.push_back(*ix);
- }
- }
- }
-
- // Window cycling expects the topmost window at the front of the list.
- if (!top_most_at_end)
- std::reverse(windows.begin(), windows.end());
-
- return windows;
-}
-
-void WindowCycleController::OnRootWindowAdded(aura::RootWindow* root_window) {
- for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
- aura::Window* container =
- Shell::GetContainer(root_window, kContainerIds[i]);
- container->AddObserver(this);
- }
-
- aura::Window* default_container =
- Shell::GetContainer(root_window,
- internal::kShellWindowId_DefaultContainer);
- for (size_t i = 0; i < default_container->children().size(); ++i) {
- aura::Window* workspace_window = default_container->children()[i];
- DCHECK_EQ(internal::kShellWindowId_WorkspaceContainer,
- workspace_window->id());
- workspace_window->AddObserver(this);
- }
-}
-
//////////////////////////////////////////////////////////////////////////////
// WindowCycleController, private:
void WindowCycleController::StartCycling() {
- windows_.reset(new WindowCycleList(BuildWindowList(&mru_windows_, false)));
+ windows_.reset(new WindowCycleList(ash::Shell::GetInstance()->
+ mru_window_tracker()->BuildMruWindowList()));
}
void WindowCycleController::Step(Direction direction) {
@@ -254,23 +129,6 @@ void WindowCycleController::StopCycling() {
Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get());
event_handler_.reset();
}
-
- // Add the currently focused window to the MRU list
- aura::Window* active_window = wm::GetActiveWindow();
- mru_windows_.remove(active_window);
- mru_windows_.push_front(active_window);
-}
-
-// static
-bool WindowCycleController::IsTrackedContainer(aura::Window* window) {
- if (!window)
- return false;
- for (size_t i = 0; i < arraysize(kContainerIds); ++i) {
- if (window->id() == kContainerIds[i]) {
- return true;
- }
- }
- return window->id() == internal::kShellWindowId_WorkspaceContainer;
}
void WindowCycleController::InstallEventFilter() {
@@ -278,28 +136,4 @@ void WindowCycleController::InstallEventFilter() {
Shell::GetInstance()->AddPreTargetHandler(event_handler_.get());
}
-void WindowCycleController::OnWindowActivated(aura::Window* gained_active,
- aura::Window* lost_active) {
- if (gained_active && !IsCycling() &&
- IsTrackedContainer(gained_active->parent())) {
- mru_windows_.remove(gained_active);
- mru_windows_.push_front(gained_active);
- }
-}
-
-void WindowCycleController::OnWindowAdded(aura::Window* window) {
- if (window->id() == internal::kShellWindowId_WorkspaceContainer)
- window->AddObserver(this);
-}
-
-void WindowCycleController::OnWillRemoveWindow(aura::Window* window) {
- mru_windows_.remove(window);
- if (window->id() == internal::kShellWindowId_WorkspaceContainer)
- window->RemoveObserver(this);
-}
-
-void WindowCycleController::OnWindowDestroying(aura::Window* window) {
- window->RemoveObserver(this);
-}
-
} // namespace ash
diff --git a/ash/wm/window_cycle_controller.h b/ash/wm/window_cycle_controller.h
index 9f5b8be..12822c0 100644
--- a/ash/wm/window_cycle_controller.h
+++ b/ash/wm/window_cycle_controller.h
@@ -5,22 +5,9 @@
#ifndef ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
#define ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
-#include <list>
-#include <vector>
-
#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/aura/client/activation_change_observer.h"
-#include "ui/aura/window_observer.h"
-
-namespace aura {
-class RootWindow;
-class Window;
-namespace client {
-class ActivationClient;
-}
-}
namespace ui {
class EventHandler;
@@ -37,16 +24,13 @@ class WindowCycleList;
// until the cycling ends. Thus we maintain the state of the windows
// at the beginning of the gesture so you can cycle through in a consistent
// order.
-class ASH_EXPORT WindowCycleController
- : public aura::client::ActivationChangeObserver,
- public aura::WindowObserver {
+class ASH_EXPORT WindowCycleController {
public:
enum Direction {
FORWARD,
BACKWARD
};
- explicit WindowCycleController(
- aura::client::ActivationClient* activation_client);
+ WindowCycleController();
virtual ~WindowCycleController();
// Returns true if cycling through windows is enabled. This is false at
@@ -72,22 +56,6 @@ class ASH_EXPORT WindowCycleController
// Returns the WindowCycleList. Really only useful for testing.
const WindowCycleList* windows() const { return windows_.get(); }
- // Set up the observers to handle window changes for the containers we care
- // about. Called when a new root window is added.
- void OnRootWindowAdded(aura::RootWindow* root_window);
-
- // Returns the set of windows to cycle through. This method creates
- // the vector based on the current set of windows across all valid root
- // windows. As a result it is not necessarily the same as the set of
- // windows being iterated over.
- // If |mru_windows| is not NULL, windows in this list are put at the head of
- // the window list.
- // If |top_most_at_end| the window list will return in ascending order instead
- // of the default descending.
- static std::vector<aura::Window*> BuildWindowList(
- const std::list<aura::Window*>* mru_windows,
- bool top_most_at_end);
-
private:
// Call to start cycling windows. You must call StopCycling() when done.
void StartCycling();
@@ -101,29 +69,11 @@ class ASH_EXPORT WindowCycleController
// Stops the current window cycle and cleans up the event filter.
void StopCycling();
- // Checks if the window represents a container whose children we track.
- static bool IsTrackedContainer(aura::Window* window);
-
- // Overridden from aura::client::ActivationChangeObserver:
- virtual void OnWindowActivated(aura::Window* gained_active,
- aura::Window* lost_active) OVERRIDE;
-
- // Overridden from WindowObserver:
- virtual void OnWindowAdded(aura::Window* window) OVERRIDE;
- virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
- virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
-
scoped_ptr<WindowCycleList> windows_;
// Event handler to watch for release of alt key.
scoped_ptr<ui::EventHandler> event_handler_;
- // List of windows that have been activated in containers that we cycle
- // through, sorted by most recently used.
- std::list<aura::Window*> mru_windows_;
-
- aura::client::ActivationClient* activation_client_;
-
DISALLOW_COPY_AND_ASSIGN(WindowCycleController);
};
diff --git a/ash/wm/window_cycle_list.cc b/ash/wm/window_cycle_list.cc
index fd39d0f..428804f 100644
--- a/ash/wm/window_cycle_list.cc
+++ b/ash/wm/window_cycle_list.cc
@@ -4,6 +4,8 @@
#include "ash/wm/window_cycle_list.h"
+#include "ash/shell.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
#include "ui/views/corewm/window_animations.h"
@@ -13,6 +15,7 @@ namespace ash {
WindowCycleList::WindowCycleList(const WindowList& windows)
: windows_(windows),
current_index_(-1) {
+ ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
// Locate the currently active window in the list to use as our start point.
aura::Window* active_window = wm::GetActiveWindow();
@@ -27,6 +30,7 @@ WindowCycleList::WindowCycleList(const WindowList& windows)
}
WindowCycleList::~WindowCycleList() {
+ ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
for (WindowList::const_iterator i = windows_.begin(); i != windows_.end();
++i) {
(*i)->RemoveObserver(this);
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
index 1d79a69..5fc5876 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
@@ -7,7 +7,7 @@
#include <vector>
#include "ash/shell.h"
-#include "ash/wm/window_cycle_controller.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_util.h"
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
@@ -141,7 +141,7 @@ class WindowStateManager : public aura::WindowObserver {
}
void BuildWindowListAndMinimizeInactive(aura::Window* active_window) {
- windows_ = ash::WindowCycleController::BuildWindowList(NULL, false);
+ windows_ = ash::MruWindowTracker::BuildWindowList(false);
// Remove active window.
std::vector<aura::Window*>::iterator last =
std::remove(windows_.begin(), windows_.end(), active_window);
diff --git a/chrome/browser/ui/ash/window_positioner.cc b/chrome/browser/ui/ash/window_positioner.cc
index 04fa3f29..41ad8dd 100644
--- a/chrome/browser/ui/ash/window_positioner.cc
+++ b/chrome/browser/ui/ash/window_positioner.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/ui/ash/window_positioner.h"
#include "ash/shell.h"
-#include "ash/wm/window_cycle_controller.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
@@ -100,7 +100,7 @@ gfx::Rect WindowPositioner::SmartPopupPosition(
const gfx::Rect& work_area,
int grid) {
const std::vector<aura::Window*> windows =
- ash::WindowCycleController::BuildWindowList(NULL, false);
+ ash::MruWindowTracker::BuildWindowList(false);
std::vector<const gfx::Rect*> regions;
// Process the window list and check if we can bail immediately.
diff --git a/chrome/browser/ui/window_sizer/window_sizer_ash.cc b/chrome/browser/ui/window_sizer/window_sizer_ash.cc
index 254d047..4537423 100644
--- a/chrome/browser/ui/window_sizer/window_sizer_ash.cc
+++ b/chrome/browser/ui/window_sizer/window_sizer_ash.cc
@@ -6,7 +6,7 @@
#include "ash/ash_switches.h"
#include "ash/shell.h"
-#include "ash/wm/window_cycle_controller.h"
+#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
@@ -72,7 +72,7 @@ aura::Window* GetTopWindow(const gfx::Rect& bounds_in_screen) {
// Get a list of all windows.
const std::vector<aura::Window*> windows =
- ash::WindowCycleController::BuildWindowList(NULL, false);
+ ash::MruWindowTracker::BuildWindowList(false);
if (windows.empty())
return NULL;