diff options
author | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-20 04:17:33 +0000 |
---|---|---|
committer | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-20 04:17:33 +0000 |
commit | 5bf76f0e4a43c36e066883ead23a79c9059fdc80 (patch) | |
tree | 0acc912c237d9464a052bc39f19af2b6ad4cbb99 /ash | |
parent | 58952d86e4f2a8b692c1df8b421df5b640c6d743 (diff) | |
download | chromium_src-5bf76f0e4a43c36e066883ead23a79c9059fdc80.zip chromium_src-5bf76f0e4a43c36e066883ead23a79c9059fdc80.tar.gz chromium_src-5bf76f0e4a43c36e066883ead23a79c9059fdc80.tar.bz2 |
Observe the windows in the mru window list rather than all containers.
BUG=291354
Review URL: https://chromiumcodereview.appspot.com/23523063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/shell.cc | 2 | ||||
-rw-r--r-- | ash/wm/mru_window_tracker.cc | 82 | ||||
-rw-r--r-- | ash/wm/mru_window_tracker.h | 10 |
3 files changed, 45 insertions, 49 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index 7777227..3606c5d 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -929,8 +929,6 @@ void Shell::InitRootWindowController( aura::client::SetUserActionClient(root_window, user_action_client_.get()); controller->Init(first_run_after_boot); - - mru_window_tracker_->OnRootWindowAdded(root_window); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ash/wm/mru_window_tracker.cc b/ash/wm/mru_window_tracker.cc index 8b31c17..f2ab29a 100644 --- a/ash/wm/mru_window_tracker.cc +++ b/ash/wm/mru_window_tracker.cc @@ -31,6 +31,17 @@ void AddTrackedWindows(aura::RootWindow* root, windows->insert(windows->end(), children.begin(), children.end()); } +// Returns true if |window| is a container whose windows can be cycled to. +bool IsSwitchableContainer(aura::Window* window) { + if (!window) + return false; + for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { + if (window->id() == kSwitchableWindowContainerIds[i]) + return true; + } + return false; +} + // 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 @@ -70,6 +81,13 @@ MruWindowTracker::WindowList BuildWindowListInternal( for (std::list<aura::Window*>::const_reverse_iterator ix = mru_windows->rbegin(); ix != mru_windows->rend(); ++ix) { + // Exclude windows in non-switchable containers and those which cannot + // be activated. + if (!IsSwitchableContainer((*ix)->parent()) || + !ash::wm::CanActivateWindow(*ix)) { + continue; + } + MruWindowTracker::WindowList::iterator window = std::find(windows.begin(), windows.end(), *ix); if (window != windows.end()) { @@ -108,15 +126,9 @@ MruWindowTracker::MruWindowTracker( } 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 < kSwitchableWindowContainerIdsLength; ++i) { - aura::Window* container = Shell::GetContainer(*iter, - kSwitchableWindowContainerIds[i]); - if (container) - container->RemoveObserver(this); - } + for (std::list<aura::Window*>::iterator iter = mru_windows_.begin(); + iter != mru_windows_.end(); ++iter) { + (*iter)->RemoveObserver(this); } activation_client_->RemoveObserver(this); @@ -132,54 +144,44 @@ MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() { return BuildWindowListInternal(&mru_windows_, false); } -void MruWindowTracker::OnRootWindowAdded(aura::RootWindow* root_window) { - for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { - aura::Window* container = - Shell::GetContainer(root_window, kSwitchableWindowContainerIds[i]); - container->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); - } + if (!ignore) + SetActiveWindow(wm::GetActiveWindow()); } ////////////////////////////////////////////////////////////////////////////// // MruWindowTracker, private: -// static -bool MruWindowTracker::IsTrackedContainer(aura::Window* window) { - if (!window) - return false; - for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { - if (window->id() == kSwitchableWindowContainerIds[i]) - return true; - } - return false; +void MruWindowTracker::SetActiveWindow(aura::Window* active_window) { + if (!active_window) + return; + + std::list<aura::Window*>::iterator iter = + std::find(mru_windows_.begin(), mru_windows_.end(), active_window); + // Observe all newly tracked windows. + if (iter == mru_windows_.end()) + active_window->AddObserver(this); + else + mru_windows_.erase(iter); + // TODO(flackr): Remove this check if this doesn't fire for a while. This + // should verify that all tracked windows start with a layer, see + // http://crbug.com/291354. + CHECK(active_window->layer()); + mru_windows_.push_front(active_window); } 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::OnWillRemoveWindow(aura::Window* window) { - mru_windows_.remove(window); + if (!ignore_window_activations_) + SetActiveWindow(gained_active); } void MruWindowTracker::OnWindowDestroying(aura::Window* window) { + mru_windows_.remove(window); window->RemoveObserver(this); } diff --git a/ash/wm/mru_window_tracker.h b/ash/wm/mru_window_tracker.h index fb84496..1569a98 100644 --- a/ash/wm/mru_window_tracker.h +++ b/ash/wm/mru_window_tracker.h @@ -42,10 +42,6 @@ class ASH_EXPORT 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 @@ -66,15 +62,15 @@ class ASH_EXPORT MruWindowTracker void SetIgnoreActivations(bool ignore); private: - // Checks if the window represents a container whose children we track. - static bool IsTrackedContainer(aura::Window* window); + // Updates the mru_windows_ list to insert/move |active_window| at/to the + // front. + void SetActiveWindow(aura::Window* active_window); // Overridden from aura::client::ActivationChangeObserver: virtual void OnWindowActivated(aura::Window* gained_active, aura::Window* lost_active) OVERRIDE; // Overridden from WindowObserver: - 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 |