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

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

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

Powered by Google App Engine
This is Rietveld 408576698