Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 set_has_ink_drop_action_on_click(true); | 231 set_has_ink_drop_action_on_click(true); |
| 232 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 232 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 233 SetFocusForPlatform(); | 233 SetFocusForPlatform(); |
| 234 SetMinSize(gfx::Size(kMinWidth, 0)); | 234 SetMinSize(gfx::Size(kMinWidth, 0)); |
| 235 SetFocusPainter(nullptr); | 235 SetFocusPainter(nullptr); |
| 236 label()->SetAutoColorReadabilityEnabled(false); | 236 label()->SetAutoColorReadabilityEnabled(false); |
| 237 AddChildView(focus_ring_); | 237 AddChildView(focus_ring_); |
| 238 focus_ring_->SetVisible(false); | 238 focus_ring_->SetVisible(false); |
| 239 set_request_focus_on_press(false); | 239 set_request_focus_on_press(false); |
| 240 LabelButton::SetFontList(GetMdFontList()); | 240 LabelButton::SetFontList(GetMdFontList()); |
| 241 | |
| 242 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful | |
| 243 // for fractional DSF). | |
| 244 SetPaintToLayer(true); | |
|
sky
2016/09/07 21:22:37
It makes me sad that you have to do this.
Evan Stade
2016/09/07 22:31:25
yea, me too, an angel is losing its wings. Is ther
Evan Stade
2016/09/07 22:43:40
I mean, I assume there isn't currently, but perhap
| |
| 245 layer()->SetFillsBoundsOpaquely(false); | |
| 241 } | 246 } |
| 242 | 247 |
| 243 MdTextButton::~MdTextButton() {} | 248 MdTextButton::~MdTextButton() {} |
| 244 | 249 |
| 245 void MdTextButton::UpdatePadding() { | 250 void MdTextButton::UpdatePadding() { |
| 246 // Don't use font-based padding when there's no text visible. | 251 // Don't use font-based padding when there's no text visible. |
| 247 if (GetText().empty()) { | 252 if (GetText().empty()) { |
| 248 SetBorder(Border::NullBorder()); | 253 SetBorder(Border::NullBorder()); |
| 249 return; | 254 return; |
| 250 } | 255 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 294 |
| 290 SkColor text_color = label()->enabled_color(); | 295 SkColor text_color = label()->enabled_color(); |
| 291 SkColor bg_color = | 296 SkColor bg_color = |
| 292 bg_color_override_ | 297 bg_color_override_ |
| 293 ? *bg_color_override_ | 298 ? *bg_color_override_ |
| 294 : is_cta_ | 299 : is_cta_ |
| 295 ? theme->GetSystemColor( | 300 ? theme->GetSystemColor( |
| 296 ui::NativeTheme::kColorId_CallToActionColor) | 301 ui::NativeTheme::kColorId_CallToActionColor) |
| 297 : is_default() | 302 : is_default() |
| 298 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) | 303 ? color_utils::BlendTowardOppositeLuma(text_color, 0xD8) |
| 299 : SK_ColorTRANSPARENT; | 304 : theme->GetSystemColor( |
| 305 ui::NativeTheme::kColorId_DialogBackground); | |
| 300 | 306 |
| 301 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); | 307 bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state()); |
| 302 | 308 |
| 303 const SkAlpha kStrokeOpacity = 0x1A; | 309 const SkAlpha kStrokeOpacity = 0x1A; |
| 304 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) | 310 SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color)) |
| 305 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) | 311 ? SkColorSetA(SK_ColorBLACK, kStrokeOpacity) |
| 306 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); | 312 : SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity); |
| 307 | 313 |
| 314 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | |
| 308 set_background(Background::CreateBackgroundPainter( | 315 set_background(Background::CreateBackgroundPainter( |
| 309 true, Painter::CreateRoundRectWith1PxBorderPainter( | 316 true, Painter::CreateRoundRectWith1PxBorderPainter( |
| 310 bg_color, stroke_color, kInkDropSmallCornerRadius))); | 317 bg_color, stroke_color, kInkDropSmallCornerRadius))); |
| 311 } | 318 } |
| 312 | 319 |
| 313 } // namespace views | 320 } // namespace views |
| OLD | NEW |