NestedBrowsingContextPaintable.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Debug.h>
  7. #include <LibWeb/HTML/BrowsingContextContainer.h>
  8. #include <LibWeb/Layout/FrameBox.h>
  9. #include <LibWeb/Layout/InitialContainingBlock.h>
  10. #include <LibWeb/Painting/NestedBrowsingContextPaintable.h>
  11. namespace Web::Painting {
  12. NonnullRefPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::create(Layout::FrameBox const& layout_box)
  13. {
  14. return adopt_ref(*new NestedBrowsingContextPaintable(layout_box));
  15. }
  16. NestedBrowsingContextPaintable::NestedBrowsingContextPaintable(Layout::FrameBox const& layout_box)
  17. : PaintableBox(layout_box)
  18. {
  19. }
  20. Layout::FrameBox const& NestedBrowsingContextPaintable::layout_box() const
  21. {
  22. return static_cast<Layout::FrameBox const&>(layout_node());
  23. }
  24. void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase phase) const
  25. {
  26. PaintableBox::paint(context, phase);
  27. if (phase == PaintPhase::Foreground) {
  28. auto* hosted_document = layout_box().dom_node().content_document_without_origin_check();
  29. if (!hosted_document)
  30. return;
  31. auto* hosted_layout_tree = hosted_document->layout_node();
  32. if (!hosted_layout_tree)
  33. return;
  34. context.painter().save();
  35. auto old_viewport_rect = context.viewport_rect();
  36. context.painter().add_clip_rect(enclosing_int_rect(absolute_rect()));
  37. context.painter().translate(absolute_x(), absolute_y());
  38. context.set_viewport_rect({ {}, layout_box().dom_node().nested_browsing_context()->size() });
  39. const_cast<Layout::InitialContainingBlock*>(hosted_layout_tree)->paint_all_phases(context);
  40. context.set_viewport_rect(old_viewport_rect);
  41. context.painter().restore();
  42. if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
  43. if (layout_box().dom_node().nested_browsing_context()->is_focused_context()) {
  44. context.painter().draw_rect(absolute_rect().to_type<int>(), Color::Cyan);
  45. }
  46. }
  47. }
  48. }
  49. }