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" | 
| 28 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" | 
| 29 #include "ui/views/background.h" | 31 #include "ui/views/background.h" | 
| 30 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" | 
| 31 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" | 
| 32 #include "ui/views/controls/textfield/textfield.h" | 34 #include "ui/views/controls/textfield/textfield.h" | 
| 33 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" | 
| 34 #include "ui/views/layout/grid_layout.h" | 36 #include "ui/views/layout/grid_layout.h" | 
| 35 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" | 
| 36 | 38 | 
| 37 namespace app_list { | 39 namespace app_list { | 
| 38 | 40 | 
| 39 namespace { | 41 namespace { | 
| 40 | 42 | 
| 41 // Layout constants. | 43 // Layout constants. | 
| 42 constexpr int kInstantContainerSpacing = 24; | 44 constexpr int kInstantContainerSpacing = 24; | 
| 43 constexpr int kSearchBoxAndTilesSpacing = 35; | 45 constexpr int kSearchBoxAndTilesSpacing = 35; | 
| 44 constexpr int kStartPageSearchBoxWidth = 480; | 46 constexpr int kStartPageSearchBoxWidth = 480; | 
| 47 constexpr int kStartPageSearchBoxWidthFullscreen = 544; | |
| 45 | 48 | 
| 46 // WebView constants. | 49 // WebView constants. | 
| 47 constexpr int kWebViewWidth = 700; | 50 constexpr int kWebViewWidth = 700; | 
| 48 constexpr int kWebViewHeight = 224; | 51 constexpr int kWebViewHeight = 224; | 
| 49 | 52 | 
| 50 // Tile container constants. | 53 // Tile container constants. | 
| 51 constexpr int kTileSpacing = 7; | 54 constexpr int kTileSpacing = 7; | 
| 52 constexpr int kNumStartPageTilesCols = 5; | 55 constexpr int kNumStartPageTilesCols = 5; | 
| 53 constexpr int kTilesHorizontalMarginLeft = 145; | 56 constexpr int kTilesHorizontalMarginLeft = 145; | 
| 57 constexpr int kCenterColumnOfStartPageAppGrid = 3; | |
| 
 
vadimt
2017/05/26 01:27:57
Can it be calculated from other constants?
Then yo
 
newcomer
2017/05/26 17:11:28
I would have to divide by 2 (which I would need a
 
 | |
| 54 | 58 | 
| 55 constexpr int kLauncherPageBackgroundWidth = 400; | 59 constexpr int kLauncherPageBackgroundWidth = 400; | 
| 56 | 60 | 
| 61 // An invisible placeholder view which fills the space for the search box view | |
| 62 // in a box layout. The search box view itself is a child of the AppListView | |
| 63 // (because it is visible on many different pages). | |
| 64 class SearchBoxSpacerView : public views::View { | |
| 65 public: | |
| 66 explicit SearchBoxSpacerView(const gfx::Size& search_box_size) | |
| 67 : size_(features::IsFullscreenAppListEnabled() | |
| 68 ? kStartPageSearchBoxWidthFullscreen | |
| 69 : kStartPageSearchBoxWidth, | |
| 70 search_box_size.height()) {} | |
| 71 | |
| 72 ~SearchBoxSpacerView() override {} | |
| 73 | |
| 74 // Overridden from views::View: | |
| 75 gfx::Size GetPreferredSize() const override { return size_; } | |
| 76 | |
| 77 private: | |
| 78 gfx::Size size_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(SearchBoxSpacerView); | |
| 81 }; | |
| 82 | |
| 57 } // namespace | 83 } // namespace | 
| 58 | 84 | 
| 59 class CustomLauncherPageBackgroundView : public views::View { | 85 class CustomLauncherPageBackgroundView : public views::View { | 
| 60 public: | 86 public: | 
| 61 explicit CustomLauncherPageBackgroundView( | 87 explicit CustomLauncherPageBackgroundView( | 
| 62 const std::string& custom_launcher_page_name) | 88 const std::string& custom_launcher_page_name) | 
| 63 : selected_(false), | 89 : selected_(false), | 
| 64 custom_launcher_page_name_(custom_launcher_page_name) { | 90 custom_launcher_page_name_(custom_launcher_page_name) { | 
| 65 set_background(views::Background::CreateSolidBackground(kSelectedColor)); | 91 set_background(views::Background::CreateSolidBackground(kSelectedColor)); | 
| 66 } | 92 } | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 ContentsView* contents_view, | 156 ContentsView* contents_view, | 
| 131 AllAppsTileItemView* all_apps_button, | 157 AllAppsTileItemView* all_apps_button, | 
| 132 AppListViewDelegate* view_delegate) | 158 AppListViewDelegate* view_delegate) | 
| 133 : contents_view_(contents_view), | 159 : contents_view_(contents_view), | 
| 134 view_delegate_(view_delegate), | 160 view_delegate_(view_delegate), | 
| 135 all_apps_button_(all_apps_button) { | 161 all_apps_button_(all_apps_button) { | 
| 136 set_background( | 162 set_background( | 
| 137 views::Background::CreateSolidBackground(kLabelBackgroundColor)); | 163 views::Background::CreateSolidBackground(kLabelBackgroundColor)); | 
| 138 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 164 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 
| 139 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); | 165 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); | 
| 140 CreateAppsGrid(kNumStartPageTiles); | 166 | 
| 167 CreateAppsGrid(features::IsFullscreenAppListEnabled() | |
| 168 ? fullscreen_constants::kNumStartPageTiles | |
| 169 : kNumStartPageTiles); | |
| 141 } | 170 } | 
| 142 | 171 | 
| 143 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { | 172 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { | 
| 144 } | 173 } | 
| 145 | 174 | 
| 146 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 175 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 
| 147 int index) { | 176 int index) { | 
| 148 DCHECK_GT(num_results(), index); | 177 DCHECK_GT(num_results(), index); | 
| 149 if (index == num_results() - 1) | 178 if (index == num_results() - 1) | 
| 150 return all_apps_button_; | 179 return all_apps_button_; | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 164 | 193 | 
| 165 std::vector<SearchResult*> display_results = | 194 std::vector<SearchResult*> display_results = | 
| 166 AppListModel::FilterSearchResultsByDisplayType( | 195 AppListModel::FilterSearchResultsByDisplayType( | 
| 167 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 196 results(), SearchResult::DISPLAY_RECOMMENDATION, kNumStartPageTiles); | 
| 168 if (display_results.size() != search_result_tile_views_.size()) { | 197 if (display_results.size() != search_result_tile_views_.size()) { | 
| 169 // We should recreate the grid layout in this case. | 198 // We should recreate the grid layout in this case. | 
| 170 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | 199 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) | 
| 171 delete search_result_tile_views_[i]; | 200 delete search_result_tile_views_[i]; | 
| 172 search_result_tile_views_.clear(); | 201 search_result_tile_views_.clear(); | 
| 173 RemoveChildView(all_apps_button_); | 202 RemoveChildView(all_apps_button_); | 
| 174 CreateAppsGrid(std::min(kNumStartPageTiles, display_results.size())); | 203 | 
| 204 CreateAppsGrid( | |
| 205 features::IsFullscreenAppListEnabled() | |
| 206 ? fullscreen_constants::kNumStartPageTiles | |
| 207 : std::min<int>(kNumStartPageTiles, display_results.size())); | |
| 175 } | 208 } | 
| 176 | 209 | 
| 177 // Update the tile item results. | 210 // Update the tile item results. | 
| 178 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 211 for (size_t i = 0; i < search_result_tile_views_.size(); ++i) { | 
| 179 SearchResult* item = nullptr; | 212 SearchResult* item = nullptr; | 
| 180 if (i < display_results.size()) | 213 if (i < display_results.size()) | 
| 181 item = display_results[i]; | 214 item = display_results[i]; | 
| 182 search_result_tile_views_[i]->SetSearchResult(item); | 215 search_result_tile_views_[i]->SetSearchResult(item); | 
| 183 search_result_tile_views_[i]->SetEnabled(true); | 216 search_result_tile_views_[i]->SetEnabled(true); | 
| 184 } | 217 } | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 for (int col = 0; col < kNumStartPageTilesCols; ++col) { | 257 for (int col = 0; col < kNumStartPageTilesCols; ++col) { | 
| 225 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 258 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 
| 226 views::GridLayout::USE_PREF, 0, 0); | 259 views::GridLayout::USE_PREF, 0, 0); | 
| 227 column_set->AddPaddingColumn(0, kTileSpacing); | 260 column_set->AddPaddingColumn(0, kTileSpacing); | 
| 228 } | 261 } | 
| 229 | 262 | 
| 230 // Add SearchResultTileItemViews to the container. | 263 // Add SearchResultTileItemViews to the container. | 
| 231 int i = 0; | 264 int i = 0; | 
| 232 search_result_tile_views_.reserve(apps_num); | 265 search_result_tile_views_.reserve(apps_num); | 
| 233 for (; i < apps_num; ++i) { | 266 for (; i < apps_num; ++i) { | 
| 267 // if (features::IsFullscreenAppListEnabled() && i == 5) { | |
| 
 
vadimt
2017/05/26 01:27:57
Remove.
 
newcomer
2017/05/26 17:11:28
Done.
 
 | |
| 268 // break; | |
| 269 //} | |
| 234 SearchResultTileItemView* tile_item = | 270 SearchResultTileItemView* tile_item = | 
| 235 new SearchResultTileItemView(this, view_delegate_); | 271 new SearchResultTileItemView(this, view_delegate_); | 
| 236 if (i % kNumStartPageTilesCols == 0) | 272 if (i % kNumStartPageTilesCols == 0) | 
| 237 tiles_layout_manager->StartRow(0, 0); | 273 tiles_layout_manager->StartRow(0, 0); | 
| 238 tiles_layout_manager->AddView(tile_item); | 274 tiles_layout_manager->AddView(tile_item); | 
| 239 AddChildView(tile_item); | 275 AddChildView(tile_item); | 
| 240 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | 276 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | 
| 241 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 277 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 
| 242 search_result_tile_views_.emplace_back(tile_item); | 278 search_result_tile_views_.emplace_back(tile_item); | 
| 243 } | 279 } | 
| 244 | 280 | 
| 245 // Also add a special "all apps" button to the end of the container. | |
| 246 all_apps_button_->UpdateIcon(); | 281 all_apps_button_->UpdateIcon(); | 
| 247 if (i % kNumStartPageTilesCols == 0) | 282 if (features::IsFullscreenAppListEnabled()) { | 
| 283 // Also add a special "all apps" button to the middle of the next row of the | |
| 284 // container. | |
| 248 tiles_layout_manager->StartRow(0, 0); | 285 tiles_layout_manager->StartRow(0, 0); | 
| 286 tiles_layout_manager->SkipColumns(kCenterColumnOfStartPageAppGrid); | |
| 287 } else { | |
| 288 // Also add a special "all apps" button to the end of the next row of the | |
| 289 // container. | |
| 290 if (i % kNumStartPageTilesCols == 0) | |
| 291 tiles_layout_manager->StartRow(0, 0); | |
| 292 } | |
| 293 | |
| 249 tiles_layout_manager->AddView(all_apps_button_); | 294 tiles_layout_manager->AddView(all_apps_button_); | 
| 250 AddChildView(all_apps_button_); | 295 AddChildView(all_apps_button_); | 
| 251 } | 296 } | 
| 252 | 297 | 
| 253 //////////////////////////////////////////////////////////////////////////////// | 298 //////////////////////////////////////////////////////////////////////////////// | 
| 254 // StartPageView implementation: | 299 // StartPageView implementation: | 
| 255 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 300 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 
| 256 AppListViewDelegate* view_delegate) | 301 AppListViewDelegate* view_delegate, | 
| 302 AppListView* app_list_view) | |
| 257 : app_list_main_view_(app_list_main_view), | 303 : app_list_main_view_(app_list_main_view), | 
| 258 view_delegate_(view_delegate), | 304 view_delegate_(view_delegate), | 
| 259 search_box_spacer_view_(new View()), | 305 search_box_spacer_view_(new View()), | 
| 260 instant_container_(new views::View), | 306 instant_container_(new views::View), | 
| 261 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 307 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 
| 262 view_delegate_->GetModel()->custom_launcher_page_name())), | 308 view_delegate_->GetModel()->custom_launcher_page_name())), | 
| 263 tiles_container_(new StartPageTilesContainer( | 309 tiles_container_(new StartPageTilesContainer( | 
| 264 app_list_main_view->contents_view(), | 310 app_list_main_view->contents_view(), | 
| 265 new AllAppsTileItemView(app_list_main_view_->contents_view()), | 311 new AllAppsTileItemView(app_list_main_view_->contents_view(), | 
| 312 app_list_view), | |
| 266 view_delegate)) { | 313 view_delegate)) { | 
| 267 search_box_spacer_view_->SetPreferredSize(gfx::Size( | 314 search_box_spacer_view_->SetPreferredSize(gfx::Size( | 
| 268 kStartPageSearchBoxWidth, | 315 kStartPageSearchBoxWidth, | 
| 269 app_list_main_view->search_box_view()->GetPreferredSize().height())); | 316 app_list_main_view->search_box_view()->GetPreferredSize().height())); | 
| 270 | 317 | 
| 271 // The view containing the start page WebContents and SearchBoxSpacerView. | 318 // The view containing the start page WebContents and SearchBoxSpacerView. | 
| 272 InitInstantContainer(); | 319 InitInstantContainer(); | 
| 273 AddChildView(instant_container_); | 320 AddChildView(instant_container_); | 
| 274 | 321 | 
| 275 // The view containing the start page tiles. | 322 // The view containing the start page tiles. | 
| 276 AddChildView(tiles_container_); | 323 AddChildView(tiles_container_); | 
| 277 | |
| 278 AddChildView(custom_launcher_page_background_); | 324 AddChildView(custom_launcher_page_background_); | 
| 279 | 325 | 
| 280 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 326 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 
| 281 } | 327 } | 
| 282 | 328 | 
| 283 StartPageView::~StartPageView() { | 329 StartPageView::~StartPageView() { | 
| 284 } | 330 } | 
| 285 | 331 | 
| 286 void StartPageView::InitInstantContainer() { | 332 void StartPageView::InitInstantContainer() { | 
| 287 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 333 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 
| 288 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 334 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 
| 289 instant_layout_manager->set_inside_border_insets( | 335 instant_layout_manager->set_inside_border_insets( | 
| 290 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 336 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 
| 291 instant_layout_manager->set_main_axis_alignment( | 337 instant_layout_manager->set_main_axis_alignment( | 
| 292 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 338 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 
| 293 instant_layout_manager->set_cross_axis_alignment( | 339 instant_layout_manager->set_cross_axis_alignment( | 
| 294 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 340 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 
| 295 instant_container_->SetLayoutManager(instant_layout_manager); | 341 instant_container_->SetLayoutManager(instant_layout_manager); | 
| 296 | 342 | 
| 297 views::View* web_view = view_delegate_->CreateStartPageWebView( | 343 // Create the view for the Google Doodle if the fullscreen launcher is not | 
| 298 gfx::Size(kWebViewWidth, kWebViewHeight)); | 344 // enabled. | 
| 299 if (web_view) { | 345 if (!features::IsFullscreenAppListEnabled()) { | 
| 300 web_view->SetFocusBehavior(FocusBehavior::NEVER); | 346 views::View* web_view = view_delegate_->CreateStartPageWebView( | 
| 301 instant_container_->AddChildView(web_view); | 347 gfx::Size(kWebViewWidth, kWebViewHeight)); | 
| 348 | |
| 349 if (web_view) { | |
| 350 web_view->SetFocusBehavior(FocusBehavior::NEVER); | |
| 351 instant_container_->AddChildView(web_view); | |
| 352 } | |
| 302 } | 353 } | 
| 303 | 354 | 
| 304 instant_container_->AddChildView(search_box_spacer_view_); | 355 instant_container_->AddChildView(search_box_spacer_view_); | 
| 305 } | 356 } | 
| 306 | 357 | 
| 307 void StartPageView::MaybeOpenCustomLauncherPage() { | 358 void StartPageView::MaybeOpenCustomLauncherPage() { | 
| 308 // Switch to the custom page. | 359 // Switch to the custom page. | 
| 309 ContentsView* contents_view = app_list_main_view_->contents_view(); | 360 ContentsView* contents_view = app_list_main_view_->contents_view(); | 
| 310 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) | 361 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) | 
| 311 return; | 362 return; | 
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // is enabled). | 561 // is enabled). | 
| 511 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 562 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 
| 512 MaybeOpenCustomLauncherPage(); | 563 MaybeOpenCustomLauncherPage(); | 
| 513 } | 564 } | 
| 514 | 565 | 
| 515 TileItemView* StartPageView::GetTileItemView(size_t index) { | 566 TileItemView* StartPageView::GetTileItemView(size_t index) { | 
| 516 return tiles_container_->GetTileItemView(index); | 567 return tiles_container_->GetTileItemView(index); | 
| 517 } | 568 } | 
| 518 | 569 | 
| 519 } // namespace app_list | 570 } // namespace app_list | 
| OLD | NEW |