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 int kStartPageSearchBoxWidth = 480; |
|
vadimt
2017/05/22 23:36:58
constexpr?
newcomer
2017/05/25 23:10:53
Done.
| |
| 45 | 47 int kStartPageSearchBoxWidthFullscreen = 544; |
| 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; |
| 54 | 56 |
| 55 constexpr int kLauncherPageBackgroundWidth = 400; | 57 constexpr int kLauncherPageBackgroundWidth = 400; |
| 56 | 58 |
| 57 // An invisible placeholder view which fills the space for the search box view | 59 // An invisible placeholder view which fills the space for the search box view |
| 58 // in a box layout. The search box view itself is a child of the AppListView | 60 // in a box layout. The search box view itself is a child of the AppListView |
| 59 // (because it is visible on many different pages). | 61 // (because it is visible on many different pages). |
| 60 class SearchBoxSpacerView : public views::View { | 62 class SearchBoxSpacerView : public views::View { |
| 61 public: | 63 public: |
| 62 explicit SearchBoxSpacerView(const gfx::Size& search_box_size) | 64 explicit SearchBoxSpacerView(const gfx::Size& search_box_size) |
| 63 : size_(kStartPageSearchBoxWidth, search_box_size.height()) {} | 65 : size_(features::IsFullscreenAppListEnabled() |
| 66 ? kStartPageSearchBoxWidthFullscreen | |
| 67 : kStartPageSearchBoxWidth, | |
| 68 search_box_size.height()) {} | |
| 64 | 69 |
| 65 ~SearchBoxSpacerView() override {} | 70 ~SearchBoxSpacerView() override {} |
| 66 | 71 |
| 67 // Overridden from views::View: | 72 // Overridden from views::View: |
| 68 gfx::Size GetPreferredSize() const override { return size_; } | 73 gfx::Size GetPreferredSize() const override { return size_; } |
| 69 | 74 |
| 70 private: | 75 private: |
| 71 gfx::Size size_; | 76 gfx::Size size_; |
| 72 | 77 |
| 73 DISALLOW_COPY_AND_ASSIGN(SearchBoxSpacerView); | 78 DISALLOW_COPY_AND_ASSIGN(SearchBoxSpacerView); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 ContentsView* contents_view, | 154 ContentsView* contents_view, |
| 150 AllAppsTileItemView* all_apps_button, | 155 AllAppsTileItemView* all_apps_button, |
| 151 AppListViewDelegate* view_delegate) | 156 AppListViewDelegate* view_delegate) |
| 152 : contents_view_(contents_view), | 157 : contents_view_(contents_view), |
| 153 view_delegate_(view_delegate), | 158 view_delegate_(view_delegate), |
| 154 all_apps_button_(all_apps_button) { | 159 all_apps_button_(all_apps_button) { |
| 155 set_background( | 160 set_background( |
| 156 views::Background::CreateSolidBackground(kLabelBackgroundColor)); | 161 views::Background::CreateSolidBackground(kLabelBackgroundColor)); |
| 157 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 162 all_apps_button_->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); |
| 158 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); | 163 all_apps_button_->SetParentBackgroundColor(kLabelBackgroundColor); |
| 159 CreateAppsGrid(kNumStartPageTiles); | 164 if (features::IsFullscreenAppListEnabled()) |
|
vadimt
2017/05/22 23:36:58
Move condition into param calculation as a ternary
newcomer
2017/05/25 23:10:53
Done.
| |
| 165 CreateAppsGrid(fullscreen_constants::kNumStartPageTiles); | |
| 166 else | |
| 167 CreateAppsGrid(kNumStartPageTiles); | |
| 160 } | 168 } |
| 161 | 169 |
| 162 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { | 170 StartPageView::StartPageTilesContainer::~StartPageTilesContainer() { |
| 163 } | 171 } |
| 164 | 172 |
| 165 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( | 173 TileItemView* StartPageView::StartPageTilesContainer::GetTileItemView( |
| 166 int index) { | 174 int index) { |
| 167 DCHECK_GT(num_results(), index); | 175 DCHECK_GT(num_results(), index); |
| 168 if (index == num_results() - 1) | 176 if (index == num_results() - 1) |
| 169 return all_apps_button_; | 177 return all_apps_button_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 for (int col = 0; col < kNumStartPageTilesCols; ++col) { | 251 for (int col = 0; col < kNumStartPageTilesCols; ++col) { |
| 244 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 252 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 245 views::GridLayout::USE_PREF, 0, 0); | 253 views::GridLayout::USE_PREF, 0, 0); |
| 246 column_set->AddPaddingColumn(0, kTileSpacing); | 254 column_set->AddPaddingColumn(0, kTileSpacing); |
| 247 } | 255 } |
| 248 | 256 |
| 249 // Add SearchResultTileItemViews to the container. | 257 // Add SearchResultTileItemViews to the container. |
| 250 int i = 0; | 258 int i = 0; |
| 251 search_result_tile_views_.reserve(apps_num); | 259 search_result_tile_views_.reserve(apps_num); |
| 252 for (; i < apps_num; ++i) { | 260 for (; i < apps_num; ++i) { |
| 261 if (features::IsFullscreenAppListEnabled() && i == 5) { | |
|
vadimt
2017/05/22 23:36:58
Const for 5.
xiyuan
2017/05/24 18:28:18
Make |apps_num| 5 somehow (either here or at call
newcomer
2017/05/25 23:10:53
Done! I think I left this in by accident while exp
newcomer
2017/05/25 23:10:53
Done.
| |
| 262 break; | |
| 263 } | |
| 253 SearchResultTileItemView* tile_item = | 264 SearchResultTileItemView* tile_item = |
| 254 new SearchResultTileItemView(this, view_delegate_); | 265 new SearchResultTileItemView(this, view_delegate_); |
| 255 if (i % kNumStartPageTilesCols == 0) | 266 if (i % kNumStartPageTilesCols == 0) |
| 256 tiles_layout_manager->StartRow(0, 0); | 267 tiles_layout_manager->StartRow(0, 0); |
| 257 tiles_layout_manager->AddView(tile_item); | 268 tiles_layout_manager->AddView(tile_item); |
| 258 AddChildView(tile_item); | 269 AddChildView(tile_item); |
| 259 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | 270 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); |
| 260 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 271 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); |
| 261 search_result_tile_views_.emplace_back(tile_item); | 272 search_result_tile_views_.emplace_back(tile_item); |
| 262 } | 273 } |
| 263 | 274 |
| 264 // Also add a special "all apps" button to the end of the container. | |
| 265 all_apps_button_->UpdateIcon(); | 275 all_apps_button_->UpdateIcon(); |
| 266 if (i % kNumStartPageTilesCols == 0) | 276 if (features::IsFullscreenAppListEnabled()) { |
| 277 // Also add a special "all apps" button to the middle of the next row of the | |
| 278 // container. | |
| 267 tiles_layout_manager->StartRow(0, 0); | 279 tiles_layout_manager->StartRow(0, 0); |
| 280 tiles_layout_manager->SkipColumns(3); | |
|
vadimt
2017/05/22 23:36:58
... and 3
newcomer
2017/05/25 23:10:53
Done.
| |
| 281 } else { | |
| 282 // Also add a special "all apps" button to the end of the next row of the | |
| 283 // container. | |
| 284 if (i % kNumStartPageTilesCols == 0) | |
| 285 tiles_layout_manager->StartRow(0, 0); | |
| 286 } | |
| 287 | |
| 268 tiles_layout_manager->AddView(all_apps_button_); | 288 tiles_layout_manager->AddView(all_apps_button_); |
| 269 AddChildView(all_apps_button_); | 289 AddChildView(all_apps_button_); |
| 270 } | 290 } |
| 271 | 291 |
| 272 //////////////////////////////////////////////////////////////////////////////// | 292 //////////////////////////////////////////////////////////////////////////////// |
| 273 // StartPageView implementation: | 293 // StartPageView implementation: |
| 274 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 294 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
| 275 AppListViewDelegate* view_delegate) | 295 AppListViewDelegate* view_delegate) |
| 276 : app_list_main_view_(app_list_main_view), | 296 : app_list_main_view_(app_list_main_view), |
| 277 view_delegate_(view_delegate), | 297 view_delegate_(view_delegate), |
| 278 search_box_spacer_view_(new SearchBoxSpacerView( | 298 search_box_spacer_view_(new SearchBoxSpacerView( |
| 279 app_list_main_view->search_box_view()->GetPreferredSize())), | 299 app_list_main_view->search_box_view()->GetPreferredSize())), |
| 280 instant_container_(new views::View), | 300 instant_container_(new views::View), |
| 281 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 301 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( |
| 282 view_delegate_->GetModel()->custom_launcher_page_name())), | 302 view_delegate_->GetModel()->custom_launcher_page_name())), |
| 283 tiles_container_(new StartPageTilesContainer( | 303 tiles_container_(new StartPageTilesContainer( |
| 284 app_list_main_view->contents_view(), | 304 app_list_main_view->contents_view(), |
| 285 new AllAppsTileItemView(app_list_main_view_->contents_view()), | 305 new AllAppsTileItemView(app_list_main_view_->contents_view()), |
| 286 view_delegate)) { | 306 view_delegate)) { |
| 287 // The view containing the start page WebContents and SearchBoxSpacerView. | 307 // The view containing the start page WebContents and SearchBoxSpacerView. |
| 288 InitInstantContainer(); | 308 InitInstantContainer(); |
| 289 AddChildView(instant_container_); | 309 AddChildView(instant_container_); |
| 290 | 310 |
| 291 // The view containing the start page tiles. | 311 // The view containing the start page tiles. |
| 292 AddChildView(tiles_container_); | 312 AddChildView(tiles_container_); |
| 293 | |
| 294 AddChildView(custom_launcher_page_background_); | 313 AddChildView(custom_launcher_page_background_); |
| 295 | 314 |
| 296 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 315 tiles_container_->SetResults(view_delegate_->GetModel()->results()); |
| 297 } | 316 } |
| 298 | 317 |
| 299 StartPageView::~StartPageView() { | 318 StartPageView::~StartPageView() { |
| 300 } | 319 } |
| 301 | 320 |
| 302 void StartPageView::InitInstantContainer() { | 321 void StartPageView::InitInstantContainer() { |
| 303 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 322 views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
| 304 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 323 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); |
| 305 instant_layout_manager->set_inside_border_insets( | 324 instant_layout_manager->set_inside_border_insets( |
| 306 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 325 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); |
| 307 instant_layout_manager->set_main_axis_alignment( | 326 instant_layout_manager->set_main_axis_alignment( |
| 308 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 327 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
| 309 instant_layout_manager->set_cross_axis_alignment( | 328 instant_layout_manager->set_cross_axis_alignment( |
| 310 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 329 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 311 instant_container_->SetLayoutManager(instant_layout_manager); | 330 instant_container_->SetLayoutManager(instant_layout_manager); |
| 312 | 331 |
| 313 views::View* web_view = view_delegate_->CreateStartPageWebView( | 332 // Create the view for the Google Doodle if the fullscreen launcher is not |
| 314 gfx::Size(kWebViewWidth, kWebViewHeight)); | 333 // enabled. |
| 315 if (web_view) { | 334 if (!features::IsFullscreenAppListEnabled()) { |
| 316 web_view->SetFocusBehavior(FocusBehavior::NEVER); | 335 views::View* web_view = view_delegate_->CreateStartPageWebView( |
| 317 instant_container_->AddChildView(web_view); | 336 gfx::Size(kWebViewWidth, kWebViewHeight)); |
| 337 | |
| 338 if (web_view) { | |
| 339 web_view->SetFocusBehavior(FocusBehavior::NEVER); | |
| 340 instant_container_->AddChildView(web_view); | |
| 341 } | |
| 318 } | 342 } |
| 319 | 343 |
| 320 instant_container_->AddChildView(search_box_spacer_view_); | 344 instant_container_->AddChildView(search_box_spacer_view_); |
| 321 } | 345 } |
| 322 | 346 |
| 323 void StartPageView::MaybeOpenCustomLauncherPage() { | 347 void StartPageView::MaybeOpenCustomLauncherPage() { |
| 324 // Switch to the custom page. | 348 // Switch to the custom page. |
| 325 ContentsView* contents_view = app_list_main_view_->contents_view(); | 349 ContentsView* contents_view = app_list_main_view_->contents_view(); |
| 326 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) | 350 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) |
| 327 return; | 351 return; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 // is enabled). | 550 // is enabled). |
| 527 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 551 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
| 528 MaybeOpenCustomLauncherPage(); | 552 MaybeOpenCustomLauncherPage(); |
| 529 } | 553 } |
| 530 | 554 |
| 531 TileItemView* StartPageView::GetTileItemView(size_t index) { | 555 TileItemView* StartPageView::GetTileItemView(size_t index) { |
| 532 return tiles_container_->GetTileItemView(index); | 556 return tiles_container_->GetTileItemView(index); |
| 533 } | 557 } |
| 534 | 558 |
| 535 } // namespace app_list | 559 } // namespace app_list |
| OLD | NEW |