7 #include "stylesheet.h"
8 #include "css_offsets.h"
9 #include "css_margins.h"
10 #include "css_properties.h"
18 class element
: public std::enable_shared_from_this
<element
>
20 friend class line_box
;
21 friend class html_tag
;
22 friend class el_table
;
23 friend class document
;
25 typedef std::shared_ptr
<element
> ptr
;
26 typedef std::shared_ptr
<const element
> const_ptr
;
27 typedef std::weak_ptr
<element
> weak_ptr
;
29 std::weak_ptr
<element
> m_parent
;
30 std::weak_ptr
<document
> m_doc
;
31 elements_list m_children
;
33 std::list
<std::weak_ptr
<render_item
>> m_renders
;
34 used_selector::vector m_used_styles
;
36 virtual void select_all(const css_selector
& selector
, elements_list
& res
);
37 element::ptr
_add_before_after(int type
, const style
& style
);
39 explicit element(const std::shared_ptr
<document
>& doc
);
40 virtual ~element() = default;
42 const css_properties
& css() const;
43 css_properties
& css_w();
45 bool in_normal_flow() const;
46 bool is_inline() const; // returns true if element is inline
47 bool is_inline_box() const; // returns true if element is inline box (inline-table, inline-box, inline-flex)
48 bool is_block_box() const;
49 position
get_placement() const;
50 bool is_positioned() const;
51 bool is_float() const;
52 bool is_block_formatting_context() const;
55 element::ptr
parent() const;
56 void parent(const element::ptr
& par
);
57 // returns true for elements inside a table (but outside cells) that don't participate in table rendering
58 bool is_table_skip() const;
60 std::shared_ptr
<document
> get_document() const;
61 const std::list
<std::shared_ptr
<element
>>& children() const;
63 virtual elements_list
select_all(const string
& selector
);
64 virtual elements_list
select_all(const css_selector
& selector
);
66 virtual element::ptr
select_one(const string
& selector
);
67 virtual element::ptr
select_one(const css_selector
& selector
);
69 virtual bool appendChild(const ptr
&el
);
70 virtual bool removeChild(const ptr
&el
);
71 virtual void clearRecursive();
73 virtual string_id
id() const;
74 virtual string_id
tag() const;
75 virtual const char* get_tagName() const;
76 virtual void set_tagName(const char* tag
);
77 virtual void set_data(const char* data
);
79 virtual void set_attr(const char* name
, const char* val
);
80 virtual const char* get_attr(const char* name
, const char* def
= nullptr) const;
81 virtual void apply_stylesheet(const litehtml::css
& stylesheet
);
82 virtual void refresh_styles();
83 virtual bool is_white_space() const;
84 virtual bool is_space() const;
85 virtual bool is_comment() const;
86 virtual bool is_body() const;
87 virtual bool is_break() const;
88 virtual bool is_text() const;
90 virtual bool on_mouse_over();
91 virtual bool on_mouse_leave();
92 virtual bool on_lbutton_down();
93 virtual bool on_lbutton_up();
94 virtual void on_click();
95 virtual bool set_pseudo_class(string_id cls
, bool add
);
96 virtual bool set_class(const char* pclass
, bool add
);
97 virtual bool is_replaced() const;
98 virtual void compute_styles(bool recursive
= true);
99 virtual void draw(uint_ptr hdc
, int x
, int y
, const position
*clip
, const std::shared_ptr
<render_item
>& ri
);
100 virtual void draw_background(uint_ptr hdc
, int x
, int y
, const position
*clip
, const std::shared_ptr
<render_item
> &ri
);
101 virtual int get_enum_property (string_id name
, bool inherited
, int default_value
, uint_ptr css_properties_member_offset
) const;
102 virtual css_length
get_length_property(string_id name
, bool inherited
, css_length default_value
, uint_ptr css_properties_member_offset
) const;
103 virtual web_color
get_color_property (string_id name
, bool inherited
, web_color default_value
, uint_ptr css_properties_member_offset
) const;
104 virtual string
get_string_property(string_id name
, bool inherited
, const string
& default_value
, uint_ptr css_properties_member_offset
) const;
105 virtual float get_number_property(string_id name
, bool inherited
, float default_value
, uint_ptr css_properties_member_offset
) const;
106 virtual string_vector
get_string_vector_property(string_id name
, bool inherited
, const string_vector
& default_value
, uint_ptr css_properties_member_offset
) const;
107 virtual int_vector
get_int_vector_property (string_id name
, bool inherited
, const int_vector
& default_value
, uint_ptr css_properties_member_offset
) const;
108 virtual length_vector
get_length_vector_property(string_id name
, bool inherited
, const length_vector
& default_value
, uint_ptr css_properties_member_offset
) const;
109 virtual size_vector
get_size_vector_property (string_id name
, bool inherited
, const size_vector
& default_value
, uint_ptr css_properties_member_offset
) const;
110 virtual string
get_custom_property(string_id name
, const string
& default_value
) const;
112 virtual void get_text(string
& text
);
113 virtual void parse_attributes();
114 virtual int select(const string
& selector
);
115 virtual int select(const css_selector
& selector
, bool apply_pseudo
= true);
116 virtual int select(const css_element_selector
& selector
, bool apply_pseudo
= true);
117 virtual element::ptr
find_ancestor(const css_selector
& selector
, bool apply_pseudo
= true, bool* is_pseudo
= nullptr);
118 virtual bool is_ancestor(const ptr
&el
) const;
119 virtual element::ptr
find_adjacent_sibling(const element::ptr
& el
, const css_selector
& selector
, bool apply_pseudo
= true, bool* is_pseudo
= nullptr);
120 virtual element::ptr
find_sibling(const element::ptr
& el
, const css_selector
& selector
, bool apply_pseudo
= true, bool* is_pseudo
= nullptr);
121 virtual void get_content_size(size
& sz
, int max_width
);
122 virtual bool is_nth_child(const element::ptr
& el
, int num
, int off
, bool of_type
) const;
123 virtual bool is_nth_last_child(const element::ptr
& el
, int num
, int off
, bool of_type
) const;
124 virtual bool is_only_child(const element::ptr
& el
, bool of_type
) const;
125 virtual void add_style(const style
& style
);
126 virtual const background
* get_background(bool own_only
= false);
128 virtual string
dump_get_name();
129 virtual std::vector
<std::tuple
<string
, string
>> dump_get_attrs();
130 void dump(litehtml::dumper
& cout
);
132 std::tuple
<element::ptr
, element::ptr
, element::ptr
> split_inlines();
133 virtual std::shared_ptr
<render_item
> create_render_item(const std::shared_ptr
<render_item
>& parent_ri
);
134 bool requires_styles_update();
135 void add_render(const std::shared_ptr
<render_item
>& ri
);
136 bool find_styles_changes( position::vector
& redraw_boxes
);
137 element::ptr
add_pseudo_before(const style
& style
)
139 return _add_before_after(0, style
);
141 element::ptr
add_pseudo_after(const style
& style
)
143 return _add_before_after(1, style
);
147 //////////////////////////////////////////////////////////////////////////
148 // INLINE FUNCTIONS //
149 //////////////////////////////////////////////////////////////////////////
151 inline bool litehtml::element::in_normal_flow() const
153 if(css().get_position() != element_position_absolute
&& css().get_display() != display_none
)
160 inline bool litehtml::element::is_root() const
162 return m_parent
.expired();
165 inline element::ptr
litehtml::element::parent() const
167 return m_parent
.lock();
170 inline void litehtml::element::parent(const element::ptr
& par
)
175 inline bool litehtml::element::is_positioned() const
177 return (css().get_position() > element_position_static
);
180 inline bool litehtml::element::is_float() const
182 return (css().get_float() != float_none
);
185 inline std::shared_ptr
<document
> element::get_document() const
190 inline const css_properties
& element::css() const
195 inline css_properties
& element::css_w()
200 inline bool element::is_block_box() const
202 if (css().get_display() == display_block
||
203 css().get_display() == display_flex
||
204 css().get_display() == display_table
||
205 css().get_display() == display_list_item
||
206 css().get_display() == display_flex
)
213 inline const std::list
<std::shared_ptr
<element
>>& element::children() const
219 #endif // LH_ELEMENT_H