ClippableAndScrollable.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Painting/ClippableAndScrollable.h>
  7. namespace Web::Painting {
  8. Optional<int> ClippableAndScrollable::scroll_frame_id() const
  9. {
  10. if (m_enclosing_scroll_frame)
  11. return m_enclosing_scroll_frame->id;
  12. return {};
  13. }
  14. Optional<CSSPixelPoint> ClippableAndScrollable::enclosing_scroll_frame_offset() const
  15. {
  16. if (m_enclosing_scroll_frame)
  17. return m_enclosing_scroll_frame->offset;
  18. return {};
  19. }
  20. Optional<CSSPixelRect> ClippableAndScrollable::clip_rect() const
  21. {
  22. if (m_enclosing_clip_frame) {
  23. auto rect = m_enclosing_clip_frame->rect();
  24. // NOTE: Since the painting command executor applies a CSS transform and the clip rect is calculated
  25. // with this transform taken into account, we need to remove the transform from the clip rect.
  26. // Otherwise, the transform will be applied twice to the clip rect.
  27. // Similarly, for hit-testing, the transform must be removed from the clip rectangle since the position
  28. // includes the transform.
  29. auto combined_transform = compute_combined_css_transform_for_clippable_and_scrollable();
  30. rect.translate_by(-combined_transform.translation().to_type<CSSPixels>());
  31. return rect;
  32. }
  33. return {};
  34. }
  35. Span<BorderRadiiClip const> ClippableAndScrollable::border_radii_clips() const
  36. {
  37. if (m_enclosing_clip_frame)
  38. return m_enclosing_clip_frame->border_radii_clips();
  39. return {};
  40. }
  41. }