| 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" | |
| 21 #include "ui/app_list/views/search_result_list_view.h" | 20 #include "ui/app_list/views/search_result_list_view.h" |
| 22 #include "ui/app_list/views/search_result_page_view.h" | 21 #include "ui/app_list/views/search_result_page_view.h" |
| 23 #include "ui/app_list/views/search_result_tile_item_list_view.h" | 22 #include "ui/app_list/views/search_result_tile_item_list_view.h" |
| 24 #include "ui/app_list/views/start_page_view.h" | 23 #include "ui/app_list/views/start_page_view.h" |
| 25 #include "ui/events/event.h" | 24 #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 |
| 31 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 63 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
| 32 : model_(nullptr), | 64 : model_(nullptr), |
| 33 apps_container_view_(nullptr), | 65 apps_container_view_(nullptr), |
| 34 search_results_page_view_(nullptr), | 66 search_results_page_view_(nullptr), |
| 35 start_page_view_(nullptr), | 67 start_page_view_(nullptr), |
| 36 custom_page_view_(nullptr), | 68 custom_page_view_(nullptr), |
| 69 search_answer_container_view_(nullptr), |
| 37 app_list_main_view_(app_list_main_view), | 70 app_list_main_view_(app_list_main_view), |
| 38 page_before_search_(0) { | 71 page_before_search_(0) { |
| 39 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, | 72 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, |
| 40 kOverscrollPageTransitionDurationMs); | 73 kOverscrollPageTransitionDurationMs); |
| 41 pagination_model_.AddObserver(this); | 74 pagination_model_.AddObserver(this); |
| 42 } | 75 } |
| 43 | 76 |
| 44 ContentsView::~ContentsView() { | 77 ContentsView::~ContentsView() { |
| 45 pagination_model_.RemoveObserver(this); | 78 pagination_model_.RemoveObserver(this); |
| 79 if (model_) |
| 80 model_->RemoveObserver(this); |
| 46 } | 81 } |
| 47 | 82 |
| 48 void ContentsView::Init(AppListModel* model) { | 83 void ContentsView::Init(AppListModel* model) { |
| 49 DCHECK(model); | 84 DCHECK(model); |
| 50 model_ = model; | 85 model_ = model; |
| 51 | 86 |
| 52 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); | 87 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); |
| 53 | 88 |
| 54 std::vector<views::View*> custom_page_views = | 89 std::vector<views::View*> custom_page_views = |
| 55 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); | 90 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); |
| 56 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore | 91 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore |
| 57 // any subsequent custom pages. | 92 // any subsequent custom pages. |
| 58 if (!custom_page_views.empty()) { | 93 if (!custom_page_views.empty()) { |
| 59 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); | 94 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); |
| 60 | 95 |
| 61 AddLauncherPage(custom_page_view_, | 96 AddLauncherPage(custom_page_view_, |
| 62 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 97 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 63 } | 98 } |
| 64 | 99 |
| 65 // Start page. | 100 // Start page. |
| 66 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 101 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
| 67 AddLauncherPage(start_page_view_, AppListModel::STATE_START); | 102 AddLauncherPage(start_page_view_, AppListModel::STATE_START); |
| 68 | 103 |
| 69 // Search results UI. | 104 // Search results UI. |
| 70 search_results_page_view_ = new SearchResultPageView(); | 105 search_results_page_view_ = new SearchResultPageView(); |
| 71 | 106 |
| 72 // Search result containers. | 107 // Search answer container UI. |
| 73 views::View* const search_answer_view = | 108 search_answer_container_view_ = |
| 74 view_delegate->GetSearchAnswerWebView(); | 109 new SearchAnswerContainerView(search_results_page_view_); |
| 75 if (search_answer_view) { | 110 search_answer_container_view_->SetVisible(false); |
| 76 search_results_page_view_->AddSearchResultContainerView( | 111 views::View* search_answer_view = view_delegate->GetSearchAnswerWebView(); |
| 77 nullptr, new SearchResultAnswerCardView( | 112 if (search_answer_view) |
| 78 model_, search_results_page_view_, search_answer_view)); | 113 search_answer_container_view_->AddChildView(search_answer_view); |
| 79 } | 114 search_results_page_view_->AddChildView(search_answer_container_view_); |
| 80 | 115 |
| 81 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); | 116 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); |
| 82 search_results_page_view_->AddSearchResultContainerView( | 117 search_results_page_view_->AddSearchResultContainerView( |
| 83 results, new SearchResultListView(app_list_main_view_, view_delegate)); | 118 results, new SearchResultListView(app_list_main_view_, view_delegate)); |
| 84 | 119 |
| 85 search_results_page_view_->AddSearchResultContainerView( | 120 search_results_page_view_->AddSearchResultContainerView( |
| 86 results, new SearchResultTileItemListView( | 121 results, new SearchResultTileItemListView( |
| 87 GetSearchBoxView()->search_box(), view_delegate)); | 122 GetSearchBoxView()->search_box(), view_delegate)); |
| 88 AddLauncherPage(search_results_page_view_, | 123 AddLauncherPage(search_results_page_view_, |
| 89 AppListModel::STATE_SEARCH_RESULTS); | 124 AppListModel::STATE_SEARCH_RESULTS); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 // (as it will trigger a SelectedPageChanged call). | 135 // (as it will trigger a SelectedPageChanged call). |
| 101 pagination_model_.SetTotalPages(app_list_pages_.size()); | 136 pagination_model_.SetTotalPages(app_list_pages_.size()); |
| 102 | 137 |
| 103 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting | 138 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting |
| 104 // the initial page. | 139 // the initial page. |
| 105 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); | 140 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); |
| 106 | 141 |
| 107 pagination_model_.SelectPage(initial_page_index, false); | 142 pagination_model_.SelectPage(initial_page_index, false); |
| 108 | 143 |
| 109 ActivePageChanged(); | 144 ActivePageChanged(); |
| 145 |
| 146 model_->AddObserver(this); |
| 110 } | 147 } |
| 111 | 148 |
| 112 void ContentsView::CancelDrag() { | 149 void ContentsView::CancelDrag() { |
| 113 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 150 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 114 apps_container_view_->apps_grid_view()->EndDrag(true); | 151 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 115 if (apps_container_view_->app_list_folder_view() | 152 if (apps_container_view_->app_list_folder_view() |
| 116 ->items_grid_view() | 153 ->items_grid_view() |
| 117 ->has_dragged_view()) { | 154 ->has_dragged_view()) { |
| 118 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 155 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
| 119 true); | 156 true); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 app_list_pages_[new_selected]->OnShown(); | 517 app_list_pages_[new_selected]->OnShown(); |
| 481 } | 518 } |
| 482 | 519 |
| 483 void ContentsView::TransitionStarted() { | 520 void ContentsView::TransitionStarted() { |
| 484 } | 521 } |
| 485 | 522 |
| 486 void ContentsView::TransitionChanged() { | 523 void ContentsView::TransitionChanged() { |
| 487 UpdatePageBounds(); | 524 UpdatePageBounds(); |
| 488 } | 525 } |
| 489 | 526 |
| 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 |
| 490 } // namespace app_list | 535 } // namespace app_list |
| OLD | NEW |