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