2007-03-22 10:30:00 -07: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):
|
|
|
|
* Author: Aaron Leventhal (aaronl@netscape.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 "nsHTMLImageAccessible.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
|
|
|
#include "nsAccUtils.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2012-04-10 23:16:00 -07:00
|
|
|
#include "AccIterator.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "States.h"
|
2007-07-16 05:42:36 -07:00
|
|
|
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.h"
|
2012-04-10 23:16:00 -07:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
2008-03-05 19:33:33 -08:00
|
|
|
#include "nsILink.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-03-05 19:33:33 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLImageAccessible
|
2010-04-05 17:41:28 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-05 19:33:33 -08:00
|
|
|
|
2010-04-05 17:41:28 -07:00
|
|
|
nsHTMLImageAccessible::
|
2012-02-07 14:38:54 -08:00
|
|
|
nsHTMLImageAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
|
|
|
|
nsLinkableAccessible(aContent, aDoc)
|
2010-04-05 17:41:28 -07:00
|
|
|
{
|
2012-04-24 22:42:58 -07:00
|
|
|
mFlags |= eImageAccessible;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-05 19:33:33 -08:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLImageAccessible, nsAccessible,
|
|
|
|
nsIAccessibleImage)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-04-05 17:41:28 -07:00
|
|
|
// nsAccessible public
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64
|
|
|
|
nsHTMLImageAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// The state is a bitfield, get our inherited state, then logically OR it with
|
2011-04-09 16:38:06 -07:00
|
|
|
// states::ANIMATED if this is an animated image.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64 state = nsLinkableAccessible::NativeState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(mContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<imgIRequest> imageRequest;
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
if (content)
|
2007-03-22 10:30:00 -07:00
|
|
|
content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imageRequest));
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2007-04-02 08:56:24 -07:00
|
|
|
if (imageRequest)
|
2007-03-22 10:30:00 -07:00
|
|
|
imageRequest->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
|
|
|
|
if (imgContainer) {
|
2011-09-28 23:19:26 -07: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-20 18:50:15 -07:00
|
|
|
imgContainer->GetAnimated(&animated);
|
|
|
|
if (animated)
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::ANIMATED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-13 01:58:58 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLImageAccessible::GetNameInternal(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasAltAttrib =
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName);
|
2008-10-13 01:58:58 -07:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
2008-10-10 05:26:55 -07:00
|
|
|
|
2008-10-14 01:27:02 -07:00
|
|
|
nsresult rv = nsAccessible::GetNameInternal(aName);
|
2008-10-13 01:58:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-12-16 08:13:49 -08: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-13 01:58:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
nsHTMLImageAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::GRAPHIC;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-05 17:41:28 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessible
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-05 12:35:43 -07:00
|
|
|
PRUint8
|
|
|
|
nsHTMLImageAccessible::ActionCount()
|
2008-08-26 00:39:17 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
PRUint8 actionCount = nsLinkableAccessible::ActionCount();
|
|
|
|
return HasLongDesc() ? actionCount + 1 : actionCount;
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-04-10 23:16:00 -07:00
|
|
|
if (IsLongDescIndex(aIndex) && HasLongDesc()) {
|
2008-08-26 00:39:17 -07:00
|
|
|
aName.AssignLiteral("showlongdesc");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsLinkableAccessible::GetActionName(aIndex, aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::DoAction(PRUint8 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-08-26 00:39:17 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-04-10 23:16:00 -07: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));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-05 19:33:33 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessibleImage
|
|
|
|
|
2007-12-01 09:30:09 -08: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-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-01 09:30:09 -08:00
|
|
|
PRInt32 x, y;
|
|
|
|
return GetBounds(&x, &y, aWidth, aHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-16 05:42:36 -07:00
|
|
|
|
2010-04-05 17:41:28 -07:00
|
|
|
// nsAccessible
|
2008-04-22 23:03:02 -07: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 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src);
|
2008-04-22 23:03:02 -07:00
|
|
|
if (!src.IsEmpty())
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::src, src);
|
2008-04-22 23:03:02 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-26 00:39:17 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private methods
|
|
|
|
|
2012-04-10 23:16:00 -07:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsHTMLImageAccessible::GetLongDescURI() const
|
2008-08-26 00:39:17 -07:00
|
|
|
{
|
2012-04-10 23:16:00 -07: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 05:57:00 -07:00
|
|
|
while (nsIContent* target = iter.NextElem()) {
|
2012-04-10 23:16:00 -07: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 00:39:17 -07:00
|
|
|
|
2012-04-10 23:16:00 -07:00
|
|
|
return nsnull;
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-04-10 23:16:00 -07:00
|
|
|
nsHTMLImageAccessible::IsLongDescIndex(PRUint8 aIndex)
|
2008-08-26 00:39:17 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
return aIndex == nsLinkableAccessible::ActionCount();
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
2012-04-10 23:16:00 -07:00
|
|
|
|