mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:42:44 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			63 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  * Copyright (c) 2021, Tobias Christiansen <tobi@tobyase.de>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibGfx/Painter.h>
 | |
| #include <LibWeb/Layout/ListItemMarkerBox.h>
 | |
| 
 | |
| namespace Web::Layout {
 | |
| 
 | |
| ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType style_type, size_t index)
 | |
|     : Box(document, nullptr, CSS::StyleProperties::create())
 | |
|     , m_list_style_type(style_type)
 | |
|     , m_index(index)
 | |
| {
 | |
| }
 | |
| 
 | |
| ListItemMarkerBox::~ListItemMarkerBox()
 | |
| {
 | |
| }
 | |
| 
 | |
| void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase)
 | |
| {
 | |
|     if (phase != PaintPhase::Foreground)
 | |
|         return;
 | |
| 
 | |
|     // FIXME: It would be nicer to not have to go via the parent here to get our inherited style.
 | |
|     auto color = parent()->computed_values().color();
 | |
| 
 | |
|     auto enclosing = enclosing_int_rect(absolute_rect());
 | |
|     int marker_width = (int)enclosing.height() / 2;
 | |
|     Gfx::IntRect marker_rect { 0, 0, marker_width, marker_width };
 | |
|     marker_rect.center_within(enclosing);
 | |
| 
 | |
|     switch (m_list_style_type) {
 | |
|     case CSS::ListStyleType::Square:
 | |
|         context.painter().fill_rect(marker_rect, color);
 | |
|         break;
 | |
|     case CSS::ListStyleType::Circle:
 | |
|         // For some reason for draw_ellipse() the ellipse is outside of the rect while for fill_ellipse() the ellipse is inside.
 | |
|         // Scale the marker_rect with sqrt(2) to get an ellipse arc (circle) that appears as if it was inside of the marker_rect.
 | |
|         marker_rect.set_height(marker_rect.height() / 1.41);
 | |
|         marker_rect.set_width(marker_rect.width() / 1.41);
 | |
|         marker_rect.center_within(enclosing);
 | |
|         context.painter().draw_ellipse_intersecting(marker_rect, color);
 | |
|         break;
 | |
|     case CSS::ListStyleType::Decimal:
 | |
|         context.painter().draw_text(enclosing, String::formatted("{}.", m_index), Gfx::TextAlignment::Center);
 | |
|         break;
 | |
|     case CSS::ListStyleType::Disc:
 | |
|         context.painter().fill_ellipse(marker_rect, color);
 | |
|         break;
 | |
|     case CSS::ListStyleType::None:
 | |
|         return;
 | |
| 
 | |
|     default:
 | |
|         VERIFY_NOT_REACHED();
 | |
|     }
 | |
| }
 | |
| 
 | |
| }
 |