nsIFocusManager 编辑

dom/interfaces/base/nsIFocusManager.idlScriptable Please add a summary to this article. 1.0 66 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

AttributeTypeDescription
activeWindownsIDOMWindowThe 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.
focusedElementnsIDOMElementThe 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.
focusedWindownsIDOMWindowThe 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

ConstantValueDescription
FLAG_RAISE1 
FLAG_NOSCROLL2Do not scroll the element to focus into view.
FLAG_NOSWITCHFRAME4If 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_BYMOUSE0x1000Focus is changing due to a mouse operation, for instance the mouse was clicked on an element.
FLAG_BYKEY0x2000Focus 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_BYMOVEFOCUS0x4000Focus 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_SHOWRING0x100000Always show the focus ring or other indicator of focus, regardless of other state.
MOVEFOCUS_FORWARD1Move focus forward one element, used when pressing TAB.
MOVEFOCUS_BACKWARD2Move focus backward one element, used when pressing Shift+TAB.
MOVEFOCUS_FORWARDDOC3Move focus forward to the next frame document, used when pressing F6.
MOVEFOCUS_BACKWARDDOC4Move focus forward to the previous frame document, used when pressing Shift+F6.
MOVEFOCUS_FIRST5Move focus to the first focusable element.
MOVEFOCUS_LAST6Move focus to the last focusable element.
MOVEFOCUS_ROOT7Move focus to the root element in the document.
MOVEFOCUS_CARET8Move 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:72 次

字数:17527

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文