HTMLMenuElement.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_HTMLMenuElement_h
  6. #define mozilla_dom_HTMLMenuElement_h
  7. #include "mozilla/Attributes.h"
  8. #include "nsIDOMHTMLMenuElement.h"
  9. #include "nsIHTMLMenu.h"
  10. #include "nsGenericHTMLElement.h"
  11. namespace mozilla {
  12. namespace dom {
  13. class HTMLMenuElement final : public nsGenericHTMLElement,
  14. public nsIDOMHTMLMenuElement,
  15. public nsIHTMLMenu
  16. {
  17. public:
  18. explicit HTMLMenuElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
  19. NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuElement, menu)
  20. // nsISupports
  21. NS_DECL_ISUPPORTS_INHERITED
  22. // nsIDOMHTMLMenuElement
  23. NS_DECL_NSIDOMHTMLMENUELEMENT
  24. // nsIHTMLMenu
  25. NS_DECL_NSIHTMLMENU
  26. virtual bool ParseAttribute(int32_t aNamespaceID,
  27. nsIAtom* aAttribute,
  28. const nsAString& aValue,
  29. nsAttrValue& aResult) override;
  30. virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
  31. uint8_t GetType() const { return mType; }
  32. // WebIDL
  33. // The XPCOM GetType is OK for us
  34. void SetType(const nsAString& aType, ErrorResult& aError)
  35. {
  36. SetHTMLAttr(nsGkAtoms::type, aType, aError);
  37. }
  38. // The XPCOM GetLabel is OK for us
  39. void SetLabel(const nsAString& aLabel, ErrorResult& aError)
  40. {
  41. SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
  42. }
  43. bool Compact() const
  44. {
  45. return GetBoolAttr(nsGkAtoms::compact);
  46. }
  47. void SetCompact(bool aCompact, ErrorResult& aError)
  48. {
  49. SetHTMLBoolAttr(nsGkAtoms::compact, aCompact, aError);
  50. }
  51. // The XPCOM SendShowEvent is OK for us
  52. already_AddRefed<nsIMenuBuilder> CreateBuilder();
  53. // The XPCOM Build is OK for us
  54. protected:
  55. virtual ~HTMLMenuElement();
  56. virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
  57. protected:
  58. static bool CanLoadIcon(nsIContent* aContent, const nsAString& aIcon);
  59. void BuildSubmenu(const nsAString& aLabel,
  60. nsIContent* aContent,
  61. nsIMenuBuilder* aBuilder);
  62. void TraverseContent(nsIContent* aContent,
  63. nsIMenuBuilder* aBuilder,
  64. int8_t& aSeparator);
  65. void AddSeparator(nsIMenuBuilder* aBuilder, int8_t& aSeparator);
  66. uint8_t mType;
  67. };
  68. } // namespace dom
  69. } // namespace mozilla
  70. #endif // mozilla_dom_HTMLMenuElement_h