Adding top and left to screen object because they're not always at 0,0 and

availTop and availLeft aren't good enough for all cases.
This commit is contained in:
pinkerton%netscape.com 2000-04-20 02:00:55 +00:00
Родитель e81b66e77b
Коммит ae9fdaa5ca
3 изменённых файлов: 116 добавлений и 53 удалений

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

@ -46,14 +46,16 @@ static NS_DEFINE_IID(kIScreenIID, NS_IDOMSCREEN_IID);
// Screen property ids
//
enum Screen_slots {
SCREEN_WIDTH = -1,
SCREEN_HEIGHT = -2,
SCREEN_PIXELDEPTH = -3,
SCREEN_COLORDEPTH = -4,
SCREEN_AVAILWIDTH = -5,
SCREEN_AVAILHEIGHT = -6,
SCREEN_AVAILLEFT = -7,
SCREEN_AVAILTOP = -8
SCREEN_TOP = -1,
SCREEN_LEFT = -2,
SCREEN_WIDTH = -3,
SCREEN_HEIGHT = -4,
SCREEN_PIXELDEPTH = -5,
SCREEN_COLORDEPTH = -6,
SCREEN_AVAILWIDTH = -7,
SCREEN_AVAILHEIGHT = -8,
SCREEN_AVAILLEFT = -9,
SCREEN_AVAILTOP = -10
};
/***********************************************************************/
@ -76,6 +78,30 @@ GetScreenProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (!secMan)
return PR_FALSE;
switch(JSVAL_TO_INT(id)) {
case SCREEN_TOP:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_SCREEN_TOP, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
PRInt32 prop;
rv = a->GetTop(&prop);
if (NS_SUCCEEDED(rv)) {
*vp = INT_TO_JSVAL(prop);
}
}
break;
}
case SCREEN_LEFT:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_SCREEN_LEFT, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
PRInt32 prop;
rv = a->GetLeft(&prop);
if (NS_SUCCEEDED(rv)) {
*vp = INT_TO_JSVAL(prop);
}
}
break;
}
case SCREEN_WIDTH:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_SCREEN_WIDTH, PR_FALSE);
@ -275,6 +301,8 @@ JSClass ScreenClass = {
//
static JSPropertySpec ScreenProperties[] =
{
{"top", SCREEN_TOP, JSPROP_ENUMERATE | JSPROP_READONLY},
{"left", SCREEN_LEFT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"width", SCREEN_WIDTH, JSPROP_ENUMERATE | JSPROP_READONLY},
{"height", SCREEN_HEIGHT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"pixelDepth", SCREEN_PIXELDEPTH, JSPROP_ENUMERATE | JSPROP_READONLY},

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

@ -83,10 +83,53 @@ ScreenImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
return res;
}
NS_IMETHODIMP
ScreenImpl::GetTop(PRInt32* aTop)
{
/*
*** for now...
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext() );
if ( context )
{
PRInt32 left;
context->GetDeviceTopLeft( *aTop, left );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aTop = NSToIntRound(float(*aTop) / devUnits );
return NS_OK;
}
*/
*aTop = -1;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
ScreenImpl::GetLeft(PRInt32* aLeft)
{
/*
*** for now...
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext() );
if ( context )
{
PRInt32 top;
context->GetDeficeTopLeft( top, *aLeft );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aLeft = NSToIntRound(float(*aLeft) / devUnits );
return NS_OK;
}
*/
*aLeft = -1;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
ScreenImpl::GetWidth(PRInt32* aWidth)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
PRInt32 height;
@ -94,7 +137,6 @@ ScreenImpl::GetWidth(PRInt32* aWidth)
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aWidth = NSToIntRound(float( *aWidth) / devUnits );
NS_RELEASE( context );
return NS_OK;
}
@ -105,7 +147,7 @@ ScreenImpl::GetWidth(PRInt32* aWidth)
NS_IMETHODIMP
ScreenImpl::GetHeight(PRInt32* aHeight)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
PRInt32 width;
@ -113,7 +155,6 @@ ScreenImpl::GetHeight(PRInt32* aHeight)
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aHeight = NSToIntRound(float( *aHeight) / devUnits );
NS_RELEASE( context );
return NS_OK;
}
@ -124,13 +165,12 @@ ScreenImpl::GetHeight(PRInt32* aHeight)
NS_IMETHODIMP
ScreenImpl::GetPixelDepth(PRInt32* aPixelDepth)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
PRUint32 depth;
context->GetDepth( depth );
*aPixelDepth = depth;
NS_RELEASE( context );
return NS_OK;
}
//XXX not implmented
@ -141,13 +181,12 @@ ScreenImpl::GetPixelDepth(PRInt32* aPixelDepth)
NS_IMETHODIMP
ScreenImpl::GetColorDepth(PRInt32* aColorDepth)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
PRUint32 depth;
context->GetDepth( depth );
*aColorDepth = depth;
NS_RELEASE( context );
return NS_OK;
}
@ -158,19 +197,16 @@ ScreenImpl::GetColorDepth(PRInt32* aColorDepth)
NS_IMETHODIMP
ScreenImpl::GetAvailWidth(PRInt32* aAvailWidth)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailWidth = NSToIntRound(float( rect.width) / devUnits );
NS_RELEASE( context );
return NS_OK;
}
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailWidth = NSToIntRound(float( rect.width) / devUnits );
return NS_OK;
}
*aAvailWidth = -1;
return NS_ERROR_FAILURE;
@ -180,17 +216,16 @@ ScreenImpl::GetAvailWidth(PRInt32* aAvailWidth)
NS_IMETHODIMP
ScreenImpl::GetAvailHeight(PRInt32* aAvailHeight)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailHeight = NSToIntRound(float( rect.height) / devUnits );
NS_RELEASE( context );
return NS_OK;
}
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailHeight = NSToIntRound(float( rect.height) / devUnits );
return NS_OK;
}
*aAvailHeight = -1;
return NS_ERROR_FAILURE;
@ -200,16 +235,15 @@ ScreenImpl::GetAvailHeight(PRInt32* aAvailHeight)
NS_IMETHODIMP
ScreenImpl::GetAvailLeft(PRInt32* aAvailLeft)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailLeft = NSToIntRound(float( rect.x) / devUnits );
NS_RELEASE( context );
return NS_OK;
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailLeft = NSToIntRound(float( rect.x) / devUnits );
return NS_OK;
}
*aAvailLeft = -1;
@ -219,17 +253,16 @@ ScreenImpl::GetAvailLeft(PRInt32* aAvailLeft)
NS_IMETHODIMP
ScreenImpl::GetAvailTop(PRInt32* aAvailTop)
{
nsIDeviceContext* context = GetDeviceContext();
nsCOMPtr<nsIDeviceContext> context ( getter_AddRefs(GetDeviceContext()) );
if ( context )
{
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailTop = NSToIntRound(float( rect.y) / devUnits );
NS_RELEASE( context );
return NS_OK;
}
nsRect rect;
context->GetClientRect( rect );
float devUnits;
context->GetDevUnitsToAppUnits(devUnits);
*aAvailTop = NSToIntRound(float( rect.y) / devUnits );
return NS_OK;
}
*aAvailTop = -1;
return NS_ERROR_FAILURE;

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

@ -44,6 +44,8 @@ public:
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD GetTop(PRInt32* aWidth);
NS_IMETHOD GetLeft(PRInt32* aWidth);
NS_IMETHOD GetWidth(PRInt32* aWidth);
NS_IMETHOD GetHeight(PRInt32* aHeight);
NS_IMETHOD GetPixelDepth(PRInt32* aPixelDepth);