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

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

Issue 186483004: Add a skeleton Start Page to the experimental app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares_change_experimental_animation
Patch Set: address comments Created 6 years, 7 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
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_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"
xiyuan 2014/05/08 16:17:48 nit: do we still need this?
calamity 2014/05/09 07:09:39 Done.
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 StartPageView* GetStartPageView(views::ViewModel* model) {
51 return static_cast<StartPageView*>(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()
(...skipping 18 matching lines...) Expand all
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.
xiyuan 2014/05/08 16:17:48 nit: update comment. It's more like "Notify parent
calamity 2014/05/09 07:09:39 Done.
128 app_list_main_view_->OnContentsViewShowStateChanged(show_state_);
xiyuan 2014/05/08 16:17:48 nit: Slightly prefer to add a show_state() accesso
calamity 2014/05/09 07:09:39 Done.
129
130 if (show_state_ == SHOW_START_PAGE)
131 GetStartPageView(view_model_.get())->Reset();
132
110 AnimateToIdealBounds(); 133 AnimateToIdealBounds();
111 } 134 }
112 135
113 void ContentsView::CalculateIdealBounds() { 136 void ContentsView::CalculateIdealBounds() {
114 gfx::Rect rect(GetContentsBounds()); 137 gfx::Rect rect(GetContentsBounds());
115 if (rect.IsEmpty()) 138 if (rect.IsEmpty())
116 return; 139 return;
117 140
118 if (app_list::switches::IsExperimentalAppListEnabled()) { 141 if (app_list::switches::IsExperimentalAppListEnabled()) {
119 int incoming_view_index = 0; 142 int incoming_view_index = 0;
120 switch (show_state_) { 143 switch (show_state_) {
121 case SHOW_APPS: 144 case SHOW_APPS:
122 incoming_view_index = kIndexAppsContainer; 145 incoming_view_index = kIndexAppsContainer;
123 break; 146 break;
124 case SHOW_SEARCH_RESULTS: 147 case SHOW_SEARCH_RESULTS:
125 incoming_view_index = kIndexSearchResults; 148 incoming_view_index = kIndexSearchResults;
126 break; 149 break;
150 case SHOW_START_PAGE:
151 incoming_view_index = kIndexStartPage;
152 break;
127 default: 153 default:
128 NOTREACHED(); 154 NOTREACHED();
129 } 155 }
130 156
131 gfx::Rect incoming_target(rect); 157 gfx::Rect incoming_target(rect);
132 gfx::Rect outgoing_target(rect); 158 gfx::Rect outgoing_target(rect);
133 outgoing_target.set_y(-outgoing_target.height()); 159 outgoing_target.set_y(-outgoing_target.height());
134 160
135 for (int i = 0; i < view_model_->view_size(); ++i) { 161 for (int i = 0; i < view_model_->view_size(); ++i) {
136 view_model_->set_ideal_bounds(i, 162 view_model_->set_ideal_bounds(i,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 CalculateIdealBounds(); 225 CalculateIdealBounds();
200 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 226 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
201 } 227 }
202 228
203 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { 229 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) {
204 switch (show_state_) { 230 switch (show_state_) {
205 case SHOW_APPS: 231 case SHOW_APPS:
206 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); 232 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event);
207 case SHOW_SEARCH_RESULTS: 233 case SHOW_SEARCH_RESULTS:
208 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); 234 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event);
235 case SHOW_START_PAGE:
236 return GetStartPageView(view_model_.get())->OnKeyPressed(event);
209 default: 237 default:
210 NOTREACHED() << "Unknown show state " << show_state_; 238 NOTREACHED() << "Unknown show state " << show_state_;
211 } 239 }
212 return false; 240 return false;
213 } 241 }
214 242
215 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { 243 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) {
216 if (show_state_ != SHOW_APPS) 244 if (show_state_ != SHOW_APPS)
217 return false; 245 return false;
218 246
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (!pagination_model_->has_transition()) { 313 if (!pagination_model_->has_transition()) {
286 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, 314 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1,
287 true); 315 true);
288 } 316 }
289 event->SetHandled(); 317 event->SetHandled();
290 event->StopPropagation(); 318 event->StopPropagation();
291 } 319 }
292 } 320 }
293 321
294 } // namespace app_list 322 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698