Check for a valid rendering context before we actually start drawing. Use a new stack-based class for saving rendering context state. Hopefully, it won't live here forever, but will be ok for everyone to use.

This commit is contained in:
pinkerton%netscape.com 1999-02-04 00:10:28 +00:00
Родитель 40822ed808
Коммит 82a78924ae
1 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -35,6 +35,28 @@
#include "nsXULAtoms.h"
//
// class StRenderingContext
//
// A stack-based helper class that guarantees taht the state will be restored to it's
// previous state when the current scope finishes. It is exception safe.
//
class StRenderingContextSaver
{
public:
StRenderingContextSaver ( nsIRenderingContext & inContext ) : mContext(&inContext) { mContext->PushState(); };
~StRenderingContextSaver ( )
{
PRBool ignored;
mContext->PopState(ignored);
}
private:
nsCOMPtr<nsIRenderingContext> mContext;
}; // class StRenderingContextSaver
//
// NS_NewToolboxFrame
//
@ -180,10 +202,16 @@ void
nsToolboxFrame :: DrawGrippy ( nsIPresContext& aPresContext, nsIRenderingContext & aRenderingContext,
const nsRect & aBoundingRect, PRBool aDrawHilighted ) const
{
aRenderingContext.PushState();
StRenderingContextSaver saved(aRenderingContext);
nsCOMPtr<nsIStyleContext> style ( aDrawHilighted ? mGrippyRolloverStyle : mGrippyNormalStyle ) ;
if ( !mGrippyRolloverStyle ) {
#ifdef NS_DEBUG
printf("nsToolboxFrame::DrawGrippy() -- style context null, css file not loaded correctly??\n");
#endif
return; // something must be seriously wrong
}
const nsStyleColor* grippyColor = (const nsStyleColor*)style->GetStyleData(eStyleStruct_Color);
const nsStyleSpacing* grippySpacing = (const nsStyleSpacing*)style->GetStyleData(eStyleStruct_Spacing);
const nsStyleFont* grippyFont = (const nsStyleFont*)style->GetStyleData(eStyleStruct_Font);
@ -194,9 +222,6 @@ nsToolboxFrame :: DrawGrippy ( nsIPresContext& aPresContext, nsIRenderingContex
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, nonConstSelf,
aBoundingRect, aBoundingRect, *grippySpacing, style, 0);
PRBool clipState;
aRenderingContext.PopState(clipState);
} // DrawGrippy
@ -477,4 +502,4 @@ nsToolboxFrame :: ExpandToolbar ( TabInfo & inTab )
mContent->UnsetAttribute ( nsXULAtoms::nameSpaceID, kSelectedAtom, PR_TRUE );
} // ExpandToolbar
} // ExpandToolbar