BlockBox.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Layout/Box.h>
  8. #include <LibWeb/Layout/LineBox.h>
  9. namespace Web::Layout {
  10. class BlockBox : public Box {
  11. public:
  12. BlockBox(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
  13. BlockBox(DOM::Document&, DOM::Node*, CSS::ComputedValues);
  14. virtual ~BlockBox() override;
  15. virtual void paint(PaintContext&, PaintPhase) override;
  16. virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
  17. BlockBox* previous_sibling() { return verify_cast<BlockBox>(Node::previous_sibling()); }
  18. const BlockBox* previous_sibling() const { return verify_cast<BlockBox>(Node::previous_sibling()); }
  19. BlockBox* next_sibling() { return verify_cast<BlockBox>(Node::next_sibling()); }
  20. const BlockBox* next_sibling() const { return verify_cast<BlockBox>(Node::next_sibling()); }
  21. template<typename Callback>
  22. void for_each_fragment(Callback);
  23. template<typename Callback>
  24. void for_each_fragment(Callback) const;
  25. virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;
  26. bool is_scrollable() const;
  27. const Gfx::FloatPoint& scroll_offset() const { return m_scroll_offset; }
  28. void set_scroll_offset(const Gfx::FloatPoint&);
  29. private:
  30. virtual bool is_block_box() const final { return true; }
  31. virtual bool wants_mouse_events() const override { return false; }
  32. virtual bool handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta) override;
  33. bool should_clip_overflow() const;
  34. Gfx::FloatPoint m_scroll_offset;
  35. };
  36. template<>
  37. inline bool Node::fast_is<BlockBox>() const { return is_block_box(); }
  38. template<typename Callback>
  39. void BlockBox::for_each_fragment(Callback callback)
  40. {
  41. for (auto& line_box : line_boxes()) {
  42. for (auto& fragment : line_box.fragments()) {
  43. if (callback(fragment) == IterationDecision::Break)
  44. return;
  45. }
  46. }
  47. }
  48. template<typename Callback>
  49. void BlockBox::for_each_fragment(Callback callback) const
  50. {
  51. for (auto& line_box : line_boxes()) {
  52. for (auto& fragment : line_box.fragments()) {
  53. if (callback(fragment) == IterationDecision::Break)
  54. return;
  55. }
  56. }
  57. }
  58. }