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

Side by Side Diff: chrome/browser/ui/views/download/download_shelf_context_menu_view.cc

Issue 2394123002: Views: Expose an on_closed callback via the MenuRunner constructor. (Closed)
Patch Set: default arg Created 4 years, 2 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
OLDNEW
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/geometry/point.h" 12 #include "ui/gfx/geometry/point.h"
13 #include "ui/views/controls/menu/menu_model_adapter.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 : DownloadShelfContextMenu(download_item) { 17 : DownloadShelfContextMenu(download_item) {
19 } 18 }
20 19
21 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} 20 DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {}
22 21
23 void DownloadShelfContextMenuView::Run( 22 void DownloadShelfContextMenuView::Run(
24 views::Widget* parent_widget, 23 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 const base::Closure& on_menu_closed_callback) { 26 const base::Closure& on_menu_closed_callback) {
28 ui::MenuModel* menu_model = GetMenuModel(); 27 ui::MenuModel* menu_model = GetMenuModel();
29 // Run() should not be getting called if the DownloadItem was destroyed. 28 // Run() should not be getting called if the DownloadItem was destroyed.
30 DCHECK(menu_model); 29 DCHECK(menu_model);
31 30
32 menu_model_adapter_.reset(new views::MenuModelAdapter( 31 menu_runner_.reset(new views::MenuRunner(
33 menu_model, base::Bind(&DownloadShelfContextMenuView::OnMenuClosed, 32 menu_model,
34 base::Unretained(this), on_menu_closed_callback))); 33 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU |
35 34 views::MenuRunner::ASYNC,
36 menu_runner_.reset(new views::MenuRunner(menu_model_adapter_->CreateMenu(), 35 base::Bind(&DownloadShelfContextMenuView::OnMenuClosed,
37 views::MenuRunner::HAS_MNEMONICS | 36 base::Unretained(this), on_menu_closed_callback)));
38 views::MenuRunner::CONTEXT_MENU |
39 views::MenuRunner::ASYNC));
40 37
41 // The menu's alignment is determined based on the UI layout. 38 // The menu's alignment is determined based on the UI layout.
42 views::MenuAnchorPosition position; 39 views::MenuAnchorPosition position;
43 if (base::i18n::IsRTL()) 40 if (base::i18n::IsRTL())
44 position = views::MENU_ANCHOR_TOPRIGHT; 41 position = views::MENU_ANCHOR_TOPRIGHT;
45 else 42 else
46 position = views::MENU_ANCHOR_TOPLEFT; 43 position = views::MENU_ANCHOR_TOPLEFT;
47 44
48 menu_runner_->RunMenuAt(parent_widget, NULL, rect, position, source_type); 45 menu_runner_->RunMenuAt(parent_widget, NULL, rect, position, source_type);
49 } 46 }
50 47
51 void DownloadShelfContextMenuView::OnMenuClosed( 48 void DownloadShelfContextMenuView::OnMenuClosed(
52 const base::Closure& on_menu_closed_callback) { 49 const base::Closure& on_menu_closed_callback) {
53 close_time_ = base::TimeTicks::Now(); 50 close_time_ = base::TimeTicks::Now();
54 51
55 // This must be ran before clearing |menu_model_adapter_| who owns the 52 // This must be run before clearing |menu_runner_| who owns the reference.
56 // reference.
57 if (!on_menu_closed_callback.is_null()) 53 if (!on_menu_closed_callback.is_null())
58 on_menu_closed_callback.Run(); 54 on_menu_closed_callback.Run();
59 55
60 menu_model_adapter_.reset();
61 menu_runner_.reset(); 56 menu_runner_.reset();
62 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698