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 : #ifndef mozilla_dom_HTMLMenuElement_h
8 : #define mozilla_dom_HTMLMenuElement_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "nsIDOMHTMLMenuElement.h"
12 : #include "nsGenericHTMLElement.h"
13 :
14 : class nsIMenuBuilder;
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : class HTMLMenuElement final : public nsGenericHTMLElement,
20 : public nsIDOMHTMLMenuElement
21 : {
22 : public:
23 : explicit HTMLMenuElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
24 :
25 0 : NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuElement, menu)
26 :
27 : // nsISupports
28 : NS_DECL_ISUPPORTS_INHERITED
29 :
30 : // nsIDOMHTMLMenuElement
31 : NS_DECL_NSIDOMHTMLMENUELEMENT
32 :
33 : virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
34 : const nsAttrValue* aValue,
35 : const nsAttrValue* aOldValue,
36 : bool aNotify) override;
37 : virtual bool ParseAttribute(int32_t aNamespaceID,
38 : nsIAtom* aAttribute,
39 : const nsAString& aValue,
40 : nsAttrValue& aResult) override;
41 :
42 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
43 : bool aPreallocateChildren) const override;
44 :
45 : uint8_t GetType() const { return mType; }
46 :
47 : // WebIDL
48 :
49 : // The XPCOM GetType is OK for us
50 0 : void SetType(const nsAString& aType, ErrorResult& aError)
51 : {
52 0 : SetHTMLAttr(nsGkAtoms::type, aType, aError);
53 0 : }
54 :
55 : // The XPCOM GetLabel is OK for us
56 0 : void SetLabel(const nsAString& aLabel, ErrorResult& aError)
57 : {
58 0 : SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
59 0 : }
60 :
61 0 : bool Compact() const
62 : {
63 0 : return GetBoolAttr(nsGkAtoms::compact);
64 : }
65 0 : void SetCompact(bool aCompact, ErrorResult& aError)
66 : {
67 0 : SetHTMLBoolAttr(nsGkAtoms::compact, aCompact, aError);
68 0 : }
69 :
70 : void SendShowEvent();
71 :
72 : already_AddRefed<nsIMenuBuilder> CreateBuilder();
73 :
74 : void Build(nsIMenuBuilder* aBuilder);
75 :
76 : protected:
77 : virtual ~HTMLMenuElement();
78 :
79 : virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
80 :
81 :
82 : protected:
83 : static bool CanLoadIcon(nsIContent* aContent, const nsAString& aIcon);
84 :
85 : void BuildSubmenu(const nsAString& aLabel,
86 : nsIContent* aContent,
87 : nsIMenuBuilder* aBuilder);
88 :
89 : void TraverseContent(nsIContent* aContent,
90 : nsIMenuBuilder* aBuilder,
91 : int8_t& aSeparator);
92 :
93 : void AddSeparator(nsIMenuBuilder* aBuilder, int8_t& aSeparator);
94 :
95 : uint8_t mType;
96 : };
97 :
98 : } // namespace dom
99 : } // namespace mozilla
100 :
101 : #endif // mozilla_dom_HTMLMenuElement_h
|