mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-11-04 07:10:57 +00:00 
			
		
		
		
	This reverts commit 76daba3069.
We're going to need separate types for the JS-exposed style values, so
it doesn't make sense for us to match their names with our internal
types.
		
	
			
		
			
				
	
	
		
			44 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
 | 
						|
 *
 | 
						|
 * SPDX-License-Identifier: BSD-2-Clause
 | 
						|
 */
 | 
						|
 | 
						|
#include <AK/String.h>
 | 
						|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
 | 
						|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
 | 
						|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
 | 
						|
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
 | 
						|
#include <LibWeb/CSS/StyleValues/TranslationStyleValue.h>
 | 
						|
 | 
						|
namespace Web::CSS {
 | 
						|
 | 
						|
// https://www.w3.org/TR/2021/WD-css-transforms-2-20211109/#individual-transform-serialization
 | 
						|
String TranslationStyleValue::to_string(SerializationMode) const
 | 
						|
{
 | 
						|
    auto resolve_to_string = [](LengthPercentage const& value) -> Optional<String> {
 | 
						|
        if (value.is_length()) {
 | 
						|
            if (value.length().raw_value() == 0)
 | 
						|
                return {};
 | 
						|
        }
 | 
						|
        if (value.is_percentage()) {
 | 
						|
            if (value.percentage().value() == 0)
 | 
						|
                return {};
 | 
						|
        }
 | 
						|
        return value.to_string();
 | 
						|
    };
 | 
						|
 | 
						|
    auto x_value = resolve_to_string(m_properties.x);
 | 
						|
    auto y_value = resolve_to_string(m_properties.y);
 | 
						|
 | 
						|
    StringBuilder builder;
 | 
						|
    builder.append(x_value.value_or("0px"_string));
 | 
						|
    if (y_value.has_value()) {
 | 
						|
        builder.append(" "sv);
 | 
						|
        builder.append(y_value.value());
 | 
						|
    }
 | 
						|
 | 
						|
    return builder.to_string_without_validation();
 | 
						|
}
 | 
						|
 | 
						|
}
 |