1 #ifndef LH_TYPES_H
2 #define LH_TYPES_H
3 
4 #include <stdlib.h>
5 #include <memory>
6 #include <map>
7 #include <vector>
8 
9 namespace litehtml
10 {
11 	class document;
12 	class element;
13 
14 	typedef std::map<litehtml::tstring, litehtml::tstring>			string_map;
15 	typedef std::vector< std::shared_ptr<litehtml::element> >		elements_vector;
16 	typedef std::vector<int>										int_vector;
17 	typedef std::vector<litehtml::tstring>							string_vector;
18 
19 	const unsigned int font_decoration_none			= 0x00;
20 	const unsigned int font_decoration_underline	= 0x01;
21 	const unsigned int font_decoration_linethrough	= 0x02;
22 	const unsigned int font_decoration_overline		= 0x04;
23 
24 	typedef unsigned char	byte;
25 	typedef unsigned int	ucode_t;
26 
27 	struct margins
28 	{
29 		int	left;
30 		int	right;
31 		int top;
32 		int bottom;
33 
marginsmargins34 		margins()
35 		{
36 			left = right = top = bottom = 0;
37 		}
38 
widthmargins39 		int width()		const	{ return left + right; }
heightmargins40 		int height()	const	{ return top + bottom; }
41 	};
42 
43 	struct size
44 	{
45 		int		width;
46 		int		height;
47 
sizesize48 		size()
49 		{
50 			width	= 0;
51 			height	= 0;
52 		}
53 	};
54 
55 	struct position
56 	{
57 		typedef std::vector<position>	vector;
58 
59 		int	x;
60 		int	y;
61 		int	width;
62 		int	height;
63 
positionposition64 		position()
65 		{
66 			x = y = width = height = 0;
67 		}
68 
positionposition69 		position(int x, int y, int width, int height)
70 		{
71 			this->x			= x;
72 			this->y			= y;
73 			this->width		= width;
74 			this->height	= height;
75 		}
76 
rightposition77 		int right()		const		{ return x + width;		}
bottomposition78 		int bottom()	const		{ return y + height;	}
leftposition79 		int left()		const		{ return x;				}
topposition80 		int top()		const		{ return y;				}
81 
82 		void operator+=(const margins& mg)
83 		{
84 			x		-= mg.left;
85 			y		-= mg.top;
86 			width	+= mg.left + mg.right;
87 			height	+= mg.top + mg.bottom;
88 		}
89 		void operator-=(const margins& mg)
90 		{
91 			x		+= mg.left;
92 			y		+= mg.top;
93 			width	-= mg.left + mg.right;
94 			height	-= mg.top + mg.bottom;
95 		}
96 
clearposition97 		void clear()
98 		{
99 			x = y = width = height = 0;
100 		}
101 
102 		void operator=(const size& sz)
103 		{
104 			width	= sz.width;
105 			height	= sz.height;
106 		}
107 
move_toposition108 		void move_to(int x, int y)
109 		{
110 			this->x = x;
111 			this->y = y;
112 		}
113 
does_intersectposition114 		bool does_intersect(const position* val) const
115 		{
116 			if(!val) return true;
117 
118 			return (
119 				left()			<= val->right()		&&
120 				right()			>= val->left()		&&
121 				bottom()		>= val->top()		&&
122 				top()			<= val->bottom()	)
123 				|| (
124 				val->left()		<= right()			&&
125 				val->right()	>= left()			&&
126 				val->bottom()	>= top()			&&
127 				val->top()		<= bottom()			);
128 		}
129 
emptyposition130 		bool empty() const
131 		{
132 			if(!width && !height)
133 			{
134 				return true;
135 			}
136 			return false;
137 		}
138 
is_point_insideposition139 		bool is_point_inside(int x, int y) const
140 		{
141 			if(x >= left() && x <= right() && y >= top() && y <= bottom())
142 			{
143 				return true;
144 			}
145 			return false;
146 		}
147 	};
148 
149 	struct font_metrics
150 	{
151 		int		height;
152 		int		ascent;
153 		int		descent;
154 		int		x_height;
155 		bool	draw_spaces;
156 
font_metricsfont_metrics157 		font_metrics()
158 		{
159 			height			= 0;
160 			ascent			= 0;
161 			descent			= 0;
162 			x_height		= 0;
163 			draw_spaces		= true;
164 		}
base_linefont_metrics165 		int base_line()	{ return descent; }
166 	};
167 
168 	struct font_item
169 	{
170 		uint_ptr		font;
171 		font_metrics	metrics;
172 	};
173 
174 	typedef std::map<tstring, font_item>	fonts_map;
175 
176 	enum draw_flag
177 	{
178 		draw_root,
179 		draw_block,
180 		draw_floats,
181 		draw_inlines,
182 		draw_positioned,
183 	};
184 
185 #define  style_display_strings		_t("none;block;inline;inline-block;inline-table;list-item;table;table-caption;table-cell;table-column;table-column-group;table-footer-group;table-header-group;table-row;table-row-group;inline-text")
186 
187 	enum style_display
188 	{
189 		display_none,
190 		display_block,
191 		display_inline,
192 		display_inline_block,
193 		display_inline_table,
194 		display_list_item,
195 		display_table,
196 		display_table_caption,
197 		display_table_cell,
198 		display_table_column,
199 		display_table_column_group,
200 		display_table_footer_group,
201 		display_table_header_group,
202 		display_table_row,
203 		display_table_row_group,
204 		display_inline_text,
205 	};
206 
207 	enum style_border
208 	{
209 		borderNope,
210 		borderNone,
211 		borderHidden,
212 		borderDotted,
213 		borderDashed,
214 		borderSolid,
215 		borderDouble
216 	};
217 
218 #define  font_size_strings		_t("xx-small;x-small;small;medium;large;x-large;xx-large;smaller;larger")
219 
220 	enum font_size
221 	{
222 		fontSize_xx_small,
223 		fontSize_x_small,
224 		fontSize_small,
225 		fontSize_medium,
226 		fontSize_large,
227 		fontSize_x_large,
228 		fontSize_xx_large,
229 		fontSize_smaller,
230 		fontSize_larger,
231 	};
232 
233 #define  font_style_strings		_t("normal;italic")
234 
235 	enum font_style
236 	{
237 		fontStyleNormal,
238 		fontStyleItalic
239 	};
240 
241 #define  font_variant_strings		_t("normal;small-caps")
242 
243 	enum font_variant
244 	{
245 		font_variant_normal,
246 		font_variant_italic
247 	};
248 
249 #define  font_weight_strings	_t("normal;bold;bolder;lighter;100;200;300;400;500;600;700")
250 
251 	enum font_weight
252 	{
253 		fontWeightNormal,
254 		fontWeightBold,
255 		fontWeightBolder,
256 		fontWeightLighter,
257 		fontWeight100,
258 		fontWeight200,
259 		fontWeight300,
260 		fontWeight400,
261 		fontWeight500,
262 		fontWeight600,
263 		fontWeight700
264 	};
265 
266 #define  list_style_type_strings	_t("none;circle;disc;square;armenian;cjk-ideographic;decimal;decimal-leading-zero;georgian;hebrew;hiragana;hiragana-iroha;katakana;katakana-iroha;lower-alpha;lower-greek;lower-latin;lower-roman;upper-alpha;upper-latin;upper-roman")
267 
268 	enum list_style_type
269 	{
270 		list_style_type_none,
271 		list_style_type_circle,
272 		list_style_type_disc,
273 		list_style_type_square,
274 		list_style_type_armenian,
275 		list_style_type_cjk_ideographic,
276 		list_style_type_decimal,
277 		list_style_type_decimal_leading_zero,
278 		list_style_type_georgian,
279 		list_style_type_hebrew,
280 		list_style_type_hiragana,
281 		list_style_type_hiragana_iroha,
282 		list_style_type_katakana,
283 		list_style_type_katakana_iroha,
284 		list_style_type_lower_alpha,
285 		list_style_type_lower_greek,
286 		list_style_type_lower_latin,
287 		list_style_type_lower_roman,
288 		list_style_type_upper_alpha,
289 		list_style_type_upper_latin,
290 		list_style_type_upper_roman,
291 	};
292 
293 #define  list_style_position_strings	_t("inside;outside")
294 
295 	enum list_style_position
296 	{
297 		list_style_position_inside,
298 		list_style_position_outside
299 	};
300 
301 #define  vertical_align_strings	_t("baseline;sub;super;top;text-top;middle;bottom;text-bottom")
302 
303 	enum vertical_align
304 	{
305 		va_baseline,
306 		va_sub,
307 		va_super,
308 		va_top,
309 		va_text_top,
310 		va_middle,
311 		va_bottom,
312 		va_text_bottom
313 	};
314 
315 #define  border_width_strings	_t("thin;medium;thick")
316 
317 	enum border_width
318 	{
319 		border_width_thin,
320 		border_width_medium,
321 		border_width_thick
322 	};
323 
324 #define  border_style_strings	_t("none;hidden;dotted;dashed;solid;double;groove;ridge;inset;outset")
325 
326 	enum border_style
327 	{
328 		border_style_none,
329 		border_style_hidden,
330 		border_style_dotted,
331 		border_style_dashed,
332 		border_style_solid,
333 		border_style_double,
334 		border_style_groove,
335 		border_style_ridge,
336 		border_style_inset,
337 		border_style_outset
338 	};
339 
340 #define  element_float_strings	_t("none;left;right")
341 
342 	enum element_float
343 	{
344 		float_none,
345 		float_left,
346 		float_right
347 	};
348 
349 #define  element_clear_strings	_t("none;left;right;both")
350 
351 	enum element_clear
352 	{
353 		clear_none,
354 		clear_left,
355 		clear_right,
356 		clear_both
357 	};
358 
359 #define  css_units_strings	_t("none;%;in;cm;mm;em;ex;pt;pc;px;dpi;dpcm;vw;vh;vmin;vmax;rem")
360 
361 	enum css_units
362 	{
363 		css_units_none,
364 		css_units_percentage,
365 		css_units_in,
366 		css_units_cm,
367 		css_units_mm,
368 		css_units_em,
369 		css_units_ex,
370 		css_units_pt,
371 		css_units_pc,
372 		css_units_px,
373 		css_units_dpi,
374 		css_units_dpcm,
375 		css_units_vw,
376 		css_units_vh,
377 		css_units_vmin,
378 		css_units_vmax,
379 		css_units_rem,
380 	};
381 
382 #define  background_attachment_strings	_t("scroll;fixed")
383 
384 	enum background_attachment
385 	{
386 		background_attachment_scroll,
387 		background_attachment_fixed
388 	};
389 
390 #define  background_repeat_strings	_t("repeat;repeat-x;repeat-y;no-repeat")
391 
392 	enum background_repeat
393 	{
394 		background_repeat_repeat,
395 		background_repeat_repeat_x,
396 		background_repeat_repeat_y,
397 		background_repeat_no_repeat
398 	};
399 
400 #define  background_box_strings	_t("border-box;padding-box;content-box")
401 
402 	enum background_box
403 	{
404 		background_box_border,
405 		background_box_padding,
406 		background_box_content
407 	};
408 
409 #define element_position_strings	_t("static;relative;absolute;fixed")
410 
411 	enum element_position
412 	{
413 		element_position_static,
414 		element_position_relative,
415 		element_position_absolute,
416 		element_position_fixed,
417 	};
418 
419 #define text_align_strings		_t("left;right;center;justify")
420 
421 	enum text_align
422 	{
423 		text_align_left,
424 		text_align_right,
425 		text_align_center,
426 		text_align_justify
427 	};
428 
429 #define text_transform_strings		_t("none;capitalize;uppercase;lowercase")
430 
431 	enum text_transform
432 	{
433 		text_transform_none,
434 		text_transform_capitalize,
435 		text_transform_uppercase,
436 		text_transform_lowercase
437 	};
438 
439 #define white_space_strings		_t("normal;nowrap;pre;pre-line;pre-wrap")
440 
441 	enum white_space
442 	{
443 		white_space_normal,
444 		white_space_nowrap,
445 		white_space_pre,
446 		white_space_pre_line,
447 		white_space_pre_wrap
448 	};
449 
450 #define overflow_strings		_t("visible;hidden;scroll;auto;no-display;no-content")
451 
452 	enum overflow
453 	{
454 		overflow_visible,
455 		overflow_hidden,
456 		overflow_scroll,
457 		overflow_auto,
458 		overflow_no_display,
459 		overflow_no_content
460 	};
461 
462 #define background_size_strings		_t("auto;cover;contain")
463 
464 	enum background_size
465 	{
466 		background_size_auto,
467 		background_size_cover,
468 		background_size_contain,
469 	};
470 
471 #define visibility_strings			_t("visible;hidden;collapse")
472 
473 	enum visibility
474 	{
475 		visibility_visible,
476 		visibility_hidden,
477 		visibility_collapse,
478 	};
479 
480 #define border_collapse_strings		_t("collapse;separate")
481 
482 	enum border_collapse
483 	{
484 		border_collapse_collapse,
485 		border_collapse_separate,
486 	};
487 
488 
489 #define pseudo_class_strings		_t("only-child;only-of-type;first-child;first-of-type;last-child;last-of-type;nth-child;nth-of-type;nth-last-child;nth-last-of-type;not;lang")
490 
491 	enum pseudo_class
492 	{
493 		pseudo_class_only_child,
494 		pseudo_class_only_of_type,
495 		pseudo_class_first_child,
496 		pseudo_class_first_of_type,
497 		pseudo_class_last_child,
498 		pseudo_class_last_of_type,
499 		pseudo_class_nth_child,
500 		pseudo_class_nth_of_type,
501 		pseudo_class_nth_last_child,
502 		pseudo_class_nth_last_of_type,
503 		pseudo_class_not,
504 		pseudo_class_lang,
505 	};
506 
507 #define content_property_string		_t("none;normal;open-quote;close-quote;no-open-quote;no-close-quote")
508 
509 	enum content_property
510 	{
511 		content_property_none,
512 		content_property_normal,
513 		content_property_open_quote,
514 		content_property_close_quote,
515 		content_property_no_open_quote,
516 		content_property_no_close_quote,
517 	};
518 
519 
520 	struct floated_box
521 	{
522 		typedef std::vector<floated_box>	vector;
523 
524 		position		pos;
525 		element_float	float_side;
526 		element_clear	clear_floats;
527 		std::shared_ptr<element>	el;
528 
529 		floated_box() = default;
floated_boxfloated_box530 		floated_box(const floated_box& val)
531 		{
532 			pos = val.pos;
533 			float_side = val.float_side;
534 			clear_floats = val.clear_floats;
535 			el = val.el;
536 		}
537 		floated_box& operator=(const floated_box& val)
538 		{
539 			pos = val.pos;
540 			float_side = val.float_side;
541 			clear_floats = val.clear_floats;
542 			el = val.el;
543 			return *this;
544 		}
floated_boxfloated_box545 		floated_box(floated_box&& val)
546 		{
547 			pos = val.pos;
548 			float_side = val.float_side;
549 			clear_floats = val.clear_floats;
550 			el = std::move(val.el);
551 		}
552 		void operator=(floated_box&& val)
553 		{
554 			pos = val.pos;
555 			float_side = val.float_side;
556 			clear_floats = val.clear_floats;
557 			el = std::move(val.el);
558 		}
559 	};
560 
561 	struct int_int_cache
562 	{
563 		int		hash;
564 		int		val;
565 		bool	is_valid;
566 		bool	is_default;
567 
int_int_cacheint_int_cache568 		int_int_cache()
569 		{
570 			hash		= 0;
571 			val			= 0;
572 			is_valid	= false;
573 			is_default	= false;
574 		}
invalidateint_int_cache575 		void invalidate()
576 		{
577 			is_valid	= false;
578 			is_default	= false;
579 		}
set_valueint_int_cache580 		void set_value(int vHash, int vVal)
581 		{
582 			hash		= vHash;
583 			val			= vVal;
584 			is_valid	= true;
585 		}
586 	};
587 
588 	enum select_result
589 	{
590 		select_no_match				= 0x00,
591 		select_match				= 0x01,
592 		select_match_pseudo_class	= 0x02,
593 		select_match_with_before	= 0x10,
594 		select_match_with_after		= 0x20,
595 	};
596 
597 	template<class T>
598 	class def_value
599 	{
600 		T		m_val;
601 		bool	m_is_default;
602 	public:
def_value(T def_val)603 		def_value(T def_val)
604 		{
605 			m_is_default	= true;
606 			m_val			= def_val;
607 		}
reset(T def_val)608 		void reset(T def_val)
609 		{
610 			m_is_default	= true;
611 			m_val			= def_val;
612 		}
is_default()613 		bool is_default()
614 		{
615 			return m_is_default;
616 		}
617 		T operator=(T new_val)
618 		{
619 			m_val			= new_val;
620 			m_is_default	= false;
621 			return m_val;
622 		}
T()623 		operator T()
624 		{
625 			return m_val;
626 		}
627 	};
628 
629 
630 #define media_orientation_strings		_t("portrait;landscape")
631 
632 	enum media_orientation
633 	{
634 		media_orientation_portrait,
635 		media_orientation_landscape,
636 	};
637 
638 #define media_feature_strings		_t("none;width;min-width;max-width;height;min-height;max-height;device-width;min-device-width;max-device-width;device-height;min-device-height;max-device-height;orientation;aspect-ratio;min-aspect-ratio;max-aspect-ratio;device-aspect-ratio;min-device-aspect-ratio;max-device-aspect-ratio;color;min-color;max-color;color-index;min-color-index;max-color-index;monochrome;min-monochrome;max-monochrome;resolution;min-resolution;max-resolution")
639 
640 	enum media_feature
641 	{
642 		media_feature_none,
643 
644 		media_feature_width,
645 		media_feature_min_width,
646 		media_feature_max_width,
647 
648 		media_feature_height,
649 		media_feature_min_height,
650 		media_feature_max_height,
651 
652 		media_feature_device_width,
653 		media_feature_min_device_width,
654 		media_feature_max_device_width,
655 
656 		media_feature_device_height,
657 		media_feature_min_device_height,
658 		media_feature_max_device_height,
659 
660 		media_feature_orientation,
661 
662 		media_feature_aspect_ratio,
663 		media_feature_min_aspect_ratio,
664 		media_feature_max_aspect_ratio,
665 
666 		media_feature_device_aspect_ratio,
667 		media_feature_min_device_aspect_ratio,
668 		media_feature_max_device_aspect_ratio,
669 
670 		media_feature_color,
671 		media_feature_min_color,
672 		media_feature_max_color,
673 
674 		media_feature_color_index,
675 		media_feature_min_color_index,
676 		media_feature_max_color_index,
677 
678 		media_feature_monochrome,
679 		media_feature_min_monochrome,
680 		media_feature_max_monochrome,
681 
682 		media_feature_resolution,
683 		media_feature_min_resolution,
684 		media_feature_max_resolution,
685 	};
686 
687 #define box_sizing_strings		_t("content-box;border-box")
688 
689 	enum box_sizing
690 	{
691 		box_sizing_content_box,
692 		box_sizing_border_box,
693 	};
694 
695 
696 #define media_type_strings		_t("none;all;screen;print;braille;embossed;handheld;projection;speech;tty;tv")
697 
698 	enum media_type
699 	{
700 		media_type_none,
701 		media_type_all,
702 		media_type_screen,
703 		media_type_print,
704 		media_type_braille,
705 		media_type_embossed,
706 		media_type_handheld,
707 		media_type_projection,
708 		media_type_speech,
709 		media_type_tty,
710 		media_type_tv,
711 	};
712 
713 	struct media_features
714 	{
715 		media_type	type;
716 		int			width;			// (pixels) For continuous media, this is the width of the viewport including the size of a rendered scroll bar (if any). For paged media, this is the width of the page box.
717 		int			height;			// (pixels) The height of the targeted display area of the output device. For continuous media, this is the height of the viewport including the size of a rendered scroll bar (if any). For paged media, this is the height of the page box.
718 		int			device_width;	// (pixels) The width of the rendering surface of the output device. For continuous media, this is the width of the screen. For paged media, this is the width of the page sheet size.
719 		int			device_height;	// (pixels) The height of the rendering surface of the output device. For continuous media, this is the height of the screen. For paged media, this is the height of the page sheet size.
720 		int			color;			// The number of bits per color component of the output device. If the device is not a color device, the value is zero.
721 		int			color_index;	// The number of entries in the color lookup table of the output device. If the device does not use a color lookup table, the value is zero.
722 		int			monochrome;		// The number of bits per pixel in a monochrome frame buffer. If the device is not a monochrome device, the output device value will be 0.
723 		int			resolution;		// The resolution of the output device (in DPI)
724 	};
725 
726 	enum render_type
727 	{
728 		render_all,
729 		render_no_fixed,
730 		render_fixed_only,
731 	};
732 
733 	// List of the Void Elements (can't have any contents)
734 	const litehtml::tchar_t* const void_elements = _t("area;base;br;col;command;embed;hr;img;input;keygen;link;meta;param;source;track;wbr");
735 }
736 
737 #endif  // LH_TYPES_H
738