summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/button/md_text_button.cc
diff options
context:
space:
mode:
authorestade <estade@chromium.org>2015-12-30 19:19:36 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-31 03:20:44 +0000
commitae2205f5a4c1a0957c88f892776d26c37499b981 (patch)
treebd530f8498bfc10eb4fbe2af31868790faf874d8 /ui/views/controls/button/md_text_button.cc
parent22724956ac1d6475f8178d6a68421ff164d87851 (diff)
downloadchromium_src-ae2205f5a4c1a0957c88f892776d26c37499b981.zip
chromium_src-ae2205f5a4c1a0957c88f892776d26c37499b981.tar.gz
chromium_src-ae2205f5a4c1a0957c88f892776d26c37499b981.tar.bz2
First stab at MD text buttons
These buttons are implemented as a new class separate from LabelButton, which we'll need to retain even when MD is default for certain use cases such as the bookmarks bar. This new class is used on MD infobars. This first rough cut doesn't support a) different button attributes that might affect rendering such as being a Call to Action or default in a dialog. TODO: estade b) hover or press effects. TODO: bruthig c) images on the button. I doubt we'll ever want to support images on material buttons, but it's possible we'll decide to add them later. BUG=520266,571500 Review URL: https://codereview.chromium.org/1525163004 Cr-Commit-Position: refs/heads/master@{#367224}
Diffstat (limited to 'ui/views/controls/button/md_text_button.cc')
-rw-r--r--ui/views/controls/button/md_text_button.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/ui/views/controls/button/md_text_button.cc b/ui/views/controls/button/md_text_button.cc
new file mode 100644
index 0000000..4cae74f
--- /dev/null
+++ b/ui/views/controls/button/md_text_button.cc
@@ -0,0 +1,65 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/controls/button/md_text_button.h"
+
+#include "base/i18n/case_conversion.h"
+#include "ui/gfx/render_text.h"
+#include "ui/native_theme/native_theme.h"
+
+namespace views {
+
+namespace {
+
+// Inset between clickable region border and button contents (text).
+const int kHorizontalPadding = 12;
+const int kVerticalPadding = 6;
+
+// Minimum size to reserve for the button contents.
+const int kMinWidth = 48;
+
+const gfx::FontList& GetFontList() {
+ static base::LazyInstance<gfx::FontList>::Leaky font_list =
+ LAZY_INSTANCE_INITIALIZER;
+ return font_list.Get();
+}
+
+} // namespace
+
+MdTextButton::MdTextButton(ButtonListener* listener, const base::string16& text)
+ : CustomButton(listener),
+ render_text_(gfx::RenderText::CreateInstance()) {
+ render_text_->SetFontList(GetFontList());
+ render_text_->SetCursorEnabled(false);
+ render_text_->SetText(base::i18n::ToUpper(text));
+
+ SetFocusable(true);
+}
+
+MdTextButton::~MdTextButton() {}
+
+void MdTextButton::OnPaint(gfx::Canvas* canvas) {
+ UpdateColor();
+ gfx::Rect rect = GetLocalBounds();
+ rect.Inset(kHorizontalPadding, kVerticalPadding);
+ render_text_->SetDisplayRect(rect);
+ render_text_->Draw(canvas);
+}
+
+gfx::Size MdTextButton::GetPreferredSize() const {
+ gfx::Size size = render_text_->GetStringSize();
+ size.SetToMax(gfx::Size(kMinWidth, 0));
+ size.Enlarge(kHorizontalPadding * 2, kVerticalPadding * 2);
+ return size;
+}
+
+void MdTextButton::UpdateColor() {
+ // TODO(estade): handle call to action theming and other things that can
+ // affect the text color.
+ render_text_->SetColor(GetNativeTheme()->GetSystemColor(
+ enabled() ? ui::NativeTheme::kColorId_MdTextButtonEnabledColor
+ : ui::NativeTheme::kColorId_MdTextButtonDisabledColor));
+}
+
+} // namespace views