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):
|
2008-03-18 11:37:12 +00:00
|
|
|
* Aaron Leventhal <aleventh@us.ibm.com> (original author)
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.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 "nsHTMLLinkAccessible.h"
|
|
|
|
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsCoreUtils.h"
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
#include "nsILink.h"
|
2002-07-02 05:37:35 +00:00
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLLinkAccessible
|
|
|
|
|
|
|
|
nsHTMLLinkAccessible::nsHTMLLinkAccessible(nsIDOMNode* aDomNode,
|
|
|
|
nsIWeakReference* aShell):
|
|
|
|
nsHyperTextAccessibleWrap(aDomNode, aShell)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
// Expose nsIAccessibleHyperLink unconditionally
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLLinkAccessible, nsHyperTextAccessibleWrap,
|
|
|
|
nsIAccessibleHyperLink)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessible
|
|
|
|
|
2009-03-07 15:38:58 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLLinkAccessible::GetRoleInternal(PRUint32 *aRole)
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2008-03-18 11:37:12 +00:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_LINK;
|
2001-05-11 21:11:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-04 03:37:46 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLLinkAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
|
2002-08-01 21:36:02 +00:00
|
|
|
{
|
2008-11-04 03:37:46 +00:00
|
|
|
nsresult rv = nsHyperTextAccessibleWrap::GetStateInternal(aState,
|
|
|
|
aExtraState);
|
2008-11-27 04:04:05 +00:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-04-02 15:56:24 +00:00
|
|
|
|
2007-03-15 14:18:33 +00:00
|
|
|
*aState &= ~nsIAccessibleStates::STATE_READONLY;
|
2005-01-30 01:31:50 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (content && content->HasAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::name)) {
|
|
|
|
// This is how we indicate it is a named anchor
|
|
|
|
// In other words, this anchor can be selected as a location :)
|
|
|
|
// There is no other better state to use to indicate this.
|
2007-03-15 14:18:33 +00:00
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTABLE;
|
2005-01-30 01:31:50 +00:00
|
|
|
}
|
2002-08-01 21:36:02 +00:00
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
nsLinkState linkState = content->GetLinkState();
|
2008-06-19 03:11:46 +00:00
|
|
|
if (linkState == eLinkState_NotLink || linkState == eLinkState_Unknown) {
|
|
|
|
// This is a either named anchor (a link with also a name attribute) or
|
|
|
|
// it doesn't have any attributes. Check if 'click' event handler is
|
|
|
|
// registered, otherwise bail out.
|
2010-02-03 15:00:25 +00:00
|
|
|
PRBool isOnclick = nsCoreUtils::HasClickListener(content);
|
2008-06-19 03:11:46 +00:00
|
|
|
if (!isOnclick)
|
|
|
|
return NS_OK;
|
2008-03-20 02:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aState |= nsIAccessibleStates::STATE_LINKED;
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
if (linkState == eLinkState_Visited)
|
|
|
|
*aState |= nsIAccessibleStates::STATE_TRAVERSED;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkAccessible::GetValue(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
nsresult rv = nsHyperTextAccessible::GetValue(aValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!aValue.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
|
|
|
if (mDOMNode && presShell)
|
|
|
|
return presShell->GetLinkLocation(mDOMNode, aValue);
|
|
|
|
|
2002-08-01 21:36:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-03-18 11:37:12 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkAccessible::GetNumActions(PRUint8 *aNumActions)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumActions);
|
|
|
|
|
2008-06-20 05:50:27 +00:00
|
|
|
if (!IsLinked())
|
|
|
|
return nsHyperTextAccessible::GetNumActions(aNumActions);
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
*aNumActions = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
2008-06-20 05:50:27 +00:00
|
|
|
|
|
|
|
if (!IsLinked())
|
|
|
|
return nsHyperTextAccessible::GetActionName(aIndex, aName);
|
|
|
|
|
|
|
|
// Action 0 (default action): Jump to link
|
2008-03-18 11:37:12 +00:00
|
|
|
if (aIndex != eAction_Jump)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
aName.AssignLiteral("jump");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkAccessible::DoAction(PRUint8 aIndex)
|
|
|
|
{
|
2008-06-20 05:50:27 +00:00
|
|
|
if (!IsLinked())
|
|
|
|
return nsHyperTextAccessible::DoAction(aIndex);
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
// Action 0 (default action): Jump to link
|
|
|
|
if (aIndex != eAction_Jump)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-01-25 15:09:25 +00:00
|
|
|
DoCommand();
|
|
|
|
return NS_OK;
|
2008-03-18 11:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessibleHyperLink
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLLinkAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
*aURI = nsnull;
|
|
|
|
|
|
|
|
if (aIndex != 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
nsCOMPtr<nsIContent> link(do_QueryInterface(mDOMNode));
|
2008-03-18 11:37:12 +00:00
|
|
|
NS_ENSURE_STATE(link);
|
|
|
|
|
2009-07-14 16:37:37 +00:00
|
|
|
*aURI = link->GetHrefURI().get();
|
2009-07-13 11:48:06 +00:00
|
|
|
return NS_OK;
|
2008-03-18 11:37:12 +00:00
|
|
|
}
|
2008-06-20 05:50:27 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Protected members
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLLinkAccessible::IsLinked()
|
|
|
|
{
|
2009-07-13 11:48:06 +00:00
|
|
|
nsCOMPtr<nsIContent> link(do_QueryInterface(mDOMNode));
|
2008-06-20 05:50:27 +00:00
|
|
|
if (!link)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
nsLinkState linkState = link->GetLinkState();
|
2008-06-20 05:50:27 +00:00
|
|
|
|
2009-07-13 11:48:06 +00:00
|
|
|
return linkState != eLinkState_NotLink && linkState != eLinkState_Unknown;
|
2008-06-20 05:50:27 +00:00
|
|
|
}
|