| 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; |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 new SearchResultTileItemView(this, view_delegate_); | 268 new SearchResultTileItemView(this, view_delegate_); |
| 236 if (i % kNumStartPageTilesCols == 0) | 269 if (i % kNumStartPageTilesCols == 0) |
| 237 tiles_layout_manager->StartRow(0, 0); | 270 tiles_layout_manager->StartRow(0, 0); |
| 238 tiles_layout_manager->AddView(tile_item); | 271 tiles_layout_manager->AddView(tile_item); |
| 239 AddChildView(tile_item); | 272 AddChildView(tile_item); |
| 240 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); | 273 tile_item->SetParentBackgroundColor(kLabelBackgroundColor); |
| 241 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); | 274 tile_item->SetHoverStyle(TileItemView::HOVER_STYLE_ANIMATE_SHADOW); |
| 242 search_result_tile_views_.emplace_back(tile_item); | 275 search_result_tile_views_.emplace_back(tile_item); |
| 243 } | 276 } |
| 244 | 277 |
| 245 // Also add a special "all apps" button to the end of the container. | |
| 246 all_apps_button_->UpdateIcon(); | 278 all_apps_button_->UpdateIcon(); |
| 247 if (i % kNumStartPageTilesCols == 0) | 279 if (features::IsFullscreenAppListEnabled()) { |
| 280 // Also add a special "all apps" button to the middle of the next row of the |
| 281 // container. |
| 248 tiles_layout_manager->StartRow(0, 0); | 282 tiles_layout_manager->StartRow(0, 0); |
| 283 tiles_layout_manager->SkipColumns(kCenterColumnOfStartPageAppGrid); |
| 284 } else { |
| 285 // Also add a special "all apps" button to the end of the next row of the |
| 286 // container. |
| 287 if (i % kNumStartPageTilesCols == 0) |
| 288 tiles_layout_manager->StartRow(0, 0); |
| 289 } |
| 290 |
| 249 tiles_layout_manager->AddView(all_apps_button_); | 291 tiles_layout_manager->AddView(all_apps_button_); |
| 250 AddChildView(all_apps_button_); | 292 AddChildView(all_apps_button_); |
| 251 } | 293 } |
| 252 | 294 |
| 253 //////////////////////////////////////////////////////////////////////////////// | 295 //////////////////////////////////////////////////////////////////////////////// |
| 254 // StartPageView implementation: | 296 // StartPageView implementation: |
| 255 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 297 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
| 256 AppListViewDelegate* view_delegate) | 298 AppListViewDelegate* view_delegate, |
| 299 AppListView* app_list_view) |
| 257 : app_list_main_view_(app_list_main_view), | 300 : app_list_main_view_(app_list_main_view), |
| 258 view_delegate_(view_delegate), | 301 view_delegate_(view_delegate), |
| 259 search_box_spacer_view_(new View()), | 302 search_box_spacer_view_(new View()), |
| 260 instant_container_(new views::View), | 303 instant_container_(new views::View), |
| 261 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 304 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( |
| 262 view_delegate_->GetModel()->custom_launcher_page_name())), | 305 view_delegate_->GetModel()->custom_launcher_page_name())), |
| 263 tiles_container_(new StartPageTilesContainer( | 306 tiles_container_(new StartPageTilesContainer( |
| 264 app_list_main_view->contents_view(), | 307 app_list_main_view->contents_view(), |
| 265 new AllAppsTileItemView(app_list_main_view_->contents_view()), | 308 new AllAppsTileItemView(app_list_main_view_->contents_view(), |
| 309 app_list_view), |
| 266 view_delegate)) { | 310 view_delegate)) { |
| 267 search_box_spacer_view_->SetPreferredSize(gfx::Size( | 311 search_box_spacer_view_->SetPreferredSize(gfx::Size( |
| 268 kStartPageSearchBoxWidth, | 312 kStartPageSearchBoxWidth, |
| 269 app_list_main_view->search_box_view()->GetPreferredSize().height())); | 313 app_list_main_view->search_box_view()->GetPreferredSize().height())); |
| 270 | 314 |
| 271 // The view containing the start page WebContents and SearchBoxSpacerView. | 315 // The view containing the start page WebContents and SearchBoxSpacerView. |
| 272 InitInstantContainer(); | 316 InitInstantContainer(); |
| 273 AddChildView(instant_container_); | 317 AddChildView(instant_container_); |
| 274 | 318 |
| 275 // The view containing the start page tiles. | 319 // The view containing the start page tiles. |
| 276 AddChildView(tiles_container_); | 320 AddChildView(tiles_container_); |
| 277 | |
| 278 AddChildView(custom_launcher_page_background_); | 321 AddChildView(custom_launcher_page_background_); |
| 279 | 322 |
| 280 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 323 tiles_container_->SetResults(view_delegate_->GetModel()->results()); |
| 281 } | 324 } |
| 282 | 325 |
| 283 StartPageView::~StartPageView() { | 326 StartPageView::~StartPageView() { |
| 284 } | 327 } |
| 285 | 328 |
| 286 void StartPageView::InitInstantContainer() { | 329 void StartPageView::InitInstantContainer() { |
| 287 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 330 views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
| 288 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 331 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); |
| 289 instant_layout_manager->set_inside_border_insets( | 332 instant_layout_manager->set_inside_border_insets( |
| 290 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 333 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); |
| 291 instant_layout_manager->set_main_axis_alignment( | 334 instant_layout_manager->set_main_axis_alignment( |
| 292 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 335 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
| 293 instant_layout_manager->set_cross_axis_alignment( | 336 instant_layout_manager->set_cross_axis_alignment( |
| 294 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 337 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 295 instant_container_->SetLayoutManager(instant_layout_manager); | 338 instant_container_->SetLayoutManager(instant_layout_manager); |
| 296 | 339 |
| 297 views::View* web_view = view_delegate_->CreateStartPageWebView( | 340 // Create the view for the Google Doodle if the fullscreen launcher is not |
| 298 gfx::Size(kWebViewWidth, kWebViewHeight)); | 341 // enabled. |
| 299 if (web_view) { | 342 if (!features::IsFullscreenAppListEnabled()) { |
| 300 web_view->SetFocusBehavior(FocusBehavior::NEVER); | 343 views::View* web_view = view_delegate_->CreateStartPageWebView( |
| 301 instant_container_->AddChildView(web_view); | 344 gfx::Size(kWebViewWidth, kWebViewHeight)); |
| 345 |
| 346 if (web_view) { |
| 347 web_view->SetFocusBehavior(FocusBehavior::NEVER); |
| 348 instant_container_->AddChildView(web_view); |
| 349 } |
| 302 } | 350 } |
| 303 | 351 |
| 304 instant_container_->AddChildView(search_box_spacer_view_); | 352 instant_container_->AddChildView(search_box_spacer_view_); |
| 305 } | 353 } |
| 306 | 354 |
| 307 void StartPageView::MaybeOpenCustomLauncherPage() { | 355 void StartPageView::MaybeOpenCustomLauncherPage() { |
| 308 // Switch to the custom page. | 356 // Switch to the custom page. |
| 309 ContentsView* contents_view = app_list_main_view_->contents_view(); | 357 ContentsView* contents_view = app_list_main_view_->contents_view(); |
| 310 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) | 358 if (!app_list_main_view_->ShouldShowCustomLauncherPage()) |
| 311 return; | 359 return; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 // is enabled). | 558 // is enabled). |
| 511 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 559 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
| 512 MaybeOpenCustomLauncherPage(); | 560 MaybeOpenCustomLauncherPage(); |
| 513 } | 561 } |
| 514 | 562 |
| 515 TileItemView* StartPageView::GetTileItemView(size_t index) { | 563 TileItemView* StartPageView::GetTileItemView(size_t index) { |
| 516 return tiles_container_->GetTileItemView(index); | 564 return tiles_container_->GetTileItemView(index); |
| 517 } | 565 } |
| 518 | 566 |
| 519 } // namespace app_list | 567 } // namespace app_list |
| OLD | NEW |