CalculatedOr.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "CalculatedOr.h"
  7. #include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
  8. #include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
  9. #include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
  10. #include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
  11. #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
  12. #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
  13. #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
  14. #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
  15. #include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
  16. namespace Web::CSS {
  17. Angle AngleOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  18. {
  19. return calculated->resolve_angle().value();
  20. }
  21. NonnullRefPtr<StyleValue> AngleOrCalculated::create_style_value() const
  22. {
  23. return AngleStyleValue::create(value());
  24. }
  25. Flex FlexOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  26. {
  27. return calculated->resolve_flex().value();
  28. }
  29. NonnullRefPtr<StyleValue> FlexOrCalculated::create_style_value() const
  30. {
  31. return FlexStyleValue::create(value());
  32. }
  33. Frequency FrequencyOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  34. {
  35. return calculated->resolve_frequency().value();
  36. }
  37. NonnullRefPtr<StyleValue> FrequencyOrCalculated::create_style_value() const
  38. {
  39. return FrequencyStyleValue::create(value());
  40. }
  41. i64 IntegerOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  42. {
  43. return calculated->resolve_integer().value();
  44. }
  45. NonnullRefPtr<StyleValue> IntegerOrCalculated::create_style_value() const
  46. {
  47. return IntegerStyleValue::create(value());
  48. }
  49. Length LengthOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const& layout_node) const
  50. {
  51. return calculated->resolve_length(layout_node).value();
  52. }
  53. Length LengthOrCalculated::resolved(Length::ResolutionContext const& context) const
  54. {
  55. if (is_calculated())
  56. return calculated()->resolve_length(context).value();
  57. return value();
  58. }
  59. NonnullRefPtr<StyleValue> LengthOrCalculated::create_style_value() const
  60. {
  61. return LengthStyleValue::create(value());
  62. }
  63. double NumberOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  64. {
  65. return calculated->resolve_number().value();
  66. }
  67. NonnullRefPtr<StyleValue> NumberOrCalculated::create_style_value() const
  68. {
  69. return NumberStyleValue::create(value());
  70. }
  71. Percentage PercentageOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  72. {
  73. return calculated->resolve_percentage().value();
  74. }
  75. NonnullRefPtr<StyleValue> PercentageOrCalculated::create_style_value() const
  76. {
  77. return PercentageStyleValue::create(value());
  78. }
  79. Resolution ResolutionOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  80. {
  81. return calculated->resolve_resolution().value();
  82. }
  83. NonnullRefPtr<StyleValue> ResolutionOrCalculated::create_style_value() const
  84. {
  85. return ResolutionStyleValue::create(value());
  86. }
  87. Time TimeOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue> const& calculated, Layout::Node const&) const
  88. {
  89. return calculated->resolve_time().value();
  90. }
  91. NonnullRefPtr<StyleValue> TimeOrCalculated::create_style_value() const
  92. {
  93. return TimeStyleValue::create(value());
  94. }
  95. }