CheckBoxPaintable.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGUI/Event.h>
  7. #include <LibGfx/StylePainter.h>
  8. #include <LibWeb/HTML/BrowsingContext.h>
  9. #include <LibWeb/HTML/HTMLImageElement.h>
  10. #include <LibWeb/Layout/CheckBox.h>
  11. #include <LibWeb/Layout/Label.h>
  12. #include <LibWeb/Painting/CheckBoxPaintable.h>
  13. namespace Web::Painting {
  14. NonnullRefPtr<CheckBoxPaintable> CheckBoxPaintable::create(Layout::CheckBox const& layout_box)
  15. {
  16. return adopt_ref(*new CheckBoxPaintable(layout_box));
  17. }
  18. CheckBoxPaintable::CheckBoxPaintable(Layout::CheckBox const& layout_box)
  19. : LabelablePaintable(layout_box)
  20. {
  21. }
  22. Layout::CheckBox const& CheckBoxPaintable::layout_box() const
  23. {
  24. return static_cast<Layout::CheckBox const&>(layout_node());
  25. }
  26. Layout::CheckBox& CheckBoxPaintable::layout_box()
  27. {
  28. return static_cast<Layout::CheckBox&>(layout_node());
  29. }
  30. void CheckBoxPaintable::paint(PaintContext& context, PaintPhase phase) const
  31. {
  32. if (!is_visible())
  33. return;
  34. PaintableBox::paint(context, phase);
  35. auto const& checkbox = static_cast<HTML::HTMLInputElement const&>(layout_box().dom_node());
  36. if (phase == PaintPhase::Foreground)
  37. Gfx::StylePainter::paint_check_box(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), layout_box().dom_node().enabled(), checkbox.checked(), being_pressed());
  38. }
  39. }