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