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.
5 #ifndef UI_VIEWS_BACKGROUND_H_
6 #define UI_VIEWS_BACKGROUND_H_
8 #include "build/build_config.h"
12 #endif // defined(OS_WIN)
14 #include "base/basictypes.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/views/views_export.h"
27 /////////////////////////////////////////////////////////////////////////////
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.
35 // Any View can have a background. See View::SetBackground() and
36 // View::OnPaintBackground()
38 /////////////////////////////////////////////////////////////////////////////
39 class VIEWS_EXPORT Background
{
42 virtual ~Background();
44 // Creates a background that fills the canvas in the specified color.
45 static Background
* CreateSolidBackground(SkColor color
);
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
));
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
));
57 // Creates a background that contains a vertical gradient that varies
58 // from |color1| to |color2|
59 static Background
* CreateVerticalGradientBackground(SkColor color1
,
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
,
71 // Creates Chrome's standard panel background
72 static Background
* CreateStandardPanelBackground();
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
,
79 // Render the background for the provided view
80 virtual void Paint(gfx::Canvas
* canvas
, View
* view
) const = 0;
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
);
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_
; }
93 // TODO(port): Make GetNativeControlBrush portable (currently uses HBRUSH).
95 // Get the brush that was specified by SetNativeControlColor
96 HBRUSH
GetNativeControlBrush() const;
97 #endif // defined(OS_WIN)
102 // TODO(port): Create portable replacement for HBRUSH.
103 mutable HBRUSH native_control_brush_
;
104 #endif // defined(OS_WIN)
106 DISALLOW_COPY_AND_ASSIGN(Background
);
111 #endif // UI_VIEWS_BACKGROUND_H_