2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-02 04:30:34 -07:00
|
|
|
#include "ImageAccessible.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"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
2013-09-10 15:18:59 -07:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-09-07 06:01:08 -07:00
|
|
|
#include "nsIURI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-03-05 19:33:33 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-02 04:30:34 -07:00
|
|
|
// ImageAccessible
|
2010-04-05 17:41:28 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-05 19:33:33 -08:00
|
|
|
|
2012-06-02 04:30:34 -07:00
|
|
|
ImageAccessible::
|
|
|
|
ImageAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-06-04 05:32:29 -07:00
|
|
|
LinkableAccessible(aContent, aDoc)
|
2010-04-05 17:41:28 -07:00
|
|
|
{
|
2012-12-17 21:22:26 -08:00
|
|
|
mType = eImageType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-08 14:23:18 -07:00
|
|
|
ImageAccessible::~ImageAccessible()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-05 19:33:33 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible public
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-02 04:30:34 -07:00
|
|
|
ImageAccessible::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
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t state = LinkableAccessible::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
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
ImageAccessible::NativeName(nsString& 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())
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2008-10-13 01:58:58 -07:00
|
|
|
|
2012-10-16 23:38:16 -07:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return nameFlag;
|
2008-10-13 01:58:58 -07:00
|
|
|
|
2012-10-16 23:38:16 -07:00
|
|
|
// 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
|
|
|
|
// Accessible::Name() method for details).
|
|
|
|
return hasAltAttrib ? eNoNameOnPurpose : eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-02 04:30:34 -07:00
|
|
|
ImageAccessible::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
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-21 17:49:28 -07:00
|
|
|
// Accessible
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-02 04:30:34 -07:00
|
|
|
ImageAccessible::ActionCount()
|
2008-08-26 00:39:17 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t actionCount = LinkableAccessible::ActionCount();
|
2011-06-05 12:35:43 -07:00
|
|
|
return HasLongDesc() ? actionCount + 1 : actionCount;
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
void
|
|
|
|
ImageAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2008-08-26 00:39:17 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
2014-09-16 10:30:23 -07:00
|
|
|
if (IsLongDescIndex(aIndex) && HasLongDesc())
|
2008-08-26 00:39:17 -07:00
|
|
|
aName.AssignLiteral("showlongdesc");
|
2014-09-16 10:30:23 -07:00
|
|
|
else
|
|
|
|
LinkableAccessible::ActionNameAt(aIndex, aName);
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
ImageAccessible::DoAction(uint8_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-10 23:16:00 -07:00
|
|
|
// Get the long description uri and open in a new window.
|
|
|
|
if (!IsLongDescIndex(aIndex))
|
2012-06-04 05:32:29 -07:00
|
|
|
return LinkableAccessible::DoAction(aIndex);
|
2012-04-10 23:16:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = GetLongDescURI();
|
|
|
|
if (!uri)
|
2014-09-16 10:30:23 -07:00
|
|
|
return false;
|
2012-04-10 23:16:00 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString utf8spec;
|
2012-04-10 23:16:00 -07:00
|
|
|
uri->GetSpec(utf8spec);
|
|
|
|
NS_ConvertUTF8toUTF16 spec(utf8spec);
|
|
|
|
|
|
|
|
nsIDocument* document = mContent->OwnerDoc();
|
|
|
|
nsCOMPtr<nsPIDOMWindow> piWindow = document->GetWindow();
|
2015-10-26 14:37:32 -07:00
|
|
|
if (!piWindow)
|
2014-09-16 10:30:23 -07:00
|
|
|
return false;
|
2012-04-10 23:16:00 -07:00
|
|
|
|
2015-10-26 14:37:32 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> tmp;
|
|
|
|
return NS_SUCCEEDED(piWindow->Open(spec, EmptyString(), EmptyString(),
|
|
|
|
getter_AddRefs(tmp)));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-05 19:33:33 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-09-23 05:23:02 -07:00
|
|
|
// ImageAccessible
|
2008-03-05 19:33:33 -08:00
|
|
|
|
2014-09-23 05:23:02 -07:00
|
|
|
nsIntPoint
|
|
|
|
ImageAccessible::Position(uint32_t aCoordType)
|
2007-12-01 09:30:09 -08:00
|
|
|
{
|
2014-09-16 10:30:23 -07:00
|
|
|
nsIntRect rect = Bounds();
|
2014-09-23 05:23:02 -07:00
|
|
|
nsAccUtils::ConvertScreenCoordsTo(&rect.x, &rect.y, aCoordType, this);
|
|
|
|
return rect.TopLeft();
|
2007-12-01 09:30:09 -08:00
|
|
|
}
|
|
|
|
|
2014-09-23 05:23:02 -07:00
|
|
|
nsIntSize
|
|
|
|
ImageAccessible::Size()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-09-23 05:23:02 -07:00
|
|
|
return Bounds().Size();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-16 05:42:36 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible
|
2012-10-19 00:15:23 -07:00
|
|
|
already_AddRefed<nsIPersistentProperties>
|
|
|
|
ImageAccessible::NativeAttributes()
|
2008-04-22 23:03:02 -07:00
|
|
|
{
|
2012-10-19 00:15:23 -07:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
LinkableAccessible::NativeAttributes();
|
2008-04-22 23:03:02 -07:00
|
|
|
|
|
|
|
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())
|
2012-10-19 00:15:23 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::src, src);
|
2008-04-22 23:03:02 -07:00
|
|
|
|
2012-10-19 00:15:23 -07:00
|
|
|
return attributes.forget();
|
2008-04-22 23:03:02 -07:00
|
|
|
}
|
|
|
|
|
2008-08-26 00:39:17 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private methods
|
|
|
|
|
2012-04-10 23:16:00 -07:00
|
|
|
already_AddRefed<nsIURI>
|
2012-06-02 04:30:34 -07:00
|
|
|
ImageAccessible::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)) {
|
2014-10-24 10:47:57 -07:00
|
|
|
// To check if longdesc contains an invalid url.
|
|
|
|
nsAutoString longdesc;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::longdesc, longdesc);
|
|
|
|
if (longdesc.FindChar(' ') != -1 || longdesc.FindChar('\t') != -1 ||
|
|
|
|
longdesc.FindChar('\r') != -1 || longdesc.FindChar('\n') != -1) {
|
|
|
|
return nullptr;
|
2012-04-10 23:16:00 -07:00
|
|
|
}
|
2014-10-24 10:47:57 -07:00
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), longdesc,
|
|
|
|
mContent->OwnerDoc(), baseURI);
|
|
|
|
return uri.forget();
|
2012-04-10 23:16:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = Document();
|
2012-04-10 23:16:00 -07:00
|
|
|
if (document) {
|
|
|
|
IDRefsIterator iter(document, mContent, nsGkAtoms::aria_describedby);
|
2012-04-14 05:57:00 -07:00
|
|
|
while (nsIContent* target = iter.NextElem()) {
|
2015-03-03 03:08:59 -08:00
|
|
|
if ((target->IsHTMLElement(nsGkAtoms::a) ||
|
|
|
|
target->IsHTMLElement(nsGkAtoms::area)) &&
|
2012-04-10 23:16:00 -07:00
|
|
|
target->HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
|
|
|
nsGenericHTMLElement* element =
|
|
|
|
nsGenericHTMLElement::FromContent(target);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2012-07-30 07:20:58 -07:00
|
|
|
element->GetURIAttr(nsGkAtoms::href, nullptr, getter_AddRefs(uri));
|
2012-04-10 23:16:00 -07:00
|
|
|
return uri.forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-26 00:39:17 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
ImageAccessible::IsLongDescIndex(uint8_t aIndex)
|
2008-08-26 00:39:17 -07:00
|
|
|
{
|
2012-06-04 05:32:29 -07:00
|
|
|
return aIndex == LinkableAccessible::ActionCount();
|
2008-08-26 00:39:17 -07:00
|
|
|
}
|
2012-04-10 23:16:00 -07:00
|
|
|
|