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_NATIVE_THEME_NATIVE_THEME_BASE_H_ | 5 #ifndef UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ |
6 #define UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ | 6 #define UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "skia/ext/platform_canvas.h" | 13 #include "cc/paint/paint_flags.h" |
14 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 class Rect; | 17 class Rect; |
18 class Size; | 18 class Size; |
19 } | 19 } |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 // Theme support for non-Windows toolkits. | 23 // Theme support for non-Windows toolkits. |
24 class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { | 24 class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { |
25 public: | 25 public: |
26 // NativeTheme implementation: | 26 // NativeTheme implementation: |
27 gfx::Size GetPartSize(Part part, | 27 gfx::Size GetPartSize(Part part, |
28 State state, | 28 State state, |
29 const ExtraParams& extra) const override; | 29 const ExtraParams& extra) const override; |
30 void Paint(SkCanvas* canvas, | 30 void Paint(cc::PaintCanvas* canvas, |
31 Part part, | 31 Part part, |
32 State state, | 32 State state, |
33 const gfx::Rect& rect, | 33 const gfx::Rect& rect, |
34 const ExtraParams& extra) const override; | 34 const ExtraParams& extra) const override; |
35 | 35 |
36 protected: | 36 protected: |
37 NativeThemeBase(); | 37 NativeThemeBase(); |
38 ~NativeThemeBase() override; | 38 ~NativeThemeBase() override; |
39 | 39 |
40 // Draw the arrow. Used by scrollbar and inner spin button. | 40 // Draw the arrow. Used by scrollbar and inner spin button. |
41 virtual void PaintArrowButton( | 41 virtual void PaintArrowButton(cc::PaintCanvas* gc, |
42 SkCanvas* gc, | 42 const gfx::Rect& rect, |
43 const gfx::Rect& rect, | 43 Part direction, |
44 Part direction, | 44 State state) const; |
45 State state) const; | |
46 // Paint the scrollbar track. Done before the thumb so that it can contain | 45 // Paint the scrollbar track. Done before the thumb so that it can contain |
47 // alpha. | 46 // alpha. |
48 virtual void PaintScrollbarTrack( | 47 virtual void PaintScrollbarTrack( |
49 SkCanvas* canvas, | 48 cc::PaintCanvas* canvas, |
50 Part part, | 49 Part part, |
51 State state, | 50 State state, |
52 const ScrollbarTrackExtraParams& extra_params, | 51 const ScrollbarTrackExtraParams& extra_params, |
53 const gfx::Rect& rect) const; | 52 const gfx::Rect& rect) const; |
54 // Draw the scrollbar thumb over the track. | 53 // Draw the scrollbar thumb over the track. |
55 virtual void PaintScrollbarThumb( | 54 virtual void PaintScrollbarThumb( |
56 SkCanvas* canvas, | 55 cc::PaintCanvas* canvas, |
57 Part part, | 56 Part part, |
58 State state, | 57 State state, |
59 const gfx::Rect& rect, | 58 const gfx::Rect& rect, |
60 NativeTheme::ScrollbarOverlayColorTheme theme) const; | 59 NativeTheme::ScrollbarOverlayColorTheme theme) const; |
61 | 60 |
62 virtual void PaintScrollbarCorner(SkCanvas* canvas, | 61 virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas, |
63 State state, | 62 State state, |
64 const gfx::Rect& rect) const; | 63 const gfx::Rect& rect) const; |
65 | 64 |
66 virtual void PaintCheckbox( | 65 virtual void PaintCheckbox(cc::PaintCanvas* canvas, |
67 SkCanvas* canvas, | 66 State state, |
68 State state, | 67 const gfx::Rect& rect, |
69 const gfx::Rect& rect, | 68 const ButtonExtraParams& button) const; |
70 const ButtonExtraParams& button) const; | |
71 | 69 |
72 virtual void PaintRadio( | 70 virtual void PaintRadio(cc::PaintCanvas* canvas, |
73 SkCanvas* canvas, | 71 State state, |
74 State state, | 72 const gfx::Rect& rect, |
75 const gfx::Rect& rect, | 73 const ButtonExtraParams& button) const; |
76 const ButtonExtraParams& button) const; | |
77 | 74 |
78 virtual void PaintButton( | 75 virtual void PaintButton(cc::PaintCanvas* canvas, |
79 SkCanvas* canvas, | 76 State state, |
80 State state, | 77 const gfx::Rect& rect, |
81 const gfx::Rect& rect, | 78 const ButtonExtraParams& button) const; |
82 const ButtonExtraParams& button) const; | |
83 | 79 |
84 virtual void PaintTextField( | 80 virtual void PaintTextField(cc::PaintCanvas* canvas, |
85 SkCanvas* canvas, | 81 State state, |
86 State state, | 82 const gfx::Rect& rect, |
87 const gfx::Rect& rect, | 83 const TextFieldExtraParams& text) const; |
88 const TextFieldExtraParams& text) const; | |
89 | 84 |
90 virtual void PaintMenuList( | 85 virtual void PaintMenuList(cc::PaintCanvas* canvas, |
91 SkCanvas* canvas, | 86 State state, |
92 State state, | 87 const gfx::Rect& rect, |
93 const gfx::Rect& rect, | 88 const MenuListExtraParams& menu_list) const; |
94 const MenuListExtraParams& menu_list) const; | |
95 | 89 |
96 virtual void PaintMenuPopupBackground( | 90 virtual void PaintMenuPopupBackground( |
97 SkCanvas* canvas, | 91 cc::PaintCanvas* canvas, |
98 const gfx::Size& size, | 92 const gfx::Size& size, |
99 const MenuBackgroundExtraParams& menu_background) const; | 93 const MenuBackgroundExtraParams& menu_background) const; |
100 | 94 |
101 virtual void PaintMenuItemBackground( | 95 virtual void PaintMenuItemBackground( |
102 SkCanvas* canvas, | 96 cc::PaintCanvas* canvas, |
103 State state, | 97 State state, |
104 const gfx::Rect& rect, | 98 const gfx::Rect& rect, |
105 const MenuItemExtraParams& menu_item) const; | 99 const MenuItemExtraParams& menu_item) const; |
106 | 100 |
107 virtual void PaintSliderTrack( | 101 virtual void PaintSliderTrack(cc::PaintCanvas* canvas, |
108 SkCanvas* canvas, | 102 State state, |
109 State state, | 103 const gfx::Rect& rect, |
110 const gfx::Rect& rect, | 104 const SliderExtraParams& slider) const; |
111 const SliderExtraParams& slider) const; | |
112 | 105 |
113 virtual void PaintSliderThumb( | 106 virtual void PaintSliderThumb(cc::PaintCanvas* canvas, |
114 SkCanvas* canvas, | 107 State state, |
115 State state, | 108 const gfx::Rect& rect, |
116 const gfx::Rect& rect, | 109 const SliderExtraParams& slider) const; |
117 const SliderExtraParams& slider) const; | |
118 | 110 |
119 virtual void PaintInnerSpinButton( | 111 virtual void PaintInnerSpinButton( |
120 SkCanvas* canvas, | 112 cc::PaintCanvas* canvas, |
121 State state, | 113 State state, |
122 const gfx::Rect& rect, | 114 const gfx::Rect& rect, |
123 const InnerSpinButtonExtraParams& spin_button) const; | 115 const InnerSpinButtonExtraParams& spin_button) const; |
124 | 116 |
125 virtual void PaintProgressBar( | 117 virtual void PaintProgressBar( |
126 SkCanvas* canvas, | 118 cc::PaintCanvas* canvas, |
127 State state, | 119 State state, |
128 const gfx::Rect& rect, | 120 const gfx::Rect& rect, |
129 const ProgressBarExtraParams& progress_bar) const; | 121 const ProgressBarExtraParams& progress_bar) const; |
130 | 122 |
131 virtual void PaintFrameTopArea( | 123 virtual void PaintFrameTopArea( |
132 SkCanvas* canvas, | 124 SkCanvas* canvas, |
133 State state, | 125 State state, |
134 const gfx::Rect& rect, | 126 const gfx::Rect& rect, |
135 const FrameTopAreaExtraParams& frame_top_area) const; | 127 const FrameTopAreaExtraParams& frame_top_area) const; |
136 | 128 |
137 // Shrinks checkbox/radio button rect, if necessary, to make room for padding | 129 // Shrinks checkbox/radio button rect, if necessary, to make room for padding |
138 // and drop shadow. | 130 // and drop shadow. |
139 // TODO(mohsen): This is needed because checkboxes/radio buttons on Android | 131 // TODO(mohsen): This is needed because checkboxes/radio buttons on Android |
140 // have different padding from those on desktop Chrome. Get rid of this when | 132 // have different padding from those on desktop Chrome. Get rid of this when |
141 // crbug.com/530746 is resolved. | 133 // crbug.com/530746 is resolved. |
142 virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const; | 134 virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const; |
143 | 135 |
144 void set_scrollbar_button_length(int length) { | 136 void set_scrollbar_button_length(int length) { |
145 scrollbar_button_length_ = length; | 137 scrollbar_button_length_ = length; |
146 } | 138 } |
147 int scrollbar_button_length() const { return scrollbar_button_length_; } | 139 int scrollbar_button_length() const { return scrollbar_button_length_; } |
148 | 140 |
149 SkColor SaturateAndBrighten(SkScalar* hsv, | 141 SkColor SaturateAndBrighten(SkScalar* hsv, |
150 SkScalar saturate_amount, | 142 SkScalar saturate_amount, |
151 SkScalar brighten_amount) const; | 143 SkScalar brighten_amount) const; |
152 | 144 |
153 // Paints the arrow used on the scrollbar and spinner. | 145 // Paints the arrow used on the scrollbar and spinner. |
154 void PaintArrow(SkCanvas* canvas, | 146 void PaintArrow(cc::PaintCanvas* canvas, |
155 const gfx::Rect& rect, | 147 const gfx::Rect& rect, |
156 Part direction, | 148 Part direction, |
157 SkColor color) const; | 149 SkColor color) const; |
158 | 150 |
159 // Returns the color used to draw the arrow. | 151 // Returns the color used to draw the arrow. |
160 SkColor GetArrowColor(State state) const; | 152 SkColor GetArrowColor(State state) const; |
161 | 153 |
162 int scrollbar_width_; | 154 int scrollbar_width_; |
163 | 155 |
164 private: | 156 private: |
165 friend class NativeThemeAuraTest; | 157 friend class NativeThemeAuraTest; |
166 | 158 |
167 SkPath PathForArrow(const gfx::Rect& rect, Part direction) const; | 159 SkPath PathForArrow(const gfx::Rect& rect, Part direction) const; |
168 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const; | 160 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const; |
169 | 161 |
170 void DrawVertLine(SkCanvas* canvas, | 162 void DrawVertLine(cc::PaintCanvas* canvas, |
171 int x, | 163 int x, |
172 int y1, | 164 int y1, |
173 int y2, | 165 int y2, |
174 const SkPaint& paint) const; | 166 const cc::PaintFlags& paint) const; |
175 void DrawHorizLine(SkCanvas* canvas, | 167 void DrawHorizLine(cc::PaintCanvas* canvas, |
176 int x1, | 168 int x1, |
177 int x2, | 169 int x2, |
178 int y, | 170 int y, |
179 const SkPaint& paint) const; | 171 const cc::PaintFlags& paint) const; |
180 void DrawBox(SkCanvas* canvas, | 172 void DrawBox(cc::PaintCanvas* canvas, |
181 const gfx::Rect& rect, | 173 const gfx::Rect& rect, |
182 const SkPaint& paint) const; | 174 const cc::PaintFlags& paint) const; |
183 SkScalar Clamp(SkScalar value, | 175 SkScalar Clamp(SkScalar value, |
184 SkScalar min, | 176 SkScalar min, |
185 SkScalar max) const; | 177 SkScalar max) const; |
186 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; | 178 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; |
187 | 179 |
188 // Paint the common parts of the checkboxes and radio buttons. | 180 // Paint the common parts of the checkboxes and radio buttons. |
189 // borderRadius specifies how rounded the corners should be. | 181 // borderRadius specifies how rounded the corners should be. |
190 SkRect PaintCheckboxRadioCommon( | 182 SkRect PaintCheckboxRadioCommon(cc::PaintCanvas* canvas, |
191 SkCanvas* canvas, | 183 State state, |
192 State state, | 184 const gfx::Rect& rect, |
193 const gfx::Rect& rect, | 185 const SkScalar borderRadius) const; |
194 const SkScalar borderRadius) const; | |
195 | 186 |
196 // The length of the arrow buttons, 0 means no buttons are drawn. | 187 // The length of the arrow buttons, 0 means no buttons are drawn. |
197 int scrollbar_button_length_; | 188 int scrollbar_button_length_; |
198 | 189 |
199 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase); | 190 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase); |
200 }; | 191 }; |
201 | 192 |
202 } // namespace ui | 193 } // namespace ui |
203 | 194 |
204 #endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ | 195 #endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ |
OLD | NEW |