OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 GFX_NATIVE_THEME_LINUX_H_ | 5 #ifndef GFX_NATIVE_THEME_LINUX_H_ |
6 #define GFX_NATIVE_THEME_LINUX_H_ | 6 #define GFX_NATIVE_THEME_LINUX_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 public: | 21 public: |
22 // The part to be painted / sized. | 22 // The part to be painted / sized. |
23 enum Part { | 23 enum Part { |
24 kScrollbarDownArrow, | 24 kScrollbarDownArrow, |
25 kScrollbarLeftArrow, | 25 kScrollbarLeftArrow, |
26 kScrollbarRightArrow, | 26 kScrollbarRightArrow, |
27 kScrollbarUpArrow, | 27 kScrollbarUpArrow, |
28 kScrollbarHorizontalThumb, | 28 kScrollbarHorizontalThumb, |
29 kScrollbarVerticalThumb, | 29 kScrollbarVerticalThumb, |
30 kScrollbarHorizontalTrack, | 30 kScrollbarHorizontalTrack, |
31 kScrollbarVerticalTrack | 31 kScrollbarVerticalTrack, |
| 32 kCheckbox, |
| 33 kRadio, |
| 34 kPushButton, |
| 35 kTextField, |
| 36 kMenuList, |
| 37 kSliderTrack, |
| 38 kSliderThumb, |
| 39 kInnerSpinButton, |
| 40 kProgressBar, |
32 }; | 41 }; |
33 | 42 |
34 // The state of the part. | 43 // The state of the part. |
35 enum State { | 44 enum State { |
36 kDisabled, | 45 kDisabled, |
37 kHover, | 46 kHovered, |
38 kNormal, | 47 kNormal, |
39 kPressed, | 48 kPressed, |
40 }; | 49 }; |
41 | 50 |
42 // Extra data needed to draw scrollbar track correctly. | 51 // Extra data needed to draw scrollbar track correctly. |
43 struct ScrollbarTrackExtraParams { | 52 struct ScrollbarTrackExtraParams { |
44 int track_x; | 53 int track_x; |
45 int track_y; | 54 int track_y; |
46 int track_width; | 55 int track_width; |
47 int track_height; | 56 int track_height; |
48 }; | 57 }; |
49 | 58 |
| 59 struct ButtonExtraParams { |
| 60 bool checked; |
| 61 bool indeterminate; // Whether the button state is indeterminate. |
| 62 bool is_default; // Whether the button is default button. |
| 63 SkColor background_color; |
| 64 }; |
| 65 |
| 66 struct TextFieldExtraParams { |
| 67 bool is_text_area; |
| 68 bool is_listbox; |
| 69 SkColor background_color; |
| 70 }; |
| 71 |
| 72 struct MenuListExtraParams { |
| 73 int arrow_x; |
| 74 int arrow_y; |
| 75 SkColor background_color; |
| 76 }; |
| 77 |
| 78 struct SliderExtraParams { |
| 79 bool vertical; |
| 80 bool in_drag; |
| 81 }; |
| 82 |
| 83 struct InnerSpinButtonExtraParams { |
| 84 bool spin_up; |
| 85 bool read_only; |
| 86 }; |
| 87 |
| 88 struct ProgressBarExtraParams { |
| 89 bool determinate; |
| 90 int value_rect_x; |
| 91 int value_rect_y; |
| 92 int value_rect_width; |
| 93 int value_rect_height; |
| 94 }; |
| 95 |
50 union ExtraParams { | 96 union ExtraParams { |
51 ScrollbarTrackExtraParams scrollbar_track; | 97 ScrollbarTrackExtraParams scrollbar_track; |
| 98 ButtonExtraParams button; |
| 99 MenuListExtraParams menu_list; |
| 100 SliderExtraParams slider; |
| 101 TextFieldExtraParams text_field; |
| 102 InnerSpinButtonExtraParams inner_spin; |
| 103 ProgressBarExtraParams progress_bar; |
52 }; | 104 }; |
53 | 105 |
54 // Gets our singleton instance. | 106 // Gets our singleton instance. |
55 static NativeThemeLinux* instance(); | 107 static NativeThemeLinux* instance(); |
56 | 108 |
57 // Return the size of the part. | 109 // Return the size of the part. |
58 virtual gfx::Size GetSize(Part part) const; | 110 virtual gfx::Size GetPartSize(Part part) const; |
59 // Paint the part to the canvas. | 111 // Paint the part to the canvas. |
60 virtual void Paint(skia::PlatformCanvas* canvas, | 112 virtual void Paint(skia::PlatformCanvas* canvas, |
61 Part part, | 113 Part part, |
62 State state, | 114 State state, |
63 const gfx::Rect& rect, | 115 const gfx::Rect& rect, |
64 const ExtraParams& extra); | 116 const ExtraParams& extra); |
65 // Supports theme specific colors. | 117 // Supports theme specific colors. |
66 void SetScrollbarColors(unsigned inactive_color, | 118 void SetScrollbarColors(unsigned inactive_color, |
67 unsigned active_color, | 119 unsigned active_color, |
68 unsigned track_color) const; | 120 unsigned track_color) const; |
69 | 121 |
70 protected: | 122 protected: |
71 NativeThemeLinux(); | 123 NativeThemeLinux(); |
72 virtual ~NativeThemeLinux(); | 124 virtual ~NativeThemeLinux(); |
73 | 125 |
74 // Draw the arrow. | 126 // Draw the arrow. Used by scrollbar and inner spin button. |
75 virtual void PaintArrowButton( | 127 virtual void PaintArrowButton( |
76 skia::PlatformCanvas* gc, | 128 skia::PlatformCanvas* gc, |
77 const gfx::Rect& rect, | 129 const gfx::Rect& rect, |
78 Part direction, | 130 Part direction, |
79 State state); | 131 State state); |
80 // Paint the track. Done before the thumb so that it can contain alpha. | 132 // Paint the scrollbar track. Done before the thumb so that it can contain |
81 virtual void PaintTrack(skia::PlatformCanvas* canvas, | 133 // alpha. |
82 Part part, | 134 virtual void PaintScrollbarTrack(skia::PlatformCanvas* canvas, |
83 State state, | 135 Part part, |
84 const ScrollbarTrackExtraParams& extra_params, | 136 State state, |
85 const gfx::Rect& rect); | 137 const ScrollbarTrackExtraParams& extra_params, |
86 // Draw the thumb over the track. | 138 const gfx::Rect& rect); |
87 virtual void PaintThumb(skia::PlatformCanvas* canvas, | 139 // Draw the scrollbar thumb over the track. |
88 Part part, | 140 virtual void PaintScrollbarThumb(skia::PlatformCanvas* canvas, |
89 State state, | 141 Part part, |
90 const gfx::Rect& rect); | 142 State state, |
| 143 const gfx::Rect& rect); |
| 144 // Draw the checkbox. |
| 145 virtual void PaintCheckbox(skia::PlatformCanvas* canvas, |
| 146 State state, |
| 147 const gfx::Rect& rect, |
| 148 const ButtonExtraParams& button); |
| 149 // Draw the radio. |
| 150 virtual void PaintRadio(skia::PlatformCanvas* canvas, |
| 151 State state, |
| 152 const gfx::Rect& rect, |
| 153 const ButtonExtraParams& button); |
| 154 // Draw the push button. |
| 155 virtual void PaintButton(skia::PlatformCanvas* canvas, |
| 156 State state, |
| 157 const gfx::Rect& rect, |
| 158 const ButtonExtraParams& button); |
| 159 // Draw the text field. |
| 160 virtual void PaintTextField(skia::PlatformCanvas* canvas, |
| 161 State state, |
| 162 const gfx::Rect& rect, |
| 163 const TextFieldExtraParams& text); |
| 164 // Draw the menu list. |
| 165 virtual void PaintMenuList(skia::PlatformCanvas* canvas, |
| 166 State state, |
| 167 const gfx::Rect& rect, |
| 168 const MenuListExtraParams& menu_list); |
| 169 // Draw the slider track. |
| 170 virtual void PaintSliderTrack(skia::PlatformCanvas* canvas, |
| 171 State state, |
| 172 const gfx::Rect& rect, |
| 173 const SliderExtraParams& slider); |
| 174 // Draw the slider thumb. |
| 175 virtual void PaintSliderThumb(skia::PlatformCanvas* canvas, |
| 176 State state, |
| 177 const gfx::Rect& rect, |
| 178 const SliderExtraParams& slider); |
| 179 // Draw the inner spin button. |
| 180 virtual void PaintInnerSpinButton(skia::PlatformCanvas* canvas, |
| 181 State state, |
| 182 const gfx::Rect& rect, |
| 183 const InnerSpinButtonExtraParams& spin_button); |
| 184 // Draw the progress bar. |
| 185 virtual void PaintProgressBar(skia::PlatformCanvas* canvas, |
| 186 State state, |
| 187 const gfx::Rect& rect, |
| 188 const ProgressBarExtraParams& progress_bar); |
| 189 |
| 190 protected: |
| 191 bool IntersectsClipRectInt(skia::PlatformCanvas* canvas, |
| 192 int x, int y, int w, int h); |
| 193 |
| 194 void DrawBitmapInt(skia::PlatformCanvas* canvas, const SkBitmap& bitmap, |
| 195 int src_x, int src_y, int src_w, int src_h, |
| 196 int dest_x, int dest_y, int dest_w, int dest_h); |
| 197 |
| 198 void DrawTiledImage(SkCanvas* canvas, |
| 199 const SkBitmap& bitmap, |
| 200 int src_x, int src_y, |
| 201 double tile_scale_x, double tile_scale_y, |
| 202 int dest_x, int dest_y, int w, int h) const; |
| 203 |
| 204 SkColor SaturateAndBrighten(SkScalar* hsv, |
| 205 SkScalar saturate_amount, |
| 206 SkScalar brighten_amount) const; |
91 | 207 |
92 private: | 208 private: |
93 void DrawVertLine(SkCanvas* canvas, | 209 void DrawVertLine(SkCanvas* canvas, |
94 int x, | 210 int x, |
95 int y1, | 211 int y1, |
96 int y2, | 212 int y2, |
97 const SkPaint& paint) const; | 213 const SkPaint& paint) const; |
98 void DrawHorizLine(SkCanvas* canvas, | 214 void DrawHorizLine(SkCanvas* canvas, |
99 int x1, | 215 int x1, |
100 int x2, | 216 int x2, |
101 int y, | 217 int y, |
102 const SkPaint& paint) const; | 218 const SkPaint& paint) const; |
103 void DrawBox(SkCanvas* canvas, | 219 void DrawBox(SkCanvas* canvas, |
104 const gfx::Rect& rect, | 220 const gfx::Rect& rect, |
105 const SkPaint& paint) const; | 221 const SkPaint& paint) const; |
106 SkScalar Clamp(SkScalar value, | 222 SkScalar Clamp(SkScalar value, |
107 SkScalar min, | 223 SkScalar min, |
108 SkScalar max) const; | 224 SkScalar max) const; |
109 SkColor SaturateAndBrighten(SkScalar* hsv, | |
110 SkScalar saturate_amount, | |
111 SkScalar brighten_amount) const; | |
112 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; | 225 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; |
113 | 226 |
114 static unsigned int scrollbar_width_; | 227 static unsigned int scrollbar_width_; |
115 static unsigned int button_length_; | 228 static unsigned int button_length_; |
116 static unsigned int thumb_inactive_color_; | 229 static unsigned int thumb_inactive_color_; |
117 static unsigned int thumb_active_color_; | 230 static unsigned int thumb_active_color_; |
118 static unsigned int track_color_; | 231 static unsigned int track_color_; |
119 | 232 |
120 DISALLOW_COPY_AND_ASSIGN(NativeThemeLinux); | 233 DISALLOW_COPY_AND_ASSIGN(NativeThemeLinux); |
121 }; | 234 }; |
122 | 235 |
123 } // namespace gfx | 236 } // namespace gfx |
124 | 237 |
125 #endif // GFX_NATIVE_THEME_LINUX_H_ | 238 #endif // GFX_NATIVE_THEME_LINUX_H_ |
OLD | NEW |