NestedBrowsingContextPaintable.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/NavigableContainer.h>
  8. #include <LibWeb/Layout/FrameBox.h>
  9. #include <LibWeb/Layout/Viewport.h>
  10. #include <LibWeb/Painting/BorderRadiusCornerClipper.h>
  11. #include <LibWeb/Painting/NestedBrowsingContextPaintable.h>
  12. #include <LibWeb/Painting/ViewportPaintable.h>
  13. namespace Web::Painting {
  14. JS_DEFINE_ALLOCATOR(NestedBrowsingContextPaintable);
  15. JS::NonnullGCPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::create(Layout::FrameBox const& layout_box)
  16. {
  17. return layout_box.heap().allocate_without_realm<NestedBrowsingContextPaintable>(layout_box);
  18. }
  19. NestedBrowsingContextPaintable::NestedBrowsingContextPaintable(Layout::FrameBox const& layout_box)
  20. : PaintableBox(layout_box)
  21. {
  22. }
  23. Layout::FrameBox const& NestedBrowsingContextPaintable::layout_box() const
  24. {
  25. return static_cast<Layout::FrameBox const&>(layout_node());
  26. }
  27. void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase phase) const
  28. {
  29. if (!is_visible())
  30. return;
  31. PaintableBox::paint(context, phase);
  32. if (phase == PaintPhase::Foreground) {
  33. auto absolute_rect = this->absolute_rect();
  34. auto clip_rect = context.rounded_device_rect(absolute_rect);
  35. ScopedCornerRadiusClip corner_clip { context, clip_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
  36. auto const* hosted_document = layout_box().dom_node().content_document_without_origin_check();
  37. if (!hosted_document)
  38. return;
  39. auto const* hosted_paint_tree = hosted_document->paintable();
  40. if (!hosted_paint_tree)
  41. return;
  42. context.recording_painter().save();
  43. context.recording_painter().add_clip_rect(clip_rect.to_type<int>());
  44. auto absolute_device_rect = context.enclosing_device_rect(absolute_rect);
  45. context.recording_painter().translate(absolute_device_rect.x().value(), absolute_device_rect.y().value());
  46. HTML::Navigable::PaintConfig paint_config;
  47. paint_config.paint_overlay = context.should_paint_overlay();
  48. paint_config.should_show_line_box_borders = context.should_show_line_box_borders();
  49. paint_config.has_focus = context.has_focus();
  50. const_cast<DOM::Document*>(hosted_document)->navigable()->record_display_list(context.recording_painter(), paint_config);
  51. context.recording_painter().restore();
  52. if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
  53. if (layout_box().dom_node().content_navigable()->is_focused()) {
  54. context.recording_painter().draw_rect(clip_rect.to_type<int>(), Color::Cyan);
  55. }
  56. }
  57. }
  58. }
  59. }