ScrollOptions.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/WindowGlobalMixin.h>
  8. namespace Web::HTML {
  9. // https://w3c.github.io/csswg-drafts/cssom-view/#dictdef-scrolloptions
  10. struct ScrollOptions {
  11. Bindings::ScrollBehavior behavior { Bindings::ScrollBehavior::Auto };
  12. };
  13. // https://drafts.csswg.org/cssom-view/#normalize-non-finite-values
  14. [[nodiscard]] inline double normalize_non_finite_values(double value)
  15. {
  16. // When asked to normalize non-finite values for a value x, if x is one of the three special floating point
  17. // literal values (Infinity, -Infinity or NaN), then x must be changed to the value 0. [WEBIDL]
  18. if (isinf(value) || isnan(value))
  19. return 0;
  20. return value;
  21. }
  22. // https://drafts.csswg.org/cssom-view/#normalize-non-finite-values
  23. [[nodiscard]] inline double normalize_non_finite_values(Optional<double> const& value)
  24. {
  25. if (!value.has_value())
  26. return 0;
  27. return normalize_non_finite_values(value.value());
  28. }
  29. }