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

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

Issue 120553004: app_list: Fix SearchResultView result_ usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert unnecessary change Created 6 years, 11 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 | « no previous file | 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/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
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
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) {
329 ui::MenuModel* menu_model = result_->GetContextMenuModel(); 334 ui::MenuModel* menu_model = result_ ? result_->GetContextMenuModel() : NULL;
Matt Giuca 2014/01/07 22:55:08 Optional nit: It seems a little weird in the NULL
xiyuan 2014/01/07 23:12:44 Done.
330 if (!menu_model) 335 if (!menu_model)
331 return; 336 return;
332 337
333 context_menu_runner_.reset(new views::MenuRunner(menu_model)); 338 context_menu_runner_.reset(new views::MenuRunner(menu_model));
334 if (context_menu_runner_->RunMenuAt( 339 if (context_menu_runner_->RunMenuAt(
335 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), 340 GetWidget(), NULL, gfx::Rect(point, gfx::Size()),
336 views::MenuItemView::TOPLEFT, source_type, 341 views::MenuItemView::TOPLEFT, source_type,
337 views::MenuRunner::HAS_MNEMONICS) == 342 views::MenuRunner::HAS_MNEMONICS) ==
338 views::MenuRunner::MENU_DELETED) 343 views::MenuRunner::MENU_DELETED)
339 return; 344 return;
340 } 345 }
341 346
342 } // namespace app_list 347 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698