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

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

Issue 2966673002: Add ripple effect to action in expand button. (Closed)
Patch Set: 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" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
(...skipping 25 matching lines...) Expand all
36 // Bullet character. The divider symbol between different parts of the header. 36 // Bullet character. The divider symbol between different parts of the header.
37 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022; 37 constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022;
38 38
39 // Base ink drop color of action buttons. 39 // Base ink drop color of action buttons.
40 const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0); 40 const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0);
41 // Ripple ink drop opacity of action buttons. 41 // Ripple ink drop opacity of action buttons.
42 constexpr float kInkDropRippleVisibleOpacity = 0.08f; 42 constexpr float kInkDropRippleVisibleOpacity = 0.08f;
43 // Highlight (hover) ink drop opacity of action buttons. 43 // Highlight (hover) ink drop opacity of action buttons.
44 constexpr float kInkDropHighlightVisibleOpacity = 0.08f; 44 constexpr float kInkDropHighlightVisibleOpacity = 0.08f;
45 45
46 class ExpandButton : public views::ImageButton, public views::ButtonListener {
yoshiki 2017/07/03 06:26:49 BTW, why is it inheriting a button? Although this
tetsui 2017/07/03 07:10:54 Done.
47 public:
48 ExpandButton(NotificationHeaderView* header);
49 ~ExpandButton() override;
50
51 // ButtonListener override:
52 void ButtonPressed(Button* sender, const ui::Event& event) override;
53
54 protected:
55 // ImageButton override:
56 void OnMouseEvent(ui::MouseEvent* event) override;
57 void OnKeyEvent(ui::KeyEvent* event) override;
58
59 private:
60 NotificationHeaderView* header_;
61 };
62
63 ExpandButton::ExpandButton(NotificationHeaderView* header)
64 : views::ImageButton(this), header_(header) {
65 SetImage(views::Button::STATE_NORMAL,
66 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize,
67 gfx::kChromeIconGrey));
68 SetFocusForPlatform();
69 SetFocusPainter(views::Painter::CreateSolidFocusPainter(
70 kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
71 }
72
73 ExpandButton::~ExpandButton() = default;
74
75 void ExpandButton::ButtonPressed(Button* sender, const ui::Event& event) {
76 // No need to handle event here because raw OnMouseEvent and OnKeyEvent are
77 // forwarded to NotificationHeaderView.
78 }
79
80 void ExpandButton::OnMouseEvent(ui::MouseEvent* event) {
81 views::View* source = this;
yoshiki 2017/07/03 06:26:49 Can this method be empty? I think if you don't any
tetsui 2017/07/03 07:10:54 Done.
82 views::View* target = header_;
83 ui::MouseEvent converted_event(*event, source, target);
84 header_->OnMouseEvent(&converted_event);
85 }
86
87 void ExpandButton::OnKeyEvent(ui::KeyEvent* event) {
88 header_->OnKeyEvent(event);
89 }
90
46 } // namespace 91 } // namespace
47 92
48 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener) 93 NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener)
49 : views::CustomButton(listener) { 94 : views::CustomButton(listener) {
50 SetInkDropMode(InkDropMode::ON); 95 SetInkDropMode(InkDropMode::ON);
51 set_has_ink_drop_action_on_click(true); 96 set_has_ink_drop_action_on_click(true);
52 set_animate_on_state_change(true); 97 set_animate_on_state_change(true);
53 set_notify_enter_exit_on_child(true); 98 set_notify_enter_exit_on_child(true);
54 set_ink_drop_base_color(kInkDropBaseColor); 99 set_ink_drop_base_color(kInkDropBaseColor);
55 set_ink_drop_visible_opacity(kInkDropRippleVisibleOpacity); 100 set_ink_drop_visible_opacity(kInkDropRippleVisibleOpacity);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 app_info_container->AddChildView(summary_text_divider_); 139 app_info_container->AddChildView(summary_text_divider_);
95 140
96 // Summary text view 141 // Summary text view
97 summary_text_view_ = new views::Label(base::string16()); 142 summary_text_view_ = new views::Label(base::string16());
98 summary_text_view_->SetFontList(font_list); 143 summary_text_view_->SetFontList(font_list);
99 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 144 summary_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
100 summary_text_view_->SetVisible(false); 145 summary_text_view_->SetVisible(false);
101 app_info_container->AddChildView(summary_text_view_); 146 app_info_container->AddChildView(summary_text_view_);
102 147
103 // Expand button view 148 // Expand button view
104 expand_button_ = new views::ImageButton(listener); 149 expand_button_ = new ExpandButton(this);
105 expand_button_->SetImage(
106 views::Button::STATE_NORMAL,
107 gfx::CreateVectorIcon(kNotificationExpandMoreIcon, kExpandIconSize,
108 gfx::kChromeIconGrey));
109 expand_button_->SetFocusForPlatform();
110 expand_button_->SetFocusPainter(views::Painter::CreateSolidFocusPainter(
111 kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
112 app_info_container->AddChildView(expand_button_); 150 app_info_container->AddChildView(expand_button_);
113 151
114 // Spacer between left-aligned views and right-aligned views 152 // Spacer between left-aligned views and right-aligned views
115 views::View* spacer = new views::View; 153 views::View* spacer = new views::View;
116 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight)); 154 spacer->SetPreferredSize(gfx::Size(1, kHeaderHeight));
117 AddChildView(spacer); 155 AddChildView(spacer);
118 layout->SetFlexForView(spacer, 1); 156 layout->SetFlexForView(spacer, 1);
119 157
120 // Settings button view 158 // Settings button view
121 settings_button_ = new PaddedButton(listener); 159 settings_button_ = new PaddedButton(listener);
(...skipping 28 matching lines...) Expand all
150 has_summary_text_ = true; 188 has_summary_text_ = true;
151 UpdateSummaryTextVisibility(); 189 UpdateSummaryTextVisibility();
152 } 190 }
153 191
154 void NotificationHeaderView::ClearProgress() { 192 void NotificationHeaderView::ClearProgress() {
155 has_summary_text_ = false; 193 has_summary_text_ = false;
156 UpdateSummaryTextVisibility(); 194 UpdateSummaryTextVisibility();
157 } 195 }
158 196
159 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) { 197 void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) {
198 // SetInkDropMode iff. the visibility changed.
199 // Otherwise, the ink drop animation cannot finish.
200 if (expand_button_->visible() != enabled)
201 SetInkDropMode(enabled ? InkDropMode::ON : InkDropMode::OFF);
202
160 expand_button_->SetVisible(enabled); 203 expand_button_->SetVisible(enabled);
161 } 204 }
162 205
163 void NotificationHeaderView::SetExpanded(bool expanded) { 206 void NotificationHeaderView::SetExpanded(bool expanded) {
164 expand_button_->SetImage( 207 expand_button_->SetImage(
165 views::Button::STATE_NORMAL, 208 views::Button::STATE_NORMAL,
166 gfx::CreateVectorIcon( 209 gfx::CreateVectorIcon(
167 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon, 210 expanded ? kNotificationExpandLessIcon : kNotificationExpandMoreIcon,
168 kExpandIconSize, gfx::kChromeIconGrey)); 211 kExpandIconSize, gfx::kChromeIconGrey));
169 } 212 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 Layout(); 276 Layout();
234 } 277 }
235 278
236 void NotificationHeaderView::UpdateSummaryTextVisibility() { 279 void NotificationHeaderView::UpdateSummaryTextVisibility() {
237 summary_text_divider_->SetVisible(has_summary_text_); 280 summary_text_divider_->SetVisible(has_summary_text_);
238 summary_text_view_->SetVisible(has_summary_text_); 281 summary_text_view_->SetVisible(has_summary_text_);
239 Layout(); 282 Layout();
240 } 283 }
241 284
242 } // namespace message_center 285 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698