NestedBrowsingContextPaintable.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/BorderRadiusCornerClipper.h>
  11. #include <LibWeb/Painting/NestedBrowsingContextPaintable.h>
  12. namespace Web::Painting {
  13. NonnullRefPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::create(Layout::FrameBox const& layout_box)
  14. {
  15. return adopt_ref(*new NestedBrowsingContextPaintable(layout_box));
  16. }
  17. NestedBrowsingContextPaintable::NestedBrowsingContextPaintable(Layout::FrameBox const& layout_box)
  18. : PaintableBox(layout_box)
  19. {
  20. }
  21. Layout::FrameBox const& NestedBrowsingContextPaintable::layout_box() const
  22. {
  23. return static_cast<Layout::FrameBox const&>(layout_node());
  24. }
  25. void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase phase) const
  26. {
  27. PaintableBox::paint(context, phase);
  28. if (phase == PaintPhase::Foreground) {
  29. auto clip_rect = absolute_rect().to_rounded<int>();
  30. ScopedCornerRadiusClip corner_clip { context.painter(), clip_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
  31. auto* hosted_document = layout_box().dom_node().content_document_without_origin_check();
  32. if (!hosted_document)
  33. return;
  34. auto* hosted_layout_tree = hosted_document->layout_node();
  35. if (!hosted_layout_tree)
  36. return;
  37. context.painter().save();
  38. auto old_viewport_rect = context.viewport_rect();
  39. context.painter().add_clip_rect(clip_rect);
  40. context.painter().translate(absolute_x(), absolute_y());
  41. context.set_viewport_rect({ {}, layout_box().dom_node().nested_browsing_context()->size() });
  42. const_cast<Layout::InitialContainingBlock*>(hosted_layout_tree)->paint_all_phases(context);
  43. context.set_viewport_rect(old_viewport_rect);
  44. context.painter().restore();
  45. if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
  46. if (layout_box().dom_node().nested_browsing_context()->is_focused_context()) {
  47. context.painter().draw_rect(absolute_rect().to_type<int>(), Color::Cyan);
  48. }
  49. }
  50. }
  51. }
  52. }