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

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

Issue 2978273002: Revert of Cros Tablet Window management - Split Screen part II (Closed)
Patch Set: 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"
23 #include "ash/wm/overview/window_grid.h" 22 #include "ash/wm/overview/window_grid.h"
24 #include "ash/wm/overview/window_selector_delegate.h" 23 #include "ash/wm/overview/window_selector_delegate.h"
25 #include "ash/wm/overview/window_selector_item.h" 24 #include "ash/wm/overview/window_selector_item.h"
26 #include "ash/wm/panels/panel_layout_manager.h" 25 #include "ash/wm/panels/panel_layout_manager.h"
27 #include "ash/wm/switchable_windows.h" 26 #include "ash/wm/switchable_windows.h"
28 #include "ash/wm/window_state.h" 27 #include "ash/wm/window_state.h"
29 #include "ash/wm/window_util.h" 28 #include "ash/wm/window_util.h"
30 #include "base/auto_reset.h" 29 #include "base/auto_reset.h"
31 #include "base/command_line.h" 30 #include "base/command_line.h"
32 #include "base/metrics/histogram_macros.h" 31 #include "base/metrics/histogram_macros.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 130
132 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView); 131 DISALLOW_COPY_AND_ASSIGN(RoundedContainerView);
133 }; 132 };
134 133
135 // Triggers a shelf visibility update on all root window controllers. 134 // Triggers a shelf visibility update on all root window controllers.
136 void UpdateShelfVisibility() { 135 void UpdateShelfVisibility() {
137 for (aura::Window* root : Shell::GetAllRootWindows()) 136 for (aura::Window* root : Shell::GetAllRootWindows())
138 Shelf::ForWindow(root)->UpdateVisibilityState(); 137 Shelf::ForWindow(root)->UpdateVisibilityState();
139 } 138 }
140 139
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
160 gfx::Rect GetTextFilterPosition(aura::Window* root_window) { 140 gfx::Rect GetTextFilterPosition(aura::Window* root_window) {
161 const gfx::Rect total_bounds = GetGridBoundsInScreen(root_window); 141 gfx::Rect total_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
142 root_window->GetChildById(kShellWindowId_DefaultContainer));
143 ::wm::ConvertRectToScreen(root_window, &total_bounds);
162 return gfx::Rect( 144 return gfx::Rect(
163 total_bounds.x() + 145 0.5 * (total_bounds.width() -
164 0.5 * (total_bounds.width() - 146 std::min(kTextFilterWidth, total_bounds.width())),
165 std::min(kTextFilterWidth, total_bounds.width())),
166 total_bounds.y() + total_bounds.height() * kTextFilterTopScreenProportion, 147 total_bounds.y() + total_bounds.height() * kTextFilterTopScreenProportion,
167 std::min(kTextFilterWidth, total_bounds.width()), kTextFilterHeight); 148 std::min(kTextFilterWidth, total_bounds.width()), kTextFilterHeight);
168 } 149 }
169 150
170 // Initializes the text filter on the top of the main root window and requests 151 // Initializes the text filter on the top of the main root window and requests
171 // focus on its textfield. Uses |image| to place an icon to the left of the text 152 // focus on its textfield. Uses |image| to place an icon to the left of the text
172 // field. 153 // field.
173 views::Widget* CreateTextFilter(views::TextfieldController* controller, 154 views::Widget* CreateTextFilter(views::TextfieldController* controller,
174 aura::Window* root_window, 155 aura::Window* root_window,
175 const gfx::ImageSkia& image, 156 const gfx::ImageSkia& image,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 aura::Window* container = 261 aura::Window* container =
281 root->GetChildById(wm::kSwitchableWindowContainerIds[i]); 262 root->GetChildById(wm::kSwitchableWindowContainerIds[i]);
282 container->AddObserver(this); 263 container->AddObserver(this);
283 observed_windows_.insert(container); 264 observed_windows_.insert(container);
284 } 265 }
285 266
286 // Hide the callout widgets for panels. It is safe to call this for 267 // Hide the callout widgets for panels. It is safe to call this for
287 // root windows that don't contain any panel windows. 268 // root windows that don't contain any panel windows.
288 PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false); 269 PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false);
289 270
290 std::unique_ptr<WindowGrid> grid( 271 std::unique_ptr<WindowGrid> grid(new WindowGrid(root, windows, this));
291 new WindowGrid(root, windows, this, GetGridBoundsInScreen(root)));
292 if (grid->empty()) 272 if (grid->empty())
293 continue; 273 continue;
294 num_items_ += grid->size(); 274 num_items_ += grid->size();
295 grid_list_.push_back(std::move(grid)); 275 grid_list_.push_back(std::move(grid));
296 } 276 }
297 277
298 { 278 {
299 // The calls to WindowGrid::PrepareForOverview() and CreateTextFilter(...) 279 // The calls to WindowGrid::PrepareForOverview() and CreateTextFilter(...)
300 // requires some LayoutManagers (ie PanelLayoutManager) to perform layouts 280 // requires some LayoutManagers (ie PanelLayoutManager) to perform layouts
301 // so that windows are correctly visible and properly animated in overview 281 // so that windows are correctly visible and properly animated in overview
(...skipping 16 matching lines...) Expand all
318 vector_icons::kSearchIcon, kTextFilterIconSize, kTextFilterIconColor); 298 vector_icons::kSearchIcon, kTextFilterIconSize, kTextFilterIconColor);
319 aura::Window* root_window = Shell::GetPrimaryRootWindow(); 299 aura::Window* root_window = Shell::GetPrimaryRootWindow();
320 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_, 300 text_filter_widget_.reset(CreateTextFilter(this, root_window, search_image_,
321 &text_filter_bottom_)); 301 &text_filter_bottom_));
322 } 302 }
323 303
324 DCHECK(!grid_list_.empty()); 304 DCHECK(!grid_list_.empty());
325 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); 305 UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_);
326 306
327 Shell::Get()->activation_client()->AddObserver(this); 307 Shell::Get()->activation_client()->AddObserver(this);
328 Shell::Get()->split_view_controller()->AddObserver(this);
329 308
330 display::Screen::GetScreen()->AddObserver(this); 309 display::Screen::GetScreen()->AddObserver(this);
331 Shell::Get()->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); 310 Shell::Get()->metrics()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW);
332 // Send an a11y alert. 311 // Send an a11y alert.
333 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( 312 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert(
334 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED); 313 A11Y_ALERT_WINDOW_OVERVIEW_MODE_ENTERED);
335 314
336 UpdateShelfVisibility(); 315 UpdateShelfVisibility();
337 } 316 }
338 317
339 // NOTE: The work done in Shutdown() is not done in the destructor because it 318 // NOTE: The work done in Shutdown() is not done in the destructor because it
340 // may cause other, unrelated classes, (ie PanelLayoutManager) to make indirect 319 // may cause other, unrelated classes, (ie PanelLayoutManager) to make indirect
341 // calls to restoring_minimized_windows() on a partially destructed object. 320 // calls to restoring_minimized_windows() on a partially destructed object.
342 void WindowSelector::Shutdown() { 321 void WindowSelector::Shutdown() {
343 is_shut_down_ = true; 322 is_shut_down_ = true;
344 // Stop observing screen metrics changes first to avoid auto-positioning 323 // Stop observing screen metrics changes first to avoid auto-positioning
345 // windows in response to work area changes from window activation. 324 // windows in response to work area changes from window activation.
346 display::Screen::GetScreen()->RemoveObserver(this); 325 display::Screen::GetScreen()->RemoveObserver(this);
347 326
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
353 size_t remaining_items = 0; 327 size_t remaining_items = 0;
354 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { 328 for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) {
355 for (const auto& window_selector_item : window_grid->window_list()) 329 for (const auto& window_selector_item : window_grid->window_list())
356 window_selector_item->RestoreWindow(); 330 window_selector_item->RestoreWindow();
357 remaining_items += window_grid->size(); 331 remaining_items += window_grid->size();
358 } 332 }
359 333
360 // Setting focus after restoring windows' state avoids unnecessary animations. 334 // Setting focus after restoring windows' state avoids unnecessary animations.
361 ResetFocusRestoreWindow(true); 335 ResetFocusRestoreWindow(true);
362 RemoveAllObservers(); 336 RemoveAllObservers();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 436 }
463 } 437 }
464 item->EnsureVisible(); 438 item->EnsureVisible();
465 wm::GetWindowState(window)->Activate(); 439 wm::GetWindowState(window)->Activate();
466 } 440 }
467 441
468 void WindowSelector::WindowClosing(WindowSelectorItem* window) { 442 void WindowSelector::WindowClosing(WindowSelectorItem* window) {
469 grid_list_[selected_grid_index_]->WindowClosing(window); 443 grid_list_[selected_grid_index_]->WindowClosing(window);
470 } 444 }
471 445
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
518 bool WindowSelector::HandleKeyEvent(views::Textfield* sender, 446 bool WindowSelector::HandleKeyEvent(views::Textfield* sender,
519 const ui::KeyEvent& key_event) { 447 const ui::KeyEvent& key_event) {
520 if (key_event.type() != ui::ET_KEY_PRESSED) 448 if (key_event.type() != ui::ET_KEY_PRESSED)
521 return false; 449 return false;
522 450
523 switch (key_event.key_code()) { 451 switch (key_event.key_code()) {
524 case ui::VKEY_ESCAPE: 452 case ui::VKEY_ESCAPE:
525 CancelSelection(); 453 CancelSelection();
526 break; 454 break;
527 case ui::VKEY_UP: 455 case ui::VKEY_UP:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 504
577 void WindowSelector::OnDisplayAdded(const display::Display& display) {} 505 void WindowSelector::OnDisplayAdded(const display::Display& display) {}
578 506
579 void WindowSelector::OnDisplayRemoved(const display::Display& display) { 507 void WindowSelector::OnDisplayRemoved(const display::Display& display) {
580 // TODO(flackr): Keep window selection active on remaining displays. 508 // TODO(flackr): Keep window selection active on remaining displays.
581 CancelSelection(); 509 CancelSelection();
582 } 510 }
583 511
584 void WindowSelector::OnDisplayMetricsChanged(const display::Display& display, 512 void WindowSelector::OnDisplayMetricsChanged(const display::Display& display,
585 uint32_t metrics) { 513 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 }
591 PositionWindows(/* animate */ false); 514 PositionWindows(/* animate */ false);
592 RepositionTextFilterOnDisplayMetricsChange(); 515 RepositionTextFilterOnDisplayMetricsChange();
593 } 516 }
594 517
595 void WindowSelector::OnWindowHierarchyChanged( 518 void WindowSelector::OnWindowHierarchyChanged(
596 const HierarchyChangeParams& params) { 519 const HierarchyChangeParams& params) {
597 // Only care about newly added children of |observed_windows_|. 520 // Only care about newly added children of |observed_windows_|.
598 if (!observed_windows_.count(params.receiver) || 521 if (!observed_windows_.count(params.receiver) ||
599 !observed_windows_.count(params.new_parent)) { 522 !observed_windows_.count(params.new_parent)) {
600 return; 523 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 windows.begin(), windows.end(), 566 windows.begin(), windows.end(),
644 [gained_active](const std::unique_ptr<WindowSelectorItem>& window) { 567 [gained_active](const std::unique_ptr<WindowSelectorItem>& window) {
645 return window->Contains(gained_active); 568 return window->Contains(gained_active);
646 }); 569 });
647 570
648 if (iter == windows.end() && showing_text_filter_ && 571 if (iter == windows.end() && showing_text_filter_ &&
649 lost_active == GetTextFilterWidgetWindow()) { 572 lost_active == GetTextFilterWidgetWindow()) {
650 return; 573 return;
651 } 574 }
652 575
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
658 // Don't restore focus on exit if a window was just activated. 576 // Don't restore focus on exit if a window was just activated.
659 ResetFocusRestoreWindow(false); 577 ResetFocusRestoreWindow(false);
660 CancelSelection(); 578 CancelSelection();
661 } 579 }
662 580
663 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active, 581 void WindowSelector::OnAttemptToReactivateWindow(aura::Window* request_active,
664 aura::Window* actual_active) { 582 aura::Window* actual_active) {
665 OnWindowActivated(ActivationReason::ACTIVATION_CLIENT, request_active, 583 OnWindowActivated(ActivationReason::ACTIVATION_CLIENT, request_active,
666 actual_active); 584 actual_active);
667 } 585 }
(...skipping 30 matching lines...) Expand all
698 for (auto iter = grid_list_.begin(); iter != grid_list_.end(); iter++) 616 for (auto iter = grid_list_.begin(); iter != grid_list_.end(); iter++)
699 (*iter)->FilterItems(new_contents); 617 (*iter)->FilterItems(new_contents);
700 618
701 // If the selection widget is not active, execute a Move() command so that it 619 // If the selection widget is not active, execute a Move() command so that it
702 // shows up on the first undimmed item. 620 // shows up on the first undimmed item.
703 if (grid_list_[selected_grid_index_]->is_selecting()) 621 if (grid_list_[selected_grid_index_]->is_selecting())
704 return; 622 return;
705 Move(WindowSelector::RIGHT, false); 623 Move(WindowSelector::RIGHT, false);
706 } 624 }
707 625
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
741 aura::Window* WindowSelector::GetTextFilterWidgetWindow() { 626 aura::Window* WindowSelector::GetTextFilterWidgetWindow() {
742 return text_filter_widget_->GetNativeWindow(); 627 return text_filter_widget_->GetNativeWindow();
743 } 628 }
744 629
630 void WindowSelector::PositionWindows(bool animate) {
631 for (std::unique_ptr<WindowGrid>& grid : grid_list_)
632 grid->PositionWindows(animate);
633 }
634
745 void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() { 635 void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() {
746 const gfx::Rect rect = GetTextFilterPosition(Shell::GetPrimaryRootWindow()); 636 const gfx::Rect rect = GetTextFilterPosition(Shell::GetPrimaryRootWindow());
747 text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin; 637 text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin;
748 text_filter_widget_->SetBounds(rect); 638 text_filter_widget_->SetBounds(rect);
749 639
750 gfx::Transform transform; 640 gfx::Transform transform;
751 transform.Translate( 641 transform.Translate(
752 0, text_filter_string_length_ == 0 ? -text_filter_bottom_ : 0); 642 0, text_filter_string_length_ == 0 ? -text_filter_bottom_ : 0);
753 aura::Window* text_filter_window = GetTextFilterWidgetWindow(); 643 aura::Window* text_filter_window = GetTextFilterWidgetWindow();
754 text_filter_window->layer()->SetOpacity(text_filter_string_length_ == 0 ? 0 644 text_filter_window->layer()->SetOpacity(text_filter_string_length_ == 0 ? 0
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 for (size_t i = 0; i <= grid_list_.size() && 678 for (size_t i = 0; i <= grid_list_.size() &&
789 grid_list_[selected_grid_index_]->Move(direction, animate); 679 grid_list_[selected_grid_index_]->Move(direction, animate);
790 i++) { 680 i++) {
791 selected_grid_index_ = 681 selected_grid_index_ =
792 (selected_grid_index_ + display_direction + grid_list_.size()) % 682 (selected_grid_index_ + display_direction + grid_list_.size()) %
793 grid_list_.size(); 683 grid_list_.size();
794 } 684 }
795 } 685 }
796 686
797 } // namespace ash 687 } // 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