4 #include "render_item.h"
5 #include "render_flex.h"
6 #include "render_inline.h"
7 #include "render_table.h"
8 #include "el_before_after.h"
13 #define LITEHTML_EMPTY_FUNC {}
14 #define LITEHTML_RETURN_FUNC(ret) {return ret;}
16 element::element(const document::ptr
& doc
) : m_doc(doc
)
20 position
element::get_placement() const
24 for(const auto& ri_el
: m_renders
)
26 auto ri
= ri_el
.lock();
29 position ri_pos
= ri_el
.lock()->get_placement();
50 bool element::is_inline() const
52 if( css().get_display() == display_inline
||
53 css().get_display() == display_inline_table
||
54 css().get_display() == display_inline_block
||
55 css().get_display() == display_inline_text
||
56 css().get_display() == display_inline_flex
)
63 bool element::is_inline_box() const
65 if( css().get_display() == display_inline_table
||
66 css().get_display() == display_inline_block
||
67 css().get_display() == display_inline_flex
)
74 bool element::is_ancestor(const ptr
&el
) const
76 element::ptr el_parent
= parent();
77 while(el_parent
&& el_parent
!= el
)
79 el_parent
= el_parent
->parent();
88 bool element::is_table_skip() const
90 return is_space() || is_comment() || css().get_display() == display_none
;
93 string
element::dump_get_name()
98 std::vector
<std::tuple
<string
, string
>> element::dump_get_attrs()
100 return m_css
.dump_get_attrs();
103 void element::dump(dumper
& cout
)
105 cout
.begin_node(dump_get_name());
107 auto attrs
= dump_get_attrs();
110 cout
.begin_attrs_group("attributes");
111 for (const auto &attr
: attrs
)
113 cout
.add_attr(std::get
<0>(attr
), std::get
<1>(attr
));
115 cout
.end_attrs_group();
118 if(!m_children
.empty())
120 cout
.begin_attrs_group("children");
121 for (const auto &el
: m_children
)
125 cout
.end_attrs_group();
131 std::shared_ptr
<render_item
> element::create_render_item(const std::shared_ptr
<render_item
>& parent_ri
)
133 std::shared_ptr
<render_item
> ret
;
135 if(css().get_display() == display_table_column
||
136 css().get_display() == display_table_column_group
||
137 css().get_display() == display_table_footer_group
||
138 css().get_display() == display_table_header_group
||
139 css().get_display() == display_table_row_group
)
141 ret
= std::make_shared
<render_item_table_part
>(shared_from_this());
142 } else if(css().get_display() == display_table_row
)
144 ret
= std::make_shared
<render_item_table_row
>(shared_from_this());
145 } else if(css().get_display() == display_block
||
146 css().get_display() == display_table_cell
||
147 css().get_display() == display_table_caption
||
148 css().get_display() == display_list_item
||
149 css().get_display() == display_inline_block
)
151 ret
= std::make_shared
<render_item_block
>(shared_from_this());
152 } else if(css().get_display() == display_table
|| css().get_display() == display_inline_table
)
154 ret
= std::make_shared
<render_item_table
>(shared_from_this());
155 } else if(css().get_display() == display_inline
|| css().get_display() == display_inline_text
)
157 ret
= std::make_shared
<render_item_inline
>(shared_from_this());
158 } else if(css().get_display() == display_flex
|| css().get_display() == display_inline_flex
)
160 ret
= std::make_shared
<render_item_flex
>(shared_from_this());
164 if (css().get_display() == display_table
||
165 css().get_display() == display_inline_table
||
166 css().get_display() == display_table_caption
||
167 css().get_display() == display_table_cell
||
168 css().get_display() == display_table_column
||
169 css().get_display() == display_table_column_group
||
170 css().get_display() == display_table_footer_group
||
171 css().get_display() == display_table_header_group
||
172 css().get_display() == display_table_row
||
173 css().get_display() == display_table_row_group
)
175 get_document()->add_tabular(ret
);
178 ret
->parent(parent_ri
);
179 for(const auto& el
: m_children
)
181 auto ri
= el
->create_render_item(ret
);
191 bool element::requires_styles_update()
193 for (const auto& used_style
: m_used_styles
)
195 if(used_style
->m_selector
->is_media_valid())
197 int res
= select(*(used_style
->m_selector
), true);
198 if( (res
== select_no_match
&& used_style
->m_used
) || (res
== select_match
&& !used_style
->m_used
) )
207 void element::add_render(const std::shared_ptr
<render_item
>& ri
)
209 m_renders
.push_back(ri
);
212 bool element::find_styles_changes( position::vector
& redraw_boxes
)
214 if(css().get_display() == display_inline_text
)
221 if(requires_styles_update())
223 auto fetch_boxes
= [&](const std::shared_ptr
<element
>& el
)
225 for(const auto& weak_ri
: el
->m_renders
)
227 auto ri
= weak_ri
.lock();
230 position::vector boxes
;
231 ri
->get_rendering_boxes(boxes
);
232 for (auto &box
: boxes
)
234 redraw_boxes
.push_back(box
);
239 fetch_boxes(shared_from_this());
240 for (auto& el
: m_children
)
249 for (auto& el
: m_children
)
251 if(el
->find_styles_changes(redraw_boxes
))
259 element::ptr
element::_add_before_after(int type
, const style
& style
)
264 el
= std::make_shared
<el_before
>(get_document());
265 m_children
.insert(m_children
.begin(), el
);
268 el
= std::make_shared
<el_after
>(get_document());
269 m_children
.insert(m_children
.end(), el
);
271 el
->parent(shared_from_this());
275 bool element::is_block_formatting_context() const
277 if( m_css
.get_display() == display_inline_block
||
278 m_css
.get_display() == display_table_cell
||
279 m_css
.get_display() == display_table_caption
||
281 m_css
.get_float() != float_none
||
282 m_css
.get_position() == element_position_absolute
||
283 m_css
.get_position() == element_position_fixed
||
284 m_css
.get_overflow() > overflow_visible
)
291 const background
* element::get_background(bool own_only
) LITEHTML_RETURN_FUNC(nullptr)
292 void element::add_style( const style
& style
) LITEHTML_EMPTY_FUNC
293 void element::select_all(const css_selector
& selector
, elements_list
& res
) LITEHTML_EMPTY_FUNC
294 elements_list
element::select_all(const css_selector
& selector
) LITEHTML_RETURN_FUNC(elements_list())
295 elements_list
element::select_all(const string
& selector
) LITEHTML_RETURN_FUNC(elements_list())
296 element::ptr
element::select_one( const css_selector
& selector
) LITEHTML_RETURN_FUNC(nullptr)
297 element::ptr
element::select_one( const string
& selector
) LITEHTML_RETURN_FUNC(nullptr)
298 element::ptr
element::find_adjacent_sibling(const element::ptr
& el
, const css_selector
& selector
, bool apply_pseudo
/*= true*/, bool* is_pseudo
/*= 0*/) LITEHTML_RETURN_FUNC(nullptr)
299 element::ptr
element::find_sibling(const element::ptr
& el
, const css_selector
& selector
, bool apply_pseudo
/*= true*/, bool* is_pseudo
/*= 0*/) LITEHTML_RETURN_FUNC(nullptr)
300 bool element::is_nth_last_child(const element::ptr
& el
, int num
, int off
, bool of_type
) const LITEHTML_RETURN_FUNC(false)
301 bool element::is_nth_child(const element::ptr
&, int num
, int off
, bool of_type
) const LITEHTML_RETURN_FUNC(false)
302 bool element::is_only_child(const element::ptr
& el
, bool of_type
) const LITEHTML_RETURN_FUNC(false)
303 void element::get_content_size( size
& sz
, int max_width
) LITEHTML_EMPTY_FUNC
304 bool element::appendChild(const ptr
&el
) LITEHTML_RETURN_FUNC(false)
305 bool element::removeChild(const ptr
&el
) LITEHTML_RETURN_FUNC(false)
306 void element::clearRecursive() LITEHTML_EMPTY_FUNC
307 string_id
element::id() const LITEHTML_RETURN_FUNC(empty_id
)
308 string_id
element::tag() const LITEHTML_RETURN_FUNC(empty_id
)
309 const char* element::get_tagName() const LITEHTML_RETURN_FUNC("")
310 void element::set_tagName( const char* tag
) LITEHTML_EMPTY_FUNC
311 void element::set_data( const char* data
) LITEHTML_EMPTY_FUNC
312 void element::set_attr( const char* name
, const char* val
) LITEHTML_EMPTY_FUNC
313 void element::apply_stylesheet( const litehtml::css
& stylesheet
) LITEHTML_EMPTY_FUNC
314 void element::refresh_styles() LITEHTML_EMPTY_FUNC
315 void element::on_click() LITEHTML_EMPTY_FUNC
316 void element::compute_styles( bool recursive
) LITEHTML_EMPTY_FUNC
317 const char* element::get_attr( const char* name
, const char* def
/*= 0*/ ) const LITEHTML_RETURN_FUNC(def
)
318 bool element::is_white_space() const LITEHTML_RETURN_FUNC(false)
319 bool element::is_space() const LITEHTML_RETURN_FUNC(false)
320 bool element::is_comment() const LITEHTML_RETURN_FUNC(false)
321 bool element::is_body() const LITEHTML_RETURN_FUNC(false)
322 bool element::is_break() const LITEHTML_RETURN_FUNC(false)
323 bool element::is_text() const LITEHTML_RETURN_FUNC(false)
325 bool element::on_mouse_over() LITEHTML_RETURN_FUNC(false)
326 bool element::on_mouse_leave() LITEHTML_RETURN_FUNC(false)
327 bool element::on_lbutton_down() LITEHTML_RETURN_FUNC(false)
328 bool element::on_lbutton_up() LITEHTML_RETURN_FUNC(false)
329 bool element::set_pseudo_class( string_id cls
, bool add
) LITEHTML_RETURN_FUNC(false)
330 bool element::set_class( const char* pclass
, bool add
) LITEHTML_RETURN_FUNC(false)
331 bool element::is_replaced() const LITEHTML_RETURN_FUNC(false)
332 void element::draw(uint_ptr hdc
, int x
, int y
, const position
*clip
, const std::shared_ptr
<render_item
> &ri
) LITEHTML_EMPTY_FUNC
333 void element::draw_background(uint_ptr hdc
, int x
, int y
, const position
*clip
, const std::shared_ptr
<render_item
> &ri
) LITEHTML_EMPTY_FUNC
334 int element::get_enum_property (string_id name
, bool inherited
, int defval
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC(0)
335 css_length
element::get_length_property (string_id name
, bool inherited
, css_length defval
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC(0)
336 web_color
element::get_color_property (string_id name
, bool inherited
, web_color defval
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC(web_color())
337 string
element::get_string_property (string_id name
, bool inherited
, const string
& defval
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC("")
338 float element::get_number_property (string_id name
, bool inherited
, float defval
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC(0)
339 string_vector
element::get_string_vector_property (string_id name
, bool inherited
, const string_vector
& default_value
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC({})
340 int_vector
element::get_int_vector_property (string_id name
, bool inherited
, const int_vector
& default_value
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC({})
341 length_vector
element::get_length_vector_property (string_id name
, bool inherited
, const length_vector
& default_value
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC({})
342 size_vector
element::get_size_vector_property (string_id name
, bool inherited
, const size_vector
& default_value
, uint_ptr css_properties_member_offset
) const LITEHTML_RETURN_FUNC({})
343 string
element::get_custom_property (string_id name
, const string
& defval
) const LITEHTML_RETURN_FUNC("")
344 void element::get_text( string
& text
) LITEHTML_EMPTY_FUNC
345 void element::parse_attributes() LITEHTML_EMPTY_FUNC
346 int element::select(const string
& selector
) LITEHTML_RETURN_FUNC(select_no_match
)
347 int element::select(const css_selector
& selector
, bool apply_pseudo
) LITEHTML_RETURN_FUNC(select_no_match
)
348 int element::select( const css_element_selector
& selector
, bool apply_pseudo
/*= true*/ ) LITEHTML_RETURN_FUNC(select_no_match
)
349 element::ptr
element::find_ancestor(const css_selector
& selector
, bool apply_pseudo
, bool* is_pseudo
) LITEHTML_RETURN_FUNC(nullptr)
351 } // namespace litehtml