NestedBrowsingContextPaintable.cpp 2.7 KB

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