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 "cc/paint/paint_flags.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/gfx/animation/animation.h" | 10 #include "ui/gfx/animation/animation.h" |
11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/gfx/skia_util.h" | 13 #include "ui/gfx/skia_util.h" |
14 #include "ui/gfx/sys_color_change_listener.h" | 14 #include "ui/gfx/sys_color_change_listener.h" |
15 #include "ui/native_theme/native_theme.h" | 15 #include "ui/native_theme/native_theme.h" |
16 #include "ui/resources/grit/ui_resources.h" | 16 #include "ui/resources/grit/ui_resources.h" |
17 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
18 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 ui::NativeTheme::ExtraParams extra; | 135 ui::NativeTheme::ExtraParams extra; |
136 const gfx::Animation* animation = native_theme_delegate->GetThemeAnimation(); | 136 const gfx::Animation* animation = native_theme_delegate->GetThemeAnimation(); |
137 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); | 137 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); |
138 | 138 |
139 if (animation && animation->is_animating()) { | 139 if (animation && animation->is_animating()) { |
140 // Linearly interpolate background and foreground painters during animation. | 140 // Linearly interpolate background and foreground painters during animation. |
141 uint8_t fg_alpha = | 141 uint8_t fg_alpha = |
142 static_cast<uint8_t>(animation->CurrentValueBetween(0, 255)); | 142 static_cast<uint8_t>(animation->CurrentValueBetween(0, 255)); |
143 | 143 |
144 const SkRect sk_rect = gfx::RectToSkRect(rect); | 144 const SkRect sk_rect = gfx::RectToSkRect(rect); |
145 SkAutoCanvasRestore auto_restore(canvas->sk_canvas(), false); | 145 cc::PaintCanvasAutoRestore auto_restore(canvas->sk_canvas(), false); |
146 canvas->sk_canvas()->saveLayer(&sk_rect, nullptr); | 146 canvas->sk_canvas()->saveLayer(&sk_rect, nullptr); |
147 | 147 |
148 { | 148 { |
149 // First, modulate the background by 1 - alpha. | 149 // First, modulate the background by 1 - alpha. |
150 SkAutoCanvasRestore auto_restore(canvas->sk_canvas(), false); | 150 cc::PaintCanvasAutoRestore auto_restore(canvas->sk_canvas(), false); |
151 canvas->sk_canvas()->saveLayerAlpha(&sk_rect, 255 - fg_alpha); | 151 canvas->sk_canvas()->saveLayerAlpha(&sk_rect, 255 - fg_alpha); |
152 state = native_theme_delegate->GetBackgroundThemeState(&extra); | 152 state = native_theme_delegate->GetBackgroundThemeState(&extra); |
153 PaintHelper(this, canvas, state, rect, extra); | 153 PaintHelper(this, canvas, state, rect, extra); |
154 } | 154 } |
155 | 155 |
156 // Then modulate the foreground by alpha, and blend using kPlus_Mode. | 156 // Then modulate the foreground by alpha, and blend using kPlus_Mode. |
157 SkPaint paint; | 157 cc::PaintFlags paint; |
158 paint.setAlpha(fg_alpha); | 158 paint.setAlpha(fg_alpha); |
159 paint.setBlendMode(SkBlendMode::kPlus); | 159 paint.setBlendMode(SkBlendMode::kPlus); |
160 canvas->sk_canvas()->saveLayer(&sk_rect, &paint); | 160 canvas->sk_canvas()->saveLayer(&sk_rect, &paint); |
161 state = native_theme_delegate->GetForegroundThemeState(&extra); | 161 state = native_theme_delegate->GetForegroundThemeState(&extra); |
162 PaintHelper(this, canvas, state, rect, extra); | 162 PaintHelper(this, canvas, state, rect, extra); |
163 } else { | 163 } else { |
164 PaintHelper(this, canvas, state, rect, extra); | 164 PaintHelper(this, canvas, state, rect, extra); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
(...skipping 13 matching lines...) Expand all Loading... |
181 return painters_[focused ? 1 : 0][state].get(); | 181 return painters_[focused ? 1 : 0][state].get(); |
182 } | 182 } |
183 | 183 |
184 void LabelButtonAssetBorder::SetPainter(bool focused, | 184 void LabelButtonAssetBorder::SetPainter(bool focused, |
185 Button::ButtonState state, | 185 Button::ButtonState state, |
186 std::unique_ptr<Painter> painter) { | 186 std::unique_ptr<Painter> painter) { |
187 painters_[focused ? 1 : 0][state] = std::move(painter); | 187 painters_[focused ? 1 : 0][state] = std::move(painter); |
188 } | 188 } |
189 | 189 |
190 } // namespace views | 190 } // namespace views |
OLD | NEW |