2001-09-25 00:48:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-05-11 21:11:38 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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/
|
2001-05-11 21:11:38 +00:00
|
|
|
*
|
2001-09-25 00:48:50 +00:00
|
|
|
* 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.
|
2001-05-11 21:11:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 00:48:50 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-05-11 21:11:38 +00:00
|
|
|
*
|
2001-09-25 00:48:50 +00:00
|
|
|
* Contributor(s):
|
2004-04-17 21:52:36 +00:00
|
|
|
* Author: Aaron Leventhal (aaronl@netscape.com)
|
2001-09-25 00:48:50 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* 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"),
|
2001-09-25 00:48:50 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 00:48:50 +00:00
|
|
|
* 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
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 00:48:50 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-05-11 21:11:38 +00:00
|
|
|
|
2003-04-22 07:38:18 +00:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsHTMLImageAccessible.h"
|
2003-04-22 07:38:18 +00:00
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDocument.h"
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsIHTMLDocument.h"
|
2003-04-22 07:38:18 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2003-04-15 08:45:55 +00:00
|
|
|
#include "nsIPresShell.h"
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
|
|
|
// --- image -----
|
|
|
|
|
2001-09-25 22:32:32 +00:00
|
|
|
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
|
2001-06-30 00:25:09 +00:00
|
|
|
nsLinkableAccessible(aDOMNode, aShell)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));
|
2003-04-15 08:45:55 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
|
2001-10-12 21:05:31 +00:00
|
|
|
if (!shell)
|
|
|
|
return;
|
2001-06-30 00:25:09 +00:00
|
|
|
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2001-05-11 21:11:38 +00:00
|
|
|
nsAutoString mapElementName;
|
|
|
|
|
|
|
|
if (doc && element) {
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
|
|
|
|
element->GetAttribute(NS_LITERAL_STRING("usemap"),mapElementName);
|
|
|
|
if (htmlDoc && !mapElementName.IsEmpty()) {
|
|
|
|
if (mapElementName.CharAt(0) == '#')
|
|
|
|
mapElementName.Cut(0,1);
|
2004-02-03 23:23:10 +00:00
|
|
|
mMapElement = htmlDoc->GetImageMap(mapElementName);
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-31 08:09:39 +00:00
|
|
|
NS_IMETHODIMP nsHTMLImageAccessible::GetState(PRUint32 *_retval)
|
2001-08-14 00:18:04 +00:00
|
|
|
{
|
|
|
|
// The state is a bitfield, get our inherited state, then logically OR it with STATE_ANIMATED if this
|
|
|
|
// is an animated image.
|
|
|
|
|
2003-07-31 08:09:39 +00:00
|
|
|
nsLinkableAccessible::GetState(_retval);
|
2001-08-14 02:27:30 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(mDOMNode));
|
2001-08-14 00:18:04 +00:00
|
|
|
nsCOMPtr<imgIRequest> imageRequest;
|
2003-03-19 03:47:09 +00:00
|
|
|
|
|
|
|
if (content)
|
|
|
|
content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imageRequest));
|
2001-08-14 00:18:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
|
|
|
if (imageRequest)
|
|
|
|
imageRequest->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
|
|
|
|
if (imgContainer) {
|
|
|
|
PRUint32 numFrames;
|
|
|
|
imgContainer->GetNumFrames(&numFrames);
|
|
|
|
if (numFrames > 1)
|
|
|
|
*_retval |= STATE_ANIMATED;
|
|
|
|
}
|
2001-08-14 02:27:30 +00:00
|
|
|
|
2001-08-14 00:18:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-31 08:09:39 +00:00
|
|
|
/* wstring getName (); */
|
|
|
|
NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& _retval)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2001-06-30 00:25:09 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mDOMNode));
|
2001-05-11 21:11:38 +00:00
|
|
|
if (imageContent) {
|
2001-06-30 00:25:09 +00:00
|
|
|
nsAutoString name;
|
|
|
|
rv = AppendFlatStringFromContentNode(imageContent, &name);
|
2001-05-11 21:11:38 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-03-23 21:52:27 +00:00
|
|
|
// Temp var needed until CompressWhitespace built for nsAString
|
2001-06-30 00:25:09 +00:00
|
|
|
name.CompressWhitespace();
|
|
|
|
_retval.Assign(name);
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-30 00:25:09 +00:00
|
|
|
return rv;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2003-07-31 08:09:39 +00:00
|
|
|
/* wstring getRole (); */
|
|
|
|
NS_IMETHODIMP nsHTMLImageAccessible::GetRole(PRUint32 *_retval)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
|
|
|
*_retval = ROLE_GRAPHIC;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-04 22:01:36 +00:00
|
|
|
already_AddRefed<nsIAccessible> nsHTMLImageAccessible::CreateAreaAccessible(PRInt32 areaNum)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
|
|
|
if (!mMapElement)
|
|
|
|
return nsnull;
|
|
|
|
|
2002-07-02 05:37:35 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
|
|
|
|
mMapElement->GetAreas(getter_AddRefs(mapAreas));
|
2001-05-11 21:11:38 +00:00
|
|
|
if (!mapAreas)
|
|
|
|
return nsnull;
|
|
|
|
|
2002-07-02 05:37:35 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> domNode;
|
|
|
|
mapAreas->Item(areaNum,getter_AddRefs(domNode));
|
2001-05-11 21:11:38 +00:00
|
|
|
if (!domNode)
|
|
|
|
return nsnull;
|
|
|
|
|
2001-06-30 00:25:09 +00:00
|
|
|
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
|
|
|
|
if (!accService)
|
|
|
|
return nsnull;
|
2001-05-11 21:11:38 +00:00
|
|
|
if (accService) {
|
|
|
|
nsIAccessible* acc = nsnull;
|
2003-04-15 08:45:55 +00:00
|
|
|
accService->GetCachedAccessible(domNode, mWeakShell, &acc);
|
|
|
|
if (!acc) {
|
|
|
|
accService->CreateHTMLAreaAccessible(mWeakShell, domNode, this, &acc);
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-04 22:01:36 +00:00
|
|
|
void nsHTMLImageAccessible::CacheChildren(PRBool aWalkAnonContent)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2004-06-04 22:01:36 +00:00
|
|
|
if (!mWeakShell) {
|
|
|
|
// This node has been shut down
|
|
|
|
mAccChildCount = -1;
|
|
|
|
return;
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
|
2004-06-04 22:01:36 +00:00
|
|
|
if (mAccChildCount != eChildCountUninitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
|
2004-06-04 22:01:36 +00:00
|
|
|
mAccChildCount = 0;
|
|
|
|
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
|
2001-05-11 21:11:38 +00:00
|
|
|
if (mMapElement) {
|
2003-04-15 08:45:55 +00:00
|
|
|
mMapElement->GetAreas(getter_AddRefs(mapAreas));
|
2004-06-04 22:01:36 +00:00
|
|
|
}
|
|
|
|
if (!mapAreas) {
|
|
|
|
return;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2004-06-04 22:01:36 +00:00
|
|
|
PRUint32 numMapAreas;
|
|
|
|
mapAreas->GetLength(&numMapAreas);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> areaAccessible;
|
|
|
|
nsCOMPtr<nsPIAccessible> privatePrevAccessible;
|
|
|
|
while (mAccChildCount < numMapAreas &&
|
|
|
|
(areaAccessible = CreateAreaAccessible(mAccChildCount)) != nsnull) {
|
|
|
|
if (privatePrevAccessible) {
|
|
|
|
privatePrevAccessible->SetNextSibling(areaAccessible);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetFirstChild(areaAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
++mAccChildCount;
|
|
|
|
|
|
|
|
privatePrevAccessible = do_QueryInterface(areaAccessible);
|
|
|
|
NS_ASSERTION(privatePrevAccessible, "nsIAccessible impl's should always support nsPIAccessible as well");
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2004-06-04 22:01:36 +00:00
|
|
|
|