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