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