vCalendar: Honor VTIMEZONE component if present
[claws.git] / src / plugins / litehtml_viewer / litehtml / el_image.cpp
blob9cf8146b4cb2073f0add46c6b7ae89d6d0579c5d
1 #include "html.h"
2 #include "el_image.h"
3 #include "render_image.h"
5 litehtml::el_image::el_image(const document::ptr& doc) : html_tag(doc)
7 m_css.set_display(display_inline_block);
10 void litehtml::el_image::get_content_size( size& sz, int max_width )
12 get_document()->container()->get_image_size(m_src.c_str(), 0, sz);
15 bool litehtml::el_image::is_replaced() const
17 return true;
20 void litehtml::el_image::parse_attributes()
22 m_src = get_attr("src", "");
24 const char* attr_height = get_attr("height");
25 if(attr_height)
27 m_style.add_property(_height_, attr_height);
29 const char* attr_width = get_attr("width");
30 if(attr_width)
32 m_style.add_property(_width_, attr_width);
36 void litehtml::el_image::draw(uint_ptr hdc, int x, int y, const position *clip, const std::shared_ptr<render_item> &ri)
38 position pos = ri->pos();
39 pos.x += x;
40 pos.y += y;
42 position el_pos = pos;
43 el_pos += ri->get_paddings();
44 el_pos += ri->get_borders();
46 // draw standard background here
47 if (el_pos.does_intersect(clip))
49 const background* bg = get_background();
50 if (bg)
52 std::vector<background_paint> bg_paint;
53 init_background_paint(pos, bg_paint, bg, ri);
55 get_document()->container()->draw_background(hdc, bg_paint);
59 // draw image as background
60 if(pos.does_intersect(clip))
62 if (pos.width > 0 && pos.height > 0) {
63 background_paint bg;
64 bg.image = m_src;
65 bg.clip_box = pos;
66 bg.origin_box = pos;
67 bg.border_box = pos;
68 bg.border_box += ri->get_paddings();
69 bg.border_box += ri->get_borders();
70 bg.repeat = background_repeat_no_repeat;
71 bg.image_size.width = pos.width;
72 bg.image_size.height = pos.height;
73 bg.border_radius = css().get_borders().radius.calc_percents(bg.border_box.width, bg.border_box.height);
74 bg.position_x = pos.x;
75 bg.position_y = pos.y;
76 get_document()->container()->draw_background(hdc, {bg});
80 // draw borders
81 if (el_pos.does_intersect(clip))
83 position border_box = pos;
84 border_box += ri->get_paddings();
85 border_box += ri->get_borders();
87 borders bdr = css().get_borders();
88 bdr.radius = css().get_borders().radius.calc_percents(border_box.width, border_box.height);
90 get_document()->container()->draw_borders(hdc, bdr, border_box, is_root());
94 void litehtml::el_image::compute_styles(bool recursive)
96 html_tag::compute_styles(recursive);
98 if(!m_src.empty())
100 if(!css().get_height().is_predefined() && !css().get_width().is_predefined())
102 get_document()->container()->load_image(m_src.c_str(), nullptr, true);
103 } else
105 get_document()->container()->load_image(m_src.c_str(), nullptr, false);
110 litehtml::string litehtml::el_image::dump_get_name()
112 return "img src=\"" + m_src + "\"";
115 std::shared_ptr<litehtml::render_item> litehtml::el_image::create_render_item(const std::shared_ptr<render_item>& parent_ri)
117 auto ret = std::make_shared<render_item_image>(shared_from_this());
118 ret->parent(parent_ri);
119 return ret;