dom/interfaces/base/nsIFocusManager.idl

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:6dc63846061c
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 nsIDocument;
9 interface nsIContent;
10
11 [scriptable, uuid(51db277b-7ee7-4bce-9b84-fd2efcd2c8bd)]
12 /**
13 * The focus manager deals with all focus related behaviour. Only one element
14 * in the entire application may have the focus at a time; this element
15 * receives any keyboard events. While there is only one application-wide
16 * focused element, each nsIDOMWindow maintains a reference to the element
17 * that would be focused if the window was active.
18 *
19 * If the window's reference is to a frame element (iframe, browser,
20 * editor), then the child window contains the element that is currently
21 * focused. If the window's reference is to a root element, then the root is
22 * focused. If a window's reference is null, then no element is focused, yet
23 * the window is still focused.
24 *
25 * The blur event is fired on an element when it loses the application focus.
26 * After this blur event, if the focus is moving away from a document, two
27 * additional blur events are fired on the old document and window containing
28 * the focus respectively.
29 *
30 * When a new document is focused, two focus events are fired on the new
31 * document and window respectively. Then the focus event is fired on an
32 * element when it gains the application focus.
33 *
34 * A special case is that the root element may be focused, yet does not
35 * receive the element focus and blur events. Instead a focus outline may be
36 * drawn around the document.
37 *
38 * Blur and focus events do not bubble as per the W3C DOM Events spec.
39 */
40 interface nsIFocusManager : nsISupports
41 {
42 /**
43 * The most active (frontmost) window, or null if no window that is part of
44 * the application is active. Setting the activeWindow raises it, and
45 * focuses the current child window's current element, if any. Setting this
46 * to null or to a non-top-level window throws an NS_ERROR_INVALID_ARG
47 * exception.
48 */
49 attribute nsIDOMWindow activeWindow;
50
51 /**
52 * The child window within the activeWindow that is focused. This will
53 * always be activeWindow, a child window of activeWindow or null if no
54 * child window is focused. Setting the focusedWindow changes the focused
55 * window and raises the toplevel window it is in. If the current focus
56 * within the new focusedWindow is a frame element, then the focusedWindow
57 * will actually be set to the child window and the current element within
58 * that set as the focused element. This process repeats downwards until a
59 * non-frame element is found.
60 */
61 attribute nsIDOMWindow focusedWindow;
62
63 /**
64 * The element that is currently focused. This will always be an element
65 * within the document loaded in focusedWindow or null if no element in that
66 * document is focused.
67 */
68 readonly attribute nsIDOMElement focusedElement;
69
70 /**
71 * Returns the method that was used to focus the element in window. This
72 * will either be 0, FLAG_BYMOUSE or FLAG_BYKEY. If window is null, then
73 * the current focusedWindow will be used by default. This has the result
74 * of retrieving the method that was used to focus the currently focused
75 * element.
76 */
77 uint32_t getLastFocusMethod(in nsIDOMWindow window);
78
79 /**
80 * Changes the focused element reference within the window containing
81 * aElement to aElement.
82 */
83 void setFocus(in nsIDOMElement aElement, in unsigned long aFlags);
84
85 /**
86 * Move the focus to another element. If aStartElement is specified, then
87 * movement is done relative to aStartElement. If aStartElement is null,
88 * then movement is done relative to the currently focused element. If no
89 * element is focused, focus the first focusable element within the
90 * document (or the last focusable element if aType is MOVEFOCUS_END). This
91 * method is equivalent to setting the focusedElement to the new element.
92 *
93 * Specifying aStartElement and using MOVEFOCUS_LAST is not currently
94 * implemented.
95 *
96 * If no element is found, and aType is either MOVEFOCUS_ROOT or
97 * MOVEFOCUS_CARET, then the focus is cleared. If aType is any other value,
98 * the focus is not changed.
99 *
100 * Returns the element that was focused.
101 */
102 nsIDOMElement moveFocus(in nsIDOMWindow aWindow, in nsIDOMElement aStartElement,
103 in unsigned long aType, in unsigned long aFlags);
104
105 /**
106 * Clears the focused element within aWindow. If the current focusedWindow
107 * is a descendant of aWindow, sets the current focusedWindow to aWindow.
108 *
109 * @throws NS_ERROR_INVALID_ARG if aWindow is null
110 */
111 void clearFocus(in nsIDOMWindow aWindow);
112
113 /**
114 * Returns the currently focused element within aWindow. If aWindow is equal
115 * to the current value of focusedWindow, then the returned element will be
116 * the application-wide focused element (the value of focusedElement). The
117 * return value will be null if no element is focused.
118 *
119 * If aDeep is true, then child frames are traversed and the return value
120 * may be the element within a child descendant window that is focused. If
121 * aDeep if false, then the return value will be the frame element if the
122 * focus is in a child frame.
123 *
124 * aFocusedWindow will be set to the currently focused descendant window of
125 * aWindow, or to aWindow if aDeep is false. This will be set even if no
126 * element is focused.
127 *
128 * @throws NS_ERROR_INVALID_ARG if aWindow is null
129 */
130 nsIDOMElement getFocusedElementForWindow(in nsIDOMWindow aWindow, in boolean aDeep,
131 out nsIDOMWindow aFocusedWindow);
132
133 /**
134 * Moves the selection caret within aWindow to the current focus.
135 */
136 void moveCaretToFocus(in nsIDOMWindow aWindow);
137
138 /***
139 * Check if given element is focusable.
140 */
141 boolean elementIsFocusable(in nsIDOMElement aElement, in unsigned long aFlags);
142
143 /*
144 * Raise the window when switching focus
145 */
146 const unsigned long FLAG_RAISE = 1;
147
148 /**
149 * Do not scroll the element to focus into view
150 */
151 const unsigned long FLAG_NOSCROLL = 2;
152
153 /**
154 * If attempting to change focus in a window that is not focused, do not
155 * switch focus to that window. Instead, just update the focus within that
156 * window and leave the application focus as is. This flag will have no
157 * effect if a child window is focused and an attempt is made to adjust the
158 * focus in an ancestor, as the frame must be switched in this case.
159 */
160 const unsigned long FLAG_NOSWITCHFRAME = 4;
161
162 /**
163 * This flag is only used when passed to moveFocus. If set, focus is never
164 * moved to the parent frame of the starting element's document, instead
165 * iterating around to the beginning of that document again. Child frames
166 * are navigated as normal.
167 */
168 const unsigned long FLAG_NOPARENTFRAME = 8;
169
170 /**
171 * Focus is changing due to a mouse operation, for instance the mouse was
172 * clicked on an element.
173 */
174 const unsigned long FLAG_BYMOUSE = 0x1000;
175
176 /**
177 * Focus is changing due to a key operation, for instance pressing the tab
178 * key. This flag would normally be passed when MOVEFOCUS_FORWARD or
179 * MOVEFOCUS_BACKWARD is used.
180 */
181 const unsigned long FLAG_BYKEY = 0x2000;
182
183 /**
184 * Focus is changing due to a call to MoveFocus. This flag will be implied
185 * when MoveFocus is called except when one of the other mechanisms (mouse
186 * or key) is specified, or when the type is MOVEFOCUS_ROOT or
187 * MOVEFOCUS_CARET.
188 */
189 const unsigned long FLAG_BYMOVEFOCUS = 0x4000;
190
191 /**
192 * Always show the focus ring or other indicator of focus, regardless of
193 * other state.
194 */
195 const unsigned long FLAG_SHOWRING = 0x100000;
196
197 // these constants are used with the aType argument to MoveFocus
198
199 /** move focus forward one element, used when pressing TAB */
200 const unsigned long MOVEFOCUS_FORWARD = 1;
201 /** move focus backward one element, used when pressing Shift+TAB */
202 const unsigned long MOVEFOCUS_BACKWARD = 2;
203 /** move focus forward to the next frame document, used when pressing F6 */
204 const unsigned long MOVEFOCUS_FORWARDDOC = 3;
205 /** move focus forward to the previous frame document, used when pressing Shift+F6 */
206 const unsigned long MOVEFOCUS_BACKWARDDOC = 4;
207 /** move focus to the first focusable element */
208 const unsigned long MOVEFOCUS_FIRST = 5;
209 /** move focus to the last focusable element */
210 const unsigned long MOVEFOCUS_LAST = 6;
211 /** move focus to the root element in the document */
212 const unsigned long MOVEFOCUS_ROOT = 7;
213 /** move focus to a link at the position of the caret. This is a special value used to
214 * focus links as the caret moves over them in caret browsing mode.
215 */
216 const unsigned long MOVEFOCUS_CARET = 8;
217
218 /**
219 * Called when a window has been raised.
220 */
221 [noscript] void windowRaised(in nsIDOMWindow aWindow);
222
223 /**
224 * Called when a window has been lowered.
225 */
226 [noscript] void windowLowered(in nsIDOMWindow aWindow);
227
228 /**
229 * Called when a new document in a window is shown.
230 *
231 * If aNeedsFocus is true, then focus events are expected to be fired on the
232 * window if this window is in the focused window chain.
233 */
234 [noscript] void windowShown(in nsIDOMWindow aWindow, in boolean aNeedsFocus);
235
236 /**
237 * Called when a document in a window has been hidden or otherwise can no
238 * longer accept focus.
239 */
240 [noscript] void windowHidden(in nsIDOMWindow aWindow);
241
242 /**
243 * Fire any events that have been delayed due to synchronized actions.
244 */
245 [noscript] void fireDelayedEvents(in nsIDocument aDocument);
246
247 /**
248 * Indicate that a plugin wishes to take the focus. This is similar to a
249 * normal focus except that the widget focus is not changed. Updating the
250 * widget focus state is the responsibility of the caller.
251 */
252 [noscript] void focusPlugin(in nsIContent aPlugin);
253 };

mercurial