Commit 081d4cf1 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Chromium LUCI CQ

overview: Rename |restore_focus_window_|.

Rename |restore_focus_window_| to |active_window_before_overview_| to
better match the code. The active window might not be the same window
as the focused window, but by activating the right window, the focus
will be restored properly as well.

Pure renaming. No functional change.

Bug: None
Change-Id: I67250ce1fd5a48cf817ec04ef4f59de0ab83c38d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644348Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846232}
parent 9c9a1794
...@@ -949,7 +949,7 @@ void OverviewGrid::OnSplitViewStateChanged( ...@@ -949,7 +949,7 @@ void OverviewGrid::OnSplitViewStateChanged(
// split view mode was ended by activating an unsnappable window. // split view mode was ended by activating an unsnappable window.
if (state != SplitViewController::State::kNoSnap || if (state != SplitViewController::State::kNoSnap ||
unsnappable_window_activated) { unsnappable_window_activated) {
overview_session_->ResetFocusRestoreWindow(false); overview_session_->RestoreWindowActivation(false);
} }
// If two windows were snapped to both sides of the screen or an unsnappable // If two windows were snapped to both sides of the screen or an unsnappable
...@@ -1020,7 +1020,6 @@ void OverviewGrid::OnStartingAnimationComplete(bool canceled) { ...@@ -1020,7 +1020,6 @@ void OverviewGrid::OnStartingAnimationComplete(bool canceled) {
for (auto& window : window_list()) for (auto& window : window_list())
window->OnStartingAnimationComplete(); window->OnStartingAnimationComplete();
} }
void OverviewGrid::CalculateWindowListAnimationStates( void OverviewGrid::CalculateWindowListAnimationStates(
......
...@@ -208,7 +208,7 @@ class OverviewSession::AccessibilityFocusAnnotator { ...@@ -208,7 +208,7 @@ class OverviewSession::AccessibilityFocusAnnotator {
OverviewSession::OverviewSession(OverviewDelegate* delegate) OverviewSession::OverviewSession(OverviewDelegate* delegate)
: delegate_(delegate), : delegate_(delegate),
restore_focus_window_(window_util::GetFocusedWindow()), active_window_before_overview_(window_util::GetActiveWindow()),
overview_start_time_(base::Time::Now()), overview_start_time_(base::Time::Now()),
highlight_controller_( highlight_controller_(
std::make_unique<OverviewHighlightController>(this)) { std::make_unique<OverviewHighlightController>(this)) {
...@@ -235,8 +235,8 @@ void OverviewSession::Init(const WindowList& windows, ...@@ -235,8 +235,8 @@ void OverviewSession::Init(const WindowList& windows,
hide_overview_windows_ = std::make_unique<ScopedOverviewHideWindows>( hide_overview_windows_ = std::make_unique<ScopedOverviewHideWindows>(
std::move(hide_windows), /*force_hidden=*/false); std::move(hide_windows), /*force_hidden=*/false);
if (restore_focus_window_) if (active_window_before_overview_)
restore_focus_window_->AddObserver(this); active_window_before_overview_->AddObserver(this);
aura::Window::Windows root_windows = Shell::GetAllRootWindows(); aura::Window::Windows root_windows = Shell::GetAllRootWindows();
std::sort(root_windows.begin(), root_windows.end(), std::sort(root_windows.begin(), root_windows.end(),
...@@ -353,12 +353,12 @@ void OverviewSession::Shutdown() { ...@@ -353,12 +353,12 @@ void OverviewSession::Shutdown() {
} }
// Setting focus after restoring windows' state avoids unnecessary animations. // Setting focus after restoring windows' state avoids unnecessary animations.
// No need to restore if we are sliding to the home launcher screen, as all // No need to restore if we are fading out to the home launcher screen, as all
// windows will be minimized. // windows will be minimized.
const bool should_focus = const bool should_restore =
enter_exit_overview_type_ == OverviewEnterExitType::kNormal || enter_exit_overview_type_ == OverviewEnterExitType::kNormal ||
enter_exit_overview_type_ == OverviewEnterExitType::kImmediateExit; enter_exit_overview_type_ == OverviewEnterExitType::kImmediateExit;
ResetFocusRestoreWindow(should_focus); RestoreWindowActivation(should_restore);
RemoveAllObservers(); RemoveAllObservers();
for (std::unique_ptr<OverviewGrid>& overview_grid : grid_list_) for (std::unique_ptr<OverviewGrid>& overview_grid : grid_list_)
...@@ -574,9 +574,9 @@ void OverviewSession::RemoveItem(OverviewItem* overview_item) { ...@@ -574,9 +574,9 @@ void OverviewSession::RemoveItem(OverviewItem* overview_item) {
void OverviewSession::RemoveItem(OverviewItem* overview_item, void OverviewSession::RemoveItem(OverviewItem* overview_item,
bool item_destroying, bool item_destroying,
bool reposition) { bool reposition) {
if (overview_item->GetWindow() == restore_focus_window_) { if (overview_item->GetWindow() == active_window_before_overview_) {
restore_focus_window_->RemoveObserver(this); active_window_before_overview_->RemoveObserver(this);
restore_focus_window_ = nullptr; active_window_before_overview_ = nullptr;
} }
overview_item->overview_grid()->RemoveItem(overview_item, item_destroying, overview_item->overview_grid()->RemoveItem(overview_item, item_destroying,
...@@ -802,9 +802,9 @@ void OverviewSession::OnWindowActivating( ...@@ -802,9 +802,9 @@ void OverviewSession::OnWindowActivating(
} }
if (!gained_active) { if (!gained_active) {
// Cancel overview session and do not restore focus when active window is // Cancel overview session and do not restore activation when active window
// set to nullptr. This happens when removing a display. // is set to nullptr. This happens when removing a display.
ResetFocusRestoreWindow(false); RestoreWindowActivation(false);
EndOverview(); EndOverview();
return; return;
} }
...@@ -814,7 +814,7 @@ void OverviewSession::OnWindowActivating( ...@@ -814,7 +814,7 @@ void OverviewSession::OnWindowActivating(
// mode, so do not handle it here. // mode, so do not handle it here.
if (gained_active == Shell::Get()->app_list_controller()->GetWindow() && if (gained_active == Shell::Get()->app_list_controller()->GetWindow() &&
!Shell::Get()->tablet_mode_controller()->InTabletMode()) { !Shell::Get()->tablet_mode_controller()->InTabletMode()) {
ResetFocusRestoreWindow(false); RestoreWindowActivation(false);
EndOverview(); EndOverview();
return; return;
} }
...@@ -851,8 +851,8 @@ void OverviewSession::OnWindowActivating( ...@@ -851,8 +851,8 @@ void OverviewSession::OnWindowActivating(
if (iter != windows.end()) if (iter != windows.end())
selected_item_ = iter->get(); selected_item_ = iter->get();
// Don't restore focus on exit if a window was just activated. // Don't restore window activation on exit if a window was just activated.
ResetFocusRestoreWindow(false); RestoreWindowActivation(false);
EndOverview(); EndOverview();
} }
...@@ -888,23 +888,23 @@ bool OverviewSession::IsEmpty() const { ...@@ -888,23 +888,23 @@ bool OverviewSession::IsEmpty() const {
return true; return true;
} }
void OverviewSession::ResetFocusRestoreWindow(bool focus) { void OverviewSession::RestoreWindowActivation(bool restore) {
if (!restore_focus_window_) if (!active_window_before_overview_)
return; return;
// Do not restore focus to a window that exists on an inactive desk. // Do not restore focus to a window that exists on an inactive desk.
focus &= base::Contains(DesksController::Get()->active_desk()->windows(), restore &= base::Contains(DesksController::Get()->active_desk()->windows(),
restore_focus_window_); active_window_before_overview_);
// Ensure the window is still in the window hierarchy and not in the middle // Ensure the window is still in the window hierarchy and not in the middle
// of teardown. // of teardown.
if (focus && restore_focus_window_->GetRootWindow()) { if (restore && active_window_before_overview_->GetRootWindow()) {
base::AutoReset<bool> restoring_focus(&ignore_activations_, true); base::AutoReset<bool> restoring_focus(&ignore_activations_, true);
wm::ActivateWindow(restore_focus_window_); wm::ActivateWindow(active_window_before_overview_);
} }
restore_focus_window_->RemoveObserver(this); active_window_before_overview_->RemoveObserver(this);
restore_focus_window_ = nullptr; active_window_before_overview_ = nullptr;
} }
void OverviewSession::OnHighlightedItemActivated(OverviewItem* item) { void OverviewSession::OnHighlightedItemActivated(OverviewItem* item) {
...@@ -996,9 +996,9 @@ void OverviewSession::OnDisplayMetricsChanged(const display::Display& display, ...@@ -996,9 +996,9 @@ void OverviewSession::OnDisplayMetricsChanged(const display::Display& display,
} }
void OverviewSession::OnWindowDestroying(aura::Window* window) { void OverviewSession::OnWindowDestroying(aura::Window* window) {
DCHECK_EQ(restore_focus_window_, window); DCHECK_EQ(active_window_before_overview_, window);
restore_focus_window_->RemoveObserver(this); active_window_before_overview_->RemoveObserver(this);
restore_focus_window_ = nullptr; active_window_before_overview_ = nullptr;
} }
void OverviewSession::OnKeyEvent(ui::KeyEvent* event) { void OverviewSession::OnKeyEvent(ui::KeyEvent* event) {
...@@ -1203,9 +1203,9 @@ bool OverviewSession::ProcessForScrolling(const ui::KeyEvent& event) { ...@@ -1203,9 +1203,9 @@ bool OverviewSession::ProcessForScrolling(const ui::KeyEvent& event) {
void OverviewSession::RemoveAllObservers() { void OverviewSession::RemoveAllObservers() {
display::Screen::GetScreen()->RemoveObserver(this); display::Screen::GetScreen()->RemoveObserver(this);
if (restore_focus_window_) if (active_window_before_overview_)
restore_focus_window_->RemoveObserver(this); active_window_before_overview_->RemoveObserver(this);
restore_focus_window_ = nullptr; active_window_before_overview_ = nullptr;
} }
void OverviewSession::UpdateNoWindowsWidget() { void OverviewSession::UpdateNoWindowsWidget() {
......
...@@ -227,9 +227,12 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver, ...@@ -227,9 +227,12 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver,
// Returns true if all its window grids don't have any window item. // Returns true if all its window grids don't have any window item.
bool IsEmpty() const; bool IsEmpty() const;
// If |focus| is true, restores focus to |restore_focus_window_|. Sets // If |restore| is true, activate window |active_window_before_overview_|.
// |restore_focus_window_| to null regardless of |focus|. // This is usually called when exiting overview to restore window activation
void ResetFocusRestoreWindow(bool focus); // to the window that was active before entering overview. If |restore| is
// false, reset |active_window_before_overview_| to nullptr so that window
// activation will not be restore when overview is ended.
void RestoreWindowActivation(bool restore);
// Handles requests to active or close the currently highlighted |item|. // Handles requests to active or close the currently highlighted |item|.
void OnHighlightedItemActivated(OverviewItem* item); void OnHighlightedItemActivated(OverviewItem* item);
...@@ -341,9 +344,9 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver, ...@@ -341,9 +344,9 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver,
// is made. // is made.
OverviewDelegate* delegate_; OverviewDelegate* delegate_;
// A weak pointer to the window which was focused on starting overview. If // A weak pointer to the window which was active on starting overview. If
// overview is canceled the focus should be restored to this window. // overview is canceled the activation should be restored to this window.
aura::Window* restore_focus_window_ = nullptr; aura::Window* active_window_before_overview_ = nullptr;
// A hidden window that receives focus while in overview mode. It is needed // A hidden window that receives focus while in overview mode. It is needed
// because accessibility needs something focused for it to work and we cannot // because accessibility needs something focused for it to work and we cannot
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment