Commit b0fb6c2c authored by Timothy Nikkel's avatar Timothy Nikkel
Browse files

Bug 655264. Clean up some a11y code and make it less reliant on views. r=roc f=surkov

parent 1f924d27
Loading
Loading
Loading
Loading
+2 −47
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@
#include "nsIForm.h"
#include "nsIFormControl.h"

#include "nsLayoutUtils.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsIFrame.h"
@@ -682,15 +683,7 @@ nsAccessible::IsVisible(PRBool* aIsOffscreen)
  }

  // The frame intersects the viewport, but we need to check the parent view chain :(
  nsIDocument* doc = mContent->GetOwnerDoc();
  if (!doc)  {
    return PR_FALSE;
  }

  nsIFrame* frameWithView =
    frame->HasView() ? frame : frame->GetAncestorWithViewExternal();
  nsIView* view = frameWithView->GetViewExternal();
  PRBool isVisible = CheckVisibilityInParentChain(doc, view);
  bool isVisible = nsCoreUtils::CheckVisibilityInParentChain(frame);
  if (isVisible && rectVisibility == nsRectVisibility_kVisible) {
    *aIsOffscreen = PR_FALSE;
  }
@@ -3251,44 +3244,6 @@ nsAccessible::GetFirstAvailableAccessible(nsINode *aStartNode) const
  return nsnull;
}

PRBool nsAccessible::CheckVisibilityInParentChain(nsIDocument* aDocument, nsIView* aView)
{
  nsIDocument* document = aDocument;
  nsIView* view = aView;
  // both view chain and widget chain are broken between chrome and content
  while (document != nsnull) {
    while (view != nsnull) {
      if (view->GetVisibility() == nsViewVisibility_kHide) {
        return PR_FALSE;
      }
      view = view->GetParent();
    }

    nsIDocument* parentDoc = document->GetParentDocument();
    if (parentDoc != nsnull) {
      nsIContent* content = parentDoc->FindContentForSubDocument(document);
      if (content != nsnull) {
        nsIPresShell* shell = parentDoc->GetShell();
        if (!shell) {
          return PR_FALSE;
        }
        nsIFrame* frame = content->GetPrimaryFrame();
        while (frame != nsnull && !frame->HasView()) {
          frame = frame->GetParent();
        }

        if (frame != nsnull) {
          view = frame->GetViewExternal();
        }
      }
    }

    document = parentDoc;
  }

  return PR_TRUE;
}

nsresult
nsAccessible::GetAttrValue(nsIAtom *aProperty, double *aValue)
{
+0 −3
Original line number Diff line number Diff line
@@ -606,9 +606,6 @@ protected:
  //////////////////////////////////////////////////////////////////////////////
  // Helpers

  // Check the visibility across both parent content and chrome
  PRBool CheckVisibilityInParentChain(nsIDocument* aDocument, nsIView* aView);

  /**
   *  Get the container node for an atomic region, defined by aria-atomic="true"
   *  @return the container node
+25 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@
#include "nsPIDOMWindow.h"
#include "nsGUIEvent.h"
#include "nsIView.h"
#include "nsLayoutUtils.h"

#include "nsContentCID.h"
#include "nsComponentManagerUtils.h"
@@ -753,6 +754,30 @@ nsCoreUtils::IsColumnHidden(nsITreeColumn *aColumn)
                              nsAccessibilityAtoms::_true, eCaseMatters);
}

bool
nsCoreUtils::CheckVisibilityInParentChain(nsIFrame* aFrame)
{
  nsIView* view = aFrame->GetClosestView();
  if (view && !view->IsEffectivelyVisible())
    return false;

  nsIPresShell* presShell = aFrame->PresContext()->GetPresShell();
  while (presShell) {
    if (!presShell->IsActive()) {
      return false;
    }

    nsIFrame* rootFrame = presShell->GetRootFrame();
    presShell = nsnull;
    if (rootFrame) {
      nsIFrame* frame = nsLayoutUtils::GetCrossDocParentFrame(rootFrame);
      if (frame) {
        presShell = frame->PresContext()->GetPresShell();
      }
    }
  }
  return true;
}

////////////////////////////////////////////////////////////////////////////////
// nsAccessibleDOMStringList
+6 −0
Original line number Diff line number Diff line
@@ -367,6 +367,12 @@ public:
    return aContent->NodeInfo()->Equals(nsAccessibilityAtoms::th) ||
      aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::scope);
  }

  /**
   * Check the visibility across both parent content and chrome.
   */
  static bool CheckVisibilityInParentChain(nsIFrame* aFrame);

};


+1 −6
Original line number Diff line number Diff line
@@ -313,12 +313,7 @@ nsDocAccessible::NativeState()
  }
 
  nsIFrame* frame = GetFrame();
  while (frame != nsnull && !frame->HasView()) {
    frame = frame->GetParent();
  }
 
  if (frame == nsnull ||
      !CheckVisibilityInParentChain(mDocument, frame->GetViewExternal())) {
  if (!frame || !nsCoreUtils::CheckVisibilityInParentChain(frame)) {
    state |= states::INVISIBLE | states::OFFSCREEN;
  }