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" |
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 Loading... | |
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 // Linearly interpolate background and foreground painters during animation. |
123 int alpha = animation->CurrentValueBetween(0, 0xff); | 125 canvas->sk_canvas()->saveLayer(NULL, NULL); |
reed1
2013/08/14 13:33:56
Not specific to this CL, but..
Skia definitely ta
msw
2013/08/14 16:17:11
Done.
| |
124 state = native_theme_delegate->GetBackgroundThemeState(&extra); | 126 state = native_theme_delegate->GetBackgroundThemeState(&extra); |
125 canvas->SaveLayerAlpha(static_cast<uint8>(0xff - alpha)); | |
126 PaintHelper(this, canvas, theme, part, state, rect, extra); | 127 PaintHelper(this, canvas, theme, part, state, rect, extra); |
127 canvas->Restore(); | |
128 | 128 |
129 SkPaint paint; | |
130 paint.setXfermode(SkLerpXfermode::Create(animation->GetCurrentValue())); | |
reed1
2013/08/14 13:33:56
Create returns an object of reference-count 1
setX
msw
2013/08/14 16:17:11
Done. I too easily forgot how tricky using skia in
| |
131 canvas->sk_canvas()->saveLayer(NULL, &paint); | |
reed1
2013/08/14 13:33:56
Same comment here about the value of passing in a
msw
2013/08/14 16:17:11
Done.
| |
129 state = native_theme_delegate->GetForegroundThemeState(&extra); | 132 state = native_theme_delegate->GetForegroundThemeState(&extra); |
130 canvas->SaveLayerAlpha(static_cast<uint8>(alpha)); | |
131 PaintHelper(this, canvas, theme, part, state, rect, extra); | 133 PaintHelper(this, canvas, theme, part, state, rect, extra); |
132 canvas->Restore(); | 134 canvas->sk_canvas()->restore(); |
135 | |
136 canvas->sk_canvas()->restore(); | |
133 } else { | 137 } else { |
134 PaintHelper(this, canvas, theme, part, state, rect, extra); | 138 PaintHelper(this, canvas, theme, part, state, rect, extra); |
135 } | 139 } |
136 | 140 |
137 // For inverted color schemes, draw a solid fill with the button color. | 141 // For inverted color schemes, draw a solid fill with the button color. |
138 if (gfx::IsInvertedColorScheme()) { | 142 if (gfx::IsInvertedColorScheme()) { |
139 rect.Inset(insets_); | 143 rect.Inset(insets_); |
140 canvas->FillRect(rect, extra.button.background_color); | 144 canvas->FillRect(rect, extra.button.background_color); |
141 } | 145 } |
142 | 146 |
(...skipping 12 matching lines...) Expand all Loading... | |
155 return painters_[focused ? 1 : 0][state].get(); | 159 return painters_[focused ? 1 : 0][state].get(); |
156 } | 160 } |
157 | 161 |
158 void LabelButtonBorder::SetPainter(bool focused, | 162 void LabelButtonBorder::SetPainter(bool focused, |
159 Button::ButtonState state, | 163 Button::ButtonState state, |
160 Painter* painter) { | 164 Painter* painter) { |
161 painters_[focused ? 1 : 0][state].reset(painter); | 165 painters_[focused ? 1 : 0][state].reset(painter); |
162 } | 166 } |
163 | 167 |
164 } // namespace views | 168 } // namespace views |
OLD | NEW |