Bug 698232 - s/IsInside/GetArea to simplify the code, r=mats

This commit is contained in:
Olli Pettay 2011-10-30 21:51:19 +02:00
Родитель 5795eeb8b4
Коммит ea9f2a5db4
3 изменённых файлов: 13 добавлений и 22 удалений

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

@ -1563,11 +1563,9 @@ nsImageFrame::GetContentForEvent(nsEvent* aEvent,
TranslateEventCoords(
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
bool inside = false;
nsCOMPtr<nsIContent> area;
inside = map->IsInside(p.x, p.y, getter_AddRefs(area));
if (inside && area) {
*aContent = area;
NS_ADDREF(*aContent);
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
if (area) {
area.swap(*aContent);
return NS_OK;
}
}
@ -1601,8 +1599,7 @@ nsImageFrame::HandleEvent(nsPresContext* aPresContext,
// (in case we deal with a case of both client-side and
// sever-side on the same image - it happens!)
if (nsnull != map) {
nsCOMPtr<nsIContent> area;
inside = map->IsInside(p.x, p.y, getter_AddRefs(area));
inside = !!map->GetArea(p.x, p.y);
}
if (!inside && isServerMap) {
@ -1649,8 +1646,8 @@ nsImageFrame::GetCursor(const nsPoint& aPoint,
if (nsnull != map) {
nsIntPoint p;
TranslateEventCoords(aPoint, p);
nsCOMPtr<nsIContent> area;
if (map->IsInside(p.x, p.y, getter_AddRefs(area))) {
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
if (area) {
// Use the cursor from the style of the *area* element.
// XXX Using the image as the parent style context isn't
// technically correct, but it's probably the right thing to do

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

@ -878,22 +878,19 @@ nsImageMap::AddArea(nsIContent* aArea)
return NS_OK;
}
bool
nsImageMap::IsInside(nscoord aX, nscoord aY,
nsIContent** aContent) const
nsIContent*
nsImageMap::GetArea(nscoord aX, nscoord aY) const
{
NS_ASSERTION(mMap, "Not initialized");
PRUint32 i, n = mAreas.Length();
for (i = 0; i < n; i++) {
Area* area = mAreas.ElementAt(i);
if (area->IsInside(aX, aY)) {
NS_ADDREF(*aContent = area->mArea);
return true;
return area->mArea;
}
}
return false;
return nsnull;
}
void

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

@ -61,13 +61,10 @@ public:
nsresult Init(nsImageFrame* aImageFrame, nsIContent* aMap);
/**
* See if the given aX,aY <b>pixel</b> coordinates are in the image
* map. If they are then true is returned and aContent points to the
* found area. If the coordinates are not in the map then false
* is returned.
* Return the first area element (in content order) for the given aX,aY pixel
* coordinate or nsnull if the coordinate is outside all areas.
*/
bool IsInside(nscoord aX, nscoord aY,
nsIContent** aContent) const;
nsIContent* GetArea(nscoord aX, nscoord aY) const;
void Draw(nsIFrame* aFrame, nsRenderingContext& aRC);