void nsTextBoxFrame::PaintTitle(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsPoint aPt) { if (mTitle.IsEmpty()) return; nsRect textRect(CalcTextRect(aRenderingContext, aPt)); // Paint the text shadow before doing any foreground stuff const nsStyleText* textStyle = GetStyleText(); if (textStyle->mTextShadow) { // Text shadow happens with the last value being painted at the back, // ie. it is painted first. for (PRUint32 i = textStyle->mTextShadow->Length(); i > 0; --i) { PaintOneShadow(aRenderingContext.ThebesContext(), textRect, textStyle->mTextShadow->ShadowAt(i - 1), GetStyleColor()->mColor, aDirtyRect); } } DrawText(aRenderingContext, textRect, nsnull); }
//------------------------------------------------------------ void nsGfxCheckboxControlFrame::PaintCheckBox(nsIRenderingContext& aRenderingContext, nsPoint aPt, const nsRect& aDirtyRect) { // REVIEW: moved the mAppearance test out so we avoid constructing // a display item if it's not needed nsRect checkRect(aPt, mRect.Size()); checkRect.Deflate(GetUsedBorderAndPadding()); const nsStyleColor* color = GetStyleColor(); aRenderingContext.SetColor(color->mColor); PaintCheckMark(aRenderingContext, checkRect); }
NS_IMETHODIMP nsMathMLmsqrtFrame::Paint(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer, PRUint32 aFlags) { ///////////// // paint the content we are square-rooting nsresult rv = nsMathMLContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); ///////////// // paint the sqrt symbol if (!NS_MATHML_HAS_ERROR(mPresentationData.flags)) { mSqrChar.Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, this); if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && mStyleContext->GetStyleVisibility()->IsVisible() && !mBarRect.IsEmpty()) { // paint the overline bar const nsStyleColor* color = GetStyleColor(); aRenderingContext.SetColor(color->mColor); aRenderingContext.FillRect(mBarRect); } #if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX) // for visual debug if (NS_MATHML_PAINT_BOUNDING_METRICS(mPresentationData.flags)) { nsRect rect; mSqrChar.GetRect(rect); nsBoundingMetrics bm; mSqrChar.GetBoundingMetrics(bm); aRenderingContext.SetColor(NS_RGB(255,0,0)); nscoord x = rect.x + bm.leftBearing; nscoord y = rect.y; nscoord w = bm.rightBearing - bm.leftBearing; nscoord h = bm.ascent + bm.descent; aRenderingContext.DrawRect(x,y,w,h); } #endif } return rv; }
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(); }
void nsHTMLContainerFrame::GetTextDecorations(nsPresContext* aPresContext, PRBool aIsBlock, PRUint8& aDecorations, nscolor& aUnderColor, nscolor& aOverColor, nscolor& aStrikeColor) { aDecorations = NS_STYLE_TEXT_DECORATION_NONE; if (!mStyleContext->HasTextDecorations()) { // This is a necessary, but not sufficient, condition for text // decorations. return; } // A mask of all possible decorations. PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_UNDERLINE | NS_STYLE_TEXT_DECORATION_OVERLINE | NS_STYLE_TEXT_DECORATION_LINE_THROUGH; if (!aIsBlock) { aDecorations = GetStyleTextReset()->mTextDecoration & decorMask; if (aDecorations) { const nsStyleColor* styleColor = GetStyleColor(); aUnderColor = styleColor->mColor; aOverColor = styleColor->mColor; aStrikeColor = styleColor->mColor; } } else { // walk tree for (nsIFrame *frame = this; frame && decorMask; frame = frame->GetParent()) { // find text-decorations. "Inherit" from parent *block* frames nsStyleContext* styleContext = frame->GetStyleContext(); const nsStyleDisplay* styleDisplay = styleContext->GetStyleDisplay(); if (!styleDisplay->IsBlockLevel() && styleDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL) { // If an inline frame is discovered while walking up the tree, // we should stop according to CSS3 draft. CSS2 is rather vague // about this. break; } const nsStyleTextReset* styleText = styleContext->GetStyleTextReset(); PRUint8 decors = decorMask & styleText->mTextDecoration; if (decors) { // A *new* text-decoration is found. nscolor color = styleContext->GetStyleColor()->mColor; if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decors) { aUnderColor = color; decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE; aDecorations |= NS_STYLE_TEXT_DECORATION_UNDERLINE; } if (NS_STYLE_TEXT_DECORATION_OVERLINE & decors) { aOverColor = color; decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE; aDecorations |= NS_STYLE_TEXT_DECORATION_OVERLINE; } if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decors) { aStrikeColor = color; decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH; aDecorations |= NS_STYLE_TEXT_DECORATION_LINE_THROUGH; } } } } if (aDecorations) { // If this frame contains no text, we're required to ignore this property if (!HasTextFrameDescendantOrInFlow(aPresContext, this)) { aDecorations = NS_STYLE_TEXT_DECORATION_NONE; } } }
void nsTextBoxFrame::DrawText(nsIRenderingContext& aRenderingContext, const nsRect& aTextRect, const nscolor* aOverrideColor) { nsPresContext* presContext = PresContext(); // paint the title nscolor overColor; nscolor underColor; nscolor strikeColor; nsStyleContext* context = mStyleContext; PRUint8 decorations = NS_STYLE_TEXT_DECORATION_NONE; // Begin with no decorations PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_UNDERLINE | NS_STYLE_TEXT_DECORATION_OVERLINE | NS_STYLE_TEXT_DECORATION_LINE_THROUGH; // A mask of all possible decorations. PRBool hasDecorations = context->HasTextDecorations(); do { // find decoration colors const nsStyleTextReset* styleText = context->GetStyleTextReset(); if (decorMask & styleText->mTextDecoration) { // a decoration defined here nscolor color = aOverrideColor ? *aOverrideColor : context->GetStyleColor()->mColor; if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decorMask & styleText->mTextDecoration) { underColor = color; decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE; decorations |= NS_STYLE_TEXT_DECORATION_UNDERLINE; } if (NS_STYLE_TEXT_DECORATION_OVERLINE & decorMask & styleText->mTextDecoration) { overColor = color; decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE; decorations |= NS_STYLE_TEXT_DECORATION_OVERLINE; } if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decorMask & styleText->mTextDecoration) { strikeColor = color; decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH; decorations |= NS_STYLE_TEXT_DECORATION_LINE_THROUGH; } } if (0 != decorMask) { context = context->GetParent(); if (context) { hasDecorations = context->HasTextDecorations(); } } } while (context && hasDecorations && (0 != decorMask)); nsCOMPtr<nsIFontMetrics> fontMet; nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet)); nscoord offset; nscoord size; nscoord ascent; fontMet->GetMaxAscent(ascent); nscoord baseline = presContext->RoundAppUnitsToNearestDevPixels(aTextRect.y + ascent); nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext(); gfxPoint pt(presContext->AppUnitsToGfxUnits(aTextRect.x), presContext->AppUnitsToGfxUnits(aTextRect.y)); gfxFloat width = presContext->AppUnitsToGfxUnits(aTextRect.width); gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent); // Underlines are drawn before overlines, and both before the text // itself, per http://www.w3.org/TR/CSS21/zindex.html point 7.2.1.4.1.1. // (We don't apply this rule to the access-key underline because we only // find out where that is as a side effect of drawing the text, in the // general case -- see below.) if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) { fontMet->GetUnderline(offset, size); gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset); gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size); if (decorations & NS_FONT_DECORATION_UNDERLINE) { nsCSSRendering::PaintDecorationLine(ctx, underColor, pt, gfxSize(width, sizePixel), ascentPixel, offsetPixel, NS_STYLE_TEXT_DECORATION_UNDERLINE, nsCSSRendering::DECORATION_STYLE_SOLID); } if (decorations & NS_FONT_DECORATION_OVERLINE) { nsCSSRendering::PaintDecorationLine(ctx, overColor, pt, gfxSize(width, sizePixel), ascentPixel, ascentPixel, NS_STYLE_TEXT_DECORATION_OVERLINE, nsCSSRendering::DECORATION_STYLE_SOLID); } } aRenderingContext.SetFont(fontMet); CalculateUnderline(aRenderingContext); aRenderingContext.SetColor(aOverrideColor ? *aOverrideColor : GetStyleColor()->mColor); #ifdef IBMBIDI nsresult rv = NS_ERROR_FAILURE; if (mState & NS_FRAME_IS_BIDI) { presContext->SetBidiEnabled(); nsBidiPresUtils* bidiUtils = presContext->GetBidiUtils(); if (bidiUtils) { const nsStyleVisibility* vis = GetStyleVisibility(); nsBidiDirection direction = (NS_STYLE_DIRECTION_RTL == vis->mDirection) ? NSBIDI_RTL : NSBIDI_LTR; if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) { // We let the RenderText function calculate the mnemonic's // underline position for us. nsBidiPositionResolve posResolve; posResolve.logicalIndex = mAccessKeyInfo->mAccesskeyIndex; rv = bidiUtils->RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), direction, presContext, aRenderingContext, aTextRect.x, baseline, &posResolve, 1); mAccessKeyInfo->mBeforeWidth = posResolve.visualLeftTwips; mAccessKeyInfo->mAccessWidth = posResolve.visualWidth; } else { rv = bidiUtils->RenderText(mCroppedTitle.get(), mCroppedTitle.Length(), direction, presContext, aRenderingContext, aTextRect.x, baseline); } } } if (NS_FAILED(rv) ) #endif // IBMBIDI { aRenderingContext.SetTextRunRTL(PR_FALSE); if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) { // In the simple (non-BiDi) case, we calculate the mnemonic's // underline position by getting the text metric. // XXX are attribute values always two byte? if (mAccessKeyInfo->mAccesskeyIndex > 0) aRenderingContext.GetWidth(mCroppedTitle.get(), mAccessKeyInfo->mAccesskeyIndex, mAccessKeyInfo->mBeforeWidth); else mAccessKeyInfo->mBeforeWidth = 0; } aRenderingContext.DrawString(mCroppedTitle, aTextRect.x, baseline); } if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) { aRenderingContext.FillRect(aTextRect.x + mAccessKeyInfo->mBeforeWidth, aTextRect.y + mAccessKeyInfo->mAccessOffset, mAccessKeyInfo->mAccessWidth, mAccessKeyInfo->mAccessUnderlineSize); } // Strikeout is drawn on top of the text, per // http://www.w3.org/TR/CSS21/zindex.html point 7.2.1.4.1.1. if (decorations & NS_FONT_DECORATION_LINE_THROUGH) { fontMet->GetStrikeout(offset, size); gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset); gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size); nsCSSRendering::PaintDecorationLine(ctx, strikeColor, pt, gfxSize(width, sizePixel), ascentPixel, offsetPixel, NS_STYLE_TEXT_DECORATION_LINE_THROUGH, nsCSSRendering::DECORATION_STYLE_SOLID); } }