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), |
54 view_model_(new views::ViewModel), | 61 view_model_(new views::ViewModel), |
55 bounds_animator_(new views::BoundsAnimator(this)) { | 62 bounds_animator_(new views::BoundsAnimator(this)) { |
56 DCHECK(model); | 63 DCHECK(model); |
57 pagination_model_->SetTransitionDurations( | 64 pagination_model_->SetTransitionDurations( |
58 kPageTransitionDurationInMs, | 65 kPageTransitionDurationInMs, |
59 kOverscrollPageTransitionDurationMs); | 66 kOverscrollPageTransitionDurationMs); |
60 | 67 |
61 content::WebContents* start_page_contents = | 68 content::WebContents* start_page_contents = |
62 view_delegate ? view_delegate->GetStartPageContents() : NULL; | 69 view_delegate ? view_delegate->GetStartPageContents() : NULL; |
63 apps_container_view_ = new AppsContainerView( | 70 apps_container_view_ = new AppsContainerView( |
64 app_list_main_view, pagination_model, model, start_page_contents); | 71 app_list_main_view, pagination_model, model, start_page_contents); |
65 AddChildView(apps_container_view_); | 72 AddChildView(apps_container_view_); |
66 view_model_->Add(apps_container_view_, kIndexAppsContainer); | 73 view_model_->Add(apps_container_view_, kIndexAppsContainer); |
67 | 74 |
68 SearchResultListView* search_results_view = new SearchResultListView( | 75 SearchResultListView* search_results_view = new SearchResultListView( |
69 app_list_main_view, view_delegate); | 76 app_list_main_view, view_delegate); |
70 AddChildView(search_results_view); | 77 AddChildView(search_results_view); |
71 view_model_->Add(search_results_view, kIndexSearchResults); | 78 view_model_->Add(search_results_view, kIndexSearchResults); |
72 | 79 |
| 80 if (app_list::switches::IsExperimentalAppListEnabled()) { |
| 81 StartPageView* start_page_view = |
| 82 new StartPageView(app_list_main_view, start_page_contents); |
| 83 AddChildView(start_page_view); |
| 84 view_model_->Add(start_page_view, kIndexStartPage); |
| 85 } |
| 86 |
73 GetSearchResultListView(view_model_.get())->SetResults(model->results()); | 87 GetSearchResultListView(view_model_.get())->SetResults(model->results()); |
74 } | 88 } |
75 | 89 |
76 ContentsView::~ContentsView() { | 90 ContentsView::~ContentsView() { |
77 } | 91 } |
78 | 92 |
79 void ContentsView::CancelDrag() { | 93 void ContentsView::CancelDrag() { |
80 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 94 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
81 apps_container_view_->apps_grid_view()->EndDrag(true); | 95 apps_container_view_->apps_grid_view()->EndDrag(true); |
82 } | 96 } |
83 | 97 |
84 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 98 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
85 ApplicationDragAndDropHost* drag_and_drop_host) { | 99 ApplicationDragAndDropHost* drag_and_drop_host) { |
86 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 100 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
87 } | 101 } |
88 | 102 |
89 void ContentsView::SetShowState(ShowState show_state) { | 103 void ContentsView::SetShowState(ShowState show_state) { |
90 if (show_state_ == show_state) | 104 if (show_state_ == show_state) |
91 return; | 105 return; |
92 | 106 |
93 show_state_ = show_state; | 107 show_state_ = show_state; |
94 ShowStateChanged(); | 108 ShowStateChanged(); |
95 } | 109 } |
96 | 110 |
| 111 AppListMainView* ContentsView::GetMainView() { |
| 112 return static_cast<AppListMainView*>(parent()); |
| 113 } |
| 114 |
97 void ContentsView::ShowStateChanged() { | 115 void ContentsView::ShowStateChanged() { |
98 SearchResultListView* results_view = | 116 SearchResultListView* results_view = |
99 GetSearchResultListView(view_model_.get()); | 117 GetSearchResultListView(view_model_.get()); |
100 // TODO(xiyuan): Highlight default match instead of the first. | 118 // TODO(xiyuan): Highlight default match instead of the first. |
101 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) | 119 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) |
102 results_view->SetSelectedIndex(0); | 120 results_view->SetSelectedIndex(0); |
103 results_view->UpdateAutoLaunchState(); | 121 results_view->UpdateAutoLaunchState(); |
104 | 122 |
| 123 // Don't show the search box for the start page. |
| 124 app_list_main_view_->search_box_view()->SetVisible(show_state_ != |
| 125 SHOW_START_PAGE); |
| 126 |
105 AnimateToIdealBounds(); | 127 AnimateToIdealBounds(); |
106 } | 128 } |
107 | 129 |
108 void ContentsView::CalculateIdealBounds() { | 130 void ContentsView::CalculateIdealBounds() { |
109 gfx::Rect rect(GetContentsBounds()); | 131 gfx::Rect rect(GetContentsBounds()); |
110 if (rect.IsEmpty()) | 132 if (rect.IsEmpty()) |
111 return; | 133 return; |
112 | 134 |
113 if (app_list::switches::IsExperimentalAppListEnabled()) { | 135 if (app_list::switches::IsExperimentalAppListEnabled()) { |
114 int incoming_view_index = 0; | 136 int incoming_view_index = 0; |
115 switch (show_state_) { | 137 switch (show_state_) { |
116 case SHOW_APPS: | 138 case SHOW_APPS: |
117 incoming_view_index = kIndexAppsContainer; | 139 incoming_view_index = kIndexAppsContainer; |
118 break; | 140 break; |
119 case SHOW_SEARCH_RESULTS: | 141 case SHOW_SEARCH_RESULTS: |
120 incoming_view_index = kIndexSearchResults; | 142 incoming_view_index = kIndexSearchResults; |
121 break; | 143 break; |
| 144 case SHOW_START_PAGE: |
| 145 incoming_view_index = kIndexStartPage; |
| 146 break; |
122 default: | 147 default: |
123 NOTREACHED(); | 148 NOTREACHED(); |
124 } | 149 } |
125 | 150 |
126 gfx::Rect incoming_target(rect); | 151 gfx::Rect incoming_target(rect); |
127 gfx::Rect outgoing_target(rect); | 152 gfx::Rect outgoing_target(rect); |
128 outgoing_target.set_y(-outgoing_target.height()); | 153 outgoing_target.set_y(-outgoing_target.height()); |
129 | 154 |
130 for (int i = 0; i < view_model_->view_size(); ++i) { | 155 for (int i = 0; i < view_model_->view_size(); ++i) { |
131 view_model_->set_ideal_bounds(i, | 156 view_model_->set_ideal_bounds(i, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 CalculateIdealBounds(); | 219 CalculateIdealBounds(); |
195 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 220 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
196 } | 221 } |
197 | 222 |
198 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 223 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
199 switch (show_state_) { | 224 switch (show_state_) { |
200 case SHOW_APPS: | 225 case SHOW_APPS: |
201 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); | 226 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); |
202 case SHOW_SEARCH_RESULTS: | 227 case SHOW_SEARCH_RESULTS: |
203 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); | 228 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); |
| 229 case SHOW_START_PAGE: |
| 230 return GetStartPageView(view_model_.get())->OnKeyPressed(event); |
204 default: | 231 default: |
205 NOTREACHED() << "Unknown show state " << show_state_; | 232 NOTREACHED() << "Unknown show state " << show_state_; |
206 } | 233 } |
207 return false; | 234 return false; |
208 } | 235 } |
209 | 236 |
210 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 237 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
211 if (show_state_ != SHOW_APPS) | 238 if (show_state_ != SHOW_APPS) |
212 return false; | 239 return false; |
213 | 240 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (!pagination_model_->has_transition()) { | 307 if (!pagination_model_->has_transition()) { |
281 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, | 308 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, |
282 true); | 309 true); |
283 } | 310 } |
284 event->SetHandled(); | 311 event->SetHandled(); |
285 event->StopPropagation(); | 312 event->StopPropagation(); |
286 } | 313 } |
287 } | 314 } |
288 | 315 |
289 } // namespace app_list | 316 } // namespace app_list |
OLD | NEW |