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

Unified Diff: ui/views/controls/button/label_button_border.cc

Issue 14921006: Fix LabelButtonBorder image blending. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use a skia::RefPtr to free the SkXfermode after use. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/label_button_border.cc
diff --git a/ui/views/controls/button/label_button_border.cc b/ui/views/controls/button/label_button_border.cc
index ef827667f9e119114afaac3ba7f2c2eae4ba1ef3..210b50accb7593612a91f719cad8e4c603825b65 100644
--- a/ui/views/controls/button/label_button_border.cc
+++ b/ui/views/controls/button/label_button_border.cc
@@ -6,6 +6,8 @@
#include "base/logging.h"
#include "grit/ui_resources.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/effects/SkLerpXfermode.h"
#include "ui/base/animation/animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h"
@@ -44,6 +46,7 @@ Button::ButtonState GetButtonState(ui::NativeTheme::State state) {
// A helper function to paint the native theme or images as appropriate.
void PaintHelper(LabelButtonBorder* border,
gfx::Canvas* canvas,
+ const SkPaint& paint,
const ui::NativeTheme* theme,
ui::NativeTheme::Part part,
ui::NativeTheme::State state,
@@ -54,11 +57,8 @@ void PaintHelper(LabelButtonBorder* border,
} else {
Painter* painter =
border->GetPainter(extra.button.is_focused, GetButtonState(state));
- // Paint any corresponding unfocused painter if there is no focused painter.
- if (!painter && extra.button.is_focused)
- painter = border->GetPainter(false, GetButtonState(state));
if (painter)
- painter->Paint(canvas, rect.size());
+ painter->PaintWithSkPaint(canvas, rect.size(), paint);
}
}
@@ -98,29 +98,38 @@ LabelButtonBorder::LabelButtonBorder(Button::ButtonStyle style)
LabelButtonBorder::~LabelButtonBorder() {}
void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) {
- const NativeThemeDelegate* native_theme_delegate =
- static_cast<const LabelButton*>(&view);
- ui::NativeTheme::Part part = native_theme_delegate->GetThemePart();
- gfx::Rect rect(native_theme_delegate->GetThemePaintRect());
+ const NativeThemeDelegate* delegate = static_cast<const LabelButton*>(&view);
+ const ui::NativeTheme::Part part = delegate->GetThemePart();
+ const gfx::Rect rect(delegate->GetThemePaintRect());
ui::NativeTheme::ExtraParams extra;
const ui::NativeTheme* theme = view.GetNativeTheme();
- const ui::Animation* animation = native_theme_delegate->GetThemeAnimation();
- ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra);
+ const ui::Animation* animation = delegate->GetThemeAnimation();
+ SkPaint paint;
if (animation && animation->is_animating()) {
// Composite the background and foreground painters during state animations.
- int alpha = animation->CurrentValueBetween(0, 0xff);
- state = native_theme_delegate->GetBackgroundThemeState(&extra);
- canvas->SaveLayerAlpha(static_cast<uint8>(0xff - alpha));
- PaintHelper(this, canvas, theme, part, state, rect, extra);
- canvas->Restore();
-
- state = native_theme_delegate->GetForegroundThemeState(&extra);
- canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
- PaintHelper(this, canvas, theme, part, state, rect, extra);
- canvas->Restore();
+ ui::NativeTheme::State back = delegate->GetBackgroundThemeState(&extra);
+ ui::NativeTheme::State fore = delegate->GetForegroundThemeState(&extra);
sky 2013/06/13 16:22:04 foreground, or fg.
+ if (style() == Button::STYLE_NATIVE_TEXTBUTTON) {
+ // NativeTheme does not support image interpolation, use alpha blending.
+ PaintHelper(this, canvas, paint, theme, part, back, rect, extra);
+ const int alpha = animation->CurrentValueBetween(0, 0xff);
+ canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
+ PaintHelper(this, canvas, paint, theme, part, fore, rect, extra);
+ canvas->Restore();
+ } else {
+ canvas->Save();
+ // Use linear interpolation to blend background and foreground images.
+ PaintHelper(this, canvas, paint, theme, part, back, rect, extra);
+ skia::RefPtr<SkXfermode> mode(
+ skia::AdoptRef(SkLerpXfermode::Create(animation->GetCurrentValue())));
+ paint.setXfermode(mode.get());
+ PaintHelper(this, canvas, paint, theme, part, fore, rect, extra);
+ canvas->Restore();
+ }
} else {
- PaintHelper(this, canvas, theme, part, state, rect, extra);
+ ui::NativeTheme::State state = delegate->GetThemeState(&extra);
+ PaintHelper(this, canvas, paint, theme, part, state, rect, extra);
}
// Draw the Views focus border for the native theme style.
@@ -135,6 +144,9 @@ gfx::Insets LabelButtonBorder::GetInsets() const {
Painter* LabelButtonBorder::GetPainter(bool focused,
Button::ButtonState state) {
+ // Use any corresponding unfocused painter if there is no focused painter.
+ if (focused && !painters_[1][state])
+ return painters_[0][state].get();
return painters_[focused ? 1 : 0][state].get();
}
« no previous file with comments | « ui/views/controls/button/blue_button.cc ('k') | ui/views/painter.h » ('j') | ui/views/painter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698