summaryrefslogtreecommitdiff
path: root/src/layeng/cr-box.h
blob: d96fe424f759ad8f8d03bfe1aea3cfd574607641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */

/*
 * This file is part of The Croco Library
 *
 * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#ifndef __CR_BOX_H__
#define __CR_BOX_H__

#include "cr-style.h"
#include "libxml/tree.h"

/*
 *$Id$
 */

G_BEGIN_DECLS

/**
 *@file 
 *the declaration of the #CRBox class.
 */
enum CRBoxContentType
{
	NO_CONTENT_TYPE,
	TEXT_CONTENT_TYPE,
	IMAGE_CONTENT_TYPE
} ;

typedef struct _CRImageContentDesc CRImageContentDesc ;
struct _CRImageContentDesc
{
	guchar *img_buf ;
	gulong *len ;
	guchar *img_path ;
} ;

typedef struct _CRBoxContent CRBoxContent ;
struct _CRBoxContent
{
	enum CRBoxContentType type ;
	union 
	{
		guchar *text ;
		CRImageContentDesc *img_desc ;
	} u ;

        /*
         *a place where the rendered content can be cached.
         *This can be usefull because sometime, during the layout,
         *calculating the size of the content is better achieve by
         *rendering it. In this case, the rendered content is just cached
         *here so that the rendering stage can just pick it.
         */
        gpointer content_cache ;
} ;

typedef struct _CRBoxEdge CRBoxEdge ;

/**
 *An internal data structure
 *used by #CRBox.
 *An edge is an rectangular area
 *defined by the coordinates of the it top left corner,
 *its width and height.
 */
struct _CRBoxEdge
{
	gulong x, y, width, max_width, 
                height, x_offset, y_offset,
                child_rmost_x ;
} ;


enum CRBoxType
{
        BOX_TYPE_UNDEFINED,
        BOX_TYPE_BOX_MODEL,
        BOX_TYPE_BLOCK,
        BOX_TYPE_ANONYMOUS_BLOCK,
        BOX_TYPE_INLINE,
        BOX_TYPE_ANONYMOUS_INLINE,
        BOX_TYPE_COMPACT,
        BOX_TYPE_RUN_IN
} ;

typedef struct _CRBoxData CRBoxData ;

/**
 *Some data stored in the box.
 *these data are about the node which
 *generated the current box.
 */
struct _CRBoxData
{
        /**
         *The xml node which generated
         *the css box. If NULL, it means
         *that this node is an anonymous node
         */
        xmlNode *xml_node ;
} ;

CRBoxData *
cr_box_data_new (xmlNode *a_node)  ;

void
cr_box_data_destroy (CRBoxData *a_this) ;

typedef struct _CRBoxModel CRBoxModel ;
typedef struct _CRBox CRBox ;

/**
 *The CRBox class.
 *Abstracts the css2 box as defined in the
 *css2 spec in chapter 8.
  *It is actually a tree of boxes, each being "generated"
 *by an xml document tree node.
 */
struct _CRBox
{
        enum CRBoxType type ;

	/**
	 *The inner edge, or content edge.
	 *Is the one that immediately wraps
	 *the content of the box.
	 *The content of the box may be
	 *a text, an image, or a set of boxes.
	 *If the content is a set of boxes, then
	 *this set is inevitably the set of children
	 *boxes of this current box.
	 */
	CRBoxEdge inner_edge ;

	/**
	 *The padding edge.
	 *It includes the inner_edge plus a
	 *a surrounding area called "padding".
	 *When the padding is inexistent, the
	 *padding edge equals the inner or content edge.
	 */
	CRBoxEdge padding_edge ;

	/**
	 *The border edge.
	 *It includes the padding edge plus
	 *a surrounding area called "border".
	 *If the border is inexistant, the
	 *border edge equals the padding edge.
	 */
	CRBoxEdge border_edge ;

	/**
	 *The outer edge aka margin edge.
	 *It includes the border edge plus
	 *a surrounding area called "margin".
	 *If the border is inexistant, the outer
	 *edge equals the border_edge.
	 */
	CRBoxEdge outer_edge ;

	/**
	 *The values of all the preceding
	 *edges are infered from the value
	 *of the 'style' field.
	 */

	/**
	 *The content (text or image) of this
	 *box
	 */
	CRBoxContent *content ;

	/**
	 *if TRUE, it means that this box has
	 *a simple content. Simple content means
	 *either a text or image content.
	 *Normally, to be logic, if this is
	 *set to TRUE, the children pointer should
	 *be NULL ... see what I mean ?
	 */
	gboolean as_simple_content ;

	/**
	 *The value infered from what has been found
	 *in the css stylesheet.
	 */
	CRStyle *style ;

	/**the containing box*/
	CRBox *parent ;

	/**the next box in the flow*/
	CRBox *next ;

	/**the previous box in the flow*/
	CRBox *prev ;

	/**the children (contained) boxes*/
	CRBox *children ;

        CRBoxModel * box_model ;

        /**some custom data used by libcroco*/
        CRBoxData *box_data ;
        /**some application data that will never 
         *be used by libcroco. Applications
         *are free to use it.
         */
        gpointer *app_data ;
        
        gulong ref_count ;
} ;

struct _CRBoxModel
{
        CRBox box ;
        gulong viewport_width ;
        gulong viewport_height ;
        gulong ref_count ;
} ;


CRBoxModel *
cr_box_model_new (void) ;

void
cr_box_model_destroy (CRBoxModel *a_this) ;

void
cr_box_model_ref (CRBoxModel *a_this) ;

gboolean
cr_box_model_unref (CRBoxModel *a_this) ;

CRBoxContent *
cr_box_content_new_from_text (guchar *a_text) ;

void
cr_box_content_destroy (CRBoxContent *a_this) ;

CRBox *
cr_box_new (CRStyle *a_this, gboolean a_set_default_style) ;

enum CRStatus
cr_box_insert_sibling (CRBox *a_prev,
                       CRBox *a_next,
                       CRBox *a_to_insert) ;
enum CRStatus
cr_box_to_string (CRBox *a_this, 
                  gulong a_nb_indent,
                  GString **a_string) ;

enum CRStatus
cr_box_dump_to_file (CRBox *a_this, 
                     gulong a_nb_indent,
                     FILE *a_filep) ;

enum CRStatus
cr_box_ref (CRBox *a_this) ;


gboolean
cr_box_unref (CRBox *a_this) ;

enum CRStatus
cr_box_append_child (CRBox *a_this, CRBox *a_to_append) ;

void
cr_box_destroy (CRBox *a_this) ;


G_END_DECLS

#endif /*__CR_BOX_H__*/