NestedBrowsingContextPaintable.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.translated(enclosing_scroll_frame_offset()));
  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.display_list_recorder().save();
  43. context.display_list_recorder().add_clip_rect(clip_rect.to_type<int>());
  44. HTML::Navigable::PaintConfig paint_config;
  45. paint_config.paint_overlay = context.should_paint_overlay();
  46. paint_config.should_show_line_box_borders = context.should_show_line_box_borders();
  47. paint_config.has_focus = context.has_focus();
  48. auto display_list = const_cast<DOM::Document*>(hosted_document)->navigable()->record_display_list(paint_config);
  49. context.display_list_recorder().paint_nested_display_list(display_list, context.enclosing_device_rect(absolute_rect).to_type<int>());
  50. context.display_list_recorder().restore();
  51. if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
  52. if (layout_box().dom_node().content_navigable()->is_focused()) {
  53. context.display_list_recorder().draw_rect(clip_rect.to_type<int>(), Color::Cyan);
  54. }
  55. }
  56. }
  57. }
  58. }