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") 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;lighter100;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") 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 }; 380 381 #define background_attachment_strings _t("scroll;fixed") 382 383 enum background_attachment 384 { 385 background_attachment_scroll, 386 background_attachment_fixed 387 }; 388 389 #define background_repeat_strings _t("repeat;repeat-x;repeat-y;no-repeat") 390 391 enum background_repeat 392 { 393 background_repeat_repeat, 394 background_repeat_repeat_x, 395 background_repeat_repeat_y, 396 background_repeat_no_repeat 397 }; 398 399 #define background_box_strings _t("border-box;padding-box;content-box") 400 401 enum background_box 402 { 403 background_box_border, 404 background_box_padding, 405 background_box_content 406 }; 407 408 #define element_position_strings _t("static;relative;absolute;fixed") 409 410 enum element_position 411 { 412 element_position_static, 413 element_position_relative, 414 element_position_absolute, 415 element_position_fixed, 416 }; 417 418 #define text_align_strings _t("left;right;center;justify") 419 420 enum text_align 421 { 422 text_align_left, 423 text_align_right, 424 text_align_center, 425 text_align_justify 426 }; 427 428 #define text_transform_strings _t("none;capitalize;uppercase;lowercase") 429 430 enum text_transform 431 { 432 text_transform_none, 433 text_transform_capitalize, 434 text_transform_uppercase, 435 text_transform_lowercase 436 }; 437 438 #define white_space_strings _t("normal;nowrap;pre;pre-line;pre-wrap") 439 440 enum white_space 441 { 442 white_space_normal, 443 white_space_nowrap, 444 white_space_pre, 445 white_space_pre_line, 446 white_space_pre_wrap 447 }; 448 449 #define overflow_strings _t("visible;hidden;scroll;auto;no-display;no-content") 450 451 enum overflow 452 { 453 overflow_visible, 454 overflow_hidden, 455 overflow_scroll, 456 overflow_auto, 457 overflow_no_display, 458 overflow_no_content 459 }; 460 461 #define background_size_strings _t("auto;cover;contain") 462 463 enum background_size 464 { 465 background_size_auto, 466 background_size_cover, 467 background_size_contain, 468 }; 469 470 #define visibility_strings _t("visible;hidden;collapse") 471 472 enum visibility 473 { 474 visibility_visible, 475 visibility_hidden, 476 visibility_collapse, 477 }; 478 479 #define border_collapse_strings _t("collapse;separate") 480 481 enum border_collapse 482 { 483 border_collapse_collapse, 484 border_collapse_separate, 485 }; 486 487 488 #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") 489 490 enum pseudo_class 491 { 492 pseudo_class_only_child, 493 pseudo_class_only_of_type, 494 pseudo_class_first_child, 495 pseudo_class_first_of_type, 496 pseudo_class_last_child, 497 pseudo_class_last_of_type, 498 pseudo_class_nth_child, 499 pseudo_class_nth_of_type, 500 pseudo_class_nth_last_child, 501 pseudo_class_nth_last_of_type, 502 pseudo_class_not, 503 pseudo_class_lang, 504 }; 505 506 #define content_property_string _t("none;normal;open-quote;close-quote;no-open-quote;no-close-quote") 507 508 enum content_property 509 { 510 content_property_none, 511 content_property_normal, 512 content_property_open_quote, 513 content_property_close_quote, 514 content_property_no_open_quote, 515 content_property_no_close_quote, 516 }; 517 518 519 struct floated_box 520 { 521 typedef std::vector<floated_box> vector; 522 523 position pos; 524 element_float float_side; 525 element_clear clear_floats; 526 std::shared_ptr<element> el; 527 528 floated_box() = default; floated_boxfloated_box529 floated_box(const floated_box& val) 530 { 531 pos = val.pos; 532 float_side = val.float_side; 533 clear_floats = val.clear_floats; 534 el = val.el; 535 } 536 floated_box& operator=(const floated_box& val) 537 { 538 pos = val.pos; 539 float_side = val.float_side; 540 clear_floats = val.clear_floats; 541 el = val.el; 542 return *this; 543 } floated_boxfloated_box544 floated_box(floated_box&& val) 545 { 546 pos = val.pos; 547 float_side = val.float_side; 548 clear_floats = val.clear_floats; 549 el = std::move(val.el); 550 } 551 void operator=(floated_box&& val) 552 { 553 pos = val.pos; 554 float_side = val.float_side; 555 clear_floats = val.clear_floats; 556 el = std::move(val.el); 557 } 558 }; 559 560 struct int_int_cache 561 { 562 int hash; 563 int val; 564 bool is_valid; 565 bool is_default; 566 int_int_cacheint_int_cache567 int_int_cache() 568 { 569 hash = 0; 570 val = 0; 571 is_valid = false; 572 is_default = false; 573 } invalidateint_int_cache574 void invalidate() 575 { 576 is_valid = false; 577 is_default = false; 578 } set_valueint_int_cache579 void set_value(int vHash, int vVal) 580 { 581 hash = vHash; 582 val = vVal; 583 is_valid = true; 584 } 585 }; 586 587 enum select_result 588 { 589 select_no_match = 0x00, 590 select_match = 0x01, 591 select_match_pseudo_class = 0x02, 592 select_match_with_before = 0x10, 593 select_match_with_after = 0x20, 594 }; 595 596 template<class T> 597 class def_value 598 { 599 T m_val; 600 bool m_is_default; 601 public: def_value(T def_val)602 def_value(T def_val) 603 { 604 m_is_default = true; 605 m_val = def_val; 606 } reset(T def_val)607 void reset(T def_val) 608 { 609 m_is_default = true; 610 m_val = def_val; 611 } is_default()612 bool is_default() 613 { 614 return m_is_default; 615 } 616 T operator=(T new_val) 617 { 618 m_val = new_val; 619 m_is_default = false; 620 return m_val; 621 } T()622 operator T() 623 { 624 return m_val; 625 } 626 }; 627 628 629 #define media_orientation_strings _t("portrait;landscape") 630 631 enum media_orientation 632 { 633 media_orientation_portrait, 634 media_orientation_landscape, 635 }; 636 637 #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") 638 639 enum media_feature 640 { 641 media_feature_none, 642 643 media_feature_width, 644 media_feature_min_width, 645 media_feature_max_width, 646 647 media_feature_height, 648 media_feature_min_height, 649 media_feature_max_height, 650 651 media_feature_device_width, 652 media_feature_min_device_width, 653 media_feature_max_device_width, 654 655 media_feature_device_height, 656 media_feature_min_device_height, 657 media_feature_max_device_height, 658 659 media_feature_orientation, 660 661 media_feature_aspect_ratio, 662 media_feature_min_aspect_ratio, 663 media_feature_max_aspect_ratio, 664 665 media_feature_device_aspect_ratio, 666 media_feature_min_device_aspect_ratio, 667 media_feature_max_device_aspect_ratio, 668 669 media_feature_color, 670 media_feature_min_color, 671 media_feature_max_color, 672 673 media_feature_color_index, 674 media_feature_min_color_index, 675 media_feature_max_color_index, 676 677 media_feature_monochrome, 678 media_feature_min_monochrome, 679 media_feature_max_monochrome, 680 681 media_feature_resolution, 682 media_feature_min_resolution, 683 media_feature_max_resolution, 684 }; 685 686 #define box_sizing_strings _t("content-box;border-box") 687 688 enum box_sizing 689 { 690 box_sizing_content_box, 691 box_sizing_border_box, 692 }; 693 694 695 #define media_type_strings _t("none;all;screen;print;braille;embossed;handheld;projection;speech;tty;tv") 696 697 enum media_type 698 { 699 media_type_none, 700 media_type_all, 701 media_type_screen, 702 media_type_print, 703 media_type_braille, 704 media_type_embossed, 705 media_type_handheld, 706 media_type_projection, 707 media_type_speech, 708 media_type_tty, 709 media_type_tv, 710 }; 711 712 struct media_features 713 { 714 media_type type; 715 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. 716 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. 717 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. 718 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. 719 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. 720 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. 721 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. 722 int resolution; // The resolution of the output device (in DPI) 723 }; 724 725 enum render_type 726 { 727 render_all, 728 render_no_fixed, 729 render_fixed_only, 730 }; 731 732 // List of the Void Elements (can't have any contents) 733 const litehtml::tchar_t* const void_elements = _t("area;base;br;col;command;embed;hr;img;input;keygen;link;meta;param;source;track;wbr"); 734 } 735 736 #endif // LH_TYPES_H 737