Bug 1704628 Part 4: Avoid use of ESC to close context menu in browser_toolbox_content...
[gecko.git] / dom / webidl / Element.webidl
blob5cbbf16cc44f178f573a84c1406d133ed607357f
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 file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/.
5  *
6  * The origin of this IDL file is
7  * http://dom.spec.whatwg.org/#element and
8  * http://domparsing.spec.whatwg.org/ and
9  * http://dev.w3.org/csswg/cssom-view/ and
10  * http://www.w3.org/TR/selectors-api/
11  *
12  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
13  * liability, trademark and document use rules apply.
14  */
16 [Exposed=Window]
17 interface Element : Node {
18   [Constant]
19   readonly attribute DOMString? namespaceURI;
20   [Constant]
21   readonly attribute DOMString? prefix;
22   [Constant]
23   readonly attribute DOMString localName;
25   // Not [Constant] because it depends on which document we're in
26   [Pure]
27   readonly attribute DOMString tagName;
29   [CEReactions, Pure]
30            attribute DOMString id;
31   [CEReactions, Pure]
32            attribute DOMString className;
33   [Constant, PutForwards=value]
34   readonly attribute DOMTokenList classList;
36   // https://drafts.csswg.org/css-shadow-parts/#idl
37   [SameObject, PutForwards=value]
38   readonly attribute DOMTokenList part;
40   [SameObject]
41   readonly attribute NamedNodeMap attributes;
42   [Pure]
43   sequence<DOMString> getAttributeNames();
44   [Pure]
45   DOMString? getAttribute(DOMString name);
46   [Pure]
47   DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
48   [CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
49   boolean toggleAttribute(DOMString name, optional boolean force);
50   [CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
51   void setAttribute(DOMString name, DOMString value);
52   [CEReactions, NeedsSubjectPrincipal=NonSystem, Throws]
53   void setAttributeNS(DOMString? namespace, DOMString name, DOMString value);
54   [CEReactions, Throws]
55   void removeAttribute(DOMString name);
56   [CEReactions, Throws]
57   void removeAttributeNS(DOMString? namespace, DOMString localName);
58   [Pure]
59   boolean hasAttribute(DOMString name);
60   [Pure]
61   boolean hasAttributeNS(DOMString? namespace, DOMString localName);
62   [Pure]
63   boolean hasAttributes();
65   [Throws, Pure]
66   Element? closest(UTF8String selector);
68   [Throws, Pure]
69   boolean matches(UTF8String selector);
70   [Throws, Pure, BinaryName="matches"]
71   boolean webkitMatchesSelector(UTF8String selector);
73   [Pure]
74   HTMLCollection getElementsByTagName(DOMString localName);
75   [Throws, Pure]
76   HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
77   [Pure]
78   HTMLCollection getElementsByClassName(DOMString classNames);
80   [CEReactions, Throws]
81   Element? insertAdjacentElement(DOMString where, Element element); // historical
83   [Throws]
84   void insertAdjacentText(DOMString where, DOMString data); // historical
86   /**
87    * The ratio of font-size-inflated text font size to computed font
88    * size for this element. This will query the element for its primary frame,
89    * and then use this to get font size inflation information about the frame.
90    * This will be 1.0 if font size inflation is not enabled, and -1.0 if an
91    * error occurred during the retrieval of the font size inflation.
92    *
93    * @note The font size inflation ratio that is returned is actually the
94    *       font size inflation data for the element's _primary frame_, not the
95    *       element itself, but for most purposes, this should be sufficient.
96    */
97   [ChromeOnly]
98   readonly attribute float fontSizeInflation;
100   /**
101    * Returns the pseudo-element string if this element represents a
102    * pseudo-element, or null otherwise.
103    */
104   [ChromeOnly]
105   readonly attribute DOMString? implementedPseudoElement;
107   // Selectors API
108   /**
109    * Returns whether this element would be selected by the given selector
110    * string.
111    *
112    * See <http://dev.w3.org/2006/webapi/selectors-api2/#matchesselector>
113    */
114   [Throws, Pure, BinaryName="matches"]
115   boolean mozMatchesSelector(UTF8String selector);
117   // Pointer events methods.
118   [Throws]
119   void setPointerCapture(long pointerId);
120   [Throws]
121   void releasePointerCapture(long pointerId);
122   boolean hasPointerCapture(long pointerId);
124   // Proprietary extensions
125   /**
126    * Set this during a mousedown event to grab and retarget all mouse events
127    * to this element until the mouse button is released or releaseCapture is
128    * called. If retargetToElement is true, then all events are targetted at
129    * this element. If false, events can also fire at descendants of this
130    * element.
131    *
132    */
133   [UseCounter]
134   void setCapture(optional boolean retargetToElement = false);
136   /**
137    * If this element has captured the mouse, release the capture. If another
138    * element has captured the mouse, this method has no effect.
139    */
140   [UseCounter]
141   void releaseCapture();
143   /*
144    * Chrome-only version of setCapture that works outside of a mousedown event.
145    */
146   [ChromeOnly]
147   void setCaptureAlways(optional boolean retargetToElement = false);
149   // Mozilla extensions
151   // Obsolete methods.
152   Attr? getAttributeNode(DOMString name);
153   [CEReactions, Throws]
154   Attr? setAttributeNode(Attr newAttr);
155   [CEReactions, Throws]
156   Attr? removeAttributeNode(Attr oldAttr);
157   Attr? getAttributeNodeNS(DOMString? namespaceURI, DOMString localName);
158   [CEReactions, Throws]
159   Attr? setAttributeNodeNS(Attr newAttr);
161   [Func="nsContentUtils::IsCallerChromeOrElementTransformGettersEnabled"]
162   DOMMatrixReadOnly getTransformToAncestor(Element ancestor);
163   [Func="nsContentUtils::IsCallerChromeOrElementTransformGettersEnabled"]
164   DOMMatrixReadOnly getTransformToParent();
165   [Func="nsContentUtils::IsCallerChromeOrElementTransformGettersEnabled"]
166   DOMMatrixReadOnly getTransformToViewport();
169 // https://html.spec.whatwg.org/#focus-management-apis
170 dictionary FocusOptions {
171   boolean preventScroll = false;
172   // Prevents the focus ring if this is not a text control / editable element.
173   [ChromeOnly] boolean preventFocusRing = false;
176 interface mixin HTMLOrForeignElement {
177   [SameObject] readonly attribute DOMStringMap dataset;
178   // See bug 1389421
179   // attribute DOMString nonce; // intentionally no [CEReactions]
181   // See bug 1575154
182   // [CEReactions] attribute boolean autofocus;
183   [CEReactions, SetterThrows, Pure] attribute long tabIndex;
184   [Throws, NeedsCallerType] void focus(optional FocusOptions options = {});
185   [Throws] void blur();
188 // https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-mixin
189 interface mixin ElementCSSInlineStyle {
190   [SameObject, PutForwards=cssText]
191   readonly attribute CSSStyleDeclaration style;
194 // http://dev.w3.org/csswg/cssom-view/
195 enum ScrollLogicalPosition { "start", "center", "end", "nearest" };
196 dictionary ScrollIntoViewOptions : ScrollOptions {
197   ScrollLogicalPosition block = "start";
198   ScrollLogicalPosition inline = "nearest";
201 // http://dev.w3.org/csswg/cssom-view/#extensions-to-the-element-interface
202 partial interface Element {
203   DOMRectList getClientRects();
204   DOMRect getBoundingClientRect();
206   // scrolling
207   void scrollIntoView(optional (boolean or ScrollIntoViewOptions) arg = {});
208   // None of the CSSOM attributes are [Pure], because they flush
209            attribute long scrollTop;   // scroll on setting
210            attribute long scrollLeft;  // scroll on setting
211   readonly attribute long scrollWidth;
212   readonly attribute long scrollHeight;
214   void scroll(unrestricted double x, unrestricted double y);
215   void scroll(optional ScrollToOptions options = {});
216   void scrollTo(unrestricted double x, unrestricted double y);
217   void scrollTo(optional ScrollToOptions options = {});
218   void scrollBy(unrestricted double x, unrestricted double y);
219   void scrollBy(optional ScrollToOptions options = {});
220   // mozScrollSnap is used by chrome to perform scroll snapping after the
221   // user performs actions that may affect scroll position
222   // mozScrollSnap is deprecated, to be replaced by a web accessible API, such
223   // as an extension to the ScrollOptions dictionary.  See bug 1137937.
224   [ChromeOnly] void mozScrollSnap();
226   readonly attribute long clientTop;
227   readonly attribute long clientLeft;
228   readonly attribute long clientWidth;
229   readonly attribute long clientHeight;
231   // Mozilla specific stuff
232   /* The minimum/maximum offset that the element can be scrolled to
233      (i.e., the value that scrollLeft/scrollTop would be clamped to if they were
234      set to arbitrarily large values. */
235   [ChromeOnly] readonly attribute long scrollTopMin;
236                readonly attribute long scrollTopMax;
237   [ChromeOnly] readonly attribute long scrollLeftMin;
238                readonly attribute long scrollLeftMax;
241 // http://domparsing.spec.whatwg.org/#extensions-to-the-element-interface
242 partial interface Element {
243   [CEReactions, SetterNeedsSubjectPrincipal=NonSystem, Pure, SetterThrows, GetterCanOOM]
244   attribute [LegacyNullToEmptyString] DOMString innerHTML;
245   [CEReactions, Pure, SetterThrows]
246   attribute [LegacyNullToEmptyString] DOMString outerHTML;
247   [CEReactions, Throws]
248   void insertAdjacentHTML(DOMString position, DOMString text);
251 // http://www.w3.org/TR/selectors-api/#interface-definitions
252 partial interface Element {
253   [Throws, Pure]
254   Element?  querySelector(UTF8String selectors);
255   [Throws, Pure]
256   NodeList  querySelectorAll(UTF8String selectors);
259 // https://dom.spec.whatwg.org/#dictdef-shadowrootinit
260 dictionary ShadowRootInit {
261   required ShadowRootMode mode;
264 // https://dom.spec.whatwg.org/#element
265 partial interface Element {
266   // Shadow DOM v1
267   [Throws, UseCounter]
268   ShadowRoot attachShadow(ShadowRootInit shadowRootInitDict);
269   [BinaryName="shadowRootByMode"]
270   readonly attribute ShadowRoot? shadowRoot;
272   [Func="Document::IsCallerChromeOrAddon", BinaryName="shadowRoot"]
273   readonly attribute ShadowRoot? openOrClosedShadowRoot;
275   [BinaryName="assignedSlotByMode"]
276   readonly attribute HTMLSlotElement? assignedSlot;
278   [ChromeOnly, BinaryName="assignedSlot"]
279   readonly attribute HTMLSlotElement? openOrClosedAssignedSlot;
281   [CEReactions, Unscopable, SetterThrows]
282            attribute DOMString slot;
285 Element includes ChildNode;
286 Element includes NonDocumentTypeChildNode;
287 Element includes ParentNode;
288 Element includes Animatable;
289 Element includes GeometryUtils;
290 Element includes AccessibilityRole;
291 Element includes AriaAttributes;
293 // https://fullscreen.spec.whatwg.org/#api
294 partial interface Element {
295   [Throws, NeedsCallerType]
296   Promise<void> requestFullscreen();
297   [Throws, BinaryName="requestFullscreen", NeedsCallerType, Deprecated="MozRequestFullScreenDeprecatedPrefix"]
298   Promise<void> mozRequestFullScreen();
300   // Events handlers
301   attribute EventHandler onfullscreenchange;
302   attribute EventHandler onfullscreenerror;
305 // https://w3c.github.io/pointerlock/#extensions-to-the-element-interface
306 partial interface Element {
307   [NeedsCallerType, Pref="dom.pointer-lock.enabled"]
308   void requestPointerLock();
311 // Mozilla-specific additions to support devtools
312 partial interface Element {
313   // Support reporting of Flexbox properties
314   /**
315    * If this element has a display:flex or display:inline-flex style,
316    * this property returns an object with computed values for flex
317    * properties, as well as a property that exposes the flex lines
318    * in this container.
319    */
320   [ChromeOnly, Pure]
321   Flex? getAsFlexContainer();
323   // Support reporting of Grid properties
324   /**
325    * If this element has a display:grid or display:inline-grid style,
326    * this property returns an object with computed values for grid
327    * tracks and lines.
328    */
329   [ChromeOnly, Pure]
330   sequence<Grid> getGridFragments();
332   /**
333    * Returns whether there are any grid fragments on this element.
334    */
335   [ChromeOnly, Pure]
336   boolean hasGridFragments();
338   /**
339    * Returns a sequence of all the descendent elements of this element
340    * that have display:grid or display:inline-grid style and generate
341    * a frame.
342    */
343   [ChromeOnly, Pure]
344   sequence<Element> getElementsWithGrid();
346   /**
347    * Set attribute on the Element with a customized Content-Security-Policy
348    * appropriate to devtools, which includes:
349    * style-src 'unsafe-inline'
350    */
351   [ChromeOnly, CEReactions, Throws]
352   void setAttributeDevtools(DOMString name, DOMString value);
353   [ChromeOnly, CEReactions, Throws]
354   void setAttributeDevtoolsNS(DOMString? namespace, DOMString name, DOMString value);
356   /**
357    * Provide a direct way to determine if this Element has visible
358    * scrollbars. Flushes layout.
359    */
360   [ChromeOnly]
361   readonly attribute boolean hasVisibleScrollbars;
364 // These variables are used in vtt.js, they are used for positioning vtt cues.
365 partial interface Element {
366   // These two attributes are a double version of the clientHeight and the
367   // clientWidth.
368   [ChromeOnly]
369   readonly attribute double clientHeightDouble;
370   [ChromeOnly]
371   readonly attribute double clientWidthDouble;
372   // This attribute returns the block size of the first line box under the different
373   // writing directions. If the direction is horizontal, it represents box's
374   // height. If the direction is vertical, it represents box's width.
375   [ChromeOnly]
376   readonly attribute double firstLineBoxBSize;