Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsIFocusManager

Please add a summary to this article.
1.0
34.0.5
Introduced
Gecko 1.9.2
Inherits from: nsISupports Last changed in Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2)

Implemented by: @mozilla.org/focus-manager;1 as a service:

var focusManager = Components.classes["@mozilla.org/focus-manager;1"]
                     .getService(Components.interfaces.nsIFocusManager);

Method overview

void clearFocus(in nsIDOMWindow aWindow);
void contentRemoved(in nsIDocument aDocument, in nsIContent aElement); Native code only! Obsolete since Gecko 2.0
void fireDelayedEvents(in nsIDocument aDocument); Native code only!
void focusPlugin(in nsIContent aPlugin); Native code only!
nsIDOMElement getFocusedElementForWindow(in nsIDOMWindow aWindow, in PRBool aDeep, out nsIDOMWindow aFocusedWindow);
PRUint32 getLastFocusMethod(in nsIDOMWindow window);
void moveCaretToFocus(in nsIDOMWindow aWindow);
void elementIsFocusable(in nsIDOMElement aElement, in unsigned long aFlags);
nsIDOMElement moveFocus(in nsIDOMWindow aWindow, in nsIDOMElement aStartElement, in unsigned long aType, in unsigned long aFlags);
void setFocus(in nsIDOMElement aElement, in unsigned long aFlags);
void windowHidden(in nsIDOMWindow aWindow); Native code only!
void windowLowered(in nsIDOMWindow aWindow); Native code only!
void windowRaised(in nsIDOMWindow aWindow); Native code only!
void windowShown(in nsIDOMWindow aWindow, in PRBool aNeedsFocus); Native code only!

Attributes

Attribute Type Description
activeWindow nsIDOMWindow The most active (frontmost) window, or null if no window that is part of the application is active. Setting the activeWindow raises it, and focuses the current child window's current element, if any. Setting this to null or to a non-top-level window throws an NS_ERROR_INVALID_ARG exception.
focusedElement nsIDOMElement The element that is currently focused. This will always be an element within the document loaded in focusedWindow or null if no element in that document is focused. Read only.
focusedWindow nsIDOMWindow The child window within the activeWindow that is focused. This will always be activeWindow, a child window of activeWindow or null if no child window is focused. Setting the focusedWindow changes the focused window and raises the toplevel window it is in. If the current focus within the new focusedWindow is a frame element, then the focusedWindow will actually be set to the child window and the current element within that set as the focused element. This process repeats downwards until a non-frame element is found.

Constants

Constant Value Description
FLAG_RAISE 1  
FLAG_NOSCROLL 2 Do not scroll the element to focus into view.
FLAG_NOSWITCHFRAME 4 If attempting to change focus in a window that is not focused, do not switch focus to that window. Instead, just update the focus within that window and leave the application focus as is. This flag will have no effect if a child window is focused and an attempt is made to adjust the focus in an ancestor, as the frame must be switched in this case.
FLAG_BYMOUSE 0x1000 Focus is changing due to a mouse operation, for instance the mouse was clicked on an element.
FLAG_BYKEY 0x2000 Focus is changing due to a key operation, for instance pressing the tab key. This flag would normally be passed when MOVEFOCUS_FORWARD or MOVEFOCUS_BACKWARD is used.
FLAG_BYMOVEFOCUS 0x4000 Focus is changing due to a call to MoveFocus(). This flag will be implied when MoveFocus() is called except when one of the other mechanisms (mouse or key) is specified, or when the type is MOVEFOCUS_ROOT or MOVEFOCUS_CARET.
FLAG_SHOWRING 0x100000 Always show the focus ring or other indicator of focus, regardless of other state.
MOVEFOCUS_FORWARD 1 Move focus forward one element, used when pressing TAB.
MOVEFOCUS_BACKWARD 2 Move focus backward one element, used when pressing Shift+TAB.
MOVEFOCUS_FORWARDDOC 3 Move focus forward to the next frame document, used when pressing F6.
MOVEFOCUS_BACKWARDDOC 4 Move focus forward to the previous frame document, used when pressing Shift+F6.
MOVEFOCUS_FIRST 5 Move focus to the first focusable element.
MOVEFOCUS_LAST 6 Move focus to the last focusable element.
MOVEFOCUS_ROOT 7 Move focus to the root element in the document.
MOVEFOCUS_CARET 8 Move focus to a link at the position of the caret. This is a special value used to focus links as the caret moves over them in caret browsing mode.

Methods

clearFocus()

Clears the focused element within aWindow. If the current focusedWindow is a descendant of aWindow, sets the current focusedWindow to aWindow.

void clearFocus(
  in nsIDOMWindow aWindow
);
Parameters
aWindow
 
Exceptions thrown
NS_ERROR_INVALID_ARG
If aWindow is null.

Native code only!

contentRemoved

Obsolete since Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Called when content has been removed.

void contentRemoved(
  in nsIDocument aDocument,
  in nsIContent aElement
);
Parameters
aDocument
 
aElement
 

Native code only!

fireDelayedEvents

Fire any events that have been delayed due to synchronized actions.

void fireDelayedEvents(
  in nsIDocument aDocument
);
Parameters
aDocument
 

Native code only!

focusPlugin

Indicate that a plugin wishes to take the focus. This is similar to a normal focus except that the widget focus is not changed. Updating the widget focus state is the responsibility of the caller.

void focusPlugin(
  in nsIContent aPlugin
);
Parameters
aPlugin
 

getFocusedElementForWindow()

nsIDOMElement getFocusedElementForWindow(
  in nsIDOMWindow aWindow,
  in PRBool aDeep,
  out nsIDOMWindow aFocusedWindow
);
Parameters
aWindow
If equal to the current value of focusedWindow, then the returned element will be the application-wide focused element (the value of focusedElement). The return value will be null if no element is focused.
aDeep
If true, then child frames are traversed and the return value may be the element within a child descendant window that is focused. If false, then the return value will be the frame element if the focus is in a child frame.
aFocusedWindow
Will be set to the currently focused descendant window of aWindow, or to aWindow if aDeep is false. This will be set even if no element is focused.
Return value

The currently focused element within aWindow.

Exceptions thrown
NS_ERROR_INVALID_ARG
If aWindow is null.

getLastFocusMethod()

PRUint32 getLastFocusMethod(
  in nsIDOMWindow window
);
Parameters
window
If null, then the current focusedWindow will be used by default. This has the result of retrieving the method that was used to focus the currently focused element.
Return value

The method that was used to focus the element in window. This will either be 0, FLAG_BYMOUSE or FLAG_BYKEY.

moveCaretToFocus()

Moves the selection caret within aWindow to the current focus.

void moveCaretToFocus(
  in nsIDOMWindow aWindow
);
Parameters
aWindow
 

elementIsFocusable()

Check if given element is focusable.

boolean elementIsFocusable(in nsIDOMElement aElement, in unsigned long aFlags);
Parameters
aElement
 
aFlags
 
Return value

True if aElement is focusable.

 

moveFocus()

Move the focus to another element. If aStartElement is specified, then movement is done relative to aStartElement. If aStartElement is null, then movement is done relative to the currently focused element. If no element is focused, focus the first focusable element within the document (or the last focusable element if aType is MOVEFOCUS_END). This method is equivalent to setting the focusedElement to the new element.

Specifying aStartElement and using MOVEFOCUS_LAST is not currently implemented.

If no element is found, and aType is either MOVEFOCUS_ROOT or MOVEFOCUS_CARET, then the focus is cleared. If aType is any other value, the focus is not changed.

nsIDOMElement moveFocus(
  in nsIDOMWindow aWindow,
  in nsIDOMElement aStartElement,
  in unsigned long aType,
  in unsigned long aFlags
);
Parameters
aWindow
 
aStartElement
 
aType
 
aFlags
 
Return value

The element that was focused.

setFocus()

Changes the focused element reference within the window containing aElement to aElement.

void setFocus(
  in nsIDOMElement aElement,
  in unsigned long aFlags
);
Parameters
aElement
 
aFlags
 

Native code only!

windowHidden

Called when a document in a window has been hidden or otherwise can no longer accept focus.

void windowHidden(
  in nsIDOMWindow aWindow
);
Parameters
aWindow
 

Native code only!

windowLowered

Called when a window has been lowered.

void windowLowered(
  in nsIDOMWindow aWindow
);
Parameters
aWindow
 

Native code only!

windowRaised

Called when a window has been raised.

void windowRaised(
  in nsIDOMWindow aWindow
);
Parameters
aWindow
 

Native code only!

windowShown

Called when a new document in a window is shown.

void windowShown(
  in nsIDOMWindow aWindow,
  in PRBool aNeedsFocus
);
Parameters
aWindow
 
aNeedsFocus
If true, then focus events are expected to be fired on the window if this window is in the focused window chain.

Document Tags and Contributors

 Contributors to this page: Changbin, Sheppy, freaktechnik, trevorh
 Last updated by: Changbin,