rogerta@chromium.org | 0a4a1bb2 | 2011-04-11 18:36:42 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef VIEWS_NATIVE_THEME_PAINTER_H_ |
| 6 | #define VIEWS_NATIVE_THEME_PAINTER_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "base/compiler_specific.h" |
| 10 | #include "ui/gfx/native_theme.h" |
| 11 | #include "views/painter.h" |
| 12 | |
| 13 | namespace gfx { |
| 14 | class Canvas; |
| 15 | class Size; |
| 16 | } |
| 17 | |
| 18 | namespace ui { |
| 19 | class Animation; |
| 20 | } |
| 21 | |
| 22 | namespace views { |
| 23 | |
| 24 | // A Painter that uses NativeTheme to implement painting and sizing. A |
| 25 | // theme delegate must be given at construction time so that the appropriate |
| 26 | // painting and sizing can be done. |
| 27 | class NativeThemePainter : public Painter { |
| 28 | public: |
| 29 | // A delagate that supports animating transtions between different native |
| 30 | // theme states. If animation is onging, the native theme painter will |
| 31 | // composite the foreground state over the backgroud state using an alpha |
| 32 | // between 0 and 255 based on the current value of the animation. |
| 33 | class Delegate { |
| 34 | public: |
| 35 | virtual ~Delegate() {} |
| 36 | |
| 37 | // Get the part that this native theme painter should draw. |
| 38 | virtual gfx::NativeTheme::Part GetThemePart() const = 0; |
| 39 | |
| 40 | // Get the state of the part, along with any extra data needed for painting. |
| 41 | virtual gfx::NativeTheme::State GetThemeState( |
| 42 | gfx::NativeTheme::ExtraParams* params) const = 0; |
| 43 | |
| 44 | // If the native theme painter is animated, return the Animation object |
| 45 | // that is controlling it. If no animation is ongoing, NULL may be |
| 46 | // returned. |
| 47 | virtual ui::Animation* GetThemeAnimation() const = 0; |
| 48 | |
| 49 | // If animation is onging, this returns the background native theme state. |
| 50 | virtual gfx::NativeTheme::State GetBackgroundThemeState( |
| 51 | gfx::NativeTheme::ExtraParams* params) const = 0; |
| 52 | |
| 53 | // If animation is onging, this returns the foreground native theme state. |
| 54 | // This state will be composited over the background using an alpha value |
| 55 | // based on the current value of the animation. |
| 56 | virtual gfx::NativeTheme::State GetForegroundThemeState( |
| 57 | gfx::NativeTheme::ExtraParams* params) const = 0; |
| 58 | }; |
| 59 | |
| 60 | explicit NativeThemePainter(Delegate* delegate); |
| 61 | |
| 62 | virtual ~NativeThemePainter() {} |
| 63 | |
| 64 | // Returns the preferred size of the native part being painted. |
| 65 | gfx::Size GetPreferredSize(); |
| 66 | |
| 67 | private: |
| 68 | // The delegate the controls the appearance of this painter. |
| 69 | Delegate* delegate_; |
| 70 | |
| 71 | // Overridden from Painter: |
| 72 | virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(NativeThemePainter); |
| 75 | }; |
| 76 | |
| 77 | } // namespace views |
| 78 | |
| 79 | #endif // VIEWS_NATIVE_THEME_PAINTER_H_ |