Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
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 "BaseAccessibles.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "Accessible-inl.h" |
michael@0 | 9 | #include "HyperTextAccessibleWrap.h" |
michael@0 | 10 | #include "nsAccessibilityService.h" |
michael@0 | 11 | #include "nsAccUtils.h" |
michael@0 | 12 | #include "nsCoreUtils.h" |
michael@0 | 13 | #include "Role.h" |
michael@0 | 14 | #include "States.h" |
michael@0 | 15 | #include "nsIURI.h" |
michael@0 | 16 | |
michael@0 | 17 | using namespace mozilla::a11y; |
michael@0 | 18 | |
michael@0 | 19 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 20 | // LeafAccessible |
michael@0 | 21 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 22 | |
michael@0 | 23 | LeafAccessible:: |
michael@0 | 24 | LeafAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 25 | AccessibleWrap(aContent, aDoc) |
michael@0 | 26 | { |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | NS_IMPL_ISUPPORTS_INHERITED0(LeafAccessible, Accessible) |
michael@0 | 30 | |
michael@0 | 31 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 32 | // LeafAccessible: Accessible public |
michael@0 | 33 | |
michael@0 | 34 | Accessible* |
michael@0 | 35 | LeafAccessible::ChildAtPoint(int32_t aX, int32_t aY, |
michael@0 | 36 | EWhichChildAtPoint aWhichChild) |
michael@0 | 37 | { |
michael@0 | 38 | // Don't walk into leaf accessibles. |
michael@0 | 39 | return this; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | bool |
michael@0 | 43 | LeafAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild) |
michael@0 | 44 | { |
michael@0 | 45 | NS_NOTREACHED("InsertChildAt called on leaf accessible!"); |
michael@0 | 46 | return false; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | bool |
michael@0 | 50 | LeafAccessible::RemoveChild(Accessible* aChild) |
michael@0 | 51 | { |
michael@0 | 52 | NS_NOTREACHED("RemoveChild called on leaf accessible!"); |
michael@0 | 53 | return false; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 57 | // LeafAccessible: Accessible private |
michael@0 | 58 | |
michael@0 | 59 | void |
michael@0 | 60 | LeafAccessible::CacheChildren() |
michael@0 | 61 | { |
michael@0 | 62 | // No children for leaf accessible. |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 67 | // LinkableAccessible |
michael@0 | 68 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 69 | |
michael@0 | 70 | LinkableAccessible:: |
michael@0 | 71 | LinkableAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 72 | AccessibleWrap(aContent, aDoc), |
michael@0 | 73 | mActionAcc(nullptr), |
michael@0 | 74 | mIsLink(false), |
michael@0 | 75 | mIsOnclick(false) |
michael@0 | 76 | { |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | NS_IMPL_ISUPPORTS_INHERITED0(LinkableAccessible, AccessibleWrap) |
michael@0 | 80 | |
michael@0 | 81 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 82 | // LinkableAccessible. nsIAccessible |
michael@0 | 83 | |
michael@0 | 84 | NS_IMETHODIMP |
michael@0 | 85 | LinkableAccessible::TakeFocus() |
michael@0 | 86 | { |
michael@0 | 87 | return mActionAcc ? mActionAcc->TakeFocus() : AccessibleWrap::TakeFocus(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | uint64_t |
michael@0 | 91 | LinkableAccessible::NativeLinkState() const |
michael@0 | 92 | { |
michael@0 | 93 | if (mIsLink) |
michael@0 | 94 | return states::LINKED | (mActionAcc->LinkState() & states::TRAVERSED); |
michael@0 | 95 | |
michael@0 | 96 | return 0; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | void |
michael@0 | 100 | LinkableAccessible::Value(nsString& aValue) |
michael@0 | 101 | { |
michael@0 | 102 | aValue.Truncate(); |
michael@0 | 103 | |
michael@0 | 104 | Accessible::Value(aValue); |
michael@0 | 105 | if (!aValue.IsEmpty()) |
michael@0 | 106 | return; |
michael@0 | 107 | |
michael@0 | 108 | if (aValue.IsEmpty() && mIsLink) |
michael@0 | 109 | mActionAcc->Value(aValue); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | |
michael@0 | 113 | uint8_t |
michael@0 | 114 | LinkableAccessible::ActionCount() |
michael@0 | 115 | { |
michael@0 | 116 | return (mIsOnclick || mIsLink) ? 1 : 0; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | NS_IMETHODIMP |
michael@0 | 120 | LinkableAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 121 | { |
michael@0 | 122 | aName.Truncate(); |
michael@0 | 123 | |
michael@0 | 124 | // Action 0 (default action): Jump to link |
michael@0 | 125 | if (aIndex == eAction_Jump) { |
michael@0 | 126 | if (mIsLink) { |
michael@0 | 127 | aName.AssignLiteral("jump"); |
michael@0 | 128 | return NS_OK; |
michael@0 | 129 | } |
michael@0 | 130 | else if (mIsOnclick) { |
michael@0 | 131 | aName.AssignLiteral("click"); |
michael@0 | 132 | return NS_OK; |
michael@0 | 133 | } |
michael@0 | 134 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 135 | } |
michael@0 | 136 | return NS_ERROR_INVALID_ARG; |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | NS_IMETHODIMP |
michael@0 | 140 | LinkableAccessible::DoAction(uint8_t aIndex) |
michael@0 | 141 | { |
michael@0 | 142 | if (aIndex != eAction_Jump) |
michael@0 | 143 | return NS_ERROR_INVALID_ARG; |
michael@0 | 144 | |
michael@0 | 145 | return mActionAcc ? mActionAcc->DoAction(aIndex) : |
michael@0 | 146 | AccessibleWrap::DoAction(aIndex); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | KeyBinding |
michael@0 | 150 | LinkableAccessible::AccessKey() const |
michael@0 | 151 | { |
michael@0 | 152 | return mActionAcc ? |
michael@0 | 153 | mActionAcc->AccessKey() : Accessible::AccessKey(); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 157 | // LinkableAccessible. Accessible |
michael@0 | 158 | |
michael@0 | 159 | void |
michael@0 | 160 | LinkableAccessible::Shutdown() |
michael@0 | 161 | { |
michael@0 | 162 | mIsLink = false; |
michael@0 | 163 | mIsOnclick = false; |
michael@0 | 164 | mActionAcc = nullptr; |
michael@0 | 165 | AccessibleWrap::Shutdown(); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 169 | // LinkableAccessible: HyperLinkAccessible |
michael@0 | 170 | |
michael@0 | 171 | already_AddRefed<nsIURI> |
michael@0 | 172 | LinkableAccessible::AnchorURIAt(uint32_t aAnchorIndex) |
michael@0 | 173 | { |
michael@0 | 174 | if (mIsLink) { |
michael@0 | 175 | NS_ASSERTION(mActionAcc->IsLink(), |
michael@0 | 176 | "nsIAccessibleHyperLink isn't implemented."); |
michael@0 | 177 | |
michael@0 | 178 | if (mActionAcc->IsLink()) |
michael@0 | 179 | return mActionAcc->AnchorURIAt(aAnchorIndex); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | return nullptr; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 186 | // LinkableAccessible: Accessible protected |
michael@0 | 187 | |
michael@0 | 188 | void |
michael@0 | 189 | LinkableAccessible::BindToParent(Accessible* aParent, |
michael@0 | 190 | uint32_t aIndexInParent) |
michael@0 | 191 | { |
michael@0 | 192 | AccessibleWrap::BindToParent(aParent, aIndexInParent); |
michael@0 | 193 | |
michael@0 | 194 | // Cache action content. |
michael@0 | 195 | mActionAcc = nullptr; |
michael@0 | 196 | mIsLink = false; |
michael@0 | 197 | mIsOnclick = false; |
michael@0 | 198 | |
michael@0 | 199 | if (nsCoreUtils::HasClickListener(mContent)) { |
michael@0 | 200 | mIsOnclick = true; |
michael@0 | 201 | return; |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | // XXX: The logic looks broken since the click listener may be registered |
michael@0 | 205 | // on non accessible node in parent chain but this node is skipped when tree |
michael@0 | 206 | // is traversed. |
michael@0 | 207 | Accessible* walkUpAcc = this; |
michael@0 | 208 | while ((walkUpAcc = walkUpAcc->Parent()) && !walkUpAcc->IsDoc()) { |
michael@0 | 209 | if (walkUpAcc->LinkState() & states::LINKED) { |
michael@0 | 210 | mIsLink = true; |
michael@0 | 211 | mActionAcc = walkUpAcc; |
michael@0 | 212 | return; |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | if (nsCoreUtils::HasClickListener(walkUpAcc->GetContent())) { |
michael@0 | 216 | mActionAcc = walkUpAcc; |
michael@0 | 217 | mIsOnclick = true; |
michael@0 | 218 | return; |
michael@0 | 219 | } |
michael@0 | 220 | } |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | void |
michael@0 | 224 | LinkableAccessible::UnbindFromParent() |
michael@0 | 225 | { |
michael@0 | 226 | mActionAcc = nullptr; |
michael@0 | 227 | mIsLink = false; |
michael@0 | 228 | mIsOnclick = false; |
michael@0 | 229 | |
michael@0 | 230 | AccessibleWrap::UnbindFromParent(); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 234 | // EnumRoleAccessible |
michael@0 | 235 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 236 | |
michael@0 | 237 | EnumRoleAccessible:: |
michael@0 | 238 | EnumRoleAccessible(nsIContent* aNode, DocAccessible* aDoc, roles::Role aRole) : |
michael@0 | 239 | AccessibleWrap(aNode, aDoc), mRole(aRole) |
michael@0 | 240 | { |
michael@0 | 241 | } |
michael@0 | 242 | |
michael@0 | 243 | NS_IMPL_ISUPPORTS_INHERITED0(EnumRoleAccessible, Accessible) |
michael@0 | 244 | |
michael@0 | 245 | role |
michael@0 | 246 | EnumRoleAccessible::NativeRole() |
michael@0 | 247 | { |
michael@0 | 248 | return mRole; |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 252 | // DummyAccessible |
michael@0 | 253 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 254 | |
michael@0 | 255 | uint64_t |
michael@0 | 256 | DummyAccessible::NativeState() |
michael@0 | 257 | { |
michael@0 | 258 | return 0; |
michael@0 | 259 | } |
michael@0 | 260 | uint64_t |
michael@0 | 261 | DummyAccessible::NativeInteractiveState() const |
michael@0 | 262 | { |
michael@0 | 263 | return 0; |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | uint64_t |
michael@0 | 267 | DummyAccessible::NativeLinkState() const |
michael@0 | 268 | { |
michael@0 | 269 | return 0; |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | bool |
michael@0 | 273 | DummyAccessible::NativelyUnavailable() const |
michael@0 | 274 | { |
michael@0 | 275 | return false; |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | void |
michael@0 | 279 | DummyAccessible::ApplyARIAState(uint64_t* aState) const |
michael@0 | 280 | { |
michael@0 | 281 | } |