Photon 1.0.0
Loading...
Searching...
No Matches
html_tag.h
Go to the documentation of this file.
1#ifndef LH_HTML_TAG_H
2#define LH_HTML_TAG_H
3
4#include "element.h"
5#include "style.h"
6#include "background.h"
7#include "css_margins.h"
8#include "borders.h"
9#include "css_selector.h"
10#include "stylesheet.h"
11#include "line_box.h"
12#include "table.h"
13
14namespace litehtml
15{
16
17 class html_tag : public element
18 {
19 friend class elements_iterator;
20 friend class el_table;
21 friend class table_grid;
22 friend class line_box;
23 public:
24 typedef shared_ptr<html_tag> ptr;
25 protected:
26 string_id m_tag;
27 string_id m_id;
29 vector<string_id> m_classes;
32 vector<string_id> m_pseudo_classes;
33
34 void select_all(const css_selector& selector, elements_list& res) override;
35
36 public:
37 explicit html_tag(const shared_ptr<document>& doc);
38 // constructor for anonymous wrapper boxes
39 explicit html_tag(const element::ptr& parent, const string& style = "display: block");
40
41 bool appendChild(const element::ptr& el) override;
42 bool removeChild(const element::ptr& el) override;
43 void clearRecursive() override;
44 string_id tag() const override;
45 string_id id() const override;
46 const char* get_tagName() const override;
47 void set_tagName(const char* tag) override;
48 void set_data(const char* data) override;
49 const vector<string_id>& classes() const { return m_classes; }
50 const string_vector& str_classes() const { return m_str_classes; }
51
52 void set_attr(const char* name, const char* val) override;
53 const char* get_attr(const char* name, const char* def = nullptr) const override;
54 void apply_stylesheet(const litehtml::css& stylesheet) override;
55 void refresh_styles() override;
56
57 bool is_white_space() const override;
58 bool is_body() const override;
59 bool is_break() const override;
60
61 bool on_mouse_over() override;
62 bool on_mouse_leave() override;
63 bool on_lbutton_down() override;
64 bool on_lbutton_up() override;
65 void on_click() override;
66 bool set_pseudo_class(string_id cls, bool add) override;
67 bool set_class(const char* pclass, bool add) override;
68 bool is_replaced() const override;
69 void compute_styles(bool recursive = true) override;
70 void draw(uint_ptr hdc, int x, int y, const position *clip, const std::shared_ptr<render_item> &ri) override;
71 void draw_background(uint_ptr hdc, int x, int y, const position *clip,
72 const std::shared_ptr<render_item> &ri) override;
73
74 template<class Type>
75 const Type& get_property(string_id name, bool inherited, const Type& default_value, uint_ptr css_properties_member_offset) const;
76 bool get_custom_property(string_id name, css_token_vector& result) const;
77
79
80 int select(const css_selector::vector& selector_list, bool apply_pseudo = true) override;
81 int select(const string& selector) override;
82 int select(const css_selector& selector, bool apply_pseudo = true) override;
83 int select(const css_element_selector& selector, bool apply_pseudo = true) override;
86
87 elements_list select_all(const string& selector) override;
88 elements_list select_all(const css_selector& selector) override;
89
90 element::ptr select_one(const string& selector) override;
91 element::ptr select_one(const css_selector& selector) override;
92
93 element::ptr find_ancestor(const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
94 element::ptr find_adjacent_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
95 element::ptr find_sibling(const element::ptr& el, const css_selector& selector, bool apply_pseudo = true, bool* is_pseudo = nullptr) override;
96 void get_text(string& text) override;
97 void parse_attributes() override;
98
99 void get_content_size(size& sz, int max_width) override;
100 void add_style(const style& style) override;
101
102 bool is_nth_child(const element::ptr& el, int num, int off, bool of_type, const css_selector::vector& selector_list) const override;
103 bool is_nth_last_child(const element::ptr& el, int num, int off, bool of_type, const css_selector::vector& selector_list) const override;
104 bool is_only_child(const element::ptr& el, bool of_type) const override;
105 const background* get_background(bool own_only = false) override;
106
107 string dump_get_name() override;
108
109 protected:
110 void draw_list_marker( uint_ptr hdc, const position &pos );
111 string get_list_marker_text(int index);
112 element::ptr get_element_before(const style& style, bool create);
113 element::ptr get_element_after(const style& style, bool create);
114
115 void map_to_pixel_length_property(string_id prop_name, string attr_value);
116 void map_to_pixel_length_property_with_default_value(string_id prop_name, string attr_value, int default_value);
117 void map_to_dimension_property(string_id prop_name, string attr_value);
118 void map_to_dimension_property_ignoring_zero(string_id prop_name, string attr_value);
119
120 private:
122
123 };
124
125 /************************************************************************/
126 /* Inline Functions */
127 /************************************************************************/
128
130 {
131 return m_children;
132 }
133
134 template<class Type>
135 const Type& html_tag::get_property(string_id name, bool inherited, const Type& default_value, uint_ptr css_properties_member_offset) const
136 {
138
139 if (value.is<Type>())
140 {
141 return value.get<Type>();
142 }
143 else if (inherited || value.is<inherit>())
144 {
145 if (auto _parent = parent())
146 {
147 return *(Type*)((byte*)&_parent->css() + css_properties_member_offset);
148 }
149 return default_value;
150 }
151 return default_value;
152 }
153
154}
155
156#endif // LH_HTML_TAG_H
Definition background.h:91
Definition css_selector.h:173
Definition css_selector.h:195
std::vector< css_selector::ptr > vector
Definition css_selector.h:198
Definition stylesheet.h:45
Definition el_table.h:16
Definition element.h:19
elements_list m_children
Definition element.h:31
element::ptr parent() const
Definition element.h:170
std::shared_ptr< element > ptr
Definition element.h:25
friend class html_tag
Definition element.h:21
Definition iterators.h:29
Definition html_tag.h:18
const background * get_background(bool own_only=false) override
Definition html_tag.cpp:1477
element::ptr find_sibling(const element::ptr &el, const css_selector &selector, bool apply_pseudo=true, bool *is_pseudo=nullptr) override
Definition html_tag.cpp:1291
int select_attribute(const css_attribute_selector &sel)
Definition html_tag.cpp:652
void set_attr(const char *name, const char *val) override
Definition html_tag.cpp:86
void map_to_dimension_property_ignoring_zero(string_id prop_name, string attr_value)
Definition html_tag.cpp:1569
element::ptr find_adjacent_sibling(const element::ptr &el, const css_selector &selector, bool apply_pseudo=true, bool *is_pseudo=nullptr) override
Definition html_tag.cpp:1254
bool is_break() const override
Definition html_tag.cpp:850
element::ptr find_ancestor(const css_selector &selector, bool apply_pseudo=true, bool *is_pseudo=nullptr) override
Definition html_tag.cpp:713
vector< string_id > m_classes
Definition html_tag.h:29
bool is_replaced() const override
Definition html_tag.cpp:1040
bool is_only_child(const element::ptr &el, bool of_type) const override
Definition html_tag.cpp:1324
const Type & get_property(string_id name, bool inherited, const Type &default_value, uint_ptr css_properties_member_offset) const
Definition html_tag.h:135
bool on_mouse_leave() override
Definition html_tag.cpp:781
bool on_mouse_over() override
Definition html_tag.cpp:764
void draw_list_marker(uint_ptr hdc, const position &pos)
Definition html_tag.cpp:1045
void on_click() override
Definition html_tag.cpp:838
bool is_body() const override
Definition html_tag.cpp:754
void apply_stylesheet(const litehtml::css &stylesheet) override
Definition html_tag.cpp:180
void map_to_pixel_length_property_with_default_value(string_id prop_name, string attr_value, int default_value)
Definition html_tag.cpp:1543
element::ptr select_one(const string &selector) override
Definition html_tag.cpp:154
element::ptr get_element_after(const style &style, bool create)
Definition html_tag.cpp:1361
void add_style(const style &style) override
Definition html_tag.cpp:1400
void map_to_dimension_property(string_id prop_name, string attr_value)
Definition html_tag.cpp:1552
const vector< string_id > & classes() const
Definition html_tag.h:49
void set_data(const char *data) override
Definition html_tag.cpp:759
html_tag(const shared_ptr< document > &doc)
bool removeChild(const element::ptr &el) override
Definition html_tag.cpp:45
const string_vector & str_classes() const
Definition html_tag.h:50
bool set_class(const char *pclass, bool add) override
Definition html_tag.cpp:994
bool is_white_space() const override
Definition html_tag.cpp:363
string_id m_tag
Definition html_tag.h:26
void refresh_styles() override
Definition html_tag.cpp:1406
bool appendChild(const element::ptr &el) override
Definition html_tag.cpp:34
bool is_nth_child(const element::ptr &el, int num, int off, bool of_type, const css_selector::vector &selector_list) const override
Definition html_tag.cpp:1188
string dump_get_name() override
Definition html_tag.cpp:1522
vector< string_id > m_pseudo_classes
Definition html_tag.h:32
bool get_custom_property(string_id name, css_token_vector &result) const
Definition html_tag.cpp:324
bool on_lbutton_down() override
Definition html_tag.cpp:802
bool on_lbutton_up() override
Definition html_tag.cpp:819
element::ptr get_element_before(const style &style, bool create)
Definition html_tag.cpp:1345
void handle_counter_properties()
Definition html_tag.cpp:1378
style m_style
Definition html_tag.h:30
string_vector m_str_classes
Definition html_tag.h:28
elements_list & children()
Definition html_tag.h:129
const char * get_tagName() const override
Definition html_tag.cpp:76
string_id m_id
Definition html_tag.h:27
bool is_nth_last_child(const element::ptr &el, int num, int off, bool of_type, const css_selector::vector &selector_list) const override
Definition html_tag.cpp:1221
string get_list_marker_text(int index)
Definition html_tag.cpp:1143
string_id tag() const override
Definition html_tag.cpp:71
void set_tagName(const char *tag) override
Definition html_tag.cpp:81
bool set_pseudo_class(string_id cls, bool add) override
Definition html_tag.cpp:972
void compute_styles(bool recursive=true) override
Definition html_tag.cpp:340
void draw_background(uint_ptr hdc, int x, int y, const position *clip, const std::shared_ptr< render_item > &ri) override
Definition html_tag.cpp:855
void map_to_pixel_length_property(string_id prop_name, string attr_value)
Definition html_tag.cpp:1532
void get_text(string &text) override
Definition html_tag.cpp:746
const char * get_attr(const char *name, const char *def=nullptr) const override
Definition html_tag.cpp:115
void clearRecursive() override
Definition html_tag.cpp:56
void get_content_size(size &sz, int max_width) override
Definition html_tag.cpp:278
shared_ptr< html_tag > ptr
Definition html_tag.h:24
void parse_attributes() override
Definition html_tag.cpp:738
void select_all(const css_selector &selector, elements_list &res) override
Definition html_tag.cpp:140
string_id id() const override
Definition html_tag.cpp:66
void draw(uint_ptr hdc, int x, int y, const position *clip, const std::shared_ptr< render_item > &ri) override
Definition html_tag.cpp:290
string_map m_attrs
Definition html_tag.h:31
int select_pseudoclass(const css_attribute_selector &sel)
Definition html_tag.cpp:538
Definition line_box.h:110
Definition style.h:40
const property_value & get_property(string_id name) const
Definition style.cpp:1431
Definition table.h:197
Definition core.h:1598
Definition background.h:12
vector< css_token > css_token_vector
Definition css_tokenizer.h:151
std::uintptr_t uint_ptr
Definition types.h:17
const char * name
Definition encodings.cpp:1358
std::list< std::shared_ptr< element > > elements_list
Definition types.h:32
std::map< string, string > string_map
Definition types.h:31
std::vector< string > string_vector
Definition types.h:34
Definition format.h:1901
Definition css_selector.h:150
Definition style.h:9
Definition types.h:103
Definition style.h:26
Definition types.h:89
annotation select
Definition tag_strings.h:116