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

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

Issue 22744003: Fix LabelButtonBorder image blending during state transitions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit addressed. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/label_button_border.h" 5 #include "ui/views/controls/button/label_button_border.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkXfermode.h"
9 #include "ui/base/animation/animation.h" 11 #include "ui/base/animation/animation.h"
10 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
13 #include "ui/gfx/sys_color_change_listener.h" 15 #include "ui/gfx/sys_color_change_listener.h"
14 #include "ui/native_theme/native_theme.h" 16 #include "ui/native_theme/native_theme.h"
15 #include "ui/views/controls/button/label_button.h" 17 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/native_theme_delegate.h" 18 #include "ui/views/native_theme_delegate.h"
17 19
18 namespace views { 20 namespace views {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const NativeThemeDelegate* native_theme_delegate = 114 const NativeThemeDelegate* native_theme_delegate =
113 static_cast<const LabelButton*>(&view); 115 static_cast<const LabelButton*>(&view);
114 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); 116 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart();
115 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); 117 gfx::Rect rect(native_theme_delegate->GetThemePaintRect());
116 ui::NativeTheme::ExtraParams extra; 118 ui::NativeTheme::ExtraParams extra;
117 const ui::NativeTheme* theme = view.GetNativeTheme(); 119 const ui::NativeTheme* theme = view.GetNativeTheme();
118 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); 120 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation();
119 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); 121 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra);
120 122
121 if (animation && animation->is_animating()) { 123 if (animation && animation->is_animating()) {
122 // Composite the background and foreground painters during state animations. 124 // Fade from the background to the foreground painter during state
125 // animations. This is done by performing an additive blending of the two
126 // states in an intermediate layer.
127 canvas->sk_canvas()->saveLayer(NULL, NULL);
128 SkPaint paint;
129 paint.setXfermode(SkXfermode::Create(SkXfermode::kPlus_Mode));
130
131 state = native_theme_delegate->GetBackgroundThemeState(&extra);
123 int alpha = animation->CurrentValueBetween(0, 0xff); 132 int alpha = animation->CurrentValueBetween(0, 0xff);
124 state = native_theme_delegate->GetBackgroundThemeState(&extra); 133 paint.setAlpha(0xff - alpha);
125 canvas->SaveLayerAlpha(static_cast<uint8>(0xff - alpha)); 134 canvas->sk_canvas()->saveLayer(NULL, &paint);
126 PaintHelper(this, canvas, theme, part, state, rect, extra); 135 PaintHelper(this, canvas, theme, part, state, rect, extra);
127 canvas->Restore(); 136 canvas->sk_canvas()->restore();
128 137
129 state = native_theme_delegate->GetForegroundThemeState(&extra); 138 state = native_theme_delegate->GetForegroundThemeState(&extra);
130 canvas->SaveLayerAlpha(static_cast<uint8>(alpha)); 139 paint.setAlpha(alpha);
140 canvas->sk_canvas()->saveLayer(NULL, &paint);
131 PaintHelper(this, canvas, theme, part, state, rect, extra); 141 PaintHelper(this, canvas, theme, part, state, rect, extra);
132 canvas->Restore(); 142 canvas->sk_canvas()->restore();
143
144 canvas->sk_canvas()->restore();
133 } else { 145 } else {
134 PaintHelper(this, canvas, theme, part, state, rect, extra); 146 PaintHelper(this, canvas, theme, part, state, rect, extra);
135 } 147 }
136 148
137 // For inverted color schemes, draw a solid fill with the button color. 149 // For inverted color schemes, draw a solid fill with the button color.
138 if (gfx::IsInvertedColorScheme()) { 150 if (gfx::IsInvertedColorScheme()) {
139 rect.Inset(insets_); 151 rect.Inset(insets_);
140 canvas->FillRect(rect, extra.button.background_color); 152 canvas->FillRect(rect, extra.button.background_color);
141 } 153 }
142 154
(...skipping 12 matching lines...) Expand all
155 return painters_[focused ? 1 : 0][state].get(); 167 return painters_[focused ? 1 : 0][state].get();
156 } 168 }
157 169
158 void LabelButtonBorder::SetPainter(bool focused, 170 void LabelButtonBorder::SetPainter(bool focused,
159 Button::ButtonState state, 171 Button::ButtonState state,
160 Painter* painter) { 172 Painter* painter) {
161 painters_[focused ? 1 : 0][state].reset(painter); 173 painters_[focused ? 1 : 0][state].reset(painter);
162 } 174 }
163 175
164 } // namespace views 176 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698