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..ccccc854130bc577353b9a1aae8a938cc97b2318 100644 |
--- a/ash/wm/overview/window_selector.cc |
+++ b/ash/wm/overview/window_selector.cc |
@@ -10,31 +10,23 @@ |
#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" |
-#include "ash/wm/overview/window_selector_window.h" |
#include "ash/wm/window_state.h" |
#include "base/auto_reset.h" |
-#include "base/command_line.h" |
#include "base/metrics/histogram.h" |
-#include "base/strings/string_number_conversions.h" |
-#include "third_party/skia/include/core/SkColor.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/compositor/layer_animation_observer.h" |
#include "ui/compositor/scoped_layer_animation_settings.h" |
#include "ui/events/event.h" |
#include "ui/gfx/screen.h" |
-#include "ui/views/background.h" |
-#include "ui/views/widget/widget.h" |
#include "ui/wm/core/window_util.h" |
#include "ui/wm/public/activation_client.h" |
@@ -42,76 +34,20 @@ 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; |
- |
-// The minimum number of cards along the major axis (i.e. horizontally on a |
-// landscape orientation). |
-const int kMinCardsMajor = 3; |
- |
-// A comparator for locating a given target window. |
-struct WindowSelectorItemComparator |
- : public std::unary_function<WindowSelectorItem*, bool> { |
- explicit WindowSelectorItemComparator(const aura::Window* target_window) |
- : target(target_window) { |
+// 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()(WindowSelectorItem* window) const { |
- return window->HasSelectableWindow(target); |
+ bool operator()(WindowGrid* grid) const { |
+ return (grid->root_window() == root_window_); |
} |
- 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); |
+ const aura::Window* root_window_; |
}; |
-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 +87,16 @@ 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) { |
+ std::vector<WindowSelectorItem*>::const_iterator iter = |
+ std::find_if(window_list.begin(), window_list.end(), |
+ WindowSelectorItemTargetComparator(window)); |
+ return iter != window_list.end(); |
flackr
2014/06/04 22:25:06
No need to create/store iter variable, i.e. just r
Nina
2014/06/05 18:04:35
Done. Note that the method has been moved to Windo
|
+} |
+ |
} // namespace |
WindowSelector::WindowSelector(const WindowList& windows, |
@@ -158,51 +104,26 @@ 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_); |
+ Shell* shell = Shell::GetInstance(); |
+ shell->OnOverviewModeStarting(); |
if (restore_focus_window_) |
restore_focus_window_->AddObserver(this); |
- std::vector<WindowSelectorPanels*> panels_items; |
- for (size_t i = 0; i < windows.size(); ++i) { |
- WindowSelectorItem* item = NULL; |
- if (windows[i] != restore_focus_window_) |
- windows[i]->AddObserver(this); |
- observed_windows_.insert(windows[i]); |
- |
- if (windows[i]->type() == ui::wm::WINDOW_TYPE_PANEL && |
- wm::GetWindowState(windows[i])->panel_attached()) { |
- // Attached panel windows are grouped into a single overview item per |
- // root window (display). |
- std::vector<WindowSelectorPanels*>::iterator iter = |
- std::find_if(panels_items.begin(), panels_items.end(), |
- WindowSelectorItemForRoot(windows[i]->GetRootWindow())); |
- WindowSelectorPanels* panels_item = NULL; |
- if (iter == panels_items.end()) { |
- panels_item = new WindowSelectorPanels(); |
- panels_items.push_back(panels_item); |
- windows_.push_back(panels_item); |
- } else { |
- panels_item = *iter; |
- } |
- panels_item->AddWindow(windows[i]); |
- item = panels_item; |
+ const aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
+ size_t items = 0; |
+ for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
+ iter != root_windows.end(); iter++) { |
+ WindowGrid* grid(new WindowGrid(*iter, windows, this)); |
+ if (grid->empty()) { |
+ delete grid; |
} else { |
flackr
2014/06/04 22:25:06
nit: Instead of else, use continue in first if sta
Nina
2014/06/05 18:04:35
But then we wouldn't add the containers to the obs
flackr
2014/06/05 20:16:32
You can move observing the containers before creat
Nina
2014/06/05 22:06:22
Done.
|
- item = new WindowSelectorWindow(windows[i]); |
- windows_.push_back(item); |
+ grid_list_.push_back(grid); |
+ items += grid_list_.size(); |
} |
- // Verify that the window has been added to an item in overview. |
- CHECK(item->Contains(windows[i])); |
- } |
- UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", windows_.size()); |
- |
- // Observe window activations and switchable containers on all root windows |
- // for newly created windows during overview. |
- Shell::GetInstance()->activation_client()->AddObserver(this); |
- aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
- for (aura::Window::Windows::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]); |
@@ -211,7 +132,28 @@ WindowSelector::WindowSelector(const WindowList& windows, |
} |
} |
- StartOverview(); |
+ DCHECK(!grid_list_.empty()); |
+ UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", items); |
+ |
+ // Observe window activations and switchable containers on all root windows |
flackr
2014/06/04 22:25:06
Observing switchable containers seems to be lines
Nina
2014/06/05 18:04:35
Moved and modified comment.
|
+ // for newly created windows during overview. |
+ shell->activation_client()->AddObserver(this); |
+ |
+ // Remove focus from active window before entering overview. |
+ aura::client::GetFocusClient( |
+ Shell::GetPrimaryRootWindow())->FocusWindow(NULL); |
+ |
+ DCHECK(!grid_list_.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(); |
} |
WindowSelector::~WindowSelector() { |
@@ -249,7 +191,7 @@ WindowSelector::~WindowSelector() { |
shell->OnOverviewModeEnding(); |
// Clearing the window list resets the ignored_by_shelf flag on the windows. |
- windows_.clear(); |
+ grid_list_.clear(); |
UpdateShelfVisibility(); |
} |
@@ -257,20 +199,59 @@ void WindowSelector::CancelSelection() { |
delegate_->OnSelectionEnded(); |
} |
+void WindowSelector::OnGridEmpty(WindowGrid* grid) { |
+ ScopedVector<WindowGrid>::iterator iter = |
+ std::find(grid_list_.begin(), grid_list_.end(), grid); |
+ DCHECK(iter != grid_list_.end()); |
+ grid_list_.erase(iter); |
+ // TODO(nsatragno): Use the previous index for more than two displays. |
+ selected_grid_index_ = 0; |
+ if (grid_list_.empty()) |
+ CancelSelection(); |
+} |
+ |
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) { |
+ // TODO(nsatragno): Keep window selection active on remaining displays. |
+ CancelSelection(); |
} |
void WindowSelector::OnDisplayMetricsChanged(const gfx::Display& display, |
@@ -295,47 +276,10 @@ 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; |
- |
- windows_.erase(iter); |
- if (windows_.empty()) { |
- CancelSelection(); |
- return; |
- } |
- PositionWindows(true); |
-} |
- |
-void WindowSelector::OnWindowBoundsChanged(aura::Window* window, |
- const gfx::Rect& old_bounds, |
- const gfx::Rect& new_bounds) { |
- ScopedVector<WindowSelectorItem>::iterator iter = |
- std::find_if(windows_.begin(), windows_.end(), |
- WindowSelectorItemTargetComparator(window)); |
- if (iter == windows_.end()) |
- return; |
- |
- // Immediately finish any active bounds animation. |
- window->layer()->GetAnimator()->StopAnimatingProperty( |
- ui::LayerAnimationElement::BOUNDS); |
- |
- // Recompute the transform for the window. |
- (*iter)->RecomputeWindowTransforms(); |
} |
void WindowSelector::OnWindowActivated(aura::Window* gained_active, |
@@ -343,11 +287,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(), |
- WindowSelectorItemComparator(gained_active)); |
+ 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(); |
- if (iter != windows_.end()) |
+ ScopedVector<WindowSelectorItem>::const_iterator iter = std::find_if( |
+ windows.begin(), windows.end(), |
+ WindowSelectorItemTargetComparator(gained_active)); |
+ |
+ if (iter != windows.end()) |
(*iter)->RestoreWindowOnExit(gained_active); |
// Don't restore focus on exit if a window was just activated. |
@@ -360,91 +311,10 @@ 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); |
} |
} |
@@ -454,13 +324,21 @@ void WindowSelector::HideAndTrackNonOverviewWindows() { |
aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
for (aura::Window::Windows::const_iterator root_iter = root_windows.begin(); |
root_iter != root_windows.end(); ++root_iter) { |
flackr
2014/06/04 22:25:06
May as well change this to loop through the Window
Nina
2014/06/05 18:04:35
Sounds reasonable, done.
|
+ // Find the overview items for this root window. |
+ std::vector<WindowSelectorItem*> overview_items; |
+ ScopedVector<WindowGrid>::iterator grid = |
+ std::find_if(grid_list_.begin(), grid_list_.end(), |
+ RootWindowGridComparator(*root_iter)); |
+ if (grid != grid_list_.end()) |
+ overview_items = (*grid)->window_list(); |
flackr
2014/06/04 22:25:06
Instead, add WindowGrid::Contains(Window*) and use
Nina
2014/06/05 18:04:36
Done.
|
+ |
for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) { |
aura::Window* container = Shell::GetContainer(*root_iter, |
kSwitchableWindowContainerIds[i]); |
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 +381,16 @@ 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. |
+ // TODO(nsatragno): If there are more than two monitors, move between grids |
+ // in the requested direction. |
+ selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); |
+ grid_list_[selected_grid_index_]->Move(direction); |
+ } |
+} |
+ |
} // namespace ash |