Line data Source code
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/. */
6 :
7 : /**
8 : * Declaration of HTML <label> elements.
9 : */
10 : #ifndef HTMLLabelElement_h
11 : #define HTMLLabelElement_h
12 :
13 : #include "mozilla/Attributes.h"
14 : #include "nsGenericHTMLElement.h"
15 : #include "nsIDOMHTMLLabelElement.h"
16 :
17 : namespace mozilla {
18 : class EventChainPostVisitor;
19 : namespace dom {
20 :
21 : class HTMLLabelElement final : public nsGenericHTMLElement,
22 : public nsIDOMHTMLLabelElement
23 : {
24 : public:
25 0 : explicit HTMLLabelElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
26 0 : : nsGenericHTMLElement(aNodeInfo),
27 0 : mHandlingEvent(false)
28 : {
29 0 : }
30 :
31 28 : NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLLabelElement, label)
32 :
33 : // nsISupports
34 : NS_DECL_ISUPPORTS_INHERITED
35 :
36 : // Element
37 0 : virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override
38 : {
39 0 : return true;
40 : }
41 :
42 : // nsIDOMHTMLLabelElement
43 : NS_DECL_NSIDOMHTMLLABELELEMENT
44 :
45 : HTMLFormElement* GetForm() const;
46 0 : void GetHtmlFor(nsString& aHtmlFor)
47 : {
48 0 : GetHTMLAttr(nsGkAtoms::_for, aHtmlFor);
49 0 : }
50 0 : void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& aError)
51 : {
52 0 : SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, aError);
53 0 : }
54 0 : nsGenericHTMLElement* GetControl() const
55 : {
56 0 : return GetLabeledElement();
57 : }
58 :
59 : using nsGenericHTMLElement::Focus;
60 : virtual void Focus(mozilla::ErrorResult& aError) override;
61 :
62 0 : virtual bool IsDisabled() const override { return false; }
63 :
64 : // nsIContent
65 : virtual nsresult PostHandleEvent(
66 : EventChainPostVisitor& aVisitor) override;
67 : virtual bool PerformAccesskey(bool aKeyCausesActivation,
68 : bool aIsTrustedEvent) override;
69 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
70 : bool aPreallocateChildren) const override;
71 :
72 : nsGenericHTMLElement* GetLabeledElement() const;
73 : protected:
74 : virtual ~HTMLLabelElement();
75 :
76 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
77 :
78 : nsGenericHTMLElement* GetFirstLabelableDescendant() const;
79 :
80 : // XXX It would be nice if we could use an event flag instead.
81 : bool mHandlingEvent;
82 : };
83 :
84 : } // namespace dom
85 : } // namespace mozilla
86 :
87 : #endif /* HTMLLabelElement_h */
|