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 #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/accessibility_delegate.h" | 13 #include "ash/accessibility_delegate.h" |
14 #include "ash/accessibility_types.h" | 14 #include "ash/accessibility_types.h" |
15 #include "ash/metrics/user_metrics_action.h" | 15 #include "ash/metrics/user_metrics_action.h" |
16 #include "ash/public/cpp/shell_window_ids.h" | 16 #include "ash/public/cpp/shell_window_ids.h" |
17 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
18 #include "ash/shelf/wm_shelf.h" | 18 #include "ash/shelf/wm_shelf.h" |
19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 20 #include "ash/shell_port.h" |
20 #include "ash/wm/mru_window_tracker.h" | 21 #include "ash/wm/mru_window_tracker.h" |
21 #include "ash/wm/overview/window_grid.h" | 22 #include "ash/wm/overview/window_grid.h" |
22 #include "ash/wm/overview/window_selector_delegate.h" | 23 #include "ash/wm/overview/window_selector_delegate.h" |
23 #include "ash/wm/overview/window_selector_item.h" | 24 #include "ash/wm/overview/window_selector_item.h" |
24 #include "ash/wm/panels/panel_layout_manager.h" | 25 #include "ash/wm/panels/panel_layout_manager.h" |
25 #include "ash/wm/switchable_windows.h" | 26 #include "ash/wm/switchable_windows.h" |
26 #include "ash/wm/window_state.h" | 27 #include "ash/wm/window_state.h" |
27 #include "ash/wm/window_util.h" | 28 #include "ash/wm/window_util.h" |
28 #include "ash/wm/wm_screen_util.h" | 29 #include "ash/wm/wm_screen_util.h" |
29 #include "ash/wm_shell.h" | |
30 #include "ash/wm_window.h" | 30 #include "ash/wm_window.h" |
31 #include "base/auto_reset.h" | 31 #include "base/auto_reset.h" |
32 #include "base/command_line.h" | 32 #include "base/command_line.h" |
33 #include "base/metrics/histogram_macros.h" | 33 #include "base/metrics/histogram_macros.h" |
34 #include "third_party/skia/include/core/SkPath.h" | 34 #include "third_party/skia/include/core/SkPath.h" |
35 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/compositor/scoped_layer_animation_settings.h" | 36 #include "ui/compositor/scoped_layer_animation_settings.h" |
37 #include "ui/display/screen.h" | 37 #include "ui/display/screen.h" |
38 #include "ui/events/event.h" | 38 #include "ui/events/event.h" |
39 #include "ui/gfx/canvas.h" | 39 #include "ui/gfx/canvas.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 private: | 125 private: |
126 int corner_radius_; | 126 int corner_radius_; |
127 SkColor background_; | 127 SkColor background_; |
128 | 128 |
129 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); | 129 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); |
130 }; | 130 }; |
131 | 131 |
132 // Triggers a shelf visibility update on all root window controllers. | 132 // Triggers a shelf visibility update on all root window controllers. |
133 void UpdateShelfVisibility() { | 133 void UpdateShelfVisibility() { |
134 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) | 134 for (WmWindow* root : ShellPort::Get()->GetAllRootWindows()) |
135 WmShelf::ForWindow(root)->UpdateVisibilityState(); | 135 WmShelf::ForWindow(root)->UpdateVisibilityState(); |
136 } | 136 } |
137 | 137 |
138 gfx::Rect GetTextFilterPosition(WmWindow* root_window) { | 138 gfx::Rect GetTextFilterPosition(WmWindow* root_window) { |
139 gfx::Rect total_bounds = root_window->ConvertRectToScreen( | 139 gfx::Rect total_bounds = root_window->ConvertRectToScreen( |
140 wm::GetDisplayWorkAreaBoundsInParent(root_window->GetChildByShellWindowId( | 140 wm::GetDisplayWorkAreaBoundsInParent(root_window->GetChildByShellWindowId( |
141 kShellWindowId_DefaultContainer))); | 141 kShellWindowId_DefaultContainer))); |
142 return gfx::Rect( | 142 return gfx::Rect( |
143 0.5 * (total_bounds.width() - | 143 0.5 * (total_bounds.width() - |
144 std::min(kTextFilterWidth, total_bounds.width())), | 144 std::min(kTextFilterWidth, total_bounds.width())), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 RemoveAllObservers(); | 236 RemoveAllObservers(); |
237 } | 237 } |
238 | 238 |
239 // NOTE: The work done in Init() is not done in the constructor because it may | 239 // NOTE: The work done in Init() is not done in the constructor because it may |
240 // cause other, unrelated classes, (ie PanelLayoutManager) to make indirect | 240 // cause other, unrelated classes, (ie PanelLayoutManager) to make indirect |
241 // calls to restoring_minimized_windows() on a partially constructed object. | 241 // calls to restoring_minimized_windows() on a partially constructed object. |
242 void WindowSelector::Init(const WindowList& windows) { | 242 void WindowSelector::Init(const WindowList& windows) { |
243 if (restore_focus_window_) | 243 if (restore_focus_window_) |
244 restore_focus_window_->aura_window()->AddObserver(this); | 244 restore_focus_window_->aura_window()->AddObserver(this); |
245 | 245 |
246 WmShell* shell = WmShell::Get(); | 246 ShellPort* shell_port = ShellPort::Get(); |
247 | 247 |
248 std::vector<WmWindow*> root_windows = shell->GetAllRootWindows(); | 248 std::vector<WmWindow*> root_windows = shell_port->GetAllRootWindows(); |
249 std::sort(root_windows.begin(), root_windows.end(), | 249 std::sort(root_windows.begin(), root_windows.end(), |
250 [](const WmWindow* a, const WmWindow* b) { | 250 [](const WmWindow* a, const WmWindow* b) { |
251 // Since we don't know if windows are vertically or horizontally | 251 // Since we don't know if windows are vertically or horizontally |
252 // oriented we use both x and y position. This may be confusing | 252 // oriented we use both x and y position. This may be confusing |
253 // if you have 3 or more monitors which are not strictly | 253 // if you have 3 or more monitors which are not strictly |
254 // horizontal or vertical but that case is not yet supported. | 254 // horizontal or vertical but that case is not yet supported. |
255 return (a->GetBoundsInScreen().x() + a->GetBoundsInScreen().y()) < | 255 return (a->GetBoundsInScreen().x() + a->GetBoundsInScreen().y()) < |
256 (b->GetBoundsInScreen().x() + b->GetBoundsInScreen().y()); | 256 (b->GetBoundsInScreen().x() + b->GetBoundsInScreen().y()); |
257 }); | 257 }); |
258 | 258 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // Do not call PrepareForOverview until all items are added to window_list_ | 291 // Do not call PrepareForOverview until all items are added to window_list_ |
292 // as we don't want to cause any window updates until all windows in | 292 // as we don't want to cause any window updates until all windows in |
293 // overview are observed. See http://crbug.com/384495. | 293 // overview are observed. See http://crbug.com/384495. |
294 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { | 294 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { |
295 window_grid->PrepareForOverview(); | 295 window_grid->PrepareForOverview(); |
296 window_grid->PositionWindows(true); | 296 window_grid->PositionWindows(true); |
297 } | 297 } |
298 | 298 |
299 search_image_ = gfx::CreateVectorIcon(ui::kSearchIcon, kTextFilterIconSize, | 299 search_image_ = gfx::CreateVectorIcon(ui::kSearchIcon, kTextFilterIconSize, |
300 kTextFilterIconColor); | 300 kTextFilterIconColor); |
301 WmWindow* root_window = shell->GetPrimaryRootWindow(); | 301 WmWindow* root_window = shell_port->GetPrimaryRootWindow(); |
302 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, | 302 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, |
303 &text_filter_bottom_)); | 303 &text_filter_bottom_)); |
304 } | 304 } |
305 | 305 |
306 DCHECK(!grid_list_.empty()); | 306 DCHECK(!grid_list_.empty()); |
307 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); | 307 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); |
308 | 308 |
309 Shell::Get()->activation_client()->AddObserver(this); | 309 Shell::Get()->activation_client()->AddObserver(this); |
310 | 310 |
311 display::Screen::GetScreen()->AddObserver(this); | 311 display::Screen::GetScreen()->AddObserver(this); |
312 shell->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); | 312 shell_port->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
313 // Send an a11y alert. | 313 // Send an a11y alert. |
314 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( | 314 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( |
315 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); | 315 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); |
316 | 316 |
317 UpdateShelfVisibility(); | 317 UpdateShelfVisibility(); |
318 } | 318 } |
319 | 319 |
320 // NOTE: The work done in Shutdown() is not done in the destructor because it | 320 // NOTE: The work done in Shutdown() is not done in the destructor because it |
321 // may cause other, unrelated classes, (ie PanelLayoutManager) to make indirect | 321 // may cause other, unrelated classes, (ie PanelLayoutManager) to make indirect |
322 // calls to restoring_minimized_windows() on a partially destructed object. | 322 // calls to restoring_minimized_windows() on a partially destructed object. |
323 void WindowSelector::Shutdown() { | 323 void WindowSelector::Shutdown() { |
324 is_shut_down_ = true; | 324 is_shut_down_ = true; |
325 // Stop observing screen metrics changes first to avoid auto-positioning | 325 // Stop observing screen metrics changes first to avoid auto-positioning |
326 // windows in response to work area changes from window activation. | 326 // windows in response to work area changes from window activation. |
327 display::Screen::GetScreen()->RemoveObserver(this); | 327 display::Screen::GetScreen()->RemoveObserver(this); |
328 | 328 |
329 size_t remaining_items = 0; | 329 size_t remaining_items = 0; |
330 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { | 330 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { |
331 for (const auto& window_selector_item : window_grid->window_list()) | 331 for (const auto& window_selector_item : window_grid->window_list()) |
332 window_selector_item->RestoreWindow(); | 332 window_selector_item->RestoreWindow(); |
333 remaining_items += window_grid->size(); | 333 remaining_items += window_grid->size(); |
334 } | 334 } |
335 | 335 |
336 // Setting focus after restoring windows' state avoids unnecessary animations. | 336 // Setting focus after restoring windows' state avoids unnecessary animations. |
337 ResetFocusRestoreWindow(true); | 337 ResetFocusRestoreWindow(true); |
338 RemoveAllObservers(); | 338 RemoveAllObservers(); |
339 | 339 |
340 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows(); | 340 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows(); |
341 for (WmWindow* window : root_windows) { | 341 for (WmWindow* window : root_windows) { |
342 // Un-hide the callout widgets for panels. It is safe to call this for | 342 // Un-hide the callout widgets for panels. It is safe to call this for |
343 // root_windows that don't contain any panel windows. | 343 // root_windows that don't contain any panel windows. |
344 PanelLayoutManager::Get(window)->SetShowCalloutWidgets(true); | 344 PanelLayoutManager::Get(window)->SetShowCalloutWidgets(true); |
345 } | 345 } |
346 | 346 |
347 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) | 347 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) |
348 window_grid->Shutdown(); | 348 window_grid->Shutdown(); |
349 | 349 |
350 DCHECK(num_items_ >= remaining_items); | 350 DCHECK(num_items_ >= remaining_items); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 421 |
422 void WindowSelector::SelectWindow(WindowSelectorItem* item) { | 422 void WindowSelector::SelectWindow(WindowSelectorItem* item) { |
423 WmWindow* window = item->GetWindow(); | 423 WmWindow* window = item->GetWindow(); |
424 std::vector<WmWindow*> window_list = | 424 std::vector<WmWindow*> window_list = |
425 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); | 425 Shell::Get()->mru_window_tracker()->BuildMruWindowList(); |
426 if (!window_list.empty()) { | 426 if (!window_list.empty()) { |
427 // Record UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED if the user is selecting | 427 // Record UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED if the user is selecting |
428 // a window other than the window that was active prior to entering overview | 428 // a window other than the window that was active prior to entering overview |
429 // mode (i.e., the window at the front of the MRU list). | 429 // mode (i.e., the window at the front of the MRU list). |
430 if (window_list[0] != window) { | 430 if (window_list[0] != window) { |
431 WmShell::Get()->RecordUserMetricsAction( | 431 ShellPort::Get()->RecordUserMetricsAction( |
432 UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED); | 432 UMA_WINDOW_OVERVIEW_ACTIVE_WINDOW_CHANGED); |
433 } | 433 } |
434 const auto it = std::find(window_list.begin(), window_list.end(), window); | 434 const auto it = std::find(window_list.begin(), window_list.end(), window); |
435 if (it != window_list.end()) { | 435 if (it != window_list.end()) { |
436 // Record 1-based index so that selecting a top MRU window will record 1. | 436 // Record 1-based index so that selecting a top MRU window will record 1. |
437 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.SelectionDepth", | 437 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.SelectionDepth", |
438 1 + it - window_list.begin()); | 438 1 + it - window_list.begin()); |
439 } | 439 } |
440 } | 440 } |
441 item->EnsureVisible(); | 441 item->EnsureVisible(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 case ui::VKEY_LEFT: | 474 case ui::VKEY_LEFT: |
475 num_key_presses_++; | 475 num_key_presses_++; |
476 Move(WindowSelector::LEFT, true); | 476 Move(WindowSelector::LEFT, true); |
477 break; | 477 break; |
478 case ui::VKEY_W: | 478 case ui::VKEY_W: |
479 if (!(key_event.flags() & ui::EF_CONTROL_DOWN) || | 479 if (!(key_event.flags() & ui::EF_CONTROL_DOWN) || |
480 !grid_list_[selected_grid_index_]->is_selecting()) { | 480 !grid_list_[selected_grid_index_]->is_selecting()) { |
481 // Allow the textfield to handle 'W' key when not used with Ctrl. | 481 // Allow the textfield to handle 'W' key when not used with Ctrl. |
482 return false; | 482 return false; |
483 } | 483 } |
484 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_KEY); | 484 ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_KEY); |
485 grid_list_[selected_grid_index_]->SelectedWindow()->CloseWindow(); | 485 grid_list_[selected_grid_index_]->SelectedWindow()->CloseWindow(); |
486 break; | 486 break; |
487 case ui::VKEY_RETURN: | 487 case ui::VKEY_RETURN: |
488 // Ignore if no item is selected. | 488 // Ignore if no item is selected. |
489 if (!grid_list_[selected_grid_index_]->is_selecting()) | 489 if (!grid_list_[selected_grid_index_]->is_selecting()) |
490 return false; | 490 return false; |
491 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ArrowKeyPresses", | 491 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.ArrowKeyPresses", |
492 num_key_presses_); | 492 num_key_presses_); |
493 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.WindowSelector.KeyPressesOverItemsRatio", | 493 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.WindowSelector.KeyPressesOverItemsRatio", |
494 (num_key_presses_ * 100) / num_items_, 1, 300, | 494 (num_key_presses_ * 100) / num_items_, 1, 300, |
495 30); | 495 30); |
496 WmShell::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_ENTER_KEY); | 496 ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_ENTER_KEY); |
497 SelectWindow(grid_list_[selected_grid_index_]->SelectedWindow()); | 497 SelectWindow(grid_list_[selected_grid_index_]->SelectedWindow()); |
498 break; | 498 break; |
499 default: | 499 default: |
500 // Not a key we are interested in, allow the textfield to handle it. | 500 // Not a key we are interested in, allow the textfield to handle it. |
501 return false; | 501 return false; |
502 } | 502 } |
503 return true; | 503 return true; |
504 } | 504 } |
505 | 505 |
506 void WindowSelector::OnDisplayAdded(const display::Display& display) {} | 506 void WindowSelector::OnDisplayAdded(const display::Display& display) {} |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 WmWindow* WindowSelector::GetTextFilterWidgetWindow() { | 629 WmWindow* WindowSelector::GetTextFilterWidgetWindow() { |
630 return WmWindow::Get(text_filter_widget_->GetNativeWindow()); | 630 return WmWindow::Get(text_filter_widget_->GetNativeWindow()); |
631 } | 631 } |
632 | 632 |
633 void WindowSelector::PositionWindows(bool animate) { | 633 void WindowSelector::PositionWindows(bool animate) { |
634 for (std::unique_ptr<WindowGrid>& grid : grid_list_) | 634 for (std::unique_ptr<WindowGrid>& grid : grid_list_) |
635 grid->PositionWindows(animate); | 635 grid->PositionWindows(animate); |
636 } | 636 } |
637 | 637 |
638 void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() { | 638 void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() { |
639 WmWindow* root_window = WmShell::Get()->GetPrimaryRootWindow(); | 639 WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow(); |
640 const gfx::Rect rect = GetTextFilterPosition(root_window); | 640 const gfx::Rect rect = GetTextFilterPosition(root_window); |
641 text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin; | 641 text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin; |
642 text_filter_widget_->SetBounds(rect); | 642 text_filter_widget_->SetBounds(rect); |
643 | 643 |
644 gfx::Transform transform; | 644 gfx::Transform transform; |
645 transform.Translate( | 645 transform.Translate( |
646 0, text_filter_string_length_ == 0 ? -text_filter_bottom_ : 0); | 646 0, text_filter_string_length_ == 0 ? -text_filter_bottom_ : 0); |
647 WmWindow* text_filter_window = GetTextFilterWidgetWindow(); | 647 WmWindow* text_filter_window = GetTextFilterWidgetWindow(); |
648 text_filter_window->SetOpacity(text_filter_string_length_ == 0 ? 0 : 1); | 648 text_filter_window->SetOpacity(text_filter_string_length_ == 0 ? 0 : 1); |
649 text_filter_window->SetTransform(transform); | 649 text_filter_window->SetTransform(transform); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 for (size_t i = 0; i <= grid_list_.size() && | 681 for (size_t i = 0; i <= grid_list_.size() && |
682 grid_list_[selected_grid_index_]->Move(direction, animate); | 682 grid_list_[selected_grid_index_]->Move(direction, animate); |
683 i++) { | 683 i++) { |
684 selected_grid_index_ = | 684 selected_grid_index_ = |
685 (selected_grid_index_ + display_direction + grid_list_.size()) % | 685 (selected_grid_index_ + display_direction + grid_list_.size()) % |
686 grid_list_.size(); | 686 grid_list_.size(); |
687 } | 687 } |
688 } | 688 } |
689 | 689 |
690 } // namespace ash | 690 } // namespace ash |
OLD | NEW |