Chromium Code Reviews| Index: ash/wm/overview/window_selector.cc |
| diff --git a/ash/wm/overview/window_selector.cc b/ash/wm/overview/window_selector.cc |
| index 76bdee5d0a5df0d43b389118d44f1869d3de38f4..a599a521f46a40e9f8b9e7034364f8474b5a40e2 100644 |
| --- a/ash/wm/overview/window_selector.cc |
| +++ b/ash/wm/overview/window_selector.cc |
| @@ -20,10 +20,12 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_port.h" |
| #include "ash/wm/mru_window_tracker.h" |
| +#include "ash/wm/overview/overview_window_drag_controller.h" |
| #include "ash/wm/overview/window_grid.h" |
| #include "ash/wm/overview/window_selector_delegate.h" |
| #include "ash/wm/overview/window_selector_item.h" |
| #include "ash/wm/panels/panel_layout_manager.h" |
| +#include "ash/wm/splitview/split_view_controller.h" |
| #include "ash/wm/switchable_windows.h" |
| #include "ash/wm/window_state.h" |
| #include "ash/wm/window_util.h" |
| @@ -138,13 +140,33 @@ void UpdateShelfVisibility() { |
| Shelf::ForWindow(root)->UpdateVisibilityState(); |
| } |
| +// Returns the bounds for the overview window grids according to the split view |
| +// state. If split view mode is active, the overview window should open on the |
| +// opposite side of the default snap window. |
|
oshima
2017/06/16 19:39:15
left is the default correct?
xdai1
2017/06/16 20:01:46
It depends. The default position is decided by the
|
| +gfx::Rect GetGridsBoundsInScreen(aura::Window* root_window) { |
| + if (Shell::Get()->IsSplitViewModeActive()) { |
| + SplitViewController::State state = |
| + Shell::Get()->split_view_controller()->state(); |
| + SplitViewController::State oppsite_state = |
| + (state == SplitViewController::LEFT_SNAPPED) |
| + ? SplitViewController::RIGHT_SNAPPED |
| + : SplitViewController::LEFT_SNAPPED; |
| + return Shell::Get() |
| + ->split_view_controller() |
| + ->GetSnappedWindowBoundsInScreen(root_window, oppsite_state); |
| + } else { |
| + return Shell::Get() |
| + ->split_view_controller() |
| + ->GetDisplayWorkAreaBoundsInScreen(root_window); |
| + } |
| +} |
| + |
| gfx::Rect GetTextFilterPosition(aura::Window* root_window) { |
| - gfx::Rect total_bounds = ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| - root_window->GetChildById(kShellWindowId_DefaultContainer)); |
| - ::wm::ConvertRectToScreen(root_window, &total_bounds); |
| + gfx::Rect total_bounds = GetGridsBoundsInScreen(root_window); |
| return gfx::Rect( |
| 0.5 * (total_bounds.width() - |
| - std::min(kTextFilterWidth, total_bounds.width())), |
| + std::min(kTextFilterWidth, total_bounds.width())) + |
| + total_bounds.x(), |
| total_bounds.y() + total_bounds.height() * kTextFilterTopScreenProportion, |
| std::min(kTextFilterWidth, total_bounds.width()), kTextFilterHeight); |
| } |
| @@ -271,7 +293,8 @@ void WindowSelector::Init(const WindowList& windows) { |
| // root windows that don't contain any panel windows. |
| PanelLayoutManager::Get(root)->SetShowCalloutWidgets(false); |
| - std::unique_ptr<WindowGrid> grid(new WindowGrid(root, windows, this)); |
| + std::unique_ptr<WindowGrid> grid( |
| + new WindowGrid(root, windows, this, GetGridsBoundsInScreen(root))); |
| if (grid->empty()) |
| continue; |
| num_items_ += grid->size(); |
| @@ -308,6 +331,7 @@ void WindowSelector::Init(const WindowList& windows) { |
| UMA_HISTOGRAM_COUNTS_100("Ash.WindowSelector.Items", num_items_); |
| Shell::Get()->activation_client()->AddObserver(this); |
| + Shell::Get()->split_view_controller()->AddObserver(this); |
| display::Screen::GetScreen()->AddObserver(this); |
| ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW); |
| @@ -327,6 +351,11 @@ void WindowSelector::Shutdown() { |
| // windows in response to work area changes from window activation. |
| display::Screen::GetScreen()->RemoveObserver(this); |
| + // Stop observing split view state changes before restoring window focus. |
| + // Otherwise the activation of the window triggers OnSplitViewStateChanged() |
| + // that will call into this function again. |
| + Shell::Get()->split_view_controller()->RemoveObserver(this); |
| + |
| size_t remaining_items = 0; |
| for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) { |
| for (const auto& window_selector_item : window_grid->window_list()) |
| @@ -446,6 +475,47 @@ void WindowSelector::WindowClosing(WindowSelectorItem* window) { |
| grid_list_[selected_grid_index_]->WindowClosing(window); |
| } |
| +void WindowSelector::SetBoundsForWindowGridsInScreen(const gfx::Rect bounds) { |
| + for (std::unique_ptr<WindowGrid>& grid : grid_list_) |
| + grid->SetTotalBoundsInScreen(bounds); |
| +} |
| + |
| +void WindowSelector::RemoveWindowSelectorItem(WindowSelectorItem* item) { |
| + if (item->GetWindow()->HasObserver(this)) { |
| + item->GetWindow()->RemoveObserver(this); |
| + observed_windows_.erase(item->GetWindow()); |
| + if (item->GetWindow() == restore_focus_window_) |
| + restore_focus_window_ = nullptr; |
| + } |
| + |
| + // Remove |item| from the corresponding grid. |
| + for (std::unique_ptr<WindowGrid>& grid : grid_list_) { |
| + if (grid->Contains(item->GetWindow())) { |
| + grid->RemoveItem(item); |
| + break; |
| + } |
| + } |
| +} |
| + |
| +void WindowSelector::InitiateDrag(WindowSelectorItem* item, |
| + const gfx::Point& location_in_screen) { |
| + window_drag_controller_.reset(new OverviewWindowDragController(this)); |
| + window_drag_controller_->InitiateDrag(item, location_in_screen); |
| +} |
| + |
| +void WindowSelector::Drag(WindowSelectorItem* item, |
| + const gfx::Point& location_in_screen) { |
| + DCHECK(window_drag_controller_.get()); |
| + DCHECK_EQ(item, window_drag_controller_->item()); |
| + window_drag_controller_->Drag(location_in_screen); |
| +} |
| + |
| +void WindowSelector::CompleteDrag(WindowSelectorItem* item) { |
| + DCHECK(window_drag_controller_.get()); |
| + DCHECK_EQ(item, window_drag_controller_->item()); |
| + window_drag_controller_->CompleteDrag(); |
| +} |
| + |
| bool WindowSelector::HandleKeyEvent(views::Textfield* sender, |
| const ui::KeyEvent& key_event) { |
| if (key_event.type() != ui::ET_KEY_PRESSED) |
| @@ -512,6 +582,11 @@ void WindowSelector::OnDisplayRemoved(const display::Display& display) { |
| void WindowSelector::OnDisplayMetricsChanged(const display::Display& display, |
| uint32_t metrics) { |
| + // Re-calculate the bounds for the window grids and position all the windows. |
| + for (std::unique_ptr<WindowGrid>& grid : grid_list_) { |
| + SetBoundsForWindowGridsInScreen( |
| + GetGridsBoundsInScreen(const_cast<aura::Window*>(grid->root_window()))); |
| + } |
| PositionWindows(/* animate */ false); |
| RepositionTextFilterOnDisplayMetricsChange(); |
| } |
| @@ -574,6 +649,11 @@ void WindowSelector::OnWindowActivated(ActivationReason reason, |
| return; |
| } |
| + // Do not cancel the overview mode if the window activation was caused by |
| + // snapping window to one side of the screen. |
| + if (Shell::Get()->IsSplitViewModeActive()) |
| + return; |
| + |
| // Don't restore focus on exit if a window was just activated. |
| ResetFocusRestoreWindow(false); |
| CancelSelection(); |
| @@ -624,8 +704,39 @@ void WindowSelector::ContentsChanged(views::Textfield* sender, |
| Move(WindowSelector::RIGHT, false); |
| } |
| -aura::Window* WindowSelector::GetTextFilterWidgetWindow() { |
| - return text_filter_widget_->GetNativeWindow(); |
| +void WindowSelector::OnSplitViewStateChanged( |
| + SplitViewController::State previous_state, |
| + SplitViewController::State state) { |
| + if (state != SplitViewController::NOSNAP) { |
| + // Do not restore focus if a window was just snapped and activated. |
| + ResetFocusRestoreWindow(false); |
| + } |
| + |
| + if (state == SplitViewController::LEFT_SNAPPED) { |
| + aura::Window* snapped_window = |
| + Shell::Get()->split_view_controller()->left_window(); |
| + const gfx::Rect bounds_in_screen = |
| + Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInScreen( |
| + snapped_window, SplitViewController::RIGHT_SNAPPED); |
| + SetBoundsForWindowGridsInScreen(bounds_in_screen); |
| + } else if (state == SplitViewController::RIGHT_SNAPPED) { |
| + aura::Window* snapped_window = |
| + Shell::Get()->split_view_controller()->right_window(); |
| + const gfx::Rect bounds_in_screen = |
| + Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInScreen( |
| + snapped_window, SplitViewController::LEFT_SNAPPED); |
| + SetBoundsForWindowGridsInScreen(bounds_in_screen); |
| + } else if (state == SplitViewController::BOTH_SNAPPED) { |
| + CancelSelection(); |
| + } else { |
| + DCHECK(state == SplitViewController::BOTH_SNAPPED || |
| + state == SplitViewController::NOSNAP); |
| + // If two windows were snapped to both sides of the screen, end overview |
| + // mode. If split view mode was ended (e.g., one of the snapped window was |
| + // closed or minimized / fullscreened / maximized), also end overview mode |
| + // if overview mode is active. |
| + CancelSelection(); |
| + } |
| } |
| void WindowSelector::PositionWindows(bool animate) { |
| @@ -633,6 +744,10 @@ void WindowSelector::PositionWindows(bool animate) { |
| grid->PositionWindows(animate); |
| } |
| +aura::Window* WindowSelector::GetTextFilterWidgetWindow() { |
| + return text_filter_widget_->GetNativeWindow(); |
| +} |
| + |
| void WindowSelector::RepositionTextFilterOnDisplayMetricsChange() { |
| const gfx::Rect rect = GetTextFilterPosition(Shell::GetPrimaryRootWindow()); |
| text_filter_bottom_ = rect.bottom() + kTextFieldBottomMargin; |