Index: ash/wm/overview/window_selector.cc |
diff --git a/ash/wm/overview/window_selector.cc b/ash/wm/overview/window_selector.cc |
index 840c4eeb7a9ddd2b2fb3eb925915d8a3589d10f7..e6a0b20f00d566d3c084c682d60b104e5d4867de 100644 |
--- a/ash/wm/overview/window_selector.cc |
+++ b/ash/wm/overview/window_selector.cc |
@@ -21,10 +21,7 @@ |
#include "base/strings/string_number_conversions.h" |
#include "ui/aura/client/focus_client.h" |
#include "ui/aura/window.h" |
-#include "ui/aura/window_event_dispatcher.h" |
#include "ui/aura/window_observer.h" |
-#include "ui/events/event.h" |
-#include "ui/events/event_handler.h" |
#include "ui/wm/core/window_util.h" |
#include "ui/wm/public/activation_client.h" |
@@ -74,42 +71,6 @@ struct WindowSelectorItemForRoot |
const aura::Window* root_window; |
}; |
-// Filter to watch for the termination of a keyboard gesture to cycle through |
-// multiple windows. |
-class WindowSelectorEventFilter : public ui::EventHandler { |
- public: |
- WindowSelectorEventFilter(WindowSelector* selector); |
- virtual ~WindowSelectorEventFilter(); |
- |
- // Overridden from ui::EventHandler: |
- virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
- |
- private: |
- // A weak pointer to the WindowSelector which owns this instance. |
- WindowSelector* selector_; |
- |
- DISALLOW_COPY_AND_ASSIGN(WindowSelectorEventFilter); |
-}; |
- |
-// Watch for all keyboard events by filtering the root window. |
-WindowSelectorEventFilter::WindowSelectorEventFilter(WindowSelector* selector) |
- : selector_(selector) { |
- Shell::GetInstance()->AddPreTargetHandler(this); |
-} |
- |
-WindowSelectorEventFilter::~WindowSelectorEventFilter() { |
- Shell::GetInstance()->RemovePreTargetHandler(this); |
-} |
- |
-void WindowSelectorEventFilter::OnKeyEvent(ui::KeyEvent* event) { |
- // Views uses VKEY_MENU for both left and right Alt keys. |
- if (event->key_code() == ui::VKEY_MENU && |
- event->type() == ui::ET_KEY_RELEASED) { |
- selector_->SelectWindow(); |
- // Warning: |this| will be deleted from here on. |
- } |
-} |
- |
// Triggers a shelf visibility update on all root window controllers. |
void UpdateShelfVisibility() { |
Shell::RootWindowControllerList root_window_controllers = |
@@ -121,109 +82,11 @@ void UpdateShelfVisibility() { |
} |
} |
-// Returns the window immediately below |window| in the current container. |
-aura::Window* GetWindowBelow(aura::Window* window) { |
- aura::Window* parent = window->parent(); |
- if (!parent) |
- return NULL; |
- aura::Window* below = NULL; |
- for (aura::Window::Windows::const_iterator iter = parent->children().begin(); |
- iter != parent->children().end(); ++iter) { |
- if (*iter == window) |
- return below; |
- below = *iter; |
- } |
- NOTREACHED(); |
- return NULL; |
-} |
- |
} // namespace |
-// This class restores and moves a window to the front of the stacking order for |
-// the duration of the class's scope. |
-class ScopedShowWindow : public aura::WindowObserver { |
- public: |
- ScopedShowWindow(); |
- virtual ~ScopedShowWindow(); |
- |
- // Show |window| at the top of the stacking order. |
- void Show(aura::Window* window); |
- |
- // Cancel restoring the window on going out of scope. |
- void CancelRestore(); |
- |
- aura::Window* window() { return window_; } |
- |
- // aura::WindowObserver: |
- virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE; |
- |
- private: |
- // The window being shown. |
- aura::Window* window_; |
- |
- // The window immediately below where window_ belongs. |
- aura::Window* stack_window_above_; |
- |
- // If true, minimize window_ on going out of scope. |
- bool minimized_; |
- |
- DISALLOW_COPY_AND_ASSIGN(ScopedShowWindow); |
-}; |
- |
-ScopedShowWindow::ScopedShowWindow() |
- : window_(NULL), |
- stack_window_above_(NULL), |
- minimized_(false) { |
-} |
- |
-void ScopedShowWindow::Show(aura::Window* window) { |
- DCHECK(!window_); |
- window_ = window; |
- stack_window_above_ = GetWindowBelow(window); |
- minimized_ = wm::GetWindowState(window)->IsMinimized(); |
- window_->parent()->AddObserver(this); |
- window_->Show(); |
- wm::GetWindowState(window_)->Activate(); |
-} |
- |
-ScopedShowWindow::~ScopedShowWindow() { |
- if (window_) { |
- window_->parent()->RemoveObserver(this); |
- |
- // Restore window's stacking position. |
- if (stack_window_above_) |
- window_->parent()->StackChildAbove(window_, stack_window_above_); |
- else |
- window_->parent()->StackChildAtBottom(window_); |
- |
- // Restore minimized state. |
- if (minimized_) |
- wm::GetWindowState(window_)->Minimize(); |
- } |
-} |
- |
-void ScopedShowWindow::CancelRestore() { |
- if (!window_) |
- return; |
- window_->parent()->RemoveObserver(this); |
- window_ = stack_window_above_ = NULL; |
-} |
- |
-void ScopedShowWindow::OnWillRemoveWindow(aura::Window* window) { |
- if (window == window_) { |
- CancelRestore(); |
- } else if (window == stack_window_above_) { |
- // If the window this window was above is removed, use the next window down |
- // as the restore marker. |
- stack_window_above_ = GetWindowBelow(stack_window_above_); |
- } |
-} |
- |
WindowSelector::WindowSelector(const WindowList& windows, |
- WindowSelector::Mode mode, |
WindowSelectorDelegate* delegate) |
- : mode_(mode), |
- delegate_(delegate), |
+ : delegate_(delegate), |
selected_window_(0), |
restore_focus_window_(aura::client::GetFocusClient( |
Shell::GetPrimaryRootWindow())->GetFocusedWindow()), |
@@ -280,12 +143,7 @@ WindowSelector::WindowSelector(const WindowList& windows, |
} |
} |
- if (mode == WindowSelector::CYCLE) { |
- cycle_start_time_ = base::Time::Now(); |
- event_handler_.reset(new WindowSelectorEventFilter(this)); |
- } else { |
- StartOverview(); |
- } |
+ StartOverview(); |
} |
WindowSelector::~WindowSelector() { |
@@ -307,38 +165,12 @@ WindowSelector::~WindowSelector() { |
} |
} |
-void WindowSelector::Step(WindowSelector::Direction direction) { |
- DCHECK(!windows_.empty()); |
- // Upgrade to CYCLE mode if currently in OVERVIEW mode. |
- if (mode_ != CYCLE) { |
- event_handler_.reset(new WindowSelectorEventFilter(this)); |
- DCHECK(window_overview_); |
- // Set the initial selection window to animate to the new selection. |
- window_overview_->SetSelection(selected_window_); |
- window_overview_->MoveToSingleRootWindow( |
- windows_[selected_window_]->GetRootWindow()); |
- mode_ = CYCLE; |
- } |
- |
- selected_window_ = (selected_window_ + windows_.size() + |
- (direction == WindowSelector::FORWARD ? 1 : -1)) % windows_.size(); |
- if (window_overview_) { |
- window_overview_->SetSelection(selected_window_); |
- } else { |
- base::AutoReset<bool> restoring_focus(&ignore_activations_, true); |
- showing_window_.reset(new ScopedShowWindow); |
- showing_window_->Show(windows_[selected_window_]->SelectionWindow()); |
- } |
-} |
- |
void WindowSelector::SelectWindow() { |
SelectWindow(windows_[selected_window_]->SelectionWindow()); |
} |
void WindowSelector::SelectWindow(aura::Window* window) { |
ResetFocusRestoreWindow(false); |
- if (showing_window_ && showing_window_->window() == window) |
- showing_window_->CancelRestore(); |
ScopedVector<WindowSelectorItem>::iterator iter = |
std::find_if(windows_.begin(), windows_.end(), |
WindowSelectorItemTargetComparator(window)); |
@@ -388,7 +220,6 @@ void WindowSelector::OnWindowDestroying(aura::Window* window) { |
if (!(*iter)->empty()) |
return; |
- size_t deleted_index = iter - windows_.begin(); |
windows_.erase(iter); |
if (windows_.empty()) { |
CancelSelection(); |
@@ -396,13 +227,6 @@ void WindowSelector::OnWindowDestroying(aura::Window* window) { |
} |
if (window_overview_) |
window_overview_->OnWindowsChanged(); |
- if (mode_ == CYCLE && selected_window_ >= deleted_index) { |
- if (selected_window_ > deleted_index) |
- selected_window_--; |
- selected_window_ = selected_window_ % windows_.size(); |
- if (window_overview_) |
- window_overview_->SetSelection(selected_window_); |
- } |
} |
void WindowSelector::OnWindowBoundsChanged(aura::Window* window, |
@@ -449,12 +273,7 @@ void WindowSelector::StartOverview() { |
aura::client::GetFocusClient( |
Shell::GetPrimaryRootWindow())->FocusWindow(NULL); |
- aura::Window* overview_root = NULL; |
- if (mode_ == CYCLE) |
- overview_root = windows_[selected_window_]->GetRootWindow(); |
- window_overview_.reset(new WindowOverview(this, &windows_, overview_root)); |
- if (mode_ == CYCLE) |
- window_overview_->SetSelection(selected_window_); |
+ window_overview_.reset(new WindowOverview(this, &windows_)); |
UpdateShelfVisibility(); |
} |