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/resource/resource_bundle.h" | |
10 #include "ui/views/controls/button/image_button.h" | |
11 #include "ui/views/controls/image_view.h" | |
12 #include "ui/views/controls/label.h" | |
13 #include "ui/views/layout/grid_layout.h" | |
14 | |
15 namespace message_center { | |
16 | |
17 const SkColor kNotificationColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); | |
18 const SkColor kNotificationReadColor = SkColorSetRGB(0xfa, 0xfa, 0xfa); | |
19 | |
20 // Temporarily here, this will later get merged into the Notification class. | |
miket_OOO
2012/11/15 18:35:32
Use TODO format.
Can you do this work now, rather
dharcourt
2012/11/16 02:37:00
Done.
| |
21 struct MessageViewMultiple::NotificationItem { | |
22 string16 title; | |
23 string16 details; | |
24 NotificationItem(string16 title, string16 details) | |
25 : title(title), | |
26 details(details) { | |
benwells
2012/11/15 22:27:08
drive by suggestion: you can use {} on one line he
dharcourt
2012/11/16 02:37:00
Thanks for the review & the suggestion.
| |
27 } | |
28 }; | |
29 | |
30 MessageViewMultiple::MessageViewMultiple( | |
31 NotificationList::Delegate* list_delegate, | |
32 const NotificationList::Notification& notification) | |
33 : MessageView(list_delegate, notification) { | |
34 } | |
35 | |
36 MessageViewMultiple::MessageViewMultiple() { | |
37 } | |
38 | |
39 MessageViewMultiple::~MessageViewMultiple() { | |
40 } | |
41 | |
42 // TODO(dharcourt): Make this a subclass of BaseFormatView or of a | |
43 // BaseFormatView superclass and leverage that class' SetUpView(). | |
44 void MessageViewMultiple::SetUpView() { | |
45 DCHECK(close_button_); | |
46 | |
47 // Create some bogus notification items for now. Later they'll come from the | |
48 // Notification object. | |
49 // TODO(dharcourt): Figure out if there's a simpler to provide a string16 | |
50 // constant than UTF8ToUTF16(const char *). | |
51 std::vector<NotificationItem> items; | |
52 items.push_back(NotificationItem( | |
53 UTF8ToUTF16("Andy Rubin"), | |
54 UTF8ToUTF16("This is an imporant message!"))); | |
miket_OOO
2012/11/15 18:35:32
spelling
| |
55 items.push_back(NotificationItem( | |
56 UTF8ToUTF16("James Bergen Plummer"), | |
57 UTF8ToUTF16("Just took a look at the proposal"))); | |
58 items.push_back(NotificationItem( | |
59 UTF8ToUTF16("Adam Cohen"), | |
60 UTF8ToUTF16("I see that you went to the conference"))); | |
61 items.push_back(NotificationItem( | |
62 UTF8ToUTF16("Mike Jurka"), | |
63 UTF8ToUTF16("I ate Cleron's sandwhich!"))); | |
miket_OOO
2012/11/15 18:35:32
spelling
dharcourt
2012/11/16 02:37:00
Funny. The mockup had a typo which I kepth even th
| |
64 items.push_back(NotificationItem( | |
65 UTF8ToUTF16("Winson Chung"), | |
66 UTF8ToUTF16("I saw mike steal a sandwhich :-)"))); | |
67 | |
68 SkColor bg_color = notification_.is_read ? | |
69 kNotificationReadColor : kNotificationColor; | |
70 set_background(views::Background::CreateSolidBackground(bg_color)); | |
71 | |
72 // TODO(dharcourt): If possible, us GridLayout fill functionality to make the | |
miket_OOO
2012/11/15 18:35:32
spelling
dharcourt
2012/11/16 02:37:00
Done.
| |
73 // message as wide as possible without reference to the kWebNotificationWidth. | |
74 // TODO(dharcourt): Verify intended meaning of MessageView size constants. | |
75 const int padding_width = kPaddingHorizontal / 2; | |
76 const int message_width = kWebNotificationWidth - kWebNotificationIconSize - | |
77 kWebNotificationButtonWidth - (padding_width * 3); | |
78 | |
79 views::GridLayout* layout = new views::GridLayout(this); | |
80 SetLayoutManager(layout); | |
81 | |
82 // Three columns (icon, messages, close button) surrounded by padding. | |
83 views::ColumnSet* columns = layout->AddColumnSet(0); | |
84 columns->AddPaddingColumn(0, padding_width); | |
85 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | |
86 0, /* resize weight */ | |
87 views::GridLayout::FIXED, | |
88 kWebNotificationIconSize, kWebNotificationIconSize); | |
89 columns->AddPaddingColumn(0, padding_width); | |
90 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
91 100, /* resize weight */ | |
92 views::GridLayout::FIXED, | |
93 message_width, message_width); | |
94 columns->AddPaddingColumn(0, padding_width); | |
95 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | |
96 0, /* resize weight */ | |
97 views::GridLayout::FIXED, | |
98 kWebNotificationButtonWidth, | |
99 kWebNotificationButtonWidth); | |
100 | |
101 // First row has the icon, title, and close button after some top padding. | |
102 layout->AddPaddingRow(0, kPaddingBetweenItems); | |
103 layout->StartRow(0, 0); | |
104 | |
105 views::ImageView* icon = new views::ImageView; | |
106 icon->SetImageSize( | |
107 gfx::Size(kWebNotificationIconSize, kWebNotificationIconSize)); | |
108 icon->SetImage(notification_.image); | |
109 layout->AddView(icon, 1, 1 + items.size()); | |
110 | |
111 views::Label* title = new views::Label(notification_.title); | |
112 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
113 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); | |
114 layout->AddView(title); | |
115 | |
116 close_button_ = new views::ImageButton(this); | |
117 close_button_->SetImage( | |
118 views::CustomButton::STATE_NORMAL, | |
119 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
120 IDR_MESSAGE_CLOSE)); | |
121 close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
122 views::ImageButton::ALIGN_MIDDLE); | |
123 layout->AddView(close_button_); | |
124 | |
125 // One row for each notification item. | |
126 for (std::vector<NotificationItem>::const_iterator i = items.begin(); | |
127 i != items.end(); | |
128 ++i) { | |
129 views::Label* item_title = new views::Label(i->title); | |
130 item_title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
131 layout->StartRow(0,0); | |
132 layout->SkipColumns(2); | |
133 layout->AddView(item_title); | |
134 // TODO(dharcourt): Item details. | |
135 } | |
136 | |
137 // TODO(dharcourt): Add a horizontal line. | |
138 | |
139 // One row for the summary message. TODO(dharcourt): Make it optional. | |
140 views::Label* message = new views::Label(notification_.message); | |
141 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
142 message->SetMultiLine(true); | |
143 layout->StartRow(0, 0); | |
144 layout->SkipColumns(2); | |
145 layout->AddView(message); | |
146 | |
147 // TODO(dharcourt): Add a second icon to the right of the summary message. | |
148 | |
149 // Bottom padding. | |
150 layout->AddPaddingRow(0, kPaddingBetweenItems); | |
151 } | |
152 | |
153 } // namespace message_center | |
OLD | NEW |