Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsSpatialNavigation.cpp File Reference
#include "nsSpatialNavigationPrivate.h"

Go to the source code of this file.

Functions

void DoTraversal (int aDirection, nsIBidirectionalEnumerator *aFrameTraversal, nsIFrame *aFocusedFrame, nsRect &aFocusedRect, PRBool isAREA, PRBool focusDocuments, nsPresContext *aPresContext, PRInt64 *aDSoFar, nsIContent **aCurrentContent)
void centerRect (int aDirection, nsRect &aRect)

Variables

PRInt32 gRectFudge = 20
PRInt32 gDirectionalBias = 1

Function Documentation

void centerRect ( int  aDirection,
nsRect aRect 
) [inline]

Definition at line 562 of file nsSpatialNavigation.cpp.

{
  if (aDirection == eNavLeft)
    aRect.x = 1000000;
  else if (aDirection == eNavRight)
    aRect.x = 0;
  else if (aDirection == eNavUp)
    aRect.y = 1000000;
  else
    aRect.y = 0;

  aRect.height = 1;
  aRect.width = 1;
}

Here is the caller graph for this function:

void DoTraversal ( int  aDirection,
nsIBidirectionalEnumerator aFrameTraversal,
nsIFrame aFocusedFrame,
nsRect aFocusedRect,
PRBool  isAREA,
PRBool  focusDocuments,
nsPresContext aPresContext,
PRInt64 aDSoFar,
nsIContent **  aCurrentContent 
)

Definition at line 410 of file nsSpatialNavigation.cpp.

{

  *aCurrentContent = nsnull;

  // There are some rects with zero width or height.
  // calculating distance from a non point is troublesome.
  // we will fix this up here by setting such a point to at
  // least 1 px.

  if (aFocusedRect.width == 0) {
    aFocusedRect.width = 1;
  }

  if (aFocusedRect.height == 0) {
    aFocusedRect.height = 1;
  }

  nsIFrame* frame;
  nsRect frameRect;
  
  PRInt64 d;
  
  while (1) 
  {
    aFrameTraversal->Next();
    
    nsISupports* currentItem;
    aFrameTraversal->CurrentItem(&currentItem);
    frame = NS_STATIC_CAST(nsIFrame*, currentItem);

    if (!frame)
      break;
#ifdef DEBUG_outputframes
    printf("got frame %x\n", frame);
#endif
    // So, here we want to make sure that the frame that we
    // nav to isn't part of the flow of the currently
    // focused frame

       if (!isAREA) 
    {
      nsIFrame* flowFrame = aFocusedFrame;
      PRBool currentFrameIsFocusedFrame = PR_FALSE;
      while (flowFrame) 
      {
        if (flowFrame == frame) 
        {
          currentFrameIsFocusedFrame = PR_TRUE;
          break;
        }
        flowFrame = flowFrame->GetNextInFlow();
      }
      if (currentFrameIsFocusedFrame)
        continue;
       }

    // a special case for area's which are not enumerated by the nsIFrameTraversal
    if (isMap(frame)) 
    {
      nsIContent* c = frame->GetContent();
      nsCOMPtr<nsIDOMHTMLMapElement> element = do_QueryInterface(c);
      if (!element)
        continue;

      nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
      element->GetAreas(getter_AddRefs(mapAreas));
      if (!mapAreas)
        continue;
      
      PRUint32 length;
      mapAreas->GetLength(&length);
      
      for (PRUint32 i = 0; i < length; i++) 
      {
        nsCOMPtr<nsIDOMNode> domNode;
        mapAreas->Item(i,getter_AddRefs(domNode));
        
        nsCOMPtr<nsIDOMHTMLAreaElement> e = do_QueryInterface(domNode);        
              nsCOMPtr<nsIContent> content= do_QueryInterface(domNode);
              getFrameForContent(content, &frame);
        
        getRectOfAreaElement(frame, e, &frameRect);
        
        if (!isRectInDirection(aDirection, aFocusedRect, frameRect))
          continue;
        
        d = spatialDistance(aDirection, aFocusedRect, frameRect);
        
        if ((*aDSoFar) > d) 
        {
          (*aDSoFar) = d;
          NS_IF_RELEASE(*aCurrentContent);
          NS_ADDREF(*aCurrentContent = content);
        }      
      }
      continue;
    }
    
    // we don't want to worry about the same frame if we
    // aren't an area
    if (frame == aFocusedFrame ||
        (aFocusedFrame && (frame->GetContent() == aFocusedFrame->GetContent())))
      continue;

       // make sure the frame is targetable for focus
       if (!isTargetable(focusDocuments, frame))
      continue;
       
    // RECT !!
    frameRect = makeRectRelativeToGlobalView(frame);

    // no frames without size and be navigated to
    // successfully.
    if (frameRect.width == 0 || frameRect.height == 0)
      continue;
    
    // deflate the rect to avoid overlapping with other
    // rects.
    frameRect.Deflate(gRectFudge, gRectFudge);

    if (!isRectInDirection(aDirection, aFocusedRect, frameRect))
      continue;
    
    d = spatialDistance(aDirection, aFocusedRect, frameRect);
    
    if ((*aDSoFar) >= d) 
    {
#ifdef DEBUG_dougt
      if (d == 0)
      {
        printf("there is overlapping content;\n");
      }
#endif
      (*aDSoFar) = d;
      NS_IF_RELEASE(*aCurrentContent);
      NS_ADDREF(*aCurrentContent = frame->GetContent());
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 40 of file nsSpatialNavigation.cpp.

Definition at line 39 of file nsSpatialNavigation.cpp.