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_simple_view.h" | 5 #include "ui/message_center/message_simple_view.h" |
6 | 6 |
7 #include "grit/ui_resources.h" | 7 #include "grit/ui_resources.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
9 #include "ui/message_center/notification.h" | 9 #include "ui/message_center/notification.h" |
10 #include "ui/message_center/notification_list.h" | 10 #include "ui/message_center/notification_list.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 NotificationList::Delegate* list_delegate, | 24 NotificationList::Delegate* list_delegate, |
25 const Notification& notification) | 25 const Notification& notification) |
26 : MessageView(list_delegate, notification) { | 26 : MessageView(list_delegate, notification) { |
27 views::ImageButton* close = new views::ImageButton(this); | 27 views::ImageButton* close = new views::ImageButton(this); |
28 close->SetImage( | 28 close->SetImage( |
29 views::CustomButton::STATE_NORMAL, | 29 views::CustomButton::STATE_NORMAL, |
30 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE)); | 30 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE)); |
31 close->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 31 close->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
32 views::ImageButton::ALIGN_MIDDLE); | 32 views::ImageButton::ALIGN_MIDDLE); |
33 old_style_close_button_.reset(close); | 33 old_style_close_button_.reset(close); |
| 34 SetUpView(notification); |
34 } | 35 } |
35 | 36 |
36 MessageSimpleView::~MessageSimpleView() { | 37 MessageSimpleView::~MessageSimpleView() { |
37 // old_style_close_button_ has to be cleared before content_view_ is cleared. | 38 // old_style_close_button_ has to be cleared before content_view_ is cleared. |
38 // Otherwise, resetting content_view_ will delete old_style_close_button_ so | 39 // Otherwise, resetting content_view_ will delete old_style_close_button_ so |
39 // a double-free happens. | 40 // a double-free happens. |
40 old_style_close_button_.reset(); | 41 old_style_close_button_.reset(); |
41 content_view_.reset(); | 42 content_view_.reset(); |
42 } | 43 } |
43 | 44 |
44 void MessageSimpleView::Layout() { | 45 void MessageSimpleView::Layout() { |
45 if (content_view_) { | 46 if (content_view_) { |
46 gfx::Rect contents_bounds = GetContentsBounds(); | 47 gfx::Rect contents_bounds = GetContentsBounds(); |
47 content_view_->SetBoundsRect(contents_bounds); | 48 content_view_->SetBoundsRect(contents_bounds); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 gfx::Size MessageSimpleView::GetPreferredSize() { | 52 gfx::Size MessageSimpleView::GetPreferredSize() { |
52 if (!content_view_) | 53 if (!content_view_) |
53 return gfx::Size(); | 54 return gfx::Size(); |
54 gfx::Size size = content_view_->GetPreferredSize(); | 55 gfx::Size size = content_view_->GetPreferredSize(); |
55 if (border()) { | 56 if (border()) { |
56 gfx::Insets border_insets = border()->GetInsets(); | 57 gfx::Insets border_insets = border()->GetInsets(); |
57 size.Enlarge(border_insets.width(), border_insets.height()); | 58 size.Enlarge(border_insets.width(), border_insets.height()); |
58 } | 59 } |
59 return size; | 60 return size; |
60 } | 61 } |
61 | 62 |
62 void MessageSimpleView::SetUpView() { | 63 void MessageSimpleView::SetUpView(const Notification& notification) { |
63 views::ImageView* icon = new views::ImageView; | 64 views::ImageView* icon = new views::ImageView; |
64 icon->SetImageSize( | 65 icon->SetImageSize( |
65 gfx::Size(kWebNotificationIconSize, kWebNotificationIconSize)); | 66 gfx::Size(kWebNotificationIconSize, kWebNotificationIconSize)); |
66 icon->SetImage(notification().primary_icon); | 67 icon->SetImage(notification.primary_icon()); |
67 | 68 |
68 views::Label* title = new views::Label(notification().title); | 69 views::Label* title = new views::Label(notification.title()); |
69 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 70 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
70 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); | 71 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); |
71 views::Label* message = new views::Label(notification().message); | 72 views::Label* message = new views::Label(notification.message()); |
72 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 73 message->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
73 message->SetMultiLine(true); | 74 message->SetMultiLine(true); |
74 | 75 |
75 SkColor bg_color = notification().is_read ? | 76 SkColor bg_color = notification.is_read() ? |
76 kNotificationReadColor : kNotificationColor; | 77 kNotificationReadColor : kNotificationColor; |
77 content_view_.reset(new views::View); | 78 content_view_.reset(new views::View); |
78 content_view_->set_background( | 79 content_view_->set_background( |
79 views::Background::CreateSolidBackground(bg_color)); | 80 views::Background::CreateSolidBackground(bg_color)); |
80 AddChildView(content_view_.get()); | 81 AddChildView(content_view_.get()); |
81 views::GridLayout* layout = new views::GridLayout(content_view_.get()); | 82 views::GridLayout* layout = new views::GridLayout(content_view_.get()); |
82 content_view_->SetLayoutManager(layout); | 83 content_view_->SetLayoutManager(layout); |
83 | 84 |
84 views::ColumnSet* columns = layout->AddColumnSet(0); | 85 views::ColumnSet* columns = layout->AddColumnSet(0); |
85 | 86 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 layout->AddPaddingRow(0, kPaddingBetweenItems); | 128 layout->AddPaddingRow(0, kPaddingBetweenItems); |
128 } | 129 } |
129 | 130 |
130 void MessageSimpleView::ButtonPressed(views::Button* sender, | 131 void MessageSimpleView::ButtonPressed(views::Button* sender, |
131 const ui::Event& event) { | 132 const ui::Event& event) { |
132 bool close = (sender == old_style_close_button_.get()); | 133 bool close = (sender == old_style_close_button_.get()); |
133 MessageView::ButtonPressed(close ? close_button() : sender, event); | 134 MessageView::ButtonPressed(close ? close_button() : sender, event); |
134 } | 135 } |
135 | 136 |
136 } // namespace message_center | 137 } // namespace message_center |
OLD | NEW |