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

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

Issue 13560002: Added padding below text in notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased & implemented rsesek suggestion. Created 7 years, 8 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/views/notification_view.h" 5 #include "ui/message_center/views/notification_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
(...skipping 14 matching lines...) Expand all
25 #include "ui/views/controls/label.h" 25 #include "ui/views/controls/label.h"
26 #include "ui/views/layout/box_layout.h" 26 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/layout/fill_layout.h" 27 #include "ui/views/layout/fill_layout.h"
28 28
29 namespace { 29 namespace {
30 30
31 // Dimensions. 31 // Dimensions.
32 const int kIconColumnWidth = message_center::kNotificationIconSize; 32 const int kIconColumnWidth = message_center::kNotificationIconSize;
33 const int kLegacyIconSize = 40; 33 const int kLegacyIconSize = 40;
34 const int kTextLeftPadding = kIconColumnWidth + 34 const int kTextLeftPadding = kIconColumnWidth +
35 message_center::kIconToTextPadding; 35 message_center::kIconToTextPadding;
36 const int kTextBottomPadding = 6; 36 const int kTextBottomPadding = 12;
37 const int kTextRightPadding = 23; 37 const int kTextRightPadding = 23;
38 const int kItemTitleToMessagePadding = 3; 38 const int kItemTitleToMessagePadding = 3;
39 const int kButtonHeight = 38; 39 const int kButtonHeight = 38;
40 const int kButtonHorizontalPadding = 16; 40 const int kButtonHorizontalPadding = 16;
41 const int kButtonVecticalPadding = 0; 41 const int kButtonVecticalPadding = 0;
42 const int kButtonIconTopPadding = 11; 42 const int kButtonIconTopPadding = 11;
43 const int kButtonIconToTitlePadding = 16; 43 const int kButtonIconToTitlePadding = 16;
44 const int kButtonTitleTopPadding = 0; 44 const int kButtonTitleTopPadding = 0;
45 45
46 const size_t kTitleCharacterLimit = 100; 46 const size_t kTitleCharacterLimit = 100;
47 const size_t kMessageCharacterLimit = 200; 47 const size_t kMessageCharacterLimit = 200;
48 48
49 // Notification colors. The text background colors below are used only to keep 49 // Notification colors. The text background colors below are used only to keep
50 // view::Label from modifying the text color and will not actually be drawn. 50 // view::Label from modifying the text color and will not actually be drawn.
51 // See view::Label's SetEnabledColor() and SetBackgroundColor() for details. 51 // See view::Label's SetEnabledColor() and SetBackgroundColor() for details.
52 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE; 52 const SkColor kRegularTextBackgroundColor = SK_ColorWHITE;
53 const SkColor kDimTextColor = SkColorSetRGB(136, 136, 136); 53 const SkColor kDimTextColor = SkColorSetRGB(136, 136, 136);
54 const SkColor kDimTextBackgroundColor = SK_ColorBLACK; 54 const SkColor kDimTextBackgroundColor = SK_ColorBLACK;
55 const SkColor kButtonSeparatorColor = SkColorSetRGB(234, 234, 234); 55 const SkColor kButtonSeparatorColor = SkColorSetRGB(234, 234, 234);
56 const SkColor kHoveredButtonBackgroundColor = SkColorSetRGB(243, 243, 243); 56 const SkColor kHoveredButtonBackgroundColor = SkColorSetRGB(243, 243, 243);
57 57
58 // Static. 58 // static
59 views::Background* MakeBackground( 59 views::Background* MakeBackground(
60 SkColor color = message_center::kNotificationBackgroundColor) { 60 SkColor color = message_center::kNotificationBackgroundColor) {
61 return views::Background::CreateSolidBackground(color); 61 return views::Background::CreateSolidBackground(color);
62 } 62 }
63 63
64 // Static. 64 // static
65 views::Border* MakeBorder(int top, 65 views::Border* MakeEmptyBorder(int top, int left, int bottom, int right) {
66 int bottom, 66 return views::Border::CreateEmptyBorder(top, left, bottom, right);
67 int left = kTextLeftPadding, 67 }
68 int right = kTextRightPadding, 68
69 SkColor color = 0x00000000) { 69 // static
70 return (color == 0x00000000) ? 70 views::Border* MakeTextBorder(int top, int bottom) {
71 views::Border::CreateEmptyBorder(top, left, bottom, right) : 71 return MakeEmptyBorder(top, kTextLeftPadding, bottom, kTextRightPadding);
72 views::Border::CreateSolidSidedBorder(top, left, bottom, right, color); 72 }
73
74 // static
75 views::Border* MakeSeparatorBorder(int top, int left, SkColor color) {
76 return views::Border::CreateSolidSidedBorder(top, left, 0, 0, color);
73 } 77 }
74 78
75 // ContainerView /////////////////////////////////////////////////////////////// 79 // ContainerView ///////////////////////////////////////////////////////////////
76 80
77 // ContainerViews are vertical BoxLayout views that propagates their childrens' 81 // ContainerViews are vertical BoxLayout views that propagates their childrens'
78 // ChildPreferredSizeChanged() and ChildVisibilityChanged() calls. 82 // ChildPreferredSizeChanged() and ChildVisibilityChanged() calls.
79 class ContainerView : public views::View { 83 class ContainerView : public views::View {
80 public: 84 public:
81 ContainerView(); 85 ContainerView();
82 virtual ~ContainerView(); 86 virtual ~ContainerView();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 delete icon_; // This removes the icon from this view's children. 274 delete icon_; // This removes the icon from this view's children.
271 if (image.isNull()) { 275 if (image.isNull()) {
272 icon_ = NULL; 276 icon_ = NULL;
273 } else { 277 } else {
274 icon_ = new views::ImageView(); 278 icon_ = new views::ImageView();
275 icon_->SetImageSize(gfx::Size(message_center::kNotificationButtonIconSize, 279 icon_->SetImageSize(gfx::Size(message_center::kNotificationButtonIconSize,
276 message_center::kNotificationButtonIconSize)); 280 message_center::kNotificationButtonIconSize));
277 icon_->SetImage(image); 281 icon_->SetImage(image);
278 icon_->SetHorizontalAlignment(views::ImageView::LEADING); 282 icon_->SetHorizontalAlignment(views::ImageView::LEADING);
279 icon_->SetVerticalAlignment(views::ImageView::LEADING); 283 icon_->SetVerticalAlignment(views::ImageView::LEADING);
280 icon_->set_border(MakeBorder(kButtonIconTopPadding, 0, 0, 0)); 284 icon_->set_border(MakeEmptyBorder(kButtonIconTopPadding, 0, 0, 0));
281 AddChildViewAt(icon_, 0); 285 AddChildViewAt(icon_, 0);
282 } 286 }
283 } 287 }
284 288
285 void NotificationButton::SetTitle(const string16& title) { 289 void NotificationButton::SetTitle(const string16& title) {
286 if (title_ != NULL) 290 if (title_ != NULL)
287 delete title_; // This removes the title from this view's children. 291 delete title_; // This removes the title from this view's children.
288 if (title.empty()) { 292 if (title.empty()) {
289 title_ = NULL; 293 title_ = NULL;
290 } else { 294 } else {
291 title_ = new views::Label(title); 295 title_ = new views::Label(title);
292 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 296 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
293 title_->SetElideBehavior(views::Label::ELIDE_AT_END); 297 title_->SetElideBehavior(views::Label::ELIDE_AT_END);
294 title_->SetEnabledColor(message_center::kRegularTextColor); 298 title_->SetEnabledColor(message_center::kRegularTextColor);
295 title_->SetBackgroundColor(kRegularTextBackgroundColor); 299 title_->SetBackgroundColor(kRegularTextBackgroundColor);
296 title_->set_border(MakeBorder(kButtonTitleTopPadding, 0, 0, 0)); 300 title_->set_border(MakeEmptyBorder(kButtonTitleTopPadding, 0, 0, 0));
297 AddChildView(title_); 301 AddChildView(title_);
298 } 302 }
299 } 303 }
300 304
301 gfx::Size NotificationButton::GetPreferredSize() { 305 gfx::Size NotificationButton::GetPreferredSize() {
302 return gfx::Size(message_center::kNotificationWidth, kButtonHeight); 306 return gfx::Size(message_center::kNotificationWidth, kButtonHeight);
303 } 307 }
304 308
305 int NotificationButton::GetHeightForWidth(int width) { 309 int NotificationButton::GetHeightForWidth(int width) {
306 return kButtonHeight; 310 return kButtonHeight;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 bool expanded) 360 bool expanded)
357 : MessageView(notification, observer, expanded) { 361 : MessageView(notification, observer, expanded) {
358 // Create the opaque background that's above the view's shadow. 362 // Create the opaque background that's above the view's shadow.
359 background_view_ = new views::View(); 363 background_view_ = new views::View();
360 background_view_->set_background(MakeBackground()); 364 background_view_->set_background(MakeBackground());
361 365
362 // Create the top_view_, which collects into a vertical box all content 366 // Create the top_view_, which collects into a vertical box all content
363 // at the top of the notification (to the right of the icon) except for the 367 // at the top of the notification (to the right of the icon) except for the
364 // close button. 368 // close button.
365 top_view_ = new ContainerView(); 369 top_view_ = new ContainerView();
370 top_view_->set_border(MakeEmptyBorder(kTextTopPadding - 8, 0,
371 kTextBottomPadding - 5, 0));
366 372
367 // Create the title view if appropriate. 373 // Create the title view if appropriate.
368 title_view_ = NULL; 374 title_view_ = NULL;
369 if (!notification.title().empty()) { 375 if (!notification.title().empty()) {
370 title_view_ = new views::Label( 376 title_view_ = new views::Label(
371 MaybeTruncateText( notification.title(), kTitleCharacterLimit)); 377 MaybeTruncateText( notification.title(), kTitleCharacterLimit));
372 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 378 title_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
373 if (is_expanded()) 379 if (is_expanded())
374 title_view_->SetMultiLine(true); 380 title_view_->SetMultiLine(true);
375 else 381 else
376 title_view_->SetElideBehavior(views::Label::ELIDE_AT_END); 382 title_view_->SetElideBehavior(views::Label::ELIDE_AT_END);
377 title_view_->SetFont(title_view_->font().DeriveFont(2)); 383 title_view_->SetFont(title_view_->font().DeriveFont(2));
378 title_view_->SetEnabledColor(message_center::kRegularTextColor); 384 title_view_->SetEnabledColor(message_center::kRegularTextColor);
379 title_view_->SetBackgroundColor(kRegularTextBackgroundColor); 385 title_view_->SetBackgroundColor(kRegularTextBackgroundColor);
380 title_view_->set_border(MakeBorder(kTextTopPadding, 3)); 386 title_view_->set_border(MakeTextBorder(3, 0));
381 top_view_->AddChildView(title_view_); 387 top_view_->AddChildView(title_view_);
382 } 388 }
383 389
384 // Create the message view if appropriate. 390 // Create the message view if appropriate.
385 message_view_ = NULL; 391 message_view_ = NULL;
386 if (!notification.message().empty()) { 392 if (!notification.message().empty()) {
387 message_view_ = new views::Label( 393 message_view_ = new views::Label(
388 MaybeTruncateText(notification.message(), kMessageCharacterLimit)); 394 MaybeTruncateText(notification.message(), kMessageCharacterLimit));
389 message_view_->SetVisible(!is_expanded() || !notification.items().size()); 395 message_view_->SetVisible(!is_expanded() || !notification.items().size());
390 message_view_->set_collapse_when_hidden(true); 396 message_view_->set_collapse_when_hidden(true);
391 message_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 397 message_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
392 if (is_expanded()) 398 if (is_expanded())
393 message_view_->SetMultiLine(true); 399 message_view_->SetMultiLine(true);
394 else 400 else
395 message_view_->SetElideBehavior(views::Label::ELIDE_AT_END); 401 message_view_->SetElideBehavior(views::Label::ELIDE_AT_END);
396 message_view_->SetEnabledColor(message_center::kRegularTextColor); 402 message_view_->SetEnabledColor(message_center::kRegularTextColor);
397 message_view_->SetBackgroundColor(kRegularTextBackgroundColor); 403 message_view_->SetBackgroundColor(kRegularTextBackgroundColor);
398 message_view_->set_border(MakeBorder(0, 3)); 404 message_view_->set_border(MakeTextBorder(4, 1));
399 top_view_->AddChildView(message_view_); 405 top_view_->AddChildView(message_view_);
400 } 406 }
401 407
402 // Create the list item views (up to a maximum). 408 // Create the list item views (up to a maximum).
403 std::vector<NotificationItem> items = notification.items(); 409 std::vector<NotificationItem> items = notification.items();
404 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { 410 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) {
405 ItemView* item_view = new ItemView(items[i]); 411 ItemView* item_view = new ItemView(items[i]);
406 item_view->SetVisible(is_expanded()); 412 item_view->SetVisible(is_expanded());
407 item_view->set_border(MakeBorder(0, 4)); 413 item_view->set_border(MakeTextBorder(i > 0 ? 0 : 4, 1));
408 item_views_.push_back(item_view); 414 item_views_.push_back(item_view);
409 top_view_->AddChildView(item_view); 415 top_view_->AddChildView(item_view);
410 } 416 }
411 417
412 // Create the notification icon view. 418 // Create the notification icon view.
413 if (notification.type() == NOTIFICATION_TYPE_SIMPLE) { 419 if (notification.type() == NOTIFICATION_TYPE_SIMPLE) {
414 views::ImageView* icon_view = new views::ImageView(); 420 views::ImageView* icon_view = new views::ImageView();
415 icon_view->SetImage(notification.icon().AsImageSkia()); 421 icon_view->SetImage(notification.icon().AsImageSkia());
416 icon_view->SetImageSize(gfx::Size(kLegacyIconSize, kLegacyIconSize)); 422 icon_view->SetImageSize(gfx::Size(kLegacyIconSize, kLegacyIconSize));
417 icon_view->SetHorizontalAlignment(views::ImageView::CENTER); 423 icon_view->SetHorizontalAlignment(views::ImageView::CENTER);
(...skipping 13 matching lines...) Expand all
431 if (!notification.image().IsEmpty()) { 437 if (!notification.image().IsEmpty()) {
432 image_view_ = new ProportionalImageView(notification.image().AsImageSkia()); 438 image_view_ = new ProportionalImageView(notification.image().AsImageSkia());
433 image_view_->SetVisible(is_expanded()); 439 image_view_->SetVisible(is_expanded());
434 bottom_view_->AddChildView(image_view_); 440 bottom_view_->AddChildView(image_view_);
435 } 441 }
436 442
437 // Create action buttons if appropriate. 443 // Create action buttons if appropriate.
438 std::vector<ButtonInfo> buttons = notification.buttons(); 444 std::vector<ButtonInfo> buttons = notification.buttons();
439 for (size_t i = 0; i < buttons.size(); ++i) { 445 for (size_t i = 0; i < buttons.size(); ++i) {
440 views::View* separator = new views::ImageView(); 446 views::View* separator = new views::ImageView();
441 separator->set_border(MakeBorder(1, 0, 0, 0, kButtonSeparatorColor)); 447 separator->set_border(MakeSeparatorBorder(1, 0, kButtonSeparatorColor));
442 bottom_view_->AddChildView(separator); 448 bottom_view_->AddChildView(separator);
443 NotificationButton* button = new NotificationButton(this); 449 NotificationButton* button = new NotificationButton(this);
444 ButtonInfo button_info = buttons[i]; 450 ButtonInfo button_info = buttons[i];
445 button->SetTitle(button_info.title); 451 button->SetTitle(button_info.title);
446 button->SetIcon(button_info.icon.AsImageSkia()); 452 button->SetIcon(button_info.icon.AsImageSkia());
447 action_buttons_.push_back(button); 453 action_buttons_.push_back(button);
448 bottom_view_->AddChildView(button); 454 bottom_view_->AddChildView(button);
449 } 455 }
450 456
451 // Hide the expand button if appropriate. 457 // Hide the expand button if appropriate.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 size_t limit) { 548 size_t limit) {
543 // Currently just truncate the text by the total number of characters. 549 // Currently just truncate the text by the total number of characters.
544 // TODO(mukai): add better assumption like number of lines. 550 // TODO(mukai): add better assumption like number of lines.
545 if (!is_expanded()) 551 if (!is_expanded())
546 return text; 552 return text;
547 553
548 return ui::TruncateString(text, limit); 554 return ui::TruncateString(text, limit);
549 } 555 }
550 556
551 } // namespace message_center 557 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698