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
|
|
|
|
|
|
|
#include "nsHTMLImageAccessible.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
|
|
|
|
#include "nsAccUtils.h"
|
2012-01-12 03:07:35 +00:00
|
|
|
#include "Role.h"
|
2012-04-11 06:16:00 +00:00
|
|
|
#include "AccIterator.h"
|
2012-01-12 03:07:35 +00:00
|
|
|
#include "States.h"
|
2007-07-16 12:42:36 +00:00
|
|
|
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
2012-04-11 06:16:00 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2003-04-22 07:38:18 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
2008-03-06 03:33:33 +00:00
|
|
|
#include "nsILink.h"
|
2003-04-15 08:45:55 +00:00
|
|
|
#include "nsIPresShell.h"
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2006-07-31 05:21:46 +00:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2001-05-11 21:11:38 +00:00
|
|
|
|
2011-07-27 12:43:01 +00:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-03-06 03:33:33 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLImageAccessible
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-06 03:33:33 +00:00
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
nsHTMLImageAccessible::
|
2012-02-07 22:38:54 +00:00
|
|
|
nsHTMLImageAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
|
|
|
|
nsLinkableAccessible(aContent, aDoc)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-06 03:33:33 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLImageAccessible, nsAccessible,
|
|
|
|
nsIAccessibleImage)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-04-06 00:41:28 +00:00
|
|
|
// nsAccessible public
|
2007-02-12 07:04:58 +00:00
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64
|
|
|
|
nsHTMLImageAccessible::NativeState()
|
2001-08-14 00:18:04 +00:00
|
|
|
{
|
2007-03-15 14:18:33 +00:00
|
|
|
// The state is a bitfield, get our inherited state, then logically OR it with
|
2011-04-09 23:38:06 +00:00
|
|
|
// states::ANIMATED if this is an animated image.
|
2001-08-14 00:18:04 +00:00
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64 state = nsLinkableAccessible::NativeState();
|
2001-08-14 02:27:30 +00:00
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(mContent));
|
2001-08-14 00:18:04 +00:00
|
|
|
nsCOMPtr<imgIRequest> imageRequest;
|
2003-03-19 03:47:09 +00:00
|
|
|
|
2007-04-02 15:56:24 +00:00
|
|
|
if (content)
|
2003-03-19 03:47:09 +00:00
|
|
|
content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imageRequest));
|
2007-04-02 15:56:24 +00:00
|
|
|
|
2001-08-14 00:18:04 +00:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2007-04-02 15:56:24 +00:00
|
|
|
if (imageRequest)
|
2001-08-14 00:18:04 +00:00
|
|
|
imageRequest->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
|
|
|
|
if (imgContainer) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool animated;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
imgContainer->GetAnimated(&animated);
|
|
|
|
if (animated)
|
2011-04-09 23:38:06 +00:00
|
|
|
state |= states::ANIMATED;
|
2001-08-14 00:18:04 +00:00
|
|
|
}
|
2001-08-14 02:27:30 +00:00
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
return state;
|
2001-08-14 00:18:04 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 08:58:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLImageAccessible::GetNameInternal(nsAString& aName)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasAltAttrib =
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName);
|
2008-10-13 08:58:58 +00:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
2008-10-10 12:26:55 +00:00
|
|
|
|
2008-10-14 08:27:02 +00:00
|
|
|
nsresult rv = nsAccessible::GetNameInternal(aName);
|
2008-10-13 08:58:58 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-12-16 16:13:49 +00:00
|
|
|
if (aName.IsEmpty() && hasAltAttrib) {
|
|
|
|
// No accessible name but empty 'alt' attribute is present. If further name
|
|
|
|
// computation algorithm doesn't provide non empty name then it means
|
|
|
|
// an empty 'alt' attribute was used to indicate a decorative image (see
|
|
|
|
// nsIAccessible::name attribute for details).
|
|
|
|
return NS_OK_EMPTY_NAME;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
2008-10-13 08:58:58 +00:00
|
|
|
|
2005-03-20 14:25:03 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2010-09-05 02:14:01 +00:00
|
|
|
nsHTMLImageAccessible::NativeRole()
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::GRAPHIC;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessible
|
2004-06-04 22:01:36 +00:00
|
|
|
|
2011-06-05 19:35:43 +00:00
|
|
|
PRUint8
|
|
|
|
nsHTMLImageAccessible::ActionCount()
|
2008-08-26 07:39:17 +00:00
|
|
|
{
|
2011-06-05 19:35:43 +00:00
|
|
|
PRUint8 actionCount = nsLinkableAccessible::ActionCount();
|
|
|
|
return HasLongDesc() ? actionCount + 1 : actionCount;
|
2008-08-26 07:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-04-11 06:16:00 +00:00
|
|
|
if (IsLongDescIndex(aIndex) && HasLongDesc()) {
|
2008-08-26 07:39:17 +00:00
|
|
|
aName.AssignLiteral("showlongdesc");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsLinkableAccessible::GetActionName(aIndex, aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::DoAction(PRUint8 aIndex)
|
2006-07-31 05:21:46 +00:00
|
|
|
{
|
2008-08-26 07:39:17 +00:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-04-11 06:16:00 +00:00
|
|
|
// Get the long description uri and open in a new window.
|
|
|
|
if (!IsLongDescIndex(aIndex))
|
|
|
|
return nsLinkableAccessible::DoAction(aIndex);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = GetLongDescURI();
|
|
|
|
if (!uri)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCAutoString utf8spec;
|
|
|
|
uri->GetSpec(utf8spec);
|
|
|
|
NS_ConvertUTF8toUTF16 spec(utf8spec);
|
|
|
|
|
|
|
|
nsIDocument* document = mContent->OwnerDoc();
|
|
|
|
nsCOMPtr<nsPIDOMWindow> piWindow = document->GetWindow();
|
|
|
|
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(piWindow);
|
|
|
|
NS_ENSURE_STATE(win);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> tmp;
|
|
|
|
return win->Open(spec, EmptyString(), EmptyString(),
|
|
|
|
getter_AddRefs(tmp));
|
|
|
|
|
2006-07-31 05:21:46 +00:00
|
|
|
}
|
|
|
|
|
2008-03-06 03:33:33 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessibleImage
|
|
|
|
|
2007-12-01 17:30:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::GetImagePosition(PRUint32 aCoordType,
|
|
|
|
PRInt32 *aX, PRInt32 *aY)
|
|
|
|
{
|
|
|
|
PRInt32 width, height;
|
|
|
|
nsresult rv = GetBounds(aX, aY, &width, &height);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return nsAccUtils::ConvertScreenCoordsTo(aX, aY, aCoordType, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::GetImageSize(PRInt32 *aWidth, PRInt32 *aHeight)
|
2007-02-12 07:04:58 +00:00
|
|
|
{
|
2007-12-01 17:30:09 +00:00
|
|
|
PRInt32 x, y;
|
|
|
|
return GetBounds(&x, &y, aWidth, aHeight);
|
2007-02-12 07:04:58 +00:00
|
|
|
}
|
2007-07-16 12:42:36 +00:00
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
// nsAccessible
|
2008-04-23 06:03:02 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLImageAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv = nsLinkableAccessible::GetAttributesInternal(aAttributes);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString src;
|
2011-06-03 21:35:17 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src);
|
2008-04-23 06:03:02 +00:00
|
|
|
if (!src.IsEmpty())
|
2011-06-03 21:35:17 +00:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::src, src);
|
2008-04-23 06:03:02 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-26 07:39:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private methods
|
|
|
|
|
2012-04-11 06:16:00 +00:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLImageAccessible::GetLongDescURI() const
|
2008-08-26 07:39:17 +00:00
|
|
|
{
|
2012-04-11 06:16:00 +00:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::longdesc)) {
|
|
|
|
nsGenericHTMLElement* element =
|
|
|
|
nsGenericHTMLElement::FromContent(mContent);
|
|
|
|
if (element) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
element->GetURIAttr(nsGkAtoms::longdesc, nsnull, getter_AddRefs(uri));
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDocAccessible* document = Document();
|
|
|
|
if (document) {
|
|
|
|
IDRefsIterator iter(document, mContent, nsGkAtoms::aria_describedby);
|
2012-04-14 15:52:34 +00:00
|
|
|
nsIContent* target = nsnull;
|
|
|
|
while (target = iter.NextElem()) {
|
2012-04-11 06:16:00 +00:00
|
|
|
if ((target->IsHTML(nsGkAtoms::a) || target->IsHTML(nsGkAtoms::area)) &&
|
|
|
|
target->HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
|
|
|
nsGenericHTMLElement* element =
|
|
|
|
nsGenericHTMLElement::FromContent(target);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
element->GetURIAttr(nsGkAtoms::href, nsnull, getter_AddRefs(uri));
|
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-26 07:39:17 +00:00
|
|
|
|
2012-04-11 06:16:00 +00:00
|
|
|
return nsnull;
|
2008-08-26 07:39:17 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-04-11 06:16:00 +00:00
|
|
|
nsHTMLImageAccessible::IsLongDescIndex(PRUint8 aIndex)
|
2008-08-26 07:39:17 +00:00
|
|
|
{
|
2011-06-05 19:35:43 +00:00
|
|
|
return aIndex == nsLinkableAccessible::ActionCount();
|
2008-08-26 07:39:17 +00:00
|
|
|
}
|
2012-04-11 06:16:00 +00:00
|
|
|
|