| 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" |
| 11 #include "ui/app_list/search_result_view.h" | 11 #include "ui/app_list/search_result_view.h" |
| 12 #include "ui/app_list/search_result_list_view_delegate.h" | 12 #include "ui/app_list/search_result_list_view_delegate.h" |
| 13 #include "ui/base/event.h" |
| 13 #include "ui/views/layout/box_layout.h" | 14 #include "ui/views/layout/box_layout.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const int kMaxResults = 6; | 18 const int kMaxResults = 6; |
| 18 | 19 |
| 19 } // namespace | 20 } // namespace |
| 20 | 21 |
| 21 namespace app_list { | 22 namespace app_list { |
| 22 | 23 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 bool SearchResultListView::IsResultViewSelected( | 67 bool SearchResultListView::IsResultViewSelected( |
| 67 const SearchResultView* result_view) const { | 68 const SearchResultView* result_view) const { |
| 68 if (selected_index_ < 0) | 69 if (selected_index_ < 0) |
| 69 return false; | 70 return false; |
| 70 | 71 |
| 71 return static_cast<const SearchResultView*>(child_at(selected_index_)) == | 72 return static_cast<const SearchResultView*>(child_at(selected_index_)) == |
| 72 result_view; | 73 result_view; |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool SearchResultListView::OnKeyPressed(const views::KeyEvent& event) { | 76 bool SearchResultListView::OnKeyPressed(const ui::KeyEvent& event) { |
| 76 switch (event.key_code()) { | 77 switch (event.key_code()) { |
| 77 case ui::VKEY_UP: | 78 case ui::VKEY_UP: |
| 78 SetSelectedIndex(std::max(selected_index_ - 1, 0)); | 79 SetSelectedIndex(std::max(selected_index_ - 1, 0)); |
| 79 return true; | 80 return true; |
| 80 case ui::VKEY_DOWN: | 81 case ui::VKEY_DOWN: |
| 81 SetSelectedIndex(std::min(selected_index_ + 1, last_visible_index_)); | 82 SetSelectedIndex(std::min(selected_index_ + 1, last_visible_index_)); |
| 82 return true; | 83 return true; |
| 83 case ui::VKEY_RETURN: | 84 case ui::VKEY_RETURN: |
| 84 if (selected_index_ >= 0) | 85 if (selected_index_ >= 0) { |
| 85 ButtonPressed(GetResultViewAt(selected_index_), event); | 86 // TODO(beng): remove once views::Event is gone. |
| 87 views::MouseEvent synthetic_event( |
| 88 ui::ET_MOUSE_RELEASED, 0, 0, |
| 89 ui::EF_LEFT_MOUSE_BUTTON | event.flags()); |
| 90 ButtonPressed(GetResultViewAt(selected_index_), synthetic_event); |
| 91 } |
| 86 return true; | 92 return true; |
| 87 default: | 93 default: |
| 88 break; | 94 break; |
| 89 } | 95 } |
| 90 return false; | 96 return false; |
| 91 } | 97 } |
| 92 | 98 |
| 93 SearchResultView* SearchResultListView::GetResultViewAt(int index) { | 99 SearchResultView* SearchResultListView::GetResultViewAt(int index) { |
| 94 DCHECK(index >= 0 && index < child_count()); | 100 DCHECK(index >= 0 && index < child_count()); |
| 95 return static_cast<SearchResultView*>(child_at(index)); | 101 return static_cast<SearchResultView*>(child_at(index)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 GetResultViewAt(i)->ClearResultNoRepaint(); | 156 GetResultViewAt(i)->ClearResultNoRepaint(); |
| 151 | 157 |
| 152 ScheduleUpdate(); | 158 ScheduleUpdate(); |
| 153 } | 159 } |
| 154 | 160 |
| 155 void SearchResultListView::ListItemsChanged(size_t start, size_t count) { | 161 void SearchResultListView::ListItemsChanged(size_t start, size_t count) { |
| 156 ScheduleUpdate(); | 162 ScheduleUpdate(); |
| 157 } | 163 } |
| 158 | 164 |
| 159 } // namespace app_list | 165 } // namespace app_list |
| OLD | NEW |