OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_BORDER_H_ | 5 #ifndef UI_VIEWS_BORDER_H_ |
6 #define UI_VIEWS_BORDER_H_ | 6 #define UI_VIEWS_BORDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 class Painter; | 22 class Painter; |
23 class View; | 23 class View; |
24 | 24 |
25 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
26 // | 26 // |
27 // Border class. | 27 // Border class. |
28 // | 28 // |
29 // The border class is used to display a border around a view. | 29 // The border class is used to display a border around a view. |
30 // To set a border on a view, just call SetBorder on the view, for example: | 30 // To set a border on a view, just call SetBorder on the view, for example: |
31 // view->SetBorder(Border::CreateSolidBorder(1, SkColorSetRGB(25, 25, 112)); | 31 // view->SetBorder(CreateSolidBorder(1, SkColorSetRGB(25, 25, 112)); |
32 // Once set on a view, the border is owned by the view. | 32 // Once set on a view, the border is owned by the view. |
33 // | 33 // |
34 // IMPORTANT NOTE: not all views support borders at this point. In order to | 34 // IMPORTANT NOTE: not all views support borders at this point. In order to |
35 // support the border, views should make sure to use bounds excluding the | 35 // support the border, views should make sure to use bounds excluding the |
36 // border (by calling View::GetLocalBoundsExcludingBorder) when doing layout and | 36 // border (by calling View::GetLocalBoundsExcludingBorder) when doing layout and |
37 // painting. | 37 // painting. |
38 // | 38 // |
39 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
41 class VIEWS_EXPORT Border { | 41 class VIEWS_EXPORT Border { |
42 public: | 42 public: |
43 Border(); | 43 Border(); |
44 virtual ~Border(); | 44 virtual ~Border(); |
45 | 45 |
46 // Convenience for creating a scoped_ptr with no Border. | |
47 static std::unique_ptr<Border> NullBorder(); | |
48 | |
49 // Creates a border that is a simple line of the specified thickness and | |
50 // color. | |
51 static std::unique_ptr<Border> CreateSolidBorder(int thickness, | |
52 SkColor color); | |
53 | |
54 // Creates a border that is a rounded rectangle of the specified thickness and | |
55 // color. | |
56 static std::unique_ptr<Border> CreateRoundedRectBorder(int thickness, | |
57 int corner_radius, | |
58 SkColor color); | |
59 | |
60 // Creates a border for reserving space. The returned border does not | |
61 // paint anything. | |
62 static std::unique_ptr<Border> CreateEmptyBorder(const gfx::Insets& insets); | |
63 static std::unique_ptr<Border> CreateEmptyBorder(int top, | |
64 int left, | |
65 int bottom, | |
66 int right); | |
67 | |
68 // Creates a border of the specified color, and specified thickness on each | |
69 // side. | |
70 static std::unique_ptr<Border> CreateSolidSidedBorder(int top, | |
71 int left, | |
72 int bottom, | |
73 int right, | |
74 SkColor color); | |
75 | |
76 // Creates a new border that draws |border| and adds additional padding. This | |
77 // is equivalent to changing the insets of |border| without changing how or | |
78 // what it paints. Example: | |
79 // | |
80 // view->SetBorder(Border::CreatePaddedBorder( | |
81 // Border::CreateSolidBorder(1, SK_ColorRED), | |
82 // gfx::Insets(2, 0, 0, 0))); | |
83 // | |
84 // yields a single dip red border and an additional 2dip of unpainted padding | |
85 // above the view content (below the border). | |
86 static std::unique_ptr<Border> CreatePaddedBorder( | |
87 std::unique_ptr<Border> border, | |
88 const gfx::Insets& insets); | |
89 | |
90 // Creates a Border from the specified Painter. | |
91 // |insets| define size of an area allocated for a Border. | |
92 static std::unique_ptr<Border> CreateBorderPainter( | |
93 std::unique_ptr<Painter> painter, | |
94 const gfx::Insets& insets); | |
95 | |
96 // Renders the border for the specified view. | 46 // Renders the border for the specified view. |
97 virtual void Paint(const View& view, gfx::Canvas* canvas) = 0; | 47 virtual void Paint(const View& view, gfx::Canvas* canvas) = 0; |
98 | 48 |
99 // Returns the border insets. | 49 // Returns the border insets. |
100 virtual gfx::Insets GetInsets() const = 0; | 50 virtual gfx::Insets GetInsets() const = 0; |
101 | 51 |
102 // Returns the minimum size this border requires. Note that this may not be | 52 // Returns the minimum size this border requires. Note that this may not be |
103 // the same as the insets. For example, a Border may paint images to draw | 53 // the same as the insets. For example, a Border may paint images to draw |
104 // some graphical border around a view, and this would return the minimum size | 54 // some graphical border around a view, and this would return the minimum size |
105 // such that these images would not be clipped or overlapping -- but the | 55 // such that these images would not be clipped or overlapping -- but the |
106 // insets may be larger or smaller, depending on how the view wanted its | 56 // insets may be larger or smaller, depending on how the view wanted its |
107 // content laid out relative to these images. | 57 // content laid out relative to these images. |
108 virtual gfx::Size GetMinimumSize() const = 0; | 58 virtual gfx::Size GetMinimumSize() const = 0; |
109 | 59 |
110 private: | 60 private: |
111 DISALLOW_COPY_AND_ASSIGN(Border); | 61 DISALLOW_COPY_AND_ASSIGN(Border); |
112 }; | 62 }; |
113 | 63 |
| 64 // Convenience for creating a scoped_ptr with no Border. |
| 65 VIEWS_EXPORT std::unique_ptr<Border> NullBorder(); |
| 66 |
| 67 // Creates a border that is a simple line of the specified thickness and color. |
| 68 VIEWS_EXPORT std::unique_ptr<Border> CreateSolidBorder(int thickness, |
| 69 SkColor color); |
| 70 |
| 71 // Creates a border that is a rounded rectangle of the specified thickness and |
| 72 // color. |
| 73 VIEWS_EXPORT std::unique_ptr<Border> CreateRoundedRectBorder(int thickness, |
| 74 int corner_radius, |
| 75 SkColor color); |
| 76 |
| 77 // Creates a border for reserving space. The returned border does not paint |
| 78 // anything. |
| 79 VIEWS_EXPORT std::unique_ptr<Border> CreateEmptyBorder( |
| 80 const gfx::Insets& insets); |
| 81 VIEWS_EXPORT std::unique_ptr<Border> CreateEmptyBorder(int top, |
| 82 int left, |
| 83 int bottom, |
| 84 int right); |
| 85 |
| 86 // Creates a border of the specified color, and specified thickness on each |
| 87 // side. |
| 88 VIEWS_EXPORT std::unique_ptr<Border> CreateSolidSidedBorder(int top, |
| 89 int left, |
| 90 int bottom, |
| 91 int right, |
| 92 SkColor color); |
| 93 |
| 94 // Creates a new border that draws |border| and adds additional padding. This is |
| 95 // equivalent to changing the insets of |border| without changing how or what it |
| 96 // paints. Example: |
| 97 // |
| 98 // view->SetBorder(CreatePaddedBorder(CreateSolidBorder(1, SK_ColorRED), |
| 99 // gfx::Insets(2, 0, 0, 0))); |
| 100 // |
| 101 // yields a single dip red border and an additional 2dip of unpainted padding |
| 102 // above the view content (below the border). |
| 103 VIEWS_EXPORT std::unique_ptr<Border> CreatePaddedBorder( |
| 104 std::unique_ptr<Border> border, |
| 105 const gfx::Insets& insets); |
| 106 |
| 107 // Creates a Border from the specified Painter. |insets| define size of an area |
| 108 // allocated for a Border. |
| 109 VIEWS_EXPORT std::unique_ptr<Border> CreateBorderPainter( |
| 110 std::unique_ptr<Painter> painter, |
| 111 const gfx::Insets& insets); |
| 112 |
114 } // namespace views | 113 } // namespace views |
115 | 114 |
116 #endif // UI_VIEWS_BORDER_H_ | 115 #endif // UI_VIEWS_BORDER_H_ |
OLD | NEW |