Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; 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 "HTMLSelectAccessible.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "Accessible-inl.h" |
michael@0 | 9 | #include "nsAccessibilityService.h" |
michael@0 | 10 | #include "nsAccUtils.h" |
michael@0 | 11 | #include "DocAccessible.h" |
michael@0 | 12 | #include "nsEventShell.h" |
michael@0 | 13 | #include "nsIAccessibleEvent.h" |
michael@0 | 14 | #include "nsTextEquivUtils.h" |
michael@0 | 15 | #include "Role.h" |
michael@0 | 16 | #include "States.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "nsCOMPtr.h" |
michael@0 | 19 | #include "mozilla/dom/HTMLOptionElement.h" |
michael@0 | 20 | #include "nsIComboboxControlFrame.h" |
michael@0 | 21 | #include "nsIFrame.h" |
michael@0 | 22 | #include "nsIListControlFrame.h" |
michael@0 | 23 | |
michael@0 | 24 | using namespace mozilla::a11y; |
michael@0 | 25 | using namespace mozilla::dom; |
michael@0 | 26 | |
michael@0 | 27 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 28 | // HTMLSelectListAccessible |
michael@0 | 29 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 30 | |
michael@0 | 31 | HTMLSelectListAccessible:: |
michael@0 | 32 | HTMLSelectListAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 33 | AccessibleWrap(aContent, aDoc) |
michael@0 | 34 | { |
michael@0 | 35 | mGenericTypes |= eListControl | eSelect; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 39 | // HTMLSelectListAccessible: Accessible public |
michael@0 | 40 | |
michael@0 | 41 | uint64_t |
michael@0 | 42 | HTMLSelectListAccessible::NativeState() |
michael@0 | 43 | { |
michael@0 | 44 | uint64_t state = AccessibleWrap::NativeState(); |
michael@0 | 45 | if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple)) |
michael@0 | 46 | state |= states::MULTISELECTABLE | states::EXTSELECTABLE; |
michael@0 | 47 | |
michael@0 | 48 | return state; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | role |
michael@0 | 52 | HTMLSelectListAccessible::NativeRole() |
michael@0 | 53 | { |
michael@0 | 54 | return roles::LISTBOX; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 58 | // HTMLSelectListAccessible: SelectAccessible |
michael@0 | 59 | |
michael@0 | 60 | bool |
michael@0 | 61 | HTMLSelectListAccessible::SelectAll() |
michael@0 | 62 | { |
michael@0 | 63 | return mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple) ? |
michael@0 | 64 | AccessibleWrap::SelectAll() : false; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | bool |
michael@0 | 68 | HTMLSelectListAccessible::UnselectAll() |
michael@0 | 69 | { |
michael@0 | 70 | return mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple) ? |
michael@0 | 71 | AccessibleWrap::UnselectAll() : false; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 75 | // HTMLSelectListAccessible: Widgets |
michael@0 | 76 | |
michael@0 | 77 | bool |
michael@0 | 78 | HTMLSelectListAccessible::IsWidget() const |
michael@0 | 79 | { |
michael@0 | 80 | return true; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | bool |
michael@0 | 84 | HTMLSelectListAccessible::IsActiveWidget() const |
michael@0 | 85 | { |
michael@0 | 86 | return FocusMgr()->HasDOMFocus(mContent); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | bool |
michael@0 | 90 | HTMLSelectListAccessible::AreItemsOperable() const |
michael@0 | 91 | { |
michael@0 | 92 | return true; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | Accessible* |
michael@0 | 96 | HTMLSelectListAccessible::CurrentItem() |
michael@0 | 97 | { |
michael@0 | 98 | nsIListControlFrame* listControlFrame = do_QueryFrame(GetFrame()); |
michael@0 | 99 | if (listControlFrame) { |
michael@0 | 100 | nsCOMPtr<nsIContent> activeOptionNode = listControlFrame->GetCurrentOption(); |
michael@0 | 101 | if (activeOptionNode) { |
michael@0 | 102 | DocAccessible* document = Document(); |
michael@0 | 103 | if (document) |
michael@0 | 104 | return document->GetAccessible(activeOptionNode); |
michael@0 | 105 | } |
michael@0 | 106 | } |
michael@0 | 107 | return nullptr; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | void |
michael@0 | 111 | HTMLSelectListAccessible::SetCurrentItem(Accessible* aItem) |
michael@0 | 112 | { |
michael@0 | 113 | aItem->GetContent()->SetAttr(kNameSpaceID_None, |
michael@0 | 114 | nsGkAtoms::selected, NS_LITERAL_STRING("true"), |
michael@0 | 115 | true); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 119 | // HTMLSelectListAccessible: Accessible protected |
michael@0 | 120 | |
michael@0 | 121 | void |
michael@0 | 122 | HTMLSelectListAccessible::CacheChildren() |
michael@0 | 123 | { |
michael@0 | 124 | // Cache accessibles for <optgroup> and <option> DOM decendents as children, |
michael@0 | 125 | // as well as the accessibles for them. Avoid whitespace text nodes. We want |
michael@0 | 126 | // to count all the <optgroup>s and <option>s as children because we want |
michael@0 | 127 | // a flat tree under the Select List. |
michael@0 | 128 | for (nsIContent* childContent = mContent->GetFirstChild(); childContent; |
michael@0 | 129 | childContent = childContent->GetNextSibling()) { |
michael@0 | 130 | if (!childContent->IsHTML()) { |
michael@0 | 131 | continue; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | nsIAtom* tag = childContent->Tag(); |
michael@0 | 135 | if (tag == nsGkAtoms::option || |
michael@0 | 136 | tag == nsGkAtoms::optgroup) { |
michael@0 | 137 | |
michael@0 | 138 | // Get an accessible for option or optgroup and cache it. |
michael@0 | 139 | nsRefPtr<Accessible> accessible = |
michael@0 | 140 | GetAccService()->GetOrCreateAccessible(childContent, this); |
michael@0 | 141 | if (accessible) |
michael@0 | 142 | AppendChild(accessible); |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | |
michael@0 | 148 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 149 | // HTMLSelectOptionAccessible |
michael@0 | 150 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 151 | |
michael@0 | 152 | HTMLSelectOptionAccessible:: |
michael@0 | 153 | HTMLSelectOptionAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 154 | HyperTextAccessibleWrap(aContent, aDoc) |
michael@0 | 155 | { |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 159 | // HTMLSelectOptionAccessible: Accessible public |
michael@0 | 160 | |
michael@0 | 161 | role |
michael@0 | 162 | HTMLSelectOptionAccessible::NativeRole() |
michael@0 | 163 | { |
michael@0 | 164 | if (GetCombobox()) |
michael@0 | 165 | return roles::COMBOBOX_OPTION; |
michael@0 | 166 | |
michael@0 | 167 | return roles::OPTION; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | ENameValueFlag |
michael@0 | 171 | HTMLSelectOptionAccessible::NativeName(nsString& aName) |
michael@0 | 172 | { |
michael@0 | 173 | // CASE #1 -- great majority of the cases |
michael@0 | 174 | // find the label attribute - this is what the W3C says we should use |
michael@0 | 175 | mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName); |
michael@0 | 176 | if (!aName.IsEmpty()) |
michael@0 | 177 | return eNameOK; |
michael@0 | 178 | |
michael@0 | 179 | // CASE #2 -- no label parameter, get the first child, |
michael@0 | 180 | // use it if it is a text node |
michael@0 | 181 | nsIContent* text = mContent->GetFirstChild(); |
michael@0 | 182 | if (text && text->IsNodeOfType(nsINode::eTEXT)) { |
michael@0 | 183 | nsTextEquivUtils::AppendTextEquivFromTextContent(text, &aName); |
michael@0 | 184 | aName.CompressWhitespace(); |
michael@0 | 185 | return aName.IsEmpty() ? eNameOK : eNameFromSubtree; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | return eNameOK; |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | uint64_t |
michael@0 | 192 | HTMLSelectOptionAccessible::NativeState() |
michael@0 | 193 | { |
michael@0 | 194 | // As a HTMLSelectOptionAccessible we can have the following states: |
michael@0 | 195 | // SELECTABLE, SELECTED, FOCUSED, FOCUSABLE, OFFSCREEN |
michael@0 | 196 | // Upcall to Accessible, but skip HyperTextAccessible impl |
michael@0 | 197 | // because we don't want EDITABLE or SELECTABLE_TEXT |
michael@0 | 198 | uint64_t state = Accessible::NativeState(); |
michael@0 | 199 | |
michael@0 | 200 | Accessible* select = GetSelect(); |
michael@0 | 201 | if (!select) |
michael@0 | 202 | return state; |
michael@0 | 203 | |
michael@0 | 204 | uint64_t selectState = select->State(); |
michael@0 | 205 | if (selectState & states::INVISIBLE) |
michael@0 | 206 | return state; |
michael@0 | 207 | |
michael@0 | 208 | // Are we selected? |
michael@0 | 209 | HTMLOptionElement* option = HTMLOptionElement::FromContent(mContent); |
michael@0 | 210 | bool selected = option && option->Selected(); |
michael@0 | 211 | if (selected) |
michael@0 | 212 | state |= states::SELECTED; |
michael@0 | 213 | |
michael@0 | 214 | if (selectState & states::OFFSCREEN) { |
michael@0 | 215 | state |= states::OFFSCREEN; |
michael@0 | 216 | } else if (selectState & states::COLLAPSED) { |
michael@0 | 217 | // <select> is COLLAPSED: add OFFSCREEN, if not the currently |
michael@0 | 218 | // visible option |
michael@0 | 219 | if (!selected) { |
michael@0 | 220 | state |= states::OFFSCREEN; |
michael@0 | 221 | state ^= states::INVISIBLE; |
michael@0 | 222 | } else { |
michael@0 | 223 | // Clear offscreen and invisible for currently showing option |
michael@0 | 224 | state &= ~(states::OFFSCREEN | states::INVISIBLE); |
michael@0 | 225 | state |= selectState & states::OPAQUE1; |
michael@0 | 226 | } |
michael@0 | 227 | } else { |
michael@0 | 228 | // XXX list frames are weird, don't rely on Accessible's general |
michael@0 | 229 | // visibility implementation unless they get reimplemented in layout |
michael@0 | 230 | state &= ~states::OFFSCREEN; |
michael@0 | 231 | // <select> is not collapsed: compare bounds to calculate OFFSCREEN |
michael@0 | 232 | Accessible* listAcc = Parent(); |
michael@0 | 233 | if (listAcc) { |
michael@0 | 234 | int32_t optionX, optionY, optionWidth, optionHeight; |
michael@0 | 235 | int32_t listX, listY, listWidth, listHeight; |
michael@0 | 236 | GetBounds(&optionX, &optionY, &optionWidth, &optionHeight); |
michael@0 | 237 | listAcc->GetBounds(&listX, &listY, &listWidth, &listHeight); |
michael@0 | 238 | if (optionY < listY || optionY + optionHeight > listY + listHeight) { |
michael@0 | 239 | state |= states::OFFSCREEN; |
michael@0 | 240 | } |
michael@0 | 241 | } |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | return state; |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | uint64_t |
michael@0 | 248 | HTMLSelectOptionAccessible::NativeInteractiveState() const |
michael@0 | 249 | { |
michael@0 | 250 | return NativelyUnavailable() ? |
michael@0 | 251 | states::UNAVAILABLE : states::FOCUSABLE | states::SELECTABLE; |
michael@0 | 252 | } |
michael@0 | 253 | |
michael@0 | 254 | int32_t |
michael@0 | 255 | HTMLSelectOptionAccessible::GetLevelInternal() |
michael@0 | 256 | { |
michael@0 | 257 | nsIContent* parentContent = mContent->GetParent(); |
michael@0 | 258 | |
michael@0 | 259 | int32_t level = |
michael@0 | 260 | parentContent->NodeInfo()->Equals(nsGkAtoms::optgroup) ? 2 : 1; |
michael@0 | 261 | |
michael@0 | 262 | if (level == 1 && Role() != roles::HEADING) |
michael@0 | 263 | level = 0; // In a single level list, the level is irrelevant |
michael@0 | 264 | |
michael@0 | 265 | return level; |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | void |
michael@0 | 269 | HTMLSelectOptionAccessible::GetBoundsRect(nsRect& aTotalBounds, |
michael@0 | 270 | nsIFrame** aBoundingFrame) |
michael@0 | 271 | { |
michael@0 | 272 | Accessible* combobox = GetCombobox(); |
michael@0 | 273 | if (combobox && (combobox->State() & states::COLLAPSED)) |
michael@0 | 274 | combobox->GetBoundsRect(aTotalBounds, aBoundingFrame); |
michael@0 | 275 | else |
michael@0 | 276 | HyperTextAccessibleWrap::GetBoundsRect(aTotalBounds, aBoundingFrame); |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | NS_IMETHODIMP |
michael@0 | 280 | HTMLSelectOptionAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 281 | { |
michael@0 | 282 | if (aIndex == eAction_Select) { |
michael@0 | 283 | aName.AssignLiteral("select"); |
michael@0 | 284 | return NS_OK; |
michael@0 | 285 | } |
michael@0 | 286 | return NS_ERROR_INVALID_ARG; |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | uint8_t |
michael@0 | 290 | HTMLSelectOptionAccessible::ActionCount() |
michael@0 | 291 | { |
michael@0 | 292 | return 1; |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | NS_IMETHODIMP |
michael@0 | 296 | HTMLSelectOptionAccessible::DoAction(uint8_t aIndex) |
michael@0 | 297 | { |
michael@0 | 298 | if (aIndex != eAction_Select) |
michael@0 | 299 | return NS_ERROR_INVALID_ARG; |
michael@0 | 300 | |
michael@0 | 301 | if (IsDefunct()) |
michael@0 | 302 | return NS_ERROR_FAILURE; |
michael@0 | 303 | |
michael@0 | 304 | DoCommand(); |
michael@0 | 305 | return NS_OK; |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | NS_IMETHODIMP |
michael@0 | 309 | HTMLSelectOptionAccessible::SetSelected(bool aSelect) |
michael@0 | 310 | { |
michael@0 | 311 | if (IsDefunct()) |
michael@0 | 312 | return NS_ERROR_FAILURE; |
michael@0 | 313 | |
michael@0 | 314 | HTMLOptionElement* option = HTMLOptionElement::FromContent(mContent); |
michael@0 | 315 | return option ? option->SetSelected(aSelect) : NS_ERROR_FAILURE; |
michael@0 | 316 | } |
michael@0 | 317 | |
michael@0 | 318 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 319 | // HTMLSelectOptionAccessible: Widgets |
michael@0 | 320 | |
michael@0 | 321 | Accessible* |
michael@0 | 322 | HTMLSelectOptionAccessible::ContainerWidget() const |
michael@0 | 323 | { |
michael@0 | 324 | Accessible* parent = Parent(); |
michael@0 | 325 | if (parent && parent->IsHTMLOptGroup()) |
michael@0 | 326 | parent = parent->Parent(); |
michael@0 | 327 | |
michael@0 | 328 | return parent && parent->IsListControl() ? parent : nullptr; |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 332 | // HTMLSelectOptGroupAccessible |
michael@0 | 333 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 334 | |
michael@0 | 335 | role |
michael@0 | 336 | HTMLSelectOptGroupAccessible::NativeRole() |
michael@0 | 337 | { |
michael@0 | 338 | return roles::GROUPING; |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | uint64_t |
michael@0 | 342 | HTMLSelectOptGroupAccessible::NativeInteractiveState() const |
michael@0 | 343 | { |
michael@0 | 344 | return NativelyUnavailable() ? states::UNAVAILABLE : 0; |
michael@0 | 345 | } |
michael@0 | 346 | |
michael@0 | 347 | NS_IMETHODIMP |
michael@0 | 348 | HTMLSelectOptGroupAccessible::DoAction(uint8_t index) |
michael@0 | 349 | { |
michael@0 | 350 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | NS_IMETHODIMP |
michael@0 | 354 | HTMLSelectOptGroupAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 355 | { |
michael@0 | 356 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | uint8_t |
michael@0 | 360 | HTMLSelectOptGroupAccessible::ActionCount() |
michael@0 | 361 | { |
michael@0 | 362 | return 0; |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 366 | // HTMLComboboxAccessible |
michael@0 | 367 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 368 | |
michael@0 | 369 | HTMLComboboxAccessible:: |
michael@0 | 370 | HTMLComboboxAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 371 | AccessibleWrap(aContent, aDoc) |
michael@0 | 372 | { |
michael@0 | 373 | mGenericTypes |= eCombobox; |
michael@0 | 374 | } |
michael@0 | 375 | |
michael@0 | 376 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 377 | // HTMLComboboxAccessible: Accessible |
michael@0 | 378 | |
michael@0 | 379 | role |
michael@0 | 380 | HTMLComboboxAccessible::NativeRole() |
michael@0 | 381 | { |
michael@0 | 382 | return roles::COMBOBOX; |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | void |
michael@0 | 386 | HTMLComboboxAccessible::InvalidateChildren() |
michael@0 | 387 | { |
michael@0 | 388 | AccessibleWrap::InvalidateChildren(); |
michael@0 | 389 | |
michael@0 | 390 | if (mListAccessible) |
michael@0 | 391 | mListAccessible->InvalidateChildren(); |
michael@0 | 392 | } |
michael@0 | 393 | |
michael@0 | 394 | void |
michael@0 | 395 | HTMLComboboxAccessible::CacheChildren() |
michael@0 | 396 | { |
michael@0 | 397 | nsIComboboxControlFrame* comboFrame = do_QueryFrame(GetFrame()); |
michael@0 | 398 | if (!comboFrame) |
michael@0 | 399 | return; |
michael@0 | 400 | |
michael@0 | 401 | nsIFrame* listFrame = comboFrame->GetDropDown(); |
michael@0 | 402 | if (!listFrame) |
michael@0 | 403 | return; |
michael@0 | 404 | |
michael@0 | 405 | if (!mListAccessible) { |
michael@0 | 406 | mListAccessible = |
michael@0 | 407 | new HTMLComboboxListAccessible(mParent, mContent, mDoc); |
michael@0 | 408 | |
michael@0 | 409 | // Initialize and put into cache. |
michael@0 | 410 | Document()->BindToDocument(mListAccessible, nullptr); |
michael@0 | 411 | } |
michael@0 | 412 | |
michael@0 | 413 | if (AppendChild(mListAccessible)) { |
michael@0 | 414 | // Cache combobox option accessibles so that we build complete accessible |
michael@0 | 415 | // tree for combobox. |
michael@0 | 416 | mListAccessible->EnsureChildren(); |
michael@0 | 417 | } |
michael@0 | 418 | } |
michael@0 | 419 | |
michael@0 | 420 | void |
michael@0 | 421 | HTMLComboboxAccessible::Shutdown() |
michael@0 | 422 | { |
michael@0 | 423 | AccessibleWrap::Shutdown(); |
michael@0 | 424 | |
michael@0 | 425 | if (mListAccessible) { |
michael@0 | 426 | mListAccessible->Shutdown(); |
michael@0 | 427 | mListAccessible = nullptr; |
michael@0 | 428 | } |
michael@0 | 429 | } |
michael@0 | 430 | |
michael@0 | 431 | uint64_t |
michael@0 | 432 | HTMLComboboxAccessible::NativeState() |
michael@0 | 433 | { |
michael@0 | 434 | // As a HTMLComboboxAccessible we can have the following states: |
michael@0 | 435 | // FOCUSED, FOCUSABLE, HASPOPUP, EXPANDED, COLLAPSED |
michael@0 | 436 | // Get focus status from base class |
michael@0 | 437 | uint64_t state = Accessible::NativeState(); |
michael@0 | 438 | |
michael@0 | 439 | nsIComboboxControlFrame* comboFrame = do_QueryFrame(GetFrame()); |
michael@0 | 440 | if (comboFrame && comboFrame->IsDroppedDown()) |
michael@0 | 441 | state |= states::EXPANDED; |
michael@0 | 442 | else |
michael@0 | 443 | state |= states::COLLAPSED; |
michael@0 | 444 | |
michael@0 | 445 | state |= states::HASPOPUP; |
michael@0 | 446 | return state; |
michael@0 | 447 | } |
michael@0 | 448 | |
michael@0 | 449 | void |
michael@0 | 450 | HTMLComboboxAccessible::Description(nsString& aDescription) |
michael@0 | 451 | { |
michael@0 | 452 | aDescription.Truncate(); |
michael@0 | 453 | // First check to see if combo box itself has a description, perhaps through |
michael@0 | 454 | // tooltip (title attribute) or via aria-describedby |
michael@0 | 455 | Accessible::Description(aDescription); |
michael@0 | 456 | if (!aDescription.IsEmpty()) |
michael@0 | 457 | return; |
michael@0 | 458 | |
michael@0 | 459 | // Otherwise use description of selected option. |
michael@0 | 460 | Accessible* option = SelectedOption(); |
michael@0 | 461 | if (option) |
michael@0 | 462 | option->Description(aDescription); |
michael@0 | 463 | } |
michael@0 | 464 | |
michael@0 | 465 | void |
michael@0 | 466 | HTMLComboboxAccessible::Value(nsString& aValue) |
michael@0 | 467 | { |
michael@0 | 468 | // Use accessible name of selected option. |
michael@0 | 469 | Accessible* option = SelectedOption(); |
michael@0 | 470 | if (option) |
michael@0 | 471 | option->Name(aValue); |
michael@0 | 472 | } |
michael@0 | 473 | |
michael@0 | 474 | uint8_t |
michael@0 | 475 | HTMLComboboxAccessible::ActionCount() |
michael@0 | 476 | { |
michael@0 | 477 | return 1; |
michael@0 | 478 | } |
michael@0 | 479 | |
michael@0 | 480 | NS_IMETHODIMP |
michael@0 | 481 | HTMLComboboxAccessible::DoAction(uint8_t aIndex) |
michael@0 | 482 | { |
michael@0 | 483 | if (aIndex != eAction_Click) |
michael@0 | 484 | return NS_ERROR_INVALID_ARG; |
michael@0 | 485 | |
michael@0 | 486 | if (IsDefunct()) |
michael@0 | 487 | return NS_ERROR_FAILURE; |
michael@0 | 488 | |
michael@0 | 489 | DoCommand(); |
michael@0 | 490 | return NS_OK; |
michael@0 | 491 | } |
michael@0 | 492 | |
michael@0 | 493 | /** |
michael@0 | 494 | * Our action name is the reverse of our state: |
michael@0 | 495 | * if we are closed -> open is our name. |
michael@0 | 496 | * if we are open -> closed is our name. |
michael@0 | 497 | * Uses the frame to get the state, updated on every click |
michael@0 | 498 | */ |
michael@0 | 499 | NS_IMETHODIMP |
michael@0 | 500 | HTMLComboboxAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 501 | { |
michael@0 | 502 | if (aIndex != HTMLComboboxAccessible::eAction_Click) { |
michael@0 | 503 | return NS_ERROR_INVALID_ARG; |
michael@0 | 504 | } |
michael@0 | 505 | nsIComboboxControlFrame* comboFrame = do_QueryFrame(GetFrame()); |
michael@0 | 506 | if (!comboFrame) { |
michael@0 | 507 | return NS_ERROR_FAILURE; |
michael@0 | 508 | } |
michael@0 | 509 | if (comboFrame->IsDroppedDown()) |
michael@0 | 510 | aName.AssignLiteral("close"); |
michael@0 | 511 | else |
michael@0 | 512 | aName.AssignLiteral("open"); |
michael@0 | 513 | |
michael@0 | 514 | return NS_OK; |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 518 | // HTMLComboboxAccessible: Widgets |
michael@0 | 519 | |
michael@0 | 520 | bool |
michael@0 | 521 | HTMLComboboxAccessible::IsWidget() const |
michael@0 | 522 | { |
michael@0 | 523 | return true; |
michael@0 | 524 | } |
michael@0 | 525 | |
michael@0 | 526 | bool |
michael@0 | 527 | HTMLComboboxAccessible::IsActiveWidget() const |
michael@0 | 528 | { |
michael@0 | 529 | return FocusMgr()->HasDOMFocus(mContent); |
michael@0 | 530 | } |
michael@0 | 531 | |
michael@0 | 532 | bool |
michael@0 | 533 | HTMLComboboxAccessible::AreItemsOperable() const |
michael@0 | 534 | { |
michael@0 | 535 | nsIComboboxControlFrame* comboboxFrame = do_QueryFrame(GetFrame()); |
michael@0 | 536 | return comboboxFrame && comboboxFrame->IsDroppedDown(); |
michael@0 | 537 | } |
michael@0 | 538 | |
michael@0 | 539 | Accessible* |
michael@0 | 540 | HTMLComboboxAccessible::CurrentItem() |
michael@0 | 541 | { |
michael@0 | 542 | return AreItemsOperable() ? mListAccessible->CurrentItem() : nullptr; |
michael@0 | 543 | } |
michael@0 | 544 | |
michael@0 | 545 | void |
michael@0 | 546 | HTMLComboboxAccessible::SetCurrentItem(Accessible* aItem) |
michael@0 | 547 | { |
michael@0 | 548 | if (AreItemsOperable()) |
michael@0 | 549 | mListAccessible->SetCurrentItem(aItem); |
michael@0 | 550 | } |
michael@0 | 551 | |
michael@0 | 552 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 553 | // HTMLComboboxAccessible: protected |
michael@0 | 554 | |
michael@0 | 555 | Accessible* |
michael@0 | 556 | HTMLComboboxAccessible::SelectedOption() const |
michael@0 | 557 | { |
michael@0 | 558 | nsIFrame* frame = GetFrame(); |
michael@0 | 559 | nsIComboboxControlFrame* comboboxFrame = do_QueryFrame(frame); |
michael@0 | 560 | if (!comboboxFrame) |
michael@0 | 561 | return nullptr; |
michael@0 | 562 | |
michael@0 | 563 | nsIListControlFrame* listControlFrame = |
michael@0 | 564 | do_QueryFrame(comboboxFrame->GetDropDown()); |
michael@0 | 565 | if (listControlFrame) { |
michael@0 | 566 | nsCOMPtr<nsIContent> activeOptionNode = listControlFrame->GetCurrentOption(); |
michael@0 | 567 | if (activeOptionNode) { |
michael@0 | 568 | DocAccessible* document = Document(); |
michael@0 | 569 | if (document) |
michael@0 | 570 | return document->GetAccessible(activeOptionNode); |
michael@0 | 571 | } |
michael@0 | 572 | } |
michael@0 | 573 | |
michael@0 | 574 | return nullptr; |
michael@0 | 575 | } |
michael@0 | 576 | |
michael@0 | 577 | |
michael@0 | 578 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 579 | // HTMLComboboxListAccessible |
michael@0 | 580 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 581 | |
michael@0 | 582 | HTMLComboboxListAccessible:: |
michael@0 | 583 | HTMLComboboxListAccessible(nsIAccessible* aParent, nsIContent* aContent, |
michael@0 | 584 | DocAccessible* aDoc) : |
michael@0 | 585 | HTMLSelectListAccessible(aContent, aDoc) |
michael@0 | 586 | { |
michael@0 | 587 | mStateFlags |= eSharedNode; |
michael@0 | 588 | } |
michael@0 | 589 | |
michael@0 | 590 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 591 | // HTMLComboboxAccessible: Accessible |
michael@0 | 592 | |
michael@0 | 593 | nsIFrame* |
michael@0 | 594 | HTMLComboboxListAccessible::GetFrame() const |
michael@0 | 595 | { |
michael@0 | 596 | nsIFrame* frame = HTMLSelectListAccessible::GetFrame(); |
michael@0 | 597 | nsIComboboxControlFrame* comboBox = do_QueryFrame(frame); |
michael@0 | 598 | if (comboBox) { |
michael@0 | 599 | return comboBox->GetDropDown(); |
michael@0 | 600 | } |
michael@0 | 601 | |
michael@0 | 602 | return nullptr; |
michael@0 | 603 | } |
michael@0 | 604 | |
michael@0 | 605 | role |
michael@0 | 606 | HTMLComboboxListAccessible::NativeRole() |
michael@0 | 607 | { |
michael@0 | 608 | return roles::COMBOBOX_LIST; |
michael@0 | 609 | } |
michael@0 | 610 | |
michael@0 | 611 | uint64_t |
michael@0 | 612 | HTMLComboboxListAccessible::NativeState() |
michael@0 | 613 | { |
michael@0 | 614 | // As a HTMLComboboxListAccessible we can have the following states: |
michael@0 | 615 | // FOCUSED, FOCUSABLE, FLOATING, INVISIBLE |
michael@0 | 616 | // Get focus status from base class |
michael@0 | 617 | uint64_t state = Accessible::NativeState(); |
michael@0 | 618 | |
michael@0 | 619 | nsIComboboxControlFrame* comboFrame = do_QueryFrame(mParent->GetFrame()); |
michael@0 | 620 | if (comboFrame && comboFrame->IsDroppedDown()) |
michael@0 | 621 | state |= states::FLOATING; |
michael@0 | 622 | else |
michael@0 | 623 | state |= states::INVISIBLE; |
michael@0 | 624 | |
michael@0 | 625 | return state; |
michael@0 | 626 | } |
michael@0 | 627 | |
michael@0 | 628 | /** |
michael@0 | 629 | * Gets the bounds for the areaFrame. |
michael@0 | 630 | * Walks the Frame tree and checks for proper frames. |
michael@0 | 631 | */ |
michael@0 | 632 | void |
michael@0 | 633 | HTMLComboboxListAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame) |
michael@0 | 634 | { |
michael@0 | 635 | *aBoundingFrame = nullptr; |
michael@0 | 636 | |
michael@0 | 637 | Accessible* comboAcc = Parent(); |
michael@0 | 638 | if (!comboAcc) |
michael@0 | 639 | return; |
michael@0 | 640 | |
michael@0 | 641 | if (0 == (comboAcc->State() & states::COLLAPSED)) { |
michael@0 | 642 | HTMLSelectListAccessible::GetBoundsRect(aBounds, aBoundingFrame); |
michael@0 | 643 | return; |
michael@0 | 644 | } |
michael@0 | 645 | |
michael@0 | 646 | // Get the first option. |
michael@0 | 647 | nsIContent* content = mContent->GetFirstChild(); |
michael@0 | 648 | if (!content) { |
michael@0 | 649 | return; |
michael@0 | 650 | } |
michael@0 | 651 | nsIFrame* frame = content->GetPrimaryFrame(); |
michael@0 | 652 | if (!frame) { |
michael@0 | 653 | *aBoundingFrame = nullptr; |
michael@0 | 654 | return; |
michael@0 | 655 | } |
michael@0 | 656 | |
michael@0 | 657 | *aBoundingFrame = frame->GetParent(); |
michael@0 | 658 | aBounds = (*aBoundingFrame)->GetRect(); |
michael@0 | 659 | } |
michael@0 | 660 | |
michael@0 | 661 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 662 | // HTMLComboboxListAccessible: Widgets |
michael@0 | 663 | |
michael@0 | 664 | bool |
michael@0 | 665 | HTMLComboboxListAccessible::IsActiveWidget() const |
michael@0 | 666 | { |
michael@0 | 667 | return mParent && mParent->IsActiveWidget(); |
michael@0 | 668 | } |
michael@0 | 669 | |
michael@0 | 670 | bool |
michael@0 | 671 | HTMLComboboxListAccessible::AreItemsOperable() const |
michael@0 | 672 | { |
michael@0 | 673 | return mParent && mParent->AreItemsOperable(); |
michael@0 | 674 | } |
michael@0 | 675 |