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