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. 4 5#include "chrome/browser/ui/gtk/download/download_shelf_context_menu_gtk.h" 6 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" 12 13DownloadShelfContextMenuGtk::DownloadShelfContextMenuGtk( 14 DownloadItemGtk* download_item, 15 content::PageNavigator* navigator) 16 : DownloadShelfContextMenu(download_item->download(), navigator), 17 download_item_gtk_(download_item) { 18} 19 20DownloadShelfContextMenuGtk::~DownloadShelfContextMenuGtk() {} 21 22void DownloadShelfContextMenuGtk::Popup(GtkWidget* widget, 23 GdkEventButton* event) { 24 ui::SimpleMenuModel* menu_model = GetMenuModel(); 25 // Popup() should never be called after the DownloadItem is destroyed. 26 DCHECK(menu_model); 27 28 menu_.reset(new MenuGtk(this, menu_model)); 29 30 if (widget) 31 menu_->PopupForWidget(widget, event->button, event->time); 32 else 33 menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), 34 event->time); 35} 36 37void DownloadShelfContextMenuGtk::StoppedShowing() { 38 download_item_gtk_->menu_showing_ = false; 39 gtk_widget_queue_draw(download_item_gtk_->menu_button_); 40} 41 42GtkWidget* DownloadShelfContextMenuGtk::GetImageForCommandId( 43 int command_id) const { 44 const char* stock = NULL; 45 switch (command_id) { 46 case SHOW_IN_FOLDER: 47 case OPEN_WHEN_COMPLETE: 48 stock = GTK_STOCK_OPEN; 49 break; 50 51 case CANCEL: 52 stock = GTK_STOCK_CANCEL; 53 break; 54 55 case ALWAYS_OPEN_TYPE: 56 case TOGGLE_PAUSE: 57 stock = NULL; 58 break; 59 60 default: 61 NOTREACHED(); 62 break; 63 } 64 return stock ? gtk_image_new_from_stock(stock, GTK_ICON_SIZE_MENU) : NULL; 65} 66