Bug 761188 - reuse layout code for accessible boundaries calculation, r=tbsaunde, f=bz
authorAlexander Surkov <surkov.alexander@gmail.com>
Sun, 10 Jun 2012 22:31:27 +0900
changeset 96323 f0bdbbca7380aa10d69a3a2a5c66bc03a5891b3f
parent 96322 dcd70e227b9619b7865696843293bb351df27461
child 96324 05842457dfdf3e07ab4475c63805c2c41ca1dea2
push id22887
push userryanvm@gmail.com
push dateSun, 10 Jun 2012 22:21:35 +0000
treeherdermozilla-central@efa1dbf0da74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs761188
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 761188 - reuse layout code for accessible boundaries calculation, r=tbsaunde, f=bz
accessible/src/generic/Accessible.cpp
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -876,99 +876,25 @@ Accessible::GetDeepestChildAtPoint(PRInt
 
   NS_IF_ADDREF(*aAccessible = ChildAtPoint(aX, aY, eDeepestChild));
   return NS_OK;
 }
 
 void
 Accessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
 {
-/*
- * This method is used to determine the bounds of a content node.
- * Because HTML wraps and links are not always rectangular, this
- * method uses the following algorithm:
- *
- * 1) Start with an empty rectangle
- * 2) Add the rect for the primary frame from for the DOM node.
- * 3) For each next frame at the same depth with the same DOM node, add that rect to total
- * 4) If that frame is an inline frame, search deeper at that point in the tree, adding all rects
- */
-
-  // Initialization area
-  *aBoundingFrame = nsnull;
-  nsIFrame* firstFrame = GetFrame();
-  if (!firstFrame)
-    return;
-
-  // Find common relative parent
-  // This is an ancestor frame that will incompass all frames for this content node.
-  // We need the relative parent so we can get absolute screen coordinates
-  nsIFrame *ancestorFrame = firstFrame;
-
-  while (ancestorFrame) {  
-    *aBoundingFrame = ancestorFrame;
-    // If any other frame type, we only need to deal with the primary frame
-    // Otherwise, there may be more frames attached to the same content node
-    if (ancestorFrame->GetType() != nsGkAtoms::inlineFrame &&
-        ancestorFrame->GetType() != nsGkAtoms::textFrame)
-      break;
-    ancestorFrame = ancestorFrame->GetParent();
-  }
-
-  nsIFrame *iterFrame = firstFrame;
-  nsCOMPtr<nsIContent> firstContent(mContent);
-  nsIContent* iterContent = firstContent;
-  PRInt32 depth = 0;
-
-  // Look only at frames below this depth, or at this depth (if we're still on the content node we started with)
-  while (iterContent == firstContent || depth > 0) {
-    // Coordinates will come back relative to parent frame
-    nsRect currFrameBounds = iterFrame->GetRect();
-    
-    // Make this frame's bounds relative to common parent frame
-    currFrameBounds +=
-      iterFrame->GetParent()->GetOffsetToExternal(*aBoundingFrame);
-
-    // Add this frame's bounds to total
-    aTotalBounds.UnionRect(aTotalBounds, currFrameBounds);
-
-    nsIFrame *iterNextFrame = nsnull;
-
-    if (iterFrame->GetType() == nsGkAtoms::inlineFrame) {
-      // Only do deeper bounds search if we're on an inline frame
-      // Inline frames can contain larger frames inside of them
-      iterNextFrame = iterFrame->GetFirstPrincipalChild();
-    }
-
-    if (iterNextFrame) 
-      ++depth;  // Child was found in code above this: We are going deeper in this iteration of the loop
-    else {  
-      // Use next sibling if it exists, or go back up the tree to get the first next-in-flow or next-sibling 
-      // within our search
-      while (iterFrame) {
-        iterNextFrame = iterFrame->GetNextContinuation();
-        if (!iterNextFrame)
-          iterNextFrame = iterFrame->GetNextSibling();
-        if (iterNextFrame || --depth < 0) 
-          break;
-        iterFrame = iterFrame->GetParent();
-      }
-    }
-
-    // Get ready for the next round of our loop
-    iterFrame = iterNextFrame;
-    if (iterFrame == nsnull)
-      break;
-    iterContent = nsnull;
-    if (depth == 0)
-      iterContent = iterFrame->GetContent();
+  nsIFrame* frame = GetFrame();
+  if (frame) {
+    *aBoundingFrame = nsLayoutUtils::GetContainingBlockForClientRect(frame);
+    aTotalBounds = nsLayoutUtils::
+      GetAllInFlowRectsUnion(frame, *aBoundingFrame,
+                             nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
   }
 }
 
-
 /* void getBounds (out long x, out long y, out long width, out long height); */
 NS_IMETHODIMP
 Accessible::GetBounds(PRInt32* aX, PRInt32* aY,
                       PRInt32* aWidth, PRInt32* aHeight)
 {
   NS_ENSURE_ARG_POINTER(aX);
   *aX = 0;
   NS_ENSURE_ARG_POINTER(aY);