Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: ui/app_list/views/contents_view.cc

Issue 2905523004: Making answer card to behave like other results. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/resources/grit/ui_resources.h" 26 #include "ui/resources/grit/ui_resources.h"
26 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/view_model.h" 27 #include "ui/views/view_model.h"
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 29
30 namespace app_list { 30 namespace app_list {
31 31
32 namespace {
33
34 // Container of the search answer view.
35 class SearchAnswerContainerView : public views::View {
36 public:
37 explicit SearchAnswerContainerView(views::View* search_results_page_view)
38 : search_results_page_view_(search_results_page_view) {
39 views::BoxLayout* answer_container_layout =
40 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
41 answer_container_layout->set_main_axis_alignment(
42 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
43 SetLayoutManager(answer_container_layout);
44 }
45
46 // views::View overrides:
47 void ChildPreferredSizeChanged(View* child) override {
48 if (visible())
49 search_results_page_view_->Layout();
50 }
51
52 const char* GetClassName() const override {
53 return "SearchAnswerContainerView";
54 }
55
56 private:
57 views::View* const search_results_page_view_;
58
59 DISALLOW_COPY_AND_ASSIGN(SearchAnswerContainerView);
60 };
61
62 } // namespace
63
64 ContentsView::ContentsView(AppListMainView* app_list_main_view) 32 ContentsView::ContentsView(AppListMainView* app_list_main_view)
65 : model_(nullptr), 33 : model_(nullptr),
66 apps_container_view_(nullptr), 34 apps_container_view_(nullptr),
67 search_results_page_view_(nullptr), 35 search_results_page_view_(nullptr),
68 start_page_view_(nullptr), 36 start_page_view_(nullptr),
69 custom_page_view_(nullptr), 37 custom_page_view_(nullptr),
70 search_answer_container_view_(nullptr),
71 app_list_main_view_(app_list_main_view), 38 app_list_main_view_(app_list_main_view),
72 page_before_search_(0) { 39 page_before_search_(0) {
73 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs, 40 pagination_model_.SetTransitionDurations(kPageTransitionDurationInMs,
74 kOverscrollPageTransitionDurationMs); 41 kOverscrollPageTransitionDurationMs);
75 pagination_model_.AddObserver(this); 42 pagination_model_.AddObserver(this);
76 } 43 }
77 44
78 ContentsView::~ContentsView() { 45 ContentsView::~ContentsView() {
79 pagination_model_.RemoveObserver(this); 46 pagination_model_.RemoveObserver(this);
80 if (model_)
81 model_->RemoveObserver(this);
82 } 47 }
83 48
84 void ContentsView::Init(AppListModel* model) { 49 void ContentsView::Init(AppListModel* model) {
85 DCHECK(model); 50 DCHECK(model);
86 model_ = model; 51 model_ = model;
87 52
88 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate(); 53 AppListViewDelegate* view_delegate = app_list_main_view_->view_delegate();
89 54
90 std::vector<views::View*> custom_page_views = 55 std::vector<views::View*> custom_page_views =
91 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); 56 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size());
92 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore 57 // Only add the first custom page view as STATE_CUSTOM_LAUNCHER_PAGE. Ignore
93 // any subsequent custom pages. 58 // any subsequent custom pages.
94 if (!custom_page_views.empty()) { 59 if (!custom_page_views.empty()) {
95 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]); 60 custom_page_view_ = new CustomLauncherPageView(custom_page_views[0]);
96 61
97 AddLauncherPage(custom_page_view_, 62 AddLauncherPage(custom_page_view_,
98 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); 63 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE);
99 } 64 }
100 65
101 // Start page. 66 // Start page.
102 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); 67 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate);
103 AddLauncherPage(start_page_view_, AppListModel::STATE_START); 68 AddLauncherPage(start_page_view_, AppListModel::STATE_START);
104 69
105 // Search results UI. 70 // Search results UI.
106 search_results_page_view_ = new SearchResultPageView(); 71 search_results_page_view_ = new SearchResultPageView();
107 72
108 // Search answer container UI. 73 // Search result containers.
109 search_answer_container_view_ = 74 views::View* const search_answer_view =
110 new SearchAnswerContainerView(search_results_page_view_); 75 view_delegate->GetSearchAnswerWebView();
111 search_answer_container_view_->SetVisible(false); 76 if (search_answer_view) {
112 views::View* search_answer_view = view_delegate->GetSearchAnswerWebView(); 77 search_results_page_view_->AddSearchResultContainerView(
113 if (search_answer_view) 78 nullptr, new SearchResultAnswerCardView(
xiyuan 2017/05/25 16:42:53 nullptr looks strange. Can we following the existi
vadimt 2017/05/25 20:15:16 This is more readable, as this container doesn't u
114 search_answer_container_view_->AddChildView(search_answer_view); 79 model_, search_results_page_view_, search_answer_view));
115 search_results_page_view_->AddChildView(search_answer_container_view_); 80 }
116 81
117 AppListModel::SearchResults* results = view_delegate->GetModel()->results(); 82 AppListModel::SearchResults* results = view_delegate->GetModel()->results();
118 search_results_page_view_->AddSearchResultContainerView( 83 search_results_page_view_->AddSearchResultContainerView(
119 results, new SearchResultListView(app_list_main_view_, view_delegate)); 84 results, new SearchResultListView(app_list_main_view_, view_delegate));
120 85
121 search_results_page_view_->AddSearchResultContainerView( 86 search_results_page_view_->AddSearchResultContainerView(
122 results, new SearchResultTileItemListView( 87 results, new SearchResultTileItemListView(
123 GetSearchBoxView()->search_box(), view_delegate)); 88 GetSearchBoxView()->search_box(), view_delegate));
124 AddLauncherPage(search_results_page_view_, 89 AddLauncherPage(search_results_page_view_,
125 AppListModel::STATE_SEARCH_RESULTS); 90 AppListModel::STATE_SEARCH_RESULTS);
(...skipping 10 matching lines...) Expand all
136 // (as it will trigger a SelectedPageChanged call). 101 // (as it will trigger a SelectedPageChanged call).
137 pagination_model_.SetTotalPages(app_list_pages_.size()); 102 pagination_model_.SetTotalPages(app_list_pages_.size());
138 103
139 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting 104 // Page 0 is selected by SetTotalPages and needs to be 'hidden' when selecting
140 // the initial page. 105 // the initial page.
141 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden(); 106 app_list_pages_[GetActivePageIndex()]->OnWillBeHidden();
142 107
143 pagination_model_.SelectPage(initial_page_index, false); 108 pagination_model_.SelectPage(initial_page_index, false);
144 109
145 ActivePageChanged(); 110 ActivePageChanged();
146
147 model_->AddObserver(this);
148 } 111 }
149 112
150 void ContentsView::CancelDrag() { 113 void ContentsView::CancelDrag() {
151 if (apps_container_view_->apps_grid_view()->has_dragged_view()) 114 if (apps_container_view_->apps_grid_view()->has_dragged_view())
152 apps_container_view_->apps_grid_view()->EndDrag(true); 115 apps_container_view_->apps_grid_view()->EndDrag(true);
153 if (apps_container_view_->app_list_folder_view() 116 if (apps_container_view_->app_list_folder_view()
154 ->items_grid_view() 117 ->items_grid_view()
155 ->has_dragged_view()) { 118 ->has_dragged_view()) {
156 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( 119 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag(
157 true); 120 true);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 app_list_pages_[new_selected]->OnShown(); 481 app_list_pages_[new_selected]->OnShown();
519 } 482 }
520 483
521 void ContentsView::TransitionStarted() { 484 void ContentsView::TransitionStarted() {
522 } 485 }
523 486
524 void ContentsView::TransitionChanged() { 487 void ContentsView::TransitionChanged() {
525 UpdatePageBounds(); 488 UpdatePageBounds();
526 } 489 }
527 490
528 void ContentsView::OnSearchAnswerAvailableChanged(bool has_answer) {
529 if (has_answer == search_answer_container_view_->visible())
530 return;
531
532 search_answer_container_view_->SetVisible(has_answer);
533 search_results_page_view_->Layout();
534 }
535
536 } // namespace app_list 491 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698