1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "views/native_theme_painter.h"
#include "base/logging.h"
#include "ui/base/animation/animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/rect.h"
namespace views {
NativeThemePainter::NativeThemePainter(Delegate* delegate)
: delegate_(delegate) {
DCHECK(delegate_);
}
gfx::Size NativeThemePainter::GetPreferredSize() {
const gfx::NativeTheme* theme = gfx::NativeTheme::instance();
return theme->GetPartSize(delegate_->GetThemePart());
}
void NativeThemePainter::Paint(int w, int h, gfx::Canvas* canvas) {
const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
gfx::NativeTheme::Part part = delegate_->GetThemePart();
gfx::CanvasSkia* skia_canvas = canvas->AsCanvasSkia();
gfx::Rect rect(0, 0, w, h);
if (delegate_->GetThemeAnimation() != NULL &&
delegate_->GetThemeAnimation()->is_animating()) {
// Paint background state.
gfx::NativeTheme::ExtraParams prev_extra;
gfx::NativeTheme::State prev_state =
delegate_->GetBackgroundThemeState(&prev_extra);
native_theme->Paint(skia_canvas, part, prev_state, rect, prev_extra);
// Composite foreground state above it.
gfx::NativeTheme::ExtraParams extra;
gfx::NativeTheme::State state = delegate_->GetForegroundThemeState(&extra);
int alpha = delegate_->GetThemeAnimation()->CurrentValueBetween(0, 255);
skia_canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
native_theme->Paint(skia_canvas, part, state, rect, extra);
skia_canvas->Restore();
} else {
gfx::NativeTheme::ExtraParams extra;
gfx::NativeTheme::State state = delegate_->GetThemeState(&extra);
native_theme->Paint(skia_canvas, part, state, rect, extra);
}
}
} // namespace views
|