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 "ash/system/web_notification/message_center_bubble.h" | 5 #include "ui/message_center/message_center_bubble.h" |
6 | 6 |
7 #include "ash/system/web_notification/web_notification_view.h" | 7 #include "grit/ui_strings.h" |
8 #include "grit/ash_strings.h" | |
9 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
11 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
| 11 #include "ui/message_center/message_view.h" |
12 #include "ui/views/controls/button/text_button.h" | 12 #include "ui/views/controls/button/text_button.h" |
13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
14 #include "ui/views/controls/scroll_view.h" | 14 #include "ui/views/controls/scroll_view.h" |
15 #include "ui/views/layout/box_layout.h" | 15 #include "ui/views/layout/box_layout.h" |
16 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
17 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" |
18 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 namespace message_center { | 21 namespace message_center { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const int kWebNotificationBubbleMinHeight = 80; | 25 const int kMessageBubbleBaseMinHeight = 80; |
26 const int kWebNotificationBubbleMaxHeight = 400; | 26 const int kMessageBubbleBaseMaxHeight = 400; |
27 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 27 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); |
28 | 28 |
29 // The view for the buttons at the bottom of the web notification tray. | 29 // The view for the buttons at the bottom of the web notification tray. |
30 class WebNotificationButtonView : public views::View, | 30 class WebNotificationButtonView : public views::View, |
31 public views::ButtonListener { | 31 public views::ButtonListener { |
32 public: | 32 public: |
33 explicit WebNotificationButtonView( | 33 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) |
34 WebNotificationList::Delegate* list_delegate) | |
35 : list_delegate_(list_delegate), | 34 : list_delegate_(list_delegate), |
36 close_all_button_(NULL) { | 35 close_all_button_(NULL) { |
37 set_background(views::Background::CreateBackgroundPainter( | 36 set_background(views::Background::CreateBackgroundPainter( |
38 true, | 37 true, |
39 views::Painter::CreateVerticalGradient( | 38 views::Painter::CreateVerticalGradient( |
40 WebNotificationBubble::kHeaderBackgroundColorLight, | 39 MessageBubbleBase::kHeaderBackgroundColorLight, |
41 WebNotificationBubble::kHeaderBackgroundColorDark))); | 40 MessageBubbleBase::kHeaderBackgroundColorDark))); |
42 set_border(views::Border::CreateSolidSidedBorder( | 41 set_border(views::Border::CreateSolidSidedBorder( |
43 2, 0, 0, 0, kBorderDarkColor)); | 42 2, 0, 0, 0, kBorderDarkColor)); |
44 | 43 |
45 views::GridLayout* layout = new views::GridLayout(this); | 44 views::GridLayout* layout = new views::GridLayout(this); |
46 SetLayoutManager(layout); | 45 SetLayoutManager(layout); |
47 views::ColumnSet* columns = layout->AddColumnSet(0); | 46 views::ColumnSet* columns = layout->AddColumnSet(0); |
48 columns->AddPaddingColumn(100, 0); | 47 columns->AddPaddingColumn(100, 0); |
49 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 48 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
50 0, /* resize percent */ | 49 0, /* resize percent */ |
51 views::GridLayout::USE_PREF, 0, 0); | 50 views::GridLayout::USE_PREF, 0, 0); |
52 columns->AddPaddingColumn(0, 4); | 51 columns->AddPaddingColumn(0, 4); |
53 | 52 |
54 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
55 close_all_button_ = new views::TextButton( | 54 close_all_button_ = new views::TextButton( |
56 this, rb.GetLocalizedString(IDS_ASH_WEB_NOTFICATION_TRAY_CLEAR_ALL)); | 55 this, rb.GetLocalizedString(IDS_MESSAGE_CENTER_CLEAR_ALL)); |
57 close_all_button_->set_alignment(views::TextButton::ALIGN_CENTER); | 56 close_all_button_->set_alignment(views::TextButton::ALIGN_CENTER); |
58 close_all_button_->set_focusable(true); | 57 close_all_button_->set_focusable(true); |
59 close_all_button_->set_request_focus_on_press(false); | 58 close_all_button_->set_request_focus_on_press(false); |
60 | 59 |
61 layout->AddPaddingRow(0, 4); | 60 layout->AddPaddingRow(0, 4); |
62 layout->StartRow(0, 0); | 61 layout->StartRow(0, 0); |
63 layout->AddView(close_all_button_); | 62 layout->AddView(close_all_button_); |
64 } | 63 } |
65 | 64 |
66 virtual ~WebNotificationButtonView() {} | 65 virtual ~WebNotificationButtonView() {} |
67 | 66 |
68 void SetCloseAllVisible(bool visible) { | 67 void SetCloseAllVisible(bool visible) { |
69 close_all_button_->SetVisible(visible); | 68 close_all_button_->SetVisible(visible); |
70 } | 69 } |
71 | 70 |
72 // Overridden from ButtonListener. | 71 // Overridden from ButtonListener. |
73 virtual void ButtonPressed(views::Button* sender, | 72 virtual void ButtonPressed(views::Button* sender, |
74 const ui::Event& event) OVERRIDE { | 73 const ui::Event& event) OVERRIDE { |
75 if (sender == close_all_button_) | 74 if (sender == close_all_button_) |
76 list_delegate_->SendRemoveAllNotifications(); | 75 list_delegate_->SendRemoveAllNotifications(); |
77 } | 76 } |
78 | 77 |
79 private: | 78 private: |
80 WebNotificationList::Delegate* list_delegate_; | 79 NotificationList::Delegate* list_delegate_; |
81 views::TextButton* close_all_button_; | 80 views::TextButton* close_all_button_; |
82 | 81 |
83 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); | 82 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); |
84 }; | 83 }; |
85 | 84 |
86 // A custom scroll-view that has a specified size. | 85 // A custom scroll-view that has a specified size. |
87 class FixedSizedScrollView : public views::ScrollView { | 86 class FixedSizedScrollView : public views::ScrollView { |
88 public: | 87 public: |
89 FixedSizedScrollView() { | 88 FixedSizedScrollView() { |
90 set_focusable(true); | 89 set_focusable(true); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 private: | 159 private: |
161 gfx::Size preferred_size_; | 160 gfx::Size preferred_size_; |
162 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); | 161 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); |
163 }; | 162 }; |
164 | 163 |
165 } // namespace | 164 } // namespace |
166 | 165 |
167 // Message Center contents. | 166 // Message Center contents. |
168 class MessageCenterContentsView : public views::View { | 167 class MessageCenterContentsView : public views::View { |
169 public: | 168 public: |
170 explicit MessageCenterContentsView( | 169 explicit MessageCenterContentsView(NotificationList::Delegate* list_delegate) |
171 WebNotificationList::Delegate* list_delegate) | |
172 : list_delegate_(list_delegate) { | 170 : list_delegate_(list_delegate) { |
173 SetLayoutManager( | 171 SetLayoutManager( |
174 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 172 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
175 | 173 |
176 scroll_content_ = new ScrollContentView; | 174 scroll_content_ = new ScrollContentView; |
177 scroller_ = new FixedSizedScrollView; | 175 scroller_ = new FixedSizedScrollView; |
178 scroller_->SetContents(scroll_content_); | 176 scroller_->SetContents(scroll_content_); |
179 AddChildView(scroller_); | 177 AddChildView(scroller_); |
180 | 178 |
181 scroller_->SetPaintToLayer(true); | 179 scroller_->SetPaintToLayer(true); |
182 scroller_->SetFillsBoundsOpaquely(false); | 180 scroller_->SetFillsBoundsOpaquely(false); |
183 scroller_->layer()->SetMasksToBounds(true); | 181 scroller_->layer()->SetMasksToBounds(true); |
184 | 182 |
185 button_view_ = new WebNotificationButtonView(list_delegate); | 183 button_view_ = new WebNotificationButtonView(list_delegate); |
186 AddChildView(button_view_); | 184 AddChildView(button_view_); |
187 } | 185 } |
188 | 186 |
189 void FocusContents() { | 187 void FocusContents() { |
190 scroller_->RequestFocus(); | 188 scroller_->RequestFocus(); |
191 } | 189 } |
192 | 190 |
193 void Update(const WebNotificationList::Notifications& notifications) { | 191 void Update(const NotificationList::Notifications& notifications) { |
194 scroll_content_->RemoveAllChildViews(true); | 192 scroll_content_->RemoveAllChildViews(true); |
195 scroll_content_->set_preferred_size(gfx::Size()); | 193 scroll_content_->set_preferred_size(gfx::Size()); |
196 size_t num_children = 0; | 194 size_t num_children = 0; |
197 for (WebNotificationList::Notifications::const_iterator iter = | 195 for (NotificationList::Notifications::const_iterator iter = |
198 notifications.begin(); iter != notifications.end(); ++iter) { | 196 notifications.begin(); iter != notifications.end(); ++iter) { |
199 WebNotificationView* view = new WebNotificationView( | 197 MessageView* view = new MessageView( |
200 list_delegate_, *iter, scroller_->GetScrollBarWidth()); | 198 list_delegate_, *iter, scroller_->GetScrollBarWidth()); |
201 view->set_scroller(scroller_); | 199 view->set_scroller(scroller_); |
202 scroll_content_->AddChildView(view); | 200 scroll_content_->AddChildView(view); |
203 if (++num_children >= | 201 if (++num_children >= |
204 WebNotificationList::kMaxVisibleMessageCenterNotifications) { | 202 NotificationList::kMaxVisibleMessageCenterNotifications) { |
205 break; | 203 break; |
206 } | 204 } |
207 } | 205 } |
208 if (num_children == 0) { | 206 if (num_children == 0) { |
209 views::Label* label = new views::Label(l10n_util::GetStringUTF16( | 207 views::Label* label = new views::Label(l10n_util::GetStringUTF16( |
210 IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES)); | 208 IDS_MESSAGE_CENTER_NO_MESSAGES)); |
211 label->SetFont(label->font().DeriveFont(1)); | 209 label->SetFont(label->font().DeriveFont(1)); |
212 label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); | 210 label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
213 label->SetEnabledColor(SK_ColorGRAY); | 211 label->SetEnabledColor(SK_ColorGRAY); |
214 scroll_content_->AddChildView(label); | 212 scroll_content_->AddChildView(label); |
215 button_view_->SetCloseAllVisible(false); | 213 button_view_->SetCloseAllVisible(false); |
216 } else { | 214 } else { |
217 button_view_->SetCloseAllVisible(true); | 215 button_view_->SetCloseAllVisible(true); |
218 } | 216 } |
219 SizeScrollContent(); | 217 SizeScrollContent(); |
220 Layout(); | 218 Layout(); |
221 if (GetWidget()) | 219 if (GetWidget()) |
222 GetWidget()->GetRootView()->SchedulePaint(); | 220 GetWidget()->GetRootView()->SchedulePaint(); |
223 } | 221 } |
224 | 222 |
225 size_t NumMessageViews() const { | 223 size_t NumMessageViews() const { |
226 return scroll_content_->child_count(); | 224 return scroll_content_->child_count(); |
227 } | 225 } |
228 | 226 |
229 private: | 227 private: |
230 void SizeScrollContent() { | 228 void SizeScrollContent() { |
231 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); | 229 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); |
232 const int button_height = button_view_->GetPreferredSize().height(); | 230 const int button_height = button_view_->GetPreferredSize().height(); |
233 const int min_height = kWebNotificationBubbleMinHeight - button_height; | 231 const int min_height = kMessageBubbleBaseMinHeight - button_height; |
234 const int max_height = kWebNotificationBubbleMaxHeight - button_height; | 232 const int max_height = kMessageBubbleBaseMaxHeight - button_height; |
235 int scroll_height = std::min(std::max( | 233 int scroll_height = std::min(std::max( |
236 scroll_size.height(), min_height), max_height); | 234 scroll_size.height(), min_height), max_height); |
237 scroll_size.set_height(scroll_height); | 235 scroll_size.set_height(scroll_height); |
238 if (scroll_height == min_height) | 236 if (scroll_height == min_height) |
239 scroll_content_->set_preferred_size(scroll_size); | 237 scroll_content_->set_preferred_size(scroll_size); |
240 else | 238 else |
241 scroll_content_->set_preferred_size(gfx::Size()); | 239 scroll_content_->set_preferred_size(gfx::Size()); |
242 scroller_->SetFixedSize(scroll_size); | 240 scroller_->SetFixedSize(scroll_size); |
243 scroller_->SizeToPreferredSize(); | 241 scroller_->SizeToPreferredSize(); |
244 scroll_content_->InvalidateLayout(); | 242 scroll_content_->InvalidateLayout(); |
245 } | 243 } |
246 | 244 |
247 WebNotificationList::Delegate* list_delegate_; | 245 NotificationList::Delegate* list_delegate_; |
248 FixedSizedScrollView* scroller_; | 246 FixedSizedScrollView* scroller_; |
249 ScrollContentView* scroll_content_; | 247 ScrollContentView* scroll_content_; |
250 WebNotificationButtonView* button_view_; | 248 WebNotificationButtonView* button_view_; |
251 | 249 |
252 DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); | 250 DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); |
253 }; | 251 }; |
254 | 252 |
255 // Message Center Bubble. | 253 // Message Center Bubble. |
256 MessageCenterBubble::MessageCenterBubble( | 254 MessageCenterBubble::MessageCenterBubble(NotificationList::Delegate* delegate) |
257 WebNotificationList::Delegate* delegate) | 255 : MessageBubbleBase(delegate), |
258 : WebNotificationBubble(delegate), | |
259 contents_view_(NULL) { | 256 contents_view_(NULL) { |
260 } | 257 } |
261 | 258 |
262 MessageCenterBubble::~MessageCenterBubble() {} | 259 MessageCenterBubble::~MessageCenterBubble() {} |
263 | 260 |
264 TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( | 261 views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( |
265 TrayBubbleView::AnchorAlignment anchor_alignment) { | 262 views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
266 TrayBubbleView::InitParams init_params = | 263 views::TrayBubbleView::InitParams init_params = |
267 GetDefaultInitParams(anchor_alignment); | 264 GetDefaultInitParams(anchor_alignment); |
268 init_params.max_height = message_center::kWebNotificationBubbleMaxHeight; | 265 init_params.max_height = kMessageBubbleBaseMaxHeight; |
269 init_params.can_activate = true; | 266 init_params.can_activate = true; |
270 return init_params; | 267 return init_params; |
271 } | 268 } |
272 | 269 |
273 void MessageCenterBubble::InitializeContents(TrayBubbleView* bubble_view) { | 270 void MessageCenterBubble::InitializeContents( |
| 271 views::TrayBubbleView* bubble_view) { |
274 bubble_view_ = bubble_view; | 272 bubble_view_ = bubble_view; |
275 contents_view_ = new MessageCenterContentsView(list_delegate_); | 273 contents_view_ = new MessageCenterContentsView(list_delegate_); |
276 bubble_view_->AddChildView(contents_view_); | 274 bubble_view_->AddChildView(contents_view_); |
277 UpdateBubbleView(); | 275 UpdateBubbleView(); |
278 contents_view_->FocusContents(); | 276 contents_view_->FocusContents(); |
279 } | 277 } |
280 | 278 |
281 void MessageCenterBubble::OnBubbleViewDestroyed() { | 279 void MessageCenterBubble::OnBubbleViewDestroyed() { |
282 contents_view_ = NULL; | 280 contents_view_ = NULL; |
283 } | 281 } |
(...skipping 11 matching lines...) Expand all Loading... |
295 } | 293 } |
296 | 294 |
297 void MessageCenterBubble::OnMouseExitedView() { | 295 void MessageCenterBubble::OnMouseExitedView() { |
298 } | 296 } |
299 | 297 |
300 size_t MessageCenterBubble::NumMessageViewsForTest() const { | 298 size_t MessageCenterBubble::NumMessageViewsForTest() const { |
301 return contents_view_->NumMessageViews(); | 299 return contents_view_->NumMessageViews(); |
302 } | 300 } |
303 | 301 |
304 } // namespace message_center | 302 } // namespace message_center |
OLD | NEW |