Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Static Private Attributes | Friends
nsStackLayout Class Reference

#include <nsStackLayout.h>

Inheritance diagram for nsStackLayout:
Inheritance graph
[legend]
Collaboration diagram for nsStackLayout:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsStackLayout ()
NS_IMETHOD Layout (nsIBox *aBox, nsBoxLayoutState &aState)
NS_IMETHOD GetPrefSize (nsIBox *aBox, nsBoxLayoutState &aBoxLayoutState, nsSize &aSize)
NS_IMETHOD GetMinSize (nsIBox *aBox, nsBoxLayoutState &aBoxLayoutState, nsSize &aSize)
NS_IMETHOD GetMaxSize (nsIBox *aBox, nsBoxLayoutState &aBoxLayoutState, nsSize &aSize)
NS_IMETHOD GetAscent (nsIBox *aBox, nsBoxLayoutState &aBoxLayoutState, nscoord &aAscent)
NS_IMETHOD GetFlex (nsIBox *aBox, nsBoxLayoutState &aBoxLayoutState, nscoord &aFlex)
NS_IMETHOD IsCollapsed (nsIBox *aBox, nsBoxLayoutState &aBoxLayoutState, PRBool &aCollapsed)
NS_IMETHOD ChildrenInserted (nsIBox *aBox, nsBoxLayoutState &aState, nsIBox *aPrevBox, nsIBox *aChildList)
NS_IMETHOD ChildrenAppended (nsIBox *aBox, nsBoxLayoutState &aState, nsIBox *aChildList)
NS_IMETHOD ChildrenRemoved (nsIBox *aBox, nsBoxLayoutState &aState, nsIBox *aChildList)
NS_IMETHOD ChildrenSet (nsIBox *aBox, nsBoxLayoutState &aState, nsIBox *aChildList)
NS_IMETHOD ChildBecameDirty (nsIBox *aBox, nsBoxLayoutState &aState, nsIBox *aChild)
NS_IMETHOD BecameDirty (nsIBox *aBox, nsBoxLayoutState &aState)
virtual void GetParentLayout (nsIBox *aBox, nsIBoxLayout **aParent)
virtual void AddBorderAndPadding (nsIBox *aBox, nsSize &aSize)
virtual void AddInset (nsIBox *aBox, nsSize &aSize)
virtual void AddMargin (nsIBox *aChild, nsSize &aSize)
virtual void AddMargin (nsSize &aSize, const nsMargin &aMargin)

Static Public Member Functions

static void Shutdown ()
static PRBool AddOffset (nsBoxLayoutState &aState, nsIBox *aChild, nsSize &aSize)
static void AddLargestSize (nsSize &aSize, const nsSize &aToAdd)
static void AddSmallestSize (nsSize &aSize, const nsSize &aToAdd)

Static Private Attributes

static nsIBoxLayoutgInstance = nsnull

Friends

nsresult NS_NewStackLayout (nsIPresShell *aPresShell, nsCOMPtr< nsIBoxLayout > &aNewLayout)
 Eric D Vaughan A frame that can have multiple children.

Detailed Description

Definition at line 55 of file nsStackLayout.h.


Constructor & Destructor Documentation

Definition at line 76 of file nsStackLayout.cpp.

{
}

Member Function Documentation

void nsBoxLayout::AddBorderAndPadding ( nsIBox *  aBox,
nsSize aSize 
) [virtual, inherited]

Definition at line 76 of file nsBoxLayout.cpp.

{
  nsBox::AddBorderAndPadding(aBox, aSize);
}

Here is the caller graph for this function:

void nsBoxLayout::AddInset ( nsIBox *  aBox,
nsSize aSize 
) [virtual, inherited]

Definition at line 94 of file nsBoxLayout.cpp.

{
  nsBox::AddInset(aBox, aSize);
}

Here is the caller graph for this function:

void nsBoxLayout::AddLargestSize ( nsSize aSize,
const nsSize aToAdd 
) [static, inherited]

Definition at line 159 of file nsBoxLayout.cpp.

{
  if (aSize2.width > aSize.width)
     aSize.width = aSize2.width;

  if (aSize2.height > aSize.height)
     aSize.height = aSize2.height;
}

Here is the caller graph for this function:

void nsBoxLayout::AddMargin ( nsIBox *  aChild,
nsSize aSize 
) [virtual, inherited]

Definition at line 82 of file nsBoxLayout.cpp.

{
  nsBox::AddMargin(aBox, aSize);
}

Here is the caller graph for this function:

void nsBoxLayout::AddMargin ( nsSize aSize,
const nsMargin aMargin 
) [virtual, inherited]

Definition at line 88 of file nsBoxLayout.cpp.

{
  nsBox::AddMargin(aSize, aMargin);
}

Here is the call graph for this function:

PRBool nsStackLayout::AddOffset ( nsBoxLayoutState aState,
nsIBox *  aChild,
nsSize aSize 
) [static]

Definition at line 192 of file nsStackLayout.cpp.

{
  nsSize offset(0,0);
  
  // get the left and top offsets
  
  // As an optimization, we cache the fact that we are not positioned to avoid
  // wasting time fetching attributes and checking style data.
  if (aChild->GetStateBits() & NS_STATE_STACK_NOT_POSITIONED)
    return PR_FALSE;
  
  PRBool offsetSpecified = PR_FALSE;
  const nsStylePosition* pos = aChild->GetStylePosition();
  if (eStyleUnit_Coord == pos->mOffset.GetLeftUnit()) {
     nsStyleCoord left = 0;
     pos->mOffset.GetLeft(left);
     offset.width = left.GetCoordValue();
     offsetSpecified = PR_TRUE;
  }

  if (eStyleUnit_Coord == pos->mOffset.GetTopUnit()) {
     nsStyleCoord top = 0;
     pos->mOffset.GetTop(top);
     offset.height = top.GetCoordValue();
     offsetSpecified = PR_TRUE;
  }

  nsIContent* content = aChild->GetContent();

  if (content) {
    nsPresContext* presContext = aState.PresContext();
    nsAutoString value;
    PRInt32 error;

    if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::left, value)) {
      value.Trim("%");
      offset.width = NSIntPixelsToTwips(value.ToInteger(&error),
                                        presContext->ScaledPixelsToTwips());
      offsetSpecified = PR_TRUE;
    }

    if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::top, value)) {
      value.Trim("%");
      offset.height = NSIntPixelsToTwips(value.ToInteger(&error),
                                         presContext->ScaledPixelsToTwips());
      offsetSpecified = PR_TRUE;
    }
  }

  aSize += offset;

  if (!offsetSpecified) {
    // If no offset was specified at all, then we cache this fact to avoid requerying
    // CSS or the content model.
    aChild->AddStateBits(NS_STATE_STACK_NOT_POSITIONED);
  }
  
  return offsetSpecified;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsBoxLayout::AddSmallestSize ( nsSize aSize,
const nsSize aToAdd 
) [static, inherited]

Definition at line 169 of file nsBoxLayout.cpp.

{
  if (aSize2.width < aSize.width)
     aSize.width = aSize2.width;

  if (aSize2.height < aSize.height)
     aSize.height = aSize2.height;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsBoxLayout::BecameDirty ( nsIBox *  aBox,
nsBoxLayoutState aState 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsGridRowLeafLayout.

Definition at line 209 of file nsBoxLayout.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsBoxLayout::ChildBecameDirty ( nsIBox *  aBox,
nsBoxLayoutState aState,
nsIBox *  aChild 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsGridRowLeafLayout.

Definition at line 203 of file nsBoxLayout.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsBoxLayout::ChildrenAppended ( nsIBox *  aBox,
nsBoxLayoutState aState,
nsIBox *  aChildList 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsGridLayout2, and nsGridRowLayout.

Definition at line 185 of file nsBoxLayout.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsBoxLayout::ChildrenInserted ( nsIBox *  aBox,
nsBoxLayoutState aState,
nsIBox *  aPrevBox,
nsIBox *  aChildList 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsGridLayout2, and nsGridRowLayout.

Definition at line 179 of file nsBoxLayout.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsBoxLayout::ChildrenRemoved ( nsIBox *  aBox,
nsBoxLayoutState aState,
nsIBox *  aChildList 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsGridLayout2, and nsGridRowLayout.

Definition at line 191 of file nsBoxLayout.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsBoxLayout::ChildrenSet ( nsIBox *  aBox,
nsBoxLayoutState aState,
nsIBox *  aChildList 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsGridLayout2, and nsGridRowLayout.

Definition at line 197 of file nsBoxLayout.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsStackLayout::GetAscent ( nsIBox *  aBox,
nsBoxLayoutState aBoxLayoutState,
nscoord aAscent 
) [virtual]

Reimplemented from nsBoxLayout.

Definition at line 171 of file nsStackLayout.cpp.

{
  aAscent = 0;
  nsIBox* child = nsnull;
  aBox->GetChildBox(&child);
   
  while (child) {  
    nscoord ascent = 0;
    child->GetAscent(aState, ascent);
    nsMargin margin;
    child->GetMargin(margin);
    ascent += margin.top + margin.bottom;
    if (ascent > aAscent)
      aAscent = ascent;
    child->GetNextBox(&child);
  }

  return NS_OK;
}
NS_IMETHODIMP nsBoxLayout::GetFlex ( nsIBox *  aBox,
nsBoxLayoutState aBoxLayoutState,
nscoord aFlex 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsSprocketLayout.

Definition at line 100 of file nsBoxLayout.cpp.

{
  return aBox->GetFlex(aState, aFlex);
}
NS_IMETHODIMP nsStackLayout::GetMaxSize ( nsIBox *  aBox,
nsBoxLayoutState aBoxLayoutState,
nsSize aSize 
) [virtual]

Reimplemented from nsBoxLayout.

Reimplemented in nsGridLayout2.

Definition at line 138 of file nsStackLayout.cpp.

{
  aSize.width = NS_INTRINSICSIZE;
  aSize.height = NS_INTRINSICSIZE;

  // run through all the children and get their min, max, and preferred sizes
 
  nsIBox* child = nsnull;
  aBox->GetChildBox(&child);
   
  while (child) {  
    nsSize max(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
    child->GetMaxSize(aState, max);
    nsSize min(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
    child->GetMinSize(aState, min);
    nsBox::BoundsCheckMinMax(min, max);

    AddMargin(child, max);
    AddOffset(aState, child, max);
    AddSmallestSize(aSize, max);

    child->GetNextBox(&child);
  }

  // now add our border and padding and insets
  AddBorderAndPadding(aBox, aSize);
  AddInset(aBox, aSize);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsStackLayout::GetMinSize ( nsIBox *  aBox,
nsBoxLayoutState aBoxLayoutState,
nsSize aSize 
) [virtual]

Reimplemented from nsBoxLayout.

Reimplemented in nsGridLayout2.

Definition at line 110 of file nsStackLayout.cpp.

{
  aSize.width = 0;
  aSize.height = 0;

  // run through all the children and get their min, max, and preferred sizes
  
  nsIBox* child = nsnull;
  aBox->GetChildBox(&child);
   
  while (child) {  
    nsSize min(0,0);
    child->GetMinSize(aState, min);        
    AddMargin(child, min);
    AddOffset(aState, child, min);
    AddLargestSize(aSize, min);

    child->GetNextBox(&child);
  }

  // now add our border and padding and insets
  AddBorderAndPadding(aBox, aSize);
  AddInset(aBox,aSize);

  return NS_OK;
}

Here is the call graph for this function:

void nsBoxLayout::GetParentLayout ( nsIBox *  aBox,
nsIBoxLayout **  aParent 
) [virtual, inherited]

Definition at line 62 of file nsBoxLayout.cpp.

{
  nsIBox* parent = nsnull;
  aBox->GetParentBox(&parent);
  if (parent)
  {
    parent->GetLayoutManager(aParent);
    return;
  }

  *aParent = nsnull;
}
NS_IMETHODIMP nsStackLayout::GetPrefSize ( nsIBox *  aBox,
nsBoxLayoutState aBoxLayoutState,
nsSize aSize 
) [virtual]

Reimplemented from nsBoxLayout.

Reimplemented in nsGridLayout2.

Definition at line 81 of file nsStackLayout.cpp.

{
  aSize.width = 0;
  aSize.height = 0;

  // we are as wide as the widest child plus its left offset
  // we are tall as the tallest child plus its top offset
  nsIBox* child = nsnull;
  aBox->GetChildBox(&child);
 
  while (child) {  
    nsSize pref(0,0);
    child->GetPrefSize(aState, pref);

    AddMargin(child, pref);
    AddOffset(aState, child, pref);
    AddLargestSize(aSize, pref);

    child->GetNextBox(&child);
  }

  // now add our border and padding and insets
  AddBorderAndPadding(aBox, aSize);
  AddInset(aBox, aSize);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsBoxLayout::IsCollapsed ( nsIBox *  aBox,
nsBoxLayoutState aBoxLayoutState,
PRBool aCollapsed 
) [virtual, inherited]

Implements nsIBoxLayout.

Reimplemented in nsSprocketLayout.

Definition at line 107 of file nsBoxLayout.cpp.

{
  return aBox->IsCollapsed(aState, aCollapsed);
}
NS_IMETHODIMP nsStackLayout::Layout ( nsIBox *  aBox,
nsBoxLayoutState aState 
) [virtual]

Reimplemented from nsBoxLayout.

Reimplemented in nsGridLayout2.

Definition at line 254 of file nsStackLayout.cpp.

{
  nsRect clientRect;
  aBox->GetClientRect(clientRect);

  PRBool grow;

  do {
    nsIBox* child = nsnull;
    aBox->GetChildBox(&child);
    grow = PR_FALSE;

    while (child) 
    {  
      nsMargin margin;
      child->GetMargin(margin);
      nsRect childRect(clientRect);
      childRect.Deflate(margin);

      if (childRect.width < 0)
        childRect.width = 0;

      if (childRect.height < 0)
        childRect.height = 0;

      nsRect oldRect(child->GetRect());
      PRBool sizeChanged = (oldRect != childRect);

      // only lay out dirty children or children whose sizes have changed
      PRBool isDirty = PR_FALSE;
      PRBool hasDirtyChildren = PR_FALSE;

      child->IsDirty(isDirty);
      child->HasDirtyChildren(hasDirtyChildren);

      if (sizeChanged || isDirty || hasDirtyChildren) {
          // add in the child's margin
          nsMargin margin;
          child->GetMargin(margin);

          // obtain our offset from the top left border of the stack's content box.
          nsSize offset(0,0);
          PRBool offsetSpecified = AddOffset(aState, child, offset);

          // Correct the child's x/y position by adding in both the margins
          // and the left/top offset.
          childRect.x = clientRect.x + offset.width + margin.left;
          childRect.y = clientRect.y + offset.height + margin.top;
          
          // If we have an offset, we don't stretch the child.  Just use
          // its preferred size.
          if (offsetSpecified) {
            nsSize pref(0,0);
            child->GetPrefSize(aState, pref);
            childRect.width = pref.width;
            childRect.height = pref.height;
          }

          // Now place the child.
          child->SetBounds(aState, childRect);

          // Flow the child.
          child->Layout(aState);

          // Get the child's new rect.
          nsRect childRectNoMargin;
          childRectNoMargin = childRect = child->GetRect();
          childRect.Inflate(margin);

          // Did the child push back on us and get bigger?
          if (offset.width + childRect.width > clientRect.width) {
            clientRect.width = childRect.width + offset.width;
            grow = PR_TRUE;
          }

          if (offset.height + childRect.height > clientRect.height) {
            clientRect.height = childRect.height + offset.height;
            grow = PR_TRUE;
          }

          if (childRectNoMargin != oldRect)
          {
            // redraw the new and old positions if the 
            // child moved or resized.
            // if the new and old rect intersect meaning we just moved a little
            // then just redraw the union. If they don't intersect (meaning
            // we moved a good distance) redraw both separately.
            if (childRectNoMargin.Intersects(oldRect)) {
              nsRect u;
              u.UnionRect(oldRect, childRectNoMargin);
              aBox->Redraw(aState, &u);
            } else {
              aBox->Redraw(aState, &oldRect);
              aBox->Redraw(aState, &childRectNoMargin);
            }
          }
       }

       child->GetNextBox(&child);
     }
   } while (grow);
   
   // if some HTML inside us got bigger we need to force ourselves to
   // get bigger
   nsRect bounds(aBox->GetRect());
   nsMargin bp;
   aBox->GetBorderAndPadding(bp);
   clientRect.Inflate(bp);
   aBox->GetInset(bp);
   clientRect.Inflate(bp);

   if (clientRect.width > bounds.width || clientRect.height > bounds.height)
   {
     if (clientRect.width > bounds.width)
       bounds.width = clientRect.width;
     if (clientRect.height > bounds.height)
       bounds.height = clientRect.height;

     aBox->SetBounds(aState, bounds);
   }

   return NS_OK;
}

Here is the call graph for this function:

Definition at line 71 of file nsStackLayout.cpp.


Friends And Related Function Documentation

nsresult NS_NewStackLayout ( nsIPresShell aPresShell,
nsCOMPtr< nsIBoxLayout > &  aNewLayout 
) [friend]

Eric D Vaughan A frame that can have multiple children.

Only one child may be displayed at one time. So the can be flipped though like a deck of cards.

Definition at line 59 of file nsStackLayout.cpp.

{
  if (!nsStackLayout::gInstance) {
    nsStackLayout::gInstance = new nsStackLayout();
    NS_IF_ADDREF(nsStackLayout::gInstance);
  }
  // we have not instance variables so just return our static one.
  aNewLayout = nsStackLayout::gInstance;
  return NS_OK;
} 

Member Data Documentation

Definition at line 73 of file nsStackLayout.h.


The documentation for this class was generated from the following files: