LayoutBox.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <LibDraw/FloatRect.h>
  3. #include <LibHTML/Layout/LayoutNode.h>
  4. class LayoutBox : public LayoutNodeWithStyleAndBoxModelMetrics {
  5. public:
  6. const FloatRect& rect() const { return m_rect; }
  7. FloatRect& rect() { return m_rect; }
  8. void set_rect(const FloatRect& rect) { m_rect = rect; }
  9. float x() const { return rect().x(); }
  10. float y() const { return rect().y(); }
  11. float width() const { return rect().width(); }
  12. float height() const { return rect().height(); }
  13. FloatSize size() const { return rect().size(); }
  14. FloatPoint position() const { return rect().location(); }
  15. virtual HitTestResult hit_test(const Point& position) const override;
  16. virtual void set_needs_display() override;
  17. bool is_body() const;
  18. protected:
  19. LayoutBox(const Node* node, NonnullRefPtr<StyleProperties> style)
  20. : LayoutNodeWithStyleAndBoxModelMetrics(node, move(style))
  21. {
  22. }
  23. virtual void render(RenderingContext&) override;
  24. private:
  25. virtual bool is_box() const override { return true; }
  26. enum class Edge {
  27. Top,
  28. Right,
  29. Bottom,
  30. Left,
  31. };
  32. void paint_border(RenderingContext&, Edge, const FloatRect&, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id);
  33. FloatRect m_rect;
  34. };
  35. template<>
  36. inline bool is<LayoutBox>(const LayoutNode& node)
  37. {
  38. return node.is_box();
  39. }