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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 DISALLOW_COPY_AND_ASSIGN(SearchBoxSpacerView); | 61 DISALLOW_COPY_AND_ASSIGN(SearchBoxSpacerView); |
62 }; | 62 }; |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 // A container that holds the start page recommendation tiles and the all apps | 66 // A container that holds the start page recommendation tiles and the all apps |
67 // tile. | 67 // tile. |
68 class StartPageView::StartPageTilesContainer | 68 class StartPageView::StartPageTilesContainer |
69 : public SearchResultContainerView { | 69 : public SearchResultContainerView { |
70 public: | 70 public: |
71 explicit StartPageTilesContainer(AllAppsTileItemView* all_apps_button); | 71 StartPageTilesContainer(ContentsView* contents_view, |
| 72 AllAppsTileItemView* all_apps_button); |
72 ~StartPageTilesContainer() override; | 73 ~StartPageTilesContainer() override; |
73 | 74 |
74 TileItemView* GetTileItemView(size_t index); | 75 TileItemView* GetTileItemView(size_t index); |
75 | 76 |
76 const std::vector<SearchResultTileItemView*>& tile_views() const { | 77 const std::vector<SearchResultTileItemView*>& tile_views() const { |
77 return search_result_tile_views_; | 78 return search_result_tile_views_; |
78 } | 79 } |
79 | 80 |
80 AllAppsTileItemView* all_apps_button() { return all_apps_button_; } | 81 AllAppsTileItemView* all_apps_button() { return all_apps_button_; } |
81 | 82 |
82 // Overridden from SearchResultContainerView: | 83 // Overridden from SearchResultContainerView: |
83 int Update() override; | 84 int Update() override; |
84 void UpdateSelectedIndex(int old_selected, int new_selected) override; | 85 void UpdateSelectedIndex(int old_selected, int new_selected) override; |
85 void OnContainerSelected(bool from_bottom) override; | 86 void OnContainerSelected(bool from_bottom) override; |
86 | 87 |
87 private: | 88 private: |
| 89 ContentsView* contents_view_; |
| 90 |
88 std::vector<SearchResultTileItemView*> search_result_tile_views_; | 91 std::vector<SearchResultTileItemView*> search_result_tile_views_; |
89 AllAppsTileItemView* all_apps_button_; | 92 AllAppsTileItemView* all_apps_button_; |
90 | 93 |
91 DISALLOW_COPY_AND_ASSIGN(StartPageTilesContainer); | 94 DISALLOW_COPY_AND_ASSIGN(StartPageTilesContainer); |
92 }; | 95 }; |
93 | 96 |
94 StartPageView::StartPageTilesContainer::StartPageTilesContainer( | 97 StartPageView::StartPageTilesContainer::StartPageTilesContainer( |
| 98 ContentsView* contents_view, |
95 AllAppsTileItemView* all_apps_button) | 99 AllAppsTileItemView* all_apps_button) |
96 : all_apps_button_(all_apps_button) { | 100 : contents_view_(contents_view), all_apps_button_(all_apps_button) { |
97 views::BoxLayout* tiles_layout_manager = | 101 views::BoxLayout* tiles_layout_manager = |
98 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); | 102 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); |
99 tiles_layout_manager->set_main_axis_alignment( | 103 tiles_layout_manager->set_main_axis_alignment( |
100 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 104 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
101 SetLayoutManager(tiles_layout_manager); | 105 SetLayoutManager(tiles_layout_manager); |
102 set_background( | 106 set_background( |
103 views::Background::CreateSolidBackground(kLabelBackgroundColor)); | 107 views::Background::CreateSolidBackground(kLabelBackgroundColor)); |
104 | 108 |
105 // Add SearchResultTileItemViews to the container. | 109 // Add SearchResultTileItemViews to the container. |
106 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | 110 for (size_t i = 0; i < kNumStartPageTiles; ++i) { |
(...skipping 15 matching lines...) Expand all Loading... |
122 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 126 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( |
123 size_t index) { | 127 size_t index) { |
124 DCHECK_GT(kNumStartPageTiles + 1, index); | 128 DCHECK_GT(kNumStartPageTiles + 1, index); |
125 if (index == kNumStartPageTiles) | 129 if (index == kNumStartPageTiles) |
126 return all_apps_button_; | 130 return all_apps_button_; |
127 | 131 |
128 return search_result_tile_views_[index]; | 132 return search_result_tile_views_[index]; |
129 } | 133 } |
130 | 134 |
131 int StartPageView::StartPageTilesContainer::Update() { | 135 int StartPageView::StartPageTilesContainer::Update() { |
| 136 // Ignore updates and disable buttons when transitioning to a different |
| 137 // state. |
| 138 if (contents_view_->GetActiveState() != AppListModel::STATE_START) { |
| 139 for (auto* view : search_result_tile_views_) |
| 140 view->SetEnabled(false); |
| 141 |
| 142 return num_results(); |
| 143 } |
| 144 |
132 std::vector<SearchResult*> display_results = | 145 std::vector<SearchResult*> display_results = |
133 AppListModel::FilterSearchResultsByDisplayType( | 146 AppListModel::FilterSearchResultsByDisplayType( |
134 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 147 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); |
135 | 148 |
136 // Update the tile item results. | 149 // Update the tile item results. |
137 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 150 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { |
138 SearchResult* item = nullptr; | 151 SearchResult* item = NULL; |
139 if (i < display_results.size()) | 152 if (i < display_results.size()) |
140 item = display_results[i]; | 153 item = display_results[i]; |
141 search_result_tile_views_[i]->SetSearchResult(item); | 154 search_result_tile_views_[i]->SetSearchResult(item); |
| 155 search_result_tile_views_[i]->SetEnabled(true); |
142 } | 156 } |
143 | 157 |
144 Layout(); | 158 Layout(); |
145 parent()->Layout(); | 159 parent()->Layout(); |
146 // Add 1 to the results size to account for the all apps button. | 160 // Add 1 to the results size to account for the all apps button. |
147 return display_results.size() + 1; | 161 return display_results.size() + 1; |
148 } | 162 } |
149 | 163 |
150 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( | 164 void StartPageView::StartPageTilesContainer::UpdateSelectedIndex( |
151 int old_selected, | 165 int old_selected, |
(...skipping 11 matching lines...) Expand all Loading... |
163 | 177 |
164 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
165 // StartPageView implementation: | 179 // StartPageView implementation: |
166 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 180 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
167 AppListViewDelegate* view_delegate) | 181 AppListViewDelegate* view_delegate) |
168 : app_list_main_view_(app_list_main_view), | 182 : app_list_main_view_(app_list_main_view), |
169 view_delegate_(view_delegate), | 183 view_delegate_(view_delegate), |
170 search_box_spacer_view_(new SearchBoxSpacerView( | 184 search_box_spacer_view_(new SearchBoxSpacerView( |
171 app_list_main_view->search_box_view()->GetPreferredSize())), | 185 app_list_main_view->search_box_view()->GetPreferredSize())), |
172 instant_container_(new views::View), | 186 instant_container_(new views::View), |
173 tiles_container_(new StartPageTilesContainer(new AllAppsTileItemView( | 187 tiles_container_(new StartPageTilesContainer( |
174 app_list_main_view_->contents_view(), | 188 app_list_main_view->contents_view(), |
175 view_delegate_->GetModel()->top_level_item_list()))) { | 189 new AllAppsTileItemView( |
| 190 app_list_main_view_->contents_view(), |
| 191 view_delegate_->GetModel()->top_level_item_list()))) { |
176 // The view containing the start page WebContents and SearchBoxSpacerView. | 192 // The view containing the start page WebContents and SearchBoxSpacerView. |
177 InitInstantContainer(); | 193 InitInstantContainer(); |
178 AddChildView(instant_container_); | 194 AddChildView(instant_container_); |
179 | 195 |
180 // The view containing the start page tiles. | 196 // The view containing the start page tiles. |
181 AddChildView(tiles_container_); | 197 AddChildView(tiles_container_); |
182 | 198 |
183 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 199 tiles_container_->SetResults(view_delegate_->GetModel()->results()); |
184 Reset(); | 200 Reset(); |
185 } | 201 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 326 } |
311 | 327 |
312 custom_page_clickzone->Hide(); | 328 custom_page_clickzone->Hide(); |
313 } | 329 } |
314 | 330 |
315 TileItemView* StartPageView::GetTileItemView(size_t index) { | 331 TileItemView* StartPageView::GetTileItemView(size_t index) { |
316 return tiles_container_->GetTileItemView(index); | 332 return tiles_container_->GetTileItemView(index); |
317 } | 333 } |
318 | 334 |
319 } // namespace app_list | 335 } // namespace app_list |
OLD | NEW |