OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/app_list/views/search_result_page_view.h" |
| 6 |
| 7 #include "ui/app_list/app_list_view_delegate.h" |
| 8 #include "ui/app_list/search_result.h" |
| 9 #include "ui/app_list/views/app_list_main_view.h" |
| 10 #include "ui/app_list/views/search_box_view.h" |
| 11 #include "ui/app_list/views/search_result_list_view.h" |
| 12 #include "ui/app_list/views/search_result_tile_item_view.h" |
| 13 #include "ui/views/layout/box_layout.h" |
| 14 #include "ui/views/widget/widget.h" |
| 15 |
| 16 namespace app_list { |
| 17 |
| 18 namespace { |
| 19 |
| 20 const int kGroupSpacing = 20; |
| 21 |
| 22 // Tile container constants. |
| 23 const size_t kNumSearchResultTiles = 5; |
| 24 const int kTileSpacing = 10; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 SearchResultPageView::SearchResultPageView(AppListMainView* app_list_main_view, |
| 29 AppListViewDelegate* view_delegate) |
| 30 : results_view_( |
| 31 new SearchResultListView(app_list_main_view, view_delegate)), |
| 32 tiles_container_(new views::View) { |
| 33 SetLayoutManager( |
| 34 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, kGroupSpacing)); |
| 35 |
| 36 // The view containing the search results. |
| 37 AddChildView(results_view_); |
| 38 |
| 39 // The view containing the start page tiles. |
| 40 InitTilesContainer(); |
| 41 AddChildView(tiles_container_); |
| 42 |
| 43 AppListModel::SearchResults* model = view_delegate->GetModel()->results(); |
| 44 SetResults(model); |
| 45 results_view_->SetResults(model); |
| 46 } |
| 47 |
| 48 SearchResultPageView::~SearchResultPageView() { |
| 49 } |
| 50 |
| 51 void SearchResultPageView::InitTilesContainer() { |
| 52 views::BoxLayout* tiles_layout_manager = |
| 53 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); |
| 54 tiles_layout_manager->set_main_axis_alignment( |
| 55 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 56 tiles_container_->SetLayoutManager(tiles_layout_manager); |
| 57 for (size_t i = 0; i < kNumSearchResultTiles; ++i) { |
| 58 SearchResultTileItemView* tile_item = new SearchResultTileItemView(); |
| 59 tiles_container_->AddChildView(tile_item); |
| 60 tile_views_.push_back(tile_item); |
| 61 } |
| 62 } |
| 63 |
| 64 bool SearchResultPageView::OnKeyPressed(const ui::KeyEvent& event) { |
| 65 return results_view_->OnKeyPressed(event); |
| 66 } |
| 67 |
| 68 void SearchResultPageView::Update() { |
| 69 results_view_->SetSelectedIndex(0); |
| 70 std::vector<SearchResult*> display_results = |
| 71 AppListModel::FilterSearchResultsByDisplayType( |
| 72 results(), SearchResult::DISPLAY_TILE, kNumSearchResultTiles); |
| 73 for (size_t i = 0; i < kNumSearchResultTiles; ++i) { |
| 74 SearchResult* item = NULL; |
| 75 if (i < display_results.size()) |
| 76 item = display_results[i]; |
| 77 tile_views_[i]->SetSearchResult(item); |
| 78 } |
| 79 tiles_container_->Layout(); |
| 80 Layout(); |
| 81 } |
| 82 |
| 83 } // namespace app_list |
OLD | NEW |