OLD | NEW |
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 "third_party/skia/include/core/SkPaint.h" | 8 #include "third_party/skia/include/core/SkPaint.h" |
9 #include "third_party/skia/include/effects/SkArithmeticMode.h" | 9 #include "third_party/skia/include/effects/SkArithmeticMode.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void LabelButtonAssetBorder::Paint(const View& view, gfx::Canvas* canvas) { | 132 void LabelButtonAssetBorder::Paint(const View& view, gfx::Canvas* canvas) { |
133 const NativeThemeDelegate* native_theme_delegate = | 133 const NativeThemeDelegate* native_theme_delegate = |
134 static_cast<const LabelButton*>(&view); | 134 static_cast<const LabelButton*>(&view); |
135 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); | 135 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); |
136 ui::NativeTheme::ExtraParams extra; | 136 ui::NativeTheme::ExtraParams extra; |
137 const gfx::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 137 const gfx::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
138 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 138 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
139 | 139 |
140 if (animation && animation->is_animating()) { | 140 if (animation && animation->is_animating()) { |
141 // Linearly interpolate background and foreground painters during animation. | 141 // Linearly interpolate background and foreground painters during animation. |
| 142 uint8_t fg_alpha = |
| 143 static_cast<uint8_t>(animation->CurrentValueBetween(0, 255)); |
| 144 |
142 const SkRect sk_rect = gfx::RectToSkRect(rect); | 145 const SkRect sk_rect = gfx::RectToSkRect(rect); |
143 canvas->sk_canvas()->saveLayer(&sk_rect, NULL); | 146 SkAutoCanvasRestore auto_restore(canvas->sk_canvas(), false); |
144 state = native_theme_delegate->GetBackgroundThemeState(&extra); | 147 canvas->sk_canvas()->saveLayer(&sk_rect, nullptr); |
145 PaintHelper(this, canvas, state, rect, extra); | |
146 | 148 |
| 149 { |
| 150 // First, modulate the background by 1 - alpha. |
| 151 SkAutoCanvasRestore auto_restore(canvas->sk_canvas(), false); |
| 152 canvas->sk_canvas()->saveLayerAlpha(&sk_rect, 255 - fg_alpha); |
| 153 state = native_theme_delegate->GetBackgroundThemeState(&extra); |
| 154 PaintHelper(this, canvas, state, rect, extra); |
| 155 } |
| 156 |
| 157 // Then modulate the foreground by alpha, and blend using kPlus_Mode. |
147 SkPaint paint; | 158 SkPaint paint; |
148 double scale = animation->GetCurrentValue(); | 159 paint.setAlpha(fg_alpha); |
149 paint.setXfermode(SkArithmeticMode::Make(0.0f, scale, 1.0 - scale, 0.0)); | 160 paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
150 canvas->sk_canvas()->saveLayer(&sk_rect, &paint); | 161 canvas->sk_canvas()->saveLayer(&sk_rect, &paint); |
151 state = native_theme_delegate->GetForegroundThemeState(&extra); | 162 state = native_theme_delegate->GetForegroundThemeState(&extra); |
152 PaintHelper(this, canvas, state, rect, extra); | 163 PaintHelper(this, canvas, state, rect, extra); |
153 canvas->sk_canvas()->restore(); | |
154 | |
155 canvas->sk_canvas()->restore(); | |
156 } else { | 164 } else { |
157 PaintHelper(this, canvas, state, rect, extra); | 165 PaintHelper(this, canvas, state, rect, extra); |
158 } | 166 } |
159 } | 167 } |
160 | 168 |
161 gfx::Size LabelButtonAssetBorder::GetMinimumSize() const { | 169 gfx::Size LabelButtonAssetBorder::GetMinimumSize() const { |
162 gfx::Size minimum_size; | 170 gfx::Size minimum_size; |
163 for (int i = 0; i < 2; ++i) { | 171 for (int i = 0; i < 2; ++i) { |
164 for (int j = 0; j < Button::STATE_COUNT; ++j) { | 172 for (int j = 0; j < Button::STATE_COUNT; ++j) { |
165 if (painters_[i][j]) | 173 if (painters_[i][j]) |
166 minimum_size.SetToMax(painters_[i][j]->GetMinimumSize()); | 174 minimum_size.SetToMax(painters_[i][j]->GetMinimumSize()); |
167 } | 175 } |
168 } | 176 } |
169 return minimum_size; | 177 return minimum_size; |
170 } | 178 } |
171 | 179 |
172 Painter* LabelButtonAssetBorder::GetPainter(bool focused, | 180 Painter* LabelButtonAssetBorder::GetPainter(bool focused, |
173 Button::ButtonState state) { | 181 Button::ButtonState state) { |
174 return painters_[focused ? 1 : 0][state].get(); | 182 return painters_[focused ? 1 : 0][state].get(); |
175 } | 183 } |
176 | 184 |
177 void LabelButtonAssetBorder::SetPainter(bool focused, | 185 void LabelButtonAssetBorder::SetPainter(bool focused, |
178 Button::ButtonState state, | 186 Button::ButtonState state, |
179 Painter* painter) { | 187 Painter* painter) { |
180 painters_[focused ? 1 : 0][state].reset(painter); | 188 painters_[focused ? 1 : 0][state].reset(painter); |
181 } | 189 } |
182 | 190 |
183 } // namespace views | 191 } // namespace views |
OLD | NEW |