summaryrefslogtreecommitdiffstats
path: root/views/native_theme_painter.cc
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 18:36:42 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 18:36:42 +0000
commit0a4a1bb2afa3d3f8b9a9c981e420ff2048e68de7 (patch)
tree3ac77a84a6d49483552c936425dd580fa15dea86 /views/native_theme_painter.cc
parent3f5d3c6dd8ba59830c9aa484bed524a673749f47 (diff)
downloadchromium_src-0a4a1bb2afa3d3f8b9a9c981e420ff2048e68de7.zip
chromium_src-0a4a1bb2afa3d3f8b9a9c981e420ff2048e68de7.tar.gz
chromium_src-0a4a1bb2afa3d3f8b9a9c981e420ff2048e68de7.tar.bz2
Resubmitting change because original caused build breaks:
- clang build requires destructor in complex classes - chromeos build requires newline at end of files 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. BUG=None TEST=None R=ben@chromium.org Review URL: http://codereview.chromium.org/6820007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81128 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/native_theme_painter.cc')
-rw-r--r--views/native_theme_painter.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/views/native_theme_painter.cc b/views/native_theme_painter.cc
new file mode 100644
index 0000000..7806f33
--- /dev/null
+++ b/views/native_theme_painter.cc
@@ -0,0 +1,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