diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-08 17:26:45 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-08 17:26:45 +0000 |
commit | 3002f55e44a6d87e8d2e32c9ac34bb09ba514580 (patch) | |
tree | 5de5091ba7befe59e52aebf4e30696eeb7f158d3 /views/native_theme_painter.cc | |
parent | c97d3965f903c15cb16724f82698ca11d998b410 (diff) | |
download | chromium_src-3002f55e44a6d87e8d2e32c9ac34bb09ba514580.zip chromium_src-3002f55e44a6d87e8d2e32c9ac34bb09ba514580.tar.gz chromium_src-3002f55e44a6d87e8d2e32c9ac34bb09ba514580.tar.bz2 |
Adding a native theme painter, to allow Views to use NativeTheme to draw
their background. Added example code to show it in use. I still have not
hooked this into any existing View-based controls.
This CL depends on changes currently being made to native theme, see
http://codereview.chromium.org/6728029/ for details.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/6771056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80952 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/native_theme_painter.cc')
-rw-r--r-- | views/native_theme_painter.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/views/native_theme_painter.cc b/views/native_theme_painter.cc new file mode 100644 index 0000000..1d4ab21 --- /dev/null +++ b/views/native_theme_painter.cc @@ -0,0 +1,54 @@ +// 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 |