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

Side by Side Diff: ui/views/controls/button/md_text_button.cc

Issue 2218323002: Better CrOS logout button for vertical trays. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reviews Created 4 years, 4 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
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/controls/button/md_text_button.h" 5 #include "ui/views/controls/button/md_text_button.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "ui/base/material_design/material_design_controller.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/color_utils.h" 10 #include "ui/gfx/color_utils.h"
11 #include "ui/native_theme/native_theme.h" 11 #include "ui/native_theme/native_theme.h"
12 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
12 #include "ui/views/animation/ink_drop_highlight.h" 13 #include "ui/views/animation/ink_drop_highlight.h"
13 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" 14 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
14 #include "ui/views/background.h" 15 #include "ui/views/background.h"
15 #include "ui/views/border.h" 16 #include "ui/views/border.h"
16 #include "ui/views/controls/button/blue_button.h" 17 #include "ui/views/controls/button/blue_button.h"
17 #include "ui/views/painter.h" 18 #include "ui/views/painter.h"
18 19
19 namespace views { 20 namespace views {
20 21
21 namespace { 22 namespace {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 166
166 void MdTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { 167 void MdTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
167 LabelButton::OnNativeThemeChanged(theme); 168 LabelButton::OnNativeThemeChanged(theme);
168 UpdateColors(); 169 UpdateColors();
169 } 170 }
170 171
171 SkColor MdTextButton::GetInkDropBaseColor() const { 172 SkColor MdTextButton::GetInkDropBaseColor() const {
172 return color_utils::DeriveDefaultIconColor(label()->enabled_color()); 173 return color_utils::DeriveDefaultIconColor(label()->enabled_color());
173 } 174 }
174 175
176 std::unique_ptr<views::InkDropRipple> MdTextButton::CreateInkDropRipple()
177 const {
178 return std::unique_ptr<views::InkDropRipple>(
179 new views::FloodFillInkDropRipple(
180 GetLocalBounds(), GetInkDropCenterBasedOnLastEvent(),
181 GetInkDropBaseColor(), ink_drop_visible_opacity()));
182 }
183
175 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() 184 std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight()
176 const { 185 const {
177 if (!ShouldShowInkDropHighlight()) 186 if (!ShouldShowInkDropHighlight())
178 return nullptr; 187 return nullptr;
179 if (!is_cta_) 188 if (!is_cta_)
180 return LabelButton::CreateInkDropHighlight(); 189 return LabelButton::CreateInkDropHighlight();
181 190
182 // The call to action hover effect is a shadow. 191 // The call to action hover effect is a shadow.
183 const int kYOffset = 1; 192 const int kYOffset = 1;
184 const int kSkiaBlurRadius = 1; 193 const int kSkiaBlurRadius = 1;
(...skipping 14 matching lines...) Expand all
199 bool MdTextButton::ShouldShowInkDropForFocus() const { 208 bool MdTextButton::ShouldShowInkDropForFocus() const {
200 // These types of button use |focus_ring_|. 209 // These types of button use |focus_ring_|.
201 return false; 210 return false;
202 } 211 }
203 212
204 void MdTextButton::SetEnabledTextColors(SkColor color) { 213 void MdTextButton::SetEnabledTextColors(SkColor color) {
205 LabelButton::SetEnabledTextColors(color); 214 LabelButton::SetEnabledTextColors(color);
206 UpdateColors(); 215 UpdateColors();
207 } 216 }
208 217
218 void MdTextButton::SetText(const base::string16& text) {
219 LabelButton::SetText(text);
220 UpdatePaddingForFont();
221 }
222
209 void MdTextButton::AdjustFontSize(int size_delta) { 223 void MdTextButton::AdjustFontSize(int size_delta) {
210 LabelButton::AdjustFontSize(size_delta); 224 LabelButton::AdjustFontSize(size_delta);
211 UpdatePaddingForFont(); 225 UpdatePaddingForFont();
212 } 226 }
213 227
214 void MdTextButton::UpdateStyleToIndicateDefaultStatus() { 228 void MdTextButton::UpdateStyleToIndicateDefaultStatus() {
215 UpdateColors(); 229 UpdateColors();
216 } 230 }
217 231
218 void MdTextButton::SetFontList(const gfx::FontList& font_list) { 232 void MdTextButton::SetFontList(const gfx::FontList& font_list) {
219 NOTREACHED() 233 NOTREACHED()
220 << "Don't call MdTextButton::SetFontList (it will soon be protected)"; 234 << "Don't call MdTextButton::SetFontList (it will soon be protected)";
221 } 235 }
222 236
223 MdTextButton::MdTextButton(ButtonListener* listener) 237 MdTextButton::MdTextButton(ButtonListener* listener)
224 : LabelButton(listener, base::string16()), 238 : LabelButton(listener, base::string16()),
225 focus_ring_(new internal::MdFocusRing()), 239 focus_ring_(new internal::MdFocusRing()),
226 is_cta_(false) { 240 is_cta_(false) {
227 SetInkDropMode(InkDropMode::ON); 241 SetInkDropMode(InkDropMode::ON);
228 set_has_ink_drop_action_on_click(true); 242 set_has_ink_drop_action_on_click(true);
229 SetHorizontalAlignment(gfx::ALIGN_CENTER); 243 SetHorizontalAlignment(gfx::ALIGN_CENTER);
230 SetFocusForPlatform(); 244 SetFocusForPlatform();
231 SetMinSize(gfx::Size(kMinWidth, 0)); 245 SetMinSize(gfx::Size(kMinWidth, 0));
232 SetFocusPainter(nullptr); 246 SetFocusPainter(nullptr);
233 label()->SetAutoColorReadabilityEnabled(false); 247 label()->SetAutoColorReadabilityEnabled(false);
234 AddChildView(focus_ring_); 248 AddChildView(focus_ring_);
235 focus_ring_->SetVisible(false); 249 focus_ring_->SetVisible(false);
236 set_request_focus_on_press(false); 250 set_request_focus_on_press(false);
237 LabelButton::SetFontList(GetMdFontList()); 251 LabelButton::SetFontList(GetMdFontList());
238 UpdatePaddingForFont();
239 } 252 }
240 253
241 MdTextButton::~MdTextButton() {} 254 MdTextButton::~MdTextButton() {}
242 255
243 void MdTextButton::UpdatePaddingForFont() { 256 void MdTextButton::UpdatePaddingForFont() {
257 // Don't use font-based padding when there's no text visible.
258 if (GetText().empty()) {
259 SetBorder(Border::NullBorder());
260 return;
261 }
262
244 // Top and bottom padding depend on the font. Example: if font cap height is 263 // Top and bottom padding depend on the font. Example: if font cap height is
245 // 9dp, use 8dp bottom padding and 7dp top padding to total 24dp. 264 // 9dp, use 8dp bottom padding and 7dp top padding to total 24dp.
246 const gfx::FontList& font = label()->font_list(); 265 const gfx::FontList& font = label()->font_list();
247 int text_height = font.GetCapHeight(); 266 int text_height = font.GetCapHeight();
248 int even_text_height = text_height - (text_height % 2); 267 int even_text_height = text_height - (text_height % 2);
249 const int top_padding = even_text_height - (text_height - even_text_height); 268 const int top_padding = even_text_height - (text_height - even_text_height);
250 const int bottom_padding = even_text_height; 269 const int bottom_padding = even_text_height;
251 DCHECK_EQ(3 * even_text_height, top_padding + text_height + bottom_padding); 270 DCHECK_EQ(3 * even_text_height, top_padding + text_height + bottom_padding);
252 271
253 const int inbuilt_top_padding = font.GetBaseline() - font.GetCapHeight(); 272 const int inbuilt_top_padding = font.GetBaseline() - font.GetCapHeight();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) 304 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color))
286 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) 305 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity)
287 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); 306 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity);
288 307
289 set_background(Background::CreateBackgroundPainter( 308 set_background(Background::CreateBackgroundPainter(
290 true, Painter::CreateRoundRectWith1PxBorderPainter( 309 true, Painter::CreateRoundRectWith1PxBorderPainter(
291 bg_color, stroke_color, kInkDropSmallCornerRadius))); 310 bg_color, stroke_color, kInkDropSmallCornerRadius)));
292 } 311 }
293 312
294 } // namespace views 313 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698