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

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 commnets 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"
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.
128 app_list_main_view_->search_box_view()->SetVisible(show_state_ !=
tapted 2014/05/08 08:19:50 call app_list_main_view_->OnContentsViewShowStateC
calamity 2014/05/08 08:31:31 Done.
129 SHOW_START_PAGE);
130
131 if (show_state_ == SHOW_START_PAGE)
132 GetStartPageView(view_model_.get())->Reset();
133
110 AnimateToIdealBounds(); 134 AnimateToIdealBounds();
111 } 135 }
112 136
113 void ContentsView::CalculateIdealBounds() { 137 void ContentsView::CalculateIdealBounds() {
114 gfx::Rect rect(GetContentsBounds()); 138 gfx::Rect rect(GetContentsBounds());
115 if (rect.IsEmpty()) 139 if (rect.IsEmpty())
116 return; 140 return;
117 141
118 if (app_list::switches::IsExperimentalAppListEnabled()) { 142 if (app_list::switches::IsExperimentalAppListEnabled()) {
119 int incoming_view_index = 0; 143 int incoming_view_index = 0;
120 switch (show_state_) { 144 switch (show_state_) {
121 case SHOW_APPS: 145 case SHOW_APPS:
122 incoming_view_index = kIndexAppsContainer; 146 incoming_view_index = kIndexAppsContainer;
123 break; 147 break;
124 case SHOW_SEARCH_RESULTS: 148 case SHOW_SEARCH_RESULTS:
125 incoming_view_index = kIndexSearchResults; 149 incoming_view_index = kIndexSearchResults;
126 break; 150 break;
151 case SHOW_START_PAGE:
152 incoming_view_index = kIndexStartPage;
153 break;
127 default: 154 default:
128 NOTREACHED(); 155 NOTREACHED();
129 } 156 }
130 157
131 gfx::Rect incoming_target(rect); 158 gfx::Rect incoming_target(rect);
132 gfx::Rect outgoing_target(rect); 159 gfx::Rect outgoing_target(rect);
133 outgoing_target.set_y(-outgoing_target.height()); 160 outgoing_target.set_y(-outgoing_target.height());
134 161
135 for (int i = 0; i < view_model_->view_size(); ++i) { 162 for (int i = 0; i < view_model_->view_size(); ++i) {
136 view_model_->set_ideal_bounds(i, 163 view_model_->set_ideal_bounds(i,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 CalculateIdealBounds(); 226 CalculateIdealBounds();
200 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 227 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
201 } 228 }
202 229
203 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { 230 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) {
204 switch (show_state_) { 231 switch (show_state_) {
205 case SHOW_APPS: 232 case SHOW_APPS:
206 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); 233 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event);
207 case SHOW_SEARCH_RESULTS: 234 case SHOW_SEARCH_RESULTS:
208 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); 235 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event);
236 case SHOW_START_PAGE:
237 return GetStartPageView(view_model_.get())->OnKeyPressed(event);
209 default: 238 default:
210 NOTREACHED() << "Unknown show state " << show_state_; 239 NOTREACHED() << "Unknown show state " << show_state_;
211 } 240 }
212 return false; 241 return false;
213 } 242 }
214 243
215 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { 244 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) {
216 if (show_state_ != SHOW_APPS) 245 if (show_state_ != SHOW_APPS)
217 return false; 246 return false;
218 247
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (!pagination_model_->has_transition()) { 314 if (!pagination_model_->has_transition()) {
286 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, 315 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1,
287 true); 316 true);
288 } 317 }
289 event->SetHandled(); 318 event->SetHandled();
290 event->StopPropagation(); 319 event->StopPropagation();
291 } 320 }
292 } 321 }
293 322
294 } // namespace app_list 323 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698