Bug 1704628 Part 4: Avoid use of ESC to close context menu in browser_toolbox_content...
[gecko.git] / dom / webidl / XULPopupElement.webidl
blob9cd1c06e0cfca3d9a8be25460ee73bdee938e18a
1 /* -*- Mode: IDL; tab-width: 2; 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/. */
6 dictionary OpenPopupOptions {
7   // manner in which to anchor the popup to node
8   DOMString position = "";
9   // horizontal offset
10   long x = 0;
11   // vertical offset
12   long y = 0;
13   // isContextMenu true for context menus, false for other popups
14   boolean isContextMenu = false;
15   // true if popup node attributes override position
16   boolean attributesOverride = false;
17   // triggerEvent the event that triggered this popup (mouse click for example)
18   Event? triggerEvent = null;
21 dictionary ActivateMenuItemOptions {
22   boolean altKey = false;
23   boolean metaKey = false;
24   boolean ctrlKey = false;
25   boolean shiftKey = false;
26   short button = 0;
29 typedef (DOMString or OpenPopupOptions) StringOrOpenPopupOptions;
31 [ChromeOnly,
32  Exposed=Window]
33 interface XULPopupElement : XULElement
35   [HTMLConstructor] constructor();
37   /**
38    * Allow the popup to automatically position itself.
39    */
40   attribute boolean autoPosition;
42   /**
43    * Open the popup relative to a specified node at a specific location.
44    *
45    * The popup may be either anchored to another node or opened freely.
46    * To anchor a popup to a node, supply an anchor node and set the position
47    * to a string indicating the manner in which the popup should be anchored.
48    * Possible values for position are:
49    *    before_start, before_end, after_start, after_end,
50    *    start_before, start_after, end_before, end_after,
51    *    overlap, after_pointer
52    *
53    * The anchor node does not need to be in the same document as the popup.
54    *
55    * If the attributesOverride argument is true, the popupanchor, popupalign
56    * and position attributes on the popup node override the position value
57    * argument. If attributesOverride is false, the attributes are only used
58    * if position is empty.
59    *
60    * For an anchored popup, the x and y arguments may be used to offset the
61    * popup from its anchored position by some distance, measured in CSS pixels.
62    * x increases to the right and y increases down. Negative values may also
63    * be used to move to the left and upwards respectively.
64    *
65    * Unanchored popups may be created by supplying null as the anchor node.
66    * An unanchored popup appears at the position specified by x and y,
67    * relative to the viewport of the document containing the popup node. In
68    * this case, position and attributesOverride are ignored.
69    *
70    * @param anchorElement the node to anchor the popup to, may be null
71    * @param options either options to use, or a string position
72    * @param x horizontal offset
73    * @param y vertical offset
74    * @param isContextMenu true for context menus, false for other popups
75    * @param attributesOverride true if popup node attributes override position
76    * @param triggerEvent the event that triggered this popup (mouse click for example)
77    */
78   void openPopup(optional Element? anchorElement = null,
79                  optional StringOrOpenPopupOptions options = {},
80                  optional long x = 0,
81                  optional long y = 0,
82                  optional boolean isContextMenu = false,
83                  optional boolean attributesOverride = false,
84                  optional Event? triggerEvent = null);
86   /**
87    * Open the popup at a specific screen position specified by x and y. This
88    * position may be adjusted if it would cause the popup to be off of the
89    * screen. The x and y coordinates are measured in CSS pixels, and like all
90    * screen coordinates, are given relative to the top left of the primary
91    * screen.
92    *
93    * @param isContextMenu true for context menus, false for other popups
94    * @param x horizontal screen position
95    * @param y vertical screen position
96    * @param triggerEvent the event that triggered this popup (mouse click for example)
97    */
98   void openPopupAtScreen(optional long x = 0, optional long y = 0,
99                          optional boolean isContextMenu = false,
100                          optional Event? triggerEvent = null);
102   /**
103    * Open the popup anchored at a specific screen rectangle. This function is
104    * similar to openPopup except that that rectangle of the anchor is supplied
105    * rather than an element. The anchor rectangle arguments are screen
106    * coordinates.
107    */
108   void openPopupAtScreenRect(optional DOMString position = "",
109                              optional long x = 0,
110                              optional long y = 0,
111                              optional long width = 0,
112                              optional long height = 0,
113                              optional boolean isContextMenu = false,
114                              optional boolean attributesOverride = false,
115                              optional Event? triggerEvent = null);
117   /**
118    *  Hide the popup if it is open. The cancel argument is used as a hint that
119    *  the popup is being closed because it has been cancelled, rather than
120    *  something being selected within the panel.
121    *
122    * @param cancel if true, then the popup is being cancelled.
123    */
124   void hidePopup(optional boolean cancel = false);
126   /**
127    * Activate the item itemElement. This is the recommended way to "click" a
128    * menuitem in automated tests that involve menus.
129    * Fires the command event for the item and then closes the menu.
130    *
131    * Throws an InvalidStateError if the menu is not currently open, or if the
132    * menuitem is not inside this menu, or if the menuitem is hidden.
133    *
134    * @param itemElement The menuitem to activate.
135    * @param options Which modifier keys and button should be set on the command
136    *                event.
137    */
138   [Throws]
139   void activateItem(Element itemElement,
140                     optional ActivateMenuItemOptions options = {});
142   /**
143    * Attribute getter and setter for label.
144    */
145   [SetterThrows]
146   attribute DOMString label;
148   /**
149    * Attribute getter and setter for position.
150    */
151   [SetterThrows]
152   attribute DOMString position;
154   /**
155    * Returns the state of the popup:
156    *   closed - the popup is closed
157    *   open - the popup is open
158    *   showing - the popup is in the process of being shown
159    *   hiding - the popup is in the process of being hidden
160    */
161   readonly attribute DOMString state;
163   /**
164    * The node that triggered the popup. If the popup is not open, will return
165    * null.
166    */
167   readonly attribute Node? triggerNode;
169   /**
170    * True if the popup is anchored to a point or rectangle. False if it
171    * appears at a fixed screen coordinate.
172    */
173   readonly attribute boolean isAnchored;
175   /**
176    * Retrieve the anchor that was specified to openPopup or for menupopups in a
177    * menu, the parent menu.
178    */
179   readonly attribute Element? anchorNode;
181   /**
182    * Retrieve the screen rectangle of the popup, including the area occupied by
183    * any titlebar or borders present.
184    */
185   DOMRect getOuterScreenRect();
187   /**
188    * Move the popup to a point on screen in CSS pixels.
189    */
190   void moveTo(long left, long top);
192   /**
193    * Move an open popup to the given anchor position. The arguments have the same
194    * meaning as the corresponding argument to openPopup. This method has no effect
195    * on popups that are not open.
196    */
197   void moveToAnchor(optional Element? anchorElement = null,
198                     optional DOMString position = "",
199                     optional long x = 0, optional long y = 0,
200                     optional boolean attributesOverride = false);
202   /**
203    * Size the popup to the given dimensions
204    */
205   void sizeTo(long width, long height);
207   void setConstraintRect(DOMRectReadOnly rect);