OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_tile_item_view.h" | 5 #include "ui/app_list/views/search_result_tile_item_view.h" |
6 | 6 |
7 #include "ui/app_list/search_result.h" | 7 #include "ui/app_list/search_result.h" |
8 #include "ui/app_list/views/search_result_container_view.h" | 8 #include "ui/app_list/views/search_result_container_view.h" |
9 #include "ui/views/controls/menu/menu_runner.h" | 9 #include "ui/views/controls/menu/menu_runner.h" |
10 | 10 |
11 namespace app_list { | 11 namespace app_list { |
12 | 12 |
13 SearchResultTileItemView::SearchResultTileItemView( | 13 SearchResultTileItemView::SearchResultTileItemView( |
14 SearchResultContainerView* result_container) | 14 SearchResultContainerView* result_container) |
15 : result_container_(result_container), item_(NULL) { | 15 : result_container_(result_container), item_(NULL) { |
16 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a | 16 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a |
17 // non-null item makes the tile visible. | 17 // non-null item makes the tile visible. |
18 SetVisible(false); | 18 SetVisible(false); |
19 | 19 |
20 set_context_menu_controller(this); | 20 set_context_menu_controller(this); |
21 } | 21 } |
22 | 22 |
23 SearchResultTileItemView::~SearchResultTileItemView() { | 23 SearchResultTileItemView::~SearchResultTileItemView() { |
24 if (item_) | 24 if (item_) |
25 item_->RemoveObserver(this); | 25 item_->RemoveObserver(this); |
26 } | 26 } |
27 | 27 |
28 void SearchResultTileItemView::SetSearchResult(SearchResult* item) { | 28 void SearchResultTileItemView::SetSearchResult(SearchResult* item) { |
| 29 // Handle the case where this may be called from a nested run loop while its |
| 30 // context menu is showing. This cancels the menu (it's for the old item). |
| 31 context_menu_runner_.reset(); |
| 32 |
29 SetVisible(item != NULL); | 33 SetVisible(item != NULL); |
30 | 34 |
31 SearchResult* old_item = item_; | 35 SearchResult* old_item = item_; |
32 if (old_item) | 36 if (old_item) |
33 old_item->RemoveObserver(this); | 37 old_item->RemoveObserver(this); |
34 | 38 |
35 item_ = item; | 39 item_ = item; |
36 | 40 |
37 if (!item) | 41 if (!item) |
38 return; | 42 return; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // If RunMenuAt() fails, return immediately. This is future-proofing for | 97 // If RunMenuAt() fails, return immediately. This is future-proofing for |
94 // adding code after this call. | 98 // adding code after this call. |
95 if (context_menu_runner_->RunMenuAt( | 99 if (context_menu_runner_->RunMenuAt( |
96 GetWidget(), nullptr, gfx::Rect(point, gfx::Size()), | 100 GetWidget(), nullptr, gfx::Rect(point, gfx::Size()), |
97 views::MENU_ANCHOR_TOPLEFT, | 101 views::MENU_ANCHOR_TOPLEFT, |
98 source_type) == views::MenuRunner::MENU_DELETED) | 102 source_type) == views::MenuRunner::MENU_DELETED) |
99 return; | 103 return; |
100 } | 104 } |
101 | 105 |
102 } // namespace app_list | 106 } // namespace app_list |
OLD | NEW |