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_features.h" |
17 #include "ui/app_list/app_list_item.h" | 17 #include "ui/app_list/app_list_item.h" |
18 #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" | 19 #include "ui/app_list/app_list_switches.h" |
20 #include "ui/app_list/app_list_view_delegate.h" | 20 #include "ui/app_list/app_list_view_delegate.h" |
21 #include "ui/app_list/search_result.h" | 21 #include "ui/app_list/search_result.h" |
22 #include "ui/app_list/views/all_apps_tile_item_view.h" | 22 #include "ui/app_list/views/all_apps_tile_item_view.h" |
23 #include "ui/app_list/views/app_list_main_view.h" | 23 #include "ui/app_list/views/app_list_main_view.h" |
24 #include "ui/app_list/views/contents_view.h" | 24 #include "ui/app_list/views/contents_view.h" |
25 #include "ui/app_list/views/custom_launcher_page_view.h" | 25 #include "ui/app_list/views/custom_launcher_page_view.h" |
26 #include "ui/app_list/views/indicator_chip_view.h" | |
26 #include "ui/app_list/views/search_box_view.h" | 27 #include "ui/app_list/views/search_box_view.h" |
27 #include "ui/app_list/views/search_result_container_view.h" | 28 #include "ui/app_list/views/search_result_container_view.h" |
28 #include "ui/app_list/views/search_result_tile_item_view.h" | 29 #include "ui/app_list/views/search_result_tile_item_view.h" |
29 #include "ui/app_list/views/tile_item_view.h" | 30 #include "ui/app_list/views/tile_item_view.h" |
31 #include "ui/base/l10n/l10n_util.h" | |
30 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/geometry/insets.h" | 33 #include "ui/gfx/geometry/insets.h" |
34 #include "ui/strings/grit/ui_strings.h" | |
32 #include "ui/views/background.h" | 35 #include "ui/views/background.h" |
33 #include "ui/views/controls/image_view.h" | 36 #include "ui/views/controls/image_view.h" |
34 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
35 #include "ui/views/controls/textfield/textfield.h" | 38 #include "ui/views/controls/textfield/textfield.h" |
36 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
37 #include "ui/views/layout/grid_layout.h" | 40 #include "ui/views/layout/grid_layout.h" |
38 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
39 | 42 |
40 namespace app_list { | 43 namespace app_list { |
41 | 44 |
42 namespace { | 45 namespace { |
43 | 46 |
44 // Layout constants. | 47 // Layout constants. |
48 constexpr int kSearchBoxTopPadding = 24; | |
45 constexpr int kInstantContainerSpacing = 24; | 49 constexpr int kInstantContainerSpacing = 24; |
46 constexpr int kSearchBoxAndTilesSpacing = 35; | 50 constexpr int kSearchBoxAndTilesSpacing = 35; |
51 constexpr int kSearchBoxAndIndicatorSpacing = 21; | |
47 constexpr int kStartPageSearchBoxWidth = 480; | 52 constexpr int kStartPageSearchBoxWidth = 480; |
53 constexpr int kStartPageSearchBoxWidthFullscreen = 544; | |
48 | 54 |
49 // WebView constants. | 55 // WebView constants. |
50 constexpr int kWebViewWidth = 700; | 56 constexpr int kWebViewWidth = 700; |
51 constexpr int kWebViewHeight = 224; | 57 constexpr int kWebViewHeight = 224; |
52 | 58 |
53 // Tile container constants. | 59 // Tile container constants. |
54 constexpr int kTileSpacing = 7; | 60 constexpr int kTileSpacing = 7; |
55 constexpr int kNumStartPageTilesCols = 5; | 61 constexpr int kNumStartPageTilesCols = 5; |
56 constexpr int kTilesHorizontalMarginLeft = 145; | 62 constexpr int kTilesHorizontalMarginLeft = 145; |
57 constexpr int kCenterColumnOfStartPageAppGrid = 3; | 63 constexpr int kCenterColumnOfStartPageAppGrid = 3; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // StartPageView implementation: | 280 // StartPageView implementation: |
275 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 281 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
276 AppListViewDelegate* view_delegate, | 282 AppListViewDelegate* view_delegate, |
277 AppListView* app_list_view) | 283 AppListView* app_list_view) |
278 : app_list_main_view_(app_list_main_view), | 284 : app_list_main_view_(app_list_main_view), |
279 view_delegate_(view_delegate), | 285 view_delegate_(view_delegate), |
280 search_box_spacer_view_(new View()), | 286 search_box_spacer_view_(new View()), |
281 instant_container_(new views::View), | 287 instant_container_(new views::View), |
282 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( | 288 custom_launcher_page_background_(new CustomLauncherPageBackgroundView( |
283 view_delegate_->GetModel()->custom_launcher_page_name())), | 289 view_delegate_->GetModel()->custom_launcher_page_name())), |
290 indicator_(nullptr), | |
xiyuan
2017/06/22 22:33:52
nit: initialize in header
Qiang(Joe) Xu
2017/06/22 22:47:27
Done.
| |
284 tiles_container_(new StartPageTilesContainer( | 291 tiles_container_(new StartPageTilesContainer( |
285 app_list_main_view->contents_view(), | 292 app_list_main_view->contents_view(), |
286 new AllAppsTileItemView(app_list_main_view_->contents_view(), | 293 new AllAppsTileItemView(app_list_main_view_->contents_view(), |
287 app_list_view), | 294 app_list_view), |
288 view_delegate)) { | 295 view_delegate)), |
296 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { | |
289 search_box_spacer_view_->SetPreferredSize(gfx::Size( | 297 search_box_spacer_view_->SetPreferredSize(gfx::Size( |
290 kStartPageSearchBoxWidth, | 298 is_fullscreen_app_list_enabled_ ? kStartPageSearchBoxWidthFullscreen |
299 : kStartPageSearchBoxWidth, | |
291 app_list_main_view->search_box_view()->GetPreferredSize().height())); | 300 app_list_main_view->search_box_view()->GetPreferredSize().height())); |
292 | 301 |
293 // The view containing the start page WebContents and SearchBoxSpacerView. | 302 // The view containing the start page WebContents and SearchBoxSpacerView. |
294 InitInstantContainer(); | 303 InitInstantContainer(); |
295 AddChildView(instant_container_); | 304 AddChildView(instant_container_); |
296 | 305 |
306 if (is_fullscreen_app_list_enabled_) { | |
307 indicator_ = new IndicatorChipView( | |
308 l10n_util::GetStringUTF16(IDS_SUGGESTED_APPS_INDICATOR)); | |
309 AddChildView(indicator_); | |
310 } | |
311 | |
297 // The view containing the start page tiles. | 312 // The view containing the start page tiles. |
298 AddChildView(tiles_container_); | 313 AddChildView(tiles_container_); |
299 AddChildView(custom_launcher_page_background_); | 314 AddChildView(custom_launcher_page_background_); |
300 | 315 |
301 tiles_container_->SetResults(view_delegate_->GetModel()->results()); | 316 tiles_container_->SetResults(view_delegate_->GetModel()->results()); |
302 } | 317 } |
303 | 318 |
304 StartPageView::~StartPageView() { | 319 StartPageView::~StartPageView() = default; |
305 } | |
306 | 320 |
307 void StartPageView::InitInstantContainer() { | 321 void StartPageView::InitInstantContainer() { |
308 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 322 views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
309 views::BoxLayout::kVertical, gfx::Insets(), kInstantContainerSpacing); | 323 views::BoxLayout::kVertical, gfx::Insets(), kInstantContainerSpacing); |
310 instant_layout_manager->set_inside_border_insets( | 324 if (is_fullscreen_app_list_enabled_) { |
311 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | 325 instant_layout_manager->set_inside_border_insets( |
326 gfx::Insets(kSearchBoxTopPadding, 0, kSearchBoxAndIndicatorSpacing, 0)); | |
327 } else { | |
328 instant_layout_manager->set_inside_border_insets( | |
329 gfx::Insets(0, 0, kSearchBoxAndTilesSpacing, 0)); | |
330 } | |
312 instant_layout_manager->set_main_axis_alignment( | 331 instant_layout_manager->set_main_axis_alignment( |
313 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 332 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
314 instant_layout_manager->set_cross_axis_alignment( | 333 instant_layout_manager->set_cross_axis_alignment( |
315 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 334 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
316 instant_container_->SetLayoutManager(instant_layout_manager); | 335 instant_container_->SetLayoutManager(instant_layout_manager); |
317 | 336 |
318 // Create the view for the Google Doodle if the fullscreen launcher is not | 337 // Create the view for the Google Doodle if the fullscreen launcher is not |
319 // enabled. | 338 // enabled. |
320 if (!features::IsFullscreenAppListEnabled()) { | 339 if (!is_fullscreen_app_list_enabled_) { |
321 views::View* web_view = view_delegate_->CreateStartPageWebView( | 340 views::View* web_view = view_delegate_->CreateStartPageWebView( |
322 gfx::Size(kWebViewWidth, kWebViewHeight)); | 341 gfx::Size(kWebViewWidth, kWebViewHeight)); |
323 | 342 |
324 if (web_view) { | 343 if (web_view) { |
325 web_view->SetFocusBehavior(FocusBehavior::NEVER); | 344 web_view->SetFocusBehavior(FocusBehavior::NEVER); |
326 instant_container_->AddChildView(web_view); | 345 instant_container_->AddChildView(web_view); |
327 } | 346 } |
328 } | 347 } |
329 | 348 |
330 instant_container_->AddChildView(search_box_spacer_view_); | 349 instant_container_->AddChildView(search_box_spacer_view_); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 gfx::Rect StartPageView::GetSearchBoxBounds() const { | 405 gfx::Rect StartPageView::GetSearchBoxBounds() const { |
387 return search_box_spacer_view_->bounds() + | 406 return search_box_spacer_view_->bounds() + |
388 GetPageBoundsForState(AppListModel::STATE_START).OffsetFromOrigin(); | 407 GetPageBoundsForState(AppListModel::STATE_START).OffsetFromOrigin(); |
389 } | 408 } |
390 | 409 |
391 void StartPageView::Layout() { | 410 void StartPageView::Layout() { |
392 gfx::Rect bounds(GetContentsBounds()); | 411 gfx::Rect bounds(GetContentsBounds()); |
393 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); | 412 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); |
394 instant_container_->SetBoundsRect(bounds); | 413 instant_container_->SetBoundsRect(bounds); |
395 | 414 |
396 // Tiles begin where the instant container ends. | 415 // For old launcher, tiles begin where the instant container ends; for |
416 // fullscreen app list launcher, tiles begin where the |indicator_| ends. | |
397 bounds.set_y(bounds.bottom()); | 417 bounds.set_y(bounds.bottom()); |
418 if (indicator_) { | |
419 gfx::Rect indicator_rect(bounds); | |
420 indicator_rect.Offset( | |
421 (indicator_rect.width() - indicator_->GetPreferredSize().width()) / 2, | |
422 0); | |
423 indicator_->SetBoundsRect(indicator_rect); | |
424 bounds.Inset(0, indicator_->GetPreferredSize().height(), 0, 0); | |
425 } | |
398 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); | 426 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); |
399 tiles_container_->SetBoundsRect(bounds); | 427 tiles_container_->SetBoundsRect(bounds); |
400 | 428 |
401 CustomLauncherPageView* custom_launcher_page_view = | 429 CustomLauncherPageView* custom_launcher_page_view = |
402 app_list_main_view_->contents_view()->custom_page_view(); | 430 app_list_main_view_->contents_view()->custom_page_view(); |
403 if (!custom_launcher_page_view) | 431 if (!custom_launcher_page_view) |
404 return; | 432 return; |
405 | 433 |
406 bounds = app_list_main_view_->contents_view() | 434 bounds = app_list_main_view_->contents_view() |
407 ->custom_page_view() | 435 ->custom_page_view() |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 // is enabled). | 564 // is enabled). |
537 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) | 565 if (event->type() == ui::ET_SCROLL && event->y_offset() < 0) |
538 MaybeOpenCustomLauncherPage(); | 566 MaybeOpenCustomLauncherPage(); |
539 } | 567 } |
540 | 568 |
541 TileItemView* StartPageView::GetTileItemView(size_t index) { | 569 TileItemView* StartPageView::GetTileItemView(size_t index) { |
542 return tiles_container_->GetTileItemView(index); | 570 return tiles_container_->GetTileItemView(index); |
543 } | 571 } |
544 | 572 |
545 } // namespace app_list | 573 } // namespace app_list |
OLD | NEW |