Open NaCl IRT file only once at startup
[chromium-blink-merge.git] / views / native_theme_painter.cc
blob584667b92077d5d7fee2ca91a4b15d4c3511452a
1 // Copyright (c) 2011 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 "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/canvas_skia.h"
11 #include "ui/gfx/rect.h"
12 #include "views/native_theme_delegate.h"
14 namespace views {
16 NativeThemePainter::NativeThemePainter(NativeThemeDelegate* delegate)
17 : delegate_(delegate) {
18 DCHECK(delegate_);
21 gfx::Size NativeThemePainter::GetPreferredSize() {
22 const gfx::NativeTheme* theme = gfx::NativeTheme::instance();
23 gfx::NativeTheme::ExtraParams extra;
24 gfx::NativeTheme::State state = delegate_->GetThemeState(&extra);
25 return theme->GetPartSize(delegate_->GetThemePart(), state, extra);
28 void NativeThemePainter::Paint(int w, int h, gfx::Canvas* canvas) {
29 const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
30 gfx::NativeTheme::Part part = delegate_->GetThemePart();
31 gfx::Rect rect(0, 0, w, h);
33 if (delegate_->GetThemeAnimation() != NULL &&
34 delegate_->GetThemeAnimation()->is_animating()) {
35 // Paint background state.
36 gfx::NativeTheme::ExtraParams prev_extra;
37 gfx::NativeTheme::State prev_state =
38 delegate_->GetBackgroundThemeState(&prev_extra);
39 native_theme->Paint(
40 canvas->GetSkCanvas(), part, prev_state, rect, prev_extra);
42 // Composite foreground state above it.
43 gfx::NativeTheme::ExtraParams extra;
44 gfx::NativeTheme::State state = delegate_->GetForegroundThemeState(&extra);
45 int alpha = delegate_->GetThemeAnimation()->CurrentValueBetween(0, 255);
46 canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
47 native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra);
48 canvas->Restore();
49 } else {
50 gfx::NativeTheme::ExtraParams extra;
51 gfx::NativeTheme::State state = delegate_->GetThemeState(&extra);
52 native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra);
56 } // namespace views