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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 ContentsView::ContentsView(AppListMainView* app_list_main_view, | 47 ContentsView::ContentsView(AppListMainView* app_list_main_view, |
48 PaginationModel* pagination_model, | 48 PaginationModel* pagination_model, |
49 AppListModel* model, | 49 AppListModel* model, |
50 AppListViewDelegate* view_delegate) | 50 AppListViewDelegate* view_delegate) |
51 : show_state_(SHOW_APPS), | 51 : show_state_(SHOW_APPS), |
52 pagination_model_(pagination_model), | 52 pagination_model_(pagination_model), |
53 view_delegate_(view_delegate), | |
54 view_model_(new views::ViewModel), | 53 view_model_(new views::ViewModel), |
55 bounds_animator_(new views::BoundsAnimator(this)) { | 54 bounds_animator_(new views::BoundsAnimator(this)) { |
56 DCHECK(model); | 55 DCHECK(model); |
57 pagination_model_->SetTransitionDurations( | 56 pagination_model_->SetTransitionDurations( |
58 kPageTransitionDurationInMs, | 57 kPageTransitionDurationInMs, |
59 kOverscrollPageTransitionDurationMs); | 58 kOverscrollPageTransitionDurationMs); |
60 | 59 |
61 content::WebContents* start_page_contents = | 60 content::WebContents* start_page_contents = |
62 view_delegate ? view_delegate->GetStartPageContents() : NULL; | 61 view_delegate ? view_delegate->GetStartPageContents() : NULL; |
63 apps_container_view_ = new AppsContainerView( | 62 apps_container_view_ = new AppsContainerView( |
64 app_list_main_view, pagination_model, model, start_page_contents); | 63 app_list_main_view, pagination_model, model, start_page_contents); |
65 AddChildView(apps_container_view_); | 64 AddChildView(apps_container_view_); |
66 view_model_->Add(apps_container_view_, kIndexAppsContainer); | 65 view_model_->Add(apps_container_view_, kIndexAppsContainer); |
67 | 66 |
68 SearchResultListView* search_results_view = new SearchResultListView( | 67 SearchResultListView* search_results_view = new SearchResultListView( |
69 app_list_main_view); | 68 app_list_main_view, view_delegate); |
70 AddChildView(search_results_view); | 69 AddChildView(search_results_view); |
71 view_model_->Add(search_results_view, kIndexSearchResults); | 70 view_model_->Add(search_results_view, kIndexSearchResults); |
72 | 71 |
73 GetSearchResultListView(view_model_.get())->SetResults(model->results()); | 72 GetSearchResultListView(view_model_.get())->SetResults(model->results()); |
74 } | 73 } |
75 | 74 |
76 ContentsView::~ContentsView() { | 75 ContentsView::~ContentsView() { |
77 } | 76 } |
78 | 77 |
79 void ContentsView::CancelDrag() { | 78 void ContentsView::CancelDrag() { |
80 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 79 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
81 apps_container_view_->apps_grid_view()->EndDrag(true); | 80 apps_container_view_->apps_grid_view()->EndDrag(true); |
82 } | 81 } |
83 | 82 |
84 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 83 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
85 ApplicationDragAndDropHost* drag_and_drop_host) { | 84 ApplicationDragAndDropHost* drag_and_drop_host) { |
86 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 85 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
87 } | 86 } |
88 | 87 |
89 void ContentsView::SetShowState(ShowState show_state) { | 88 void ContentsView::SetShowState(ShowState show_state) { |
90 if (show_state_ == show_state) | 89 if (show_state_ == show_state) |
91 return; | 90 return; |
92 | 91 |
93 show_state_ = show_state; | 92 show_state_ = show_state; |
94 ShowStateChanged(); | 93 ShowStateChanged(); |
95 } | 94 } |
96 | 95 |
97 void ContentsView::ShowStateChanged() { | 96 void ContentsView::ShowStateChanged() { |
98 if (show_state_ == SHOW_SEARCH_RESULTS) { | 97 SearchResultListView* results_view = |
99 // TODO(xiyuan): Highlight default match instead of the first. | 98 GetSearchResultListView(view_model_.get()); |
100 SearchResultListView* results_view = | 99 // TODO(xiyuan): Highlight default match instead of the first. |
101 GetSearchResultListView(view_model_.get()); | 100 if (show_state_ == SHOW_SEARCH_RESULTS && results_view->visible()) |
102 if (results_view->visible()) | 101 results_view->SetSelectedIndex(0); |
103 results_view->SetSelectedIndex(0); | 102 results_view->UpdateAutoLaunchState(); |
104 } | |
105 | 103 |
106 AnimateToIdealBounds(); | 104 AnimateToIdealBounds(); |
107 } | 105 } |
108 | 106 |
109 void ContentsView::CalculateIdealBounds() { | 107 void ContentsView::CalculateIdealBounds() { |
110 gfx::Rect rect(GetContentsBounds()); | 108 gfx::Rect rect(GetContentsBounds()); |
111 if (rect.IsEmpty()) | 109 if (rect.IsEmpty()) |
112 return; | 110 return; |
113 | 111 |
114 gfx::Rect container_frame(rect); | 112 gfx::Rect container_frame(rect); |
(...skipping 22 matching lines...) Expand all Loading... |
137 void ContentsView::AnimateToIdealBounds() { | 135 void ContentsView::AnimateToIdealBounds() { |
138 CalculateIdealBounds(); | 136 CalculateIdealBounds(); |
139 for (int i = 0; i < view_model_->view_size(); ++i) { | 137 for (int i = 0; i < view_model_->view_size(); ++i) { |
140 bounds_animator_->AnimateViewTo(view_model_->view_at(i), | 138 bounds_animator_->AnimateViewTo(view_model_->view_at(i), |
141 view_model_->ideal_bounds(i)); | 139 view_model_->ideal_bounds(i)); |
142 } | 140 } |
143 } | 141 } |
144 | 142 |
145 void ContentsView::ShowSearchResults(bool show) { | 143 void ContentsView::ShowSearchResults(bool show) { |
146 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); | 144 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); |
147 SearchResultListView* results_view = | |
148 GetSearchResultListView(view_model_.get()); | |
149 if (show) | |
150 results_view->SetAutoLaunchTimeout(view_delegate_->GetAutoLaunchTimeout()); | |
151 else | |
152 results_view->CancelAutoLaunchTimeout(); | |
153 } | 145 } |
154 | 146 |
155 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 147 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
156 apps_container_view_->ShowActiveFolder(item); | 148 apps_container_view_->ShowActiveFolder(item); |
157 } | 149 } |
158 | 150 |
159 void ContentsView::CancelAutoLaunch() { | |
160 GetSearchResultListView(view_model_.get())->CancelAutoLaunchTimeout(); | |
161 view_delegate_->AutoLaunchCanceled(); | |
162 } | |
163 | |
164 void ContentsView::Prerender() { | 151 void ContentsView::Prerender() { |
165 const int selected_page = std::max(0, pagination_model_->selected_page()); | 152 const int selected_page = std::max(0, pagination_model_->selected_page()); |
166 apps_container_view_->apps_grid_view()->Prerender(selected_page); | 153 apps_container_view_->apps_grid_view()->Prerender(selected_page); |
167 } | 154 } |
168 | 155 |
169 gfx::Size ContentsView::GetPreferredSize() { | 156 gfx::Size ContentsView::GetPreferredSize() { |
170 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> | 157 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> |
171 apps_grid_view()->GetPreferredSize(); | 158 apps_grid_view()->GetPreferredSize(); |
172 const gfx::Size results_size = | 159 const gfx::Size results_size = |
173 GetSearchResultListView(view_model_.get())->GetPreferredSize(); | 160 GetSearchResultListView(view_model_.get())->GetPreferredSize(); |
174 | 161 |
175 int width = std::max(container_size.width(), results_size.width()); | 162 int width = std::max(container_size.width(), results_size.width()); |
176 int height = std::max(container_size.height(), results_size.height()); | 163 int height = std::max(container_size.height(), results_size.height()); |
177 return gfx::Size(width, height); | 164 return gfx::Size(width, height); |
178 } | 165 } |
179 | 166 |
180 void ContentsView::Layout() { | 167 void ContentsView::Layout() { |
181 CalculateIdealBounds(); | 168 CalculateIdealBounds(); |
182 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 169 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
183 } | 170 } |
184 | 171 |
185 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 172 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
186 CancelAutoLaunch(); | |
187 switch (show_state_) { | 173 switch (show_state_) { |
188 case SHOW_APPS: | 174 case SHOW_APPS: |
189 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); | 175 return GetAppsContainerView(view_model_.get())->OnKeyPressed(event); |
190 case SHOW_SEARCH_RESULTS: | 176 case SHOW_SEARCH_RESULTS: |
191 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); | 177 return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); |
192 default: | 178 default: |
193 NOTREACHED() << "Unknown show state " << show_state_; | 179 NOTREACHED() << "Unknown show state " << show_state_; |
194 } | 180 } |
195 return false; | 181 return false; |
196 } | 182 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (!pagination_model_->has_transition()) { | 254 if (!pagination_model_->has_transition()) { |
269 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, | 255 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, |
270 true); | 256 true); |
271 } | 257 } |
272 event->SetHandled(); | 258 event->SetHandled(); |
273 event->StopPropagation(); | 259 event->StopPropagation(); |
274 } | 260 } |
275 } | 261 } |
276 | 262 |
277 } // namespace app_list | 263 } // namespace app_list |
OLD | NEW |