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 "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/effects/SkLerpXfermode.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" |
| 15 #include "ui/gfx/skia_util.h" |
13 #include "ui/gfx/sys_color_change_listener.h" | 16 #include "ui/gfx/sys_color_change_listener.h" |
14 #include "ui/native_theme/native_theme.h" | 17 #include "ui/native_theme/native_theme.h" |
15 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
16 #include "ui/views/native_theme_delegate.h" | 19 #include "ui/views/native_theme_delegate.h" |
17 | 20 |
18 namespace views { | 21 namespace views { |
19 | 22 |
20 namespace { | 23 namespace { |
21 | 24 |
22 // Insets for the unified button images. This assumes that the images | 25 // Insets for the unified button images. This assumes that the images |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 const NativeThemeDelegate* native_theme_delegate = | 115 const NativeThemeDelegate* native_theme_delegate = |
113 static_cast<const LabelButton*>(&view); | 116 static_cast<const LabelButton*>(&view); |
114 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); | 117 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); |
115 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); | 118 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); |
116 ui::NativeTheme::ExtraParams extra; | 119 ui::NativeTheme::ExtraParams extra; |
117 const ui::NativeTheme* theme = view.GetNativeTheme(); | 120 const ui::NativeTheme* theme = view.GetNativeTheme(); |
118 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 121 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
119 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 122 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
120 | 123 |
121 if (animation && animation->is_animating()) { | 124 if (animation && animation->is_animating()) { |
122 // Composite the background and foreground painters during state animations. | 125 // Linearly interpolate background and foreground painters during animation. |
123 int alpha = animation->CurrentValueBetween(0, 0xff); | 126 const SkRect sk_rect = gfx::RectToSkRect(rect); |
| 127 canvas->sk_canvas()->saveLayer(&sk_rect, NULL); |
124 state = native_theme_delegate->GetBackgroundThemeState(&extra); | 128 state = native_theme_delegate->GetBackgroundThemeState(&extra); |
125 canvas->SaveLayerAlpha(static_cast<uint8>(0xff - alpha)); | |
126 PaintHelper(this, canvas, theme, part, state, rect, extra); | 129 PaintHelper(this, canvas, theme, part, state, rect, extra); |
127 canvas->Restore(); | |
128 | 130 |
| 131 SkPaint paint; |
| 132 skia::RefPtr<SkXfermode> sk_lerp_xfer = |
| 133 skia::AdoptRef(SkLerpXfermode::Create(animation->GetCurrentValue())); |
| 134 paint.setXfermode(sk_lerp_xfer.get()); |
| 135 canvas->sk_canvas()->saveLayer(&sk_rect, &paint); |
129 state = native_theme_delegate->GetForegroundThemeState(&extra); | 136 state = native_theme_delegate->GetForegroundThemeState(&extra); |
130 canvas->SaveLayerAlpha(static_cast<uint8>(alpha)); | |
131 PaintHelper(this, canvas, theme, part, state, rect, extra); | 137 PaintHelper(this, canvas, theme, part, state, rect, extra); |
132 canvas->Restore(); | 138 canvas->sk_canvas()->restore(); |
| 139 |
| 140 canvas->sk_canvas()->restore(); |
133 } else { | 141 } else { |
134 PaintHelper(this, canvas, theme, part, state, rect, extra); | 142 PaintHelper(this, canvas, theme, part, state, rect, extra); |
135 } | 143 } |
136 | 144 |
137 // For inverted color schemes, draw a solid fill with the button color. | 145 // For inverted color schemes, draw a solid fill with the button color. |
138 if (gfx::IsInvertedColorScheme()) { | 146 if (gfx::IsInvertedColorScheme()) { |
139 rect.Inset(insets_); | 147 rect.Inset(insets_); |
140 canvas->FillRect(rect, extra.button.background_color); | 148 canvas->FillRect(rect, extra.button.background_color); |
141 } | 149 } |
142 | 150 |
(...skipping 12 matching lines...) Expand all Loading... |
155 return painters_[focused ? 1 : 0][state].get(); | 163 return painters_[focused ? 1 : 0][state].get(); |
156 } | 164 } |
157 | 165 |
158 void LabelButtonBorder::SetPainter(bool focused, | 166 void LabelButtonBorder::SetPainter(bool focused, |
159 Button::ButtonState state, | 167 Button::ButtonState state, |
160 Painter* painter) { | 168 Painter* painter) { |
161 painters_[focused ? 1 : 0][state].reset(painter); | 169 painters_[focused ? 1 : 0][state].reset(painter); |
162 } | 170 } |
163 | 171 |
164 } // namespace views | 172 } // namespace views |
OLD | NEW |