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 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
11 #include "ui/app_list/app_list_switches.h" | 11 #include "ui/app_list/app_list_switches.h" |
12 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
13 #include "ui/app_list/pagination_model.h" | 13 #include "ui/app_list/pagination_model.h" |
14 #include "ui/app_list/views/app_list_folder_view.h" | 14 #include "ui/app_list/views/app_list_folder_view.h" |
15 #include "ui/app_list/views/app_list_main_view.h" | 15 #include "ui/app_list/views/app_list_main_view.h" |
16 #include "ui/app_list/views/apps_container_view.h" | 16 #include "ui/app_list/views/apps_container_view.h" |
17 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
18 #include "ui/app_list/views/search_result_list_view.h" | 18 #include "ui/app_list/views/search_result_list_view.h" |
| 19 #include "ui/app_list/views/start_page_view.h" |
19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
20 #include "ui/views/animation/bounds_animator.h" | 21 #include "ui/views/animation/bounds_animator.h" |
21 #include "ui/views/view_model.h" | 22 #include "ui/views/view_model.h" |
22 #include "ui/views/view_model_utils.h" | 23 #include "ui/views/view_model_utils.h" |
23 | 24 |
24 namespace app_list { | 25 namespace app_list { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // Indexes of interesting views in ViewModel of ContentsView. | 29 // Indexes of interesting views in ViewModel of ContentsView. |
29 const int kIndexAppsContainer = 0; | 30 const int kIndexAppsContainer = 0; |
30 const int kIndexSearchResults = 1; | 31 const int kIndexSearchResults = 1; |
| 32 const int kIndexStartPage = 2; |
31 | 33 |
32 const int kMinMouseWheelToSwitchPage = 20; | 34 const int kMinMouseWheelToSwitchPage = 20; |
33 const int kMinScrollToSwitchPage = 20; | 35 const int kMinScrollToSwitchPage = 20; |
34 const int kMinHorizVelocityToSwitchPage = 800; | 36 const int kMinHorizVelocityToSwitchPage = 800; |
35 | 37 |
36 const double kFinishTransitionThreshold = 0.33; | 38 const double kFinishTransitionThreshold = 0.33; |
37 | 39 |
38 AppsContainerView* GetAppsContainerView(views::ViewModel* model) { | 40 AppsContainerView* GetAppsContainerView(views::ViewModel* model) { |
39 return static_cast<AppsContainerView*>(model->view_at(kIndexAppsContainer)); | 41 return static_cast<AppsContainerView*>(model->view_at(kIndexAppsContainer)); |
40 } | 42 } |
41 | 43 |
42 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { | 44 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { |
43 return static_cast<SearchResultListView*>( | 45 return static_cast<SearchResultListView*>( |
44 model->view_at(kIndexSearchResults)); | 46 model->view_at(kIndexSearchResults)); |
45 } | 47 } |
46 | 48 |
| 49 StartPageView* GetStartPageView(views::ViewModel* model) { |
| 50 return static_cast<StartPageView*>(model->view_at(kIndexStartPage)); |
| 51 } |
| 52 |
47 } // namespace | 53 } // namespace |
48 | 54 |
49 ContentsView::ContentsView(AppListMainView* app_list_main_view, | 55 ContentsView::ContentsView(AppListMainView* app_list_main_view, |
50 PaginationModel* pagination_model, | 56 PaginationModel* pagination_model, |
51 AppListModel* model, | 57 AppListModel* model, |
52 AppListViewDelegate* view_delegate) | 58 AppListViewDelegate* view_delegate) |
53 : show_state_(SHOW_APPS), | 59 : show_state_(SHOW_APPS), |
54 pagination_model_(pagination_model), | 60 pagination_model_(pagination_model), |
55 view_model_(new views::ViewModel), | 61 view_model_(new views::ViewModel), |
56 bounds_animator_(new views::BoundsAnimator(this)) { | 62 bounds_animator_(new views::BoundsAnimator(this)), |
| 63 app_list_main_view_(app_list_main_view) { |
57 DCHECK(model); | 64 DCHECK(model); |
58 pagination_model_->SetTransitionDurations( | 65 pagination_model_->SetTransitionDurations( |
59 kPageTransitionDurationInMs, | 66 kPageTransitionDurationInMs, |
60 kOverscrollPageTransitionDurationMs); | 67 kOverscrollPageTransitionDurationMs); |
61 | 68 |
62 apps_container_view_ = | 69 apps_container_view_ = |
63 new AppsContainerView(app_list_main_view, pagination_model, model); | 70 new AppsContainerView(app_list_main_view, pagination_model, model); |
64 AddChildView(apps_container_view_); | 71 AddChildView(apps_container_view_); |
65 view_model_->Add(apps_container_view_, kIndexAppsContainer); | 72 view_model_->Add(apps_container_view_, kIndexAppsContainer); |
66 | 73 |
67 SearchResultListView* search_results_view = new SearchResultListView( | 74 SearchResultListView* search_results_view = new SearchResultListView( |
68 app_list_main_view, view_delegate); | 75 app_list_main_view, view_delegate); |
69 AddChildView(search_results_view); | 76 AddChildView(search_results_view); |
70 view_model_->Add(search_results_view, kIndexSearchResults); | 77 view_model_->Add(search_results_view, kIndexSearchResults); |
71 | 78 |
| 79 if (app_list::switches::IsExperimentalAppListEnabled()) { |
| 80 content::WebContents* start_page_contents = |
| 81 view_delegate->GetStartPageContents(); |
| 82 StartPageView* start_page_view = |
| 83 new StartPageView(app_list_main_view, start_page_contents); |
| 84 AddChildView(start_page_view); |
| 85 view_model_->Add(start_page_view, kIndexStartPage); |
| 86 } |
| 87 |
72 GetSearchResultListView(view_model_.get())->SetResults(model->results()); | 88 GetSearchResultListView(view_model_.get())->SetResults(model->results()); |
73 } | 89 } |
74 | 90 |
75 ContentsView::~ContentsView() { | 91 ContentsView::~ContentsView() { |
76 } | 92 } |
77 | 93 |
78 void ContentsView::CancelDrag() { | 94 void ContentsView::CancelDrag() { |
79 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 95 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
80 apps_container_view_->apps_grid_view()->EndDrag(true); | 96 apps_container_view_->apps_grid_view()->EndDrag(true); |
81 if (apps_container_view_->app_list_folder_view() | 97 if (apps_container_view_->app_list_folder_view() |
(...skipping 18 matching lines...) Expand all Loading... |
100 } | 116 } |
101 | 117 |
102 void ContentsView::ShowStateChanged() { | 118 void ContentsView::ShowStateChanged() { |
103 SearchResultListView* results_view = | 119 SearchResultListView* results_view = |
104 GetSearchResultListView(view_model_.get()); | 120 GetSearchResultListView(view_model_.get()); |
105 // TODO(xiyuan): Highlight default match instead of the first. | 121 // TODO(xiyuan): Highlight default match instead of the first. |
106 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) | 122 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) |
107 results_view->SetSelectedIndex(0); | 123 results_view->SetSelectedIndex(0); |
108 results_view->UpdateAutoLaunchState(); | 124 results_view->UpdateAutoLaunchState(); |
109 | 125 |
| 126 // Notify parent AppListMainView of show state change. |
| 127 app_list_main_view_->OnContentsViewShowStateChanged(); |
| 128 |
| 129 if (show_state_ == SHOW_START_PAGE) |
| 130 GetStartPageView(view_model_.get())->Reset(); |
| 131 |
110 AnimateToIdealBounds(); | 132 AnimateToIdealBounds(); |
111 } | 133 } |
112 | 134 |
113 void ContentsView::CalculateIdealBounds() { | 135 void ContentsView::CalculateIdealBounds() { |
114 gfx::Rect rect(GetContentsBounds()); | 136 gfx::Rect rect(GetContentsBounds()); |
115 if (rect.IsEmpty()) | 137 if (rect.IsEmpty()) |
116 return; | 138 return; |
117 | 139 |
118 if (app_list::switches::IsExperimentalAppListEnabled()) { | 140 if (app_list::switches::IsExperimentalAppListEnabled()) { |
119 int incoming_view_index = 0; | 141 int incoming_view_index = 0; |
120 switch (show_state_) { | 142 switch (show_state_) { |
121 case SHOW_APPS: | 143 case SHOW_APPS: |
122 incoming_view_index = kIndexAppsContainer; | 144 incoming_view_index = kIndexAppsContainer; |
123 break; | 145 break; |
124 case SHOW_SEARCH_RESULTS: | 146 case SHOW_SEARCH_RESULTS: |
125 incoming_view_index = kIndexSearchResults; | 147 incoming_view_index = kIndexSearchResults; |
126 break; | 148 break; |
| 149 case SHOW_START_PAGE: |
| 150 incoming_view_index = kIndexStartPage; |
| 151 break; |
127 default: | 152 default: |
128 NOTREACHED(); | 153 NOTREACHED(); |
129 } | 154 } |
130 | 155 |
131 gfx::Rect incoming_target(rect); | 156 gfx::Rect incoming_target(rect); |
132 gfx::Rect outgoing_target(rect); | 157 gfx::Rect outgoing_target(rect); |
133 outgoing_target.set_y(-outgoing_target.height()); | 158 outgoing_target.set_y(-outgoing_target.height()); |
134 | 159 |
135 for (int i = 0; i < view_model_->view_size(); ++i) { | 160 for (int i = 0; i < view_model_->view_size(); ++i) { |
136 view_model_->set_ideal_bounds(i, | 161 view_model_->set_ideal_bounds(i, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 CalculateIdealBounds(); | 224 CalculateIdealBounds(); |
200 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 225 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
201 } | 226 } |
202 | 227 |
203 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 228 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
204 switch (show_state_) { | 229 switch (show_state_) { |
205 case SHOW_APPS: | 230 case SHOW_APPS: |
206 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); | 231 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); |
207 case SHOW_SEARCH_RESULTS: | 232 case SHOW_SEARCH_RESULTS: |
208 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); | 233 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); |
| 234 case SHOW_START_PAGE: |
| 235 return GetStartPageView(view_model_.get())->OnKeyPressed(event); |
209 default: | 236 default: |
210 NOTREACHED() << "Unknown show state " << show_state_; | 237 NOTREACHED() << "Unknown show state " << show_state_; |
211 } | 238 } |
212 return false; | 239 return false; |
213 } | 240 } |
214 | 241 |
215 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 242 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
216 if (show_state_ != SHOW_APPS) | 243 if (show_state_ != SHOW_APPS) |
217 return false; | 244 return false; |
218 | 245 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 if (!pagination_model_->has_transition()) { | 312 if (!pagination_model_->has_transition()) { |
286 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, | 313 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, |
287 true); | 314 true); |
288 } | 315 } |
289 event->SetHandled(); | 316 event->SetHandled(); |
290 event->StopPropagation(); | 317 event->StopPropagation(); |
291 } | 318 } |
292 } | 319 } |
293 | 320 |
294 } // namespace app_list | 321 } // namespace app_list |
OLD | NEW |