Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/controls/button/md_text_button.h" | |
| 6 | |
| 7 #include "base/i18n/case_conversion.h" | |
| 8 #include "ui/gfx/render_text.h" | |
| 9 #include "ui/native_theme/native_theme.h" | |
| 10 | |
| 11 namespace views { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // Inset between clickable region border and button contents (text). | |
| 16 const int kHorizontalPadding = 12; | |
| 17 const int kVerticalPadding = 6; | |
| 18 | |
| 19 // Minimum size to reserve for the button contents. | |
| 20 const int kMinWidth = 48; | |
| 21 | |
| 22 const gfx::FontList& GetFontList() { | |
| 23 static base::LazyInstance<gfx::FontList>::Leaky font_list = | |
| 24 LAZY_INSTANCE_INITIALIZER; | |
| 25 return font_list.Get(); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 MdTextButton::MdTextButton(ButtonListener* listener, const base::string16& text) | |
| 31 : CustomButton(listener), | |
| 32 render_text_(gfx::RenderText::CreateInstance()) { | |
| 33 render_text_->SetFontList(GetFontList()); | |
| 34 render_text_->SetCursorEnabled(false); | |
| 35 render_text_->SetText(base::i18n::ToUpper(text)); | |
| 36 render_text_->SetColor(SK_ColorBLUE); | |
| 37 | |
| 38 SetFocusable(true); | |
| 39 } | |
| 40 | |
| 41 MdTextButton::~MdTextButton() {} | |
| 42 | |
| 43 void MdTextButton::OnPaint(gfx::Canvas* canvas) { | |
| 44 UpdateColor(); | |
|
bruthig
2015/12/22 15:56:19
The material design ripple is supposed to be drawn
Evan Stade
2015/12/29 18:14:04
If we need another layer, wouldn't we just create
| |
| 45 gfx::Rect rect = GetLocalBounds(); | |
| 46 rect.Inset(kHorizontalPadding, kVerticalPadding); | |
| 47 render_text_->SetDisplayRect(rect); | |
| 48 render_text_->Draw(canvas); | |
| 49 } | |
| 50 | |
| 51 gfx::Size MdTextButton::GetPreferredSize() const { | |
| 52 gfx::Size size = render_text_->GetStringSize(); | |
| 53 size.SetToMax(gfx::Size(kMinWidth, 0)); | |
| 54 size.Enlarge(kHorizontalPadding * 2, kVerticalPadding * 2); | |
| 55 return size; | |
| 56 } | |
| 57 | |
| 58 void MdTextButton::UpdateColor() { | |
| 59 // TODO(estade): handle call to action theming and other things that can | |
| 60 // affect the text color. | |
| 61 render_text_->SetColor(GetNativeTheme()->GetSystemColor( | |
| 62 enabled() ? ui::NativeTheme::kColorId_MdTextButtonEnabledColor | |
| 63 : ui::NativeTheme::kColorId_MdTextButtonDisabledColor)); | |
| 64 } | |
| 65 | |
| 66 } // namespace views | |
| OLD | NEW |