Label.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public:
  13. Label(DOM::Document&, HTML::HTMLLabelElement*, NonnullRefPtr<CSS::StyleProperties>);
  14. virtual ~Label() override;
  15. static bool is_inside_associated_label(LabelableNode const&, CSSPixelPoint);
  16. static bool is_associated_label_hovered(LabelableNode const&);
  17. const HTML::HTMLLabelElement& dom_node() const { return static_cast<const HTML::HTMLLabelElement&>(*BlockContainer::dom_node()); }
  18. HTML::HTMLLabelElement& dom_node() { return static_cast<HTML::HTMLLabelElement&>(*BlockContainer::dom_node()); }
  19. void handle_mousedown_on_label(Badge<Painting::TextPaintable>, CSSPixelPoint, unsigned button);
  20. void handle_mouseup_on_label(Badge<Painting::TextPaintable>, CSSPixelPoint, unsigned button);
  21. void handle_mousemove_on_label(Badge<Painting::TextPaintable>, CSSPixelPoint, unsigned button);
  22. LabelableNode* labeled_control();
  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. }