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

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

Issue 12326091: Made notification center notifications collapsed and expandable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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/message_view.h" 5 #include "ui/message_center/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/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/base/models/simple_menu_model.h" 10 #include "ui/base/models/simple_menu_model.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/compositor/scoped_layer_animation_settings.h" 12 #include "ui/compositor/scoped_layer_animation_settings.h"
13 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
14 #include "ui/views/controls/button/image_button.h" 14 #include "ui/views/controls/button/image_button.h"
15 #include "ui/views/controls/menu/menu_model_adapter.h" 15 #include "ui/views/controls/menu/menu_model_adapter.h"
16 #include "ui/views/controls/menu/menu_runner.h" 16 #include "ui/views/controls/menu/menu_runner.h"
17 #include "ui/views/controls/scroll_view.h" 17 #include "ui/views/controls/scroll_view.h"
18 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
19 19
20 namespace { 20 namespace {
21 21
22 const int kCloseButtonSize = 29; 22 const int kControlButtonSize = 29;
23 const int kCloseIconTopPadding = 5; 23 const int kCloseIconTopPadding = 5;
24 const int kCloseIconRightPadding = 5; 24 const int kCloseIconRightPadding = 5;
25 const int kExpandIconBottomPadding = 8;
26 const int kExpandIconRightPadding = 11;
25 27
26 // ControlButtons are ImageButtons whose image can be padded within the button. 28 // ControlButtons are ImageButtons whose image can be padded within the button.
27 // This allows the creation of buttons like the notification close and expand 29 // This allows the creation of buttons like the notification close and expand
28 // buttons whose clickable areas extends beyond their image areas 30 // buttons whose clickable areas extends beyond their image areas
29 // (<http://crbug.com/168822>) without the need to create and maintain 31 // (<http://crbug.com/168822>) without the need to create and maintain
30 // corresponding resource images with alpha padding. In the future, this class 32 // corresponding resource images with alpha padding. In the future, this class
31 // will also allow for buttons whose touch areas extend beyond their clickable 33 // will also allow for buttons whose touch areas extend beyond their clickable
32 // area (<http://crbug.com/168856>). 34 // area (<http://crbug.com/168856>).
33 class ControlButton : public views::ImageButton { 35 class ControlButton : public views::ImageButton {
34 public: 36 public:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 resource_id)); 86 resource_id));
85 } 87 }
86 88
87 void ControlButton::SetPressedImage(int resource_id) { 89 void ControlButton::SetPressedImage(int resource_id) {
88 SetImage(views::CustomButton::STATE_PRESSED, 90 SetImage(views::CustomButton::STATE_PRESSED,
89 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 91 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
90 resource_id)); 92 resource_id));
91 } 93 }
92 94
93 gfx::Size ControlButton::GetPreferredSize() { 95 gfx::Size ControlButton::GetPreferredSize() {
94 return gfx::Size(kCloseButtonSize, kCloseButtonSize); 96 return gfx::Size(kControlButtonSize, kControlButtonSize);
95 } 97 }
96 98
97 void ControlButton::OnPaint(gfx::Canvas* canvas) { 99 void ControlButton::OnPaint(gfx::Canvas* canvas) {
98 // This is the same implementation as ImageButton::OnPaint except 100 // This is the same implementation as ImageButton::OnPaint except
99 // that it calls ComputePaddedImagePaintPosition() instead of 101 // that it calls ComputePaddedImagePaintPosition() instead of
100 // ComputeImagePaintPosition(), in effect overriding that private method. 102 // ComputeImagePaintPosition(), in effect overriding that private method.
101 View::OnPaint(canvas); 103 View::OnPaint(canvas);
102 gfx::ImageSkia image = GetImageToPaint(); 104 gfx::ImageSkia image = GetImageToPaint();
103 if (!image.isNull()) { 105 if (!image.isNull()) {
104 gfx::Point position = ComputePaddedImagePaintPosition(image); 106 gfx::Point position = ComputePaddedImagePaintPosition(image);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 Notification notification_; 220 Notification notification_;
219 221
220 DISALLOW_COPY_AND_ASSIGN(WebNotificationMenuModel); 222 DISALLOW_COPY_AND_ASSIGN(WebNotificationMenuModel);
221 }; 223 };
222 224
223 MessageView::MessageView( 225 MessageView::MessageView(
224 NotificationList::Delegate* list_delegate, 226 NotificationList::Delegate* list_delegate,
225 const Notification& notification) 227 const Notification& notification)
226 : list_delegate_(list_delegate), 228 : list_delegate_(list_delegate),
227 notification_(notification), 229 notification_(notification),
228 scroller_(NULL) { 230 scroller_(NULL),
231 expanded_(false) {
229 ControlButton *close = new ControlButton(this); 232 ControlButton *close = new ControlButton(this);
230 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding); 233 close->SetPadding(-kCloseIconRightPadding, kCloseIconTopPadding);
231 close->SetNormalImage(IDR_NOTIFICATION_CLOSE); 234 close->SetNormalImage(IDR_NOTIFICATION_CLOSE);
232 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER); 235 close->SetHoveredImage(IDR_NOTIFICATION_CLOSE_HOVER);
233 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED); 236 close->SetPressedImage(IDR_NOTIFICATION_CLOSE_PRESSED);
237 close->set_owned_by_client();
dharcourt 2013/02/23 04:32:00 This isn't strictly needed because close_button_ w
234 close_button_.reset(close); 238 close_button_.reset(close);
239
240 ControlButton *expand = new ControlButton(this);
241 expand->SetPadding(-kExpandIconRightPadding, -kExpandIconBottomPadding);
242 expand->SetNormalImage(IDR_NOTIFICATIONS_EXPAND);
243 expand->SetHoveredImage(IDR_NOTIFICATIONS_EXPAND_HOVER);
244 expand->SetPressedImage(IDR_NOTIFICATIONS_EXPAND_PRESSED);
245 expand->set_owned_by_client();
246 expand_button_.reset(expand);
235 } 247 }
236 248
237 MessageView::MessageView() { 249 MessageView::MessageView() {
238 } 250 }
239 251
240 MessageView::~MessageView() { 252 MessageView::~MessageView() {
241 } 253 }
242 254
243 bool MessageView::OnMousePressed(const ui::MouseEvent& event) { 255 bool MessageView::OnMousePressed(const ui::MouseEvent& event) {
244 if (event.flags() & ui::EF_RIGHT_MOUSE_BUTTON) { 256 if (event.flags() & ui::EF_RIGHT_MOUSE_BUTTON) {
(...skipping 27 matching lines...) Expand all
272 284
273 if (scroller_) 285 if (scroller_)
274 scroller_->OnGestureEvent(event); 286 scroller_->OnGestureEvent(event);
275 event->SetHandled(); 287 event->SetHandled();
276 } 288 }
277 289
278 void MessageView::ButtonPressed(views::Button* sender, 290 void MessageView::ButtonPressed(views::Button* sender,
279 const ui::Event& event) { 291 const ui::Event& event) {
280 if (sender == close_button()) 292 if (sender == close_button())
281 list_delegate_->SendRemoveNotification(notification_.id); 293 list_delegate_->SendRemoveNotification(notification_.id);
294 else if (sender == expand_button())
295 SetExpanded(!expanded_);
296 }
297
298 bool MessageView::IsExpanded() {
299 return expanded_;
300 }
301
302 void MessageView::SetExpanded(bool expanded) {
303 expanded_ = expanded;
282 } 304 }
283 305
284 void MessageView::ShowMenu(gfx::Point screen_location) { 306 void MessageView::ShowMenu(gfx::Point screen_location) {
285 WebNotificationMenuModel menu_model(list_delegate_, notification_); 307 WebNotificationMenuModel menu_model(list_delegate_, notification_);
286 if (menu_model.GetItemCount() == 0) 308 if (menu_model.GetItemCount() == 0)
287 return; 309 return;
288 310
289 views::MenuModelAdapter menu_model_adapter(&menu_model); 311 views::MenuModelAdapter menu_model_adapter(&menu_model);
290 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); 312 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu());
291 313
292 views::View::ConvertPointToScreen(this, &screen_location); 314 views::View::ConvertPointToScreen(this, &screen_location);
293 ignore_result(menu_runner.RunMenuAt( 315 ignore_result(menu_runner.RunMenuAt(
294 GetWidget()->GetTopLevelWidget(), 316 GetWidget()->GetTopLevelWidget(),
295 NULL, 317 NULL,
296 gfx::Rect(screen_location, gfx::Size()), 318 gfx::Rect(screen_location, gfx::Size()),
297 views::MenuItemView::TOPRIGHT, 319 views::MenuItemView::TOPRIGHT,
298 views::MenuRunner::HAS_MNEMONICS)); 320 views::MenuRunner::HAS_MNEMONICS));
299 } 321 }
300 322
301 void MessageView::OnSlideOut() { 323 void MessageView::OnSlideOut() {
302 list_delegate_->SendRemoveNotification(notification_.id); 324 list_delegate_->SendRemoveNotification(notification_.id);
303 } 325 }
304 326
305 } // namespace message_center 327 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698