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/gfx/render_text.h" | 8 #include "ui/gfx/render_text.h" |
9 #include "ui/native_theme/native_theme.h" | 9 #include "ui/native_theme/native_theme.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 MdTextButton::MdTextButton(ButtonListener* listener, const base::string16& text) | 30 MdTextButton::MdTextButton(ButtonListener* listener, const base::string16& text) |
31 : CustomButton(listener), | 31 : CustomButton(listener), |
32 render_text_(gfx::RenderText::CreateInstance()) { | 32 render_text_(gfx::RenderText::CreateInstance()) { |
33 render_text_->SetFontList(GetFontList()); | 33 render_text_->SetFontList(GetFontList()); |
34 render_text_->SetCursorEnabled(false); | 34 render_text_->SetCursorEnabled(false); |
35 render_text_->SetText(base::i18n::ToUpper(text)); | 35 render_text_->SetText(base::i18n::ToUpper(text)); |
36 | 36 |
| 37 #if !defined(OS_MACOSX) |
37 SetFocusable(true); | 38 SetFocusable(true); |
| 39 #else |
| 40 SetFocusable(false); |
| 41 SetAccessibilityFocusable(true); |
| 42 #endif |
38 } | 43 } |
39 | 44 |
40 MdTextButton::~MdTextButton() {} | 45 MdTextButton::~MdTextButton() {} |
41 | 46 |
42 void MdTextButton::OnPaint(gfx::Canvas* canvas) { | 47 void MdTextButton::OnPaint(gfx::Canvas* canvas) { |
43 UpdateColor(); | 48 UpdateColor(); |
44 gfx::Rect rect = GetLocalBounds(); | 49 gfx::Rect rect = GetLocalBounds(); |
45 rect.Inset(kHorizontalPadding, kVerticalPadding); | 50 rect.Inset(kHorizontalPadding, kVerticalPadding); |
46 render_text_->SetDisplayRect(rect); | 51 render_text_->SetDisplayRect(rect); |
47 render_text_->Draw(canvas); | 52 render_text_->Draw(canvas); |
48 } | 53 } |
49 | 54 |
50 gfx::Size MdTextButton::GetPreferredSize() const { | 55 gfx::Size MdTextButton::GetPreferredSize() const { |
51 gfx::Size size = render_text_->GetStringSize(); | 56 gfx::Size size = render_text_->GetStringSize(); |
52 size.SetToMax(gfx::Size(kMinWidth, 0)); | 57 size.SetToMax(gfx::Size(kMinWidth, 0)); |
53 size.Enlarge(kHorizontalPadding * 2, kVerticalPadding * 2); | 58 size.Enlarge(kHorizontalPadding * 2, kVerticalPadding * 2); |
54 return size; | 59 return size; |
55 } | 60 } |
56 | 61 |
57 void MdTextButton::UpdateColor() { | 62 void MdTextButton::UpdateColor() { |
58 // TODO(estade): handle call to action theming and other things that can | 63 // TODO(estade): handle call to action theming and other things that can |
59 // affect the text color. | 64 // affect the text color. |
60 render_text_->SetColor(GetNativeTheme()->GetSystemColor( | 65 render_text_->SetColor(GetNativeTheme()->GetSystemColor( |
61 enabled() ? ui::NativeTheme::kColorId_MdTextButtonEnabledColor | 66 enabled() ? ui::NativeTheme::kColorId_MdTextButtonEnabledColor |
62 : ui::NativeTheme::kColorId_MdTextButtonDisabledColor)); | 67 : ui::NativeTheme::kColorId_MdTextButtonDisabledColor)); |
63 } | 68 } |
64 | 69 |
65 } // namespace views | 70 } // namespace views |
OLD | NEW |