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