| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/overview/window_selector.h" | 5 #include "ash/wm/overview/window_selector.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/accessibility_delegate.h" | 9 #include "ash/accessibility_delegate.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/metrics/user_metrics_recorder.h" | 11 #include "ash/metrics/user_metrics_recorder.h" |
| 12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 15 #include "ash/switchable_windows.h" | 15 #include "ash/switchable_windows.h" |
| 16 #include "ash/wm/overview/scoped_transform_overview_window.h" | 16 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| 17 #include "ash/wm/overview/window_grid.h" | 17 #include "ash/wm/overview/window_grid.h" |
| 18 #include "ash/wm/overview/window_selector_delegate.h" | 18 #include "ash/wm/overview/window_selector_delegate.h" |
| 19 #include "ash/wm/overview/window_selector_item.h" | 19 #include "ash/wm/overview/window_selector_item.h" |
| 20 #include "ash/wm/window_state.h" | 20 #include "ash/wm/window_state.h" |
| 21 #include "base/auto_reset.h" | 21 #include "base/auto_reset.h" |
| 22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
| 24 #include "third_party/skia/include/core/SkPaint.h" |
| 25 #include "third_party/skia/include/core/SkPath.h" |
| 24 #include "ui/aura/client/focus_client.h" | 26 #include "ui/aura/client/focus_client.h" |
| 25 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_event_dispatcher.h" | 28 #include "ui/aura/window_event_dispatcher.h" |
| 27 #include "ui/aura/window_observer.h" | 29 #include "ui/aura/window_observer.h" |
| 30 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/compositor/scoped_layer_animation_settings.h" | 31 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 29 #include "ui/events/event.h" | 32 #include "ui/events/event.h" |
| 33 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 35 #include "ui/gfx/skia_util.h" |
| 31 #include "ui/views/border.h" | 36 #include "ui/views/border.h" |
| 32 #include "ui/views/controls/textfield/textfield.h" | 37 #include "ui/views/controls/textfield/textfield.h" |
| 38 #include "ui/views/layout/box_layout.h" |
| 33 #include "ui/wm/core/window_util.h" | 39 #include "ui/wm/core/window_util.h" |
| 34 #include "ui/wm/public/activation_client.h" | 40 #include "ui/wm/public/activation_client.h" |
| 35 | 41 |
| 36 namespace ash { | 42 namespace ash { |
| 37 | 43 |
| 38 namespace { | 44 namespace { |
| 39 | 45 |
| 40 // The proportion of screen width that the text filter takes. | 46 // The proportion of screen width that the text filter takes. |
| 41 const float kTextFilterScreenProportion = 0.5; | 47 const float kTextFilterScreenProportion = 0.25; |
| 42 | 48 |
| 43 // The height of the text filter. | 49 // The amount of padding surrounding the text in the text filtering textbox. |
| 44 const int kTextFilterHeight = 50; | 50 const int kTextFilterHorizontalPadding = 8; |
| 45 | 51 |
| 46 // Solid shadow length from the text filter. | 52 // The distance between the top of the screen and the top edge of the |
| 47 const int kVerticalShadowOffset = 1; | 53 // text filtering textbox. |
| 54 const int kTextFilterDistanceFromTop = 32; |
| 48 | 55 |
| 49 // Amount of blur applied to the text filter shadow. | 56 // The height of the text filtering textbox. |
| 50 const int kShadowBlur = 10; | 57 const int kTextFilterHeight = 32; |
| 51 | 58 |
| 52 // Text filter shadow color. | 59 // The font style used for text filtering. |
| 53 const SkColor kTextFilterShadow = 0xB0000000; | 60 static const ::ui::ResourceBundle::FontStyle kTextFilterFontStyle = |
| 61 ::ui::ResourceBundle::FontStyle::MediumFont; |
| 62 |
| 63 // The alpha value for the background of the text filtering textbox. |
| 64 const unsigned char kTextFilterOpacity = 180; |
| 65 |
| 66 // The radius used for the rounded corners on the text filtering textbox. |
| 67 const int kTextFilterCornerRadius = 1; |
| 54 | 68 |
| 55 // A comparator for locating a grid with a given root window. | 69 // A comparator for locating a grid with a given root window. |
| 56 struct RootWindowGridComparator | 70 struct RootWindowGridComparator |
| 57 : public std::unary_function<WindowGrid*, bool> { | 71 : public std::unary_function<WindowGrid*, bool> { |
| 58 explicit RootWindowGridComparator(const aura::Window* root_window) | 72 explicit RootWindowGridComparator(const aura::Window* root_window) |
| 59 : root_window_(root_window) { | 73 : root_window_(root_window) { |
| 60 } | 74 } |
| 61 | 75 |
| 62 bool operator()(WindowGrid* grid) const { | 76 bool operator()(WindowGrid* grid) const { |
| 63 return (grid->root_window() == root_window_); | 77 return (grid->root_window() == root_window_); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 87 : root_window(root) { | 101 : root_window(root) { |
| 88 } | 102 } |
| 89 | 103 |
| 90 bool operator()(WindowSelectorItem* item) const { | 104 bool operator()(WindowSelectorItem* item) const { |
| 91 return item->GetRootWindow() == root_window; | 105 return item->GetRootWindow() == root_window; |
| 92 } | 106 } |
| 93 | 107 |
| 94 const aura::Window* root_window; | 108 const aura::Window* root_window; |
| 95 }; | 109 }; |
| 96 | 110 |
| 111 // A View having rounded corners and a specified background color which is |
| 112 // only painted within the bounds defined by the rounded corners. |
| 113 // TODO(tdanderson): This duplicates code from RoundedImageView. Refactor these |
| 114 // classes and move into ui/views. |
| 115 class RoundedContainerView : public views::View { |
| 116 public: |
| 117 RoundedContainerView(int corner_radius, SkColor background) |
| 118 : corner_radius_(corner_radius), |
| 119 background_(background) { |
| 120 } |
| 121 |
| 122 virtual ~RoundedContainerView() {} |
| 123 |
| 124 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 125 views::View::OnPaint(canvas); |
| 126 |
| 127 SkScalar radius = SkIntToScalar(corner_radius_); |
| 128 const SkScalar kRadius[8] = {radius, radius, radius, radius, |
| 129 radius, radius, radius, radius}; |
| 130 SkPath path; |
| 131 gfx::Rect bounds(size()); |
| 132 path.addRoundRect(gfx::RectToSkRect(bounds), kRadius); |
| 133 |
| 134 SkPaint paint; |
| 135 paint.setAntiAlias(true); |
| 136 canvas->ClipPath(path, true); |
| 137 canvas->DrawColor(background_); |
| 138 } |
| 139 |
| 140 private: |
| 141 int corner_radius_; |
| 142 SkColor background_; |
| 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); |
| 145 }; |
| 146 |
| 97 // Triggers a shelf visibility update on all root window controllers. | 147 // Triggers a shelf visibility update on all root window controllers. |
| 98 void UpdateShelfVisibility() { | 148 void UpdateShelfVisibility() { |
| 99 Shell::RootWindowControllerList root_window_controllers = | 149 Shell::RootWindowControllerList root_window_controllers = |
| 100 Shell::GetInstance()->GetAllRootWindowControllers(); | 150 Shell::GetInstance()->GetAllRootWindowControllers(); |
| 101 for (Shell::RootWindowControllerList::iterator iter = | 151 for (Shell::RootWindowControllerList::iterator iter = |
| 102 root_window_controllers.begin(); | 152 root_window_controllers.begin(); |
| 103 iter != root_window_controllers.end(); ++iter) { | 153 iter != root_window_controllers.end(); ++iter) { |
| 104 (*iter)->UpdateShelfVisibility(); | 154 (*iter)->UpdateShelfVisibility(); |
| 105 } | 155 } |
| 106 } | 156 } |
| 107 | 157 |
| 108 // Initializes the text filter on the top of the main root window and requests | 158 // Initializes the text filter on the top of the main root window and requests |
| 109 // focus on its textfield. | 159 // focus on its textfield. |
| 110 views::Widget* CreateTextFilter(views::TextfieldController* controller, | 160 views::Widget* CreateTextFilter(views::TextfieldController* controller, |
| 111 aura::Window* root_window) { | 161 aura::Window* root_window) { |
| 112 views::Widget* widget = new views::Widget; | 162 views::Widget* widget = new views::Widget; |
| 113 views::Widget::InitParams params; | 163 views::Widget::InitParams params; |
| 114 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 164 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 115 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 165 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 116 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 166 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 117 params.parent = | 167 params.parent = |
| 118 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | 168 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); |
| 119 params.accept_events = true; | 169 params.accept_events = true; |
| 120 params.bounds = gfx::Rect( | 170 params.bounds = gfx::Rect( |
| 121 root_window->bounds().width() / 2 * (1 - kTextFilterScreenProportion), 0, | 171 root_window->bounds().width() / 2 * (1 - kTextFilterScreenProportion), |
| 172 kTextFilterDistanceFromTop, |
| 122 root_window->bounds().width() * kTextFilterScreenProportion, | 173 root_window->bounds().width() * kTextFilterScreenProportion, |
| 123 kTextFilterHeight); | 174 kTextFilterHeight); |
| 124 widget->Init(params); | 175 widget->Init(params); |
| 125 | 176 |
| 177 // Use |container| to specify the padding surrounding the text and to give |
| 178 // the textfield rounded corners. |
| 179 views::View* container = new RoundedContainerView( |
| 180 kTextFilterCornerRadius, SkColorSetARGB(kTextFilterOpacity, 0, 0, 0)); |
| 181 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 182 int text_height = bundle.GetFontList(kTextFilterFontStyle).GetHeight(); |
| 183 DCHECK(text_height); |
| 184 int vertical_padding = (kTextFilterHeight - text_height) / 2; |
| 185 container->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
| 186 kTextFilterHorizontalPadding, |
| 187 vertical_padding, |
| 188 0)); |
| 189 |
| 126 views::Textfield* textfield = new views::Textfield; | 190 views::Textfield* textfield = new views::Textfield; |
| 127 textfield->set_controller(controller); | 191 textfield->set_controller(controller); |
| 128 textfield->SetBackgroundColor(SK_ColorTRANSPARENT); | 192 textfield->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 129 textfield->SetBorder(views::Border::NullBorder()); | 193 textfield->SetBorder(views::Border::NullBorder()); |
| 130 textfield->SetTextColor(SK_ColorWHITE); | 194 textfield->SetTextColor(SK_ColorWHITE); |
| 131 textfield->SetShadows(gfx::ShadowValues(1, gfx::ShadowValue( | 195 textfield->SetFontList(bundle.GetFontList(kTextFilterFontStyle)); |
| 132 gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kTextFilterShadow))); | |
| 133 widget->SetContentsView(textfield); | |
| 134 | 196 |
| 197 container->AddChildView(textfield); |
| 198 widget->SetContentsView(container); |
| 199 |
| 200 // The textfield initially contains no text, so shift its position to be |
| 201 // outside the visible bounds of the screen. |
| 135 gfx::Transform transform; | 202 gfx::Transform transform; |
| 136 transform.Translate(0, -kTextFilterHeight); | 203 transform.Translate(0, -WindowSelector::kTextFilterBottomEdge); |
| 137 widget->GetNativeWindow()->SetTransform(transform); | 204 widget->GetNativeWindow()->SetTransform(transform); |
| 138 widget->Show(); | 205 widget->Show(); |
| 139 textfield->RequestFocus(); | 206 textfield->RequestFocus(); |
| 140 | 207 |
| 141 return widget; | 208 return widget; |
| 142 } | 209 } |
| 143 | 210 |
| 144 } // namespace | 211 } // namespace |
| 145 | 212 |
| 213 const int WindowSelector::kTextFilterBottomEdge = |
| 214 kTextFilterDistanceFromTop + kTextFilterHeight; |
| 215 |
| 146 WindowSelector::WindowSelector(const WindowList& windows, | 216 WindowSelector::WindowSelector(const WindowList& windows, |
| 147 WindowSelectorDelegate* delegate) | 217 WindowSelectorDelegate* delegate) |
| 148 : delegate_(delegate), | 218 : delegate_(delegate), |
| 149 restore_focus_window_(aura::client::GetFocusClient( | 219 restore_focus_window_(aura::client::GetFocusClient( |
| 150 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), | 220 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), |
| 151 ignore_activations_(false), | 221 ignore_activations_(false), |
| 152 selected_grid_index_(0), | 222 selected_grid_index_(0), |
| 153 overview_start_time_(base::Time::Now()), | 223 overview_start_time_(base::Time::Now()), |
| 154 num_key_presses_(0), | 224 num_key_presses_(0), |
| 155 num_items_(0), | 225 num_items_(0), |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 bool should_show_selection_widget = !new_contents.empty(); | 483 bool should_show_selection_widget = !new_contents.empty(); |
| 414 if (showing_selection_widget_ != should_show_selection_widget) { | 484 if (showing_selection_widget_ != should_show_selection_widget) { |
| 415 ui::ScopedLayerAnimationSettings animation_settings( | 485 ui::ScopedLayerAnimationSettings animation_settings( |
| 416 text_filter_widget_->GetNativeWindow()->layer()->GetAnimator()); | 486 text_filter_widget_->GetNativeWindow()->layer()->GetAnimator()); |
| 417 animation_settings.SetPreemptionStrategy( | 487 animation_settings.SetPreemptionStrategy( |
| 418 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 488 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 419 animation_settings.SetTweenType(showing_selection_widget_ ? | 489 animation_settings.SetTweenType(showing_selection_widget_ ? |
| 420 gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN); | 490 gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN); |
| 421 | 491 |
| 422 gfx::Transform transform; | 492 gfx::Transform transform; |
| 423 if (should_show_selection_widget) | 493 if (should_show_selection_widget) { |
| 424 transform.Translate(0, 0); | 494 transform.Translate(0, 0); |
| 425 else | 495 text_filter_widget_->GetNativeWindow()->layer()->SetOpacity(1); |
| 426 transform.Translate(0, -kTextFilterHeight); | 496 } else { |
| 497 transform.Translate(0, -kTextFilterBottomEdge); |
| 498 text_filter_widget_->GetNativeWindow()->layer()->SetOpacity(0); |
| 499 } |
| 427 | 500 |
| 428 text_filter_widget_->GetNativeWindow()->SetTransform(transform); | 501 text_filter_widget_->GetNativeWindow()->SetTransform(transform); |
| 429 showing_selection_widget_ = should_show_selection_widget; | 502 showing_selection_widget_ = should_show_selection_widget; |
| 430 } | 503 } |
| 431 for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); | 504 for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); |
| 432 iter != grid_list_.end(); iter++) { | 505 iter != grid_list_.end(); iter++) { |
| 433 (*iter)->FilterItems(new_contents); | 506 (*iter)->FilterItems(new_contents); |
| 434 } | 507 } |
| 435 | 508 |
| 436 // If the selection widget is not active, execute a Move() command so that it | 509 // If the selection widget is not active, execute a Move() command so that it |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 for (size_t i = 0; | 581 for (size_t i = 0; |
| 509 i <= grid_list_.size() && | 582 i <= grid_list_.size() && |
| 510 grid_list_[selected_grid_index_]->Move(direction, animate); i++) { | 583 grid_list_[selected_grid_index_]->Move(direction, animate); i++) { |
| 511 // TODO(flackr): If there are more than two monitors, move between grids | 584 // TODO(flackr): If there are more than two monitors, move between grids |
| 512 // in the requested direction. | 585 // in the requested direction. |
| 513 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); | 586 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); |
| 514 } | 587 } |
| 515 } | 588 } |
| 516 | 589 |
| 517 } // namespace ash | 590 } // namespace ash |
| OLD | NEW |