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