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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h"
7 #include "base/logging.h"
8 #include "chrome/browser/download/download_item_model.h"
9 #include "chrome/browser/ui/gtk/download/download_item_gtk.h"
10 #include "content/public/browser/page_navigator.h"
11 #include "ui/gfx/point.h"
13 DownloadShelfContextMenuGtk::DownloadShelfContextMenuGtk(
14 DownloadItemGtk* download_item,
15 content::PageNavigator* navigator)
16 : DownloadShelfContextMenu(download_item->download(), navigator),
17 download_item_gtk_(download_item) {
20 DownloadShelfContextMenuGtk::~DownloadShelfContextMenuGtk() {}
22 void DownloadShelfContextMenuGtk::Popup(GtkWidget* widget,
23 GdkEventButton* event) {
24 ui::SimpleMenuModel* menu_model = GetMenuModel();
25 // Popup() should never be called after the DownloadItem is destroyed.
28 menu_.reset(new MenuGtk(this, menu_model));
31 menu_->PopupForWidget(widget, event->button, event->time);
33 menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root),
37 void DownloadShelfContextMenuGtk::StoppedShowing() {
38 download_item_gtk_->menu_showing_ = false;
39 gtk_widget_queue_draw(download_item_gtk_->menu_button_);
42 GtkWidget* DownloadShelfContextMenuGtk::GetImageForCommandId(
43 int command_id) const {
44 const char* stock = NULL;
47 case OPEN_WHEN_COMPLETE:
48 stock = GTK_STOCK_OPEN;
52 stock = GTK_STOCK_CANCEL;
55 case ALWAYS_OPEN_TYPE:
64 return stock ? gtk_image_new_from_stock(stock, GTK_ICON_SIZE_MENU) : NULL;