- add sources.
[platform/framework/web/crosswalk.git] / src / ui / views / background.h
1 // Copyright (c) 2012 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 UI_VIEWS_BACKGROUND_H_
6 #define UI_VIEWS_BACKGROUND_H_
7
8 #include "build/build_config.h"
9
10 #if defined(OS_WIN)
11 #include <windows.h>
12 #endif  // defined(OS_WIN)
13
14 #include "base/basictypes.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/views/views_export.h"
17
18 namespace gfx {
19 class Canvas;
20 }
21
22 namespace views {
23
24 class Painter;
25 class View;
26
27 /////////////////////////////////////////////////////////////////////////////
28 //
29 // Background class
30 //
31 // A background implements a way for views to paint a background. The
32 // background can be either solid or based on a gradient. Of course,
33 // Background can be subclassed to implement various effects.
34 //
35 // Any View can have a background. See View::SetBackground() and
36 // View::OnPaintBackground()
37 //
38 /////////////////////////////////////////////////////////////////////////////
39 class VIEWS_EXPORT Background {
40  public:
41   Background();
42   virtual ~Background();
43
44   // Creates a background that fills the canvas in the specified color.
45   static Background* CreateSolidBackground(SkColor color);
46
47   // Creates a background that fills the canvas in the specified color.
48   static Background* CreateSolidBackground(int r, int g, int b) {
49     return CreateSolidBackground(SkColorSetRGB(r, g, b));
50   }
51
52   // Creates a background that fills the canvas in the specified color.
53   static Background* CreateSolidBackground(int r, int g, int b, int a) {
54     return CreateSolidBackground(SkColorSetARGB(a, r, g, b));
55   }
56
57   // Creates a background that contains a vertical gradient that varies
58   // from |color1| to |color2|
59   static Background* CreateVerticalGradientBackground(SkColor color1,
60                                                       SkColor color2);
61
62   // Creates a background that contains a vertical gradient. The gradient can
63   // have multiple |colors|. The |pos| array contains the relative positions of
64   // each corresponding color. |colors| and |pos| must be the same size. The
65   // first element in |pos| must be 0.0 and the last element must be 1.0.
66   // |count| contains the number of elements in |colors| and |pos|.
67   static Background* CreateVerticalMultiColorGradientBackground(SkColor* colors,
68                                                                 SkScalar* pos,
69                                                                 size_t count);
70
71   // Creates Chrome's standard panel background
72   static Background* CreateStandardPanelBackground();
73
74   // Creates a Background from the specified Painter. If owns_painter is
75   // true, the Painter is deleted when the Border is deleted.
76   static Background* CreateBackgroundPainter(bool owns_painter,
77                                              Painter* painter);
78
79   // Render the background for the provided view
80   virtual void Paint(gfx::Canvas* canvas, View* view) const = 0;
81
82   // Set a solid, opaque color to be used when drawing backgrounds of native
83   // controls.  Unfortunately alpha=0 is not an option.
84   void SetNativeControlColor(SkColor color);
85
86   // Returns the "background color".  This is equivalent to the color set in
87   // SetNativeControlColor().  For solid backgrounds, this is the color; for
88   // gradient backgrounds, it's the midpoint of the gradient; for painter
89   // backgrounds, this is not useful (returns a default color).
90   SkColor get_color() const { return color_; }
91
92 #if defined(OS_WIN)
93   // TODO(port): Make GetNativeControlBrush portable (currently uses HBRUSH).
94
95   // Get the brush that was specified by SetNativeControlColor
96   HBRUSH GetNativeControlBrush() const;
97 #endif  // defined(OS_WIN)
98
99  private:
100   SkColor color_;
101 #if defined(OS_WIN)
102   // TODO(port): Create portable replacement for HBRUSH.
103   mutable HBRUSH native_control_brush_;
104 #endif  // defined(OS_WIN)
105
106   DISALLOW_COPY_AND_ASSIGN(Background);
107 };
108
109 }  // namespace views
110
111 #endif  // UI_VIEWS_BACKGROUND_H_