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

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

Issue 2945303006: Add percentage of progress in notification header. (Closed)
Patch Set: Fix merge mistake. 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 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022;
yoshiki 2017/06/27 07:15:18 nit: could you explain about the character as a co
tetsui 2017/06/27 07:37:36 Done.
31 34
32 } // namespace 35 } // namespace
33 36
34 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) 37 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener)
35 : views::CustomButton(listener) { 38 : views::CustomButton(listener) {
36 views::BoxLayout* layout = new views::BoxLayout( 39 views::BoxLayout* layout = new views::BoxLayout(
37 views::BoxLayout::kHorizontal, kHeaderPadding, kHeaderHorizontalSpacing); 40 views::BoxLayout::kHorizontal, kHeaderPadding, kHeaderHorizontalSpacing);
38 layout->set_cross_axis_alignment( 41 layout->set_cross_axis_alignment(
39 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 42 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
40 SetLayoutManager(layout); 43 SetLayoutManager(layout);
(...skipping 14 matching lines...) Expand all
55 app_info_container->AddChildView(app_icon_view_); 58 app_info_container->AddChildView(app_icon_view_);
56 59
57 // App name view 60 // App name view
58 const gfx::FontList& font_list = views::Label().font_list().Derive( 61 const gfx::FontList& font_list = views::Label().font_list().Derive(
59 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL); 62 -2, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL);
60 app_name_view_ = new views::Label(base::string16()); 63 app_name_view_ = new views::Label(base::string16());
61 app_name_view_->SetFontList(font_list); 64 app_name_view_->SetFontList(font_list);
62 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 65 app_name_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
63 app_info_container->AddChildView(app_name_view_); 66 app_info_container->AddChildView(app_name_view_);
64 67
68 // Summary text divider
69 summary_text_divider_ =
70 new views::Label(base::ASCIIToUTF16(" ") +
71 base::string16(1, kNotificationHeaderDividerSymbol) +
72 base::ASCIIToUTF16(" "));
73 summary_text_divider_->SetFontList(font_list);
74 summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
75 summary_text_divider_->SetVisible(false);
76 app_info_container->AddChildView(summary_text_divider_);
77
78 // Summary text view
79 summary_text_view_ = new views::Label(base::string16());
80 summary_text_view_->SetFontList(font_list);
81 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
82 summary_text_view_->SetVisible(false);
83 app_info_container->AddChildView(summary_text_view_);
84
65 // Expand button view 85 // Expand button view
66 expand_button_ = new views::ImageButton(listener); 86 expand_button_ = new views::ImageButton(listener);
67 expand_button_->SetImage( 87 expand_button_->SetImage(
68 views::Button::STATE_NORMAL, 88 views::Button::STATE_NORMAL,
69 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize, 89 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize,
70 gfx::kChromeIconGrey)); 90 gfx::kChromeIconGrey));
71 expand_button_->SetFocusForPlatform(); 91 expand_button_->SetFocusForPlatform();
72 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter( 92 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter(
73 kFocusBorderColor, gfx::Insets(1, 2, 2, 2))); 93 kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
74 app_info_container->AddChildView(expand_button_); 94 app_info_container->AddChildView(expand_button_);
(...skipping 24 matching lines...) Expand all
99 } 119 }
100 120
101 void NotificationHeaderView::SetAppIcon(const gfx::ImageSkia& img) { 121 void NotificationHeaderView::SetAppIcon(const gfx::ImageSkia& img) {
102 app_icon_view_->SetImage(img); 122 app_icon_view_->SetImage(img);
103 } 123 }
104 124
105 void NotificationHeaderView::SetAppName(const base::string16& name) { 125 void NotificationHeaderView::SetAppName(const base::string16& name) {
106 app_name_view_->SetText(name); 126 app_name_view_->SetText(name);
107 } 127 }
108 128
129 void NotificationHeaderView::SetProgress(int progress) {
130 summary_text_view_->SetText(l10n_util::GetStringFUTF16Int(
131 IDS_MESSAGE_CENTER_NOTIFICATION_PROGRESS_PERCENTAGE, progress));
132 has_progress_ = true;
yoshiki 2017/06/27 07:15:18 nit: has_summary_text_ might be better? it's up to
tetsui 2017/06/27 07:37:36 Done.
133 UpdateSummaryTextVisibility();
134 }
135
136 void NotificationHeaderView::ClearProgress() {
137 has_progress_ = false;
138 UpdateSummaryTextVisibility();
139 }
140
109 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { 141 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) {
110 expand_button_->SetVisible(enabled); 142 expand_button_->SetVisible(enabled);
111 } 143 }
112 144
113 void NotificationHeaderView::SetExpanded(bool expanded) { 145 void NotificationHeaderView::SetExpanded(bool expanded) {
114 expand_button_->SetImage( 146 expand_button_->SetImage(
115 views::Button::STATE_NORMAL, 147 views::Button::STATE_NORMAL,
116 gfx::CreateVectorIcon( 148 gfx::CreateVectorIcon(
117 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon, 149 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon,
118 kExpandIconSize, gfx::kChromeIconGrey)); 150 kExpandIconSize, gfx::kChromeIconGrey));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 184 }
153 185
154 void NotificationHeaderView::UpdateControlButtonsVisibility() { 186 void NotificationHeaderView::UpdateControlButtonsVisibility() {
155 settings_button_->SetVisible(settings_button_enabled_ && 187 settings_button_->SetVisible(settings_button_enabled_ &&
156 is_control_buttons_visible_); 188 is_control_buttons_visible_);
157 close_button_->SetVisible(close_button_enabled_ && 189 close_button_->SetVisible(close_button_enabled_ &&
158 is_control_buttons_visible_); 190 is_control_buttons_visible_);
159 Layout(); 191 Layout();
160 } 192 }
161 193
194 void NotificationHeaderView::UpdateSummaryTextVisibility() {
195 summary_text_divider_->SetVisible(has_progress_);
196 summary_text_view_->SetVisible(has_progress_);
197 Layout();
198 }
199
162 } // namespace message_center 200 } // 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