| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/contents_view.h" | 5 #include "ui/app_list/views/contents_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
| 12 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
| 13 #include "ui/app_list/app_list_view_delegate.h" | 13 #include "ui/app_list/app_list_view_delegate.h" |
| 14 #include "ui/app_list/views/app_list_folder_view.h" | 14 #include "ui/app_list/views/app_list_folder_view.h" |
| 15 #include "ui/app_list/views/app_list_main_view.h" | 15 #include "ui/app_list/views/app_list_main_view.h" |
| 16 #include "ui/app_list/views/apps_container_view.h" | 16 #include "ui/app_list/views/apps_container_view.h" |
| 17 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
| 18 #include "ui/app_list/views/custom_launcher_page_view.h" | 18 #include "ui/app_list/views/custom_launcher_page_view.h" |
| 19 #include "ui/app_list/views/search_box_view.h" | 19 #include "ui/app_list/views/search_box_view.h" |
| 20 #include "ui/app_list/views/search_result_answer_card_view.h" |
| 20 #include "ui/app_list/views/search_result_list_view.h" | 21 #include "ui/app_list/views/search_result_list_view.h" |
| 21 #include "ui/app_list/views/search_result_page_view.h" | 22 #include "ui/app_list/views/search_result_page_view.h" |
| 22 #include "ui/app_list/views/search_result_tile_item_list_view.h" | 23 #include "ui/app_list/views/search_result_tile_item_list_view.h" |
| 23 #include "ui/app_list/views/start_page_view.h" | 24 #include "ui/app_list/views/start_page_view.h" |
| 24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 25 #include "ui/views/layout/box_layout.h" | |
| 26 #include "ui/views/view_model.h" | 26 #include "ui/views/view_model.h" |
| 27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 28 | 28 |
| 29 namespace app_list { | 29 namespace app_list { |
| 30 | 30 |
| 31 namespace { | |
| 32 | |
| 33 // Container of the search answer view. | |
| 34 class SearchAnswerContainerView : public views::View { | |
| 35 public: | |
| 36 explicit SearchAnswerContainerView(views::View* search_results_page_view) | |
| 37 : search_results_page_view_(search_results_page_view) { | |
| 38 views::BoxLayout* answer_container_layout = | |
| 39 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 40 answer_container_layout->set_main_axis_alignment( | |
| 41 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 42 SetLayoutManager(answer_container_layout); | |
| 43 } | |
| 44 | |
| 45 // views::View overrides: | |
| 46 void ChildPreferredSizeChanged(View* child) override { | |
| 47 if (visible()) | |
| 48 search_results_page_view_->Layout(); | |
| 49 } | |
| 50 | |
| 51 const char* GetClassName() const override { | |
| 52 return "SearchAnswerContainerView"; | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 views::View* const search_results_page_view_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(SearchAnswerContainerView); | |
| 59 }; | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 31 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
| 64 : model_(nullptr), | 32 : model_(nullptr), |
| 65 apps_container_view_(nullptr), | 33 apps_container_view_(nullptr), |
| 66 search_results_page_view_(nullptr), | 34 search_results_page_view_(nullptr), |
| 67 start_page_view_(nullptr), | 35 start_page_view_(nullptr), |
| 68 custom_page_view_(nullptr), | 36 custom_page_view_(nullptr), |
| 69 search_answer_container_view_(nullptr), | |
| 70 app_list_main_view_(app_list_main_view), | 37 app_list_main_view_(app_list_main_view), |
| 71 page_before_search_(0) { | 38 page_before_search_(0) { |
| 72 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, | 39 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, |
| 73 kOverscrollPageTransitionDurationMs); | 40 kOverscrollPageTransitionDurationMs); |
| 74 pagination_model_.AddObserver(this); | 41 pagination_model_.AddObserver(this); |
| 75 } | 42 } |
| 76 | 43 |
| 77 ContentsView::~ContentsView() { | 44 ContentsView::~ContentsView() { |
| 78 pagination_model_.RemoveObserver(this); | 45 pagination_model_.RemoveObserver(this); |
| 79 if (model_) | |
| 80 model_->RemoveObserver(this); | |
| 81 } | 46 } |
| 82 | 47 |
| 83 void ContentsView::Init(AppListModel* model) { | 48 void ContentsView::Init(AppListModel* model) { |
| 84 DCHECK(model); | 49 DCHECK(model); |
| 85 model_ = model; | 50 model_ = model; |
| 86 | 51 |
| 87 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); | 52 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); |
| 88 | 53 |
| 89 std::vector<views::View*> custom_page_views = | 54 std::vector<views::View*> custom_page_views = |
| 90 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); | 55 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); |
| 91 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore | 56 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore |
| 92 // any subsequent custom pages. | 57 // any subsequent custom pages. |
| 93 if (!custom_page_views.empty()) { | 58 if (!custom_page_views.empty()) { |
| 94 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); | 59 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); |
| 95 | 60 |
| 96 AddLauncherPage(custom_page_view_, | 61 AddLauncherPage(custom_page_view_, |
| 97 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 62 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 98 } | 63 } |
| 99 | 64 |
| 100 // Start page. | 65 // Start page. |
| 101 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 66 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
| 102 AddLauncherPage(start_page_view_, AppListModel::STATE_START); | 67 AddLauncherPage(start_page_view_, AppListModel::STATE_START); |
| 103 | 68 |
| 104 // Search results UI. | 69 // Search results UI. |
| 105 search_results_page_view_ = new SearchResultPageView(); | 70 search_results_page_view_ = new SearchResultPageView(); |
| 106 | 71 |
| 107 // Search answer container UI. | 72 // Search result containers. |
| 108 search_answer_container_view_ = | 73 views::View* const search_answer_view = |
| 109 new SearchAnswerContainerView(search_results_page_view_); | 74 view_delegate->GetSearchAnswerWebView(); |
| 110 search_answer_container_view_->SetVisible(false); | 75 if (search_answer_view) { |
| 111 views::View* search_answer_view = view_delegate->GetSearchAnswerWebView(); | 76 search_results_page_view_->AddSearchResultContainerView( |
| 112 if (search_answer_view) | 77 nullptr, new SearchResultAnswerCardView( |
| 113 search_answer_container_view_->AddChildView(search_answer_view); | 78 model_, search_results_page_view_, search_answer_view)); |
| 114 search_results_page_view_->AddChildView(search_answer_container_view_); | 79 } |
| 115 | 80 |
| 116 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); | 81 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); |
| 117 search_results_page_view_->AddSearchResultContainerView( | 82 search_results_page_view_->AddSearchResultContainerView( |
| 118 results, new SearchResultListView(app_list_main_view_, view_delegate)); | 83 results, new SearchResultListView(app_list_main_view_, view_delegate)); |
| 119 | 84 |
| 120 search_results_page_view_->AddSearchResultContainerView( | 85 search_results_page_view_->AddSearchResultContainerView( |
| 121 results, new SearchResultTileItemListView( | 86 results, new SearchResultTileItemListView( |
| 122 GetSearchBoxView()->search_box(), view_delegate)); | 87 GetSearchBoxView()->search_box(), view_delegate)); |
| 123 AddLauncherPage(search_results_page_view_, | 88 AddLauncherPage(search_results_page_view_, |
| 124 AppListModel::STATE_SEARCH_RESULTS); | 89 AppListModel::STATE_SEARCH_RESULTS); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 135 // (as it will trigger a SelectedPageChanged call). | 100 // (as it will trigger a SelectedPageChanged call). |
| 136 pagination_model_.SetTotalPages(app_list_pages_.size()); | 101 pagination_model_.SetTotalPages(app_list_pages_.size()); |
| 137 | 102 |
| 138 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting | 103 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting |
| 139 // the initial page. | 104 // the initial page. |
| 140 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); | 105 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); |
| 141 | 106 |
| 142 pagination_model_.SelectPage(initial_page_index, false); | 107 pagination_model_.SelectPage(initial_page_index, false); |
| 143 | 108 |
| 144 ActivePageChanged(); | 109 ActivePageChanged(); |
| 145 | |
| 146 model_->AddObserver(this); | |
| 147 } | 110 } |
| 148 | 111 |
| 149 void ContentsView::CancelDrag() { | 112 void ContentsView::CancelDrag() { |
| 150 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 113 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 151 apps_container_view_->apps_grid_view()->EndDrag(true); | 114 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 152 if (apps_container_view_->app_list_folder_view() | 115 if (apps_container_view_->app_list_folder_view() |
| 153 ->items_grid_view() | 116 ->items_grid_view() |
| 154 ->has_dragged_view()) { | 117 ->has_dragged_view()) { |
| 155 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 118 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
| 156 true); | 119 true); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 app_list_pages_[new_selected]->OnShown(); | 480 app_list_pages_[new_selected]->OnShown(); |
| 518 } | 481 } |
| 519 | 482 |
| 520 void ContentsView::TransitionStarted() { | 483 void ContentsView::TransitionStarted() { |
| 521 } | 484 } |
| 522 | 485 |
| 523 void ContentsView::TransitionChanged() { | 486 void ContentsView::TransitionChanged() { |
| 524 UpdatePageBounds(); | 487 UpdatePageBounds(); |
| 525 } | 488 } |
| 526 | 489 |
| 527 void ContentsView::OnSearchAnswerAvailableChanged(bool has_answer) { | |
| 528 if (has_answer == search_answer_container_view_->visible()) | |
| 529 return; | |
| 530 | |
| 531 search_answer_container_view_->SetVisible(has_answer); | |
| 532 search_results_page_view_->Layout(); | |
| 533 } | |
| 534 | |
| 535 } // namespace app_list | 490 } // namespace app_list |
| OLD | NEW |