@@ -676,58 +676,70 @@ int litehtml::render_item_block::_render(int x, int y, int max_width, const cont
676676
677677 containing_block_context cb_size = calculate_containing_block_context (containing_block_size);
678678
679- max_width -= content_offset_left () + content_offset_right ();
680- if (max_width < 0 ) max_width = 0 ;
681- max_width = std::min (max_width, cb_size.width );
679+ if (cb_size.width_type != containing_block_context::cbc_value_type_auto)
680+ {
681+ // If width is absolute value, we render into cb_size.width size
682+ max_width = cb_size.width ;
683+ if (src_el ()->css ().get_box_sizing () == box_sizing_border_box)
684+ {
685+ // for style "box-sizing: border-box" we have to decrease rendering width for borders + paddings
686+ max_width -= box_sizing_width ();
687+ }
688+ } else
689+ {
690+ // for "width: auto" we render with max_width minus content offset
691+ max_width -= content_offset_width ();
692+ if (max_width < 0 ) max_width = 0 ;
693+ }
682694
683695 // *****************************************
684696 // Render content
685697 // *****************************************
686698 ret_width = _render_content (x, y, max_width, second_pass, ret_width, cb_size);
687699 // *****************************************
688700
689- bool requires_rerender = false ;
701+ bool requires_rerender = false ; // when true, the second pass for content rendering is required
690702
691703 // Set block width
692- if (cb_size.width_type == containing_block_context::cbc_value_type_auto &&
693- (src_el ()->is_inline_box () ||
694- src_el ()->css ().get_float () != float_none ||
695- src_el ()->css ().get_display () == display_table_cell ||
696- src_el ()->css ().get_display () == display_table_caption ||
697- src_el ()->css ().get_position () > element_position_relative
698- ))
704+ if (cb_size.width_type == containing_block_context::cbc_value_type_absolute)
699705 {
700- m_pos.width = ret_width;
701- if (ret_width < cb_size.width )
706+ m_pos.width = cb_size.width ;
707+ ret_width = cb_size.width ;
708+ if (src_el ()->css ().get_box_sizing () == box_sizing_border_box)
702709 {
703- // We have to render content again with new max_width
704- requires_rerender = true ;
710+ m_pos.width -= box_sizing_width ();
705711 }
706- } else
712+ } else if (cb_size. width_type == containing_block_context::cbc_value_type_percentage)
707713 {
708714 m_pos.width = cb_size.width ;
709- if (cb_size. width_type == containing_block_context::cbc_value_type_absolute )
715+ if (src_el ()-> css (). get_box_sizing () == box_sizing_border_box )
710716 {
711- ret_width = cb_size. width ;
717+ m_pos. width -= box_sizing_width () ;
712718 }
713- }
714-
715- // Set block height
716- if (cb_size.height_type != containing_block_context::cbc_value_type_auto)
719+ } else
717720 {
718- m_pos.height = cb_size.height ;
721+ if (src_el ()->is_inline_box () ||
722+ src_el ()->css ().get_float () != float_none ||
723+ src_el ()->css ().get_display () == display_table_cell ||
724+ src_el ()->css ().get_display () == display_table_caption ||
725+ src_el ()->css ().get_position () > element_position_relative)
726+ {
727+ m_pos.width = ret_width;
728+ if (ret_width < cb_size.width )
729+ {
730+ // We have to render content again with new max_width
731+ requires_rerender = true ;
732+ }
733+ } else
734+ {
735+ m_pos.width = cb_size.width ;
736+ if (src_el ()->css ().get_box_sizing () == box_sizing_border_box)
737+ {
738+ m_pos.width -= box_sizing_width ();
739+ }
740+ }
719741 }
720742
721- // add the floats' height to the block height
722- if (src_el ()->is_floats_holder ())
723- {
724- int floats_height = get_floats_height ();
725- if (floats_height > m_pos.height )
726- {
727- m_pos.height = floats_height;
728- }
729- }
730-
731743 calc_auto_margins (containing_block_size.width );
732744
733745 // Fix width with min-width attribute
@@ -750,6 +762,26 @@ int litehtml::render_item_block::_render(int x, int y, int max_width, const cont
750762 }
751763 }
752764
765+ // Set block height
766+ if (cb_size.height_type != containing_block_context::cbc_value_type_auto)
767+ {
768+ m_pos.height = cb_size.height ;
769+ if (src_el ()->css ().get_box_sizing () == box_sizing_border_box)
770+ {
771+ m_pos.height -= box_sizing_height ();
772+ }
773+ }
774+
775+ // add the floats' height to the block height
776+ if (src_el ()->is_floats_holder ())
777+ {
778+ int floats_height = get_floats_height ();
779+ if (floats_height > m_pos.height )
780+ {
781+ m_pos.height = floats_height;
782+ }
783+ }
784+
753785 // Fix height with min-height attribute
754786 if (cb_size.min_height_type != containing_block_context::cbc_value_type_none)
755787 {
0 commit comments