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

Side by Side Diff: ash/common/wm/overview/window_selector.cc

Issue 2087153003: Moves common code in ash/wm/overview to ash/common/wm/overview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
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/common/wm/overview/window_selector.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/common/accessibility_delegate.h" 13 #include "ash/common/accessibility_delegate.h"
14 #include "ash/common/accessibility_types.h" 14 #include "ash/common/accessibility_types.h"
15 #include "ash/common/ash_switches.h" 15 #include "ash/common/ash_switches.h"
16 #include "ash/common/material_design/material_design_controller.h" 16 #include "ash/common/material_design/material_design_controller.h"
17 #include "ash/common/metrics/user_metrics_action.h" 17 #include "ash/common/metrics/user_metrics_action.h"
18 #include "ash/common/shelf/wm_shelf.h" 18 #include "ash/common/shelf/wm_shelf.h"
19 #include "ash/common/shell_window_ids.h" 19 #include "ash/common/shell_window_ids.h"
20 #include "ash/common/wm/mru_window_tracker.h" 20 #include "ash/common/wm/mru_window_tracker.h"
21 #include "ash/common/wm/overview/window_grid.h"
22 #include "ash/common/wm/overview/window_selector_delegate.h"
23 #include "ash/common/wm/overview/window_selector_item.h"
21 #include "ash/common/wm/panels/panel_layout_manager.h" 24 #include "ash/common/wm/panels/panel_layout_manager.h"
22 #include "ash/common/wm/switchable_windows.h" 25 #include "ash/common/wm/switchable_windows.h"
23 #include "ash/common/wm/window_state.h" 26 #include "ash/common/wm/window_state.h"
24 #include "ash/common/wm/wm_screen_util.h" 27 #include "ash/common/wm/wm_screen_util.h"
25 #include "ash/common/wm_lookup.h" 28 #include "ash/common/wm_lookup.h"
26 #include "ash/common/wm_root_window_controller.h" 29 #include "ash/common/wm_root_window_controller.h"
27 #include "ash/common/wm_shell.h" 30 #include "ash/common/wm_shell.h"
28 #include "ash/common/wm_window.h" 31 #include "ash/common/wm_window.h"
29 #include "ash/wm/overview/window_grid.h"
30 #include "ash/wm/overview/window_selector_delegate.h"
31 #include "ash/wm/overview/window_selector_item.h"
32 #include "base/auto_reset.h" 32 #include "base/auto_reset.h"
33 #include "base/command_line.h" 33 #include "base/command_line.h"
34 #include "base/metrics/histogram.h" 34 #include "base/metrics/histogram.h"
35 #include "third_party/skia/include/core/SkPaint.h" 35 #include "third_party/skia/include/core/SkPaint.h"
36 #include "third_party/skia/include/core/SkPath.h" 36 #include "third_party/skia/include/core/SkPath.h"
37 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
38 #include "ui/compositor/scoped_layer_animation_settings.h" 38 #include "ui/compositor/scoped_layer_animation_settings.h"
39 #include "ui/display/screen.h" 39 #include "ui/display/screen.h"
40 #include "ui/events/event.h" 40 #include "ui/events/event.h"
41 #include "ui/gfx/canvas.h" 41 #include "ui/gfx/canvas.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const WmWindow* root_window; 131 const WmWindow* root_window;
132 }; 132 };
133 133
134 // A View having rounded corners and a specified background color which is 134 // A View having rounded corners and a specified background color which is
135 // only painted within the bounds defined by the rounded corners. 135 // only painted within the bounds defined by the rounded corners.
136 // TODO(tdanderson): This duplicates code from RoundedImageView. Refactor these 136 // TODO(tdanderson): This duplicates code from RoundedImageView. Refactor these
137 // classes and move into ui/views. 137 // classes and move into ui/views.
138 class RoundedContainerView : public views::View { 138 class RoundedContainerView : public views::View {
139 public: 139 public:
140 RoundedContainerView(int corner_radius, SkColor background) 140 RoundedContainerView(int corner_radius, SkColor background)
141 : corner_radius_(corner_radius), 141 : corner_radius_(corner_radius), background_(background) {}
142 background_(background) {
143 }
144 142
145 ~RoundedContainerView() override {} 143 ~RoundedContainerView() override {}
146 144
147 void OnPaint(gfx::Canvas* canvas) override { 145 void OnPaint(gfx::Canvas* canvas) override {
148 views::View::OnPaint(canvas); 146 views::View::OnPaint(canvas);
149 147
150 SkScalar radius = SkIntToScalar(corner_radius_); 148 SkScalar radius = SkIntToScalar(corner_radius_);
151 const SkScalar kRadius[8] = {radius, radius, radius, radius, 149 const SkScalar kRadius[8] = {radius, radius, radius, radius,
152 radius, radius, radius, radius}; 150 radius, radius, radius, radius};
153 SkPath path; 151 SkPath path;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 404
407 // Record metrics related to text filtering. 405 // Record metrics related to text filtering.
408 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.TextFilteringStringLength", 406 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.TextFilteringStringLength",
409 text_filter_string_length_); 407 text_filter_string_length_);
410 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.TextFilteringTextfieldCleared", 408 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.TextFilteringTextfieldCleared",
411 num_times_textfield_cleared_); 409 num_times_textfield_cleared_);
412 if (text_filter_string_length_) { 410 if (text_filter_string_length_) {
413 UMA_HISTOGRAM_MEDIUM_TIMES( 411 UMA_HISTOGRAM_MEDIUM_TIMES(
414 "Ash.WindowSelector.TimeInOverviewWithTextFiltering", 412 "Ash.WindowSelector.TimeInOverviewWithTextFiltering",
415 base::Time::Now() - overview_start_time_); 413 base::Time::Now() - overview_start_time_);
416 UMA_HISTOGRAM_COUNTS_100( 414 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ItemsWhenTextFilteringUsed",
417 "Ash.WindowSelector.ItemsWhenTextFilteringUsed", 415 remaining_items);
418 remaining_items);
419 } 416 }
420 417
421 // Clearing the window list resets the ignored_by_shelf flag on the windows. 418 // Clearing the window list resets the ignored_by_shelf flag on the windows.
422 grid_list_.clear(); 419 grid_list_.clear();
423 UpdateShelfVisibility(); 420 UpdateShelfVisibility();
424 } 421 }
425 422
426 void WindowSelector::RemoveAllObservers() { 423 void WindowSelector::RemoveAllObservers() {
427 for (WmWindow* window : observed_windows_) 424 for (WmWindow* window : observed_windows_)
428 window->RemoveObserver(this); 425 window->RemoveObserver(this);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 case ui::VKEY_LEFT: 493 case ui::VKEY_LEFT:
497 num_key_presses_++; 494 num_key_presses_++;
498 Move(WindowSelector::LEFT, true); 495 Move(WindowSelector::LEFT, true);
499 break; 496 break;
500 case ui::VKEY_RETURN: 497 case ui::VKEY_RETURN:
501 // Ignore if no item is selected. 498 // Ignore if no item is selected.
502 if (!grid_list_[selected_grid_index_]->is_selecting()) 499 if (!grid_list_[selected_grid_index_]->is_selecting())
503 return false; 500 return false;
504 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ArrowKeyPresses", 501 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ArrowKeyPresses",
505 num_key_presses_); 502 num_key_presses_);
506 UMA_HISTOGRAM_CUSTOM_COUNTS( 503 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.WindowSelector.KeyPressesOverItemsRatio",
507 "Ash.WindowSelector.KeyPressesOverItemsRatio", 504 (num_key_presses_ * 100) / num_items_, 1, 300,
508 (num_key_presses_ * 100) / num_items_, 1, 300, 30); 505 30);
509 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_ENTER_KEY); 506 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_ENTER_KEY);
510 SelectWindow( 507 SelectWindow(
511 grid_list_[selected_grid_index_]->SelectedWindow()->GetWindow()); 508 grid_list_[selected_grid_index_]->SelectedWindow()->GetWindow());
512 break; 509 break;
513 default: 510 default:
514 // Not a key we are interested in, allow the textfield to handle it. 511 // Not a key we are interested in, allow the textfield to handle it.
515 return false; 512 return false;
516 } 513 }
517 return true; 514 return true;
518 } 515 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (!text_filter_string_length_) 593 if (!text_filter_string_length_)
597 num_times_textfield_cleared_++; 594 num_times_textfield_cleared_++;
598 595
599 bool should_show_selection_widget = !new_contents.empty(); 596 bool should_show_selection_widget = !new_contents.empty();
600 if (showing_selection_widget_ != should_show_selection_widget) { 597 if (showing_selection_widget_ != should_show_selection_widget) {
601 WmWindow* text_filter_widget_window = GetTextFilterWidgetWindow(); 598 WmWindow* text_filter_widget_window = GetTextFilterWidgetWindow();
602 ui::ScopedLayerAnimationSettings animation_settings( 599 ui::ScopedLayerAnimationSettings animation_settings(
603 text_filter_widget_window->GetLayer()->GetAnimator()); 600 text_filter_widget_window->GetLayer()->GetAnimator());
604 animation_settings.SetPreemptionStrategy( 601 animation_settings.SetPreemptionStrategy(
605 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 602 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
606 animation_settings.SetTweenType(showing_selection_widget_ ? 603 animation_settings.SetTweenType(showing_selection_widget_
607 gfx::Tween::FAST_OUT_LINEAR_IN : gfx::Tween::LINEAR_OUT_SLOW_IN); 604 ? gfx::Tween::FAST_OUT_LINEAR_IN
605 : gfx::Tween::LINEAR_OUT_SLOW_IN);
608 606
609 gfx::Transform transform; 607 gfx::Transform transform;
610 if (should_show_selection_widget) { 608 if (should_show_selection_widget) {
611 transform.Translate(0, 0); 609 transform.Translate(0, 0);
612 text_filter_widget_window->SetOpacity(1); 610 text_filter_widget_window->SetOpacity(1);
613 } else { 611 } else {
614 transform.Translate(0, -text_filter_bottom_); 612 transform.Translate(0, -text_filter_bottom_);
615 text_filter_widget_window->SetOpacity(0); 613 text_filter_widget_window->SetOpacity(0);
616 } 614 }
617 615
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 void WindowSelector::ResetFocusRestoreWindow(bool focus) { 650 void WindowSelector::ResetFocusRestoreWindow(bool focus) {
653 if (!restore_focus_window_) 651 if (!restore_focus_window_)
654 return; 652 return;
655 if (focus) { 653 if (focus) {
656 base::AutoReset<bool> restoring_focus(&ignore_activations_, true); 654 base::AutoReset<bool> restoring_focus(&ignore_activations_, true);
657 restore_focus_window_->Activate(); 655 restore_focus_window_->Activate();
658 } 656 }
659 // If the window is in the observed_windows_ list it needs to continue to be 657 // If the window is in the observed_windows_ list it needs to continue to be
660 // observed. 658 // observed.
661 if (observed_windows_.find(restore_focus_window_) == 659 if (observed_windows_.find(restore_focus_window_) ==
662 observed_windows_.end()) { 660 observed_windows_.end()) {
663 restore_focus_window_->RemoveObserver(this); 661 restore_focus_window_->RemoveObserver(this);
664 } 662 }
665 restore_focus_window_ = nullptr; 663 restore_focus_window_ = nullptr;
666 } 664 }
667 665
668 void WindowSelector::Move(Direction direction, bool animate) { 666 void WindowSelector::Move(Direction direction, bool animate) {
669 // Direction to move if moving past the end of a display. 667 // Direction to move if moving past the end of a display.
670 int display_direction = (direction == RIGHT || direction == DOWN) ? 1 : -1; 668 int display_direction = (direction == RIGHT || direction == DOWN) ? 1 : -1;
671 669
672 // If this is the first move and it's going backwards, start on the last 670 // If this is the first move and it's going backwards, start on the last
673 // display. 671 // display.
674 if (display_direction == -1 && !grid_list_.empty() && 672 if (display_direction == -1 && !grid_list_.empty() &&
675 !grid_list_[selected_grid_index_]->is_selecting()) { 673 !grid_list_[selected_grid_index_]->is_selecting()) {
676 selected_grid_index_ = grid_list_.size() - 1; 674 selected_grid_index_ = grid_list_.size() - 1;
677 } 675 }
678 676
679 // Keep calling Move() on the grids until one of them reports no overflow or 677 // Keep calling Move() on the grids until one of them reports no overflow or
680 // we made a full cycle on all the grids. 678 // we made a full cycle on all the grids.
681 for (size_t i = 0; 679 for (size_t i = 0; i <= grid_list_.size() &&
682 i <= grid_list_.size() && 680 grid_list_[selected_grid_index_]->Move(direction, animate);
683 grid_list_[selected_grid_index_]->Move(direction, animate); i++) { 681 i++) {
684 selected_grid_index_ = 682 selected_grid_index_ =
685 (selected_grid_index_ + display_direction + grid_list_.size()) % 683 (selected_grid_index_ + display_direction + grid_list_.size()) %
686 grid_list_.size(); 684 grid_list_.size();
687 } 685 }
688 } 686 }
689 687
690 } // namespace ash 688 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector.h ('k') | ash/common/wm/overview/window_selector_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698