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
3 // found in the LICENSE file.
5 #include "ui/views/native_theme_painter.h"
7 #include "base/logging.h"
8 #include "ui/base/animation/animation.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/views/native_theme_delegate.h"
15 NativeThemePainter::NativeThemePainter(NativeThemeDelegate
* delegate
)
16 : delegate_(delegate
) {
20 gfx::Size
NativeThemePainter::GetPreferredSize() {
21 const ui::NativeTheme
* theme
= ui::NativeTheme::instance();
22 ui::NativeTheme::ExtraParams extra
;
23 ui::NativeTheme::State state
= delegate_
->GetThemeState(&extra
);
24 return theme
->GetPartSize(delegate_
->GetThemePart(), state
, extra
);
27 void NativeThemePainter::Paint(gfx::Canvas
* canvas
, const gfx::Size
& size
) {
28 const ui::NativeTheme
* native_theme
= ui::NativeTheme::instance();
29 ui::NativeTheme::Part part
= delegate_
->GetThemePart();
32 if (delegate_
->GetThemeAnimation() != NULL
&&
33 delegate_
->GetThemeAnimation()->is_animating()) {
34 // Paint background state.
35 ui::NativeTheme::ExtraParams prev_extra
;
36 ui::NativeTheme::State prev_state
=
37 delegate_
->GetBackgroundThemeState(&prev_extra
);
38 native_theme
->Paint(canvas
->sk_canvas(), part
, prev_state
, rect
,
41 // Composite foreground state above it.
42 ui::NativeTheme::ExtraParams extra
;
43 ui::NativeTheme::State state
= delegate_
->GetForegroundThemeState(&extra
);
44 int alpha
= delegate_
->GetThemeAnimation()->CurrentValueBetween(0, 255);
45 canvas
->SaveLayerAlpha(static_cast<uint8
>(alpha
));
46 native_theme
->Paint(canvas
->sk_canvas(), part
, state
, rect
, extra
);
49 ui::NativeTheme::ExtraParams extra
;
50 ui::NativeTheme::State state
= delegate_
->GetThemeState(&extra
);
51 native_theme
->Paint(canvas
->sk_canvas(), part
, state
, rect
, extra
);