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.
5 #include "ui/message_center/views/message_view_context_menu_controller.h"
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"
13 namespace message_center
{
15 MessageViewContextMenuController::MessageViewContextMenuController(
16 MessageCenterController
* controller
)
17 : controller_(controller
) {
20 MessageViewContextMenuController::~MessageViewContextMenuController() {
23 void MessageViewContextMenuController::ShowContextMenuForView(
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()));
32 if (!menu_model
|| menu_model
->GetItemCount() == 0)
35 views::MenuRunner
menu_runner(menu_model
.get(),
36 views::MenuRunner::HAS_MNEMONICS
);
38 ignore_result(menu_runner
.RunMenuAt(source
->GetWidget()->GetTopLevelWidget(),
40 gfx::Rect(point
, gfx::Size()),
41 views::MENU_ANCHOR_TOPRIGHT
,
45 } // namespace message_center