if (child) {
if(child != NULL) {
nsObjectFrame::Paint(nsIPresContext*      aPresContext,                     nsIRenderingContext& aRenderingContext,                     const nsRect&        aDirtyRect,                     nsFramePaintLayer    aWhichLayer,                     PRUint32             aFlags){  const nsStyleVisibility* vis = (const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility);  if ((vis != nsnull) && !vis->IsVisibleOrCollapsed())    return NS_OK;    nsIFrame * child = mFrames.FirstChild();  if (child) {    // if we have children, we are probably not really a plugin    nsObjectFrameSuper::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);    return NS_OK;  }  // determine if we are printing  nsCOMPtr<nsIPrintContext> thePrinterContext = do_QueryInterface(aPresContext);  if  (thePrinterContext) {    // we only want to print on the content layer pass    if (eFramePaintLayer_Content != aWhichLayer)      return NS_OK;    // if we are printing, we need to get the correct nsIPluginInstance    // for THIS content node in order to call ->Print() on the right plugin    // first, we need to get the document    nsCOMPtr<nsIDocument> doc;    mContent->GetDocument(*getter_AddRefs(doc));    NS_ENSURE_TRUE(doc, NS_ERROR_NULL_POINTER);    // now we need to get the shell for the screen    // XXX assuming that the shell at zero will always be the screen one    nsCOMPtr<nsIPresShell> shell;    doc->GetShellAt(0, getter_AddRefs(shell));    NS_ENSURE_TRUE(shell, NS_ERROR_NULL_POINTER);    // then the shell can give us the screen frame for this content node    nsIFrame* frame = nsnull;    shell->GetPrimaryFrameFor(mContent, &frame);    NS_ENSURE_TRUE(frame, NS_ERROR_NULL_POINTER);    // make sure this is REALLY an nsIObjectFrame    // we may need to go through the children to get it    nsIObjectFrame* objectFrame = nsnull;    CallQueryInterface(frame,&objectFrame);    if (!objectFrame)      GetNextObjectFrame(aPresContext,frame,&objectFrame);    NS_ENSURE_TRUE(objectFrame,NS_ERROR_FAILURE);    // finally we can get our plugin instance    nsCOMPtr<nsIPluginInstance> pi;    if (NS_FAILED(objectFrame->GetPluginInstance(*getter_AddRefs(pi))) || !pi)      return NS_ERROR_FAILURE;    // now we need to setup the correct location for printing    nsresult rv;    nsPluginWindow    window;    nsIView          *parentWithView;    nsPoint           origin;    float             t2p;    nsMargin          margin(0,0,0,0);    window.window =   nsnull;    // prepare embedded mode printing struct    nsPluginPrint npprint;    npprint.mode = nsPluginMode_Embedded;    // we need to find out if we are windowless or not    PRBool    windowless;    pi->GetValue(nsPluginInstanceVariable_WindowlessBool, (void *)&windowless);    window.type  =  windowless ? nsPluginWindowType_Drawable : nsPluginWindowType_Window;    // get a few things    nsCOMPtr<nsIPrintSettings> printSettings;    thePrinterContext->GetPrintSettings(getter_AddRefs(printSettings));    printSettings->GetMarginInTwips(margin);    aPresContext->GetTwipsToPixels(&t2p);    GetOffsetFromView(aPresContext, origin, &parentWithView);    // set it all up    // XXX is windowless different?    window.x = NSToCoordRound((origin.x + margin.left) * t2p);    window.y = NSToCoordRound((origin.y + margin.top ) * t2p);    window.width = NSToCoordRound(mRect.width * t2p);    window.height= NSToCoordRound(mRect.height * t2p);    window.clipRect.bottom = 0; window.clipRect.top = 0;    window.clipRect.left = 0; window.clipRect.right = 0;    // XXX platform specific printing code#if defined(XP_MAC) && !TARGET_CARBON    // Mac does things a little differently.    GrafPort *curPort;    ::GetPort(&curPort);  // get the current port    nsPluginPort port;    port.port = (CGrafPort*)curPort;    port.portx = window.x;    port.porty = window.y;    RgnHandle curClip = ::NewRgn();    NS_ENSURE_TRUE(curClip, NS_ERROR_NULL_POINTER);    ::GetClip(curClip); // save old clip        ::SetOrigin(-window.x,-window.y); // port must be set correctly prior to telling plugin to print    Rect r = {0,0,window.height,window.width};    ::ClipRect(&r);  // also set the clip        window.window = &port;    npprint.print.embedPrint.platformPrint = (void*)window.window;#elif defined (XP_UNIX)    // UNIX does things completely differently    PRUnichar *printfile = nsnull;    if (printSettings) {      printSettings->GetToFileName(&printfile);    }    if (!printfile)       return NS_OK; // XXX what to do on UNIX when we don't have a PS file????     NPPrintCallbackStruct npPrintInfo;    npPrintInfo.type = NP_PRINT;    npPrintInfo.fp = (FILE*)printfile;        npprint.print.embedPrint.platformPrint = (void*) &npPrintInfo;#else  // Windows and non-UNIX, non-Mac(Classic) cases    // we need the native printer device context to pass to plugin    // On Windows, this will be the HDC    PRUint32 pDC = 0;    aRenderingContext.RetrieveCurrentNativeGraphicData(&pDC);    if (!pDC)      return NS_OK;  // no dc implemented so quit    npprint.print.embedPrint.platformPrint = (void*)pDC;#endif     npprint.print.embedPrint.window = window;    // send off print info to plugin    rv = pi->Print(&npprint);#if defined(XP_MAC) && !TARGET_CARBON    // Clean-up on Mac    ::SetOrigin(0,0);    ::SetClip(curClip);  // restore previous clip    ::DisposeRgn(curClip);#endif    // XXX Nav 4.x always sent a SetWindow call after print. Should we do the same?    nsCOMPtr<nsIPresContext> screenPcx;    shell->GetPresContext(getter_AddRefs(screenPcx));    nsDidReflowStatus status = NS_FRAME_REFLOW_FINISHED; // should we use a special status?    frame->DidReflow(screenPcx, nsnull, status);  // DidReflow will take care of it    return rv;  // done with printing  }// Screen painting code#if defined (XP_MAC)  // delegate all painting to the plugin instance.  if ((NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) && (nsnull != mInstanceOwner))      mInstanceOwner->Paint(aDirtyRect);#elif defined (XP_PC)  if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {    nsIPluginInstance * inst;    if (NS_OK == GetPluginInstance(inst)) {      // Look if it's windowless      nsPluginWindow * window;      mInstanceOwner->GetWindow(window);      if (window->type == nsPluginWindowType_Drawable) {        // check if we need to call SetWindow with updated parameters        PRBool doupdatewindow = PR_FALSE;        // check if we need to update hdc        PRUint32 hdc;        aRenderingContext.RetrieveCurrentNativeGraphicData(&hdc);        if(NS_REINTERPRET_CAST(PRUint32, window->window) != hdc) {          window->window = NS_REINTERPRET_CAST(nsPluginPort*, hdc);          doupdatewindow = PR_TRUE;        }        // check if we need to update window position        nsPoint origin;        GetWindowOriginInPixels(aPresContext, PR_TRUE, &origin);        if((window->x != origin.x) || (window->y != origin.y)) {          window->x = origin.x;          window->y = origin.y;          doupdatewindow = PR_TRUE;        }        if(doupdatewindow)          inst->SetWindow(window);        mInstanceOwner->Paint(aDirtyRect, hdc);      }      NS_RELEASE(inst);    }  }#endif /* !XP_MAC */  DO_GLOBAL_REFLOW_COUNT_DSP("nsObjectFrame", &aRenderingContext);  return NS_OK;}