| 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/views/search_result_view.h" | 5 #include "ui/app_list/views/search_result_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
| 10 #include "ui/app_list/search_result.h" | 10 #include "ui/app_list/search_result.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const int progress_height = progress_bar_->GetPreferredSize().height(); | 165 const int progress_height = progress_bar_->GetPreferredSize().height(); |
| 166 const gfx::Rect progress_bounds( | 166 const gfx::Rect progress_bounds( |
| 167 rect.right() - kActionButtonRightMargin - progress_width, | 167 rect.right() - kActionButtonRightMargin - progress_width, |
| 168 rect.y() + (rect.height() - progress_height) / 2, | 168 rect.y() + (rect.height() - progress_height) / 2, |
| 169 progress_width, | 169 progress_width, |
| 170 progress_height); | 170 progress_height); |
| 171 progress_bar_->SetBoundsRect(progress_bounds); | 171 progress_bar_->SetBoundsRect(progress_bounds); |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool SearchResultView::OnKeyPressed(const ui::KeyEvent& event) { | 174 bool SearchResultView::OnKeyPressed(const ui::KeyEvent& event) { |
| 175 DCHECK(result_); | 175 // |result_| could be NULL when result list is changing. |
| 176 if (!result_) |
| 177 return false; |
| 176 | 178 |
| 177 switch (event.key_code()) { | 179 switch (event.key_code()) { |
| 178 case ui::VKEY_TAB: { | 180 case ui::VKEY_TAB: { |
| 179 int new_selected = actions_view_->selected_action() | 181 int new_selected = actions_view_->selected_action() |
| 180 + (event.IsShiftDown() ? -1 : 1); | 182 + (event.IsShiftDown() ? -1 : 1); |
| 181 actions_view_->SetSelectedAction(new_selected); | 183 actions_view_->SetSelectedAction(new_selected); |
| 182 return actions_view_->IsValidActionIndex(new_selected); | 184 return actions_view_->IsValidActionIndex(new_selected); |
| 183 } | 185 } |
| 184 case ui::VKEY_RETURN: { | 186 case ui::VKEY_RETURN: { |
| 185 int selected = actions_view_->selected_action(); | 187 int selected = actions_view_->selected_action(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 : SearchResult::Actions()); | 299 : SearchResult::Actions()); |
| 298 } | 300 } |
| 299 | 301 |
| 300 void SearchResultView::OnIsInstallingChanged() { | 302 void SearchResultView::OnIsInstallingChanged() { |
| 301 const bool is_installing = result_ && result_->is_installing(); | 303 const bool is_installing = result_ && result_->is_installing(); |
| 302 actions_view_->SetVisible(!is_installing); | 304 actions_view_->SetVisible(!is_installing); |
| 303 progress_bar_->SetVisible(is_installing); | 305 progress_bar_->SetVisible(is_installing); |
| 304 } | 306 } |
| 305 | 307 |
| 306 void SearchResultView::OnPercentDownloadedChanged() { | 308 void SearchResultView::OnPercentDownloadedChanged() { |
| 307 progress_bar_->SetValue(result_->percent_downloaded() / 100.0); | 309 progress_bar_->SetValue(result_ ? result_->percent_downloaded() / 100.0 : 0); |
| 308 } | 310 } |
| 309 | 311 |
| 310 void SearchResultView::OnItemInstalled() { | 312 void SearchResultView::OnItemInstalled() { |
| 311 delegate_->OnSearchResultInstalled(this); | 313 delegate_->OnSearchResultInstalled(this); |
| 312 } | 314 } |
| 313 | 315 |
| 314 void SearchResultView::OnItemUninstalled() { | 316 void SearchResultView::OnItemUninstalled() { |
| 315 delegate_->OnSearchResultUninstalled(this); | 317 delegate_->OnSearchResultUninstalled(this); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void SearchResultView::OnSearchResultActionActivated(size_t index, | 320 void SearchResultView::OnSearchResultActionActivated(size_t index, |
| 319 int event_flags) { | 321 int event_flags) { |
| 320 DCHECK(result_); | 322 // |result_| could be NULL when result list is changing. |
| 323 if (!result_) |
| 324 return; |
| 325 |
| 321 DCHECK_LT(index, result_->actions().size()); | 326 DCHECK_LT(index, result_->actions().size()); |
| 322 | 327 |
| 323 delegate_->SearchResultActionActivated(this, index, event_flags); | 328 delegate_->SearchResultActionActivated(this, index, event_flags); |
| 324 } | 329 } |
| 325 | 330 |
| 326 void SearchResultView::ShowContextMenuForView(views::View* source, | 331 void SearchResultView::ShowContextMenuForView(views::View* source, |
| 327 const gfx::Point& point, | 332 const gfx::Point& point, |
| 328 ui::MenuSourceType source_type) { | 333 ui::MenuSourceType source_type) { |
| 334 // |result_| could be NULL when result list is changing. |
| 335 if (!result_) |
| 336 return; |
| 337 |
| 329 ui::MenuModel* menu_model = result_->GetContextMenuModel(); | 338 ui::MenuModel* menu_model = result_->GetContextMenuModel(); |
| 330 if (!menu_model) | 339 if (!menu_model) |
| 331 return; | 340 return; |
| 332 | 341 |
| 333 context_menu_runner_.reset(new views::MenuRunner(menu_model)); | 342 context_menu_runner_.reset(new views::MenuRunner(menu_model)); |
| 334 if (context_menu_runner_->RunMenuAt( | 343 if (context_menu_runner_->RunMenuAt( |
| 335 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 344 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
| 336 views::MenuItemView::TOPLEFT, source_type, | 345 views::MenuItemView::TOPLEFT, source_type, |
| 337 views::MenuRunner::HAS_MNEMONICS) == | 346 views::MenuRunner::HAS_MNEMONICS) == |
| 338 views::MenuRunner::MENU_DELETED) | 347 views::MenuRunner::MENU_DELETED) |
| 339 return; | 348 return; |
| 340 } | 349 } |
| 341 | 350 |
| 342 } // namespace app_list | 351 } // namespace app_list |
| OLD | NEW |