Box.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, 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. if (!is_inline()) {
  29. browsing_context().set_needs_display(enclosing_int_rect(paint_box()->absolute_rect()));
  30. return;
  31. }
  32. Node::set_needs_display();
  33. }
  34. bool Box::is_body() const
  35. {
  36. return dom_node() && dom_node() == document().body();
  37. }
  38. RefPtr<Painting::Paintable> Box::create_paintable() const
  39. {
  40. return Painting::PaintableBox::create(*this);
  41. }
  42. Painting::PaintableBox const* Box::paint_box() const
  43. {
  44. return static_cast<Painting::PaintableBox const*>(Node::paintable());
  45. }
  46. }