aPresContext->GetPixelsToTwips(&twipsPerPx);
twipsPerPx = aPresContext->PixelsToTwips();
nsSVGOuterSVGFrame::Reflow(nsIPresContext*          aPresContext,                           nsHTMLReflowMetrics&     aDesiredSize,                           const nsHTMLReflowState& aReflowState,                           nsReflowStatus&          aStatus){  nsresult rv;  #if defined(DEBUG) && defined(SVG_DEBUG_PRINTING)  {    printf("nsSVGOuterSVGFrame(%p)::Reflow()[\n",this);    float twipsPerScPx,twipsPerPx;    aPresContext->GetScaledPixelsToTwips(&twipsPerScPx);    aPresContext->GetPixelsToTwips(&twipsPerPx);    printf("tw/sc(px)=%f tw/px=%f\n", twipsPerScPx, twipsPerPx);    printf("]\n");  }#endif    // check whether this reflow request is targeted at us or a child  // frame (e.g. a foreignObject):  if (aReflowState.reason == eReflowReason_Incremental) {    nsReflowPath::iterator iter = aReflowState.path->FirstChild();    nsReflowPath::iterator end = aReflowState.path->EndChildren();    for ( ; iter != end; ++iter) {      // The actual target of this reflow is one of our child      // frames. Since SVG as such doesn't use reflow, this will      // probably be the child of a <foreignObject>. Some HTML|XUL      // content frames target reflow events at themselves when they      // need to be redrawn in response to e.g. a style change. For      // correct visual updating, we must make sure the reflow      // reaches its intended target.              // Since it is an svg frame (probably an nsSVGForeignObjectFrame),      // we might as well pass in our aDesiredSize and aReflowState      // objects - they are ignored by svg frames:      nsSize availSpace(0, 0); // XXXwaterson probably wrong!      nsHTMLReflowState state(aPresContext, aReflowState, *iter, availSpace);      (*iter)->Reflow (aPresContext,                       aDesiredSize,                       state,                       aStatus);      // XXX do we really have to return our metrics although we're      // not affected by the reflow? Is there a way of telling our      // parent that we don't want anything changed?      aDesiredSize.width  = mRect.width;      aDesiredSize.height = mRect.height;      aDesiredSize.ascent = aDesiredSize.height;      aDesiredSize.descent = 0;    }    if (! aReflowState.path->mReflowCommand) {      // We're not the target of the incremental reflow, so just bail.      aStatus = NS_FRAME_COMPLETE;      return NS_OK;    }  }    //  SVG CR 20001102: When the SVG content is embedded inline within  //  a containing document, and that document is styled using CSS,  //  then if there are CSS positioning properties specified on the  //  outermost 'svg' element that are sufficient to establish the  //  width of the viewport, then these positioning properties  //  establish the viewport's width; otherwise, the width attribute  //  on the outermost 'svg' element establishes the viewport's width.  //  Similarly, if there are CSS positioning properties specified on  //  the outermost 'svg' element that are sufficient to establish the  //  height of the viewport, then these positioning properties  //  establish the viewport's height; otherwise, the height attribute  //  on the outermost 'svg' element establishes the viewport's  //  height.#ifdef DEBUG  // printf("--- nsSVGOuterSVGFrame(%p)::Reflow(frame:%p,reason:%d) ---\n",this,aReflowState.frame,aReflowState.reason);#endif    NS_ENSURE_TRUE(mContent, NS_ERROR_FAILURE);  nsCOMPtr<nsISVGSVGElement> SVGElement = do_QueryInterface(mContent);  NS_ENSURE_TRUE(SVGElement, NS_ERROR_FAILURE);  float pxPerTwips = GetPxPerTwips();  float twipsPerPx = GetTwipsPerPx();  // The width/height attribs given on the <svg>-element might be  // percentage values of the parent viewport. We will set the parent  // viewport dimensions to the available space.  nsRect maxRect, preferredRect;  CalculateAvailableSpace(&maxRect, &preferredRect, aPresContext, aReflowState);  float preferredWidth = preferredRect.width * pxPerTwips;  float preferredHeight = preferredRect.height * pxPerTwips;  SuspendRedraw();     // As soon as we set the viewport, the width/height attributes might  // emit change-notifications. We don't want those right now:  RemoveAsWidthHeightObserver();  nsCOMPtr<nsISVGViewportRect> parentViewport;  SVGElement->GetParentViewportRect(getter_AddRefs(parentViewport));  NS_ENSURE_TRUE(parentViewport, NS_ERROR_FAILURE);  nsCOMPtr<nsISVGValue> pvp_value = do_QueryInterface(parentViewport);  pvp_value->BeginBatchUpdate();  rv = SetViewportDimensions(parentViewport, preferredWidth, preferredHeight);  NS_ENSURE_SUCCESS(rv,rv);  rv = SetViewportScale(parentViewport, aPresContext);  NS_ENSURE_SUCCESS(rv,rv);  pvp_value->EndBatchUpdate();  #ifdef DEBUG  // some debug stuff://   {//     nsRect r=aPresContext->GetVisibleArea();//     printf("******* aw: %d, ah: %d visiw: %d, visih: %d\n",//            aReflowState.availableWidth,//            aReflowState.availableHeight,//            r.width, r.height);//     printf("******* cw: %d, ch: %d \n    cmaxw: %d, cmaxh: %d\n",//            aReflowState.mComputedWidth,//            aReflowState.mComputedHeight,//            aReflowState.mComputedMaxWidth,//            aReflowState.mComputedMaxHeight);//     if (aReflowState.parentReflowState) {//       printf("******* parent aw: %d, parent ah: %d \n",//              aReflowState.parentReflowState->availableWidth,//              aReflowState.parentReflowState->availableHeight);//       printf("******* parent cw: %d, parent ch: %d \n  parent cmaxw: %d, parent cmaxh: %d\n",//              aReflowState.parentReflowState->mComputedWidth,//              aReflowState.parentReflowState->mComputedHeight,//              aReflowState.parentReflowState->mComputedMaxWidth,//              aReflowState.parentReflowState->mComputedMaxHeight);//     }//   }#endif  // now that the parent viewport dimensions have been set, the  // width/height attributes will be valid.  // Let's work out our desired dimensions.  float width;  {    nsCOMPtr<nsIDOMSVGAnimatedLength> animLength;    SVGElement->GetWidth(getter_AddRefs(animLength));    NS_ENSURE_TRUE(animLength, NS_ERROR_FAILURE);    nsCOMPtr<nsIDOMSVGLength> length;    animLength->GetAnimVal(getter_AddRefs(length));    NS_ENSURE_TRUE(length, NS_ERROR_FAILURE);        length->GetValue(&width);        aDesiredSize.width = (int)(width*twipsPerPx);  }  float height;  {    nsCOMPtr<nsIDOMSVGAnimatedLength> animLength;    SVGElement->GetHeight(getter_AddRefs(animLength));    NS_ENSURE_TRUE(animLength, NS_ERROR_FAILURE);    nsCOMPtr<nsIDOMSVGLength> length;    animLength->GetAnimVal(getter_AddRefs(length));    NS_ENSURE_TRUE(length, NS_ERROR_FAILURE);        length->GetValue(&height);        aDesiredSize.height = (int)(height*twipsPerPx);  }    aDesiredSize.ascent = aDesiredSize.height;  aDesiredSize.descent = 0;    // XXX add in CSS borders ??  aStatus = NS_FRAME_COMPLETE;  NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);  // Set the viewport.  // XXX. I have a feeling that this code belongs in DidReflow(),  // using mRect. Bug #118723 prevents us from putting it there.  nsCOMPtr<nsIDOMSVGRect> domViewport;  SVGElement->GetViewport(getter_AddRefs(domViewport));  NS_ENSURE_TRUE(domViewport, NS_ERROR_FAILURE);  nsCOMPtr<nsISVGViewportRect> viewport = do_QueryInterface(domViewport);  NS_ENSURE_TRUE(viewport, NS_ERROR_FAILURE);    nsCOMPtr<nsISVGValue> vp_value = do_QueryInterface(viewport);  vp_value->BeginBatchUpdate();  rv = SetViewportDimensions(viewport, width, height);  NS_ENSURE_SUCCESS(rv,rv);  rv = SetViewportScale(viewport, aPresContext);  NS_ENSURE_SUCCESS(rv,rv);  vp_value->EndBatchUpdate();    AddAsWidthHeightObserver();    UnsuspendRedraw();    return NS_OK;}