1 /*
2  * Copyright © 2011 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_IMAGE_PRIVATE_H__
21 #define __GTK_CSS_IMAGE_PRIVATE_H__
22 
23 #include <cairo.h>
24 #include <glib-object.h>
25 
26 #include <gtk/css/gtkcss.h>
27 #include "gtk/css/gtkcsstokenizerprivate.h"
28 #include "gtk/css/gtkcssparserprivate.h"
29 #include "gtk/gtkcsstypesprivate.h"
30 #include "gtk/gtksnapshot.h"
31 #include "gtk/gtkstyleprovider.h"
32 
33 G_BEGIN_DECLS
34 
35 #define GTK_TYPE_CSS_IMAGE           (_gtk_css_image_get_type ())
36 #define GTK_CSS_IMAGE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_IMAGE, GtkCssImage))
37 #define GTK_CSS_IMAGE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_IMAGE, GtkCssImageClass))
38 #define GTK_IS_CSS_IMAGE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_IMAGE))
39 #define GTK_IS_CSS_IMAGE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_IMAGE))
40 #define GTK_CSS_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_IMAGE, GtkCssImageClass))
41 
42 typedef struct _GtkCssImage           GtkCssImage;
43 typedef struct _GtkCssImageClass      GtkCssImageClass;
44 
45 struct _GtkCssImage
46 {
47   GObject parent;
48 };
49 
50 struct _GtkCssImageClass
51 {
52   GObjectClass parent_class;
53 
54   /* width of image or 0 if it has no width (optional) */
55   int          (* get_width)                       (GtkCssImage                *image);
56   /* height of image or 0 if it has no height (optional) */
57   int          (* get_height)                      (GtkCssImage                *image);
58   /* aspect ratio (width / height) of image or 0 if it has no aspect ratio (optional) */
59   double       (* get_aspect_ratio)                (GtkCssImage                *image);
60 
61   /* create "computed value" in CSS terms, returns a new reference */
62   GtkCssImage *(* compute)                         (GtkCssImage                *image,
63                                                     guint                       property_id,
64                                                     GtkStyleProvider           *provider,
65                                                     GtkCssStyle                *style,
66                                                     GtkCssStyle                *parent_style);
67   /* compare two images for equality */
68   gboolean     (* equal)                           (GtkCssImage                *image1,
69                                                     GtkCssImage                *image2);
70   /* transition between start and end image (end may be NULL), returns new reference (optional) */
71   GtkCssImage *(* transition)                      (GtkCssImage                *start,
72                                                     GtkCssImage                *end,
73                                                     guint                       property_id,
74                                                     double                      progress);
75 
76   /* draw to 0,0 with the given width and height */
77   void         (* snapshot)                        (GtkCssImage                *image,
78                                                     GtkSnapshot                *snapshot,
79                                                     double                      width,
80                                                     double                      height);
81   /* is this image to be considered invalid (see https://drafts.csswg.org/css-images-4/#invalid-image for details) */
82   gboolean     (* is_invalid)                      (GtkCssImage                *image);
83   /* does this image change based on timestamp? (optional) */
84   gboolean     (* is_dynamic)                      (GtkCssImage                *image);
85   /* get image for given timestamp or @image when not dynamic (optional) */
86   GtkCssImage *(* get_dynamic_image)               (GtkCssImage                *image,
87                                                     gint64                      monotonic_time);
88   /* parse CSS, return TRUE on success */
89   gboolean     (* parse)                           (GtkCssImage                *image,
90                                                     GtkCssParser               *parser);
91   /* print to CSS */
92   void         (* print)                           (GtkCssImage                *image,
93                                                     GString                    *string);
94   gboolean     (* is_computed)                     (GtkCssImage                *image);
95 };
96 
97 GType          _gtk_css_image_get_type             (void) G_GNUC_CONST;
98 
99 gboolean       _gtk_css_image_can_parse            (GtkCssParser               *parser);
100 GtkCssImage *  _gtk_css_image_new_parse            (GtkCssParser               *parser);
101 
102 int            _gtk_css_image_get_width            (GtkCssImage                *image) G_GNUC_PURE;
103 int            _gtk_css_image_get_height           (GtkCssImage                *image) G_GNUC_PURE;
104 double         _gtk_css_image_get_aspect_ratio     (GtkCssImage                *image) G_GNUC_PURE;
105 
106 GtkCssImage *  _gtk_css_image_compute              (GtkCssImage                *image,
107                                                     guint                       property_id,
108                                                     GtkStyleProvider           *provider,
109                                                     GtkCssStyle                *style,
110                                                     GtkCssStyle                *parent_style);
111 gboolean       _gtk_css_image_equal                (GtkCssImage                *image1,
112                                                     GtkCssImage                *image2) G_GNUC_PURE;
113 GtkCssImage *  _gtk_css_image_transition           (GtkCssImage                *start,
114                                                     GtkCssImage                *end,
115                                                     guint                       property_id,
116                                                     double                      progress);
117 
118 void           _gtk_css_image_draw                 (GtkCssImage                *image,
119                                                     cairo_t                    *cr,
120                                                     double                      width,
121                                                     double                      height);
122 void           gtk_css_image_snapshot              (GtkCssImage                *image,
123                                                     GtkSnapshot                *snapshot,
124                                                     double                      width,
125                                                     double                      height);
126 gboolean       gtk_css_image_is_invalid            (GtkCssImage                *image) G_GNUC_PURE;
127 gboolean       gtk_css_image_is_dynamic            (GtkCssImage                *image) G_GNUC_PURE;
128 GtkCssImage *  gtk_css_image_get_dynamic_image     (GtkCssImage                *image,
129                                                     gint64                      monotonic_time);
130 void           _gtk_css_image_print                (GtkCssImage                *image,
131                                                     GString                    *string);
132 char *         gtk_css_image_to_string             (GtkCssImage                *image);
133 
134 void           _gtk_css_image_get_concrete_size    (GtkCssImage                *image,
135                                                     double                      specified_width,
136                                                     double                      specified_height,
137                                                     double                      default_width,
138                                                     double                      default_height,
139                                                     double                     *concrete_width,
140                                                     double                     *concrete_height);
141 cairo_surface_t *
142                _gtk_css_image_get_surface          (GtkCssImage                *image,
143                                                     cairo_surface_t            *target,
144                                                     int                         surface_width,
145                                                     int                         surface_height);
146 gboolean       gtk_css_image_is_computed           (GtkCssImage                *image) G_GNUC_PURE;
147 
148 
149 G_END_DECLS
150 
151 #endif /* __GTK_CSS_IMAGE_PRIVATE_H__ */
152