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
|
|
|
|
2005-03-20 14:25:03 +00:00
|
|
|
#include "nsAccessibilityAtoms.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccUtils.h"
|
2007-07-16 12:42:36 +00:00
|
|
|
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgIRequest.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
|
|
|
|
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::
|
2010-06-11 08:23:18 +00:00
|
|
|
nsHTMLImageAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
|
|
|
nsLinkableAccessible(aContent, aShell)
|
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
|
|
|
|
2008-11-04 03:37:46 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLImageAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
|
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
|
|
|
|
// STATE_ANIMATED if this is an animated image.
|
2001-08-14 00:18:04 +00:00
|
|
|
|
2008-11-04 03:37:46 +00:00
|
|
|
nsresult rv = nsLinkableAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-27 04:04:05 +00:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
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) {
|
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
|
|
|
PRBool animated;
|
|
|
|
imgContainer->GetAnimated(&animated);
|
|
|
|
if (animated)
|
2007-04-02 15:56:24 +00:00
|
|
|
*aState |= nsIAccessibleStates::STATE_ANIMATED;
|
2001-08-14 00:18:04 +00:00
|
|
|
}
|
2001-08-14 02:27:30 +00:00
|
|
|
|
2001-08-14 00:18:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-13 08:58:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLImageAccessible::GetNameInternal(nsAString& aName)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2008-04-24 06:01:28 +00:00
|
|
|
PRBool hasAltAttrib =
|
2010-06-11 08:23:18 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::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
|
|
|
}
|
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLImageAccessible::GetRoleInternal(PRUint32 *aRole)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2010-04-06 00:41:28 +00:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_GRAPHIC;
|
2001-05-11 21:11:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessible
|
2004-06-04 22:01:36 +00:00
|
|
|
|
2008-08-26 07:39:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::GetNumActions(PRUint8 *aNumActions)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumActions);
|
|
|
|
*aNumActions = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv= nsLinkableAccessible::GetNumActions(aNumActions);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (HasLongDesc())
|
|
|
|
(*aNumActions)++;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLImageAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (IsValidLongDescIndex(aIndex)) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (IsValidLongDescIndex(aIndex)) {
|
2006-07-31 05:21:46 +00:00
|
|
|
//get the long description uri and open in a new window
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> element(do_QueryInterface(mContent));
|
2006-07-31 05:21:46 +00:00
|
|
|
NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
|
2010-06-11 08:23:18 +00:00
|
|
|
|
2006-07-31 05:21:46 +00:00
|
|
|
nsAutoString longDesc;
|
|
|
|
nsresult rv = element->GetLongDesc(longDesc);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-11 08:23:18 +00:00
|
|
|
|
|
|
|
nsIDocument* document = mContent->GetOwnerDoc();
|
2006-07-31 05:21:46 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> piWindow = document->GetWindow();
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(piWindow));
|
|
|
|
NS_ENSURE_TRUE(win, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDOMWindow> tmp;
|
2010-05-18 07:50:14 +00:00
|
|
|
return win->Open(longDesc, EmptyString(), EmptyString(),
|
2006-07-31 05:21:46 +00:00
|
|
|
getter_AddRefs(tmp));
|
|
|
|
}
|
2008-08-26 07:39:17 +00:00
|
|
|
return nsLinkableAccessible::DoAction(aIndex);
|
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;
|
2010-06-11 08:23:18 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::src, src);
|
2008-04-23 06:03:02 +00:00
|
|
|
if (!src.IsEmpty())
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::src, src);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-26 07:39:17 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private methods
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLImageAccessible::HasLongDesc()
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-06-11 08:23:18 +00:00
|
|
|
return mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::longDesc);
|
2008-08-26 07:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLImageAccessible::IsValidLongDescIndex(PRUint8 aIndex)
|
|
|
|
{
|
|
|
|
if (!HasLongDesc())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRUint8 numActions = 0;
|
|
|
|
nsresult rv = nsLinkableAccessible::GetNumActions(&numActions);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
|
|
|
return (aIndex == numActions);
|
|
|
|
}
|