Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3033)

Unified Diff: ash/wm/overview/window_selector.cc

Issue 358553004: Added text filtering to Overview Mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Terry's comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/overview/window_selector.cc
diff --git a/ash/wm/overview/window_selector.cc b/ash/wm/overview/window_selector.cc
index 467aca6a8be669310006d0cafc85b779f1f87e3f..4eeeec4d1fe3103b4cb4c775ed51dd8d1667f6f1 100644
--- a/ash/wm/overview/window_selector.cc
+++ b/ash/wm/overview/window_selector.cc
@@ -27,6 +27,8 @@
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/events/event.h"
#include "ui/gfx/screen.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/textfield/textfield.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_client.h"
@@ -87,6 +89,34 @@ void UpdateShelfVisibility() {
}
}
+// Initializes the text filter on the top of the main root window and requests
+// focus on its textfield.
+views::Widget* CreateTextFilter(views::TextfieldController* controller,
+ aura::Window* root_window) {
+ views::Widget* widget = new views::Widget;
+ views::Widget::InitParams params;
+ params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
+ params.parent =
+ Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer);
+ params.accept_events = true;
+ params.bounds = gfx::Rect(root_window->bounds().width() / 4, 0,
+ root_window->bounds().width() / 2, 0);
flackr 2014/06/26 17:33:07 nit: use constants, in this case something like kT
Nina 2014/06/27 15:20:39 Done.
+ widget->Init(params);
+ views::Textfield* textfield = new views::Textfield;
+ textfield->set_controller(controller);
+ textfield->SetBackgroundColor(SK_ColorTRANSPARENT);
+ textfield->SetBorder(views::Border::NullBorder());
+ textfield->SetTextColor(SK_ColorWHITE);
+ textfield->DisplayShadow(true);
+ widget->SetContentsView(textfield);
+ widget->Show();
+ textfield->RequestFocus();
+
+ return widget;
+}
+
} // namespace
WindowSelector::WindowSelector(const WindowList& windows,
@@ -98,7 +128,8 @@ WindowSelector::WindowSelector(const WindowList& windows,
selected_grid_index_(0),
overview_start_time_(base::Time::Now()),
num_key_presses_(0),
- num_items_(0) {
+ num_items_(0),
+ showing_selection_widget_(false) {
flackr 2014/06/26 17:33:07 Do we need this variable or can we just check if t
Nina 2014/06/27 15:20:39 We could remove the variable at the cost of having
DCHECK(delegate_);
Shell* shell = Shell::GetInstance();
shell->OnOverviewModeStarting();
@@ -127,13 +158,11 @@ WindowSelector::WindowSelector(const WindowList& windows,
DCHECK(!grid_list_.empty());
UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_);
- shell->activation_client()->AddObserver(this);
+ text_filter_widget_.reset(
+ CreateTextFilter(this, Shell::GetPrimaryRootWindow()));
- // Remove focus from active window before entering overview.
- aura::client::GetFocusClient(
- Shell::GetPrimaryRootWindow())->FocusWindow(NULL);
+ shell->activation_client()->AddObserver(this);
- shell->PrependPreTargetHandler(this);
shell->GetScreen()->AddObserver(this);
shell->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW);
HideAndTrackNonOverviewWindows();
@@ -168,7 +197,6 @@ WindowSelector::~WindowSelector() {
(*iter)->Show();
}
- shell->RemovePreTargetHandler(this);
shell->GetScreen()->RemoveObserver(this);
size_t remaining_items = 0;
@@ -207,11 +235,12 @@ void WindowSelector::OnGridEmpty(WindowGrid* grid) {
CancelSelection();
}
-void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
- if (event->type() != ui::ET_KEY_PRESSED)
- return;
+bool WindowSelector::HandleKeyEvent(views::Textfield* sender,
+ const ui::KeyEvent& key_event) {
+ if (key_event.type() != ui::ET_KEY_PRESSED)
+ return false;
- switch (event->key_code()) {
+ switch (key_event.key_code()) {
case ui::VKEY_ESCAPE:
CancelSelection();
break;
@@ -234,7 +263,7 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
case ui::VKEY_RETURN:
// Ignore if no item is selected.
if (!grid_list_[selected_grid_index_]->is_selecting())
- return;
+ return true;
UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ArrowKeyPresses",
num_key_presses_);
UMA_HISTOGRAM_CUSTOM_COUNTS(
@@ -246,10 +275,10 @@ void WindowSelector::OnKeyEvent(ui::KeyEvent* event) {
SelectedWindow()->SelectionWindow())->Activate();
break;
default:
- // Not a key we are interested in.
- return;
+ // Not a key we are interested in, allow the textfield to handle it.
+ return false;
}
- event->StopPropagation();
+ return true;
}
void WindowSelector::OnDisplayAdded(const gfx::Display& display) {
@@ -290,8 +319,11 @@ void WindowSelector::OnWindowDestroying(aura::Window* window) {
void WindowSelector::OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) {
- if (ignore_activations_ || !gained_active)
+ if (ignore_activations_ ||
+ !gained_active ||
+ gained_active == text_filter_widget_->GetNativeWindow()) {
return;
+ }
ScopedVector<WindowGrid>::iterator grid =
std::find_if(grid_list_.begin(), grid_list_.end(),
@@ -317,6 +349,27 @@ void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active,
OnWindowActivated(request_active, actual_active);
}
+void WindowSelector::ContentsChanged(views::Textfield* sender,
+ const base::string16& new_contents) {
+ if (!showing_selection_widget_ || new_contents.empty()) {
flackr 2014/06/26 17:33:07 We did say this should be behind a flag right? Can
Nina 2014/06/27 15:20:39 Added --disable* flag
+ ui::ScopedLayerAnimationSettings animation_settings(
+ text_filter_widget_->GetNativeWindow()->layer()->GetAnimator());
+ animation_settings.SetPreemptionStrategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+ animation_settings.SetTweenType(showing_selection_widget_ ?
+ gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN);
+ size_t root_window_width = Shell::GetPrimaryRootWindow()->bounds().width();
+ text_filter_widget_->SetBounds(
+ gfx::Rect(root_window_width / 4, 0,root_window_width / 2,
+ showing_selection_widget_ ? 0 : 50));
flackr 2014/06/26 17:33:07 To do this animation on the compositor this should
Nina 2014/06/27 15:20:39 Done!
+ showing_selection_widget_ = !showing_selection_widget_;
+ }
+ for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin();
+ iter != grid_list_.end(); iter++) {
+ (*iter)->FilterItems(new_contents);
+ }
+}
+
void WindowSelector::PositionWindows(bool animate) {
for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin();
iter != grid_list_.end(); iter++) {

Powered by Google App Engine
This is Rietveld 408576698