Adding support for XOR selection. Updated nsIRenderingContext interface
to support InvertRect() for the XOR-ing of rectangles. Makes selection work as expected on windows and unix as opposed to the rectangle hack. Stubs added for all other platforms.
This commit is contained in:
Родитель
d892c40a0a
Коммит
89f257f698
|
@ -325,6 +325,21 @@ public:
|
|||
*/
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
|
||||
|
||||
/**
|
||||
* XOR Invert a rectangle in the current foreground color
|
||||
* @param aRect The rectangle to draw
|
||||
*/
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect) = 0;
|
||||
|
||||
/**
|
||||
* XOR Invert a rectangle in the current foreground color
|
||||
* @param aX Horizontal left Coordinate in twips
|
||||
* @param aY Vertical top Coordinate in twips
|
||||
* @param aWidth Width of rectangle in twips
|
||||
* @param aHeight Height of rectangle in twips
|
||||
*/
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) = 0;
|
||||
|
||||
/**
|
||||
* Draw a poly in the current foreground color
|
||||
* @param aPoints points to use for the drawing, last must equal first
|
||||
|
|
|
@ -823,6 +823,22 @@ NS_IMETHODIMP nsRenderingContextBeOS::FillRect(nscoord aX, nscoord aY, nscoord a
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextBeOS :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextBeOS::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextBeOS :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextBeOS::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextBeOS::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
// First transform nsPoint's into BPoint's; perform coordinate space
|
||||
|
|
|
@ -96,9 +96,13 @@ public:
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -745,6 +745,40 @@ NS_IMETHODIMP nsRenderingContextGTK::FillRect(nscoord aX, nscoord aY, nscoord aW
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextGTK::InvertRect(const nsRect& aRect)
|
||||
{
|
||||
return InvertRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextGTK::InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
if (nsnull == mTMatrix || nsnull == mSurface) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
// Set XOR drawing mode
|
||||
::gdk_gc_set_function(mSurface->GetGC(),GDK_XOR);
|
||||
|
||||
// Fill the rect
|
||||
::gdk_draw_rectangle(mSurface->GetDrawable(), mSurface->GetGC(),
|
||||
TRUE,
|
||||
x, y, w, h);
|
||||
|
||||
// Back to normal copy drawing mode
|
||||
::gdk_gc_set_function(mSurface->GetGC(),GDK_COPY);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextGTK::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
|
||||
|
|
|
@ -98,9 +98,13 @@ public:
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -992,6 +992,21 @@ NS_IMETHODIMP nsRenderingContextMotif :: FillRect(nscoord aX, nscoord aY, nscoor
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextMotif :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextMotif::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextMotif :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextMotif::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextMotif::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
|
|
|
@ -106,9 +106,13 @@ public:
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -1003,6 +1003,22 @@ nsresult nsRenderingContextOS2::FillRect( nscoord aX, nscoord aY, nscoord aWidth
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextOS2 :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextOS2::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextOS2 :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextOS2::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRenderingContextOS2::PMDrawRect( nsRect &rect, BOOL fill)
|
||||
{
|
||||
mTMatrix.TransformCoord( &rect.x, &rect.y, &rect.width, &rect.height);
|
||||
|
|
|
@ -112,6 +112,9 @@ class nsRenderingContextOS2 : public nsIRenderingContext,
|
|||
NS_IMETHOD FillRect( const nsRect& aRect);
|
||||
NS_IMETHOD FillRect( nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon( const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon( const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -996,6 +996,21 @@ NS_IMETHODIMP nsRenderingContextPh :: FillRect(nscoord aX, nscoord aY, nscoord a
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextPh :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextPh::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextPh :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextPh::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextPh :: DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
|
|
|
@ -106,9 +106,13 @@ public:
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -724,6 +724,22 @@ nsRenderingContextPS :: FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextPS::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextPS :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsRenderingContextPS::InvertRect");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** ---------------------------------------------------
|
||||
* See documentation in nsIRenderingContext.h
|
||||
* @update 12/21/98 dwc
|
||||
|
|
|
@ -104,9 +104,13 @@ public:
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -1202,6 +1202,35 @@ NS_IMETHODIMP nsRenderingContextWin :: FillRect(nscoord aX, nscoord aY, nscoord
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextWin :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
RECT nr;
|
||||
nsRect tr;
|
||||
|
||||
tr = aRect;
|
||||
mTMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
|
||||
ConditionRect(tr, nr);
|
||||
::InvertRect(mDC, &nr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextWin :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
RECT nr;
|
||||
nsRect tr;
|
||||
|
||||
mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight);
|
||||
nr.left = aX;
|
||||
nr.top = aY;
|
||||
nr.right = aX+aWidth;
|
||||
nr.bottom = aY+aHeight;
|
||||
|
||||
::InvertRect(mDC, &nr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRenderingContextWin :: DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
// First transform nsPoint's into POINT's; perform coordinate space
|
||||
|
|
|
@ -102,9 +102,13 @@ public:
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -826,6 +826,49 @@ nsRenderingContextXlib::FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextXlib :: InvertRect(const nsRect& aRect)
|
||||
{
|
||||
return InvertRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextXlib :: InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
||||
{
|
||||
if (nsnull == mTMatrix || nsnull == mRenderingSurface)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nscoord x,y,w,h;
|
||||
|
||||
x = aX;
|
||||
y = aY;
|
||||
w = aWidth;
|
||||
h = aHeight;
|
||||
|
||||
mTMatrix->TransformCoord(&x,&y,&w,&h);
|
||||
|
||||
// Set XOR drawing mode
|
||||
::XSetFunction(mDisplay,
|
||||
mRenderingSurface->GetGC(),
|
||||
GXxor);
|
||||
|
||||
::XFillRectangle(mDisplay,
|
||||
mRenderingSurface->GetDrawable(),
|
||||
mRenderingSurface->GetGC(),
|
||||
x,
|
||||
y,
|
||||
w,
|
||||
h);
|
||||
|
||||
// Back to normal copy drawing mode
|
||||
// Set XOR drawing mode
|
||||
::XSetFunction(mDisplay,
|
||||
mRenderingSurface->GetGC(),
|
||||
GXcopy);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRenderingContextXlib::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints)
|
||||
{
|
||||
|
|
|
@ -101,9 +101,13 @@ class nsRenderingContextXlib : public nsIRenderingContext,
|
|||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD InvertRect(const nsRect& aRect);
|
||||
NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
|
|
|
@ -864,8 +864,20 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext,
|
|||
switch (aDetails->mType)
|
||||
{
|
||||
case SELECTION_NORMAL:{
|
||||
//
|
||||
// XOR InvertRect is currently implemented only in the unix and windows
|
||||
// rendering contexts. When other platforms implement InvertRect(), they
|
||||
// can be added here. Eventually this #ifdef should die.
|
||||
//
|
||||
// For platforms that dont implement InvertRect(), the selection will be
|
||||
// a non-filled rectangle.
|
||||
#if defined(XP_PC) || defined(XP_UNIX)
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);
|
||||
#else
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);
|
||||
#endif
|
||||
}break;
|
||||
case SELECTION_SPELLCHECK:{
|
||||
aTextStyle.mNormalFont->GetUnderline(offset, size);
|
||||
|
|
|
@ -864,8 +864,20 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext,
|
|||
switch (aDetails->mType)
|
||||
{
|
||||
case SELECTION_NORMAL:{
|
||||
//
|
||||
// XOR InvertRect is currently implemented only in the unix and windows
|
||||
// rendering contexts. When other platforms implement InvertRect(), they
|
||||
// can be added here. Eventually this #ifdef should die.
|
||||
//
|
||||
// For platforms that dont implement InvertRect(), the selection will be
|
||||
// a non-filled rectangle.
|
||||
#if defined(XP_PC) || defined(XP_UNIX)
|
||||
aRenderingContext.SetColor(NS_RGB(255,255,255));
|
||||
aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height);
|
||||
#else
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height);
|
||||
#endif
|
||||
}break;
|
||||
case SELECTION_SPELLCHECK:{
|
||||
aTextStyle.mNormalFont->GetUnderline(offset, size);
|
||||
|
|
Загрузка…
Ссылка в новой задаче