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