summaryrefslogtreecommitdiffstats
path: root/layout/inspector/inIDOMUtils.idl
blob: 30c15003fb52b27724ad6537112e61fec3458b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

interface nsIArray;
interface nsIArrayExtensions;
interface nsIDOMCharacterData;
interface nsIDOMElement;
interface nsIDOMDocument;
interface nsIDOMCSSRule;
interface nsIDOMCSSStyleRule;
interface nsIDOMNode;
interface nsIDOMNodeList;
interface nsIDOMFontFaceList;
interface nsIDOMRange;
interface nsIDOMCSSStyleSheet;

[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
interface inIDOMUtils : nsISupports
{
  // CSS utilities
  void getAllStyleSheets (in nsIDOMDocument aDoc,
                          [optional] out unsigned long aLength,
                          [array, size_is (aLength), retval] out nsISupports aSheets);
  nsIArrayExtensions getCSSStyleRules(in nsIDOMElement aElement, [optional] in DOMString aPseudo);

  /**
   * Get the line number of a rule.
   *
   * @param nsIDOMCSSRule aRule The rule.
   * @return The rule's line number.  Line numbers are 1-based.
   */
  unsigned long getRuleLine(in nsIDOMCSSRule aRule);

  /**
   * Get the column number of a rule.
   *
   * @param nsIDOMCSSRule aRule The rule.
   * @return The rule's column number.  Column numbers are 1-based.
   */
  unsigned long getRuleColumn(in nsIDOMCSSRule aRule);

  /**
   * Like getRuleLine, but if the rule is in a <style> element,
   * returns a line number relative to the start of the element.
   *
   * @param nsIDOMCSSRule aRule the rule to examine
   * @return the line number of the rule, possibly relative to the
   *         <style> element
   */
  unsigned long getRelativeRuleLine(in nsIDOMCSSRule aRule);

  [implicit_jscontext]
  jsval getCSSLexer(in DOMString aText);

  // Utilities for working with selectors.  We don't have a JS OM representation
  // of a single selector or a selector list yet, but given a rule we can index
  // into the selector list.
  //
  // This is a somewhat backwards API; once we move StyleRule to WebIDL we
  // should consider using [ChromeOnly] APIs on that.
  unsigned long getSelectorCount(in nsIDOMCSSStyleRule aRule);
  // For all three functions below, aSelectorIndex is 0-based
  AString getSelectorText(in nsIDOMCSSStyleRule aRule,
                          in unsigned long aSelectorIndex);
  unsigned long long getSpecificity(in nsIDOMCSSStyleRule aRule,
                                    in unsigned long aSelectorIndex);
  // Note: This does not handle scoped selectors correctly, because it has no
  // idea what the right scope is.
  bool selectorMatchesElement(in nsIDOMElement aElement,
                              in nsIDOMCSSStyleRule aRule,
                              in unsigned long aSelectorIndex,
                              [optional] in DOMString aPseudo);

  // Utilities for working with CSS properties
  //
  // Returns true if the string names a property that is inherited by default.
  bool isInheritedProperty(in AString aPropertyName);

  // Get a list of all our supported property names.  Optionally
  // shorthands can be excluded or property aliases included.
  const unsigned long EXCLUDE_SHORTHANDS = (1<<0);
  const unsigned long INCLUDE_ALIASES = (1<<1);
  void getCSSPropertyNames([optional] in unsigned long aFlags,
			   [optional] out unsigned long aCount,
			   [retval, array, size_is(aCount)] out wstring aProps);

  // Get a list of all valid keywords and colors for aProperty.
  void getCSSValuesForProperty(in AString aProperty,
                               [optional] out unsigned long aLength,
                               [array, size_is(aLength), retval] out wstring aValues);

  // Utilities for working with CSS colors
  [implicit_jscontext]
  jsval colorNameToRGB(in DOMString aColorName);
  AString rgbToColorName(in octet aR, in octet aG, in octet aB);

  // Convert a given CSS color string to rgba. Returns null on failure or an
  // InspectorRGBATuple on success.
  //
  // NOTE: Converting a color to RGBA may be lossy when converting from some
  // formats e.g. CMYK.
  [implicit_jscontext]
  jsval colorToRGBA(in DOMString aColorString);

  // Check whether a given color is a valid CSS color.
  bool isValidCSSColor(in AString aColorString);

  // Utilities for obtaining information about a CSS property.

  // Check whether a CSS property and value are a valid combination. If the
  // property is pref-disabled it will still be processed.
  // aPropertyName: A property name e.g. "color"
  // aPropertyValue: A property value e.g. "red" or "red !important"
  bool cssPropertyIsValid(in AString aPropertyName, in AString aPropertyValue);

  // Get a list of the longhands corresponding to the given CSS property.  If
  // the property is a longhand already, just returns the property itself.
  // Throws on unsupported property names.
  void getSubpropertiesForCSSProperty(in AString aProperty,
                                      [optional] out unsigned long aLength,
                                      [array, size_is(aLength), retval] out wstring aValues);
  // Check whether a given CSS property is a shorthand.  Throws on unsupported
  // property names.
  bool cssPropertyIsShorthand(in AString aProperty);

  // Check whether values of the given type are valid values for the property.
  // For shorthands, checks whether there's a corresponding longhand property
  // that accepts values of this type.  Throws on unsupported properties or
  // unknown types.
  const unsigned long TYPE_LENGTH = 0;
  const unsigned long TYPE_PERCENTAGE = 1;
  const unsigned long TYPE_COLOR = 2;
  const unsigned long TYPE_URL = 3;
  const unsigned long TYPE_ANGLE = 4;
  const unsigned long TYPE_FREQUENCY = 5;
  const unsigned long TYPE_TIME = 6;
  const unsigned long TYPE_GRADIENT = 7;
  const unsigned long TYPE_TIMING_FUNCTION = 8;
  const unsigned long TYPE_IMAGE_RECT = 9;
  const unsigned long TYPE_NUMBER = 10;
  bool cssPropertySupportsType(in AString aProperty, in unsigned long type);

  // DOM Node utilities
  boolean isIgnorableWhitespace(in nsIDOMCharacterData aDataNode);
  // Returns the "parent" of a node.  The parent of a document node is the
  // frame/iframe containing that document.  aShowingAnonymousContent says
  // whether we are showing anonymous content.
  nsIDOMNode getParentForNode(in nsIDOMNode aNode,
                              in boolean aShowingAnonymousContent);
  nsIDOMNodeList getChildrenForNode(in nsIDOMNode aNode,
                                    in boolean aShowingAnonymousContent);
  
  // XBL utilities
  nsIArray getBindingURLs(in nsIDOMElement aElement);

  // content state utilities
  unsigned long long getContentState(in nsIDOMElement aElement);
  /**
   * Setting and removing content state on an element. Both these functions
   * calling EventStateManager::SetContentState internally, the difference is
   * that for the remove case we simply pass in nullptr for the element.
   * Use them accordingly.
   *
   * @return Returns true if the state was set successfully. See more details
   * in EventStateManager.h SetContentState.
   */
  bool setContentState(in nsIDOMElement aElement, in unsigned long long aState);
  bool removeContentState(in nsIDOMElement aElement, in unsigned long long aState);

  nsIDOMFontFaceList getUsedFontFaces(in nsIDOMRange aRange);

  /**
   * Get the names of all the supported pseudo-elements.
   * Pseudo-elements which are only accepted in UA style sheets are
   * not included.
   *
   * @param {unsigned long} aCount the number of items returned
   * @param {wstring[]} aNames the names
   */
  void getCSSPseudoElementNames([optional] out unsigned long aCount,
                                [retval, array, size_is(aCount)] out wstring aNames);

  // pseudo-class style locking methods. aPseudoClass must be a valid pseudo-class
  // selector string, e.g. ":hover". ":any-link" and non-event-state
  // pseudo-classes are ignored.
  void addPseudoClassLock(in nsIDOMElement aElement, in DOMString aPseudoClass);
  void removePseudoClassLock(in nsIDOMElement aElement, in DOMString aPseudoClass);
  bool hasPseudoClassLock(in nsIDOMElement aElement, in DOMString aPseudoClass);
  void clearPseudoClassLocks(in nsIDOMElement aElement);

  /**
   * Parse CSS and update the style sheet in place.
   *
   * @param DOMCSSStyleSheet aSheet
   * @param DOMString aInput
   *        The new source string for the style sheet.
   */
  void parseStyleSheet(in nsIDOMCSSStyleSheet aSheet, in DOMString aInput);
  /**
   * Scroll an element completely into view, if possible.
   * This is similar to ensureElementIsVisible but for all ancestors.
   *
   * @param DOMElement aElement
   */
  void scrollElementIntoView(in nsIDOMElement aElement);
};

%{ C++
#define IN_DOMUTILS_CONTRACTID "@mozilla.org/inspector/dom-utils;1"
%}