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

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

Issue 2920393002: Implementing answer card hover highlight. (Closed)
Patch Set: CR comments 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
« no previous file with comments | « ui/app_list/search_result_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/search_result_answer_card_view.h" 5 #include "ui/app_list/views/search_result_answer_card_view.h"
6 6
7 #include "ui/app_list/app_list_constants.h" 7 #include "ui/app_list/app_list_constants.h"
8 #include "ui/app_list/app_list_features.h" 8 #include "ui/app_list/app_list_features.h"
9 #include "ui/app_list/app_list_view_delegate.h" 9 #include "ui/app_list/app_list_view_delegate.h"
10 #include "ui/app_list/search_result_observer.h"
10 #include "ui/views/background.h" 11 #include "ui/views/background.h"
11 #include "ui/views/controls/button/custom_button.h" 12 #include "ui/views/controls/button/custom_button.h"
12 #include "ui/views/layout/box_layout.h" 13 #include "ui/views/layout/box_layout.h"
13 #include "ui/views/layout/fill_layout.h" 14 #include "ui/views/layout/fill_layout.h"
14 15
15 namespace app_list { 16 namespace app_list {
16 17
17 // Container of the search answer view. 18 // Container of the search answer view.
18 class SearchResultAnswerCardView::SearchAnswerContainerView 19 class SearchResultAnswerCardView::SearchAnswerContainerView
19 : public views::CustomButton, 20 : public views::CustomButton,
20 public views::ButtonListener { 21 public views::ButtonListener,
22 public SearchResultObserver {
21 public: 23 public:
22 explicit SearchAnswerContainerView(AppListViewDelegate* view_delegate) 24 explicit SearchAnswerContainerView(AppListViewDelegate* view_delegate)
23 : CustomButton(this), view_delegate_(view_delegate) { 25 : CustomButton(this), view_delegate_(view_delegate) {
24 // Center the card horizontally in the container. 26 // Center the card horizontally in the container.
25 views::BoxLayout* answer_container_layout = 27 views::BoxLayout* answer_container_layout =
26 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 28 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
27 answer_container_layout->set_main_axis_alignment( 29 answer_container_layout->set_main_axis_alignment(
28 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 30 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
29 SetLayoutManager(answer_container_layout); 31 SetLayoutManager(answer_container_layout);
30 SetVisible(false); 32 SetVisible(false);
(...skipping 11 matching lines...) Expand all
42 views::View* const new_result_view = 44 views::View* const new_result_view =
43 search_result ? search_result->view() : nullptr; 45 search_result ? search_result->view() : nullptr;
44 46
45 if (old_result_view != new_result_view) { 47 if (old_result_view != new_result_view) {
46 if (old_result_view != nullptr) 48 if (old_result_view != nullptr)
47 RemoveChildView(old_result_view); 49 RemoveChildView(old_result_view);
48 if (new_result_view != nullptr) 50 if (new_result_view != nullptr)
49 AddChildView(new_result_view); 51 AddChildView(new_result_view);
50 } 52 }
51 53
54 if (search_result_)
55 search_result_->RemoveObserver(this);
52 search_result_ = search_result ? search_result->Duplicate() : nullptr; 56 search_result_ = search_result ? search_result->Duplicate() : nullptr;
57 if (search_result_)
58 search_result_->AddObserver(this);
53 59
54 SetVisible(new_result_view != nullptr); 60 SetVisible(new_result_view != nullptr);
55 } 61 }
56 62
57 // views::CustomButton overrides: 63 // views::CustomButton overrides:
58 const char* GetClassName() const override { 64 const char* GetClassName() const override {
59 return "SearchAnswerContainerView"; 65 return "SearchAnswerContainerView";
60 } 66 }
61 67
62 void StateChanged(ButtonState old_state) override { UpdateBackgroundColor(); } 68 void StateChanged(ButtonState old_state) override { UpdateBackgroundColor(); }
63 69
64 // views::ButtonListener overrides: 70 // views::ButtonListener overrides:
65 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 71 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
66 DCHECK(sender == this); 72 DCHECK(sender == this);
67 DCHECK(search_result_); 73 DCHECK(search_result_);
68 view_delegate_->OpenSearchResult(search_result_.get(), false, 74 view_delegate_->OpenSearchResult(search_result_.get(), false,
69 event.flags()); 75 event.flags());
70 } 76 }
71 77
78 // SearchResultObserver overrides:
79 void OnViewHoverStateChanged() override { UpdateBackgroundColor(); }
80
72 private: 81 private:
73 void UpdateBackgroundColor() { 82 void UpdateBackgroundColor() {
74 if (selected_) 83 if (selected_) {
75 SetBackground(views::CreateSolidBackground(kSelectedColor)); 84 SetBackground(views::CreateSolidBackground(kSelectedColor));
76 else if (state() == STATE_HOVERED || state() == STATE_PRESSED) 85 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED ||
86 (search_result_ && search_result_->is_mouse_in_view())) {
77 SetBackground(views::CreateSolidBackground(kHighlightedColor)); 87 SetBackground(views::CreateSolidBackground(kHighlightedColor));
88 } else {
89 SetBackground(nullptr);
90 }
78 91
79 SchedulePaint(); 92 SchedulePaint();
80 } 93 }
81 94
82 AppListViewDelegate* const view_delegate_; // Not owned. 95 AppListViewDelegate* const view_delegate_; // Not owned.
83 bool selected_ = false; 96 bool selected_ = false;
84 std::unique_ptr<SearchResult> search_result_; 97 std::unique_ptr<SearchResult> search_result_;
85 98
86 DISALLOW_COPY_AND_ASSIGN(SearchAnswerContainerView); 99 DISALLOW_COPY_AND_ASSIGN(SearchAnswerContainerView);
87 }; 100 };
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 bool SearchResultAnswerCardView::OnKeyPressed(const ui::KeyEvent& event) { 155 bool SearchResultAnswerCardView::OnKeyPressed(const ui::KeyEvent& event) {
143 if (selected_index() == 0 && 156 if (selected_index() == 0 &&
144 search_answer_container_view_->OnKeyPressed(event)) { 157 search_answer_container_view_->OnKeyPressed(event)) {
145 return true; 158 return true;
146 } 159 }
147 160
148 return SearchResultContainerView::OnKeyPressed(event); 161 return SearchResultContainerView::OnKeyPressed(event);
149 } 162 }
150 163
151 } // namespace app_list 164 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/search_result_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698