summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorestade <estade@chromium.org>2016-03-21 17:48:22 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-22 00:50:13 +0000
commite9d92a8bc3c4c10dc6b68daa5c834a26c5db9ab1 (patch)
tree885c85a194d9a2c007f4b8112abbd356ad8e38f1 /ui
parent927577223c78bf91118825cf94a4725c4b7a810b (diff)
downloadchromium_src-e9d92a8bc3c4c10dc6b68daa5c834a26c5db9ab1.zip
chromium_src-e9d92a8bc3c4c10dc6b68daa5c834a26c5db9ab1.tar.gz
chromium_src-e9d92a8bc3c4c10dc6b68daa5c834a26c5db9ab1.tar.bz2
Iterate on MdTextButtons (call to action styling).
Right now the different styles are only used in views examples. This also fixes a bug that I ran into while running views_examples_exe --force-device-scale-factor=2 where DesktopScreenX11::GetCursorScreenPoint() wasn't accounting for the proper device scale. BUG=596238,571500 Review URL: https://codereview.chromium.org/1815923002 Cr-Commit-Position: refs/heads/master@{#382463}
Diffstat (limited to 'ui')
-rw-r--r--ui/native_theme/common_theme.cc16
-rw-r--r--ui/native_theme/native_theme.h3
-rw-r--r--ui/views/animation/ink_drop_host_view.cc4
-rw-r--r--ui/views/animation/ink_drop_host_view.h2
-rw-r--r--ui/views/controls/button/label_button.cc8
-rw-r--r--ui/views/controls/button/md_text_button.cc87
-rw-r--r--ui/views/controls/button/md_text_button.h18
-rw-r--r--ui/views/examples/button_example.cc10
-rw-r--r--ui/views/painter.cc44
-rw-r--r--ui/views/painter.h4
-rw-r--r--ui/views/view.cc2
-rw-r--r--ui/views/widget/desktop_aura/desktop_screen_x11.cc5
12 files changed, 159 insertions, 44 deletions
diff --git a/ui/native_theme/common_theme.cc b/ui/native_theme/common_theme.cc
index 3f4c4ce..cf6b6af 100644
--- a/ui/native_theme/common_theme.cc
+++ b/ui/native_theme/common_theme.cc
@@ -29,11 +29,6 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
if (ui::MaterialDesignController::IsModeMaterial()) {
// Dialogs:
static const SkColor kDialogBackgroundColorMd = SK_ColorWHITE;
- // Button:
- static const SkColor kTextButtonEnabledColorMd =
- SkColorSetRGB(0x64, 0x64, 0x64);
- static const SkColor kTextButtonDisabledColorMd =
- SkColorSetA(kTextButtonEnabledColorMd, 0x80);
// MenuItem:
static const SkColor kMenuHighlightBackgroundColorMd =
SkColorSetARGB(0x14, 0x00, 0x00, 0x00);
@@ -54,12 +49,6 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_BubbleBackground:
return kDialogBackgroundColorMd;
- // Button
- case NativeTheme::kColorId_MdTextButtonEnabledColor:
- return kTextButtonEnabledColorMd;
- case NativeTheme::kColorId_MdTextButtonDisabledColor:
- return kTextButtonDisabledColorMd;
-
// MenuItem
case NativeTheme::kColorId_FocusedMenuItemBackgroundColor:
return kMenuHighlightBackgroundColorMd;
@@ -132,6 +121,7 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
static const SkColor kBlueButtonHoverColor = SK_ColorWHITE;
static const SkColor kBlueButtonShadowColor = SkColorSetRGB(0x53, 0x8C, 0xEA);
static const SkColor kCallToActionColor = gfx::kGoogleBlue500;
+ static const SkColor kTextOnCallToActionColor = SK_ColorWHITE;
// MenuItem:
static const SkColor kMenuBackgroundColor = SK_ColorWHITE;
static const SkColor kMenuHighlightBackgroundColor =
@@ -263,6 +253,8 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
return kBlueButtonShadowColor;
case NativeTheme::kColorId_CallToActionColor:
return kCallToActionColor;
+ case NativeTheme::kColorId_TextOnCallToActionColor:
+ return kTextOnCallToActionColor;
// MenuItem
case NativeTheme::kColorId_MenuBorderColor:
@@ -405,8 +397,6 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_ThrobberLightColor:
return kThrobberLightColor;
- case NativeTheme::kColorId_MdTextButtonEnabledColor:
- case NativeTheme::kColorId_MdTextButtonDisabledColor:
case NativeTheme::kColorId_NumColors:
break;
}
diff --git a/ui/native_theme/native_theme.h b/ui/native_theme/native_theme.h
index f4dbd69..057d49c 100644
--- a/ui/native_theme/native_theme.h
+++ b/ui/native_theme/native_theme.h
@@ -265,8 +265,7 @@ class NATIVE_THEME_EXPORT NativeTheme {
kColorId_BlueButtonHoverColor,
kColorId_BlueButtonShadowColor,
kColorId_CallToActionColor,
- kColorId_MdTextButtonEnabledColor,
- kColorId_MdTextButtonDisabledColor,
+ kColorId_TextOnCallToActionColor,
// MenuItem
kColorId_EnabledMenuItemForegroundColor,
kColorId_DisabledMenuItemForegroundColor,
diff --git a/ui/views/animation/ink_drop_host_view.cc b/ui/views/animation/ink_drop_host_view.cc
index 77e2817..ab55881 100644
--- a/ui/views/animation/ink_drop_host_view.cc
+++ b/ui/views/animation/ink_drop_host_view.cc
@@ -13,7 +13,9 @@ namespace views {
// Default sizes for ink drop effects.
const int kInkDropSize = 24;
const int kInkDropLargeCornerRadius = 4;
-const int kInkDropSmallCornerRadius = 2;
+
+// static
+const int InkDropHostView::kInkDropSmallCornerRadius = 2;
InkDropHostView::InkDropHostView()
: ink_drop_size_(kInkDropSize, kInkDropSize) {}
diff --git a/ui/views/animation/ink_drop_host_view.h b/ui/views/animation/ink_drop_host_view.h
index 9467d1e..3a3efa6 100644
--- a/ui/views/animation/ink_drop_host_view.h
+++ b/ui/views/animation/ink_drop_host_view.h
@@ -31,6 +31,8 @@ class VIEWS_EXPORT InkDropHostView : public views::View, public InkDropHost {
void set_ink_drop_size(const gfx::Size& size) { ink_drop_size_ = size; }
protected:
+ static const int kInkDropSmallCornerRadius;
+
// Overrideable methods to allow views to provide minor tweaks to the default
// ink drop.
virtual gfx::Point GetInkDropCenter() const;
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc
index 03a3395..0068e12 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -424,10 +424,10 @@ scoped_ptr<views::InkDropAnimation> LabelButton::CreateInkDropAnimation()
scoped_ptr<views::InkDropHover> LabelButton::CreateInkDropHover() const {
if (!ShouldShowInkDropHover())
return nullptr;
- return GetText().empty()
- ? CustomButton::CreateInkDropHover()
- : make_scoped_ptr(new views::InkDropHover(
- size(), 0, GetInkDropCenter(), GetInkDropBaseColor()));
+ return GetText().empty() ? CustomButton::CreateInkDropHover()
+ : make_scoped_ptr(new views::InkDropHover(
+ size(), kInkDropSmallCornerRadius,
+ GetInkDropCenter(), GetInkDropBaseColor()));
}
gfx::Point LabelButton::GetInkDropCenter() const {
diff --git a/ui/views/controls/button/md_text_button.cc b/ui/views/controls/button/md_text_button.cc
index 1db8d64..46e201e 100644
--- a/ui/views/controls/button/md_text_button.cc
+++ b/ui/views/controls/button/md_text_button.cc
@@ -9,6 +9,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h"
+#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/painter.h"
@@ -25,7 +26,7 @@ const int kMinWidth = 48;
// The amount to enlarge the focus border in all directions relative to the
// button.
-const int kFocusBorderOutset = -4;
+const int kFocusBorderOutset = -2;
// The corner radius of the focus border roundrect.
const int kFocusBorderCornerRadius = 3;
@@ -59,22 +60,34 @@ class MdFocusRing : public views::View {
// static
LabelButton* MdTextButton::CreateStandardButton(ButtonListener* listener,
const base::string16& text) {
- if (ui::MaterialDesignController::IsModeMaterial()) {
- MdTextButton* button = new MdTextButton(listener);
- button->SetText(text);
- // TODO(estade): can we get rid of the platform style border hoopla if
- // we apply the MD treatment to all buttons, even GTK buttons?
- button->SetBorder(
- Border::CreateEmptyBorder(kVerticalPadding, kHorizontalPadding,
- kVerticalPadding, kHorizontalPadding));
- return button;
- }
+ if (ui::MaterialDesignController::IsModeMaterial())
+ return CreateMdButton(listener, text);
LabelButton* button = new LabelButton(listener, text);
button->SetStyle(STYLE_BUTTON);
return button;
}
+MdTextButton* MdTextButton::CreateMdButton(ButtonListener* listener,
+ const base::string16& text) {
+ MdTextButton* button = new MdTextButton(listener);
+ button->SetText(text);
+ // TODO(estade): can we get rid of the platform style border hoopla if
+ // we apply the MD treatment to all buttons, even GTK buttons?
+ button->SetBorder(
+ Border::CreateEmptyBorder(kVerticalPadding, kHorizontalPadding,
+ kVerticalPadding, kHorizontalPadding));
+ return button;
+}
+
+void MdTextButton::SetCallToAction(CallToAction cta) {
+ if (cta_ == cta)
+ return;
+
+ cta_ = cta;
+ UpdateColorsFromNativeTheme();
+}
+
void MdTextButton::Layout() {
LabelButton::Layout();
@@ -83,14 +96,9 @@ void MdTextButton::Layout() {
focus_ring_->SetBoundsRect(focus_bounds);
}
-void MdTextButton::OnFocus() {
- View::OnFocus();
- focus_ring_->SetVisible(true);
-}
-
-void MdTextButton::OnBlur() {
- View::OnBlur();
- focus_ring_->SetVisible(false);
+void MdTextButton::OnNativeThemeChanged(const ui::NativeTheme* theme) {
+ LabelButton::OnNativeThemeChanged(theme);
+ UpdateColorsFromNativeTheme();
}
SkColor MdTextButton::GetInkDropBaseColor() const {
@@ -101,10 +109,21 @@ void MdTextButton::SetText(const base::string16& text) {
LabelButton::SetText(base::i18n::ToUpper(text));
}
+void MdTextButton::OnFocus() {
+ View::OnFocus();
+ focus_ring_->SetVisible(true);
+}
+
+void MdTextButton::OnBlur() {
+ View::OnBlur();
+ focus_ring_->SetVisible(false);
+}
+
MdTextButton::MdTextButton(ButtonListener* listener)
: LabelButton(listener, base::string16()),
ink_drop_delegate_(this, this),
- focus_ring_(new MdFocusRing()) {
+ focus_ring_(new MdFocusRing()),
+ cta_(NO_CALL_TO_ACTION) {
set_ink_drop_delegate(&ink_drop_delegate_);
set_has_ink_drop_action_on_click(true);
SetHorizontalAlignment(gfx::ALIGN_CENTER);
@@ -115,8 +134,36 @@ MdTextButton::MdTextButton(ButtonListener* listener)
focus_ring_->SetVisible(false);
SetFocusPainter(nullptr);
set_request_focus_on_press(false);
+
+ label()->SetAutoColorReadabilityEnabled(false);
}
MdTextButton::~MdTextButton() {}
+void MdTextButton::UpdateColorsFromNativeTheme() {
+ ui::NativeTheme::ColorId fg_color_id = ui::NativeTheme::kColorId_NumColors;
+ switch (cta_) {
+ case NO_CALL_TO_ACTION:
+ fg_color_id = ui::NativeTheme::kColorId_ButtonEnabledColor;
+ break;
+ case WEAK_CALL_TO_ACTION:
+ fg_color_id = ui::NativeTheme::kColorId_CallToActionColor;
+ break;
+ case STRONG_CALL_TO_ACTION:
+ fg_color_id = ui::NativeTheme::kColorId_TextOnCallToActionColor;
+ break;
+ }
+ ui::NativeTheme* theme = GetNativeTheme();
+ SetEnabledTextColors(theme->GetSystemColor(fg_color_id));
+
+ set_background(
+ cta_ == STRONG_CALL_TO_ACTION
+ ? Background::CreateBackgroundPainter(
+ true, Painter::CreateSolidRoundRectPainter(
+ theme->GetSystemColor(
+ ui::NativeTheme::kColorId_CallToActionColor),
+ kInkDropSmallCornerRadius))
+ : nullptr);
+}
+
} // namespace views
diff --git a/ui/views/controls/button/md_text_button.h b/ui/views/controls/button/md_text_button.h
index 10a9e3a..eecbf81 100644
--- a/ui/views/controls/button/md_text_button.h
+++ b/ui/views/controls/button/md_text_button.h
@@ -14,13 +14,26 @@ namespace views {
// A button class that implements the Material Design text button spec.
class VIEWS_EXPORT MdTextButton : public LabelButton {
public:
+ // Describes the presentation of a button. A stronger call to action draws
+ // more attention.
+ enum CallToAction {
+ NO_CALL_TO_ACTION, // Default.
+ WEAK_CALL_TO_ACTION,
+ STRONG_CALL_TO_ACTION,
+ };
+
// Creates a normal STYLE_BUTTON LabelButton in pre-MD, or an MdTextButton
// in MD mode.
static LabelButton* CreateStandardButton(ButtonListener* listener,
const base::string16& text);
+ static MdTextButton* CreateMdButton(ButtonListener* listener,
+ const base::string16& text);
+
+ void SetCallToAction(CallToAction cta);
// LabelButton:
void Layout() override;
+ void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
SkColor GetInkDropBaseColor() const override;
void SetText(const base::string16& text) override;
@@ -33,6 +46,8 @@ class VIEWS_EXPORT MdTextButton : public LabelButton {
MdTextButton(ButtonListener* listener);
~MdTextButton() override;
+ void UpdateColorsFromNativeTheme();
+
ButtonInkDropDelegate ink_drop_delegate_;
// A child view to draw the focus ring. This is not done via a FocusPainter
@@ -40,6 +55,9 @@ class VIEWS_EXPORT MdTextButton : public LabelButton {
// |this|.
views::View* focus_ring_;
+ // The call to action style for this button.
+ CallToAction cta_;
+
DISALLOW_COPY_AND_ASSIGN(MdTextButton);
};
diff --git a/ui/views/examples/button_example.cc b/ui/views/examples/button_example.cc
index 3b4de23..2cf42af 100644
--- a/ui/views/examples/button_example.cc
+++ b/ui/views/examples/button_example.cc
@@ -65,8 +65,16 @@ void ButtonExample::CreateExampleView(View* container) {
container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button")));
- container->AddChildView(MdTextButton::CreateStandardButton(
+ container->AddChildView(MdTextButton::CreateMdButton(
nullptr, base::ASCIIToUTF16("Material design")));
+ MdTextButton* md_button = MdTextButton::CreateMdButton(
+ nullptr, base::ASCIIToUTF16("Strong call to action"));
+ md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION);
+ container->AddChildView(md_button);
+ md_button = MdTextButton::CreateMdButton(
+ nullptr, base::ASCIIToUTF16("Weak call to action"));
+ md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION);
+ container->AddChildView(md_button);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
image_button_ = new ImageButton(this);
diff --git a/ui/views/painter.cc b/ui/views/painter.cc
index 8e0d3e6..9a67795 100644
--- a/ui/views/painter.cc
+++ b/ui/views/painter.cc
@@ -12,7 +12,9 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/rect_f.h"
+#include "ui/gfx/geometry/size.h"
+#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
@@ -23,6 +25,41 @@ namespace views {
namespace {
+// SolidRoundRectPainter -------------------------------------------------------
+
+class SolidRoundRectPainter : public Painter {
+ public:
+ SolidRoundRectPainter(SkColor color, float radius);
+ ~SolidRoundRectPainter() override;
+
+ // Painter:
+ gfx::Size GetMinimumSize() const override;
+ void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
+
+ private:
+ const SkColor color_;
+ const float radius_;
+
+ DISALLOW_COPY_AND_ASSIGN(SolidRoundRectPainter);
+};
+
+SolidRoundRectPainter::SolidRoundRectPainter(SkColor color, float radius)
+ : color_(color), radius_(radius) {}
+
+SolidRoundRectPainter::~SolidRoundRectPainter() {}
+
+gfx::Size SolidRoundRectPainter::GetMinimumSize() const {
+ return gfx::Size();
+}
+
+void SolidRoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
+ gfx::RectF rect((gfx::SizeF(size)));
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(color_);
+ canvas->DrawRoundRect(rect, radius_, paint);
+}
+
// DashedFocusPainter ----------------------------------------------------------
class DashedFocusPainter : public Painter {
@@ -235,6 +272,11 @@ void Painter::PaintFocusPainter(View* view,
}
// static
+Painter* Painter::CreateSolidRoundRectPainter(SkColor color, float radius) {
+ return new SolidRoundRectPainter(color, radius);
+}
+
+// static
Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) {
SkColor colors[2];
colors[0] = c1;
diff --git a/ui/views/painter.h b/ui/views/painter.h
index d75688e..76cc996 100644
--- a/ui/views/painter.h
+++ b/ui/views/painter.h
@@ -46,6 +46,10 @@ class VIEWS_EXPORT Painter {
gfx::Canvas* canvas,
Painter* focus_painter);
+ // Creates a painter that draws a RoundRect with a solid color and given
+ // corner radius.
+ static Painter* CreateSolidRoundRectPainter(SkColor color, float radius);
+
// Creates a painter that draws a gradient between the two colors.
static Painter* CreateHorizontalGradient(SkColor c1, SkColor c2);
static Painter* CreateVerticalGradient(SkColor c1, SkColor c2);
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 2dc8012..3580d04 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -716,7 +716,7 @@ void View::ConvertPointFromScreen(const View* dst, gfx::Point* p) {
if (!widget)
return;
*p -= widget->GetClientAreaBoundsInScreen().OffsetFromOrigin();
- views::View::ConvertPointFromWidget(dst, p);
+ ConvertPointFromWidget(dst, p);
}
gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const {
diff --git a/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/ui/views/widget/desktop_aura/desktop_screen_x11.cc
index 89ea817..e71ae6a 100644
--- a/ui/views/widget/desktop_aura/desktop_screen_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_screen_x11.cc
@@ -38,9 +38,12 @@ const int64_t kConfigureDelayMs = 500;
double GetDeviceScaleFactor() {
float device_scale_factor = 1.0f;
- if (views::LinuxUI::instance())
+ if (views::LinuxUI::instance()) {
device_scale_factor =
views::LinuxUI::instance()->GetDeviceScaleFactor();
+ } else if (gfx::Display::HasForceDeviceScaleFactor()) {
+ device_scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
+ }
return device_scale_factor;
}