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/public/browser/download_item.h" | 10 #include "content/public/browser/download_item.h" |
11 #include "content/public/browser/page_navigator.h" | 11 #include "content/public/browser/page_navigator.h" |
12 #include "ui/gfx/point.h" | 12 #include "ui/gfx/point.h" |
13 #include "ui/views/controls/menu/menu_item_view.h" | |
14 #include "ui/views/controls/menu/menu_runner.h" | 13 #include "ui/views/controls/menu/menu_runner.h" |
15 | 14 |
16 DownloadShelfContextMenuView::DownloadShelfContextMenuView( | 15 DownloadShelfContextMenuView::DownloadShelfContextMenuView( |
17 content::DownloadItem* download_item, | 16 content::DownloadItem* download_item, |
18 content::PageNavigator* navigator) | 17 content::PageNavigator* navigator) |
19 : DownloadShelfContextMenu(download_item, navigator) { | 18 : DownloadShelfContextMenu(download_item, navigator) { |
20 } | 19 } |
21 | 20 |
22 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} | 21 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} |
23 | 22 |
24 void DownloadShelfContextMenuView::Run(views::Widget* parent_widget, | 23 void DownloadShelfContextMenuView::Run(views::Widget* parent_widget, |
25 const gfx::Rect& rect, | 24 const gfx::Rect& rect, |
26 ui::MenuSourceType source_type) { | 25 ui::MenuSourceType source_type) { |
27 ui::MenuModel* menu_model = GetMenuModel(); | 26 ui::MenuModel* menu_model = GetMenuModel(); |
28 // Run() should not be getting called if the DownloadItem was destroyed. | 27 // Run() should not be getting called if the DownloadItem was destroyed. |
29 DCHECK(menu_model); | 28 DCHECK(menu_model); |
30 | 29 |
31 menu_runner_.reset(new views::MenuRunner(menu_model)); | 30 menu_runner_.reset(new views::MenuRunner(menu_model)); |
32 | 31 |
33 // The menu's alignment is determined based on the UI layout. | 32 // The menu's alignment is determined based on the UI layout. |
34 views::MenuItemView::AnchorPosition position; | 33 views::MenuAnchorPosition position; |
35 if (base::i18n::IsRTL()) | 34 if (base::i18n::IsRTL()) |
36 position = views::MenuItemView::TOPRIGHT; | 35 position = views::MENU_ANCHOR_TOPRIGHT; |
37 else | 36 else |
38 position = views::MenuItemView::TOPLEFT; | 37 position = views::MENU_ANCHOR_TOPLEFT; |
39 | 38 |
40 // The return value of RunMenuAt indicates whether the MenuRunner was deleted | 39 // The return value of RunMenuAt indicates whether the MenuRunner was deleted |
41 // while running the menu, which indicates that the containing view may have | 40 // while running the menu, which indicates that the containing view may have |
42 // been deleted. We ignore the return value because our caller already assumes | 41 // been deleted. We ignore the return value because our caller already assumes |
43 // that the view could be deleted by the time we return from here. | 42 // that the view could be deleted by the time we return from here. |
44 if (menu_runner_->RunMenuAt( | 43 if (menu_runner_->RunMenuAt( |
45 parent_widget, | 44 parent_widget, |
46 NULL, | 45 NULL, |
47 rect, | 46 rect, |
48 position, | 47 position, |
49 source_type, | 48 source_type, |
50 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 49 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
51 views::MenuRunner::MENU_DELETED) { | 50 views::MenuRunner::MENU_DELETED) { |
52 return; | 51 return; |
53 } | 52 } |
54 close_time_ = base::TimeTicks::Now(); | 53 close_time_ = base::TimeTicks::Now(); |
55 } | 54 } |
OLD | NEW |