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(
// split view mode was ended by activating an unsnappable window.
if (state != SplitViewController::State::kNoSnap ||
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
......@@ -1020,7 +1020,6 @@ void OverviewGrid::OnStartingAnimationComplete(bool canceled) {
for (auto& window : window_list())
window->OnStartingAnimationComplete();
}
void OverviewGrid::CalculateWindowListAnimationStates(
......
......@@ -208,7 +208,7 @@ class OverviewSession::AccessibilityFocusAnnotator {
OverviewSession::OverviewSession(OverviewDelegate* delegate)
: delegate_(delegate),
restore_focus_window_(window_util::GetFocusedWindow()),
active_window_before_overview_(window_util::GetActiveWindow()),
overview_start_time_(base::Time::Now()),
highlight_controller_(
std::make_unique<OverviewHighlightController>(this)) {
......@@ -235,8 +235,8 @@ void OverviewSession::Init(const WindowList& windows,
hide_overview_windows_ = std::make_unique<ScopedOverviewHideWindows>(
std::move(hide_windows), /*force_hidden=*/false);
if (restore_focus_window_)
restore_focus_window_->AddObserver(this);
if (active_window_before_overview_)
active_window_before_overview_->AddObserver(this);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
std::sort(root_windows.begin(), root_windows.end(),
......@@ -353,12 +353,12 @@ void OverviewSession::Shutdown() {
}
// 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.
const bool should_focus =
const bool should_restore =
enter_exit_overview_type_ == OverviewEnterExitType::kNormal ||
enter_exit_overview_type_ == OverviewEnterExitType::kImmediateExit;
ResetFocusRestoreWindow(should_focus);
RestoreWindowActivation(should_restore);
RemoveAllObservers();
for (std::unique_ptr<OverviewGrid>& overview_grid : grid_list_)
......@@ -574,9 +574,9 @@ void OverviewSession::RemoveItem(OverviewItem* overview_item) {
void OverviewSession::RemoveItem(OverviewItem* overview_item,
bool item_destroying,
bool reposition) {
if (overview_item->GetWindow() == restore_focus_window_) {
restore_focus_window_->RemoveObserver(this);
restore_focus_window_ = nullptr;
if (overview_item->GetWindow() == active_window_before_overview_) {
active_window_before_overview_->RemoveObserver(this);
active_window_before_overview_ = nullptr;
}
overview_item->overview_grid()->RemoveItem(overview_item, item_destroying,
......@@ -802,9 +802,9 @@ void OverviewSession::OnWindowActivating(
}
if (!gained_active) {
// Cancel overview session and do not restore focus when active window is
// set to nullptr. This happens when removing a display.
ResetFocusRestoreWindow(false);
// Cancel overview session and do not restore activation when active window
// is set to nullptr. This happens when removing a display.
RestoreWindowActivation(false);
EndOverview();
return;
}
......@@ -814,7 +814,7 @@ void OverviewSession::OnWindowActivating(
// mode, so do not handle it here.
if (gained_active == Shell::Get()->app_list_controller()->GetWindow() &&
!Shell::Get()->tablet_mode_controller()->InTabletMode()) {
ResetFocusRestoreWindow(false);
RestoreWindowActivation(false);
EndOverview();
return;
}
......@@ -851,8 +851,8 @@ void OverviewSession::OnWindowActivating(
if (iter != windows.end())
selected_item_ = iter->get();
// Don't restore focus on exit if a window was just activated.
ResetFocusRestoreWindow(false);
// Don't restore window activation on exit if a window was just activated.
RestoreWindowActivation(false);
EndOverview();
}
......@@ -888,23 +888,23 @@ bool OverviewSession::IsEmpty() const {
return true;
}
void OverviewSession::ResetFocusRestoreWindow(bool focus) {
if (!restore_focus_window_)
void OverviewSession::RestoreWindowActivation(bool restore) {
if (!active_window_before_overview_)
return;
// Do not restore focus to a window that exists on an inactive desk.
focus &= base::Contains(DesksController::Get()->active_desk()->windows(),
restore_focus_window_);
restore &= base::Contains(DesksController::Get()->active_desk()->windows(),
active_window_before_overview_);
// Ensure the window is still in the window hierarchy and not in the middle
// of teardown.
if (focus && restore_focus_window_->GetRootWindow()) {
if (restore && active_window_before_overview_->GetRootWindow()) {
base::AutoReset<bool> restoring_focus(&ignore_activations_, true);
wm::ActivateWindow(restore_focus_window_);
wm::ActivateWindow(active_window_before_overview_);
}
restore_focus_window_->RemoveObserver(this);
restore_focus_window_ = nullptr;
active_window_before_overview_->RemoveObserver(this);
active_window_before_overview_ = nullptr;
}
void OverviewSession::OnHighlightedItemActivated(OverviewItem* item) {
......@@ -996,9 +996,9 @@ void OverviewSession::OnDisplayMetricsChanged(const display::Display& display,
}
void OverviewSession::OnWindowDestroying(aura::Window* window) {
DCHECK_EQ(restore_focus_window_, window);
restore_focus_window_->RemoveObserver(this);
restore_focus_window_ = nullptr;
DCHECK_EQ(active_window_before_overview_, window);
active_window_before_overview_->RemoveObserver(this);
active_window_before_overview_ = nullptr;
}
void OverviewSession::OnKeyEvent(ui::KeyEvent* event) {
......@@ -1203,9 +1203,9 @@ bool OverviewSession::ProcessForScrolling(const ui::KeyEvent& event) {
void OverviewSession::RemoveAllObservers() {
display::Screen::GetScreen()->RemoveObserver(this);
if (restore_focus_window_)
restore_focus_window_->RemoveObserver(this);
restore_focus_window_ = nullptr;
if (active_window_before_overview_)
active_window_before_overview_->RemoveObserver(this);
active_window_before_overview_ = nullptr;
}
void OverviewSession::UpdateNoWindowsWidget() {
......
......@@ -227,9 +227,12 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver,
// Returns true if all its window grids don't have any window item.
bool IsEmpty() const;
// If |focus| is true, restores focus to |restore_focus_window_|. Sets
// |restore_focus_window_| to null regardless of |focus|.
void ResetFocusRestoreWindow(bool focus);
// If |restore| is true, activate window |active_window_before_overview_|.
// This is usually called when exiting overview to restore window activation
// 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|.
void OnHighlightedItemActivated(OverviewItem* item);
......@@ -341,9 +344,9 @@ class ASH_EXPORT OverviewSession : public display::DisplayObserver,
// is made.
OverviewDelegate* delegate_;
// A weak pointer to the window which was focused on starting overview. If
// overview is canceled the focus should be restored to this window.
aura::Window* restore_focus_window_ = nullptr;
// A weak pointer to the window which was active on starting overview. If
// overview is canceled the activation should be restored to this window.
aura::Window* active_window_before_overview_ = nullptr;
// 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
......
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