OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/contents_view.h" | 5 #include "ui/app_list/views/contents_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 ContentsView::~ContentsView() { | 42 ContentsView::~ContentsView() { |
43 pagination_model_.RemoveObserver(this); | 43 pagination_model_.RemoveObserver(this); |
44 if (contents_switcher_view_) | 44 if (contents_switcher_view_) |
45 pagination_model_.RemoveObserver(contents_switcher_view_); | 45 pagination_model_.RemoveObserver(contents_switcher_view_); |
46 } | 46 } |
47 | 47 |
48 void ContentsView::Init(AppListModel* model, | 48 void ContentsView::Init(AppListModel* model, |
49 AppListViewDelegate* view_delegate) { | 49 AppListViewDelegate* view_delegate) { |
50 DCHECK(model); | 50 DCHECK(model); |
51 | 51 |
| 52 view_delegate_ = view_delegate; |
| 53 |
52 if (app_list::switches::IsExperimentalAppListEnabled()) { | 54 if (app_list::switches::IsExperimentalAppListEnabled()) { |
53 std::vector<views::View*> custom_page_views = | 55 std::vector<views::View*> custom_page_views = |
54 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); | 56 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); |
55 for (std::vector<views::View*>::const_iterator it = | 57 for (std::vector<views::View*>::const_iterator it = |
56 custom_page_views.begin(); | 58 custom_page_views.begin(); |
57 it != custom_page_views.end(); | 59 it != custom_page_views.end(); |
58 ++it) { | 60 ++it) { |
59 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON); | 61 // Only the first launcher page is considered to represent |
| 62 // STATE_CUSTOM_LAUNCHER_PAGE. |
| 63 if (it == custom_page_views.begin()) { |
| 64 AddLauncherPage(*it, |
| 65 IDR_APP_LIST_NOTIFICATIONS_ICON, |
| 66 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 67 } else { |
| 68 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON); |
| 69 } |
60 } | 70 } |
61 | 71 |
62 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 72 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
63 AddLauncherPage( | 73 AddLauncherPage( |
64 start_page_view_, IDR_APP_LIST_SEARCH_ICON, AppListModel::STATE_START); | 74 start_page_view_, IDR_APP_LIST_SEARCH_ICON, AppListModel::STATE_START); |
65 } else { | 75 } else { |
66 search_results_view_ = | 76 search_results_view_ = |
67 new SearchResultListView(app_list_main_view_, view_delegate); | 77 new SearchResultListView(app_list_main_view_, view_delegate); |
68 AddLauncherPage( | 78 AddLauncherPage( |
69 search_results_view_, 0, AppListModel::STATE_SEARCH_RESULTS); | 79 search_results_view_, 0, AppListModel::STATE_SEARCH_RESULTS); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // The start page and search page origins are above; all other pages' origins | 214 // The start page and search page origins are above; all other pages' origins |
205 // are below. | 215 // are below. |
206 int page_height = bounds.height(); | 216 int page_height = bounds.height(); |
207 bool origin_above = | 217 bool origin_above = |
208 GetPageIndexForState(AppListModel::STATE_START) == page_index || | 218 GetPageIndexForState(AppListModel::STATE_START) == page_index || |
209 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; | 219 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; |
210 bounds.set_y(origin_above ? -page_height : page_height); | 220 bounds.set_y(origin_above ? -page_height : page_height); |
211 return bounds; | 221 return bounds; |
212 } | 222 } |
213 | 223 |
| 224 void ContentsView::NotifyCustomLauncherPageAnimationChanged(double progress, |
| 225 int current_page, |
| 226 int target_page) { |
| 227 int custom_launcher_page_index = |
| 228 GetPageIndexForState(AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 229 if (custom_launcher_page_index == target_page) |
| 230 view_delegate_->CustomLauncherPageAnimationChanged(progress); |
| 231 else if (custom_launcher_page_index == current_page) |
| 232 view_delegate_->CustomLauncherPageAnimationChanged(1 - progress); |
| 233 } |
| 234 |
214 void ContentsView::UpdatePageBounds() { | 235 void ContentsView::UpdatePageBounds() { |
215 // The bounds calculations will potentially be mid-transition (depending on | 236 // The bounds calculations will potentially be mid-transition (depending on |
216 // the state of the PaginationModel). | 237 // the state of the PaginationModel). |
217 int current_page = std::max(0, pagination_model_.selected_page()); | 238 int current_page = std::max(0, pagination_model_.selected_page()); |
218 int target_page = current_page; | 239 int target_page = current_page; |
219 double progress = 1; | 240 double progress = 1; |
220 if (pagination_model_.has_transition()) { | 241 if (pagination_model_.has_transition()) { |
221 const PaginationModel::Transition& transition = | 242 const PaginationModel::Transition& transition = |
222 pagination_model_.transition(); | 243 pagination_model_.transition(); |
223 if (pagination_model_.is_valid_page(transition.target_page)) { | 244 if (pagination_model_.is_valid_page(transition.target_page)) { |
224 target_page = transition.target_page; | 245 target_page = transition.target_page; |
225 progress = transition.progress; | 246 progress = transition.progress; |
226 } | 247 } |
227 } | 248 } |
228 | 249 |
| 250 NotifyCustomLauncherPageAnimationChanged(progress, current_page, target_page); |
| 251 |
229 // Move |current_page| from 0 to its origin. Move |target_page| from its | 252 // Move |current_page| from 0 to its origin. Move |target_page| from its |
230 // origin to 0. | 253 // origin to 0. |
231 gfx::Rect on_screen(GetDefaultContentsBounds()); | 254 gfx::Rect on_screen(GetDefaultContentsBounds()); |
232 gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page)); | 255 gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page)); |
233 gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page)); | 256 gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page)); |
234 gfx::Rect current_page_rect( | 257 gfx::Rect current_page_rect( |
235 gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin)); | 258 gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin)); |
236 gfx::Rect target_page_rect( | 259 gfx::Rect target_page_rect( |
237 gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen)); | 260 gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen)); |
238 | 261 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 379 } |
357 | 380 |
358 void ContentsView::TransitionStarted() { | 381 void ContentsView::TransitionStarted() { |
359 } | 382 } |
360 | 383 |
361 void ContentsView::TransitionChanged() { | 384 void ContentsView::TransitionChanged() { |
362 UpdatePageBounds(); | 385 UpdatePageBounds(); |
363 } | 386 } |
364 | 387 |
365 } // namespace app_list | 388 } // namespace app_list |
OLD | NEW |