Label.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/HTML/HTMLLabelElement.h>
  8. #include <LibWeb/Layout/BlockContainer.h>
  9. namespace Web::Layout {
  10. class Label final : public BlockContainer {
  11. JS_CELL(Label, BlockContainer);
  12. JS_DECLARE_ALLOCATOR(Label);
  13. public:
  14. Label(DOM::Document&, HTML::HTMLLabelElement*, CSS::StyleProperties);
  15. virtual ~Label() override;
  16. static bool is_inside_associated_label(LabelableNode const&, CSSPixelPoint);
  17. static bool is_associated_label_hovered(LabelableNode const&);
  18. const HTML::HTMLLabelElement& dom_node() const { return static_cast<const HTML::HTMLLabelElement&>(*BlockContainer::dom_node()); }
  19. HTML::HTMLLabelElement& dom_node() { return static_cast<HTML::HTMLLabelElement&>(*BlockContainer::dom_node()); }
  20. void handle_mousedown_on_label(Badge<Painting::TextPaintable>, CSSPixelPoint, unsigned button);
  21. void handle_mouseup_on_label(Badge<Painting::TextPaintable>, CSSPixelPoint, unsigned button);
  22. void handle_mousemove_on_label(Badge<Painting::TextPaintable>, CSSPixelPoint, unsigned button);
  23. private:
  24. virtual bool is_label() const override { return true; }
  25. static Label const* label_for_control_node(LabelableNode const&);
  26. bool m_tracking_mouse { false };
  27. };
  28. template<>
  29. inline bool Node::fast_is<Label>() const { return is_label(); }
  30. }