Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" | 
| 11 #include "base/macros.h" | 11 #include "base/macros.h" | 
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" | 
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" | 
| 14 #include "ui/accessibility/ax_node_data.h" | 14 #include "ui/accessibility/ax_node_data.h" | 
| 15 #include "ui/app_list/app_list_constants.h" | 15 #include "ui/app_list/app_list_constants.h" | 
| 16 #include "ui/app_list/app_list_features.h" | |
| 16 #include "ui/app_list/app_list_item.h" | 17 #include "ui/app_list/app_list_item.h" | 
| 17 #include "ui/app_list/app_list_model.h" | 18 #include "ui/app_list/app_list_model.h" | 
| 19 #include "ui/app_list/app_list_switches.h" | |
| 18 #include "ui/app_list/app_list_view_delegate.h" | 20 #include "ui/app_list/app_list_view_delegate.h" | 
| 19 #include "ui/app_list/search_result.h" | 21 #include "ui/app_list/search_result.h" | 
| 20 #include "ui/app_list/views/all_apps_tile_item_view.h" | 22 #include "ui/app_list/views/all_apps_tile_item_view.h" | 
| 21 #include "ui/app_list/views/app_list_main_view.h" | 23 #include "ui/app_list/views/app_list_main_view.h" | 
| 22 #include "ui/app_list/views/contents_view.h" | 24 #include "ui/app_list/views/contents_view.h" | 
| 23 #include "ui/app_list/views/custom_launcher_page_view.h" | 25 #include "ui/app_list/views/custom_launcher_page_view.h" | 
| 24 #include "ui/app_list/views/search_box_view.h" | 26 #include "ui/app_list/views/search_box_view.h" | 
| 25 #include "ui/app_list/views/search_result_container_view.h" | 27 #include "ui/app_list/views/search_result_container_view.h" | 
| 26 #include "ui/app_list/views/search_result_tile_item_view.h" | 28 #include "ui/app_list/views/search_result_tile_item_view.h" | 
| 27 #include "ui/app_list/views/tile_item_view.h" | 29 #include "ui/app_list/views/tile_item_view.h" | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 44 constexpr int kStartPageSearchBoxWidth = 480; | 46 constexpr int kStartPageSearchBoxWidth = 480; | 
| 45 | 47 | 
| 46 // WebView constants. | 48 // WebView constants. | 
| 47 constexpr int kWebViewWidth = 700; | 49 constexpr int kWebViewWidth = 700; | 
| 48 constexpr int kWebViewHeight = 224; | 50 constexpr int kWebViewHeight = 224; | 
| 49 | 51 | 
| 50 // Tile container constants. | 52 // Tile container constants. | 
| 51 constexpr int kTileSpacing = 7; | 53 constexpr int kTileSpacing = 7; | 
| 52 constexpr int kNumStartPageTilesCols = 5; | 54 constexpr int kNumStartPageTilesCols = 5; | 
| 53 constexpr int kTilesHorizontalMarginLeft = 145; | 55 constexpr int kTilesHorizontalMarginLeft = 145; | 
| 56 constexpr int kCenterColumnOfStartPageAppGrid = 3; | |
| 54 | 57 | 
| 55 constexpr int kLauncherPageBackgroundWidth = 400; | 58 constexpr int kLauncherPageBackgroundWidth = 400; | 
| 56 | |
| 
 
xiyuan
2017/05/30 22:18:50
nit: please restore. Prevailing style is to have a
 
newcomer
2017/06/01 01:42:54
Done.
 
 | |
| 57 } // namespace | 59 } // namespace | 
| 58 | 60 | 
| 59 class CustomLauncherPageBackgroundView : public views::View { | 61 class CustomLauncherPageBackgroundView : public views::View { | 
| 60 public: | 62 public: | 
| 61 explicit CustomLauncherPageBackgroundView( | 63 explicit CustomLauncherPageBackgroundView( | 
| 62 const std::string& custom_launcher_page_name) | 64 const std::string& custom_launcher_page_name) | 
| 63 : selected_(false), | 65 : selected_(false), | 
| 64 custom_launcher_page_name_(custom_launcher_page_name) { | 66 custom_launcher_page_name_(custom_launcher_page_name) { | 
| 65 set_background(views::Background::CreateSolidBackground(kSelectedColor)); | 67 set_background(views::Background::CreateSolidBackground(kSelectedColor)); | 
| 66 } | 68 } | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 ContentsView* contents_view, | 132 ContentsView* contents_view, | 
| 131 AllAppsTileItemView* all_apps_button, | 133 AllAppsTileItemView* all_apps_button, | 
| 132 AppListViewDelegate* view_delegate) | 134 AppListViewDelegate* view_delegate) | 
| 133 : contents_view_(contents_view), | 135 : contents_view_(contents_view), | 
| 134 view_delegate_(view_delegate), | 136 view_delegate_(view_delegate), | 
| 135 all_apps_button_(all_apps_button) { | 137 all_apps_button_(all_apps_button) { | 
| 136 set_background( | 138 set_background( | 
| 137 views::Background::CreateSolidBackground(kLabelBackgroundColor)); | 139 views::Background::CreateSolidBackground(kLabelBackgroundColor)); | 
| 138 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 140 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 
| 139 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); | 141 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); | 
| 140 CreateAppsGrid(kNumStartPageTiles); | 142 | 
| 143 CreateAppsGrid(features::IsFullscreenAppListEnabled() | |
| 144 ? fullscreen_constants::kNumStartPageTiles | |
| 145 : kNumStartPageTiles); | |
| 141 } | 146 } | 
| 142 | 147 | 
| 143 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { | 148 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { | 
| 144 } | 149 } | 
| 145 | 150 | 
| 146 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 151 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 
| 147 int index) { | 152 int index) { | 
| 148 DCHECK_GT(num_results(), index); | 153 DCHECK_GT(num_results(), index); | 
| 149 if (index == num_results() - 1) | 154 if (index == num_results() - 1) | 
| 150 return all_apps_button_; | 155 return all_apps_button_; | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 164 | 169 | 
| 165 std::vector<SearchResult*> display_results = | 170 std::vector<SearchResult*> display_results = | 
| 166 AppListModel::FilterSearchResultsByDisplayType( | 171 AppListModel::FilterSearchResultsByDisplayType( | 
| 167 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 172 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 
| 168 if (display_results.size() != search_result_tile_views_.size()) { | 173 if (display_results.size() != search_result_tile_views_.size()) { | 
| 169 // We should recreate the grid layout in this case. | 174 // We should recreate the grid layout in this case. | 
| 170 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | 175 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | 
| 171 delete search_result_tile_views_[i]; | 176 delete search_result_tile_views_[i]; | 
| 172 search_result_tile_views_.clear(); | 177 search_result_tile_views_.clear(); | 
| 173 RemoveChildView(all_apps_button_); | 178 RemoveChildView(all_apps_button_); | 
| 174 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | 179 | 
| 180 CreateAppsGrid(features::IsFullscreenAppListEnabled() | |
| 181 ? fullscreen_constants::kNumStartPageTiles | |
| 182 : std::min(kNumStartPageTiles, display_results.size())); | |
| 175 } | 183 } | 
| 176 | 184 | 
| 177 // Update the tile item results. | 185 // Update the tile item results. | 
| 178 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 186 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 
| 179 SearchResult* item = nullptr; | 187 SearchResult* item = nullptr; | 
| 180 if (i < display_results.size()) | 188 if (i < display_results.size()) | 
| 181 item = display_results[i]; | 189 item = display_results[i]; | 
| 182 search_result_tile_views_[i]->SetSearchResult(item); | 190 search_result_tile_views_[i]->SetSearchResult(item); | 
| 183 search_result_tile_views_[i]->SetEnabled(true); | 191 search_result_tile_views_[i]->SetEnabled(true); | 
| 184 } | 192 } | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 new SearchResultTileItemView(this, view_delegate_); | 243 new SearchResultTileItemView(this, view_delegate_); | 
| 236 if (i % kNumStartPageTilesCols == 0) | 244 if (i % kNumStartPageTilesCols == 0) | 
| 237 tiles_layout_manager->StartRow(0, 0); | 245 tiles_layout_manager->StartRow(0, 0); | 
| 238 tiles_layout_manager->AddView(tile_item); | 246 tiles_layout_manager->AddView(tile_item); | 
| 239 AddChildView(tile_item); | 247 AddChildView(tile_item); | 
| 240 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | 248 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | 
| 241 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 249 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 
| 242 search_result_tile_views_.emplace_back(tile_item); | 250 search_result_tile_views_.emplace_back(tile_item); | 
| 243 } | 251 } | 
| 244 | 252 | 
| 245 // Also add a special "all apps" button to the end of the container. | |
| 246 all_apps_button_->UpdateIcon(); | 253 all_apps_button_->UpdateIcon(); | 
| 247 if (i % kNumStartPageTilesCols == 0) | 254 if (features::IsFullscreenAppListEnabled()) { | 
| 255 // Also add a special "all apps" button to the middle of the next row of the | |
| 256 // container. | |
| 248 tiles_layout_manager->StartRow(0, 0); | 257 tiles_layout_manager->StartRow(0, 0); | 
| 258 tiles_layout_manager->SkipColumns(kCenterColumnOfStartPageAppGrid); | |
| 259 } else { | |
| 260 // Also add a special "all apps" button to the end of the next row of the | |
| 261 // container. | |
| 262 if (i % kNumStartPageTilesCols == 0) | |
| 263 tiles_layout_manager->StartRow(0, 0); | |
| 264 } | |
| 265 | |
| 249 tiles_layout_manager->AddView(all_apps_button_); | 266 tiles_layout_manager->AddView(all_apps_button_); | 
| 250 AddChildView(all_apps_button_); | 267 AddChildView(all_apps_button_); | 
| 251 } | 268 } | 
| 252 | 269 | 
| 253 //////////////////////////////////////////////////////////////////////////////// | 270 //////////////////////////////////////////////////////////////////////////////// | 
| 254 // StartPageView implementation: | 271 // StartPageView implementation: | 
| 255 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 272 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 
| 256 AppListViewDelegate* view_delegate) | 273 AppListViewDelegate* view_delegate, | 
| 274 AppListView* app_list_view) | |
| 257 : app_list_main_view_(app_list_main_view), | 275 : app_list_main_view_(app_list_main_view), | 
| 258 view_delegate_(view_delegate), | 276 view_delegate_(view_delegate), | 
| 259 search_box_spacer_view_(new View()), | 277 search_box_spacer_view_(new View()), | 
| 260 instant_container_(new views::View), | 278 instant_container_(new views::View), | 
| 261 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 279 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 
| 262 view_delegate_->GetModel()->custom_launcher_page_name())), | 280 view_delegate_->GetModel()->custom_launcher_page_name())), | 
| 263 tiles_container_(new StartPageTilesContainer( | 281 tiles_container_(new StartPageTilesContainer( | 
| 264 app_list_main_view->contents_view(), | 282 app_list_main_view->contents_view(), | 
| 265 new AllAppsTileItemView(app_list_main_view_->contents_view()), | 283 new AllAppsTileItemView(app_list_main_view_->contents_view(), | 
| 284 app_list_view), | |
| 266 view_delegate)) { | 285 view_delegate)) { | 
| 267 search_box_spacer_view_->SetPreferredSize(gfx::Size( | 286 search_box_spacer_view_->SetPreferredSize(gfx::Size( | 
| 268 kStartPageSearchBoxWidth, | 287 kStartPageSearchBoxWidth, | 
| 269 app_list_main_view->search_box_view()->GetPreferredSize().height())); | 288 app_list_main_view->search_box_view()->GetPreferredSize().height())); | 
| 270 | 289 | 
| 271 // The view containing the start page WebContents and SearchBoxSpacerView. | 290 // The view containing the start page WebContents and SearchBoxSpacerView. | 
| 272 InitInstantContainer(); | 291 InitInstantContainer(); | 
| 273 AddChildView(instant_container_); | 292 AddChildView(instant_container_); | 
| 274 | 293 | 
| 275 // The view containing the start page tiles. | 294 // The view containing the start page tiles. | 
| 276 AddChildView(tiles_container_); | 295 AddChildView(tiles_container_); | 
| 277 | |
| 278 AddChildView(custom_launcher_page_background_); | 296 AddChildView(custom_launcher_page_background_); | 
| 279 | 297 | 
| 280 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 298 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 
| 281 } | 299 } | 
| 282 | 300 | 
| 283 StartPageView::~StartPageView() { | 301 StartPageView::~StartPageView() { | 
| 284 } | 302 } | 
| 285 | 303 | 
| 286 void StartPageView::InitInstantContainer() { | 304 void StartPageView::InitInstantContainer() { | 
| 287 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 305 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 
| 288 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 306 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 
| 289 instant_layout_manager->set_inside_border_insets( | 307 instant_layout_manager->set_inside_border_insets( | 
| 290 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 308 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 
| 291 instant_layout_manager->set_main_axis_alignment( | 309 instant_layout_manager->set_main_axis_alignment( | 
| 292 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 310 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 
| 293 instant_layout_manager->set_cross_axis_alignment( | 311 instant_layout_manager->set_cross_axis_alignment( | 
| 294 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 312 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 
| 295 instant_container_->SetLayoutManager(instant_layout_manager); | 313 instant_container_->SetLayoutManager(instant_layout_manager); | 
| 296 | 314 | 
| 297 views::View* web_view = view_delegate_->CreateStartPageWebView( | 315 // Create the view for the Google Doodle if the fullscreen launcher is not | 
| 298 gfx::Size(kWebViewWidth, kWebViewHeight)); | 316 // enabled. | 
| 299 if (web_view) { | 317 if (!features::IsFullscreenAppListEnabled()) { | 
| 300 web_view->SetFocusBehavior(FocusBehavior::NEVER); | 318 views::View* web_view = view_delegate_->CreateStartPageWebView( | 
| 301 instant_container_->AddChildView(web_view); | 319 gfx::Size(kWebViewWidth, kWebViewHeight)); | 
| 320 | |
| 321 if (web_view) { | |
| 322 web_view->SetFocusBehavior(FocusBehavior::NEVER); | |
| 323 instant_container_->AddChildView(web_view); | |
| 324 } | |
| 302 } | 325 } | 
| 303 | 326 | 
| 304 instant_container_->AddChildView(search_box_spacer_view_); | 327 instant_container_->AddChildView(search_box_spacer_view_); | 
| 305 } | 328 } | 
| 306 | 329 | 
| 307 void StartPageView::MaybeOpenCustomLauncherPage() { | 330 void StartPageView::MaybeOpenCustomLauncherPage() { | 
| 308 // Switch to the custom page. | 331 // Switch to the custom page. | 
| 309 ContentsView* contents_view = app_list_main_view_->contents_view(); | 332 ContentsView* contents_view = app_list_main_view_->contents_view(); | 
| 310 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) | 333 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) | 
| 311 return; | 334 return; | 
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // is enabled). | 533 // is enabled). | 
| 511 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 534 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 
| 512 MaybeOpenCustomLauncherPage(); | 535 MaybeOpenCustomLauncherPage(); | 
| 513 } | 536 } | 
| 514 | 537 | 
| 515 TileItemView* StartPageView::GetTileItemView(size_t index) { | 538 TileItemView* StartPageView::GetTileItemView(size_t index) { | 
| 516 return tiles_container_->GetTileItemView(index); | 539 return tiles_container_->GetTileItemView(index); | 
| 517 } | 540 } | 
| 518 | 541 | 
| 519 } // namespace app_list | 542 } // namespace app_list | 
| OLD | NEW |