OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/start_page_view.h" | 5 #include "ui/app_list/views/start_page_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/app_list/app_list_constants.h" | 8 #include "ui/app_list/app_list_constants.h" |
9 #include "ui/app_list/app_list_item.h" | 9 #include "ui/app_list/app_list_item.h" |
10 #include "ui/app_list/app_list_model.h" | 10 #include "ui/app_list/app_list_model.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 views::View* web_view = view_delegate_->CreateStartPageWebView( | 217 views::View* web_view = view_delegate_->CreateStartPageWebView( |
218 gfx::Size(kWebViewWidth, kWebViewHeight)); | 218 gfx::Size(kWebViewWidth, kWebViewHeight)); |
219 if (web_view) { | 219 if (web_view) { |
220 web_view->SetFocusable(false); | 220 web_view->SetFocusable(false); |
221 instant_container_->AddChildView(web_view); | 221 instant_container_->AddChildView(web_view); |
222 } | 222 } |
223 | 223 |
224 instant_container_->AddChildView(search_box_spacer_view_); | 224 instant_container_->AddChildView(search_box_spacer_view_); |
225 } | 225 } |
226 | 226 |
| 227 void StartPageView::MaybeOpenCustomLauncherPage() { |
| 228 // Switch to the custom page. |
| 229 ContentsView* contents_view = app_list_main_view_->contents_view(); |
| 230 if (!contents_view->ShouldShowCustomPageClickzone()) |
| 231 return; |
| 232 |
| 233 int custom_page_index = contents_view->GetPageIndexForState( |
| 234 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 235 contents_view->SetActivePage(custom_page_index); |
| 236 } |
| 237 |
227 void StartPageView::Reset() { | 238 void StartPageView::Reset() { |
228 tiles_container_->Update(); | 239 tiles_container_->Update(); |
229 } | 240 } |
230 | 241 |
231 void StartPageView::UpdateForTesting() { | 242 void StartPageView::UpdateForTesting() { |
232 tiles_container_->Update(); | 243 tiles_container_->Update(); |
233 } | 244 } |
234 | 245 |
235 const std::vector<SearchResultTileItemView*>& StartPageView::tile_views() | 246 const std::vector<SearchResultTileItemView*>& StartPageView::tile_views() |
236 const { | 247 const { |
237 return tiles_container_->tile_views(); | 248 return tiles_container_->tile_views(); |
238 } | 249 } |
239 | 250 |
240 TileItemView* StartPageView::all_apps_button() const { | 251 TileItemView* StartPageView::all_apps_button() const { |
241 return tiles_container_->all_apps_button(); | 252 return tiles_container_->all_apps_button(); |
242 } | 253 } |
243 | 254 |
244 void StartPageView::OnShow() { | 255 void StartPageView::OnShow() { |
245 UpdateCustomPageClickzoneVisibility(); | |
246 tiles_container_->Update(); | 256 tiles_container_->Update(); |
247 tiles_container_->ClearSelectedIndex(); | 257 tiles_container_->ClearSelectedIndex(); |
248 } | 258 } |
249 | 259 |
250 void StartPageView::OnHide() { | |
251 UpdateCustomPageClickzoneVisibility(); | |
252 } | |
253 | |
254 void StartPageView::Layout() { | 260 void StartPageView::Layout() { |
255 gfx::Rect bounds(GetContentsBounds()); | 261 gfx::Rect bounds(GetContentsBounds()); |
256 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); | 262 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); |
257 instant_container_->SetBoundsRect(bounds); | 263 instant_container_->SetBoundsRect(bounds); |
258 | 264 |
259 // Tiles begin where the instant container ends. | 265 // Tiles begin where the instant container ends. |
260 bounds.set_y(bounds.bottom()); | 266 bounds.set_y(bounds.bottom()); |
261 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); | 267 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); |
262 tiles_container_->SetBoundsRect(bounds); | 268 tiles_container_->SetBoundsRect(bounds); |
263 } | 269 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 305 |
300 int selection_index = selected_index + dir; | 306 int selection_index = selected_index + dir; |
301 if (tiles_container_->IsValidSelectionIndex(selection_index)) { | 307 if (tiles_container_->IsValidSelectionIndex(selection_index)) { |
302 tiles_container_->SetSelectedIndex(selection_index); | 308 tiles_container_->SetSelectedIndex(selection_index); |
303 return true; | 309 return true; |
304 } | 310 } |
305 | 311 |
306 return false; | 312 return false; |
307 } | 313 } |
308 | 314 |
| 315 bool StartPageView::OnMousePressed(const ui::MouseEvent& event) { |
| 316 ContentsView* contents_view = app_list_main_view_->contents_view(); |
| 317 if (!contents_view->GetCustomPageCollapsedBounds().Contains(event.location())) |
| 318 return false; |
| 319 |
| 320 MaybeOpenCustomLauncherPage(); |
| 321 return true; |
| 322 } |
| 323 |
| 324 bool StartPageView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 325 if (event.y_offset() > 0) { |
| 326 MaybeOpenCustomLauncherPage(); |
| 327 return true; |
| 328 } |
| 329 |
| 330 return false; |
| 331 } |
| 332 |
| 333 void StartPageView::OnGestureEvent(ui::GestureEvent* event) { |
| 334 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN && |
| 335 event->details().scroll_y_hint() < 0) |
| 336 MaybeOpenCustomLauncherPage(); |
| 337 |
| 338 ContentsView* contents_view = app_list_main_view_->contents_view(); |
| 339 if (event->type() == ui::ET_GESTURE_TAP && |
| 340 contents_view->GetCustomPageCollapsedBounds().Contains(event->location())) |
| 341 MaybeOpenCustomLauncherPage(); |
| 342 } |
| 343 |
| 344 void StartPageView::OnScrollEvent(ui::ScrollEvent* event) { |
| 345 if (event->type() == ui::ET_SCROLL && event->y_offset() > 0) |
| 346 MaybeOpenCustomLauncherPage(); |
| 347 } |
| 348 |
309 gfx::Rect StartPageView::GetSearchBoxBounds() const { | 349 gfx::Rect StartPageView::GetSearchBoxBounds() const { |
310 return search_box_spacer_view_->bounds(); | 350 return search_box_spacer_view_->bounds(); |
311 } | 351 } |
312 | 352 |
313 void StartPageView::UpdateCustomPageClickzoneVisibility() { | |
314 // This can get called before InitWidgets(), so we cannot guarantee that | |
315 // custom_page_clickzone_ will not be null. | |
316 views::Widget* custom_page_clickzone = | |
317 app_list_main_view_->GetCustomPageClickzone(); | |
318 if (!custom_page_clickzone) | |
319 return; | |
320 | |
321 if (app_list_main_view_->contents_view()->ShouldShowCustomPageClickzone()) { | |
322 custom_page_clickzone->ShowInactive(); | |
323 return; | |
324 } | |
325 | |
326 custom_page_clickzone->Hide(); | |
327 } | |
328 | |
329 TileItemView* StartPageView::GetTileItemView(size_t index) { | 353 TileItemView* StartPageView::GetTileItemView(size_t index) { |
330 return tiles_container_->GetTileItemView(index); | 354 return tiles_container_->GetTileItemView(index); |
331 } | 355 } |
332 | 356 |
333 } // namespace app_list | 357 } // namespace app_list |
OLD | NEW |