//------------------------------------------------------------------------------ void nsSimplePageSequenceFrame::PaintPageSequence(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsPoint aPt) { nsRect rect = aDirtyRect; float scale = PresContext()->GetPrintPreviewScale(); aRenderingContext.PushState(); nsPoint framePos = aPt; aRenderingContext.Translate(framePos.x, framePos.y); rect -= framePos; aRenderingContext.Scale(scale, scale); rect.ScaleRoundOut(1.0f / scale); // Now the rect and the rendering coordinates are are relative to this frame. // Loop over the pages and paint them. nsIFrame* child = GetFirstChild(nsnull); while (child) { nsPoint pt = child->GetPosition(); // The rendering context has to be translated before each call to PaintFrame aRenderingContext.PushState(); aRenderingContext.Translate(pt.x, pt.y); nsLayoutUtils::PaintFrame(&aRenderingContext, child, nsRegion(rect - pt), NS_RGBA(0,0,0,0)); aRenderingContext.PopState(); child = child->GetNextSibling(); } aRenderingContext.PopState(); }
//------------------------------------------------------------------------------ void nsPageFrame::PaintPageContent(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsPoint aPt) { nsIFrame* pageContentFrame = mFrames.FirstChild(); nsRect rect = aDirtyRect; float scale = PresContext()->GetPageScale(); aRenderingContext.PushState(); nsPoint framePos = aPt + pageContentFrame->GetOffsetTo(this); aRenderingContext.Translate(framePos.x, framePos.y); // aPt translates to coords relative to this, then margins translate to // pageContentFrame's coords rect -= framePos; aRenderingContext.Scale(scale, scale); rect.ScaleRoundOut(1.0f / scale); // Make sure we don't draw where we aren't supposed to draw, especially // when printing selection nsRect clipRect(nsPoint(0, 0), pageContentFrame->GetSize()); // Note: this computation matches how we compute maxSize.height // in nsPageFrame::Reflow nscoord expectedPageContentHeight = NSToCoordCeil((GetSize().height - mPD->mReflowMargin.TopBottom()) / scale); if (clipRect.height > expectedPageContentHeight) { // We're doing print-selection, with one long page-content frame. // Clip to the appropriate page-content slice for the current page. NS_ASSERTION(mPageNum > 0, "page num should be positive"); // Note: The pageContentFrame's y-position has been set such that a zero // y-value matches the top edge of the current page. So, to clip to the // current page's content (in coordinates *relative* to the page content // frame), we just negate its y-position and add the top margin. clipRect.y = NSToCoordCeil((-pageContentFrame->GetRect().y + mPD->mReflowMargin.top) / scale); clipRect.height = expectedPageContentHeight; NS_ASSERTION(clipRect.y < pageContentFrame->GetSize().height, "Should be clipping to region inside the page content bounds"); } aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsRect backgroundRect = nsRect(nsPoint(0, 0), pageContentFrame->GetSize()); nsCSSRendering::PaintBackground(PresContext(), aRenderingContext, this, rect, backgroundRect, nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES); nsLayoutUtils::PaintFrame(&aRenderingContext, pageContentFrame, nsRegion(rect), NS_RGBA(0,0,0,0), nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES); aRenderingContext.PopState(); }
NS_IMETHODIMP nsScrollPortView::Paint(nsIRenderingContext& aRC, const nsIRegion& aRegion, PRUint32 aPaintFlags, PRBool &aResult) { aRC.PushState(); nsRect bounds; GetDimensions(bounds); bounds.x = bounds.y = 0; aRC.SetClipRect(bounds, nsClipCombine_kIntersect); nsresult rv = nsView::Paint(aRC, aRegion, aPaintFlags, aResult); aRC.PopState(); return rv; }
//------------------------------------------------------------------------------ void nsPageFrame::PaintPageContent(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsPoint aPt) { nsIFrame* pageContentFrame = mFrames.FirstChild(); nsRect rect = aDirtyRect; float scale = PresContext()->GetPageScale(); aRenderingContext.PushState(); nsPoint framePos = aPt + pageContentFrame->GetOffsetTo(this); aRenderingContext.Translate(framePos.x, framePos.y); // aPt translates to coords relative to this, then margins translate to // pageContentFrame's coords rect -= framePos; aRenderingContext.Scale(scale, scale); rect.ScaleRoundOut(1.0f / scale); // Make sure we don't draw where we aren't supposed to draw, especially // when printing selection nsRect clipRect(nsPoint(0, 0), pageContentFrame->GetSize()); // Note: this computation matches how we compute maxSize.height // in nsPageFrame::Reflow nscoord expectedPageContentHeight = NSToCoordCeil((GetSize().height - mPD->mReflowMargin.TopBottom()) / scale); if (clipRect.height > expectedPageContentHeight) { // We're doing print-selection, with one long page-content frame. // Clip to the appropriate page-content slice for the current page. NS_ASSERTION(mPageNum > 0, "page num should be positive"); clipRect.y = expectedPageContentHeight * (mPageNum - 1); clipRect.height = expectedPageContentHeight; NS_ASSERTION(clipRect.y < pageContentFrame->GetSize().height, "Should be clipping to region inside the page content bounds"); } aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); const nsStyleBorder* border = GetStyleBorder(); const nsStylePadding* padding = GetStylePadding(); nsRect backgroundRect = nsRect(nsPoint(0, 0), pageContentFrame->GetSize()); nsCSSRendering::PaintBackground(PresContext(), aRenderingContext, this, rect, backgroundRect, *border, *padding, PR_TRUE); nsLayoutUtils::PaintFrame(&aRenderingContext, pageContentFrame, nsRegion(rect), NS_RGBA(0,0,0,0)); aRenderingContext.PopState(); }
void nsComboboxControlFrame::PaintFocus(nsIRenderingContext& aRenderingContext, nsPoint aPt) { /* Do we need to do anything? */ if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled) || mFocused != this) return; aRenderingContext.PushState(); nsRect clipRect = mDisplayFrame->GetRect() + aPt; aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); // REVIEW: Why does the old code paint mDisplayFrame again? We've // already painted it in the children above. So clipping it here won't do // us much good. ///////////////////// // draw focus aRenderingContext.SetLineStyle(nsLineStyle_kDotted); aRenderingContext.SetColor(GetStyleColor()->mColor); //aRenderingContext.DrawRect(clipRect); nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); clipRect.width -= onePixel; clipRect.height -= onePixel; aRenderingContext.DrawLine(clipRect.x, clipRect.y, clipRect.x+clipRect.width, clipRect.y); aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y, clipRect.x+clipRect.width, clipRect.y+clipRect.height); aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height, clipRect.x, clipRect.y+clipRect.height); aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, clipRect.x, clipRect.y); aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, clipRect.x, clipRect.y); aRenderingContext.PopState(); }
NS_IMETHODIMP nsTableCellFrame::Paint(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer, PRUint32 aFlags) { NS_ENSURE_TRUE(aPresContext, NS_ERROR_NULL_POINTER); PRBool isVisible; if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_FALSE, &isVisible)) && !isVisible) { return NS_OK; } PRBool paintChildren = PR_TRUE; if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) { const nsStyleBorder* myBorder = nsnull; const nsStylePadding* myPadding = nsnull; const nsStyleTableBorder* cellTableStyle = nsnull; const nsStyleVisibility* vis = GetStyleVisibility(); if (vis->IsVisible()) { myBorder = GetStyleBorder(); myPadding = GetStylePadding(); cellTableStyle = GetStyleTableBorder(); // draw the border & background only when there is content or showing empty cells if (NS_STYLE_TABLE_EMPTY_CELLS_HIDE != cellTableStyle->mEmptyCells || !GetContentEmpty()) { PaintUnderlay(*aPresContext, aRenderingContext, aDirtyRect, aFlags, *myBorder, *myPadding, *cellTableStyle); } // Paint outline nsRect rect(0, 0, mRect.width, mRect.height); const nsStyleOutline* myOutline = GetStyleOutline(); nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this, aDirtyRect, rect, *myBorder, *myOutline, mStyleContext, 0); const nsStyleBackground* myColor = GetStyleBackground(); DecorateForSelection(aPresContext, aRenderingContext,myColor); //ignore return value } paintChildren = !(aFlags & NS_PAINT_FLAG_TABLE_CELL_BG_PASS); //flags were for us; remove them for our children aFlags &= ~ (NS_PAINT_FLAG_TABLE_CELL_BG_PASS | NS_PAINT_FLAG_TABLE_BG_PAINT); } #ifdef DEBUG // for debug... if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) { aRenderingContext.SetColor(NS_RGB(0, 0, 128)); aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height); } #endif // paint the children unless we've been told not to if (paintChildren) { const nsStyleDisplay* disp = GetStyleDisplay(); // if the cell originates in a row and/or col that is collapsed, the // bottom and/or right portion of the cell is painted by translating // the rendering context. nsPoint offset; GetCollapseOffset(offset); PRBool pushed = PR_FALSE; if ((0 != offset.x) || (0 != offset.y)) { aRenderingContext.PushState(); pushed = PR_TRUE; aRenderingContext.Translate(offset.x, offset.y); aRenderingContext.SetClipRect(nsRect(-offset.x, -offset.y, mRect.width, mRect.height), nsClipCombine_kIntersect); } else { // XXXldb HIDDEN should really create a scrollframe, // but use |IsTableClip| here since it doesn't. if (disp->IsTableClip() || (HasPctOverHeight() && eCompatibility_NavQuirks == aPresContext->CompatibilityMode())) { aRenderingContext.PushState(); pushed = PR_TRUE; SetOverflowClipRect(aRenderingContext); } } PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aFlags); if (pushed) { aRenderingContext.PopState(); } } DO_GLOBAL_REFLOW_COUNT_DSP_J("nsTableCellFrame", &aRenderingContext, 0); return NS_OK; /*nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);*/ }
// Draw a header or footer string // @param aRenderingContext - rendering context to draw into // @param aHeaderFooter - indicates whether it is a header or footer // @param aJust - indicates where the string is located within the header/footer // @param aStr - the string to be drawn // @param aRect - the rect of the page // @param aHeight - the height of the font // @param aAscent - the ascent of the font // @param aWidth - available width for the string void nsPageFrame::DrawHeaderFooter(nsIRenderingContext& aRenderingContext, nsHeaderFooterEnum aHeaderFooter, PRInt32 aJust, const nsString& aStr, const nsRect& aRect, nscoord aAscent, nscoord aHeight, nscoord aWidth) { nscoord contentWidth = aWidth - (mPD->mEdgePaperMargin.left + mPD->mEdgePaperMargin.right); if ((aHeaderFooter == eHeader && aHeight < mPD->mReflowMargin.top) || (aHeaderFooter == eFooter && aHeight < mPD->mReflowMargin.bottom)) { nsAutoString str; ProcessSpecialCodes(aStr, str); PRInt32 indx; PRInt32 textWidth = 0; const PRUnichar* text = str.get(); PRInt32 len = (PRInt32)str.Length(); if (len == 0) { return; // bail is empty string } // find how much text fits, the "position" is the size of the available area if (nsLayoutUtils::BinarySearchForPosition(&aRenderingContext, text, 0, 0, 0, len, PRInt32(contentWidth), indx, textWidth)) { if (indx < len-1 ) { // we can't fit in all the text if (indx > 3) { // But we can fit in at least 4 chars. Show all but 3 of them, then // an ellipsis. // XXXbz for non-plane0 text, this may be cutting things in the // middle of a codepoint! Also, we have no guarantees that the three // dots will fit in the space the three chars we removed took up with // these font metrics! str.Truncate(indx-3); str.AppendLiteral("..."); } else { // We can only fit 3 or fewer chars. Just show nothing str.Truncate(); } } } else { return; // bail if couldn't find the correct length } if (HasRTLChars(str)) { PresContext()->SetBidiEnabled(); } // cacl the x and y positions of the text nscoord x = GetXPosition(aRenderingContext, aRect, aJust, str); nscoord y; if (aHeaderFooter == eHeader) { y = aRect.y + mPD->mExtraMargin.top + mPD->mEdgePaperMargin.top; } else { y = aRect.YMost() - aHeight - mPD->mExtraMargin.bottom - mPD->mEdgePaperMargin.bottom; } // set up new clip and draw the text aRenderingContext.PushState(); aRenderingContext.SetColor(NS_RGB(0,0,0)); aRenderingContext.SetClipRect(aRect, nsClipCombine_kIntersect); nsLayoutUtils::DrawString(this, &aRenderingContext, str.get(), str.Length(), nsPoint(x, y + aAscent)); aRenderingContext.PopState(); } }
void nsGroupBoxFrame::PaintBorderBackground(nsIRenderingContext& aRenderingContext, nsPoint aPt, const nsRect& aDirtyRect) { PRIntn skipSides = 0; const nsStyleBorder* borderStyleData = GetStyleBorder(); const nsMargin& border = borderStyleData->GetActualBorder(); nscoord yoff = 0; nsPresContext* presContext = PresContext(); nsRect groupRect; nsIBox* groupBox = GetCaptionBox(presContext, groupRect); if (groupBox) { // if the border is smaller than the legend. Move the border down // to be centered on the legend. nsMargin groupMargin; groupBox->GetStyleMargin()->GetMargin(groupMargin); groupRect.Inflate(groupMargin); if (border.top < groupRect.height) yoff = (groupRect.height - border.top)/2 + groupRect.y; } nsRect rect(aPt.x, aPt.y + yoff, mRect.width, mRect.height - yoff); groupRect += aPt; nsCSSRendering::PaintBackground(presContext, aRenderingContext, this, aDirtyRect, rect, 0); if (groupBox) { // we should probably use PaintBorderEdges to do this but for now just use clipping // to achieve the same effect. // draw left side nsRect clipRect(rect); clipRect.width = groupRect.x - rect.x; clipRect.height = border.top; aRenderingContext.PushState(); aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsCSSRendering::PaintBorder(presContext, aRenderingContext, this, aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides); aRenderingContext.PopState(); // draw right side clipRect = rect; clipRect.x = groupRect.XMost(); clipRect.width = rect.XMost() - groupRect.XMost(); clipRect.height = border.top; aRenderingContext.PushState(); aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsCSSRendering::PaintBorder(presContext, aRenderingContext, this, aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides); aRenderingContext.PopState(); // draw bottom clipRect = rect; clipRect.y += border.top; clipRect.height = mRect.height - (yoff + border.top); aRenderingContext.PushState(); aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsCSSRendering::PaintBorder(presContext, aRenderingContext, this, aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides); aRenderingContext.PopState(); } else { nsCSSRendering::PaintBorder(presContext, aRenderingContext, this, aDirtyRect, nsRect(aPt, GetSize()), *borderStyleData, mStyleContext, skipSides); } }
// this is identical to nsHTMLContainerFrame::Paint except for the background and border. NS_IMETHODIMP nsFieldSetFrame::Paint(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer, PRUint32 aFlags) { if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) { // Paint our background and border PRBool isVisible; if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && isVisible && mRect.width && mRect.height) { PRIntn skipSides = GetSkipSides(); const nsStyleBorder* borderStyle = GetStyleBorder(); const nsStylePadding* paddingStyle = GetStylePadding(); nscoord topBorder = borderStyle->GetBorderWidth(NS_SIDE_TOP); nscoord yoff = 0; // if the border is smaller than the legend. Move the border down // to be centered on the legend. if (topBorder < mLegendRect.height) yoff = (mLegendRect.height - topBorder)/2; nsRect rect(0, yoff, mRect.width, mRect.height - yoff); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, rect, *borderStyle, *paddingStyle, PR_TRUE); if (mLegendFrame) { // Use the rect of the legend frame, not mLegendRect, so we draw our // border under the legend's left and right margins. const nsRect & legendRect = mLegendFrame->GetRect(); // we should probably use PaintBorderEdges to do this but for now just use clipping // to achieve the same effect. // draw left side nsRect clipRect(rect); clipRect.width = legendRect.x - rect.x; clipRect.height = topBorder; aRenderingContext.PushState(); aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, aDirtyRect, rect, *borderStyle, mStyleContext, skipSides); aRenderingContext.PopState(); // draw right side clipRect = rect; clipRect.x = legendRect.x + legendRect.width; clipRect.width -= (legendRect.x + legendRect.width); clipRect.height = topBorder; aRenderingContext.PushState(); aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, aDirtyRect, rect, *borderStyle, mStyleContext, skipSides); aRenderingContext.PopState(); // draw bottom clipRect = rect; clipRect.y += topBorder; clipRect.height = mRect.height - (yoff + topBorder); aRenderingContext.PushState(); aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, aDirtyRect, rect, *borderStyle, mStyleContext, skipSides); aRenderingContext.PopState(); } else { nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, aDirtyRect, nsRect(0,0,mRect.width, mRect.height), *borderStyle, mStyleContext, skipSides); } } } PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); #ifdef DEBUG if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) { if (HasView()) { aRenderingContext.SetColor(NS_RGB(0,0,255)); } else { aRenderingContext.SetColor(NS_RGB(255,0,0)); } aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height); } #endif DO_GLOBAL_REFLOW_COUNT_DSP("nsFieldSetFrame", &aRenderingContext); return NS_OK; }