nsIFocusManager.idl (11677B)
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/. */ 5 6 #include "domstubs.idl" 7 8 interface mozIDOMWindowProxy; 9 10 webidl BrowsingContext; 11 webidl Document; 12 webidl Element; 13 14 native CallerType(mozilla::dom::CallerType); 15 16 /** 17 * The focus manager deals with all focus related behaviour. Only one element 18 * in the entire application may have the focus at a time; this element 19 * receives any keyboard events. While there is only one application-wide 20 * focused element, each nsIDOMWindow maintains a reference to the element 21 * that would be focused if the window was active. 22 * 23 * If the window's reference is to a frame element (iframe, browser, 24 * editor), then the child window contains the element that is currently 25 * focused. If the window's reference is to a root element, then the root is 26 * focused. If a window's reference is null, then no element is focused, yet 27 * the window is still focused. 28 * 29 * The blur event is fired on an element when it loses the application focus. 30 * After this blur event, if the focus is moving away from a document, two 31 * additional blur events are fired on the old document and window containing 32 * the focus respectively. 33 * 34 * When a new document is focused, two focus events are fired on the new 35 * document and window respectively. Then the focus event is fired on an 36 * element when it gains the application focus. 37 * 38 * A special case is that the root element may be focused, yet does not 39 * receive the element focus and blur events. Instead a focus outline may be 40 * drawn around the document. 41 * 42 * Blur and focus events do not bubble as per the W3C DOM Events spec. 43 */ 44 [scriptable, uuid(86e1f1e1-365d-493b-b52a-a649f3f311dc)] 45 interface nsIFocusManager : nsISupports 46 { 47 /** 48 * The most active (frontmost) window, or null if no window that is part of 49 * the application is active. Do not use outside the parent process. 50 */ 51 readonly attribute mozIDOMWindowProxy activeWindow; 52 53 /** 54 * In the parent process: The BrowsingContext corresponding to activeWindow. 55 * In content processes: The top-level Web content browsing context that 56 * focus is in if the application is active and focus is in Web content. 57 */ 58 readonly attribute BrowsingContext activeBrowsingContext; 59 60 /** 61 * Parent-process only: The chrome process notion of content's active 62 * browsing context. 63 */ 64 readonly attribute BrowsingContext activeContentBrowsingContext; 65 66 /** 67 * The child window within the activeWindow that is focused. This will 68 * always be activeWindow, a child window of activeWindow or null if no 69 * child window is focused. Setting the focusedWindow changes the focused 70 * window and raises the toplevel window it is in. If the current focus 71 * within the new focusedWindow is a frame element, then the focusedWindow 72 * will actually be set to the child window and the current element within 73 * that set as the focused element. This process repeats downwards until a 74 * non-frame element is found. 75 * The setter for this attribute defaults to CallerType::System. 76 * If focus is in another process, this is null in content processes and 77 * the closest ancestor in the parent process. 78 */ 79 [setter_can_run_script] 80 attribute mozIDOMWindowProxy focusedWindow; 81 82 /** 83 * Parent-process only: The content BrowsingContext that currently has focus, 84 * if any. Note this can be different from activeBrowsingContext in the case 85 * of subframes. 86 */ 87 readonly attribute BrowsingContext focusedContentBrowsingContext; 88 89 /** 90 * The element that is currently focused. This will always be an element 91 * within the document loaded in focusedWindow or null if no element in that 92 * document is focused. 93 */ 94 readonly attribute Element focusedElement; 95 96 /** 97 * Returns the method that was used to focus the element in window. This 98 * will either be 0, FLAG_BYMOUSE or FLAG_BYKEY. If window is null, then 99 * the current focusedWindow will be used by default. This has the result 100 * of retrieving the method that was used to focus the currently focused 101 * element. 102 */ 103 uint32_t getLastFocusMethod(in mozIDOMWindowProxy window); 104 105 /** 106 * Changes the focused element reference within the window containing 107 * aElement to aElement or potentially redirects it to an anonymous 108 * descendant of it (e.g., for `<input type="number">` the focus is redirected 109 * to its descendant `<input type="text">`). 110 */ 111 [can_run_script] 112 void setFocus(in Element aElement, in unsigned long aFlags); 113 114 /** 115 * Move the focus to another element. If aStartElement is specified, then 116 * movement is done relative to aStartElement. If aStartElement is null, 117 * then movement is done relative to the currently focused element. If no 118 * element is focused, focus the first focusable element within the 119 * document (or the last focusable element if aType is MOVEFOCUS_END). This 120 * method is equivalent to setting the focusedElement to the new element. 121 * 122 * Specifying aStartElement and using MOVEFOCUS_LAST is not currently 123 * implemented. 124 * 125 * If no element is found, and aType is either MOVEFOCUS_ROOT or 126 * MOVEFOCUS_CARET, then the focus is cleared. If aType is any other value, 127 * the focus is not changed. 128 * 129 * Returns the element that was focused (see setFocus). The return value 130 * may be null if focus was moved into a child process. 131 */ 132 Element moveFocus(in mozIDOMWindowProxy aWindow, 133 in Element aStartElement, 134 in unsigned long aType, in unsigned long aFlags); 135 136 /** 137 * Clears the focused element within aWindow. If the current focusedWindow 138 * is a descendant of aWindow, sets the current focusedWindow to aWindow. 139 * 140 * @throws NS_ERROR_INVALID_ARG if aWindow is null 141 */ 142 [can_run_script] 143 void clearFocus(in mozIDOMWindowProxy aWindow); 144 145 /** 146 * Returns the currently focused element within aWindow. If aWindow is equal 147 * to the current value of focusedWindow, then the returned element will be 148 * the application-wide focused element (the value of focusedElement). The 149 * return value will be null if no element is focused. 150 * 151 * If aDeep is true, then child frames are traversed and the return value 152 * may be the element within a child descendant window that is focused. If 153 * aDeep if false, then the return value will be the frame element if the 154 * focus is in a child frame. 155 * 156 * aFocusedWindow will be set to the currently focused descendant window of 157 * aWindow, or to aWindow if aDeep is false. This will be set even if no 158 * element is focused. 159 * 160 * @throws NS_ERROR_INVALID_ARG if aWindow is null 161 */ 162 Element getFocusedElementForWindow(in mozIDOMWindowProxy aWindow, 163 in boolean aDeep, 164 out mozIDOMWindowProxy aFocusedWindow); 165 166 /** 167 * Moves the selection caret within aWindow to the current focus. 168 */ 169 [can_run_script] 170 void moveCaretToFocus(in mozIDOMWindowProxy aWindow); 171 172 /*** 173 * Check if given element (or potentially a descendant, see setFocus) is 174 * focusable. 175 */ 176 [can_run_script] 177 boolean elementIsFocusable(in Element aElement, in unsigned long aFlags); 178 179 /* 180 * Raise the window when switching focus 181 */ 182 const unsigned long FLAG_RAISE = 1 << 0; 183 184 /** 185 * Do not scroll the element to focus into view. 186 */ 187 const unsigned long FLAG_NOSCROLL = 1 << 1; 188 189 /** 190 * If attempting to change focus in a window that is not focused, do not 191 * switch focus to that window. Instead, just update the focus within that 192 * window and leave the application focus as is. This flag will have no 193 * effect if a child window is focused and an attempt is made to adjust the 194 * focus in an ancestor, as the frame must be switched in this case. 195 */ 196 const unsigned long FLAG_NOSWITCHFRAME = 1 << 2; 197 198 /** 199 * This flag is only used when passed to moveFocus. If set, focus is never 200 * moved to the parent frame of the starting element's document, instead 201 * iterating around to the beginning of that document again. Child frames 202 * are navigated as normal. 203 */ 204 const unsigned long FLAG_NOPARENTFRAME = 1 << 3; 205 206 /** 207 * This flag is used for window and element focus operations to signal 208 * whether the caller is system or non system. 209 */ 210 const unsigned long FLAG_NONSYSTEMCALLER = 1 << 4; 211 212 /** 213 * Focus is changing due to a mouse operation, for instance the mouse was 214 * clicked on an element. 215 */ 216 const unsigned long FLAG_BYMOUSE = 1 << 12; 217 218 /** 219 * Focus is changing due to a key operation, for instance pressing the tab 220 * key. This flag would normally be passed when MOVEFOCUS_FORWARD or 221 * MOVEFOCUS_BACKWARD is used. 222 */ 223 const unsigned long FLAG_BYKEY = 1 << 13; 224 225 /** 226 * Focus is changing due to a call to MoveFocus. This flag will be implied 227 * when MoveFocus is called except when one of the other mechanisms (mouse 228 * or key) is specified, or when the type is MOVEFOCUS_ROOT or 229 * MOVEFOCUS_CARET. 230 */ 231 const unsigned long FLAG_BYMOVEFOCUS = 1 << 14; 232 233 /** 234 * Do not show a ring around the element to focus, if this is not a text 235 * control, regardless of other state. 236 */ 237 const unsigned long FLAG_NOSHOWRING = 1 << 15; 238 239 /** 240 * Always show the focus ring or other indicator of focus, regardless of 241 * other state. Overrides FLAG_NOSHOWRING. 242 */ 243 const unsigned long FLAG_SHOWRING = 1 << 16; 244 245 /** 246 * Focus is changing due to a touch operation that generated a mouse event. 247 * Normally used in conjunction with FLAG_BYMOUSE. 248 */ 249 const unsigned long FLAG_BYTOUCH = 1 << 17; 250 251 /** Focus is changing due to a JS focus() call or similar operation. */ 252 const unsigned long FLAG_BYJS = 1 << 18; 253 254 /** Focus is changing due to a long press operation by touch or mouse. */ 255 const unsigned long FLAG_BYLONGPRESS = 1 << 19; 256 257 /** Mask with all the focus methods. */ 258 const unsigned long METHOD_MASK = FLAG_BYMOUSE | FLAG_BYKEY | FLAG_BYMOVEFOCUS | FLAG_BYTOUCH | FLAG_BYJS | FLAG_BYLONGPRESS; 259 260 /** Mask with all the focus methods, plus the SHOW / NOSHOWRING flags. */ 261 const unsigned long METHODANDRING_MASK = METHOD_MASK | FLAG_SHOWRING | FLAG_NOSHOWRING; 262 263 // these constants are used with the aType argument to MoveFocus 264 265 /** move focus forward one element, used when pressing TAB */ 266 const unsigned long MOVEFOCUS_FORWARD = 1; 267 /** move focus backward one element, used when pressing Shift+TAB */ 268 const unsigned long MOVEFOCUS_BACKWARD = 2; 269 /** move focus forward to the next frame document, used when pressing F6 */ 270 const unsigned long MOVEFOCUS_FORWARDDOC = 3; 271 /** move focus forward to the previous frame document, used when pressing Shift+F6 */ 272 const unsigned long MOVEFOCUS_BACKWARDDOC = 4; 273 /** move focus to the first focusable element */ 274 const unsigned long MOVEFOCUS_FIRST = 5; 275 /** move focus to the last focusable element */ 276 const unsigned long MOVEFOCUS_LAST = 6; 277 /** move focus to the root element in the document */ 278 const unsigned long MOVEFOCUS_ROOT = 7; 279 /** move focus to a link at the position of the caret. This is a special value used to 280 * focus links as the caret moves over them in caret browsing mode. 281 */ 282 const unsigned long MOVEFOCUS_CARET = 8; 283 284 /** move focus to the first focusable document */ 285 const unsigned long MOVEFOCUS_FIRSTDOC = 9; 286 /** move focus to the last focusable document */ 287 const unsigned long MOVEFOCUS_LASTDOC = 10; 288 };