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

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

Issue 11926032: Updated the look of web and basic notifications to match latest mockups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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
(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/base_format_view.h"
6
7 #include "base/i18n/time_formatting.h"
8 #include "grit/ui_resources.h"
9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/views/controls/button/image_button.h"
11 #include "ui/views/controls/button/label_button.h"
12 #include "ui/views/controls/image_view.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/grid_layout.h"
15
16 namespace message_center {
17
18 const SkColor kNotificationColor = SkColorSetRGB(0xfe, 0xfe, 0xfe);
19 const SkColor kNotificationReadColor = SkColorSetRGB(0xfa, 0xfa, 0xfa);
20
21 const int kBaseFormatPrimaryIconWidth = 64;
22 const int kBaseFormatSecondaryIconWidth = 16;
23 const int kBaseFormatTimestampWidth = 60;
24 const int kBaseFormatButtonWidth = 60;
25 const int kBaseFormatPaddingBetweenItems = 10;
26 const int kBaseFormatOuterHorizontalPadding = 18;
27
28 BaseFormatView::BaseFormatView(
29 NotificationList::Delegate* list_delegate,
30 const NotificationList::Notification& notification)
31 : MessageView(list_delegate, notification),
32 button_one_(NULL),
33 button_two_(NULL) {
34 }
35
36 BaseFormatView::~BaseFormatView() {
37 }
38
39 void BaseFormatView::SetUpView() {
40 SkColor bg_color = notification().is_read ?
41 kNotificationReadColor : kNotificationColor;
42 set_background(views::Background::CreateSolidBackground(bg_color));
43
44 views::ImageView* icon = new views::ImageView;
45 icon->SetImageSize(
46 gfx::Size(kBaseFormatPrimaryIconWidth, kBaseFormatPrimaryIconWidth));
47 icon->SetImage(notification().primary_icon);
48
49 views::ImageView* second_icon = new views::ImageView;
50 second_icon->SetImageSize(
51 gfx::Size(kBaseFormatSecondaryIconWidth, kBaseFormatSecondaryIconWidth));
52 // TODO: set up second image
53 second_icon->SetImage(notification().primary_icon);
54
55 views::Label* title = new views::Label(notification().title);
56 title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
57 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD));
58
59 views::Label* message = new views::Label(notification().message);
60 message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
61 message->SetMultiLine(true);
62 message->SetElideBehavior(views::Label::ELIDE_AT_END);
63 message->SizeToFit(
64 kBaseFormatButtonWidth * 2 + kBaseFormatPaddingBetweenItems * 3 +
65 kBaseFormatTimestampWidth);
66
67 views::Label* timestamp = NULL;
68 if (notification().timestamp != base::Time()) {
69 timestamp = new views::Label(
70 base::TimeFormatTimeOfDay(notification().timestamp));
71 timestamp->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
72 }
73
74 // TODO(miket): unreadCount
75
76 if (notification().button_titles.size() > 0) {
77 button_one_ = new views::LabelButton(this, notification().button_titles[0]);
78 button_one_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
79 button_one_->SetNativeTheme(true);
80 }
81 if (notification().button_titles.size() > 1) {
82 button_two_ = new views::LabelButton(this, notification().button_titles[1]);
83 button_two_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
84 button_two_->SetNativeTheme(true);
85 }
86
87 views::Label* expanded_message = new views::Label(
88 notification().expanded_message);
89 expanded_message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
90 expanded_message->SetMultiLine(true);
91 expanded_message->SizeToFit(
92 kBaseFormatButtonWidth * 2 + kBaseFormatPaddingBetweenItems);
93
94 // TODO(miket): Image thumbnail for image-type notifications (imageUrl)
95
96 views::GridLayout* layout = new views::GridLayout(this);
97 SetLayoutManager(layout);
98
99 views::ColumnSet* columns = layout->AddColumnSet(0);
100
101 const int padding_width = kBaseFormatOuterHorizontalPadding / 2;
102 columns->AddPaddingColumn(0, padding_width);
103
104 // Column 0: Notification Icon.
105 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING,
106 0, /* resize percent */
107 views::GridLayout::FIXED,
108 kBaseFormatPrimaryIconWidth, kBaseFormatPrimaryIconWidth);
109 columns->AddPaddingColumn(0, kBaseFormatPaddingBetweenItems);
110
111 // Column 1: Notification message text and first button.
112 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
113 100, /* resize percent */
114 views::GridLayout::USE_PREF,
115 kBaseFormatButtonWidth, kBaseFormatButtonWidth);
116 columns->AddPaddingColumn(0, kBaseFormatPaddingBetweenItems);
117
118 // Column 2: Notification message text and second button.
119 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
120 100, /* resize percent */
121 views::GridLayout::USE_PREF,
122 kBaseFormatButtonWidth, kBaseFormatButtonWidth);
123 columns->AddPaddingColumn(0, kBaseFormatPaddingBetweenItems);
124
125 // Column 3: Notification message text and timestamp.
126 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
127 0, /* resize percent */
128 views::GridLayout::FIXED,
129 kBaseFormatTimestampWidth, kBaseFormatTimestampWidth);
130 columns->AddPaddingColumn(0, kBaseFormatPaddingBetweenItems);
131
132 // Column 4: Close button and secondary icon.
133 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::BASELINE,
134 0, /* resize percent */
135 views::GridLayout::FIXED,
136 kBaseFormatSecondaryIconWidth,
137 kBaseFormatSecondaryIconWidth);
138 columns->AddPaddingColumn(0, kBaseFormatPaddingBetweenItems);
139
140 // Lay out rows.
141 // Row 0: Just timestamp and close box.
142 layout->StartRow(0, 0);
143 layout->SkipColumns(5);
144 if (timestamp)
145 layout->AddView(timestamp, 1, 1);
146 else
147 layout->SkipColumns(1);
148 layout->AddView(close_button(), 1, 1);
149
150 // Row 1: Big icon, title.
151 layout->StartRow(0, 0);
152 layout->AddView(icon, 1, 3);
153 layout->AddView(title, 3, 1);
154 layout->SkipColumns(1);
155
156 // Row 2: Continuation of big icon, message.
157 layout->StartRow(0, 0);
158 layout->SkipColumns(1);
159 layout->AddView(message, 3, 1);
160 layout->SkipColumns(1);
161 layout->AddPaddingRow(0, kBaseFormatPaddingBetweenItems);
162
163 // Row 3: Continuation of big icon, two buttons, secondary icon.
164 layout->StartRow(0,0);
165 layout->SkipColumns(1);
166 if (button_two_) {
167 layout->AddView(button_one_, 1, 1);
168 layout->AddView(button_two_, 1, 1);
169 } else if (button_one_) {
170 layout->AddView(button_one_, 1, 1);
171 layout->SkipColumns(1);
172 } else {
173 layout->SkipColumns(3); // two buttons plus padding
174 }
175 layout->SkipColumns(1);
176 layout->AddView(second_icon, 1, 1);
177 layout->AddPaddingRow(0, kBaseFormatPaddingBetweenItems);
178
179 // Row 4: Secondary message.
180 layout->StartRow(0,0);
181 layout->SkipColumns(1);
182 layout->AddView(expanded_message, 3, 1);
183
184 // A final bit of padding to make it look nice.
185 layout->AddPaddingRow(0, kBaseFormatPaddingBetweenItems);
186 }
187
188 void BaseFormatView::ButtonPressed(views::Button* sender,
189 const ui::Event& event) {
190 // TODO(miket): consider changing the _one, _two etc. widgets to an array or
191 // map so that we can move this behavior to the superclass. It seems like
192 // something we wouldn't want to keep recoding for each subclass.
193 if (sender == button_one_) {
194 list_delegate()->OnButtonClicked(notification().id, 0);
195 } else if (sender == button_two_) {
196 list_delegate()->OnButtonClicked(notification().id, 1);
197 } else {
198 MessageView::ButtonPressed(sender, event);
199 }
200 }
201
202 } // namespace message_center
dharcourt 2013/01/19 03:06:13 BaseFormatView replaced by NotificationView.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698