Commit 58c2c84a authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS: Get rid of "IsHomeScreenAvailable"

Whether the home screen is available is strictly equivalent to whether
tablet mode is on. I understand the desire for the extra level of
indirection but it doesn't seem like this is changing anytime soon,
and if/when it does, it won't be hard to re-add :-) In the mean time,
I think we should favor readability / understandability.

Bug: 982512
Change-Id: Ifb34f316ae0fe579ee2854b70025a0b2de216d93
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826198Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Auto-Submit: Manu Cornet <manucornet@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700341}
parent aaf6b747
...@@ -64,10 +64,6 @@ namespace ash { ...@@ -64,10 +64,6 @@ namespace ash {
namespace { namespace {
bool IsHomeScreenAvailable() {
return Shell::Get()->home_screen_controller()->IsHomeScreenAvailable();
}
bool IsTabletMode() { bool IsTabletMode() {
return Shell::Get()->tablet_mode_controller()->InTabletMode(); return Shell::Get()->tablet_mode_controller()->InTabletMode();
} }
...@@ -474,7 +470,7 @@ void AppListControllerImpl::OnAppListItemAdded(app_list::AppListItem* item) { ...@@ -474,7 +470,7 @@ void AppListControllerImpl::OnAppListItemAdded(app_list::AppListItem* item) {
void AppListControllerImpl::OnActiveUserPrefServiceChanged( void AppListControllerImpl::OnActiveUserPrefServiceChanged(
PrefService* /* pref_service */) { PrefService* /* pref_service */) {
if (!IsHomeScreenAvailable()) { if (!IsTabletMode()) {
DismissAppList(); DismissAppList();
return; return;
} }
...@@ -552,7 +548,7 @@ void AppListControllerImpl::UpdateYPositionAndOpacity( ...@@ -552,7 +548,7 @@ void AppListControllerImpl::UpdateYPositionAndOpacity(
int y_position_in_screen, int y_position_in_screen,
float background_opacity) { float background_opacity) {
// Avoid changing app list opacity and position when homecher is enabled. // Avoid changing app list opacity and position when homecher is enabled.
if (IsHomeScreenAvailable()) if (IsTabletMode())
return; return;
presenter_.UpdateYPositionAndOpacity(y_position_in_screen, presenter_.UpdateYPositionAndOpacity(y_position_in_screen,
background_opacity); background_opacity);
...@@ -561,7 +557,7 @@ void AppListControllerImpl::UpdateYPositionAndOpacity( ...@@ -561,7 +557,7 @@ void AppListControllerImpl::UpdateYPositionAndOpacity(
void AppListControllerImpl::EndDragFromShelf( void AppListControllerImpl::EndDragFromShelf(
ash::AppListViewState app_list_state) { ash::AppListViewState app_list_state) {
// Avoid dragging app list when homecher is enabled. // Avoid dragging app list when homecher is enabled.
if (IsHomeScreenAvailable()) if (IsTabletMode())
return; return;
presenter_.EndDragFromShelf(app_list_state); presenter_.EndDragFromShelf(app_list_state);
} }
...@@ -590,7 +586,7 @@ ash::AppListViewState AppListControllerImpl::GetAppListViewState() { ...@@ -590,7 +586,7 @@ ash::AppListViewState AppListControllerImpl::GetAppListViewState() {
} }
void AppListControllerImpl::OnShelfAlignmentChanged(aura::Window* root_window) { void AppListControllerImpl::OnShelfAlignmentChanged(aura::Window* root_window) {
if (!IsHomeScreenAvailable()) if (!IsTabletMode())
DismissAppList(); DismissAppList();
} }
...@@ -601,7 +597,7 @@ void AppListControllerImpl::OnShellDestroying() { ...@@ -601,7 +597,7 @@ void AppListControllerImpl::OnShellDestroying() {
} }
void AppListControllerImpl::OnOverviewModeStarting() { void AppListControllerImpl::OnOverviewModeStarting() {
if (!IsHomeScreenAvailable()) if (!IsTabletMode())
DismissAppList(); DismissAppList();
} }
...@@ -665,7 +661,6 @@ void AppListControllerImpl::OnDisplayConfigurationChanged() { ...@@ -665,7 +661,6 @@ void AppListControllerImpl::OnDisplayConfigurationChanged() {
// expected if it's enabled and we're still in tablet mode. // expected if it's enabled and we're still in tablet mode.
// https://crbug.com/900956. // https://crbug.com/900956.
const bool should_be_shown = IsTabletMode(); const bool should_be_shown = IsTabletMode();
DCHECK_EQ(should_be_shown, IsHomeScreenAvailable());
if (should_be_shown == GetTargetVisibility()) if (should_be_shown == GetTargetVisibility())
return; return;
...@@ -706,7 +701,7 @@ void AppListControllerImpl::OnUiVisibilityChanged( ...@@ -706,7 +701,7 @@ void AppListControllerImpl::OnUiVisibilityChanged(
// When Launcher is closing, we do not want to call // When Launcher is closing, we do not want to call
// |ShowEmbeddedAssistantUI(false)|, which will show previous state page // |ShowEmbeddedAssistantUI(false)|, which will show previous state page
// in Launcher and make the UI flash. // in Launcher and make the UI flash.
if (IsHomeScreenAvailable()) { if (IsTabletMode()) {
base::Optional< base::Optional<
app_list::ContentsView::ScopedSetActiveStateAnimationDisabler> app_list::ContentsView::ScopedSetActiveStateAnimationDisabler>
set_active_state_animation_disabler; set_active_state_animation_disabler;
...@@ -811,7 +806,7 @@ ash::ShelfAction AppListControllerImpl::OnHomeButtonPressed( ...@@ -811,7 +806,7 @@ ash::ShelfAction AppListControllerImpl::OnHomeButtonPressed(
int64_t display_id, int64_t display_id,
app_list::AppListShowSource show_source, app_list::AppListShowSource show_source,
base::TimeTicks event_time_stamp) { base::TimeTicks event_time_stamp) {
if (!IsHomeScreenAvailable()) if (!IsTabletMode())
return ToggleAppList(display_id, show_source, event_time_stamp); return ToggleAppList(display_id, show_source, event_time_stamp);
bool handled = Shell::Get()->home_screen_controller()->GoHome(display_id); bool handled = Shell::Get()->home_screen_controller()->GoHome(display_id);
...@@ -830,9 +825,9 @@ bool AppListControllerImpl::IsShowingEmbeddedAssistantUI() const { ...@@ -830,9 +825,9 @@ bool AppListControllerImpl::IsShowingEmbeddedAssistantUI() const {
void AppListControllerImpl::UpdateExpandArrowVisibility() { void AppListControllerImpl::UpdateExpandArrowVisibility() {
bool should_show = false; bool should_show = false;
// Hide the expand arrow view when the home screen is available and there is // Hide the expand arrow view when in tablet mode and there is no activatable
// no activatable window on the current active desk. // window on the current active desk.
if (IsHomeScreenAvailable()) { if (IsTabletMode()) {
should_show = !ash::Shell::Get() should_show = !ash::Shell::Get()
->mru_window_tracker() ->mru_window_tracker()
->BuildWindowForCycleList(kActiveDesk) ->BuildWindowForCycleList(kActiveDesk)
...@@ -884,7 +879,7 @@ void AppListControllerImpl::StartAssistant() { ...@@ -884,7 +879,7 @@ void AppListControllerImpl::StartAssistant() {
return; return;
} }
if (!IsHomeScreenAvailable()) if (!IsTabletMode())
DismissAppList(); DismissAppList();
ash::Shell::Get()->assistant_controller()->ui_controller()->ShowUi( ash::Shell::Get()->assistant_controller()->ui_controller()->ShowUi(
...@@ -1394,8 +1389,7 @@ void AppListControllerImpl::UpdateAssistantVisibility() { ...@@ -1394,8 +1389,7 @@ void AppListControllerImpl::UpdateAssistantVisibility() {
} }
int64_t AppListControllerImpl::GetDisplayIdToShowAppListOn() { int64_t AppListControllerImpl::GetDisplayIdToShowAppListOn() {
if (IsHomeScreenAvailable() && if (IsTabletMode() && !Shell::Get()->display_manager()->IsInUnifiedMode()) {
!Shell::Get()->display_manager()->IsInUnifiedMode()) {
return display::Display::HasInternalDisplay() return display::Display::HasInternalDisplay()
? display::Display::InternalDisplayId() ? display::Display::InternalDisplayId()
: display::Screen::GetScreen()->GetPrimaryDisplay().id(); : display::Screen::GetScreen()->GetPrimaryDisplay().id();
...@@ -1407,7 +1401,7 @@ int64_t AppListControllerImpl::GetDisplayIdToShowAppListOn() { ...@@ -1407,7 +1401,7 @@ int64_t AppListControllerImpl::GetDisplayIdToShowAppListOn() {
} }
void AppListControllerImpl::ResetHomeLauncherIfShown() { void AppListControllerImpl::ResetHomeLauncherIfShown() {
if (!IsHomeScreenAvailable() || !presenter_.IsVisible()) if (!IsTabletMode() || !presenter_.IsVisible())
return; return;
auto* const keyboard_controller = keyboard::KeyboardUIController::Get(); auto* const keyboard_controller = keyboard::KeyboardUIController::Get();
...@@ -1462,7 +1456,7 @@ aura::Window* AppListControllerImpl::GetContainerForDisplayId( ...@@ -1462,7 +1456,7 @@ aura::Window* AppListControllerImpl::GetContainerForDisplayId(
} }
bool AppListControllerImpl::ShouldLauncherShowBehindApps() const { bool AppListControllerImpl::ShouldLauncherShowBehindApps() const {
return IsHomeScreenAvailable() && return IsTabletMode() &&
model_->state() != ash::AppListState::kStateEmbeddedAssistant; model_->state() != ash::AppListState::kStateEmbeddedAssistant;
} }
......
...@@ -58,12 +58,8 @@ HomeScreenController::~HomeScreenController() { ...@@ -58,12 +58,8 @@ HomeScreenController::~HomeScreenController() {
Shell::Get()->overview_controller()->RemoveObserver(this); Shell::Get()->overview_controller()->RemoveObserver(this);
} }
bool HomeScreenController::IsHomeScreenAvailable() {
return Shell::Get()->tablet_mode_controller()->InTabletMode();
}
void HomeScreenController::Show() { void HomeScreenController::Show() {
DCHECK(IsHomeScreenAvailable()); DCHECK(Shell::Get()->tablet_mode_controller()->InTabletMode());
if (!Shell::Get()->session_controller()->IsActiveUserSessionStarted()) if (!Shell::Get()->session_controller()->IsActiveUserSessionStarted())
return; return;
...@@ -77,7 +73,7 @@ void HomeScreenController::Show() { ...@@ -77,7 +73,7 @@ void HomeScreenController::Show() {
} }
bool HomeScreenController::GoHome(int64_t display_id) { bool HomeScreenController::GoHome(int64_t display_id) {
DCHECK(IsHomeScreenAvailable()); DCHECK(Shell::Get()->tablet_mode_controller()->InTabletMode());
if (home_launcher_gesture_handler_->ShowHomeLauncher( if (home_launcher_gesture_handler_->ShowHomeLauncher(
Shell::Get()->display_manager()->GetDisplayForId(display_id))) { Shell::Get()->display_manager()->GetDisplayForId(display_id))) {
...@@ -160,7 +156,7 @@ void HomeScreenController::OnWallpaperPreviewEnded() { ...@@ -160,7 +156,7 @@ void HomeScreenController::OnWallpaperPreviewEnded() {
} }
void HomeScreenController::UpdateVisibility() { void HomeScreenController::UpdateVisibility() {
if (!IsHomeScreenAvailable()) if (!Shell::Get()->tablet_mode_controller()->InTabletMode())
return; return;
aura::Window* window = delegate_->GetHomeScreenWindow(); aura::Window* window = delegate_->GetHomeScreenWindow();
......
...@@ -27,10 +27,6 @@ class ASH_EXPORT HomeScreenController : public OverviewObserver, ...@@ -27,10 +27,6 @@ class ASH_EXPORT HomeScreenController : public OverviewObserver,
HomeScreenController(); HomeScreenController();
~HomeScreenController() override; ~HomeScreenController() override;
// Returns true if the home screen can be shown (generally corresponds to the
// device being in tablet mode).
bool IsHomeScreenAvailable();
// Shows the home screen. // Shows the home screen.
void Show(); void Show();
......
...@@ -31,7 +31,7 @@ namespace { ...@@ -31,7 +31,7 @@ namespace {
// Returns true if the button should appear activatable. // Returns true if the button should appear activatable.
bool CanActivate() { bool CanActivate() {
return Shell::Get()->home_screen_controller()->IsHomeScreenAvailable() || return Shell::Get()->tablet_mode_controller()->InTabletMode() ||
!Shell::Get()->app_list_controller()->IsVisible(); !Shell::Get()->app_list_controller()->IsVisible();
} }
...@@ -172,9 +172,9 @@ void HomeButtonController::StartAssistantAnimation() { ...@@ -172,9 +172,9 @@ void HomeButtonController::StartAssistantAnimation() {
} }
void HomeButtonController::OnAppListShown() { void HomeButtonController::OnAppListShown() {
// Do not show a highlight if the home screen is available, since the home // Do not show a highlight in tablet mode, since the home screen view is
// screen view is always open in the background. // always open in the background.
if (!Shell::Get()->home_screen_controller()->IsHomeScreenAvailable()) if (!Shell::Get()->tablet_mode_controller()->InTabletMode())
button_->AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); button_->AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr);
is_showing_app_list_ = true; is_showing_app_list_ = true;
RootWindowController::ForWindow(button_->GetWidget()->GetNativeWindow()) RootWindowController::ForWindow(button_->GetWidget()->GetNativeWindow())
......
...@@ -106,25 +106,14 @@ bool IsAppListWindow(const aura::Window* window) { ...@@ -106,25 +106,14 @@ bool IsAppListWindow(const aura::Window* window) {
bool IsTabletModeEnabled() { bool IsTabletModeEnabled() {
// Shell could be destroying. Shell destroys TabletModeController before // Shell could be destroying. Shell destroys TabletModeController before
// closing all windows. // closing all windows.
if (!Shell::Get()->tablet_mode_controller()) return Shell::Get()->tablet_mode_controller() &&
return false; Shell::Get()->tablet_mode_controller()->InTabletMode();
return Shell::Get()->tablet_mode_controller()->InTabletMode();
} }
bool IsHotseatEnabled() { bool IsHotseatEnabled() {
return IsTabletModeEnabled() && chromeos::switches::ShouldShowShelfHotseat(); return IsTabletModeEnabled() && chromeos::switches::ShouldShowShelfHotseat();
} }
bool IsHomeScreenAvailable() {
// Shell could be destroying. Shell destroys HomeScreenController before
// closing all windows.
if (!Shell::Get() || !Shell::Get()->home_screen_controller())
return false;
return Shell::Get()->home_screen_controller()->IsHomeScreenAvailable();
}
// Returns the |WorkspaceWindowState| of the currently active desk on the root // Returns the |WorkspaceWindowState| of the currently active desk on the root
// window of |shelf_window|. // window of |shelf_window|.
WorkspaceWindowState GetShelfWorkspaceWindowState(aura::Window* shelf_window) { WorkspaceWindowState GetShelfWorkspaceWindowState(aura::Window* shelf_window) {
...@@ -632,7 +621,7 @@ ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { ...@@ -632,7 +621,7 @@ ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const {
->home_screen_controller() ->home_screen_controller()
->home_launcher_gesture_handler() ->home_launcher_gesture_handler()
->GetActiveWindow()); ->GetActiveWindow());
if (IsHomeScreenAvailable()) { if (IsTabletModeEnabled()) {
// If the home launcher is shown, being animated, or dragged, show the // If the home launcher is shown, being animated, or dragged, show the
// default background. // default background.
if (is_app_list_visible_ || home_launcher_animation_state_ == kShowing) if (is_app_list_visible_ || home_launcher_animation_state_ == kShowing)
...@@ -1638,7 +1627,7 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( ...@@ -1638,7 +1627,7 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
if (shelf_->auto_hide_lock()) if (shelf_->auto_hide_lock())
return state_.auto_hide_state; return state_.auto_hide_state;
if (shelf_widget_->IsShowingAppList() && !IsHomeScreenAvailable()) if (shelf_widget_->IsShowingAppList() && !IsTabletModeEnabled())
return SHELF_AUTO_HIDE_SHOWN; return SHELF_AUTO_HIDE_SHOWN;
if (shelf_widget_->status_area_widget() && if (shelf_widget_->status_area_widget() &&
...@@ -1781,7 +1770,7 @@ float ShelfLayoutManager::ComputeTargetOpacity(const State& state) const { ...@@ -1781,7 +1770,7 @@ float ShelfLayoutManager::ComputeTargetOpacity(const State& state) const {
bool ShelfLayoutManager::IsShelfHiddenForFullscreen() const { bool ShelfLayoutManager::IsShelfHiddenForFullscreen() const {
// If the non-fullscreen app list should be shown, the shelf should not be // If the non-fullscreen app list should be shown, the shelf should not be
// hidden. // hidden.
if (!IsHomeScreenAvailable() && if (!IsTabletModeEnabled() &&
Shell::Get()->app_list_controller()->GetTargetVisibility()) { Shell::Get()->app_list_controller()->GetTargetVisibility()) {
return false; return false;
} }
...@@ -1957,7 +1946,7 @@ bool ShelfLayoutManager::StartAppListDrag( ...@@ -1957,7 +1946,7 @@ bool ShelfLayoutManager::StartAppListDrag(
float scroll_y_hint) { float scroll_y_hint) {
// If the home screen is available, gesture dragging is handled by // If the home screen is available, gesture dragging is handled by
// HomeLauncherGestureHandler. // HomeLauncherGestureHandler.
if (IsHomeScreenAvailable() && event_in_screen.IsGestureEvent()) if (IsTabletModeEnabled() && event_in_screen.IsGestureEvent())
return false; return false;
// Fullscreen app list can only be dragged from bottom alignment shelf. // Fullscreen app list can only be dragged from bottom alignment shelf.
...@@ -2002,7 +1991,7 @@ bool ShelfLayoutManager::StartAppListDrag( ...@@ -2002,7 +1991,7 @@ bool ShelfLayoutManager::StartAppListDrag(
bool ShelfLayoutManager::StartShelfDrag( bool ShelfLayoutManager::StartShelfDrag(
const ui::LocatedEvent& event_in_screen) { const ui::LocatedEvent& event_in_screen) {
// Disable the shelf dragging if the fullscreen app list is opened. // Disable the shelf dragging if the fullscreen app list is opened.
if (is_app_list_visible_ && !IsHomeScreenAvailable()) if (is_app_list_visible_ && !IsTabletModeEnabled())
return false; return false;
// Also disable shelf drags until the overflow shelf is closed. // Also disable shelf drags until the overflow shelf is closed.
......
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