| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_APP_LIST_PRESENTER_APP_LIST_PRESENTER_IMPL_H_ | 5 #ifndef UI_APP_LIST_PRESENTER_APP_LIST_PRESENTER_IMPL_H_ |
| 6 #define UI_APP_LIST_PRESENTER_APP_LIST_PRESENTER_IMPL_H_ | 6 #define UI_APP_LIST_PRESENTER_APP_LIST_PRESENTER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ui/app_list/pagination_model_observer.h" | 12 #include "ui/app_list/pagination_model_observer.h" |
| 13 #include "ui/app_list/presenter/app_list_presenter.h" | 13 #include "ui/app_list/presenter/app_list_presenter.mojom.h" |
| 14 #include "ui/app_list/presenter/app_list_presenter_delegate.h" | 14 #include "ui/app_list/presenter/app_list_presenter_delegate.h" |
| 15 #include "ui/app_list/presenter/app_list_presenter_export.h" |
| 15 #include "ui/aura/client/focus_change_observer.h" | 16 #include "ui/aura/client/focus_change_observer.h" |
| 16 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
| 17 #include "ui/compositor/layer_animation_observer.h" | 18 #include "ui/compositor/layer_animation_observer.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/views/widget/widget_observer.h" | 20 #include "ui/views/widget/widget_observer.h" |
| 20 | 21 |
| 21 namespace app_list { | 22 namespace app_list { |
| 22 class AppListView; | 23 class AppListView; |
| 23 class AppListViewDelegate; | 24 class AppListViewDelegate; |
| 24 class AppListPresenterDelegateFactory; | 25 class AppListPresenterDelegateFactory; |
| 25 | 26 |
| 26 namespace test { | 27 namespace test { |
| 27 class AppListPresenterImplTestApi; | 28 class AppListPresenterImplTestApi; |
| 28 } | 29 } |
| 29 | 30 |
| 30 class AppListViewDelegate; | 31 class AppListViewDelegate; |
| 31 | 32 |
| 32 // Manages app list UI. Creates AppListView and schedules showing/hiding | 33 // Manages app list UI. Creates AppListView and schedules showing/hiding |
| 33 // animation. While the UI is visible, it monitors things such as app list | 34 // animation. While the UI is visible, it monitors things such as app list |
| 34 // activation state to auto dismiss the UI. Delegates the responsibility | 35 // activation state to auto dismiss the UI. Delegates the responsibility |
| 35 // for laying out the app list UI to ash::AppListLayoutDelegate. | 36 // for laying out the app list UI to ash::AppListLayoutDelegate. |
| 36 class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl | 37 class APP_LIST_PRESENTER_EXPORT AppListPresenterImpl |
| 37 : public AppListPresenter, | 38 : public aura::client::FocusChangeObserver, |
| 38 public aura::client::FocusChangeObserver, | |
| 39 public aura::WindowObserver, | 39 public aura::WindowObserver, |
| 40 public ui::ImplicitAnimationObserver, | 40 public ui::ImplicitAnimationObserver, |
| 41 public views::WidgetObserver, | 41 public views::WidgetObserver, |
| 42 public PaginationModelObserver { | 42 public PaginationModelObserver { |
| 43 public: | 43 public: |
| 44 explicit AppListPresenterImpl(AppListPresenterDelegateFactory* factory); | 44 explicit AppListPresenterImpl( |
| 45 std::unique_ptr<AppListPresenterDelegateFactory> factory); |
| 45 ~AppListPresenterImpl() override; | 46 ~AppListPresenterImpl() override; |
| 46 | 47 |
| 47 // Returns app list window or NULL if it is not visible. | 48 // Returns app list window or NULL if it is not visible. |
| 48 aura::Window* GetWindow(); | 49 aura::Window* GetWindow(); |
| 49 | 50 |
| 50 // Returns app list view if one exists, or NULL otherwise. | 51 // Returns app list view if one exists, or NULL otherwise. |
| 51 AppListView* GetView() { return view_; } | 52 AppListView* GetView() { return view_; } |
| 52 | 53 |
| 53 // AppListPresenter: | 54 // Show/hide app list window. The |window| is used to deterime in which |
| 54 void Show(int64_t display_id) override; | 55 // display (in which the |window| exists) the app list should be shown. |
| 55 void Dismiss() final; | 56 void Show(int64_t display_id); |
| 56 void ToggleAppList(int64_t display_id) override; | 57 |
| 57 bool IsVisible() const override; | 58 // Invoked to dismiss app list. This may leave the view open but hidden from |
| 58 bool GetTargetVisibility() const override; | 59 // the user. |
| 60 void Dismiss(); |
| 61 |
| 62 // Show the app list if it is visible, hide it if it is hidden. |
| 63 void ToggleAppList(int64_t display_id); |
| 64 |
| 65 // Returns current visibility of the app list. |
| 66 bool IsVisible() const; |
| 67 |
| 68 // Returns target visibility. This may differ from IsVisible() if a visibility |
| 69 // transition is in progress. |
| 70 bool GetTargetVisibility() const; |
| 71 |
| 72 // Sets the app list interface pointer; used to report visibility changes. |
| 73 void SetAppList(mojom::AppListPtr app_list); |
| 59 | 74 |
| 60 private: | 75 private: |
| 61 friend class test::AppListPresenterImplTestApi; | 76 friend class test::AppListPresenterImplTestApi; |
| 62 | 77 |
| 63 // Sets the app list view and attempts to show it. | 78 // Sets the app list view and attempts to show it. |
| 64 void SetView(AppListView* view); | 79 void SetView(AppListView* view); |
| 65 | 80 |
| 66 // Forgets the view. | 81 // Forgets the view. |
| 67 void ResetView(); | 82 void ResetView(); |
| 68 | 83 |
| 69 // Starts show/hide animation. | 84 // Starts show/hide animation. |
| 70 void ScheduleAnimation(); | 85 void ScheduleAnimation(); |
| 71 | 86 |
| 72 // aura::client::FocusChangeObserver overrides: | 87 // aura::client::FocusChangeObserver overrides: |
| 73 void OnWindowFocused(aura::Window* gained_focus, | 88 void OnWindowFocused(aura::Window* gained_focus, |
| 74 aura::Window* lost_focus) override; | 89 aura::Window* lost_focus) override; |
| 75 | 90 |
| 76 // aura::WindowObserver overrides: | 91 // aura::WindowObserver overrides: |
| 77 void OnWindowBoundsChanged(aura::Window* root, | 92 void OnWindowBoundsChanged(aura::Window* root, |
| 78 const gfx::Rect& old_bounds, | 93 const gfx::Rect& old_bounds, |
| 79 const gfx::Rect& new_bounds) override; | 94 const gfx::Rect& new_bounds) override; |
| 80 | 95 |
| 81 // ui::ImplicitAnimationObserver overrides: | 96 // ui::ImplicitAnimationObserver overrides: |
| 82 void OnImplicitAnimationsCompleted() override; | 97 void OnImplicitAnimationsCompleted() override; |
| 83 | 98 |
| 84 // views::WidgetObserver overrides: | 99 // views::WidgetObserver overrides: |
| 85 void OnWidgetDestroying(views::Widget* widget) override; | 100 void OnWidgetDestroying(views::Widget* widget) override; |
| 101 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override; |
| 86 | 102 |
| 87 // PaginationModelObserver overrides: | 103 // PaginationModelObserver overrides: |
| 88 void TotalPagesChanged() override; | 104 void TotalPagesChanged() override; |
| 89 void SelectedPageChanged(int old_selected, int new_selected) override; | 105 void SelectedPageChanged(int old_selected, int new_selected) override; |
| 90 void TransitionStarted() override; | 106 void TransitionStarted() override; |
| 91 void TransitionChanged() override; | 107 void TransitionChanged() override; |
| 92 | 108 |
| 93 // Not owned | 109 // The factory for the presenter's delegate. |
| 94 AppListPresenterDelegateFactory* const factory_; | 110 std::unique_ptr<AppListPresenterDelegateFactory> factory_; |
| 95 | 111 |
| 96 // Responsible for laying out the app list UI. | 112 // Responsible for laying out the app list UI. |
| 97 std::unique_ptr<AppListPresenterDelegate> presenter_delegate_; | 113 std::unique_ptr<AppListPresenterDelegate> presenter_delegate_; |
| 98 | 114 |
| 99 // Whether we should show or hide app list widget. | 115 // Whether we should show or hide app list widget. |
| 100 bool is_visible_ = false; | 116 bool is_visible_ = false; |
| 101 | 117 |
| 102 // The AppListView this class manages, owned by its widget. | 118 // The AppListView this class manages, owned by its widget. |
| 103 AppListView* view_ = nullptr; | 119 AppListView* view_ = nullptr; |
| 104 | 120 |
| 105 // The current page of the AppsGridView of |view_|. This is stored outside of | 121 // The current page of the AppsGridView of |view_|. This is stored outside of |
| 106 // the view's PaginationModel, so that it persists when the view is destroyed. | 122 // the view's PaginationModel, so that it persists when the view is destroyed. |
| 107 int current_apps_page_ = -1; | 123 int current_apps_page_ = -1; |
| 108 | 124 |
| 109 // Cached bounds of |view_| for snapping back animation after over-scroll. | 125 // Cached bounds of |view_| for snapping back animation after over-scroll. |
| 110 gfx::Rect view_bounds_; | 126 gfx::Rect view_bounds_; |
| 111 | 127 |
| 112 // Whether should schedule snap back animation. | 128 // Whether should schedule snap back animation. |
| 113 bool should_snap_back_ = false; | 129 bool should_snap_back_ = false; |
| 114 | 130 |
| 131 // The app list interface pointer; used for reporting visibility changes. |
| 132 mojom::AppListPtr app_list_; |
| 133 |
| 115 DISALLOW_COPY_AND_ASSIGN(AppListPresenterImpl); | 134 DISALLOW_COPY_AND_ASSIGN(AppListPresenterImpl); |
| 116 }; | 135 }; |
| 117 | 136 |
| 118 } // namespace app_list | 137 } // namespace app_list |
| 119 | 138 |
| 120 #endif // UI_APP_LIST_PRESENTER_APP_LIST_PRESENTER_IMPL_H_ | 139 #endif // UI_APP_LIST_PRESENTER_APP_LIST_PRESENTER_IMPL_H_ |
| OLD | NEW |