1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_HOME_SCREEN_HOME_SCREEN_CONTROLLER_H_ 6 #define ASH_HOME_SCREEN_HOME_SCREEN_CONTROLLER_H_ 7 8 #include <memory> 9 10 #include "ash/ash_export.h" 11 #include "ash/home_screen/home_screen_presenter.h" 12 #include "ash/public/cpp/wallpaper_controller_observer.h" 13 #include "ash/wm/overview/overview_observer.h" 14 #include "ash/wm/overview/overview_session.h" 15 #include "ash/wm/splitview/split_view_controller.h" 16 #include "ash/wm/splitview/split_view_observer.h" 17 #include "base/macros.h" 18 #include "base/memory/weak_ptr.h" 19 #include "base/optional.h" 20 #include "base/scoped_observer.h" 21 22 namespace ui { 23 class ThroughputTracker; 24 } 25 26 namespace ash { 27 28 class HomeLauncherGestureHandler; 29 class HomeScreenDelegate; 30 31 // HomeScreenController handles the home launcher (e.g., tablet-mode app list) 32 // and owns the HomeLauncherGestureHandler that transitions the launcher window 33 // and other windows when the launcher is shown, hidden or animated. 34 class ASH_EXPORT HomeScreenController : public OverviewObserver, 35 public SplitViewObserver, 36 public WallpaperControllerObserver { 37 public: 38 HomeScreenController(); 39 ~HomeScreenController() override; 40 41 // Shows the home screen. 42 void Show(); 43 44 // Takes the user to the home screen, either by ending Overview Mode/Split 45 // View Mode or by minimizing the other windows. Returns false if there was 46 // nothing to do because the given display was already "home". 47 bool GoHome(int64_t display_id); 48 49 // Sets the delegate for home screen animations. 50 void SetDelegate(HomeScreenDelegate* delegate); 51 52 // Called when a window starts/ends dragging. If the home screen is shown, we 53 // should hide it during dragging a window and reshow it when the drag ends. 54 void OnWindowDragStarted(); 55 // If |animate| is true, scale-in-to-show home screen if home screen should 56 // be shown after drag ends. 57 void OnWindowDragEnded(bool animate); 58 59 // True if home screen is visible. 60 bool IsHomeScreenVisible() const; 61 62 // Responsible to starting or stopping |smoothness_tracker_|. 63 void StartTrackingAnimationSmoothness(int64_t display_id); 64 void RecordAnimationSmoothness(); 65 66 // Called when the app list view is shown. 67 // Note that IsHomeScreenVisible() might still return false at this point, as 68 // the home screen visibility takes into account whether the app list view is 69 // obscured by an app window, or overview UI. This method gets called when the 70 // app list view widget visibility changes (regardless of whether anything is 71 // stacked above the home screen). 72 // TODO(https://crbug.com/1053316): Make the home screen visibility API, and 73 // relationship between home screen controller and app list controller less 74 // confusing. HomeScreenController logic can probably be folded into 75 // AppListController (as level of abstraction it's providing is no longer 76 // necessary). 77 void OnAppListViewShown(); 78 79 // Called when the app list view is hidden. 80 void OnAppListViewClosing(); 81 82 // SplitViewObserver: 83 void OnSplitViewStateChanged(SplitViewController::State previous_state, 84 SplitViewController::State state) override; 85 delegate()86 HomeScreenDelegate* delegate() { return delegate_; } 87 home_launcher_gesture_handler()88 HomeLauncherGestureHandler* home_launcher_gesture_handler() { 89 return home_launcher_gesture_handler_.get(); 90 } 91 92 private: 93 // OverviewObserver: 94 void OnOverviewModeStarting() override; 95 void OnOverviewModeEnding(OverviewSession* overview_session) override; 96 void OnOverviewModeEndingAnimationComplete(bool canceled) override; 97 98 // WallpaperControllerObserver: 99 void OnWallpaperPreviewStarted() override; 100 void OnWallpaperPreviewEnded() override; 101 102 // Updates the visibility of the home screen based on e.g. if the device is 103 // in overview mode. 104 void UpdateVisibility(); 105 106 // Notifies home screen delegate that a home launcher transition has ended. 107 // |shown| - whether the final home state was shown. 108 // |display_id| - the home screen display ID. 109 void NotifyHomeLauncherTransitionEnded(bool shown, int64_t display_id); 110 111 // Returns true if home screen should be shown based on the current 112 // configuration. 113 bool ShouldShowHomeScreen() const; 114 115 // Whether the wallpaper is being previewed. The home screen should be hidden 116 // during wallpaper preview. 117 bool in_wallpaper_preview_ = false; 118 119 // Whether we're currently in a window dragging process. 120 bool in_window_dragging_ = false; 121 122 // Not owned. 123 HomeScreenDelegate* delegate_ = nullptr; 124 125 // Owned pointer to the object which handles gestures related to the home 126 // launcher. 127 std::unique_ptr<HomeLauncherGestureHandler> home_launcher_gesture_handler_; 128 129 // Presenter that manages home screen animations. 130 HomeScreenPresenter home_screen_presenter_{this}; 131 132 // The last overview mode exit type - cached when the overview exit starts, so 133 // it can be used to decide how to update home screen when overview mode exit 134 // animations are finished (at which point this information will not be 135 // available). 136 base::Optional<OverviewEnterExitType> overview_exit_type_; 137 138 // Responsible for recording smoothness related UMA stats for homescreen 139 // animations. 140 base::Optional<ui::ThroughputTracker> smoothness_tracker_; 141 142 ScopedObserver<SplitViewController, SplitViewObserver> split_view_observer_{ 143 this}; 144 145 base::WeakPtrFactory<HomeScreenController> weak_ptr_factory_{this}; 146 147 DISALLOW_COPY_AND_ASSIGN(HomeScreenController); 148 }; 149 150 } // namespace ash 151 152 #endif // ASH_HOME_SCREEN_HOME_SCREEN_CONTROLLER_H_ 153