Serenity Operating System
at master 58 lines 1.3 kB view raw
1/* 2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibWeb/Layout/AvailableSpace.h> 8#include <math.h> 9 10namespace Web::Layout { 11 12AvailableSize AvailableSize::make_definite(CSSPixels value) 13{ 14 return AvailableSize { Type::Definite, value }; 15} 16 17AvailableSize AvailableSize::make_indefinite() 18{ 19 return AvailableSize { Type::Indefinite, INFINITY }; 20} 21 22AvailableSize AvailableSize::make_min_content() 23{ 24 return AvailableSize { Type::MinContent, 0 }; 25} 26 27AvailableSize AvailableSize::make_max_content() 28{ 29 return AvailableSize { Type::MaxContent, INFINITY }; 30} 31 32DeprecatedString AvailableSize::to_deprecated_string() const 33{ 34 switch (m_type) { 35 case Type::Definite: 36 return DeprecatedString::formatted("definite({})", m_value); 37 case Type::Indefinite: 38 return "indefinite"; 39 case Type::MinContent: 40 return "min-content"; 41 case Type::MaxContent: 42 return "max-content"; 43 } 44 VERIFY_NOT_REACHED(); 45} 46 47DeprecatedString AvailableSpace::to_deprecated_string() const 48{ 49 return DeprecatedString::formatted("{} x {}", width, height); 50} 51 52AvailableSize::AvailableSize(Type type, CSSPixels value) 53 : m_type(type) 54 , m_value(value) 55{ 56} 57 58}