OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" | 5 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/download/download_item_model.h" | 9 #include "chrome/browser/download/download_item_model.h" |
10 #include "content/browser/download/download_item.h" | 10 #include "content/browser/download/download_item.h" |
11 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
12 #include "ui/views/controls/menu/menu_item_view.h" | 12 #include "ui/views/controls/menu/menu_item_view.h" |
13 #include "ui/views/controls/menu/menu_model_adapter.h" | 13 #include "ui/views/controls/menu/menu_model_adapter.h" |
14 #include "ui/views/controls/menu/menu_runner.h" | 14 #include "ui/views/controls/menu/menu_runner.h" |
15 | 15 |
16 DownloadShelfContextMenuView::DownloadShelfContextMenuView( | 16 DownloadShelfContextMenuView::DownloadShelfContextMenuView( |
17 BaseDownloadItemModel* model) | 17 BaseDownloadItemModel* model) |
18 : DownloadShelfContextMenu(model) { | 18 : DownloadShelfContextMenu(model) { |
19 DCHECK(model); | 19 DCHECK(model); |
20 } | 20 } |
21 | 21 |
22 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} | 22 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} |
23 | 23 |
24 bool DownloadShelfContextMenuView::Run(views::Widget* parent_widget, | 24 void DownloadShelfContextMenuView::Run(views::Widget* parent_widget, |
25 const gfx::Rect& rect) { | 25 const gfx::Rect& rect) { |
26 views::MenuModelAdapter menu_model_adapter(GetMenuModel()); | 26 views::MenuModelAdapter menu_model_adapter(GetMenuModel()); |
27 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); | 27 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); |
28 | 28 |
29 // The menu's alignment is determined based on the UI layout. | 29 // The menu's alignment is determined based on the UI layout. |
30 views::MenuItemView::AnchorPosition position; | 30 views::MenuItemView::AnchorPosition position; |
31 if (base::i18n::IsRTL()) | 31 if (base::i18n::IsRTL()) |
32 position = views::MenuItemView::TOPRIGHT; | 32 position = views::MenuItemView::TOPRIGHT; |
33 else | 33 else |
34 position = views::MenuItemView::TOPLEFT; | 34 position = views::MenuItemView::TOPLEFT; |
35 return menu_runner_->RunMenuAt( | 35 |
| 36 // The return value of RunMenuAt indicates whether the MenuRunner was deleted |
| 37 // while running the menu, which indicates that the containing view may have |
| 38 // been deleted. We ignore the return value because our caller already assumes |
| 39 // that the view could be deleted by the time we return from here. |
| 40 ignore_result(menu_runner_->RunMenuAt( |
36 parent_widget, | 41 parent_widget, |
37 NULL, | 42 NULL, |
38 rect, | 43 rect, |
39 position, | 44 position, |
40 views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED; | 45 views::MenuRunner::HAS_MNEMONICS)); |
41 } | 46 } |
42 | |
43 void DownloadShelfContextMenuView::Stop() { | |
44 set_download_item(NULL); | |
45 } | |
OLD | NEW |