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/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/url_formatter/elide_url.h" | 11 #include "components/url_formatter/elide_url.h" |
12 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
13 #include "third_party/skia/include/core/SkPath.h" | 13 #include "third_party/skia/include/core/SkPath.h" |
14 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/layout.h" | 16 #include "ui/base/layout.h" |
17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
19 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
20 #include "ui/gfx/text_elider.h" | 20 #include "ui/gfx/text_elider.h" |
21 #include "ui/message_center/message_center.h" | 21 #include "ui/message_center/message_center.h" |
22 #include "ui/message_center/message_center_style.h" | 22 #include "ui/message_center/message_center_style.h" |
23 #include "ui/message_center/notification.h" | 23 #include "ui/message_center/notification.h" |
24 #include "ui/message_center/notification_types.h" | 24 #include "ui/message_center/notification_types.h" |
25 #include "ui/message_center/views/bounded_label.h" | 25 #include "ui/message_center/views/bounded_label.h" |
26 #include "ui/message_center/views/constants.h" | 26 #include "ui/message_center/views/constants.h" |
27 #include "ui/message_center/views/message_center_controller.h" | 27 #include "ui/message_center/views/message_center_controller.h" |
28 #include "ui/message_center/views/notification_button.h" | 28 #include "ui/message_center/views/notification_button.h" |
| 29 #include "ui/message_center/views/notification_progress_bar.h" |
29 #include "ui/message_center/views/padded_button.h" | 30 #include "ui/message_center/views/padded_button.h" |
30 #include "ui/message_center/views/proportional_image_view.h" | 31 #include "ui/message_center/views/proportional_image_view.h" |
31 #include "ui/native_theme/native_theme.h" | 32 #include "ui/native_theme/native_theme.h" |
32 #include "ui/resources/grit/ui_resources.h" | 33 #include "ui/resources/grit/ui_resources.h" |
33 #include "ui/strings/grit/ui_strings.h" | 34 #include "ui/strings/grit/ui_strings.h" |
34 #include "ui/views/background.h" | 35 #include "ui/views/background.h" |
35 #include "ui/views/border.h" | 36 #include "ui/views/border.h" |
36 #include "ui/views/controls/button/image_button.h" | 37 #include "ui/views/controls/button/image_button.h" |
37 #include "ui/views/controls/image_view.h" | 38 #include "ui/views/controls/image_view.h" |
38 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
39 #include "ui/views/controls/progress_bar.h" | 40 #include "ui/views/controls/progress_bar.h" |
40 #include "ui/views/layout/box_layout.h" | 41 #include "ui/views/layout/box_layout.h" |
41 #include "ui/views/layout/fill_layout.h" | 42 #include "ui/views/layout/fill_layout.h" |
42 #include "ui/views/native_cursor.h" | 43 #include "ui/views/native_cursor.h" |
43 #include "ui/views/painter.h" | 44 #include "ui/views/painter.h" |
44 #include "ui/views/view_targeter.h" | 45 #include "ui/views/view_targeter.h" |
45 #include "ui/views/widget/widget.h" | 46 #include "ui/views/widget/widget.h" |
46 #include "url/gurl.h" | 47 #include "url/gurl.h" |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
50 // Dimensions. | 51 // Dimensions. |
51 const int kProgressBarWidth = message_center::kNotificationWidth - | |
52 message_center::kTextLeftPadding - message_center::kTextRightPadding; | |
53 const int kProgressBarBottomPadding = 0; | 52 const int kProgressBarBottomPadding = 0; |
54 | 53 |
55 // static | 54 // static |
56 scoped_ptr<views::Border> MakeEmptyBorder(int top, | 55 scoped_ptr<views::Border> MakeEmptyBorder(int top, |
57 int left, | 56 int left, |
58 int bottom, | 57 int bottom, |
59 int right) { | 58 int right) { |
60 return views::Border::CreateEmptyBorder(top, left, bottom, right); | 59 return views::Border::CreateEmptyBorder(top, left, bottom, right); |
61 } | 60 } |
62 | 61 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 149 |
151 ItemView::~ItemView() { | 150 ItemView::~ItemView() { |
152 } | 151 } |
153 | 152 |
154 void ItemView::SetVisible(bool visible) { | 153 void ItemView::SetVisible(bool visible) { |
155 views::View::SetVisible(visible); | 154 views::View::SetVisible(visible); |
156 for (int i = 0; i < child_count(); ++i) | 155 for (int i = 0; i < child_count(); ++i) |
157 child_at(i)->SetVisible(visible); | 156 child_at(i)->SetVisible(visible); |
158 } | 157 } |
159 | 158 |
160 // NotificationProgressBar ///////////////////////////////////////////////////// | |
161 | |
162 class NotificationProgressBar : public views::ProgressBar { | |
163 public: | |
164 NotificationProgressBar(); | |
165 ~NotificationProgressBar() override; | |
166 | |
167 private: | |
168 // Overriden from View | |
169 gfx::Size GetPreferredSize() const override; | |
170 void OnPaint(gfx::Canvas* canvas) override; | |
171 | |
172 DISALLOW_COPY_AND_ASSIGN(NotificationProgressBar); | |
173 }; | |
174 | |
175 NotificationProgressBar::NotificationProgressBar() { | |
176 } | |
177 | |
178 NotificationProgressBar::~NotificationProgressBar() { | |
179 } | |
180 | |
181 gfx::Size NotificationProgressBar::GetPreferredSize() const { | |
182 gfx::Size pref_size(kProgressBarWidth, message_center::kProgressBarThickness); | |
183 gfx::Insets insets = GetInsets(); | |
184 pref_size.Enlarge(insets.width(), insets.height()); | |
185 return pref_size; | |
186 } | |
187 | |
188 void NotificationProgressBar::OnPaint(gfx::Canvas* canvas) { | |
189 gfx::Rect content_bounds = GetContentsBounds(); | |
190 | |
191 // Draw background. | |
192 SkPath background_path; | |
193 background_path.addRoundRect(gfx::RectToSkRect(content_bounds), | |
194 message_center::kProgressBarCornerRadius, | |
195 message_center::kProgressBarCornerRadius); | |
196 SkPaint background_paint; | |
197 background_paint.setStyle(SkPaint::kFill_Style); | |
198 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
199 background_paint.setColor(message_center::kProgressBarBackgroundColor); | |
200 canvas->DrawPath(background_path, background_paint); | |
201 | |
202 // Draw slice. | |
203 const int slice_width = | |
204 static_cast<int>(content_bounds.width() * GetNormalizedValue() + 0.5); | |
205 if (slice_width < 1) | |
206 return; | |
207 | |
208 gfx::Rect slice_bounds = content_bounds; | |
209 slice_bounds.set_width(slice_width); | |
210 SkPath slice_path; | |
211 slice_path.addRoundRect(gfx::RectToSkRect(slice_bounds), | |
212 message_center::kProgressBarCornerRadius, | |
213 message_center::kProgressBarCornerRadius); | |
214 SkPaint slice_paint; | |
215 slice_paint.setStyle(SkPaint::kFill_Style); | |
216 slice_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
217 slice_paint.setColor(message_center::kProgressBarSliceColor); | |
218 canvas->DrawPath(slice_path, slice_paint); | |
219 } | |
220 | |
221 } // namespace | 159 } // namespace |
222 | 160 |
223 namespace message_center { | 161 namespace message_center { |
224 | 162 |
225 // NotificationView //////////////////////////////////////////////////////////// | 163 // NotificationView //////////////////////////////////////////////////////////// |
226 | 164 |
227 // static | 165 // static |
228 NotificationView* NotificationView::Create(MessageCenterController* controller, | 166 NotificationView* NotificationView::Create(MessageCenterController* controller, |
229 const Notification& notification, | 167 const Notification& notification, |
230 bool top_level) { | 168 bool top_level) { |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 if (progress_bar_view_) { | 594 if (progress_bar_view_) { |
657 // Deletion will also remove |progress_bar_view_| from its parent. | 595 // Deletion will also remove |progress_bar_view_| from its parent. |
658 delete progress_bar_view_; | 596 delete progress_bar_view_; |
659 progress_bar_view_ = NULL; | 597 progress_bar_view_ = NULL; |
660 } | 598 } |
661 return; | 599 return; |
662 } | 600 } |
663 | 601 |
664 DCHECK(top_view_ != NULL); | 602 DCHECK(top_view_ != NULL); |
665 | 603 |
| 604 bool is_indeterminate = (notification.progress() < 0); |
| 605 if (progress_bar_view_ && |
| 606 progress_bar_view_->is_indeterminate() != is_indeterminate) { |
| 607 delete progress_bar_view_; |
| 608 progress_bar_view_ = NULL; |
| 609 } |
| 610 |
666 if (!progress_bar_view_) { | 611 if (!progress_bar_view_) { |
667 progress_bar_view_ = new NotificationProgressBar(); | 612 if (!is_indeterminate) |
| 613 progress_bar_view_ = new NotificationProgressBar(); |
| 614 else |
| 615 progress_bar_view_ = new NotificationIndeterminateProgressBar(); |
| 616 |
668 progress_bar_view_->SetBorder(MakeProgressBarBorder( | 617 progress_bar_view_->SetBorder(MakeProgressBarBorder( |
669 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | 618 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
670 top_view_->AddChildView(progress_bar_view_); | 619 top_view_->AddChildView(progress_bar_view_); |
671 } | 620 } |
672 | 621 |
673 progress_bar_view_->SetValue(notification.progress() / 100.0); | 622 if (!is_indeterminate) |
| 623 progress_bar_view_->SetValue(notification.progress() / 100.0); |
| 624 |
674 progress_bar_view_->SetVisible(!notification.items().size()); | 625 progress_bar_view_->SetVisible(!notification.items().size()); |
675 } | 626 } |
676 | 627 |
677 void NotificationView::CreateOrUpdateListItemViews( | 628 void NotificationView::CreateOrUpdateListItemViews( |
678 const Notification& notification) { | 629 const Notification& notification) { |
679 for (size_t i = 0; i < item_views_.size(); ++i) | 630 for (size_t i = 0; i < item_views_.size(); ++i) |
680 delete item_views_[i]; | 631 delete item_views_[i]; |
681 item_views_.clear(); | 632 item_views_.clear(); |
682 | 633 |
683 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 634 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 | 792 |
842 return message_line_limit; | 793 return message_line_limit; |
843 } | 794 } |
844 | 795 |
845 int NotificationView::GetMessageHeight(int width, int limit) const { | 796 int NotificationView::GetMessageHeight(int width, int limit) const { |
846 return message_view_ ? | 797 return message_view_ ? |
847 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 798 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
848 } | 799 } |
849 | 800 |
850 } // namespace message_center | 801 } // namespace message_center |
OLD | NEW |