| 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/animation/slide_animation.h" |
| 17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 19 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 20 #include "ui/gfx/text_elider.h" | 21 #include "ui/gfx/text_elider.h" |
| 21 #include "ui/message_center/message_center.h" | 22 #include "ui/message_center/message_center.h" |
| 22 #include "ui/message_center/message_center_style.h" | 23 #include "ui/message_center/message_center_style.h" |
| 23 #include "ui/message_center/notification.h" | 24 #include "ui/message_center/notification.h" |
| 24 #include "ui/message_center/notification_types.h" | 25 #include "ui/message_center/notification_types.h" |
| 25 #include "ui/message_center/views/bounded_label.h" | 26 #include "ui/message_center/views/bounded_label.h" |
| 26 #include "ui/message_center/views/constants.h" | 27 #include "ui/message_center/views/constants.h" |
| 27 #include "ui/message_center/views/message_center_controller.h" | 28 #include "ui/message_center/views/message_center_controller.h" |
| 28 #include "ui/message_center/views/notification_button.h" | 29 #include "ui/message_center/views/notification_button.h" |
| 30 #include "ui/message_center/views/notification_progress_bar.h" |
| 29 #include "ui/message_center/views/padded_button.h" | 31 #include "ui/message_center/views/padded_button.h" |
| 30 #include "ui/message_center/views/proportional_image_view.h" | 32 #include "ui/message_center/views/proportional_image_view.h" |
| 31 #include "ui/native_theme/native_theme.h" | 33 #include "ui/native_theme/native_theme.h" |
| 32 #include "ui/resources/grit/ui_resources.h" | 34 #include "ui/resources/grit/ui_resources.h" |
| 33 #include "ui/strings/grit/ui_strings.h" | 35 #include "ui/strings/grit/ui_strings.h" |
| 34 #include "ui/views/background.h" | 36 #include "ui/views/background.h" |
| 35 #include "ui/views/border.h" | 37 #include "ui/views/border.h" |
| 36 #include "ui/views/controls/button/image_button.h" | 38 #include "ui/views/controls/button/image_button.h" |
| 37 #include "ui/views/controls/image_view.h" | 39 #include "ui/views/controls/image_view.h" |
| 38 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
| 39 #include "ui/views/controls/progress_bar.h" | 41 #include "ui/views/controls/progress_bar.h" |
| 40 #include "ui/views/layout/box_layout.h" | 42 #include "ui/views/layout/box_layout.h" |
| 41 #include "ui/views/layout/fill_layout.h" | 43 #include "ui/views/layout/fill_layout.h" |
| 42 #include "ui/views/native_cursor.h" | 44 #include "ui/views/native_cursor.h" |
| 43 #include "ui/views/painter.h" | 45 #include "ui/views/painter.h" |
| 44 #include "ui/views/view_targeter.h" | 46 #include "ui/views/view_targeter.h" |
| 45 #include "ui/views/widget/widget.h" | 47 #include "ui/views/widget/widget.h" |
| 46 #include "url/gurl.h" | 48 #include "url/gurl.h" |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| 50 // Dimensions. | 52 // Dimensions. |
| 51 const int kProgressBarWidth = message_center::kNotificationWidth - | |
| 52 message_center::kTextLeftPadding - message_center::kTextRightPadding; | |
| 53 const int kProgressBarBottomPadding = 0; | 53 const int kProgressBarBottomPadding = 0; |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 scoped_ptr<views::Border> MakeEmptyBorder(int top, | 56 scoped_ptr<views::Border> MakeEmptyBorder(int top, |
| 57 int left, | 57 int left, |
| 58 int bottom, | 58 int bottom, |
| 59 int right) { | 59 int right) { |
| 60 return views::Border::CreateEmptyBorder(top, left, bottom, right); | 60 return views::Border::CreateEmptyBorder(top, left, bottom, right); |
| 61 } | 61 } |
| 62 | 62 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 ItemView::~ItemView() { | 151 ItemView::~ItemView() { |
| 152 } | 152 } |
| 153 | 153 |
| 154 void ItemView::SetVisible(bool visible) { | 154 void ItemView::SetVisible(bool visible) { |
| 155 views::View::SetVisible(visible); | 155 views::View::SetVisible(visible); |
| 156 for (int i = 0; i < child_count(); ++i) | 156 for (int i = 0; i < child_count(); ++i) |
| 157 child_at(i)->SetVisible(visible); | 157 child_at(i)->SetVisible(visible); |
| 158 } | 158 } |
| 159 | 159 |
| 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 | 160 } // namespace |
| 222 | 161 |
| 223 namespace message_center { | 162 namespace message_center { |
| 224 | 163 |
| 225 // NotificationView //////////////////////////////////////////////////////////// | 164 // NotificationView //////////////////////////////////////////////////////////// |
| 226 | 165 |
| 227 // static | 166 // static |
| 228 NotificationView* NotificationView::Create(MessageCenterController* controller, | 167 NotificationView* NotificationView::Create(MessageCenterController* controller, |
| 229 const Notification& notification, | 168 const Notification& notification, |
| 230 bool top_level) { | 169 bool top_level) { |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 | 602 |
| 664 DCHECK(top_view_ != NULL); | 603 DCHECK(top_view_ != NULL); |
| 665 | 604 |
| 666 if (!progress_bar_view_) { | 605 if (!progress_bar_view_) { |
| 667 progress_bar_view_ = new NotificationProgressBar(); | 606 progress_bar_view_ = new NotificationProgressBar(); |
| 668 progress_bar_view_->SetBorder(MakeProgressBarBorder( | 607 progress_bar_view_->SetBorder(MakeProgressBarBorder( |
| 669 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | 608 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
| 670 top_view_->AddChildView(progress_bar_view_); | 609 top_view_->AddChildView(progress_bar_view_); |
| 671 } | 610 } |
| 672 | 611 |
| 612 progress_bar_view_->SetIndeterminate(notification.progress() < 0); |
| 673 progress_bar_view_->SetValue(notification.progress() / 100.0); | 613 progress_bar_view_->SetValue(notification.progress() / 100.0); |
| 674 progress_bar_view_->SetVisible(!notification.items().size()); | 614 progress_bar_view_->SetVisible(!notification.items().size()); |
| 675 } | 615 } |
| 676 | 616 |
| 677 void NotificationView::CreateOrUpdateListItemViews( | 617 void NotificationView::CreateOrUpdateListItemViews( |
| 678 const Notification& notification) { | 618 const Notification& notification) { |
| 679 for (size_t i = 0; i < item_views_.size(); ++i) | 619 for (size_t i = 0; i < item_views_.size(); ++i) |
| 680 delete item_views_[i]; | 620 delete item_views_[i]; |
| 681 item_views_.clear(); | 621 item_views_.clear(); |
| 682 | 622 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 | 781 |
| 842 return message_line_limit; | 782 return message_line_limit; |
| 843 } | 783 } |
| 844 | 784 |
| 845 int NotificationView::GetMessageHeight(int width, int limit) const { | 785 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 846 return message_view_ ? | 786 return message_view_ ? |
| 847 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 787 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 848 } | 788 } |
| 849 | 789 |
| 850 } // namespace message_center | 790 } // namespace message_center |
| OLD | NEW |