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