Disable stack execution on plugins
[claws.git] / src / plugins / litehtml_viewer / litehtml / document.h
blobe2623b2221430d7a5277c012c820665917f7ac30
1 #ifndef LH_DOCUMENT_H
2 #define LH_DOCUMENT_H
4 #include "style.h"
5 #include "types.h"
6 #include "master_css.h"
8 namespace litehtml
10 struct css_text
12 typedef std::vector<css_text> vector;
14 string text;
15 string baseurl;
16 string media;
18 css_text() = default;
20 css_text(const char* txt, const char* url, const char* media_str)
22 text = txt ? txt : "";
23 baseurl = url ? url : "";
24 media = media_str ? media_str : "";
27 css_text(const css_text& val)
29 text = val.text;
30 baseurl = val.baseurl;
31 media = val.media;
35 class dumper
37 public:
38 virtual ~dumper() {}
39 virtual void begin_node(const litehtml::string& descr) = 0;
40 virtual void end_node() = 0;
41 virtual void begin_attrs_group(const litehtml::string& descr) = 0;
42 virtual void end_attrs_group() = 0;
43 virtual void add_attr(const litehtml::string& name, const litehtml::string& value) = 0;
46 class html_tag;
47 class render_item;
49 class document : public std::enable_shared_from_this<document>
51 public:
52 typedef std::shared_ptr<document> ptr;
53 typedef std::weak_ptr<document> weak_ptr;
54 private:
55 std::shared_ptr<element> m_root;
56 std::shared_ptr<render_item> m_root_render;
57 document_container* m_container;
58 fonts_map m_fonts;
59 css_text::vector m_css;
60 litehtml::css m_styles;
61 litehtml::web_color m_def_color;
62 litehtml::css m_master_css;
63 litehtml::css m_user_css;
64 litehtml::size m_size;
65 litehtml::size m_content_size;
66 position::vector m_fixed_boxes;
67 media_query_list::vector m_media_lists;
68 element::ptr m_over_element;
69 std::list<std::shared_ptr<render_item>> m_tabular_elements;
70 media_features m_media;
71 string m_lang;
72 string m_culture;
73 public:
74 document(document_container* objContainer);
75 virtual ~document();
77 document_container* container() { return m_container; }
78 uint_ptr get_font(const char* name, int size, const char* weight, const char* style, const char* decoration, font_metrics* fm);
79 int render(int max_width, render_type rt = render_all);
80 void draw(uint_ptr hdc, int x, int y, const position* clip);
81 web_color get_def_color() { return m_def_color; }
82 int to_pixels(const char* str, int fontSize, bool* is_percent = nullptr) const;
83 void cvt_units(css_length& val, int fontSize, int size = 0) const;
84 int to_pixels(const css_length& val, int fontSize, int size = 0) const;
85 int width() const;
86 int height() const;
87 int content_width() const;
88 int content_height() const;
89 void add_stylesheet(const char* str, const char* baseurl, const char* media);
90 bool on_mouse_over(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
91 bool on_lbutton_down(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
92 bool on_lbutton_up(int x, int y, int client_x, int client_y, position::vector& redraw_boxes);
93 bool on_mouse_leave(position::vector& redraw_boxes);
94 element::ptr create_element(const char* tag_name, const string_map& attributes);
95 element::ptr root();
96 void get_fixed_boxes(position::vector& fixed_boxes);
97 void add_fixed_box(const position& pos);
98 void add_media_list(const media_query_list::ptr& list);
99 bool media_changed();
100 bool lang_changed();
101 bool match_lang(const string& lang);
102 void add_tabular(const std::shared_ptr<render_item>& el);
103 element::const_ptr get_over_element() const { return m_over_element; }
105 void append_children_from_string(element& parent, const char* str);
106 void dump(dumper& cout);
108 static litehtml::document::ptr createFromString(const char* str, litehtml::document_container* objPainter, const char* master_styles = litehtml::master_css, const char* user_styles = "");
110 private:
111 uint_ptr add_font(const char* name, int size, const char* weight, const char* style, const char* decoration, font_metrics* fm);
113 void create_node(void* gnode, elements_list& elements, bool parseTextNode);
114 bool update_media_lists(const media_features& features);
115 void fix_tables_layout();
116 void fix_table_children(const std::shared_ptr<render_item>& el_ptr, style_display disp, const char* disp_str);
117 void fix_table_parent(const std::shared_ptr<render_item> & el_ptr, style_display disp, const char* disp_str);
120 inline element::ptr document::root()
122 return m_root;
124 inline void document::add_tabular(const std::shared_ptr<render_item>& el)
126 m_tabular_elements.push_back(el);
128 inline bool document::match_lang(const string& lang)
130 return lang == m_lang || lang == m_culture;
134 #endif // LH_DOCUMENT_H