Chromium Code Reviews| 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 : background_(background) { | |
| 119 for (int i = 0; i < 4; ++i) | |
| 120 corner_radius_[i] = corner_radius; | |
|
flackr
2014/08/08 17:43:59
nit: As long as these are all the same, we should
tdanderson
2014/08/08 19:25:44
Done.
| |
| 121 } | |
| 122 | |
| 123 virtual ~RoundedContainerView() {} | |
| 124 | |
| 125 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 126 views::View::OnPaint(canvas); | |
| 127 | |
| 128 const SkScalar kRadius[8] = { | |
| 129 SkIntToScalar(corner_radius_[0]), SkIntToScalar(corner_radius_[0]), | |
| 130 SkIntToScalar(corner_radius_[1]), SkIntToScalar(corner_radius_[1]), | |
| 131 SkIntToScalar(corner_radius_[2]), SkIntToScalar(corner_radius_[2]), | |
| 132 SkIntToScalar(corner_radius_[3]), SkIntToScalar(corner_radius_[3])}; | |
| 133 | |
| 134 SkPath path; | |
| 135 gfx::Rect bounds(size()); | |
| 136 path.addRoundRect(gfx::RectToSkRect(bounds), kRadius); | |
| 137 | |
| 138 SkPaint paint; | |
| 139 paint.setAntiAlias(true); | |
| 140 canvas->ClipPath(path, true); | |
| 141 canvas->DrawColor(background_); | |
| 142 } | |
| 143 | |
| 144 private: | |
| 145 int corner_radius_[4]; | |
| 146 SkColor background_; | |
| 147 | |
| 148 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); | |
| 149 }; | |
| 150 | |
| 97 // Triggers a shelf visibility update on all root window controllers. | 151 // Triggers a shelf visibility update on all root window controllers. |
| 98 void UpdateShelfVisibility() { | 152 void UpdateShelfVisibility() { |
| 99 Shell::RootWindowControllerList root_window_controllers = | 153 Shell::RootWindowControllerList root_window_controllers = |
| 100 Shell::GetInstance()->GetAllRootWindowControllers(); | 154 Shell::GetInstance()->GetAllRootWindowControllers(); |
| 101 for (Shell::RootWindowControllerList::iterator iter = | 155 for (Shell::RootWindowControllerList::iterator iter = |
| 102 root_window_controllers.begin(); | 156 root_window_controllers.begin(); |
| 103 iter != root_window_controllers.end(); ++iter) { | 157 iter != root_window_controllers.end(); ++iter) { |
| 104 (*iter)->UpdateShelfVisibility(); | 158 (*iter)->UpdateShelfVisibility(); |
| 105 } | 159 } |
| 106 } | 160 } |
| 107 | 161 |
| 108 // Initializes the text filter on the top of the main root window and requests | 162 // Initializes the text filter on the top of the main root window and requests |
| 109 // focus on its textfield. | 163 // focus on its textfield. |
| 110 views::Widget* CreateTextFilter(views::TextfieldController* controller, | 164 views::Widget* CreateTextFilter(views::TextfieldController* controller, |
| 111 aura::Window* root_window) { | 165 aura::Window* root_window) { |
| 112 views::Widget* widget = new views::Widget; | 166 views::Widget* widget = new views::Widget; |
| 113 views::Widget::InitParams params; | 167 views::Widget::InitParams params; |
| 114 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 168 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 115 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 169 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 116 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 170 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 117 params.parent = | 171 params.parent = |
| 118 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); | 172 Shell::GetContainer(root_window, ash::kShellWindowId_OverlayContainer); |
| 119 params.accept_events = true; | 173 params.accept_events = true; |
| 120 params.bounds = gfx::Rect( | 174 params.bounds = gfx::Rect( |
| 121 root_window->bounds().width() / 2 * (1 - kTextFilterScreenProportion), 0, | 175 root_window->bounds().width() / 2 * (1 - kTextFilterScreenProportion), |
| 176 kTextFilterDistanceFromTop, | |
| 122 root_window->bounds().width() * kTextFilterScreenProportion, | 177 root_window->bounds().width() * kTextFilterScreenProportion, |
| 123 kTextFilterHeight); | 178 kTextFilterHeight); |
| 124 widget->Init(params); | 179 widget->Init(params); |
| 125 | 180 |
| 181 // Use |container| to specify the padding surrounding the text and to give | |
| 182 // the textfield rounded corners. | |
| 183 views::View* container = new RoundedContainerView( | |
| 184 kTextFilterCornerRadius, SkColorSetARGB(kTextFilterOpacity, 0, 0, 0)); | |
| 185 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 186 int text_height = bundle.GetFontList(kTextFilterFontStyle).GetHeight(); | |
| 187 DCHECK(text_height); | |
| 188 int vertical_padding = (kTextFilterHeight - text_height) / 2; | |
| 189 container->SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | |
| 190 kTextFilterHorizontalPadding, | |
| 191 vertical_padding, | |
| 192 0)); | |
| 193 | |
| 126 views::Textfield* textfield = new views::Textfield; | 194 views::Textfield* textfield = new views::Textfield; |
| 127 textfield->set_controller(controller); | 195 textfield->set_controller(controller); |
| 128 textfield->SetBackgroundColor(SK_ColorTRANSPARENT); | 196 textfield->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 129 textfield->SetBorder(views::Border::NullBorder()); | 197 textfield->SetBorder(views::Border::NullBorder()); |
| 130 textfield->SetTextColor(SK_ColorWHITE); | 198 textfield->SetTextColor(SK_ColorWHITE); |
| 131 textfield->SetShadows(gfx::ShadowValues(1, gfx::ShadowValue( | 199 textfield->SetFontList(bundle.GetFontList(kTextFilterFontStyle)); |
| 132 gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kTextFilterShadow))); | |
| 133 widget->SetContentsView(textfield); | |
| 134 | 200 |
| 201 container->AddChildView(textfield); | |
| 202 widget->SetContentsView(container); | |
| 203 | |
| 204 // The textfield initially contains no text, so shift its position to be | |
| 205 // outside the visible bounds of the screen. | |
| 135 gfx::Transform transform; | 206 gfx::Transform transform; |
| 136 transform.Translate(0, -kTextFilterHeight); | 207 transform.Translate(0, -WindowSelector::kTextFilterBottomEdge); |
| 137 widget->GetNativeWindow()->SetTransform(transform); | 208 widget->GetNativeWindow()->SetTransform(transform); |
| 138 widget->Show(); | 209 widget->Show(); |
| 139 textfield->RequestFocus(); | 210 textfield->RequestFocus(); |
| 140 | 211 |
| 141 return widget; | 212 return widget; |
| 142 } | 213 } |
| 143 | 214 |
| 144 } // namespace | 215 } // namespace |
| 145 | 216 |
| 217 const int WindowSelector::kTextFilterBottomEdge = | |
| 218 kTextFilterDistanceFromTop + kTextFilterHeight; | |
| 219 | |
| 146 WindowSelector::WindowSelector(const WindowList& windows, | 220 WindowSelector::WindowSelector(const WindowList& windows, |
| 147 WindowSelectorDelegate* delegate) | 221 WindowSelectorDelegate* delegate) |
| 148 : delegate_(delegate), | 222 : delegate_(delegate), |
| 149 restore_focus_window_(aura::client::GetFocusClient( | 223 restore_focus_window_(aura::client::GetFocusClient( |
| 150 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), | 224 Shell::GetPrimaryRootWindow())->GetFocusedWindow()), |
| 151 ignore_activations_(false), | 225 ignore_activations_(false), |
| 152 selected_grid_index_(0), | 226 selected_grid_index_(0), |
| 153 overview_start_time_(base::Time::Now()), | 227 overview_start_time_(base::Time::Now()), |
| 154 num_key_presses_(0), | 228 num_key_presses_(0), |
| 155 num_items_(0), | 229 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(); | 487 bool should_show_selection_widget = !new_contents.empty(); |
| 414 if (showing_selection_widget_ != should_show_selection_widget) { | 488 if (showing_selection_widget_ != should_show_selection_widget) { |
| 415 ui::ScopedLayerAnimationSettings animation_settings( | 489 ui::ScopedLayerAnimationSettings animation_settings( |
| 416 text_filter_widget_->GetNativeWindow()->layer()->GetAnimator()); | 490 text_filter_widget_->GetNativeWindow()->layer()->GetAnimator()); |
| 417 animation_settings.SetPreemptionStrategy( | 491 animation_settings.SetPreemptionStrategy( |
| 418 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 492 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 419 animation_settings.SetTweenType(showing_selection_widget_ ? | 493 animation_settings.SetTweenType(showing_selection_widget_ ? |
| 420 gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN); | 494 gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN); |
| 421 | 495 |
| 422 gfx::Transform transform; | 496 gfx::Transform transform; |
| 423 if (should_show_selection_widget) | 497 if (should_show_selection_widget) { |
| 424 transform.Translate(0, 0); | 498 transform.Translate(0, 0); |
| 425 else | 499 text_filter_widget_->GetNativeWindow()->layer()->SetOpacity(1); |
| 426 transform.Translate(0, -kTextFilterHeight); | 500 } else { |
| 501 transform.Translate(0, -kTextFilterBottomEdge); | |
| 502 text_filter_widget_->GetNativeWindow()->layer()->SetOpacity(0); | |
| 503 } | |
| 427 | 504 |
| 428 text_filter_widget_->GetNativeWindow()->SetTransform(transform); | 505 text_filter_widget_->GetNativeWindow()->SetTransform(transform); |
| 429 showing_selection_widget_ = should_show_selection_widget; | 506 showing_selection_widget_ = should_show_selection_widget; |
| 430 } | 507 } |
| 431 for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); | 508 for (ScopedVector<WindowGrid>::iterator iter = grid_list_.begin(); |
| 432 iter != grid_list_.end(); iter++) { | 509 iter != grid_list_.end(); iter++) { |
| 433 (*iter)->FilterItems(new_contents); | 510 (*iter)->FilterItems(new_contents); |
| 434 } | 511 } |
| 435 | 512 |
| 436 // If the selection widget is not active, execute a Move() command so that it | 513 // 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; | 585 for (size_t i = 0; |
| 509 i <= grid_list_.size() && | 586 i <= grid_list_.size() && |
| 510 grid_list_[selected_grid_index_]->Move(direction, animate); i++) { | 587 grid_list_[selected_grid_index_]->Move(direction, animate); i++) { |
| 511 // TODO(flackr): If there are more than two monitors, move between grids | 588 // TODO(flackr): If there are more than two monitors, move between grids |
| 512 // in the requested direction. | 589 // in the requested direction. |
| 513 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); | 590 selected_grid_index_ = (selected_grid_index_ + 1) % grid_list_.size(); |
| 514 } | 591 } |
| 515 } | 592 } |
| 516 | 593 |
| 517 } // namespace ash | 594 } // namespace ash |
| OLD | NEW |