1 /*
2  * Copyright © 2012 Red Hat Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors: Benjamin Otte <otte@gnome.org>
18  */
19 
20 #ifndef __GTK_CSS_STYLE_PRIVATE_H__
21 #define __GTK_CSS_STYLE_PRIVATE_H__
22 
23 #include <glib-object.h>
24 #include <gtk/css/gtkcss.h>
25 
26 #include "gtk/gtkbitmaskprivate.h"
27 #include "gtk/gtkcssvalueprivate.h"
28 
29 G_BEGIN_DECLS
30 
31 #define GTK_TYPE_CSS_STYLE           (gtk_css_style_get_type ())
32 #define GTK_CSS_STYLE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_STYLE, GtkCssStyle))
33 #define GTK_CSS_STYLE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_STYLE, GtkCssStyleClass))
34 #define GTK_IS_CSS_STYLE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_STYLE))
35 #define GTK_IS_CSS_STYLE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_STYLE))
36 #define GTK_CSS_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_STYLE, GtkCssStyleClass))
37 
38 typedef enum {
39   GTK_CSS_CORE_VALUES,
40   GTK_CSS_CORE_INITIAL_VALUES,
41   GTK_CSS_BACKGROUND_VALUES,
42   GTK_CSS_BACKGROUND_INITIAL_VALUES,
43   GTK_CSS_BORDER_VALUES,
44   GTK_CSS_BORDER_INITIAL_VALUES,
45   GTK_CSS_ICON_VALUES,
46   GTK_CSS_ICON_INITIAL_VALUES,
47   GTK_CSS_OUTLINE_VALUES,
48   GTK_CSS_OUTLINE_INITIAL_VALUES,
49   GTK_CSS_FONT_VALUES,
50   GTK_CSS_FONT_INITIAL_VALUES,
51   GTK_CSS_FONT_VARIANT_VALUES,
52   GTK_CSS_FONT_VARIANT_INITIAL_VALUES,
53   GTK_CSS_ANIMATION_VALUES,
54   GTK_CSS_ANIMATION_INITIAL_VALUES,
55   GTK_CSS_TRANSITION_VALUES,
56   GTK_CSS_TRANSITION_INITIAL_VALUES,
57   GTK_CSS_SIZE_VALUES,
58   GTK_CSS_SIZE_INITIAL_VALUES,
59   GTK_CSS_OTHER_VALUES,
60   GTK_CSS_OTHER_INITIAL_VALUES,
61 } GtkCssValuesType;
62 
63 typedef struct _GtkCssValues GtkCssValues;
64 typedef struct _GtkCssCoreValues GtkCssCoreValues;
65 typedef struct _GtkCssBackgroundValues GtkCssBackgroundValues;
66 typedef struct _GtkCssBorderValues GtkCssBorderValues;
67 typedef struct _GtkCssIconValues GtkCssIconValues;
68 typedef struct _GtkCssOutlineValues GtkCssOutlineValues;
69 typedef struct _GtkCssFontValues GtkCssFontValues;
70 typedef struct _GtkCssFontVariantValues GtkCssFontVariantValues;
71 typedef struct _GtkCssAnimationValues GtkCssAnimationValues;
72 typedef struct _GtkCssTransitionValues GtkCssTransitionValues;
73 typedef struct _GtkCssSizeValues GtkCssSizeValues;
74 typedef struct _GtkCssOtherValues GtkCssOtherValues;
75 
76 struct _GtkCssValues {
77   int ref_count;
78   GtkCssValuesType type;
79 };
80 
81 struct _GtkCssCoreValues {
82   GtkCssValues base;
83   GtkCssValue *color;
84   GtkCssValue *dpi;
85   GtkCssValue *font_size;
86   GtkCssValue *icon_palette;
87 };
88 
89 struct _GtkCssBackgroundValues {
90   GtkCssValues base;
91   GtkCssValue *background_color;
92   GtkCssValue *box_shadow;
93   GtkCssValue *background_clip;
94   GtkCssValue *background_origin;
95   GtkCssValue *background_size;
96   GtkCssValue *background_position;
97   GtkCssValue *background_repeat;
98   GtkCssValue *background_image;
99   GtkCssValue *background_blend_mode;
100 };
101 
102 struct _GtkCssBorderValues {
103   GtkCssValues base;
104   GtkCssValue *border_top_style;
105   GtkCssValue *border_top_width;
106   GtkCssValue *border_left_style;
107   GtkCssValue *border_left_width;
108   GtkCssValue *border_bottom_style;
109   GtkCssValue *border_bottom_width;
110   GtkCssValue *border_right_style;
111   GtkCssValue *border_right_width;
112   GtkCssValue *border_top_left_radius;
113   GtkCssValue *border_top_right_radius;
114   GtkCssValue *border_bottom_right_radius;
115   GtkCssValue *border_bottom_left_radius;
116   GtkCssValue *border_top_color; // NULL if currentColor
117   GtkCssValue *border_right_color; // NULL if currentColor
118   GtkCssValue *border_bottom_color; // NULL if currentColor
119   GtkCssValue *border_left_color; // NULL if currentColor
120   GtkCssValue *border_image_source;
121   GtkCssValue *border_image_repeat;
122   GtkCssValue *border_image_slice;
123   GtkCssValue *border_image_width;
124 };
125 
126 struct _GtkCssIconValues {
127   GtkCssValues base;
128   GtkCssValue *icon_size;
129   GtkCssValue *icon_shadow;
130   GtkCssValue *icon_style;
131 };
132 
133 
134 struct _GtkCssOutlineValues {
135   GtkCssValues base;
136   GtkCssValue *outline_style;
137   GtkCssValue *outline_width;
138   GtkCssValue *outline_offset;
139   GtkCssValue *outline_color; // NULL if currentColor
140 };
141 
142 struct _GtkCssFontValues {
143   GtkCssValues base;
144   GtkCssValue *font_family;
145   GtkCssValue *font_style;
146   GtkCssValue *font_weight;
147   GtkCssValue *font_stretch;
148   GtkCssValue *letter_spacing;
149   GtkCssValue *text_shadow;
150   GtkCssValue *caret_color; // NULL if currentColor
151   GtkCssValue *secondary_caret_color; // NULL if currentColor
152   GtkCssValue *font_feature_settings;
153   GtkCssValue *font_variation_settings;
154 };
155 
156 struct _GtkCssFontVariantValues {
157   GtkCssValues base;
158   GtkCssValue *text_decoration_line;
159   GtkCssValue *text_decoration_color; // NULL if currentColor
160   GtkCssValue *text_decoration_style;
161   GtkCssValue *font_kerning;
162   GtkCssValue *font_variant_ligatures;
163   GtkCssValue *font_variant_position;
164   GtkCssValue *font_variant_caps;
165   GtkCssValue *font_variant_numeric;
166   GtkCssValue *font_variant_alternates;
167   GtkCssValue *font_variant_east_asian;
168 };
169 
170 struct _GtkCssAnimationValues {
171   GtkCssValues base;
172   GtkCssValue *animation_name;
173   GtkCssValue *animation_duration;
174   GtkCssValue *animation_timing_function;
175   GtkCssValue *animation_iteration_count;
176   GtkCssValue *animation_direction;
177   GtkCssValue *animation_play_state;
178   GtkCssValue *animation_delay;
179   GtkCssValue *animation_fill_mode;
180 };
181 
182 struct _GtkCssTransitionValues {
183   GtkCssValues base;
184   GtkCssValue *transition_property;
185   GtkCssValue *transition_duration;
186   GtkCssValue *transition_timing_function;
187   GtkCssValue *transition_delay;
188 };
189 
190 struct _GtkCssSizeValues {
191   GtkCssValues base;
192   GtkCssValue *margin_top;
193   GtkCssValue *margin_left;
194   GtkCssValue *margin_bottom;
195   GtkCssValue *margin_right;
196   GtkCssValue *padding_top;
197   GtkCssValue *padding_left;
198   GtkCssValue *padding_bottom;
199   GtkCssValue *padding_right;
200   GtkCssValue *border_spacing;
201   GtkCssValue *min_width;
202   GtkCssValue *min_height;
203 };
204 
205 struct _GtkCssOtherValues {
206   GtkCssValues base;
207   GtkCssValue *icon_source;
208   GtkCssValue *icon_transform;
209   GtkCssValue *icon_filter;
210   GtkCssValue *transform;
211   GtkCssValue *transform_origin;
212   GtkCssValue *opacity;
213   GtkCssValue *filter;
214 };
215 
216 /* typedef struct _GtkCssStyle           GtkCssStyle; */
217 typedef struct _GtkCssStyleClass      GtkCssStyleClass;
218 
219 struct _GtkCssStyle
220 {
221   GObject parent;
222 
223   GtkCssCoreValues        *core;
224   GtkCssBackgroundValues  *background;
225   GtkCssBorderValues      *border;
226   GtkCssIconValues        *icon;
227   GtkCssOutlineValues     *outline;
228   GtkCssFontValues        *font;
229   GtkCssFontVariantValues *font_variant;
230   GtkCssAnimationValues   *animation;
231   GtkCssTransitionValues  *transition;
232   GtkCssSizeValues        *size;
233   GtkCssOtherValues       *other;
234 };
235 
236 struct _GtkCssStyleClass
237 {
238   GObjectClass parent_class;
239 
240   /* Get the section the value at the given id was declared at or NULL if unavailable.
241    * Optional: default impl will just return NULL */
242   GtkCssSection *       (* get_section)                         (GtkCssStyle            *style,
243                                                                  guint                   id);
244   /* TRUE if this style will require changes based on timestamp */
245   gboolean              (* is_static)                           (GtkCssStyle            *style);
246 
247   GtkCssStaticStyle *   (* get_static_style)                    (GtkCssStyle            *style);
248 };
249 
250 GType                   gtk_css_style_get_type                  (void) G_GNUC_CONST;
251 
252 GtkCssValue *           gtk_css_style_get_value                 (GtkCssStyle            *style,
253                                                                  guint                   id) G_GNUC_PURE;
254 GtkCssSection *         gtk_css_style_get_section               (GtkCssStyle            *style,
255                                                                  guint                   id) G_GNUC_PURE;
256 gboolean                gtk_css_style_is_static                 (GtkCssStyle            *style) G_GNUC_PURE;
257 GtkCssStaticStyle *     gtk_css_style_get_static_style          (GtkCssStyle            *style);
258 
259 char *                  gtk_css_style_to_string                 (GtkCssStyle            *style);
260 gboolean                gtk_css_style_print                     (GtkCssStyle            *style,
261                                                                  GString                *string,
262                                                                  guint                   indent,
263                                                                  gboolean                skip_initial);
264 
265 char *                  gtk_css_style_compute_font_features     (GtkCssStyle            *style);
266 PangoAttrList *         gtk_css_style_get_pango_attributes      (GtkCssStyle            *style);
267 PangoFontDescription *  gtk_css_style_get_pango_font            (GtkCssStyle            *style);
268 
269 GtkCssValues *gtk_css_values_new   (GtkCssValuesType  type);
270 GtkCssValues *gtk_css_values_ref   (GtkCssValues     *values);
271 void          gtk_css_values_unref (GtkCssValues     *values);
272 GtkCssValues *gtk_css_values_copy  (GtkCssValues     *values);
273 
274 void gtk_css_core_values_compute_changes_and_affects (GtkCssStyle *style1,
275                                                       GtkCssStyle *style2,
276                                                       GtkBitmask    **changes,
277                                                       GtkCssAffects *affects);
278 void gtk_css_background_values_compute_changes_and_affects (GtkCssStyle *style1,
279                                                       GtkCssStyle *style2,
280                                                       GtkBitmask    **changes,
281                                                       GtkCssAffects *affects);
282 void gtk_css_border_values_compute_changes_and_affects (GtkCssStyle *style1,
283                                                       GtkCssStyle *style2,
284                                                       GtkBitmask    **changes,
285                                                       GtkCssAffects *affects);
286 void gtk_css_icon_values_compute_changes_and_affects (GtkCssStyle *style1,
287                                                       GtkCssStyle *style2,
288                                                       GtkBitmask    **changes,
289                                                       GtkCssAffects *affects);
290 void gtk_css_outline_values_compute_changes_and_affects (GtkCssStyle *style1,
291                                                       GtkCssStyle *style2,
292                                                       GtkBitmask    **changes,
293                                                       GtkCssAffects *affects);
294 void gtk_css_font_values_compute_changes_and_affects (GtkCssStyle *style1,
295                                                       GtkCssStyle *style2,
296                                                       GtkBitmask    **changes,
297                                                       GtkCssAffects *affects);
298 void gtk_css_font_variant_values_compute_changes_and_affects (GtkCssStyle *style1,
299                                                       GtkCssStyle *style2,
300                                                       GtkBitmask    **changes,
301                                                       GtkCssAffects *affects);
302 void gtk_css_animation_values_compute_changes_and_affects (GtkCssStyle *style1,
303                                                       GtkCssStyle *style2,
304                                                       GtkBitmask    **changes,
305                                                       GtkCssAffects *affects);
306 void gtk_css_transition_values_compute_changes_and_affects (GtkCssStyle *style1,
307                                                       GtkCssStyle *style2,
308                                                       GtkBitmask    **changes,
309                                                       GtkCssAffects *affects);
310 void gtk_css_size_values_compute_changes_and_affects (GtkCssStyle *style1,
311                                                       GtkCssStyle *style2,
312                                                       GtkBitmask    **changes,
313                                                       GtkCssAffects *affects);
314 void gtk_css_other_values_compute_changes_and_affects (GtkCssStyle *style1,
315                                                       GtkCssStyle *style2,
316                                                       GtkBitmask    **changes,
317                                                       GtkCssAffects *affects);
318 
319 G_END_DECLS
320 
321 #endif /* __GTK_CSS_STYLE_PRIVATE_H__ */
322