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 "base/command_line.h" | |
7 #include "grit/ui_strings.h" | 8 #include "grit/ui_strings.h" |
8 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
9 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/gfx/size.h" | 11 #include "ui/gfx/size.h" |
12 #include "ui/message_center/message_center_switches.h" | |
11 #include "ui/message_center/message_view.h" | 13 #include "ui/message_center/message_view.h" |
12 #include "ui/message_center/message_view_factory.h" | 14 #include "ui/message_center/message_view_factory.h" |
15 #include "ui/views/background.h" | |
16 #include "ui/views/border.h" | |
13 #include "ui/views/controls/button/text_button.h" | 17 #include "ui/views/controls/button/text_button.h" |
14 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
15 #include "ui/views/controls/scroll_view.h" | 19 #include "ui/views/controls/scroll_view.h" |
16 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
17 #include "ui/views/layout/grid_layout.h" | 21 #include "ui/views/layout/grid_layout.h" |
18 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
19 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
20 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
21 | 25 |
22 namespace message_center { | 26 namespace message_center { |
23 | 27 |
24 namespace { | 28 namespace { |
25 | 29 |
26 const int kMessageBubbleBaseMinHeight = 80; | 30 const int kMessageBubbleBaseMinHeight = 80; |
27 const int kMessageBubbleBaseMaxHeight = 400; | 31 const int kMessageBubbleBaseMaxHeight = 400; |
32 const int kMarginBetweenItems = 10; | |
33 const int kItemShadowHeight = 4; | |
34 const SkColor kMessageCenterBackgroundColor = SkColorSetRGB(0xe5, 0xe5, 0xe5); | |
28 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 35 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); |
36 const SkColor kMessageItemShadowColorBase = SkColorSetARGB(0.3 * 255, 0, 0, 0); | |
37 const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); | |
38 | |
39 bool UseNewDesign() { | |
40 return CommandLine::ForCurrentProcess()->HasSwitch( | |
41 switches::kEnableNewMessageCenterBubble); | |
42 } | |
29 | 43 |
30 // The view for the buttons at the bottom of the web notification tray. | 44 // The view for the buttons at the bottom of the web notification tray. |
31 class WebNotificationButtonView : public views::View, | 45 class WebNotificationButtonView : public views::View, |
32 public views::ButtonListener { | 46 public views::ButtonListener { |
33 public: | 47 public: |
34 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) | 48 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) |
35 : list_delegate_(list_delegate), | 49 : list_delegate_(list_delegate), |
36 close_all_button_(NULL) { | 50 close_all_button_(NULL) { |
37 set_background(views::Background::CreateBackgroundPainter( | 51 set_background(views::Background::CreateBackgroundPainter( |
38 true, | 52 true, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 | 96 |
83 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); | 97 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); |
84 }; | 98 }; |
85 | 99 |
86 // A custom scroll-view that has a specified size. | 100 // A custom scroll-view that has a specified size. |
87 class FixedSizedScrollView : public views::ScrollView { | 101 class FixedSizedScrollView : public views::ScrollView { |
88 public: | 102 public: |
89 FixedSizedScrollView() { | 103 FixedSizedScrollView() { |
90 set_focusable(true); | 104 set_focusable(true); |
91 set_notify_enter_exit_on_child(true); | 105 set_notify_enter_exit_on_child(true); |
106 if (UseNewDesign()) { | |
107 set_background(views::Background::CreateSolidBackground( | |
108 kMessageCenterBackgroundColor)); | |
109 } | |
92 } | 110 } |
93 | 111 |
94 virtual ~FixedSizedScrollView() {} | 112 virtual ~FixedSizedScrollView() {} |
95 | 113 |
96 void SetFixedSize(const gfx::Size& size) { | 114 void SetFixedSize(const gfx::Size& size) { |
97 if (fixed_size_ == size) | 115 if (fixed_size_ == size) |
98 return; | 116 return; |
99 fixed_size_ = size; | 117 fixed_size_ = size; |
100 PreferredSizeChanged(); | 118 PreferredSizeChanged(); |
101 } | 119 } |
(...skipping 29 matching lines...) Expand all Loading... | |
131 private: | 149 private: |
132 gfx::Size fixed_size_; | 150 gfx::Size fixed_size_; |
133 | 151 |
134 DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); | 152 DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); |
135 }; | 153 }; |
136 | 154 |
137 // Container for the messages. | 155 // Container for the messages. |
138 class ScrollContentView : public views::View { | 156 class ScrollContentView : public views::View { |
139 public: | 157 public: |
140 ScrollContentView() { | 158 ScrollContentView() { |
141 views::BoxLayout* layout = | 159 if (UseNewDesign()) { |
142 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); | 160 // Set the margin to 0 for the layout. BoxLayout assumes the same margin |
143 layout->set_spread_blank_space(true); | 161 // for top and bottom, but the bottom margin here should be smaller |
144 SetLayoutManager(layout); | 162 // because of the shadow of message view. Use an empty border instead |
163 // to provide this margin. | |
164 SetLayoutManager( | |
165 new views::BoxLayout(views::BoxLayout::kVertical, | |
166 0, | |
167 0, | |
168 kMarginBetweenItems - kItemShadowHeight)); | |
169 set_background(views::Background::CreateSolidBackground( | |
170 kMessageCenterBackgroundColor)); | |
171 set_border(views::Border::CreateEmptyBorder( | |
172 kMarginBetweenItems, /* top */ | |
173 kMarginBetweenItems, /* left */ | |
174 kMarginBetweenItems - kItemShadowHeight, /* bottom */ | |
175 kMarginBetweenItems /* right */ )); | |
176 } else { | |
177 views::BoxLayout* layout = | |
178 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); | |
179 layout->set_spread_blank_space(true); | |
180 SetLayoutManager(layout); | |
181 } | |
145 } | 182 } |
146 | 183 |
147 virtual ~ScrollContentView() { | 184 virtual ~ScrollContentView() { |
148 } | 185 } |
149 | 186 |
150 virtual gfx::Size GetPreferredSize() OVERRIDE { | 187 virtual gfx::Size GetPreferredSize() OVERRIDE { |
151 if (!preferred_size_.IsEmpty()) | 188 if (!preferred_size_.IsEmpty()) |
152 return preferred_size_; | 189 return preferred_size_; |
153 return views::View::GetPreferredSize(); | 190 return views::View::GetPreferredSize(); |
154 } | 191 } |
155 | 192 |
156 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } | 193 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } |
157 | 194 |
158 private: | 195 private: |
159 gfx::Size preferred_size_; | 196 gfx::Size preferred_size_; |
160 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); | 197 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); |
161 }; | 198 }; |
162 | 199 |
200 // A view to draw gradient shadow for each MessageView. | |
201 class MessageViewShadow : public views::View { | |
202 public: | |
203 MessageViewShadow() | |
204 : painter_(views::Painter::CreateVerticalGradient( | |
205 kMessageItemShadowColorBase, kTransparentColor)) { | |
206 } | |
207 | |
208 private: | |
209 // views::View overrides: | |
210 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
211 // The preferred size must not be empty. Thus put an arbitrary non-zero | |
212 // width here. It will be just ignored by the vertical box layout. | |
213 return gfx::Size(1, kItemShadowHeight); | |
214 } | |
215 | |
216 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
217 painter_->Paint(canvas, bounds().size()); | |
218 } | |
219 | |
220 scoped_ptr<views::Painter> painter_; | |
221 DISALLOW_COPY_AND_ASSIGN(MessageViewShadow); | |
222 }; | |
223 | |
163 } // namespace | 224 } // namespace |
164 | 225 |
165 // Message Center contents. | 226 // Message Center contents. |
166 class MessageCenterContentsView : public views::View { | 227 class MessageCenterContentsView : public views::View { |
167 public: | 228 public: |
168 explicit MessageCenterContentsView(NotificationList::Delegate* list_delegate) | 229 explicit MessageCenterContentsView(NotificationList::Delegate* list_delegate) |
169 : list_delegate_(list_delegate) { | 230 : list_delegate_(list_delegate) { |
231 int between_child = UseNewDesign() ? 0 : 1; | |
170 SetLayoutManager( | 232 SetLayoutManager( |
171 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 233 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, between_child)); |
172 | 234 |
173 scroll_content_ = new ScrollContentView; | 235 scroll_content_ = new ScrollContentView; |
174 scroller_ = new FixedSizedScrollView; | 236 scroller_ = new FixedSizedScrollView; |
175 scroller_->SetContents(scroll_content_); | 237 scroller_->SetContents(scroll_content_); |
176 AddChildView(scroller_); | 238 AddChildView(scroller_); |
177 | 239 |
178 scroller_->SetPaintToLayer(true); | 240 scroller_->SetPaintToLayer(true); |
179 scroller_->SetFillsBoundsOpaquely(false); | 241 scroller_->SetFillsBoundsOpaquely(false); |
180 scroller_->layer()->SetMasksToBounds(true); | 242 scroller_->layer()->SetMasksToBounds(true); |
181 | 243 |
182 button_view_ = new WebNotificationButtonView(list_delegate); | 244 button_view_ = new WebNotificationButtonView(list_delegate); |
183 AddChildView(button_view_); | 245 AddChildView(button_view_); |
184 } | 246 } |
185 | 247 |
186 void FocusContents() { | 248 void FocusContents() { |
187 scroller_->RequestFocus(); | 249 scroller_->RequestFocus(); |
188 } | 250 } |
189 | 251 |
190 void Update(const NotificationList::Notifications& notifications) { | 252 void Update(const NotificationList::Notifications& notifications) { |
191 scroll_content_->RemoveAllChildViews(true); | 253 scroll_content_->RemoveAllChildViews(true); |
192 scroll_content_->set_preferred_size(gfx::Size()); | 254 scroll_content_->set_preferred_size(gfx::Size()); |
193 size_t num_children = 0; | 255 size_t num_children = 0; |
194 for (NotificationList::Notifications::const_iterator iter = | 256 for (NotificationList::Notifications::const_iterator iter = |
195 notifications.begin(); iter != notifications.end(); ++iter) { | 257 notifications.begin(); iter != notifications.end(); ++iter) { |
196 MessageView* view = | 258 MessageView* view = |
197 MessageViewFactory::ViewForNotification(*iter, list_delegate_); | 259 MessageViewFactory::ViewForNotification(*iter, list_delegate_); |
198 view->set_scroller(scroller_); | 260 view->set_scroller(scroller_); |
199 view->SetUpView(); | 261 view->SetUpView(); |
200 scroll_content_->AddChildView(view); | 262 if (UseNewDesign()) { |
263 views::View* container = new views::View(); | |
264 container->SetLayoutManager( | |
265 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
266 container->AddChildView(view); | |
267 container->AddChildView(new MessageViewShadow()); | |
268 scroll_content_->AddChildView(container); | |
269 } else { | |
270 scroll_content_->AddChildView(view); | |
271 } | |
dharcourt
2013/01/07 23:08:16
Couldn't the view and its shadow be two views one
Jun Mukai
2013/01/08 01:33:22
The margin between the |view| and shadow has to be
dharcourt
2013/01/08 01:43:37
You're right :-). Sorry I missed that.
| |
201 if (++num_children >= | 272 if (++num_children >= |
202 NotificationList::kMaxVisibleMessageCenterNotifications) { | 273 NotificationList::kMaxVisibleMessageCenterNotifications) { |
203 break; | 274 break; |
204 } | 275 } |
205 } | 276 } |
206 if (num_children == 0) { | 277 if (num_children == 0) { |
207 views::Label* label = new views::Label(l10n_util::GetStringUTF16( | 278 views::Label* label = new views::Label(l10n_util::GetStringUTF16( |
208 IDS_MESSAGE_CENTER_NO_MESSAGES)); | 279 IDS_MESSAGE_CENTER_NO_MESSAGES)); |
209 label->SetFont(label->font().DeriveFont(1)); | 280 label->SetFont(label->font().DeriveFont(1)); |
210 label->SetEnabledColor(SK_ColorGRAY); | 281 label->SetEnabledColor(SK_ColorGRAY); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 : MessageBubbleBase(delegate), | 325 : MessageBubbleBase(delegate), |
255 contents_view_(NULL) { | 326 contents_view_(NULL) { |
256 } | 327 } |
257 | 328 |
258 MessageCenterBubble::~MessageCenterBubble() {} | 329 MessageCenterBubble::~MessageCenterBubble() {} |
259 | 330 |
260 views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( | 331 views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( |
261 views::TrayBubbleView::AnchorAlignment anchor_alignment) { | 332 views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
262 views::TrayBubbleView::InitParams init_params = | 333 views::TrayBubbleView::InitParams init_params = |
263 GetDefaultInitParams(anchor_alignment); | 334 GetDefaultInitParams(anchor_alignment); |
335 if (UseNewDesign()) { | |
336 init_params.min_width += kMarginBetweenItems * 2; | |
337 init_params.max_width += kMarginBetweenItems * 2; | |
dharcourt
2013/01/07 23:08:16
Message_view.h's kWebNotificationWidth needs to be
Jun Mukai
2013/01/08 01:33:22
very good catch...
I talked with somas, and he sa
| |
338 } | |
339 // TODO(mukai): The new design bubble should have screen-height at most. | |
264 init_params.max_height = kMessageBubbleBaseMaxHeight; | 340 init_params.max_height = kMessageBubbleBaseMaxHeight; |
265 init_params.can_activate = true; | 341 init_params.can_activate = true; |
266 return init_params; | 342 return init_params; |
267 } | 343 } |
268 | 344 |
269 void MessageCenterBubble::InitializeContents( | 345 void MessageCenterBubble::InitializeContents( |
270 views::TrayBubbleView* new_bubble_view) { | 346 views::TrayBubbleView* new_bubble_view) { |
271 set_bubble_view(new_bubble_view); | 347 set_bubble_view(new_bubble_view); |
272 contents_view_ = new MessageCenterContentsView(list_delegate()); | 348 contents_view_ = new MessageCenterContentsView(list_delegate()); |
273 bubble_view()->AddChildView(contents_view_); | 349 bubble_view()->AddChildView(contents_view_); |
(...skipping 19 matching lines...) Expand all Loading... | |
293 } | 369 } |
294 | 370 |
295 void MessageCenterBubble::OnMouseExitedView() { | 371 void MessageCenterBubble::OnMouseExitedView() { |
296 } | 372 } |
297 | 373 |
298 size_t MessageCenterBubble::NumMessageViewsForTest() const { | 374 size_t MessageCenterBubble::NumMessageViewsForTest() const { |
299 return contents_view_->NumMessageViews(); | 375 return contents_view_->NumMessageViews(); |
300 } | 376 } |
301 | 377 |
302 } // namespace message_center | 378 } // namespace message_center |
OLD | NEW |