| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/message_center/message_view_multiple.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "grit/ui_resources.h" | |
| 9 #include "ui/base/accessibility/accessible_view_state.h" | |
| 10 #include "ui/base/resource/resource_bundle.h" | |
| 11 #include "ui/base/text/text_elider.h" | |
| 12 #include "ui/gfx/canvas.h" | |
| 13 #include "ui/gfx/size.h" | |
| 14 #include "ui/message_center/message_center_constants.h" | |
| 15 #include "ui/native_theme/native_theme.h" | |
| 16 #include "ui/views/controls/button/image_button.h" | |
| 17 #include "ui/views/controls/image_view.h" | |
| 18 #include "ui/views/controls/label.h" | |
| 19 #include "ui/views/layout/box_layout.h" | |
| 20 #include "ui/views/layout/grid_layout.h" | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // Notification dimensions. | |
| 25 const int kIconLeftPadding = 0; | |
| 26 const int kIconColumnWidth = message_center::kNotificationIconWidth; | |
| 27 const int kIconToTextPadding = 15; | |
| 28 const int kTextToClosePadding = 10; | |
| 29 const int kCloseColumnWidth = 8; | |
| 30 const int kCloseRightPadding = 6; | |
| 31 const int kIconTopPadding = 0; | |
| 32 const int kTextTopPadding = 9; | |
| 33 const int kCloseTopPadding = 6; | |
| 34 const int kIconBottomPadding = 0; | |
| 35 const int kTextBottomPadding = 12; | |
| 36 const int kItemTitleToDetailsPadding = 3; | |
| 37 | |
| 38 // Notification colors. The text background colors below are used only to keep | |
| 39 // view::Label from modifying the text color and will not actually be drawn. | |
| 40 // See view::Label's SetEnabledColor() and SetBackgroundColor() for details. | |
| 41 const SkColor kBackgroundColor = SkColorSetRGB(255, 255, 255); | |
| 42 const SkColor kTitleColor = SkColorSetRGB(68, 68, 68); | |
| 43 const SkColor kTitleBackgroundColor = SK_ColorWHITE; | |
| 44 const SkColor kMessageColor = SkColorSetRGB(136, 136, 136); | |
| 45 const SkColor kMessageBackgroundColor = SK_ColorBLACK; | |
| 46 | |
| 47 // Static function to create an empty border to be used as padding. | |
| 48 views::Border* MakePadding(int top, int left, int bottom, int right) { | |
| 49 return views::Border::CreateEmptyBorder(top, left, bottom, right); | |
| 50 } | |
| 51 | |
| 52 // ItemViews are responsible for drawing each MessageViewMultiple item's title | |
| 53 // and message next to each other within a single column. | |
| 54 class ItemView : public views::View { | |
| 55 public: | |
| 56 ItemView(const message_center::NotificationList::NotificationItem& item); | |
| 57 virtual ~ItemView(); | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(ItemView); | |
| 61 }; | |
| 62 | |
| 63 ItemView::ItemView( | |
| 64 const message_center::NotificationList::NotificationItem& item) { | |
| 65 views::BoxLayout* layout = | |
| 66 new views::BoxLayout(views::BoxLayout::kHorizontal, | |
| 67 0, 0, kItemTitleToDetailsPadding); | |
| 68 SetLayoutManager(layout); | |
| 69 | |
| 70 views::Label* title = new views::Label(item.title); | |
| 71 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 72 title->SetElideBehavior(views::Label::ELIDE_AT_END); | |
| 73 title->SetEnabledColor(kTitleColor); | |
| 74 title->SetBackgroundColor(kTitleBackgroundColor); | |
| 75 AddChildViewAt(title, 0); | |
| 76 | |
| 77 views::Label* details = new views::Label(item.message); | |
| 78 details->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 79 details->SetElideBehavior(views::Label::ELIDE_AT_END); | |
| 80 details->SetEnabledColor(kMessageColor); | |
| 81 details->SetBackgroundColor(kMessageBackgroundColor); | |
| 82 AddChildViewAt(details, 1); | |
| 83 | |
| 84 PreferredSizeChanged(); | |
| 85 SchedulePaint(); | |
| 86 } | |
| 87 | |
| 88 ItemView::~ItemView() { | |
| 89 } | |
| 90 | |
| 91 } // namespace | |
| 92 | |
| 93 namespace message_center { | |
| 94 | |
| 95 MessageViewMultiple::MessageViewMultiple( | |
| 96 NotificationList::Delegate* list_delegate, | |
| 97 const NotificationList::Notification& notification) | |
| 98 : MessageView(list_delegate, notification) { | |
| 99 } | |
| 100 | |
| 101 MessageViewMultiple::~MessageViewMultiple() { | |
| 102 } | |
| 103 | |
| 104 // TODO(dharcourt): Make this a subclass of BaseFormatView or of a | |
| 105 // BaseFormatView superclass and leverage that class' SetUpView(). | |
| 106 void MessageViewMultiple::SetUpView() { | |
| 107 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
| 108 | |
| 109 views::GridLayout* layout = new views::GridLayout(this); | |
| 110 SetLayoutManager(layout); | |
| 111 | |
| 112 // Three columns (icon, text, close button) surrounded by padding. The icon | |
| 113 // and close button columns and the padding have fixed widths and the text | |
| 114 // column fills up the remaining space. To minimize the number of columns and | |
| 115 // simplify column spanning padding is applied to each view within columns | |
| 116 // instead of through padding columns. | |
| 117 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 118 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, | |
| 119 0, views::GridLayout::FIXED, | |
| 120 kIconLeftPadding + kIconColumnWidth + kIconToTextPadding, | |
| 121 kIconLeftPadding + kIconColumnWidth + kIconToTextPadding); | |
| 122 // Padding + icon + padding. | |
| 123 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 124 100, views::GridLayout::USE_PREF, | |
| 125 0, 0); | |
| 126 // Text + padding (kTextToClosePadding). | |
| 127 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, | |
| 128 0, views::GridLayout::FIXED, | |
| 129 kCloseColumnWidth + kCloseRightPadding, | |
| 130 kCloseColumnWidth + kCloseRightPadding); | |
| 131 // Close button + padding. | |
| 132 | |
| 133 // First row: Icon. This vertically spans the close button padding row, the | |
| 134 // close button row, and all item rows. | |
| 135 layout->StartRow(0, 0); | |
| 136 views::ImageView* icon = new views::ImageView(); | |
| 137 icon->SetImageSize(gfx::Size(message_center::kNotificationIconWidth, | |
| 138 message_center::kNotificationIconWidth)); | |
| 139 icon->SetImage(notification_.primary_icon); | |
| 140 icon->SetHorizontalAlignment(views::ImageView::LEADING); | |
| 141 icon->SetVerticalAlignment(views::ImageView::LEADING); | |
| 142 icon->set_border(MakePadding(kIconTopPadding, kIconLeftPadding, | |
| 143 kIconBottomPadding, kIconToTextPadding)); | |
| 144 layout->AddView(icon, 1, 2 + notification_.items.size()); | |
| 145 | |
| 146 // First row: Title. This vertically spans the close button padding row and | |
| 147 // the close button row. | |
| 148 // TODO(dharcourt): Skip the title Label when there's no title text. | |
| 149 views::Label* title = new views::Label(notification_.title); | |
| 150 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 151 title->SetFont(title->font().DeriveFont(4)); | |
| 152 title->SetEnabledColor(kTitleColor); | |
| 153 title->SetBackgroundColor(kTitleBackgroundColor); | |
| 154 title->set_border(MakePadding(kTextTopPadding, 0, 3, kTextToClosePadding)); | |
| 155 layout->AddView(title, 1, 2); | |
| 156 | |
| 157 // First row: Close button padding. | |
| 158 views::View* padding = new views::ImageView(); | |
| 159 padding->set_border(MakePadding(kCloseTopPadding, 1, 0, 0)); | |
| 160 layout->AddView(padding); | |
| 161 | |
| 162 // Second row: Close button, which has to be on a row of its own because its | |
| 163 // top padding can't be set using empty borders (ImageButtons don't support | |
| 164 // borders). The resize factor of this row (100) is much higher than that of | |
| 165 // other rows (0) to ensure the first row's height stays at kCloseTopPadding. | |
| 166 layout->StartRow(100, 0); | |
| 167 layout->SkipColumns(2); | |
| 168 DCHECK(close_button_); | |
| 169 layout->AddView(close_button_); | |
| 170 | |
| 171 // One row for each notification item, including appropriate padding. | |
| 172 for (int i = 0, n = notification_.items.size(); i < n; ++i) { | |
| 173 int bottom_padding = (i < n - 1) ? 4 : (kTextBottomPadding - 2); | |
| 174 layout->StartRow(0, 0); | |
| 175 layout->SkipColumns(1); | |
| 176 ItemView* item = new ItemView(notification_.items[i]); | |
| 177 item->set_border(MakePadding(0, 0, bottom_padding, kTextToClosePadding)); | |
| 178 layout->AddView(item); | |
| 179 layout->SkipColumns(1); | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 } // namespace message_center | |
| OLD | NEW |