Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsFrame.cpp File Reference
#include "nsCOMPtr.h"
#include "nsFrame.h"
#include "nsFrameList.h"
#include "nsLineLayout.h"
#include "nsIContent.h"
#include "nsContentUtils.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsStyleContext.h"
#include "nsReflowPath.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsIScrollableFrame.h"
#include "nsPresContext.h"
#include "nsCRT.h"
#include "nsGUIEvent.h"
#include "nsIDOMEvent.h"
#include "nsPLDOMEvent.h"
#include "nsStyleConsts.h"
#include "nsIPresShell.h"
#include "prlog.h"
#include "prprf.h"
#include <stdarg.h>
#include "nsFrameManager.h"
#include "nsCSSRendering.h"
#include "nsLayoutUtils.h"
#include "nsIDOMText.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLHRElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDeviceContext.h"
#include "nsIEditorDocShell.h"
#include "nsIEventStateManager.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
#include "nsIFrameSelection.h"
#include "nsHTMLParts.h"
#include "nsLayoutAtoms.h"
#include "nsCSSAnonBoxes.h"
#include "nsCSSPseudoElements.h"
#include "nsHTMLAtoms.h"
#include "nsIHTMLContentSink.h"
#include "nsCSSFrameConstructor.h"
#include "nsFrameTraversal.h"
#include "nsStyleChangeList.h"
#include "nsIDOMRange.h"
#include "nsITableLayout.h"
#include "nsITableCellLayout.h"
#include "nsITextControlFrame.h"
#include "nsINameSpaceManager.h"
#include "nsIPercentHeightObserver.h"
#include "nsTextTransformer.h"
#include "nsIServiceManager.h"
#include "nsISelectionImageService.h"
#include "imgIContainer.h"
#include "imgIRequest.h"
#include "gfxIImageFrame.h"
#include "nsILookAndFeel.h"
#include "nsLayoutCID.h"
#include "nsWidgetsCID.h"
#include "nsUnicharUtils.h"
#include "nsLayoutErrors.h"
#include "nsContentErrors.h"
#include "nsHTMLContainerFrame.h"
#include "nsBoxLayoutState.h"
#include "nsICaret.h"
#include "nsILineIterator.h"
#include "prenv.h"

Go to the source code of this file.

Classes

struct  nsBoxLayoutMetrics
class  SelectionImageService

Defines

#define SELECTION_DEBUG   0
#define FORCE_SELECTION_UPDATE   1
#define CALC_DEBUG   0
#define SEL_IMAGE_WIDTH   32
#define SEL_IMAGE_HEIGHT   32
#define SEL_ALPHA_AMOUNT   128
#define HUGE_DISTANCE   999999
#define MAX_FRAME_DEPTH   (MAX_REFLOW_DEPTH+4)

Functions

static NS_DEFINE_CID (kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID)
static NS_DEFINE_CID (kLookAndFeelCID, NS_LOOKANDFEEL_CID)
static NS_DEFINE_CID (kWidgetCID, NS_CHILD_CID)
nsresult NS_NewSelectionImageService (nsISelectionImageService **aResult)
void SetFontFromStyle (nsIRenderingContext *aRC, nsStyleContext *aSC)
nsresult NS_NewEmptyFrame (nsIPresShell *aPresShell, nsIFrame **aNewFrame)
static nsIFrameGetActiveSelectionFrame (nsIFrame *aFrame)
PRBool ContentContainsPoint (nsPresContext *aPresContext, nsIContent *aContent, nsPoint *aPoint, nsIView *aRelativeView)
static nsIViewGetNearestCapturingView (nsIFrame *aFrame)
static void GetFrameSelectionFor (nsIFrame *aFrame, nsIFrameSelection **aFrameSel, nsISelectionController **aSelCon)
static nsresult HandleFrameSelection (nsIFrameSelection *aFrameSelection, nsIContent *aContent, PRInt32 aStartOffset, PRInt32 aEndOffset, PRBool aBeginFrameContent, PRBool aHandleTableSel, PRInt32 aContentOffsetForTableSel, PRInt32 aTargetForTableSel, nsGUIEvent *aEvent, nsEventStatus *aEventStatus)
 This static method handles part of the nsFrame::HandleRelease in a way which doesn't rely on the nsFrame object to stay alive.
static nsRect ComputeOutlineRect (const nsIFrame *aFrame, PRBool *aAnyOutline, const nsRect &aOverflowRect)
static nsILineIteratorGetBlockFrameAndLineIter (nsIFrame *aFrame, nsIFrame **aBlockFrame)
static nsresult DrillDownToEndOfLine (nsIFrame *aFrame, PRInt32 aLineNo, PRInt32 aLineFrameCount, nsRect &aUsedRect, nsPeekOffsetStruct *aPos)
static void DestroyRectFunc (void *aFrame, nsIAtom *aPropertyName, void *aPropertyValue, void *aDtorData)
static nsresult GetIBSpecialSibling (nsPresContext *aPresContext, nsIFrame *aFrame, nsIFrame **aSpecialSibling)
 This function takes a "special" frame and if that frame is the anonymous block crated by an ib split it returns the split inline as aSpecialSibling.
static nsresult GetCorrectedParent (nsPresContext *aPresContext, nsIFrame *aFrame, nsIFrame **aSpecialParent)
 Get the parent, corrected for the mangled frame tree resulting from having a block within an inline.
static void PruneReflowPathFor (nsIFrame *aFrame, nsReflowPath *aReflowPath)
static nsReflowPathFindReflowPathFor (nsIFrame *aFrame, nsReflowPath *aReflowPath)
static void DeleteBoxMetrics (void *aObject, nsIAtom *aPropertyName, void *aPropertyValue, void *aData)

Class Documentation

struct nsBoxLayoutMetrics

Definition at line 120 of file nsFrame.cpp.

Collaboration diagram for nsBoxLayoutMetrics:
Class Members
nscoord mAscent
nscoord mBlockAscent
nsSize mBlockMinSize
nsSize mBlockPrefSize
nscoord mFlex
PRPackedBool mIncludeOverflow
nsSize mLastSize
nsSize mMaxSize
nsSize mMinSize
nsSize mOverflow
nsSize mPrefSize
PRPackedBool mStyleChange
PRPackedBool mWasCollapsed

Define Documentation

#define CALC_DEBUG   0

Definition at line 144 of file nsFrame.cpp.

Definition at line 143 of file nsFrame.cpp.

#define HUGE_DISTANCE   999999

Definition at line 2702 of file nsFrame.cpp.

Definition at line 337 of file nsFrame.cpp.

Definition at line 336 of file nsFrame.cpp.

Definition at line 335 of file nsFrame.cpp.

Definition at line 142 of file nsFrame.cpp.


Function Documentation

static nsRect ComputeOutlineRect ( const nsIFrame aFrame,
PRBool aAnyOutline,
const nsRect aOverflowRect 
) [static]

Definition at line 2610 of file nsFrame.cpp.

                                                              {
  const nsStyleOutline* outline = aFrame->GetStyleOutline();
  PRUint8 outlineStyle = outline->GetOutlineStyle();
  nsRect r = aOverflowRect;
  *aAnyOutline = PR_FALSE;
  if (outlineStyle != NS_STYLE_BORDER_STYLE_NONE) {
    nscoord width;
#ifdef DEBUG
    PRBool result = 
#endif
      outline->GetOutlineWidth(width);
    NS_ASSERTION(result, "GetOutlineWidth had no cached outline width");
    if (width > 0) {
      nscoord offset;
      outline->GetOutlineOffset(offset);
      nscoord inflateBy = PR_MAX(width + offset, 0);
      r.Inflate(inflateBy, inflateBy);
      *aAnyOutline = PR_TRUE;
    }
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool ContentContainsPoint ( nsPresContext aPresContext,
nsIContent aContent,
nsPoint aPoint,
nsIView aRelativeView 
)

Definition at line 1215 of file nsFrame.cpp.

{
  nsIPresShell *presShell = aPresContext->GetPresShell();

  if (!presShell) return PR_FALSE;

  nsIFrame *frame = nsnull;

  nsresult rv = presShell->GetPrimaryFrameFor(aContent, &frame);

  if (NS_FAILED(rv) || !frame) return PR_FALSE;

  nsIView *frameView = nsnull;
  nsPoint offsetPoint;

  // Get the view that contains the content's frame.

  rv = frame->GetOffsetFromView(offsetPoint, &frameView);

  if (NS_FAILED(rv) || !frameView) return PR_FALSE;

  // aPoint is relative to aRelativeView's upper left corner! Make sure
  // that our point is in the same view space our content frame's
  // rects are in.

  nsPoint point = *aPoint + aRelativeView->GetOffsetTo(frameView);

  // Now check to see if the point is within the bounds of the
  // content's primary frame, or any of it's continuation frames.

  while (frame) {
    // Get the frame's rect and make it relative to the
    // upper left corner of it's parent view.

    nsRect frameRect = frame->GetRect();
    frameRect.x = offsetPoint.x;
    frameRect.y = offsetPoint.y;

    if (frameRect.Contains(point)) {
      // point is within this frame's rect!
      return PR_TRUE;
    }

    frame = frame->GetNextInFlow();

  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void DeleteBoxMetrics ( void aObject,
nsIAtom aPropertyName,
void aPropertyValue,
void aData 
) [static]

Definition at line 5803 of file nsFrame.cpp.

{
  delete NS_STATIC_CAST(nsBoxLayoutMetrics*, aPropertyValue);
}

Here is the caller graph for this function:

static void DestroyRectFunc ( void aFrame,
nsIAtom aPropertyName,
void aPropertyValue,
void aDtorData 
) [static]

Definition at line 4374 of file nsFrame.cpp.

{
  delete (nsRect*)aPropertyValue;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult DrillDownToEndOfLine ( nsIFrame aFrame,
PRInt32  aLineNo,
PRInt32  aLineFrameCount,
nsRect aUsedRect,
nsPeekOffsetStruct aPos 
) [static]

Definition at line 3697 of file nsFrame.cpp.

{
  if (!aFrame)
    return NS_ERROR_UNEXPECTED;
  nsresult rv = NS_ERROR_FAILURE;
  PRBool found = PR_FALSE;
  nsCOMPtr<nsIAtom> frameType;
  while (!found)  // this loop searches for a valid point to leave the peek offset struct.
  {
    nsIFrame *nextFrame = aFrame;
    nsIFrame *currentFrame = aFrame;
    PRInt32 i;
    for (i=1; i<aLineFrameCount && nextFrame; i++) //already have 1st frame
    {
                currentFrame = nextFrame;
      // If we do GetNextSibling, we don't go far enough
      // (is aLineFrameCount too small?)
      // If we do GetNextInFlow, we hit a null.
      nextFrame = currentFrame->GetNextSibling();
    }
    if (!nextFrame) //premature leaving of loop.
    {
      nextFrame = currentFrame; //back it up. lets show a warning
      NS_WARNING("lineFrame Count lied to us from nsILineIterator!\n");
    }
    if (!nextFrame->GetRect().width) //this can happen with BR frames and or empty placeholder frames.
    {
      //if we do hit an empty frame then back up the current frame to the frame before it if there is one.
      nextFrame = currentFrame; 
    }
      
    nsPoint offsetPoint; //used for offset of result frame
    nsIView * view; //used for call of get offset from view
    nextFrame->GetOffsetFromView(offsetPoint, &view);

    offsetPoint.x += 2* aUsedRect.width; //2* just to be sure we are off the edge
    // This doesn't seem very efficient since GetPosition
    // has to do a binary search.

    nsPresContext *context = aPos->mShell->GetPresContext();
    PRInt32 endoffset;
    rv = nextFrame->GetContentAndOffsetsFromPoint(context,
                                                  offsetPoint,
                                                  getter_AddRefs(aPos->mResultContent),
                                                  aPos->mContentOffset,
                                                  endoffset,
                                                  aPos->mPreferLeft);
    if (NS_SUCCEEDED(rv))
      return PR_TRUE;

#ifdef DEBUG_paragraph
    NS_ASSERTION(PR_FALSE, "Looping around in PeekOffset\n");
#endif
    aLineFrameCount--;
    if (aLineFrameCount == 0)
      break;//just fail out
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsReflowPath* FindReflowPathFor ( nsIFrame aFrame,
nsReflowPath aReflowPath 
) [static]

Definition at line 5612 of file nsFrame.cpp.

{
  nsReflowPath::iterator iter, end = aReflowPath->EndChildren();
  for (iter = aReflowPath->FirstChild(); iter != end; ++iter) {
    if (*iter == aFrame)
      return iter.get();

    nsReflowPath *subtree = FindReflowPathFor(aFrame, iter.get());
    if (subtree)
      return subtree;
  }

  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIFrame* GetActiveSelectionFrame ( nsIFrame aFrame) [static]

Definition at line 732 of file nsFrame.cpp.

{
  nsIView* mouseGrabber;
  aFrame->GetPresContext()->GetViewManager()->GetMouseEventGrabber(mouseGrabber);
  if (mouseGrabber) {
    nsIFrame* activeFrame = nsLayoutUtils::GetFrameFor(mouseGrabber);
    if (activeFrame) {
      return activeFrame;
    }
  }
    
  return aFrame;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsILineIterator* GetBlockFrameAndLineIter ( nsIFrame aFrame,
nsIFrame **  aBlockFrame 
) [static]

Definition at line 3539 of file nsFrame.cpp.

{
  nsILineIterator* it;
  nsIFrame *blockFrame = aFrame;

  blockFrame = blockFrame->GetParent();
  if (!blockFrame) //if at line 0 then nothing to do
    return 0;
  nsresult result = blockFrame->QueryInterface(NS_GET_IID(nsILineIterator), (void**)&it);
  if (NS_SUCCEEDED(result) && it)
  {
    if (aBlockFrame)
      *aBlockFrame = blockFrame;
    return it;
  }

  while (blockFrame)
  {
    blockFrame = blockFrame->GetParent();
    if (blockFrame) {
      result = blockFrame->QueryInterface(NS_GET_IID(nsILineIterator),
                                          (void**)&it);
      if (NS_SUCCEEDED(result) && it)
      {
        if (aBlockFrame)
          *aBlockFrame = blockFrame;
        return it;
      }
    }
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult GetCorrectedParent ( nsPresContext aPresContext,
nsIFrame aFrame,
nsIFrame **  aSpecialParent 
) [static]

Get the parent, corrected for the mangled frame tree resulting from having a block within an inline.

The result only differs from the result of |GetParent| when |GetParent| returns an anonymous block that was created for an element that was 'display: inline' because that element contained a block.

Also skip anonymous scrolled-content parents; inherit directly from the outer scroll frame.

Definition at line 4534 of file nsFrame.cpp.

{
  nsIFrame *parent = aFrame->GetParent();
  if (!parent) {
    *aSpecialParent = nsnull;
  } else {
    nsIAtom* pseudo = aFrame->GetStyleContext()->GetPseudoType();
    // Outer tables are always anon boxes; if we're in here for an outer
    // table, that actually means its the _inner_ table that wants to
    // know its parent.  So get the pseudo of the inner in that case.
    if (pseudo == nsCSSAnonBoxes::tableOuter) {
      pseudo =
        aFrame->GetFirstChild(nsnull)->GetStyleContext()->GetPseudoType();
    }
    *aSpecialParent = nsFrame::CorrectStyleParentFrame(parent, pseudo);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void GetFrameSelectionFor ( nsIFrame aFrame,
nsIFrameSelection **  aFrameSel,
nsISelectionController **  aSelCon 
) [static]

Definition at line 1789 of file nsFrame.cpp.

{
  *aSelCon = nsnull;
  *aFrameSel = nsnull;
  nsresult result = aFrame->GetSelectionController(aFrame->GetPresContext(), aSelCon);
  if (NS_SUCCEEDED(result) && *aSelCon)
    CallQueryInterface(*aSelCon, aFrameSel);
  if (!*aFrameSel)
    NS_IF_ADDREF(*aFrameSel = aFrame->GetPresContext()->GetPresShell()->FrameSelection());
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult GetIBSpecialSibling ( nsPresContext aPresContext,
nsIFrame aFrame,
nsIFrame **  aSpecialSibling 
) [static]

This function takes a "special" frame and if that frame is the anonymous block crated by an ib split it returns the split inline as aSpecialSibling.

This is needed because the split inline's style context is the parent of the anonymous block's srtyle context.

If aFrame is not the anonymous block, aSpecialSibling is not touched.

Definition at line 4490 of file nsFrame.cpp.

{
  NS_PRECONDITION(aFrame, "Must have a non-null frame!");
  NS_ASSERTION(aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL,
               "GetIBSpecialSibling should not be called on a non-special frame");
  
  // Find the first-in-flow of the frame.  (Ugh.  This ends up
  // being O(N^2) when it is called O(N) times.)
  aFrame = aFrame->GetFirstInFlow();

  /*
   * Now look up the nsLayoutAtoms::IBSplitSpecialPrevSibling
   * property, which is only set on the anonymous block frames we're
   * interested in.
   */
  nsresult rv;
  nsIFrame *specialSibling = NS_STATIC_CAST(nsIFrame*,
                             aPresContext->PropertyTable()->GetProperty(aFrame,
                               nsLayoutAtoms::IBSplitSpecialPrevSibling, &rv));

  if (NS_PROPTABLE_PROP_NOT_THERE == rv) {
    *aSpecialSibling = nsnull;
    rv = NS_OK;
  } else if (NS_SUCCEEDED(rv)) {
    NS_ASSERTION(specialSibling, "null special sibling");
    *aSpecialSibling = specialSibling;
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIView* GetNearestCapturingView ( nsIFrame aFrame) [static]

Definition at line 1711 of file nsFrame.cpp.

                                                          {
  nsIView* view = nsnull;
  while (!(view = aFrame->GetMouseCapturer()) && aFrame->GetParent()) {
    aFrame = aFrame->GetParent();
  }
  if (!view) {
    // Use the root view. The root frame always has the root view.
    view = aFrame->GetView();
  }
  NS_ASSERTION(view, "No capturing view found");
  return view;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult HandleFrameSelection ( nsIFrameSelection aFrameSelection,
nsIContent aContent,
PRInt32  aStartOffset,
PRInt32  aEndOffset,
PRBool  aBeginFrameContent,
PRBool  aHandleTableSel,
PRInt32  aContentOffsetForTableSel,
PRInt32  aTargetForTableSel,
nsGUIEvent aEvent,
nsEventStatus aEventStatus 
) [static]

This static method handles part of the nsFrame::HandleRelease in a way which doesn't rely on the nsFrame object to stay alive.

Definition at line 1805 of file nsFrame.cpp.

{
  if (!aFrameSelection) {
    return NS_OK;
  }

  nsresult rv = NS_OK;

  if (nsEventStatus_eConsumeNoDefault != *aEventStatus && aContent) {
    if (!aHandleTableSel) {
      nsMouseEvent* me = nsnull;
      aFrameSelection->GetDelayedCaretData(&me);
      if (!me) {
        return NS_ERROR_FAILURE;
      }
      // We are doing this to simulate what we would have done on HandlePress
      aFrameSelection->SetMouseDownState(PR_TRUE);
      rv = aFrameSelection->HandleClick(aContent, aStartOffset, aEndOffset,
                                        me->isShift, PR_FALSE,
                                        aBeginFrameContent);
      if (NS_FAILED(rv)) {
        return rv;
      }
    } else {
      aFrameSelection->SetMouseDownState(PR_FALSE);
      aFrameSelection->HandleTableSelection(aContent,
                                            aContentOffsetForTableSel,
                                            aTargetForTableSel,
                                            (nsMouseEvent *)aEvent);
      if (NS_FAILED(rv)) {
        return rv;
      }
    }
    aFrameSelection->SetDelayedCaretData(0);
  }

  aFrameSelection->SetMouseDownState(PR_FALSE);
  aFrameSelection->StopAutoScrollTimer();
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kSelectionImageService  ,
NS_SELECTIONIMAGESERVICE_CID   
) [static]
static NS_DEFINE_CID ( kLookAndFeelCID  ,
NS_LOOKANDFEEL_CID   
) [static]
static NS_DEFINE_CID ( kWidgetCID  ,
NS_CHILD_CID   
) [static]
nsresult NS_NewEmptyFrame ( nsIPresShell aPresShell,
nsIFrame **  aNewFrame 
)

Definition at line 425 of file nsFrame.cpp.

{
  NS_PRECONDITION(aNewFrame, "null OUT ptr");
  if (nsnull == aNewFrame) {
    return NS_ERROR_NULL_POINTER;
  }
  nsFrame* it = new (aPresShell) nsFrame;
  if (nsnull == it) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  *aNewFrame = it;
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 403 of file nsFrame.cpp.

{
  *aResult = new SelectionImageService;
  if (!*aResult)
    return NS_ERROR_OUT_OF_MEMORY;
  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:

static void PruneReflowPathFor ( nsIFrame aFrame,
nsReflowPath aReflowPath 
) [static]

Definition at line 5289 of file nsFrame.cpp.

{
  nsReflowPath::iterator iter, end = aReflowPath->EndChildren();
  for (iter = aReflowPath->FirstChild(); iter != end; ++iter) {
    if (*iter == aFrame) {
      aReflowPath->Remove(iter);
      break;
    }

    PruneReflowPathFor(aFrame, iter.get());
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 416 of file nsFrame.cpp.

{
  const nsStyleFont* font = aSC->GetStyleFont();
  const nsStyleVisibility* visibility = aSC->GetStyleVisibility();

  aRC->SetFont(font->mFont, visibility->mLangGroup);
}

Here is the call graph for this function:

Here is the caller graph for this function: