1 // Copyright 2013 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 "ui/message_center/views/message_view_context_menu_controller.h" 6 7 #include "ui/base/models/menu_model.h" 8 #include "ui/message_center/views/message_center_controller.h" 9 #include "ui/message_center/views/message_view.h" 10 #include "ui/views/controls/menu/menu_runner.h" 11 #include "ui/views/widget/widget.h" 12 13 namespace message_center { 14 15 MessageViewContextMenuController::MessageViewContextMenuController( 16 MessageCenterController* controller) 17 : controller_(controller) { 18 } 19 20 MessageViewContextMenuController::~MessageViewContextMenuController() { 21 } 22 23 void MessageViewContextMenuController::ShowContextMenuForView( 24 views::View* source, 25 const gfx::Point& point, 26 ui::MenuSourceType source_type) { 27 // Assumes that the target view has to be MessageView. 28 MessageView* message_view = static_cast<MessageView*>(source); 29 scoped_ptr<ui::MenuModel> menu_model(controller_->CreateMenuModel( 30 message_view->notifier_id(), message_view->display_source())); 31 32 if (!menu_model || menu_model->GetItemCount() == 0) 33 return; 34 35 views::MenuRunner menu_runner(menu_model.get()); 36 37 ignore_result(menu_runner.RunMenuAt(source->GetWidget()->GetTopLevelWidget(), 38 NULL, 39 gfx::Rect(point, gfx::Size()), 40 views::MENU_ANCHOR_TOPRIGHT, 41 source_type, 42 views::MenuRunner::HAS_MNEMONICS)); 43 } 44 45 } // namespace message_center 46