~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/accessible/src/html/nsHTMLImageAccessible.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 * Author: Aaron Leventhal (aaronl@netscape.com)
 
24
 *
 
25
 *
 
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.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
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"
 
50
 
 
51
// --- image -----
 
52
 
 
53
nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
 
54
nsLinkableAccessible(aDOMNode, aShell)
 
55
 
56
  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aDOMNode));
 
57
  nsCOMPtr<nsIDocument> doc;
 
58
  nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
 
59
  if (!shell)
 
60
    return;
 
61
 
 
62
  shell->GetDocument(getter_AddRefs(doc));
 
63
  nsAutoString mapElementName;
 
64
 
 
65
  if (doc && element) {
 
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);
 
72
    }
 
73
  }
 
74
}
 
75
 
 
76
NS_IMETHODIMP nsHTMLImageAccessible::GetState(PRUint32 *_retval)
 
77
{
 
78
  // The state is a bitfield, get our inherited state, then logically OR it with STATE_ANIMATED if this
 
79
  // is an animated image.
 
80
 
 
81
  nsLinkableAccessible::GetState(_retval);
 
82
 
 
83
  nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(mDOMNode));
 
84
  nsCOMPtr<imgIRequest> imageRequest;
 
85
 
 
86
  if (content) 
 
87
    content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
 
88
                        getter_AddRefs(imageRequest));
 
89
  
 
90
  nsCOMPtr<imgIContainer> imgContainer;
 
91
  if (imageRequest) 
 
92
    imageRequest->GetImage(getter_AddRefs(imgContainer));
 
93
 
 
94
  if (imgContainer) {
 
95
    PRUint32 numFrames;
 
96
    imgContainer->GetNumFrames(&numFrames);
 
97
    if (numFrames > 1)
 
98
      *_retval |= STATE_ANIMATED;
 
99
  }
 
100
 
 
101
  return NS_OK;
 
102
}
 
103
 
 
104
 
 
105
/* wstring getName (); */
 
106
NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& _retval)
 
107
{
 
108
  nsresult rv = NS_ERROR_FAILURE;
 
109
 
 
110
  nsCOMPtr<nsIContent> imageContent(do_QueryInterface(mDOMNode));
 
111
  if (imageContent) {
 
112
    nsAutoString name;
 
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);
 
118
    }
 
119
  }
 
120
  return rv;
 
121
}
 
122
 
 
123
/* wstring getRole (); */
 
124
NS_IMETHODIMP nsHTMLImageAccessible::GetRole(PRUint32 *_retval)
 
125
{
 
126
  *_retval = ROLE_GRAPHIC;
 
127
  return NS_OK;
 
128
}
 
129
 
 
130
 
 
131
nsIAccessible *nsHTMLImageAccessible::CreateAreaAccessible(PRInt32 areaNum)
 
132
{
 
133
  if (!mMapElement) 
 
134
    return nsnull;
 
135
 
 
136
   if (areaNum == -1) {
 
137
    PRInt32 numAreaMaps;
 
138
    GetChildCount(&numAreaMaps);
 
139
    if (numAreaMaps<=0)
 
140
      return nsnull;
 
141
    areaNum = NS_STATIC_CAST(PRUint32,numAreaMaps-1);
 
142
  }
 
143
 
 
144
  nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
 
145
  mMapElement->GetAreas(getter_AddRefs(mapAreas));
 
146
  if (!mapAreas) 
 
147
    return nsnull;
 
148
 
 
149
  nsCOMPtr<nsIDOMNode> domNode;
 
150
  mapAreas->Item(areaNum,getter_AddRefs(domNode));
 
151
  if (!domNode)
 
152
    return nsnull;
 
153
 
 
154
  nsCOMPtr<nsIAccessibilityService> accService(do_GetService("@mozilla.org/accessibilityService;1"));
 
155
  if (!accService)
 
156
    return nsnull;
 
157
  if (accService) {
 
158
    nsIAccessible* acc = nsnull;
 
159
    accService->GetCachedAccessible(domNode, mWeakShell, &acc);
 
160
    if (!acc) {
 
161
      accService->CreateHTMLAreaAccessible(mWeakShell, domNode, this, &acc);
 
162
    }
 
163
    return acc;
 
164
  }
 
165
  return nsnull;
 
166
}
 
167
 
 
168
 
 
169
/* nsIAccessible getFirstChild (); */
 
170
NS_IMETHODIMP nsHTMLImageAccessible::GetFirstChild(nsIAccessible **_retval)
 
171
{
 
172
  *_retval = CreateAreaAccessible(0);
 
173
  return NS_OK;
 
174
}
 
175
 
 
176
 
 
177
/* nsIAccessible getLastChild (); */
 
178
NS_IMETHODIMP nsHTMLImageAccessible::GetLastChild(nsIAccessible **_retval)
 
179
{
 
180
  *_retval = CreateAreaAccessible(-1);
 
181
  return NS_OK;
 
182
}
 
183
 
 
184
#ifdef NEVER
 
185
/* long getAccChildCount (); */
 
186
NS_IMETHODIMP nsHTMLImageAccessible::GetChildCount(PRInt32 *_retval)
 
187
{
 
188
  *_retval = 0;
 
189
  if (mMapElement) {
 
190
    nsCOMPtr<nsIDOMHTMLCollection> mapAreas;
 
191
    mMapElement->GetAreas(getter_AddRefs(mapAreas));
 
192
    if (mapAreas) {
 
193
      PRUint32 length;
 
194
      mapAreas->GetLength(&length);
 
195
      *_retval = NS_STATIC_CAST(PRInt32, length);
 
196
    }
 
197
  }
 
198
 
 
199
  return NS_OK;
 
200
}
 
201
#endif