Commit 436f594a authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: More accurately track whether the app list has been hidden

This should fix the linked bug.

Bug: 1018362
Change-Id: I8ca7543b7a2eb382d091c4cb78c0cce0cbf0b806
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1883654
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712336}
parent f9b56089
......@@ -49,6 +49,9 @@ class APP_LIST_EXPORT AppListPresenterDelegate {
// Returns whether the on-screen keyboard is shown.
virtual bool GetOnScreenKeyboardShown() = 0;
// Returns the container parent of the given window.
virtual aura::Window* GetContainerForWindow(aura::Window* window) = 0;
// Returns the root Window for the given display id. If there is no display
// for |display_id| null is returned.
virtual aura::Window* GetRootWindowForDisplayId(int64_t display_id) = 0;
......
......@@ -23,6 +23,7 @@
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/wm/container_finder.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/command_line.h"
#include "chromeos/constants/chromeos_switches.h"
......@@ -150,6 +151,11 @@ bool AppListPresenterDelegateImpl::GetOnScreenKeyboardShown() {
return controller_->onscreen_keyboard_shown();
}
aura::Window* AppListPresenterDelegateImpl::GetContainerForWindow(
aura::Window* window) {
return ash::GetContainerForWindow(window);
}
aura::Window* AppListPresenterDelegateImpl::GetRootWindowForDisplayId(
int64_t display_id) {
return ash::Shell::Get()->GetRootWindowForDisplayId(display_id);
......
......@@ -48,6 +48,7 @@ class ASH_EXPORT AppListPresenterDelegateImpl : public AppListPresenterDelegate,
bool IsTabletMode() const override;
AppListViewDelegate* GetAppListViewDelegate() override;
bool GetOnScreenKeyboardShown() override;
aura::Window* GetContainerForWindow(aura::Window* window) override;
aura::Window* GetRootWindowForDisplayId(int64_t display_id) override;
void OnVisibilityChanged(bool visible, int64_t display_id) override;
void OnVisibilityWillChange(bool visible, int64_t display_id) override;
......
......@@ -14,6 +14,7 @@
#include "ash/public/cpp/app_list/app_list_switches.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/pagination/pagination_model.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/metrics/histogram_macros.h"
......@@ -59,6 +60,12 @@ void DidPresentCompositorFrame(base::TimeTicks event_time_stamp,
} // namespace
constexpr std::array<int, 6> kIdsOfContainersThatWontHideAppList = {
kShellWindowId_AppListContainer, kShellWindowId_HomeScreenContainer,
kShellWindowId_MenuContainer, kShellWindowId_SettingBubbleContainer,
kShellWindowId_ShelfBubbleContainer, kShellWindowId_ShelfContainer,
};
AppListPresenterImpl::AppListPresenterImpl(
std::unique_ptr<AppListPresenterDelegate> delegate)
: delegate_(std::move(delegate)) {
......@@ -404,12 +411,27 @@ void AppListPresenterImpl::OnVisibilityWillChange(bool visible,
void AppListPresenterImpl::OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) {
if (view_ && is_target_visibility_show_) {
int gained_focus_container_id = kShellWindowId_Invalid;
if (gained_focus) {
gained_focus_container_id = gained_focus->id();
const aura::Window* container =
delegate_->GetContainerForWindow(gained_focus);
if (container)
gained_focus_container_id = container->id();
}
aura::Window* applist_window = view_->GetWidget()->GetNativeView();
aura::Window* applist_container = applist_window->parent();
// An AppList dialog window may take focus from the AppList window. Don't
// consider this a visibility change.
const aura::Window* applist_container = applist_window->parent();
// An AppList dialog window, or a child window of the system tray, may
// take focus from the AppList window. Don't consider this a visibility
// change since the app list is still visible for the most part.
const bool gained_focus_hides_app_list =
gained_focus_container_id != kShellWindowId_Invalid &&
!base::Contains(kIdsOfContainersThatWontHideAppList,
gained_focus_container_id);
const bool app_list_lost_focus =
gained_focus ? !applist_container->Contains(gained_focus)
gained_focus ? gained_focus_hides_app_list
: (lost_focus && applist_container->Contains(lost_focus));
if (delegate_->IsTabletMode()) {
......
......@@ -12,6 +12,8 @@
#include "ash/app_list/views/app_list_item_view.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/apps_grid_view.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/wm/container_finder.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "ui/aura/client/focus_client.h"
......@@ -56,6 +58,9 @@ class AppListPresenterDelegateTest : public AppListPresenterDelegate {
void OnClosed() override {}
bool IsTabletMode() const override { return false; }
bool GetOnScreenKeyboardShown() override { return false; }
aura::Window* GetContainerForWindow(aura::Window* window) override {
return ash::GetContainerForWindow(window);
}
aura::Window* GetRootWindowForDisplayId(int64_t display_id) override {
return container_->GetRootWindow();
}
......@@ -106,7 +111,8 @@ AppListPresenterImplTest::~AppListPresenterImplTest() {}
void AppListPresenterImplTest::SetUp() {
AuraTestBase::SetUp();
new wm::DefaultActivationClient(root_window());
container_.reset(CreateNormalWindow(0, root_window(), nullptr));
container_.reset(CreateNormalWindow(kShellWindowId_AppListContainer,
root_window(), nullptr));
std::unique_ptr<AppListPresenterDelegateTest> presenter_delegate =
std::make_unique<AppListPresenterDelegateTest>(container_.get());
presenter_delegate_ = presenter_delegate.get();
......
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