accessible/src/html/HTMLLinkAccessible.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "HTMLLinkAccessible.h"
michael@0 7
michael@0 8 #include "nsCoreUtils.h"
michael@0 9 #include "DocAccessible.h"
michael@0 10 #include "Role.h"
michael@0 11 #include "States.h"
michael@0 12
michael@0 13 #include "nsContentUtils.h"
michael@0 14 #include "mozilla/EventStates.h"
michael@0 15 #include "mozilla/dom/Element.h"
michael@0 16
michael@0 17 using namespace mozilla;
michael@0 18 using namespace mozilla::a11y;
michael@0 19
michael@0 20 ////////////////////////////////////////////////////////////////////////////////
michael@0 21 // HTMLLinkAccessible
michael@0 22 ////////////////////////////////////////////////////////////////////////////////
michael@0 23
michael@0 24 HTMLLinkAccessible::
michael@0 25 HTMLLinkAccessible(nsIContent* aContent, DocAccessible* aDoc) :
michael@0 26 HyperTextAccessibleWrap(aContent, aDoc)
michael@0 27 {
michael@0 28 }
michael@0 29
michael@0 30 // Expose nsIAccessibleHyperLink unconditionally
michael@0 31 NS_IMPL_ISUPPORTS_INHERITED(HTMLLinkAccessible, HyperTextAccessibleWrap,
michael@0 32 nsIAccessibleHyperLink)
michael@0 33
michael@0 34 ////////////////////////////////////////////////////////////////////////////////
michael@0 35 // nsIAccessible
michael@0 36
michael@0 37 role
michael@0 38 HTMLLinkAccessible::NativeRole()
michael@0 39 {
michael@0 40 return roles::LINK;
michael@0 41 }
michael@0 42
michael@0 43 uint64_t
michael@0 44 HTMLLinkAccessible::NativeState()
michael@0 45 {
michael@0 46 return HyperTextAccessibleWrap::NativeState() & ~states::READONLY;
michael@0 47 }
michael@0 48
michael@0 49 uint64_t
michael@0 50 HTMLLinkAccessible::NativeLinkState() const
michael@0 51 {
michael@0 52 EventStates eventState = mContent->AsElement()->State();
michael@0 53 if (eventState.HasState(NS_EVENT_STATE_UNVISITED))
michael@0 54 return states::LINKED;
michael@0 55
michael@0 56 if (eventState.HasState(NS_EVENT_STATE_VISITED))
michael@0 57 return states::LINKED | states::TRAVERSED;
michael@0 58
michael@0 59 // This is a either named anchor (a link with also a name attribute) or
michael@0 60 // it doesn't have any attributes. Check if 'click' event handler is
michael@0 61 // registered, otherwise bail out.
michael@0 62 return nsCoreUtils::HasClickListener(mContent) ? states::LINKED : 0;
michael@0 63 }
michael@0 64
michael@0 65 uint64_t
michael@0 66 HTMLLinkAccessible::NativeInteractiveState() const
michael@0 67 {
michael@0 68 uint64_t state = HyperTextAccessibleWrap::NativeInteractiveState();
michael@0 69
michael@0 70 // This is how we indicate it is a named anchor. In other words, this anchor
michael@0 71 // can be selected as a location :) There is no other better state to use to
michael@0 72 // indicate this.
michael@0 73 if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::name))
michael@0 74 state |= states::SELECTABLE;
michael@0 75
michael@0 76 return state;
michael@0 77 }
michael@0 78
michael@0 79 void
michael@0 80 HTMLLinkAccessible::Value(nsString& aValue)
michael@0 81 {
michael@0 82 aValue.Truncate();
michael@0 83
michael@0 84 HyperTextAccessible::Value(aValue);
michael@0 85 if (aValue.IsEmpty())
michael@0 86 nsContentUtils::GetLinkLocation(mContent->AsElement(), aValue);
michael@0 87 }
michael@0 88
michael@0 89 uint8_t
michael@0 90 HTMLLinkAccessible::ActionCount()
michael@0 91 {
michael@0 92 return IsLinked() ? 1 : HyperTextAccessible::ActionCount();
michael@0 93 }
michael@0 94
michael@0 95 NS_IMETHODIMP
michael@0 96 HTMLLinkAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
michael@0 97 {
michael@0 98 aName.Truncate();
michael@0 99
michael@0 100 if (!IsLinked())
michael@0 101 return HyperTextAccessible::GetActionName(aIndex, aName);
michael@0 102
michael@0 103 // Action 0 (default action): Jump to link
michael@0 104 if (aIndex != eAction_Jump)
michael@0 105 return NS_ERROR_INVALID_ARG;
michael@0 106
michael@0 107 aName.AssignLiteral("jump");
michael@0 108 return NS_OK;
michael@0 109 }
michael@0 110
michael@0 111 NS_IMETHODIMP
michael@0 112 HTMLLinkAccessible::DoAction(uint8_t aIndex)
michael@0 113 {
michael@0 114 if (!IsLinked())
michael@0 115 return HyperTextAccessible::DoAction(aIndex);
michael@0 116
michael@0 117 // Action 0 (default action): Jump to link
michael@0 118 if (aIndex != eAction_Jump)
michael@0 119 return NS_ERROR_INVALID_ARG;
michael@0 120
michael@0 121 if (IsDefunct())
michael@0 122 return NS_ERROR_FAILURE;
michael@0 123
michael@0 124 DoCommand();
michael@0 125 return NS_OK;
michael@0 126 }
michael@0 127
michael@0 128 ////////////////////////////////////////////////////////////////////////////////
michael@0 129 // HyperLinkAccessible
michael@0 130
michael@0 131 bool
michael@0 132 HTMLLinkAccessible::IsLink()
michael@0 133 {
michael@0 134 // Expose HyperLinkAccessible unconditionally.
michael@0 135 return true;
michael@0 136 }
michael@0 137
michael@0 138 already_AddRefed<nsIURI>
michael@0 139 HTMLLinkAccessible::AnchorURIAt(uint32_t aAnchorIndex)
michael@0 140 {
michael@0 141 return aAnchorIndex == 0 ? mContent->GetHrefURI() : nullptr;
michael@0 142 }
michael@0 143
michael@0 144 ////////////////////////////////////////////////////////////////////////////////
michael@0 145 // Protected members
michael@0 146
michael@0 147 bool
michael@0 148 HTMLLinkAccessible::IsLinked()
michael@0 149 {
michael@0 150 if (IsDefunct())
michael@0 151 return false;
michael@0 152
michael@0 153 EventStates state = mContent->AsElement()->State();
michael@0 154 return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED |
michael@0 155 NS_EVENT_STATE_UNVISITED);
michael@0 156 }

mercurial