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>
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/win/enum_variant.h"
15 #include "base/win/scoped_comptr.h"
16 #include "base/win/windows_version.h"
17 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
18 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
19 #include "content/common/accessibility_messages.h"
20 #include "content/public/common/content_client.h"
21 #include "ui/accessibility/ax_text_utils.h"
22 #include "ui/base/win/accessibility_ids_win.h"
23 #include "ui/base/win/accessibility_misc_utils.h"
24 #include "ui/base/win/atl_module.h"
28 // These nonstandard GUIDs are taken directly from the Mozilla sources
29 // (accessible/src/msaa/nsAccessNodeWrap.cpp); some documentation is here:
30 // http://developer.mozilla.org/en/Accessibility/AT-APIs/ImplementationFeatures/MSAA
31 const GUID GUID_ISimpleDOM
= {
32 0x0c539790, 0x12e4, 0x11cf,
33 0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8};
34 const GUID GUID_IAccessibleContentDocument
= {
35 0xa5d8e1f3, 0x3571, 0x4d8f,
36 0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e};
38 const base::char16
BrowserAccessibilityWin::kEmbeddedCharacter
= L
'\xfffc';
41 LONG
BrowserAccessibilityWin::next_unique_id_win_
=
42 base::win::kFirstBrowserAccessibilityManagerAccessibilityId
;
45 // BrowserAccessibilityRelation
47 // A simple implementation of IAccessibleRelation, used to represent
48 // a relationship between two accessible nodes in the tree.
51 class BrowserAccessibilityRelation
52 : public CComObjectRootEx
<CComMultiThreadModel
>,
53 public IAccessibleRelation
{
54 BEGIN_COM_MAP(BrowserAccessibilityRelation
)
55 COM_INTERFACE_ENTRY(IAccessibleRelation
)
58 CONTENT_EXPORT
BrowserAccessibilityRelation() {}
59 CONTENT_EXPORT
virtual ~BrowserAccessibilityRelation() {}
61 CONTENT_EXPORT
void Initialize(BrowserAccessibilityWin
* owner
,
62 const base::string16
& type
);
63 CONTENT_EXPORT
void AddTarget(int target_id
);
65 // IAccessibleRelation methods.
66 CONTENT_EXPORT STDMETHODIMP
get_relationType(BSTR
* relation_type
);
67 CONTENT_EXPORT STDMETHODIMP
get_nTargets(long* n_targets
);
68 CONTENT_EXPORT STDMETHODIMP
get_target(long target_index
, IUnknown
** target
);
69 CONTENT_EXPORT STDMETHODIMP
get_targets(long max_targets
,
73 // IAccessibleRelation methods not implemented.
74 CONTENT_EXPORT STDMETHODIMP
get_localizedRelationType(BSTR
* relation_type
) {
80 base::win::ScopedComPtr
<BrowserAccessibilityWin
> owner_
;
81 std::vector
<int> target_ids_
;
84 void BrowserAccessibilityRelation::Initialize(BrowserAccessibilityWin
* owner
,
85 const base::string16
& type
) {
90 void BrowserAccessibilityRelation::AddTarget(int target_id
) {
91 target_ids_
.push_back(target_id
);
94 STDMETHODIMP
BrowserAccessibilityRelation::get_relationType(
95 BSTR
* relation_type
) {
99 if (!owner_
->instance_active())
102 *relation_type
= SysAllocString(type_
.c_str());
103 DCHECK(*relation_type
);
107 STDMETHODIMP
BrowserAccessibilityRelation::get_nTargets(long* n_targets
) {
111 if (!owner_
->instance_active())
114 *n_targets
= static_cast<long>(target_ids_
.size());
116 BrowserAccessibilityManager
* manager
= owner_
->manager();
117 for (long i
= *n_targets
- 1; i
>= 0; --i
) {
118 BrowserAccessibility
* result
= manager
->GetFromID(target_ids_
[i
]);
119 if (!result
|| !result
->instance_active()) {
127 STDMETHODIMP
BrowserAccessibilityRelation::get_target(long target_index
,
132 if (!owner_
->instance_active())
135 if (target_index
< 0 ||
136 target_index
>= static_cast<long>(target_ids_
.size())) {
140 BrowserAccessibilityManager
* manager
= owner_
->manager();
141 BrowserAccessibility
* result
=
142 manager
->GetFromID(target_ids_
[target_index
]);
143 if (!result
|| !result
->instance_active())
146 *target
= static_cast<IAccessible
*>(
147 result
->ToBrowserAccessibilityWin()->NewReference());
151 STDMETHODIMP
BrowserAccessibilityRelation::get_targets(long max_targets
,
154 if (!targets
|| !n_targets
)
157 if (!owner_
->instance_active())
160 long count
= static_cast<long>(target_ids_
.size());
161 if (count
> max_targets
)
168 for (long i
= 0; i
< count
; ++i
) {
169 HRESULT result
= get_target(i
, &targets
[i
]);
178 // BrowserAccessibilityWin::WinAttributes
181 BrowserAccessibilityWin::WinAttributes::WinAttributes()
189 // BrowserAccessibilityWin
193 BrowserAccessibility
* BrowserAccessibility::Create() {
194 ui::win::CreateATLModuleIfNeeded();
195 CComObject
<BrowserAccessibilityWin
>* instance
;
196 HRESULT hr
= CComObject
<BrowserAccessibilityWin
>::CreateInstance(&instance
);
197 DCHECK(SUCCEEDED(hr
));
198 return instance
->NewReference();
201 BrowserAccessibilityWin
* BrowserAccessibility::ToBrowserAccessibilityWin() {
202 return static_cast<BrowserAccessibilityWin
*>(this);
205 BrowserAccessibilityWin::BrowserAccessibilityWin()
206 : win_attributes_(new WinAttributes()),
207 previous_scroll_x_(0),
208 previous_scroll_y_(0) {
209 // Start unique IDs at -1 and decrement each time, because get_accChild
210 // uses positive IDs to enumerate children, so we use negative IDs to
211 // clearly distinguish between indices and unique IDs.
212 unique_id_win_
= next_unique_id_win_
;
213 if (next_unique_id_win_
==
214 base::win::kLastBrowserAccessibilityManagerAccessibilityId
) {
215 next_unique_id_win_
=
216 base::win::kFirstBrowserAccessibilityManagerAccessibilityId
;
218 next_unique_id_win_
--;
221 BrowserAccessibilityWin::~BrowserAccessibilityWin() {
222 for (size_t i
= 0; i
< relations_
.size(); ++i
)
223 relations_
[i
]->Release();
227 // IAccessible methods.
230 // * Always test for instance_active() first and return E_FAIL if it's false.
231 // * Always check for invalid arguments first, even if they're unused.
232 // * Return S_FALSE if the only output is a string argument and it's empty.
235 HRESULT
BrowserAccessibilityWin::accDoDefaultAction(VARIANT var_id
) {
236 if (!instance_active())
239 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
243 manager()->DoDefaultAction(*target
);
247 STDMETHODIMP
BrowserAccessibilityWin::accHitTest(LONG x_left
,
250 if (!instance_active())
256 gfx::Point
point(x_left
, y_top
);
257 if (!GetGlobalBoundsRect().Contains(point
)) {
258 // Return S_FALSE and VT_EMPTY when the outside the object's boundaries.
259 child
->vt
= VT_EMPTY
;
263 BrowserAccessibility
* result
= BrowserAccessibilityForPoint(point
);
264 if (result
== this) {
265 // Point is within this object.
267 child
->lVal
= CHILDID_SELF
;
269 child
->vt
= VT_DISPATCH
;
270 child
->pdispVal
= result
->ToBrowserAccessibilityWin()->NewReference();
275 STDMETHODIMP
BrowserAccessibilityWin::accLocation(LONG
* x_left
,
280 if (!instance_active())
283 if (!x_left
|| !y_top
|| !width
|| !height
)
286 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
290 gfx::Rect bounds
= target
->GetGlobalBoundsRect();
291 *x_left
= bounds
.x();
293 *width
= bounds
.width();
294 *height
= bounds
.height();
299 STDMETHODIMP
BrowserAccessibilityWin::accNavigate(LONG nav_dir
,
302 BrowserAccessibilityWin
* target
= GetTargetFromChildID(start
);
306 if ((nav_dir
== NAVDIR_LASTCHILD
|| nav_dir
== NAVDIR_FIRSTCHILD
) &&
307 start
.lVal
!= CHILDID_SELF
) {
308 // MSAA states that navigating to first/last child can only be from self.
312 uint32 child_count
= target
->PlatformChildCount();
314 BrowserAccessibility
* result
= NULL
;
320 // These directions are not implemented, matching Mozilla and IE.
322 case NAVDIR_FIRSTCHILD
:
324 result
= target
->PlatformGetChild(0);
326 case NAVDIR_LASTCHILD
:
328 result
= target
->PlatformGetChild(child_count
- 1);
331 result
= target
->GetNextSibling();
333 case NAVDIR_PREVIOUS
:
334 result
= target
->GetPreviousSibling();
343 end
->vt
= VT_DISPATCH
;
344 end
->pdispVal
= result
->ToBrowserAccessibilityWin()->NewReference();
348 STDMETHODIMP
BrowserAccessibilityWin::get_accChild(VARIANT var_child
,
349 IDispatch
** disp_child
) {
350 if (!instance_active())
358 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_child
);
362 (*disp_child
) = target
->NewReference();
366 STDMETHODIMP
BrowserAccessibilityWin::get_accChildCount(LONG
* child_count
) {
367 if (!instance_active())
373 *child_count
= PlatformChildCount();
378 STDMETHODIMP
BrowserAccessibilityWin::get_accDefaultAction(VARIANT var_id
,
380 if (!instance_active())
386 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
390 return target
->GetStringAttributeAsBstr(
391 ui::AX_ATTR_ACTION
, def_action
);
394 STDMETHODIMP
BrowserAccessibilityWin::get_accDescription(VARIANT var_id
,
396 if (!instance_active())
402 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
406 base::string16 description_str
= target
->description();
407 if (description_str
.empty())
410 *desc
= SysAllocString(description_str
.c_str());
416 STDMETHODIMP
BrowserAccessibilityWin::get_accFocus(VARIANT
* focus_child
) {
417 if (!instance_active())
423 BrowserAccessibilityWin
* focus
= static_cast<BrowserAccessibilityWin
*>(
424 manager()->GetFocus(this));
426 focus_child
->vt
= VT_I4
;
427 focus_child
->lVal
= CHILDID_SELF
;
428 } else if (focus
== NULL
) {
429 focus_child
->vt
= VT_EMPTY
;
431 focus_child
->vt
= VT_DISPATCH
;
432 focus_child
->pdispVal
= focus
->NewReference();
438 STDMETHODIMP
BrowserAccessibilityWin::get_accHelp(VARIANT var_id
, BSTR
* help
) {
439 if (!instance_active())
445 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
449 base::string16 help_str
= target
->help();
450 if (help_str
.empty())
453 *help
= SysAllocString(help_str
.c_str());
459 STDMETHODIMP
BrowserAccessibilityWin::get_accKeyboardShortcut(VARIANT var_id
,
461 if (!instance_active())
467 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
471 return target
->GetStringAttributeAsBstr(
472 ui::AX_ATTR_SHORTCUT
, acc_key
);
475 STDMETHODIMP
BrowserAccessibilityWin::get_accName(VARIANT var_id
, BSTR
* name
) {
476 if (!instance_active())
482 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
486 base::string16 name_str
= target
->name();
488 // If the name is empty, see if it's labeled by another element.
489 if (name_str
.empty()) {
491 if (target
->GetIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT
,
493 BrowserAccessibilityWin
* title_elem
=
494 manager()->GetFromID(title_elem_id
)->ToBrowserAccessibilityWin();
496 name_str
= title_elem
->GetNameRecursive();
500 if (name_str
.empty())
503 *name
= SysAllocString(name_str
.c_str());
509 STDMETHODIMP
BrowserAccessibilityWin::get_accParent(IDispatch
** disp_parent
) {
510 if (!instance_active())
516 IAccessible
* parent_obj
= GetParent()->ToBrowserAccessibilityWin();
517 if (parent_obj
== NULL
) {
518 // This happens if we're the root of the tree;
519 // return the IAccessible for the window.
521 manager()->ToBrowserAccessibilityManagerWin()->GetParentIAccessible();
522 // |parent| can only be NULL if the manager was created before the parent
523 // IAccessible was known and it wasn't subsequently set before a client
524 // requested it. This has been fixed. |parent| may also be NULL during
525 // destruction. Possible cases where this could occur include tabs being
526 // dragged to a new window, etc.
528 DVLOG(1) << "In Function: "
530 << ". Parent IAccessible interface is NULL. Returning failure";
534 parent_obj
->AddRef();
535 *disp_parent
= parent_obj
;
539 STDMETHODIMP
BrowserAccessibilityWin::get_accRole(VARIANT var_id
,
541 if (!instance_active())
547 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
551 if (!target
->role_name().empty()) {
553 role
->bstrVal
= SysAllocString(target
->role_name().c_str());
556 role
->lVal
= target
->ia_role();
561 STDMETHODIMP
BrowserAccessibilityWin::get_accState(VARIANT var_id
,
563 if (!instance_active())
569 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
574 state
->lVal
= target
->ia_state();
575 if (manager()->GetFocus(NULL
) == this)
576 state
->lVal
|= STATE_SYSTEM_FOCUSED
;
581 STDMETHODIMP
BrowserAccessibilityWin::get_accValue(VARIANT var_id
,
583 if (!instance_active())
589 BrowserAccessibilityWin
* target
= GetTargetFromChildID(var_id
);
593 if (target
->ia_role() == ROLE_SYSTEM_PROGRESSBAR
||
594 target
->ia_role() == ROLE_SYSTEM_SCROLLBAR
||
595 target
->ia_role() == ROLE_SYSTEM_SLIDER
) {
596 base::string16 value_text
= target
->GetValueText();
597 *value
= SysAllocString(value_text
.c_str());
602 // Expose color well value.
603 if (target
->ia2_role() == IA2_ROLE_COLOR_CHOOSER
) {
604 int r
= target
->GetIntAttribute(
605 ui::AX_ATTR_COLOR_VALUE_RED
);
606 int g
= target
->GetIntAttribute(
607 ui::AX_ATTR_COLOR_VALUE_GREEN
);
608 int b
= target
->GetIntAttribute(
609 ui::AX_ATTR_COLOR_VALUE_BLUE
);
610 base::string16 value_text
;
611 value_text
= base::IntToString16((r
* 100) / 255) + L
"% red " +
612 base::IntToString16((g
* 100) / 255) + L
"% green " +
613 base::IntToString16((b
* 100) / 255) + L
"% blue";
614 *value
= SysAllocString(value_text
.c_str());
619 *value
= SysAllocString(target
->value().c_str());
624 STDMETHODIMP
BrowserAccessibilityWin::get_accHelpTopic(BSTR
* help_file
,
630 STDMETHODIMP
BrowserAccessibilityWin::get_accSelection(VARIANT
* selected
) {
631 if (!instance_active())
634 if (GetRole() != ui::AX_ROLE_LIST_BOX
)
637 unsigned long selected_count
= 0;
638 for (size_t i
= 0; i
< InternalChildCount(); ++i
) {
639 if (InternalGetChild(i
)->HasState(ui::AX_STATE_SELECTED
))
643 if (selected_count
== 0) {
644 selected
->vt
= VT_EMPTY
;
648 if (selected_count
== 1) {
649 for (size_t i
= 0; i
< InternalChildCount(); ++i
) {
650 if (InternalGetChild(i
)->HasState(ui::AX_STATE_SELECTED
)) {
651 selected
->vt
= VT_DISPATCH
;
653 InternalGetChild(i
)->ToBrowserAccessibilityWin()->NewReference();
659 // Multiple items are selected.
660 base::win::EnumVariant
* enum_variant
=
661 new base::win::EnumVariant(selected_count
);
662 enum_variant
->AddRef();
663 unsigned long index
= 0;
664 for (size_t i
= 0; i
< InternalChildCount(); ++i
) {
665 if (InternalGetChild(i
)->HasState(ui::AX_STATE_SELECTED
)) {
666 enum_variant
->ItemAt(index
)->vt
= VT_DISPATCH
;
667 enum_variant
->ItemAt(index
)->pdispVal
=
668 InternalGetChild(i
)->ToBrowserAccessibilityWin()->NewReference();
672 selected
->vt
= VT_UNKNOWN
;
673 selected
->punkVal
= static_cast<IUnknown
*>(
674 static_cast<base::win::IUnknownImpl
*>(enum_variant
));
678 STDMETHODIMP
BrowserAccessibilityWin::accSelect(
679 LONG flags_sel
, VARIANT var_id
) {
680 if (!instance_active())
683 if (flags_sel
& SELFLAG_TAKEFOCUS
) {
684 manager()->SetFocus(this, true);
692 // IAccessible2 methods.
695 STDMETHODIMP
BrowserAccessibilityWin::role(LONG
* role
) {
696 if (!instance_active())
707 STDMETHODIMP
BrowserAccessibilityWin::get_attributes(BSTR
* attributes
) {
708 if (!instance_active())
714 // The iaccessible2 attributes are a set of key-value pairs
715 // separated by semicolons, with a colon between the key and the value.
717 const std::vector
<base::string16
>& attributes_list
= ia2_attributes();
718 for (unsigned int i
= 0; i
< attributes_list
.size(); ++i
) {
719 str
+= attributes_list
[i
] + L
';';
725 *attributes
= SysAllocString(str
.c_str());
730 STDMETHODIMP
BrowserAccessibilityWin::get_states(AccessibleStates
* states
) {
731 if (!instance_active())
737 *states
= ia2_state();
742 STDMETHODIMP
BrowserAccessibilityWin::get_uniqueID(LONG
* unique_id
) {
743 if (!instance_active())
749 *unique_id
= unique_id_win_
;
753 STDMETHODIMP
BrowserAccessibilityWin::get_windowHandle(HWND
* window_handle
) {
754 if (!instance_active())
761 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND();
768 STDMETHODIMP
BrowserAccessibilityWin::get_indexInParent(LONG
* index_in_parent
) {
769 if (!instance_active())
772 if (!index_in_parent
)
775 *index_in_parent
= this->GetIndexInParent();
779 STDMETHODIMP
BrowserAccessibilityWin::get_nRelations(LONG
* n_relations
) {
780 if (!instance_active())
786 *n_relations
= relations_
.size();
790 STDMETHODIMP
BrowserAccessibilityWin::get_relation(
792 IAccessibleRelation
** relation
) {
793 if (!instance_active())
796 if (relation_index
< 0 ||
797 relation_index
>= static_cast<long>(relations_
.size())) {
804 relations_
[relation_index
]->AddRef();
805 *relation
= relations_
[relation_index
];
809 STDMETHODIMP
BrowserAccessibilityWin::get_relations(
811 IAccessibleRelation
** relations
,
813 if (!instance_active())
816 if (!relations
|| !n_relations
)
819 long count
= static_cast<long>(relations_
.size());
820 *n_relations
= count
;
824 for (long i
= 0; i
< count
; ++i
) {
825 relations_
[i
]->AddRef();
826 relations
[i
] = relations_
[i
];
832 STDMETHODIMP
BrowserAccessibilityWin::scrollTo(enum IA2ScrollType scroll_type
) {
833 if (!instance_active())
836 gfx::Rect r
= GetLocation();
837 switch(scroll_type
) {
838 case IA2_SCROLL_TYPE_TOP_LEFT
:
839 manager()->ScrollToMakeVisible(*this, gfx::Rect(r
.x(), r
.y(), 0, 0));
841 case IA2_SCROLL_TYPE_BOTTOM_RIGHT
:
842 manager()->ScrollToMakeVisible(
843 *this, gfx::Rect(r
.right(), r
.bottom(), 0, 0));
845 case IA2_SCROLL_TYPE_TOP_EDGE
:
846 manager()->ScrollToMakeVisible(
847 *this, gfx::Rect(r
.x(), r
.y(), r
.width(), 0));
849 case IA2_SCROLL_TYPE_BOTTOM_EDGE
:
850 manager()->ScrollToMakeVisible(
851 *this, gfx::Rect(r
.x(), r
.bottom(), r
.width(), 0));
853 case IA2_SCROLL_TYPE_LEFT_EDGE
:
854 manager()->ScrollToMakeVisible(
855 *this, gfx::Rect(r
.x(), r
.y(), 0, r
.height()));
857 case IA2_SCROLL_TYPE_RIGHT_EDGE
:
858 manager()->ScrollToMakeVisible(
859 *this, gfx::Rect(r
.right(), r
.y(), 0, r
.height()));
861 case IA2_SCROLL_TYPE_ANYWHERE
:
863 manager()->ScrollToMakeVisible(*this, r
);
867 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
872 STDMETHODIMP
BrowserAccessibilityWin::scrollToPoint(
873 enum IA2CoordinateType coordinate_type
,
876 if (!instance_active())
879 gfx::Point
scroll_to(x
, y
);
881 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
882 scroll_to
-= manager()->GetViewBounds().OffsetFromOrigin();
883 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
885 scroll_to
+= GetParent()->GetLocation().OffsetFromOrigin();
890 manager()->ScrollToPoint(*this, scroll_to
);
891 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
896 STDMETHODIMP
BrowserAccessibilityWin::get_groupPosition(
898 LONG
* similar_items_in_group
,
899 LONG
* position_in_group
) {
900 if (!instance_active())
903 if (!group_level
|| !similar_items_in_group
|| !position_in_group
)
907 *similar_items_in_group
= GetIntAttribute(ui::AX_ATTR_SET_SIZE
);
908 *position_in_group
= GetIntAttribute(ui::AX_ATTR_POS_IN_SET
);
913 // IAccessibleApplication methods.
916 STDMETHODIMP
BrowserAccessibilityWin::get_appName(BSTR
* app_name
) {
917 // No need to check |instance_active()| because this interface is
918 // global, and doesn't depend on any local state.
923 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
924 // the part before the "/".
925 std::vector
<std::string
> product_components
;
926 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components
);
927 DCHECK_EQ(2U, product_components
.size());
928 if (product_components
.size() != 2)
930 *app_name
= SysAllocString(base::UTF8ToUTF16(product_components
[0]).c_str());
932 return *app_name
? S_OK
: E_FAIL
;
935 STDMETHODIMP
BrowserAccessibilityWin::get_appVersion(BSTR
* app_version
) {
936 // No need to check |instance_active()| because this interface is
937 // global, and doesn't depend on any local state.
942 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
943 // the part after the "/".
944 std::vector
<std::string
> product_components
;
945 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components
);
946 DCHECK_EQ(2U, product_components
.size());
947 if (product_components
.size() != 2)
950 SysAllocString(base::UTF8ToUTF16(product_components
[1]).c_str());
951 DCHECK(*app_version
);
952 return *app_version
? S_OK
: E_FAIL
;
955 STDMETHODIMP
BrowserAccessibilityWin::get_toolkitName(BSTR
* toolkit_name
) {
956 // No need to check |instance_active()| because this interface is
957 // global, and doesn't depend on any local state.
962 // This is hard-coded; all products based on the Chromium engine
963 // will have the same toolkit name, so that assistive technology can
964 // detect any Chrome-based product.
965 *toolkit_name
= SysAllocString(L
"Chrome");
966 DCHECK(*toolkit_name
);
967 return *toolkit_name
? S_OK
: E_FAIL
;
970 STDMETHODIMP
BrowserAccessibilityWin::get_toolkitVersion(
971 BSTR
* toolkit_version
) {
972 // No need to check |instance_active()| because this interface is
973 // global, and doesn't depend on any local state.
975 if (!toolkit_version
)
978 std::string user_agent
= GetContentClient()->GetUserAgent();
979 *toolkit_version
= SysAllocString(base::UTF8ToUTF16(user_agent
).c_str());
980 DCHECK(*toolkit_version
);
981 return *toolkit_version
? S_OK
: E_FAIL
;
985 // IAccessibleImage methods.
988 STDMETHODIMP
BrowserAccessibilityWin::get_description(BSTR
* desc
) {
989 if (!instance_active())
995 if (description().empty())
998 *desc
= SysAllocString(description().c_str());
1004 STDMETHODIMP
BrowserAccessibilityWin::get_imagePosition(
1005 enum IA2CoordinateType coordinate_type
,
1008 if (!instance_active())
1012 return E_INVALIDARG
;
1014 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
1016 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND();
1019 POINT top_left
= {0, 0};
1020 ::ClientToScreen(parent_hwnd
, &top_left
);
1021 *x
= GetLocation().x() + top_left
.x
;
1022 *y
= GetLocation().y() + top_left
.y
;
1023 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
1024 *x
= GetLocation().x();
1025 *y
= GetLocation().y();
1027 *x
-= GetParent()->GetLocation().x();
1028 *y
-= GetParent()->GetLocation().y();
1031 return E_INVALIDARG
;
1037 STDMETHODIMP
BrowserAccessibilityWin::get_imageSize(LONG
* height
, LONG
* width
) {
1038 if (!instance_active())
1041 if (!height
|| !width
)
1042 return E_INVALIDARG
;
1044 *height
= GetLocation().height();
1045 *width
= GetLocation().width();
1050 // IAccessibleTable methods.
1053 STDMETHODIMP
BrowserAccessibilityWin::get_accessibleAt(
1056 IUnknown
** accessible
) {
1057 if (!instance_active())
1061 return E_INVALIDARG
;
1065 if (!GetIntAttribute(
1066 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1068 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1074 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1075 return E_INVALIDARG
;
1077 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1078 ui::AX_ATTR_CELL_IDS
);
1079 DCHECK_EQ(columns
* rows
, static_cast<int>(cell_ids
.size()));
1081 int cell_id
= cell_ids
[row
* columns
+ column
];
1082 BrowserAccessibilityWin
* cell
= GetFromID(cell_id
);
1084 *accessible
= static_cast<IAccessible
*>(cell
->NewReference());
1089 return E_INVALIDARG
;
1092 STDMETHODIMP
BrowserAccessibilityWin::get_caption(IUnknown
** accessible
) {
1093 if (!instance_active())
1097 return E_INVALIDARG
;
1099 // TODO(dmazzoni): implement
1103 STDMETHODIMP
BrowserAccessibilityWin::get_childIndex(long row
,
1106 if (!instance_active())
1110 return E_INVALIDARG
;
1114 if (!GetIntAttribute(
1115 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1117 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1123 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1124 return E_INVALIDARG
;
1126 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1127 ui::AX_ATTR_CELL_IDS
);
1128 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1129 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1130 DCHECK_EQ(columns
* rows
, static_cast<int>(cell_ids
.size()));
1131 int cell_id
= cell_ids
[row
* columns
+ column
];
1132 for (size_t i
= 0; i
< unique_cell_ids
.size(); ++i
) {
1133 if (unique_cell_ids
[i
] == cell_id
) {
1134 *cell_index
= (long)i
;
1142 STDMETHODIMP
BrowserAccessibilityWin::get_columnDescription(long column
,
1143 BSTR
* description
) {
1144 if (!instance_active())
1148 return E_INVALIDARG
;
1152 if (!GetIntAttribute(
1153 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1154 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1160 if (column
< 0 || column
>= columns
)
1161 return E_INVALIDARG
;
1163 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1164 ui::AX_ATTR_CELL_IDS
);
1165 for (int i
= 0; i
< rows
; ++i
) {
1166 int cell_id
= cell_ids
[i
* columns
+ column
];
1167 BrowserAccessibilityWin
* cell
= static_cast<BrowserAccessibilityWin
*>(
1168 manager()->GetFromID(cell_id
));
1169 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
) {
1170 base::string16 cell_name
= cell
->GetString16Attribute(
1172 if (cell_name
.size() > 0) {
1173 *description
= SysAllocString(cell_name
.c_str());
1177 if (cell
->description().size() > 0) {
1178 *description
= SysAllocString(cell
->description().c_str());
1187 STDMETHODIMP
BrowserAccessibilityWin::get_columnExtentAt(
1190 long* n_columns_spanned
) {
1191 if (!instance_active())
1194 if (!n_columns_spanned
)
1195 return E_INVALIDARG
;
1199 if (!GetIntAttribute(
1200 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1201 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1207 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1208 return E_INVALIDARG
;
1210 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1211 ui::AX_ATTR_CELL_IDS
);
1212 int cell_id
= cell_ids
[row
* columns
+ column
];
1213 BrowserAccessibilityWin
* cell
= static_cast<BrowserAccessibilityWin
*>(
1214 manager()->GetFromID(cell_id
));
1217 cell
->GetIntAttribute(
1218 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1220 *n_columns_spanned
= colspan
;
1227 STDMETHODIMP
BrowserAccessibilityWin::get_columnHeader(
1228 IAccessibleTable
** accessible_table
,
1229 long* starting_row_index
) {
1230 // TODO(dmazzoni): implement
1234 STDMETHODIMP
BrowserAccessibilityWin::get_columnIndex(long cell_index
,
1235 long* column_index
) {
1236 if (!instance_active())
1240 return E_INVALIDARG
;
1242 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1243 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1244 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1246 return E_INVALIDARG
;
1247 if (cell_index
>= cell_id_count
)
1250 int cell_id
= unique_cell_ids
[cell_index
];
1251 BrowserAccessibilityWin
* cell
=
1252 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1255 cell
->GetIntAttribute(
1256 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &col_index
)) {
1257 *column_index
= col_index
;
1264 STDMETHODIMP
BrowserAccessibilityWin::get_nColumns(long* column_count
) {
1265 if (!instance_active())
1269 return E_INVALIDARG
;
1272 if (GetIntAttribute(
1273 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
)) {
1274 *column_count
= columns
;
1281 STDMETHODIMP
BrowserAccessibilityWin::get_nRows(long* row_count
) {
1282 if (!instance_active())
1286 return E_INVALIDARG
;
1289 if (GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1297 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedChildren(long* cell_count
) {
1298 if (!instance_active())
1302 return E_INVALIDARG
;
1304 // TODO(dmazzoni): add support for selected cells/rows/columns in tables.
1309 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedColumns(long* column_count
) {
1310 if (!instance_active())
1314 return E_INVALIDARG
;
1320 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedRows(long* row_count
) {
1321 if (!instance_active())
1325 return E_INVALIDARG
;
1331 STDMETHODIMP
BrowserAccessibilityWin::get_rowDescription(long row
,
1332 BSTR
* description
) {
1333 if (!instance_active())
1337 return E_INVALIDARG
;
1341 if (!GetIntAttribute(
1342 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1343 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1349 if (row
< 0 || row
>= rows
)
1350 return E_INVALIDARG
;
1352 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1353 ui::AX_ATTR_CELL_IDS
);
1354 for (int i
= 0; i
< columns
; ++i
) {
1355 int cell_id
= cell_ids
[row
* columns
+ i
];
1356 BrowserAccessibilityWin
* cell
=
1357 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1358 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
) {
1359 base::string16 cell_name
= cell
->GetString16Attribute(
1361 if (cell_name
.size() > 0) {
1362 *description
= SysAllocString(cell_name
.c_str());
1366 if (cell
->description().size() > 0) {
1367 *description
= SysAllocString(cell
->description().c_str());
1376 STDMETHODIMP
BrowserAccessibilityWin::get_rowExtentAt(long row
,
1378 long* n_rows_spanned
) {
1379 if (!instance_active())
1382 if (!n_rows_spanned
)
1383 return E_INVALIDARG
;
1387 if (!GetIntAttribute(
1388 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1389 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1395 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1396 return E_INVALIDARG
;
1398 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1399 ui::AX_ATTR_CELL_IDS
);
1400 int cell_id
= cell_ids
[row
* columns
+ column
];
1401 BrowserAccessibilityWin
* cell
=
1402 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1405 cell
->GetIntAttribute(
1406 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1408 *n_rows_spanned
= rowspan
;
1415 STDMETHODIMP
BrowserAccessibilityWin::get_rowHeader(
1416 IAccessibleTable
** accessible_table
,
1417 long* starting_column_index
) {
1418 // TODO(dmazzoni): implement
1422 STDMETHODIMP
BrowserAccessibilityWin::get_rowIndex(long cell_index
,
1424 if (!instance_active())
1428 return E_INVALIDARG
;
1430 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1431 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1432 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1434 return E_INVALIDARG
;
1435 if (cell_index
>= cell_id_count
)
1438 int cell_id
= unique_cell_ids
[cell_index
];
1439 BrowserAccessibilityWin
* cell
=
1440 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1443 cell
->GetIntAttribute(
1444 ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &cell_row_index
)) {
1445 *row_index
= cell_row_index
;
1452 STDMETHODIMP
BrowserAccessibilityWin::get_selectedChildren(long max_children
,
1455 if (!instance_active())
1458 if (!children
|| !n_children
)
1459 return E_INVALIDARG
;
1461 // TODO(dmazzoni): Implement this.
1466 STDMETHODIMP
BrowserAccessibilityWin::get_selectedColumns(long max_columns
,
1469 if (!instance_active())
1472 if (!columns
|| !n_columns
)
1473 return E_INVALIDARG
;
1475 // TODO(dmazzoni): Implement this.
1480 STDMETHODIMP
BrowserAccessibilityWin::get_selectedRows(long max_rows
,
1483 if (!instance_active())
1486 if (!rows
|| !n_rows
)
1487 return E_INVALIDARG
;
1489 // TODO(dmazzoni): Implement this.
1494 STDMETHODIMP
BrowserAccessibilityWin::get_summary(IUnknown
** accessible
) {
1495 if (!instance_active())
1499 return E_INVALIDARG
;
1501 // TODO(dmazzoni): implement
1505 STDMETHODIMP
BrowserAccessibilityWin::get_isColumnSelected(
1507 boolean
* is_selected
) {
1508 if (!instance_active())
1512 return E_INVALIDARG
;
1514 // TODO(dmazzoni): Implement this.
1515 *is_selected
= false;
1519 STDMETHODIMP
BrowserAccessibilityWin::get_isRowSelected(long row
,
1520 boolean
* is_selected
) {
1521 if (!instance_active())
1525 return E_INVALIDARG
;
1527 // TODO(dmazzoni): Implement this.
1528 *is_selected
= false;
1532 STDMETHODIMP
BrowserAccessibilityWin::get_isSelected(long row
,
1534 boolean
* is_selected
) {
1535 if (!instance_active())
1539 return E_INVALIDARG
;
1541 // TODO(dmazzoni): Implement this.
1542 *is_selected
= false;
1546 STDMETHODIMP
BrowserAccessibilityWin::get_rowColumnExtentsAtIndex(
1551 long* column_extents
,
1552 boolean
* is_selected
) {
1553 if (!instance_active())
1556 if (!row
|| !column
|| !row_extents
|| !column_extents
|| !is_selected
)
1557 return E_INVALIDARG
;
1559 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1560 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1561 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1563 return E_INVALIDARG
;
1564 if (index
>= cell_id_count
)
1567 int cell_id
= unique_cell_ids
[index
];
1568 BrowserAccessibilityWin
* cell
=
1569 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1573 cell
->GetIntAttribute(
1574 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1575 cell
->GetIntAttribute(
1576 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1579 *row_extents
= rowspan
;
1580 *column_extents
= colspan
;
1588 // IAccessibleTable2 methods.
1591 STDMETHODIMP
BrowserAccessibilityWin::get_cellAt(long row
,
1594 return get_accessibleAt(row
, column
, cell
);
1597 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedCells(long* cell_count
) {
1598 return get_nSelectedChildren(cell_count
);
1601 STDMETHODIMP
BrowserAccessibilityWin::get_selectedCells(
1603 long* n_selected_cells
) {
1604 if (!instance_active())
1607 if (!cells
|| !n_selected_cells
)
1608 return E_INVALIDARG
;
1610 // TODO(dmazzoni): Implement this.
1611 *n_selected_cells
= 0;
1615 STDMETHODIMP
BrowserAccessibilityWin::get_selectedColumns(long** columns
,
1617 if (!instance_active())
1620 if (!columns
|| !n_columns
)
1621 return E_INVALIDARG
;
1623 // TODO(dmazzoni): Implement this.
1628 STDMETHODIMP
BrowserAccessibilityWin::get_selectedRows(long** rows
,
1630 if (!instance_active())
1633 if (!rows
|| !n_rows
)
1634 return E_INVALIDARG
;
1636 // TODO(dmazzoni): Implement this.
1643 // IAccessibleTableCell methods.
1646 STDMETHODIMP
BrowserAccessibilityWin::get_columnExtent(
1647 long* n_columns_spanned
) {
1648 if (!instance_active())
1651 if (!n_columns_spanned
)
1652 return E_INVALIDARG
;
1655 if (GetIntAttribute(
1656 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1658 *n_columns_spanned
= colspan
;
1665 STDMETHODIMP
BrowserAccessibilityWin::get_columnHeaderCells(
1666 IUnknown
*** cell_accessibles
,
1667 long* n_column_header_cells
) {
1668 if (!instance_active())
1671 if (!cell_accessibles
|| !n_column_header_cells
)
1672 return E_INVALIDARG
;
1674 *n_column_header_cells
= 0;
1677 if (!GetIntAttribute(
1678 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
)) {
1682 BrowserAccessibility
* table
= GetParent();
1683 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
1684 table
= table
->GetParent();
1692 if (!table
->GetIntAttribute(
1693 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1694 !table
->GetIntAttribute(
1695 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1698 if (columns
<= 0 || rows
<= 0 || column
< 0 || column
>= columns
)
1701 const std::vector
<int32
>& cell_ids
= table
->GetIntListAttribute(
1702 ui::AX_ATTR_CELL_IDS
);
1704 for (int i
= 0; i
< rows
; ++i
) {
1705 int cell_id
= cell_ids
[i
* columns
+ column
];
1706 BrowserAccessibilityWin
* cell
=
1707 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1708 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
)
1709 (*n_column_header_cells
)++;
1712 *cell_accessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(
1713 (*n_column_header_cells
) * sizeof(cell_accessibles
[0])));
1715 for (int i
= 0; i
< rows
; ++i
) {
1716 int cell_id
= cell_ids
[i
* columns
+ column
];
1717 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1718 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
) {
1719 (*cell_accessibles
)[index
] = static_cast<IAccessible
*>(
1720 cell
->ToBrowserAccessibilityWin()->NewReference());
1728 STDMETHODIMP
BrowserAccessibilityWin::get_columnIndex(long* column_index
) {
1729 if (!instance_active())
1733 return E_INVALIDARG
;
1736 if (GetIntAttribute(
1737 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
)) {
1738 *column_index
= column
;
1745 STDMETHODIMP
BrowserAccessibilityWin::get_rowExtent(long* n_rows_spanned
) {
1746 if (!instance_active())
1749 if (!n_rows_spanned
)
1750 return E_INVALIDARG
;
1753 if (GetIntAttribute(
1754 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1756 *n_rows_spanned
= rowspan
;
1763 STDMETHODIMP
BrowserAccessibilityWin::get_rowHeaderCells(
1764 IUnknown
*** cell_accessibles
,
1765 long* n_row_header_cells
) {
1766 if (!instance_active())
1769 if (!cell_accessibles
|| !n_row_header_cells
)
1770 return E_INVALIDARG
;
1772 *n_row_header_cells
= 0;
1775 if (!GetIntAttribute(
1776 ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
)) {
1780 BrowserAccessibility
* table
= GetParent();
1781 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
1782 table
= table
->GetParent();
1790 if (!table
->GetIntAttribute(
1791 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1792 !table
->GetIntAttribute(
1793 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1796 if (columns
<= 0 || rows
<= 0 || row
< 0 || row
>= rows
)
1799 const std::vector
<int32
>& cell_ids
= table
->GetIntListAttribute(
1800 ui::AX_ATTR_CELL_IDS
);
1802 for (int i
= 0; i
< columns
; ++i
) {
1803 int cell_id
= cell_ids
[row
* columns
+ i
];
1804 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1805 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
)
1806 (*n_row_header_cells
)++;
1809 *cell_accessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(
1810 (*n_row_header_cells
) * sizeof(cell_accessibles
[0])));
1812 for (int i
= 0; i
< columns
; ++i
) {
1813 int cell_id
= cell_ids
[row
* columns
+ i
];
1814 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1815 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
) {
1816 (*cell_accessibles
)[index
] = static_cast<IAccessible
*>(
1817 cell
->ToBrowserAccessibilityWin()->NewReference());
1825 STDMETHODIMP
BrowserAccessibilityWin::get_rowIndex(long* row_index
) {
1826 if (!instance_active())
1830 return E_INVALIDARG
;
1833 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
)) {
1840 STDMETHODIMP
BrowserAccessibilityWin::get_isSelected(boolean
* is_selected
) {
1841 if (!instance_active())
1845 return E_INVALIDARG
;
1847 *is_selected
= false;
1851 STDMETHODIMP
BrowserAccessibilityWin::get_rowColumnExtents(
1855 long* column_extents
,
1856 boolean
* is_selected
) {
1857 if (!instance_active())
1865 return E_INVALIDARG
;
1872 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
) &&
1874 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
) &&
1876 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1878 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
)) {
1880 *column_index
= column
;
1881 *row_extents
= rowspan
;
1882 *column_extents
= colspan
;
1883 *is_selected
= false;
1890 STDMETHODIMP
BrowserAccessibilityWin::get_table(IUnknown
** table
) {
1891 if (!instance_active())
1895 return E_INVALIDARG
;
1900 GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
);
1901 GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
);
1903 BrowserAccessibility
* find_table
= GetParent();
1904 while (find_table
&& find_table
->GetRole() != ui::AX_ROLE_TABLE
)
1905 find_table
= find_table
->GetParent();
1911 *table
= static_cast<IAccessibleTable
*>(
1912 find_table
->ToBrowserAccessibilityWin()->NewReference());
1918 // IAccessibleText methods.
1921 STDMETHODIMP
BrowserAccessibilityWin::get_nCharacters(LONG
* n_characters
) {
1922 if (!instance_active())
1926 return E_INVALIDARG
;
1928 *n_characters
= TextForIAccessibleText().length();
1932 STDMETHODIMP
BrowserAccessibilityWin::get_caretOffset(LONG
* offset
) {
1933 if (!instance_active())
1937 return E_INVALIDARG
;
1939 // IA2 spec says that caret offset should be -1 if the object is not focused.
1940 if (manager()->GetFocus(this) != this) {
1946 if (IsEditableText()) {
1948 if (GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START
,
1950 *offset
= sel_start
;
1956 STDMETHODIMP
BrowserAccessibilityWin::get_characterExtents(
1958 enum IA2CoordinateType coordinate_type
,
1963 if (!instance_active())
1966 if (!out_x
|| !out_y
|| !out_width
|| !out_height
)
1967 return E_INVALIDARG
;
1969 const base::string16
& text_str
= TextForIAccessibleText();
1970 HandleSpecialTextOffset(text_str
, &offset
);
1972 if (offset
< 0 || offset
> static_cast<LONG
>(text_str
.size()))
1973 return E_INVALIDARG
;
1975 gfx::Rect character_bounds
;
1976 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
1977 character_bounds
= GetGlobalBoundsForRange(offset
, 1);
1978 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
1979 character_bounds
= GetLocalBoundsForRange(offset
, 1);
1980 character_bounds
-= GetLocation().OffsetFromOrigin();
1982 return E_INVALIDARG
;
1985 *out_x
= character_bounds
.x();
1986 *out_y
= character_bounds
.y();
1987 *out_width
= character_bounds
.width();
1988 *out_height
= character_bounds
.height();
1993 STDMETHODIMP
BrowserAccessibilityWin::get_nSelections(LONG
* n_selections
) {
1994 if (!instance_active())
1998 return E_INVALIDARG
;
2001 if (IsEditableText()) {
2004 if (GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START
,
2006 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, &sel_end
) &&
2007 sel_start
!= sel_end
)
2014 STDMETHODIMP
BrowserAccessibilityWin::get_selection(LONG selection_index
,
2017 if (!instance_active())
2020 if (!start_offset
|| !end_offset
|| selection_index
!= 0)
2021 return E_INVALIDARG
;
2023 LONG n_selections
= 0;
2024 if (FAILED(get_nSelections(&n_selections
)) || n_selections
< 1)
2025 return E_INVALIDARG
;
2029 if (IsEditableText()) {
2032 if (GetIntAttribute(
2033 ui::AX_ATTR_TEXT_SEL_START
, &sel_start
) &&
2034 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, &sel_end
)) {
2035 *start_offset
= sel_start
;
2036 *end_offset
= sel_end
;
2043 STDMETHODIMP
BrowserAccessibilityWin::get_text(LONG start_offset
,
2046 if (!instance_active())
2050 return E_INVALIDARG
;
2052 const base::string16
& text_str
= TextForIAccessibleText();
2054 // Handle special text offsets.
2055 HandleSpecialTextOffset(text_str
, &start_offset
);
2056 HandleSpecialTextOffset(text_str
, &end_offset
);
2058 // The spec allows the arguments to be reversed.
2059 if (start_offset
> end_offset
) {
2060 LONG tmp
= start_offset
;
2061 start_offset
= end_offset
;
2065 // The spec does not allow the start or end offsets to be out or range;
2066 // we must return an error if so.
2067 LONG len
= text_str
.length();
2068 if (start_offset
< 0)
2069 return E_INVALIDARG
;
2070 if (end_offset
> len
)
2071 return E_INVALIDARG
;
2073 base::string16 substr
= text_str
.substr(start_offset
,
2074 end_offset
- start_offset
);
2078 *text
= SysAllocString(substr
.c_str());
2083 STDMETHODIMP
BrowserAccessibilityWin::get_textAtOffset(
2085 enum IA2TextBoundaryType boundary_type
,
2089 if (!instance_active())
2092 if (!start_offset
|| !end_offset
|| !text
)
2093 return E_INVALIDARG
;
2095 const base::string16
& text_str
= TextForIAccessibleText();
2096 HandleSpecialTextOffset(text_str
, &offset
);
2098 return E_INVALIDARG
;
2100 LONG text_len
= text_str
.length();
2101 if (offset
> text_len
)
2102 return E_INVALIDARG
;
2104 // The IAccessible2 spec says we don't have to implement the "sentence"
2105 // boundary type, we can just let the screenreader handle it.
2106 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2113 // According to the IA2 Spec, only line boundaries should succeed when
2114 // the offset is one past the end of the text.
2115 if (offset
== text_len
&& boundary_type
!= IA2_TEXT_BOUNDARY_LINE
) {
2122 *start_offset
= FindBoundary(
2123 text_str
, boundary_type
, offset
, ui::BACKWARDS_DIRECTION
);
2124 *end_offset
= FindBoundary(
2125 text_str
, boundary_type
, offset
, ui::FORWARDS_DIRECTION
);
2126 return get_text(*start_offset
, *end_offset
, text
);
2129 STDMETHODIMP
BrowserAccessibilityWin::get_textBeforeOffset(
2131 enum IA2TextBoundaryType boundary_type
,
2135 if (!instance_active())
2138 if (!start_offset
|| !end_offset
|| !text
)
2139 return E_INVALIDARG
;
2141 // The IAccessible2 spec says we don't have to implement the "sentence"
2142 // boundary type, we can just let the screenreader handle it.
2143 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2150 const base::string16
& text_str
= TextForIAccessibleText();
2152 *start_offset
= FindBoundary(
2153 text_str
, boundary_type
, offset
, ui::BACKWARDS_DIRECTION
);
2154 *end_offset
= offset
;
2155 return get_text(*start_offset
, *end_offset
, text
);
2158 STDMETHODIMP
BrowserAccessibilityWin::get_textAfterOffset(
2160 enum IA2TextBoundaryType boundary_type
,
2164 if (!instance_active())
2167 if (!start_offset
|| !end_offset
|| !text
)
2168 return E_INVALIDARG
;
2170 // The IAccessible2 spec says we don't have to implement the "sentence"
2171 // boundary type, we can just let the screenreader handle it.
2172 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2179 const base::string16
& text_str
= TextForIAccessibleText();
2181 *start_offset
= offset
;
2182 *end_offset
= FindBoundary(
2183 text_str
, boundary_type
, offset
, ui::FORWARDS_DIRECTION
);
2184 return get_text(*start_offset
, *end_offset
, text
);
2187 STDMETHODIMP
BrowserAccessibilityWin::get_newText(IA2TextSegment
* new_text
) {
2188 if (!instance_active())
2192 return E_INVALIDARG
;
2194 if (!old_win_attributes_
)
2197 int start
, old_len
, new_len
;
2198 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
2202 base::string16 substr
= hypertext().substr(start
, new_len
);
2203 new_text
->text
= SysAllocString(substr
.c_str());
2204 new_text
->start
= static_cast<long>(start
);
2205 new_text
->end
= static_cast<long>(start
+ new_len
);
2209 STDMETHODIMP
BrowserAccessibilityWin::get_oldText(IA2TextSegment
* old_text
) {
2210 if (!instance_active())
2214 return E_INVALIDARG
;
2216 if (!old_win_attributes_
)
2219 int start
, old_len
, new_len
;
2220 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
2224 base::string16 old_hypertext
= old_win_attributes_
->hypertext
;
2225 base::string16 substr
= old_hypertext
.substr(start
, old_len
);
2226 old_text
->text
= SysAllocString(substr
.c_str());
2227 old_text
->start
= static_cast<long>(start
);
2228 old_text
->end
= static_cast<long>(start
+ old_len
);
2232 STDMETHODIMP
BrowserAccessibilityWin::get_offsetAtPoint(
2235 enum IA2CoordinateType coord_type
,
2237 if (!instance_active())
2241 return E_INVALIDARG
;
2243 // TODO(dmazzoni): implement this. We're returning S_OK for now so that
2244 // screen readers still return partially accurate results rather than
2245 // completely failing.
2250 STDMETHODIMP
BrowserAccessibilityWin::scrollSubstringTo(
2253 enum IA2ScrollType scroll_type
) {
2254 // TODO(dmazzoni): adjust this for the start and end index, too.
2255 return scrollTo(scroll_type
);
2258 STDMETHODIMP
BrowserAccessibilityWin::scrollSubstringToPoint(
2261 enum IA2CoordinateType coordinate_type
,
2263 // TODO(dmazzoni): adjust this for the start and end index, too.
2264 return scrollToPoint(coordinate_type
, x
, y
);
2267 STDMETHODIMP
BrowserAccessibilityWin::addSelection(LONG start_offset
,
2269 if (!instance_active())
2272 const base::string16
& text_str
= TextForIAccessibleText();
2273 HandleSpecialTextOffset(text_str
, &start_offset
);
2274 HandleSpecialTextOffset(text_str
, &end_offset
);
2276 manager()->SetTextSelection(*this, start_offset
, end_offset
);
2280 STDMETHODIMP
BrowserAccessibilityWin::removeSelection(LONG selection_index
) {
2281 if (!instance_active())
2284 if (selection_index
!= 0)
2285 return E_INVALIDARG
;
2287 manager()->SetTextSelection(*this, 0, 0);
2291 STDMETHODIMP
BrowserAccessibilityWin::setCaretOffset(LONG offset
) {
2292 if (!instance_active())
2295 const base::string16
& text_str
= TextForIAccessibleText();
2296 HandleSpecialTextOffset(text_str
, &offset
);
2297 manager()->SetTextSelection(*this, offset
, offset
);
2301 STDMETHODIMP
BrowserAccessibilityWin::setSelection(LONG selection_index
,
2304 if (!instance_active())
2307 if (selection_index
!= 0)
2308 return E_INVALIDARG
;
2310 const base::string16
& text_str
= TextForIAccessibleText();
2311 HandleSpecialTextOffset(text_str
, &start_offset
);
2312 HandleSpecialTextOffset(text_str
, &end_offset
);
2314 manager()->SetTextSelection(*this, start_offset
, end_offset
);
2319 // IAccessibleHypertext methods.
2322 STDMETHODIMP
BrowserAccessibilityWin::get_nHyperlinks(long* hyperlink_count
) {
2323 if (!instance_active())
2326 if (!hyperlink_count
)
2327 return E_INVALIDARG
;
2329 *hyperlink_count
= hyperlink_offset_to_index().size();
2333 STDMETHODIMP
BrowserAccessibilityWin::get_hyperlink(
2335 IAccessibleHyperlink
** hyperlink
) {
2336 if (!instance_active())
2341 index
>= static_cast<long>(hyperlinks().size())) {
2342 return E_INVALIDARG
;
2345 int32 id
= hyperlinks()[index
];
2346 BrowserAccessibilityWin
* child
=
2347 manager()->GetFromID(id
)->ToBrowserAccessibilityWin();
2349 *hyperlink
= static_cast<IAccessibleHyperlink
*>(child
->NewReference());
2356 STDMETHODIMP
BrowserAccessibilityWin::get_hyperlinkIndex(
2358 long* hyperlink_index
) {
2359 if (!instance_active())
2362 if (!hyperlink_index
)
2363 return E_INVALIDARG
;
2365 *hyperlink_index
= -1;
2367 if (char_index
< 0 ||
2368 char_index
>= static_cast<long>(hypertext().size())) {
2369 return E_INVALIDARG
;
2372 std::map
<int32
, int32
>::iterator it
=
2373 hyperlink_offset_to_index().find(char_index
);
2374 if (it
== hyperlink_offset_to_index().end())
2377 *hyperlink_index
= it
->second
;
2382 // IAccessibleValue methods.
2385 STDMETHODIMP
BrowserAccessibilityWin::get_currentValue(VARIANT
* value
) {
2386 if (!instance_active())
2390 return E_INVALIDARG
;
2393 if (GetFloatAttribute(
2394 ui::AX_ATTR_VALUE_FOR_RANGE
, &float_val
)) {
2396 value
->dblVal
= float_val
;
2400 value
->vt
= VT_EMPTY
;
2404 STDMETHODIMP
BrowserAccessibilityWin::get_minimumValue(VARIANT
* value
) {
2405 if (!instance_active())
2409 return E_INVALIDARG
;
2412 if (GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
,
2415 value
->dblVal
= float_val
;
2419 value
->vt
= VT_EMPTY
;
2423 STDMETHODIMP
BrowserAccessibilityWin::get_maximumValue(VARIANT
* value
) {
2424 if (!instance_active())
2428 return E_INVALIDARG
;
2431 if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
,
2434 value
->dblVal
= float_val
;
2438 value
->vt
= VT_EMPTY
;
2442 STDMETHODIMP
BrowserAccessibilityWin::setCurrentValue(VARIANT new_value
) {
2443 // TODO(dmazzoni): Implement this.
2448 // ISimpleDOMDocument methods.
2451 STDMETHODIMP
BrowserAccessibilityWin::get_URL(BSTR
* url
) {
2452 if (!instance_active())
2456 return E_INVALIDARG
;
2458 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_URL
, url
);
2461 STDMETHODIMP
BrowserAccessibilityWin::get_title(BSTR
* title
) {
2462 if (!instance_active())
2466 return E_INVALIDARG
;
2468 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_TITLE
, title
);
2471 STDMETHODIMP
BrowserAccessibilityWin::get_mimeType(BSTR
* mime_type
) {
2472 if (!instance_active())
2476 return E_INVALIDARG
;
2478 return GetStringAttributeAsBstr(
2479 ui::AX_ATTR_DOC_MIMETYPE
, mime_type
);
2482 STDMETHODIMP
BrowserAccessibilityWin::get_docType(BSTR
* doc_type
) {
2483 if (!instance_active())
2487 return E_INVALIDARG
;
2489 return GetStringAttributeAsBstr(
2490 ui::AX_ATTR_DOC_DOCTYPE
, doc_type
);
2494 // ISimpleDOMNode methods.
2497 STDMETHODIMP
BrowserAccessibilityWin::get_nodeInfo(
2499 short* name_space_id
,
2501 unsigned int* num_children
,
2502 unsigned int* unique_id
,
2503 unsigned short* node_type
) {
2504 if (!instance_active())
2507 if (!node_name
|| !name_space_id
|| !node_value
|| !num_children
||
2508 !unique_id
|| !node_type
) {
2509 return E_INVALIDARG
;
2513 if (GetString16Attribute(ui::AX_ATTR_HTML_TAG
, &tag
))
2514 *node_name
= SysAllocString(tag
.c_str());
2519 *node_value
= SysAllocString(value().c_str());
2520 *num_children
= PlatformChildCount();
2521 *unique_id
= unique_id_win_
;
2523 if (ia_role() == ROLE_SYSTEM_DOCUMENT
) {
2524 *node_type
= NODETYPE_DOCUMENT
;
2525 } else if (ia_role() == ROLE_SYSTEM_TEXT
&&
2526 ((ia2_state() & IA2_STATE_EDITABLE
) == 0)) {
2527 *node_type
= NODETYPE_TEXT
;
2529 *node_type
= NODETYPE_ELEMENT
;
2535 STDMETHODIMP
BrowserAccessibilityWin::get_attributes(
2536 unsigned short max_attribs
,
2538 short* name_space_id
,
2539 BSTR
* attrib_values
,
2540 unsigned short* num_attribs
) {
2541 if (!instance_active())
2544 if (!attrib_names
|| !name_space_id
|| !attrib_values
|| !num_attribs
)
2545 return E_INVALIDARG
;
2547 *num_attribs
= max_attribs
;
2548 if (*num_attribs
> GetHtmlAttributes().size())
2549 *num_attribs
= GetHtmlAttributes().size();
2551 for (unsigned short i
= 0; i
< *num_attribs
; ++i
) {
2552 attrib_names
[i
] = SysAllocString(
2553 base::UTF8ToUTF16(GetHtmlAttributes()[i
].first
).c_str());
2554 name_space_id
[i
] = 0;
2555 attrib_values
[i
] = SysAllocString(
2556 base::UTF8ToUTF16(GetHtmlAttributes()[i
].second
).c_str());
2561 STDMETHODIMP
BrowserAccessibilityWin::get_attributesForNames(
2562 unsigned short num_attribs
,
2564 short* name_space_id
,
2565 BSTR
* attrib_values
) {
2566 if (!instance_active())
2569 if (!attrib_names
|| !name_space_id
|| !attrib_values
)
2570 return E_INVALIDARG
;
2572 for (unsigned short i
= 0; i
< num_attribs
; ++i
) {
2573 name_space_id
[i
] = 0;
2575 std::string name
= base::UTF16ToUTF8((LPCWSTR
)attrib_names
[i
]);
2576 for (unsigned int j
= 0; j
< GetHtmlAttributes().size(); ++j
) {
2577 if (GetHtmlAttributes()[j
].first
== name
) {
2578 attrib_values
[i
] = SysAllocString(
2579 base::UTF8ToUTF16(GetHtmlAttributes()[j
].second
).c_str());
2585 attrib_values
[i
] = NULL
;
2591 STDMETHODIMP
BrowserAccessibilityWin::get_computedStyle(
2592 unsigned short max_style_properties
,
2593 boolean use_alternate_view
,
2594 BSTR
* style_properties
,
2596 unsigned short *num_style_properties
) {
2597 if (!instance_active())
2600 if (!style_properties
|| !style_values
)
2601 return E_INVALIDARG
;
2603 // We only cache a single style property for now: DISPLAY
2605 base::string16 display
;
2606 if (max_style_properties
== 0 ||
2607 !GetString16Attribute(ui::AX_ATTR_DISPLAY
, &display
)) {
2608 *num_style_properties
= 0;
2612 *num_style_properties
= 1;
2613 style_properties
[0] = SysAllocString(L
"display");
2614 style_values
[0] = SysAllocString(display
.c_str());
2619 STDMETHODIMP
BrowserAccessibilityWin::get_computedStyleForProperties(
2620 unsigned short num_style_properties
,
2621 boolean use_alternate_view
,
2622 BSTR
* style_properties
,
2623 BSTR
* style_values
) {
2624 if (!instance_active())
2627 if (!style_properties
|| !style_values
)
2628 return E_INVALIDARG
;
2630 // We only cache a single style property for now: DISPLAY
2632 for (unsigned short i
= 0; i
< num_style_properties
; ++i
) {
2633 base::string16 name
= (LPCWSTR
)style_properties
[i
];
2634 base::StringToLowerASCII(&name
);
2635 if (name
== L
"display") {
2636 base::string16 display
= GetString16Attribute(
2637 ui::AX_ATTR_DISPLAY
);
2638 style_values
[i
] = SysAllocString(display
.c_str());
2640 style_values
[i
] = NULL
;
2647 STDMETHODIMP
BrowserAccessibilityWin::scrollTo(boolean placeTopLeft
) {
2648 return scrollTo(placeTopLeft
?
2649 IA2_SCROLL_TYPE_TOP_LEFT
: IA2_SCROLL_TYPE_ANYWHERE
);
2652 STDMETHODIMP
BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode
** node
) {
2653 if (!instance_active())
2657 return E_INVALIDARG
;
2659 *node
= GetParent()->ToBrowserAccessibilityWin()->NewReference();
2663 STDMETHODIMP
BrowserAccessibilityWin::get_firstChild(ISimpleDOMNode
** node
) {
2664 if (!instance_active())
2668 return E_INVALIDARG
;
2670 if (PlatformChildCount() == 0) {
2675 *node
= PlatformGetChild(0)->ToBrowserAccessibilityWin()->NewReference();
2679 STDMETHODIMP
BrowserAccessibilityWin::get_lastChild(ISimpleDOMNode
** node
) {
2680 if (!instance_active())
2684 return E_INVALIDARG
;
2686 if (PlatformChildCount() == 0) {
2691 *node
= PlatformGetChild(PlatformChildCount() - 1)
2692 ->ToBrowserAccessibilityWin()->NewReference();
2696 STDMETHODIMP
BrowserAccessibilityWin::get_previousSibling(
2697 ISimpleDOMNode
** node
) {
2698 if (!instance_active())
2702 return E_INVALIDARG
;
2704 if (!GetParent() || GetIndexInParent() <= 0) {
2709 *node
= GetParent()->InternalGetChild(GetIndexInParent() - 1)->
2710 ToBrowserAccessibilityWin()->NewReference();
2714 STDMETHODIMP
BrowserAccessibilityWin::get_nextSibling(ISimpleDOMNode
** node
) {
2715 if (!instance_active())
2719 return E_INVALIDARG
;
2722 GetIndexInParent() < 0 ||
2723 GetIndexInParent() >= static_cast<int>(
2724 GetParent()->InternalChildCount()) - 1) {
2729 *node
= GetParent()->InternalGetChild(GetIndexInParent() + 1)->
2730 ToBrowserAccessibilityWin()->NewReference();
2734 STDMETHODIMP
BrowserAccessibilityWin::get_childAt(
2735 unsigned int child_index
,
2736 ISimpleDOMNode
** node
) {
2737 if (!instance_active())
2741 return E_INVALIDARG
;
2743 if (child_index
>= PlatformChildCount())
2744 return E_INVALIDARG
;
2746 BrowserAccessibility
* child
= PlatformGetChild(child_index
);
2752 *node
= child
->ToBrowserAccessibilityWin()->NewReference();
2757 // ISimpleDOMText methods.
2760 STDMETHODIMP
BrowserAccessibilityWin::get_domText(BSTR
* dom_text
) {
2761 if (!instance_active())
2765 return E_INVALIDARG
;
2767 return GetStringAttributeAsBstr(
2768 ui::AX_ATTR_NAME
, dom_text
);
2771 STDMETHODIMP
BrowserAccessibilityWin::get_clippedSubstringBounds(
2772 unsigned int start_index
,
2773 unsigned int end_index
,
2778 // TODO(dmazzoni): fully support this API by intersecting the
2779 // rect with the container's rect.
2780 return get_unclippedSubstringBounds(
2781 start_index
, end_index
, out_x
, out_y
, out_width
, out_height
);
2784 STDMETHODIMP
BrowserAccessibilityWin::get_unclippedSubstringBounds(
2785 unsigned int start_index
,
2786 unsigned int end_index
,
2791 if (!instance_active())
2794 if (!out_x
|| !out_y
|| !out_width
|| !out_height
)
2795 return E_INVALIDARG
;
2797 const base::string16
& text_str
= TextForIAccessibleText();
2798 if (start_index
> text_str
.size() ||
2799 end_index
> text_str
.size() ||
2800 start_index
> end_index
) {
2801 return E_INVALIDARG
;
2804 gfx::Rect bounds
= GetGlobalBoundsForRange(
2805 start_index
, end_index
- start_index
);
2806 *out_x
= bounds
.x();
2807 *out_y
= bounds
.y();
2808 *out_width
= bounds
.width();
2809 *out_height
= bounds
.height();
2813 STDMETHODIMP
BrowserAccessibilityWin::scrollToSubstring(
2814 unsigned int start_index
,
2815 unsigned int end_index
) {
2816 if (!instance_active())
2819 const base::string16
& text_str
= TextForIAccessibleText();
2820 if (start_index
> text_str
.size() ||
2821 end_index
> text_str
.size() ||
2822 start_index
> end_index
) {
2823 return E_INVALIDARG
;
2826 manager()->ScrollToMakeVisible(*this, GetLocalBoundsForRange(
2827 start_index
, end_index
- start_index
));
2828 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
2834 // IServiceProvider methods.
2837 STDMETHODIMP
BrowserAccessibilityWin::QueryService(REFGUID guidService
,
2840 if (!instance_active())
2843 // The system uses IAccessible APIs for many purposes, but only
2844 // assistive technology like screen readers uses IAccessible2.
2845 // Enable full accessibility support when IAccessible2 APIs are queried.
2846 if (riid
== IID_IAccessible2
)
2847 BrowserAccessibilityStateImpl::GetInstance()->EnableAccessibility();
2849 if (guidService
== GUID_IAccessibleContentDocument
) {
2850 // Special Mozilla extension: return the accessible for the root document.
2851 // Screen readers use this to distinguish between a document loaded event
2852 // on the root document vs on an iframe.
2853 return manager()->GetRoot()->ToBrowserAccessibilityWin()->QueryInterface(
2854 IID_IAccessible2
, object
);
2857 if (guidService
== IID_IAccessible
||
2858 guidService
== IID_IAccessible2
||
2859 guidService
== IID_IAccessibleAction
||
2860 guidService
== IID_IAccessibleApplication
||
2861 guidService
== IID_IAccessibleHyperlink
||
2862 guidService
== IID_IAccessibleHypertext
||
2863 guidService
== IID_IAccessibleImage
||
2864 guidService
== IID_IAccessibleTable
||
2865 guidService
== IID_IAccessibleTable2
||
2866 guidService
== IID_IAccessibleTableCell
||
2867 guidService
== IID_IAccessibleText
||
2868 guidService
== IID_IAccessibleValue
||
2869 guidService
== IID_ISimpleDOMDocument
||
2870 guidService
== IID_ISimpleDOMNode
||
2871 guidService
== IID_ISimpleDOMText
||
2872 guidService
== GUID_ISimpleDOM
) {
2873 return QueryInterface(riid
, object
);
2876 // We only support the IAccessibleEx interface on Windows 8 and above. This
2877 // is needed for the on-screen Keyboard to show up in metro mode, when the
2878 // user taps an editable portion on the page.
2879 // All methods in the IAccessibleEx interface are unimplemented.
2880 if (riid
== IID_IAccessibleEx
&&
2881 base::win::GetVersion() >= base::win::VERSION_WIN8
) {
2882 return QueryInterface(riid
, object
);
2889 STDMETHODIMP
BrowserAccessibilityWin::GetPatternProvider(PATTERNID id
,
2890 IUnknown
** provider
) {
2891 DVLOG(1) << "In Function: "
2893 << " for pattern id: "
2895 if (id
== UIA_ValuePatternId
|| id
== UIA_TextPatternId
) {
2896 if (IsEditableText()) {
2897 DVLOG(1) << "Returning UIA text provider";
2898 base::win::UIATextProvider::CreateTextProvider(
2899 GetValueText(), true, provider
);
2906 STDMETHODIMP
BrowserAccessibilityWin::GetPropertyValue(PROPERTYID id
,
2908 DVLOG(1) << "In Function: "
2910 << " for property id: "
2912 V_VT(ret
) = VT_EMPTY
;
2913 if (id
== UIA_ControlTypePropertyId
) {
2914 if (IsEditableText()) {
2916 ret
->lVal
= UIA_EditControlTypeId
;
2917 DVLOG(1) << "Returning Edit control type";
2919 DVLOG(1) << "Returning empty control type";
2926 // CComObjectRootEx methods.
2930 HRESULT WINAPI
BrowserAccessibilityWin::InternalQueryInterface(
2932 const _ATL_INTMAP_ENTRY
* entries
,
2935 BrowserAccessibilityWin
* accessibility
=
2936 reinterpret_cast<BrowserAccessibilityWin
*>(this_ptr
);
2937 int32 ia_role
= accessibility
->ia_role();
2938 if (iid
== IID_IAccessibleImage
) {
2939 if (ia_role
!= ROLE_SYSTEM_GRAPHIC
) {
2941 return E_NOINTERFACE
;
2943 } else if (iid
== IID_IAccessibleTable
|| iid
== IID_IAccessibleTable2
) {
2944 if (ia_role
!= ROLE_SYSTEM_TABLE
) {
2946 return E_NOINTERFACE
;
2948 } else if (iid
== IID_IAccessibleTableCell
) {
2949 if (!accessibility
->IsCellOrTableHeaderRole()) {
2951 return E_NOINTERFACE
;
2953 } else if (iid
== IID_IAccessibleValue
) {
2954 if (ia_role
!= ROLE_SYSTEM_PROGRESSBAR
&&
2955 ia_role
!= ROLE_SYSTEM_SCROLLBAR
&&
2956 ia_role
!= ROLE_SYSTEM_SLIDER
) {
2958 return E_NOINTERFACE
;
2960 } else if (iid
== IID_ISimpleDOMDocument
) {
2961 if (ia_role
!= ROLE_SYSTEM_DOCUMENT
) {
2963 return E_NOINTERFACE
;
2967 return CComObjectRootBase::InternalQueryInterface(
2968 this_ptr
, entries
, iid
, object
);
2975 void BrowserAccessibilityWin::UpdateStep1ComputeWinAttributes() {
2976 // Swap win_attributes_ to old_win_attributes_, allowing us to see
2977 // exactly what changed and fire appropriate events. Note that
2978 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents.
2979 old_win_attributes_
.swap(win_attributes_
);
2980 win_attributes_
.reset(new WinAttributes());
2984 win_attributes_
->ia2_attributes
.clear();
2986 // Expose autocomplete attribute for combobox and textbox.
2987 StringAttributeToIA2(ui::AX_ATTR_AUTO_COMPLETE
, "autocomplete");
2989 // Expose the "display" and "tag" attributes.
2990 StringAttributeToIA2(ui::AX_ATTR_DISPLAY
, "display");
2991 StringAttributeToIA2(ui::AX_ATTR_DROPEFFECT
, "dropeffect");
2992 StringAttributeToIA2(ui::AX_ATTR_TEXT_INPUT_TYPE
, "text-input-type");
2993 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG
, "tag");
2994 StringAttributeToIA2(ui::AX_ATTR_ROLE
, "xml-roles");
2996 // Expose "level" attribute for headings, trees, etc.
2997 IntAttributeToIA2(ui::AX_ATTR_HIERARCHICAL_LEVEL
, "level");
2999 // Expose the set size and position in set.
3000 IntAttributeToIA2(ui::AX_ATTR_SET_SIZE
, "setsize");
3001 IntAttributeToIA2(ui::AX_ATTR_POS_IN_SET
, "posinset");
3003 if (ia_role() == ROLE_SYSTEM_CHECKBUTTON
||
3004 ia_role() == ROLE_SYSTEM_RADIOBUTTON
||
3005 ia2_role() == IA2_ROLE_CHECK_MENU_ITEM
||
3006 ia2_role() == IA2_ROLE_RADIO_MENU_ITEM
||
3007 ia2_role() == IA2_ROLE_TOGGLE_BUTTON
) {
3008 win_attributes_
->ia2_attributes
.push_back(L
"checkable:true");
3011 // Expose live region attributes.
3012 StringAttributeToIA2(ui::AX_ATTR_LIVE_STATUS
, "live");
3013 StringAttributeToIA2(ui::AX_ATTR_LIVE_RELEVANT
, "relevant");
3014 BoolAttributeToIA2(ui::AX_ATTR_LIVE_ATOMIC
, "atomic");
3015 BoolAttributeToIA2(ui::AX_ATTR_LIVE_BUSY
, "busy");
3017 // Expose aria-grabbed attributes.
3018 BoolAttributeToIA2(ui::AX_ATTR_GRABBED
, "grabbed");
3020 // Expose container live region attributes.
3021 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_STATUS
,
3023 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT
,
3024 "container-relevant");
3025 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC
,
3026 "container-atomic");
3027 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY
,
3030 // Expose table cell index.
3031 if (IsCellOrTableHeaderRole()) {
3032 BrowserAccessibility
* table
= GetParent();
3033 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
3034 table
= table
->GetParent();
3036 const std::vector
<int32
>& unique_cell_ids
= table
->GetIntListAttribute(
3037 ui::AX_ATTR_UNIQUE_CELL_IDS
);
3038 for (size_t i
= 0; i
< unique_cell_ids
.size(); ++i
) {
3039 if (unique_cell_ids
[i
] == GetId()) {
3040 win_attributes_
->ia2_attributes
.push_back(
3041 base::string16(L
"table-cell-index:") + base::IntToString16(i
));
3047 // Expose invalid state for form controls and elements with aria-invalid.
3049 if (GetIntAttribute(ui::AX_ATTR_INVALID_STATE
, &invalid_state
)) {
3050 // TODO(nektar): Handle the possibility of having multiple aria-invalid
3051 // attributes defined, e.g., "invalid:spelling,grammar".
3052 switch (invalid_state
) {
3053 case ui::AX_INVALID_STATE_FALSE
:
3054 win_attributes_
->ia2_attributes
.push_back(L
"invalid:false");
3056 case ui::AX_INVALID_STATE_TRUE
:
3057 win_attributes_
->ia2_attributes
.push_back(L
"invalid:true");
3059 case ui::AX_INVALID_STATE_SPELLING
:
3060 win_attributes_
->ia2_attributes
.push_back(L
"invalid:spelling");
3062 case ui::AX_INVALID_STATE_GRAMMAR
:
3063 win_attributes_
->ia2_attributes
.push_back(L
"invalid:grammar");
3065 case ui::AX_INVALID_STATE_OTHER
:
3067 base::string16 aria_invalid_value
;
3068 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE
,
3069 &aria_invalid_value
)) {
3070 win_attributes_
->ia2_attributes
.push_back(
3071 L
"invalid:" + aria_invalid_value
);
3073 // Set the attribute to L"true", since we cannot be more specific.
3074 win_attributes_
->ia2_attributes
.push_back(L
"invalid:true");
3083 // Expose row or column header sort direction.
3084 int32 sort_direction
;
3085 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER
||
3086 ia_role() == ROLE_SYSTEM_ROWHEADER
) &&
3087 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION
, &sort_direction
)) {
3088 switch (sort_direction
) {
3089 case ui::AX_SORT_DIRECTION_UNSORTED
:
3090 win_attributes_
->ia2_attributes
.push_back(L
"sort:none");
3092 case ui::AX_SORT_DIRECTION_ASCENDING
:
3093 win_attributes_
->ia2_attributes
.push_back(L
"sort:ascending");
3095 case ui::AX_SORT_DIRECTION_DESCENDING
:
3096 win_attributes_
->ia2_attributes
.push_back(L
"sort:descending");
3098 case ui::AX_SORT_DIRECTION_OTHER
:
3099 win_attributes_
->ia2_attributes
.push_back(L
"sort:other");
3106 // The calculation of the accessible name of an element has been
3107 // standardized in the HTML to Platform Accessibility APIs Implementation
3108 // Guide (http://www.w3.org/TR/html-aapi/). In order to return the
3109 // appropriate accessible name on Windows, we need to apply some logic
3110 // to the fields we get from WebKit.
3112 // TODO(dmazzoni): move most of this logic into WebKit.
3116 // name: the default name, e.g. inner text
3117 // title ui element: a reference to a <label> element on the same
3118 // page that labels this node.
3119 // description: accessible labels that override the default name:
3120 // aria-label or aria-labelledby or aria-describedby
3121 // help: the value of the "title" attribute
3123 // On Windows, the logic we apply lets some fields take precedence and
3124 // always returns the primary name in "name" and the secondary name,
3125 // if any, in "description".
3127 int title_elem_id
= GetIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT
);
3128 base::string16 name
= GetString16Attribute(ui::AX_ATTR_NAME
);
3129 base::string16 description
= GetString16Attribute(ui::AX_ATTR_DESCRIPTION
);
3130 base::string16 help
= GetString16Attribute(ui::AX_ATTR_HELP
);
3131 base::string16 value
= GetString16Attribute(ui::AX_ATTR_VALUE
);
3133 // WebKit annoyingly puts the title in the description if there's no other
3134 // description, which just confuses the rest of the logic. Put it back.
3135 // Now "help" is always the value of the "title" attribute, if present.
3136 base::string16 title_attr
;
3137 if (GetHtmlAttribute("title", &title_attr
) &&
3138 description
== title_attr
&&
3141 description
.clear();
3144 // Now implement the main logic: the descripion should become the name if
3145 // it's nonempty, and the help should become the description if
3146 // there's no description - or the name if there's no name or description.
3147 if (!description
.empty()) {
3149 description
.clear();
3151 if (!help
.empty() && description
.empty()) {
3155 if (!description
.empty() && name
.empty() && !title_elem_id
) {
3157 description
.clear();
3160 // If it's a text field, also consider the placeholder.
3161 base::string16 placeholder
;
3162 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
&&
3163 HasState(ui::AX_STATE_FOCUSABLE
) &&
3164 GetHtmlAttribute("placeholder", &placeholder
)) {
3165 if (name
.empty() && !title_elem_id
) {
3167 } else if (description
.empty()) {
3168 description
= placeholder
;
3172 // On Windows, the value of a document should be its url.
3173 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA
||
3174 GetRole() == ui::AX_ROLE_WEB_AREA
) {
3175 value
= GetString16Attribute(ui::AX_ATTR_DOC_URL
);
3178 // For certain roles (listbox option, static text, and list marker)
3179 // WebKit stores the main accessible text in the "value" - swap it so
3180 // that it's the "name".
3182 (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
||
3183 GetRole() == ui::AX_ROLE_STATIC_TEXT
||
3184 GetRole() == ui::AX_ROLE_LIST_MARKER
)) {
3185 base::string16 tmp
= value
;
3190 // If this doesn't have a value and is linked then set its value to the url
3191 // attribute. This allows screen readers to read an empty link's destination.
3192 if (value
.empty() && (ia_state() & STATE_SYSTEM_LINKED
))
3193 value
= GetString16Attribute(ui::AX_ATTR_URL
);
3195 win_attributes_
->name
= name
;
3196 win_attributes_
->description
= description
;
3197 win_attributes_
->help
= help
;
3198 win_attributes_
->value
= value
;
3200 // Clear any old relationships between this node and other nodes.
3201 for (size_t i
= 0; i
< relations_
.size(); ++i
)
3202 relations_
[i
]->Release();
3205 // Handle title UI element.
3206 if (title_elem_id
) {
3207 // Add a labelled by relationship.
3208 CComObject
<BrowserAccessibilityRelation
>* relation
;
3209 HRESULT hr
= CComObject
<BrowserAccessibilityRelation
>::CreateInstance(
3211 DCHECK(SUCCEEDED(hr
));
3213 relation
->Initialize(this, IA2_RELATION_LABELLED_BY
);
3214 relation
->AddTarget(title_elem_id
);
3215 relations_
.push_back(relation
);
3218 // Expose slider value.
3219 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR
||
3220 ia_role() == ROLE_SYSTEM_SCROLLBAR
||
3221 ia_role() == ROLE_SYSTEM_SLIDER
) {
3222 win_attributes_
->ia2_attributes
.push_back(L
"valuetext:" + GetValueText());
3225 // If this is a web area for a presentational iframe, give it a role of
3226 // something other than DOCUMENT so that the fact that it's a separate doc
3227 // is not exposed to AT.
3228 if (IsWebAreaForPresentationalIframe()) {
3229 win_attributes_
->ia_role
= ROLE_SYSTEM_GROUPING
;
3230 win_attributes_
->ia2_role
= ROLE_SYSTEM_GROUPING
;
3234 void BrowserAccessibilityWin::UpdateStep2ComputeHypertext() {
3235 // Construct the hypertext for this node, which contains the concatenation
3236 // of all of the static text of this node's children and an embedded object
3237 // character for all non-static-text children. Build up a map from the
3238 // character index of each embedded object character to the id of the
3239 // child object it points to.
3240 for (unsigned int i
= 0; i
< PlatformChildCount(); ++i
) {
3241 BrowserAccessibilityWin
* child
=
3242 PlatformGetChild(i
)->ToBrowserAccessibilityWin();
3243 if (child
->GetRole() == ui::AX_ROLE_STATIC_TEXT
) {
3244 win_attributes_
->hypertext
+= child
->name();
3246 int32 char_offset
= hypertext().size();
3247 int32 child_id
= child
->GetId();
3248 int32 index
= hyperlinks().size();
3249 win_attributes_
->hyperlink_offset_to_index
[char_offset
] = index
;
3250 win_attributes_
->hyperlinks
.push_back(child_id
);
3251 win_attributes_
->hypertext
+= kEmbeddedCharacter
;
3256 void BrowserAccessibilityWin::UpdateStep3FireEvents(bool is_subtree_creation
) {
3257 BrowserAccessibilityManagerWin
* manager
=
3258 this->manager()->ToBrowserAccessibilityManagerWin();
3260 // Fire an event when an alert first appears.
3261 if (ia_role() == ROLE_SYSTEM_ALERT
&&
3262 old_win_attributes_
->ia_role
!= ROLE_SYSTEM_ALERT
) {
3263 manager
->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT
, this);
3266 // Fire an event when a new subtree is created.
3267 if (is_subtree_creation
)
3268 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SHOW
, this);
3270 // The rest of the events only fire on changes, not on new objects.
3271 if (old_win_attributes_
->ia_role
!= 0 ||
3272 !old_win_attributes_
->role_name
.empty()) {
3273 // Fire an event if the name, description, help, or value changes.
3274 if (name() != old_win_attributes_
->name
)
3275 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, this);
3276 if (description() != old_win_attributes_
->description
)
3277 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_DESCRIPTIONCHANGE
, this);
3278 if (help() != old_win_attributes_
->help
)
3279 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_HELPCHANGE
, this);
3280 if (value() != old_win_attributes_
->value
)
3281 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_VALUECHANGE
, this);
3282 if (ia_state() != old_win_attributes_
->ia_state
)
3283 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, this);
3285 // Normally focus events are handled elsewhere, however
3286 // focus for managed descendants is platform-specific.
3287 // Fire a focus event if the focused descendant in a multi-select
3288 // list box changes.
3289 if (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
&&
3290 (ia_state() & STATE_SYSTEM_FOCUSABLE
) &&
3291 (ia_state() & STATE_SYSTEM_SELECTABLE
) &&
3292 (ia_state() & STATE_SYSTEM_FOCUSED
) &&
3293 !(old_win_attributes_
->ia_state
& STATE_SYSTEM_FOCUSED
)) {
3294 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_FOCUS
, this);
3297 // Handle selection being added or removed.
3298 bool is_selected_now
= (ia_state() & STATE_SYSTEM_SELECTED
) != 0;
3299 bool was_selected_before
=
3300 (old_win_attributes_
->ia_state
& STATE_SYSTEM_SELECTED
) != 0;
3301 if (is_selected_now
&& !was_selected_before
) {
3302 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTIONADD
, this);
3303 } else if (!is_selected_now
&& was_selected_before
) {
3304 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTIONREMOVE
, this);
3307 // Fire an event if this container object has scrolled.
3310 if (GetIntAttribute(ui::AX_ATTR_SCROLL_X
, &sx
) &&
3311 GetIntAttribute(ui::AX_ATTR_SCROLL_Y
, &sy
)) {
3312 if (sx
!= previous_scroll_x_
|| sy
!= previous_scroll_y_
)
3313 manager
->MaybeCallNotifyWinEvent(EVENT_SYSTEM_SCROLLINGEND
, this);
3314 previous_scroll_x_
= sx
;
3315 previous_scroll_y_
= sy
;
3318 // Changing a static text node can affect the IAccessibleText hypertext
3319 // of the parent node, so force an update on the parent.
3320 BrowserAccessibilityWin
* parent
= GetParent()->ToBrowserAccessibilityWin();
3322 GetRole() == ui::AX_ROLE_STATIC_TEXT
&&
3323 name() != old_win_attributes_
->name
) {
3324 parent
->UpdateStep1ComputeWinAttributes();
3325 parent
->UpdateStep2ComputeHypertext();
3326 parent
->UpdateStep3FireEvents(false);
3329 // Fire hypertext-related events.
3330 int start
, old_len
, new_len
;
3331 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
3333 // In-process screen readers may call IAccessibleText::get_oldText
3334 // in reaction to this event to retrieve the text that was removed.
3335 manager
->MaybeCallNotifyWinEvent(IA2_EVENT_TEXT_REMOVED
, this);
3338 // In-process screen readers may call IAccessibleText::get_newText
3339 // in reaction to this event to retrieve the text that was inserted.
3340 manager
->MaybeCallNotifyWinEvent(IA2_EVENT_TEXT_INSERTED
, this);
3344 old_win_attributes_
.reset(nullptr);
3347 void BrowserAccessibilityWin::OnSubtreeWillBeDeleted() {
3348 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3349 EVENT_OBJECT_HIDE
, this);
3352 void BrowserAccessibilityWin::NativeAddReference() {
3356 void BrowserAccessibilityWin::NativeReleaseReference() {
3360 bool BrowserAccessibilityWin::IsNative() const {
3364 void BrowserAccessibilityWin::OnLocationChanged() {
3365 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3366 EVENT_OBJECT_LOCATIONCHANGE
, this);
3369 BrowserAccessibilityWin
* BrowserAccessibilityWin::NewReference() {
3374 BrowserAccessibilityWin
* BrowserAccessibilityWin::GetTargetFromChildID(
3375 const VARIANT
& var_id
) {
3376 if (var_id
.vt
!= VT_I4
)
3379 LONG child_id
= var_id
.lVal
;
3380 if (child_id
== CHILDID_SELF
)
3383 if (child_id
>= 1 && child_id
<= static_cast<LONG
>(PlatformChildCount()))
3384 return PlatformGetChild(child_id
- 1)->ToBrowserAccessibilityWin();
3386 return manager()->ToBrowserAccessibilityManagerWin()->
3387 GetFromUniqueIdWin(child_id
);
3390 HRESULT
BrowserAccessibilityWin::GetStringAttributeAsBstr(
3391 ui::AXStringAttribute attribute
,
3395 if (!GetString16Attribute(attribute
, &str
))
3401 *value_bstr
= SysAllocString(str
.c_str());
3402 DCHECK(*value_bstr
);
3407 void BrowserAccessibilityWin::StringAttributeToIA2(
3408 ui::AXStringAttribute attribute
,
3409 const char* ia2_attr
) {
3410 base::string16 value
;
3411 if (GetString16Attribute(attribute
, &value
)) {
3412 win_attributes_
->ia2_attributes
.push_back(
3413 base::ASCIIToUTF16(ia2_attr
) + L
":" + value
);
3417 void BrowserAccessibilityWin::BoolAttributeToIA2(
3418 ui::AXBoolAttribute attribute
,
3419 const char* ia2_attr
) {
3421 if (GetBoolAttribute(attribute
, &value
)) {
3422 win_attributes_
->ia2_attributes
.push_back(
3423 (base::ASCIIToUTF16(ia2_attr
) + L
":") +
3424 (value
? L
"true" : L
"false"));
3428 void BrowserAccessibilityWin::IntAttributeToIA2(
3429 ui::AXIntAttribute attribute
,
3430 const char* ia2_attr
) {
3432 if (GetIntAttribute(attribute
, &value
)) {
3433 win_attributes_
->ia2_attributes
.push_back(
3434 base::ASCIIToUTF16(ia2_attr
) + L
":" +
3435 base::IntToString16(value
));
3439 base::string16
BrowserAccessibilityWin::GetNameRecursive() const {
3440 if (!name().empty()) {
3444 base::string16 result
;
3445 for (uint32 i
= 0; i
< PlatformChildCount(); ++i
) {
3446 result
+= PlatformGetChild(i
)->ToBrowserAccessibilityWin()->
3452 base::string16
BrowserAccessibilityWin::GetValueText() {
3454 base::string16 value
= this->value();
3456 if (value
.empty() &&
3457 GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
, &fval
)) {
3458 value
= base::UTF8ToUTF16(base::DoubleToString(fval
));
3463 base::string16
BrowserAccessibilityWin::TextForIAccessibleText() {
3464 if (IsEditableText())
3466 return (GetRole() == ui::AX_ROLE_STATIC_TEXT
) ? name() : hypertext();
3469 bool BrowserAccessibilityWin::IsSameHypertextCharacter(size_t old_char_index
,
3470 size_t new_char_index
) {
3471 CHECK(old_win_attributes_
);
3473 // For anything other than the "embedded character", we just compare the
3474 // characters directly.
3475 base::char16 old_ch
= old_win_attributes_
->hypertext
[old_char_index
];
3476 base::char16 new_ch
= win_attributes_
->hypertext
[new_char_index
];
3477 if (old_ch
!= new_ch
)
3479 if (old_ch
== new_ch
&& new_ch
!= kEmbeddedCharacter
)
3482 // If it's an embedded character, they're only identical if the child id
3483 // the hyperlink points to is the same.
3484 std::map
<int32
, int32
>& old_offset_to_index
=
3485 old_win_attributes_
->hyperlink_offset_to_index
;
3486 std::vector
<int32
>& old_hyperlinks
= old_win_attributes_
->hyperlinks
;
3487 int32 old_hyperlinks_count
= static_cast<int32
>(old_hyperlinks
.size());
3488 std::map
<int32
, int32
>::iterator iter
;
3489 iter
= old_offset_to_index
.find(old_char_index
);
3490 int old_index
= (iter
!= old_offset_to_index
.end()) ? iter
->second
: -1;
3491 int old_child_id
= (old_index
>= 0 && old_index
< old_hyperlinks_count
) ?
3492 old_hyperlinks
[old_index
] : -1;
3494 std::map
<int32
, int32
>& new_offset_to_index
=
3495 win_attributes_
->hyperlink_offset_to_index
;
3496 std::vector
<int32
>& new_hyperlinks
= win_attributes_
->hyperlinks
;
3497 int32 new_hyperlinks_count
= static_cast<int32
>(new_hyperlinks
.size());
3498 iter
= new_offset_to_index
.find(new_char_index
);
3499 int new_index
= (iter
!= new_offset_to_index
.end()) ? iter
->second
: -1;
3500 int new_child_id
= (new_index
>= 0 && new_index
< new_hyperlinks_count
) ?
3501 new_hyperlinks
[new_index
] : -1;
3503 return old_child_id
== new_child_id
;
3506 void BrowserAccessibilityWin::ComputeHypertextRemovedAndInserted(
3507 int* start
, int* old_len
, int* new_len
) {
3508 CHECK(old_win_attributes_
);
3514 const base::string16
& old_text
= old_win_attributes_
->hypertext
;
3515 const base::string16
& new_text
= hypertext();
3517 size_t common_prefix
= 0;
3518 while (common_prefix
< old_text
.size() &&
3519 common_prefix
< new_text
.size() &&
3520 IsSameHypertextCharacter(common_prefix
, common_prefix
)) {
3524 size_t common_suffix
= 0;
3525 while (common_prefix
+ common_suffix
< old_text
.size() &&
3526 common_prefix
+ common_suffix
< new_text
.size() &&
3527 IsSameHypertextCharacter(
3528 old_text
.size() - common_suffix
- 1,
3529 new_text
.size() - common_suffix
- 1)) {
3533 *start
= common_prefix
;
3534 *old_len
= old_text
.size() - common_prefix
- common_suffix
;
3535 *new_len
= new_text
.size() - common_prefix
- common_suffix
;
3538 void BrowserAccessibilityWin::HandleSpecialTextOffset(
3539 const base::string16
& text
,
3541 if (*offset
== IA2_TEXT_OFFSET_LENGTH
)
3542 *offset
= static_cast<LONG
>(text
.size());
3543 else if (*offset
== IA2_TEXT_OFFSET_CARET
)
3544 get_caretOffset(offset
);
3547 ui::TextBoundaryType
BrowserAccessibilityWin::IA2TextBoundaryToTextBoundary(
3548 IA2TextBoundaryType ia2_boundary
) {
3549 switch(ia2_boundary
) {
3550 case IA2_TEXT_BOUNDARY_CHAR
:
3551 return ui::CHAR_BOUNDARY
;
3552 case IA2_TEXT_BOUNDARY_WORD
:
3553 return ui::WORD_BOUNDARY
;
3554 case IA2_TEXT_BOUNDARY_LINE
:
3555 return ui::LINE_BOUNDARY
;
3556 case IA2_TEXT_BOUNDARY_SENTENCE
:
3557 return ui::SENTENCE_BOUNDARY
;
3558 case IA2_TEXT_BOUNDARY_PARAGRAPH
:
3559 return ui::PARAGRAPH_BOUNDARY
;
3560 case IA2_TEXT_BOUNDARY_ALL
:
3561 return ui::ALL_BOUNDARY
;
3565 return ui::CHAR_BOUNDARY
;
3568 LONG
BrowserAccessibilityWin::FindBoundary(
3569 const base::string16
& text
,
3570 IA2TextBoundaryType ia2_boundary
,
3572 ui::TextBoundaryDirection direction
) {
3573 HandleSpecialTextOffset(text
, &start_offset
);
3574 if (ia2_boundary
== IA2_TEXT_BOUNDARY_WORD
&&
3575 GetRole() == ui::AX_ROLE_TEXT_FIELD
) {
3576 return GetWordStartBoundary(static_cast<int>(start_offset
), direction
);
3579 ui::TextBoundaryType boundary
= IA2TextBoundaryToTextBoundary(ia2_boundary
);
3580 const std::vector
<int32
>& line_breaks
= GetIntListAttribute(
3581 ui::AX_ATTR_LINE_BREAKS
);
3582 return ui::FindAccessibleTextBoundary(
3583 text
, line_breaks
, boundary
, start_offset
, direction
);
3586 BrowserAccessibilityWin
* BrowserAccessibilityWin::GetFromID(int32 id
) {
3587 return manager()->GetFromID(id
)->ToBrowserAccessibilityWin();
3590 void BrowserAccessibilityWin::InitRoleAndState() {
3593 base::string16 role_name
;
3595 int32 ia2_state
= IA2_STATE_OPAQUE
;
3597 if (HasState(ui::AX_STATE_BUSY
))
3598 ia_state
|= STATE_SYSTEM_BUSY
;
3599 if (HasState(ui::AX_STATE_CHECKED
))
3600 ia_state
|= STATE_SYSTEM_CHECKED
;
3601 if (HasState(ui::AX_STATE_COLLAPSED
))
3602 ia_state
|= STATE_SYSTEM_COLLAPSED
;
3603 if (HasState(ui::AX_STATE_EXPANDED
))
3604 ia_state
|= STATE_SYSTEM_EXPANDED
;
3605 if (HasState(ui::AX_STATE_FOCUSABLE
))
3606 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3607 if (HasState(ui::AX_STATE_HASPOPUP
))
3608 ia_state
|= STATE_SYSTEM_HASPOPUP
;
3609 if (HasState(ui::AX_STATE_INDETERMINATE
))
3610 ia_state
|= STATE_SYSTEM_INDETERMINATE
;
3611 if (HasIntAttribute(ui::AX_ATTR_INVALID_STATE
) &&
3612 GetIntAttribute(ui::AX_ATTR_INVALID_STATE
) != ui::AX_INVALID_STATE_FALSE
)
3613 ia2_state
|= IA2_STATE_INVALID_ENTRY
;
3614 if (HasState(ui::AX_STATE_INVISIBLE
))
3615 ia_state
|= STATE_SYSTEM_INVISIBLE
;
3616 if (HasState(ui::AX_STATE_LINKED
))
3617 ia_state
|= STATE_SYSTEM_LINKED
;
3618 if (HasState(ui::AX_STATE_MULTISELECTABLE
)) {
3619 ia_state
|= STATE_SYSTEM_EXTSELECTABLE
;
3620 ia_state
|= STATE_SYSTEM_MULTISELECTABLE
;
3622 // TODO(ctguil): Support STATE_SYSTEM_EXTSELECTABLE/accSelect.
3623 if (HasState(ui::AX_STATE_OFFSCREEN
))
3624 ia_state
|= STATE_SYSTEM_OFFSCREEN
;
3625 if (HasState(ui::AX_STATE_PRESSED
))
3626 ia_state
|= STATE_SYSTEM_PRESSED
;
3627 if (HasState(ui::AX_STATE_PROTECTED
))
3628 ia_state
|= STATE_SYSTEM_PROTECTED
;
3629 if (HasState(ui::AX_STATE_REQUIRED
))
3630 ia2_state
|= IA2_STATE_REQUIRED
;
3631 if (HasState(ui::AX_STATE_SELECTABLE
))
3632 ia_state
|= STATE_SYSTEM_SELECTABLE
;
3633 if (HasState(ui::AX_STATE_SELECTED
))
3634 ia_state
|= STATE_SYSTEM_SELECTED
;
3635 if (HasState(ui::AX_STATE_VISITED
))
3636 ia_state
|= STATE_SYSTEM_TRAVERSED
;
3637 if (!HasState(ui::AX_STATE_ENABLED
))
3638 ia_state
|= STATE_SYSTEM_UNAVAILABLE
;
3639 if (HasState(ui::AX_STATE_VERTICAL
))
3640 ia2_state
|= IA2_STATE_VERTICAL
;
3641 if (HasState(ui::AX_STATE_HORIZONTAL
))
3642 ia2_state
|= IA2_STATE_HORIZONTAL
;
3643 if (HasState(ui::AX_STATE_VISITED
))
3644 ia_state
|= STATE_SYSTEM_TRAVERSED
;
3646 // Expose whether or not the mouse is over an element, but suppress
3647 // this for tests because it can make the test results flaky depending
3648 // on the position of the mouse.
3649 BrowserAccessibilityStateImpl
* accessibility_state
=
3650 BrowserAccessibilityStateImpl::GetInstance();
3651 if (!accessibility_state
->disable_hot_tracking_for_testing()) {
3652 if (HasState(ui::AX_STATE_HOVERED
))
3653 ia_state
|= STATE_SYSTEM_HOTTRACKED
;
3656 // WebKit marks everything as readonly unless it's editable text, so if it's
3657 // not readonly, mark it as editable now. The final computation of the
3658 // READONLY state for MSAA is below, after the switch.
3659 if (!HasState(ui::AX_STATE_READ_ONLY
))
3660 ia2_state
|= IA2_STATE_EDITABLE
;
3662 if (GetBoolAttribute(ui::AX_ATTR_BUTTON_MIXED
))
3663 ia_state
|= STATE_SYSTEM_MIXED
;
3665 if (GetBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE
))
3666 ia2_state
|= IA2_STATE_EDITABLE
;
3668 if (!GetStringAttribute(ui::AX_ATTR_AUTO_COMPLETE
).empty())
3669 ia2_state
|= IA2_STATE_SUPPORTS_AUTOCOMPLETION
;
3671 base::string16 html_tag
= GetString16Attribute(
3672 ui::AX_ATTR_HTML_TAG
);
3673 switch (GetRole()) {
3674 case ui::AX_ROLE_ALERT
:
3675 ia_role
= ROLE_SYSTEM_ALERT
;
3677 case ui::AX_ROLE_ALERT_DIALOG
:
3678 ia_role
= ROLE_SYSTEM_DIALOG
;
3680 case ui::AX_ROLE_APPLICATION
:
3681 ia_role
= ROLE_SYSTEM_APPLICATION
;
3683 case ui::AX_ROLE_ARTICLE
:
3684 ia_role
= ROLE_SYSTEM_DOCUMENT
;
3685 ia_state
|= STATE_SYSTEM_READONLY
;
3687 case ui::AX_ROLE_BANNER
:
3688 ia_role
= ROLE_SYSTEM_GROUPING
;
3689 ia2_role
= IA2_ROLE_HEADER
;
3691 case ui::AX_ROLE_BLOCKQUOTE
:
3692 role_name
= html_tag
;
3693 ia2_role
= IA2_ROLE_SECTION
;
3695 case ui::AX_ROLE_BUSY_INDICATOR
:
3696 ia_role
= ROLE_SYSTEM_ANIMATION
;
3697 ia_state
|= STATE_SYSTEM_READONLY
;
3699 case ui::AX_ROLE_BUTTON
:
3700 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
3702 case ui::AX_ROLE_CANVAS
:
3703 if (GetBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK
)) {
3704 role_name
= L
"canvas";
3705 ia2_role
= IA2_ROLE_CANVAS
;
3707 ia_role
= ROLE_SYSTEM_GRAPHIC
;
3710 case ui::AX_ROLE_CAPTION
:
3711 ia_role
= ROLE_SYSTEM_TEXT
;
3712 ia2_role
= IA2_ROLE_CAPTION
;
3714 case ui::AX_ROLE_CELL
:
3715 ia_role
= ROLE_SYSTEM_CELL
;
3717 case ui::AX_ROLE_CHECK_BOX
:
3718 ia_role
= ROLE_SYSTEM_CHECKBUTTON
;
3719 ia2_state
|= IA2_STATE_CHECKABLE
;
3721 case ui::AX_ROLE_COLOR_WELL
:
3722 ia_role
= ROLE_SYSTEM_TEXT
;
3723 ia2_role
= IA2_ROLE_COLOR_CHOOSER
;
3725 case ui::AX_ROLE_COLUMN
:
3726 ia_role
= ROLE_SYSTEM_COLUMN
;
3728 case ui::AX_ROLE_COLUMN_HEADER
:
3729 ia_role
= ROLE_SYSTEM_COLUMNHEADER
;
3731 case ui::AX_ROLE_COMBO_BOX
:
3732 ia_role
= ROLE_SYSTEM_COMBOBOX
;
3734 case ui::AX_ROLE_COMPLEMENTARY
:
3735 ia_role
= ROLE_SYSTEM_GROUPING
;
3736 ia2_role
= IA2_ROLE_NOTE
;
3738 case ui::AX_ROLE_CONTENT_INFO
:
3739 ia_role
= ROLE_SYSTEM_TEXT
;
3740 ia2_role
= IA2_ROLE_PARAGRAPH
;
3742 case ui::AX_ROLE_DATE
:
3743 case ui::AX_ROLE_DATE_TIME
:
3744 ia_role
= ROLE_SYSTEM_DROPLIST
;
3745 ia2_role
= IA2_ROLE_DATE_EDITOR
;
3747 case ui::AX_ROLE_DIV
:
3749 ia_role
= ROLE_SYSTEM_GROUPING
;
3750 ia2_role
= IA2_ROLE_SECTION
;
3752 case ui::AX_ROLE_DEFINITION
:
3753 role_name
= html_tag
;
3754 ia2_role
= IA2_ROLE_PARAGRAPH
;
3755 ia_state
|= STATE_SYSTEM_READONLY
;
3757 case ui::AX_ROLE_DESCRIPTION_LIST_DETAIL
:
3758 role_name
= html_tag
;
3759 ia_role
= ROLE_SYSTEM_TEXT
;
3760 ia2_role
= IA2_ROLE_PARAGRAPH
;
3762 case ui::AX_ROLE_DESCRIPTION_LIST
:
3763 role_name
= html_tag
;
3764 ia_role
= ROLE_SYSTEM_LIST
;
3765 ia_state
|= STATE_SYSTEM_READONLY
;
3767 case ui::AX_ROLE_DESCRIPTION_LIST_TERM
:
3768 ia_role
= ROLE_SYSTEM_LISTITEM
;
3769 ia_state
|= STATE_SYSTEM_READONLY
;
3771 case ui::AX_ROLE_DETAILS
:
3772 role_name
= html_tag
;
3773 ia_role
= ROLE_SYSTEM_GROUPING
;
3775 case ui::AX_ROLE_DIALOG
:
3776 ia_role
= ROLE_SYSTEM_DIALOG
;
3778 case ui::AX_ROLE_DISCLOSURE_TRIANGLE
:
3779 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
3781 case ui::AX_ROLE_DOCUMENT
:
3782 case ui::AX_ROLE_ROOT_WEB_AREA
:
3783 case ui::AX_ROLE_WEB_AREA
:
3784 ia_role
= ROLE_SYSTEM_DOCUMENT
;
3785 ia_state
|= STATE_SYSTEM_READONLY
;
3786 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3788 case ui::AX_ROLE_EMBEDDED_OBJECT
:
3789 ia_role
= ROLE_SYSTEM_CLIENT
;
3790 ia2_role
= IA2_ROLE_EMBEDDED_OBJECT
;
3792 case ui::AX_ROLE_FIGCAPTION
:
3793 role_name
= html_tag
;
3794 ia2_role
= IA2_ROLE_CAPTION
;
3796 case ui::AX_ROLE_FIGURE
:
3797 ia_role
= ROLE_SYSTEM_GROUPING
;
3799 case ui::AX_ROLE_FORM
:
3800 role_name
= L
"form";
3801 ia2_role
= IA2_ROLE_FORM
;
3803 case ui::AX_ROLE_FOOTER
:
3804 ia_role
= ROLE_SYSTEM_GROUPING
;
3805 ia2_role
= IA2_ROLE_FOOTER
;
3807 case ui::AX_ROLE_GRID
:
3808 ia_role
= ROLE_SYSTEM_TABLE
;
3809 ia_state
|= STATE_SYSTEM_READONLY
;
3811 case ui::AX_ROLE_GROUP
: {
3812 base::string16 aria_role
= GetString16Attribute(
3814 if (aria_role
== L
"group" || html_tag
== L
"fieldset") {
3815 ia_role
= ROLE_SYSTEM_GROUPING
;
3816 } else if (html_tag
== L
"li") {
3817 ia_role
= ROLE_SYSTEM_LISTITEM
;
3818 ia_state
|= STATE_SYSTEM_READONLY
;
3820 if (html_tag
.empty())
3823 role_name
= html_tag
;
3824 ia2_role
= IA2_ROLE_SECTION
;
3828 case ui::AX_ROLE_HEADING
:
3829 role_name
= html_tag
;
3830 ia2_role
= IA2_ROLE_HEADING
;
3832 case ui::AX_ROLE_IFRAME
:
3833 ia_role
= ROLE_SYSTEM_DOCUMENT
;
3834 ia2_role
= IA2_ROLE_INTERNAL_FRAME
;
3835 ia_state
= STATE_SYSTEM_READONLY
;
3837 case ui::AX_ROLE_IFRAME_PRESENTATIONAL
:
3838 ia_role
= ROLE_SYSTEM_GROUPING
;
3840 case ui::AX_ROLE_IMAGE
:
3841 ia_role
= ROLE_SYSTEM_GRAPHIC
;
3842 ia_state
|= STATE_SYSTEM_READONLY
;
3844 case ui::AX_ROLE_IMAGE_MAP
:
3845 role_name
= html_tag
;
3846 ia2_role
= IA2_ROLE_IMAGE_MAP
;
3847 ia_state
|= STATE_SYSTEM_READONLY
;
3849 case ui::AX_ROLE_IMAGE_MAP_LINK
:
3850 ia_role
= ROLE_SYSTEM_LINK
;
3851 ia_state
|= STATE_SYSTEM_LINKED
;
3852 ia_state
|= STATE_SYSTEM_READONLY
;
3854 case ui::AX_ROLE_LABEL_TEXT
:
3855 case ui::AX_ROLE_LEGEND
:
3856 ia_role
= ROLE_SYSTEM_TEXT
;
3857 ia2_role
= IA2_ROLE_LABEL
;
3859 case ui::AX_ROLE_LINK
:
3860 ia_role
= ROLE_SYSTEM_LINK
;
3861 ia_state
|= STATE_SYSTEM_LINKED
;
3863 case ui::AX_ROLE_LIST
:
3864 ia_role
= ROLE_SYSTEM_LIST
;
3865 ia_state
|= STATE_SYSTEM_READONLY
;
3867 case ui::AX_ROLE_LIST_BOX
:
3868 ia_role
= ROLE_SYSTEM_LIST
;
3870 case ui::AX_ROLE_LIST_BOX_OPTION
:
3871 ia_role
= ROLE_SYSTEM_LISTITEM
;
3872 if (ia_state
& STATE_SYSTEM_SELECTABLE
) {
3873 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3874 if (HasState(ui::AX_STATE_FOCUSED
))
3875 ia_state
|= STATE_SYSTEM_FOCUSED
;
3878 case ui::AX_ROLE_LIST_ITEM
:
3879 ia_role
= ROLE_SYSTEM_LISTITEM
;
3880 ia_state
|= STATE_SYSTEM_READONLY
;
3882 case ui::AX_ROLE_MAIN
:
3883 ia_role
= ROLE_SYSTEM_GROUPING
;
3884 ia2_role
= IA2_ROLE_PARAGRAPH
;
3886 case ui::AX_ROLE_MARQUEE
:
3887 ia_role
= ROLE_SYSTEM_ANIMATION
;
3889 case ui::AX_ROLE_MATH
:
3890 ia_role
= ROLE_SYSTEM_EQUATION
;
3892 case ui::AX_ROLE_MENU
:
3893 case ui::AX_ROLE_MENU_BUTTON
:
3894 ia_role
= ROLE_SYSTEM_MENUPOPUP
;
3896 case ui::AX_ROLE_MENU_BAR
:
3897 ia_role
= ROLE_SYSTEM_MENUBAR
;
3899 case ui::AX_ROLE_MENU_ITEM
:
3900 ia_role
= ROLE_SYSTEM_MENUITEM
;
3902 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX
:
3903 ia_role
= ROLE_SYSTEM_MENUITEM
;
3904 ia2_role
= IA2_ROLE_CHECK_MENU_ITEM
;
3905 ia2_state
|= IA2_STATE_CHECKABLE
;
3907 case ui::AX_ROLE_MENU_ITEM_RADIO
:
3908 ia_role
= ROLE_SYSTEM_MENUITEM
;
3909 ia2_role
= IA2_ROLE_RADIO_MENU_ITEM
;
3911 case ui::AX_ROLE_MENU_LIST_POPUP
:
3912 ia_role
= ROLE_SYSTEM_CLIENT
;
3914 case ui::AX_ROLE_MENU_LIST_OPTION
:
3915 ia_role
= ROLE_SYSTEM_LISTITEM
;
3916 if (ia_state
& STATE_SYSTEM_SELECTABLE
) {
3917 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3918 if (HasState(ui::AX_STATE_FOCUSED
))
3919 ia_state
|= STATE_SYSTEM_FOCUSED
;
3922 case ui::AX_ROLE_METER
:
3923 role_name
= html_tag
;
3924 ia_role
= ROLE_SYSTEM_PROGRESSBAR
;
3926 case ui::AX_ROLE_NAVIGATION
:
3927 ia_role
= ROLE_SYSTEM_GROUPING
;
3928 ia2_role
= IA2_ROLE_SECTION
;
3930 case ui::AX_ROLE_NOTE
:
3931 ia_role
= ROLE_SYSTEM_GROUPING
;
3932 ia2_role
= IA2_ROLE_NOTE
;
3934 case ui::AX_ROLE_OUTLINE
:
3935 ia_role
= ROLE_SYSTEM_OUTLINE
;
3937 case ui::AX_ROLE_PARAGRAPH
:
3939 ia2_role
= IA2_ROLE_PARAGRAPH
;
3941 case ui::AX_ROLE_POP_UP_BUTTON
:
3942 if (html_tag
== L
"select") {
3943 ia_role
= ROLE_SYSTEM_COMBOBOX
;
3945 ia_role
= ROLE_SYSTEM_BUTTONMENU
;
3948 case ui::AX_ROLE_PRE
:
3949 role_name
= html_tag
;
3950 ia_role
= ROLE_SYSTEM_TEXT
;
3951 ia2_role
= IA2_ROLE_PARAGRAPH
;
3953 case ui::AX_ROLE_PROGRESS_INDICATOR
:
3954 ia_role
= ROLE_SYSTEM_PROGRESSBAR
;
3955 ia_state
|= STATE_SYSTEM_READONLY
;
3957 case ui::AX_ROLE_RADIO_BUTTON
:
3958 ia_role
= ROLE_SYSTEM_RADIOBUTTON
;
3959 ia2_state
= IA2_STATE_CHECKABLE
;
3961 case ui::AX_ROLE_RADIO_GROUP
:
3962 ia_role
= ROLE_SYSTEM_GROUPING
;
3964 case ui::AX_ROLE_REGION
:
3965 if (html_tag
== L
"section") {
3966 ia_role
= ROLE_SYSTEM_GROUPING
;
3967 ia2_role
= IA2_ROLE_SECTION
;
3969 ia_role
= ROLE_SYSTEM_PANE
;
3972 case ui::AX_ROLE_ROW
:
3973 ia_role
= ROLE_SYSTEM_ROW
;
3975 case ui::AX_ROLE_ROW_HEADER
:
3976 ia_role
= ROLE_SYSTEM_ROWHEADER
;
3978 case ui::AX_ROLE_RUBY
:
3979 ia_role
= ROLE_SYSTEM_TEXT
;
3980 ia2_role
= IA2_ROLE_TEXT_FRAME
;
3982 case ui::AX_ROLE_RULER
:
3983 ia_role
= ROLE_SYSTEM_CLIENT
;
3984 ia2_role
= IA2_ROLE_RULER
;
3985 ia_state
|= STATE_SYSTEM_READONLY
;
3987 case ui::AX_ROLE_SCROLL_AREA
:
3988 ia_role
= ROLE_SYSTEM_CLIENT
;
3989 ia2_role
= IA2_ROLE_SCROLL_PANE
;
3990 ia_state
|= STATE_SYSTEM_READONLY
;
3991 ia2_state
&= ~(IA2_STATE_EDITABLE
);
3993 case ui::AX_ROLE_SCROLL_BAR
:
3994 ia_role
= ROLE_SYSTEM_SCROLLBAR
;
3996 case ui::AX_ROLE_SEARCH
:
3997 ia_role
= ROLE_SYSTEM_GROUPING
;
3998 ia2_role
= IA2_ROLE_SECTION
;
4000 case ui::AX_ROLE_SLIDER
:
4001 ia_role
= ROLE_SYSTEM_SLIDER
;
4003 case ui::AX_ROLE_SPIN_BUTTON
:
4004 ia_role
= ROLE_SYSTEM_SPINBUTTON
;
4006 case ui::AX_ROLE_SPIN_BUTTON_PART
:
4007 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4009 case ui::AX_ROLE_ANNOTATION
:
4010 case ui::AX_ROLE_LIST_MARKER
:
4011 case ui::AX_ROLE_STATIC_TEXT
:
4012 ia_role
= ROLE_SYSTEM_STATICTEXT
;
4014 case ui::AX_ROLE_STATUS
:
4015 ia_role
= ROLE_SYSTEM_STATUSBAR
;
4017 case ui::AX_ROLE_SPLITTER
:
4018 ia_role
= ROLE_SYSTEM_SEPARATOR
;
4020 case ui::AX_ROLE_SVG_ROOT
:
4021 ia_role
= ROLE_SYSTEM_GRAPHIC
;
4023 case ui::AX_ROLE_SWITCH
:
4024 role_name
= L
"switch";
4025 ia2_role
= IA2_ROLE_TOGGLE_BUTTON
;
4027 case ui::AX_ROLE_TAB
:
4028 ia_role
= ROLE_SYSTEM_PAGETAB
;
4030 case ui::AX_ROLE_TABLE
: {
4031 base::string16 aria_role
= GetString16Attribute(
4033 if (aria_role
== L
"treegrid") {
4034 ia_role
= ROLE_SYSTEM_OUTLINE
;
4036 ia_role
= ROLE_SYSTEM_TABLE
;
4040 case ui::AX_ROLE_TABLE_HEADER_CONTAINER
:
4041 ia_role
= ROLE_SYSTEM_GROUPING
;
4042 ia2_role
= IA2_ROLE_SECTION
;
4043 ia_state
|= STATE_SYSTEM_READONLY
;
4045 case ui::AX_ROLE_TAB_LIST
:
4046 ia_role
= ROLE_SYSTEM_PAGETABLIST
;
4048 case ui::AX_ROLE_TAB_PANEL
:
4049 ia_role
= ROLE_SYSTEM_PROPERTYPAGE
;
4051 case ui::AX_ROLE_TOGGLE_BUTTON
:
4052 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4053 ia2_role
= IA2_ROLE_TOGGLE_BUTTON
;
4055 case ui::AX_ROLE_TEXT_FIELD
:
4056 case ui::AX_ROLE_SEARCH_BOX
:
4057 ia_role
= ROLE_SYSTEM_TEXT
;
4058 if (HasState(ui::AX_STATE_MULTILINE
))
4059 ia2_state
|= IA2_STATE_MULTI_LINE
;
4061 ia2_state
|= IA2_STATE_SINGLE_LINE
;
4062 ia2_state
|= IA2_STATE_EDITABLE
;
4063 ia2_state
|= IA2_STATE_SELECTABLE_TEXT
;
4065 case ui::AX_ROLE_TIME
:
4066 ia_role
= ROLE_SYSTEM_SPINBUTTON
;
4068 case ui::AX_ROLE_TIMER
:
4069 ia_role
= ROLE_SYSTEM_CLOCK
;
4070 ia_state
|= STATE_SYSTEM_READONLY
;
4072 case ui::AX_ROLE_TOOLBAR
:
4073 ia_role
= ROLE_SYSTEM_TOOLBAR
;
4074 ia_state
|= STATE_SYSTEM_READONLY
;
4076 case ui::AX_ROLE_TOOLTIP
:
4077 ia_role
= ROLE_SYSTEM_TOOLTIP
;
4078 ia_state
|= STATE_SYSTEM_READONLY
;
4080 case ui::AX_ROLE_TREE
:
4081 ia_role
= ROLE_SYSTEM_OUTLINE
;
4083 case ui::AX_ROLE_TREE_GRID
:
4084 ia_role
= ROLE_SYSTEM_OUTLINE
;
4086 case ui::AX_ROLE_TREE_ITEM
:
4087 ia_role
= ROLE_SYSTEM_OUTLINEITEM
;
4089 case ui::AX_ROLE_LINE_BREAK
:
4090 ia_role
= ROLE_SYSTEM_WHITESPACE
;
4092 case ui::AX_ROLE_WINDOW
:
4093 ia_role
= ROLE_SYSTEM_WINDOW
;
4096 // TODO(dmazzoni): figure out the proper MSAA role for all of these.
4097 case ui::AX_ROLE_DIRECTORY
:
4098 case ui::AX_ROLE_IGNORED
:
4099 case ui::AX_ROLE_LOG
:
4100 case ui::AX_ROLE_NONE
:
4101 case ui::AX_ROLE_PRESENTATIONAL
:
4102 case ui::AX_ROLE_SLIDER_THUMB
:
4104 ia_role
= ROLE_SYSTEM_CLIENT
;
4108 // Compute the final value of READONLY for MSAA.
4110 // We always set the READONLY state for elements that have the
4111 // aria-readonly attribute and for a few roles (in the switch above).
4112 // We clear the READONLY state on focusable controls and on a document.
4113 // Everything else, the majority of objects, do not have this state set.
4114 if (HasState(ui::AX_STATE_FOCUSABLE
) &&
4115 ia_role
!= ROLE_SYSTEM_DOCUMENT
) {
4116 ia_state
&= ~(STATE_SYSTEM_READONLY
);
4118 if (!HasState(ui::AX_STATE_READ_ONLY
))
4119 ia_state
&= ~(STATE_SYSTEM_READONLY
);
4120 if (GetBoolAttribute(ui::AX_ATTR_ARIA_READONLY
))
4121 ia_state
|= STATE_SYSTEM_READONLY
;
4123 // The role should always be set.
4124 DCHECK(!role_name
.empty() || ia_role
);
4126 // If we didn't explicitly set the IAccessible2 role, make it the same
4127 // as the MSAA role.
4131 win_attributes_
->ia_role
= ia_role
;
4132 win_attributes_
->ia_state
= ia_state
;
4133 win_attributes_
->role_name
= role_name
;
4134 win_attributes_
->ia2_role
= ia2_role
;
4135 win_attributes_
->ia2_state
= ia2_state
;
4138 } // namespace content