Chromium Code Reviews| Index: ash/wm/overview/window_grid.cc |
| diff --git a/ash/wm/overview/window_grid.cc b/ash/wm/overview/window_grid.cc |
| index 99ea37c2d1e54056e20674b2f1366eb468a595f8..b358df9e0905700b905ed4abb3e1d18169375ef7 100644 |
| --- a/ash/wm/overview/window_grid.cc |
| +++ b/ash/wm/overview/window_grid.cc |
| @@ -14,6 +14,9 @@ |
| #include "ash/wm/overview/window_selector_window.h" |
| #include "ash/wm/window_state.h" |
| #include "base/memory/scoped_vector.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "third_party/icu/source/i18n/unicode/translit.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "ui/aura/window.h" |
| #include "ui/compositor/layer_animation_observer.h" |
| @@ -128,7 +131,8 @@ WindowGrid::WindowGrid(aura::Window* root_window, |
| const std::vector<aura::Window*>& windows, |
| WindowSelector* window_selector) |
| : root_window_(root_window), |
| - window_selector_(window_selector) { |
| + window_selector_(window_selector), |
| + item_active_(true) { |
| WindowSelectorPanels* panels_item = NULL; |
| for (aura::Window::Windows::const_iterator iter = windows.begin(); |
| iter != windows.end(); ++iter) { |
| @@ -197,6 +201,7 @@ void WindowGrid::PositionWindows(bool animate) { |
| (total_bounds.width() - num_columns_ * window_size.width())) / 2; |
| int y_offset = total_bounds.y() + (total_bounds.height() - |
| num_rows * window_size.height()) / 2; |
| + |
| for (size_t i = 0; i < window_list_.size(); ++i) { |
| gfx::Transform transform; |
| int column = i % num_columns_; |
| @@ -219,6 +224,9 @@ void WindowGrid::PositionWindows(bool animate) { |
| } |
| bool WindowGrid::Move(WindowSelector::Direction direction) { |
| + if (!item_active_) |
| + return false; |
| + |
| bool recreate_selection_widget = false; |
| bool out_of_bounds = false; |
| if (!selection_widget_) { |
| @@ -235,7 +243,8 @@ bool WindowGrid::Move(WindowSelector::Direction direction) { |
| selected_index_ = 0; |
| break; |
| } |
| - } else { |
| + } |
| + while (!SelectedWindow()->active() || selection_widget_) { |
| switch (direction) { |
| case WindowSelector::RIGHT: |
| if (selected_index_ >= window_list_.size() - 1) |
| @@ -272,6 +281,9 @@ bool WindowGrid::Move(WindowSelector::Direction direction) { |
| } |
| break; |
| } |
| + // Exit the loop if we broke free from the grid or found an active item. |
| + if (out_of_bounds || SelectedWindow()->active()) |
| + break; |
| } |
| MoveSelectionWidget(direction, recreate_selection_widget, out_of_bounds); |
| @@ -289,6 +301,39 @@ bool WindowGrid::Contains(const aura::Window* window) const { |
| window_list_.end(); |
| } |
| +void WindowGrid::Filter(const base::string16& pattern) { |
| + item_active_ = false; |
| + UErrorCode status = U_ZERO_ERROR; |
| + |
| + // Construct a transilterator that removes accents and converts uppercase |
| + // letters to lowercase in a l10n sensitive context. |
|
tdanderson
2014/06/25 15:48:23
I would instead mention the fact that your filteri
Nina
2014/06/26 15:20:17
Done.
|
| + icu::Transliterator* translit = icu::Transliterator::createInstance( |
| + "Lower (Upper); NFD; [:Nonspacing Mark:] Remove; NFC", |
| + UTRANS_FORWARD, status); |
| + icu::UnicodeString target(pattern.c_str()); |
| + translit->transliterate(target); |
| + |
| + for (ScopedVector<WindowSelectorItem>::iterator iter = window_list_.begin(); |
| + iter != window_list_.end(); iter++) { |
| + icu::UnicodeString title_string( |
| + (*iter)->SelectionWindow()->title().c_str()); |
| + translit->transliterate(title_string); |
| + const base::string16& title(title_string.getTerminatedBuffer()); |
| + if (title.find(target.getTerminatedBuffer()) != base::string16::npos) { |
| + (*iter)->SetActive(true); |
| + item_active_ = true; |
| + } else { |
| + (*iter)->SetActive(false); |
| + if (selection_widget_ && SelectedWindow() == *iter) |
| + selection_widget_.reset(); |
| + } |
| + } |
| + // If the selection widget is not active, execute a Move() command so that it |
| + // shows up. |
|
tdanderson
2014/06/25 15:48:23
"shows up on the first unfiltered item"?
Nina
2014/06/26 15:20:17
Done.
|
| + if (!selection_widget_) |
| + Move(WindowSelector::RIGHT); |
| +} |
| + |
| void WindowGrid::OnWindowDestroying(aura::Window* window) { |
| window->RemoveObserver(this); |
| observed_windows_.erase(window); |