StackingContext.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibGfx/Matrix4x4.h>
  9. #include <LibWeb/Layout/Node.h>
  10. #include <LibWeb/Painting/Paintable.h>
  11. namespace Web::Painting {
  12. class StackingContext {
  13. public:
  14. StackingContext(Layout::Box&, StackingContext* parent);
  15. StackingContext* parent() { return m_parent; }
  16. StackingContext const* parent() const { return m_parent; }
  17. PaintableBox const& paintable() const { return *m_box->paint_box(); }
  18. enum class StackingContextPaintPhase {
  19. BackgroundAndBorders,
  20. Floats,
  21. BackgroundAndBordersForInlineLevelAndReplaced,
  22. Foreground,
  23. FocusAndOverlay,
  24. };
  25. void paint_descendants(PaintContext&, Layout::Node const&, StackingContextPaintPhase) const;
  26. void paint(PaintContext&) const;
  27. Optional<HitTestResult> hit_test(CSSPixelPoint, HitTestType) const;
  28. Gfx::FloatMatrix4x4 const& transform_matrix() const { return m_transform; }
  29. Gfx::AffineTransform affine_transform_matrix() const;
  30. void dump(int indent = 0) const;
  31. void sort();
  32. private:
  33. JS::NonnullGCPtr<Layout::Box> m_box;
  34. Gfx::FloatMatrix4x4 m_transform;
  35. Gfx::FloatPoint m_transform_origin;
  36. StackingContext* const m_parent { nullptr };
  37. Vector<StackingContext*> m_children;
  38. void paint_internal(PaintContext&) const;
  39. Gfx::FloatMatrix4x4 get_transformation_matrix(CSS::Transformation const& transformation) const;
  40. Gfx::FloatMatrix4x4 combine_transformations(Vector<CSS::Transformation> const& transformations) const;
  41. Gfx::FloatPoint transform_origin() const { return m_transform_origin; }
  42. Gfx::FloatPoint compute_transform_origin() const;
  43. };
  44. }