2001-09-25 00:48:50 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2001-05-11 21:11:38 +00:00
|
|
|
|
2012-06-04 12:32:38 +00:00
|
|
|
#include "HTMLLinkAccessible.h"
|
2001-05-11 21:11:38 +00:00
|
|
|
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsCoreUtils.h"
|
2012-05-27 09:01:40 +00:00
|
|
|
#include "DocAccessible.h"
|
2012-01-12 03:07:35 +00:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
|
2012-05-24 06:57:16 +00:00
|
|
|
#include "nsContentUtils.h"
|
2011-04-21 17:35:52 +00:00
|
|
|
#include "nsEventStates.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2002-07-02 05:37:35 +00:00
|
|
|
|
2011-07-27 12:43:01 +00:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:38 +00:00
|
|
|
// HTMLLinkAccessible
|
2010-06-11 08:23:18 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-18 11:37:12 +00:00
|
|
|
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::
|
|
|
|
HTMLLinkAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-31 08:04:41 +00:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2010-06-11 08:23:18 +00:00
|
|
|
{
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:37:12 +00:00
|
|
|
// Expose nsIAccessibleHyperLink unconditionally
|
2012-06-04 12:32:38 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(HTMLLinkAccessible, HyperTextAccessibleWrap,
|
2008-03-18 11:37:12 +00:00
|
|
|
nsIAccessibleHyperLink)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessible
|
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::NativeRole()
|
2001-05-11 21:11:38 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::LINK;
|
2001-05-11 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 23:38:06 +00:00
|
|
|
PRUint64
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::NativeState()
|
2002-08-01 21:36:02 +00:00
|
|
|
{
|
2012-06-04 05:41:06 +00:00
|
|
|
return HyperTextAccessibleWrap::NativeState() & ~states::READONLY;
|
2012-05-17 09:37:37 +00:00
|
|
|
}
|
2010-10-20 15:04:18 +00:00
|
|
|
|
2012-05-17 09:37:37 +00:00
|
|
|
PRUint64
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::NativeLinkState() const
|
2012-05-17 09:37:37 +00:00
|
|
|
{
|
|
|
|
nsEventStates eventState = mContent->AsElement()->State();
|
|
|
|
if (eventState.HasState(NS_EVENT_STATE_UNVISITED))
|
|
|
|
return states::LINKED;
|
2008-03-20 02:05:35 +00:00
|
|
|
|
2012-05-17 09:37:37 +00:00
|
|
|
if (eventState.HasState(NS_EVENT_STATE_VISITED))
|
|
|
|
return states::LINKED | states::TRAVERSED;
|
2008-03-20 02:05:35 +00:00
|
|
|
|
2010-10-20 15:04:18 +00:00
|
|
|
// 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.
|
2012-05-17 09:37:37 +00:00
|
|
|
return nsCoreUtils::HasClickListener(mContent) ? states::LINKED : 0;
|
2008-03-18 11:37:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 05:41:06 +00:00
|
|
|
PRUint64
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::NativeInteractiveState() const
|
2012-06-04 05:41:06 +00:00
|
|
|
{
|
|
|
|
PRUint64 state = HyperTextAccessibleWrap::NativeInteractiveState();
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::name))
|
|
|
|
state |= states::SELECTABLE;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-04-09 09:48:41 +00:00
|
|
|
void
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::Value(nsString& aValue)
|
2008-03-18 11:37:12 +00:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
2012-05-31 08:04:41 +00:00
|
|
|
HyperTextAccessible::Value(aValue);
|
2012-05-24 06:57:16 +00:00
|
|
|
if (aValue.IsEmpty())
|
|
|
|
nsContentUtils::GetLinkLocation(mContent->AsElement(), aValue);
|
2002-08-01 21:36:02 +00:00
|
|
|
}
|
2008-03-18 11:37:12 +00:00
|
|
|
|
2011-06-05 19:35:43 +00:00
|
|
|
PRUint8
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::ActionCount()
|
2008-03-18 11:37:12 +00:00
|
|
|
{
|
2012-05-31 08:04:41 +00:00
|
|
|
return IsLinked() ? 1 : HyperTextAccessible::ActionCount();
|
2008-03-18 11:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
2008-03-18 11:37:12 +00:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
2008-06-20 05:50:27 +00:00
|
|
|
|
|
|
|
if (!IsLinked())
|
2012-05-31 08:04:41 +00:00
|
|
|
return HyperTextAccessible::GetActionName(aIndex, aName);
|
2008-06-20 05:50:27 +00:00
|
|
|
|
|
|
|
// 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
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::DoAction(PRUint8 aIndex)
|
2008-03-18 11:37:12 +00:00
|
|
|
{
|
2008-06-20 05:50:27 +00:00
|
|
|
if (!IsLinked())
|
2012-05-31 08:04:41 +00:00
|
|
|
return HyperTextAccessible::DoAction(aIndex);
|
2008-06-20 05:50:27 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-09-01 03:26:13 +00:00
|
|
|
// HyperLinkAccessible
|
2008-03-18 11:37:12 +00:00
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
bool
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::IsLink()
|
2008-03-18 11:37:12 +00:00
|
|
|
{
|
2010-09-01 03:26:13 +00:00
|
|
|
// Expose HyperLinkAccessible unconditionally.
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-18 11:37:12 +00:00
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
already_AddRefed<nsIURI>
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::AnchorURIAt(PRUint32 aAnchorIndex)
|
2010-09-01 03:26:13 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return aAnchorIndex == 0 ? mContent->GetHrefURI() : nullptr;
|
2008-03-18 11:37:12 +00:00
|
|
|
}
|
2008-06-20 05:50:27 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Protected members
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible::IsLinked()
|
2008-06-20 05:50:27 +00:00
|
|
|
{
|
2010-06-11 08:23:18 +00:00
|
|
|
if (IsDefunct())
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-06-20 05:50:27 +00:00
|
|
|
|
2011-06-01 01:46:57 +00:00
|
|
|
nsEventStates state = mContent->AsElement()->State();
|
2010-10-20 15:04:18 +00:00
|
|
|
return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED |
|
|
|
|
NS_EVENT_STATE_UNVISITED);
|
2008-06-20 05:50:27 +00:00
|
|
|
}
|