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

Side by Side Diff: ui/app_list/search_result_list_view.cc

Issue 10534051: app_list: Add transition for apps grid and search results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/search_result_list_view.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 (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/search_result_list_view.h" 5 #include "ui/app_list/search_result_list_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 bool SearchResultListView::IsResultViewSelected( 66 bool SearchResultListView::IsResultViewSelected(
67 const SearchResultView* result_view) const { 67 const SearchResultView* result_view) const {
68 if (selected_index_ < 0) 68 if (selected_index_ < 0)
69 return false; 69 return false;
70 70
71 return static_cast<const SearchResultView*>(child_at(selected_index_)) == 71 return static_cast<const SearchResultView*>(child_at(selected_index_)) ==
72 result_view; 72 result_view;
73 } 73 }
74 74
75 bool SearchResultListView::OnKeyPressed(const views::KeyEvent& event) {
76 switch (event.key_code()) {
77 case ui::VKEY_UP:
78 SetSelectedIndex(std::max(selected_index_ - 1, 0));
79 return true;
80 case ui::VKEY_DOWN:
81 SetSelectedIndex(std::min(selected_index_ + 1, last_visible_index_));
82 return true;
83 case ui::VKEY_RETURN:
84 if (selected_index_ >= 0)
85 ButtonPressed(GetResultViewAt(selected_index_), event);
86 return true;
87 default:
88 break;
89 }
90 return false;
91 }
92
75 SearchResultView* SearchResultListView::GetResultViewAt(int index) { 93 SearchResultView* SearchResultListView::GetResultViewAt(int index) {
76 DCHECK(index >= 0 && index < child_count()); 94 DCHECK(index >= 0 && index < child_count());
77 return static_cast<SearchResultView*>(child_at(index)); 95 return static_cast<SearchResultView*>(child_at(index));
78 } 96 }
79 97
80 void SearchResultListView::Update() { 98 void SearchResultListView::Update() {
81 last_visible_index_ = 0; 99 last_visible_index_ = 0;
82 for (size_t i = 0; i < static_cast<size_t>(child_count()); ++i) { 100 for (size_t i = 0; i < static_cast<size_t>(child_count()); ++i) {
83 SearchResultView* result_view = GetResultViewAt(i); 101 SearchResultView* result_view = GetResultViewAt(i);
84 if (i < results_->item_count()) { 102 if (i < results_->item_count()) {
(...skipping 16 matching lines...) Expand all
101 // When search results are added one by one, each addition generates an update 119 // When search results are added one by one, each addition generates an update
102 // request. Consolidates those update requests into one Update call. 120 // request. Consolidates those update requests into one Update call.
103 if (!update_factory_.HasWeakPtrs()) { 121 if (!update_factory_.HasWeakPtrs()) {
104 MessageLoop::current()->PostTask( 122 MessageLoop::current()->PostTask(
105 FROM_HERE, 123 FROM_HERE,
106 base::Bind(&SearchResultListView::Update, 124 base::Bind(&SearchResultListView::Update,
107 update_factory_.GetWeakPtr())); 125 update_factory_.GetWeakPtr()));
108 } 126 }
109 } 127 }
110 128
111 bool SearchResultListView::OnKeyPressed(const views::KeyEvent& event) {
112 switch (event.key_code()) {
113 case ui::VKEY_UP:
114 SetSelectedIndex(std::max(selected_index_ - 1, 0));
115 return true;
116 case ui::VKEY_DOWN:
117 SetSelectedIndex(std::min(selected_index_ + 1, last_visible_index_));
118 return true;
119 case ui::VKEY_RETURN:
120 if (selected_index_ >= 0)
121 ButtonPressed(GetResultViewAt(selected_index_), event);
122 return true;
123 default:
124 break;
125 }
126 return false;
127 }
128
129 void SearchResultListView::ButtonPressed(views::Button* sender, 129 void SearchResultListView::ButtonPressed(views::Button* sender,
130 const views::Event& event) { 130 const views::Event& event) {
131 if (sender->GetClassName() != SearchResultView::kViewClassName) 131 if (sender->GetClassName() != SearchResultView::kViewClassName)
132 return; 132 return;
133 133
134 if (delegate_) { 134 if (delegate_) {
135 const SearchResult* result = 135 const SearchResult* result =
136 static_cast<SearchResultView*>(sender)->result(); 136 static_cast<SearchResultView*>(sender)->result();
137 DCHECK(result); 137 DCHECK(result);
138 delegate_->OpenResult(*result, event.flags()); 138 delegate_->OpenResult(*result, event.flags());
139 } 139 }
140 } 140 }
141 141
142 void SearchResultListView::ListItemsAdded(size_t start, size_t count) { 142 void SearchResultListView::ListItemsAdded(size_t start, size_t count) {
143 ScheduleUpdate(); 143 ScheduleUpdate();
144 } 144 }
145 145
146 void SearchResultListView::ListItemsRemoved(size_t start, size_t count) { 146 void SearchResultListView::ListItemsRemoved(size_t start, size_t count) {
147 ScheduleUpdate(); 147 ScheduleUpdate();
148 } 148 }
149 149
150 void SearchResultListView::ListItemsChanged(size_t start, size_t count) { 150 void SearchResultListView::ListItemsChanged(size_t start, size_t count) {
151 ScheduleUpdate(); 151 ScheduleUpdate();
152 } 152 }
153 153
154 } // namespace app_list 154 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/search_result_list_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698