Chromium Code Reviews| 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" | |
|
Jun Mukai
2015/11/24 17:51:12
this is not used here?
yoshiki
2015/11/25 15:14:28
Done.
| |
| 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) { |
| 231 switch (notification.type()) { | 170 switch (notification.type()) { |
| 232 case NOTIFICATION_TYPE_BASE_FORMAT: | 171 case NOTIFICATION_TYPE_BASE_FORMAT: |
| 233 case NOTIFICATION_TYPE_IMAGE: | 172 case NOTIFICATION_TYPE_IMAGE: |
| 234 case NOTIFICATION_TYPE_MULTIPLE: | 173 case NOTIFICATION_TYPE_MULTIPLE: |
| 235 case NOTIFICATION_TYPE_SIMPLE: | 174 case NOTIFICATION_TYPE_SIMPLE: |
| 236 case NOTIFICATION_TYPE_PROGRESS: | 175 case NOTIFICATION_TYPE_PROGRESS: |
| 176 case NOTIFICATION_TYPE_PROGRESS_INDETERMINATE: | |
| 237 break; | 177 break; |
| 238 default: | 178 default: |
| 239 // If the caller asks for an unrecognized kind of view (entirely possible | 179 // If the caller asks for an unrecognized kind of view (entirely possible |
| 240 // if an application is running on an older version of this code that | 180 // if an application is running on an older version of this code that |
| 241 // doesn't have the requested kind of notification template), we'll fall | 181 // doesn't have the requested kind of notification template), we'll fall |
| 242 // back to a notification instance that will provide at least basic | 182 // back to a notification instance that will provide at least basic |
| 243 // functionality. | 183 // functionality. |
| 244 LOG(WARNING) << "Unable to fulfill request for unrecognized " | 184 LOG(WARNING) << "Unable to fulfill request for unrecognized " |
| 245 << "notification type " << notification.type() << ". " | 185 << "notification type " << notification.type() << ". " |
| 246 << "Falling back to simple notification type."; | 186 << "Falling back to simple notification type."; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 return buttons[i]->GetEventHandlerForPoint(point_in_child); | 224 return buttons[i]->GetEventHandlerForPoint(point_in_child); |
| 285 } | 225 } |
| 286 | 226 |
| 287 return root; | 227 return root; |
| 288 } | 228 } |
| 289 | 229 |
| 290 void NotificationView::CreateOrUpdateViews(const Notification& notification) { | 230 void NotificationView::CreateOrUpdateViews(const Notification& notification) { |
| 291 CreateOrUpdateTitleView(notification); | 231 CreateOrUpdateTitleView(notification); |
| 292 CreateOrUpdateMessageView(notification); | 232 CreateOrUpdateMessageView(notification); |
| 293 CreateOrUpdateProgressBarView(notification); | 233 CreateOrUpdateProgressBarView(notification); |
| 234 CreateOrUpdateIndeterminateProgressBarView(notification); | |
| 294 CreateOrUpdateListItemViews(notification); | 235 CreateOrUpdateListItemViews(notification); |
| 295 CreateOrUpdateIconView(notification); | 236 CreateOrUpdateIconView(notification); |
| 296 CreateOrUpdateImageView(notification); | 237 CreateOrUpdateImageView(notification); |
| 297 CreateOrUpdateContextMessageView(notification); | 238 CreateOrUpdateContextMessageView(notification); |
| 298 CreateOrUpdateSettingsButtonView(notification); | 239 CreateOrUpdateSettingsButtonView(notification); |
| 299 CreateOrUpdateActionButtonViews(notification); | 240 CreateOrUpdateActionButtonViews(notification); |
| 300 } | 241 } |
| 301 | 242 |
| 302 void NotificationView::SetAccessibleName(const Notification& notification) { | 243 void NotificationView::SetAccessibleName(const Notification& notification) { |
| 303 std::vector<base::string16> accessible_lines; | 244 std::vector<base::string16> accessible_lines; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 324 clickable_(notification.clickable()), | 265 clickable_(notification.clickable()), |
| 325 top_view_(NULL), | 266 top_view_(NULL), |
| 326 title_view_(NULL), | 267 title_view_(NULL), |
| 327 message_view_(NULL), | 268 message_view_(NULL), |
| 328 context_message_view_(NULL), | 269 context_message_view_(NULL), |
| 329 settings_button_view_(NULL), | 270 settings_button_view_(NULL), |
| 330 icon_view_(NULL), | 271 icon_view_(NULL), |
| 331 bottom_view_(NULL), | 272 bottom_view_(NULL), |
| 332 image_container_(NULL), | 273 image_container_(NULL), |
| 333 image_view_(NULL), | 274 image_view_(NULL), |
| 334 progress_bar_view_(NULL) { | 275 progress_bar_view_(NULL), |
| 276 indeterminate_progress_bar_view_(NULL) { | |
| 335 // Create the top_view_, which collects into a vertical box all content | 277 // Create the top_view_, which collects into a vertical box all content |
| 336 // at the top of the notification (to the right of the icon) except for the | 278 // at the top of the notification (to the right of the icon) except for the |
| 337 // close button. | 279 // close button. |
| 338 top_view_ = new views::View(); | 280 top_view_ = new views::View(); |
| 339 top_view_->SetLayoutManager( | 281 top_view_->SetLayoutManager( |
| 340 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 282 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 341 top_view_->SetBorder( | 283 top_view_->SetBorder( |
| 342 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); | 284 MakeEmptyBorder(kTextTopPadding - 8, 0, kTextBottomPadding - 5, 0)); |
| 343 AddChildView(top_view_); | 285 AddChildView(top_view_); |
| 344 // Create the bottom_view_, which collects into a vertical box all content | 286 // Create the bottom_view_, which collects into a vertical box all content |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 progress_bar_view_ = new NotificationProgressBar(); | 609 progress_bar_view_ = new NotificationProgressBar(); |
| 668 progress_bar_view_->SetBorder(MakeProgressBarBorder( | 610 progress_bar_view_->SetBorder(MakeProgressBarBorder( |
| 669 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | 611 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); |
| 670 top_view_->AddChildView(progress_bar_view_); | 612 top_view_->AddChildView(progress_bar_view_); |
| 671 } | 613 } |
| 672 | 614 |
| 673 progress_bar_view_->SetValue(notification.progress() / 100.0); | 615 progress_bar_view_->SetValue(notification.progress() / 100.0); |
| 674 progress_bar_view_->SetVisible(!notification.items().size()); | 616 progress_bar_view_->SetVisible(!notification.items().size()); |
| 675 } | 617 } |
| 676 | 618 |
| 619 void NotificationView::CreateOrUpdateIndeterminateProgressBarView( | |
| 620 const Notification& notification) { | |
| 621 if (notification.type() != NOTIFICATION_TYPE_PROGRESS_INDETERMINATE) { | |
| 622 if (indeterminate_progress_bar_view_) { | |
| 623 // Deletion will also remove |progress_bar_view_| from its parent. | |
| 624 delete indeterminate_progress_bar_view_; | |
| 625 indeterminate_progress_bar_view_ = NULL; | |
| 626 } | |
| 627 return; | |
| 628 } | |
| 629 | |
| 630 DCHECK(top_view_ != NULL); | |
| 631 | |
| 632 if (!indeterminate_progress_bar_view_) { | |
| 633 indeterminate_progress_bar_view_ = | |
| 634 new NotificationIndeterminateProgressBar(); | |
| 635 indeterminate_progress_bar_view_->SetBorder(MakeProgressBarBorder( | |
| 636 message_center::kProgressBarTopPadding, kProgressBarBottomPadding)); | |
| 637 top_view_->AddChildView(indeterminate_progress_bar_view_); | |
| 638 } | |
| 639 | |
| 640 indeterminate_progress_bar_view_->SetVisible(!notification.items().size()); | |
| 641 } | |
| 642 | |
| 677 void NotificationView::CreateOrUpdateListItemViews( | 643 void NotificationView::CreateOrUpdateListItemViews( |
| 678 const Notification& notification) { | 644 const Notification& notification) { |
| 679 for (size_t i = 0; i < item_views_.size(); ++i) | 645 for (size_t i = 0; i < item_views_.size(); ++i) |
| 680 delete item_views_[i]; | 646 delete item_views_[i]; |
| 681 item_views_.clear(); | 647 item_views_.clear(); |
| 682 | 648 |
| 683 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); | 649 int padding = kMessageLineHeight - views::Label().font_list().GetHeight(); |
| 684 std::vector<NotificationItem> items = notification.items(); | 650 std::vector<NotificationItem> items = notification.items(); |
| 685 | 651 |
| 686 if (items.size() == 0) | 652 if (items.size() == 0) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 | 807 |
| 842 return message_line_limit; | 808 return message_line_limit; |
| 843 } | 809 } |
| 844 | 810 |
| 845 int NotificationView::GetMessageHeight(int width, int limit) const { | 811 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 846 return message_view_ ? | 812 return message_view_ ? |
| 847 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 813 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 848 } | 814 } |
| 849 | 815 |
| 850 } // namespace message_center | 816 } // namespace message_center |
| OLD | NEW |