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 #include "ui/app_list/presenter/app_list_presenter_impl.h" | 5 #include "ui/app_list/presenter/app_list_presenter_impl.h" |
6 | 6 |
7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
8 #include "ui/app_list/app_list_switches.h" | 8 #include "ui/app_list/app_list_switches.h" |
9 #include "ui/app_list/pagination_model.h" | 9 #include "ui/app_list/pagination_model.h" |
10 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" | 10 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // The maximum shift in pixels when over-scroll happens. | 24 // The maximum shift in pixels when over-scroll happens. |
25 const int kMaxOverScrollShift = 48; | 25 const int kMaxOverScrollShift = 48; |
26 | 26 |
27 ui::Layer* GetLayer(views::Widget* widget) { | 27 ui::Layer* GetLayer(views::Widget* widget) { |
28 return widget->GetNativeView()->layer(); | 28 return widget->GetNativeView()->layer(); |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 AppListPresenterImpl::AppListPresenterImpl( | 33 AppListPresenterImpl::AppListPresenterImpl( |
34 AppListPresenterDelegateFactory* factory) | 34 std::unique_ptr<AppListPresenterDelegateFactory> factory) |
35 : factory_(factory) { | 35 : factory_(std::move(factory)) { |
36 DCHECK(factory); | 36 DCHECK(factory_); |
37 } | 37 } |
38 | 38 |
39 AppListPresenterImpl::~AppListPresenterImpl() { | 39 AppListPresenterImpl::~AppListPresenterImpl() { |
40 Dismiss(); | 40 Dismiss(); |
41 presenter_delegate_.reset(); | 41 presenter_delegate_.reset(); |
42 // Ensures app list view goes before the controller since pagination model | 42 // Ensures app list view goes before the controller since pagination model |
43 // lives in the controller and app list view would access it on destruction. | 43 // lives in the controller and app list view would access it on destruction. |
44 if (view_) { | 44 if (view_) { |
45 view_->GetAppsPaginationModel()->RemoveObserver(this); | 45 view_->GetAppsPaginationModel()->RemoveObserver(this); |
46 if (view_->GetWidget()) | 46 if (view_->GetWidget()) |
47 view_->GetWidget()->CloseNow(); | 47 view_->GetWidget()->CloseNow(); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 aura::Window* AppListPresenterImpl::GetWindow() { | 51 aura::Window* AppListPresenterImpl::GetWindow() { |
52 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : nullptr; | 52 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : nullptr; |
53 } | 53 } |
54 | 54 |
55 void AppListPresenterImpl::Show(int64_t display_id) { | 55 void AppListPresenterImpl::Show(int64_t display_id) { |
56 if (is_visible_) | 56 if (is_visible_) |
57 return; | 57 return; |
58 | 58 |
59 is_visible_ = true; | 59 is_visible_ = true; |
| 60 if (app_list_) |
| 61 app_list_->OnTargetVisibilityChanged(GetTargetVisibility()); |
| 62 |
60 if (view_) { | 63 if (view_) { |
61 ScheduleAnimation(); | 64 ScheduleAnimation(); |
62 } else { | 65 } else { |
63 presenter_delegate_ = factory_->GetDelegate(this); | 66 presenter_delegate_ = factory_->GetDelegate(this); |
64 AppListViewDelegate* view_delegate = presenter_delegate_->GetViewDelegate(); | 67 AppListViewDelegate* view_delegate = presenter_delegate_->GetViewDelegate(); |
65 DCHECK(view_delegate); | 68 DCHECK(view_delegate); |
66 // Note the AppListViewDelegate outlives the AppListView. For Ash, the view | 69 // Note the AppListViewDelegate outlives the AppListView. For Ash, the view |
67 // is destroyed when dismissed. | 70 // is destroyed when dismissed. |
68 AppListView* view = new AppListView(view_delegate); | 71 AppListView* view = new AppListView(view_delegate); |
69 presenter_delegate_->Init(view, display_id, current_apps_page_); | 72 presenter_delegate_->Init(view, display_id, current_apps_page_); |
70 SetView(view); | 73 SetView(view); |
71 } | 74 } |
72 presenter_delegate_->OnShown(display_id); | 75 presenter_delegate_->OnShown(display_id); |
73 } | 76 } |
74 | 77 |
75 void AppListPresenterImpl::Dismiss() { | 78 void AppListPresenterImpl::Dismiss() { |
76 if (!is_visible_) | 79 if (!is_visible_) |
77 return; | 80 return; |
78 | 81 |
79 // If the app list is currently visible, there should be an existing view. | 82 // If the app list is currently visible, there should be an existing view. |
80 DCHECK(view_); | 83 DCHECK(view_); |
81 | 84 |
82 is_visible_ = false; | 85 is_visible_ = false; |
| 86 if (app_list_) |
| 87 app_list_->OnTargetVisibilityChanged(GetTargetVisibility()); |
83 | 88 |
84 // The dismissal may have occurred in response to the app list losing | 89 // The dismissal may have occurred in response to the app list losing |
85 // activation. Otherwise, our widget is currently active. When the animation | 90 // activation. Otherwise, our widget is currently active. When the animation |
86 // completes we'll hide the widget, changing activation. If a menu is shown | 91 // completes we'll hide the widget, changing activation. If a menu is shown |
87 // before the animation completes then the activation change triggers the menu | 92 // before the animation completes then the activation change triggers the menu |
88 // to close. By deactivating now we ensure there is no activation change when | 93 // to close. By deactivating now we ensure there is no activation change when |
89 // the animation completes and any menus stay open. | 94 // the animation completes and any menus stay open. |
90 if (view_->GetWidget()->IsActive()) | 95 if (view_->GetWidget()->IsActive()) |
91 view_->GetWidget()->Deactivate(); | 96 view_->GetWidget()->Deactivate(); |
92 | 97 |
(...skipping 10 matching lines...) Expand all Loading... |
103 } | 108 } |
104 | 109 |
105 bool AppListPresenterImpl::IsVisible() const { | 110 bool AppListPresenterImpl::IsVisible() const { |
106 return view_ && view_->GetWidget()->IsVisible(); | 111 return view_ && view_->GetWidget()->IsVisible(); |
107 } | 112 } |
108 | 113 |
109 bool AppListPresenterImpl::GetTargetVisibility() const { | 114 bool AppListPresenterImpl::GetTargetVisibility() const { |
110 return is_visible_; | 115 return is_visible_; |
111 } | 116 } |
112 | 117 |
| 118 void AppListPresenterImpl::SetAppList(mojom::AppListPtr app_list) { |
| 119 DCHECK(app_list); |
| 120 app_list_ = std::move(app_list); |
| 121 // Notify the app list interface of the current [target] visibility. |
| 122 app_list_->OnTargetVisibilityChanged(GetTargetVisibility()); |
| 123 app_list_->OnVisibilityChanged(IsVisible()); |
| 124 } |
| 125 |
113 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// |
114 // AppListPresenterImpl, private: | 127 // AppListPresenterImpl, private: |
115 | 128 |
116 void AppListPresenterImpl::SetView(AppListView* view) { | 129 void AppListPresenterImpl::SetView(AppListView* view) { |
117 DCHECK(view_ == nullptr); | 130 DCHECK(view_ == nullptr); |
118 DCHECK(is_visible_); | 131 DCHECK(is_visible_); |
119 | 132 |
120 view_ = view; | 133 view_ = view; |
121 views::Widget* widget = view_->GetWidget(); | 134 views::Widget* widget = view_->GetWidget(); |
122 widget->AddObserver(this); | 135 widget->AddObserver(this); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 if (is_visible_) | 217 if (is_visible_) |
205 view_->GetWidget()->Activate(); | 218 view_->GetWidget()->Activate(); |
206 else | 219 else |
207 view_->GetWidget()->Close(); | 220 view_->GetWidget()->Close(); |
208 } | 221 } |
209 | 222 |
210 //////////////////////////////////////////////////////////////////////////////// | 223 //////////////////////////////////////////////////////////////////////////////// |
211 // AppListPresenterImpl, views::WidgetObserver implementation: | 224 // AppListPresenterImpl, views::WidgetObserver implementation: |
212 | 225 |
213 void AppListPresenterImpl::OnWidgetDestroying(views::Widget* widget) { | 226 void AppListPresenterImpl::OnWidgetDestroying(views::Widget* widget) { |
214 DCHECK(view_->GetWidget() == widget); | 227 DCHECK_EQ(view_->GetWidget(), widget); |
215 if (is_visible_) | 228 if (is_visible_) |
216 Dismiss(); | 229 Dismiss(); |
217 ResetView(); | 230 ResetView(); |
218 } | 231 } |
219 | 232 |
| 233 void AppListPresenterImpl::OnWidgetVisibilityChanged(views::Widget* widget, |
| 234 bool visible) { |
| 235 DCHECK_EQ(view_->GetWidget(), widget); |
| 236 if (app_list_) |
| 237 app_list_->OnVisibilityChanged(visible); |
| 238 } |
| 239 |
220 //////////////////////////////////////////////////////////////////////////////// | 240 //////////////////////////////////////////////////////////////////////////////// |
221 // AppListPresenterImpl, PaginationModelObserver implementation: | 241 // AppListPresenterImpl, PaginationModelObserver implementation: |
222 | 242 |
223 void AppListPresenterImpl::TotalPagesChanged() {} | 243 void AppListPresenterImpl::TotalPagesChanged() {} |
224 | 244 |
225 void AppListPresenterImpl::SelectedPageChanged(int old_selected, | 245 void AppListPresenterImpl::SelectedPageChanged(int old_selected, |
226 int new_selected) { | 246 int new_selected) { |
227 current_apps_page_ = new_selected; | 247 current_apps_page_ = new_selected; |
228 } | 248 } |
229 | 249 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } else if (should_snap_back_) { | 285 } else if (should_snap_back_) { |
266 should_snap_back_ = false; | 286 should_snap_back_ = false; |
267 ui::ScopedLayerAnimationSettings animation(widget_animator); | 287 ui::ScopedLayerAnimationSettings animation(widget_animator); |
268 animation.SetTransitionDuration( | 288 animation.SetTransitionDuration( |
269 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); | 289 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); |
270 widget->SetBounds(view_bounds_); | 290 widget->SetBounds(view_bounds_); |
271 } | 291 } |
272 } | 292 } |
273 | 293 |
274 } // namespace app_list | 294 } // namespace app_list |
OLD | NEW |