mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:12:44 +00:00 
			
		
		
		
	LibWeb: Create "empty" line box fragments for inline elements
In order for inline elements (e.g <span>) to contribute padding etc. to line boxes, we now create special "leading" and "trailing" fragments for Layout::InlineNode and size them according to the horizontal padding values. The height of these fragments is taken from the tallest fragment on the line. (Perhaps we should stop having per-fragment heights and just keep a single height per line box, but that's a separate issue.) In order to make things look nice, we now also adjust the height of all fragments on a line so that nobody is shorter than the CSS line-height.
This commit is contained in:
		
							parent
							
								
									311e1039b5
								
							
						
					
					
						commit
						d59ec3ab85
					
				
					 7 changed files with 56 additions and 4 deletions
				
			
		|  | @ -24,7 +24,9 @@ | |||
|  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
|  */ | ||||
| 
 | ||||
| #include <LibGfx/Painter.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/Layout/BlockBox.h> | ||||
| #include <LibWeb/Layout/InlineNode.h> | ||||
| 
 | ||||
| namespace Web::Layout { | ||||
|  | @ -39,4 +41,30 @@ InlineNode::~InlineNode() | |||
| { | ||||
| } | ||||
| 
 | ||||
| void InlineNode::split_into_lines(BlockBox& containing_block, LayoutMode layout_mode) | ||||
| { | ||||
|     if (!style().padding().left.is_undefined_or_auto()) { | ||||
|         float padding_left = style().padding().left.resolved(CSS::Length::make_px(0), *this, containing_block.width()).to_px(*this); | ||||
|         containing_block.ensure_last_line_box().add_fragment(*this, 0, 0, padding_left, 0, LineBoxFragment::Type::Leading); | ||||
|     } | ||||
| 
 | ||||
|     Node::split_into_lines(containing_block, layout_mode); | ||||
| 
 | ||||
|     if (!style().padding().right.is_undefined_or_auto()) { | ||||
|         float padding_right = style().padding().right.resolved(CSS::Length::make_px(0), *this, containing_block.width()).to_px(*this); | ||||
|         containing_block.ensure_last_line_box().add_fragment(*this, 0, 0, padding_right, 0, LineBoxFragment::Type::Trailing); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void InlineNode::paint_fragment(PaintContext& context, const LineBoxFragment& fragment, PaintPhase phase) const | ||||
| { | ||||
|     auto& painter = context.painter(); | ||||
| 
 | ||||
|     if (phase == PaintPhase::Background) { | ||||
|         auto background_color = specified_style().property(CSS::PropertyID::BackgroundColor); | ||||
|         if (background_color.has_value() && background_color.value()->is_color()) | ||||
|             painter.fill_rect(enclosing_int_rect(fragment.absolute_rect()), background_color.value()->to_color(document())); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling