diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 18:22:51 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 18:22:51 +0000 |
commit | 194ad1dd149ad2a577cd1a41ccfdd4a1fb7cd656 (patch) | |
tree | 8b71cea824e13b6fca3734642fdf83e56c7d47f7 /ash/wm/window_cycle_controller.cc | |
parent | 783eb300ba843d498bfb55076d81d45e77bb6fff (diff) | |
download | chromium_src-194ad1dd149ad2a577cd1a41ccfdd4a1fb7cd656.zip chromium_src-194ad1dd149ad2a577cd1a41ccfdd4a1fb7cd656.tar.gz chromium_src-194ad1dd149ad2a577cd1a41ccfdd4a1fb7cd656.tar.bz2 |
Tweaks for the launcher:
. App list and browser shortcut buttons can be moved around.
. Clicking the tabbed button cycles windows (creating a new one if
there isn't one).
BUG=110094
TEST=see bug
R=ben@chromium.org,jamescook@chromium.org
Review URL: http://codereview.chromium.org/9231030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/window_cycle_controller.cc')
-rw-r--r-- | ash/wm/window_cycle_controller.cc | 69 |
1 files changed, 21 insertions, 48 deletions
diff --git a/ash/wm/window_cycle_controller.cc b/ash/wm/window_cycle_controller.cc index 529ff27..f94cace 100644 --- a/ash/wm/window_cycle_controller.cc +++ b/ash/wm/window_cycle_controller.cc @@ -6,6 +6,7 @@ #include "ash/shell.h" #include "ash/shell_delegate.h" +#include "ash/wm/window_cycle_list.h" #include "ash/wm/window_util.h" #include "ui/aura/event.h" #include "ui/aura/event_filter.h" @@ -75,21 +76,26 @@ ui::GestureStatus WindowCycleEventFilter::PreHandleGestureEvent( ////////////////////////////////////////////////////////////////////////////// // WindowCycleController, public: -WindowCycleController::WindowCycleController() : current_index_(-1) { +WindowCycleController::WindowCycleController() { } WindowCycleController::~WindowCycleController() { StopCycling(); } +// static +bool WindowCycleController::CanCycle() { + // Don't allow window cycling if the screen is locked or a modal dialog is + // open. + return !Shell::GetInstance()->IsScreenLocked() && + !Shell::GetInstance()->IsModalWindowOpen(); +} + void WindowCycleController::HandleCycleWindow(Direction direction, bool is_alt_down) { - // Don't allow window cycling if the screen is locked. - if (Shell::GetInstance()->IsScreenLocked()) - return; - // Don't cycle away from modal dialogs. - if (Shell::GetInstance()->IsModalWindowOpen()) + if (!CanCycle()) return; + if (is_alt_down) { if (!IsCycling()) { // This is the start of an alt-tab cycle through multiple windows, so @@ -119,46 +125,21 @@ void WindowCycleController::AltKeyReleased() { void WindowCycleController::StartCycling() { // Most-recently-used cycling is confusing in compact window mode because // you can't see all the windows. - windows_ = ash::Shell::GetInstance()->delegate()->GetCycleWindowList( - Shell::GetInstance()->IsWindowModeCompact() ? - ShellDelegate::ORDER_LINEAR : - ShellDelegate::ORDER_MRU); - - // Locate the currently active window in the list to use as our start point. - aura::Window* active_window = GetActiveWindow(); - if (!active_window) { - DLOG(ERROR) << "No active window"; - return; - } - // The active window may not be in the cycle list, which is expected if there - // are additional modal windows on the screen. Our index will be -1 and we - // won't step through the windows below. - current_index_ = GetWindowIndex(active_window); + windows_.reset(new WindowCycleList( + ash::Shell::GetInstance()->delegate()->GetCycleWindowList( + ShellDelegate::SOURCE_KEYBOARD, + Shell::GetInstance()->IsWindowModeCompact() ? + ShellDelegate::ORDER_LINEAR : ShellDelegate::ORDER_MRU))); } void WindowCycleController::Step(Direction direction) { - // Ensure we have at least one window to step to. - if (windows_.empty()) { - DLOG(ERROR) << "No windows in cycle list"; - return; - } - if (current_index_ == -1) { - // We weren't able to find our active window in the shell delegate's - // provided window list. Just switch to the first (or last) one. - current_index_ = (direction == FORWARD ? 0 : windows_.size() - 1); - } else { - // We're in a valid cycle, so step forward or backward. - current_index_ += (direction == FORWARD ? 1 : -1); - } - // Wrap to window list size. - current_index_ = (current_index_ + windows_.size()) % windows_.size(); - DCHECK(windows_[current_index_]); - ActivateWindow(windows_[current_index_]); + DCHECK(windows_.get()); + windows_->Step(direction == FORWARD ? WindowCycleList::FORWARD : + WindowCycleList::BACKWARD); } void WindowCycleController::StopCycling() { - windows_.clear(); - current_index_ = -1; + windows_.reset(); // Remove our key event filter. if (event_filter_.get()) { Shell::GetInstance()->RemoveRootWindowEventFilter(event_filter_.get()); @@ -171,12 +152,4 @@ void WindowCycleController::InstallEventFilter() { Shell::GetInstance()->AddRootWindowEventFilter(event_filter_.get()); } -int WindowCycleController::GetWindowIndex(aura::Window* window) { - WindowList::const_iterator it = - std::find(windows_.begin(), windows_.end(), window); - if (it == windows_.end()) - return -1; // Not found. - return it - windows_.begin(); -} - } // namespace ash |