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

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

Issue 2910173003: Revert of 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/app_list/views/search_result_answer_card_view.h"
6
7 #include "ui/app_list/app_list_constants.h"
8 #include "ui/app_list/app_list_features.h"
9 #include "ui/app_list/views/search_result_page_view.h"
10 #include "ui/views/background.h"
11 #include "ui/views/controls/button/custom_button.h"
12 #include "ui/views/layout/box_layout.h"
13 #include "ui/views/layout/fill_layout.h"
14
15 namespace app_list {
16
17 namespace {
18
19 // Answer card relevance is high to always have it first.
20 constexpr double kSearchAnswerCardRelevance = 100;
21
22 // Container of the search answer view.
23 class SearchAnswerContainerView : public views::CustomButton {
24 public:
25 explicit SearchAnswerContainerView(views::View* search_results_page_view)
26 : CustomButton(nullptr),
27 search_results_page_view_(search_results_page_view) {
28 // Center the card horizontally in the container.
29 views::BoxLayout* answer_container_layout =
30 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
31 answer_container_layout->set_main_axis_alignment(
32 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
33 SetLayoutManager(answer_container_layout);
34 }
35
36 void SetSelected(bool selected) {
37 if (selected == selected_)
38 return;
39 selected_ = selected;
40 UpdateBackgroundColor();
41 }
42
43 // views::CustomButton overrides:
44 void ChildPreferredSizeChanged(View* child) override {
45 // Card size changed.
46 if (visible())
47 search_results_page_view_->Layout();
48 }
49
50 int GetHeightForWidth(int w) const override {
51 return visible() ? CustomButton::GetHeightForWidth(w) : 0;
52 }
53
54 const char* GetClassName() const override {
55 return "SearchAnswerContainerView";
56 }
57
58 void StateChanged(ButtonState old_state) override { UpdateBackgroundColor(); }
59
60 private:
61 void UpdateBackgroundColor() {
62 views::Background* background = nullptr;
63
64 if (selected_) {
65 background = views::Background::CreateSolidBackground(kSelectedColor);
66 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
67 background = views::Background::CreateSolidBackground(kHighlightedColor);
68 }
69
70 set_background(background);
71 SchedulePaint();
72 }
73
74 views::View* const search_results_page_view_;
75 bool selected_ = false;
76
77 DISALLOW_COPY_AND_ASSIGN(SearchAnswerContainerView);
78 };
79
80 } // namespace
81
82 SearchResultAnswerCardView::SearchResultAnswerCardView(
83 AppListModel* model,
84 SearchResultPageView* search_results_page_view,
85 views::View* search_answer_view)
86 : model_(model),
87 search_answer_container_view_(
88 new SearchAnswerContainerView(search_results_page_view)) {
89 search_answer_container_view_->SetVisible(false);
90 search_answer_container_view_->AddChildView(search_answer_view);
91 AddChildView(search_answer_container_view_);
92 model->AddObserver(this);
93 SetLayoutManager(new views::FillLayout);
94 }
95
96 SearchResultAnswerCardView::~SearchResultAnswerCardView() {
97 model_->RemoveObserver(this);
98 }
99
100 const char* SearchResultAnswerCardView::GetClassName() const {
101 return "SearchResultAnswerCardView";
102 }
103
104 void SearchResultAnswerCardView::OnContainerSelected(
105 bool from_bottom,
106 bool directional_movement) {
107 if (num_results() == 0)
108 return;
109
110 SetSelectedIndex(0);
111 }
112
113 int SearchResultAnswerCardView::GetYSize() {
114 return num_results();
115 }
116
117 int SearchResultAnswerCardView::DoUpdate() {
118 const bool have_result = search_answer_container_view_->visible();
119 set_container_score(have_result ? kSearchAnswerCardRelevance : 0);
120 return have_result ? 1 : 0;
121 }
122
123 void SearchResultAnswerCardView::UpdateSelectedIndex(int old_selected,
124 int new_selected) {
125 if (new_selected == old_selected)
126 return;
127
128 const bool is_selected = new_selected == 0;
129 search_answer_container_view_->SetSelected(is_selected);
130 if (is_selected)
131 NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
132 }
133
134 void SearchResultAnswerCardView::OnSearchAnswerAvailableChanged(
135 bool has_answer) {
136 const bool visible = has_answer && !features::IsAnswerCardDarkRunEnabled();
137 if (visible == search_answer_container_view_->visible())
138 return;
139
140 search_answer_container_view_->SetVisible(visible);
141 ScheduleUpdate();
142 }
143
144 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_result_answer_card_view.h ('k') | ui/app_list/views/search_result_container_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698