michael@0: /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "domstubs.idl" michael@0: michael@0: interface nsIDocument; michael@0: interface nsIContent; michael@0: michael@0: [scriptable, uuid(51db277b-7ee7-4bce-9b84-fd2efcd2c8bd)] michael@0: /** michael@0: * The focus manager deals with all focus related behaviour. Only one element michael@0: * in the entire application may have the focus at a time; this element michael@0: * receives any keyboard events. While there is only one application-wide michael@0: * focused element, each nsIDOMWindow maintains a reference to the element michael@0: * that would be focused if the window was active. michael@0: * michael@0: * If the window's reference is to a frame element (iframe, browser, michael@0: * editor), then the child window contains the element that is currently michael@0: * focused. If the window's reference is to a root element, then the root is michael@0: * focused. If a window's reference is null, then no element is focused, yet michael@0: * the window is still focused. michael@0: * michael@0: * The blur event is fired on an element when it loses the application focus. michael@0: * After this blur event, if the focus is moving away from a document, two michael@0: * additional blur events are fired on the old document and window containing michael@0: * the focus respectively. michael@0: * michael@0: * When a new document is focused, two focus events are fired on the new michael@0: * document and window respectively. Then the focus event is fired on an michael@0: * element when it gains the application focus. michael@0: * michael@0: * A special case is that the root element may be focused, yet does not michael@0: * receive the element focus and blur events. Instead a focus outline may be michael@0: * drawn around the document. michael@0: * michael@0: * Blur and focus events do not bubble as per the W3C DOM Events spec. michael@0: */ michael@0: interface nsIFocusManager : nsISupports michael@0: { michael@0: /** michael@0: * The most active (frontmost) window, or null if no window that is part of michael@0: * the application is active. Setting the activeWindow raises it, and michael@0: * focuses the current child window's current element, if any. Setting this michael@0: * to null or to a non-top-level window throws an NS_ERROR_INVALID_ARG michael@0: * exception. michael@0: */ michael@0: attribute nsIDOMWindow activeWindow; michael@0: michael@0: /** michael@0: * The child window within the activeWindow that is focused. This will michael@0: * always be activeWindow, a child window of activeWindow or null if no michael@0: * child window is focused. Setting the focusedWindow changes the focused michael@0: * window and raises the toplevel window it is in. If the current focus michael@0: * within the new focusedWindow is a frame element, then the focusedWindow michael@0: * will actually be set to the child window and the current element within michael@0: * that set as the focused element. This process repeats downwards until a michael@0: * non-frame element is found. michael@0: */ michael@0: attribute nsIDOMWindow focusedWindow; michael@0: michael@0: /** michael@0: * The element that is currently focused. This will always be an element michael@0: * within the document loaded in focusedWindow or null if no element in that michael@0: * document is focused. michael@0: */ michael@0: readonly attribute nsIDOMElement focusedElement; michael@0: michael@0: /** michael@0: * Returns the method that was used to focus the element in window. This michael@0: * will either be 0, FLAG_BYMOUSE or FLAG_BYKEY. If window is null, then michael@0: * the current focusedWindow will be used by default. This has the result michael@0: * of retrieving the method that was used to focus the currently focused michael@0: * element. michael@0: */ michael@0: uint32_t getLastFocusMethod(in nsIDOMWindow window); michael@0: michael@0: /** michael@0: * Changes the focused element reference within the window containing michael@0: * aElement to aElement. michael@0: */ michael@0: void setFocus(in nsIDOMElement aElement, in unsigned long aFlags); michael@0: michael@0: /** michael@0: * Move the focus to another element. If aStartElement is specified, then michael@0: * movement is done relative to aStartElement. If aStartElement is null, michael@0: * then movement is done relative to the currently focused element. If no michael@0: * element is focused, focus the first focusable element within the michael@0: * document (or the last focusable element if aType is MOVEFOCUS_END). This michael@0: * method is equivalent to setting the focusedElement to the new element. michael@0: * michael@0: * Specifying aStartElement and using MOVEFOCUS_LAST is not currently michael@0: * implemented. michael@0: * michael@0: * If no element is found, and aType is either MOVEFOCUS_ROOT or michael@0: * MOVEFOCUS_CARET, then the focus is cleared. If aType is any other value, michael@0: * the focus is not changed. michael@0: * michael@0: * Returns the element that was focused. michael@0: */ michael@0: nsIDOMElement moveFocus(in nsIDOMWindow aWindow, in nsIDOMElement aStartElement, michael@0: in unsigned long aType, in unsigned long aFlags); michael@0: michael@0: /** michael@0: * Clears the focused element within aWindow. If the current focusedWindow michael@0: * is a descendant of aWindow, sets the current focusedWindow to aWindow. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if aWindow is null michael@0: */ michael@0: void clearFocus(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * Returns the currently focused element within aWindow. If aWindow is equal michael@0: * to the current value of focusedWindow, then the returned element will be michael@0: * the application-wide focused element (the value of focusedElement). The michael@0: * return value will be null if no element is focused. michael@0: * michael@0: * If aDeep is true, then child frames are traversed and the return value michael@0: * may be the element within a child descendant window that is focused. If michael@0: * aDeep if false, then the return value will be the frame element if the michael@0: * focus is in a child frame. michael@0: * michael@0: * aFocusedWindow will be set to the currently focused descendant window of michael@0: * aWindow, or to aWindow if aDeep is false. This will be set even if no michael@0: * element is focused. michael@0: * michael@0: * @throws NS_ERROR_INVALID_ARG if aWindow is null michael@0: */ michael@0: nsIDOMElement getFocusedElementForWindow(in nsIDOMWindow aWindow, in boolean aDeep, michael@0: out nsIDOMWindow aFocusedWindow); michael@0: michael@0: /** michael@0: * Moves the selection caret within aWindow to the current focus. michael@0: */ michael@0: void moveCaretToFocus(in nsIDOMWindow aWindow); michael@0: michael@0: /*** michael@0: * Check if given element is focusable. michael@0: */ michael@0: boolean elementIsFocusable(in nsIDOMElement aElement, in unsigned long aFlags); michael@0: michael@0: /* michael@0: * Raise the window when switching focus michael@0: */ michael@0: const unsigned long FLAG_RAISE = 1; michael@0: michael@0: /** michael@0: * Do not scroll the element to focus into view michael@0: */ michael@0: const unsigned long FLAG_NOSCROLL = 2; michael@0: michael@0: /** michael@0: * If attempting to change focus in a window that is not focused, do not michael@0: * switch focus to that window. Instead, just update the focus within that michael@0: * window and leave the application focus as is. This flag will have no michael@0: * effect if a child window is focused and an attempt is made to adjust the michael@0: * focus in an ancestor, as the frame must be switched in this case. michael@0: */ michael@0: const unsigned long FLAG_NOSWITCHFRAME = 4; michael@0: michael@0: /** michael@0: * This flag is only used when passed to moveFocus. If set, focus is never michael@0: * moved to the parent frame of the starting element's document, instead michael@0: * iterating around to the beginning of that document again. Child frames michael@0: * are navigated as normal. michael@0: */ michael@0: const unsigned long FLAG_NOPARENTFRAME = 8; michael@0: michael@0: /** michael@0: * Focus is changing due to a mouse operation, for instance the mouse was michael@0: * clicked on an element. michael@0: */ michael@0: const unsigned long FLAG_BYMOUSE = 0x1000; michael@0: michael@0: /** michael@0: * Focus is changing due to a key operation, for instance pressing the tab michael@0: * key. This flag would normally be passed when MOVEFOCUS_FORWARD or michael@0: * MOVEFOCUS_BACKWARD is used. michael@0: */ michael@0: const unsigned long FLAG_BYKEY = 0x2000; michael@0: michael@0: /** michael@0: * Focus is changing due to a call to MoveFocus. This flag will be implied michael@0: * when MoveFocus is called except when one of the other mechanisms (mouse michael@0: * or key) is specified, or when the type is MOVEFOCUS_ROOT or michael@0: * MOVEFOCUS_CARET. michael@0: */ michael@0: const unsigned long FLAG_BYMOVEFOCUS = 0x4000; michael@0: michael@0: /** michael@0: * Always show the focus ring or other indicator of focus, regardless of michael@0: * other state. michael@0: */ michael@0: const unsigned long FLAG_SHOWRING = 0x100000; michael@0: michael@0: // these constants are used with the aType argument to MoveFocus michael@0: michael@0: /** move focus forward one element, used when pressing TAB */ michael@0: const unsigned long MOVEFOCUS_FORWARD = 1; michael@0: /** move focus backward one element, used when pressing Shift+TAB */ michael@0: const unsigned long MOVEFOCUS_BACKWARD = 2; michael@0: /** move focus forward to the next frame document, used when pressing F6 */ michael@0: const unsigned long MOVEFOCUS_FORWARDDOC = 3; michael@0: /** move focus forward to the previous frame document, used when pressing Shift+F6 */ michael@0: const unsigned long MOVEFOCUS_BACKWARDDOC = 4; michael@0: /** move focus to the first focusable element */ michael@0: const unsigned long MOVEFOCUS_FIRST = 5; michael@0: /** move focus to the last focusable element */ michael@0: const unsigned long MOVEFOCUS_LAST = 6; michael@0: /** move focus to the root element in the document */ michael@0: const unsigned long MOVEFOCUS_ROOT = 7; michael@0: /** move focus to a link at the position of the caret. This is a special value used to michael@0: * focus links as the caret moves over them in caret browsing mode. michael@0: */ michael@0: const unsigned long MOVEFOCUS_CARET = 8; michael@0: michael@0: /** michael@0: * Called when a window has been raised. michael@0: */ michael@0: [noscript] void windowRaised(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * Called when a window has been lowered. michael@0: */ michael@0: [noscript] void windowLowered(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * Called when a new document in a window is shown. michael@0: * michael@0: * If aNeedsFocus is true, then focus events are expected to be fired on the michael@0: * window if this window is in the focused window chain. michael@0: */ michael@0: [noscript] void windowShown(in nsIDOMWindow aWindow, in boolean aNeedsFocus); michael@0: michael@0: /** michael@0: * Called when a document in a window has been hidden or otherwise can no michael@0: * longer accept focus. michael@0: */ michael@0: [noscript] void windowHidden(in nsIDOMWindow aWindow); michael@0: michael@0: /** michael@0: * Fire any events that have been delayed due to synchronized actions. michael@0: */ michael@0: [noscript] void fireDelayedEvents(in nsIDocument aDocument); michael@0: michael@0: /** michael@0: * Indicate that a plugin wishes to take the focus. This is similar to a michael@0: * normal focus except that the widget focus is not changed. Updating the michael@0: * widget focus state is the responsibility of the caller. michael@0: */ michael@0: [noscript] void focusPlugin(in nsIContent aPlugin); michael@0: };