Box.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. if (paint_box())
  29. browsing_context().set_needs_display(paint_box()->absolute_rect());
  30. }
  31. bool Box::is_body() const
  32. {
  33. return dom_node() && dom_node() == document().body();
  34. }
  35. RefPtr<Painting::Paintable> Box::create_paintable() const
  36. {
  37. return Painting::PaintableBox::create(*this);
  38. }
  39. Painting::PaintableBox const* Box::paint_box() const
  40. {
  41. return static_cast<Painting::PaintableBox const*>(Node::paintable());
  42. }
  43. }