Commit b440caef authored by estade's avatar estade Committed by Commit bot

Adjust shadow and stroke of MdTextButton.

Also fix the appearance of the "Show All" button on the download shelf when using custom themes (this regressed at some point in M55, as it works properly in my M54 build).

BUG=647047

Review-Url: https://codereview.chromium.org/2400563004
Cr-Commit-Position: refs/heads/master@{#423689}
parent feb2e37e
...@@ -109,7 +109,7 @@ LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf) ...@@ -109,7 +109,7 @@ LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf)
views::MdTextButton* button = views::MdTextButton* button =
views::MdTextButton::Create(this, base::string16()); views::MdTextButton::Create(this, base::string16());
button->SetProminent(true); button->SetProminent(true);
button->set_bg_color_override(gfx::kGoogleRed700); button->SetBgColorOverride(gfx::kGoogleRed700);
// Base font size + 2 = 14. // Base font size + 2 = 14.
// TODO(estade): should this 2 be shared with other tray views? See // TODO(estade): should this 2 be shared with other tray views? See
// crbug.com/623987 // crbug.com/623987
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_stats.h" #include "chrome/browser/download/download_stats.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
...@@ -309,10 +311,21 @@ bool DownloadShelfView::CanFitFirstDownloadItem() { ...@@ -309,10 +311,21 @@ bool DownloadShelfView::CanFitFirstDownloadItem() {
void DownloadShelfView::UpdateColorsFromTheme() { void DownloadShelfView::UpdateColorsFromTheme() {
if (show_all_view_ && close_button_ && GetThemeProvider()) { if (show_all_view_ && close_button_ && GetThemeProvider()) {
set_background(views::Background::CreateSolidBackground( const SkColor bg_color =
GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR))); GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR);
set_background(views::Background::CreateSolidBackground(bg_color));
show_all_view_->SetEnabledTextColors( show_all_view_->SetEnabledTextColors(
GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
if (ThemeServiceFactory::GetForProfile(browser_->profile())
->UsingDefaultTheme()) {
// For the normal theme, just use the default button bg color.
show_all_view_->SetBgColorOverride(base::Optional<SkColor>());
} else {
// For custom themes, we have to make up a background color for the
// button. Use a slight tint of the shelf background.
show_all_view_->SetBgColorOverride(
color_utils::BlendTowardOppositeLuma(bg_color, 0x10));
}
} }
} }
......
...@@ -96,7 +96,7 @@ void ConfirmInfoBar::ViewHierarchyChanged( ...@@ -96,7 +96,7 @@ void ConfirmInfoBar::ViewHierarchyChanged(
// TODO(estade): These should be removed and moved into the native // TODO(estade): These should be removed and moved into the native
// theme. Also, infobars should always use the normal (non-incognito) // theme. Also, infobars should always use the normal (non-incognito)
// native theme. // native theme.
cancel_button_->set_bg_color_override(SK_ColorWHITE); cancel_button_->SetBgColorOverride(SK_ColorWHITE);
cancel_button_->SetEnabledTextColors(kTextColor); cancel_button_->SetEnabledTextColors(kTextColor);
} }
AddViewToContentArea(cancel_button_); AddViewToContentArea(cancel_button_);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkDrawLooper.h"
#include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "ui/compositor/paint_recorder.h" #include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
...@@ -132,10 +133,12 @@ void RoundedRectangleLayerDelegate::OnPaintLayer( ...@@ -132,10 +133,12 @@ void RoundedRectangleLayerDelegate::OnPaintLayer(
BorderShadowLayerDelegate::BorderShadowLayerDelegate( BorderShadowLayerDelegate::BorderShadowLayerDelegate(
const std::vector<gfx::ShadowValue>& shadows, const std::vector<gfx::ShadowValue>& shadows,
const gfx::Rect& shadowed_area_bounds, const gfx::Rect& shadowed_area_bounds,
SkColor fill_color,
int corner_radius) int corner_radius)
: BasePaintedLayerDelegate(gfx::kPlaceholderColor), : BasePaintedLayerDelegate(gfx::kPlaceholderColor),
shadows_(shadows), shadows_(shadows),
bounds_(shadowed_area_bounds), bounds_(shadowed_area_bounds),
fill_color_(fill_color),
corner_radius_(corner_radius) {} corner_radius_(corner_radius) {}
BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {} BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {}
...@@ -152,22 +155,24 @@ gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { ...@@ -152,22 +155,24 @@ gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const {
void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
SkPaint paint; SkPaint paint;
paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_));
paint.setStyle(SkPaint::kFill_Style); paint.setStyle(SkPaint::kFill_Style);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setColor(SK_ColorTRANSPARENT); paint.setColor(fill_color_);
gfx::RectF rrect_bounds = gfx::RectF rrect_bounds =
gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin());
SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds),
corner_radius_, corner_radius_);
// First the fill color.
ui::PaintRecorder recorder(context, GetPaintedBounds().size()); ui::PaintRecorder recorder(context, GetPaintedBounds().size());
recorder.canvas()->DrawRoundRect(rrect_bounds, corner_radius_, paint); recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint);
SkPaint clear_paint; // Now the shadow.
clear_paint.setAntiAlias(true); paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_));
clear_paint.setXfermodeMode(SkXfermode::kClear_Mode); recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkRegion::kDifference_Op,
// If we don't care about actually clearing preexisting buffer content, true);
// this could be replaced with a kDifference clip for the draw above. recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint);
recorder.canvas()->DrawRoundRect(rrect_bounds, corner_radius_, clear_paint);
} }
} // namespace views } // namespace views
...@@ -114,11 +114,12 @@ class VIEWS_EXPORT RoundedRectangleLayerDelegate ...@@ -114,11 +114,12 @@ class VIEWS_EXPORT RoundedRectangleLayerDelegate
}; };
// A BasePaintedLayerDelegate that paints a shadow around the outside of a // A BasePaintedLayerDelegate that paints a shadow around the outside of a
// specified roundrect. // specified roundrect, and also fills the round rect.
class VIEWS_EXPORT BorderShadowLayerDelegate : public BasePaintedLayerDelegate { class VIEWS_EXPORT BorderShadowLayerDelegate : public BasePaintedLayerDelegate {
public: public:
BorderShadowLayerDelegate(const std::vector<gfx::ShadowValue>& shadows, BorderShadowLayerDelegate(const std::vector<gfx::ShadowValue>& shadows,
const gfx::Rect& shadowed_area_bounds, const gfx::Rect& shadowed_area_bounds,
SkColor fill_color,
int corner_radius); int corner_radius);
~BorderShadowLayerDelegate() override; ~BorderShadowLayerDelegate() override;
...@@ -133,9 +134,11 @@ class VIEWS_EXPORT BorderShadowLayerDelegate : public BasePaintedLayerDelegate { ...@@ -133,9 +134,11 @@ class VIEWS_EXPORT BorderShadowLayerDelegate : public BasePaintedLayerDelegate {
const std::vector<gfx::ShadowValue> shadows_; const std::vector<gfx::ShadowValue> shadows_;
// The bounds of the shadowed area. // The bounds of the shadowed area.
gfx::Rect bounds_; const gfx::Rect bounds_;
int corner_radius_; const SkColor fill_color_;
const int corner_radius_;
DISALLOW_COPY_AND_ASSIGN(BorderShadowLayerDelegate); DISALLOW_COPY_AND_ASSIGN(BorderShadowLayerDelegate);
}; };
......
...@@ -86,6 +86,11 @@ void MdTextButton::SetProminent(bool is_prominent) { ...@@ -86,6 +86,11 @@ void MdTextButton::SetProminent(bool is_prominent) {
UpdateColors(); UpdateColors();
} }
void MdTextButton::SetBgColorOverride(const base::Optional<SkColor>& color) {
bg_color_override_ = color;
UpdateColors();
}
void MdTextButton::OnFocus() { void MdTextButton::OnFocus() {
LabelButton::OnFocus(); LabelButton::OnFocus();
FocusRing::Install(this); FocusRing::Install(this);
...@@ -122,12 +127,11 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() ...@@ -122,12 +127,11 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight()
const { const {
if (!ShouldShowInkDropHighlight()) if (!ShouldShowInkDropHighlight())
return nullptr; return nullptr;
if (!is_prominent_)
return LabelButton::CreateInkDropHighlight();
// The prominent button hover effect is a shadow. // The prominent button hover effect is a shadow.
const int kYOffset = 1; const int kYOffset = 1;
const int kSkiaBlurRadius = 1; const int kSkiaBlurRadius = 2;
const int shadow_alpha = is_prominent_ ? 0x3D : 0x1A;
std::vector<gfx::ShadowValue> shadows; std::vector<gfx::ShadowValue> shadows;
// The notion of blur that gfx::ShadowValue uses is twice the Skia/CSS value. // The notion of blur that gfx::ShadowValue uses is twice the Skia/CSS value.
// Skia counts the number of pixels outside the mask area whereas // Skia counts the number of pixels outside the mask area whereas
...@@ -135,11 +139,13 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight() ...@@ -135,11 +139,13 @@ std::unique_ptr<views::InkDropHighlight> MdTextButton::CreateInkDropHighlight()
// the mask bounds. // the mask bounds.
shadows.push_back(gfx::ShadowValue(gfx::Vector2d(0, kYOffset), shadows.push_back(gfx::ShadowValue(gfx::Vector2d(0, kYOffset),
2 * kSkiaBlurRadius, 2 * kSkiaBlurRadius,
SkColorSetA(SK_ColorBLACK, 0x3D))); SkColorSetA(SK_ColorBLACK, shadow_alpha)));
const SkColor fill_color =
SkColorSetA(SK_ColorWHITE, is_prominent_ ? 0x0D : 0x05);
return base::MakeUnique<InkDropHighlight>( return base::MakeUnique<InkDropHighlight>(
gfx::RectF(GetLocalBounds()).CenterPoint(), gfx::RectF(GetLocalBounds()).CenterPoint(),
base::WrapUnique(new BorderShadowLayerDelegate( base::WrapUnique(new BorderShadowLayerDelegate(
shadows, GetLocalBounds(), kInkDropSmallCornerRadius))); shadows, GetLocalBounds(), fill_color, kInkDropSmallCornerRadius)));
} }
bool MdTextButton::ShouldShowInkDropForFocus() const { bool MdTextButton::ShouldShowInkDropForFocus() const {
...@@ -264,11 +270,8 @@ void MdTextButton::UpdateColors() { ...@@ -264,11 +270,8 @@ void MdTextButton::UpdateColors() {
bg_color = color_utils::GetResultingPaintColor(shade, bg_color); bg_color = color_utils::GetResultingPaintColor(shade, bg_color);
} }
const SkAlpha kStrokeOpacity = 0x1A; SkColor stroke_color =
SkColor stroke_color = (is_prominent_ || color_utils::IsDark(text_color)) is_prominent_ ? SK_ColorTRANSPARENT : SkColorSetA(text_color, 0x33);
? SkColorSetA(SK_ColorBLACK, kStrokeOpacity)
: SkColorSetA(SK_ColorWHITE, 2 * kStrokeOpacity);
DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color)));
set_background(Background::CreateBackgroundPainter( set_background(Background::CreateBackgroundPainter(
true, Painter::CreateRoundRectWith1PxBorderPainter( true, Painter::CreateRoundRectWith1PxBorderPainter(
......
...@@ -26,7 +26,9 @@ class VIEWS_EXPORT MdTextButton : public LabelButton { ...@@ -26,7 +26,9 @@ class VIEWS_EXPORT MdTextButton : public LabelButton {
// See |is_prominent_|. // See |is_prominent_|.
void SetProminent(bool is_prominent); void SetProminent(bool is_prominent);
void set_bg_color_override(SkColor color) { bg_color_override_ = color; }
// See |bg_color_override_|.
void SetBgColorOverride(const base::Optional<SkColor>& color);
// LabelButton: // LabelButton:
void OnFocus() override; void OnFocus() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment