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