mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 652635 - Fallback missing @longdesc to aria-describedby pointing to <a href>, r=surkov, jonas
This commit is contained in:
parent
9c63458607
commit
86d94910f9
@ -75,6 +75,8 @@ LOCAL_INCLUDES = \
|
||||
-I$(srcdir)/../base \
|
||||
-I$(srcdir)/../generic \
|
||||
-I$(srcdir)/../xpcom \
|
||||
-I$(srcdir)/../../../content/base/src \
|
||||
-I$(srcdir)/../../../content/html/content/src \
|
||||
-I$(srcdir)/../../../layout/generic \
|
||||
-I$(srcdir)/../../../layout/xul/base/src \
|
||||
$(NULL)
|
||||
|
@ -40,10 +40,12 @@
|
||||
|
||||
#include "nsAccUtils.h"
|
||||
#include "Role.h"
|
||||
#include "AccIterator.h"
|
||||
#include "States.h"
|
||||
|
||||
#include "imgIContainer.h"
|
||||
#include "imgIRequest.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIImageLoadingContent.h"
|
||||
#include "nsILink.h"
|
||||
@ -146,7 +148,7 @@ nsHTMLImageAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
||||
if (IsDefunct())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (IsValidLongDescIndex(aIndex)) {
|
||||
if (IsLongDescIndex(aIndex) && HasLongDesc()) {
|
||||
aName.AssignLiteral("showlongdesc");
|
||||
return NS_OK;
|
||||
}
|
||||
@ -159,24 +161,27 @@ nsHTMLImageAccessible::DoAction(PRUint8 aIndex)
|
||||
if (IsDefunct())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (IsValidLongDescIndex(aIndex)) {
|
||||
//get the long description uri and open in a new window
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> element(do_QueryInterface(mContent));
|
||||
NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
|
||||
// Get the long description uri and open in a new window.
|
||||
if (!IsLongDescIndex(aIndex))
|
||||
return nsLinkableAccessible::DoAction(aIndex);
|
||||
|
||||
nsAutoString longDesc;
|
||||
nsresult rv = element->GetLongDesc(longDesc);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
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));
|
||||
|
||||
nsIDocument* document = mContent->OwnerDoc();
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow = document->GetWindow();
|
||||
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(piWindow);
|
||||
NS_ENSURE_TRUE(win, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIDOMWindow> tmp;
|
||||
return win->Open(longDesc, EmptyString(), EmptyString(),
|
||||
getter_AddRefs(tmp));
|
||||
}
|
||||
return nsLinkableAccessible::DoAction(aIndex);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -222,20 +227,42 @@ nsHTMLImageAccessible::GetAttributesInternal(nsIPersistentProperties *aAttribute
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
|
||||
bool
|
||||
nsHTMLImageAccessible::HasLongDesc()
|
||||
already_AddRefed<nsIURI>
|
||||
nsHTMLImageAccessible::GetLongDescURI() const
|
||||
{
|
||||
if (IsDefunct())
|
||||
return false;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
return mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::longdesc);
|
||||
nsDocAccessible* document = Document();
|
||||
if (document) {
|
||||
IDRefsIterator iter(document, mContent, nsGkAtoms::aria_describedby);
|
||||
nsIContent* target = nsnull;
|
||||
while (target = iter.NextElem()) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLImageAccessible::IsValidLongDescIndex(PRUint8 aIndex)
|
||||
nsHTMLImageAccessible::IsLongDescIndex(PRUint8 aIndex)
|
||||
{
|
||||
if (!HasLongDesc())
|
||||
return false;
|
||||
|
||||
return aIndex == nsLinkableAccessible::ActionCount();
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@
|
||||
#include "nsBaseWidgetAccessible.h"
|
||||
#include "nsIAccessibleImage.h"
|
||||
|
||||
class nsGenericHTMLElement;
|
||||
|
||||
/* Accessible for supporting images
|
||||
* supports:
|
||||
* - gets name, role
|
||||
@ -74,26 +76,37 @@ public:
|
||||
|
||||
private:
|
||||
/**
|
||||
* Determine if this image accessible has a longdesc attribute.
|
||||
*
|
||||
* @returns true if the longdesc attribute is present.
|
||||
* Return whether the element has a longdesc URI.
|
||||
*/
|
||||
bool HasLongDesc();
|
||||
|
||||
bool HasLongDesc() const
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri = GetLongDescURI();
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an URI for showlongdesc action if any.
|
||||
*/
|
||||
already_AddRefed<nsIURI> GetLongDescURI() const;
|
||||
|
||||
/**
|
||||
* Used by GetActionName and DoAction to ensure the index for opening the
|
||||
* longdesc URL is valid.
|
||||
* It is always assumed that the highest possible index opens the longdesc.
|
||||
* This doesn't check that there is actually a longdesc, just that the index
|
||||
* would be correct if there was one.
|
||||
*
|
||||
* @param aIndex The 0-based index to be tested.
|
||||
*
|
||||
* @returns true if index is valid for longdesc action.
|
||||
*/
|
||||
bool IsValidLongDescIndex(PRUint8 aIndex);
|
||||
inline bool IsLongDescIndex(PRUint8 aIndex);
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsAccessible downcasting method
|
||||
|
||||
inline nsHTMLImageAccessible*
|
||||
nsAccessible::AsImage()
|
||||
{
|
||||
|
@ -128,6 +128,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659
|
||||
testThis("click", "moz.png",
|
||||
89, 38, 1, actionNamesArray);
|
||||
|
||||
// Image with long desc
|
||||
actionNamesArray = null;
|
||||
actionNamesArray = new Array("showlongdesc");
|
||||
testThis("longdesc2", "moz.png",
|
||||
89, 38, 1, actionNamesArray);
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
@ -138,10 +144,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659
|
||||
<body>
|
||||
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=429659">Mozilla Bug 429659</a>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=652635"
|
||||
title="fall back missing @longdesc to aria-describedby pointing to a href">
|
||||
Mozilla Bug 652635
|
||||
</a>
|
||||
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<br>Simple image:<br>
|
||||
<img id="nonLinkedImage" src="moz.png"/>
|
||||
<br>Linked image:<br>
|
||||
@ -152,8 +165,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659
|
||||
<br>Image with click and longdesc:<br>
|
||||
<img id="clickAndLongdesc" src="moz.png" longdesc="longdesc_src.html"
|
||||
alt="Another image of Mozilla logo" onclick="alert('Clicked!');"/>
|
||||
|
||||
<br>image described by a link to be treated as longdesc<br>
|
||||
<img id="longdesc2" src="moz.png" aria-describedby="describing_link"
|
||||
alt="Second Image of Mozilla logo"/>
|
||||
<a id="describing_link" href="longdesc_src.html">link to description of image</a>
|
||||
|
||||
<br>Image with click:<br>
|
||||
<img id="click" src="moz.png"
|
||||
alt="A third image of Mozilla logo" onclick="alert('Clicked, too!');"/>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -525,6 +525,14 @@ public:
|
||||
*/
|
||||
NS_HIDDEN_(nsresult) GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsAString& aResult);
|
||||
|
||||
/**
|
||||
* Gets the absolute URI values of an attribute, by resolving any relative
|
||||
* URIs in the attribute against the baseuri of the element. If a substring
|
||||
* isn't a relative URI, the substring is returned as is. Only works for
|
||||
* attributes in null namespace.
|
||||
*/
|
||||
bool GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsIURI** aURI) const;
|
||||
|
||||
/**
|
||||
* Returns the current disabled state of the element.
|
||||
*/
|
||||
@ -705,14 +713,6 @@ protected:
|
||||
*/
|
||||
NS_HIDDEN_(nsresult) SetDoubleAttr(nsIAtom* aAttr, double aValue);
|
||||
|
||||
/**
|
||||
* Helper for GetURIAttr and GetHrefURIForAnchors which returns an
|
||||
* nsIURI in the out param.
|
||||
*
|
||||
* @return true if we had the attr, false otherwise.
|
||||
*/
|
||||
NS_HIDDEN_(bool) GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsIURI** aURI) const;
|
||||
|
||||
/**
|
||||
* This method works like GetURIAttr, except that it supports multiple
|
||||
* URIs separated by whitespace (one or more U+0020 SPACE characters).
|
||||
|
Loading…
Reference in New Issue
Block a user