Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / html / HTMLLabelElement.h
blobf6c574cebe80b18d91a8ca9dc932acd57c198895
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 * Declaration of HTML <label> elements.
9 */
10 #ifndef HTMLLabelElement_h
11 #define HTMLLabelElement_h
13 #include "mozilla/Attributes.h"
14 #include "nsGenericHTMLElement.h"
16 namespace mozilla {
17 class EventChainPostVisitor;
18 namespace dom {
20 class HTMLLabelElement final : public nsGenericHTMLElement {
21 public:
22 explicit HTMLLabelElement(
23 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
24 : nsGenericHTMLElement(std::move(aNodeInfo)), mHandlingEvent(false) {}
26 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLLabelElement, label)
28 // nsISupports
29 NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLLabelElement, nsGenericHTMLElement)
31 // Element
32 virtual bool IsInteractiveHTMLContent() const override { return true; }
34 HTMLFormElement* GetForm() const;
35 void GetHtmlFor(nsString& aHtmlFor) {
36 GetHTMLAttr(nsGkAtoms::_for, aHtmlFor);
38 void SetHtmlFor(const nsAString& aHtmlFor) {
39 SetHTMLAttr(nsGkAtoms::_for, aHtmlFor);
41 nsGenericHTMLElement* GetControl() const { return GetLabeledElement(); }
43 using nsGenericHTMLElement::Focus;
44 virtual void Focus(const FocusOptions& aOptions,
45 const mozilla::dom::CallerType aCallerType,
46 ErrorResult& aError) override;
48 // nsIContent
49 MOZ_CAN_RUN_SCRIPT_BOUNDARY
50 virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
51 MOZ_CAN_RUN_SCRIPT
52 virtual Result<bool, nsresult> PerformAccesskey(
53 bool aKeyCausesActivation, bool aIsTrustedEvent) override;
54 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
56 nsGenericHTMLElement* GetLabeledElement() const;
58 protected:
59 virtual ~HTMLLabelElement();
61 virtual JSObject* WrapNode(JSContext* aCx,
62 JS::Handle<JSObject*> aGivenProto) override;
64 nsGenericHTMLElement* GetFirstLabelableDescendant() const;
66 // XXX It would be nice if we could use an event flag instead.
67 bool mHandlingEvent;
70 } // namespace dom
71 } // namespace mozilla
73 #endif /* HTMLLabelElement_h */