bug 822580 - clean up nsAccUtils functions for position r=surkov

This commit is contained in:
Trevor Saunders 2012-12-17 15:11:02 -05:00
parent cf75409acc
commit 6e1cfcb285
5 changed files with 36 additions and 65 deletions

View File

@ -294,15 +294,12 @@ nsAccUtils::GetTextAccessibleFromSelection(nsISelection* aSelection)
return nullptr;
}
nsresult
nsIntPoint
nsAccUtils::ConvertToScreenCoords(int32_t aX, int32_t aY,
uint32_t aCoordinateType,
nsAccessNode *aAccessNode,
nsIntPoint *aCoords)
Accessible* aAccessible)
{
NS_ENSURE_ARG_POINTER(aCoords);
aCoords->MoveTo(aX, aY);
nsIntPoint coords(aX, aY);
switch (aCoordinateType) {
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
@ -310,29 +307,27 @@ nsAccUtils::ConvertToScreenCoords(int32_t aX, int32_t aY,
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
{
NS_ENSURE_ARG(aAccessNode);
*aCoords += GetScreenCoordsForWindow(aAccessNode);
coords += nsCoreUtils::GetScreenCoordsForWindow(aAccessible->GetNode());
break;
}
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
{
NS_ENSURE_ARG(aAccessNode);
*aCoords += GetScreenCoordsForParent(aAccessNode);
coords += GetScreenCoordsForParent(aAccessible);
break;
}
default:
return NS_ERROR_INVALID_ARG;
NS_NOTREACHED("invalid coord type!");
}
return NS_OK;
return coords;
}
nsresult
void
nsAccUtils::ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
uint32_t aCoordinateType,
nsAccessNode *aAccessNode)
Accessible* aAccessible)
{
switch (aCoordinateType) {
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
@ -340,8 +335,7 @@ nsAccUtils::ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
{
NS_ENSURE_ARG(aAccessNode);
nsIntPoint coords = nsAccUtils::GetScreenCoordsForWindow(aAccessNode);
nsIntPoint coords = nsCoreUtils::GetScreenCoordsForWindow(aAccessible->GetNode());
*aX -= coords.x;
*aY -= coords.y;
break;
@ -349,31 +343,21 @@ nsAccUtils::ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
{
NS_ENSURE_ARG(aAccessNode);
nsIntPoint coords = nsAccUtils::GetScreenCoordsForParent(aAccessNode);
nsIntPoint coords = GetScreenCoordsForParent(aAccessible);
*aX -= coords.x;
*aY -= coords.y;
break;
}
default:
return NS_ERROR_INVALID_ARG;
NS_NOTREACHED("invalid coord type!");
}
return NS_OK;
}
nsIntPoint
nsAccUtils::GetScreenCoordsForWindow(nsAccessNode *aAccessNode)
nsAccUtils::GetScreenCoordsForParent(Accessible* aAccessible)
{
return nsCoreUtils::GetScreenCoordsForWindow(aAccessNode->GetNode());
}
nsIntPoint
nsAccUtils::GetScreenCoordsForParent(nsAccessNode *aAccessNode)
{
DocAccessible* document = aAccessNode->Document();
Accessible* parent = document->GetContainerAccessible(aAccessNode->GetNode());
Accessible* parent = aAccessible->Parent();
if (!parent)
return nsIntPoint(0, 0);

View File

@ -25,7 +25,6 @@ struct nsRoleMapEntry;
namespace mozilla {
namespace a11y {
class nsAccessNode;
class Accessible;
class HyperTextAccessible;
class DocAccessible;
@ -166,14 +165,13 @@ public:
* @param aY [in] the given y coord
* @param aCoordinateType [in] specifies coordinates origin (refer to
* nsIAccessibleCoordinateType)
* @param aAccessNode [in] the accessible if coordinates are given
* @param aAccessible [in] the accessible if coordinates are given
* relative it.
* @param aCoords [out] converted coordinates
* @return converted coordinates
*/
static nsresult ConvertToScreenCoords(int32_t aX, int32_t aY,
uint32_t aCoordinateType,
nsAccessNode *aAccessNode,
nsIntPoint *aCoords);
static nsIntPoint ConvertToScreenCoords(int32_t aX, int32_t aY,
uint32_t aCoordinateType,
Accessible* aAccessible);
/**
* Converts the given coordinates relative screen to another coordinate
@ -183,26 +181,19 @@ public:
* @param aY [in, out] the given y coord
* @param aCoordinateType [in] specifies coordinates origin (refer to
* nsIAccessibleCoordinateType)
* @param aAccessNode [in] the accessible if coordinates are given
* @param aAccessible [in] the accessible if coordinates are given
* relative it
*/
static nsresult ConvertScreenCoordsTo(int32_t *aX, int32_t *aY,
uint32_t aCoordinateType,
nsAccessNode *aAccessNode);
/**
* Returns coordinates relative screen for the top level window.
*
* @param aAccessNode the accessible hosted in the window
*/
static nsIntPoint GetScreenCoordsForWindow(nsAccessNode *aAccessNode);
static void ConvertScreenCoordsTo(int32_t* aX, int32_t* aY,
uint32_t aCoordinateType,
Accessible* aAccessible);
/**
* Returns coordinates relative screen for the parent of the given accessible.
*
* @param aAccessNode the accessible
* @param [in] aAccessible the accessible
*/
static nsIntPoint GetScreenCoordsForParent(nsAccessNode *aAccessNode);
static nsIntPoint GetScreenCoordsForParent(Accessible* aAccessible);
/**
* Return the role of the given accessible.

View File

@ -2164,10 +2164,8 @@ Accessible::ScrollToPoint(uint32_t aCoordinateType, int32_t aX, int32_t aY)
if (!frame)
return NS_ERROR_FAILURE;
nsIntPoint coords;
nsresult rv = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
this, &coords);
NS_ENSURE_SUCCESS(rv, rv);
nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
this);
nsIFrame *parentFrame = frame;
while ((parentFrame = parentFrame->GetParent()))

View File

@ -1217,7 +1217,8 @@ HyperTextAccessible::GetRangeExtents(int32_t aStartOffset, int32_t aEndOffset,
*aWidth = boundsRect.width;
*aHeight = boundsRect.height;
return nsAccUtils::ConvertScreenCoordsTo(aX, aY, aCoordType, this);
nsAccUtils::ConvertScreenCoordsTo(aX, aY, aCoordType, this);
return NS_OK;
}
/*
@ -1238,10 +1239,8 @@ HyperTextAccessible::GetOffsetAtPoint(int32_t aX, int32_t aY,
return NS_ERROR_FAILURE;
}
nsIntPoint coords;
nsresult rv = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordType,
this, &coords);
NS_ENSURE_SUCCESS(rv, rv);
nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordType,
this);
nsPresContext* presContext = mDoc->PresContext();
nsPoint coordsInAppUnits =
@ -1900,13 +1899,11 @@ HyperTextAccessible::ScrollSubstringToPoint(int32_t aStartIndex,
if (!frame)
return NS_ERROR_FAILURE;
nsIntPoint coords;
nsresult rv = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
this, &coords);
NS_ENSURE_SUCCESS(rv, rv);
nsIntPoint coords = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
this);
nsRefPtr<nsRange> range = new nsRange();
rv = HypertextOffsetsToDOMRange(aStartIndex, aEndIndex, range);
nsresult rv = HypertextOffsetsToDOMRange(aStartIndex, aEndIndex, range);
NS_ENSURE_SUCCESS(rv, rv);
nsPresContext* presContext = frame->PresContext();

View File

@ -158,7 +158,8 @@ ImageAccessible::GetImagePosition(uint32_t aCoordType, int32_t* aX, int32_t* aY)
if (NS_FAILED(rv))
return rv;
return nsAccUtils::ConvertScreenCoordsTo(aX, aY, aCoordType, this);
nsAccUtils::ConvertScreenCoordsTo(aX, aY, aCoordType, this);
return NS_OK;
}
NS_IMETHODIMP