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

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

Issue 2190453002: Update CrOS logout button for MD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix override 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"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 bool MdTextButton::ShouldShowInkDropForFocus() const { 199 bool MdTextButton::ShouldShowInkDropForFocus() const {
200 // These types of button use |focus_ring_|. 200 // These types of button use |focus_ring_|.
201 return false; 201 return false;
202 } 202 }
203 203
204 void MdTextButton::SetEnabledTextColors(SkColor color) { 204 void MdTextButton::SetEnabledTextColors(SkColor color) {
205 LabelButton::SetEnabledTextColors(color); 205 LabelButton::SetEnabledTextColors(color);
206 UpdateColors(); 206 UpdateColors();
207 } 207 }
208 208
209 void MdTextButton::AdjustFontSize(int size_delta) {
210 LabelButton::AdjustFontSize(size_delta);
211 UpdatePaddingForFont();
212 }
213
209 void MdTextButton::UpdateStyleToIndicateDefaultStatus() { 214 void MdTextButton::UpdateStyleToIndicateDefaultStatus() {
210 UpdateColors(); 215 UpdateColors();
211 } 216 }
212 217
218 void MdTextButton::SetFontList(const gfx::FontList& font_list) {
219 NOTREACHED()
220 << "Don't call MdTextButton::SetFontList (it will soon be protected)";
221 }
222
213 MdTextButton::MdTextButton(ButtonListener* listener) 223 MdTextButton::MdTextButton(ButtonListener* listener)
214 : LabelButton(listener, base::string16()), 224 : LabelButton(listener, base::string16()),
215 focus_ring_(new internal::MdFocusRing()), 225 focus_ring_(new internal::MdFocusRing()),
216 is_cta_(false) { 226 is_cta_(false) {
217 SetInkDropMode(InkDropMode::ON); 227 SetInkDropMode(InkDropMode::ON);
218 set_has_ink_drop_action_on_click(true); 228 set_has_ink_drop_action_on_click(true);
219 SetHorizontalAlignment(gfx::ALIGN_CENTER); 229 SetHorizontalAlignment(gfx::ALIGN_CENTER);
220 SetFocusForPlatform(); 230 SetFocusForPlatform();
221 SetMinSize(gfx::Size(kMinWidth, 0)); 231 SetMinSize(gfx::Size(kMinWidth, 0));
222 SetFocusPainter(nullptr); 232 SetFocusPainter(nullptr);
223 label()->SetAutoColorReadabilityEnabled(false); 233 label()->SetAutoColorReadabilityEnabled(false);
224 SetFontList(GetMdFontList());
225
226 AddChildView(focus_ring_); 234 AddChildView(focus_ring_);
227 focus_ring_->SetVisible(false); 235 focus_ring_->SetVisible(false);
228 set_request_focus_on_press(false); 236 set_request_focus_on_press(false);
237 LabelButton::SetFontList(GetMdFontList());
238 UpdatePaddingForFont();
239 }
229 240
241 MdTextButton::~MdTextButton() {}
242
243 void MdTextButton::UpdatePaddingForFont() {
230 // Top and bottom padding depend on the font. Example: if font cap height is 244 // Top and bottom padding depend on the font. Example: if font cap height is
231 // 9dp, use 8dp bottom padding and 7dp top padding to total 24dp. 245 // 9dp, use 8dp bottom padding and 7dp top padding to total 24dp.
232 const gfx::FontList& font = label()->font_list(); 246 const gfx::FontList& font = label()->font_list();
233 int text_height = font.GetCapHeight(); 247 int text_height = font.GetCapHeight();
234 int even_text_height = text_height - (text_height % 2); 248 int even_text_height = text_height - (text_height % 2);
235 const int top_padding = even_text_height - (text_height - even_text_height); 249 const int top_padding = even_text_height - (text_height - even_text_height);
236 const int bottom_padding = even_text_height; 250 const int bottom_padding = even_text_height;
237 DCHECK_EQ(3 * even_text_height, top_padding + text_height + bottom_padding); 251 DCHECK_EQ(3 * even_text_height, top_padding + text_height + bottom_padding);
238 252
239 const int inbuilt_top_padding = font.GetBaseline() - font.GetCapHeight(); 253 const int inbuilt_top_padding = font.GetBaseline() - font.GetCapHeight();
240 const int inbuilt_bottom_padding = 254 const int inbuilt_bottom_padding =
241 font.GetHeight() - label()->font_list().GetBaseline(); 255 font.GetHeight() - label()->font_list().GetBaseline();
242 256
243 // TODO(estade): can we get rid of the platform style border hoopla if 257 // TODO(estade): can we get rid of the platform style border hoopla if
244 // we apply the MD treatment to all buttons, even GTK buttons? 258 // we apply the MD treatment to all buttons, even GTK buttons?
245 SetBorder(Border::CreateEmptyBorder( 259 SetBorder(Border::CreateEmptyBorder(
246 top_padding - inbuilt_top_padding, kHorizontalPadding, 260 top_padding - inbuilt_top_padding, kHorizontalPadding,
247 bottom_padding - inbuilt_bottom_padding, kHorizontalPadding)); 261 bottom_padding - inbuilt_bottom_padding, kHorizontalPadding));
248 } 262 }
249 263
250 MdTextButton::~MdTextButton() {}
251
252 void MdTextButton::UpdateColors() { 264 void MdTextButton::UpdateColors() {
253 ui::NativeTheme::ColorId fg_color_id = 265 ui::NativeTheme::ColorId fg_color_id =
254 is_cta_ ? ui::NativeTheme::kColorId_TextOnCallToActionColor 266 is_cta_ ? ui::NativeTheme::kColorId_TextOnCallToActionColor
255 : ui::NativeTheme::kColorId_ButtonEnabledColor; 267 : ui::NativeTheme::kColorId_ButtonEnabledColor;
256 268
257 ui::NativeTheme* theme = GetNativeTheme(); 269 ui::NativeTheme* theme = GetNativeTheme();
258 if (!explicitly_set_normal_color()) 270 if (!explicitly_set_normal_color())
259 LabelButton::SetEnabledTextColors(theme->GetSystemColor(fg_color_id)); 271 LabelButton::SetEnabledTextColors(theme->GetSystemColor(fg_color_id));
260 272
261 SkColor text_color = label()->enabled_color(); 273 SkColor text_color = label()->enabled_color();
(...skipping 11 matching lines...) Expand all
273 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) 285 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color))
274 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) 286 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity)
275 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); 287 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity);
276 288
277 set_background(Background::CreateBackgroundPainter( 289 set_background(Background::CreateBackgroundPainter(
278 true, Painter::CreateRoundRectWith1PxBorderPainter( 290 true, Painter::CreateRoundRectWith1PxBorderPainter(
279 bg_color, stroke_color, kInkDropSmallCornerRadius))); 291 bg_color, stroke_color, kInkDropSmallCornerRadius)));
280 } 292 }
281 293
282 } // namespace views 294 } // 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