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 #ifndef mozilla_dom_HTMLLegendElement_h
8 #define mozilla_dom_HTMLLegendElement_h
9 
10 #include "mozilla/Attributes.h"
11 #include "nsGenericHTMLElement.h"
12 #include "mozilla/dom/HTMLFormElement.h"
13 
14 namespace mozilla {
15 namespace dom {
16 
17 class HTMLLegendElement final : public nsGenericHTMLElement {
18  public:
HTMLLegendElement(already_AddRefed<mozilla::dom::NodeInfo> && aNodeInfo)19   explicit HTMLLegendElement(
20       already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
21       : nsGenericHTMLElement(std::move(aNodeInfo)) {}
22 
23   NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLLegendElement, legend)
24 
25   using nsGenericHTMLElement::Focus;
26   virtual void Focus(const FocusOptions& aOptions,
27                      const mozilla::dom::CallerType aCallerType,
28                      ErrorResult& aError) override;
29 
30   virtual Result<bool, nsresult> PerformAccesskey(
31       bool aKeyCausesActivation, bool aIsTrustedEvent) override;
32 
33   // nsIContent
34   virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
35   virtual void UnbindFromTree(bool aNullParent = true) override;
36   virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
37                               const nsAString& aValue,
38                               nsIPrincipal* aMaybeScriptedPrincipal,
39                               nsAttrValue& aResult) override;
40   virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
41                                               int32_t aModType) const override;
42 
43   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
44 
45   enum class LegendAlignValue : uint8_t {
46     Left,
47     Right,
48     Center,
49     Bottom,
50     Top,
51     InlineStart,
52     InlineEnd,
53   };
54 
55   /**
56    * Return the align value to use for the given fieldset writing-mode.
57    * (This method resolves Left/Right to the appropriate InlineStart/InlineEnd).
58    * @param aCBWM the fieldset writing-mode
59    * @note we only parse left/right/center, so this method returns Center,
60    * InlineStart or InlineEnd.
61    */
62   LegendAlignValue LogicalAlign(mozilla::WritingMode aCBWM) const;
63 
64   /**
65    * WebIDL Interface
66    */
67 
68   HTMLFormElement* GetForm() const;
69 
GetAlign(DOMString & aAlign)70   void GetAlign(DOMString& aAlign) { GetHTMLAttr(nsGkAtoms::align, aAlign); }
71 
SetAlign(const nsAString & aAlign,ErrorResult & aError)72   void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
73     SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
74   }
75 
GetScopeChainParent()76   nsINode* GetScopeChainParent() const override {
77     Element* form = GetForm();
78     return form ? form : nsGenericHTMLElement::GetScopeChainParent();
79   }
80 
81  protected:
82   virtual ~HTMLLegendElement();
83 
84   virtual JSObject* WrapNode(JSContext* aCx,
85                              JS::Handle<JSObject*> aGivenProto) override;
86 
87   /**
88    * Get the fieldset content element that contains this legend.
89    * Returns null if there is no fieldset containing this legend.
90    */
91   nsIContent* GetFieldSet() const;
92 };
93 
94 }  // namespace dom
95 }  // namespace mozilla
96 
97 #endif /* mozilla_dom_HTMLLegendElement_h */
98