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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 const int kIndexAppsContainer = 0; | 30 const int kIndexAppsContainer = 0; |
31 const int kIndexSearchResults = 1; | 31 const int kIndexSearchResults = 1; |
32 const int kIndexStartPage = 2; | 32 const int kIndexStartPage = 2; |
33 | 33 |
34 const int kMinMouseWheelToSwitchPage = 20; | 34 const int kMinMouseWheelToSwitchPage = 20; |
35 const int kMinScrollToSwitchPage = 20; | 35 const int kMinScrollToSwitchPage = 20; |
36 const int kMinHorizVelocityToSwitchPage = 800; | 36 const int kMinHorizVelocityToSwitchPage = 800; |
37 | 37 |
38 const double kFinishTransitionThreshold = 0.33; | 38 const double kFinishTransitionThreshold = 0.33; |
39 | 39 |
40 AppsContainerView* GetAppsContainerView(views::ViewModel* model) { | |
41 return static_cast<AppsContainerView*>(model->view_at(kIndexAppsContainer)); | |
42 } | |
43 | |
44 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { | |
45 return static_cast<SearchResultListView*>( | |
46 model->view_at(kIndexSearchResults)); | |
47 } | |
48 | |
49 StartPageView* GetStartPageView(views::ViewModel* model) { | |
50 return static_cast<StartPageView*>(model->view_at(kIndexStartPage)); | |
51 } | |
52 | |
53 } // namespace | 40 } // namespace |
54 | 41 |
55 ContentsView::ContentsView(AppListMainView* app_list_main_view, | 42 ContentsView::ContentsView(AppListMainView* app_list_main_view, |
56 AppListModel* model, | 43 AppListModel* model, |
57 AppListViewDelegate* view_delegate) | 44 AppListViewDelegate* view_delegate) |
58 : show_state_(SHOW_APPS), | 45 : show_state_(SHOW_APPS), |
59 start_page_view_(NULL), | 46 start_page_view_(NULL), |
60 app_list_main_view_(app_list_main_view), | 47 app_list_main_view_(app_list_main_view), |
61 view_model_(new views::ViewModel), | 48 view_model_(new views::ViewModel), |
62 bounds_animator_(new views::BoundsAnimator(this)) { | 49 bounds_animator_(new views::BoundsAnimator(this)) { |
63 DCHECK(model); | 50 DCHECK(model); |
64 | 51 |
65 apps_container_view_ = new AppsContainerView(app_list_main_view, model); | 52 apps_container_view_ = new AppsContainerView(app_list_main_view, model); |
66 AddChildView(apps_container_view_); | 53 AddChildView(apps_container_view_); |
67 view_model_->Add(apps_container_view_, kIndexAppsContainer); | 54 view_model_->Add(apps_container_view_, kIndexAppsContainer); |
68 | 55 |
69 SearchResultListView* search_results_view = new SearchResultListView( | 56 search_results_view_ = |
70 app_list_main_view, view_delegate); | 57 new SearchResultListView(app_list_main_view, view_delegate); |
71 AddChildView(search_results_view); | 58 AddChildView(search_results_view_); |
72 view_model_->Add(search_results_view, kIndexSearchResults); | 59 view_model_->Add(search_results_view_, kIndexSearchResults); |
73 | 60 |
74 if (app_list::switches::IsExperimentalAppListEnabled()) { | 61 if (app_list::switches::IsExperimentalAppListEnabled()) { |
75 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); | 62 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); |
76 AddChildView(start_page_view_); | 63 AddChildView(start_page_view_); |
77 view_model_->Add(start_page_view_, kIndexStartPage); | 64 view_model_->Add(start_page_view_, kIndexStartPage); |
78 } | 65 } |
79 | 66 |
80 GetSearchResultListView(view_model_.get())->SetResults(model->results()); | 67 search_results_view_->SetResults(model->results()); |
81 } | 68 } |
82 | 69 |
83 ContentsView::~ContentsView() { | 70 ContentsView::~ContentsView() { |
84 } | 71 } |
85 | 72 |
86 void ContentsView::CancelDrag() { | 73 void ContentsView::CancelDrag() { |
87 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 74 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
88 apps_container_view_->apps_grid_view()->EndDrag(true); | 75 apps_container_view_->apps_grid_view()->EndDrag(true); |
89 if (apps_container_view_->app_list_folder_view() | 76 if (apps_container_view_->app_list_folder_view() |
90 ->items_grid_view() | 77 ->items_grid_view() |
(...skipping 10 matching lines...) Expand all Loading... |
101 | 88 |
102 void ContentsView::SetShowState(ShowState show_state) { | 89 void ContentsView::SetShowState(ShowState show_state) { |
103 if (show_state_ == show_state) | 90 if (show_state_ == show_state) |
104 return; | 91 return; |
105 | 92 |
106 show_state_ = show_state; | 93 show_state_ = show_state; |
107 ShowStateChanged(); | 94 ShowStateChanged(); |
108 } | 95 } |
109 | 96 |
110 void ContentsView::ShowStateChanged() { | 97 void ContentsView::ShowStateChanged() { |
111 SearchResultListView* results_view = | |
112 GetSearchResultListView(view_model_.get()); | |
113 // TODO(xiyuan): Highlight default match instead of the first. | 98 // TODO(xiyuan): Highlight default match instead of the first. |
114 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) | 99 if (show_state_ == SHOW_SEARCH_RESULTS && search_results_view_->visible()) |
115 results_view->SetSelectedIndex(0); | 100 search_results_view_->SetSelectedIndex(0); |
116 results_view->UpdateAutoLaunchState(); | 101 search_results_view_->UpdateAutoLaunchState(); |
117 | 102 |
118 // Notify parent AppListMainView of show state change. | 103 // Notify parent AppListMainView of show state change. |
119 app_list_main_view_->OnContentsViewShowStateChanged(); | 104 app_list_main_view_->OnContentsViewShowStateChanged(); |
120 | 105 |
121 if (show_state_ == SHOW_START_PAGE) | 106 if (show_state_ == SHOW_START_PAGE) |
122 GetStartPageView(view_model_.get())->Reset(); | 107 start_page_view_->Reset(); |
123 | 108 |
124 AnimateToIdealBounds(); | 109 AnimateToIdealBounds(); |
125 } | 110 } |
126 | 111 |
127 void ContentsView::CalculateIdealBounds() { | 112 void ContentsView::CalculateIdealBounds() { |
128 gfx::Rect rect(GetContentsBounds()); | 113 gfx::Rect rect(GetContentsBounds()); |
129 if (rect.IsEmpty()) | 114 if (rect.IsEmpty()) |
130 return; | 115 return; |
131 | 116 |
132 if (app_list::switches::IsExperimentalAppListEnabled()) { | 117 if (app_list::switches::IsExperimentalAppListEnabled()) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 apps_container_view_->ShowActiveFolder(item); | 185 apps_container_view_->ShowActiveFolder(item); |
201 } | 186 } |
202 | 187 |
203 void ContentsView::Prerender() { | 188 void ContentsView::Prerender() { |
204 const int selected_page = | 189 const int selected_page = |
205 std::max(0, GetAppsPaginationModel()->selected_page()); | 190 std::max(0, GetAppsPaginationModel()->selected_page()); |
206 apps_container_view_->apps_grid_view()->Prerender(selected_page); | 191 apps_container_view_->apps_grid_view()->Prerender(selected_page); |
207 } | 192 } |
208 | 193 |
209 gfx::Size ContentsView::GetPreferredSize() const { | 194 gfx::Size ContentsView::GetPreferredSize() const { |
210 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> | 195 const gfx::Size container_size = |
211 apps_grid_view()->GetPreferredSize(); | 196 apps_container_view_->apps_grid_view()->GetPreferredSize(); |
212 const gfx::Size results_size = | 197 const gfx::Size results_size = search_results_view_->GetPreferredSize(); |
213 GetSearchResultListView(view_model_.get())->GetPreferredSize(); | |
214 | 198 |
215 int width = std::max(container_size.width(), results_size.width()); | 199 int width = std::max(container_size.width(), results_size.width()); |
216 int height = std::max(container_size.height(), results_size.height()); | 200 int height = std::max(container_size.height(), results_size.height()); |
217 return gfx::Size(width, height); | 201 return gfx::Size(width, height); |
218 } | 202 } |
219 | 203 |
220 void ContentsView::Layout() { | 204 void ContentsView::Layout() { |
221 CalculateIdealBounds(); | 205 CalculateIdealBounds(); |
222 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 206 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
223 } | 207 } |
224 | 208 |
225 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 209 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
226 switch (show_state_) { | 210 switch (show_state_) { |
227 case SHOW_APPS: | 211 case SHOW_APPS: |
228 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); | 212 return apps_container_view_->OnKeyPressed(event); |
229 case SHOW_SEARCH_RESULTS: | 213 case SHOW_SEARCH_RESULTS: |
230 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); | 214 return search_results_view_->OnKeyPressed(event); |
231 case SHOW_START_PAGE: | 215 case SHOW_START_PAGE: |
232 return GetStartPageView(view_model_.get())->OnKeyPressed(event); | 216 return start_page_view_->OnKeyPressed(event); |
233 default: | 217 default: |
234 NOTREACHED() << "Unknown show state " << show_state_; | 218 NOTREACHED() << "Unknown show state " << show_state_; |
235 } | 219 } |
236 return false; | 220 return false; |
237 } | 221 } |
238 | 222 |
239 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 223 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
240 if (show_state_ != SHOW_APPS) | 224 if (show_state_ != SHOW_APPS) |
241 return false; | 225 return false; |
242 | 226 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 if (std::abs(offset) > kMinScrollToSwitchPage) { | 291 if (std::abs(offset) > kMinScrollToSwitchPage) { |
308 if (!GetAppsPaginationModel()->has_transition()) { | 292 if (!GetAppsPaginationModel()->has_transition()) { |
309 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | 293 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
310 } | 294 } |
311 event->SetHandled(); | 295 event->SetHandled(); |
312 event->StopPropagation(); | 296 event->StopPropagation(); |
313 } | 297 } |
314 } | 298 } |
315 | 299 |
316 } // namespace app_list | 300 } // namespace app_list |
OLD | NEW |