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

Side by Side Diff: ui/message_center/views/message_view.cc

Issue 114323002: Fixes the context menu for a notification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix2 Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/message_center/views/message_view.h" 5 #include "ui/message_center/views/message_view.h"
6 6
7 #include "grit/ui_resources.h" 7 #include "grit/ui_resources.h"
8 #include "grit/ui_strings.h" 8 #include "grit/ui_strings.h"
9 #include "ui/base/accessibility/accessible_view_state.h" 9 #include "ui/base/accessibility/accessible_view_state.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/models/simple_menu_model.h" 11 #include "ui/base/models/simple_menu_model.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/message_center/message_center.h" 15 #include "ui/message_center/message_center.h"
16 #include "ui/message_center/message_center_style.h" 16 #include "ui/message_center/message_center_style.h"
17 #include "ui/message_center/message_center_util.h" 17 #include "ui/message_center/message_center_util.h"
18 #include "ui/message_center/views/padded_button.h" 18 #include "ui/message_center/views/padded_button.h"
19 #include "ui/views/background.h" 19 #include "ui/views/background.h"
20 #include "ui/views/context_menu_controller.h"
21 #include "ui/views/controls/button/image_button.h" 20 #include "ui/views/controls/button/image_button.h"
22 #include "ui/views/controls/menu/menu_runner.h"
23 #include "ui/views/controls/scroll_view.h" 21 #include "ui/views/controls/scroll_view.h"
22 #include "ui/views/focus/focus_manager.h"
24 #include "ui/views/painter.h" 23 #include "ui/views/painter.h"
25 #include "ui/views/shadow_border.h" 24 #include "ui/views/shadow_border.h"
26 #include "ui/views/widget/widget.h"
27 25
28 namespace { 26 namespace {
29 27
30 const int kCloseIconTopPadding = 5; 28 const int kCloseIconTopPadding = 5;
31 const int kCloseIconRightPadding = 5; 29 const int kCloseIconRightPadding = 5;
32 30
33 const int kShadowOffset = 1; 31 const int kShadowOffset = 1;
34 const int kShadowBlur = 4; 32 const int kShadowBlur = 4;
35 33
36 // Menu constants
37 const int kTogglePermissionCommand = 0;
38 const int kShowSettingsCommand = 1;
39
40 // A dropdown menu for notifications.
41 class MenuModel : public ui::SimpleMenuModel,
42 public ui::SimpleMenuModel::Delegate {
43 public:
44 MenuModel(message_center::MessageViewController* controller,
45 message_center::NotifierId notifier_id,
46 const string16& display_source);
47 virtual ~MenuModel();
48
49 // Overridden from ui::SimpleMenuModel::Delegate:
50 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
51 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
52 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
53 virtual bool GetAcceleratorForCommandId(
54 int command_id,
55 ui::Accelerator* accelerator) OVERRIDE;
56 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
57
58 private:
59 message_center::MessageViewController* controller_;
60 message_center::NotifierId notifier_id_;
61 DISALLOW_COPY_AND_ASSIGN(MenuModel);
62 };
63
64 MenuModel::MenuModel(message_center::MessageViewController* controller,
65 message_center::NotifierId notifier_id,
66 const string16& display_source)
67 : ui::SimpleMenuModel(this),
68 controller_(controller),
69 notifier_id_(notifier_id) {
70 // Add 'disable notifications' menu item.
71 if (!display_source.empty()) {
72 AddItem(kTogglePermissionCommand,
73 l10n_util::GetStringFUTF16(IDS_MESSAGE_CENTER_NOTIFIER_DISABLE,
74 display_source));
75 }
76 // Add settings menu item.
77 AddItem(kShowSettingsCommand,
78 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS));
79 }
80
81 MenuModel::~MenuModel() {
82 }
83
84 bool MenuModel::IsItemForCommandIdDynamic(int command_id) const {
85 return false;
86 }
87
88 bool MenuModel::IsCommandIdChecked(int command_id) const {
89 return false;
90 }
91
92 bool MenuModel::IsCommandIdEnabled(int command_id) const {
93 return true;
94 }
95
96 bool MenuModel::GetAcceleratorForCommandId(int command_id,
97 ui::Accelerator* accelerator) {
98 return false;
99 }
100
101 void MenuModel::ExecuteCommand(int command_id, int event_flags) {
102 switch (command_id) {
103 case kTogglePermissionCommand:
104 controller_->DisableNotificationsFromThisSource(notifier_id_);
105 break;
106 case kShowSettingsCommand:
107 controller_->ShowNotifierSettingsBubble();
108 break;
109 default:
110 NOTREACHED();
111 }
112 }
113
114 } // namespace 34 } // namespace
115 35
116 namespace message_center { 36 namespace message_center {
117 37
118 class MessageViewContextMenuController : public views::ContextMenuController {
119 public:
120 MessageViewContextMenuController(MessageViewController* controller,
121 const NotifierId& notifier_id,
122 const string16& display_source);
123 virtual ~MessageViewContextMenuController();
124
125 protected:
126 // Overridden from views::ContextMenuController:
127 virtual void ShowContextMenuForView(views::View* source,
128 const gfx::Point& point,
129 ui::MenuSourceType source_type) OVERRIDE;
130
131 MessageViewController* controller_; // Weak, owns us.
132 NotifierId notifier_id_;
133 string16 display_source_;
134 };
135
136 MessageViewContextMenuController::MessageViewContextMenuController(
137 MessageViewController* controller,
138 const NotifierId& notifier_id,
139 const string16& display_source)
140 : controller_(controller),
141 notifier_id_(notifier_id),
142 display_source_(display_source) {
143 }
144
145 MessageViewContextMenuController::~MessageViewContextMenuController() {
146 }
147
148 void MessageViewContextMenuController::ShowContextMenuForView(
149 views::View* source,
150 const gfx::Point& point,
151 ui::MenuSourceType source_type) {
152 MenuModel menu_model(controller_, notifier_id_, display_source_);
153 if (menu_model.GetItemCount() == 0)
154 return;
155
156 views::MenuRunner menu_runner(&menu_model);
157
158 ignore_result(menu_runner.RunMenuAt(
159 source->GetWidget()->GetTopLevelWidget(),
160 NULL,
161 gfx::Rect(point, gfx::Size()),
162 views::MenuItemView::TOPRIGHT,
163 source_type,
164 views::MenuRunner::HAS_MNEMONICS));
165 }
166
167 MessageView::MessageView(MessageViewController* controller, 38 MessageView::MessageView(MessageViewController* controller,
168 const std::string& notification_id, 39 const std::string& notification_id,
169 const NotifierId& notifier_id, 40 const NotifierId& notifier_id,
170 const string16& display_source) 41 const string16& display_source)
171 : controller_(controller), 42 : controller_(controller),
172 notification_id_(notification_id), 43 notification_id_(notification_id),
173 notifier_id_(notifier_id), 44 notifier_id_(notifier_id),
174 context_menu_controller_(
175 new MessageViewContextMenuController(controller,
176 notifier_id,
177 display_source)),
178 background_view_(NULL), 45 background_view_(NULL),
179 scroller_(NULL) { 46 scroller_(NULL),
47 display_source_(display_source) {
180 SetFocusable(true); 48 SetFocusable(true);
181 set_context_menu_controller(context_menu_controller_.get());
182 49
183 // Create the opaque background that's above the view's shadow. 50 // Create the opaque background that's above the view's shadow.
184 background_view_ = new views::View(); 51 background_view_ = new views::View();
185 background_view_->set_background( 52 background_view_->set_background(
186 views::Background::CreateSolidBackground(kNotificationBackgroundColor)); 53 views::Background::CreateSolidBackground(kNotificationBackgroundColor));
187 AddChildView(background_view_); 54 AddChildView(background_view_);
188 55
189 PaddedButton *close = new PaddedButton(this); 56 PaddedButton *close = new PaddedButton(this);
190 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); 57 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding);
191 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); 58 close->SetNormalImage(IDR_NOTIFICATION_CLOSE);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (sender == close_button()) { 192 if (sender == close_button()) {
326 controller_->RemoveNotification(notification_id_, true); // By user. 193 controller_->RemoveNotification(notification_id_, true); // By user.
327 } 194 }
328 } 195 }
329 196
330 void MessageView::OnSlideOut() { 197 void MessageView::OnSlideOut() {
331 controller_->RemoveNotification(notification_id_, true); // By user. 198 controller_->RemoveNotification(notification_id_, true); // By user.
332 } 199 }
333 200
334 } // namespace message_center 201 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_view.h ('k') | ui/message_center/views/message_view_context_menu_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698