Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1233)

Side by Side Diff: ui/message_center/views/notification_header_view.cc

Issue 2945303006: Add percentage of progress in notification header. (Closed)
Patch Set: Resolve review comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_header_view.h" 5 #include "ui/message_center/views/notification_header_view.h"
6 6
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
7 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
8 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
9 #include "ui/gfx/font_list.h" 11 #include "ui/gfx/font_list.h"
10 #include "ui/gfx/paint_vector_icon.h" 12 #include "ui/gfx/paint_vector_icon.h"
11 #include "ui/message_center/message_center_style.h" 13 #include "ui/message_center/message_center_style.h"
12 #include "ui/message_center/vector_icons.h" 14 #include "ui/message_center/vector_icons.h"
13 #include "ui/message_center/views/padded_button.h" 15 #include "ui/message_center/views/padded_button.h"
14 #include "ui/strings/grit/ui_strings.h" 16 #include "ui/strings/grit/ui_strings.h"
15 #include "ui/views/controls/button/image_button.h" 17 #include "ui/views/controls/button/image_button.h"
16 #include "ui/views/controls/image_view.h" 18 #include "ui/views/controls/image_view.h"
17 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
18 #include "ui/views/layout/box_layout.h" 20 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/painter.h" 21 #include "ui/views/painter.h"
20 22
21 namespace message_center { 23 namespace message_center {
22 24
23 namespace { 25 namespace {
24 26
25 constexpr int kHeaderHeight = 28; 27 constexpr int kHeaderHeight = 28;
26 constexpr int kAppIconSize = 12; 28 constexpr int kAppIconSize = 12;
27 constexpr int kExpandIconSize = 12; 29 constexpr int kExpandIconSize = 12;
28 constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2); 30 constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2);
29 constexpr int kHeaderHorizontalSpacing = 2; 31 constexpr int kHeaderHorizontalSpacing = 2;
30 constexpr int kAppInfoConatainerTopPadding = 12; 32 constexpr int kAppInfoConatainerTopPadding = 12;
33 // Bullet character. The divider symbol between different parts of the header.
34 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022;
31 35
32 } // namespace 36 } // namespace
33 37
34 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) 38 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener)
35 : views::CustomButton(listener) { 39 : views::CustomButton(listener) {
36 views::BoxLayout* layout = new views::BoxLayout( 40 views::BoxLayout* layout = new views::BoxLayout(
37 views::BoxLayout::kHorizontal, kHeaderPadding, kHeaderHorizontalSpacing); 41 views::BoxLayout::kHorizontal, kHeaderPadding, kHeaderHorizontalSpacing);
38 layout->set_cross_axis_alignment( 42 layout->set_cross_axis_alignment(
39 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 43 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
40 SetLayoutManager(layout); 44 SetLayoutManager(layout);
(...skipping 14 matching lines...) Expand all
55 app_info_container->AddChildView(app_icon_view_); 59 app_info_container->AddChildView(app_icon_view_);
56 60
57 // App name view 61 // App name view
58 const gfx::FontList& font_list = views::Label().font_list().Derive( 62 const gfx::FontList& font_list = views::Label().font_list().Derive(
59 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); 63 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
60 app_name_view_ = new views::Label(base::string16()); 64 app_name_view_ = new views::Label(base::string16());
61 app_name_view_->SetFontList(font_list); 65 app_name_view_->SetFontList(font_list);
62 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 66 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
63 app_info_container->AddChildView(app_name_view_); 67 app_info_container->AddChildView(app_name_view_);
64 68
69 // Summary text divider
70 summary_text_divider_ =
71 new views::Label(base::ASCIIToUTF16(" ") +
72 base::string16(1, kNotificationHeaderDividerSymbol) +
73 base::ASCIIToUTF16(" "));
74 summary_text_divider_->SetFontList(font_list);
75 summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
76 summary_text_divider_->SetVisible(false);
77 app_info_container->AddChildView(summary_text_divider_);
78
79 // Summary text view
80 summary_text_view_ = new views::Label(base::string16());
81 summary_text_view_->SetFontList(font_list);
82 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
83 summary_text_view_->SetVisible(false);
84 app_info_container->AddChildView(summary_text_view_);
85
65 // Expand button view 86 // Expand button view
66 expand_button_ = new views::ImageButton(listener); 87 expand_button_ = new views::ImageButton(listener);
67 expand_button_->SetImage( 88 expand_button_->SetImage(
68 views::Button::STATE_NORMAL, 89 views::Button::STATE_NORMAL,
69 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize, 90 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize,
70 gfx::kChromeIconGrey)); 91 gfx::kChromeIconGrey));
71 expand_button_->SetFocusForPlatform(); 92 expand_button_->SetFocusForPlatform();
72 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter( 93 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter(
73 kFocusBorderColor, gfx::Insets(1, 2, 2, 2))); 94 kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
74 app_info_container->AddChildView(expand_button_); 95 app_info_container->AddChildView(expand_button_);
(...skipping 24 matching lines...) Expand all
99 } 120 }
100 121
101 void NotificationHeaderView::SetAppIcon(const gfx::ImageSkia& img) { 122 void NotificationHeaderView::SetAppIcon(const gfx::ImageSkia& img) {
102 app_icon_view_->SetImage(img); 123 app_icon_view_->SetImage(img);
103 } 124 }
104 125
105 void NotificationHeaderView::SetAppName(const base::string16& name) { 126 void NotificationHeaderView::SetAppName(const base::string16& name) {
106 app_name_view_->SetText(name); 127 app_name_view_->SetText(name);
107 } 128 }
108 129
130 void NotificationHeaderView::SetProgress(int progress) {
131 summary_text_view_->SetText(l10n_util::GetStringFUTF16Int(
132 IDS_MESSAGE_CENTER_NOTIFICATION_PROGRESS_PERCENTAGE, progress));
133 has_summary_text_ = true;
134 UpdateSummaryTextVisibility();
135 }
136
137 void NotificationHeaderView::ClearProgress() {
138 has_summary_text_ = false;
139 UpdateSummaryTextVisibility();
140 }
141
109 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { 142 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) {
110 expand_button_->SetVisible(enabled); 143 expand_button_->SetVisible(enabled);
111 } 144 }
112 145
113 void NotificationHeaderView::SetExpanded(bool expanded) { 146 void NotificationHeaderView::SetExpanded(bool expanded) {
114 expand_button_->SetImage( 147 expand_button_->SetImage(
115 views::Button::STATE_NORMAL, 148 views::Button::STATE_NORMAL,
116 gfx::CreateVectorIcon( 149 gfx::CreateVectorIcon(
117 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon, 150 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon,
118 kExpandIconSize, gfx::kChromeIconGrey)); 151 kExpandIconSize, gfx::kChromeIconGrey));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 185 }
153 186
154 void NotificationHeaderView::UpdateControlButtonsVisibility() { 187 void NotificationHeaderView::UpdateControlButtonsVisibility() {
155 settings_button_->SetVisible(settings_button_enabled_ && 188 settings_button_->SetVisible(settings_button_enabled_ &&
156 is_control_buttons_visible_); 189 is_control_buttons_visible_);
157 close_button_->SetVisible(close_button_enabled_ && 190 close_button_->SetVisible(close_button_enabled_ &&
158 is_control_buttons_visible_); 191 is_control_buttons_visible_);
159 Layout(); 192 Layout();
160 } 193 }
161 194
195 void NotificationHeaderView::UpdateSummaryTextVisibility() {
196 summary_text_divider_->SetVisible(has_summary_text_);
197 summary_text_view_->SetVisible(has_summary_text_);
198 Layout();
199 }
200
162 } // namespace message_center 201 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_header_view.h ('k') | ui/message_center/views/notification_view_md.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698