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

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

Issue 2955203002: Cros Tablet Window management - Split Screen part II (Closed)
Patch Set: Fix the failed ash_unittest. Created 3 years, 5 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
« no previous file with comments | « ash/wm/overview/window_selector.h ('k') | ash/wm/overview/window_selector_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/metrics/user_metrics_recorder.h" 16 #include "ash/metrics/user_metrics_recorder.h"
17 #include "ash/public/cpp/shell_window_ids.h" 17 #include "ash/public/cpp/shell_window_ids.h"
18 #include "ash/screen_util.h" 18 #include "ash/screen_util.h"
19 #include "ash/shelf/shelf.h" 19 #include "ash/shelf/shelf.h"
20 #include "ash/shell.h" 20 #include "ash/shell.h"
21 #include "ash/wm/mru_window_tracker.h" 21 #include "ash/wm/mru_window_tracker.h"
22 #include "ash/wm/overview/overview_window_drag_controller.h"
22 #include "ash/wm/overview/window_grid.h" 23 #include "ash/wm/overview/window_grid.h"
23 #include "ash/wm/overview/window_selector_delegate.h" 24 #include "ash/wm/overview/window_selector_delegate.h"
24 #include "ash/wm/overview/window_selector_item.h" 25 #include "ash/wm/overview/window_selector_item.h"
25 #include "ash/wm/panels/panel_layout_manager.h" 26 #include "ash/wm/panels/panel_layout_manager.h"
26 #include "ash/wm/switchable_windows.h" 27 #include "ash/wm/switchable_windows.h"
27 #include "ash/wm/window_state.h" 28 #include "ash/wm/window_state.h"
28 #include "ash/wm/window_util.h" 29 #include "ash/wm/window_util.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"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); 132 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView);
132 }; 133 };
133 134
134 // Triggers a shelf visibility update on all root window controllers. 135 // Triggers a shelf visibility update on all root window controllers.
135 void UpdateShelfVisibility() { 136 void UpdateShelfVisibility() {
136 for (aura::Window* root : Shell::GetAllRootWindows()) 137 for (aura::Window* root : Shell::GetAllRootWindows())
137 Shelf::ForWindow(root)->UpdateVisibilityState(); 138 Shelf::ForWindow(root)->UpdateVisibilityState();
138 } 139 }
139 140
141 // Returns the bounds for the overview window grid according to the split view
142 // state. If split view mode is active, the overview window should open on the
143 // opposite side of the default snap window.
144 gfx::Rect GetGridBoundsInScreen(aura::Window* root_window) {
145 SplitViewController* split_view_controller =
146 Shell::Get()->split_view_controller();
147 if (split_view_controller->IsSplitViewModeActive()) {
148 SplitViewController::SnapPosition oppsite_position =
149 (split_view_controller->default_snap_position() ==
150 SplitViewController::LEFT)
151 ? SplitViewController::RIGHT
152 : SplitViewController::LEFT;
153 return split_view_controller->GetSnappedWindowBoundsInScreen(
154 root_window, oppsite_position);
155 } else {
156 return split_view_controller->GetDisplayWorkAreaBoundsInScreen(root_window);
157 }
158 }
159
140 gfx::Rect GetTextFilterPosition(aura::Window* root_window) { 160 gfx::Rect GetTextFilterPosition(aura::Window* root_window) {
141 gfx::Rect total_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( 161 const gfx::Rect total_bounds = GetGridBoundsInScreen(root_window);
142 root_window->GetChildById(kShellWindowId_DefaultContainer));
143 ::wm::ConvertRectToScreen(root_window, &total_bounds);
144 return gfx::Rect( 162 return gfx::Rect(
145 0.5 * (total_bounds.width() - 163 total_bounds.x() +
146 std::min(kTextFilterWidth, total_bounds.width())), 164 0.5 * (total_bounds.width() -
165 std::min(kTextFilterWidth, total_bounds.width())),
147 total_bounds.y() + total_bounds.height() * kTextFilterTopScreenProportion, 166 total_bounds.y() + total_bounds.height() * kTextFilterTopScreenProportion,
148 std::min(kTextFilterWidth, total_bounds.width()), kTextFilterHeight); 167 std::min(kTextFilterWidth, total_bounds.width()), kTextFilterHeight);
149 } 168 }
150 169
151 // Initializes the text filter on the top of the main root window and requests 170 // Initializes the text filter on the top of the main root window and requests
152 // focus on its textfield. Uses |image| to place an icon to the left of the text 171 // focus on its textfield. Uses |image| to place an icon to the left of the text
153 // field. 172 // field.
154 views::Widget* CreateTextFilter(views::TextfieldController* controller, 173 views::Widget* CreateTextFilter(views::TextfieldController* controller,
155 aura::Window* root_window, 174 aura::Window* root_window,
156 const gfx::ImageSkia& image, 175 const gfx::ImageSkia& image,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 aura::Window* container = 280 aura::Window* container =
262 root->GetChildById(wm::kSwitchableWindowContainerIds[i]); 281 root->GetChildById(wm::kSwitchableWindowContainerIds[i]);
263 container->AddObserver(this); 282 container->AddObserver(this);
264 observed_windows_.insert(container); 283 observed_windows_.insert(container);
265 } 284 }
266 285
267 // Hide the callout widgets for panels. It is safe to call this for 286 // Hide the callout widgets for panels. It is safe to call this for
268 // root windows that don't contain any panel windows. 287 // root windows that don't contain any panel windows.
269 PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false); 288 PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false);
270 289
271 std::unique_ptr<WindowGrid> grid(new WindowGrid(root, windows, this)); 290 std::unique_ptr<WindowGrid> grid(
291 new WindowGrid(root, windows, this, GetGridBoundsInScreen(root)));
272 if (grid->empty()) 292 if (grid->empty())
273 continue; 293 continue;
274 num_items_ += grid->size(); 294 num_items_ += grid->size();
275 grid_list_.push_back(std::move(grid)); 295 grid_list_.push_back(std::move(grid));
276 } 296 }
277 297
278 { 298 {
279 // The calls to WindowGrid::PrepareForOverview() and CreateTextFilter(...) 299 // The calls to WindowGrid::PrepareForOverview() and CreateTextFilter(...)
280 // requires some LayoutManagers (ie PanelLayoutManager) to perform layouts 300 // requires some LayoutManagers (ie PanelLayoutManager) to perform layouts
281 // so that windows are correctly visible and properly animated in overview 301 // so that windows are correctly visible and properly animated in overview
(...skipping 16 matching lines...) Expand all
298 vector_icons::kSearchIcon, kTextFilterIconSize, kTextFilterIconColor); 318 vector_icons::kSearchIcon, kTextFilterIconSize, kTextFilterIconColor);
299 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 319 aura::Window* root_window = Shell::GetPrimaryRootWindow();
300 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, 320 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_,
301 &text_filter_bottom_)); 321 &text_filter_bottom_));
302 } 322 }
303 323
304 DCHECK(!grid_list_.empty()); 324 DCHECK(!grid_list_.empty());
305 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); 325 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_);
306 326
307 Shell::Get()->activation_client()->AddObserver(this); 327 Shell::Get()->activation_client()->AddObserver(this);
328 Shell::Get()->split_view_controller()->AddObserver(this);
308 329
309 display::Screen::GetScreen()->AddObserver(this); 330 display::Screen::GetScreen()->AddObserver(this);
310 Shell::Get()->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); 331 Shell::Get()->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW);
311 // Send an a11y alert. 332 // Send an a11y alert.
312 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( 333 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert(
313 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); 334 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED);
314 335
315 UpdateShelfVisibility(); 336 UpdateShelfVisibility();
316 } 337 }
317 338
318 // NOTE: The work done in Shutdown() is not done in the destructor because it 339 // NOTE: The work done in Shutdown() is not done in the destructor because it
319 // may cause other, unrelated classes, (ie PanelLayoutManager) to make indirect 340 // may cause other, unrelated classes, (ie PanelLayoutManager) to make indirect
320 // calls to restoring_minimized_windows() on a partially destructed object. 341 // calls to restoring_minimized_windows() on a partially destructed object.
321 void WindowSelector::Shutdown() { 342 void WindowSelector::Shutdown() {
322 is_shut_down_ = true; 343 is_shut_down_ = true;
323 // Stop observing screen metrics changes first to avoid auto-positioning 344 // Stop observing screen metrics changes first to avoid auto-positioning
324 // windows in response to work area changes from window activation. 345 // windows in response to work area changes from window activation.
325 display::Screen::GetScreen()->RemoveObserver(this); 346 display::Screen::GetScreen()->RemoveObserver(this);
326 347
348 // Stop observing split view state changes before restoring window focus.
349 // Otherwise the activation of the window triggers OnSplitViewStateChanged()
350 // that will call into this function again.
351 Shell::Get()->split_view_controller()->RemoveObserver(this);
352
327 size_t remaining_items = 0; 353 size_t remaining_items = 0;
328 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { 354 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) {
329 for (const auto& window_selector_item : window_grid->window_list()) 355 for (const auto& window_selector_item : window_grid->window_list())
330 window_selector_item->RestoreWindow(); 356 window_selector_item->RestoreWindow();
331 remaining_items += window_grid->size(); 357 remaining_items += window_grid->size();
332 } 358 }
333 359
334 // Setting focus after restoring windows' state avoids unnecessary animations. 360 // Setting focus after restoring windows' state avoids unnecessary animations.
335 ResetFocusRestoreWindow(true); 361 ResetFocusRestoreWindow(true);
336 RemoveAllObservers(); 362 RemoveAllObservers();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 462 }
437 } 463 }
438 item->EnsureVisible(); 464 item->EnsureVisible();
439 wm::GetWindowState(window)->Activate(); 465 wm::GetWindowState(window)->Activate();
440 } 466 }
441 467
442 void WindowSelector::WindowClosing(WindowSelectorItem* window) { 468 void WindowSelector::WindowClosing(WindowSelectorItem* window) {
443 grid_list_[selected_grid_index_]->WindowClosing(window); 469 grid_list_[selected_grid_index_]->WindowClosing(window);
444 } 470 }
445 471
472 void WindowSelector::SetBoundsForWindowGridsInScreen(const gfx::Rect& bounds) {
473 for (std::unique_ptr<WindowGrid>& grid : grid_list_)
474 grid->SetBoundsAndUpdatePositions(bounds);
475 }
476
477 void WindowSelector::RemoveWindowSelectorItem(WindowSelectorItem* item) {
478 if (item->GetWindow()->HasObserver(this)) {
479 item->GetWindow()->RemoveObserver(this);
480 observed_windows_.erase(item->GetWindow());
481 if (item->GetWindow() == restore_focus_window_)
482 restore_focus_window_ = nullptr;
483 }
484
485 // Remove |item| from the corresponding grid.
486 for (std::unique_ptr<WindowGrid>& grid : grid_list_) {
487 if (grid->Contains(item->GetWindow())) {
488 grid->RemoveItem(item);
489 break;
490 }
491 }
492 }
493
494 void WindowSelector::InitiateDrag(WindowSelectorItem* item,
495 const gfx::Point& location_in_screen) {
496 window_drag_controller_.reset(new OverviewWindowDragController(this));
497 window_drag_controller_->InitiateDrag(item, location_in_screen);
498 }
499
500 void WindowSelector::Drag(WindowSelectorItem* item,
501 const gfx::Point& location_in_screen) {
502 DCHECK(window_drag_controller_.get());
503 DCHECK_EQ(item, window_drag_controller_->item());
504 window_drag_controller_->Drag(location_in_screen);
505 }
506
507 void WindowSelector::CompleteDrag(WindowSelectorItem* item) {
508 DCHECK(window_drag_controller_.get());
509 DCHECK_EQ(item, window_drag_controller_->item());
510 window_drag_controller_->CompleteDrag();
511 }
512
513 void WindowSelector::PositionWindows(bool animate) {
514 for (std::unique_ptr<WindowGrid>& grid : grid_list_)
515 grid->PositionWindows(animate);
516 }
517
446 bool WindowSelector::HandleKeyEvent(views::Textfield* sender, 518 bool WindowSelector::HandleKeyEvent(views::Textfield* sender,
447 const ui::KeyEvent& key_event) { 519 const ui::KeyEvent& key_event) {
448 if (key_event.type() != ui::ET_KEY_PRESSED) 520 if (key_event.type() != ui::ET_KEY_PRESSED)
449 return false; 521 return false;
450 522
451 switch (key_event.key_code()) { 523 switch (key_event.key_code()) {
452 case ui::VKEY_ESCAPE: 524 case ui::VKEY_ESCAPE:
453 CancelSelection(); 525 CancelSelection();
454 break; 526 break;
455 case ui::VKEY_UP: 527 case ui::VKEY_UP:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 576
505 void WindowSelector::OnDisplayAdded(const display::Display& display) {} 577 void WindowSelector::OnDisplayAdded(const display::Display& display) {}
506 578
507 void WindowSelector::OnDisplayRemoved(const display::Display& display) { 579 void WindowSelector::OnDisplayRemoved(const display::Display& display) {
508 // TODO(flackr): Keep window selection active on remaining displays. 580 // TODO(flackr): Keep window selection active on remaining displays.
509 CancelSelection(); 581 CancelSelection();
510 } 582 }
511 583
512 void WindowSelector::OnDisplayMetricsChanged(const display::Display& display, 584 void WindowSelector::OnDisplayMetricsChanged(const display::Display& display,
513 uint32_t metrics) { 585 uint32_t metrics) {
586 // Re-calculate the bounds for the window grids and position all the windows.
587 for (std::unique_ptr<WindowGrid>& grid : grid_list_) {
588 SetBoundsForWindowGridsInScreen(
589 GetGridBoundsInScreen(const_cast<aura::Window*>(grid->root_window())));
590 }
514 PositionWindows(/* animate */ false); 591 PositionWindows(/* animate */ false);
515 RepositionTextFilterOnDisplayMetricsChange(); 592 RepositionTextFilterOnDisplayMetricsChange();
516 } 593 }
517 594
518 void WindowSelector::OnWindowHierarchyChanged( 595 void WindowSelector::OnWindowHierarchyChanged(
519 const HierarchyChangeParams& params) { 596 const HierarchyChangeParams& params) {
520 // Only care about newly added children of |observed_windows_|. 597 // Only care about newly added children of |observed_windows_|.
521 if (!observed_windows_.count(params.receiver) || 598 if (!observed_windows_.count(params.receiver) ||
522 !observed_windows_.count(params.new_parent)) { 599 !observed_windows_.count(params.new_parent)) {
523 return; 600 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 windows.begin(), windows.end(), 643 windows.begin(), windows.end(),
567 [gained_active](const std::unique_ptr<WindowSelectorItem>& window) { 644 [gained_active](const std::unique_ptr<WindowSelectorItem>& window) {
568 return window->Contains(gained_active); 645 return window->Contains(gained_active);
569 }); 646 });
570 647
571 if (iter == windows.end() && showing_text_filter_ && 648 if (iter == windows.end() && showing_text_filter_ &&
572 lost_active == GetTextFilterWidgetWindow()) { 649 lost_active == GetTextFilterWidgetWindow()) {
573 return; 650 return;
574 } 651 }
575 652
653 // Do not cancel the overview mode if the window activation was caused by
654 // snapping window to one side of the screen.
655 if (Shell::Get()->IsSplitViewModeActive())
656 return;
657
576 // Don't restore focus on exit if a window was just activated. 658 // Don't restore focus on exit if a window was just activated.
577 ResetFocusRestoreWindow(false); 659 ResetFocusRestoreWindow(false);
578 CancelSelection(); 660 CancelSelection();
579 } 661 }
580 662
581 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active, 663 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active,
582 aura::Window* actual_active) { 664 aura::Window* actual_active) {
583 OnWindowActivated(ActivationReason::ACTIVATION_CLIENT, request_active, 665 OnWindowActivated(ActivationReason::ACTIVATION_CLIENT, request_active,
584 actual_active); 666 actual_active);
585 } 667 }
(...skipping 30 matching lines...) Expand all
616 for (auto iter = grid_list_.begin(); iter != grid_list_.end(); iter++) 698 for (auto iter = grid_list_.begin(); iter != grid_list_.end(); iter++)
617 (*iter)->FilterItems(new_contents); 699 (*iter)->FilterItems(new_contents);
618 700
619 // If the selection widget is not active, execute a Move() command so that it 701 // If the selection widget is not active, execute a Move() command so that it
620 // shows up on the first undimmed item. 702 // shows up on the first undimmed item.
621 if (grid_list_[selected_grid_index_]->is_selecting()) 703 if (grid_list_[selected_grid_index_]->is_selecting())
622 return; 704 return;
623 Move(WindowSelector::RIGHT, false); 705 Move(WindowSelector::RIGHT, false);
624 } 706 }
625 707
708 void WindowSelector::OnSplitViewStateChanged(
709 SplitViewController::State previous_state,
710 SplitViewController::State state) {
711 if (state != SplitViewController::NO_SNAP) {
712 // Do not restore focus if a window was just snapped and activated.
713 ResetFocusRestoreWindow(false);
714 }
715
716 if (state == SplitViewController::LEFT_SNAPPED) {
717 aura::Window* snapped_window =
718 Shell::Get()->split_view_controller()->left_window();
719 const gfx::Rect bounds_in_screen =
720 Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInScreen(
721 snapped_window, SplitViewController::RIGHT);
722 SetBoundsForWindowGridsInScreen(bounds_in_screen);
723 } else if (state == SplitViewController::RIGHT_SNAPPED) {
724 aura::Window* snapped_window =
725 Shell::Get()->split_view_controller()->right_window();
726 const gfx::Rect bounds_in_screen =
727 Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInScreen(
728 snapped_window, SplitViewController::LEFT);
729 SetBoundsForWindowGridsInScreen(bounds_in_screen);
730 } else {
731 DCHECK(state == SplitViewController::BOTH_SNAPPED ||
732 state == SplitViewController::NO_SNAP);
733 // If two windows were snapped to both sides of the screen, end overview
734 // mode. If split view mode was ended (e.g., one of the snapped window was
735 // closed or minimized / fullscreened / maximized), also end overview mode
736 // if overview mode is active.
737 CancelSelection();
738 }
739 }
740
626 aura::Window* WindowSelector::GetTextFilterWidgetWindow() { 741 aura::Window* WindowSelector::GetTextFilterWidgetWindow() {
627 return text_filter_widget_->GetNativeWindow(); 742 return text_filter_widget_->GetNativeWindow();
628 } 743 }
629 744
630 void WindowSelector::PositionWindows(bool animate) {
631 for (std::unique_ptr<WindowGrid>& grid : grid_list_)
632 grid->PositionWindows(animate);
633 }
634
635 void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() { 745 void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() {
636 const gfx::Rect rect = GetTextFilterPosition(Shell::GetPrimaryRootWindow()); 746 const gfx::Rect rect = GetTextFilterPosition(Shell::GetPrimaryRootWindow());
637 text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin; 747 text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin;
638 text_filter_widget_->SetBounds(rect); 748 text_filter_widget_->SetBounds(rect);
639 749
640 gfx::Transform transform; 750 gfx::Transform transform;
641 transform.Translate( 751 transform.Translate(
642 0, text_filter_string_length_ == 0 ? -text_filter_bottom_ : 0); 752 0, text_filter_string_length_ == 0 ? -text_filter_bottom_ : 0);
643 aura::Window* text_filter_window = GetTextFilterWidgetWindow(); 753 aura::Window* text_filter_window = GetTextFilterWidgetWindow();
644 text_filter_window->layer()->SetOpacity(text_filter_string_length_ == 0 ? 0 754 text_filter_window->layer()->SetOpacity(text_filter_string_length_ == 0 ? 0
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 for (size_t i = 0; i <= grid_list_.size() && 788 for (size_t i = 0; i <= grid_list_.size() &&
679 grid_list_[selected_grid_index_]->Move(direction, animate); 789 grid_list_[selected_grid_index_]->Move(direction, animate);
680 i++) { 790 i++) {
681 selected_grid_index_ = 791 selected_grid_index_ =
682 (selected_grid_index_ + display_direction + grid_list_.size()) % 792 (selected_grid_index_ + display_direction + grid_list_.size()) %
683 grid_list_.size(); 793 grid_list_.size();
684 } 794 }
685 } 795 }
686 796
687 } // namespace ash 797 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/window_selector.h ('k') | ash/wm/overview/window_selector_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698