5 litehtml::el_image::el_image(const std::shared_ptr<litehtml::document>& doc) : html_tag(doc)
7 m_display = display_inline_block;
10 litehtml::el_image::~el_image( void )
15 void litehtml::el_image::get_content_size( size& sz, int max_width )
17 get_document()->container()->get_image_size(m_src.c_str(), 0, sz);
20 int litehtml::el_image::line_height() const
25 bool litehtml::el_image::is_replaced() const
30 int litehtml::el_image::render( int x, int y, int max_width, bool second_pass )
32 int parent_width = max_width;
34 calc_outlines(parent_width);
38 document::ptr doc = get_document();
41 doc->container()->get_image_size(m_src.c_str(), 0, sz);
43 m_pos.width = sz.width;
44 m_pos.height = sz.height;
46 if(m_css_height.is_predefined() && m_css_width.is_predefined())
48 m_pos.height = sz.height;
49 m_pos.width = sz.width;
51 // check for max-height
52 if(!m_css_max_width.is_predefined())
54 int max_width = doc->cvt_units(m_css_max_width, m_font_size, parent_width);
55 if(m_pos.width > max_width)
57 m_pos.width = max_width;
61 m_pos.height = (int) ((float) m_pos.width * (float) sz.height / (float)sz.width);
64 m_pos.height = sz.height;
68 // check for max-height
69 if(!m_css_max_height.is_predefined())
71 int max_height = doc->cvt_units(m_css_max_height, m_font_size);
72 if(m_pos.height > max_height)
74 m_pos.height = max_height;
78 m_pos.width = (int) (m_pos.height * (float)sz.width / (float)sz.height);
81 m_pos.width = sz.width;
84 } else if(!m_css_height.is_predefined() && m_css_width.is_predefined())
86 if (!get_predefined_height(m_pos.height))
88 m_pos.height = (int)m_css_height.val();
91 // check for max-height
92 if(!m_css_max_height.is_predefined())
94 int max_height = doc->cvt_units(m_css_max_height, m_font_size);
95 if(m_pos.height > max_height)
97 m_pos.height = max_height;
103 m_pos.width = (int) (m_pos.height * (float)sz.width / (float)sz.height);
106 m_pos.width = sz.width;
108 } else if(m_css_height.is_predefined() && !m_css_width.is_predefined())
110 m_pos.width = (int) m_css_width.calc_percent(parent_width);
112 // check for max-width
113 if(!m_css_max_width.is_predefined())
115 int max_width = doc->cvt_units(m_css_max_width, m_font_size, parent_width);
116 if(m_pos.width > max_width)
118 m_pos.width = max_width;
124 m_pos.height = (int) ((float) m_pos.width * (float) sz.height / (float)sz.width);
127 m_pos.height = sz.height;
131 m_pos.width = (int) m_css_width.calc_percent(parent_width);
133 if (!get_predefined_height(m_pos.height))
135 m_pos.height = (int)m_css_height.val();
138 // check for max-height
139 if(!m_css_max_height.is_predefined())
141 int max_height = doc->cvt_units(m_css_max_height, m_font_size);
142 if(m_pos.height > max_height)
144 m_pos.height = max_height;
148 // check for max-height
149 if(!m_css_max_width.is_predefined())
151 int max_width = doc->cvt_units(m_css_max_width, m_font_size, parent_width);
152 if(m_pos.width > max_width)
154 m_pos.width = max_width;
159 calc_auto_margins(parent_width);
161 m_pos.x += content_margins_left();
162 m_pos.y += content_margins_top();
164 return m_pos.width + content_margins_left() + content_margins_right();
167 void litehtml::el_image::parse_attributes()
169 m_src = get_attr(_t("src"), _t(""));
171 const tchar_t* attr_height = get_attr(_t("height"));
174 m_style.add_property(_t("height"), attr_height, 0, false);
176 const tchar_t* attr_width = get_attr(_t("width"));
179 m_style.add_property(_t("width"), attr_width, 0, false);
183 void litehtml::el_image::draw( uint_ptr hdc, int x, int y, const position* clip )
185 position pos = m_pos;
189 position el_pos = pos;
193 // draw standard background here
194 if (el_pos.does_intersect(clip))
196 const background* bg = get_background();
199 background_paint bg_paint;
200 init_background_paint(pos, bg_paint, bg);
202 get_document()->container()->draw_background(hdc, bg_paint);
206 // draw image as background
207 if(pos.does_intersect(clip))
209 if (pos.width > 0 && pos.height > 0) {
215 bg.border_box += m_padding;
216 bg.border_box += m_borders;
217 bg.repeat = background_repeat_no_repeat;
218 bg.image_size.width = pos.width;
219 bg.image_size.height = pos.height;
220 bg.border_radius = m_css_borders.radius.calc_percents(bg.border_box.width, bg.border_box.height);
221 bg.position_x = pos.x;
222 bg.position_y = pos.y;
223 get_document()->container()->draw_background(hdc, bg);
228 if (el_pos.does_intersect(clip))
230 position border_box = pos;
231 border_box += m_padding;
232 border_box += m_borders;
234 borders bdr = m_css_borders;
235 bdr.radius = m_css_borders.radius.calc_percents(border_box.width, border_box.height);
237 get_document()->container()->draw_borders(hdc, bdr, border_box, have_parent() ? false : true);
241 void litehtml::el_image::parse_styles( bool is_reparse /*= false*/ )
243 html_tag::parse_styles(is_reparse);
247 if(!m_css_height.is_predefined() && !m_css_width.is_predefined())
249 get_document()->container()->load_image(m_src.c_str(), 0, true);
252 get_document()->container()->load_image(m_src.c_str(), 0, false);