BackgroundPainting.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibGfx/Painter.h>
  8. #include <LibWeb/Painting/BackgroundPainting.h>
  9. #include <LibWeb/Painting/PaintContext.h>
  10. namespace Web::Painting {
  11. void paint_background(PaintContext& context, Gfx::IntRect const& background_rect, BackgroundData const& background_data, BorderRadiusData const& border_radius)
  12. {
  13. // FIXME: Support elliptical corners
  14. context.painter().fill_rect_with_rounded_corners(background_rect, background_data.color, border_radius.top_left, border_radius.top_right, border_radius.bottom_right, border_radius.bottom_left);
  15. // FIXME: Support multiple background layers
  16. if (background_data.image) {
  17. auto image_rect = background_rect;
  18. switch (background_data.repeat_x) {
  19. case CSS::Repeat::Round:
  20. case CSS::Repeat::Space:
  21. // FIXME: Support 'round' and 'space'. Fall through to 'repeat' since that most closely resembles these.
  22. case CSS::Repeat::Repeat:
  23. // The background rect is already sized to align with 'repeat'.
  24. break;
  25. case CSS::Repeat::NoRepeat:
  26. image_rect.set_width(background_data.image->width());
  27. break;
  28. }
  29. switch (background_data.repeat_y) {
  30. case CSS::Repeat::Round:
  31. case CSS::Repeat::Space:
  32. // FIXME: Support 'round' and 'space'. Fall through to 'repeat' since that most closely resembles these.
  33. case CSS::Repeat::Repeat:
  34. // The background rect is already sized to align with 'repeat'.
  35. break;
  36. case CSS::Repeat::NoRepeat:
  37. image_rect.set_height(background_data.image->height());
  38. break;
  39. }
  40. // FIXME: Handle rounded corners
  41. context.painter().blit_tiled(image_rect, *background_data.image, background_data.image->rect());
  42. }
  43. }
  44. }