Box.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibGfx/Painter.h>
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/HTML/HTMLHtmlElement.h>
  10. #include <LibWeb/Layout/BlockContainer.h>
  11. #include <LibWeb/Layout/Box.h>
  12. #include <LibWeb/Layout/FormattingContext.h>
  13. #include <LibWeb/Painting/PaintableBox.h>
  14. namespace Web::Layout {
  15. Box::Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
  16. : NodeWithStyleAndBoxModelMetrics(document, node, move(style))
  17. {
  18. }
  19. Box::Box(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
  20. : NodeWithStyleAndBoxModelMetrics(document, node, move(computed_values))
  21. {
  22. }
  23. Box::~Box()
  24. {
  25. }
  26. void Box::set_needs_display()
  27. {
  28. // FIXME: Make `set_needs_display` take CSSPixels
  29. if (paint_box())
  30. browsing_context().set_needs_display(enclosing_int_rect(paint_box()->absolute_rect().to_type<float>()));
  31. }
  32. bool Box::is_body() const
  33. {
  34. return dom_node() && dom_node() == document().body();
  35. }
  36. RefPtr<Painting::Paintable> Box::create_paintable() const
  37. {
  38. return Painting::PaintableBox::create(*this);
  39. }
  40. Painting::PaintableBox const* Box::paint_box() const
  41. {
  42. return static_cast<Painting::PaintableBox const*>(Node::paintable());
  43. }
  44. }