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

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

Issue 1773893002: Make MdTextButton a LabelButton, use it in the DL shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove commented out code Created 4 years, 9 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') | ui/views/examples/button_example.cc » ('j') | 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/gfx/render_text.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/gfx/color_utils.h"
9 #include "ui/native_theme/native_theme.h" 10 #include "ui/native_theme/native_theme.h"
11 #include "ui/views/border.h"
12 #include "ui/views/painter.h"
10 13
11 namespace views { 14 namespace views {
12 15
13 namespace { 16 namespace {
14 17
15 // Inset between clickable region border and button contents (text). 18 // Inset between clickable region border and button contents (text).
16 const int kHorizontalPadding = 12; 19 const int kHorizontalPadding = 12;
17 const int kVerticalPadding = 6; 20 const int kVerticalPadding = 6;
18 21
19 // Minimum size to reserve for the button contents. 22 // Minimum size to reserve for the button contents.
20 const int kMinWidth = 48; 23 const int kMinWidth = 48;
21 24
22 const gfx::FontList& GetFontList() { 25 } // namespace
23 static base::LazyInstance<gfx::FontList>::Leaky font_list = 26
24 LAZY_INSTANCE_INITIALIZER; 27 // static
25 return font_list.Get(); 28 LabelButton* MdTextButton::CreateStandardButton(ButtonListener* listener,
29 const base::string16& text) {
30 if (ui::MaterialDesignController::IsModeMaterial()) {
31 MdTextButton* button = new MdTextButton(listener);
32 button->SetText(text);
33 // TODO(estade): can we get rid of the platform style border hoopla if
34 // we apply the MD treatment to all buttons, even GTK buttons?
35 button->SetBorder(
36 Border::CreateEmptyBorder(kVerticalPadding, kHorizontalPadding,
37 kVerticalPadding, kHorizontalPadding));
38 return button;
39 }
40
41 LabelButton* button = new LabelButton(listener, text);
42 button->SetStyle(STYLE_BUTTON);
43 return button;
26 } 44 }
27 45
28 } // namespace 46 SkColor MdTextButton::GetInkDropBaseColor() const {
47 return color_utils::DeriveDefaultIconColor(label()->enabled_color());
48 }
29 49
30 MdTextButton::MdTextButton(ButtonListener* listener, const base::string16& text) 50 void MdTextButton::SetText(const base::string16& text) {
31 : CustomButton(listener), 51 LabelButton::SetText(base::i18n::ToUpper(text));
32 render_text_(gfx::RenderText::CreateInstance()) { 52 }
33 render_text_->SetFontList(GetFontList());
34 render_text_->SetCursorEnabled(false);
35 render_text_->SetText(base::i18n::ToUpper(text));
36 53
54 MdTextButton::MdTextButton(ButtonListener* listener)
55 : LabelButton(listener, base::string16()),
56 ink_drop_delegate_(this, this) {
57 set_ink_drop_delegate(&ink_drop_delegate_);
58 set_has_ink_drop_action_on_click(true);
59 SetHorizontalAlignment(gfx::ALIGN_CENTER);
37 SetFocusable(true); 60 SetFocusable(true);
61 // TODO(estade): create a focus painter.
62 SetFocusPainter(nullptr);
63 SetMinSize(gfx::Size(kMinWidth, 0));
38 } 64 }
39 65
40 MdTextButton::~MdTextButton() {} 66 MdTextButton::~MdTextButton() {}
41 67
42 void MdTextButton::OnPaint(gfx::Canvas* canvas) {
43 UpdateColor();
44 gfx::Rect rect = GetLocalBounds();
45 rect.Inset(kHorizontalPadding, kVerticalPadding);
46 render_text_->SetDisplayRect(rect);
47 render_text_->Draw(canvas);
48 }
49
50 gfx::Size MdTextButton::GetPreferredSize() const {
51 gfx::Size size = render_text_->GetStringSize();
52 size.SetToMax(gfx::Size(kMinWidth, 0));
53 size.Enlarge(kHorizontalPadding * 2, kVerticalPadding * 2);
54 return size;
55 }
56
57 void MdTextButton::UpdateColor() {
58 // TODO(estade): handle call to action theming and other things that can
59 // affect the text color.
60 render_text_->SetColor(GetNativeTheme()->GetSystemColor(
61 enabled() ? ui::NativeTheme::kColorId_MdTextButtonEnabledColor
62 : ui::NativeTheme::kColorId_MdTextButtonDisabledColor));
63 }
64
65 } // namespace views 68 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/examples/button_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698