OLD | NEW |
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/message_center_bubble.h" | 5 #include "ui/message_center/message_center_bubble.h" |
6 | 6 |
7 #include "grit/ui_strings.h" | 7 #include "grit/ui_strings.h" |
8 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
23 | 23 |
24 namespace message_center { | 24 namespace message_center { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const int kMessageBubbleBaseMinHeight = 80; | 28 const int kMessageBubbleBaseMinHeight = 80; |
29 const int kMessageBubbleBaseMaxHeight = 400; | 29 const int kMessageBubbleBaseMaxHeight = 400; |
30 const int kMarginBetweenItems = 10; | 30 const int kMarginBetweenItems = 10; |
31 const SkColor kMessageCenterBackgroundColor = SkColorSetRGB(0xd3, 0xd3, 0xd3); | 31 const int kItemShadowHeight = 4; |
| 32 const SkColor kMessageCenterBackgroundColor = SkColorSetRGB(0xe5, 0xe5, 0xe5); |
32 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 33 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); |
33 const SkColor kMessageItemBorderWidth = 1; | 34 const SkColor kMessageItemShadowColorBase = SkColorSetARGB(0.3 * 255, 0, 0, 0); |
34 const SkColor kMessageItemBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 35 const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); |
35 | 36 |
36 // The view for the buttons at the bottom of the web notification tray. | 37 // The view for the buttons at the bottom of the web notification tray. |
37 class WebNotificationButtonView : public views::View, | 38 class WebNotificationButtonView : public views::View, |
38 public views::ButtonListener { | 39 public views::ButtonListener { |
39 public: | 40 public: |
40 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) | 41 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) |
41 : list_delegate_(list_delegate), | 42 : list_delegate_(list_delegate), |
42 close_all_button_(NULL) { | 43 close_all_button_(NULL) { |
43 set_background(views::Background::CreateBackgroundPainter( | 44 set_background(views::Background::CreateBackgroundPainter( |
44 true, | 45 true, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 private: | 142 private: |
142 gfx::Size fixed_size_; | 143 gfx::Size fixed_size_; |
143 | 144 |
144 DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); | 145 DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); |
145 }; | 146 }; |
146 | 147 |
147 // Container for the messages. | 148 // Container for the messages. |
148 class ScrollContentView : public views::View { | 149 class ScrollContentView : public views::View { |
149 public: | 150 public: |
150 ScrollContentView() { | 151 ScrollContentView() { |
| 152 // Set the margin to 0 for the layout. BoxLayout assumes the same margin |
| 153 // for top and bottom, but the bottom margin here should be smaller |
| 154 // because of the shadow of message view. Use an empty border instead |
| 155 // to provide this margin. |
151 SetLayoutManager( | 156 SetLayoutManager( |
152 new views::BoxLayout(views::BoxLayout::kVertical, | 157 new views::BoxLayout(views::BoxLayout::kVertical, |
153 kMarginBetweenItems, | 158 0, |
154 kMarginBetweenItems, | 159 0, |
155 kMarginBetweenItems)); | 160 kMarginBetweenItems - kItemShadowHeight)); |
156 set_background(views::Background::CreateSolidBackground( | 161 set_background(views::Background::CreateSolidBackground( |
157 kMessageCenterBackgroundColor)); | 162 kMessageCenterBackgroundColor)); |
| 163 set_border(views::Border::CreateEmptyBorder( |
| 164 kMarginBetweenItems, /* top */ |
| 165 kMarginBetweenItems, /* left */ |
| 166 kMarginBetweenItems - kItemShadowHeight, /* bottom */ |
| 167 kMarginBetweenItems /* right */ )); |
158 } | 168 } |
159 | 169 |
160 virtual ~ScrollContentView() { | 170 virtual ~ScrollContentView() { |
161 } | 171 } |
162 | 172 |
163 virtual gfx::Size GetPreferredSize() OVERRIDE { | 173 virtual gfx::Size GetPreferredSize() OVERRIDE { |
164 if (!preferred_size_.IsEmpty()) | 174 if (!preferred_size_.IsEmpty()) |
165 return preferred_size_; | 175 return preferred_size_; |
166 return views::View::GetPreferredSize(); | 176 return views::View::GetPreferredSize(); |
167 } | 177 } |
168 | 178 |
169 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } | 179 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } |
170 | 180 |
171 private: | 181 private: |
172 gfx::Size preferred_size_; | 182 gfx::Size preferred_size_; |
173 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); | 183 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); |
174 }; | 184 }; |
175 | 185 |
| 186 // A view to draw gradient shadow for each MessageView. |
| 187 class MessageViewShadow : public views::View { |
| 188 public: |
| 189 MessageViewShadow() |
| 190 : painter_(views::Painter::CreateVerticalGradient( |
| 191 kMessageItemShadowColorBase, kTransparentColor)) { |
| 192 } |
| 193 |
| 194 private: |
| 195 // views::View overrides: |
| 196 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 197 // The preferred size must not be empty. Thus put an arbitrary non-zero |
| 198 // width here. It will be just ignored by the vertical box layout. |
| 199 return gfx::Size(1, kItemShadowHeight); |
| 200 } |
| 201 |
| 202 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 203 painter_->Paint(canvas, bounds().size()); |
| 204 } |
| 205 |
| 206 scoped_ptr<views::Painter> painter_; |
| 207 DISALLOW_COPY_AND_ASSIGN(MessageViewShadow); |
| 208 }; |
| 209 |
176 } // namespace | 210 } // namespace |
177 | 211 |
178 // Message Center contents. | 212 // Message Center contents. |
179 class MessageCenterContentsView : public views::View { | 213 class MessageCenterContentsView : public views::View { |
180 public: | 214 public: |
181 explicit MessageCenterContentsView(NotificationList::Delegate* list_delegate) | 215 explicit MessageCenterContentsView(NotificationList::Delegate* list_delegate) |
182 : list_delegate_(list_delegate) { | 216 : list_delegate_(list_delegate) { |
183 SetLayoutManager( | 217 SetLayoutManager( |
184 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 218 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
185 | 219 |
(...skipping 16 matching lines...) Expand all Loading... |
202 | 236 |
203 void Update(const NotificationList::Notifications& notifications) { | 237 void Update(const NotificationList::Notifications& notifications) { |
204 scroll_content_->RemoveAllChildViews(true); | 238 scroll_content_->RemoveAllChildViews(true); |
205 scroll_content_->set_preferred_size(gfx::Size()); | 239 scroll_content_->set_preferred_size(gfx::Size()); |
206 size_t num_children = 0; | 240 size_t num_children = 0; |
207 for (NotificationList::Notifications::const_iterator iter = | 241 for (NotificationList::Notifications::const_iterator iter = |
208 notifications.begin(); iter != notifications.end(); ++iter) { | 242 notifications.begin(); iter != notifications.end(); ++iter) { |
209 MessageView* view = | 243 MessageView* view = |
210 MessageViewFactory::ViewForNotification(*iter, list_delegate_); | 244 MessageViewFactory::ViewForNotification(*iter, list_delegate_); |
211 view->set_scroller(scroller_); | 245 view->set_scroller(scroller_); |
212 view->set_border(views::Border::CreateSolidBorder( | |
213 kMessageItemBorderWidth, kMessageItemBorderColor)); | |
214 view->SetUpView(); | 246 view->SetUpView(); |
215 scroll_content_->AddChildView(view); | 247 |
| 248 views::View* container = new views::View(); |
| 249 container->SetLayoutManager( |
| 250 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 251 container->AddChildView(view); |
| 252 container->AddChildView(new MessageViewShadow()); |
| 253 scroll_content_->AddChildView(container); |
216 if (++num_children >= | 254 if (++num_children >= |
217 NotificationList::kMaxVisibleMessageCenterNotifications) { | 255 NotificationList::kMaxVisibleMessageCenterNotifications) { |
218 break; | 256 break; |
219 } | 257 } |
220 } | 258 } |
221 if (num_children == 0) { | 259 if (num_children == 0) { |
222 views::Label* label = new views::Label(l10n_util::GetStringUTF16( | 260 views::Label* label = new views::Label(l10n_util::GetStringUTF16( |
223 IDS_MESSAGE_CENTER_NO_MESSAGES)); | 261 IDS_MESSAGE_CENTER_NO_MESSAGES)); |
224 label->SetFont(label->font().DeriveFont(1)); | 262 label->SetFont(label->font().DeriveFont(1)); |
225 label->SetEnabledColor(SK_ColorGRAY); | 263 label->SetEnabledColor(SK_ColorGRAY); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 346 } |
309 | 347 |
310 void MessageCenterBubble::OnMouseExitedView() { | 348 void MessageCenterBubble::OnMouseExitedView() { |
311 } | 349 } |
312 | 350 |
313 size_t MessageCenterBubble::NumMessageViewsForTest() const { | 351 size_t MessageCenterBubble::NumMessageViewsForTest() const { |
314 return contents_view_->NumMessageViews(); | 352 return contents_view_->NumMessageViews(); |
315 } | 353 } |
316 | 354 |
317 } // namespace message_center | 355 } // namespace message_center |
OLD | NEW |