2019-09-25 12:40:37 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibGUI/GPainter.h> 
  
						 
					
						
							
								
									
										
										
										
											2019-10-05 23:47:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibHTML/CSS/StyleResolver.h> 
  
						 
					
						
							
								
									
										
										
										
											2019-06-15 23:41:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibHTML/DOM/Element.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibHTML/Layout/LayoutBlock.h> 
  
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibHTML/Layout/LayoutInline.h> 
  
						 
					
						
							
								
									
										
										
										
											2019-10-15 16:48:38 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibHTML/Layout/LayoutReplaced.h> 
  
						 
					
						
							
								
									
										
										
										
											2019-06-15 22:49:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-07 09:23:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								LayoutBlock : : LayoutBlock ( const  Node *  node ,  NonnullRefPtr < StyleProperties >  style )  
						 
					
						
							
								
									
										
										
										
											2019-10-15 16:48:38 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    :  LayoutBox ( node ,  move ( style ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 22:49:44 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								LayoutBlock : : ~ LayoutBlock ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-06-20 23:00:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-08 17:42:23 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								LayoutNode &  LayoutBlock : : inline_wrapper ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-09-25 11:56:16 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! last_child ( )  | |  ! last_child ( ) - > is_block ( )  | |  last_child ( ) - > node ( )  ! =  nullptr )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-05 23:47:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        append_child ( adopt ( * new  LayoutBlock ( nullptr ,  style_for_anonymous_block ( ) ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-08 17:42:23 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  * last_child ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-20 23:00:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  LayoutBlock : : layout ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-07-01 07:28:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    compute_width ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    compute_position ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( children_are_inline ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        layout_inline_children ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        layout_block_children ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    compute_height ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  LayoutBlock : : layout_block_children ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ASSERT ( ! children_are_inline ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    int  content_height  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for_each_child ( [ & ] ( auto &  child )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-15 16:48:38 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ASSERT ( is < LayoutBlock > ( child ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto &  child_block  =  static_cast < LayoutBlock & > ( child ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        child_block . layout ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        content_height  =  child_block . rect ( ) . bottom ( )  +  child_block . box_model ( ) . full_margin ( ) . bottom  -  rect ( ) . top ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    rect ( ) . set_height ( content_height ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-06-20 23:00:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  LayoutBlock : : layout_inline_children ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ASSERT ( children_are_inline ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_line_boxes . clear ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for_each_child ( [ & ] ( auto &  child )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ASSERT ( child . is_inline ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-05 23:20:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        child . split_into_lines ( * this ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-12 13:47:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    int  min_line_height  =  style ( ) . line_height ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    int  content_height  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-16 20:32:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // FIXME: This should be done by the CSS parser!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    CSS : : ValueID  text_align  =  CSS : : ValueID : : Left ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  text_align_string  =  style ( ) . string_or_fallback ( CSS : : PropertyID : : TextAlign ,  " left " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( text_align_string  = =  " center " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        text_align  =  CSS : : ValueID : : Center ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  if  ( text_align_string  = =  " left " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        text_align  =  CSS : : ValueID : : Left ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else  if  ( text_align_string  = =  " right " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        text_align  =  CSS : : ValueID : : Right ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  ( auto &  line_box  :  m_line_boxes )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-12 13:47:49 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        int  max_height  =  min_line_height ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        for  ( auto &  fragment  :  line_box . fragments ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            max_height  =  max ( max_height ,  fragment . rect ( ) . height ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-16 20:32:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        int  x_offset  =  x ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        switch  ( text_align )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  CSS : : ValueID : : Center : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            x_offset  + =  ( width ( )  -  line_box . width ( ) )  /  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  CSS : : ValueID : : Right : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            x_offset  + =  ( width ( )  -  line_box . width ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        case  CSS : : ValueID : : Left : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        for  ( auto &  fragment  :  line_box . fragments ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // Vertically align everyone's bottom to the line.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // FIXME: Support other kinds of vertical alignment.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-16 20:32:17 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            fragment . rect ( ) . set_x ( x_offset  +  fragment . rect ( ) . x ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-13 17:31:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            fragment . rect ( ) . set_y ( y ( )  +  content_height  +  ( max_height  -  fragment . rect ( ) . height ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-05 23:20:35 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-15 16:48:38 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( is < LayoutReplaced > ( fragment . layout_node ( ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                const_cast < LayoutReplaced & > ( to < LayoutReplaced > ( fragment . layout_node ( ) ) ) . set_rect ( fragment . rect ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        content_height  + =  max_height ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    rect ( ) . set_height ( content_height ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-01 07:28:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  LayoutBlock : : compute_width ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-10-07 09:23:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  style  =  this - > style ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 07:34:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  auto_value  =  Length ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  zero_value  =  Length ( 0 ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-08 15:34:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  width  =  style . length_or_fallback ( CSS : : PropertyID : : Width ,  auto_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  margin_left  =  style . length_or_fallback ( CSS : : PropertyID : : MarginLeft ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  margin_right  =  style . length_or_fallback ( CSS : : PropertyID : : MarginRight ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  border_left  =  style . length_or_fallback ( CSS : : PropertyID : : BorderLeftWidth ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  border_right  =  style . length_or_fallback ( CSS : : PropertyID : : BorderRightWidth ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  padding_left  =  style . length_or_fallback ( CSS : : PropertyID : : PaddingLeft ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  padding_right  =  style . length_or_fallback ( CSS : : PropertyID : : PaddingRight ,  zero_value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-24 07:34:07 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:42:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef HTML_DEBUG 
  
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    dbg ( )  < <  "  Left:  "  < <  margin_left  < <  " + "  < <  border_left  < <  " + "  < <  padding_left ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    dbg ( )  < <  " Right:  "  < <  margin_right  < <  " + "  < <  border_right  < <  " + "  < <  padding_right ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:42:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2019-07-26 08:05:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    int  total_px  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto &  value  :  {  margin_left ,  border_left ,  padding_left ,  width ,  padding_right ,  border_right ,  margin_right  } )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        total_px  + =  value . to_px ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-26 08:05:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:42:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# ifdef HTML_DEBUG 
  
						 
					
						
							
								
									
										
										
										
											2019-07-26 08:05:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    dbg ( )  < <  " Total:  "  < <  total_px ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:42:10 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
									
										
										
										
											2019-07-26 08:05:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 10.3.3 Block-level, non-replaced elements in normal flow
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // If 'width' is not 'auto' and 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larger than the width of the containing block, then any 'auto' values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-13 17:31:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( width . is_auto ( )  & &  total_px  >  containing_block ( ) - > width ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( margin_left . is_auto ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-26 08:05:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            margin_left  =  zero_value ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( margin_right . is_auto ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-26 08:05:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            margin_right  =  zero_value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // 10.3.3 cont'd.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-13 17:31:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  underflow_px  =  containing_block ( ) - > width ( )  -  total_px ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:09:56 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( width . is_auto ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( margin_left . is_auto ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_left  =  zero_value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( margin_right . is_auto ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_right  =  zero_value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( underflow_px  > =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            width  =  Length ( underflow_px ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            width  =  zero_value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_right  =  Length ( margin_right . to_px ( )  +  underflow_px ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! margin_left . is_auto ( )  & &  ! margin_right . is_auto ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_right  =  Length ( margin_right . to_px ( )  +  underflow_px ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( ! margin_left . is_auto ( )  & &  margin_right . is_auto ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_right  =  Length ( underflow_px ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  if  ( margin_left . is_auto ( )  & &  ! margin_right . is_auto ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_left  =  Length ( underflow_px ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  {  // margin_left.is_auto() && margin_right.is_auto()
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            auto  half_of_the_underflow  =  Length ( underflow_px  /  2 ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_left  =  half_of_the_underflow ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            margin_right  =  half_of_the_underflow ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    rect ( ) . set_width ( width . to_px ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-04 15:50:50 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    box_model ( ) . margin ( ) . left  =  margin_left ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . margin ( ) . right  =  margin_right ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . border ( ) . left  =  border_left ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . border ( ) . right  =  border_right ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . padding ( ) . left  =  padding_left ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . padding ( ) . right  =  padding_right ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-01 07:28:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  LayoutBlock : : compute_position ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-10-07 09:23:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  style  =  this - > style ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  auto_value  =  Length ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  zero_value  =  Length ( 0 ,  Length : : Type : : Absolute ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-08 15:34:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  width  =  style . length_or_fallback ( CSS : : PropertyID : : Width ,  auto_value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:28:35 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-08 15:34:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    box_model ( ) . margin ( ) . top  =  style . length_or_fallback ( CSS : : PropertyID : : MarginTop ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . margin ( ) . bottom  =  style . length_or_fallback ( CSS : : PropertyID : : MarginBottom ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . border ( ) . top  =  style . length_or_fallback ( CSS : : PropertyID : : BorderTopWidth ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . border ( ) . bottom  =  style . length_or_fallback ( CSS : : PropertyID : : BorderBottomWidth ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . padding ( ) . top  =  style . length_or_fallback ( CSS : : PropertyID : : PaddingTop ,  zero_value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    box_model ( ) . padding ( ) . bottom  =  style . length_or_fallback ( CSS : : PropertyID : : PaddingBottom ,  zero_value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-13 17:31:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    rect ( ) . set_x ( containing_block ( ) - > x ( )  +  box_model ( ) . margin ( ) . left . to_px ( )  +  box_model ( ) . border ( ) . left . to_px ( )  +  box_model ( ) . padding ( ) . left . to_px ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:28:35 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    int  top_border  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( previous_sibling ( )  ! =  nullptr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        auto &  previous_sibling_rect  =  previous_sibling ( ) - > rect ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-04 15:50:50 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        auto &  previous_sibling_style  =  previous_sibling ( ) - > box_model ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:28:35 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        top_border  =  previous_sibling_rect . y ( )  +  previous_sibling_rect . height ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        top_border  + =  previous_sibling_style . full_margin ( ) . bottom ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-13 17:31:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        top_border  =  containing_block ( ) - > y ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:28:35 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-04 15:50:50 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    rect ( ) . set_y ( top_border  +  box_model ( ) . full_margin ( ) . top ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-01 07:28:37 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  LayoutBlock : : compute_height ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-10-07 09:23:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto &  style  =  this - > style ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-21 15:32:17 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-08 15:34:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    auto  height_property  =  style . property ( CSS : : PropertyID : : Height ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-18 08:37:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! height_property . has_value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  height_length  =  height_property . value ( ) - > to_length ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( height_length . is_absolute ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        rect ( ) . set_height ( height_length . to_px ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-20 23:00:26 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:40:37 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  LayoutBlock : : render ( RenderingContext &  context )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-10-09 21:25:29 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( ! is_visible ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-15 19:12:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    LayoutBox : : render ( context ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:40:37 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( children_are_inline ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto &  line_box  :  m_line_boxes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  ( auto &  fragment  :  line_box . fragments ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-12 15:02:53 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( context . should_show_line_box_borders ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    context . painter ( ) . draw_rect ( fragment . rect ( ) ,  Color : : Green ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                fragment . render ( context ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bool  LayoutBlock : : children_are_inline ( )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2019-10-11 23:23:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  first_child ( )  & &  first_child ( ) - > is_inline ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HitTestResult  LayoutBlock : : hit_test ( const  Point &  position )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( ! children_are_inline ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-15 22:02:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  LayoutBox : : hit_test ( position ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 15:20:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    HitTestResult  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( auto &  line_box  :  m_line_boxes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  ( auto &  fragment  :  line_box . fragments ( ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ( fragment . rect ( ) . contains ( position ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  {  fragment . layout_node ( )  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-25 12:40:37 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-10-05 23:47:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								NonnullRefPtr < StyleProperties >  LayoutBlock : : style_for_anonymous_block ( )  const  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    auto  new_style  =  StyleProperties : : create ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-08 15:34:19 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    style ( ) . for_each_property ( [ & ] ( auto  property_id ,  auto &  value )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( StyleResolver : : is_inherited_property ( property_id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            new_style - > set_property ( property_id ,  value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-05 23:47:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  new_style ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-10-13 17:24:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								LineBox &  LayoutBlock : : ensure_last_line_box ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( m_line_boxes . is_empty ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        m_line_boxes . append ( LineBox ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  m_line_boxes . last ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								LineBox &  LayoutBlock : : add_line_box ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    m_line_boxes . append ( LineBox ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  m_line_boxes . last ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}