180551 - Add color, thickness, and invert to the flasher interface. They should not be passed around so often to its methods since they rarely change and really

belong on the interface to begin with.
r=timeless,sr=peterv


git-svn-id: svn://10.0.0.236/trunk@134416 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
caillon%returnzero.com 2002-11-25 23:24:30 +00:00
parent 58385b1d1d
commit be4452b730
4 changed files with 113 additions and 46 deletions

View File

@ -46,7 +46,11 @@ interface nsIDOMWindowInternal;
[scriptable, uuid(7B4A099F-6F6E-4565-977B-FB622ADBFF49)]
interface inIFlasher : nsISupports
{
void drawElementOutline(in nsIDOMElement aElement, in wstring aColor, in long aThickness, in boolean aInvert);
attribute DOMString color;
attribute boolean invert;
attribute unsigned short thickness;
void drawElementOutline(in nsIDOMElement aElement);
void repaintElement(in nsIDOMElement aElement);
void scrollElementIntoView(in nsIDOMElement aElement);
};

View File

@ -47,11 +47,16 @@
#include "nsIPresShell.h"
#include "nsIFrame.h"
#include "prprf.h"
static NS_DEFINE_CID(kInspectorCSSUtilsCID, NS_INSPECTORCSSUTILS_CID);
///////////////////////////////////////////////////////////////////////////////
inFlasher::inFlasher()
inFlasher::inFlasher() :
mColor(NS_RGB(0,0,0)),
mThickness(0),
mInvert(PR_FALSE)
{
NS_INIT_ISUPPORTS();
mCSSUtils = do_GetService(kInspectorCSSUtilsCID);
@ -66,7 +71,72 @@ NS_IMPL_ISUPPORTS1(inFlasher, inIFlasher);
///////////////////////////////////////////////////////////////////////////////
// inIFlasher
NS_IMETHODIMP
NS_IMETHODIMP
inFlasher::GetColor(nsAString& aColor)
{
// Copied from nsGenericHTMLElement::ColorToString()
char buf[10];
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
NS_GET_R(mColor), NS_GET_G(mColor), NS_GET_B(mColor));
aColor.Assign(NS_ConvertASCIItoUCS2(buf));
return NS_OK;
}
NS_IMETHODIMP
inFlasher::SetColor(const nsAString& aColor)
{
NS_ENSURE_FALSE(aColor.IsEmpty(), NS_ERROR_ILLEGAL_VALUE);
nsAutoString colorStr;
colorStr.Assign(aColor);
if (colorStr.CharAt(0) != '#') {
if (NS_ColorNameToRGB(colorStr, &mColor)) {
return NS_OK;
}
}
else {
colorStr.Cut(0, 1);
if (NS_HexToRGB(colorStr, &mColor)) {
return NS_OK;
}
}
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IMETHODIMP
inFlasher::GetThickness(PRUint16 *aThickness)
{
NS_PRECONDITION(aThickness, "Null pointer");
*aThickness = mThickness;
return NS_OK;
}
NS_IMETHODIMP
inFlasher::SetThickness(PRUint16 aThickness)
{
mThickness = aThickness;
return NS_OK;
}
NS_IMETHODIMP
inFlasher::GetInvert(PRBool *aInvert)
{
NS_PRECONDITION(aInvert, "Null pointer");
*aInvert = mInvert;
return NS_OK;
}
NS_IMETHODIMP
inFlasher::SetInvert(PRBool aInvert)
{
mInvert = aInvert;
return NS_OK;
}
NS_IMETHODIMP
inFlasher::RepaintElement(nsIDOMElement* aElement)
{
nsCOMPtr<nsIDOMWindowInternal> window = inLayoutUtils::GetWindowFor(aElement);
@ -100,7 +170,7 @@ inFlasher::RepaintElement(nsIDOMElement* aElement)
}
NS_IMETHODIMP
inFlasher::DrawElementOutline(nsIDOMElement* aElement, const PRUnichar* aColor, PRInt32 aThickness, PRBool aInvert)
inFlasher::DrawElementOutline(nsIDOMElement* aElement)
{
nsCOMPtr<nsIDOMWindowInternal> window = inLayoutUtils::GetWindowFor(aElement);
if (!window) return NS_OK;
@ -121,18 +191,14 @@ inFlasher::DrawElementOutline(nsIDOMElement* aElement, const PRUnichar* aColor,
rect.y = origin.y;
mCSSUtils->AdjustRectForMargins(frame, rect);
nsAutoString colorStr;
colorStr.Assign(aColor);
nscolor color;
NS_HexToRGB(colorStr, &color);
float p2t;
presContext->GetPixelsToTwips(&p2t);
if (aInvert)
if (mInvert) {
rcontext->InvertRect(rect.x, rect.y, rect.width, rect.height);
}
DrawOutline(rect.x, rect.y, rect.width, rect.height, color, aThickness, p2t, rcontext);
DrawOutline(rect.x, rect.y, rect.width, rect.height, p2t, rcontext);
return NS_OK;
}
@ -164,31 +230,27 @@ inFlasher::ScrollElementIntoView(nsIDOMElement *aElement)
///////////////////////////////////////////////////////////////////////////////
// inFlasher
nsresult
void
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
nscolor aColor, PRUint32 aThickness, float aP2T,
nsIRenderingContext* aRenderContext)
float aP2T, nsIRenderingContext* aRenderContext)
{
aRenderContext->SetColor(aColor);
DrawLine(aX, aY, aWidth, aThickness, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext);
DrawLine(aX, aY, aHeight, aThickness, DIR_VERTICAL, BOUND_OUTER, aP2T, aRenderContext);
DrawLine(aX, aY+aHeight, aWidth, aThickness, DIR_HORIZONTAL, BOUND_INNER, aP2T, aRenderContext);
DrawLine(aX+aWidth, aY, aHeight, aThickness, DIR_VERTICAL, BOUND_INNER, aP2T, aRenderContext);
aRenderContext->SetColor(mColor);
return NS_OK;
DrawLine(aX, aY, aWidth, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext);
DrawLine(aX, aY, aHeight, DIR_VERTICAL, BOUND_OUTER, aP2T, aRenderContext);
DrawLine(aX, aY+aHeight, aWidth, DIR_HORIZONTAL, BOUND_INNER, aP2T, aRenderContext);
DrawLine(aX+aWidth, aY, aHeight, DIR_VERTICAL, BOUND_INNER, aP2T, aRenderContext);
}
nsresult
void
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
PRUint32 aThickness, PRBool aDir, PRBool aBounds,
float aP2T, nsIRenderingContext* aRenderContext)
PRBool aDir, PRBool aBounds, float aP2T,
nsIRenderingContext* aRenderContext)
{
nscoord thickTwips = NSIntPixelsToTwips(aThickness, aP2T);
nscoord thickTwips = NSIntPixelsToTwips(mThickness, aP2T);
if (aDir) { // horizontal
aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips);
} else { // vertical
aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength);
}
return NS_OK;
}

View File

@ -63,14 +63,18 @@ public:
virtual ~inFlasher();
protected:
nsresult DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
nscolor aColor, PRUint32 aThickness, float aP2T,
nsIRenderingContext* aRenderContext);
nsresult DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness,
PRBool aDir, PRBool aBounds, float aP2T,
nsIRenderingContext* aRenderContext);
void DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
float aP2T, nsIRenderingContext* aRenderContext);
void DrawLine(nscoord aX, nscoord aY, nscoord aLength,
PRBool aDir, PRBool aBounds, float aP2T,
nsIRenderingContext* aRenderContext);
nsCOMPtr<nsIInspectorCSSUtils> mCSSUtils;
nscolor mColor;
PRUint16 mThickness;
PRPackedBool mInvert;
};
#endif // __inFlasher_h__

View File

@ -55,12 +55,12 @@ var gFlasherRegistry = [];
function Flasher(aColor, aThickness, aDuration, aSpeed, aInvert)
{
this.mShell = XPCU.createInstance("@mozilla.org/inspector/flasher;1", "inIFlasher");
this.color = aColor;
this.mThickness = aThickness;
this.mShell = XPCU.getService("@mozilla.org/inspector/flasher;1", "inIFlasher");
this.mShell.color = aColor;
this.mShell.thickness = aThickness;
this.mShell.invert = aInvert;
this.duration = aDuration;
this.mSpeed = aSpeed;
this.mInvert = aInvert;
this.register();
}
@ -75,11 +75,8 @@ Flasher.prototype =
mRegistryId: null,
mFlashes: 0,
mStartTime: 0,
mColor: null,
mThickness: 0,
mDuration: 0,
mSpeed: 0,
mInvert: false,
////////////////////////////////////////////////////////////////////////////
//// Properties
@ -96,11 +93,11 @@ Flasher.prototype =
throw "Invalid node type.";
},
get color() { return this.mColor; },
set color(aVal) { if (aVal.charAt(0) == '#') aVal = aVal.substr(1); this.mColor = aVal; },
get color() { return this.mShell.color; },
set color(aVal) { return this.mShell.color = aVal; },
get thickness() { return this.mThickness; },
set thickness(aVal) { this.mThickness = aVal; },
get thickness() { return this.mShell.thickness; },
set thickness(aVal) { this.mShell.thickness = aVal; },
get duration() { return this.mDuration; },
set duration(aVal) { this.mDuration = aVal; },
@ -108,8 +105,8 @@ Flasher.prototype =
get speed() { return this.mSpeed; },
set speed(aVal) { this.mSpeed = aVal; },
get invert() { return this.mInvert; },
set invert(aVal) { this.mInvert = aVal; },
get invert() { return this.mShell.invert; },
set invert(aVal) { this.mShell.invert = aVal; },
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// :::::::::::::::::::: Methods ::::::::::::::::::::::::::::
@ -159,7 +156,7 @@ Flasher.prototype =
paintOn: function()
{
this.mShell.drawElementOutline(this.mElement, this.mColor, this.mThickness, this.mInvert);
this.mShell.drawElementOutline(this.mElement);
},
paintOff: function()