| 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/common/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/metrics/user_metrics_action.h" | 15 #include "ash/common/metrics/user_metrics_action.h" |
| 16 #include "ash/common/shelf/wm_shelf.h" | 16 #include "ash/common/shelf/wm_shelf.h" |
| 17 #include "ash/common/wm/mru_window_tracker.h" | 17 #include "ash/common/wm/mru_window_tracker.h" |
| 18 #include "ash/common/wm/overview/window_grid.h" | 18 #include "ash/common/wm/overview/window_grid.h" |
| 19 #include "ash/common/wm/overview/window_selector_delegate.h" | 19 #include "ash/common/wm/overview/window_selector_delegate.h" |
| 20 #include "ash/common/wm/overview/window_selector_item.h" | 20 #include "ash/common/wm/overview/window_selector_item.h" |
| 21 #include "ash/common/wm/panels/panel_layout_manager.h" | 21 #include "ash/common/wm/panels/panel_layout_manager.h" |
| 22 #include "ash/common/wm/switchable_windows.h" | 22 #include "ash/common/wm/switchable_windows.h" |
| 23 #include "ash/common/wm/window_state.h" | 23 #include "ash/common/wm/window_state.h" |
| 24 #include "ash/common/wm/wm_screen_util.h" | 24 #include "ash/common/wm/wm_screen_util.h" |
| 25 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
| 26 #include "ash/common/wm_window.h" | 26 #include "ash/common/wm_window.h" |
| 27 #include "ash/public/cpp/shell_window_ids.h" | 27 #include "ash/public/cpp/shell_window_ids.h" |
| 28 #include "ash/root_window_controller.h" | 28 #include "ash/root_window_controller.h" |
| 29 #include "ash/shell.h" |
| 29 #include "base/auto_reset.h" | 30 #include "base/auto_reset.h" |
| 30 #include "base/command_line.h" | 31 #include "base/command_line.h" |
| 31 #include "base/metrics/histogram_macros.h" | 32 #include "base/metrics/histogram_macros.h" |
| 32 #include "third_party/skia/include/core/SkPath.h" | 33 #include "third_party/skia/include/core/SkPath.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/compositor/scoped_layer_animation_settings.h" | 35 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 35 #include "ui/display/screen.h" | 36 #include "ui/display/screen.h" |
| 36 #include "ui/events/event.h" | 37 #include "ui/events/event.h" |
| 37 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
| 38 #include "ui/gfx/paint_vector_icon.h" | 39 #include "ui/gfx/paint_vector_icon.h" |
| 39 #include "ui/gfx/skia_util.h" | 40 #include "ui/gfx/skia_util.h" |
| 40 #include "ui/gfx/vector_icons_public.h" | 41 #include "ui/gfx/vector_icons_public.h" |
| 41 #include "ui/views/border.h" | 42 #include "ui/views/border.h" |
| 42 #include "ui/views/controls/image_view.h" | 43 #include "ui/views/controls/image_view.h" |
| 43 #include "ui/views/controls/textfield/textfield.h" | 44 #include "ui/views/controls/textfield/textfield.h" |
| 44 #include "ui/views/layout/box_layout.h" | 45 #include "ui/views/layout/box_layout.h" |
| 46 #include "ui/wm/public/activation_client.h" |
| 45 | 47 |
| 46 namespace ash { | 48 namespace ash { |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| 50 // The amount of padding surrounding the text in the text filtering textbox. | 52 // The amount of padding surrounding the text in the text filtering textbox. |
| 51 const int kTextFilterHorizontalPadding = 10; | 53 const int kTextFilterHorizontalPadding = 10; |
| 52 | 54 |
| 53 // The height of the text filtering textbox. | 55 // The height of the text filtering textbox. |
| 54 const int kTextFilterHeight = 40; | 56 const int kTextFilterHeight = 40; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, | 299 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, |
| 298 kTextFilterIconSize, kTextFilterIconColor); | 300 kTextFilterIconSize, kTextFilterIconColor); |
| 299 WmWindow* root_window = shell->GetPrimaryRootWindow(); | 301 WmWindow* root_window = shell->GetPrimaryRootWindow(); |
| 300 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, | 302 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, |
| 301 &text_filter_bottom_)); | 303 &text_filter_bottom_)); |
| 302 } | 304 } |
| 303 | 305 |
| 304 DCHECK(!grid_list_.empty()); | 306 DCHECK(!grid_list_.empty()); |
| 305 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); | 307 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); |
| 306 | 308 |
| 307 shell->AddActivationObserver(this); | 309 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 308 | 310 |
| 309 display::Screen::GetScreen()->AddObserver(this); | 311 display::Screen::GetScreen()->AddObserver(this); |
| 310 shell->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); | 312 shell->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
| 311 // Send an a11y alert. | 313 // Send an a11y alert. |
| 312 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( | 314 WmShell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( |
| 313 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); | 315 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); |
| 314 | 316 |
| 315 UpdateShelfVisibility(); | 317 UpdateShelfVisibility(); |
| 316 } | 318 } |
| 317 | 319 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 368 |
| 367 // Clearing the window list resets the ignored_by_shelf flag on the windows. | 369 // Clearing the window list resets the ignored_by_shelf flag on the windows. |
| 368 grid_list_.clear(); | 370 grid_list_.clear(); |
| 369 UpdateShelfVisibility(); | 371 UpdateShelfVisibility(); |
| 370 } | 372 } |
| 371 | 373 |
| 372 void WindowSelector::RemoveAllObservers() { | 374 void WindowSelector::RemoveAllObservers() { |
| 373 for (WmWindow* window : observed_windows_) | 375 for (WmWindow* window : observed_windows_) |
| 374 window->aura_window()->RemoveObserver(this); | 376 window->aura_window()->RemoveObserver(this); |
| 375 | 377 |
| 376 WmShell::Get()->RemoveActivationObserver(this); | 378 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 377 display::Screen::GetScreen()->RemoveObserver(this); | 379 display::Screen::GetScreen()->RemoveObserver(this); |
| 378 if (restore_focus_window_) | 380 if (restore_focus_window_) |
| 379 restore_focus_window_->aura_window()->RemoveObserver(this); | 381 restore_focus_window_->aura_window()->RemoveObserver(this); |
| 380 } | 382 } |
| 381 | 383 |
| 382 void WindowSelector::CancelSelection() { | 384 void WindowSelector::CancelSelection() { |
| 383 delegate_->OnSelectionEnded(); | 385 delegate_->OnSelectionEnded(); |
| 384 } | 386 } |
| 385 | 387 |
| 386 void WindowSelector::OnGridEmpty(WindowGrid* grid) { | 388 void WindowSelector::OnGridEmpty(WindowGrid* grid) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 } | 539 } |
| 538 } | 540 } |
| 539 | 541 |
| 540 void WindowSelector::OnWindowDestroying(aura::Window* window) { | 542 void WindowSelector::OnWindowDestroying(aura::Window* window) { |
| 541 window->RemoveObserver(this); | 543 window->RemoveObserver(this); |
| 542 observed_windows_.erase(WmWindow::Get(window)); | 544 observed_windows_.erase(WmWindow::Get(window)); |
| 543 if (WmWindow::Get(window) == restore_focus_window_) | 545 if (WmWindow::Get(window) == restore_focus_window_) |
| 544 restore_focus_window_ = nullptr; | 546 restore_focus_window_ = nullptr; |
| 545 } | 547 } |
| 546 | 548 |
| 547 void WindowSelector::OnWindowActivated(WmWindow* gained_active, | 549 void WindowSelector::OnWindowActivated(ActivationReason reason, |
| 548 WmWindow* lost_active) { | 550 aura::Window* gained_active, |
| 549 if (ignore_activations_ || !gained_active || | 551 aura::Window* lost_active) { |
| 550 gained_active == GetTextFilterWidgetWindow()) { | 552 WmWindow* wm_gained_active = WmWindow::Get(gained_active); |
| 553 if (ignore_activations_ || !wm_gained_active || |
| 554 wm_gained_active == GetTextFilterWidgetWindow()) { |
| 551 return; | 555 return; |
| 552 } | 556 } |
| 553 | 557 |
| 554 WmWindow* root_window = gained_active->GetRootWindow(); | 558 WmWindow* root_window = wm_gained_active->GetRootWindow(); |
| 555 auto grid = | 559 auto grid = |
| 556 std::find_if(grid_list_.begin(), grid_list_.end(), | 560 std::find_if(grid_list_.begin(), grid_list_.end(), |
| 557 [root_window](const std::unique_ptr<WindowGrid>& grid) { | 561 [root_window](const std::unique_ptr<WindowGrid>& grid) { |
| 558 return grid->root_window() == root_window; | 562 return grid->root_window() == root_window; |
| 559 }); | 563 }); |
| 560 if (grid == grid_list_.end()) | 564 if (grid == grid_list_.end()) |
| 561 return; | 565 return; |
| 562 const auto& windows = (*grid)->window_list(); | 566 const auto& windows = (*grid)->window_list(); |
| 563 | 567 |
| 564 auto iter = std::find_if( | 568 auto iter = std::find_if( |
| 565 windows.begin(), windows.end(), | 569 windows.begin(), windows.end(), |
| 566 [gained_active](const std::unique_ptr<WindowSelectorItem>& window) { | 570 [wm_gained_active](const std::unique_ptr<WindowSelectorItem>& window) { |
| 567 return window->Contains(gained_active); | 571 return window->Contains(wm_gained_active); |
| 568 }); | 572 }); |
| 569 | 573 |
| 570 if (iter == windows.end() && showing_text_filter_ && | 574 if (iter == windows.end() && showing_text_filter_ && |
| 571 lost_active == GetTextFilterWidgetWindow()) { | 575 WmWindow::Get(lost_active) == GetTextFilterWidgetWindow()) { |
| 572 return; | 576 return; |
| 573 } | 577 } |
| 574 | 578 |
| 575 // Don't restore focus on exit if a window was just activated. | 579 // Don't restore focus on exit if a window was just activated. |
| 576 ResetFocusRestoreWindow(false); | 580 ResetFocusRestoreWindow(false); |
| 577 CancelSelection(); | 581 CancelSelection(); |
| 578 } | 582 } |
| 579 | 583 |
| 580 void WindowSelector::OnAttemptToReactivateWindow(WmWindow* request_active, | 584 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active, |
| 581 WmWindow* actual_active) { | 585 aura::Window* actual_active) { |
| 582 OnWindowActivated(request_active, actual_active); | 586 OnWindowActivated(ActivationReason::ACTIVATION_CLIENT, request_active, |
| 587 actual_active); |
| 583 } | 588 } |
| 584 | 589 |
| 585 void WindowSelector::ContentsChanged(views::Textfield* sender, | 590 void WindowSelector::ContentsChanged(views::Textfield* sender, |
| 586 const base::string16& new_contents) { | 591 const base::string16& new_contents) { |
| 587 text_filter_string_length_ = new_contents.length(); | 592 text_filter_string_length_ = new_contents.length(); |
| 588 if (!text_filter_string_length_) | 593 if (!text_filter_string_length_) |
| 589 num_times_textfield_cleared_++; | 594 num_times_textfield_cleared_++; |
| 590 | 595 |
| 591 bool should_show_text_filter = !new_contents.empty(); | 596 bool should_show_text_filter = !new_contents.empty(); |
| 592 if (showing_text_filter_ != should_show_text_filter) { | 597 if (showing_text_filter_ != should_show_text_filter) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 for (size_t i = 0; i <= grid_list_.size() && | 681 for (size_t i = 0; i <= grid_list_.size() && |
| 677 grid_list_[selected_grid_index_]->Move(direction, animate); | 682 grid_list_[selected_grid_index_]->Move(direction, animate); |
| 678 i++) { | 683 i++) { |
| 679 selected_grid_index_ = | 684 selected_grid_index_ = |
| 680 (selected_grid_index_ + display_direction + grid_list_.size()) % | 685 (selected_grid_index_ + display_direction + grid_list_.size()) % |
| 681 grid_list_.size(); | 686 grid_list_.size(); |
| 682 } | 687 } |
| 683 } | 688 } |
| 684 | 689 |
| 685 } // namespace ash | 690 } // namespace ash |
| OLD | NEW |