Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: content/browser/accessibility/browser_accessibility_win.cc

Issue 1952863003: Implemented the "aria-current" state on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/accessibility/browser_accessibility_win.h" 5 #include "content/browser/accessibility/browser_accessibility_win.h"
6 6
7 #include <UIAutomationClient.h> 7 #include <UIAutomationClient.h>
8 #include <UIAutomationCoreApi.h> 8 #include <UIAutomationCoreApi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 3363 matching lines...) Expand 10 before | Expand all | Expand 10 after
3374 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY, 3374 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY,
3375 "container-busy"); 3375 "container-busy");
3376 3376
3377 // Expose the non-standard explicit-name IA2 attribute. 3377 // Expose the non-standard explicit-name IA2 attribute.
3378 int name_from; 3378 int name_from;
3379 if (GetIntAttribute(ui::AX_ATTR_NAME_FROM, &name_from) && 3379 if (GetIntAttribute(ui::AX_ATTR_NAME_FROM, &name_from) &&
3380 name_from != ui::AX_NAME_FROM_CONTENTS) { 3380 name_from != ui::AX_NAME_FROM_CONTENTS) {
3381 win_attributes_->ia2_attributes.push_back(L"explicit-name:true"); 3381 win_attributes_->ia2_attributes.push_back(L"explicit-name:true");
3382 } 3382 }
3383 3383
3384 // Expose the aria-current attribute.
3385 int32_t aria_current;
3386 if (GetIntAttribute(ui::AX_ATTR_ARIA_CURRENT, &aria_current)) {
3387 switch (static_cast<ui::AXAriaCurrent>(aria_current)) {
3388 case ui::AX_ARIA_CURRENT_NONE:
3389 break;
3390 case ui::AX_ARIA_CURRENT_FALSE:
3391 win_attributes_->ia2_attributes.push_back(L"current:false");
3392 break;
3393 case ui::AX_ARIA_CURRENT_TRUE:
3394 win_attributes_->ia2_attributes.push_back(L"current:true");
3395 break;
3396 case ui::AX_ARIA_CURRENT_PAGE:
3397 win_attributes_->ia2_attributes.push_back(L"current:page");
3398 break;
3399 case ui::AX_ARIA_CURRENT_LOCATION:
3400 win_attributes_->ia2_attributes.push_back(L"current:location");
3401 break;
3402 case ui::AX_ARIA_CURRENT_DATE:
3403 win_attributes_->ia2_attributes.push_back(L"current:date");
3404 break;
3405 case ui::AX_ARIA_CURRENT_TIME:
3406 win_attributes_->ia2_attributes.push_back(L"current:time");
3407 break;
3408 }
3409 }
3410
3384 // Expose table cell index. 3411 // Expose table cell index.
3385 if (IsCellOrTableHeaderRole()) { 3412 if (IsCellOrTableHeaderRole()) {
3386 BrowserAccessibility* table = GetParent(); 3413 BrowserAccessibility* table = GetParent();
3387 while (table && table->GetRole() != ui::AX_ROLE_TABLE) 3414 while (table && table->GetRole() != ui::AX_ROLE_TABLE)
3388 table = table->GetParent(); 3415 table = table->GetParent();
3389 if (table) { 3416 if (table) {
3390 const std::vector<int32_t>& unique_cell_ids = 3417 const std::vector<int32_t>& unique_cell_ids =
3391 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); 3418 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS);
3392 for (size_t i = 0; i < unique_cell_ids.size(); ++i) { 3419 for (size_t i = 0; i < unique_cell_ids.size(); ++i) {
3393 if (unique_cell_ids[i] == GetId()) { 3420 if (unique_cell_ids[i] == GetId()) {
3394 win_attributes_->ia2_attributes.push_back( 3421 win_attributes_->ia2_attributes.push_back(
3395 base::string16(L"table-cell-index:") + base::IntToString16(i)); 3422 base::string16(L"table-cell-index:") + base::IntToString16(i));
3396 } 3423 }
3397 } 3424 }
3398 } 3425 }
3399 } 3426 }
3400 3427
3401 // Expose row or column header sort direction. 3428 // Expose row or column header sort direction.
3402 int32_t sort_direction; 3429 int32_t sort_direction;
3403 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER || 3430 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER ||
3404 ia_role() == ROLE_SYSTEM_ROWHEADER) && 3431 ia_role() == ROLE_SYSTEM_ROWHEADER) &&
3405 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION, &sort_direction)) { 3432 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION, &sort_direction)) {
3406 switch (sort_direction) { 3433 switch (static_cast<ui::AXSortDirection>(sort_direction)) {
3407 case ui::AX_SORT_DIRECTION_UNSORTED: 3434 case ui::AX_SORT_DIRECTION_UNSORTED:
3408 win_attributes_->ia2_attributes.push_back(L"sort:none"); 3435 win_attributes_->ia2_attributes.push_back(L"sort:none");
3409 break; 3436 break;
3410 case ui::AX_SORT_DIRECTION_ASCENDING: 3437 case ui::AX_SORT_DIRECTION_ASCENDING:
3411 win_attributes_->ia2_attributes.push_back(L"sort:ascending"); 3438 win_attributes_->ia2_attributes.push_back(L"sort:ascending");
3412 break; 3439 break;
3413 case ui::AX_SORT_DIRECTION_DESCENDING: 3440 case ui::AX_SORT_DIRECTION_DESCENDING:
3414 win_attributes_->ia2_attributes.push_back(L"sort:descending"); 3441 win_attributes_->ia2_attributes.push_back(L"sort:descending");
3415 break; 3442 break;
3416 case ui::AX_SORT_DIRECTION_OTHER: 3443 case ui::AX_SORT_DIRECTION_OTHER:
3417 win_attributes_->ia2_attributes.push_back(L"sort:other"); 3444 win_attributes_->ia2_attributes.push_back(L"sort:other");
3418 break; 3445 break;
3419 default:
3420 NOTREACHED();
3421 } 3446 }
3422 } 3447 }
3423 3448
3424 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME); 3449 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME);
3425 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); 3450 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION);
3426 3451
3427 base::string16 value = GetValue(); 3452 base::string16 value = GetValue();
3428 3453
3429 // On Windows, the value of a document should be its url. 3454 // On Windows, the value of a document should be its url.
3430 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || 3455 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA ||
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
3733 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE, 3758 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE,
3734 &aria_invalid_value)) { 3759 &aria_invalid_value)) {
3735 SanitizeStringAttributeForIA2(aria_invalid_value, &aria_invalid_value); 3760 SanitizeStringAttributeForIA2(aria_invalid_value, &aria_invalid_value);
3736 attributes.push_back(L"invalid:" + aria_invalid_value); 3761 attributes.push_back(L"invalid:" + aria_invalid_value);
3737 } else { 3762 } else {
3738 // Set the attribute to L"true", since we cannot be more specific. 3763 // Set the attribute to L"true", since we cannot be more specific.
3739 attributes.push_back(L"invalid:true"); 3764 attributes.push_back(L"invalid:true");
3740 } 3765 }
3741 break; 3766 break;
3742 } 3767 }
3743 default:
3744 NOTREACHED();
3745 } 3768 }
3746 3769
3747 base::string16 language(GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE)); 3770 base::string16 language(GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE));
3748 // Default value should be L"en-US". 3771 // Default value should be L"en-US".
3749 if (language.empty()) { 3772 if (language.empty()) {
3750 attributes.push_back(L"language:en-US"); 3773 attributes.push_back(L"language:en-US");
3751 } else { 3774 } else {
3752 SanitizeStringAttributeForIA2(language, &language); 3775 SanitizeStringAttributeForIA2(language, &language);
3753 attributes.push_back(L"language:" + language); 3776 attributes.push_back(L"language:" + language);
3754 } 3777 }
(...skipping 24 matching lines...) Expand all
3779 case ui::AX_TEXT_DIRECTION_RTL: 3802 case ui::AX_TEXT_DIRECTION_RTL:
3780 attributes.push_back(L"writing-mode:rl"); 3803 attributes.push_back(L"writing-mode:rl");
3781 break; 3804 break;
3782 case ui::AX_TEXT_DIRECTION_TTB: 3805 case ui::AX_TEXT_DIRECTION_TTB:
3783 attributes.push_back(L"writing-mode:tb"); 3806 attributes.push_back(L"writing-mode:tb");
3784 break; 3807 break;
3785 case ui::AX_TEXT_DIRECTION_BTT: 3808 case ui::AX_TEXT_DIRECTION_BTT:
3786 // Not listed in the IA2 Spec. 3809 // Not listed in the IA2 Spec.
3787 attributes.push_back(L"writing-mode:bt"); 3810 attributes.push_back(L"writing-mode:bt");
3788 break; 3811 break;
3789 default:
3790 NOTREACHED();
3791 } 3812 }
3792 3813
3793 return attributes; 3814 return attributes;
3794 } 3815 }
3795 3816
3796 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() { 3817 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() {
3797 AddRef(); 3818 AddRef();
3798 return this; 3819 return this;
3799 } 3820 }
3800 3821
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 case IA2_TEXT_BOUNDARY_WORD: 4245 case IA2_TEXT_BOUNDARY_WORD:
4225 return ui::WORD_BOUNDARY; 4246 return ui::WORD_BOUNDARY;
4226 case IA2_TEXT_BOUNDARY_LINE: 4247 case IA2_TEXT_BOUNDARY_LINE:
4227 return ui::LINE_BOUNDARY; 4248 return ui::LINE_BOUNDARY;
4228 case IA2_TEXT_BOUNDARY_SENTENCE: 4249 case IA2_TEXT_BOUNDARY_SENTENCE:
4229 return ui::SENTENCE_BOUNDARY; 4250 return ui::SENTENCE_BOUNDARY;
4230 case IA2_TEXT_BOUNDARY_PARAGRAPH: 4251 case IA2_TEXT_BOUNDARY_PARAGRAPH:
4231 return ui::PARAGRAPH_BOUNDARY; 4252 return ui::PARAGRAPH_BOUNDARY;
4232 case IA2_TEXT_BOUNDARY_ALL: 4253 case IA2_TEXT_BOUNDARY_ALL:
4233 return ui::ALL_BOUNDARY; 4254 return ui::ALL_BOUNDARY;
4234 default:
4235 NOTREACHED();
4236 } 4255 }
4256 NOTREACHED();
4237 return ui::CHAR_BOUNDARY; 4257 return ui::CHAR_BOUNDARY;
4238 } 4258 }
4239 4259
4240 LONG BrowserAccessibilityWin::FindBoundary( 4260 LONG BrowserAccessibilityWin::FindBoundary(
4241 const base::string16& text, 4261 const base::string16& text,
4242 IA2TextBoundaryType ia2_boundary, 4262 IA2TextBoundaryType ia2_boundary,
4243 LONG start_offset, 4263 LONG start_offset,
4244 ui::TextBoundaryDirection direction) { 4264 ui::TextBoundaryDirection direction) {
4245 HandleSpecialTextOffset(text, &start_offset); 4265 HandleSpecialTextOffset(text, &start_offset);
4246 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD) 4266 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD)
(...skipping 24 matching lines...) Expand all
4271 --iterator; 4291 --iterator;
4272 return static_cast<LONG>(iterator->first); 4292 return static_cast<LONG>(iterator->first);
4273 } 4293 }
4274 case ui::FORWARDS_DIRECTION: { 4294 case ui::FORWARDS_DIRECTION: {
4275 const auto iterator = 4295 const auto iterator =
4276 offset_to_text_attributes().upper_bound(start_offset); 4296 offset_to_text_attributes().upper_bound(start_offset);
4277 if (iterator == offset_to_text_attributes().end()) 4297 if (iterator == offset_to_text_attributes().end())
4278 return text_length; 4298 return text_length;
4279 return static_cast<LONG>(iterator->first); 4299 return static_cast<LONG>(iterator->first);
4280 } 4300 }
4281 default:
4282 NOTREACHED();
4283 } 4301 }
4284 4302
4285 return start_offset; 4303 return start_offset;
4286 } 4304 }
4287 4305
4288 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32_t id) const { 4306 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32_t id) const {
4289 if (!instance_active()) 4307 if (!instance_active())
4290 return nullptr; 4308 return nullptr;
4291 return ToBrowserAccessibilityWin(manager()->GetFromID(id)); 4309 return ToBrowserAccessibilityWin(manager()->GetFromID(id));
4292 } 4310 }
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 return static_cast<BrowserAccessibilityWin*>(obj); 4981 return static_cast<BrowserAccessibilityWin*>(obj);
4964 } 4982 }
4965 4983
4966 const BrowserAccessibilityWin* 4984 const BrowserAccessibilityWin*
4967 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { 4985 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) {
4968 DCHECK(!obj || obj->IsNative()); 4986 DCHECK(!obj || obj->IsNative());
4969 return static_cast<const BrowserAccessibilityWin*>(obj); 4987 return static_cast<const BrowserAccessibilityWin*>(obj);
4970 } 4988 }
4971 4989
4972 } // namespace content 4990 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698