| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 14 * its contributors may be used to endorse or promote products derived | 14 * its contributors may be used to endorse or promote products derived |
| 15 * from this software without specific prior written permission. | 15 * from this software without specific prior written permission. |
| 16 * | 16 * |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "modules/accessibility/AXObjectImpl.h" | 29 #include "modules/accessibility/AXObject.h" |
| 30 | 30 |
| 31 #include "SkMatrix44.h" | 31 #include "SkMatrix44.h" |
| 32 #include "core/InputTypeNames.h" | 32 #include "core/InputTypeNames.h" |
| 33 #include "core/css/resolver/StyleResolver.h" | 33 #include "core/css/resolver/StyleResolver.h" |
| 34 #include "core/dom/AccessibleNode.h" | 34 #include "core/dom/AccessibleNode.h" |
| 35 #include "core/dom/DocumentUserGestureToken.h" | 35 #include "core/dom/DocumentUserGestureToken.h" |
| 36 #include "core/editing/EditingUtilities.h" | 36 #include "core/editing/EditingUtilities.h" |
| 37 #include "core/editing/VisibleUnits.h" | 37 #include "core/editing/VisibleUnits.h" |
| 38 #include "core/frame/FrameView.h" | 38 #include "core/frame/FrameView.h" |
| 39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kRoles); ++i) | 284 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kRoles); ++i) |
| 285 role_map->Set(String(kRoles[i].aria_role), kRoles[i].webcore_role); | 285 role_map->Set(String(kRoles[i].aria_role), kRoles[i].webcore_role); |
| 286 return role_map; | 286 return role_map; |
| 287 } | 287 } |
| 288 | 288 |
| 289 static Vector<AtomicString>* CreateRoleNameVector() { | 289 static Vector<AtomicString>* CreateRoleNameVector() { |
| 290 Vector<AtomicString>* role_name_vector = new Vector<AtomicString>(kNumRoles); | 290 Vector<AtomicString>* role_name_vector = new Vector<AtomicString>(kNumRoles); |
| 291 for (int i = 0; i < kNumRoles; i++) | 291 for (int i = 0; i < kNumRoles; i++) |
| 292 (*role_name_vector)[i] = g_null_atom; | 292 (*role_name_vector)[i] = g_null_atom; |
| 293 | 293 |
| 294 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kRoles); ++i) { | 294 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kRoles); ++i) |
| 295 (*role_name_vector)[kRoles[i].webcore_role] = | 295 (*role_name_vector)[kRoles[i].webcore_role] = |
| 296 AtomicString(kRoles[i].aria_role); | 296 AtomicString(kRoles[i].aria_role); |
| 297 } | |
| 298 | 297 |
| 299 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kReverseRoles); ++i) { | 298 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kReverseRoles); ++i) |
| 300 (*role_name_vector)[kReverseRoles[i].webcore_role] = | 299 (*role_name_vector)[kReverseRoles[i].webcore_role] = |
| 301 AtomicString(kReverseRoles[i].aria_role); | 300 AtomicString(kReverseRoles[i].aria_role); |
| 302 } | |
| 303 | 301 |
| 304 return role_name_vector; | 302 return role_name_vector; |
| 305 } | 303 } |
| 306 | 304 |
| 307 static Vector<AtomicString>* CreateInternalRoleNameVector() { | 305 static Vector<AtomicString>* CreateInternalRoleNameVector() { |
| 308 Vector<AtomicString>* internal_role_name_vector = | 306 Vector<AtomicString>* internal_role_name_vector = |
| 309 new Vector<AtomicString>(kNumRoles); | 307 new Vector<AtomicString>(kNumRoles); |
| 310 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kInternalRoles); i++) { | 308 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kInternalRoles); i++) |
| 311 (*internal_role_name_vector)[kInternalRoles[i].webcore_role] = | 309 (*internal_role_name_vector)[kInternalRoles[i].webcore_role] = |
| 312 AtomicString(kInternalRoles[i].internal_role_name); | 310 AtomicString(kInternalRoles[i].internal_role_name); |
| 313 } | |
| 314 | 311 |
| 315 return internal_role_name_vector; | 312 return internal_role_name_vector; |
| 316 } | 313 } |
| 317 | 314 |
| 318 const char* g_aria_widgets[] = { | 315 const char* g_aria_widgets[] = { |
| 319 // From http://www.w3.org/TR/wai-aria/roles#widget_roles | 316 // From http://www.w3.org/TR/wai-aria/roles#widget_roles |
| 320 "alert", "alertdialog", "button", "checkbox", "dialog", "gridcell", "link", | 317 "alert", "alertdialog", "button", "checkbox", "dialog", "gridcell", "link", |
| 321 "log", "marquee", "menuitem", "menuitemcheckbox", "menuitemradio", "option", | 318 "log", "marquee", "menuitem", "menuitemcheckbox", "menuitemradio", "option", |
| 322 "progressbar", "radio", "scrollbar", "slider", "spinbutton", "status", | 319 "progressbar", "radio", "scrollbar", "slider", "spinbutton", "status", |
| 323 "tab", "tabpanel", "textbox", "timer", "tooltip", "treeitem", | 320 "tab", "tabpanel", "textbox", "timer", "tooltip", "treeitem", |
| (...skipping 16 matching lines...) Expand all Loading... |
| 340 "aria-disabled", // If it's disabled, it can be made interactive. | 337 "aria-disabled", // If it's disabled, it can be made interactive. |
| 341 "aria-expanded", "aria-haspopup", "aria-multiselectable", | 338 "aria-expanded", "aria-haspopup", "aria-multiselectable", |
| 342 "aria-pressed", "aria-required", "aria-selected"}; | 339 "aria-pressed", "aria-required", "aria-selected"}; |
| 343 | 340 |
| 344 HTMLDialogElement* GetActiveDialogElement(Node* node) { | 341 HTMLDialogElement* GetActiveDialogElement(Node* node) { |
| 345 return node->GetDocument().ActiveModalDialog(); | 342 return node->GetDocument().ActiveModalDialog(); |
| 346 } | 343 } |
| 347 | 344 |
| 348 } // namespace | 345 } // namespace |
| 349 | 346 |
| 350 unsigned AXObjectImpl::number_of_live_ax_objects_ = 0; | 347 unsigned AXObject::number_of_live_ax_objects_ = 0; |
| 351 | 348 |
| 352 AXObjectImpl::AXObjectImpl(AXObjectCacheImpl& ax_object_cache) | 349 AXObject::AXObject(AXObjectCacheImpl& ax_object_cache) |
| 353 : id_(0), | 350 : id_(0), |
| 354 have_children_(false), | 351 have_children_(false), |
| 355 role_(kUnknownRole), | 352 role_(kUnknownRole), |
| 356 last_known_is_ignored_value_(kDefaultBehavior), | 353 last_known_is_ignored_value_(kDefaultBehavior), |
| 357 explicit_container_id_(0), | 354 explicit_container_id_(0), |
| 358 parent_(nullptr), | 355 parent_(nullptr), |
| 359 last_modification_count_(-1), | 356 last_modification_count_(-1), |
| 360 cached_is_ignored_(false), | 357 cached_is_ignored_(false), |
| 361 cached_is_inert_or_aria_hidden_(false), | 358 cached_is_inert_or_aria_hidden_(false), |
| 362 cached_is_descendant_of_leaf_node_(false), | 359 cached_is_descendant_of_leaf_node_(false), |
| 363 cached_is_descendant_of_disabled_node_(false), | 360 cached_is_descendant_of_disabled_node_(false), |
| 364 cached_has_inherited_presentational_role_(false), | 361 cached_has_inherited_presentational_role_(false), |
| 365 cached_is_presentational_child_(false), | 362 cached_is_presentational_child_(false), |
| 366 cached_ancestor_exposes_active_descendant_(false), | 363 cached_ancestor_exposes_active_descendant_(false), |
| 367 cached_live_region_root_(nullptr), | 364 cached_live_region_root_(nullptr), |
| 368 ax_object_cache_(&ax_object_cache) { | 365 ax_object_cache_(&ax_object_cache) { |
| 369 ++number_of_live_ax_objects_; | 366 ++number_of_live_ax_objects_; |
| 370 } | 367 } |
| 371 | 368 |
| 372 AXObjectImpl::~AXObjectImpl() { | 369 AXObject::~AXObject() { |
| 373 DCHECK(IsDetached()); | 370 DCHECK(IsDetached()); |
| 374 --number_of_live_ax_objects_; | 371 --number_of_live_ax_objects_; |
| 375 } | 372 } |
| 376 | 373 |
| 377 void AXObjectImpl::Detach() { | 374 void AXObject::Detach() { |
| 378 // Clear any children and call detachFromParent on them so that | 375 // Clear any children and call detachFromParent on them so that |
| 379 // no children are left with dangling pointers to their parent. | 376 // no children are left with dangling pointers to their parent. |
| 380 ClearChildren(); | 377 ClearChildren(); |
| 381 | 378 |
| 382 ax_object_cache_ = nullptr; | 379 ax_object_cache_ = nullptr; |
| 383 } | 380 } |
| 384 | 381 |
| 385 bool AXObjectImpl::IsDetached() const { | 382 bool AXObject::IsDetached() const { |
| 386 return !ax_object_cache_; | 383 return !ax_object_cache_; |
| 387 } | 384 } |
| 388 | 385 |
| 389 const AtomicString& AXObjectImpl::GetAOMPropertyOrARIAAttribute( | 386 const AtomicString& AXObject::GetAOMPropertyOrARIAAttribute( |
| 390 AOMStringProperty property) const { | 387 AOMStringProperty property) const { |
| 391 Node* node = this->GetNode(); | 388 Node* node = this->GetNode(); |
| 392 if (!node || !node->IsElementNode()) | 389 if (!node || !node->IsElementNode()) |
| 393 return g_null_atom; | 390 return g_null_atom; |
| 394 | 391 |
| 395 return AccessibleNode::GetPropertyOrARIAAttribute(ToElement(node), property); | 392 return AccessibleNode::GetPropertyOrARIAAttribute(ToElement(node), property); |
| 396 } | 393 } |
| 397 | 394 |
| 398 bool AXObjectImpl::IsARIATextControl() const { | 395 bool AXObject::IsARIATextControl() const { |
| 399 return AriaRoleAttribute() == kTextFieldRole || | 396 return AriaRoleAttribute() == kTextFieldRole || |
| 400 AriaRoleAttribute() == kSearchBoxRole || | 397 AriaRoleAttribute() == kSearchBoxRole || |
| 401 AriaRoleAttribute() == kComboBoxRole; | 398 AriaRoleAttribute() == kComboBoxRole; |
| 402 } | 399 } |
| 403 | 400 |
| 404 bool AXObjectImpl::IsButton() const { | 401 bool AXObject::IsButton() const { |
| 405 AccessibilityRole role = RoleValue(); | 402 AccessibilityRole role = RoleValue(); |
| 406 | 403 |
| 407 return role == kButtonRole || role == kPopUpButtonRole || | 404 return role == kButtonRole || role == kPopUpButtonRole || |
| 408 role == kToggleButtonRole; | 405 role == kToggleButtonRole; |
| 409 } | 406 } |
| 410 | 407 |
| 411 bool AXObjectImpl::IsCheckable() const { | 408 bool AXObject::IsCheckable() const { |
| 412 switch (RoleValue()) { | 409 switch (RoleValue()) { |
| 413 case kCheckBoxRole: | 410 case kCheckBoxRole: |
| 414 case kMenuItemCheckBoxRole: | 411 case kMenuItemCheckBoxRole: |
| 415 case kMenuItemRadioRole: | 412 case kMenuItemRadioRole: |
| 416 case kRadioButtonRole: | 413 case kRadioButtonRole: |
| 417 case kSwitchRole: | 414 case kSwitchRole: |
| 418 return true; | 415 return true; |
| 419 default: | 416 default: |
| 420 return false; | 417 return false; |
| 421 } | 418 } |
| 422 } | 419 } |
| 423 | 420 |
| 424 // Why this is here instead of AXNodeObject: | 421 // Why this is here instead of AXNodeObject: |
| 425 // Because an AXMenuListOption (<option>) can | 422 // Because an AXMenuListOption (<option>) can |
| 426 // have an ARIA role of menuitemcheckbox/menuitemradio | 423 // have an ARIA role of menuitemcheckbox/menuitemradio |
| 427 // yet does not inherit from AXNodeObject | 424 // yet does not inherit from AXNodeObject |
| 428 AccessibilityButtonState AXObjectImpl::CheckedState() const { | 425 AccessibilityButtonState AXObject::CheckedState() const { |
| 429 if (!IsCheckable()) | 426 if (!IsCheckable()) |
| 430 return kButtonStateOff; | 427 return kButtonStateOff; |
| 431 | 428 |
| 432 const AtomicString& checkedAttribute = | 429 const AtomicString& checkedAttribute = |
| 433 GetAOMPropertyOrARIAAttribute(AOMStringProperty::kChecked); | 430 GetAOMPropertyOrARIAAttribute(AOMStringProperty::kChecked); |
| 434 if (checkedAttribute) { | 431 if (checkedAttribute) { |
| 435 if (EqualIgnoringASCIICase(checkedAttribute, "true")) | 432 if (EqualIgnoringASCIICase(checkedAttribute, "true")) |
| 436 return kButtonStateOn; | 433 return kButtonStateOn; |
| 437 | 434 |
| 438 if (EqualIgnoringASCIICase(checkedAttribute, "mixed")) { | 435 if (EqualIgnoringASCIICase(checkedAttribute, "mixed")) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 454 return kButtonStateMixed; | 451 return kButtonStateMixed; |
| 455 | 452 |
| 456 if (isHTMLInputElement(*node) && | 453 if (isHTMLInputElement(*node) && |
| 457 toHTMLInputElement(*node).ShouldAppearChecked()) { | 454 toHTMLInputElement(*node).ShouldAppearChecked()) { |
| 458 return kButtonStateOn; | 455 return kButtonStateOn; |
| 459 } | 456 } |
| 460 | 457 |
| 461 return kButtonStateOff; | 458 return kButtonStateOff; |
| 462 } | 459 } |
| 463 | 460 |
| 464 bool AXObjectImpl::IsNativeInputInMixedState(const Node* node) { | 461 bool AXObject::IsNativeInputInMixedState(const Node* node) { |
| 465 if (!isHTMLInputElement(node)) | 462 if (!isHTMLInputElement(node)) |
| 466 return false; | 463 return false; |
| 467 | 464 |
| 468 const HTMLInputElement* input = toHTMLInputElement(node); | 465 const HTMLInputElement* input = toHTMLInputElement(node); |
| 469 const auto inputType = input->type(); | 466 const auto inputType = input->type(); |
| 470 if (inputType != InputTypeNames::checkbox && | 467 if (inputType != InputTypeNames::checkbox && |
| 471 inputType != InputTypeNames::radio) | 468 inputType != InputTypeNames::radio) |
| 472 return false; | 469 return false; |
| 473 return input->ShouldAppearIndeterminate(); | 470 return input->ShouldAppearIndeterminate(); |
| 474 } | 471 } |
| 475 | 472 |
| 476 bool AXObjectImpl::IsLandmarkRelated() const { | 473 bool AXObject::IsLandmarkRelated() const { |
| 477 switch (RoleValue()) { | 474 switch (RoleValue()) { |
| 478 case kApplicationRole: | 475 case kApplicationRole: |
| 479 case kArticleRole: | 476 case kArticleRole: |
| 480 case kBannerRole: | 477 case kBannerRole: |
| 481 case kComplementaryRole: | 478 case kComplementaryRole: |
| 482 case kContentInfoRole: | 479 case kContentInfoRole: |
| 483 case kFooterRole: | 480 case kFooterRole: |
| 484 case kFormRole: | 481 case kFormRole: |
| 485 case kMainRole: | 482 case kMainRole: |
| 486 case kNavigationRole: | 483 case kNavigationRole: |
| 487 case kRegionRole: | 484 case kRegionRole: |
| 488 case kSearchRole: | 485 case kSearchRole: |
| 489 return true; | 486 return true; |
| 490 default: | 487 default: |
| 491 return false; | 488 return false; |
| 492 } | 489 } |
| 493 } | 490 } |
| 494 | 491 |
| 495 bool AXObjectImpl::IsMenuRelated() const { | 492 bool AXObject::IsMenuRelated() const { |
| 496 switch (RoleValue()) { | 493 switch (RoleValue()) { |
| 497 case kMenuRole: | 494 case kMenuRole: |
| 498 case kMenuBarRole: | 495 case kMenuBarRole: |
| 499 case kMenuButtonRole: | 496 case kMenuButtonRole: |
| 500 case kMenuItemRole: | 497 case kMenuItemRole: |
| 501 case kMenuItemCheckBoxRole: | 498 case kMenuItemCheckBoxRole: |
| 502 case kMenuItemRadioRole: | 499 case kMenuItemRadioRole: |
| 503 return true; | 500 return true; |
| 504 default: | 501 default: |
| 505 return false; | 502 return false; |
| 506 } | 503 } |
| 507 } | 504 } |
| 508 | 505 |
| 509 bool AXObjectImpl::IsPasswordFieldAndShouldHideValue() const { | 506 bool AXObject::IsPasswordFieldAndShouldHideValue() const { |
| 510 Settings* settings = GetDocument()->GetSettings(); | 507 Settings* settings = GetDocument()->GetSettings(); |
| 511 if (!settings || settings->GetAccessibilityPasswordValuesEnabled()) | 508 if (!settings || settings->GetAccessibilityPasswordValuesEnabled()) |
| 512 return false; | 509 return false; |
| 513 | 510 |
| 514 return IsPasswordField(); | 511 return IsPasswordField(); |
| 515 } | 512 } |
| 516 | 513 |
| 517 bool AXObjectImpl::IsClickable() const { | 514 bool AXObject::IsClickable() const { |
| 518 switch (RoleValue()) { | 515 switch (RoleValue()) { |
| 519 case kButtonRole: | 516 case kButtonRole: |
| 520 case kCheckBoxRole: | 517 case kCheckBoxRole: |
| 521 case kColorWellRole: | 518 case kColorWellRole: |
| 522 case kComboBoxRole: | 519 case kComboBoxRole: |
| 523 case kImageMapLinkRole: | 520 case kImageMapLinkRole: |
| 524 case kLinkRole: | 521 case kLinkRole: |
| 525 case kListBoxOptionRole: | 522 case kListBoxOptionRole: |
| 526 case kMenuButtonRole: | 523 case kMenuButtonRole: |
| 527 case kPopUpButtonRole: | 524 case kPopUpButtonRole: |
| 528 case kRadioButtonRole: | 525 case kRadioButtonRole: |
| 529 case kSpinButtonRole: | 526 case kSpinButtonRole: |
| 530 case kTabRole: | 527 case kTabRole: |
| 531 case kTextFieldRole: | 528 case kTextFieldRole: |
| 532 case kToggleButtonRole: | 529 case kToggleButtonRole: |
| 533 return true; | 530 return true; |
| 534 default: | 531 default: |
| 535 return false; | 532 return false; |
| 536 } | 533 } |
| 537 } | 534 } |
| 538 | 535 |
| 539 bool AXObjectImpl::AccessibilityIsIgnored() const { | 536 bool AXObject::AccessibilityIsIgnored() const { |
| 540 UpdateCachedAttributeValuesIfNeeded(); | 537 UpdateCachedAttributeValuesIfNeeded(); |
| 541 return cached_is_ignored_; | 538 return cached_is_ignored_; |
| 542 } | 539 } |
| 543 | 540 |
| 544 void AXObjectImpl::UpdateCachedAttributeValuesIfNeeded() const { | 541 void AXObject::UpdateCachedAttributeValuesIfNeeded() const { |
| 545 if (IsDetached()) | 542 if (IsDetached()) |
| 546 return; | 543 return; |
| 547 | 544 |
| 548 AXObjectCacheImpl& cache = AxObjectCache(); | 545 AXObjectCacheImpl& cache = AxObjectCache(); |
| 549 | 546 |
| 550 if (cache.ModificationCount() == last_modification_count_) | 547 if (cache.ModificationCount() == last_modification_count_) |
| 551 return; | 548 return; |
| 552 | 549 |
| 553 last_modification_count_ = cache.ModificationCount(); | 550 last_modification_count_ = cache.ModificationCount(); |
| 554 cached_background_color_ = ComputeBackgroundColor(); | 551 cached_background_color_ = ComputeBackgroundColor(); |
| 555 cached_is_inert_or_aria_hidden_ = ComputeIsInertOrAriaHidden(); | 552 cached_is_inert_or_aria_hidden_ = ComputeIsInertOrAriaHidden(); |
| 556 cached_is_descendant_of_leaf_node_ = (LeafNodeAncestor() != 0); | 553 cached_is_descendant_of_leaf_node_ = (LeafNodeAncestor() != 0); |
| 557 cached_is_descendant_of_disabled_node_ = (DisabledAncestor() != 0); | 554 cached_is_descendant_of_disabled_node_ = (DisabledAncestor() != 0); |
| 558 cached_has_inherited_presentational_role_ = | 555 cached_has_inherited_presentational_role_ = |
| 559 (InheritsPresentationalRoleFrom() != 0); | 556 (InheritsPresentationalRoleFrom() != 0); |
| 560 cached_is_presentational_child_ = | 557 cached_is_presentational_child_ = |
| 561 (AncestorForWhichThisIsAPresentationalChild() != 0); | 558 (AncestorForWhichThisIsAPresentationalChild() != 0); |
| 562 cached_is_ignored_ = ComputeAccessibilityIsIgnored(); | 559 cached_is_ignored_ = ComputeAccessibilityIsIgnored(); |
| 563 cached_live_region_root_ = | 560 cached_live_region_root_ = |
| 564 IsLiveRegion() | 561 IsLiveRegion() |
| 565 ? const_cast<AXObjectImpl*>(this) | 562 ? const_cast<AXObject*>(this) |
| 566 : (ParentObjectIfExists() ? ParentObjectIfExists()->LiveRegionRoot() | 563 : (ParentObjectIfExists() ? ParentObjectIfExists()->LiveRegionRoot() |
| 567 : 0); | 564 : 0); |
| 568 cached_ancestor_exposes_active_descendant_ = | 565 cached_ancestor_exposes_active_descendant_ = |
| 569 ComputeAncestorExposesActiveDescendant(); | 566 ComputeAncestorExposesActiveDescendant(); |
| 570 } | 567 } |
| 571 | 568 |
| 572 bool AXObjectImpl::AccessibilityIsIgnoredByDefault( | 569 bool AXObject::AccessibilityIsIgnoredByDefault( |
| 573 IgnoredReasons* ignored_reasons) const { | 570 IgnoredReasons* ignored_reasons) const { |
| 574 return DefaultObjectInclusion(ignored_reasons) == kIgnoreObject; | 571 return DefaultObjectInclusion(ignored_reasons) == kIgnoreObject; |
| 575 } | 572 } |
| 576 | 573 |
| 577 AXObjectInclusion AXObjectImpl::AccessibilityPlatformIncludesObject() const { | 574 AXObjectInclusion AXObject::AccessibilityPlatformIncludesObject() const { |
| 578 if (IsMenuListPopup() || IsMenuListOption()) | 575 if (IsMenuListPopup() || IsMenuListOption()) |
| 579 return kIncludeObject; | 576 return kIncludeObject; |
| 580 | 577 |
| 581 return kDefaultBehavior; | 578 return kDefaultBehavior; |
| 582 } | 579 } |
| 583 | 580 |
| 584 AXObjectInclusion AXObjectImpl::DefaultObjectInclusion( | 581 AXObjectInclusion AXObject::DefaultObjectInclusion( |
| 585 IgnoredReasons* ignored_reasons) const { | 582 IgnoredReasons* ignored_reasons) const { |
| 586 if (IsInertOrAriaHidden()) { | 583 if (IsInertOrAriaHidden()) { |
| 587 if (ignored_reasons) | 584 if (ignored_reasons) |
| 588 ComputeIsInertOrAriaHidden(ignored_reasons); | 585 ComputeIsInertOrAriaHidden(ignored_reasons); |
| 589 return kIgnoreObject; | 586 return kIgnoreObject; |
| 590 } | 587 } |
| 591 | 588 |
| 592 if (IsPresentationalChild()) { | 589 if (IsPresentationalChild()) { |
| 593 if (ignored_reasons) { | 590 if (ignored_reasons) { |
| 594 AXObjectImpl* ancestor = AncestorForWhichThisIsAPresentationalChild(); | 591 AXObject* ancestor = AncestorForWhichThisIsAPresentationalChild(); |
| 595 ignored_reasons->push_back( | 592 ignored_reasons->push_back( |
| 596 IgnoredReason(kAXAncestorDisallowsChild, ancestor)); | 593 IgnoredReason(kAXAncestorDisallowsChild, ancestor)); |
| 597 } | 594 } |
| 598 return kIgnoreObject; | 595 return kIgnoreObject; |
| 599 } | 596 } |
| 600 | 597 |
| 601 return AccessibilityPlatformIncludesObject(); | 598 return AccessibilityPlatformIncludesObject(); |
| 602 } | 599 } |
| 603 | 600 |
| 604 bool AXObjectImpl::IsInertOrAriaHidden() const { | 601 bool AXObject::IsInertOrAriaHidden() const { |
| 605 UpdateCachedAttributeValuesIfNeeded(); | 602 UpdateCachedAttributeValuesIfNeeded(); |
| 606 return cached_is_inert_or_aria_hidden_; | 603 return cached_is_inert_or_aria_hidden_; |
| 607 } | 604 } |
| 608 | 605 |
| 609 bool AXObjectImpl::ComputeIsInertOrAriaHidden( | 606 bool AXObject::ComputeIsInertOrAriaHidden( |
| 610 IgnoredReasons* ignored_reasons) const { | 607 IgnoredReasons* ignored_reasons) const { |
| 611 if (GetNode()) { | 608 if (GetNode()) { |
| 612 if (GetNode()->IsInert()) { | 609 if (GetNode()->IsInert()) { |
| 613 if (ignored_reasons) { | 610 if (ignored_reasons) { |
| 614 HTMLDialogElement* dialog = GetActiveDialogElement(GetNode()); | 611 HTMLDialogElement* dialog = GetActiveDialogElement(GetNode()); |
| 615 if (dialog) { | 612 if (dialog) { |
| 616 AXObjectImpl* dialog_object = AxObjectCache().GetOrCreate(dialog); | 613 AXObject* dialog_object = AxObjectCache().GetOrCreate(dialog); |
| 617 if (dialog_object) { | 614 if (dialog_object) |
| 618 ignored_reasons->push_back( | 615 ignored_reasons->push_back( |
| 619 IgnoredReason(kAXActiveModalDialog, dialog_object)); | 616 IgnoredReason(kAXActiveModalDialog, dialog_object)); |
| 620 } else { | 617 else |
| 621 ignored_reasons->push_back(IgnoredReason(kAXInert)); | 618 ignored_reasons->push_back(IgnoredReason(kAXInert)); |
| 622 } | |
| 623 } else { | 619 } else { |
| 624 // TODO(aboxhall): handle inert attribute if it eventuates | 620 // TODO(aboxhall): handle inert attribute if it eventuates |
| 625 ignored_reasons->push_back(IgnoredReason(kAXInert)); | 621 ignored_reasons->push_back(IgnoredReason(kAXInert)); |
| 626 } | 622 } |
| 627 } | 623 } |
| 628 return true; | 624 return true; |
| 629 } | 625 } |
| 630 } else { | 626 } else { |
| 631 AXObjectImpl* parent = ParentObject(); | 627 AXObject* parent = ParentObject(); |
| 632 if (parent && parent->IsInertOrAriaHidden()) { | 628 if (parent && parent->IsInertOrAriaHidden()) { |
| 633 if (ignored_reasons) | 629 if (ignored_reasons) |
| 634 parent->ComputeIsInertOrAriaHidden(ignored_reasons); | 630 parent->ComputeIsInertOrAriaHidden(ignored_reasons); |
| 635 return true; | 631 return true; |
| 636 } | 632 } |
| 637 } | 633 } |
| 638 | 634 |
| 639 const AXObjectImpl* hidden_root = AriaHiddenRoot(); | 635 const AXObject* hidden_root = AriaHiddenRoot(); |
| 640 if (hidden_root) { | 636 if (hidden_root) { |
| 641 if (ignored_reasons) { | 637 if (ignored_reasons) { |
| 642 if (hidden_root == this) { | 638 if (hidden_root == this) |
| 643 ignored_reasons->push_back(IgnoredReason(kAXAriaHidden)); | 639 ignored_reasons->push_back(IgnoredReason(kAXAriaHidden)); |
| 644 } else { | 640 else |
| 645 ignored_reasons->push_back( | 641 ignored_reasons->push_back( |
| 646 IgnoredReason(kAXAriaHiddenRoot, hidden_root)); | 642 IgnoredReason(kAXAriaHiddenRoot, hidden_root)); |
| 647 } | |
| 648 } | 643 } |
| 649 return true; | 644 return true; |
| 650 } | 645 } |
| 651 | 646 |
| 652 return false; | 647 return false; |
| 653 } | 648 } |
| 654 | 649 |
| 655 bool AXObjectImpl::IsDescendantOfLeafNode() const { | 650 bool AXObject::IsDescendantOfLeafNode() const { |
| 656 UpdateCachedAttributeValuesIfNeeded(); | 651 UpdateCachedAttributeValuesIfNeeded(); |
| 657 return cached_is_descendant_of_leaf_node_; | 652 return cached_is_descendant_of_leaf_node_; |
| 658 } | 653 } |
| 659 | 654 |
| 660 AXObjectImpl* AXObjectImpl::LeafNodeAncestor() const { | 655 AXObject* AXObject::LeafNodeAncestor() const { |
| 661 if (AXObjectImpl* parent = ParentObject()) { | 656 if (AXObject* parent = ParentObject()) { |
| 662 if (!parent->CanHaveChildren()) | 657 if (!parent->CanHaveChildren()) |
| 663 return parent; | 658 return parent; |
| 664 | 659 |
| 665 return parent->LeafNodeAncestor(); | 660 return parent->LeafNodeAncestor(); |
| 666 } | 661 } |
| 667 | 662 |
| 668 return 0; | 663 return 0; |
| 669 } | 664 } |
| 670 | 665 |
| 671 const AXObjectImpl* AXObjectImpl::AriaHiddenRoot() const { | 666 const AXObject* AXObject::AriaHiddenRoot() const { |
| 672 for (const AXObjectImpl* object = this; object; | 667 for (const AXObject* object = this; object; object = object->ParentObject()) { |
| 673 object = object->ParentObject()) { | |
| 674 if (EqualIgnoringASCIICase(object->GetAttribute(aria_hiddenAttr), "true")) | 668 if (EqualIgnoringASCIICase(object->GetAttribute(aria_hiddenAttr), "true")) |
| 675 return object; | 669 return object; |
| 676 } | 670 } |
| 677 | 671 |
| 678 return 0; | 672 return 0; |
| 679 } | 673 } |
| 680 | 674 |
| 681 bool AXObjectImpl::IsDescendantOfDisabledNode() const { | 675 bool AXObject::IsDescendantOfDisabledNode() const { |
| 682 UpdateCachedAttributeValuesIfNeeded(); | 676 UpdateCachedAttributeValuesIfNeeded(); |
| 683 return cached_is_descendant_of_disabled_node_; | 677 return cached_is_descendant_of_disabled_node_; |
| 684 } | 678 } |
| 685 | 679 |
| 686 const AXObjectImpl* AXObjectImpl::DisabledAncestor() const { | 680 const AXObject* AXObject::DisabledAncestor() const { |
| 687 const AtomicString& disabled = GetAttribute(aria_disabledAttr); | 681 const AtomicString& disabled = GetAttribute(aria_disabledAttr); |
| 688 if (EqualIgnoringASCIICase(disabled, "true")) | 682 if (EqualIgnoringASCIICase(disabled, "true")) |
| 689 return this; | 683 return this; |
| 690 if (EqualIgnoringASCIICase(disabled, "false")) | 684 if (EqualIgnoringASCIICase(disabled, "false")) |
| 691 return 0; | 685 return 0; |
| 692 | 686 |
| 693 if (AXObjectImpl* parent = ParentObject()) | 687 if (AXObject* parent = ParentObject()) |
| 694 return parent->DisabledAncestor(); | 688 return parent->DisabledAncestor(); |
| 695 | 689 |
| 696 return 0; | 690 return 0; |
| 697 } | 691 } |
| 698 | 692 |
| 699 bool AXObjectImpl::LastKnownIsIgnoredValue() { | 693 bool AXObject::LastKnownIsIgnoredValue() { |
| 700 if (last_known_is_ignored_value_ == kDefaultBehavior) { | 694 if (last_known_is_ignored_value_ == kDefaultBehavior) |
| 701 last_known_is_ignored_value_ = | 695 last_known_is_ignored_value_ = |
| 702 AccessibilityIsIgnored() ? kIgnoreObject : kIncludeObject; | 696 AccessibilityIsIgnored() ? kIgnoreObject : kIncludeObject; |
| 703 } | |
| 704 | 697 |
| 705 return last_known_is_ignored_value_ == kIgnoreObject; | 698 return last_known_is_ignored_value_ == kIgnoreObject; |
| 706 } | 699 } |
| 707 | 700 |
| 708 void AXObjectImpl::SetLastKnownIsIgnoredValue(bool is_ignored) { | 701 void AXObject::SetLastKnownIsIgnoredValue(bool is_ignored) { |
| 709 last_known_is_ignored_value_ = is_ignored ? kIgnoreObject : kIncludeObject; | 702 last_known_is_ignored_value_ = is_ignored ? kIgnoreObject : kIncludeObject; |
| 710 } | 703 } |
| 711 | 704 |
| 712 bool AXObjectImpl::HasInheritedPresentationalRole() const { | 705 bool AXObject::HasInheritedPresentationalRole() const { |
| 713 UpdateCachedAttributeValuesIfNeeded(); | 706 UpdateCachedAttributeValuesIfNeeded(); |
| 714 return cached_has_inherited_presentational_role_; | 707 return cached_has_inherited_presentational_role_; |
| 715 } | 708 } |
| 716 | 709 |
| 717 bool AXObjectImpl::IsPresentationalChild() const { | 710 bool AXObject::IsPresentationalChild() const { |
| 718 UpdateCachedAttributeValuesIfNeeded(); | 711 UpdateCachedAttributeValuesIfNeeded(); |
| 719 return cached_is_presentational_child_; | 712 return cached_is_presentational_child_; |
| 720 } | 713 } |
| 721 | 714 |
| 722 bool AXObjectImpl::AncestorExposesActiveDescendant() const { | 715 bool AXObject::AncestorExposesActiveDescendant() const { |
| 723 UpdateCachedAttributeValuesIfNeeded(); | 716 UpdateCachedAttributeValuesIfNeeded(); |
| 724 return cached_ancestor_exposes_active_descendant_; | 717 return cached_ancestor_exposes_active_descendant_; |
| 725 } | 718 } |
| 726 | 719 |
| 727 bool AXObjectImpl::ComputeAncestorExposesActiveDescendant() const { | 720 bool AXObject::ComputeAncestorExposesActiveDescendant() const { |
| 728 const AXObjectImpl* parent = ParentObjectUnignored(); | 721 const AXObject* parent = ParentObjectUnignored(); |
| 729 if (!parent) | 722 if (!parent) |
| 730 return false; | 723 return false; |
| 731 | 724 |
| 732 if (parent->SupportsActiveDescendant() && | 725 if (parent->SupportsActiveDescendant() && |
| 733 !parent->GetAttribute(aria_activedescendantAttr).IsEmpty()) { | 726 !parent->GetAttribute(aria_activedescendantAttr).IsEmpty()) { |
| 734 return true; | 727 return true; |
| 735 } | 728 } |
| 736 | 729 |
| 737 return parent->AncestorExposesActiveDescendant(); | 730 return parent->AncestorExposesActiveDescendant(); |
| 738 } | 731 } |
| 739 | 732 |
| 740 // Simplify whitespace, but preserve a single leading and trailing whitespace | 733 // Simplify whitespace, but preserve a single leading and trailing whitespace |
| 741 // character if it's present. | 734 // character if it's present. |
| 742 // static | 735 // static |
| 743 String AXObjectImpl::CollapseWhitespace(const String& str) { | 736 String AXObject::CollapseWhitespace(const String& str) { |
| 744 StringBuilder result; | 737 StringBuilder result; |
| 745 if (!str.IsEmpty() && IsHTMLSpace<UChar>(str[0])) | 738 if (!str.IsEmpty() && IsHTMLSpace<UChar>(str[0])) |
| 746 result.Append(' '); | 739 result.Append(' '); |
| 747 result.Append(str.SimplifyWhiteSpace(IsHTMLSpace<UChar>)); | 740 result.Append(str.SimplifyWhiteSpace(IsHTMLSpace<UChar>)); |
| 748 if (!str.IsEmpty() && IsHTMLSpace<UChar>(str[str.length() - 1])) | 741 if (!str.IsEmpty() && IsHTMLSpace<UChar>(str[str.length() - 1])) |
| 749 result.Append(' '); | 742 result.Append(' '); |
| 750 return result.ToString(); | 743 return result.ToString(); |
| 751 } | 744 } |
| 752 | 745 |
| 753 String AXObjectImpl::ComputedName() const { | 746 String AXObject::ComputedName() const { |
| 754 AXNameFrom name_from; | 747 AXNameFrom name_from; |
| 755 AXObjectImpl::AXObjectVector name_objects; | 748 AXObject::AXObjectVector name_objects; |
| 756 return GetName(name_from, &name_objects); | 749 return GetName(name_from, &name_objects); |
| 757 } | 750 } |
| 758 | 751 |
| 759 String AXObjectImpl::GetName(AXNameFrom& name_from, | 752 String AXObject::GetName(AXNameFrom& name_from, |
| 760 AXObjectImpl::AXObjectVector* name_objects) const { | 753 AXObject::AXObjectVector* name_objects) const { |
| 761 HeapHashSet<Member<const AXObjectImpl>> visited; | 754 HeapHashSet<Member<const AXObject>> visited; |
| 762 AXRelatedObjectVector related_objects; | 755 AXRelatedObjectVector related_objects; |
| 763 String text = TextAlternative(false, false, visited, name_from, | 756 String text = TextAlternative(false, false, visited, name_from, |
| 764 &related_objects, nullptr); | 757 &related_objects, nullptr); |
| 765 | 758 |
| 766 AccessibilityRole role = RoleValue(); | 759 AccessibilityRole role = RoleValue(); |
| 767 if (!GetNode() || (!isHTMLBRElement(GetNode()) && role != kStaticTextRole && | 760 if (!GetNode() || (!isHTMLBRElement(GetNode()) && role != kStaticTextRole && |
| 768 role != kInlineTextBoxRole)) | 761 role != kInlineTextBoxRole)) |
| 769 text = CollapseWhitespace(text); | 762 text = CollapseWhitespace(text); |
| 770 | 763 |
| 771 if (name_objects) { | 764 if (name_objects) { |
| 772 name_objects->clear(); | 765 name_objects->clear(); |
| 773 for (size_t i = 0; i < related_objects.size(); i++) | 766 for (size_t i = 0; i < related_objects.size(); i++) |
| 774 name_objects->push_back(related_objects[i]->object); | 767 name_objects->push_back(related_objects[i]->object); |
| 775 } | 768 } |
| 776 | 769 |
| 777 return text; | 770 return text; |
| 778 } | 771 } |
| 779 | 772 |
| 780 String AXObjectImpl::GetName(NameSources* name_sources) const { | 773 String AXObject::GetName(NameSources* name_sources) const { |
| 781 AXObjectSet visited; | 774 AXObjectSet visited; |
| 782 AXNameFrom tmp_name_from; | 775 AXNameFrom tmp_name_from; |
| 783 AXRelatedObjectVector tmp_related_objects; | 776 AXRelatedObjectVector tmp_related_objects; |
| 784 String text = TextAlternative(false, false, visited, tmp_name_from, | 777 String text = TextAlternative(false, false, visited, tmp_name_from, |
| 785 &tmp_related_objects, name_sources); | 778 &tmp_related_objects, name_sources); |
| 786 text = text.SimplifyWhiteSpace(IsHTMLSpace<UChar>); | 779 text = text.SimplifyWhiteSpace(IsHTMLSpace<UChar>); |
| 787 return text; | 780 return text; |
| 788 } | 781 } |
| 789 | 782 |
| 790 String AXObjectImpl::RecursiveTextAlternative( | 783 String AXObject::RecursiveTextAlternative(const AXObject& ax_obj, |
| 791 const AXObjectImpl& ax_obj, | 784 bool in_aria_labelled_by_traversal, |
| 792 bool in_aria_labelled_by_traversal, | 785 AXObjectSet& visited) { |
| 793 AXObjectSet& visited) { | |
| 794 if (visited.Contains(&ax_obj) && !in_aria_labelled_by_traversal) | 786 if (visited.Contains(&ax_obj) && !in_aria_labelled_by_traversal) |
| 795 return String(); | 787 return String(); |
| 796 | 788 |
| 797 AXNameFrom tmp_name_from; | 789 AXNameFrom tmp_name_from; |
| 798 return ax_obj.TextAlternative(true, in_aria_labelled_by_traversal, visited, | 790 return ax_obj.TextAlternative(true, in_aria_labelled_by_traversal, visited, |
| 799 tmp_name_from, nullptr, nullptr); | 791 tmp_name_from, nullptr, nullptr); |
| 800 } | 792 } |
| 801 | 793 |
| 802 bool AXObjectImpl::IsHiddenForTextAlternativeCalculation() const { | 794 bool AXObject::IsHiddenForTextAlternativeCalculation() const { |
| 803 if (EqualIgnoringASCIICase(GetAttribute(aria_hiddenAttr), "false")) | 795 if (EqualIgnoringASCIICase(GetAttribute(aria_hiddenAttr), "false")) |
| 804 return false; | 796 return false; |
| 805 | 797 |
| 806 if (GetLayoutObject()) | 798 if (GetLayoutObject()) |
| 807 return GetLayoutObject()->Style()->Visibility() != EVisibility::kVisible; | 799 return GetLayoutObject()->Style()->Visibility() != EVisibility::kVisible; |
| 808 | 800 |
| 809 // This is an obscure corner case: if a node has no LayoutObject, that means | 801 // This is an obscure corner case: if a node has no LayoutObject, that means |
| 810 // it's not rendered, but we still may be exploring it as part of a text | 802 // it's not rendered, but we still may be exploring it as part of a text |
| 811 // alternative calculation, for example if it was explicitly referenced by | 803 // alternative calculation, for example if it was explicitly referenced by |
| 812 // aria-labelledby. So we need to explicitly call the style resolver to check | 804 // aria-labelledby. So we need to explicitly call the style resolver to check |
| 813 // whether it's invisible or display:none, rather than relying on the style | 805 // whether it's invisible or display:none, rather than relying on the style |
| 814 // cached in the LayoutObject. | 806 // cached in the LayoutObject. |
| 815 Document* document = GetDocument(); | 807 Document* document = GetDocument(); |
| 816 if (!document || !document->GetFrame()) | 808 if (!document || !document->GetFrame()) |
| 817 return false; | 809 return false; |
| 818 if (Node* node = GetNode()) { | 810 if (Node* node = GetNode()) { |
| 819 if (node->isConnected() && node->IsElementNode()) { | 811 if (node->isConnected() && node->IsElementNode()) { |
| 820 RefPtr<ComputedStyle> style = | 812 RefPtr<ComputedStyle> style = |
| 821 document->EnsureStyleResolver().StyleForElement(ToElement(node)); | 813 document->EnsureStyleResolver().StyleForElement(ToElement(node)); |
| 822 return style->Display() == EDisplay::kNone || | 814 return style->Display() == EDisplay::kNone || |
| 823 style->Visibility() != EVisibility::kVisible; | 815 style->Visibility() != EVisibility::kVisible; |
| 824 } | 816 } |
| 825 } | 817 } |
| 826 return false; | 818 return false; |
| 827 } | 819 } |
| 828 | 820 |
| 829 String AXObjectImpl::AriaTextAlternative(bool recursive, | 821 String AXObject::AriaTextAlternative(bool recursive, |
| 830 bool in_aria_labelled_by_traversal, | 822 bool in_aria_labelled_by_traversal, |
| 831 AXObjectSet& visited, | 823 AXObjectSet& visited, |
| 832 AXNameFrom& name_from, | 824 AXNameFrom& name_from, |
| 833 AXRelatedObjectVector* related_objects, | 825 AXRelatedObjectVector* related_objects, |
| 834 NameSources* name_sources, | 826 NameSources* name_sources, |
| 835 bool* found_text_alternative) const { | 827 bool* found_text_alternative) const { |
| 836 String text_alternative; | 828 String text_alternative; |
| 837 bool already_visited = visited.Contains(this); | 829 bool already_visited = visited.Contains(this); |
| 838 visited.insert(this); | 830 visited.insert(this); |
| 839 | 831 |
| 840 // Step 2A from: http://www.w3.org/TR/accname-aam-1.1 | 832 // Step 2A from: http://www.w3.org/TR/accname-aam-1.1 |
| 841 // If you change this logic, update AXNodeObject::nameFromLabelElement, too. | 833 // If you change this logic, update AXNodeObject::nameFromLabelElement, too. |
| 842 if (!in_aria_labelled_by_traversal && | 834 if (!in_aria_labelled_by_traversal && |
| 843 IsHiddenForTextAlternativeCalculation()) { | 835 IsHiddenForTextAlternativeCalculation()) { |
| 844 *found_text_alternative = true; | 836 *found_text_alternative = true; |
| 845 return String(); | 837 return String(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 *found_text_alternative = true; | 897 *found_text_alternative = true; |
| 906 } else { | 898 } else { |
| 907 *found_text_alternative = true; | 899 *found_text_alternative = true; |
| 908 return text_alternative; | 900 return text_alternative; |
| 909 } | 901 } |
| 910 } | 902 } |
| 911 | 903 |
| 912 return text_alternative; | 904 return text_alternative; |
| 913 } | 905 } |
| 914 | 906 |
| 915 String AXObjectImpl::TextFromElements( | 907 String AXObject::TextFromElements( |
| 916 bool in_aria_labelledby_traversal, | 908 bool in_aria_labelledby_traversal, |
| 917 AXObjectSet& visited, | 909 AXObjectSet& visited, |
| 918 HeapVector<Member<Element>>& elements, | 910 HeapVector<Member<Element>>& elements, |
| 919 AXRelatedObjectVector* related_objects) const { | 911 AXRelatedObjectVector* related_objects) const { |
| 920 StringBuilder accumulated_text; | 912 StringBuilder accumulated_text; |
| 921 bool found_valid_element = false; | 913 bool found_valid_element = false; |
| 922 AXRelatedObjectVector local_related_objects; | 914 AXRelatedObjectVector local_related_objects; |
| 923 | 915 |
| 924 for (const auto& element : elements) { | 916 for (const auto& element : elements) { |
| 925 AXObjectImpl* ax_element = AxObjectCache().GetOrCreate(element); | 917 AXObject* ax_element = AxObjectCache().GetOrCreate(element); |
| 926 if (ax_element) { | 918 if (ax_element) { |
| 927 found_valid_element = true; | 919 found_valid_element = true; |
| 928 | 920 |
| 929 String result = RecursiveTextAlternative( | 921 String result = RecursiveTextAlternative( |
| 930 *ax_element, in_aria_labelledby_traversal, visited); | 922 *ax_element, in_aria_labelledby_traversal, visited); |
| 931 local_related_objects.push_back( | 923 local_related_objects.push_back( |
| 932 new NameSourceRelatedObject(ax_element, result)); | 924 new NameSourceRelatedObject(ax_element, result)); |
| 933 if (!result.IsEmpty()) { | 925 if (!result.IsEmpty()) { |
| 934 if (!accumulated_text.IsEmpty()) | 926 if (!accumulated_text.IsEmpty()) |
| 935 accumulated_text.Append(' '); | 927 accumulated_text.Append(' '); |
| 936 accumulated_text.Append(result); | 928 accumulated_text.Append(result); |
| 937 } | 929 } |
| 938 } | 930 } |
| 939 } | 931 } |
| 940 if (!found_valid_element) | 932 if (!found_valid_element) |
| 941 return String(); | 933 return String(); |
| 942 if (related_objects) | 934 if (related_objects) |
| 943 *related_objects = local_related_objects; | 935 *related_objects = local_related_objects; |
| 944 return accumulated_text.ToString(); | 936 return accumulated_text.ToString(); |
| 945 } | 937 } |
| 946 | 938 |
| 947 void AXObjectImpl::TokenVectorFromAttribute( | 939 void AXObject::TokenVectorFromAttribute(Vector<String>& tokens, |
| 948 Vector<String>& tokens, | 940 const QualifiedName& attribute) const { |
| 949 const QualifiedName& attribute) const { | |
| 950 Node* node = this->GetNode(); | 941 Node* node = this->GetNode(); |
| 951 if (!node || !node->IsElementNode()) | 942 if (!node || !node->IsElementNode()) |
| 952 return; | 943 return; |
| 953 | 944 |
| 954 String attribute_value = GetAttribute(attribute).GetString(); | 945 String attribute_value = GetAttribute(attribute).GetString(); |
| 955 if (attribute_value.IsEmpty()) | 946 if (attribute_value.IsEmpty()) |
| 956 return; | 947 return; |
| 957 | 948 |
| 958 attribute_value.SimplifyWhiteSpace(); | 949 attribute_value.SimplifyWhiteSpace(); |
| 959 attribute_value.Split(' ', tokens); | 950 attribute_value.Split(' ', tokens); |
| 960 } | 951 } |
| 961 | 952 |
| 962 void AXObjectImpl::ElementsFromAttribute(HeapVector<Member<Element>>& elements, | 953 void AXObject::ElementsFromAttribute(HeapVector<Member<Element>>& elements, |
| 963 const QualifiedName& attribute) const { | 954 const QualifiedName& attribute) const { |
| 964 Vector<String> ids; | 955 Vector<String> ids; |
| 965 TokenVectorFromAttribute(ids, attribute); | 956 TokenVectorFromAttribute(ids, attribute); |
| 966 if (ids.IsEmpty()) | 957 if (ids.IsEmpty()) |
| 967 return; | 958 return; |
| 968 | 959 |
| 969 TreeScope& scope = GetNode()->GetTreeScope(); | 960 TreeScope& scope = GetNode()->GetTreeScope(); |
| 970 for (const auto& id : ids) { | 961 for (const auto& id : ids) { |
| 971 if (Element* id_element = scope.getElementById(AtomicString(id))) | 962 if (Element* id_element = scope.getElementById(AtomicString(id))) |
| 972 elements.push_back(id_element); | 963 elements.push_back(id_element); |
| 973 } | 964 } |
| 974 } | 965 } |
| 975 | 966 |
| 976 void AXObjectImpl::AriaLabelledbyElementVector( | 967 void AXObject::AriaLabelledbyElementVector( |
| 977 HeapVector<Member<Element>>& elements) const { | 968 HeapVector<Member<Element>>& elements) const { |
| 978 // Try both spellings, but prefer aria-labelledby, which is the official spec. | 969 // Try both spellings, but prefer aria-labelledby, which is the official spec. |
| 979 ElementsFromAttribute(elements, aria_labelledbyAttr); | 970 ElementsFromAttribute(elements, aria_labelledbyAttr); |
| 980 if (!elements.size()) | 971 if (!elements.size()) |
| 981 ElementsFromAttribute(elements, aria_labeledbyAttr); | 972 ElementsFromAttribute(elements, aria_labeledbyAttr); |
| 982 } | 973 } |
| 983 | 974 |
| 984 String AXObjectImpl::TextFromAriaLabelledby( | 975 String AXObject::TextFromAriaLabelledby( |
| 985 AXObjectSet& visited, | 976 AXObjectSet& visited, |
| 986 AXRelatedObjectVector* related_objects) const { | 977 AXRelatedObjectVector* related_objects) const { |
| 987 HeapVector<Member<Element>> elements; | 978 HeapVector<Member<Element>> elements; |
| 988 AriaLabelledbyElementVector(elements); | 979 AriaLabelledbyElementVector(elements); |
| 989 return TextFromElements(true, visited, elements, related_objects); | 980 return TextFromElements(true, visited, elements, related_objects); |
| 990 } | 981 } |
| 991 | 982 |
| 992 String AXObjectImpl::TextFromAriaDescribedby( | 983 String AXObject::TextFromAriaDescribedby( |
| 993 AXRelatedObjectVector* related_objects) const { | 984 AXRelatedObjectVector* related_objects) const { |
| 994 AXObjectSet visited; | 985 AXObjectSet visited; |
| 995 HeapVector<Member<Element>> elements; | 986 HeapVector<Member<Element>> elements; |
| 996 ElementsFromAttribute(elements, aria_describedbyAttr); | 987 ElementsFromAttribute(elements, aria_describedbyAttr); |
| 997 return TextFromElements(true, visited, elements, related_objects); | 988 return TextFromElements(true, visited, elements, related_objects); |
| 998 } | 989 } |
| 999 | 990 |
| 1000 RGBA32 AXObjectImpl::BackgroundColor() const { | 991 RGBA32 AXObject::BackgroundColor() const { |
| 1001 UpdateCachedAttributeValuesIfNeeded(); | 992 UpdateCachedAttributeValuesIfNeeded(); |
| 1002 return cached_background_color_; | 993 return cached_background_color_; |
| 1003 } | 994 } |
| 1004 | 995 |
| 1005 AccessibilityOrientation AXObjectImpl::Orientation() const { | 996 AccessibilityOrientation AXObject::Orientation() const { |
| 1006 // In ARIA 1.1, the default value for aria-orientation changed from | 997 // In ARIA 1.1, the default value for aria-orientation changed from |
| 1007 // horizontal to undefined. | 998 // horizontal to undefined. |
| 1008 return kAccessibilityOrientationUndefined; | 999 return kAccessibilityOrientationUndefined; |
| 1009 } | 1000 } |
| 1010 | 1001 |
| 1011 AXSupportedAction AXObjectImpl::Action() const { | 1002 AXSupportedAction AXObject::Action() const { |
| 1012 if (!ActionElement()) | 1003 if (!ActionElement()) |
| 1013 return AXSupportedAction::kNone; | 1004 return AXSupportedAction::kNone; |
| 1014 | 1005 |
| 1015 switch (RoleValue()) { | 1006 switch (RoleValue()) { |
| 1016 case kButtonRole: | 1007 case kButtonRole: |
| 1017 case kToggleButtonRole: | 1008 case kToggleButtonRole: |
| 1018 return AXSupportedAction::kPress; | 1009 return AXSupportedAction::kPress; |
| 1019 case kTextFieldRole: | 1010 case kTextFieldRole: |
| 1020 return AXSupportedAction::kActivate; | 1011 return AXSupportedAction::kActivate; |
| 1021 case kRadioButtonRole: | 1012 case kRadioButtonRole: |
| 1022 return AXSupportedAction::kSelect; | 1013 return AXSupportedAction::kSelect; |
| 1023 case kCheckBoxRole: | 1014 case kCheckBoxRole: |
| 1024 case kSwitchRole: | 1015 case kSwitchRole: |
| 1025 return CheckedState() == kButtonStateOff ? AXSupportedAction::kCheck | 1016 return CheckedState() == kButtonStateOff ? AXSupportedAction::kCheck |
| 1026 : AXSupportedAction::kUncheck; | 1017 : AXSupportedAction::kUncheck; |
| 1027 case kLinkRole: | 1018 case kLinkRole: |
| 1028 return AXSupportedAction::kJump; | 1019 return AXSupportedAction::kJump; |
| 1029 case kPopUpButtonRole: | 1020 case kPopUpButtonRole: |
| 1030 return AXSupportedAction::kOpen; | 1021 return AXSupportedAction::kOpen; |
| 1031 default: | 1022 default: |
| 1032 return AXSupportedAction::kClick; | 1023 return AXSupportedAction::kClick; |
| 1033 } | 1024 } |
| 1034 } | 1025 } |
| 1035 | 1026 |
| 1036 bool AXObjectImpl::IsMultiline() const { | 1027 bool AXObject::IsMultiline() const { |
| 1037 Node* node = this->GetNode(); | 1028 Node* node = this->GetNode(); |
| 1038 if (!node) | 1029 if (!node) |
| 1039 return false; | 1030 return false; |
| 1040 | 1031 |
| 1041 if (isHTMLTextAreaElement(*node)) | 1032 if (isHTMLTextAreaElement(*node)) |
| 1042 return true; | 1033 return true; |
| 1043 | 1034 |
| 1044 if (HasEditableStyle(*node)) | 1035 if (HasEditableStyle(*node)) |
| 1045 return true; | 1036 return true; |
| 1046 | 1037 |
| 1047 if (!IsNativeTextControl() && !IsNonNativeTextControl()) | 1038 if (!IsNativeTextControl() && !IsNonNativeTextControl()) |
| 1048 return false; | 1039 return false; |
| 1049 | 1040 |
| 1050 return EqualIgnoringASCIICase(GetAttribute(aria_multilineAttr), "true"); | 1041 return EqualIgnoringASCIICase(GetAttribute(aria_multilineAttr), "true"); |
| 1051 } | 1042 } |
| 1052 | 1043 |
| 1053 bool AXObjectImpl::AriaPressedIsPresent() const { | 1044 bool AXObject::AriaPressedIsPresent() const { |
| 1054 return !GetAttribute(aria_pressedAttr).IsEmpty(); | 1045 return !GetAttribute(aria_pressedAttr).IsEmpty(); |
| 1055 } | 1046 } |
| 1056 | 1047 |
| 1057 bool AXObjectImpl::SupportsActiveDescendant() const { | 1048 bool AXObject::SupportsActiveDescendant() const { |
| 1058 // According to the ARIA Spec, all ARIA composite widgets, ARIA text boxes | 1049 // According to the ARIA Spec, all ARIA composite widgets, ARIA text boxes |
| 1059 // and ARIA groups should be able to expose an active descendant. | 1050 // and ARIA groups should be able to expose an active descendant. |
| 1060 // Implicitly, <input> and <textarea> elements should also have this ability. | 1051 // Implicitly, <input> and <textarea> elements should also have this ability. |
| 1061 switch (AriaRoleAttribute()) { | 1052 switch (AriaRoleAttribute()) { |
| 1062 case kComboBoxRole: | 1053 case kComboBoxRole: |
| 1063 case kGridRole: | 1054 case kGridRole: |
| 1064 case kGroupRole: | 1055 case kGroupRole: |
| 1065 case kListBoxRole: | 1056 case kListBoxRole: |
| 1066 case kMenuRole: | 1057 case kMenuRole: |
| 1067 case kMenuBarRole: | 1058 case kMenuBarRole: |
| 1068 case kRadioGroupRole: | 1059 case kRadioGroupRole: |
| 1069 case kRowRole: | 1060 case kRowRole: |
| 1070 case kSearchBoxRole: | 1061 case kSearchBoxRole: |
| 1071 case kTabListRole: | 1062 case kTabListRole: |
| 1072 case kTextFieldRole: | 1063 case kTextFieldRole: |
| 1073 case kToolbarRole: | 1064 case kToolbarRole: |
| 1074 case kTreeRole: | 1065 case kTreeRole: |
| 1075 case kTreeGridRole: | 1066 case kTreeGridRole: |
| 1076 return true; | 1067 return true; |
| 1077 default: | 1068 default: |
| 1078 return false; | 1069 return false; |
| 1079 } | 1070 } |
| 1080 } | 1071 } |
| 1081 | 1072 |
| 1082 bool AXObjectImpl::SupportsARIAAttributes() const { | 1073 bool AXObject::SupportsARIAAttributes() const { |
| 1083 return IsLiveRegion() || SupportsARIADragging() || SupportsARIADropping() || | 1074 return IsLiveRegion() || SupportsARIADragging() || SupportsARIADropping() || |
| 1084 SupportsARIAFlowTo() || SupportsARIAOwns() || | 1075 SupportsARIAFlowTo() || SupportsARIAOwns() || |
| 1085 HasAttribute(aria_labelAttr); | 1076 HasAttribute(aria_labelAttr); |
| 1086 } | 1077 } |
| 1087 | 1078 |
| 1088 bool AXObjectImpl::SupportsRangeValue() const { | 1079 bool AXObject::SupportsRangeValue() const { |
| 1089 return IsProgressIndicator() || IsMeter() || IsSlider() || IsScrollbar() || | 1080 return IsProgressIndicator() || IsMeter() || IsSlider() || IsScrollbar() || |
| 1090 IsSpinButton(); | 1081 IsSpinButton(); |
| 1091 } | 1082 } |
| 1092 | 1083 |
| 1093 bool AXObjectImpl::SupportsSetSizeAndPosInSet() const { | 1084 bool AXObject::SupportsSetSizeAndPosInSet() const { |
| 1094 AXObjectImpl* parent = ParentObject(); | 1085 AXObject* parent = ParentObject(); |
| 1095 if (!parent) | 1086 if (!parent) |
| 1096 return false; | 1087 return false; |
| 1097 | 1088 |
| 1098 int role = RoleValue(); | 1089 int role = RoleValue(); |
| 1099 int parent_role = parent->RoleValue(); | 1090 int parent_role = parent->RoleValue(); |
| 1100 | 1091 |
| 1101 if ((role == kListBoxOptionRole && parent_role == kListBoxRole) || | 1092 if ((role == kListBoxOptionRole && parent_role == kListBoxRole) || |
| 1102 (role == kListItemRole && parent_role == kListRole) || | 1093 (role == kListItemRole && parent_role == kListRole) || |
| 1103 (role == kMenuItemRole && parent_role == kMenuRole) || | 1094 (role == kMenuItemRole && parent_role == kMenuRole) || |
| 1104 (role == kRadioButtonRole) || | 1095 (role == kRadioButtonRole) || |
| 1105 (role == kTabRole && parent_role == kTabListRole) || | 1096 (role == kTabRole && parent_role == kTabListRole) || |
| 1106 (role == kTreeItemRole && parent_role == kTreeRole) || | 1097 (role == kTreeItemRole && parent_role == kTreeRole) || |
| 1107 (role == kTreeItemRole && parent_role == kGroupRole)) { | 1098 (role == kTreeItemRole && parent_role == kGroupRole)) { |
| 1108 return true; | 1099 return true; |
| 1109 } | 1100 } |
| 1110 | 1101 |
| 1111 return false; | 1102 return false; |
| 1112 } | 1103 } |
| 1113 | 1104 |
| 1114 int AXObjectImpl::IndexInParent() const { | 1105 int AXObject::IndexInParent() const { |
| 1115 if (!ParentObject()) | 1106 if (!ParentObject()) |
| 1116 return 0; | 1107 return 0; |
| 1117 | 1108 |
| 1118 const auto& siblings = ParentObject()->Children(); | 1109 const auto& siblings = ParentObject()->Children(); |
| 1119 int child_count = siblings.size(); | 1110 int child_count = siblings.size(); |
| 1120 | 1111 |
| 1121 for (int index = 0; index < child_count; ++index) { | 1112 for (int index = 0; index < child_count; ++index) { |
| 1122 if (siblings[index].Get() == this) { | 1113 if (siblings[index].Get() == this) { |
| 1123 return index; | 1114 return index; |
| 1124 } | 1115 } |
| 1125 } | 1116 } |
| 1126 return 0; | 1117 return 0; |
| 1127 } | 1118 } |
| 1128 | 1119 |
| 1129 bool AXObjectImpl::IsLiveRegion() const { | 1120 bool AXObject::IsLiveRegion() const { |
| 1130 const AtomicString& live_region = LiveRegionStatus(); | 1121 const AtomicString& live_region = LiveRegionStatus(); |
| 1131 return EqualIgnoringASCIICase(live_region, "polite") || | 1122 return EqualIgnoringASCIICase(live_region, "polite") || |
| 1132 EqualIgnoringASCIICase(live_region, "assertive"); | 1123 EqualIgnoringASCIICase(live_region, "assertive"); |
| 1133 } | 1124 } |
| 1134 | 1125 |
| 1135 AXObjectImpl* AXObjectImpl::LiveRegionRoot() const { | 1126 AXObject* AXObject::LiveRegionRoot() const { |
| 1136 UpdateCachedAttributeValuesIfNeeded(); | 1127 UpdateCachedAttributeValuesIfNeeded(); |
| 1137 return cached_live_region_root_; | 1128 return cached_live_region_root_; |
| 1138 } | 1129 } |
| 1139 | 1130 |
| 1140 const AtomicString& AXObjectImpl::ContainerLiveRegionStatus() const { | 1131 const AtomicString& AXObject::ContainerLiveRegionStatus() const { |
| 1141 UpdateCachedAttributeValuesIfNeeded(); | 1132 UpdateCachedAttributeValuesIfNeeded(); |
| 1142 return cached_live_region_root_ ? cached_live_region_root_->LiveRegionStatus() | 1133 return cached_live_region_root_ ? cached_live_region_root_->LiveRegionStatus() |
| 1143 : g_null_atom; | 1134 : g_null_atom; |
| 1144 } | 1135 } |
| 1145 | 1136 |
| 1146 const AtomicString& AXObjectImpl::ContainerLiveRegionRelevant() const { | 1137 const AtomicString& AXObject::ContainerLiveRegionRelevant() const { |
| 1147 UpdateCachedAttributeValuesIfNeeded(); | 1138 UpdateCachedAttributeValuesIfNeeded(); |
| 1148 return cached_live_region_root_ | 1139 return cached_live_region_root_ |
| 1149 ? cached_live_region_root_->LiveRegionRelevant() | 1140 ? cached_live_region_root_->LiveRegionRelevant() |
| 1150 : g_null_atom; | 1141 : g_null_atom; |
| 1151 } | 1142 } |
| 1152 | 1143 |
| 1153 bool AXObjectImpl::ContainerLiveRegionAtomic() const { | 1144 bool AXObject::ContainerLiveRegionAtomic() const { |
| 1154 UpdateCachedAttributeValuesIfNeeded(); | 1145 UpdateCachedAttributeValuesIfNeeded(); |
| 1155 return cached_live_region_root_ && | 1146 return cached_live_region_root_ && |
| 1156 cached_live_region_root_->LiveRegionAtomic(); | 1147 cached_live_region_root_->LiveRegionAtomic(); |
| 1157 } | 1148 } |
| 1158 | 1149 |
| 1159 bool AXObjectImpl::ContainerLiveRegionBusy() const { | 1150 bool AXObject::ContainerLiveRegionBusy() const { |
| 1160 UpdateCachedAttributeValuesIfNeeded(); | 1151 UpdateCachedAttributeValuesIfNeeded(); |
| 1161 return cached_live_region_root_ && cached_live_region_root_->LiveRegionBusy(); | 1152 return cached_live_region_root_ && cached_live_region_root_->LiveRegionBusy(); |
| 1162 } | 1153 } |
| 1163 | 1154 |
| 1164 AXObjectImpl* AXObjectImpl::ElementAccessibilityHitTest( | 1155 AXObject* AXObject::ElementAccessibilityHitTest(const IntPoint& point) const { |
| 1165 const IntPoint& point) const { | |
| 1166 // Check if there are any mock elements that need to be handled. | 1156 // Check if there are any mock elements that need to be handled. |
| 1167 for (const auto& child : children_) { | 1157 for (const auto& child : children_) { |
| 1168 if (child->IsMockObject() && | 1158 if (child->IsMockObject() && |
| 1169 child->GetBoundsInFrameCoordinates().Contains(point)) | 1159 child->GetBoundsInFrameCoordinates().Contains(point)) |
| 1170 return child->ElementAccessibilityHitTest(point); | 1160 return child->ElementAccessibilityHitTest(point); |
| 1171 } | 1161 } |
| 1172 | 1162 |
| 1173 return const_cast<AXObjectImpl*>(this); | 1163 return const_cast<AXObject*>(this); |
| 1174 } | 1164 } |
| 1175 | 1165 |
| 1176 const AXObjectImpl::AXObjectVector& AXObjectImpl::Children() { | 1166 const AXObject::AXObjectVector& AXObject::Children() { |
| 1177 UpdateChildrenIfNecessary(); | 1167 UpdateChildrenIfNecessary(); |
| 1178 | 1168 |
| 1179 return children_; | 1169 return children_; |
| 1180 } | 1170 } |
| 1181 | 1171 |
| 1182 AXObjectImpl* AXObjectImpl::ParentObject() const { | 1172 AXObject* AXObject::ParentObject() const { |
| 1183 if (IsDetached()) | 1173 if (IsDetached()) |
| 1184 return 0; | 1174 return 0; |
| 1185 | 1175 |
| 1186 if (parent_) | 1176 if (parent_) |
| 1187 return parent_; | 1177 return parent_; |
| 1188 | 1178 |
| 1189 if (AxObjectCache().IsAriaOwned(this)) | 1179 if (AxObjectCache().IsAriaOwned(this)) |
| 1190 return AxObjectCache().GetAriaOwnedParent(this); | 1180 return AxObjectCache().GetAriaOwnedParent(this); |
| 1191 | 1181 |
| 1192 return ComputeParent(); | 1182 return ComputeParent(); |
| 1193 } | 1183 } |
| 1194 | 1184 |
| 1195 AXObjectImpl* AXObjectImpl::ParentObjectIfExists() const { | 1185 AXObject* AXObject::ParentObjectIfExists() const { |
| 1196 if (IsDetached()) | 1186 if (IsDetached()) |
| 1197 return 0; | 1187 return 0; |
| 1198 | 1188 |
| 1199 if (parent_) | 1189 if (parent_) |
| 1200 return parent_; | 1190 return parent_; |
| 1201 | 1191 |
| 1202 return ComputeParentIfExists(); | 1192 return ComputeParentIfExists(); |
| 1203 } | 1193 } |
| 1204 | 1194 |
| 1205 AXObjectImpl* AXObjectImpl::ParentObjectUnignored() const { | 1195 AXObject* AXObject::ParentObjectUnignored() const { |
| 1206 AXObjectImpl* parent; | 1196 AXObject* parent; |
| 1207 for (parent = ParentObject(); parent && parent->AccessibilityIsIgnored(); | 1197 for (parent = ParentObject(); parent && parent->AccessibilityIsIgnored(); |
| 1208 parent = parent->ParentObject()) { | 1198 parent = parent->ParentObject()) { |
| 1209 } | 1199 } |
| 1210 | 1200 |
| 1211 return parent; | 1201 return parent; |
| 1212 } | 1202 } |
| 1213 | 1203 |
| 1214 void AXObjectImpl::UpdateChildrenIfNecessary() { | 1204 void AXObject::UpdateChildrenIfNecessary() { |
| 1215 if (!HasChildren()) | 1205 if (!HasChildren()) |
| 1216 AddChildren(); | 1206 AddChildren(); |
| 1217 } | 1207 } |
| 1218 | 1208 |
| 1219 void AXObjectImpl::ClearChildren() { | 1209 void AXObject::ClearChildren() { |
| 1220 // Detach all weak pointers from objects to their parents. | 1210 // Detach all weak pointers from objects to their parents. |
| 1221 for (const auto& child : children_) | 1211 for (const auto& child : children_) |
| 1222 child->DetachFromParent(); | 1212 child->DetachFromParent(); |
| 1223 | 1213 |
| 1224 children_.clear(); | 1214 children_.clear(); |
| 1225 have_children_ = false; | 1215 have_children_ = false; |
| 1226 } | 1216 } |
| 1227 | 1217 |
| 1228 Document* AXObjectImpl::GetDocument() const { | 1218 Document* AXObject::GetDocument() const { |
| 1229 FrameView* frame_view = DocumentFrameView(); | 1219 FrameView* frame_view = DocumentFrameView(); |
| 1230 if (!frame_view) | 1220 if (!frame_view) |
| 1231 return 0; | 1221 return 0; |
| 1232 | 1222 |
| 1233 return frame_view->GetFrame().GetDocument(); | 1223 return frame_view->GetFrame().GetDocument(); |
| 1234 } | 1224 } |
| 1235 | 1225 |
| 1236 FrameView* AXObjectImpl::DocumentFrameView() const { | 1226 FrameView* AXObject::DocumentFrameView() const { |
| 1237 const AXObjectImpl* object = this; | 1227 const AXObject* object = this; |
| 1238 while (object && !object->IsAXLayoutObject()) | 1228 while (object && !object->IsAXLayoutObject()) |
| 1239 object = object->ParentObject(); | 1229 object = object->ParentObject(); |
| 1240 | 1230 |
| 1241 if (!object) | 1231 if (!object) |
| 1242 return 0; | 1232 return 0; |
| 1243 | 1233 |
| 1244 return object->DocumentFrameView(); | 1234 return object->DocumentFrameView(); |
| 1245 } | 1235 } |
| 1246 | 1236 |
| 1247 String AXObjectImpl::Language() const { | 1237 String AXObject::Language() const { |
| 1248 const AtomicString& lang = GetAttribute(langAttr); | 1238 const AtomicString& lang = GetAttribute(langAttr); |
| 1249 if (!lang.IsEmpty()) | 1239 if (!lang.IsEmpty()) |
| 1250 return lang; | 1240 return lang; |
| 1251 | 1241 |
| 1252 AXObjectImpl* parent = ParentObject(); | 1242 AXObject* parent = ParentObject(); |
| 1253 | 1243 |
| 1254 // As a last resort, fall back to the content language specified in the meta | 1244 // As a last resort, fall back to the content language specified in the meta |
| 1255 // tag. | 1245 // tag. |
| 1256 if (!parent) { | 1246 if (!parent) { |
| 1257 Document* doc = GetDocument(); | 1247 Document* doc = GetDocument(); |
| 1258 if (doc) | 1248 if (doc) |
| 1259 return doc->ContentLanguage(); | 1249 return doc->ContentLanguage(); |
| 1260 return g_null_atom; | 1250 return g_null_atom; |
| 1261 } | 1251 } |
| 1262 | 1252 |
| 1263 return parent->Language(); | 1253 return parent->Language(); |
| 1264 } | 1254 } |
| 1265 | 1255 |
| 1266 bool AXObjectImpl::HasAttribute(const QualifiedName& attribute) const { | 1256 bool AXObject::HasAttribute(const QualifiedName& attribute) const { |
| 1267 Node* element_node = GetNode(); | 1257 Node* element_node = GetNode(); |
| 1268 if (!element_node) | 1258 if (!element_node) |
| 1269 return false; | 1259 return false; |
| 1270 | 1260 |
| 1271 if (!element_node->IsElementNode()) | 1261 if (!element_node->IsElementNode()) |
| 1272 return false; | 1262 return false; |
| 1273 | 1263 |
| 1274 Element* element = ToElement(element_node); | 1264 Element* element = ToElement(element_node); |
| 1275 return element->FastHasAttribute(attribute); | 1265 return element->FastHasAttribute(attribute); |
| 1276 } | 1266 } |
| 1277 | 1267 |
| 1278 const AtomicString& AXObjectImpl::GetAttribute( | 1268 const AtomicString& AXObject::GetAttribute( |
| 1279 const QualifiedName& attribute) const { | 1269 const QualifiedName& attribute) const { |
| 1280 Node* element_node = GetNode(); | 1270 Node* element_node = GetNode(); |
| 1281 if (!element_node) | 1271 if (!element_node) |
| 1282 return g_null_atom; | 1272 return g_null_atom; |
| 1283 | 1273 |
| 1284 if (!element_node->IsElementNode()) | 1274 if (!element_node->IsElementNode()) |
| 1285 return g_null_atom; | 1275 return g_null_atom; |
| 1286 | 1276 |
| 1287 Element* element = ToElement(element_node); | 1277 Element* element = ToElement(element_node); |
| 1288 return element->FastGetAttribute(attribute); | 1278 return element->FastGetAttribute(attribute); |
| 1289 } | 1279 } |
| 1290 | 1280 |
| 1291 // | 1281 // |
| 1292 // Scrollable containers. | 1282 // Scrollable containers. |
| 1293 // | 1283 // |
| 1294 | 1284 |
| 1295 bool AXObjectImpl::IsScrollableContainer() const { | 1285 bool AXObject::IsScrollableContainer() const { |
| 1296 return !!GetScrollableAreaIfScrollable(); | 1286 return !!GetScrollableAreaIfScrollable(); |
| 1297 } | 1287 } |
| 1298 | 1288 |
| 1299 IntPoint AXObjectImpl::GetScrollOffset() const { | 1289 IntPoint AXObject::GetScrollOffset() const { |
| 1300 ScrollableArea* area = GetScrollableAreaIfScrollable(); | 1290 ScrollableArea* area = GetScrollableAreaIfScrollable(); |
| 1301 if (!area) | 1291 if (!area) |
| 1302 return IntPoint(); | 1292 return IntPoint(); |
| 1303 | 1293 |
| 1304 return IntPoint(area->ScrollOffsetInt().Width(), | 1294 return IntPoint(area->ScrollOffsetInt().Width(), |
| 1305 area->ScrollOffsetInt().Height()); | 1295 area->ScrollOffsetInt().Height()); |
| 1306 } | 1296 } |
| 1307 | 1297 |
| 1308 IntPoint AXObjectImpl::MinimumScrollOffset() const { | 1298 IntPoint AXObject::MinimumScrollOffset() const { |
| 1309 ScrollableArea* area = GetScrollableAreaIfScrollable(); | 1299 ScrollableArea* area = GetScrollableAreaIfScrollable(); |
| 1310 if (!area) | 1300 if (!area) |
| 1311 return IntPoint(); | 1301 return IntPoint(); |
| 1312 | 1302 |
| 1313 return IntPoint(area->MinimumScrollOffsetInt().Width(), | 1303 return IntPoint(area->MinimumScrollOffsetInt().Width(), |
| 1314 area->MinimumScrollOffsetInt().Height()); | 1304 area->MinimumScrollOffsetInt().Height()); |
| 1315 } | 1305 } |
| 1316 | 1306 |
| 1317 IntPoint AXObjectImpl::MaximumScrollOffset() const { | 1307 IntPoint AXObject::MaximumScrollOffset() const { |
| 1318 ScrollableArea* area = GetScrollableAreaIfScrollable(); | 1308 ScrollableArea* area = GetScrollableAreaIfScrollable(); |
| 1319 if (!area) | 1309 if (!area) |
| 1320 return IntPoint(); | 1310 return IntPoint(); |
| 1321 | 1311 |
| 1322 return IntPoint(area->MaximumScrollOffsetInt().Width(), | 1312 return IntPoint(area->MaximumScrollOffsetInt().Width(), |
| 1323 area->MaximumScrollOffsetInt().Height()); | 1313 area->MaximumScrollOffsetInt().Height()); |
| 1324 } | 1314 } |
| 1325 | 1315 |
| 1326 void AXObjectImpl::SetScrollOffset(const IntPoint& offset) const { | 1316 void AXObject::SetScrollOffset(const IntPoint& offset) const { |
| 1327 ScrollableArea* area = GetScrollableAreaIfScrollable(); | 1317 ScrollableArea* area = GetScrollableAreaIfScrollable(); |
| 1328 if (!area) | 1318 if (!area) |
| 1329 return; | 1319 return; |
| 1330 | 1320 |
| 1331 // TODO(bokan): This should potentially be a UserScroll. | 1321 // TODO(bokan): This should potentially be a UserScroll. |
| 1332 area->SetScrollOffset(ScrollOffset(offset.X(), offset.Y()), | 1322 area->SetScrollOffset(ScrollOffset(offset.X(), offset.Y()), |
| 1333 kProgrammaticScroll); | 1323 kProgrammaticScroll); |
| 1334 } | 1324 } |
| 1335 | 1325 |
| 1336 void AXObjectImpl::GetRelativeBounds( | 1326 void AXObject::GetRelativeBounds(AXObject** out_container, |
| 1337 AXObjectImpl** out_container, | 1327 FloatRect& out_bounds_in_container, |
| 1338 FloatRect& out_bounds_in_container, | 1328 SkMatrix44& out_container_transform) const { |
| 1339 SkMatrix44& out_container_transform) const { | |
| 1340 *out_container = nullptr; | 1329 *out_container = nullptr; |
| 1341 out_bounds_in_container = FloatRect(); | 1330 out_bounds_in_container = FloatRect(); |
| 1342 out_container_transform.setIdentity(); | 1331 out_container_transform.setIdentity(); |
| 1343 | 1332 |
| 1344 // First check if it has explicit bounds, for example if this element is tied | 1333 // First check if it has explicit bounds, for example if this element is tied |
| 1345 // to a canvas path. When explicit coordinates are provided, the ID of the | 1334 // to a canvas path. When explicit coordinates are provided, the ID of the |
| 1346 // explicit container element that the coordinates are relative to must be | 1335 // explicit container element that the coordinates are relative to must be |
| 1347 // provided too. | 1336 // provided too. |
| 1348 if (!explicit_element_rect_.IsEmpty()) { | 1337 if (!explicit_element_rect_.IsEmpty()) { |
| 1349 *out_container = AxObjectCache().ObjectFromAXID(explicit_container_id_); | 1338 *out_container = AxObjectCache().ObjectFromAXID(explicit_container_id_); |
| 1350 if (*out_container) { | 1339 if (*out_container) { |
| 1351 out_bounds_in_container = FloatRect(explicit_element_rect_); | 1340 out_bounds_in_container = FloatRect(explicit_element_rect_); |
| 1352 return; | 1341 return; |
| 1353 } | 1342 } |
| 1354 } | 1343 } |
| 1355 | 1344 |
| 1356 LayoutObject* layout_object = LayoutObjectForRelativeBounds(); | 1345 LayoutObject* layout_object = LayoutObjectForRelativeBounds(); |
| 1357 if (!layout_object) | 1346 if (!layout_object) |
| 1358 return; | 1347 return; |
| 1359 | 1348 |
| 1360 if (IsWebArea()) { | 1349 if (IsWebArea()) { |
| 1361 if (layout_object->GetFrame()->View()) { | 1350 if (layout_object->GetFrame()->View()) |
| 1362 out_bounds_in_container.SetSize( | 1351 out_bounds_in_container.SetSize( |
| 1363 FloatSize(layout_object->GetFrame()->View()->ContentsSize())); | 1352 FloatSize(layout_object->GetFrame()->View()->ContentsSize())); |
| 1364 } | |
| 1365 return; | 1353 return; |
| 1366 } | 1354 } |
| 1367 | 1355 |
| 1368 // First compute the container. The container must be an ancestor in the | 1356 // First compute the container. The container must be an ancestor in the |
| 1369 // accessibility tree, and its LayoutObject must be an ancestor in the layout | 1357 // accessibility tree, and its LayoutObject must be an ancestor in the layout |
| 1370 // tree. Get the first such ancestor that's either scrollable or has a paint | 1358 // tree. Get the first such ancestor that's either scrollable or has a paint |
| 1371 // layer. | 1359 // layer. |
| 1372 AXObjectImpl* container = ParentObjectUnignored(); | 1360 AXObject* container = ParentObjectUnignored(); |
| 1373 LayoutObject* container_layout_object = nullptr; | 1361 LayoutObject* container_layout_object = nullptr; |
| 1374 while (container) { | 1362 while (container) { |
| 1375 container_layout_object = container->GetLayoutObject(); | 1363 container_layout_object = container->GetLayoutObject(); |
| 1376 if (container_layout_object && | 1364 if (container_layout_object && |
| 1377 container_layout_object->IsBoxModelObject() && | 1365 container_layout_object->IsBoxModelObject() && |
| 1378 layout_object->IsDescendantOf(container_layout_object)) { | 1366 layout_object->IsDescendantOf(container_layout_object)) { |
| 1379 if (container->IsScrollableContainer() || | 1367 if (container->IsScrollableContainer() || |
| 1380 container_layout_object->HasLayer()) | 1368 container_layout_object->HasLayer()) |
| 1381 break; | 1369 break; |
| 1382 } | 1370 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1404 // scaling, etc. then return the full matrix instead. | 1392 // scaling, etc. then return the full matrix instead. |
| 1405 TransformationMatrix transform = layout_object->LocalToAncestorTransform( | 1393 TransformationMatrix transform = layout_object->LocalToAncestorTransform( |
| 1406 ToLayoutBoxModelObject(container_layout_object)); | 1394 ToLayoutBoxModelObject(container_layout_object)); |
| 1407 if (transform.IsIdentityOr2DTranslation()) { | 1395 if (transform.IsIdentityOr2DTranslation()) { |
| 1408 out_bounds_in_container.Move(transform.To2DTranslation()); | 1396 out_bounds_in_container.Move(transform.To2DTranslation()); |
| 1409 } else { | 1397 } else { |
| 1410 out_container_transform = TransformationMatrix::ToSkMatrix44(transform); | 1398 out_container_transform = TransformationMatrix::ToSkMatrix44(transform); |
| 1411 } | 1399 } |
| 1412 } | 1400 } |
| 1413 | 1401 |
| 1414 LayoutRect AXObjectImpl::GetBoundsInFrameCoordinates() const { | 1402 LayoutRect AXObject::GetBoundsInFrameCoordinates() const { |
| 1415 AXObjectImpl* container = nullptr; | 1403 AXObject* container = nullptr; |
| 1416 FloatRect bounds; | 1404 FloatRect bounds; |
| 1417 SkMatrix44 transform; | 1405 SkMatrix44 transform; |
| 1418 GetRelativeBounds(&container, bounds, transform); | 1406 GetRelativeBounds(&container, bounds, transform); |
| 1419 FloatRect computed_bounds(0, 0, bounds.Width(), bounds.Height()); | 1407 FloatRect computed_bounds(0, 0, bounds.Width(), bounds.Height()); |
| 1420 while (container && container != this) { | 1408 while (container && container != this) { |
| 1421 computed_bounds.Move(bounds.X(), bounds.Y()); | 1409 computed_bounds.Move(bounds.X(), bounds.Y()); |
| 1422 if (!container->IsWebArea()) { | 1410 if (!container->IsWebArea()) { |
| 1423 computed_bounds.Move(-container->GetScrollOffset().X(), | 1411 computed_bounds.Move(-container->GetScrollOffset().X(), |
| 1424 -container->GetScrollOffset().Y()); | 1412 -container->GetScrollOffset().Y()); |
| 1425 } | 1413 } |
| 1426 if (!transform.isIdentity()) { | 1414 if (!transform.isIdentity()) { |
| 1427 TransformationMatrix transformation_matrix(transform); | 1415 TransformationMatrix transformation_matrix(transform); |
| 1428 transformation_matrix.MapRect(computed_bounds); | 1416 transformation_matrix.MapRect(computed_bounds); |
| 1429 } | 1417 } |
| 1430 container->GetRelativeBounds(&container, bounds, transform); | 1418 container->GetRelativeBounds(&container, bounds, transform); |
| 1431 } | 1419 } |
| 1432 return LayoutRect(computed_bounds); | 1420 return LayoutRect(computed_bounds); |
| 1433 } | 1421 } |
| 1434 | 1422 |
| 1435 // | 1423 // |
| 1436 // Modify or take an action on an object. | 1424 // Modify or take an action on an object. |
| 1437 // | 1425 // |
| 1438 | 1426 |
| 1439 bool AXObjectImpl::Press() { | 1427 bool AXObject::Press() { |
| 1440 Document* document = GetDocument(); | 1428 Document* document = GetDocument(); |
| 1441 if (!document) | 1429 if (!document) |
| 1442 return false; | 1430 return false; |
| 1443 | 1431 |
| 1444 UserGestureIndicator gesture_indicator(DocumentUserGestureToken::Create( | 1432 UserGestureIndicator gesture_indicator(DocumentUserGestureToken::Create( |
| 1445 document, UserGestureToken::kNewGesture)); | 1433 document, UserGestureToken::kNewGesture)); |
| 1446 Element* action_elem = ActionElement(); | 1434 Element* action_elem = ActionElement(); |
| 1447 if (action_elem) { | 1435 if (action_elem) { |
| 1448 action_elem->AccessKeyAction(true); | 1436 action_elem->AccessKeyAction(true); |
| 1449 return true; | 1437 return true; |
| 1450 } | 1438 } |
| 1451 | 1439 |
| 1452 if (CanSetFocusAttribute()) { | 1440 if (CanSetFocusAttribute()) { |
| 1453 SetFocused(true); | 1441 SetFocused(true); |
| 1454 return true; | 1442 return true; |
| 1455 } | 1443 } |
| 1456 | 1444 |
| 1457 return false; | 1445 return false; |
| 1458 } | 1446 } |
| 1459 | 1447 |
| 1460 void AXObjectImpl::ScrollToMakeVisible() const { | 1448 void AXObject::ScrollToMakeVisible() const { |
| 1461 IntRect object_rect = PixelSnappedIntRect(GetBoundsInFrameCoordinates()); | 1449 IntRect object_rect = PixelSnappedIntRect(GetBoundsInFrameCoordinates()); |
| 1462 object_rect.SetLocation(IntPoint()); | 1450 object_rect.SetLocation(IntPoint()); |
| 1463 ScrollToMakeVisibleWithSubFocus(object_rect); | 1451 ScrollToMakeVisibleWithSubFocus(object_rect); |
| 1464 } | 1452 } |
| 1465 | 1453 |
| 1466 // This is a 1-dimensional scroll offset helper function that's applied | 1454 // This is a 1-dimensional scroll offset helper function that's applied |
| 1467 // separately in the horizontal and vertical directions, because the | 1455 // separately in the horizontal and vertical directions, because the |
| 1468 // logic is the same. The goal is to compute the best scroll offset | 1456 // logic is the same. The goal is to compute the best scroll offset |
| 1469 // in order to make an object visible within a viewport. | 1457 // in order to make an object visible within a viewport. |
| 1470 // | 1458 // |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 | 1541 |
| 1554 // Exit now if the focus is already within the viewport. | 1542 // Exit now if the focus is already within the viewport. |
| 1555 if (object_min - current_scroll_offset >= viewport_min && | 1543 if (object_min - current_scroll_offset >= viewport_min && |
| 1556 object_max - current_scroll_offset <= viewport_max) | 1544 object_max - current_scroll_offset <= viewport_max) |
| 1557 return current_scroll_offset; | 1545 return current_scroll_offset; |
| 1558 | 1546 |
| 1559 // Center the object in the viewport. | 1547 // Center the object in the viewport. |
| 1560 return (object_min + object_max - viewport_min - viewport_max) / 2; | 1548 return (object_min + object_max - viewport_min - viewport_max) / 2; |
| 1561 } | 1549 } |
| 1562 | 1550 |
| 1563 void AXObjectImpl::ScrollToMakeVisibleWithSubFocus( | 1551 void AXObject::ScrollToMakeVisibleWithSubFocus(const IntRect& subfocus) const { |
| 1564 const IntRect& subfocus) const { | |
| 1565 // Search up the parent chain until we find the first one that's scrollable. | 1552 // Search up the parent chain until we find the first one that's scrollable. |
| 1566 const AXObjectImpl* scroll_parent = ParentObject() ? ParentObject() : this; | 1553 const AXObject* scroll_parent = ParentObject() ? ParentObject() : this; |
| 1567 ScrollableArea* scrollable_area = 0; | 1554 ScrollableArea* scrollable_area = 0; |
| 1568 while (scroll_parent) { | 1555 while (scroll_parent) { |
| 1569 scrollable_area = scroll_parent->GetScrollableAreaIfScrollable(); | 1556 scrollable_area = scroll_parent->GetScrollableAreaIfScrollable(); |
| 1570 if (scrollable_area) | 1557 if (scrollable_area) |
| 1571 break; | 1558 break; |
| 1572 scroll_parent = scroll_parent->ParentObject(); | 1559 scroll_parent = scroll_parent->ParentObject(); |
| 1573 } | 1560 } |
| 1574 if (!scroll_parent || !scrollable_area) | 1561 if (!scroll_parent || !scrollable_area) |
| 1575 return; | 1562 return; |
| 1576 | 1563 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1604 PixelSnappedIntRect(scroll_parent->GetBoundsInFrameCoordinates()); | 1591 PixelSnappedIntRect(scroll_parent->GetBoundsInFrameCoordinates()); |
| 1605 new_subfocus.Move(new_element_rect.X(), new_element_rect.Y()); | 1592 new_subfocus.Move(new_element_rect.X(), new_element_rect.Y()); |
| 1606 new_subfocus.Move(-scroll_parent_rect.X(), -scroll_parent_rect.Y()); | 1593 new_subfocus.Move(-scroll_parent_rect.X(), -scroll_parent_rect.Y()); |
| 1607 | 1594 |
| 1608 if (scroll_parent->ParentObject()) { | 1595 if (scroll_parent->ParentObject()) { |
| 1609 // Recursively make sure the scroll parent itself is visible. | 1596 // Recursively make sure the scroll parent itself is visible. |
| 1610 scroll_parent->ScrollToMakeVisibleWithSubFocus(new_subfocus); | 1597 scroll_parent->ScrollToMakeVisibleWithSubFocus(new_subfocus); |
| 1611 } else { | 1598 } else { |
| 1612 // To minimize the number of notifications, only fire one on the topmost | 1599 // To minimize the number of notifications, only fire one on the topmost |
| 1613 // object that has been scrolled. | 1600 // object that has been scrolled. |
| 1614 AxObjectCache().PostNotification(const_cast<AXObjectImpl*>(this), | 1601 AxObjectCache().PostNotification(const_cast<AXObject*>(this), |
| 1615 AXObjectCacheImpl::kAXLocationChanged); | 1602 AXObjectCacheImpl::kAXLocationChanged); |
| 1616 } | 1603 } |
| 1617 } | 1604 } |
| 1618 | 1605 |
| 1619 void AXObjectImpl::ScrollToGlobalPoint(const IntPoint& global_point) const { | 1606 void AXObject::ScrollToGlobalPoint(const IntPoint& global_point) const { |
| 1620 // Search up the parent chain and create a vector of all scrollable parent | 1607 // Search up the parent chain and create a vector of all scrollable parent |
| 1621 // objects and ending with this object itself. | 1608 // objects and ending with this object itself. |
| 1622 HeapVector<Member<const AXObjectImpl>> objects; | 1609 HeapVector<Member<const AXObject>> objects; |
| 1623 AXObjectImpl* parent_object; | 1610 AXObject* parent_object; |
| 1624 for (parent_object = this->ParentObject(); parent_object; | 1611 for (parent_object = this->ParentObject(); parent_object; |
| 1625 parent_object = parent_object->ParentObject()) { | 1612 parent_object = parent_object->ParentObject()) { |
| 1626 if (parent_object->GetScrollableAreaIfScrollable()) | 1613 if (parent_object->GetScrollableAreaIfScrollable()) |
| 1627 objects.push_front(parent_object); | 1614 objects.push_front(parent_object); |
| 1628 } | 1615 } |
| 1629 objects.push_back(this); | 1616 objects.push_back(this); |
| 1630 | 1617 |
| 1631 // Start with the outermost scrollable (the main window) and try to scroll the | 1618 // Start with the outermost scrollable (the main window) and try to scroll the |
| 1632 // next innermost object to the given point. | 1619 // next innermost object to the given point. |
| 1633 int offset_x = 0, offset_y = 0; | 1620 int offset_x = 0, offset_y = 0; |
| 1634 IntPoint point = global_point; | 1621 IntPoint point = global_point; |
| 1635 size_t levels = objects.size() - 1; | 1622 size_t levels = objects.size() - 1; |
| 1636 for (size_t i = 0; i < levels; i++) { | 1623 for (size_t i = 0; i < levels; i++) { |
| 1637 const AXObjectImpl* outer = objects[i]; | 1624 const AXObject* outer = objects[i]; |
| 1638 const AXObjectImpl* inner = objects[i + 1]; | 1625 const AXObject* inner = objects[i + 1]; |
| 1639 ScrollableArea* scrollable_area = outer->GetScrollableAreaIfScrollable(); | 1626 ScrollableArea* scrollable_area = outer->GetScrollableAreaIfScrollable(); |
| 1640 | 1627 |
| 1641 IntRect inner_rect = | 1628 IntRect inner_rect = |
| 1642 inner->IsWebArea() | 1629 inner->IsWebArea() |
| 1643 ? PixelSnappedIntRect( | 1630 ? PixelSnappedIntRect( |
| 1644 inner->ParentObject()->GetBoundsInFrameCoordinates()) | 1631 inner->ParentObject()->GetBoundsInFrameCoordinates()) |
| 1645 : PixelSnappedIntRect(inner->GetBoundsInFrameCoordinates()); | 1632 : PixelSnappedIntRect(inner->GetBoundsInFrameCoordinates()); |
| 1646 IntRect object_rect = inner_rect; | 1633 IntRect object_rect = inner_rect; |
| 1647 IntSize scroll_offset = scrollable_area->ScrollOffsetInt(); | 1634 IntSize scroll_offset = scrollable_area->ScrollOffsetInt(); |
| 1648 | 1635 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1677 } | 1664 } |
| 1678 | 1665 |
| 1679 // To minimize the number of notifications, only fire one on the topmost | 1666 // To minimize the number of notifications, only fire one on the topmost |
| 1680 // object that has been scrolled. | 1667 // object that has been scrolled. |
| 1681 DCHECK(objects[0]); | 1668 DCHECK(objects[0]); |
| 1682 // TODO(nektar): Switch to postNotification(objects[0] and remove |getNode|. | 1669 // TODO(nektar): Switch to postNotification(objects[0] and remove |getNode|. |
| 1683 AxObjectCache().PostNotification(objects[0]->GetNode(), | 1670 AxObjectCache().PostNotification(objects[0]->GetNode(), |
| 1684 AXObjectCacheImpl::kAXLocationChanged); | 1671 AXObjectCacheImpl::kAXLocationChanged); |
| 1685 } | 1672 } |
| 1686 | 1673 |
| 1687 void AXObjectImpl::SetSequentialFocusNavigationStartingPoint() { | 1674 void AXObject::SetSequentialFocusNavigationStartingPoint() { |
| 1688 // Call it on the nearest ancestor that overrides this with a specific | 1675 // Call it on the nearest ancestor that overrides this with a specific |
| 1689 // implementation. | 1676 // implementation. |
| 1690 if (ParentObject()) | 1677 if (ParentObject()) |
| 1691 ParentObject()->SetSequentialFocusNavigationStartingPoint(); | 1678 ParentObject()->SetSequentialFocusNavigationStartingPoint(); |
| 1692 } | 1679 } |
| 1693 | 1680 |
| 1694 void AXObjectImpl::NotifyIfIgnoredValueChanged() { | 1681 void AXObject::NotifyIfIgnoredValueChanged() { |
| 1695 bool is_ignored = AccessibilityIsIgnored(); | 1682 bool is_ignored = AccessibilityIsIgnored(); |
| 1696 if (LastKnownIsIgnoredValue() != is_ignored) { | 1683 if (LastKnownIsIgnoredValue() != is_ignored) { |
| 1697 AxObjectCache().ChildrenChanged(ParentObject()); | 1684 AxObjectCache().ChildrenChanged(ParentObject()); |
| 1698 SetLastKnownIsIgnoredValue(is_ignored); | 1685 SetLastKnownIsIgnoredValue(is_ignored); |
| 1699 } | 1686 } |
| 1700 } | 1687 } |
| 1701 | 1688 |
| 1702 void AXObjectImpl::SelectionChanged() { | 1689 void AXObject::SelectionChanged() { |
| 1703 if (AXObjectImpl* parent = ParentObjectIfExists()) | 1690 if (AXObject* parent = ParentObjectIfExists()) |
| 1704 parent->SelectionChanged(); | 1691 parent->SelectionChanged(); |
| 1705 } | 1692 } |
| 1706 | 1693 |
| 1707 int AXObjectImpl::LineForPosition(const VisiblePosition& position) const { | 1694 int AXObject::LineForPosition(const VisiblePosition& position) const { |
| 1708 if (position.IsNull() || !GetNode()) | 1695 if (position.IsNull() || !GetNode()) |
| 1709 return -1; | 1696 return -1; |
| 1710 | 1697 |
| 1711 // If the position is not in the same editable region as this AX object, | 1698 // If the position is not in the same editable region as this AX object, |
| 1712 // return -1. | 1699 // return -1. |
| 1713 Node* container_node = position.DeepEquivalent().ComputeContainerNode(); | 1700 Node* container_node = position.DeepEquivalent().ComputeContainerNode(); |
| 1714 if (!container_node->IsShadowIncludingInclusiveAncestorOf(GetNode()) && | 1701 if (!container_node->IsShadowIncludingInclusiveAncestorOf(GetNode()) && |
| 1715 !GetNode()->IsShadowIncludingInclusiveAncestorOf(container_node)) | 1702 !GetNode()->IsShadowIncludingInclusiveAncestorOf(container_node)) |
| 1716 return -1; | 1703 return -1; |
| 1717 | 1704 |
| 1718 int line_count = -1; | 1705 int line_count = -1; |
| 1719 VisiblePosition current_position = position; | 1706 VisiblePosition current_position = position; |
| 1720 VisiblePosition previous_position; | 1707 VisiblePosition previous_position; |
| 1721 | 1708 |
| 1722 // Move up until we get to the top. | 1709 // Move up until we get to the top. |
| 1723 // FIXME: This only takes us to the top of the rootEditableElement, not the | 1710 // FIXME: This only takes us to the top of the rootEditableElement, not the |
| 1724 // top of the top document. | 1711 // top of the top document. |
| 1725 do { | 1712 do { |
| 1726 previous_position = current_position; | 1713 previous_position = current_position; |
| 1727 current_position = PreviousLinePosition(current_position, LayoutUnit(), | 1714 current_position = PreviousLinePosition(current_position, LayoutUnit(), |
| 1728 kHasEditableAXRole); | 1715 kHasEditableAXRole); |
| 1729 ++line_count; | 1716 ++line_count; |
| 1730 } while (current_position.IsNotNull() && | 1717 } while (current_position.IsNotNull() && |
| 1731 !InSameLine(current_position, previous_position)); | 1718 !InSameLine(current_position, previous_position)); |
| 1732 | 1719 |
| 1733 return line_count; | 1720 return line_count; |
| 1734 } | 1721 } |
| 1735 | 1722 |
| 1736 bool AXObjectImpl::IsARIAControl(AccessibilityRole aria_role) { | 1723 bool AXObject::IsARIAControl(AccessibilityRole aria_role) { |
| 1737 return IsARIAInput(aria_role) || aria_role == kButtonRole || | 1724 return IsARIAInput(aria_role) || aria_role == kButtonRole || |
| 1738 aria_role == kComboBoxRole || aria_role == kSliderRole; | 1725 aria_role == kComboBoxRole || aria_role == kSliderRole; |
| 1739 } | 1726 } |
| 1740 | 1727 |
| 1741 bool AXObjectImpl::IsARIAInput(AccessibilityRole aria_role) { | 1728 bool AXObject::IsARIAInput(AccessibilityRole aria_role) { |
| 1742 return aria_role == kRadioButtonRole || aria_role == kCheckBoxRole || | 1729 return aria_role == kRadioButtonRole || aria_role == kCheckBoxRole || |
| 1743 aria_role == kTextFieldRole || aria_role == kSwitchRole || | 1730 aria_role == kTextFieldRole || aria_role == kSwitchRole || |
| 1744 aria_role == kSearchBoxRole; | 1731 aria_role == kSearchBoxRole; |
| 1745 } | 1732 } |
| 1746 | 1733 |
| 1747 AccessibilityRole AXObjectImpl::AriaRoleToWebCoreRole(const String& value) { | 1734 AccessibilityRole AXObject::AriaRoleToWebCoreRole(const String& value) { |
| 1748 DCHECK(!value.IsEmpty()); | 1735 DCHECK(!value.IsEmpty()); |
| 1749 | 1736 |
| 1750 static const ARIARoleMap* role_map = CreateARIARoleMap(); | 1737 static const ARIARoleMap* role_map = CreateARIARoleMap(); |
| 1751 | 1738 |
| 1752 Vector<String> role_vector; | 1739 Vector<String> role_vector; |
| 1753 value.Split(' ', role_vector); | 1740 value.Split(' ', role_vector); |
| 1754 AccessibilityRole role = kUnknownRole; | 1741 AccessibilityRole role = kUnknownRole; |
| 1755 for (const auto& child : role_vector) { | 1742 for (const auto& child : role_vector) { |
| 1756 role = role_map->at(child); | 1743 role = role_map->at(child); |
| 1757 if (role) | 1744 if (role) |
| 1758 return role; | 1745 return role; |
| 1759 } | 1746 } |
| 1760 | 1747 |
| 1761 return role; | 1748 return role; |
| 1762 } | 1749 } |
| 1763 | 1750 |
| 1764 bool AXObjectImpl::IsInsideFocusableElementOrARIAWidget(const Node& node) { | 1751 bool AXObject::IsInsideFocusableElementOrARIAWidget(const Node& node) { |
| 1765 const Node* cur_node = &node; | 1752 const Node* cur_node = &node; |
| 1766 do { | 1753 do { |
| 1767 if (cur_node->IsElementNode()) { | 1754 if (cur_node->IsElementNode()) { |
| 1768 const Element* element = ToElement(cur_node); | 1755 const Element* element = ToElement(cur_node); |
| 1769 if (element->IsFocusable()) | 1756 if (element->IsFocusable()) |
| 1770 return true; | 1757 return true; |
| 1771 String role = element->getAttribute("role"); | 1758 String role = element->getAttribute("role"); |
| 1772 if (!role.IsEmpty() && AXObjectImpl::IncludesARIAWidgetRole(role)) | 1759 if (!role.IsEmpty() && AXObject::IncludesARIAWidgetRole(role)) |
| 1773 return true; | 1760 return true; |
| 1774 if (HasInteractiveARIAAttribute(*element)) | 1761 if (HasInteractiveARIAAttribute(*element)) |
| 1775 return true; | 1762 return true; |
| 1776 } | 1763 } |
| 1777 cur_node = cur_node->parentNode(); | 1764 cur_node = cur_node->parentNode(); |
| 1778 } while (cur_node && !isHTMLBodyElement(node)); | 1765 } while (cur_node && !isHTMLBodyElement(node)); |
| 1779 return false; | 1766 return false; |
| 1780 } | 1767 } |
| 1781 | 1768 |
| 1782 bool AXObjectImpl::HasInteractiveARIAAttribute(const Element& element) { | 1769 bool AXObject::HasInteractiveARIAAttribute(const Element& element) { |
| 1783 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_interactive_widget_attributes); | 1770 for (size_t i = 0; i < WTF_ARRAY_LENGTH(g_aria_interactive_widget_attributes); |
| 1784 ++i) { | 1771 ++i) { |
| 1785 const char* attribute = g_aria_interactive_widget_attributes[i]; | 1772 const char* attribute = g_aria_interactive_widget_attributes[i]; |
| 1786 if (element.hasAttribute(attribute)) { | 1773 if (element.hasAttribute(attribute)) { |
| 1787 return true; | 1774 return true; |
| 1788 } | 1775 } |
| 1789 } | 1776 } |
| 1790 return false; | 1777 return false; |
| 1791 } | 1778 } |
| 1792 | 1779 |
| 1793 bool AXObjectImpl::IncludesARIAWidgetRole(const String& role) { | 1780 bool AXObject::IncludesARIAWidgetRole(const String& role) { |
| 1794 static const HashSet<String, CaseFoldingHash>* role_set = | 1781 static const HashSet<String, CaseFoldingHash>* role_set = |
| 1795 CreateARIARoleWidgetSet(); | 1782 CreateARIARoleWidgetSet(); |
| 1796 | 1783 |
| 1797 Vector<String> role_vector; | 1784 Vector<String> role_vector; |
| 1798 role.Split(' ', role_vector); | 1785 role.Split(' ', role_vector); |
| 1799 for (const auto& child : role_vector) { | 1786 for (const auto& child : role_vector) { |
| 1800 if (role_set->Contains(child)) | 1787 if (role_set->Contains(child)) |
| 1801 return true; | 1788 return true; |
| 1802 } | 1789 } |
| 1803 return false; | 1790 return false; |
| 1804 } | 1791 } |
| 1805 | 1792 |
| 1806 bool AXObjectImpl::NameFromContents() const { | 1793 bool AXObject::NameFromContents() const { |
| 1807 // ARIA 1.1, section 5.2.7.5. | 1794 // ARIA 1.1, section 5.2.7.5. |
| 1808 switch (RoleValue()) { | 1795 switch (RoleValue()) { |
| 1809 case kAnchorRole: | 1796 case kAnchorRole: |
| 1810 case kButtonRole: | 1797 case kButtonRole: |
| 1811 case kCellRole: | 1798 case kCellRole: |
| 1812 case kCheckBoxRole: | 1799 case kCheckBoxRole: |
| 1813 case kColumnHeaderRole: | 1800 case kColumnHeaderRole: |
| 1814 case kDirectoryRole: | 1801 case kDirectoryRole: |
| 1815 case kDisclosureTriangleRole: | 1802 case kDisclosureTriangleRole: |
| 1816 case kHeadingRole: | 1803 case kHeadingRole: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1841 return true; | 1828 return true; |
| 1842 } | 1829 } |
| 1843 const Node* node = this->GetNode(); | 1830 const Node* node = this->GetNode(); |
| 1844 return node && node->IsElementNode() && ToElement(node)->IsFocusable(); | 1831 return node && node->IsElementNode() && ToElement(node)->IsFocusable(); |
| 1845 } | 1832 } |
| 1846 default: | 1833 default: |
| 1847 return false; | 1834 return false; |
| 1848 } | 1835 } |
| 1849 } | 1836 } |
| 1850 | 1837 |
| 1851 AccessibilityRole AXObjectImpl::ButtonRoleType() const { | 1838 AccessibilityRole AXObject::ButtonRoleType() const { |
| 1852 // If aria-pressed is present, then it should be exposed as a toggle button. | 1839 // If aria-pressed is present, then it should be exposed as a toggle button. |
| 1853 // http://www.w3.org/TR/wai-aria/states_and_properties#aria-pressed | 1840 // http://www.w3.org/TR/wai-aria/states_and_properties#aria-pressed |
| 1854 if (AriaPressedIsPresent()) | 1841 if (AriaPressedIsPresent()) |
| 1855 return kToggleButtonRole; | 1842 return kToggleButtonRole; |
| 1856 if (AriaHasPopup()) | 1843 if (AriaHasPopup()) |
| 1857 return kPopUpButtonRole; | 1844 return kPopUpButtonRole; |
| 1858 // We don't contemplate RadioButtonRole, as it depends on the input | 1845 // We don't contemplate RadioButtonRole, as it depends on the input |
| 1859 // type. | 1846 // type. |
| 1860 | 1847 |
| 1861 return kButtonRole; | 1848 return kButtonRole; |
| 1862 } | 1849 } |
| 1863 | 1850 |
| 1864 const AtomicString& AXObjectImpl::RoleName(AccessibilityRole role) { | 1851 const AtomicString& AXObject::RoleName(AccessibilityRole role) { |
| 1865 static const Vector<AtomicString>* role_name_vector = CreateRoleNameVector(); | 1852 static const Vector<AtomicString>* role_name_vector = CreateRoleNameVector(); |
| 1866 | 1853 |
| 1867 return role_name_vector->at(role); | 1854 return role_name_vector->at(role); |
| 1868 } | 1855 } |
| 1869 | 1856 |
| 1870 const AtomicString& AXObjectImpl::InternalRoleName(AccessibilityRole role) { | 1857 const AtomicString& AXObject::InternalRoleName(AccessibilityRole role) { |
| 1871 static const Vector<AtomicString>* internal_role_name_vector = | 1858 static const Vector<AtomicString>* internal_role_name_vector = |
| 1872 CreateInternalRoleNameVector(); | 1859 CreateInternalRoleNameVector(); |
| 1873 | 1860 |
| 1874 return internal_role_name_vector->at(role); | 1861 return internal_role_name_vector->at(role); |
| 1875 } | 1862 } |
| 1876 | 1863 |
| 1877 DEFINE_TRACE(AXObjectImpl) { | 1864 DEFINE_TRACE(AXObject) { |
| 1878 visitor->Trace(children_); | 1865 visitor->Trace(children_); |
| 1879 visitor->Trace(parent_); | 1866 visitor->Trace(parent_); |
| 1880 visitor->Trace(cached_live_region_root_); | 1867 visitor->Trace(cached_live_region_root_); |
| 1881 visitor->Trace(ax_object_cache_); | 1868 visitor->Trace(ax_object_cache_); |
| 1882 } | 1869 } |
| 1883 | 1870 |
| 1884 } // namespace blink | 1871 } // namespace blink |
| OLD | NEW |