| 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/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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 bool SearchResultListView::OnKeyPressed(const ui::KeyEvent& event) { | 76 bool SearchResultListView::OnKeyPressed(const ui::KeyEvent& event) { |
| 77 switch (event.key_code()) { | 77 switch (event.key_code()) { |
| 78 case ui::VKEY_UP: | 78 case ui::VKEY_UP: |
| 79 SetSelectedIndex(std::max(selected_index_ - 1, 0)); | 79 SetSelectedIndex(std::max(selected_index_ - 1, 0)); |
| 80 return true; | 80 return true; |
| 81 case ui::VKEY_DOWN: | 81 case ui::VKEY_DOWN: |
| 82 SetSelectedIndex(std::min(selected_index_ + 1, last_visible_index_)); | 82 SetSelectedIndex(std::min(selected_index_ + 1, last_visible_index_)); |
| 83 return true; | 83 return true; |
| 84 case ui::VKEY_RETURN: | 84 case ui::VKEY_RETURN: |
| 85 if (selected_index_ >= 0) | 85 if (selected_index_ >= 0) |
| 86 ButtonPressed(GetResultViewAt(selected_index_), event); | 86 SearchResultActivated(GetResultViewAt(selected_index_), event); |
| 87 return true; | 87 return true; |
| 88 default: | 88 default: |
| 89 break; | 89 break; |
| 90 } | 90 } |
| 91 return false; | 91 return false; |
| 92 } | 92 } |
| 93 | 93 |
| 94 SearchResultView* SearchResultListView::GetResultViewAt(int index) { | 94 SearchResultView* SearchResultListView::GetResultViewAt(int index) { |
| 95 DCHECK(index >= 0 && index < child_count()); | 95 DCHECK(index >= 0 && index < child_count()); |
| 96 return static_cast<SearchResultView*>(child_at(index)); | 96 return static_cast<SearchResultView*>(child_at(index)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 120 // When search results are added one by one, each addition generates an update | 120 // When search results are added one by one, each addition generates an update |
| 121 // request. Consolidates those update requests into one Update call. | 121 // request. Consolidates those update requests into one Update call. |
| 122 if (!update_factory_.HasWeakPtrs()) { | 122 if (!update_factory_.HasWeakPtrs()) { |
| 123 MessageLoop::current()->PostTask( | 123 MessageLoop::current()->PostTask( |
| 124 FROM_HERE, | 124 FROM_HERE, |
| 125 base::Bind(&SearchResultListView::Update, | 125 base::Bind(&SearchResultListView::Update, |
| 126 update_factory_.GetWeakPtr())); | 126 update_factory_.GetWeakPtr())); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SearchResultListView::ButtonPressed(views::Button* sender, | |
| 131 const ui::Event& event) { | |
| 132 if (sender->GetClassName() != SearchResultView::kViewClassName) | |
| 133 return; | |
| 134 | |
| 135 if (delegate_) { | |
| 136 const SearchResult* result = | |
| 137 static_cast<SearchResultView*>(sender)->result(); | |
| 138 | |
| 139 if (result) | |
| 140 delegate_->OpenResult(*result, event.flags()); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 void SearchResultListView::ListItemsAdded(size_t start, size_t count) { | 130 void SearchResultListView::ListItemsAdded(size_t start, size_t count) { |
| 145 ScheduleUpdate(); | 131 ScheduleUpdate(); |
| 146 } | 132 } |
| 147 | 133 |
| 148 void SearchResultListView::ListItemsRemoved(size_t start, size_t count) { | 134 void SearchResultListView::ListItemsRemoved(size_t start, size_t count) { |
| 149 size_t last = std::min(start + count, static_cast<size_t>(child_count())); | 135 size_t last = std::min(start + count, static_cast<size_t>(child_count())); |
| 150 for (size_t i = start; i < last; ++i) | 136 for (size_t i = start; i < last; ++i) |
| 151 GetResultViewAt(i)->ClearResultNoRepaint(); | 137 GetResultViewAt(i)->ClearResultNoRepaint(); |
| 152 | 138 |
| 153 ScheduleUpdate(); | 139 ScheduleUpdate(); |
| 154 } | 140 } |
| 155 | 141 |
| 156 void SearchResultListView::ListItemsChanged(size_t start, size_t count) { | 142 void SearchResultListView::ListItemsChanged(size_t start, size_t count) { |
| 157 ScheduleUpdate(); | 143 ScheduleUpdate(); |
| 158 } | 144 } |
| 159 | 145 |
| 146 void SearchResultListView::SearchResultActivated(SearchResultView* view, |
| 147 const ui::Event& event) { |
| 148 if (delegate_ && view->result()) |
| 149 delegate_->OpenResult(*(view->result()), event.flags()); |
| 150 } |
| 151 |
| 152 void SearchResultListView::SearchResultActionActivated(SearchResultView* view, |
| 153 int action_index, |
| 154 const ui::Event& event) { |
| 155 if (delegate_ && view->result()) { |
| 156 delegate_->InvokeResultAction( |
| 157 *(view->result()), action_index, event.flags()); |
| 158 } |
| 159 } |
| 160 |
| 160 } // namespace app_list | 161 } // namespace app_list |
| OLD | NEW |