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 XULPopupElement_h__ 8 #define XULPopupElement_h__ 9 10 #include "mozilla/Attributes.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsWrapperCache.h" 13 #include "nsString.h" 14 #include "nsXULElement.h" 15 16 struct JSContext; 17 18 namespace mozilla { 19 class ErrorResult; 20 21 namespace dom { 22 23 class DOMRect; 24 class Element; 25 class Event; 26 class StringOrOpenPopupOptions; 27 struct ActivateMenuItemOptions; 28 29 nsXULElement* NS_NewXULPopupElement( 30 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 31 32 class XULPopupElement : public nsXULElement { 33 private: 34 nsIFrame* GetFrame(bool aFlushLayout); 35 36 public: XULPopupElement(already_AddRefed<mozilla::dom::NodeInfo> && aNodeInfo)37 explicit XULPopupElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 38 : nsXULElement(std::move(aNodeInfo)) {} 39 GetLabel(DOMString & aValue)40 void GetLabel(DOMString& aValue) const { 41 GetXULAttr(nsGkAtoms::label, aValue); 42 } SetLabel(const nsAString & aValue,ErrorResult & rv)43 void SetLabel(const nsAString& aValue, ErrorResult& rv) { 44 SetXULAttr(nsGkAtoms::label, aValue, rv); 45 } 46 GetPosition(DOMString & aValue)47 void GetPosition(DOMString& aValue) const { 48 GetXULAttr(nsGkAtoms::position, aValue); 49 } SetPosition(const nsAString & aValue,ErrorResult & rv)50 void SetPosition(const nsAString& aValue, ErrorResult& rv) { 51 SetXULAttr(nsGkAtoms::position, aValue, rv); 52 } 53 54 bool AutoPosition(); 55 56 void SetAutoPosition(bool aShouldAutoPosition); 57 58 void OpenPopup(Element* aAnchorElement, 59 const StringOrOpenPopupOptions& aOptions, int32_t aXPos, 60 int32_t aYPos, bool aIsContextMenu, bool aAttributesOverride, 61 Event* aTriggerEvent); 62 63 void OpenPopupAtScreen(int32_t aXPos, int32_t aYPos, bool aIsContextMenu, 64 Event* aTriggerEvent); 65 66 void OpenPopupAtScreenRect(const nsAString& aPosition, int32_t aXPos, 67 int32_t aYPos, int32_t aWidth, int32_t aHeight, 68 bool aIsContextMenu, bool aAttributesOverride, 69 Event* aTriggerEvent); 70 71 void HidePopup(bool aCancel); 72 73 void ActivateItem(Element& aItemElement, 74 const ActivateMenuItemOptions& aOptions, ErrorResult& aRv); 75 76 void GetState(nsString& aState); 77 78 nsINode* GetTriggerNode() const; 79 80 bool IsAnchored() const; 81 82 Element* GetAnchorNode() const; 83 84 already_AddRefed<DOMRect> GetOuterScreenRect(); 85 86 void MoveTo(int32_t aLeft, int32_t aTop); 87 88 void MoveToAnchor(Element* aAnchorElement, const nsAString& aPosition, 89 int32_t aXPos, int32_t aYPos, bool aAttributesOverride); 90 91 void SizeTo(int32_t aWidth, int32_t aHeight); 92 93 void SetConstraintRect(DOMRectReadOnly& aRect); 94 95 protected: 96 virtual ~XULPopupElement() = default; 97 98 JSObject* WrapNode(JSContext* aCx, 99 JS::Handle<JSObject*> aGivenProto) override; 100 }; 101 102 } // namespace dom 103 } // namespace mozilla 104 105 #endif // XULPopupElement_h 106