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

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: Fixed switch statements to handle NONE case. 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
« no previous file with comments | « no previous file | content/browser/accessibility/dump_accessibility_tree_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_state;
3386 if (GetIntAttribute(ui::AX_ATTR_ARIA_CURRENT_STATE, &aria_current_state)) {
3387 switch (static_cast<ui::AXAriaCurrentState>(aria_current_state)) {
3388 case ui::AX_ARIA_CURRENT_STATE_NONE:
3389 break;
3390 case ui::AX_ARIA_CURRENT_STATE_FALSE:
3391 win_attributes_->ia2_attributes.push_back(L"current:false");
3392 break;
3393 case ui::AX_ARIA_CURRENT_STATE_TRUE:
3394 win_attributes_->ia2_attributes.push_back(L"current:true");
3395 break;
3396 case ui::AX_ARIA_CURRENT_STATE_PAGE:
3397 win_attributes_->ia2_attributes.push_back(L"current:page");
3398 break;
3399 case ui::AX_ARIA_CURRENT_STATE_STEP:
3400 win_attributes_->ia2_attributes.push_back(L"current:step");
3401 break;
3402 case ui::AX_ARIA_CURRENT_STATE_LOCATION:
3403 win_attributes_->ia2_attributes.push_back(L"current:location");
3404 break;
3405 case ui::AX_ARIA_CURRENT_STATE_DATE:
3406 win_attributes_->ia2_attributes.push_back(L"current:date");
3407 break;
3408 case ui::AX_ARIA_CURRENT_STATE_TIME:
3409 win_attributes_->ia2_attributes.push_back(L"current:time");
3410 break;
3411 }
3412 }
3413
3384 // Expose table cell index. 3414 // Expose table cell index.
3385 if (IsCellOrTableHeaderRole()) { 3415 if (IsCellOrTableHeaderRole()) {
3386 BrowserAccessibility* table = GetParent(); 3416 BrowserAccessibility* table = GetParent();
3387 while (table && table->GetRole() != ui::AX_ROLE_TABLE) 3417 while (table && table->GetRole() != ui::AX_ROLE_TABLE)
3388 table = table->GetParent(); 3418 table = table->GetParent();
3389 if (table) { 3419 if (table) {
3390 const std::vector<int32_t>& unique_cell_ids = 3420 const std::vector<int32_t>& unique_cell_ids =
3391 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); 3421 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS);
3392 for (size_t i = 0; i < unique_cell_ids.size(); ++i) { 3422 for (size_t i = 0; i < unique_cell_ids.size(); ++i) {
3393 if (unique_cell_ids[i] == GetId()) { 3423 if (unique_cell_ids[i] == GetId()) {
3394 win_attributes_->ia2_attributes.push_back( 3424 win_attributes_->ia2_attributes.push_back(
3395 base::string16(L"table-cell-index:") + base::IntToString16(i)); 3425 base::string16(L"table-cell-index:") + base::IntToString16(i));
3396 } 3426 }
3397 } 3427 }
3398 } 3428 }
3399 } 3429 }
3400 3430
3401 // Expose row or column header sort direction. 3431 // Expose row or column header sort direction.
3402 int32_t sort_direction; 3432 int32_t sort_direction;
3403 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER || 3433 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER ||
3404 ia_role() == ROLE_SYSTEM_ROWHEADER) && 3434 ia_role() == ROLE_SYSTEM_ROWHEADER) &&
3405 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION, &sort_direction)) { 3435 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION, &sort_direction)) {
3406 switch (sort_direction) { 3436 switch (static_cast<ui::AXSortDirection>(sort_direction)) {
3437 case ui::AX_SORT_DIRECTION_NONE:
3438 break;
3407 case ui::AX_SORT_DIRECTION_UNSORTED: 3439 case ui::AX_SORT_DIRECTION_UNSORTED:
3408 win_attributes_->ia2_attributes.push_back(L"sort:none"); 3440 win_attributes_->ia2_attributes.push_back(L"sort:none");
3409 break; 3441 break;
3410 case ui::AX_SORT_DIRECTION_ASCENDING: 3442 case ui::AX_SORT_DIRECTION_ASCENDING:
3411 win_attributes_->ia2_attributes.push_back(L"sort:ascending"); 3443 win_attributes_->ia2_attributes.push_back(L"sort:ascending");
3412 break; 3444 break;
3413 case ui::AX_SORT_DIRECTION_DESCENDING: 3445 case ui::AX_SORT_DIRECTION_DESCENDING:
3414 win_attributes_->ia2_attributes.push_back(L"sort:descending"); 3446 win_attributes_->ia2_attributes.push_back(L"sort:descending");
3415 break; 3447 break;
3416 case ui::AX_SORT_DIRECTION_OTHER: 3448 case ui::AX_SORT_DIRECTION_OTHER:
3417 win_attributes_->ia2_attributes.push_back(L"sort:other"); 3449 win_attributes_->ia2_attributes.push_back(L"sort:other");
3418 break; 3450 break;
3419 default:
3420 NOTREACHED();
3421 } 3451 }
3422 } 3452 }
3423 3453
3424 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME); 3454 win_attributes_->name = GetString16Attribute(ui::AX_ATTR_NAME);
3425 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION); 3455 win_attributes_->description = GetString16Attribute(ui::AX_ATTR_DESCRIPTION);
3426 3456
3427 base::string16 value = GetValue(); 3457 base::string16 value = GetValue();
3428 3458
3429 // On Windows, the value of a document should be its url. 3459 // On Windows, the value of a document should be its url.
3430 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA || 3460 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, 3763 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE,
3734 &aria_invalid_value)) { 3764 &aria_invalid_value)) {
3735 SanitizeStringAttributeForIA2(aria_invalid_value, &aria_invalid_value); 3765 SanitizeStringAttributeForIA2(aria_invalid_value, &aria_invalid_value);
3736 attributes.push_back(L"invalid:" + aria_invalid_value); 3766 attributes.push_back(L"invalid:" + aria_invalid_value);
3737 } else { 3767 } else {
3738 // Set the attribute to L"true", since we cannot be more specific. 3768 // Set the attribute to L"true", since we cannot be more specific.
3739 attributes.push_back(L"invalid:true"); 3769 attributes.push_back(L"invalid:true");
3740 } 3770 }
3741 break; 3771 break;
3742 } 3772 }
3743 default:
3744 NOTREACHED();
3745 } 3773 }
3746 3774
3747 base::string16 language(GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE)); 3775 base::string16 language(GetInheritedString16Attribute(ui::AX_ATTR_LANGUAGE));
3748 // Default value should be L"en-US". 3776 // Default value should be L"en-US".
3749 if (language.empty()) { 3777 if (language.empty()) {
3750 attributes.push_back(L"language:en-US"); 3778 attributes.push_back(L"language:en-US");
3751 } else { 3779 } else {
3752 SanitizeStringAttributeForIA2(language, &language); 3780 SanitizeStringAttributeForIA2(language, &language);
3753 attributes.push_back(L"language:" + language); 3781 attributes.push_back(L"language:" + language);
3754 } 3782 }
(...skipping 24 matching lines...) Expand all
3779 case ui::AX_TEXT_DIRECTION_RTL: 3807 case ui::AX_TEXT_DIRECTION_RTL:
3780 attributes.push_back(L"writing-mode:rl"); 3808 attributes.push_back(L"writing-mode:rl");
3781 break; 3809 break;
3782 case ui::AX_TEXT_DIRECTION_TTB: 3810 case ui::AX_TEXT_DIRECTION_TTB:
3783 attributes.push_back(L"writing-mode:tb"); 3811 attributes.push_back(L"writing-mode:tb");
3784 break; 3812 break;
3785 case ui::AX_TEXT_DIRECTION_BTT: 3813 case ui::AX_TEXT_DIRECTION_BTT:
3786 // Not listed in the IA2 Spec. 3814 // Not listed in the IA2 Spec.
3787 attributes.push_back(L"writing-mode:bt"); 3815 attributes.push_back(L"writing-mode:bt");
3788 break; 3816 break;
3789 default:
3790 NOTREACHED();
3791 } 3817 }
3792 3818
3793 return attributes; 3819 return attributes;
3794 } 3820 }
3795 3821
3796 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() { 3822 BrowserAccessibilityWin* BrowserAccessibilityWin::NewReference() {
3797 AddRef(); 3823 AddRef();
3798 return this; 3824 return this;
3799 } 3825 }
3800 3826
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 case IA2_TEXT_BOUNDARY_WORD: 4250 case IA2_TEXT_BOUNDARY_WORD:
4225 return ui::WORD_BOUNDARY; 4251 return ui::WORD_BOUNDARY;
4226 case IA2_TEXT_BOUNDARY_LINE: 4252 case IA2_TEXT_BOUNDARY_LINE:
4227 return ui::LINE_BOUNDARY; 4253 return ui::LINE_BOUNDARY;
4228 case IA2_TEXT_BOUNDARY_SENTENCE: 4254 case IA2_TEXT_BOUNDARY_SENTENCE:
4229 return ui::SENTENCE_BOUNDARY; 4255 return ui::SENTENCE_BOUNDARY;
4230 case IA2_TEXT_BOUNDARY_PARAGRAPH: 4256 case IA2_TEXT_BOUNDARY_PARAGRAPH:
4231 return ui::PARAGRAPH_BOUNDARY; 4257 return ui::PARAGRAPH_BOUNDARY;
4232 case IA2_TEXT_BOUNDARY_ALL: 4258 case IA2_TEXT_BOUNDARY_ALL:
4233 return ui::ALL_BOUNDARY; 4259 return ui::ALL_BOUNDARY;
4234 default:
4235 NOTREACHED();
4236 } 4260 }
4261 NOTREACHED();
4237 return ui::CHAR_BOUNDARY; 4262 return ui::CHAR_BOUNDARY;
4238 } 4263 }
4239 4264
4240 LONG BrowserAccessibilityWin::FindBoundary( 4265 LONG BrowserAccessibilityWin::FindBoundary(
4241 const base::string16& text, 4266 const base::string16& text,
4242 IA2TextBoundaryType ia2_boundary, 4267 IA2TextBoundaryType ia2_boundary,
4243 LONG start_offset, 4268 LONG start_offset,
4244 ui::TextBoundaryDirection direction) { 4269 ui::TextBoundaryDirection direction) {
4245 HandleSpecialTextOffset(text, &start_offset); 4270 HandleSpecialTextOffset(text, &start_offset);
4246 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD) 4271 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD)
(...skipping 24 matching lines...) Expand all
4271 --iterator; 4296 --iterator;
4272 return static_cast<LONG>(iterator->first); 4297 return static_cast<LONG>(iterator->first);
4273 } 4298 }
4274 case ui::FORWARDS_DIRECTION: { 4299 case ui::FORWARDS_DIRECTION: {
4275 const auto iterator = 4300 const auto iterator =
4276 offset_to_text_attributes().upper_bound(start_offset); 4301 offset_to_text_attributes().upper_bound(start_offset);
4277 if (iterator == offset_to_text_attributes().end()) 4302 if (iterator == offset_to_text_attributes().end())
4278 return text_length; 4303 return text_length;
4279 return static_cast<LONG>(iterator->first); 4304 return static_cast<LONG>(iterator->first);
4280 } 4305 }
4281 default:
4282 NOTREACHED();
4283 } 4306 }
4284 4307
4285 return start_offset; 4308 return start_offset;
4286 } 4309 }
4287 4310
4288 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32_t id) const { 4311 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32_t id) const {
4289 if (!instance_active()) 4312 if (!instance_active())
4290 return nullptr; 4313 return nullptr;
4291 return ToBrowserAccessibilityWin(manager()->GetFromID(id)); 4314 return ToBrowserAccessibilityWin(manager()->GetFromID(id));
4292 } 4315 }
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 return static_cast<BrowserAccessibilityWin*>(obj); 4986 return static_cast<BrowserAccessibilityWin*>(obj);
4964 } 4987 }
4965 4988
4966 const BrowserAccessibilityWin* 4989 const BrowserAccessibilityWin*
4967 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { 4990 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) {
4968 DCHECK(!obj || obj->IsNative()); 4991 DCHECK(!obj || obj->IsNative());
4969 return static_cast<const BrowserAccessibilityWin*>(obj); 4992 return static_cast<const BrowserAccessibilityWin*>(obj);
4970 } 4993 }
4971 4994
4972 } // namespace content 4995 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/accessibility/dump_accessibility_tree_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698