NestedBrowsingContextPaintable.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if (!layout_box().is_visible())
  28. return;
  29. PaintableBox::paint(context, phase);
  30. if (phase == PaintPhase::Foreground) {
  31. auto absolute_rect = this->absolute_rect();
  32. auto clip_rect = context.rounded_device_rect(absolute_rect);
  33. ScopedCornerRadiusClip corner_clip { context, context.painter(), clip_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
  34. auto* hosted_document = layout_box().dom_node().content_document_without_origin_check();
  35. if (!hosted_document)
  36. return;
  37. auto* hosted_layout_tree = hosted_document->layout_node();
  38. if (!hosted_layout_tree)
  39. return;
  40. context.painter().save();
  41. auto old_viewport_rect = context.device_viewport_rect();
  42. context.painter().add_clip_rect(clip_rect.to_type<int>());
  43. context.painter().translate(absolute_rect.x().value(), absolute_rect.y().value());
  44. context.set_device_viewport_rect({ {}, context.enclosing_device_size(layout_box().dom_node().nested_browsing_context()->size()) });
  45. const_cast<Layout::InitialContainingBlock*>(hosted_layout_tree)->paint_all_phases(context);
  46. context.set_device_viewport_rect(old_viewport_rect);
  47. context.painter().restore();
  48. if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
  49. if (layout_box().dom_node().nested_browsing_context()->is_focused_context()) {
  50. context.painter().draw_rect(clip_rect.to_type<int>(), Color::Cyan);
  51. }
  52. }
  53. }
  54. }
  55. }