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
3 // found in the LICENSE file.
5 #include "content/browser/accessibility/browser_accessibility_win.h"
7 #include <UIAutomationClient.h>
8 #include <UIAutomationCoreApi.h>
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/win/enum_variant.h"
17 #include "base/win/scoped_comptr.h"
18 #include "base/win/windows_version.h"
19 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
20 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
21 #include "content/common/accessibility_messages.h"
22 #include "content/public/common/content_client.h"
23 #include "ui/accessibility/ax_text_utils.h"
24 #include "ui/base/win/accessibility_ids_win.h"
25 #include "ui/base/win/accessibility_misc_utils.h"
26 #include "ui/base/win/atl_module.h"
30 // These nonstandard GUIDs are taken directly from the Mozilla sources
31 // (accessible/src/msaa/nsAccessNodeWrap.cpp); some documentation is here:
32 // http://developer.mozilla.org/en/Accessibility/AT-APIs/ImplementationFeatures/MSAA
33 const GUID GUID_ISimpleDOM
= {0x0c539790,
36 {0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8}};
37 const GUID GUID_IAccessibleContentDocument
= {
41 {0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e}};
43 const base::char16
BrowserAccessibilityWin::kEmbeddedCharacter
= L
'\xfffc';
46 LONG
BrowserAccessibilityWin::next_unique_id_win_
=
47 base::win::kFirstBrowserAccessibilityManagerAccessibilityId
;
50 // BrowserAccessibilityRelation
52 // A simple implementation of IAccessibleRelation, used to represent
53 // a relationship between two accessible nodes in the tree.
56 class BrowserAccessibilityRelation
57 : public CComObjectRootEx
<CComMultiThreadModel
>,
58 public IAccessibleRelation
{
59 BEGIN_COM_MAP(BrowserAccessibilityRelation
)
60 COM_INTERFACE_ENTRY(IAccessibleRelation
)
63 CONTENT_EXPORT
BrowserAccessibilityRelation() {}
64 CONTENT_EXPORT
virtual ~BrowserAccessibilityRelation() {}
66 CONTENT_EXPORT
void Initialize(BrowserAccessibilityWin
* owner
,
67 const base::string16
& type
);
68 CONTENT_EXPORT
void AddTarget(int target_id
);
70 // IAccessibleRelation methods.
71 CONTENT_EXPORT STDMETHODIMP
get_relationType(BSTR
* relation_type
) override
;
72 CONTENT_EXPORT STDMETHODIMP
get_nTargets(long* n_targets
) override
;
73 CONTENT_EXPORT STDMETHODIMP
74 get_target(long target_index
, IUnknown
** target
) override
;
75 CONTENT_EXPORT STDMETHODIMP
76 get_targets(long max_targets
, IUnknown
** targets
, long* n_targets
) override
;
78 // IAccessibleRelation methods not implemented.
79 CONTENT_EXPORT STDMETHODIMP
80 get_localizedRelationType(BSTR
* relation_type
) override
{
86 base::win::ScopedComPtr
<BrowserAccessibilityWin
> owner_
;
87 std::vector
<int> target_ids_
;
90 void BrowserAccessibilityRelation::Initialize(BrowserAccessibilityWin
* owner
,
91 const base::string16
& type
) {
96 void BrowserAccessibilityRelation::AddTarget(int target_id
) {
97 target_ids_
.push_back(target_id
);
100 STDMETHODIMP
BrowserAccessibilityRelation::get_relationType(
101 BSTR
* relation_type
) {
105 if (!owner_
->instance_active())
108 *relation_type
= SysAllocString(type_
.c_str());
109 DCHECK(*relation_type
);
113 STDMETHODIMP
BrowserAccessibilityRelation::get_nTargets(long* n_targets
) {
117 if (!owner_
->instance_active())
120 *n_targets
= static_cast<long>(target_ids_
.size());
122 BrowserAccessibilityManager
* manager
= owner_
->manager();
123 for (long i
= *n_targets
- 1; i
>= 0; --i
) {
124 BrowserAccessibility
* result
= manager
->GetFromID(target_ids_
[i
]);
125 if (!result
|| !result
->instance_active()) {
133 STDMETHODIMP
BrowserAccessibilityRelation::get_target(long target_index
,
138 if (!owner_
->instance_active())
141 if (target_index
< 0 ||
142 target_index
>= static_cast<long>(target_ids_
.size())) {
146 BrowserAccessibilityManager
* manager
= owner_
->manager();
147 BrowserAccessibility
* result
=
148 manager
->GetFromID(target_ids_
[target_index
]);
149 if (!result
|| !result
->instance_active())
152 *target
= static_cast<IAccessible
*>(
153 result
->ToBrowserAccessibilityWin()->NewReference());
157 STDMETHODIMP
BrowserAccessibilityRelation::get_targets(long max_targets
,
160 if (!targets
|| !n_targets
)
163 if (!owner_
->instance_active())
166 long count
= static_cast<long>(target_ids_
.size());
167 if (count
> max_targets
)
174 for (long i
= 0; i
< count
; ++i
) {
175 HRESULT result
= get_target(i
, &targets
[i
]);
184 // BrowserAccessibilityWin::WinAttributes
187 BrowserAccessibilityWin::WinAttributes::WinAttributes()
194 BrowserAccessibilityWin::WinAttributes::~WinAttributes() {
198 // BrowserAccessibilityWin
202 BrowserAccessibility
* BrowserAccessibility::Create() {
203 ui::win::CreateATLModuleIfNeeded();
204 CComObject
<BrowserAccessibilityWin
>* instance
;
205 HRESULT hr
= CComObject
<BrowserAccessibilityWin
>::CreateInstance(&instance
);
206 DCHECK(SUCCEEDED(hr
));
207 return instance
->NewReference();
210 BrowserAccessibilityWin
* BrowserAccessibility::ToBrowserAccessibilityWin() {
211 return static_cast<BrowserAccessibilityWin
*>(this);
214 BrowserAccessibilityWin::BrowserAccessibilityWin()
215 : win_attributes_(new WinAttributes()),
216 previous_scroll_x_(0),
217 previous_scroll_y_(0) {
218 // Start unique IDs at -1 and decrement each time, because get_accChild
219 // uses positive IDs to enumerate children, so we use negative IDs to
220 // clearly distinguish between indices and unique IDs.
221 unique_id_win_
= next_unique_id_win_
;
222 if (next_unique_id_win_
==
223 base::win::kLastBrowserAccessibilityManagerAccessibilityId
) {
224 next_unique_id_win_
=
225 base::win::kFirstBrowserAccessibilityManagerAccessibilityId
;
227 next_unique_id_win_
--;
230 BrowserAccessibilityWin::~BrowserAccessibilityWin() {
231 for (size_t i
= 0; i
< relations_
.size(); ++i
)
232 relations_
[i
]->Release();
236 // IAccessible methods.
239 // * Always test for instance_active() first and return E_FAIL if it's false.
240 // * Always check for invalid arguments first, even if they're unused.
241 // * Return S_FALSE if the only output is a string argument and it's empty.
244 HRESULT
BrowserAccessibilityWin::accDoDefaultAction(VARIANT var_id
) {
245 if (!instance_active())
248 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
252 manager()->DoDefaultAction(*target
);
256 STDMETHODIMP
BrowserAccessibilityWin::accHitTest(LONG x_left
,
259 if (!instance_active())
265 gfx::Point
point(x_left
, y_top
);
266 if (!GetGlobalBoundsRect().Contains(point
)) {
267 // Return S_FALSE and VT_EMPTY when the outside the object's boundaries.
268 child
->vt
= VT_EMPTY
;
272 BrowserAccessibility
* result
= BrowserAccessibilityForPoint(point
);
273 if (result
== this) {
274 // Point is within this object.
276 child
->lVal
= CHILDID_SELF
;
278 child
->vt
= VT_DISPATCH
;
279 child
->pdispVal
= result
->ToBrowserAccessibilityWin()->NewReference();
284 STDMETHODIMP
BrowserAccessibilityWin::accLocation(LONG
* x_left
,
289 if (!instance_active())
292 if (!x_left
|| !y_top
|| !width
|| !height
)
295 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
299 gfx::Rect bounds
= target
->GetGlobalBoundsRect();
300 *x_left
= bounds
.x();
302 *width
= bounds
.width();
303 *height
= bounds
.height();
308 STDMETHODIMP
BrowserAccessibilityWin::accNavigate(LONG nav_dir
,
311 BrowserAccessibilityWin
* target
= GetTargetFromChildID(start
);
315 if ((nav_dir
== NAVDIR_LASTCHILD
|| nav_dir
== NAVDIR_FIRSTCHILD
) &&
316 start
.lVal
!= CHILDID_SELF
) {
317 // MSAA states that navigating to first/last child can only be from self.
321 uint32 child_count
= target
->PlatformChildCount();
323 BrowserAccessibility
* result
= NULL
;
329 // These directions are not implemented, matching Mozilla and IE.
331 case NAVDIR_FIRSTCHILD
:
333 result
= target
->PlatformGetChild(0);
335 case NAVDIR_LASTCHILD
:
337 result
= target
->PlatformGetChild(child_count
- 1);
340 result
= target
->GetNextSibling();
342 case NAVDIR_PREVIOUS
:
343 result
= target
->GetPreviousSibling();
352 end
->vt
= VT_DISPATCH
;
353 end
->pdispVal
= result
->ToBrowserAccessibilityWin()->NewReference();
357 STDMETHODIMP
BrowserAccessibilityWin::get_accChild(VARIANT var_child
,
358 IDispatch
** disp_child
) {
359 if (!instance_active())
367 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_child
);
371 (*disp_child
) = target
->NewReference();
375 STDMETHODIMP
BrowserAccessibilityWin::get_accChildCount(LONG
* child_count
) {
376 if (!instance_active())
382 *child_count
= PlatformChildCount();
387 STDMETHODIMP
BrowserAccessibilityWin::get_accDefaultAction(VARIANT var_id
,
389 if (!instance_active())
395 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
399 return target
->GetStringAttributeAsBstr(
400 ui::AX_ATTR_ACTION
, def_action
);
403 STDMETHODIMP
BrowserAccessibilityWin::get_accDescription(VARIANT var_id
,
405 if (!instance_active())
411 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
415 base::string16 description_str
= target
->description();
416 if (description_str
.empty())
419 *desc
= SysAllocString(description_str
.c_str());
425 STDMETHODIMP
BrowserAccessibilityWin::get_accFocus(VARIANT
* focus_child
) {
426 if (!instance_active())
432 BrowserAccessibilityWin
* focus
= static_cast<BrowserAccessibilityWin
*>(
433 manager()->GetFocus(this));
435 focus_child
->vt
= VT_I4
;
436 focus_child
->lVal
= CHILDID_SELF
;
437 } else if (focus
== NULL
) {
438 focus_child
->vt
= VT_EMPTY
;
440 focus_child
->vt
= VT_DISPATCH
;
441 focus_child
->pdispVal
= focus
->NewReference();
447 STDMETHODIMP
BrowserAccessibilityWin::get_accHelp(VARIANT var_id
, BSTR
* help
) {
448 if (!instance_active())
454 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
458 base::string16 help_str
= target
->help();
459 if (help_str
.empty())
462 *help
= SysAllocString(help_str
.c_str());
468 STDMETHODIMP
BrowserAccessibilityWin::get_accKeyboardShortcut(VARIANT var_id
,
470 if (!instance_active())
476 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
480 return target
->GetStringAttributeAsBstr(
481 ui::AX_ATTR_SHORTCUT
, acc_key
);
484 STDMETHODIMP
BrowserAccessibilityWin::get_accName(VARIANT var_id
, BSTR
* name
) {
485 if (!instance_active())
491 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
495 base::string16 name_str
= target
->name();
497 // If the name is empty, see if it's labeled by another element.
498 if (name_str
.empty()) {
500 if (target
->GetIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT
,
502 BrowserAccessibilityWin
* title_elem
=
503 manager()->GetFromID(title_elem_id
)->ToBrowserAccessibilityWin();
505 name_str
= title_elem
->GetNameRecursive();
509 if (name_str
.empty())
512 *name
= SysAllocString(name_str
.c_str());
518 STDMETHODIMP
BrowserAccessibilityWin::get_accParent(IDispatch
** disp_parent
) {
519 if (!instance_active())
525 IAccessible
* parent_obj
= GetParent()->ToBrowserAccessibilityWin();
526 if (parent_obj
== NULL
) {
527 // This happens if we're the root of the tree;
528 // return the IAccessible for the window.
530 manager()->ToBrowserAccessibilityManagerWin()->GetParentIAccessible();
531 // |parent| can only be NULL if the manager was created before the parent
532 // IAccessible was known and it wasn't subsequently set before a client
533 // requested it. This has been fixed. |parent| may also be NULL during
534 // destruction. Possible cases where this could occur include tabs being
535 // dragged to a new window, etc.
537 DVLOG(1) << "In Function: "
539 << ". Parent IAccessible interface is NULL. Returning failure";
543 parent_obj
->AddRef();
544 *disp_parent
= parent_obj
;
548 STDMETHODIMP
BrowserAccessibilityWin::get_accRole(VARIANT var_id
,
550 if (!instance_active())
556 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
560 if (!target
->role_name().empty()) {
562 role
->bstrVal
= SysAllocString(target
->role_name().c_str());
565 role
->lVal
= target
->ia_role();
570 STDMETHODIMP
BrowserAccessibilityWin::get_accState(VARIANT var_id
,
572 if (!instance_active())
578 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
583 state
->lVal
= target
->ia_state();
584 if (manager()->GetFocus(NULL
) == this)
585 state
->lVal
|= STATE_SYSTEM_FOCUSED
;
590 STDMETHODIMP
BrowserAccessibilityWin::get_accValue(VARIANT var_id
,
592 if (!instance_active())
598 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
602 if (target
->ia_role() == ROLE_SYSTEM_PROGRESSBAR
||
603 target
->ia_role() == ROLE_SYSTEM_SCROLLBAR
||
604 target
->ia_role() == ROLE_SYSTEM_SLIDER
) {
605 base::string16 value_text
= target
->GetValueText();
606 *value
= SysAllocString(value_text
.c_str());
611 // Expose color well value.
612 if (target
->ia2_role() == IA2_ROLE_COLOR_CHOOSER
) {
613 int color
= target
->GetIntAttribute(ui::AX_ATTR_COLOR_VALUE
);
614 int red
= (color
>> 16) & 0xFF;
615 int green
= (color
>> 8) & 0xFF;
616 int blue
= color
& 0xFF;
617 base::string16 value_text
;
618 value_text
= base::IntToString16((red
* 100) / 255) + L
"% red " +
619 base::IntToString16((green
* 100) / 255) + L
"% green " +
620 base::IntToString16((blue
* 100) / 255) + L
"% blue";
621 *value
= SysAllocString(value_text
.c_str());
626 *value
= SysAllocString(target
->value().c_str());
631 STDMETHODIMP
BrowserAccessibilityWin::get_accHelpTopic(BSTR
* help_file
,
637 STDMETHODIMP
BrowserAccessibilityWin::get_accSelection(VARIANT
* selected
) {
638 if (!instance_active())
641 if (GetRole() != ui::AX_ROLE_LIST_BOX
)
644 unsigned long selected_count
= 0;
645 for (size_t i
= 0; i
< InternalChildCount(); ++i
) {
646 if (InternalGetChild(i
)->HasState(ui::AX_STATE_SELECTED
))
650 if (selected_count
== 0) {
651 selected
->vt
= VT_EMPTY
;
655 if (selected_count
== 1) {
656 for (size_t i
= 0; i
< InternalChildCount(); ++i
) {
657 if (InternalGetChild(i
)->HasState(ui::AX_STATE_SELECTED
)) {
658 selected
->vt
= VT_DISPATCH
;
660 InternalGetChild(i
)->ToBrowserAccessibilityWin()->NewReference();
666 // Multiple items are selected.
667 base::win::EnumVariant
* enum_variant
=
668 new base::win::EnumVariant(selected_count
);
669 enum_variant
->AddRef();
670 unsigned long index
= 0;
671 for (size_t i
= 0; i
< InternalChildCount(); ++i
) {
672 if (InternalGetChild(i
)->HasState(ui::AX_STATE_SELECTED
)) {
673 enum_variant
->ItemAt(index
)->vt
= VT_DISPATCH
;
674 enum_variant
->ItemAt(index
)->pdispVal
=
675 InternalGetChild(i
)->ToBrowserAccessibilityWin()->NewReference();
679 selected
->vt
= VT_UNKNOWN
;
680 selected
->punkVal
= static_cast<IUnknown
*>(
681 static_cast<base::win::IUnknownImpl
*>(enum_variant
));
685 STDMETHODIMP
BrowserAccessibilityWin::accSelect(
686 LONG flags_sel
, VARIANT var_id
) {
687 if (!instance_active())
690 if (flags_sel
& SELFLAG_TAKEFOCUS
) {
691 manager()->SetFocus(this, true);
699 BrowserAccessibilityWin::put_accName(VARIANT var_id
, BSTR put_name
) {
703 BrowserAccessibilityWin::put_accValue(VARIANT var_id
, BSTR put_val
) {
708 // IAccessible2 methods.
711 STDMETHODIMP
BrowserAccessibilityWin::role(LONG
* role
) {
712 if (!instance_active())
723 STDMETHODIMP
BrowserAccessibilityWin::get_attributes(BSTR
* attributes
) {
724 if (!instance_active())
730 // The iaccessible2 attributes are a set of key-value pairs
731 // separated by semicolons, with a colon between the key and the value.
733 const std::vector
<base::string16
>& attributes_list
= ia2_attributes();
734 for (unsigned int i
= 0; i
< attributes_list
.size(); ++i
) {
735 str
+= attributes_list
[i
] + L
';';
741 *attributes
= SysAllocString(str
.c_str());
746 STDMETHODIMP
BrowserAccessibilityWin::get_states(AccessibleStates
* states
) {
747 if (!instance_active())
753 *states
= ia2_state();
758 STDMETHODIMP
BrowserAccessibilityWin::get_uniqueID(LONG
* unique_id
) {
759 if (!instance_active())
765 *unique_id
= unique_id_win_
;
769 STDMETHODIMP
BrowserAccessibilityWin::get_windowHandle(HWND
* window_handle
) {
770 if (!instance_active())
777 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND();
784 STDMETHODIMP
BrowserAccessibilityWin::get_indexInParent(LONG
* index_in_parent
) {
785 if (!instance_active())
788 if (!index_in_parent
)
791 *index_in_parent
= this->GetIndexInParent();
795 STDMETHODIMP
BrowserAccessibilityWin::get_nRelations(LONG
* n_relations
) {
796 if (!instance_active())
802 *n_relations
= relations_
.size();
806 STDMETHODIMP
BrowserAccessibilityWin::get_relation(
808 IAccessibleRelation
** relation
) {
809 if (!instance_active())
812 if (relation_index
< 0 ||
813 relation_index
>= static_cast<long>(relations_
.size())) {
820 relations_
[relation_index
]->AddRef();
821 *relation
= relations_
[relation_index
];
825 STDMETHODIMP
BrowserAccessibilityWin::get_relations(
827 IAccessibleRelation
** relations
,
829 if (!instance_active())
832 if (!relations
|| !n_relations
)
835 long count
= static_cast<long>(relations_
.size());
836 *n_relations
= count
;
840 for (long i
= 0; i
< count
; ++i
) {
841 relations_
[i
]->AddRef();
842 relations
[i
] = relations_
[i
];
848 STDMETHODIMP
BrowserAccessibilityWin::scrollTo(enum IA2ScrollType scroll_type
) {
849 if (!instance_active())
852 gfx::Rect r
= GetLocation();
853 switch(scroll_type
) {
854 case IA2_SCROLL_TYPE_TOP_LEFT
:
855 manager()->ScrollToMakeVisible(*this, gfx::Rect(r
.x(), r
.y(), 0, 0));
857 case IA2_SCROLL_TYPE_BOTTOM_RIGHT
:
858 manager()->ScrollToMakeVisible(
859 *this, gfx::Rect(r
.right(), r
.bottom(), 0, 0));
861 case IA2_SCROLL_TYPE_TOP_EDGE
:
862 manager()->ScrollToMakeVisible(
863 *this, gfx::Rect(r
.x(), r
.y(), r
.width(), 0));
865 case IA2_SCROLL_TYPE_BOTTOM_EDGE
:
866 manager()->ScrollToMakeVisible(
867 *this, gfx::Rect(r
.x(), r
.bottom(), r
.width(), 0));
869 case IA2_SCROLL_TYPE_LEFT_EDGE
:
870 manager()->ScrollToMakeVisible(
871 *this, gfx::Rect(r
.x(), r
.y(), 0, r
.height()));
873 case IA2_SCROLL_TYPE_RIGHT_EDGE
:
874 manager()->ScrollToMakeVisible(
875 *this, gfx::Rect(r
.right(), r
.y(), 0, r
.height()));
877 case IA2_SCROLL_TYPE_ANYWHERE
:
879 manager()->ScrollToMakeVisible(*this, r
);
883 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
888 STDMETHODIMP
BrowserAccessibilityWin::scrollToPoint(
889 enum IA2CoordinateType coordinate_type
,
892 if (!instance_active())
895 gfx::Point
scroll_to(x
, y
);
897 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
898 scroll_to
-= manager()->GetViewBounds().OffsetFromOrigin();
899 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
901 scroll_to
+= GetParent()->GetLocation().OffsetFromOrigin();
906 manager()->ScrollToPoint(*this, scroll_to
);
907 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
912 STDMETHODIMP
BrowserAccessibilityWin::get_groupPosition(
914 LONG
* similar_items_in_group
,
915 LONG
* position_in_group
) {
916 if (!instance_active())
919 if (!group_level
|| !similar_items_in_group
|| !position_in_group
)
923 *similar_items_in_group
= GetIntAttribute(ui::AX_ATTR_SET_SIZE
);
924 *position_in_group
= GetIntAttribute(ui::AX_ATTR_POS_IN_SET
);
929 // IAccessibleEx methods not implemented.
932 STDMETHODIMP
BrowserAccessibilityWin::get_extendedRole(BSTR
* extended_role
) {
936 BrowserAccessibilityWin::get_localizedExtendedRole(
937 BSTR
* localized_extended_role
) {
941 BrowserAccessibilityWin::get_nExtendedStates(LONG
* n_extended_states
) {
945 BrowserAccessibilityWin::get_extendedStates(LONG max_extended_states
,
946 BSTR
** extended_states
,
947 LONG
* n_extended_states
) {
951 BrowserAccessibilityWin::get_localizedExtendedStates(
952 LONG max_localized_extended_states
,
953 BSTR
** localized_extended_states
,
954 LONG
* n_localized_extended_states
) {
957 STDMETHODIMP
BrowserAccessibilityWin::get_locale(IA2Locale
* locale
) {
962 // IAccessibleApplication methods.
965 STDMETHODIMP
BrowserAccessibilityWin::get_appName(BSTR
* app_name
) {
966 // No need to check |instance_active()| because this interface is
967 // global, and doesn't depend on any local state.
972 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
973 // the part before the "/".
974 std::vector
<std::string
> product_components
= base::SplitString(
975 GetContentClient()->GetProduct(), "/",
976 base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
977 DCHECK_EQ(2U, product_components
.size());
978 if (product_components
.size() != 2)
980 *app_name
= SysAllocString(base::UTF8ToUTF16(product_components
[0]).c_str());
982 return *app_name
? S_OK
: E_FAIL
;
985 STDMETHODIMP
BrowserAccessibilityWin::get_appVersion(BSTR
* app_version
) {
986 // No need to check |instance_active()| because this interface is
987 // global, and doesn't depend on any local state.
992 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
993 // the part after the "/".
994 std::vector
<std::string
> product_components
= base::SplitString(
995 GetContentClient()->GetProduct(), "/",
996 base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
997 DCHECK_EQ(2U, product_components
.size());
998 if (product_components
.size() != 2)
1001 SysAllocString(base::UTF8ToUTF16(product_components
[1]).c_str());
1002 DCHECK(*app_version
);
1003 return *app_version
? S_OK
: E_FAIL
;
1006 STDMETHODIMP
BrowserAccessibilityWin::get_toolkitName(BSTR
* toolkit_name
) {
1007 // No need to check |instance_active()| because this interface is
1008 // global, and doesn't depend on any local state.
1011 return E_INVALIDARG
;
1013 // This is hard-coded; all products based on the Chromium engine
1014 // will have the same toolkit name, so that assistive technology can
1015 // detect any Chrome-based product.
1016 *toolkit_name
= SysAllocString(L
"Chrome");
1017 DCHECK(*toolkit_name
);
1018 return *toolkit_name
? S_OK
: E_FAIL
;
1021 STDMETHODIMP
BrowserAccessibilityWin::get_toolkitVersion(
1022 BSTR
* toolkit_version
) {
1023 // No need to check |instance_active()| because this interface is
1024 // global, and doesn't depend on any local state.
1026 if (!toolkit_version
)
1027 return E_INVALIDARG
;
1029 std::string user_agent
= GetContentClient()->GetUserAgent();
1030 *toolkit_version
= SysAllocString(base::UTF8ToUTF16(user_agent
).c_str());
1031 DCHECK(*toolkit_version
);
1032 return *toolkit_version
? S_OK
: E_FAIL
;
1036 // IAccessibleImage methods.
1039 STDMETHODIMP
BrowserAccessibilityWin::get_description(BSTR
* desc
) {
1040 if (!instance_active())
1044 return E_INVALIDARG
;
1046 if (description().empty())
1049 *desc
= SysAllocString(description().c_str());
1055 STDMETHODIMP
BrowserAccessibilityWin::get_imagePosition(
1056 enum IA2CoordinateType coordinate_type
,
1059 if (!instance_active())
1063 return E_INVALIDARG
;
1065 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
1067 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND();
1070 POINT top_left
= {0, 0};
1071 ::ClientToScreen(parent_hwnd
, &top_left
);
1072 *x
= GetLocation().x() + top_left
.x
;
1073 *y
= GetLocation().y() + top_left
.y
;
1074 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
1075 *x
= GetLocation().x();
1076 *y
= GetLocation().y();
1078 *x
-= GetParent()->GetLocation().x();
1079 *y
-= GetParent()->GetLocation().y();
1082 return E_INVALIDARG
;
1088 STDMETHODIMP
BrowserAccessibilityWin::get_imageSize(LONG
* height
, LONG
* width
) {
1089 if (!instance_active())
1092 if (!height
|| !width
)
1093 return E_INVALIDARG
;
1095 *height
= GetLocation().height();
1096 *width
= GetLocation().width();
1101 // IAccessibleTable methods.
1104 STDMETHODIMP
BrowserAccessibilityWin::get_accessibleAt(
1107 IUnknown
** accessible
) {
1108 if (!instance_active())
1112 return E_INVALIDARG
;
1116 if (!GetIntAttribute(
1117 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1119 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1125 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1126 return E_INVALIDARG
;
1128 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1129 ui::AX_ATTR_CELL_IDS
);
1130 DCHECK_EQ(columns
* rows
, static_cast<int>(cell_ids
.size()));
1132 int cell_id
= cell_ids
[row
* columns
+ column
];
1133 BrowserAccessibilityWin
* cell
= GetFromID(cell_id
);
1135 *accessible
= static_cast<IAccessible
*>(cell
->NewReference());
1140 return E_INVALIDARG
;
1143 STDMETHODIMP
BrowserAccessibilityWin::get_caption(IUnknown
** accessible
) {
1144 if (!instance_active())
1148 return E_INVALIDARG
;
1150 // TODO(dmazzoni): implement
1154 STDMETHODIMP
BrowserAccessibilityWin::get_childIndex(long row
,
1157 if (!instance_active())
1161 return E_INVALIDARG
;
1165 if (!GetIntAttribute(
1166 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1168 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1174 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1175 return E_INVALIDARG
;
1177 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1178 ui::AX_ATTR_CELL_IDS
);
1179 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1180 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1181 DCHECK_EQ(columns
* rows
, static_cast<int>(cell_ids
.size()));
1182 int cell_id
= cell_ids
[row
* columns
+ column
];
1183 for (size_t i
= 0; i
< unique_cell_ids
.size(); ++i
) {
1184 if (unique_cell_ids
[i
] == cell_id
) {
1185 *cell_index
= (long)i
;
1193 STDMETHODIMP
BrowserAccessibilityWin::get_columnDescription(long column
,
1194 BSTR
* description
) {
1195 if (!instance_active())
1199 return E_INVALIDARG
;
1203 if (!GetIntAttribute(
1204 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1205 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1211 if (column
< 0 || column
>= columns
)
1212 return E_INVALIDARG
;
1214 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1215 ui::AX_ATTR_CELL_IDS
);
1216 for (int i
= 0; i
< rows
; ++i
) {
1217 int cell_id
= cell_ids
[i
* columns
+ column
];
1218 BrowserAccessibilityWin
* cell
= static_cast<BrowserAccessibilityWin
*>(
1219 manager()->GetFromID(cell_id
));
1220 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
) {
1221 base::string16 cell_name
= cell
->GetString16Attribute(
1223 if (cell_name
.size() > 0) {
1224 *description
= SysAllocString(cell_name
.c_str());
1228 if (cell
->description().size() > 0) {
1229 *description
= SysAllocString(cell
->description().c_str());
1238 STDMETHODIMP
BrowserAccessibilityWin::get_columnExtentAt(
1241 long* n_columns_spanned
) {
1242 if (!instance_active())
1245 if (!n_columns_spanned
)
1246 return E_INVALIDARG
;
1250 if (!GetIntAttribute(
1251 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1252 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1258 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1259 return E_INVALIDARG
;
1261 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1262 ui::AX_ATTR_CELL_IDS
);
1263 int cell_id
= cell_ids
[row
* columns
+ column
];
1264 BrowserAccessibilityWin
* cell
= static_cast<BrowserAccessibilityWin
*>(
1265 manager()->GetFromID(cell_id
));
1268 cell
->GetIntAttribute(
1269 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1271 *n_columns_spanned
= colspan
;
1278 STDMETHODIMP
BrowserAccessibilityWin::get_columnHeader(
1279 IAccessibleTable
** accessible_table
,
1280 long* starting_row_index
) {
1281 // TODO(dmazzoni): implement
1285 STDMETHODIMP
BrowserAccessibilityWin::get_columnIndex(long cell_index
,
1286 long* column_index
) {
1287 if (!instance_active())
1291 return E_INVALIDARG
;
1293 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1294 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1295 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1297 return E_INVALIDARG
;
1298 if (cell_index
>= cell_id_count
)
1301 int cell_id
= unique_cell_ids
[cell_index
];
1302 BrowserAccessibilityWin
* cell
=
1303 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1306 cell
->GetIntAttribute(
1307 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &col_index
)) {
1308 *column_index
= col_index
;
1315 STDMETHODIMP
BrowserAccessibilityWin::get_nColumns(long* column_count
) {
1316 if (!instance_active())
1320 return E_INVALIDARG
;
1323 if (GetIntAttribute(
1324 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
)) {
1325 *column_count
= columns
;
1332 STDMETHODIMP
BrowserAccessibilityWin::get_nRows(long* row_count
) {
1333 if (!instance_active())
1337 return E_INVALIDARG
;
1340 if (GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1348 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedChildren(long* cell_count
) {
1349 if (!instance_active())
1353 return E_INVALIDARG
;
1355 // TODO(dmazzoni): add support for selected cells/rows/columns in tables.
1360 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedColumns(long* column_count
) {
1361 if (!instance_active())
1365 return E_INVALIDARG
;
1371 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedRows(long* row_count
) {
1372 if (!instance_active())
1376 return E_INVALIDARG
;
1382 STDMETHODIMP
BrowserAccessibilityWin::get_rowDescription(long row
,
1383 BSTR
* description
) {
1384 if (!instance_active())
1388 return E_INVALIDARG
;
1392 if (!GetIntAttribute(
1393 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1394 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1400 if (row
< 0 || row
>= rows
)
1401 return E_INVALIDARG
;
1403 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1404 ui::AX_ATTR_CELL_IDS
);
1405 for (int i
= 0; i
< columns
; ++i
) {
1406 int cell_id
= cell_ids
[row
* columns
+ i
];
1407 BrowserAccessibilityWin
* cell
=
1408 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1409 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
) {
1410 base::string16 cell_name
= cell
->GetString16Attribute(
1412 if (cell_name
.size() > 0) {
1413 *description
= SysAllocString(cell_name
.c_str());
1417 if (cell
->description().size() > 0) {
1418 *description
= SysAllocString(cell
->description().c_str());
1427 STDMETHODIMP
BrowserAccessibilityWin::get_rowExtentAt(long row
,
1429 long* n_rows_spanned
) {
1430 if (!instance_active())
1433 if (!n_rows_spanned
)
1434 return E_INVALIDARG
;
1438 if (!GetIntAttribute(
1439 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1440 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1446 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1447 return E_INVALIDARG
;
1449 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1450 ui::AX_ATTR_CELL_IDS
);
1451 int cell_id
= cell_ids
[row
* columns
+ column
];
1452 BrowserAccessibilityWin
* cell
=
1453 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1456 cell
->GetIntAttribute(
1457 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1459 *n_rows_spanned
= rowspan
;
1466 STDMETHODIMP
BrowserAccessibilityWin::get_rowHeader(
1467 IAccessibleTable
** accessible_table
,
1468 long* starting_column_index
) {
1469 // TODO(dmazzoni): implement
1473 STDMETHODIMP
BrowserAccessibilityWin::get_rowIndex(long cell_index
,
1475 if (!instance_active())
1479 return E_INVALIDARG
;
1481 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1482 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1483 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1485 return E_INVALIDARG
;
1486 if (cell_index
>= cell_id_count
)
1489 int cell_id
= unique_cell_ids
[cell_index
];
1490 BrowserAccessibilityWin
* cell
=
1491 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1494 cell
->GetIntAttribute(
1495 ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &cell_row_index
)) {
1496 *row_index
= cell_row_index
;
1503 STDMETHODIMP
BrowserAccessibilityWin::get_selectedChildren(long max_children
,
1506 if (!instance_active())
1509 if (!children
|| !n_children
)
1510 return E_INVALIDARG
;
1512 // TODO(dmazzoni): Implement this.
1517 STDMETHODIMP
BrowserAccessibilityWin::get_selectedColumns(long max_columns
,
1520 if (!instance_active())
1523 if (!columns
|| !n_columns
)
1524 return E_INVALIDARG
;
1526 // TODO(dmazzoni): Implement this.
1531 STDMETHODIMP
BrowserAccessibilityWin::get_selectedRows(long max_rows
,
1534 if (!instance_active())
1537 if (!rows
|| !n_rows
)
1538 return E_INVALIDARG
;
1540 // TODO(dmazzoni): Implement this.
1545 STDMETHODIMP
BrowserAccessibilityWin::get_summary(IUnknown
** accessible
) {
1546 if (!instance_active())
1550 return E_INVALIDARG
;
1552 // TODO(dmazzoni): implement
1556 STDMETHODIMP
BrowserAccessibilityWin::get_isColumnSelected(
1558 boolean
* is_selected
) {
1559 if (!instance_active())
1563 return E_INVALIDARG
;
1565 // TODO(dmazzoni): Implement this.
1566 *is_selected
= false;
1570 STDMETHODIMP
BrowserAccessibilityWin::get_isRowSelected(long row
,
1571 boolean
* is_selected
) {
1572 if (!instance_active())
1576 return E_INVALIDARG
;
1578 // TODO(dmazzoni): Implement this.
1579 *is_selected
= false;
1583 STDMETHODIMP
BrowserAccessibilityWin::get_isSelected(long row
,
1585 boolean
* is_selected
) {
1586 if (!instance_active())
1590 return E_INVALIDARG
;
1592 // TODO(dmazzoni): Implement this.
1593 *is_selected
= false;
1597 STDMETHODIMP
BrowserAccessibilityWin::get_rowColumnExtentsAtIndex(
1602 long* column_extents
,
1603 boolean
* is_selected
) {
1604 if (!instance_active())
1607 if (!row
|| !column
|| !row_extents
|| !column_extents
|| !is_selected
)
1608 return E_INVALIDARG
;
1610 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1611 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1612 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1614 return E_INVALIDARG
;
1615 if (index
>= cell_id_count
)
1618 int cell_id
= unique_cell_ids
[index
];
1619 BrowserAccessibilityWin
* cell
=
1620 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1624 cell
->GetIntAttribute(
1625 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1626 cell
->GetIntAttribute(
1627 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1630 *row_extents
= rowspan
;
1631 *column_extents
= colspan
;
1638 STDMETHODIMP
BrowserAccessibilityWin::selectRow(long row
) {
1642 STDMETHODIMP
BrowserAccessibilityWin::selectColumn(long column
) {
1646 STDMETHODIMP
BrowserAccessibilityWin::unselectRow(long row
) {
1650 STDMETHODIMP
BrowserAccessibilityWin::unselectColumn(long column
) {
1655 BrowserAccessibilityWin::get_modelChange(IA2TableModelChange
* model_change
) {
1660 // IAccessibleTable2 methods.
1663 STDMETHODIMP
BrowserAccessibilityWin::get_cellAt(long row
,
1666 return get_accessibleAt(row
, column
, cell
);
1669 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedCells(long* cell_count
) {
1670 return get_nSelectedChildren(cell_count
);
1673 STDMETHODIMP
BrowserAccessibilityWin::get_selectedCells(
1675 long* n_selected_cells
) {
1676 if (!instance_active())
1679 if (!cells
|| !n_selected_cells
)
1680 return E_INVALIDARG
;
1682 // TODO(dmazzoni): Implement this.
1683 *n_selected_cells
= 0;
1687 STDMETHODIMP
BrowserAccessibilityWin::get_selectedColumns(long** columns
,
1689 if (!instance_active())
1692 if (!columns
|| !n_columns
)
1693 return E_INVALIDARG
;
1695 // TODO(dmazzoni): Implement this.
1700 STDMETHODIMP
BrowserAccessibilityWin::get_selectedRows(long** rows
,
1702 if (!instance_active())
1705 if (!rows
|| !n_rows
)
1706 return E_INVALIDARG
;
1708 // TODO(dmazzoni): Implement this.
1715 // IAccessibleTableCell methods.
1718 STDMETHODIMP
BrowserAccessibilityWin::get_columnExtent(
1719 long* n_columns_spanned
) {
1720 if (!instance_active())
1723 if (!n_columns_spanned
)
1724 return E_INVALIDARG
;
1727 if (GetIntAttribute(
1728 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1730 *n_columns_spanned
= colspan
;
1737 STDMETHODIMP
BrowserAccessibilityWin::get_columnHeaderCells(
1738 IUnknown
*** cell_accessibles
,
1739 long* n_column_header_cells
) {
1740 if (!instance_active())
1743 if (!cell_accessibles
|| !n_column_header_cells
)
1744 return E_INVALIDARG
;
1746 *n_column_header_cells
= 0;
1749 if (!GetIntAttribute(
1750 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
)) {
1754 BrowserAccessibility
* table
= GetParent();
1755 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
1756 table
= table
->GetParent();
1764 if (!table
->GetIntAttribute(
1765 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1766 !table
->GetIntAttribute(
1767 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1770 if (columns
<= 0 || rows
<= 0 || column
< 0 || column
>= columns
)
1773 const std::vector
<int32
>& cell_ids
= table
->GetIntListAttribute(
1774 ui::AX_ATTR_CELL_IDS
);
1776 for (int i
= 0; i
< rows
; ++i
) {
1777 int cell_id
= cell_ids
[i
* columns
+ column
];
1778 BrowserAccessibilityWin
* cell
=
1779 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1780 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
)
1781 (*n_column_header_cells
)++;
1784 *cell_accessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(
1785 (*n_column_header_cells
) * sizeof(cell_accessibles
[0])));
1787 for (int i
= 0; i
< rows
; ++i
) {
1788 int cell_id
= cell_ids
[i
* columns
+ column
];
1789 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1790 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
) {
1791 (*cell_accessibles
)[index
] = static_cast<IAccessible
*>(
1792 cell
->ToBrowserAccessibilityWin()->NewReference());
1800 STDMETHODIMP
BrowserAccessibilityWin::get_columnIndex(long* column_index
) {
1801 if (!instance_active())
1805 return E_INVALIDARG
;
1808 if (GetIntAttribute(
1809 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
)) {
1810 *column_index
= column
;
1817 STDMETHODIMP
BrowserAccessibilityWin::get_rowExtent(long* n_rows_spanned
) {
1818 if (!instance_active())
1821 if (!n_rows_spanned
)
1822 return E_INVALIDARG
;
1825 if (GetIntAttribute(
1826 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1828 *n_rows_spanned
= rowspan
;
1835 STDMETHODIMP
BrowserAccessibilityWin::get_rowHeaderCells(
1836 IUnknown
*** cell_accessibles
,
1837 long* n_row_header_cells
) {
1838 if (!instance_active())
1841 if (!cell_accessibles
|| !n_row_header_cells
)
1842 return E_INVALIDARG
;
1844 *n_row_header_cells
= 0;
1847 if (!GetIntAttribute(
1848 ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
)) {
1852 BrowserAccessibility
* table
= GetParent();
1853 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
1854 table
= table
->GetParent();
1862 if (!table
->GetIntAttribute(
1863 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1864 !table
->GetIntAttribute(
1865 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1868 if (columns
<= 0 || rows
<= 0 || row
< 0 || row
>= rows
)
1871 const std::vector
<int32
>& cell_ids
= table
->GetIntListAttribute(
1872 ui::AX_ATTR_CELL_IDS
);
1874 for (int i
= 0; i
< columns
; ++i
) {
1875 int cell_id
= cell_ids
[row
* columns
+ i
];
1876 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1877 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
)
1878 (*n_row_header_cells
)++;
1881 *cell_accessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(
1882 (*n_row_header_cells
) * sizeof(cell_accessibles
[0])));
1884 for (int i
= 0; i
< columns
; ++i
) {
1885 int cell_id
= cell_ids
[row
* columns
+ i
];
1886 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1887 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
) {
1888 (*cell_accessibles
)[index
] = static_cast<IAccessible
*>(
1889 cell
->ToBrowserAccessibilityWin()->NewReference());
1897 STDMETHODIMP
BrowserAccessibilityWin::get_rowIndex(long* row_index
) {
1898 if (!instance_active())
1902 return E_INVALIDARG
;
1905 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
)) {
1912 STDMETHODIMP
BrowserAccessibilityWin::get_isSelected(boolean
* is_selected
) {
1913 if (!instance_active())
1917 return E_INVALIDARG
;
1919 *is_selected
= false;
1923 STDMETHODIMP
BrowserAccessibilityWin::get_rowColumnExtents(
1927 long* column_extents
,
1928 boolean
* is_selected
) {
1929 if (!instance_active())
1937 return E_INVALIDARG
;
1944 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
) &&
1946 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
) &&
1948 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1950 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
)) {
1952 *column_index
= column
;
1953 *row_extents
= rowspan
;
1954 *column_extents
= colspan
;
1955 *is_selected
= false;
1962 STDMETHODIMP
BrowserAccessibilityWin::get_table(IUnknown
** table
) {
1963 if (!instance_active())
1967 return E_INVALIDARG
;
1972 GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
);
1973 GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
);
1975 BrowserAccessibility
* find_table
= GetParent();
1976 while (find_table
&& find_table
->GetRole() != ui::AX_ROLE_TABLE
)
1977 find_table
= find_table
->GetParent();
1983 *table
= static_cast<IAccessibleTable
*>(
1984 find_table
->ToBrowserAccessibilityWin()->NewReference());
1990 // IAccessibleText methods.
1993 STDMETHODIMP
BrowserAccessibilityWin::get_nCharacters(LONG
* n_characters
) {
1994 if (!instance_active())
1998 return E_INVALIDARG
;
2000 *n_characters
= TextForIAccessibleText().length();
2004 STDMETHODIMP
BrowserAccessibilityWin::get_caretOffset(LONG
* offset
) {
2005 if (!instance_active())
2009 return E_INVALIDARG
;
2011 int selection_start
, selection_end
;
2012 GetSelectionOffsets(&selection_start
, &selection_end
);
2013 *offset
= selection_start
;
2014 if (selection_start
< 0)
2020 STDMETHODIMP
BrowserAccessibilityWin::get_characterExtents(
2022 enum IA2CoordinateType coordinate_type
,
2027 if (!instance_active())
2030 if (!out_x
|| !out_y
|| !out_width
|| !out_height
)
2031 return E_INVALIDARG
;
2033 const base::string16
& text_str
= TextForIAccessibleText();
2034 HandleSpecialTextOffset(text_str
, &offset
);
2036 if (offset
< 0 || offset
> static_cast<LONG
>(text_str
.size()))
2037 return E_INVALIDARG
;
2039 gfx::Rect character_bounds
;
2040 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
2041 character_bounds
= GetGlobalBoundsForRange(offset
, 1);
2042 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
2043 character_bounds
= GetLocalBoundsForRange(offset
, 1);
2044 character_bounds
-= GetLocation().OffsetFromOrigin();
2046 return E_INVALIDARG
;
2049 *out_x
= character_bounds
.x();
2050 *out_y
= character_bounds
.y();
2051 *out_width
= character_bounds
.width();
2052 *out_height
= character_bounds
.height();
2057 STDMETHODIMP
BrowserAccessibilityWin::get_nSelections(LONG
* n_selections
) {
2058 if (!instance_active())
2062 return E_INVALIDARG
;
2065 int selection_start
, selection_end
;
2066 GetSelectionOffsets(&selection_start
, &selection_end
);
2067 if (selection_start
>= 0 && selection_end
>= 0 &&
2068 selection_start
!= selection_end
)
2074 STDMETHODIMP
BrowserAccessibilityWin::get_selection(LONG selection_index
,
2077 if (!instance_active())
2080 if (!start_offset
|| !end_offset
|| selection_index
!= 0)
2081 return E_INVALIDARG
;
2083 LONG n_selections
= 0;
2084 if (FAILED(get_nSelections(&n_selections
)) || n_selections
< 1)
2085 return E_INVALIDARG
;
2089 int selection_start
, selection_end
;
2090 GetSelectionOffsets(&selection_start
, &selection_end
);
2091 if (selection_start
>= 0 && selection_end
>= 0) {
2092 *start_offset
= selection_start
;
2093 *end_offset
= selection_end
;
2099 STDMETHODIMP
BrowserAccessibilityWin::get_text(LONG start_offset
,
2102 if (!instance_active())
2106 return E_INVALIDARG
;
2108 const base::string16
& text_str
= TextForIAccessibleText();
2110 // Handle special text offsets.
2111 HandleSpecialTextOffset(text_str
, &start_offset
);
2112 HandleSpecialTextOffset(text_str
, &end_offset
);
2114 // The spec allows the arguments to be reversed.
2115 if (start_offset
> end_offset
) {
2116 LONG tmp
= start_offset
;
2117 start_offset
= end_offset
;
2121 // The spec does not allow the start or end offsets to be out or range;
2122 // we must return an error if so.
2123 LONG len
= text_str
.length();
2124 if (start_offset
< 0)
2125 return E_INVALIDARG
;
2126 if (end_offset
> len
)
2127 return E_INVALIDARG
;
2129 base::string16 substr
= text_str
.substr(start_offset
,
2130 end_offset
- start_offset
);
2134 *text
= SysAllocString(substr
.c_str());
2139 STDMETHODIMP
BrowserAccessibilityWin::get_textAtOffset(
2141 enum IA2TextBoundaryType boundary_type
,
2145 if (!instance_active())
2148 if (!start_offset
|| !end_offset
|| !text
)
2149 return E_INVALIDARG
;
2151 const base::string16
& text_str
= TextForIAccessibleText();
2152 HandleSpecialTextOffset(text_str
, &offset
);
2154 return E_INVALIDARG
;
2156 LONG text_len
= text_str
.length();
2157 if (offset
> text_len
)
2158 return E_INVALIDARG
;
2160 // The IAccessible2 spec says we don't have to implement the "sentence"
2161 // boundary type, we can just let the screenreader handle it.
2162 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2169 // According to the IA2 Spec, only line boundaries should succeed when
2170 // the offset is one past the end of the text.
2171 if (offset
== text_len
&& boundary_type
!= IA2_TEXT_BOUNDARY_LINE
) {
2178 *start_offset
= FindBoundary(
2179 text_str
, boundary_type
, offset
, ui::BACKWARDS_DIRECTION
);
2180 *end_offset
= FindBoundary(
2181 text_str
, boundary_type
, offset
, ui::FORWARDS_DIRECTION
);
2182 return get_text(*start_offset
, *end_offset
, text
);
2185 STDMETHODIMP
BrowserAccessibilityWin::get_textBeforeOffset(
2187 enum IA2TextBoundaryType boundary_type
,
2191 if (!instance_active())
2194 if (!start_offset
|| !end_offset
|| !text
)
2195 return E_INVALIDARG
;
2197 // The IAccessible2 spec says we don't have to implement the "sentence"
2198 // boundary type, we can just let the screenreader handle it.
2199 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2206 const base::string16
& text_str
= TextForIAccessibleText();
2208 *start_offset
= FindBoundary(
2209 text_str
, boundary_type
, offset
, ui::BACKWARDS_DIRECTION
);
2210 *end_offset
= offset
;
2211 return get_text(*start_offset
, *end_offset
, text
);
2214 STDMETHODIMP
BrowserAccessibilityWin::get_textAfterOffset(
2216 enum IA2TextBoundaryType boundary_type
,
2220 if (!instance_active())
2223 if (!start_offset
|| !end_offset
|| !text
)
2224 return E_INVALIDARG
;
2226 // The IAccessible2 spec says we don't have to implement the "sentence"
2227 // boundary type, we can just let the screenreader handle it.
2228 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2235 const base::string16
& text_str
= TextForIAccessibleText();
2237 *start_offset
= offset
;
2238 *end_offset
= FindBoundary(
2239 text_str
, boundary_type
, offset
, ui::FORWARDS_DIRECTION
);
2240 return get_text(*start_offset
, *end_offset
, text
);
2243 STDMETHODIMP
BrowserAccessibilityWin::get_newText(IA2TextSegment
* new_text
) {
2244 if (!instance_active())
2248 return E_INVALIDARG
;
2250 if (!old_win_attributes_
)
2253 int start
, old_len
, new_len
;
2254 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
2258 base::string16 substr
= hypertext().substr(start
, new_len
);
2259 new_text
->text
= SysAllocString(substr
.c_str());
2260 new_text
->start
= static_cast<long>(start
);
2261 new_text
->end
= static_cast<long>(start
+ new_len
);
2265 STDMETHODIMP
BrowserAccessibilityWin::get_oldText(IA2TextSegment
* old_text
) {
2266 if (!instance_active())
2270 return E_INVALIDARG
;
2272 if (!old_win_attributes_
)
2275 int start
, old_len
, new_len
;
2276 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
2280 base::string16 old_hypertext
= old_win_attributes_
->hypertext
;
2281 base::string16 substr
= old_hypertext
.substr(start
, old_len
);
2282 old_text
->text
= SysAllocString(substr
.c_str());
2283 old_text
->start
= static_cast<long>(start
);
2284 old_text
->end
= static_cast<long>(start
+ old_len
);
2288 STDMETHODIMP
BrowserAccessibilityWin::get_offsetAtPoint(
2291 enum IA2CoordinateType coord_type
,
2293 if (!instance_active())
2297 return E_INVALIDARG
;
2299 // TODO(dmazzoni): implement this. We're returning S_OK for now so that
2300 // screen readers still return partially accurate results rather than
2301 // completely failing.
2306 STDMETHODIMP
BrowserAccessibilityWin::scrollSubstringTo(
2309 enum IA2ScrollType scroll_type
) {
2310 // TODO(dmazzoni): adjust this for the start and end index, too.
2311 return scrollTo(scroll_type
);
2314 STDMETHODIMP
BrowserAccessibilityWin::scrollSubstringToPoint(
2317 enum IA2CoordinateType coordinate_type
,
2319 // TODO(dmazzoni): adjust this for the start and end index, too.
2320 return scrollToPoint(coordinate_type
, x
, y
);
2323 STDMETHODIMP
BrowserAccessibilityWin::addSelection(LONG start_offset
,
2325 if (!instance_active())
2328 const base::string16
& text_str
= TextForIAccessibleText();
2329 HandleSpecialTextOffset(text_str
, &start_offset
);
2330 HandleSpecialTextOffset(text_str
, &end_offset
);
2332 manager()->SetTextSelection(*this, start_offset
, end_offset
);
2336 STDMETHODIMP
BrowserAccessibilityWin::removeSelection(LONG selection_index
) {
2337 if (!instance_active())
2340 if (selection_index
!= 0)
2341 return E_INVALIDARG
;
2343 manager()->SetTextSelection(*this, 0, 0);
2347 STDMETHODIMP
BrowserAccessibilityWin::setCaretOffset(LONG offset
) {
2348 if (!instance_active())
2351 const base::string16
& text_str
= TextForIAccessibleText();
2352 HandleSpecialTextOffset(text_str
, &offset
);
2353 manager()->SetTextSelection(*this, offset
, offset
);
2357 STDMETHODIMP
BrowserAccessibilityWin::setSelection(LONG selection_index
,
2360 if (!instance_active())
2363 if (selection_index
!= 0)
2364 return E_INVALIDARG
;
2366 const base::string16
& text_str
= TextForIAccessibleText();
2367 HandleSpecialTextOffset(text_str
, &start_offset
);
2368 HandleSpecialTextOffset(text_str
, &end_offset
);
2370 manager()->SetTextSelection(*this, start_offset
, end_offset
);
2375 // IAccessibleText methods not implemented.
2378 STDMETHODIMP
BrowserAccessibilityWin::get_attributes(LONG offset
,
2381 BSTR
* text_attributes
) {
2386 // IAccessibleHypertext methods.
2389 STDMETHODIMP
BrowserAccessibilityWin::get_nHyperlinks(long* hyperlink_count
) {
2390 if (!instance_active())
2393 if (!hyperlink_count
)
2394 return E_INVALIDARG
;
2396 *hyperlink_count
= hyperlink_offset_to_index().size();
2400 STDMETHODIMP
BrowserAccessibilityWin::get_hyperlink(
2402 IAccessibleHyperlink
** hyperlink
) {
2403 if (!instance_active())
2408 index
>= static_cast<long>(hyperlinks().size())) {
2409 return E_INVALIDARG
;
2412 int32 id
= hyperlinks()[index
];
2413 BrowserAccessibilityWin
* child
=
2414 manager()->GetFromID(id
)->ToBrowserAccessibilityWin();
2416 *hyperlink
= static_cast<IAccessibleHyperlink
*>(child
->NewReference());
2423 STDMETHODIMP
BrowserAccessibilityWin::get_hyperlinkIndex(
2425 long* hyperlink_index
) {
2426 if (!instance_active())
2429 if (!hyperlink_index
)
2430 return E_INVALIDARG
;
2432 *hyperlink_index
= -1;
2434 if (char_index
< 0 ||
2435 char_index
>= static_cast<long>(hypertext().size())) {
2436 return E_INVALIDARG
;
2439 std::map
<int32
, int32
>::iterator it
=
2440 hyperlink_offset_to_index().find(char_index
);
2441 if (it
== hyperlink_offset_to_index().end())
2444 *hyperlink_index
= it
->second
;
2449 // IAccessibleHyperlink not implemented.
2452 STDMETHODIMP
BrowserAccessibilityWin::get_anchor(long index
, VARIANT
* anchor
) {
2456 BrowserAccessibilityWin::get_anchorTarget(long index
, VARIANT
* anchor_target
) {
2459 STDMETHODIMP
BrowserAccessibilityWin::get_startIndex(long* index
) {
2462 STDMETHODIMP
BrowserAccessibilityWin::get_endIndex(long* index
) {
2465 STDMETHODIMP
BrowserAccessibilityWin::get_valid(boolean
* valid
) {
2470 // IAccessibleAction not implemented.
2473 STDMETHODIMP
BrowserAccessibilityWin::nActions(long* n_actions
) {
2476 STDMETHODIMP
BrowserAccessibilityWin::doAction(long action_index
) {
2480 BrowserAccessibilityWin::get_description(long action_index
, BSTR
* description
) {
2483 STDMETHODIMP
BrowserAccessibilityWin::get_keyBinding(long action_index
,
2484 long n_max_bindings
,
2485 BSTR
** key_bindings
,
2489 STDMETHODIMP
BrowserAccessibilityWin::get_name(long action_index
, BSTR
* name
) {
2493 BrowserAccessibilityWin::get_localizedName(long action_index
,
2494 BSTR
* localized_name
) {
2499 // IAccessibleValue methods.
2502 STDMETHODIMP
BrowserAccessibilityWin::get_currentValue(VARIANT
* value
) {
2503 if (!instance_active())
2507 return E_INVALIDARG
;
2510 if (GetFloatAttribute(
2511 ui::AX_ATTR_VALUE_FOR_RANGE
, &float_val
)) {
2513 value
->dblVal
= float_val
;
2517 value
->vt
= VT_EMPTY
;
2521 STDMETHODIMP
BrowserAccessibilityWin::get_minimumValue(VARIANT
* value
) {
2522 if (!instance_active())
2526 return E_INVALIDARG
;
2529 if (GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
,
2532 value
->dblVal
= float_val
;
2536 value
->vt
= VT_EMPTY
;
2540 STDMETHODIMP
BrowserAccessibilityWin::get_maximumValue(VARIANT
* value
) {
2541 if (!instance_active())
2545 return E_INVALIDARG
;
2548 if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
,
2551 value
->dblVal
= float_val
;
2555 value
->vt
= VT_EMPTY
;
2559 STDMETHODIMP
BrowserAccessibilityWin::setCurrentValue(VARIANT new_value
) {
2560 // TODO(dmazzoni): Implement this.
2565 // ISimpleDOMDocument methods.
2568 STDMETHODIMP
BrowserAccessibilityWin::get_URL(BSTR
* url
) {
2569 if (!instance_active())
2573 return E_INVALIDARG
;
2575 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_URL
, url
);
2578 STDMETHODIMP
BrowserAccessibilityWin::get_title(BSTR
* title
) {
2579 if (!instance_active())
2583 return E_INVALIDARG
;
2585 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_TITLE
, title
);
2588 STDMETHODIMP
BrowserAccessibilityWin::get_mimeType(BSTR
* mime_type
) {
2589 if (!instance_active())
2593 return E_INVALIDARG
;
2595 return GetStringAttributeAsBstr(
2596 ui::AX_ATTR_DOC_MIMETYPE
, mime_type
);
2599 STDMETHODIMP
BrowserAccessibilityWin::get_docType(BSTR
* doc_type
) {
2600 if (!instance_active())
2604 return E_INVALIDARG
;
2606 return GetStringAttributeAsBstr(
2607 ui::AX_ATTR_DOC_DOCTYPE
, doc_type
);
2611 BrowserAccessibilityWin::get_nameSpaceURIForID(short name_space_id
,
2612 BSTR
* name_space_uri
) {
2616 BrowserAccessibilityWin::put_alternateViewMediaTypes(
2617 BSTR
* comma_separated_media_types
) {
2622 // ISimpleDOMNode methods.
2625 STDMETHODIMP
BrowserAccessibilityWin::get_nodeInfo(
2627 short* name_space_id
,
2629 unsigned int* num_children
,
2630 unsigned int* unique_id
,
2631 unsigned short* node_type
) {
2632 if (!instance_active())
2635 if (!node_name
|| !name_space_id
|| !node_value
|| !num_children
||
2636 !unique_id
|| !node_type
) {
2637 return E_INVALIDARG
;
2641 if (GetString16Attribute(ui::AX_ATTR_HTML_TAG
, &tag
))
2642 *node_name
= SysAllocString(tag
.c_str());
2647 *node_value
= SysAllocString(value().c_str());
2648 *num_children
= PlatformChildCount();
2649 *unique_id
= unique_id_win_
;
2651 if (ia_role() == ROLE_SYSTEM_DOCUMENT
) {
2652 *node_type
= NODETYPE_DOCUMENT
;
2653 } else if (ia_role() == ROLE_SYSTEM_TEXT
&&
2654 ((ia2_state() & IA2_STATE_EDITABLE
) == 0)) {
2655 *node_type
= NODETYPE_TEXT
;
2657 *node_type
= NODETYPE_ELEMENT
;
2663 STDMETHODIMP
BrowserAccessibilityWin::get_attributes(
2664 unsigned short max_attribs
,
2666 short* name_space_id
,
2667 BSTR
* attrib_values
,
2668 unsigned short* num_attribs
) {
2669 if (!instance_active())
2672 if (!attrib_names
|| !name_space_id
|| !attrib_values
|| !num_attribs
)
2673 return E_INVALIDARG
;
2675 *num_attribs
= max_attribs
;
2676 if (*num_attribs
> GetHtmlAttributes().size())
2677 *num_attribs
= GetHtmlAttributes().size();
2679 for (unsigned short i
= 0; i
< *num_attribs
; ++i
) {
2680 attrib_names
[i
] = SysAllocString(
2681 base::UTF8ToUTF16(GetHtmlAttributes()[i
].first
).c_str());
2682 name_space_id
[i
] = 0;
2683 attrib_values
[i
] = SysAllocString(
2684 base::UTF8ToUTF16(GetHtmlAttributes()[i
].second
).c_str());
2689 STDMETHODIMP
BrowserAccessibilityWin::get_attributesForNames(
2690 unsigned short num_attribs
,
2692 short* name_space_id
,
2693 BSTR
* attrib_values
) {
2694 if (!instance_active())
2697 if (!attrib_names
|| !name_space_id
|| !attrib_values
)
2698 return E_INVALIDARG
;
2700 for (unsigned short i
= 0; i
< num_attribs
; ++i
) {
2701 name_space_id
[i
] = 0;
2703 std::string name
= base::UTF16ToUTF8((LPCWSTR
)attrib_names
[i
]);
2704 for (unsigned int j
= 0; j
< GetHtmlAttributes().size(); ++j
) {
2705 if (GetHtmlAttributes()[j
].first
== name
) {
2706 attrib_values
[i
] = SysAllocString(
2707 base::UTF8ToUTF16(GetHtmlAttributes()[j
].second
).c_str());
2713 attrib_values
[i
] = NULL
;
2719 STDMETHODIMP
BrowserAccessibilityWin::get_computedStyle(
2720 unsigned short max_style_properties
,
2721 boolean use_alternate_view
,
2722 BSTR
* style_properties
,
2724 unsigned short *num_style_properties
) {
2725 if (!instance_active())
2728 if (!style_properties
|| !style_values
)
2729 return E_INVALIDARG
;
2731 // We only cache a single style property for now: DISPLAY
2733 base::string16 display
;
2734 if (max_style_properties
== 0 ||
2735 !GetString16Attribute(ui::AX_ATTR_DISPLAY
, &display
)) {
2736 *num_style_properties
= 0;
2740 *num_style_properties
= 1;
2741 style_properties
[0] = SysAllocString(L
"display");
2742 style_values
[0] = SysAllocString(display
.c_str());
2747 STDMETHODIMP
BrowserAccessibilityWin::get_computedStyleForProperties(
2748 unsigned short num_style_properties
,
2749 boolean use_alternate_view
,
2750 BSTR
* style_properties
,
2751 BSTR
* style_values
) {
2752 if (!instance_active())
2755 if (!style_properties
|| !style_values
)
2756 return E_INVALIDARG
;
2758 // We only cache a single style property for now: DISPLAY
2760 for (unsigned short i
= 0; i
< num_style_properties
; ++i
) {
2761 base::string16 name
= base::ToLowerASCII(
2762 reinterpret_cast<const base::char16
*>(style_properties
[i
]));
2763 if (name
== L
"display") {
2764 base::string16 display
= GetString16Attribute(
2765 ui::AX_ATTR_DISPLAY
);
2766 style_values
[i
] = SysAllocString(display
.c_str());
2768 style_values
[i
] = NULL
;
2775 STDMETHODIMP
BrowserAccessibilityWin::scrollTo(boolean placeTopLeft
) {
2776 return scrollTo(placeTopLeft
?
2777 IA2_SCROLL_TYPE_TOP_LEFT
: IA2_SCROLL_TYPE_ANYWHERE
);
2780 STDMETHODIMP
BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode
** node
) {
2781 if (!instance_active())
2785 return E_INVALIDARG
;
2787 *node
= GetParent()->ToBrowserAccessibilityWin()->NewReference();
2791 STDMETHODIMP
BrowserAccessibilityWin::get_firstChild(ISimpleDOMNode
** node
) {
2792 if (!instance_active())
2796 return E_INVALIDARG
;
2798 if (PlatformChildCount() == 0) {
2803 *node
= PlatformGetChild(0)->ToBrowserAccessibilityWin()->NewReference();
2807 STDMETHODIMP
BrowserAccessibilityWin::get_lastChild(ISimpleDOMNode
** node
) {
2808 if (!instance_active())
2812 return E_INVALIDARG
;
2814 if (PlatformChildCount() == 0) {
2819 *node
= PlatformGetChild(PlatformChildCount() - 1)
2820 ->ToBrowserAccessibilityWin()->NewReference();
2824 STDMETHODIMP
BrowserAccessibilityWin::get_previousSibling(
2825 ISimpleDOMNode
** node
) {
2826 if (!instance_active())
2830 return E_INVALIDARG
;
2832 if (!GetParent() || GetIndexInParent() <= 0) {
2837 *node
= GetParent()->InternalGetChild(GetIndexInParent() - 1)->
2838 ToBrowserAccessibilityWin()->NewReference();
2842 STDMETHODIMP
BrowserAccessibilityWin::get_nextSibling(ISimpleDOMNode
** node
) {
2843 if (!instance_active())
2847 return E_INVALIDARG
;
2850 GetIndexInParent() < 0 ||
2851 GetIndexInParent() >= static_cast<int>(
2852 GetParent()->InternalChildCount()) - 1) {
2857 *node
= GetParent()->InternalGetChild(GetIndexInParent() + 1)->
2858 ToBrowserAccessibilityWin()->NewReference();
2862 STDMETHODIMP
BrowserAccessibilityWin::get_childAt(
2863 unsigned int child_index
,
2864 ISimpleDOMNode
** node
) {
2865 if (!instance_active())
2869 return E_INVALIDARG
;
2871 if (child_index
>= PlatformChildCount())
2872 return E_INVALIDARG
;
2874 BrowserAccessibility
* child
= PlatformGetChild(child_index
);
2880 *node
= child
->ToBrowserAccessibilityWin()->NewReference();
2884 STDMETHODIMP
BrowserAccessibilityWin::get_innerHTML(BSTR
* innerHTML
) {
2889 BrowserAccessibilityWin::get_localInterface(void** local_interface
) {
2893 STDMETHODIMP
BrowserAccessibilityWin::get_language(BSTR
* language
) {
2898 // ISimpleDOMText methods.
2901 STDMETHODIMP
BrowserAccessibilityWin::get_domText(BSTR
* dom_text
) {
2902 if (!instance_active())
2906 return E_INVALIDARG
;
2908 return GetStringAttributeAsBstr(
2909 ui::AX_ATTR_NAME
, dom_text
);
2912 STDMETHODIMP
BrowserAccessibilityWin::get_clippedSubstringBounds(
2913 unsigned int start_index
,
2914 unsigned int end_index
,
2919 // TODO(dmazzoni): fully support this API by intersecting the
2920 // rect with the container's rect.
2921 return get_unclippedSubstringBounds(
2922 start_index
, end_index
, out_x
, out_y
, out_width
, out_height
);
2925 STDMETHODIMP
BrowserAccessibilityWin::get_unclippedSubstringBounds(
2926 unsigned int start_index
,
2927 unsigned int end_index
,
2932 if (!instance_active())
2935 if (!out_x
|| !out_y
|| !out_width
|| !out_height
)
2936 return E_INVALIDARG
;
2938 const base::string16
& text_str
= TextForIAccessibleText();
2939 if (start_index
> text_str
.size() ||
2940 end_index
> text_str
.size() ||
2941 start_index
> end_index
) {
2942 return E_INVALIDARG
;
2945 gfx::Rect bounds
= GetGlobalBoundsForRange(
2946 start_index
, end_index
- start_index
);
2947 *out_x
= bounds
.x();
2948 *out_y
= bounds
.y();
2949 *out_width
= bounds
.width();
2950 *out_height
= bounds
.height();
2954 STDMETHODIMP
BrowserAccessibilityWin::scrollToSubstring(
2955 unsigned int start_index
,
2956 unsigned int end_index
) {
2957 if (!instance_active())
2960 const base::string16
& text_str
= TextForIAccessibleText();
2961 if (start_index
> text_str
.size() ||
2962 end_index
> text_str
.size() ||
2963 start_index
> end_index
) {
2964 return E_INVALIDARG
;
2967 manager()->ScrollToMakeVisible(*this, GetLocalBoundsForRange(
2968 start_index
, end_index
- start_index
));
2969 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
2974 STDMETHODIMP
BrowserAccessibilityWin::get_fontFamily(BSTR
* font_family
) {
2979 // IServiceProvider methods.
2982 STDMETHODIMP
BrowserAccessibilityWin::QueryService(REFGUID guidService
,
2985 if (!instance_active())
2988 // The system uses IAccessible APIs for many purposes, but only
2989 // assistive technology like screen readers uses IAccessible2.
2990 // Enable full accessibility support when IAccessible2 APIs are queried.
2991 if (riid
== IID_IAccessible2
)
2992 BrowserAccessibilityStateImpl::GetInstance()->EnableAccessibility();
2994 if (guidService
== GUID_IAccessibleContentDocument
) {
2995 // Special Mozilla extension: return the accessible for the root document.
2996 // Screen readers use this to distinguish between a document loaded event
2997 // on the root document vs on an iframe.
2998 return manager()->GetRoot()->ToBrowserAccessibilityWin()->QueryInterface(
2999 IID_IAccessible2
, object
);
3002 if (guidService
== IID_IAccessible
||
3003 guidService
== IID_IAccessible2
||
3004 guidService
== IID_IAccessibleAction
||
3005 guidService
== IID_IAccessibleApplication
||
3006 guidService
== IID_IAccessibleHyperlink
||
3007 guidService
== IID_IAccessibleHypertext
||
3008 guidService
== IID_IAccessibleImage
||
3009 guidService
== IID_IAccessibleTable
||
3010 guidService
== IID_IAccessibleTable2
||
3011 guidService
== IID_IAccessibleTableCell
||
3012 guidService
== IID_IAccessibleText
||
3013 guidService
== IID_IAccessibleValue
||
3014 guidService
== IID_ISimpleDOMDocument
||
3015 guidService
== IID_ISimpleDOMNode
||
3016 guidService
== IID_ISimpleDOMText
||
3017 guidService
== GUID_ISimpleDOM
) {
3018 return QueryInterface(riid
, object
);
3021 // We only support the IAccessibleEx interface on Windows 8 and above. This
3022 // is needed for the on-screen Keyboard to show up in metro mode, when the
3023 // user taps an editable portion on the page.
3024 // All methods in the IAccessibleEx interface are unimplemented.
3025 if (riid
== IID_IAccessibleEx
&&
3026 base::win::GetVersion() >= base::win::VERSION_WIN8
) {
3027 return QueryInterface(riid
, object
);
3035 BrowserAccessibilityWin::GetObjectForChild(long child_id
, IAccessibleEx
** ret
) {
3040 BrowserAccessibilityWin::GetIAccessiblePair(IAccessible
** acc
, long* child_id
) {
3044 STDMETHODIMP
BrowserAccessibilityWin::GetRuntimeId(SAFEARRAY
** runtime_id
) {
3049 BrowserAccessibilityWin::ConvertReturnedElement(
3050 IRawElementProviderSimple
* element
,
3051 IAccessibleEx
** acc
) {
3055 STDMETHODIMP
BrowserAccessibilityWin::GetPatternProvider(PATTERNID id
,
3056 IUnknown
** provider
) {
3057 DVLOG(1) << "In Function: "
3059 << " for pattern id: "
3061 if (id
== UIA_ValuePatternId
|| id
== UIA_TextPatternId
) {
3062 if (IsEditableText()) {
3063 DVLOG(1) << "Returning UIA text provider";
3064 base::win::UIATextProvider::CreateTextProvider(
3065 GetValueText(), true, provider
);
3072 STDMETHODIMP
BrowserAccessibilityWin::GetPropertyValue(PROPERTYID id
,
3074 DVLOG(1) << "In Function: "
3076 << " for property id: "
3078 V_VT(ret
) = VT_EMPTY
;
3079 if (id
== UIA_ControlTypePropertyId
) {
3080 if (IsEditableText()) {
3082 ret
->lVal
= UIA_EditControlTypeId
;
3083 DVLOG(1) << "Returning Edit control type";
3085 DVLOG(1) << "Returning empty control type";
3091 STDMETHODIMP
BrowserAccessibilityWin::get_ProviderOptions(
3092 enum ProviderOptions
* ret
) {
3096 STDMETHODIMP
BrowserAccessibilityWin::get_HostRawElementProvider(
3097 IRawElementProviderSimple
** provider
) {
3102 // CComObjectRootEx methods.
3106 HRESULT WINAPI
BrowserAccessibilityWin::InternalQueryInterface(
3108 const _ATL_INTMAP_ENTRY
* entries
,
3111 BrowserAccessibilityWin
* accessibility
=
3112 reinterpret_cast<BrowserAccessibilityWin
*>(this_ptr
);
3113 int32 ia_role
= accessibility
->ia_role();
3114 if (iid
== IID_IAccessibleImage
) {
3115 if (ia_role
!= ROLE_SYSTEM_GRAPHIC
) {
3117 return E_NOINTERFACE
;
3119 } else if (iid
== IID_IAccessibleTable
|| iid
== IID_IAccessibleTable2
) {
3120 if (ia_role
!= ROLE_SYSTEM_TABLE
) {
3122 return E_NOINTERFACE
;
3124 } else if (iid
== IID_IAccessibleTableCell
) {
3125 if (!accessibility
->IsCellOrTableHeaderRole()) {
3127 return E_NOINTERFACE
;
3129 } else if (iid
== IID_IAccessibleValue
) {
3130 if (ia_role
!= ROLE_SYSTEM_PROGRESSBAR
&&
3131 ia_role
!= ROLE_SYSTEM_SCROLLBAR
&&
3132 ia_role
!= ROLE_SYSTEM_SLIDER
) {
3134 return E_NOINTERFACE
;
3136 } else if (iid
== IID_ISimpleDOMDocument
) {
3137 if (ia_role
!= ROLE_SYSTEM_DOCUMENT
) {
3139 return E_NOINTERFACE
;
3143 return CComObjectRootBase::InternalQueryInterface(
3144 this_ptr
, entries
, iid
, object
);
3151 void BrowserAccessibilityWin::UpdateStep1ComputeWinAttributes() {
3152 // Swap win_attributes_ to old_win_attributes_, allowing us to see
3153 // exactly what changed and fire appropriate events. Note that
3154 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents.
3155 old_win_attributes_
.swap(win_attributes_
);
3156 win_attributes_
.reset(new WinAttributes());
3160 win_attributes_
->ia2_attributes
.clear();
3162 // Expose autocomplete attribute for combobox and textbox.
3163 StringAttributeToIA2(ui::AX_ATTR_AUTO_COMPLETE
, "autocomplete");
3165 // Expose the "display" and "tag" attributes.
3166 StringAttributeToIA2(ui::AX_ATTR_DISPLAY
, "display");
3167 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG
, "tag");
3168 StringAttributeToIA2(ui::AX_ATTR_ROLE
, "xml-roles");
3170 // Expose "level" attribute for headings, trees, etc.
3171 IntAttributeToIA2(ui::AX_ATTR_HIERARCHICAL_LEVEL
, "level");
3173 // Expose the set size and position in set.
3174 IntAttributeToIA2(ui::AX_ATTR_SET_SIZE
, "setsize");
3175 IntAttributeToIA2(ui::AX_ATTR_POS_IN_SET
, "posinset");
3177 if (ia_role() == ROLE_SYSTEM_CHECKBUTTON
||
3178 ia_role() == ROLE_SYSTEM_RADIOBUTTON
||
3179 ia2_role() == IA2_ROLE_CHECK_MENU_ITEM
||
3180 ia2_role() == IA2_ROLE_RADIO_MENU_ITEM
||
3181 ia2_role() == IA2_ROLE_TOGGLE_BUTTON
) {
3182 win_attributes_
->ia2_attributes
.push_back(L
"checkable:true");
3185 // Expose live region attributes.
3186 StringAttributeToIA2(ui::AX_ATTR_LIVE_STATUS
, "live");
3187 StringAttributeToIA2(ui::AX_ATTR_LIVE_RELEVANT
, "relevant");
3188 BoolAttributeToIA2(ui::AX_ATTR_LIVE_ATOMIC
, "atomic");
3189 BoolAttributeToIA2(ui::AX_ATTR_LIVE_BUSY
, "busy");
3191 // Expose container live region attributes.
3192 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_STATUS
,
3194 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT
,
3195 "container-relevant");
3196 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC
,
3197 "container-atomic");
3198 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY
,
3201 // Expose table cell index.
3202 if (IsCellOrTableHeaderRole()) {
3203 BrowserAccessibility
* table
= GetParent();
3204 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
3205 table
= table
->GetParent();
3207 const std::vector
<int32
>& unique_cell_ids
= table
->GetIntListAttribute(
3208 ui::AX_ATTR_UNIQUE_CELL_IDS
);
3209 for (size_t i
= 0; i
< unique_cell_ids
.size(); ++i
) {
3210 if (unique_cell_ids
[i
] == GetId()) {
3211 win_attributes_
->ia2_attributes
.push_back(
3212 base::string16(L
"table-cell-index:") + base::IntToString16(i
));
3218 // Expose invalid state for form controls and elements with aria-invalid.
3220 if (GetIntAttribute(ui::AX_ATTR_INVALID_STATE
, &invalid_state
)) {
3221 // TODO(nektar): Handle the possibility of having multiple aria-invalid
3222 // attributes defined, e.g., "invalid:spelling,grammar".
3223 switch (invalid_state
) {
3224 case ui::AX_INVALID_STATE_FALSE
:
3225 win_attributes_
->ia2_attributes
.push_back(L
"invalid:false");
3227 case ui::AX_INVALID_STATE_TRUE
:
3228 win_attributes_
->ia2_attributes
.push_back(L
"invalid:true");
3230 case ui::AX_INVALID_STATE_SPELLING
:
3231 win_attributes_
->ia2_attributes
.push_back(L
"invalid:spelling");
3233 case ui::AX_INVALID_STATE_GRAMMAR
:
3234 win_attributes_
->ia2_attributes
.push_back(L
"invalid:grammar");
3236 case ui::AX_INVALID_STATE_OTHER
:
3238 base::string16 aria_invalid_value
;
3239 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE
,
3240 &aria_invalid_value
)) {
3241 win_attributes_
->ia2_attributes
.push_back(
3242 L
"invalid:" + aria_invalid_value
);
3244 // Set the attribute to L"true", since we cannot be more specific.
3245 win_attributes_
->ia2_attributes
.push_back(L
"invalid:true");
3254 // Expose row or column header sort direction.
3255 int32 sort_direction
;
3256 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER
||
3257 ia_role() == ROLE_SYSTEM_ROWHEADER
) &&
3258 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION
, &sort_direction
)) {
3259 switch (sort_direction
) {
3260 case ui::AX_SORT_DIRECTION_UNSORTED
:
3261 win_attributes_
->ia2_attributes
.push_back(L
"sort:none");
3263 case ui::AX_SORT_DIRECTION_ASCENDING
:
3264 win_attributes_
->ia2_attributes
.push_back(L
"sort:ascending");
3266 case ui::AX_SORT_DIRECTION_DESCENDING
:
3267 win_attributes_
->ia2_attributes
.push_back(L
"sort:descending");
3269 case ui::AX_SORT_DIRECTION_OTHER
:
3270 win_attributes_
->ia2_attributes
.push_back(L
"sort:other");
3277 // The calculation of the accessible name of an element has been
3278 // standardized in the HTML to Platform Accessibility APIs Implementation
3279 // Guide (http://www.w3.org/TR/html-aapi/). In order to return the
3280 // appropriate accessible name on Windows, we need to apply some logic
3281 // to the fields we get from WebKit.
3283 // TODO(dmazzoni): move most of this logic into WebKit.
3287 // name: the default name, e.g. inner text
3288 // title ui element: a reference to a <label> element on the same
3289 // page that labels this node.
3290 // description: accessible labels that override the default name:
3291 // aria-label or aria-labelledby or aria-describedby
3292 // help: the value of the "title" attribute
3294 // On Windows, the logic we apply lets some fields take precedence and
3295 // always returns the primary name in "name" and the secondary name,
3296 // if any, in "description".
3298 int title_elem_id
= GetIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT
);
3299 base::string16 name
= GetString16Attribute(ui::AX_ATTR_NAME
);
3300 base::string16 description
= GetString16Attribute(ui::AX_ATTR_DESCRIPTION
);
3301 base::string16 help
= GetString16Attribute(ui::AX_ATTR_HELP
);
3302 base::string16 value
= GetString16Attribute(ui::AX_ATTR_VALUE
);
3304 // WebKit annoyingly puts the title in the description if there's no other
3305 // description, which just confuses the rest of the logic. Put it back.
3306 // Now "help" is always the value of the "title" attribute, if present.
3307 base::string16 title_attr
;
3308 if (GetHtmlAttribute("title", &title_attr
) &&
3309 description
== title_attr
&&
3312 description
.clear();
3315 // Now implement the main logic: the descripion should become the name if
3316 // it's nonempty, and the help should become the description if
3317 // there's no description - or the name if there's no name or description.
3318 if (!description
.empty()) {
3320 description
.clear();
3322 if (!help
.empty() && description
.empty()) {
3326 if (!description
.empty() && name
.empty() && !title_elem_id
) {
3328 description
.clear();
3331 // If it's a text field, also consider the placeholder.
3332 base::string16 placeholder
;
3333 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
&&
3334 HasState(ui::AX_STATE_FOCUSABLE
) &&
3335 GetHtmlAttribute("placeholder", &placeholder
)) {
3336 if (name
.empty() && !title_elem_id
) {
3338 } else if (description
.empty()) {
3339 description
= placeholder
;
3343 // On Windows, the value of a document should be its url.
3344 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA
||
3345 GetRole() == ui::AX_ROLE_WEB_AREA
) {
3346 value
= GetString16Attribute(ui::AX_ATTR_DOC_URL
);
3349 // For certain roles (listbox option, static text, and list marker)
3350 // WebKit stores the main accessible text in the "value" - swap it so
3351 // that it's the "name".
3353 (GetRole() == ui::AX_ROLE_STATIC_TEXT
||
3354 GetRole() == ui::AX_ROLE_LIST_MARKER
||
3355 IsListBoxOptionOrMenuListOption())) {
3356 base::string16 tmp
= value
;
3361 // If this doesn't have a value and is linked then set its value to the url
3362 // attribute. This allows screen readers to read an empty link's destination.
3363 if (value
.empty() && (ia_state() & STATE_SYSTEM_LINKED
))
3364 value
= GetString16Attribute(ui::AX_ATTR_URL
);
3366 win_attributes_
->name
= name
;
3367 win_attributes_
->description
= description
;
3368 win_attributes_
->help
= help
;
3369 win_attributes_
->value
= value
;
3371 // Clear any old relationships between this node and other nodes.
3372 for (size_t i
= 0; i
< relations_
.size(); ++i
)
3373 relations_
[i
]->Release();
3376 // Handle title UI element.
3377 if (title_elem_id
) {
3378 // Add a labelled by relationship.
3379 CComObject
<BrowserAccessibilityRelation
>* relation
;
3380 HRESULT hr
= CComObject
<BrowserAccessibilityRelation
>::CreateInstance(
3382 DCHECK(SUCCEEDED(hr
));
3384 relation
->Initialize(this, IA2_RELATION_LABELLED_BY
);
3385 relation
->AddTarget(title_elem_id
);
3386 relations_
.push_back(relation
);
3389 // Expose slider value.
3390 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR
||
3391 ia_role() == ROLE_SYSTEM_SCROLLBAR
||
3392 ia_role() == ROLE_SYSTEM_SLIDER
) {
3393 win_attributes_
->ia2_attributes
.push_back(L
"valuetext:" + GetValueText());
3396 // Expose dropeffect attribute.
3397 base::string16 dropEffect
;
3398 if (GetHtmlAttribute("aria-dropeffect", &dropEffect
))
3399 win_attributes_
->ia2_attributes
.push_back(L
"dropeffect:" + dropEffect
);
3401 // Expose grabbed attribute.
3402 base::string16 grabbed
;
3403 if (GetHtmlAttribute("aria-grabbed", &grabbed
))
3404 win_attributes_
->ia2_attributes
.push_back(L
"grabbed:" + grabbed
);
3406 // Expose datetime attribute.
3407 base::string16 datetime
;
3408 if (GetRole() == ui::AX_ROLE_TIME
&&
3409 GetHtmlAttribute("datetime", &datetime
))
3410 win_attributes_
->ia2_attributes
.push_back(L
"datetime:" + datetime
);
3412 // Expose input-text type attribute.
3413 base::string16 type
;
3414 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
&&
3415 GetHtmlAttribute("type", &type
))
3416 win_attributes_
->ia2_attributes
.push_back(L
"text-input-type:" + type
);
3418 // If this is a web area for a presentational iframe, give it a role of
3419 // something other than DOCUMENT so that the fact that it's a separate doc
3420 // is not exposed to AT.
3421 if (IsWebAreaForPresentationalIframe()) {
3422 win_attributes_
->ia_role
= ROLE_SYSTEM_GROUPING
;
3423 win_attributes_
->ia2_role
= ROLE_SYSTEM_GROUPING
;
3427 void BrowserAccessibilityWin::UpdateStep2ComputeHypertext() {
3428 if (!PlatformChildCount()) {
3429 win_attributes_
->hypertext
+= name();
3433 // Construct the hypertext for this node, which contains the concatenation
3434 // of all of the static text and widespace of this node's children and an
3435 // embedded object character for all the other children. Build up a map from
3436 // the character index of each embedded object character to the id of the
3437 // child object it points to.
3438 for (unsigned int i
= 0; i
< PlatformChildCount(); ++i
) {
3439 BrowserAccessibilityWin
* child
=
3440 PlatformGetChild(i
)->ToBrowserAccessibilityWin();
3442 if (child
->IsTextOnlyObject()) {
3443 win_attributes_
->hypertext
+= child
->name();
3445 int32 char_offset
= hypertext().size();
3446 int32 child_id
= child
->GetId();
3447 int32 index
= hyperlinks().size();
3448 win_attributes_
->hyperlink_offset_to_index
[char_offset
] = index
;
3449 win_attributes_
->hyperlinks
.push_back(child_id
);
3450 win_attributes_
->hypertext
+= kEmbeddedCharacter
;
3455 void BrowserAccessibilityWin::UpdateStep3FireEvents(bool is_subtree_creation
) {
3456 BrowserAccessibilityManagerWin
* manager
=
3457 this->manager()->ToBrowserAccessibilityManagerWin();
3459 // Fire an event when an alert first appears.
3460 if (ia_role() == ROLE_SYSTEM_ALERT
&&
3461 old_win_attributes_
->ia_role
!= ROLE_SYSTEM_ALERT
) {
3462 manager
->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT
, this);
3465 // Fire an event when a new subtree is created.
3466 if (is_subtree_creation
)
3467 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SHOW
, this);
3469 // The rest of the events only fire on changes, not on new objects.
3470 if (old_win_attributes_
->ia_role
!= 0 ||
3471 !old_win_attributes_
->role_name
.empty()) {
3472 // Fire an event if the name, description, help, or value changes.
3473 if (name() != old_win_attributes_
->name
)
3474 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, this);
3475 if (description() != old_win_attributes_
->description
)
3476 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_DESCRIPTIONCHANGE
, this);
3477 if (help() != old_win_attributes_
->help
)
3478 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_HELPCHANGE
, this);
3479 if (value() != old_win_attributes_
->value
)
3480 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_VALUECHANGE
, this);
3481 if (ia_state() != old_win_attributes_
->ia_state
)
3482 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, this);
3484 // Normally focus events are handled elsewhere, however
3485 // focus for managed descendants is platform-specific.
3486 // Fire a focus event if the focused descendant in a multi-select
3487 // list box changes.
3488 if (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
&&
3489 (ia_state() & STATE_SYSTEM_FOCUSABLE
) &&
3490 (ia_state() & STATE_SYSTEM_SELECTABLE
) &&
3491 (ia_state() & STATE_SYSTEM_FOCUSED
) &&
3492 !(old_win_attributes_
->ia_state
& STATE_SYSTEM_FOCUSED
)) {
3493 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_FOCUS
, this);
3496 // Handle selection being added or removed.
3497 bool is_selected_now
= (ia_state() & STATE_SYSTEM_SELECTED
) != 0;
3498 bool was_selected_before
=
3499 (old_win_attributes_
->ia_state
& STATE_SYSTEM_SELECTED
) != 0;
3500 if (is_selected_now
|| was_selected_before
) {
3501 bool multiselect
= false;
3502 if (GetParent() && GetParent()->HasState(ui::AX_STATE_MULTISELECTABLE
))
3506 // In a multi-select box, fire SELECTIONADD and SELECTIONREMOVE events.
3507 if (is_selected_now
&& !was_selected_before
) {
3508 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTIONADD
, this);
3509 } else if (!is_selected_now
&& was_selected_before
) {
3510 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTIONREMOVE
, this);
3512 } else if (is_selected_now
&& !was_selected_before
) {
3513 // In a single-select box, only fire SELECTION events.
3514 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTION
, this);
3518 // Fire an event if this container object has scrolled.
3521 if (GetIntAttribute(ui::AX_ATTR_SCROLL_X
, &sx
) &&
3522 GetIntAttribute(ui::AX_ATTR_SCROLL_Y
, &sy
)) {
3523 if (sx
!= previous_scroll_x_
|| sy
!= previous_scroll_y_
)
3524 manager
->MaybeCallNotifyWinEvent(EVENT_SYSTEM_SCROLLINGEND
, this);
3525 previous_scroll_x_
= sx
;
3526 previous_scroll_y_
= sy
;
3529 // Fire hypertext-related events.
3530 int start
, old_len
, new_len
;
3531 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
3533 // In-process screen readers may call IAccessibleText::get_oldText
3534 // in reaction to this event to retrieve the text that was removed.
3535 manager
->MaybeCallNotifyWinEvent(IA2_EVENT_TEXT_REMOVED
, this);
3538 // In-process screen readers may call IAccessibleText::get_newText
3539 // in reaction to this event to retrieve the text that was inserted.
3540 manager
->MaybeCallNotifyWinEvent(IA2_EVENT_TEXT_INSERTED
, this);
3543 // Changing a static text node can affect the IAccessibleText hypertext
3544 // of the parent node, so force an update on the parent.
3545 BrowserAccessibilityWin
* parent
= GetParent()->ToBrowserAccessibilityWin();
3546 if (parent
&& IsTextOnlyObject() &&
3547 name() != old_win_attributes_
->name
) {
3548 parent
->UpdateStep1ComputeWinAttributes();
3549 parent
->UpdateStep2ComputeHypertext();
3550 parent
->UpdateStep3FireEvents(false);
3554 old_win_attributes_
.reset(nullptr);
3557 void BrowserAccessibilityWin::OnSubtreeWillBeDeleted() {
3558 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3559 EVENT_OBJECT_HIDE
, this);
3562 void BrowserAccessibilityWin::NativeAddReference() {
3566 void BrowserAccessibilityWin::NativeReleaseReference() {
3570 bool BrowserAccessibilityWin::IsNative() const {
3574 void BrowserAccessibilityWin::OnLocationChanged() {
3575 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3576 EVENT_OBJECT_LOCATIONCHANGE
, this);
3579 BrowserAccessibilityWin
* BrowserAccessibilityWin::NewReference() {
3584 BrowserAccessibilityWin
* BrowserAccessibilityWin::GetTargetFromChildID(
3585 const VARIANT
& var_id
) {
3586 if (var_id
.vt
!= VT_I4
)
3589 LONG child_id
= var_id
.lVal
;
3590 if (child_id
== CHILDID_SELF
)
3593 if (child_id
>= 1 && child_id
<= static_cast<LONG
>(PlatformChildCount()))
3594 return PlatformGetChild(child_id
- 1)->ToBrowserAccessibilityWin();
3596 return manager()->ToBrowserAccessibilityManagerWin()->
3597 GetFromUniqueIdWin(child_id
);
3600 HRESULT
BrowserAccessibilityWin::GetStringAttributeAsBstr(
3601 ui::AXStringAttribute attribute
,
3605 if (!GetString16Attribute(attribute
, &str
))
3611 *value_bstr
= SysAllocString(str
.c_str());
3612 DCHECK(*value_bstr
);
3617 void BrowserAccessibilityWin::StringAttributeToIA2(
3618 ui::AXStringAttribute attribute
,
3619 const char* ia2_attr
) {
3620 base::string16 value
;
3621 if (GetString16Attribute(attribute
, &value
)) {
3622 win_attributes_
->ia2_attributes
.push_back(
3623 base::ASCIIToUTF16(ia2_attr
) + L
":" + value
);
3627 void BrowserAccessibilityWin::BoolAttributeToIA2(
3628 ui::AXBoolAttribute attribute
,
3629 const char* ia2_attr
) {
3631 if (GetBoolAttribute(attribute
, &value
)) {
3632 win_attributes_
->ia2_attributes
.push_back(
3633 (base::ASCIIToUTF16(ia2_attr
) + L
":") +
3634 (value
? L
"true" : L
"false"));
3638 void BrowserAccessibilityWin::IntAttributeToIA2(
3639 ui::AXIntAttribute attribute
,
3640 const char* ia2_attr
) {
3642 if (GetIntAttribute(attribute
, &value
)) {
3643 win_attributes_
->ia2_attributes
.push_back(
3644 base::ASCIIToUTF16(ia2_attr
) + L
":" +
3645 base::IntToString16(value
));
3649 int32
BrowserAccessibilityWin::GetHyperlinkIndexFromChild(
3650 const BrowserAccessibilityWin
& child
) const {
3651 auto iterator
= std::find(
3652 hyperlinks().begin(), hyperlinks().end(), child
.GetId());
3653 if (iterator
== hyperlinks().end())
3656 return static_cast<int32
>(iterator
- hyperlinks().begin());
3659 int32
BrowserAccessibilityWin::GetHypertextOffsetFromHyperlinkIndex(
3660 int32 hyperlink_index
) const {
3661 auto& offsets_map
= hyperlink_offset_to_index();
3662 for (auto& offset_index
: offsets_map
) {
3663 if (offset_index
.second
== hyperlink_index
)
3664 return offset_index
.first
;
3670 int32
BrowserAccessibilityWin::GetHypertextOffsetFromChild(
3671 const BrowserAccessibilityWin
& child
) const {
3672 int32 hyperlink_index
= GetHyperlinkIndexFromChild(child
);
3673 if (hyperlink_index
< 0)
3676 return GetHypertextOffsetFromHyperlinkIndex(hyperlink_index
);
3679 int32
BrowserAccessibilityWin::GetHypertextOffsetFromDescendant(
3680 const BrowserAccessibilityWin
& descendant
) const {
3681 auto parent_object
= descendant
.GetParent()->ToBrowserAccessibilityWin();
3682 auto current_object
= const_cast<BrowserAccessibilityWin
*>(&descendant
);
3683 while (parent_object
&& parent_object
!= this) {
3684 current_object
= parent_object
;
3685 parent_object
= current_object
->GetParent()->ToBrowserAccessibilityWin();
3690 return parent_object
->GetHypertextOffsetFromChild(*current_object
);
3693 int BrowserAccessibilityWin::GetSelectionAnchor() const {
3694 BrowserAccessibility
* root
= manager()->GetRoot();
3696 if (!root
|| !root
->GetIntAttribute(ui::AX_ATTR_ANCHOR_OBJECT_ID
, &anchor_id
))
3699 BrowserAccessibilityWin
* anchor_object
= manager()->GetFromID(
3700 anchor_id
)->ToBrowserAccessibilityWin();
3704 // Includes the case when anchor_object == this.
3705 if (IsDescendantOf(anchor_object
) ||
3706 // Text only objects that are direct descendants should behave as if they
3707 // are part of this object when computing hypertext.
3708 (anchor_object
->GetParent() == this &&
3709 anchor_object
->IsTextOnlyObject())) {
3711 if (!root
->GetIntAttribute(ui::AX_ATTR_ANCHOR_OFFSET
, &anchor_offset
))
3714 return anchor_offset
;
3717 if (anchor_object
->IsDescendantOf(this))
3718 return GetHypertextOffsetFromDescendant(*anchor_object
);
3723 int BrowserAccessibilityWin::GetSelectionFocus() const {
3724 BrowserAccessibility
* root
= manager()->GetRoot();
3726 if (!root
|| !root
->GetIntAttribute(ui::AX_ATTR_FOCUS_OBJECT_ID
, &focus_id
))
3729 BrowserAccessibilityWin
* focus_object
= manager()->GetFromID(
3730 focus_id
)->ToBrowserAccessibilityWin();
3734 // Includes the case when focus_object == this.
3735 if (IsDescendantOf(focus_object
) ||
3736 // Text only objects that are direct descendants should behave as if they
3737 // are part of this object when computing hypertext.
3738 (focus_object
->GetParent() == this && focus_object
->IsTextOnlyObject())) {
3740 if (!root
->GetIntAttribute(ui::AX_ATTR_FOCUS_OFFSET
, &focus_offset
))
3743 return focus_offset
;
3746 if (focus_object
->IsDescendantOf(this))
3747 return GetHypertextOffsetFromDescendant(*focus_object
);
3752 void BrowserAccessibilityWin::GetSelectionOffsets(
3753 int* selection_start
, int* selection_end
) const {
3754 DCHECK(selection_start
&& selection_end
);
3756 if (GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START
, selection_start
) &&
3757 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, selection_end
)) {
3761 *selection_start
= GetSelectionAnchor();
3762 *selection_end
= GetSelectionFocus();
3763 if (*selection_start
< 0 || *selection_end
< 0)
3766 if (*selection_end
< *selection_start
)
3767 std::swap(*selection_start
, *selection_end
);
3769 // IA2 Spec says that the end of the selection should be after the last
3770 // embedded object character that is part of the selection.
3774 base::string16
BrowserAccessibilityWin::GetNameRecursive() const {
3775 if (!name().empty()) {
3779 base::string16 result
;
3780 for (uint32 i
= 0; i
< PlatformChildCount(); ++i
) {
3781 result
+= PlatformGetChild(i
)->ToBrowserAccessibilityWin()->
3787 base::string16
BrowserAccessibilityWin::GetValueText() {
3789 base::string16 value
= this->value();
3791 if (value
.empty() &&
3792 GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
, &fval
)) {
3793 value
= base::UTF8ToUTF16(base::DoubleToString(fval
));
3798 base::string16
BrowserAccessibilityWin::TextForIAccessibleText() {
3799 switch (GetRole()) {
3800 case ui::AX_ROLE_TEXT_FIELD
:
3801 case ui::AX_ROLE_MENU_LIST_OPTION
:
3808 bool BrowserAccessibilityWin::IsSameHypertextCharacter(size_t old_char_index
,
3809 size_t new_char_index
) {
3810 CHECK(old_win_attributes_
);
3812 // For anything other than the "embedded character", we just compare the
3813 // characters directly.
3814 base::char16 old_ch
= old_win_attributes_
->hypertext
[old_char_index
];
3815 base::char16 new_ch
= win_attributes_
->hypertext
[new_char_index
];
3816 if (old_ch
!= new_ch
)
3818 if (old_ch
== new_ch
&& new_ch
!= kEmbeddedCharacter
)
3821 // If it's an embedded character, they're only identical if the child id
3822 // the hyperlink points to is the same.
3823 std::map
<int32
, int32
>& old_offset_to_index
=
3824 old_win_attributes_
->hyperlink_offset_to_index
;
3825 std::vector
<int32
>& old_hyperlinks
= old_win_attributes_
->hyperlinks
;
3826 int32 old_hyperlinks_count
= static_cast<int32
>(old_hyperlinks
.size());
3827 std::map
<int32
, int32
>::iterator iter
;
3828 iter
= old_offset_to_index
.find(old_char_index
);
3829 int old_index
= (iter
!= old_offset_to_index
.end()) ? iter
->second
: -1;
3830 int old_child_id
= (old_index
>= 0 && old_index
< old_hyperlinks_count
) ?
3831 old_hyperlinks
[old_index
] : -1;
3833 std::map
<int32
, int32
>& new_offset_to_index
=
3834 win_attributes_
->hyperlink_offset_to_index
;
3835 std::vector
<int32
>& new_hyperlinks
= win_attributes_
->hyperlinks
;
3836 int32 new_hyperlinks_count
= static_cast<int32
>(new_hyperlinks
.size());
3837 iter
= new_offset_to_index
.find(new_char_index
);
3838 int new_index
= (iter
!= new_offset_to_index
.end()) ? iter
->second
: -1;
3839 int new_child_id
= (new_index
>= 0 && new_index
< new_hyperlinks_count
) ?
3840 new_hyperlinks
[new_index
] : -1;
3842 return old_child_id
== new_child_id
;
3845 void BrowserAccessibilityWin::ComputeHypertextRemovedAndInserted(
3846 int* start
, int* old_len
, int* new_len
) {
3847 CHECK(old_win_attributes_
);
3853 const base::string16
& old_text
= old_win_attributes_
->hypertext
;
3854 const base::string16
& new_text
= hypertext();
3856 size_t common_prefix
= 0;
3857 while (common_prefix
< old_text
.size() &&
3858 common_prefix
< new_text
.size() &&
3859 IsSameHypertextCharacter(common_prefix
, common_prefix
)) {
3863 size_t common_suffix
= 0;
3864 while (common_prefix
+ common_suffix
< old_text
.size() &&
3865 common_prefix
+ common_suffix
< new_text
.size() &&
3866 IsSameHypertextCharacter(
3867 old_text
.size() - common_suffix
- 1,
3868 new_text
.size() - common_suffix
- 1)) {
3872 *start
= common_prefix
;
3873 *old_len
= old_text
.size() - common_prefix
- common_suffix
;
3874 *new_len
= new_text
.size() - common_prefix
- common_suffix
;
3877 void BrowserAccessibilityWin::HandleSpecialTextOffset(
3878 const base::string16
& text
,
3880 if (*offset
== IA2_TEXT_OFFSET_LENGTH
)
3881 *offset
= static_cast<LONG
>(text
.size());
3882 else if (*offset
== IA2_TEXT_OFFSET_CARET
)
3883 get_caretOffset(offset
);
3886 ui::TextBoundaryType
BrowserAccessibilityWin::IA2TextBoundaryToTextBoundary(
3887 IA2TextBoundaryType ia2_boundary
) {
3888 switch(ia2_boundary
) {
3889 case IA2_TEXT_BOUNDARY_CHAR
:
3890 return ui::CHAR_BOUNDARY
;
3891 case IA2_TEXT_BOUNDARY_WORD
:
3892 return ui::WORD_BOUNDARY
;
3893 case IA2_TEXT_BOUNDARY_LINE
:
3894 return ui::LINE_BOUNDARY
;
3895 case IA2_TEXT_BOUNDARY_SENTENCE
:
3896 return ui::SENTENCE_BOUNDARY
;
3897 case IA2_TEXT_BOUNDARY_PARAGRAPH
:
3898 return ui::PARAGRAPH_BOUNDARY
;
3899 case IA2_TEXT_BOUNDARY_ALL
:
3900 return ui::ALL_BOUNDARY
;
3904 return ui::CHAR_BOUNDARY
;
3907 LONG
BrowserAccessibilityWin::FindBoundary(
3908 const base::string16
& text
,
3909 IA2TextBoundaryType ia2_boundary
,
3911 ui::TextBoundaryDirection direction
) {
3912 HandleSpecialTextOffset(text
, &start_offset
);
3913 if (ia2_boundary
== IA2_TEXT_BOUNDARY_WORD
&&
3914 GetRole() == ui::AX_ROLE_TEXT_FIELD
) {
3915 return GetWordStartBoundary(static_cast<int>(start_offset
), direction
);
3918 ui::TextBoundaryType boundary
= IA2TextBoundaryToTextBoundary(ia2_boundary
);
3919 const std::vector
<int32
>& line_breaks
= GetIntListAttribute(
3920 ui::AX_ATTR_LINE_BREAKS
);
3921 return ui::FindAccessibleTextBoundary(
3922 text
, line_breaks
, boundary
, start_offset
, direction
);
3925 BrowserAccessibilityWin
* BrowserAccessibilityWin::GetFromID(int32 id
) {
3926 return manager()->GetFromID(id
)->ToBrowserAccessibilityWin();
3929 bool BrowserAccessibilityWin::IsListBoxOptionOrMenuListOption() {
3933 int32 role
= GetRole();
3934 int32 parent_role
= GetParent()->GetRole();
3936 if (role
== ui::AX_ROLE_LIST_BOX_OPTION
&&
3937 parent_role
== ui::AX_ROLE_LIST_BOX
) {
3941 if (role
== ui::AX_ROLE_MENU_LIST_OPTION
&&
3942 parent_role
== ui::AX_ROLE_MENU_LIST_POPUP
) {
3949 void BrowserAccessibilityWin::InitRoleAndState() {
3952 base::string16 role_name
;
3954 int32 ia2_state
= IA2_STATE_OPAQUE
;
3956 if (HasState(ui::AX_STATE_BUSY
))
3957 ia_state
|= STATE_SYSTEM_BUSY
;
3958 if (HasState(ui::AX_STATE_CHECKED
))
3959 ia_state
|= STATE_SYSTEM_CHECKED
;
3960 if (HasState(ui::AX_STATE_COLLAPSED
))
3961 ia_state
|= STATE_SYSTEM_COLLAPSED
;
3962 if (HasState(ui::AX_STATE_EXPANDED
))
3963 ia_state
|= STATE_SYSTEM_EXPANDED
;
3964 if (HasState(ui::AX_STATE_FOCUSABLE
))
3965 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3966 if (HasState(ui::AX_STATE_HASPOPUP
))
3967 ia_state
|= STATE_SYSTEM_HASPOPUP
;
3968 if (HasState(ui::AX_STATE_INDETERMINATE
))
3969 ia_state
|= STATE_SYSTEM_INDETERMINATE
;
3970 if (HasIntAttribute(ui::AX_ATTR_INVALID_STATE
) &&
3971 GetIntAttribute(ui::AX_ATTR_INVALID_STATE
) != ui::AX_INVALID_STATE_FALSE
)
3972 ia2_state
|= IA2_STATE_INVALID_ENTRY
;
3973 if (HasState(ui::AX_STATE_INVISIBLE
))
3974 ia_state
|= STATE_SYSTEM_INVISIBLE
;
3975 if (HasState(ui::AX_STATE_LINKED
))
3976 ia_state
|= STATE_SYSTEM_LINKED
;
3977 if (HasState(ui::AX_STATE_MULTISELECTABLE
)) {
3978 ia_state
|= STATE_SYSTEM_EXTSELECTABLE
;
3979 ia_state
|= STATE_SYSTEM_MULTISELECTABLE
;
3981 // TODO(ctguil): Support STATE_SYSTEM_EXTSELECTABLE/accSelect.
3982 if (HasState(ui::AX_STATE_OFFSCREEN
))
3983 ia_state
|= STATE_SYSTEM_OFFSCREEN
;
3984 if (HasState(ui::AX_STATE_PRESSED
))
3985 ia_state
|= STATE_SYSTEM_PRESSED
;
3986 if (HasState(ui::AX_STATE_PROTECTED
))
3987 ia_state
|= STATE_SYSTEM_PROTECTED
;
3988 if (HasState(ui::AX_STATE_REQUIRED
))
3989 ia2_state
|= IA2_STATE_REQUIRED
;
3990 if (HasState(ui::AX_STATE_SELECTABLE
))
3991 ia_state
|= STATE_SYSTEM_SELECTABLE
;
3992 if (HasState(ui::AX_STATE_SELECTED
))
3993 ia_state
|= STATE_SYSTEM_SELECTED
;
3994 if (HasState(ui::AX_STATE_VISITED
))
3995 ia_state
|= STATE_SYSTEM_TRAVERSED
;
3996 if (!HasState(ui::AX_STATE_ENABLED
))
3997 ia_state
|= STATE_SYSTEM_UNAVAILABLE
;
3998 if (HasState(ui::AX_STATE_VERTICAL
))
3999 ia2_state
|= IA2_STATE_VERTICAL
;
4000 if (HasState(ui::AX_STATE_HORIZONTAL
))
4001 ia2_state
|= IA2_STATE_HORIZONTAL
;
4002 if (HasState(ui::AX_STATE_VISITED
))
4003 ia_state
|= STATE_SYSTEM_TRAVERSED
;
4005 // Expose whether or not the mouse is over an element, but suppress
4006 // this for tests because it can make the test results flaky depending
4007 // on the position of the mouse.
4008 BrowserAccessibilityStateImpl
* accessibility_state
=
4009 BrowserAccessibilityStateImpl::GetInstance();
4010 if (!accessibility_state
->disable_hot_tracking_for_testing()) {
4011 if (HasState(ui::AX_STATE_HOVERED
))
4012 ia_state
|= STATE_SYSTEM_HOTTRACKED
;
4015 // WebKit marks everything as readonly unless it's editable text, so if it's
4016 // not readonly, mark it as editable now. The final computation of the
4017 // READONLY state for MSAA is below, after the switch.
4018 if (!HasState(ui::AX_STATE_READ_ONLY
))
4019 ia2_state
|= IA2_STATE_EDITABLE
;
4021 if (GetBoolAttribute(ui::AX_ATTR_BUTTON_MIXED
))
4022 ia_state
|= STATE_SYSTEM_MIXED
;
4024 if (GetBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE
))
4025 ia2_state
|= IA2_STATE_EDITABLE
;
4027 if (!GetStringAttribute(ui::AX_ATTR_AUTO_COMPLETE
).empty())
4028 ia2_state
|= IA2_STATE_SUPPORTS_AUTOCOMPLETION
;
4030 base::string16 html_tag
= GetString16Attribute(
4031 ui::AX_ATTR_HTML_TAG
);
4032 switch (GetRole()) {
4033 case ui::AX_ROLE_ALERT
:
4034 ia_role
= ROLE_SYSTEM_ALERT
;
4036 case ui::AX_ROLE_ALERT_DIALOG
:
4037 ia_role
= ROLE_SYSTEM_DIALOG
;
4039 case ui::AX_ROLE_APPLICATION
:
4040 ia_role
= ROLE_SYSTEM_APPLICATION
;
4042 case ui::AX_ROLE_ARTICLE
:
4043 ia_role
= ROLE_SYSTEM_DOCUMENT
;
4044 ia_state
|= STATE_SYSTEM_READONLY
;
4046 case ui::AX_ROLE_BANNER
:
4047 ia_role
= ROLE_SYSTEM_GROUPING
;
4048 ia2_role
= IA2_ROLE_HEADER
;
4050 case ui::AX_ROLE_BLOCKQUOTE
:
4051 role_name
= html_tag
;
4052 ia2_role
= IA2_ROLE_SECTION
;
4054 case ui::AX_ROLE_BUSY_INDICATOR
:
4055 ia_role
= ROLE_SYSTEM_ANIMATION
;
4056 ia_state
|= STATE_SYSTEM_READONLY
;
4058 case ui::AX_ROLE_BUTTON
:
4059 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4061 case ui::AX_ROLE_CANVAS
:
4062 if (GetBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK
)) {
4063 role_name
= L
"canvas";
4064 ia2_role
= IA2_ROLE_CANVAS
;
4066 ia_role
= ROLE_SYSTEM_GRAPHIC
;
4069 case ui::AX_ROLE_CAPTION
:
4070 ia_role
= ROLE_SYSTEM_TEXT
;
4071 ia2_role
= IA2_ROLE_CAPTION
;
4073 case ui::AX_ROLE_CELL
:
4074 ia_role
= ROLE_SYSTEM_CELL
;
4076 case ui::AX_ROLE_CHECK_BOX
:
4077 ia_role
= ROLE_SYSTEM_CHECKBUTTON
;
4078 ia2_state
|= IA2_STATE_CHECKABLE
;
4080 case ui::AX_ROLE_COLOR_WELL
:
4081 ia_role
= ROLE_SYSTEM_TEXT
;
4082 ia2_role
= IA2_ROLE_COLOR_CHOOSER
;
4084 case ui::AX_ROLE_COLUMN
:
4085 ia_role
= ROLE_SYSTEM_COLUMN
;
4087 case ui::AX_ROLE_COLUMN_HEADER
:
4088 ia_role
= ROLE_SYSTEM_COLUMNHEADER
;
4090 case ui::AX_ROLE_COMBO_BOX
:
4091 ia_role
= ROLE_SYSTEM_COMBOBOX
;
4093 case ui::AX_ROLE_COMPLEMENTARY
:
4094 ia_role
= ROLE_SYSTEM_GROUPING
;
4095 ia2_role
= IA2_ROLE_NOTE
;
4097 case ui::AX_ROLE_CONTENT_INFO
:
4098 ia_role
= ROLE_SYSTEM_TEXT
;
4099 ia2_role
= IA2_ROLE_PARAGRAPH
;
4101 case ui::AX_ROLE_DATE
:
4102 case ui::AX_ROLE_DATE_TIME
:
4103 ia_role
= ROLE_SYSTEM_DROPLIST
;
4104 ia2_role
= IA2_ROLE_DATE_EDITOR
;
4106 case ui::AX_ROLE_DIV
:
4108 ia_role
= ROLE_SYSTEM_GROUPING
;
4109 ia2_role
= IA2_ROLE_SECTION
;
4111 case ui::AX_ROLE_DEFINITION
:
4112 role_name
= html_tag
;
4113 ia2_role
= IA2_ROLE_PARAGRAPH
;
4114 ia_state
|= STATE_SYSTEM_READONLY
;
4116 case ui::AX_ROLE_DESCRIPTION_LIST_DETAIL
:
4117 role_name
= html_tag
;
4118 ia_role
= ROLE_SYSTEM_TEXT
;
4119 ia2_role
= IA2_ROLE_PARAGRAPH
;
4121 case ui::AX_ROLE_DESCRIPTION_LIST
:
4122 role_name
= html_tag
;
4123 ia_role
= ROLE_SYSTEM_LIST
;
4124 ia_state
|= STATE_SYSTEM_READONLY
;
4126 case ui::AX_ROLE_DESCRIPTION_LIST_TERM
:
4127 ia_role
= ROLE_SYSTEM_LISTITEM
;
4128 ia_state
|= STATE_SYSTEM_READONLY
;
4130 case ui::AX_ROLE_DETAILS
:
4131 role_name
= html_tag
;
4132 ia_role
= ROLE_SYSTEM_GROUPING
;
4134 case ui::AX_ROLE_DIALOG
:
4135 ia_role
= ROLE_SYSTEM_DIALOG
;
4137 case ui::AX_ROLE_DISCLOSURE_TRIANGLE
:
4138 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4140 case ui::AX_ROLE_DOCUMENT
:
4141 case ui::AX_ROLE_ROOT_WEB_AREA
:
4142 case ui::AX_ROLE_WEB_AREA
:
4143 ia_role
= ROLE_SYSTEM_DOCUMENT
;
4144 ia_state
|= STATE_SYSTEM_READONLY
;
4145 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
4147 case ui::AX_ROLE_EMBEDDED_OBJECT
:
4148 ia_role
= ROLE_SYSTEM_CLIENT
;
4149 ia2_role
= IA2_ROLE_EMBEDDED_OBJECT
;
4151 case ui::AX_ROLE_FIGCAPTION
:
4152 role_name
= html_tag
;
4153 ia2_role
= IA2_ROLE_CAPTION
;
4155 case ui::AX_ROLE_FIGURE
:
4156 ia_role
= ROLE_SYSTEM_GROUPING
;
4158 case ui::AX_ROLE_FORM
:
4159 role_name
= L
"form";
4160 ia2_role
= IA2_ROLE_FORM
;
4162 case ui::AX_ROLE_FOOTER
:
4163 ia_role
= ROLE_SYSTEM_GROUPING
;
4164 ia2_role
= IA2_ROLE_FOOTER
;
4166 case ui::AX_ROLE_GRID
:
4167 ia_role
= ROLE_SYSTEM_TABLE
;
4168 ia_state
|= STATE_SYSTEM_READONLY
;
4170 case ui::AX_ROLE_GROUP
: {
4171 base::string16 aria_role
= GetString16Attribute(
4173 if (aria_role
== L
"group" || html_tag
== L
"fieldset") {
4174 ia_role
= ROLE_SYSTEM_GROUPING
;
4175 } else if (html_tag
== L
"li") {
4176 ia_role
= ROLE_SYSTEM_LISTITEM
;
4177 ia_state
|= STATE_SYSTEM_READONLY
;
4179 if (html_tag
.empty())
4182 role_name
= html_tag
;
4183 ia2_role
= IA2_ROLE_SECTION
;
4187 case ui::AX_ROLE_HEADING
:
4188 role_name
= html_tag
;
4189 ia2_role
= IA2_ROLE_HEADING
;
4191 case ui::AX_ROLE_IFRAME
:
4192 ia_role
= ROLE_SYSTEM_DOCUMENT
;
4193 ia2_role
= IA2_ROLE_INTERNAL_FRAME
;
4194 ia_state
= STATE_SYSTEM_READONLY
;
4196 case ui::AX_ROLE_IFRAME_PRESENTATIONAL
:
4197 ia_role
= ROLE_SYSTEM_GROUPING
;
4199 case ui::AX_ROLE_IMAGE
:
4200 ia_role
= ROLE_SYSTEM_GRAPHIC
;
4201 ia_state
|= STATE_SYSTEM_READONLY
;
4203 case ui::AX_ROLE_IMAGE_MAP
:
4204 role_name
= html_tag
;
4205 ia2_role
= IA2_ROLE_IMAGE_MAP
;
4206 ia_state
|= STATE_SYSTEM_READONLY
;
4208 case ui::AX_ROLE_IMAGE_MAP_LINK
:
4209 ia_role
= ROLE_SYSTEM_LINK
;
4210 ia_state
|= STATE_SYSTEM_LINKED
;
4211 ia_state
|= STATE_SYSTEM_READONLY
;
4213 case ui::AX_ROLE_INPUT_TIME
:
4214 ia_role
= ROLE_SYSTEM_GROUPING
;
4216 case ui::AX_ROLE_LABEL_TEXT
:
4217 case ui::AX_ROLE_LEGEND
:
4218 ia_role
= ROLE_SYSTEM_TEXT
;
4219 ia2_role
= IA2_ROLE_LABEL
;
4221 case ui::AX_ROLE_LINK
:
4222 ia_role
= ROLE_SYSTEM_LINK
;
4223 ia_state
|= STATE_SYSTEM_LINKED
;
4225 case ui::AX_ROLE_LIST
:
4226 ia_role
= ROLE_SYSTEM_LIST
;
4227 ia_state
|= STATE_SYSTEM_READONLY
;
4229 case ui::AX_ROLE_LIST_BOX
:
4230 ia_role
= ROLE_SYSTEM_LIST
;
4232 case ui::AX_ROLE_LIST_BOX_OPTION
:
4233 ia_role
= ROLE_SYSTEM_LISTITEM
;
4234 if (ia_state
& STATE_SYSTEM_SELECTABLE
) {
4235 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
4236 if (HasState(ui::AX_STATE_FOCUSED
))
4237 ia_state
|= STATE_SYSTEM_FOCUSED
;
4240 case ui::AX_ROLE_LIST_ITEM
:
4241 ia_role
= ROLE_SYSTEM_LISTITEM
;
4242 ia_state
|= STATE_SYSTEM_READONLY
;
4244 case ui::AX_ROLE_MAIN
:
4245 ia_role
= ROLE_SYSTEM_GROUPING
;
4246 ia2_role
= IA2_ROLE_PARAGRAPH
;
4248 case ui::AX_ROLE_MARK
:
4249 ia_role
= ROLE_SYSTEM_TEXT
;
4250 ia2_role
= IA2_ROLE_TEXT_FRAME
;
4252 case ui::AX_ROLE_MARQUEE
:
4253 ia_role
= ROLE_SYSTEM_ANIMATION
;
4255 case ui::AX_ROLE_MATH
:
4256 ia_role
= ROLE_SYSTEM_EQUATION
;
4258 case ui::AX_ROLE_MENU
:
4259 case ui::AX_ROLE_MENU_BUTTON
:
4260 ia_role
= ROLE_SYSTEM_MENUPOPUP
;
4262 case ui::AX_ROLE_MENU_BAR
:
4263 ia_role
= ROLE_SYSTEM_MENUBAR
;
4265 case ui::AX_ROLE_MENU_ITEM
:
4266 ia_role
= ROLE_SYSTEM_MENUITEM
;
4268 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX
:
4269 ia_role
= ROLE_SYSTEM_MENUITEM
;
4270 ia2_role
= IA2_ROLE_CHECK_MENU_ITEM
;
4271 ia2_state
|= IA2_STATE_CHECKABLE
;
4273 case ui::AX_ROLE_MENU_ITEM_RADIO
:
4274 ia_role
= ROLE_SYSTEM_MENUITEM
;
4275 ia2_role
= IA2_ROLE_RADIO_MENU_ITEM
;
4277 case ui::AX_ROLE_MENU_LIST_POPUP
:
4278 ia_role
= ROLE_SYSTEM_LIST
;
4279 ia2_state
&= ~(IA2_STATE_EDITABLE
);
4281 case ui::AX_ROLE_MENU_LIST_OPTION
:
4282 ia_role
= ROLE_SYSTEM_LISTITEM
;
4283 ia2_state
&= ~(IA2_STATE_EDITABLE
);
4284 if (ia_state
& STATE_SYSTEM_SELECTABLE
) {
4285 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
4286 if (HasState(ui::AX_STATE_FOCUSED
))
4287 ia_state
|= STATE_SYSTEM_FOCUSED
;
4290 case ui::AX_ROLE_METER
:
4291 role_name
= html_tag
;
4292 ia_role
= ROLE_SYSTEM_PROGRESSBAR
;
4294 case ui::AX_ROLE_NAVIGATION
:
4295 ia_role
= ROLE_SYSTEM_GROUPING
;
4296 ia2_role
= IA2_ROLE_SECTION
;
4298 case ui::AX_ROLE_NOTE
:
4299 ia_role
= ROLE_SYSTEM_GROUPING
;
4300 ia2_role
= IA2_ROLE_NOTE
;
4302 case ui::AX_ROLE_OUTLINE
:
4303 ia_role
= ROLE_SYSTEM_OUTLINE
;
4305 case ui::AX_ROLE_PARAGRAPH
:
4307 ia2_role
= IA2_ROLE_PARAGRAPH
;
4309 case ui::AX_ROLE_POP_UP_BUTTON
:
4310 if (html_tag
== L
"select") {
4311 ia_role
= ROLE_SYSTEM_COMBOBOX
;
4313 ia_role
= ROLE_SYSTEM_BUTTONMENU
;
4316 case ui::AX_ROLE_PRE
:
4317 role_name
= html_tag
;
4318 ia_role
= ROLE_SYSTEM_TEXT
;
4319 ia2_role
= IA2_ROLE_PARAGRAPH
;
4321 case ui::AX_ROLE_PROGRESS_INDICATOR
:
4322 ia_role
= ROLE_SYSTEM_PROGRESSBAR
;
4323 ia_state
|= STATE_SYSTEM_READONLY
;
4325 case ui::AX_ROLE_RADIO_BUTTON
:
4326 ia_role
= ROLE_SYSTEM_RADIOBUTTON
;
4327 ia2_state
= IA2_STATE_CHECKABLE
;
4329 case ui::AX_ROLE_RADIO_GROUP
:
4330 ia_role
= ROLE_SYSTEM_GROUPING
;
4332 case ui::AX_ROLE_REGION
:
4333 if (html_tag
== L
"section") {
4334 ia_role
= ROLE_SYSTEM_GROUPING
;
4335 ia2_role
= IA2_ROLE_SECTION
;
4337 ia_role
= ROLE_SYSTEM_PANE
;
4340 case ui::AX_ROLE_ROW
:
4341 ia_role
= ROLE_SYSTEM_ROW
;
4343 case ui::AX_ROLE_ROW_HEADER
:
4344 ia_role
= ROLE_SYSTEM_ROWHEADER
;
4346 case ui::AX_ROLE_RUBY
:
4347 ia_role
= ROLE_SYSTEM_TEXT
;
4348 ia2_role
= IA2_ROLE_TEXT_FRAME
;
4350 case ui::AX_ROLE_RULER
:
4351 ia_role
= ROLE_SYSTEM_CLIENT
;
4352 ia2_role
= IA2_ROLE_RULER
;
4353 ia_state
|= STATE_SYSTEM_READONLY
;
4355 case ui::AX_ROLE_SCROLL_AREA
:
4356 ia_role
= ROLE_SYSTEM_CLIENT
;
4357 ia2_role
= IA2_ROLE_SCROLL_PANE
;
4358 ia_state
|= STATE_SYSTEM_READONLY
;
4359 ia2_state
&= ~(IA2_STATE_EDITABLE
);
4361 case ui::AX_ROLE_SCROLL_BAR
:
4362 ia_role
= ROLE_SYSTEM_SCROLLBAR
;
4364 case ui::AX_ROLE_SEARCH
:
4365 ia_role
= ROLE_SYSTEM_GROUPING
;
4366 ia2_role
= IA2_ROLE_SECTION
;
4368 case ui::AX_ROLE_SLIDER
:
4369 ia_role
= ROLE_SYSTEM_SLIDER
;
4371 case ui::AX_ROLE_SPIN_BUTTON
:
4372 ia_role
= ROLE_SYSTEM_SPINBUTTON
;
4374 case ui::AX_ROLE_SPIN_BUTTON_PART
:
4375 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4377 case ui::AX_ROLE_ANNOTATION
:
4378 case ui::AX_ROLE_LIST_MARKER
:
4379 case ui::AX_ROLE_STATIC_TEXT
:
4380 ia_role
= ROLE_SYSTEM_STATICTEXT
;
4382 case ui::AX_ROLE_STATUS
:
4383 ia_role
= ROLE_SYSTEM_STATUSBAR
;
4385 case ui::AX_ROLE_SPLITTER
:
4386 ia_role
= ROLE_SYSTEM_SEPARATOR
;
4388 case ui::AX_ROLE_SVG_ROOT
:
4389 ia_role
= ROLE_SYSTEM_GRAPHIC
;
4391 case ui::AX_ROLE_SWITCH
:
4392 role_name
= L
"switch";
4393 ia2_role
= IA2_ROLE_TOGGLE_BUTTON
;
4395 case ui::AX_ROLE_TAB
:
4396 ia_role
= ROLE_SYSTEM_PAGETAB
;
4398 case ui::AX_ROLE_TABLE
: {
4399 base::string16 aria_role
= GetString16Attribute(
4401 if (aria_role
== L
"treegrid") {
4402 ia_role
= ROLE_SYSTEM_OUTLINE
;
4404 ia_role
= ROLE_SYSTEM_TABLE
;
4408 case ui::AX_ROLE_TABLE_HEADER_CONTAINER
:
4409 ia_role
= ROLE_SYSTEM_GROUPING
;
4410 ia2_role
= IA2_ROLE_SECTION
;
4411 ia_state
|= STATE_SYSTEM_READONLY
;
4413 case ui::AX_ROLE_TAB_LIST
:
4414 ia_role
= ROLE_SYSTEM_PAGETABLIST
;
4416 case ui::AX_ROLE_TAB_PANEL
:
4417 ia_role
= ROLE_SYSTEM_PROPERTYPAGE
;
4419 case ui::AX_ROLE_TOGGLE_BUTTON
:
4420 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4421 ia2_role
= IA2_ROLE_TOGGLE_BUTTON
;
4423 case ui::AX_ROLE_TEXT_FIELD
:
4424 case ui::AX_ROLE_SEARCH_BOX
:
4425 ia_role
= ROLE_SYSTEM_TEXT
;
4426 if (HasState(ui::AX_STATE_MULTILINE
))
4427 ia2_state
|= IA2_STATE_MULTI_LINE
;
4429 ia2_state
|= IA2_STATE_SINGLE_LINE
;
4430 ia2_state
|= IA2_STATE_EDITABLE
;
4431 ia2_state
|= IA2_STATE_SELECTABLE_TEXT
;
4433 case ui::AX_ROLE_TIME
:
4434 role_name
= html_tag
;
4435 ia_role
= ROLE_SYSTEM_TEXT
;
4436 ia2_role
= IA2_ROLE_TEXT_FRAME
;
4438 case ui::AX_ROLE_TIMER
:
4439 ia_role
= ROLE_SYSTEM_CLOCK
;
4440 ia_state
|= STATE_SYSTEM_READONLY
;
4442 case ui::AX_ROLE_TOOLBAR
:
4443 ia_role
= ROLE_SYSTEM_TOOLBAR
;
4444 ia_state
|= STATE_SYSTEM_READONLY
;
4446 case ui::AX_ROLE_TOOLTIP
:
4447 ia_role
= ROLE_SYSTEM_TOOLTIP
;
4448 ia_state
|= STATE_SYSTEM_READONLY
;
4450 case ui::AX_ROLE_TREE
:
4451 ia_role
= ROLE_SYSTEM_OUTLINE
;
4453 case ui::AX_ROLE_TREE_GRID
:
4454 ia_role
= ROLE_SYSTEM_OUTLINE
;
4456 case ui::AX_ROLE_TREE_ITEM
:
4457 ia_role
= ROLE_SYSTEM_OUTLINEITEM
;
4459 case ui::AX_ROLE_LINE_BREAK
:
4460 ia_role
= ROLE_SYSTEM_WHITESPACE
;
4462 case ui::AX_ROLE_WINDOW
:
4463 ia_role
= ROLE_SYSTEM_WINDOW
;
4466 // TODO(dmazzoni): figure out the proper MSAA role for all of these.
4467 case ui::AX_ROLE_DIRECTORY
:
4468 case ui::AX_ROLE_IGNORED
:
4469 case ui::AX_ROLE_LOG
:
4470 case ui::AX_ROLE_NONE
:
4471 case ui::AX_ROLE_PRESENTATIONAL
:
4472 case ui::AX_ROLE_SLIDER_THUMB
:
4474 ia_role
= ROLE_SYSTEM_CLIENT
;
4478 // Compute the final value of READONLY for MSAA.
4480 // We always set the READONLY state for elements that have the
4481 // aria-readonly attribute and for a few roles (in the switch above).
4482 // We clear the READONLY state on focusable controls and on a document.
4483 // Everything else, the majority of objects, do not have this state set.
4484 if (HasState(ui::AX_STATE_FOCUSABLE
) &&
4485 ia_role
!= ROLE_SYSTEM_DOCUMENT
) {
4486 ia_state
&= ~(STATE_SYSTEM_READONLY
);
4488 if (!HasState(ui::AX_STATE_READ_ONLY
))
4489 ia_state
&= ~(STATE_SYSTEM_READONLY
);
4490 if (GetBoolAttribute(ui::AX_ATTR_ARIA_READONLY
))
4491 ia_state
|= STATE_SYSTEM_READONLY
;
4493 // The role should always be set.
4494 DCHECK(!role_name
.empty() || ia_role
);
4496 // If we didn't explicitly set the IAccessible2 role, make it the same
4497 // as the MSAA role.
4501 win_attributes_
->ia_role
= ia_role
;
4502 win_attributes_
->ia_state
= ia_state
;
4503 win_attributes_
->role_name
= role_name
;
4504 win_attributes_
->ia2_role
= ia2_role
;
4505 win_attributes_
->ia2_state
= ia2_state
;
4508 } // namespace content