2010-04-06 00:41:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Aaron Leventhal <aaronl@netscape.com> (original author)
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsHTMLImageMapAccessible.h"
|
|
|
|
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccUtils.h"
|
2010-11-12 19:00:55 +00:00
|
|
|
#include "nsDocAccessible.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
|
|
|
#include "nsIFrame.h"
|
2011-04-26 06:52:19 +00:00
|
|
|
#include "nsImageFrame.h"
|
2011-04-27 05:51:13 +00:00
|
|
|
#include "nsImageMap.h"
|
2010-04-06 00:41:28 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLImageMapAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsHTMLImageMapAccessible::
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLImageMapAccessible(nsIContent *aContent, nsIWeakReference *aShell,
|
2010-04-06 00:41:28 +00:00
|
|
|
nsIDOMHTMLMapElement *aMapElm) :
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLImageAccessibleWrap(aContent, aShell), mMapElement(aMapElm)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-04-08 06:43:08 +00:00
|
|
|
// nsHTMLImageMapAccessible: nsISupports
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2010-04-08 06:43:08 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(nsHTMLImageMapAccessible, nsHTMLImageAccessible)
|
2010-04-06 00:41:28 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-09-01 03:26:13 +00:00
|
|
|
// nsHTMLImageMapAccessible: nsAccessible public
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2010-09-05 02:14:01 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLImageMapAccessible::NativeRole()
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2010-09-05 02:14:01 +00:00
|
|
|
return nsIAccessibleRole::ROLE_IMAGE_MAP;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLImageMapAccessible: HyperLinkAccessible
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
PRUint32
|
|
|
|
nsHTMLImageMapAccessible::AnchorCount()
|
|
|
|
{
|
|
|
|
return GetChildCount();
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
nsAccessible*
|
|
|
|
nsHTMLImageMapAccessible::GetAnchor(PRUint32 aAnchorIndex)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2010-09-01 03:26:13 +00:00
|
|
|
return GetChildAt(aAnchorIndex);
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLImageMapAccessible::GetAnchorURI(PRUint32 aAnchorIndex)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2010-09-01 03:26:13 +00:00
|
|
|
nsAccessible* area = GetChildAt(aAnchorIndex);
|
|
|
|
if (!area)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIContent* linkContent = area->GetContent();
|
|
|
|
return linkContent ? linkContent->GetHrefURI() : nsnull;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLImageMapAccessible: nsAccessible protected
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLImageMapAccessible::CacheChildren()
|
|
|
|
{
|
2010-04-08 06:43:08 +00:00
|
|
|
if (!mMapElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
|
|
|
|
mMapElement->GetAreas(getter_AddRefs(mapAreas));
|
2010-04-06 00:41:28 +00:00
|
|
|
if (!mapAreas)
|
|
|
|
return;
|
|
|
|
|
2010-11-12 19:00:55 +00:00
|
|
|
nsDocAccessible* document = GetDocAccessible();
|
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
PRUint32 areaCount = 0;
|
|
|
|
mapAreas->GetLength(&areaCount);
|
|
|
|
|
|
|
|
for (PRUint32 areaIdx = 0; areaIdx < areaCount; areaIdx++) {
|
2010-04-08 06:43:08 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> areaNode;
|
|
|
|
mapAreas->Item(areaIdx, getter_AddRefs(areaNode));
|
|
|
|
if (!areaNode)
|
2010-04-06 00:41:28 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIContent> areaContent(do_QueryInterface(areaNode));
|
2010-11-12 19:00:55 +00:00
|
|
|
nsRefPtr<nsAccessible> area =
|
2010-06-11 08:23:18 +00:00
|
|
|
new nsHTMLAreaAccessible(areaContent, mWeakShell);
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2010-11-12 19:00:55 +00:00
|
|
|
if (!document->BindToDocument(area, nsAccUtils::GetRoleMapEntry(areaContent)) ||
|
|
|
|
!AppendChild(area)) {
|
2010-04-08 06:43:08 +00:00
|
|
|
return;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLAreaAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsHTMLAreaAccessible::
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLAreaAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
|
|
|
nsHTMLLinkAccessible(aContent, aShell)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLAreaAccessible: nsIAccessible
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLAreaAccessible::GetNameInternal(nsAString & aName)
|
|
|
|
{
|
|
|
|
nsresult rv = nsAccessible::GetNameInternal(aName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
if (!mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt,
|
|
|
|
aName)) {
|
2010-04-06 00:41:28 +00:00
|
|
|
return GetValue(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-23 13:14:05 +00:00
|
|
|
void
|
|
|
|
nsHTMLAreaAccessible::Description(nsString& aDescription)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
|
|
|
aDescription.Truncate();
|
|
|
|
|
|
|
|
// Still to do - follow IE's standard here
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mContent));
|
2010-04-06 00:41:28 +00:00
|
|
|
if (area)
|
|
|
|
area->GetShape(aDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLAreaAccessible::GetBounds(PRInt32 *aX, PRInt32 *aY,
|
|
|
|
PRInt32 *aWidth, PRInt32 *aHeight)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aX);
|
|
|
|
*aX = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aY);
|
|
|
|
*aY = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
*aWidth = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
|
|
|
*aHeight = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Essentially this uses GetRect on mAreas of nsImageMap from nsImageFrame.
|
2010-04-06 00:41:28 +00:00
|
|
|
nsPresContext *presContext = GetPresContext();
|
|
|
|
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
|
2011-04-26 06:52:19 +00:00
|
|
|
nsImageFrame *imageFrame = do_QueryFrame(frame);
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2011-04-27 05:51:13 +00:00
|
|
|
nsImageMap* map = imageFrame->GetImageMap(presContext);
|
2010-04-06 00:41:28 +00:00
|
|
|
NS_ENSURE_TRUE(map, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRect rect;
|
2010-06-11 08:23:18 +00:00
|
|
|
nsresult rv = map->GetBoundsForAreaContent(mContent, rect);
|
2010-04-06 00:41:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
*aX = presContext->AppUnitsToDevPixels(rect.x);
|
|
|
|
*aY = presContext->AppUnitsToDevPixels(rect.y);
|
2010-04-06 00:41:28 +00:00
|
|
|
|
|
|
|
// XXX Areas are screwy; they return their rects as a pair of points, one pair
|
|
|
|
// stored into the width and height.
|
2010-06-11 08:23:18 +00:00
|
|
|
*aWidth = presContext->AppUnitsToDevPixels(rect.width - rect.x);
|
|
|
|
*aHeight = presContext->AppUnitsToDevPixels(rect.height - rect.y);
|
2010-04-06 00:41:28 +00:00
|
|
|
|
|
|
|
// Put coords in absolute screen coords
|
2011-04-27 05:51:13 +00:00
|
|
|
nsIntRect orgRectPixels = frame->GetScreenRectExternal();
|
2010-06-11 08:23:18 +00:00
|
|
|
*aX += orgRectPixels.x;
|
|
|
|
*aY += orgRectPixels.y;
|
2010-04-06 00:41:28 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLAreaAccessible: nsAccessible public
|
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64
|
|
|
|
nsHTMLAreaAccessible::NativeState()
|
2010-04-13 17:55:39 +00:00
|
|
|
{
|
|
|
|
// Bypass the link states specialization for non links.
|
|
|
|
if (mRoleMapEntry &&
|
|
|
|
mRoleMapEntry->role != nsIAccessibleRole::ROLE_NOTHING &&
|
|
|
|
mRoleMapEntry->role != nsIAccessibleRole::ROLE_LINK) {
|
2011-04-09 23:38:06 +00:00
|
|
|
return nsAccessible::NativeState();
|
2010-04-13 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
return nsHTMLLinkAccessible::NativeState();
|
2010-04-13 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 04:44:20 +00:00
|
|
|
nsAccessible*
|
2010-04-06 00:41:28 +00:00
|
|
|
nsHTMLAreaAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
|
2011-03-29 04:44:20 +00:00
|
|
|
EWhichChildAtPoint aWhichChild)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
|
|
|
// Don't walk into area accessibles.
|
2011-03-29 04:44:20 +00:00
|
|
|
return this;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLImageMapAccessible: HyperLinkAccessible
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsHTMLAreaAccessible::StartOffset()
|
|
|
|
{
|
|
|
|
// Image map accessible is not hypertext accessible therefore
|
|
|
|
// StartOffset/EndOffset implementations of nsAccessible doesn't work here.
|
|
|
|
// We return index in parent because image map contains area links only which
|
|
|
|
// are embedded objects.
|
|
|
|
// XXX: image map should be a hypertext accessible.
|
|
|
|
return GetIndexInParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsHTMLAreaAccessible::EndOffset()
|
|
|
|
{
|
|
|
|
return GetIndexInParent() + 1;
|
|
|
|
}
|
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLAreaAccessible: nsAccessible protected
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLAreaAccessible::CacheChildren()
|
|
|
|
{
|
|
|
|
// No children for aria accessible.
|
|
|
|
}
|