Logo Search packages:      
Sourcecode: xulrunner version File versions  Download package

PRBool nsIFrame::IsFocusable ( PRInt32 *  aTabIndex = nsnull,
PRBool  aWithMouse = PR_FALSE 
) [virtual, inherited]

Check if this frame is focusable and in the current tab order. Tabbable is indicated by a nonnegative tabindex & is a subset of focusable. For example, only the selected radio button in a group is in the tab order, unless the radio group has no selection in which case all of the visible, non-disabled radio buttons in the group are in the tab order. On the other hand, all of the visible, non-disabled radio buttons are always focusable via clicking or script. Also, depending on the pref accessibility.tabfocus some widgets may be focusable but removed from the tab order. This is the default on Mac OS X, where fewer items are focusable.

[in,optional] aTabIndex the computed tab index < 0 if not tabbable == 0 if in normal tab order > 0 can be tabbed to in the order specified by this value
[in,optional] aWithMouse, is this focus query for mouse clicking
whether the frame is focusable via mouse, kbd or script.

Definition at line 6097 of file nsFrame.cpp.

References nsIFrame::AreAncestorViewsVisible(), nsINode::eELEMENT, nsINode::eHTML, nsINode::GetParent(), nsIFrame::GetType(), nsIContent::HasAttr(), nsIContent::IsFocusable(), nsINode::IsNodeOfType(), and nsIContent::IsRootOfNativeAnonymousSubtree().

Referenced by nsGenericElement::SetFocus().

  PRInt32 tabIndex = -1;
  if (aTabIndex) {
    *aTabIndex = -1; // Default for early return is not focusable
  PRBool isFocusable = PR_FALSE;

  if (mContent && mContent->IsNodeOfType(nsINode::eELEMENT) &&
      AreAncestorViewsVisible()) {
    const nsStyleVisibility* vis = GetStyleVisibility();
    if (vis->mVisible != NS_STYLE_VISIBILITY_COLLAPSE &&
        vis->mVisible != NS_STYLE_VISIBILITY_HIDDEN) {
      const nsStyleUserInterface* ui = GetStyleUserInterface();
      if (ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE &&
          ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE) {
        // Pass in default tabindex of -1 for nonfocusable and 0 for focusable
        tabIndex = 0;
      isFocusable = mContent->IsFocusable(&tabIndex);
      if (!isFocusable && !aWithMouse &&
          GetType() == nsGkAtoms::scrollFrame &&
          mContent->IsNodeOfType(nsINode::eHTML) &&
          !mContent->IsRootOfNativeAnonymousSubtree() &&
          mContent->GetParent() &&
          !mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
        // Elements with scrollable view are focusable with script & tabbable
        // Otherwise you couldn't scroll them with keyboard, which is
        // an accessibility issue (e.g. Section 508 rules)
        // However, we don't make them to be focusable with the mouse,
        // because the extra focus outlines are considered unnecessarily ugly.
        // When clicked on, the selection position within the element 
        // will be enough to make them keyboard scrollable.
        nsCOMPtr<nsIScrollableFrame> scrollFrame = do_QueryInterface(this);
        if (scrollFrame) {
          nsMargin margin = scrollFrame->GetActualScrollbarSizes();
          if (margin.top || margin.right || margin.bottom || margin.left) {
            // Scroll bars will be used for overflow
            isFocusable = PR_TRUE;
            tabIndex = 0;

  if (aTabIndex) {
    *aTabIndex = tabIndex;
  return isFocusable;

Generated by  Doxygen 1.6.0   Back to index