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-04 05:32:38 -07:00
|
|
|
#include "HTMLLinkAccessible.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsCoreUtils.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
|
|
|
#include "States.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2012-05-23 23:57:16 -07:00
|
|
|
#include "nsContentUtils.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-04-02 21:18:36 -07:00
|
|
|
using namespace mozilla;
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 05:32:38 -07:00
|
|
|
// HTMLLinkAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::
|
|
|
|
HTMLLinkAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-10-21 17:49:28 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLLinkAccessible, HyperTextAccessible)
|
2008-03-18 04:37:12 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessible
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::LINK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-03 22:41:06 -07:00
|
|
|
return HyperTextAccessibleWrap::NativeState() & ~states::READONLY;
|
2012-05-17 02:37:37 -07:00
|
|
|
}
|
2010-10-20 08:04:18 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::NativeLinkState() const
|
2012-05-17 02:37:37 -07:00
|
|
|
{
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates eventState = mContent->AsElement()->State();
|
2012-05-17 02:37:37 -07:00
|
|
|
if (eventState.HasState(NS_EVENT_STATE_UNVISITED))
|
|
|
|
return states::LINKED;
|
2008-03-19 19:05:35 -07:00
|
|
|
|
2012-05-17 02:37:37 -07:00
|
|
|
if (eventState.HasState(NS_EVENT_STATE_VISITED))
|
|
|
|
return states::LINKED | states::TRAVERSED;
|
2008-03-19 19:05:35 -07:00
|
|
|
|
2010-10-20 08:04:18 -07: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 02:37:37 -07:00
|
|
|
return nsCoreUtils::HasClickListener(mContent) ? states::LINKED : 0;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::NativeInteractiveState() const
|
2012-06-03 22:41:06 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::NativeInteractiveState();
|
2012-06-03 22:41:06 -07:00
|
|
|
|
|
|
|
// 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 02:48:41 -07:00
|
|
|
void
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::Value(nsString& aValue)
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible::Value(aValue);
|
2012-05-23 23:57:16 -07:00
|
|
|
if (aValue.IsEmpty())
|
|
|
|
nsContentUtils::GetLinkLocation(mContent->AsElement(), aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::ActionCount()
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
2012-05-31 01:04:41 -07:00
|
|
|
return IsLinked() ? 1 : HyperTextAccessible::ActionCount();
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
void
|
|
|
|
HTMLLinkAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
2008-06-19 22:50:27 -07:00
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
if (!IsLinked()) {
|
|
|
|
HyperTextAccessible::ActionNameAt(aIndex, aName);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-19 22:50:27 -07:00
|
|
|
|
|
|
|
// Action 0 (default action): Jump to link
|
2014-09-16 10:30:23 -07:00
|
|
|
if (aIndex == eAction_Jump)
|
|
|
|
aName.AssignLiteral("jump");
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
HTMLLinkAccessible::DoAction(uint8_t aIndex)
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
2008-06-19 22:50:27 -07:00
|
|
|
if (!IsLinked())
|
2012-05-31 01:04:41 -07:00
|
|
|
return HyperTextAccessible::DoAction(aIndex);
|
2008-06-19 22:50:27 -07:00
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
// Action 0 (default action): Jump to link
|
|
|
|
if (aIndex != eAction_Jump)
|
2014-09-16 10:30:23 -07:00
|
|
|
return false;
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2010-01-25 07:09:25 -08:00
|
|
|
DoCommand();
|
2014-09-16 10:30:23 -07:00
|
|
|
return true;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-08-31 20:26:13 -07:00
|
|
|
// HyperLinkAccessible
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
bool
|
2012-06-04 05:32:38 -07:00
|
|
|
HTMLLinkAccessible::IsLink()
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
2010-08-31 20:26:13 -07:00
|
|
|
// Expose HyperLinkAccessible unconditionally.
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
already_AddRefed<nsIURI>
|
2012-08-22 08:56:38 -07:00
|
|
|
HTMLLinkAccessible::AnchorURIAt(uint32_t aAnchorIndex)
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return aAnchorIndex == 0 ? mContent->GetHrefURI() : nullptr;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
2008-06-19 22:50:27 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Protected members
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-09-16 10:30:23 -07:00
|
|
|
HTMLLinkAccessible::IsLinked() const
|
2008-06-19 22:50:27 -07:00
|
|
|
{
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates state = mContent->AsElement()->State();
|
2010-10-20 08:04:18 -07:00
|
|
|
return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED |
|
|
|
|
NS_EVENT_STATE_UNVISITED);
|
2008-06-19 22:50:27 -07:00
|
|
|
}
|