| 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" |
| 11 #include "ui/app_list/app_list_view_delegate.h" | 11 #include "ui/app_list/app_list_view_delegate.h" |
| 12 #include "ui/app_list/search_result.h" | 12 #include "ui/app_list/search_result.h" |
| 13 #include "ui/app_list/views/all_apps_tile_item_view.h" |
| 13 #include "ui/app_list/views/app_list_main_view.h" | 14 #include "ui/app_list/views/app_list_main_view.h" |
| 14 #include "ui/app_list/views/search_box_view.h" | 15 #include "ui/app_list/views/search_box_view.h" |
| 15 #include "ui/app_list/views/search_result_list_view.h" | 16 #include "ui/app_list/views/search_result_list_view.h" |
| 17 #include "ui/app_list/views/search_result_tile_item_view.h" |
| 16 #include "ui/app_list/views/tile_item_view.h" | 18 #include "ui/app_list/views/tile_item_view.h" |
| 17 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 18 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
| 19 #include "ui/views/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/controls/textfield/textfield.h" | 23 #include "ui/views/controls/textfield/textfield.h" |
| 22 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 24 | 26 |
| 25 namespace app_list { | 27 namespace app_list { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 // Layout constants. | 31 // Layout constants. |
| 30 const int kTopMargin = 84; | 32 const int kTopMargin = 84; |
| 31 const int kInstantContainerSpacing = 11; | 33 const int kInstantContainerSpacing = 11; |
| 32 const int kSearchBoxAndTilesSpacing = 40; | 34 const int kSearchBoxAndTilesSpacing = 40; |
| 33 | 35 |
| 34 // WebView constants. | 36 // WebView constants. |
| 35 const int kWebViewWidth = 500; | 37 const int kWebViewWidth = 500; |
| 36 const int kWebViewHeight = 105; | 38 const int kWebViewHeight = 105; |
| 37 | 39 |
| 38 // DummySearchBoxView constants. | 40 // DummySearchBoxView constants. |
| 39 const int kDummySearchBoxWidth = 480; | 41 const int kDummySearchBoxWidth = 480; |
| 40 | 42 |
| 41 // Tile container constants. | 43 // Tile container constants. |
| 42 const size_t kNumStartPageTiles = 5; | 44 const size_t kNumStartPageTiles = 4; |
| 45 const size_t kNumSearchResultTiles = 5; |
| 43 const int kTileSpacing = 10; | 46 const int kTileSpacing = 10; |
| 44 | 47 |
| 45 // A placeholder search box which is sized to fit within the start page view. | 48 // A placeholder search box which is sized to fit within the start page view. |
| 46 class DummySearchBoxView : public SearchBoxView { | 49 class DummySearchBoxView : public SearchBoxView { |
| 47 public: | 50 public: |
| 48 DummySearchBoxView(SearchBoxViewDelegate* delegate, | 51 DummySearchBoxView(SearchBoxViewDelegate* delegate, |
| 49 AppListViewDelegate* view_delegate) | 52 AppListViewDelegate* view_delegate) |
| 50 : SearchBoxView(delegate, view_delegate) { | 53 : SearchBoxView(delegate, view_delegate) { |
| 51 } | 54 } |
| 52 | 55 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 127 |
| 125 instant_container_->AddChildView(search_box_container); | 128 instant_container_->AddChildView(search_box_container); |
| 126 } | 129 } |
| 127 | 130 |
| 128 void StartPageView::InitTilesContainer() { | 131 void StartPageView::InitTilesContainer() { |
| 129 views::BoxLayout* tiles_layout_manager = | 132 views::BoxLayout* tiles_layout_manager = |
| 130 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); | 133 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); |
| 131 tiles_layout_manager->set_main_axis_alignment( | 134 tiles_layout_manager->set_main_axis_alignment( |
| 132 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 135 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 133 tiles_container_->SetLayoutManager(tiles_layout_manager); | 136 tiles_container_->SetLayoutManager(tiles_layout_manager); |
| 134 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | 137 |
| 135 TileItemView* tile_item = new TileItemView(); | 138 // Add SearchResultTileItemViews to the container. |
| 139 for (size_t i = 0; i < std::max(kNumStartPageTiles, kNumSearchResultTiles); |
| 140 ++i) { |
| 141 SearchResultTileItemView* tile_item = new SearchResultTileItemView(); |
| 136 tiles_container_->AddChildView(tile_item); | 142 tiles_container_->AddChildView(tile_item); |
| 137 tile_views_.push_back(tile_item); | 143 search_result_tile_views_.push_back(tile_item); |
| 138 } | 144 } |
| 145 |
| 146 // Also add a special "all apps" button to the end of the container. |
| 147 all_apps_button_ = |
| 148 new AllAppsTileItemView(app_list_main_view_->contents_view()); |
| 149 tiles_container_->AddChildView(all_apps_button_); |
| 139 } | 150 } |
| 140 | 151 |
| 141 void StartPageView::SetModel(AppListModel* model) { | 152 void StartPageView::SetModel(AppListModel* model) { |
| 142 DCHECK(model); | 153 DCHECK(model); |
| 143 if (search_results_model_) | 154 if (search_results_model_) |
| 144 search_results_model_->RemoveObserver(this); | 155 search_results_model_->RemoveObserver(this); |
| 145 search_results_model_ = model->results(); | 156 search_results_model_ = model->results(); |
| 146 search_results_model_->AddObserver(this); | 157 search_results_model_->AddObserver(this); |
| 147 results_view_->SetResults(search_results_model_); | 158 results_view_->SetResults(search_results_model_); |
| 148 Reset(); | 159 Reset(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 192 } |
| 182 | 193 |
| 183 bool StartPageView::IsShowingSearchResults() const { | 194 bool StartPageView::IsShowingSearchResults() const { |
| 184 return show_state_ == SHOW_SEARCH_RESULTS; | 195 return show_state_ == SHOW_SEARCH_RESULTS; |
| 185 } | 196 } |
| 186 | 197 |
| 187 void StartPageView::UpdateForTesting() { | 198 void StartPageView::UpdateForTesting() { |
| 188 Update(); | 199 Update(); |
| 189 } | 200 } |
| 190 | 201 |
| 202 TileItemView* StartPageView::all_apps_button() const { |
| 203 return all_apps_button_; |
| 204 } |
| 205 |
| 191 bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) { | 206 bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) { |
| 192 if (show_state_ == SHOW_SEARCH_RESULTS) | 207 if (show_state_ == SHOW_SEARCH_RESULTS) |
| 193 return results_view_->OnKeyPressed(event); | 208 return results_view_->OnKeyPressed(event); |
| 194 | 209 |
| 195 return false; | 210 return false; |
| 196 } | 211 } |
| 197 | 212 |
| 198 void StartPageView::Layout() { | 213 void StartPageView::Layout() { |
| 199 // Instant and search results take up the height of the instant container. | 214 // Instant and search results take up the height of the instant container. |
| 200 gfx::Rect bounds(GetContentsBounds()); | 215 gfx::Rect bounds(GetContentsBounds()); |
| 201 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); | 216 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); |
| 202 instant_container_->SetBoundsRect(bounds); | 217 instant_container_->SetBoundsRect(bounds); |
| 203 results_view_->SetBoundsRect(bounds); | 218 results_view_->SetBoundsRect(bounds); |
| 204 | 219 |
| 205 // Tiles begin where the instant container ends. | 220 // Tiles begin where the instant container ends. |
| 206 bounds.set_y(bounds.bottom()); | 221 bounds.set_y(bounds.bottom()); |
| 207 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); | 222 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); |
| 208 tiles_container_->SetBoundsRect(bounds); | 223 tiles_container_->SetBoundsRect(bounds); |
| 209 } | 224 } |
| 210 | 225 |
| 211 void StartPageView::Update() { | 226 void StartPageView::Update() { |
| 227 size_t max_tiles = show_state_ == SHOW_START_PAGE ? kNumStartPageTiles |
| 228 : kNumSearchResultTiles; |
| 212 std::vector<SearchResult*> display_results = | 229 std::vector<SearchResult*> display_results = |
| 213 AppListModel::FilterSearchResultsByDisplayType(search_results_model_, | 230 AppListModel::FilterSearchResultsByDisplayType( |
| 214 SearchResult::DISPLAY_TILE, | 231 search_results_model_, SearchResult::DISPLAY_TILE, max_tiles); |
| 215 kNumStartPageTiles); | 232 |
| 216 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | 233 // Update the tile item results. |
| 234 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { |
| 217 SearchResult* item = NULL; | 235 SearchResult* item = NULL; |
| 218 if (i < display_results.size()) | 236 if (i < display_results.size()) |
| 219 item = display_results[i]; | 237 item = display_results[i]; |
| 220 tile_views_[i]->SetSearchResult(item); | 238 search_result_tile_views_[i]->SetSearchResult(item); |
| 221 } | 239 } |
| 240 |
| 241 // Show or hide the all apps button (depending on the current show state). |
| 242 all_apps_button_->SetVisible(show_state_ == SHOW_START_PAGE); |
| 243 |
| 222 tiles_container_->Layout(); | 244 tiles_container_->Layout(); |
| 223 Layout(); | 245 Layout(); |
| 224 update_factory_.InvalidateWeakPtrs(); | 246 update_factory_.InvalidateWeakPtrs(); |
| 225 } | 247 } |
| 226 | 248 |
| 227 void StartPageView::ScheduleUpdate() { | 249 void StartPageView::ScheduleUpdate() { |
| 228 // When search results are added one by one, each addition generates an update | 250 // When search results are added one by one, each addition generates an update |
| 229 // request. Consolidates those update requests into one Update call. | 251 // request. Consolidates those update requests into one Update call. |
| 230 if (!update_factory_.HasWeakPtrs()) { | 252 if (!update_factory_.HasWeakPtrs()) { |
| 231 base::MessageLoop::current()->PostTask( | 253 base::MessageLoop::current()->PostTask( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 252 | 274 |
| 253 void StartPageView::ListItemMoved(size_t index, size_t target_index) { | 275 void StartPageView::ListItemMoved(size_t index, size_t target_index) { |
| 254 ScheduleUpdate(); | 276 ScheduleUpdate(); |
| 255 } | 277 } |
| 256 | 278 |
| 257 void StartPageView::ListItemsChanged(size_t start, size_t count) { | 279 void StartPageView::ListItemsChanged(size_t start, size_t count) { |
| 258 ScheduleUpdate(); | 280 ScheduleUpdate(); |
| 259 } | 281 } |
| 260 | 282 |
| 261 } // namespace app_list | 283 } // namespace app_list |
| OLD | NEW |