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/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
11 #include "ui/base/layout.h" | 11 #include "ui/base/layout.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/base/text/text_elider.h" | 13 #include "ui/base/text/text_elider.h" |
14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 #include "ui/gfx/skia_util.h" | |
16 #include "ui/message_center/message_center.h" | 17 #include "ui/message_center/message_center.h" |
17 #include "ui/message_center/message_center_style.h" | 18 #include "ui/message_center/message_center_style.h" |
18 #include "ui/message_center/message_center_switches.h" | 19 #include "ui/message_center/message_center_switches.h" |
19 #include "ui/message_center/message_center_util.h" | 20 #include "ui/message_center/message_center_util.h" |
20 #include "ui/message_center/notification.h" | 21 #include "ui/message_center/notification.h" |
21 #include "ui/message_center/notification_types.h" | 22 #include "ui/message_center/notification_types.h" |
22 #include "ui/message_center/views/bounded_label.h" | 23 #include "ui/message_center/views/bounded_label.h" |
23 #include "ui/native_theme/native_theme.h" | 24 #include "ui/native_theme/native_theme.h" |
24 #include "ui/views/controls/button/image_button.h" | 25 #include "ui/views/controls/button/image_button.h" |
25 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
26 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
27 #include "ui/views/controls/progress_bar.h" | 28 #include "ui/views/controls/progress_bar.h" |
28 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/fill_layout.h" | 30 #include "ui/views/layout/fill_layout.h" |
30 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Dimensions. | 35 // Dimensions. |
35 const int kIconSize = message_center::kNotificationIconSize; | 36 const int kIconSize = message_center::kNotificationIconSize; |
36 const int kLegacyIconSize = 40; | 37 const int kLegacyIconSize = 40; |
37 const int kIconBottomPadding = 16; | 38 const int kIconBottomPadding = 16; |
38 const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding; | 39 const int kTextLeftPadding = kIconSize + message_center::kIconToTextPadding; |
39 const int kTextBottomPadding = 12; | 40 const int kTextBottomPadding = 12; |
40 const int kTextRightPadding = 23; | 41 const int kTextRightPadding = 23; |
41 const int kItemTitleToMessagePadding = 3; | 42 const int kItemTitleToMessagePadding = 3; |
42 const int kProgressBarWidth = message_center::kNotificationWidth - | 43 const int kProgressBarWidth = message_center::kNotificationWidth - |
43 kTextLeftPadding - kTextRightPadding; | 44 kTextLeftPadding - kTextRightPadding; |
44 const int kProgressBarHeight = 8; | 45 const int kProgressBarBottomPadding = 0; |
45 const int kProgressBarTopPadding = 12; | |
46 const int kProgressBarBottomPadding = 2; | |
47 const int kButtonVecticalPadding = 0; | 46 const int kButtonVecticalPadding = 0; |
48 const int kButtonTitleTopPadding = 0; | 47 const int kButtonTitleTopPadding = 0; |
49 | 48 |
50 // Character limits: Displayed text will be subject to the line limits above, | 49 // Character limits: Displayed text will be subject to the line limits above, |
51 // but we also remove trailing characters from text to reduce processing cost. | 50 // but we also remove trailing characters from text to reduce processing cost. |
52 // Character limit = pixels per line * line limit / min. pixels per character. | 51 // Character limit = pixels per line * line limit / min. pixels per character. |
53 const size_t kTitleCharacterLimit = | 52 const size_t kTitleCharacterLimit = |
54 message_center::kNotificationWidth * message_center::kTitleLineLimit / 4; | 53 message_center::kNotificationWidth * message_center::kTitleLineLimit / 4; |
55 const size_t kMessageCharacterLimit = | 54 const size_t kMessageCharacterLimit = |
56 message_center::kNotificationWidth * | 55 message_center::kNotificationWidth * |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 // NotificationProgressBar ///////////////////////////////////////////////////// | 236 // NotificationProgressBar ///////////////////////////////////////////////////// |
238 | 237 |
239 class NotificationProgressBar : public views::ProgressBar { | 238 class NotificationProgressBar : public views::ProgressBar { |
240 public: | 239 public: |
241 NotificationProgressBar(); | 240 NotificationProgressBar(); |
242 virtual ~NotificationProgressBar(); | 241 virtual ~NotificationProgressBar(); |
243 | 242 |
244 private: | 243 private: |
245 // Overriden from View | 244 // Overriden from View |
246 virtual gfx::Size GetPreferredSize() OVERRIDE; | 245 virtual gfx::Size GetPreferredSize() OVERRIDE; |
246 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
247 | 247 |
248 DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar); | 248 DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar); |
249 }; | 249 }; |
250 | 250 |
251 NotificationProgressBar::NotificationProgressBar() { | 251 NotificationProgressBar::NotificationProgressBar() { |
252 } | 252 } |
253 | 253 |
254 NotificationProgressBar::~NotificationProgressBar() { | 254 NotificationProgressBar::~NotificationProgressBar() { |
255 } | 255 } |
256 | 256 |
257 gfx::Size NotificationProgressBar::GetPreferredSize() { | 257 gfx::Size NotificationProgressBar::GetPreferredSize() { |
258 gfx::Size pref_size(kProgressBarWidth, kProgressBarHeight); | 258 gfx::Size pref_size(kProgressBarWidth, message_center::kProgressBarThickness); |
259 gfx::Insets insets = GetInsets(); | 259 gfx::Insets insets = GetInsets(); |
260 pref_size.Enlarge(insets.width(), insets.height()); | 260 pref_size.Enlarge(insets.width(), insets.height()); |
261 return pref_size; | 261 return pref_size; |
262 } | 262 } |
263 | 263 |
264 void NotificationProgressBar::OnPaint(gfx::Canvas* canvas) { | |
265 gfx::Rect content_bounds = GetContentsBounds(); | |
266 int bar_left = content_bounds.x(); | |
267 int bar_top = content_bounds.y(); | |
268 int bar_width = content_bounds.width(); | |
269 int bar_height = content_bounds.height(); | |
270 | |
271 // Draw background. | |
272 SkPath background_path; | |
273 background_path.addRoundRect(gfx::RectToSkRect(content_bounds), | |
274 message_center::kProgressBarCornerRadius, | |
275 message_center::kProgressBarCornerRadius); | |
276 SkPaint background_paint; | |
277 background_paint.setStyle(SkPaint::kFill_Style); | |
278 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
279 background_paint.setColor(message_center::kProgressBarBackgroundColor); | |
280 canvas->DrawPath(background_path, background_paint); | |
281 | |
282 // Draw slice. | |
283 const int slice_width = | |
284 static_cast<int>(bar_width * GetNormalizedValue() + 0.5); | |
285 if (slice_width < 1) | |
286 return; | |
287 | |
288 gfx::Rect slice_bounds = content_bounds; | |
289 slice_bounds.set_width(slice_width); | |
290 SkPath slice_path; | |
291 slice_path.addRoundRect(gfx::RectToSkRect(slice_bounds), | |
292 message_center::kProgressBarCornerRadius, | |
293 message_center::kProgressBarCornerRadius); | |
294 SkPaint slice_paint; | |
295 slice_paint.setStyle(SkPaint::kFill_Style); | |
296 slice_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
297 slice_paint.setColor(message_center::kProgressBarSliceColor); | |
298 canvas->DrawPath(slice_path, slice_paint); | |
299 } | |
300 | |
264 // NotificationButton ////////////////////////////////////////////////////////// | 301 // NotificationButton ////////////////////////////////////////////////////////// |
265 | 302 |
266 // NotificationButtons render the action buttons of notifications. | 303 // NotificationButtons render the action buttons of notifications. |
267 class NotificationButton : public views::CustomButton { | 304 class NotificationButton : public views::CustomButton { |
268 public: | 305 public: |
269 NotificationButton(views::ButtonListener* listener); | 306 NotificationButton(views::ButtonListener* listener); |
270 virtual ~NotificationButton(); | 307 virtual ~NotificationButton(); |
271 | 308 |
272 void SetIcon(const gfx::ImageSkia& icon); | 309 void SetIcon(const gfx::ImageSkia& icon); |
273 void SetTitle(const string16& title); | 310 void SetTitle(const string16& title); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 message_view_->set_border(MakeTextBorder(padding, 4, 0)); | 496 message_view_->set_border(MakeTextBorder(padding, 4, 0)); |
460 top_view_->AddChildView(message_view_); | 497 top_view_->AddChildView(message_view_); |
461 accessible_lines.push_back(notification.message()); | 498 accessible_lines.push_back(notification.message()); |
462 } | 499 } |
463 | 500 |
464 // Create the progress bar view. | 501 // Create the progress bar view. |
465 progress_bar_view_ = NULL; | 502 progress_bar_view_ = NULL; |
466 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { | 503 if (notification.type() == NOTIFICATION_TYPE_PROGRESS) { |
467 progress_bar_view_ = new NotificationProgressBar(); | 504 progress_bar_view_ = new NotificationProgressBar(); |
468 progress_bar_view_->set_border(MakeProgressBarBorder( | 505 progress_bar_view_->set_border(MakeProgressBarBorder( |
469 kProgressBarTopPadding, kProgressBarBottomPadding)); | 506 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
dewittj
2013/08/05 22:34:39
Why move one to message_center and not the other?
jianli
2013/08/05 22:42:16
We do not need extra bottom padding for progress b
| |
470 progress_bar_view_->SetValue(notification.progress() / 100.0); | 507 progress_bar_view_->SetValue(notification.progress() / 100.0); |
471 top_view_->AddChildView(progress_bar_view_); | 508 top_view_->AddChildView(progress_bar_view_); |
472 } | 509 } |
473 | 510 |
474 // Create the list item views (up to a maximum). | 511 // Create the list item views (up to a maximum). |
475 int padding = kMessageLineHeight - views::Label().font().GetHeight(); | 512 int padding = kMessageLineHeight - views::Label().font().GetHeight(); |
476 std::vector<NotificationItem> items = notification.items(); | 513 std::vector<NotificationItem> items = notification.items(); |
477 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { | 514 for (size_t i = 0; i < items.size() && i < kNotificationMaximumItems; ++i) { |
478 ItemView* item_view = new ItemView(items[i]); | 515 ItemView* item_view = new ItemView(items[i]); |
479 item_view->SetVisible(is_expanded()); | 516 item_view->SetVisible(is_expanded()); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 return message_view_ ? | 761 return message_view_ ? |
725 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; | 762 message_view_->GetLinesForWidthAndLimit(width, limit) : 0; |
726 } | 763 } |
727 | 764 |
728 int NotificationView::GetMessageHeight(int width, int limit) { | 765 int NotificationView::GetMessageHeight(int width, int limit) { |
729 return message_view_ ? | 766 return message_view_ ? |
730 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 767 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
731 } | 768 } |
732 | 769 |
733 } // namespace message_center | 770 } // namespace message_center |
OLD | NEW |