BlockContainer.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Layout/BlockContainer.h>
  7. #include <LibWeb/Painting/PaintableBox.h>
  8. namespace Web::Layout {
  9. BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
  10. : Box(document, node, move(style))
  11. {
  12. }
  13. BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
  14. : Box(document, node, move(computed_values))
  15. {
  16. }
  17. BlockContainer::~BlockContainer() = default;
  18. bool BlockContainer::is_scrollable() const
  19. {
  20. // FIXME: Support horizontal scroll as well (overflow-x)
  21. return computed_values().overflow_y() == CSS::Overflow::Scroll;
  22. }
  23. void BlockContainer::set_scroll_offset(const Gfx::FloatPoint& offset)
  24. {
  25. // FIXME: If there is horizontal and vertical scroll ignore only part of the new offset
  26. if (offset.y() < 0 || m_scroll_offset == offset)
  27. return;
  28. m_scroll_offset = offset;
  29. set_needs_display();
  30. }
  31. Painting::PaintableWithLines const* BlockContainer::paint_box() const
  32. {
  33. return static_cast<Painting::PaintableWithLines const*>(Box::paint_box());
  34. }
  35. RefPtr<Painting::Paintable> BlockContainer::create_paintable() const
  36. {
  37. return Painting::PaintableWithLines::create(*this);
  38. }
  39. }