Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: ui/app_list/views/contents_view.cc

Issue 27777002: Implement app list folder management page UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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()->has_dragged_view())
84 apps_grid_view_->EndDrag(true); 78 apps_container_view_->apps_grid_view()->EndDrag(true);
85 } 79 }
86 80
87 void ContentsView::SetDragAndDropHostOfCurrentAppList( 81 void ContentsView::SetDragAndDropHostOfCurrentAppList(
88 ApplicationDragAndDropHost* drag_and_drop_host) { 82 ApplicationDragAndDropHost* drag_and_drop_host) {
89 apps_grid_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 83 apps_container_view_->apps_grid_view()->
84 SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
90 } 85 }
91 86
92 void ContentsView::SetShowState(ShowState show_state) { 87 void ContentsView::SetShowState(ShowState show_state) {
93 if (show_state_ == show_state) 88 if (show_state_ == show_state)
94 return; 89 return;
95 90
96 show_state_ = show_state; 91 show_state_ = show_state;
97 ShowStateChanged(); 92 ShowStateChanged();
98 } 93 }
99 94
100 void ContentsView::ShowStateChanged() { 95 void ContentsView::ShowStateChanged() {
101 if (show_state_ == SHOW_SEARCH_RESULTS) { 96 if (show_state_ == SHOW_SEARCH_RESULTS) {
102 // TODO(xiyuan): Highlight default match instead of the first. 97 // TODO(xiyuan): Highlight default match instead of the first.
103 SearchResultListView* results_view = 98 SearchResultListView* results_view =
104 GetSearchResultListView(view_model_.get()); 99 GetSearchResultListView(view_model_.get());
105 if (results_view->visible()) 100 if (results_view->visible())
106 results_view->SetSelectedIndex(0); 101 results_view->SetSelectedIndex(0);
107 } 102 }
108 103
109 AnimateToIdealBounds(); 104 AnimateToIdealBounds();
110 } 105 }
111 106
112 void ContentsView::CalculateIdealBounds() { 107 void ContentsView::CalculateIdealBounds() {
113 gfx::Rect rect(GetContentsBounds()); 108 gfx::Rect rect(GetContentsBounds());
114 if (rect.IsEmpty()) 109 if (rect.IsEmpty())
115 return; 110 return;
116 111
117 gfx::Rect grid_frame(rect); 112 gfx::Rect container_frame(rect);
118 gfx::Rect results_frame(rect); 113 gfx::Rect results_frame(rect);
119 114
120 // Offsets apps grid and result list based on |show_state_|. 115 // Offsets apps grid and result list based on |show_state_|.
121 // SearchResultListView is on top of apps grid. Visible view is left in 116 // 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. 117 // visible area and invisible ones is put out of the visible area.
123 int contents_area_height = rect.height(); 118 int contents_area_height = rect.height();
124 switch (show_state_) { 119 switch (show_state_) {
125 case SHOW_APPS: 120 case SHOW_APPS:
126 results_frame.Offset(0, -contents_area_height); 121 results_frame.Offset(0, -contents_area_height);
127 break; 122 break;
128 case SHOW_SEARCH_RESULTS: 123 case SHOW_SEARCH_RESULTS:
129 grid_frame.Offset(0, contents_area_height); 124 container_frame.Offset(0, contents_area_height);
130 break; 125 break;
131 default: 126 default:
132 NOTREACHED() << "Unknown show_state_ " << show_state_; 127 NOTREACHED() << "Unknown show_state_ " << show_state_;
133 break; 128 break;
134 } 129 }
135 130
136 view_model_->set_ideal_bounds(kIndexAppsGrid, grid_frame); 131 view_model_->set_ideal_bounds(kIndexAppsContainer, container_frame);
137 view_model_->set_ideal_bounds(kIndexSearchResults, results_frame); 132 view_model_->set_ideal_bounds(kIndexSearchResults, results_frame);
138 } 133 }
139 134
140 void ContentsView::AnimateToIdealBounds() { 135 void ContentsView::AnimateToIdealBounds() {
141 CalculateIdealBounds(); 136 CalculateIdealBounds();
142 for (int i = 0; i < view_model_->view_size(); ++i) { 137 for (int i = 0; i < view_model_->view_size(); ++i) {
143 bounds_animator_->AnimateViewTo(view_model_->view_at(i), 138 bounds_animator_->AnimateViewTo(view_model_->view_at(i),
144 view_model_->ideal_bounds(i)); 139 view_model_->ideal_bounds(i));
145 } 140 }
146 } 141 }
147 142
148 void ContentsView::ShowSearchResults(bool show) { 143 void ContentsView::ShowSearchResults(bool show) {
149 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); 144 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS);
150 } 145 }
151 146
147 void ContentsView::ShowFolderContent(AppListFolderItem* item) {
148 apps_container_view_->ShowActiveFolder(item);
149 }
150
152 void ContentsView::Prerender() { 151 void ContentsView::Prerender() {
153 const int selected_page = std::max(0, pagination_model_->selected_page()); 152 const int selected_page = std::max(0, pagination_model_->selected_page());
154 GetAppsGridView(view_model_.get())->Prerender(selected_page); 153 apps_container_view_->apps_grid_view()->Prerender(selected_page);
155 } 154 }
156 155
157 gfx::Size ContentsView::GetPreferredSize() { 156 gfx::Size ContentsView::GetPreferredSize() {
158 const gfx::Size grid_size = 157 const gfx::Size container_size = GetAppsContainerView(view_model_.get())->
159 GetAppsGridView(view_model_.get())->GetPreferredSize(); 158 apps_grid_view()->GetPreferredSize();
160 const gfx::Size results_size = 159 const gfx::Size results_size =
161 GetSearchResultListView(view_model_.get())->GetPreferredSize(); 160 GetSearchResultListView(view_model_.get())->GetPreferredSize();
162 161
163 int width = std::max(grid_size.width(), results_size.width()); 162 int width = std::max(container_size.width(), results_size.width());
164 int height = std::max(grid_size.height(), results_size.height()); 163 int height = std::max(container_size.height(), results_size.height());
165 return gfx::Size(width, height); 164 return gfx::Size(width, height);
166 } 165 }
167 166
168 void ContentsView::Layout() { 167 void ContentsView::Layout() {
169 CalculateIdealBounds(); 168 CalculateIdealBounds();
170 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 169 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
171 } 170 }
172 171
173 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { 172 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) {
174 switch (show_state_) { 173 switch (show_state_) {
175 case SHOW_APPS: 174 case SHOW_APPS:
176 return GetAppsGridView(view_model_.get())->OnKeyPressed(event); 175 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event);
177 case SHOW_SEARCH_RESULTS: 176 case SHOW_SEARCH_RESULTS:
178 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); 177 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event);
179 default: 178 default:
180 NOTREACHED() << "Unknown show state " << show_state_; 179 NOTREACHED() << "Unknown show state " << show_state_;
181 } 180 }
182 return false; 181 return false;
183 } 182 }
184 183
185 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { 184 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) {
186 if (show_state_ != SHOW_APPS) 185 if (show_state_ != SHOW_APPS)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (!pagination_model_->has_transition()) { 254 if (!pagination_model_->has_transition()) {
256 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, 255 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1,
257 true); 256 true);
258 } 257 }
259 event->SetHandled(); 258 event->SetHandled();
260 event->StopPropagation(); 259 event->StopPropagation();
261 } 260 }
262 } 261 }
263 262
264 } // namespace app_list 263 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698