ProgressPaintable.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/StylePainter.h>
  7. #include <LibWeb/Painting/ProgressPaintable.h>
  8. namespace Web::Painting {
  9. JS::NonnullGCPtr<ProgressPaintable> ProgressPaintable::create(Layout::Progress const& layout_box)
  10. {
  11. return layout_box.heap().allocate_without_realm<ProgressPaintable>(layout_box);
  12. }
  13. ProgressPaintable::ProgressPaintable(Layout::Progress const& layout_box)
  14. : PaintableBox(layout_box)
  15. {
  16. }
  17. Layout::Progress const& ProgressPaintable::layout_box() const
  18. {
  19. return static_cast<Layout::Progress const&>(layout_node());
  20. }
  21. void ProgressPaintable::paint(PaintContext& context, PaintPhase phase) const
  22. {
  23. if (!is_visible())
  24. return;
  25. if (phase == PaintPhase::Foreground) {
  26. auto progress_rect = context.rounded_device_rect(absolute_rect());
  27. auto min_frame_thickness = context.rounded_device_pixels(3);
  28. auto frame_thickness = min(min(progress_rect.width(), progress_rect.height()) / 6, min_frame_thickness);
  29. context.recording_painter().paint_progressbar(
  30. progress_rect.to_type<int>(),
  31. progress_rect.shrunken(frame_thickness, frame_thickness).to_type<int>(),
  32. context.palette(),
  33. 0,
  34. round_to<int>(layout_box().dom_node().max()),
  35. round_to<int>(layout_box().dom_node().value()),
  36. ""sv);
  37. }
  38. }
  39. }