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_view_delegate.h" | 11 #include "ui/app_list/app_list_view_delegate.h" |
12 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
13 #include "ui/app_list/views/app_list_main_view.h" | 13 #include "ui/app_list/views/app_list_main_view.h" |
14 #include "ui/app_list/views/apps_container_view.h" | |
14 #include "ui/app_list/views/apps_grid_view.h" | 15 #include "ui/app_list/views/apps_grid_view.h" |
15 #include "ui/app_list/views/search_result_list_view.h" | 16 #include "ui/app_list/views/search_result_list_view.h" |
16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
17 #include "ui/views/animation/bounds_animator.h" | 18 #include "ui/views/animation/bounds_animator.h" |
18 #include "ui/views/view_model.h" | 19 #include "ui/views/view_model.h" |
19 #include "ui/views/view_model_utils.h" | 20 #include "ui/views/view_model_utils.h" |
20 | 21 |
21 namespace app_list { | 22 namespace app_list { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const int kPreferredIconDimension = 48; | |
26 | |
27 // Indexes of interesting views in ViewModel of ContentsView. | 26 // Indexes of interesting views in ViewModel of ContentsView. |
28 const int kIndexAppsGrid = 0; | 27 const int kIndexAppsContainer = 0; |
29 const int kIndexSearchResults = 1; | 28 const int kIndexSearchResults = 1; |
30 | 29 |
31 const int kMinMouseWheelToSwitchPage = 20; | 30 const int kMinMouseWheelToSwitchPage = 20; |
32 const int kMinScrollToSwitchPage = 20; | 31 const int kMinScrollToSwitchPage = 20; |
33 const int kMinHorizVelocityToSwitchPage = 800; | 32 const int kMinHorizVelocityToSwitchPage = 800; |
34 | 33 |
35 const double kFinishTransitionThreshold = 0.33; | 34 const double kFinishTransitionThreshold = 0.33; |
36 | 35 |
37 // Helpers to get certain child view from |model|. | 36 AppsContainerView* GetAppsContainerView(views::ViewModel* model) { |
38 AppsGridView* GetAppsGridView(views::ViewModel* model) { | 37 return static_cast<AppsContainerView*>(model->view_at(kIndexAppsContainer)); |
39 return static_cast<AppsGridView*>(model->view_at(kIndexAppsGrid)); | |
40 } | 38 } |
41 | 39 |
42 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { | 40 SearchResultListView* GetSearchResultListView(views::ViewModel* model) { |
43 return static_cast<SearchResultListView*>( | 41 return static_cast<SearchResultListView*>( |
44 model->view_at(kIndexSearchResults)); | 42 model->view_at(kIndexSearchResults)); |
45 } | 43 } |
46 | 44 |
47 } // namespace | 45 } // namespace |
48 | 46 |
49 ContentsView::ContentsView(AppListMainView* app_list_main_view, | 47 ContentsView::ContentsView(AppListMainView* app_list_main_view, |
50 PaginationModel* pagination_model, | 48 PaginationModel* pagination_model, |
51 AppListModel* model, | 49 AppListModel* model, |
52 content::WebContents* start_page_contents) | 50 content::WebContents* start_page_contents) |
53 : show_state_(SHOW_APPS), | 51 : show_state_(SHOW_APPS), |
54 pagination_model_(pagination_model), | 52 pagination_model_(pagination_model), |
55 view_model_(new views::ViewModel), | 53 view_model_(new views::ViewModel), |
56 bounds_animator_(new views::BoundsAnimator(this)) { | 54 bounds_animator_(new views::BoundsAnimator(this)) { |
57 DCHECK(model); | 55 DCHECK(model); |
58 pagination_model_->SetTransitionDurations( | 56 pagination_model_->SetTransitionDurations( |
59 kPageTransitionDurationInMs, | 57 kPageTransitionDurationInMs, |
60 kOverscrollPageTransitionDurationMs); | 58 kOverscrollPageTransitionDurationMs); |
61 | 59 |
62 apps_grid_view_ = new AppsGridView( | 60 apps_container_view_ = new AppsContainerView( |
63 app_list_main_view, pagination_model, start_page_contents); | 61 app_list_main_view, pagination_model, model, start_page_contents); |
64 apps_grid_view_->SetLayout(kPreferredIconDimension, | 62 AddChildView(apps_container_view_); |
65 kPreferredCols, | 63 view_model_->Add(apps_container_view_, kIndexAppsContainer); |
66 kPreferredRows); | |
67 AddChildView(apps_grid_view_); | |
68 view_model_->Add(apps_grid_view_, kIndexAppsGrid); | |
69 | 64 |
70 SearchResultListView* search_results_view = new SearchResultListView( | 65 SearchResultListView* search_results_view = new SearchResultListView( |
71 app_list_main_view); | 66 app_list_main_view); |
72 AddChildView(search_results_view); | 67 AddChildView(search_results_view); |
73 view_model_->Add(search_results_view, kIndexSearchResults); | 68 view_model_->Add(search_results_view, kIndexSearchResults); |
74 | 69 |
75 GetAppsGridView(view_model_.get())->SetModel(model); | |
76 GetSearchResultListView(view_model_.get())->SetResults(model->results()); | 70 GetSearchResultListView(view_model_.get())->SetResults(model->results()); |
77 } | 71 } |
78 | 72 |
79 ContentsView::~ContentsView() { | 73 ContentsView::~ContentsView() { |
80 } | 74 } |
81 | 75 |
82 void ContentsView::CancelDrag() { | 76 void ContentsView::CancelDrag() { |
83 if (apps_grid_view_ && apps_grid_view_->has_dragged_view()) | 77 if (apps_container_view_->apps_grid_view() && |
84 apps_grid_view_->EndDrag(true); | 78 apps_container_view_->apps_grid_view()->has_dragged_view()) |
xiyuan
2013/10/18 22:36:00
NULL test of apps_container_view_->apps_grid_view(
jennyz
2013/10/18 22:53:19
Done.
| |
79 apps_container_view_->apps_grid_view()->EndDrag(true); | |
85 } | 80 } |
86 | 81 |
87 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 82 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
88 ApplicationDragAndDropHost* drag_and_drop_host) { | 83 ApplicationDragAndDropHost* drag_and_drop_host) { |
89 apps_grid_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 84 apps_container_view_->apps_grid_view()-> |
85 SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | |
90 } | 86 } |
91 | 87 |
92 void ContentsView::SetShowState(ShowState show_state) { | 88 void ContentsView::SetShowState(ShowState show_state) { |
93 if (show_state_ == show_state) | 89 if (show_state_ == show_state) |
94 return; | 90 return; |
95 | 91 |
96 show_state_ = show_state; | 92 show_state_ = show_state; |
97 ShowStateChanged(); | 93 ShowStateChanged(); |
98 } | 94 } |
99 | 95 |
100 void ContentsView::ShowStateChanged() { | 96 void ContentsView::ShowStateChanged() { |
101 if (show_state_ == SHOW_SEARCH_RESULTS) { | 97 if (show_state_ == SHOW_SEARCH_RESULTS) { |
102 // TODO(xiyuan): Highlight default match instead of the first. | 98 // TODO(xiyuan): Highlight default match instead of the first. |
103 SearchResultListView* results_view = | 99 SearchResultListView* results_view = |
104 GetSearchResultListView(view_model_.get()); | 100 GetSearchResultListView(view_model_.get()); |
105 if (results_view->visible()) | 101 if (results_view->visible()) |
106 results_view->SetSelectedIndex(0); | 102 results_view->SetSelectedIndex(0); |
107 } | 103 } |
108 | 104 |
109 AnimateToIdealBounds(); | 105 AnimateToIdealBounds(); |
110 } | 106 } |
111 | 107 |
112 void ContentsView::CalculateIdealBounds() { | 108 void ContentsView::CalculateIdealBounds() { |
113 gfx::Rect rect(GetContentsBounds()); | 109 gfx::Rect rect(GetContentsBounds()); |
114 if (rect.IsEmpty()) | 110 if (rect.IsEmpty()) |
115 return; | 111 return; |
116 | 112 |
117 gfx::Rect grid_frame(rect); | 113 gfx::Rect container_frame(rect); |
118 gfx::Rect results_frame(rect); | 114 gfx::Rect results_frame(rect); |
119 | 115 |
120 // Offsets apps grid and result list based on |show_state_|. | 116 // Offsets apps grid and result list based on |show_state_|. |
121 // SearchResultListView is on top of apps grid. Visible view is left in | 117 // SearchResultListView is on top of apps grid. Visible view is left in |
122 // visible area and invisible ones is put out of the visible area. | 118 // visible area and invisible ones is put out of the visible area. |
123 int contents_area_height = rect.height(); | 119 int contents_area_height = rect.height(); |
124 switch (show_state_) { | 120 switch (show_state_) { |
125 case SHOW_APPS: | 121 case SHOW_APPS: |
126 results_frame.Offset(0, -contents_area_height); | 122 results_frame.Offset(0, -contents_area_height); |
127 break; | 123 break; |
128 case SHOW_SEARCH_RESULTS: | 124 case SHOW_SEARCH_RESULTS: |
129 grid_frame.Offset(0, contents_area_height); | 125 container_frame.Offset(0, contents_area_height); |
130 break; | 126 break; |
131 default: | 127 default: |
132 NOTREACHED() << "Unknown show_state_ " << show_state_; | 128 NOTREACHED() << "Unknown show_state_ " << show_state_; |
133 break; | 129 break; |
134 } | 130 } |
135 | 131 |
136 view_model_->set_ideal_bounds(kIndexAppsGrid, grid_frame); | 132 view_model_->set_ideal_bounds(kIndexAppsContainer, container_frame); |
137 view_model_->set_ideal_bounds(kIndexSearchResults, results_frame); | 133 view_model_->set_ideal_bounds(kIndexSearchResults, results_frame); |
138 } | 134 } |
139 | 135 |
140 void ContentsView::AnimateToIdealBounds() { | 136 void ContentsView::AnimateToIdealBounds() { |
141 CalculateIdealBounds(); | 137 CalculateIdealBounds(); |
142 for (int i = 0; i < view_model_->view_size(); ++i) { | 138 for (int i = 0; i < view_model_->view_size(); ++i) { |
143 bounds_animator_->AnimateViewTo(view_model_->view_at(i), | 139 bounds_animator_->AnimateViewTo(view_model_->view_at(i), |
144 view_model_->ideal_bounds(i)); | 140 view_model_->ideal_bounds(i)); |
145 } | 141 } |
146 } | 142 } |
147 | 143 |
148 void ContentsView::ShowSearchResults(bool show) { | 144 void ContentsView::ShowSearchResults(bool show) { |
149 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); | 145 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); |
150 } | 146 } |
151 | 147 |
148 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | |
149 apps_container_view_->ShowActiveFolder(item); | |
150 } | |
151 | |
152 void ContentsView::ShowApps() { | |
xiyuan
2013/10/18 22:36:00
Do we still need this?
jennyz
2013/10/18 22:53:19
Removed.
| |
153 SetShowState(SHOW_APPS); | |
154 } | |
155 | |
152 void ContentsView::Prerender() { | 156 void ContentsView::Prerender() { |
153 const int selected_page = std::max(0, pagination_model_->selected_page()); | 157 const int selected_page = std::max(0, pagination_model_->selected_page()); |
154 GetAppsGridView(view_model_.get())->Prerender(selected_page); | 158 apps_container_view_->apps_grid_view()->Prerender(selected_page); |
155 } | 159 } |
156 | 160 |
157 gfx::Size ContentsView::GetPreferredSize() { | 161 gfx::Size ContentsView::GetPreferredSize() { |
158 const gfx::Size grid_size = | 162 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> |
159 GetAppsGridView(view_model_.get())->GetPreferredSize(); | 163 apps_grid_view()->GetPreferredSize(); |
160 const gfx::Size results_size = | 164 const gfx::Size results_size = |
161 GetSearchResultListView(view_model_.get())->GetPreferredSize(); | 165 GetSearchResultListView(view_model_.get())->GetPreferredSize(); |
162 | 166 |
163 int width = std::max(grid_size.width(), results_size.width()); | 167 int width = std::max(container_size.width(), results_size.width()); |
164 int height = std::max(grid_size.height(), results_size.height()); | 168 int height = std::max(container_size.height(), results_size.height()); |
165 return gfx::Size(width, height); | 169 return gfx::Size(width, height); |
166 } | 170 } |
167 | 171 |
168 void ContentsView::Layout() { | 172 void ContentsView::Layout() { |
169 CalculateIdealBounds(); | 173 CalculateIdealBounds(); |
170 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 174 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
171 } | 175 } |
172 | 176 |
173 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 177 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
174 switch (show_state_) { | 178 switch (show_state_) { |
175 case SHOW_APPS: | 179 case SHOW_APPS: |
176 return GetAppsGridView(view_model_.get())->OnKeyPressed(event); | 180 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); |
177 case SHOW_SEARCH_RESULTS: | 181 case SHOW_SEARCH_RESULTS: |
178 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); | 182 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); |
179 default: | 183 default: |
180 NOTREACHED() << "Unknown show state " << show_state_; | 184 NOTREACHED() << "Unknown show state " << show_state_; |
181 } | 185 } |
182 return false; | 186 return false; |
183 } | 187 } |
184 | 188 |
185 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 189 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
186 if (show_state_ != SHOW_APPS) | 190 if (show_state_ != SHOW_APPS) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 if (!pagination_model_->has_transition()) { | 259 if (!pagination_model_->has_transition()) { |
256 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, | 260 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, |
257 true); | 261 true); |
258 } | 262 } |
259 event->SetHandled(); | 263 event->SetHandled(); |
260 event->StopPropagation(); | 264 event->StopPropagation(); |
261 } | 265 } |
262 } | 266 } |
263 | 267 |
264 } // namespace app_list | 268 } // namespace app_list |
OLD | NEW |