blob: 60172f1e29928cb580667beaf306fcf3666b7f9b [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_HOME_SCREEN_HOME_SCREEN_CONTROLLER_H_
#define ASH_HOME_SCREEN_HOME_SCREEN_CONTROLLER_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/home_screen/home_screen_presenter.h"
#include "ash/public/cpp/wallpaper_controller_observer.h"
#include "ash/wm/overview/overview_observer.h"
#include "ash/wm/overview/overview_session.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_observer.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/scoped_observer.h"
namespace ash {
class FpsCounter;
class HomeLauncherGestureHandler;
class HomeScreenDelegate;
// HomeScreenController handles the home launcher (e.g., tablet-mode app list)
// and owns the HomeLauncherGestureHandler that transitions the launcher window
// and other windows when the launcher is shown, hidden or animated.
class ASH_EXPORT HomeScreenController : public OverviewObserver,
public SplitViewObserver,
public WallpaperControllerObserver {
public:
HomeScreenController();
~HomeScreenController() override;
// Shows the home screen.
void Show();
// Takes the user to the home screen, either by ending Overview Mode/Split
// View Mode or by minimizing the other windows. Returns false if there was
// nothing to do because the given display was already "home".
bool GoHome(int64_t display_id);
// Sets the delegate for home screen animations.
void SetDelegate(HomeScreenDelegate* delegate);
// Called when a window starts/ends dragging. If the home screen is shown, we
// should hide it during dragging a window and reshow it when the drag ends.
void OnWindowDragStarted();
// If |animate| is true, scale-in-to-show home screen if home screen should
// be shown after drag ends.
void OnWindowDragEnded(bool animate);
// True if home screen is visible.
bool IsHomeScreenVisible() const;
// Responsible to starting or stopping |fps_counter_|.
void StartTrackingAnimationSmoothness(int64_t display_id);
void RecordAnimationSmoothness();
// Called when the app list view is shown.
// Note that IsHomeScreenVisible() might still return false at this point, as
// the home screen visibility takes into account whether the app list view is
// obscured by an app window, or overview UI. This method gets called when the
// app list view widget visibility changes (regardless of whether anything is
// stacked above the home screen).
// TODO(https://crbug.com/1053316): Make the home screen visibility API, and
// relationship between home screen controller and app list controller less
// confusing. HomeScreenController logic can probably be folded into
// AppListController (as level of abstraction it's providing is no longer
// necessary).
void OnAppListViewShown();
// Called when the app list view is hidden.
void OnAppListViewClosing();
// SplitViewObserver:
void OnSplitViewStateChanged(SplitViewController::State previous_state,
SplitViewController::State state) override;
HomeScreenDelegate* delegate() { return delegate_; }
HomeLauncherGestureHandler* home_launcher_gesture_handler() {
return home_launcher_gesture_handler_.get();
}
private:
// OverviewObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnding(OverviewSession* overview_session) override;
void OnOverviewModeEndingAnimationComplete(bool canceled) override;
// WallpaperControllerObserver:
void OnWallpaperPreviewStarted() override;
void OnWallpaperPreviewEnded() override;
// Updates the visibility of the home screen based on e.g. if the device is
// in overview mode.
void UpdateVisibility();
// Notifies home screen delegate that a home launcher transition has ended.
// |shown| - whether the final home state was shown.
// |display_id| - the home screen display ID.
void NotifyHomeLauncherTransitionEnded(bool shown, int64_t display_id);
// Returns true if home screen should be shown based on the current
// configuration.
bool ShouldShowHomeScreen() const;
// Whether the wallpaper is being previewed. The home screen should be hidden
// during wallpaper preview.
bool in_wallpaper_preview_ = false;
// Whether we're currently in a window dragging process.
bool in_window_dragging_ = false;
// Not owned.
HomeScreenDelegate* delegate_ = nullptr;
// Owned pointer to the object which handles gestures related to the home
// launcher.
std::unique_ptr<HomeLauncherGestureHandler> home_launcher_gesture_handler_;
// Presenter that manages home screen animations.
HomeScreenPresenter home_screen_presenter_{this};
// The last overview mode exit type - cached when the overview exit starts, so
// it can be used to decide how to update home screen when overview mode exit
// animations are finished (at which point this information will not be
// available).
base::Optional<OverviewSession::EnterExitOverviewType> overview_exit_type_;
// Responsible for recording smoothness related UMA stats for homescreen
// animations.
std::unique_ptr<FpsCounter> fps_counter_;
ScopedObserver<SplitViewController, SplitViewObserver> split_view_observer_{
this};
base::WeakPtrFactory<HomeScreenController> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(HomeScreenController);
};
} // namespace ash
#endif // ASH_HOME_SCREEN_HOME_SCREEN_CONTROLLER_H_