/* virtual */
LogicalSize
nsTableWrapperFrame::ComputeAutoSize(nsRenderingContext* aRenderingContext,
                                     WritingMode         aWM,
                                     const LogicalSize&  aCBSize,
                                     nscoord             aAvailableISize,
                                     const LogicalSize&  aMargin,
                                     const LogicalSize&  aBorder,
                                     const LogicalSize&  aPadding,
                                     ComputeSizeFlags    aFlags)
{
  nscoord kidAvailableISize = aAvailableISize - aMargin.ISize(aWM);
  NS_ASSERTION(aBorder.IsAllZero() && aPadding.IsAllZero(),
               "Table wrapper frames cannot have borders or paddings");

  // When we're shrink-wrapping, our auto size needs to wrap around the
  // actual size of the table, which (if it is specified as a percent)
  // could be something that is not reflected in our GetMinISize and
  // GetPrefISize.  See bug 349457 for an example.

  // Match the availableISize logic in Reflow.
  uint8_t captionSide = GetCaptionSide();
  nscoord inlineSize;
  if (captionSide == NO_SIDE) {
    inlineSize = ChildShrinkWrapISize(aRenderingContext, InnerTableFrame(), aWM,
                                      aCBSize, kidAvailableISize);
  } else if (captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
             captionSide == NS_STYLE_CAPTION_SIDE_RIGHT) {
    nscoord capISize = ChildShrinkWrapISize(aRenderingContext,
                                            mCaptionFrames.FirstChild(), aWM,
                                            aCBSize, kidAvailableISize);
    inlineSize = capISize + ChildShrinkWrapISize(aRenderingContext,
                                                 InnerTableFrame(), aWM,
                                                 aCBSize,
                                                 kidAvailableISize - capISize);
  } else if (captionSide == NS_STYLE_CAPTION_SIDE_TOP ||
             captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) {
    nscoord margin;
    inlineSize = ChildShrinkWrapISize(aRenderingContext, InnerTableFrame(), aWM,
                                      aCBSize, kidAvailableISize, &margin);
    nscoord capISize = ChildShrinkWrapISize(aRenderingContext,
                                            mCaptionFrames.FirstChild(), aWM,
                                            aCBSize, inlineSize - margin);
    if (capISize > inlineSize) {
      inlineSize = capISize;
    }
  } else {
    NS_ASSERTION(captionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE ||
                 captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE,
                 "unexpected caption-side");
    inlineSize = ChildShrinkWrapISize(aRenderingContext, InnerTableFrame(), aWM,
                                      aCBSize, kidAvailableISize);
    nscoord capISize = ChildShrinkWrapISize(aRenderingContext,
                                            mCaptionFrames.FirstChild(), aWM,
                                            aCBSize, kidAvailableISize);
    if (capISize > inlineSize) {
      inlineSize = capISize;
    }
  }

  return LogicalSize(aWM, inlineSize, NS_UNCONSTRAINEDSIZE);
}
Exemplo n.º 2
0
/* virtual */
LogicalSize
nsTableOuterFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
                                   WritingMode aWM,
                                   const LogicalSize& aCBSize,
                                   nscoord aAvailableISize,
                                   const LogicalSize& aMargin,
                                   const LogicalSize& aBorder,
                                   const LogicalSize& aPadding,
                                   bool aShrinkWrap)
{
  nscoord kidAvailableWidth = aAvailableISize - aMargin.ISize(aWM);
  NS_ASSERTION(aBorder.IsAllZero() && aPadding.IsAllZero(),
               "Table outer frames cannot have borders or paddings");

  // When we're shrink-wrapping, our auto size needs to wrap around the
  // actual size of the table, which (if it is specified as a percent)
  // could be something that is not reflected in our GetMinISize and
  // GetPrefISize.  See bug 349457 for an example.

  // XXX The use of aCBSize.GetPhysicalSize(aWM) below is temporary,
  // until ChildShrinkWrapWidth is updated and width becomes inlineSize.

  // Match the availableWidth logic in Reflow.
  uint8_t captionSide = GetCaptionSide();
  nscoord width;
  if (captionSide == NO_SIDE) {
    width = ChildShrinkWrapWidth(aRenderingContext, InnerTableFrame(),
                                 aCBSize.GetPhysicalSize(aWM),
                                 kidAvailableWidth);
  } else if (captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
             captionSide == NS_STYLE_CAPTION_SIDE_RIGHT) {
    nscoord capWidth = ChildShrinkWrapWidth(aRenderingContext,
                                            mCaptionFrames.FirstChild(),
                                            aCBSize.GetPhysicalSize(aWM),
                                            kidAvailableWidth);
    width = capWidth + ChildShrinkWrapWidth(aRenderingContext,
                                            InnerTableFrame(),
                                            aCBSize.GetPhysicalSize(aWM),
                                            kidAvailableWidth - capWidth);
  } else if (captionSide == NS_STYLE_CAPTION_SIDE_TOP ||
             captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) {
    nscoord margin;
    width = ChildShrinkWrapWidth(aRenderingContext, InnerTableFrame(),
                                 aCBSize.GetPhysicalSize(aWM),
                                 kidAvailableWidth, &margin);
    nscoord capWidth = ChildShrinkWrapWidth(aRenderingContext,
                                            mCaptionFrames.FirstChild(),
                                            aCBSize.GetPhysicalSize(aWM),
                                            width - margin);
    if (capWidth > width)
      width = capWidth;
  } else {
    NS_ASSERTION(captionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE ||
                 captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE,
                 "unexpected caption-side");
    width = ChildShrinkWrapWidth(aRenderingContext, InnerTableFrame(),
                                 aCBSize.GetPhysicalSize(aWM),
                                 kidAvailableWidth);
    nscoord capWidth = ChildShrinkWrapWidth(aRenderingContext,
                                            mCaptionFrames.FirstChild(),
                                            aCBSize.GetPhysicalSize(aWM),
                                            kidAvailableWidth);
    if (capWidth > width)
      width = capWidth;
  }

  return LogicalSize(aWM, width, NS_UNCONSTRAINEDSIZE);
}