1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* Author: Aaron Leventhal (aaronl@netscape.com)
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the NPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the NPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
40
#include "imgIContainer.h"
41
#include "imgIRequest.h"
42
#include "nsHTMLImageAccessible.h"
43
#include "nsIAccessibilityService.h"
44
#include "nsIDOMHTMLCollection.h"
45
#include "nsIDocument.h"
46
#include "nsIHTMLDocument.h"
47
#include "nsIImageLoadingContent.h"
48
#include "nsIPresShell.h"
49
#include "nsIServiceManager.h"
53
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
54
nsLinkableAccessible(aDOMNode, aShell)
56
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));
57
nsCOMPtr<nsIDocument> doc;
58
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
62
shell->GetDocument(getter_AddRefs(doc));
63
nsAutoString mapElementName;
66
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
67
element->GetAttribute(NS_LITERAL_STRING("usemap"),mapElementName);
68
if (htmlDoc && !mapElementName.IsEmpty()) {
69
if (mapElementName.CharAt(0) == '#')
70
mapElementName.Cut(0,1);
71
mMapElement = htmlDoc->GetImageMap(mapElementName);
76
NS_IMETHODIMP nsHTMLImageAccessible::GetState(PRUint32 *_retval)
78
// The state is a bitfield, get our inherited state, then logically OR it with STATE_ANIMATED if this
79
// is an animated image.
81
nsLinkableAccessible::GetState(_retval);
83
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(mDOMNode));
84
nsCOMPtr<imgIRequest> imageRequest;
87
content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
88
getter_AddRefs(imageRequest));
90
nsCOMPtr<imgIContainer> imgContainer;
92
imageRequest->GetImage(getter_AddRefs(imgContainer));
96
imgContainer->GetNumFrames(&numFrames);
98
*_retval |= STATE_ANIMATED;
105
/* wstring getName (); */
106
NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& _retval)
108
nsresult rv = NS_ERROR_FAILURE;
110
nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mDOMNode));
113
rv = AppendFlatStringFromContentNode(imageContent, &name);
114
if (NS_SUCCEEDED(rv)) {
115
// Temp var needed until CompressWhitespace built for nsAString
116
name.CompressWhitespace();
117
_retval.Assign(name);
123
/* wstring getRole (); */
124
NS_IMETHODIMP nsHTMLImageAccessible::GetRole(PRUint32 *_retval)
126
*_retval = ROLE_GRAPHIC;
131
nsIAccessible *nsHTMLImageAccessible::CreateAreaAccessible(PRInt32 areaNum)
138
GetChildCount(&numAreaMaps);
141
areaNum = NS_STATIC_CAST(PRUint32,numAreaMaps-1);
144
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
145
mMapElement->GetAreas(getter_AddRefs(mapAreas));
149
nsCOMPtr<nsIDOMNode> domNode;
150
mapAreas->Item(areaNum,getter_AddRefs(domNode));
154
nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
158
nsIAccessible* acc = nsnull;
159
accService->GetCachedAccessible(domNode, mWeakShell, &acc);
161
accService->CreateHTMLAreaAccessible(mWeakShell, domNode, this, &acc);
169
/* nsIAccessible getFirstChild (); */
170
NS_IMETHODIMP nsHTMLImageAccessible::GetFirstChild(nsIAccessible **_retval)
172
*_retval = CreateAreaAccessible(0);
177
/* nsIAccessible getLastChild (); */
178
NS_IMETHODIMP nsHTMLImageAccessible::GetLastChild(nsIAccessible **_retval)
180
*_retval = CreateAreaAccessible(-1);
185
/* long getAccChildCount (); */
186
NS_IMETHODIMP nsHTMLImageAccessible::GetChildCount(PRInt32 *_retval)
190
nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
191
mMapElement->GetAreas(getter_AddRefs(mapAreas));
194
mapAreas->GetLength(&length);
195
*_retval = NS_STATIC_CAST(PRInt32, length);