Index: ash/wm/overview/window_selector.cc |
diff --git a/ash/wm/overview/window_selector.cc b/ash/wm/overview/window_selector.cc |
index cb66caa45d44d2dd744d19d9d548d8ad3a35114e..68b88b9a6d306a4de9279a63b9b1aa7e96043140 100644 |
--- a/ash/wm/overview/window_selector.cc |
+++ b/ash/wm/overview/window_selector.cc |
@@ -10,11 +10,11 @@ |
#include "ash/ash_switches.h" |
#include "ash/metrics/user_metrics_recorder.h" |
#include "ash/root_window_controller.h" |
-#include "ash/screen_util.h" |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
#include "ash/switchable_windows.h" |
#include "ash/wm/overview/scoped_transform_overview_window.h" |
+#include "ash/wm/overview/window_grid.h" |
#include "ash/wm/overview/window_selector_delegate.h" |
#include "ash/wm/overview/window_selector_item.h" |
#include "ash/wm/overview/window_selector_panels.h" |
@@ -29,7 +29,6 @@ |
#include "ui/aura/window.h" |
#include "ui/aura/window_event_dispatcher.h" |
#include "ui/aura/window_observer.h" |
-#include "ui/compositor/layer_animation_observer.h" |
#include "ui/compositor/scoped_layer_animation_settings.h" |
#include "ui/events/event.h" |
#include "ui/gfx/screen.h" |
@@ -42,16 +41,21 @@ namespace ash { |
namespace { |
-// Conceptually the window overview is a table or grid of cells having this |
-// fixed aspect ratio. The number of columns is determined by maximizing the |
-// area of them based on the number of windows. |
-const float kCardAspectRatio = 4.0f / 3.0f; |
+// A comparator for locating a grid with a given root window. |
+struct RootWindowGridComparator |
+ : public std::unary_function<WindowGrid*, bool> { |
+ explicit RootWindowGridComparator(const aura::Window* root_window) |
+ : root_window_(root_window) { |
+ } |
+ |
+ bool operator()(WindowGrid* grid) const { |
+ return (grid->root_window() == root_window_); |
+ } |
-// The minimum number of cards along the major axis (i.e. horizontally on a |
-// landscape orientation). |
-const int kMinCardsMajor = 3; |
+ const aura::Window* root_window_; |
+}; |
-// A comparator for locating a given target window. |
+// A comparator for locating a WindowSelectorItem that contains a given target. |
flackr
2014/06/03 17:12:07
Why would using WindowSelectorItemTargetComparator
Nina
2014/06/04 20:21:13
Yes, this is more reasonable. We still use this co
|
struct WindowSelectorItemComparator |
: public std::unary_function<WindowSelectorItem*, bool> { |
explicit WindowSelectorItemComparator(const aura::Window* target_window) |
@@ -65,53 +69,6 @@ struct WindowSelectorItemComparator |
const aura::Window* target; |
}; |
-// An observer which holds onto the passed widget until the animation is |
-// complete. |
-class CleanupWidgetAfterAnimationObserver : public ui::LayerAnimationObserver { |
- public: |
- explicit CleanupWidgetAfterAnimationObserver( |
- scoped_ptr<views::Widget> widget); |
- |
- // ui::LayerAnimationObserver: |
- virtual void OnLayerAnimationEnded( |
- ui::LayerAnimationSequence* sequence) OVERRIDE; |
- virtual void OnLayerAnimationAborted( |
- ui::LayerAnimationSequence* sequence) OVERRIDE; |
- virtual void OnLayerAnimationScheduled( |
- ui::LayerAnimationSequence* sequence) OVERRIDE; |
- |
- private: |
- virtual ~CleanupWidgetAfterAnimationObserver(); |
- |
- scoped_ptr<views::Widget> widget_; |
- |
- DISALLOW_COPY_AND_ASSIGN(CleanupWidgetAfterAnimationObserver); |
-}; |
- |
-CleanupWidgetAfterAnimationObserver::CleanupWidgetAfterAnimationObserver( |
- scoped_ptr<views::Widget> widget) |
- : widget_(widget.Pass()) { |
- widget_->GetNativeWindow()->layer()->GetAnimator()->AddObserver(this); |
-} |
- |
-CleanupWidgetAfterAnimationObserver::~CleanupWidgetAfterAnimationObserver() { |
- widget_->GetNativeWindow()->layer()->GetAnimator()->RemoveObserver(this); |
-} |
- |
-void CleanupWidgetAfterAnimationObserver::OnLayerAnimationEnded( |
- ui::LayerAnimationSequence* sequence) { |
- delete this; |
-} |
- |
-void CleanupWidgetAfterAnimationObserver::OnLayerAnimationAborted( |
- ui::LayerAnimationSequence* sequence) { |
- delete this; |
-} |
- |
-void CleanupWidgetAfterAnimationObserver::OnLayerAnimationScheduled( |
- ui::LayerAnimationSequence* sequence) { |
-} |
- |
// A comparator for locating a selectable window given a targeted window. |
struct WindowSelectorItemTargetComparator |
: public std::unary_function<WindowSelectorItem*, bool> { |
@@ -151,6 +108,18 @@ void UpdateShelfVisibility() { |
} |
} |
+// Returns true if a window is contained in any of the windows passed on the |
+// list. |
+bool ContainedIn(const aura::Window* window, |
+ const std::vector<WindowSelectorItem*>& window_list) { |
flackr
2014/06/03 17:12:07
nit: Seems like you can use find_in with the Windo
Nina
2014/06/04 20:21:13
Done.
|
+ for (std::vector<WindowSelectorItem*>::const_iterator iter = |
+ window_list.begin(); iter != window_list.end(); ++iter) { |
+ if ((*iter)->Contains(window)) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
} // namespace |
WindowSelector::WindowSelector(const WindowList& windows, |
@@ -158,13 +127,16 @@ WindowSelector::WindowSelector(const WindowList& windows, |
: delegate_(delegate), |
restore_focus_window_(aura::client::GetFocusClient( |
Shell::GetPrimaryRootWindow())->GetFocusedWindow()), |
- ignore_activations_(false) { |
+ ignore_activations_(false), |
+ selected_grid_index_(0) { |
DCHECK(delegate_); |
- if (restore_focus_window_) |
+ if (restore_focus_window_) { |
flackr
2014/06/03 17:12:07
nit: no curlies { } for single line block
Nina
2014/06/04 20:21:13
Done.
|
restore_focus_window_->AddObserver(this); |
+ } |
std::vector<WindowSelectorPanels*> panels_items; |
+ std::vector<WindowSelectorItem*> overview_items; |
for (size_t i = 0; i < windows.size(); ++i) { |
WindowSelectorItem* item = NULL; |
if (windows[i] != restore_focus_window_) |
@@ -182,7 +154,7 @@ WindowSelector::WindowSelector(const WindowList& windows, |
if (iter == panels_items.end()) { |
panels_item = new WindowSelectorPanels(); |
panels_items.push_back(panels_item); |
- windows_.push_back(panels_item); |
+ overview_items.push_back(panels_item); |
} else { |
panels_item = *iter; |
} |
@@ -190,12 +162,13 @@ WindowSelector::WindowSelector(const WindowList& windows, |
item = panels_item; |
} else { |
item = new WindowSelectorWindow(windows[i]); |
- windows_.push_back(item); |
+ overview_items.push_back(item); |
} |
// Verify that the window has been added to an item in overview. |
CHECK(item->Contains(windows[i])); |
} |
flackr
2014/06/03 17:12:07
All of this building the list of overview items co
Nina
2014/06/04 20:21:13
Done. I also moved the window removal code to the
|
- UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", windows_.size()); |
+ DCHECK(!overview_items.empty()); |
+ UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", overview_items.size()); |
// Observe window activations and switchable containers on all root windows |
// for newly created windows during overview. |
@@ -211,7 +184,40 @@ WindowSelector::WindowSelector(const WindowList& windows, |
} |
} |
- StartOverview(); |
+ // Remove focus from active window before entering overview. |
+ aura::client::GetFocusClient( |
+ Shell::GetPrimaryRootWindow())->FocusWindow(NULL); |
+ |
+ Shell* shell = Shell::GetInstance(); |
flackr
2014/06/03 17:12:07
Shell::GetInstance() is also used on 175, move bef
Nina
2014/06/04 20:21:13
Done.
|
+ shell->OnOverviewModeStarting(); |
flackr
2014/06/03 17:12:07
OnOverviewModeStarting should be sent before we st
Nina
2014/06/04 20:21:13
Done.
|
+ |
+ for (WindowSelectorItemList::iterator iter = overview_items.begin(); |
+ iter != overview_items.end(); ++iter) { |
+ (*iter)->PrepareForOverview(); |
+ } |
+ |
+ // Build the window_grid list |
+ aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); |
+ for (size_t i = 0; i < root_window_list.size(); ++i) { |
+ // Make sure the root window hosts at least one overview window. |
+ if (std::find_if(overview_items.begin(), overview_items.end(), |
+ WindowSelectorItemForRoot(root_window_list[i])) != |
+ overview_items.end()) { |
+ grid_list_.push_back(new WindowGrid(root_window_list[i], |
+ overview_items)); |
+ } |
+ } |
+ DCHECK(!grid_list_.empty()); |
+ |
+ shell->PrependPreTargetHandler(this); |
+ shell->GetScreen()->AddObserver(this); |
+ shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
+ HideAndTrackNonOverviewWindows(overview_items); |
+ // Send an a11y alert. |
+ shell->accessibility_delegate()->TriggerAccessibilityAlert( |
+ A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); |
+ |
+ UpdateShelfVisibility(); |
} |
WindowSelector::~WindowSelector() { |
@@ -249,7 +255,7 @@ WindowSelector::~WindowSelector() { |
shell->OnOverviewModeEnding(); |
// Clearing the window list resets the ignored_by_shelf flag on the windows. |
- windows_.clear(); |
+ grid_list_.clear(); |
UpdateShelfVisibility(); |
} |
@@ -261,16 +267,43 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) { |
if (event->type() != ui::ET_KEY_PRESSED) |
return; |
- if (event->key_code() == ui::VKEY_ESCAPE) { |
- CancelSelection(); |
- event->SetHandled(); |
+ bool handled = true; |
+ |
+ switch (event->key_code()) { |
+ case ui::VKEY_ESCAPE: |
+ CancelSelection(); |
+ break; |
+ case ui::VKEY_UP: |
+ Move(WindowSelector::UP); |
+ break; |
+ case ui::VKEY_DOWN: |
+ Move(WindowSelector::DOWN); |
+ break; |
+ case ui::VKEY_RIGHT: |
+ Move(WindowSelector::RIGHT); |
+ break; |
+ case ui::VKEY_LEFT: |
+ Move(WindowSelector::LEFT); |
+ break; |
+ case ui::VKEY_RETURN: |
+ wm::GetWindowState( |
+ grid_list_[selected_grid_index_]-> |
+ SelectedWindow()->SelectionWindow())->Activate(); |
+ break; |
+ default: |
+ // Not a key we are interested in. |
+ handled = false; |
+ break; |
} |
+ if (handled) |
+ event->SetHandled(); |
} |
void WindowSelector::OnDisplayAdded(const gfx::Display& display) { |
} |
void WindowSelector::OnDisplayRemoved(const gfx::Display& display) { |
+ CancelSelection(); |
flackr
2014/06/03 17:12:07
TODO(nsatragno): Keep window selection active on r
Nina
2014/06/04 20:21:13
This does sound like a good idea. Adding TODO.
|
} |
void WindowSelector::OnDisplayMetricsChanged(const gfx::Display& display, |
@@ -295,39 +328,45 @@ void WindowSelector::OnWindowAdded(aura::Window* new_window) { |
} |
void WindowSelector::OnWindowDestroying(aura::Window* window) { |
- // window is one of a container, the restore_focus_window and/or |
- // one of the selectable windows in overview. |
- ScopedVector<WindowSelectorItem>::iterator iter = |
- std::find_if(windows_.begin(), windows_.end(), |
- WindowSelectorItemComparator(window)); |
window->RemoveObserver(this); |
observed_windows_.erase(window); |
if (window == restore_focus_window_) |
restore_focus_window_ = NULL; |
- if (iter == windows_.end()) |
- return; |
- (*iter)->RemoveWindow(window); |
- // If there are still windows in this selector entry then the overview is |
- // still active and the active selection remains the same. |
- if (!(*iter)->empty()) |
- return; |
+ // Find the grid corresponding to the window's root window. |
+ ScopedVector<WindowGrid>::iterator grid_iter = |
+ std::find_if(grid_list_.begin(), grid_list_.end(), |
+ RootWindowGridComparator(window->GetRootWindow())); |
- windows_.erase(iter); |
- if (windows_.empty()) { |
- CancelSelection(); |
+ // If the a container or the |restore_focus_window_| are destroyed but not |
+ // part of the overview, they will not be found in the grid list. Nothing |
+ // else to do. |
+ if (grid_iter == grid_list_.end()) |
return; |
+ |
+ (*grid_iter)->RemoveWindow(window); |
+ |
+ if ((*grid_iter)->empty()) { |
+ grid_list_.erase(grid_iter); |
+ selected_grid_index_ = 0; |
flackr
2014/06/03 17:12:07
TODO, For more than 2 displays / grids the new sel
Nina
2014/06/04 20:21:13
Added TODO although this would not be a problem cu
|
+ if (grid_list_.size() == 0) |
+ CancelSelection(); |
} |
- PositionWindows(true); |
} |
void WindowSelector::OnWindowBoundsChanged(aura::Window* window, |
flackr
2014/06/03 17:12:07
Bounds changed should really be handled in the Win
Nina
2014/06/04 20:21:13
This should be relatively easy to implement. Added
|
const gfx::Rect& old_bounds, |
const gfx::Rect& new_bounds) { |
- ScopedVector<WindowSelectorItem>::iterator iter = |
- std::find_if(windows_.begin(), windows_.end(), |
+ ScopedVector<WindowGrid>::iterator grid = |
+ std::find_if(grid_list_.begin(), grid_list_.end(), |
+ RootWindowGridComparator(window->GetRootWindow())); |
+ if (grid == grid_list_.end()) |
+ return; |
+ const std::vector<WindowSelectorItem*> windows = (*grid)->window_list(); |
+ ScopedVector<WindowSelectorItem>::const_iterator iter = |
+ std::find_if(windows.begin(), windows.end(), |
WindowSelectorItemTargetComparator(window)); |
- if (iter == windows_.end()) |
+ if (iter == windows.end()) |
return; |
// Immediately finish any active bounds animation. |
@@ -343,11 +382,18 @@ void WindowSelector::OnWindowActivated(aura::Window* gained_active, |
if (ignore_activations_ || !gained_active) |
return; |
- ScopedVector<WindowSelectorItem>::iterator iter = std::find_if( |
- windows_.begin(), windows_.end(), |
+ ScopedVector<WindowGrid>::iterator grid = |
+ std::find_if(grid_list_.begin(), grid_list_.end(), |
+ RootWindowGridComparator(gained_active->GetRootWindow())); |
+ if (grid == grid_list_.end()) |
+ return; |
+ const std::vector<WindowSelectorItem*> windows = (*grid)->window_list(); |
+ |
+ ScopedVector<WindowSelectorItem>::const_iterator iter = std::find_if( |
+ windows.begin(), windows.end(), |
WindowSelectorItemComparator(gained_active)); |
- if (iter != windows_.end()) |
+ if (iter != windows.end()) |
(*iter)->RestoreWindowOnExit(gained_active); |
// Don't restore focus on exit if a window was just activated. |
@@ -360,95 +406,15 @@ void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active, |
OnWindowActivated(request_active, actual_active); |
} |
-void WindowSelector::StartOverview() { |
- // Remove focus from active window before entering overview. |
- aura::client::GetFocusClient( |
- Shell::GetPrimaryRootWindow())->FocusWindow(NULL); |
- |
- Shell* shell = Shell::GetInstance(); |
- shell->OnOverviewModeStarting(); |
- |
- for (WindowSelectorItemList::iterator iter = windows_.begin(); |
- iter != windows_.end(); ++iter) { |
- (*iter)->PrepareForOverview(); |
- } |
- PositionWindows(/* animate */ true); |
- DCHECK(!windows_.empty()); |
- shell->PrependPreTargetHandler(this); |
- shell->GetScreen()->AddObserver(this); |
- shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
- HideAndTrackNonOverviewWindows(); |
- // Send an a11y alert. |
- shell->accessibility_delegate()->TriggerAccessibilityAlert( |
- A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); |
- |
- UpdateShelfVisibility(); |
-} |
- |
-bool WindowSelector::Contains(const aura::Window* window) { |
- for (WindowSelectorItemList::iterator iter = windows_.begin(); |
- iter != windows_.end(); ++iter) { |
- if ((*iter)->Contains(window)) |
- return true; |
- } |
- return false; |
-} |
- |
void WindowSelector::PositionWindows(bool animate) { |
- aura::Window::Windows root_window_list = Shell::GetAllRootWindows(); |
- for (size_t i = 0; i < root_window_list.size(); ++i) |
- PositionWindowsFromRoot(root_window_list[i], animate); |
-} |
- |
-void WindowSelector::PositionWindowsFromRoot(aura::Window* root_window, |
- bool animate) { |
- std::vector<WindowSelectorItem*> windows; |
- for (WindowSelectorItemList::iterator iter = windows_.begin(); |
- iter != windows_.end(); ++iter) { |
- if ((*iter)->GetRootWindow() == root_window) |
- windows.push_back(*iter); |
- } |
- |
- if (windows.empty()) |
- return; |
- |
- gfx::Size window_size; |
- gfx::Rect total_bounds = ScreenUtil::ConvertRectToScreen( |
- root_window, |
- ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
- Shell::GetContainer(root_window, kShellWindowId_DefaultContainer))); |
- |
- // Find the minimum number of windows per row that will fit all of the |
- // windows on screen. |
- size_t columns = std::max( |
- total_bounds.width() > total_bounds.height() ? kMinCardsMajor : 1, |
- static_cast<int>(ceil(sqrt(total_bounds.width() * windows.size() / |
- (kCardAspectRatio * total_bounds.height()))))); |
- size_t rows = ((windows.size() + columns - 1) / columns); |
- window_size.set_width(std::min( |
- static_cast<int>(total_bounds.width() / columns), |
- static_cast<int>(total_bounds.height() * kCardAspectRatio / rows))); |
- window_size.set_height(window_size.width() / kCardAspectRatio); |
- |
- // Calculate the X and Y offsets necessary to center the grid. |
- int x_offset = total_bounds.x() + ((windows.size() >= columns ? 0 : |
- (columns - windows.size()) * window_size.width()) + |
- (total_bounds.width() - columns * window_size.width())) / 2; |
- int y_offset = total_bounds.y() + (total_bounds.height() - |
- rows * window_size.height()) / 2; |
- for (size_t i = 0; i < windows.size(); ++i) { |
- gfx::Transform transform; |
- int column = i % columns; |
- int row = i / columns; |
- gfx::Rect target_bounds(window_size.width() * column + x_offset, |
- window_size.height() * row + y_offset, |
- window_size.width(), |
- window_size.height()); |
- windows[i]->SetBounds(root_window, target_bounds, animate); |
+ for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); |
+ iter != grid_list_.end(); iter++) { |
+ (*iter)->PositionWindows(animate); |
} |
} |
-void WindowSelector::HideAndTrackNonOverviewWindows() { |
+void WindowSelector::HideAndTrackNonOverviewWindows( |
+ const std::vector<WindowSelectorItem*>& overview_items) { |
// Add the windows to hidden_windows first so that if any are destroyed |
// while hiding them they are tracked. |
aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
@@ -460,7 +426,7 @@ void WindowSelector::HideAndTrackNonOverviewWindows() { |
for (aura::Window::Windows::const_iterator iter = |
container->children().begin(); iter != container->children().end(); |
++iter) { |
- if (Contains(*iter) || !(*iter)->IsVisible()) |
+ if (ContainedIn(*iter, overview_items) || !(*iter)->IsVisible()) |
continue; |
hidden_windows_.Add(*iter); |
} |
@@ -503,4 +469,14 @@ void WindowSelector::ResetFocusRestoreWindow(bool focus) { |
restore_focus_window_ = NULL; |
} |
+void WindowSelector::Move(Direction direction) { |
+ if (grid_list_[selected_grid_index_]->Move(direction)) { |
+ // The grid reported that the movement command corresponds to the next |
+ // root window, identify it and call Move() on it to initialize the |
+ // selection widget. |
flackr
2014/06/03 17:12:07
TODO: If there are more than 2 monitors, move betw
Nina
2014/06/04 20:21:13
Added TODO. Again, this will not be a problem for
|
+ selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); |
+ grid_list_[selected_grid_index_]->Move(direction); |
+ } |
+} |
+ |
} // namespace ash |