Skip to content

Commit 0afcf0c

Browse files
committed
Separate fixed elements rendering, mark root element background.
document::render accept render_type parameter: render_all - render all elements render_no_fixed - don't render fixed elements render_fixed_only - render the fixed elements only background_paint now have is_root member. You can check is_root to draw background in entire window (not in paint rectangle only).
1 parent 29fd19c commit 0afcf0c

File tree

10 files changed

+74
-20
lines changed

10 files changed

+74
-20
lines changed

src/background.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,35 @@ litehtml::background& litehtml::background::operator=( const background& val )
4545

4646
litehtml::background_paint::background_paint() : color(0, 0, 0, 0)
4747
{
48-
position_x = 0;
49-
position_y = 0;
50-
attachment = background_attachment_scroll;
51-
repeat = background_repeat_repeat;
48+
position_x = 0;
49+
position_y = 0;
50+
attachment = background_attachment_scroll;
51+
repeat = background_repeat_repeat;
52+
is_root = false;
53+
}
54+
55+
litehtml::background_paint::background_paint( const background_paint& val )
56+
{
57+
image = val.image;
58+
baseurl = val.baseurl;
59+
attachment = val.attachment;
60+
repeat = val.repeat;
61+
color = val.color;
62+
clip_box = val.clip_box;
63+
origin_box = val.origin_box;
64+
border_box = val.border_box;
65+
border_radius = val.border_radius;
66+
image_size = val.image_size;
67+
position_x = val.position_x;
68+
position_y = val.position_y;
69+
is_root = val.is_root;
5270
}
5371

5472
void litehtml::background_paint::operator=( const background& val )
5573
{
5674
attachment = val.m_attachment;
5775
baseurl = val.m_baseurl;
5876
image = val.m_image;
59-
repeat = val.m_repeat;
77+
repeat = val.m_repeat;
6078
color = val.m_color;
6179
}

src/background.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ namespace litehtml
4444
size image_size;
4545
int position_x;
4646
int position_y;
47+
bool is_root;
4748
public:
4849
background_paint();
50+
background_paint(const background_paint& val);
4951
void operator=(const background& val);
5052
};
5153

src/box.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ void litehtml::line_box::add_element( element* el )
173173
int el_shift_left = el->get_inline_shift_left();
174174
int el_shift_right = el->get_inline_shift_right();
175175

176-
el->m_pos.x = m_box_left + m_width + el_shift_left;
177-
el->m_pos.y = m_box_top;
176+
el->m_pos.x = m_box_left + m_width + el_shift_left + el->content_margins_left();
177+
el->m_pos.y = m_box_top + el->content_margins_top();
178178
m_width += el->width() + el_shift_left + el_shift_right;
179179
}
180180
}

src/document.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,27 @@ litehtml::element* litehtml::document::add_body()
322322
return el;
323323
}
324324

325-
int litehtml::document::render( int max_width )
325+
int litehtml::document::render( int max_width, render_type rt )
326326
{
327327
int ret = 0;
328328
if(m_root)
329329
{
330-
ret = m_root->render(0, 0, max_width);
331-
if(m_root->fetch_positioned())
330+
if(rt == render_fixed_only)
332331
{
333332
m_fixed_boxes.clear();
334-
m_root->render_positioned();
333+
m_root->render_positioned(rt);
334+
} else
335+
{
336+
ret = m_root->render(0, 0, max_width);
337+
if(m_root->fetch_positioned())
338+
{
339+
m_fixed_boxes.clear();
340+
m_root->render_positioned(rt);
341+
}
342+
m_size.width = 0;
343+
m_size.height = 0;
344+
m_root->calc_document_size(m_size);
335345
}
336-
m_size.width = 0;
337-
m_size.height = 0;
338-
m_root->calc_document_size(m_size);
339346
}
340347
return ret;
341348
}

src/document.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace litehtml
7777

7878
litehtml::document_container* container() { return m_container; }
7979
uint_ptr get_font(const tchar_t* name, int size, const tchar_t* weight, const tchar_t* style, const tchar_t* decoration, font_metrics* fm);
80-
int render(int max_width);
80+
int render(int max_width, render_type rt = render_all);
8181
void draw(uint_ptr hdc, int x, int y, const position* clip);
8282
web_color get_def_color() { return m_def_color; }
8383
int cvt_units(const tchar_t* str, int fontSize, bool* is_percent = 0) const;

src/element.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ bool litehtml::element::is_only_child(element* el, bool of_type) LITEHTML_RE
250250
litehtml::overflow litehtml::element::get_overflow() const LITEHTML_RETURN_FUNC(overflow_visible)
251251
void litehtml::element::draw_children( uint_ptr hdc, int x, int y, const position* clip, draw_flag flag, int zindex ) LITEHTML_EMPTY_FUNC
252252
void litehtml::element::draw_stacking_context( uint_ptr hdc, int x, int y, const position* clip, bool with_positioned ) LITEHTML_EMPTY_FUNC
253-
void litehtml::element::render_positioned() LITEHTML_EMPTY_FUNC
253+
void litehtml::element::render_positioned(render_type rt) LITEHTML_EMPTY_FUNC
254254
int litehtml::element::get_zindex() const LITEHTML_RETURN_FUNC(0)
255255
bool litehtml::element::fetch_positioned() LITEHTML_RETURN_FUNC(false)
256256
litehtml::visibility litehtml::element::get_visibility() const LITEHTML_RETURN_FUNC(visibility_visible)

src/element.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace litehtml
8484
virtual void calc_outlines( int parent_width );
8585
virtual void apply_vertical_align();
8686
virtual bool fetch_positioned();
87-
virtual void render_positioned();
87+
virtual void render_positioned(render_type rt = render_all);
8888

8989
virtual bool appendChild(litehtml::element* el);
9090

src/html_tag.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,7 @@ void litehtml::html_tag::init_background_paint( position pos, background_paint &
28342834
}
28352835
bg_paint.border_radius = m_css_borders.radius;
28362836
bg_paint.border_box = border_box;
2837+
bg_paint.is_root = parent() ? false : true;
28372838
}
28382839

28392840
litehtml::visibility litehtml::html_tag::get_visibility() const
@@ -3021,19 +3022,38 @@ int litehtml::html_tag::get_zindex() const
30213022
return m_z_index;
30223023
}
30233024

3024-
void litehtml::html_tag::render_positioned()
3025+
void litehtml::html_tag::render_positioned(render_type rt)
30253026
{
30263027
position wnd_position;
30273028
m_doc->container()->get_client_rect(wnd_position);
30283029

30293030
element_position el_position;
30303031
element* el;
3032+
bool process;
30313033
for(elements_vector::iterator abs_el = m_positioned.begin(); abs_el != m_positioned.end(); abs_el++)
30323034
{
30333035
el = (*abs_el);
30343036
el_position = el->get_element_position();
30353037

3036-
if(el->get_display() != display_none && (el_position == element_position_absolute || el_position == element_position_fixed))
3038+
process = false;
3039+
if(el->get_display() != display_none)
3040+
{
3041+
if(el_position == element_position_absolute)
3042+
{
3043+
if(rt != render_fixed_only)
3044+
{
3045+
process = true;
3046+
}
3047+
} else if(el_position == element_position_fixed)
3048+
{
3049+
if(rt != render_no_fixed)
3050+
{
3051+
process = true;
3052+
}
3053+
}
3054+
}
3055+
3056+
if(process)
30373057
{
30383058
int parent_height = 0;
30393059
int parent_width = 0;

src/html_tag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace litehtml
8080
virtual int render_inline(element* container, int max_width);
8181
virtual int place_element(element* el, int max_width);
8282
virtual bool fetch_positioned();
83-
virtual void render_positioned();
83+
virtual void render_positioned(render_type rt = render_all);
8484

8585
int new_box( element* el, int max_width );
8686

src/types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,4 +674,11 @@ namespace litehtml
674674
int resolution; // The resolution of the output device (in DPI)
675675
};
676676

677+
enum render_type
678+
{
679+
render_all,
680+
render_no_fixed,
681+
render_fixed_only,
682+
};
683+
677684
}

0 commit comments

Comments
 (0)