nsresult rv; nsCOMPtr<nsIPrintOptions> printService = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && printService) { nsMargin margin(0,0,0,0); printService->GetMarginInTwips(margin); rect.x -= margin.left; rect.y -= margin.top; }
void DocumentViewerImpl::CalcPageFrameLocation(nsIPresShell * aPresShell,                                               PrintObject*   aPO){  NS_ASSERTION(aPresShell, "Pointer is null!");  NS_ASSERTION(aPO, "Pointer is null!");  if (aPO != nsnull && aPO->mContent != nsnull) {    // Find that frame for the sub-doc's content element    // in the parent document    nsIFrame * frame;    aPresShell->GetPrimaryFrameFor(aPO->mContent, &frame);    NS_ASSERTION(frame, "Frame shouldn't be null!");    nsMargin borderPadding(0, 0, 0, 0);    frame->CalcBorderPadding(borderPadding);    // Calc absolute position of the frame all the way up    // to the SimpleSeq frame    nsRect rect;    frame->GetRect(rect);    rect.Deflate(borderPadding);    rect.x = 0;    rect.y = 0;    nsIFrame * parent    = frame;    nsIFrame * pageFrame = nsnull;    nsIFrame * seqFrame  = nsnull;    while (parent != nsnull) {      nsRect rr;      parent->GetRect(rr);      rect.x += rr.x;      rect.y += rr.y;      nsIFrame * temp = parent;      temp->GetParent(&parent);      // Keep a pointer to the Seq and Page frames       nsIPageSequenceFrame * sqf = nsnull;      if (parent != nsnull &&           NS_SUCCEEDED(CallQueryInterface(parent, &sqf)) && sqf) {        pageFrame = temp;        seqFrame  = parent;      }    }    NS_ASSERTION(seqFrame, "The sequencer frame can't be null!");    NS_ASSERTION(pageFrame, "The page frame can't be null!");    // The PageFrame or Seq frame has the margins set    // these need to be removed    nsresult rv;    nsCOMPtr<nsIPrintOptions> printService =              do_GetService(kPrintOptionsCID, &rv);    if (NS_SUCCEEDED(rv) && printService) {      nsMargin margin(0,0,0,0);      printService->GetMarginInTwips(margin);      rect.x -= margin.left;      rect.y -= margin.top;    }    // Remember the Frame location information for later    aPO->mRect      = rect;    aPO->mSeqFrame  = seqFrame;    aPO->mPageFrame = pageFrame;    // Calc the Page No it is on    PRInt32 pageNum = 1;    nsIFrame * child;    seqFrame->FirstChild(aPO->mPresContext, nsnull, &child);    while (child != nsnull) {      if (pageFrame == child) {        aPO->mPageNum = pageNum;        break;      }      pageNum++;      child->GetNextSibling(&child);    } // while  }}