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
)
906 if (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
&&
908 GetParent()->GetRole() == ui::AX_ROLE_LIST_BOX
) {
910 *similar_items_in_group
= GetParent()->PlatformChildCount();
911 *position_in_group
= GetIndexInParent() + 1;
919 // IAccessibleApplication methods.
922 STDMETHODIMP
BrowserAccessibilityWin::get_appName(BSTR
* app_name
) {
923 // No need to check |instance_active()| because this interface is
924 // global, and doesn't depend on any local state.
929 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
930 // the part before the "/".
931 std::vector
<std::string
> product_components
;
932 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components
);
933 DCHECK_EQ(2U, product_components
.size());
934 if (product_components
.size() != 2)
936 *app_name
= SysAllocString(base::UTF8ToUTF16(product_components
[0]).c_str());
938 return *app_name
? S_OK
: E_FAIL
;
941 STDMETHODIMP
BrowserAccessibilityWin::get_appVersion(BSTR
* app_version
) {
942 // No need to check |instance_active()| because this interface is
943 // global, and doesn't depend on any local state.
948 // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out
949 // the part after the "/".
950 std::vector
<std::string
> product_components
;
951 base::SplitString(GetContentClient()->GetProduct(), '/', &product_components
);
952 DCHECK_EQ(2U, product_components
.size());
953 if (product_components
.size() != 2)
956 SysAllocString(base::UTF8ToUTF16(product_components
[1]).c_str());
957 DCHECK(*app_version
);
958 return *app_version
? S_OK
: E_FAIL
;
961 STDMETHODIMP
BrowserAccessibilityWin::get_toolkitName(BSTR
* toolkit_name
) {
962 // No need to check |instance_active()| because this interface is
963 // global, and doesn't depend on any local state.
968 // This is hard-coded; all products based on the Chromium engine
969 // will have the same toolkit name, so that assistive technology can
970 // detect any Chrome-based product.
971 *toolkit_name
= SysAllocString(L
"Chrome");
972 DCHECK(*toolkit_name
);
973 return *toolkit_name
? S_OK
: E_FAIL
;
976 STDMETHODIMP
BrowserAccessibilityWin::get_toolkitVersion(
977 BSTR
* toolkit_version
) {
978 // No need to check |instance_active()| because this interface is
979 // global, and doesn't depend on any local state.
981 if (!toolkit_version
)
984 std::string user_agent
= GetContentClient()->GetUserAgent();
985 *toolkit_version
= SysAllocString(base::UTF8ToUTF16(user_agent
).c_str());
986 DCHECK(*toolkit_version
);
987 return *toolkit_version
? S_OK
: E_FAIL
;
991 // IAccessibleImage methods.
994 STDMETHODIMP
BrowserAccessibilityWin::get_description(BSTR
* desc
) {
995 if (!instance_active())
1001 if (description().empty())
1004 *desc
= SysAllocString(description().c_str());
1010 STDMETHODIMP
BrowserAccessibilityWin::get_imagePosition(
1011 enum IA2CoordinateType coordinate_type
,
1014 if (!instance_active())
1018 return E_INVALIDARG
;
1020 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
1022 manager()->ToBrowserAccessibilityManagerWin()->GetParentHWND();
1025 POINT top_left
= {0, 0};
1026 ::ClientToScreen(parent_hwnd
, &top_left
);
1027 *x
= GetLocation().x() + top_left
.x
;
1028 *y
= GetLocation().y() + top_left
.y
;
1029 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
1030 *x
= GetLocation().x();
1031 *y
= GetLocation().y();
1033 *x
-= GetParent()->GetLocation().x();
1034 *y
-= GetParent()->GetLocation().y();
1037 return E_INVALIDARG
;
1043 STDMETHODIMP
BrowserAccessibilityWin::get_imageSize(LONG
* height
, LONG
* width
) {
1044 if (!instance_active())
1047 if (!height
|| !width
)
1048 return E_INVALIDARG
;
1050 *height
= GetLocation().height();
1051 *width
= GetLocation().width();
1056 // IAccessibleTable methods.
1059 STDMETHODIMP
BrowserAccessibilityWin::get_accessibleAt(
1062 IUnknown
** accessible
) {
1063 if (!instance_active())
1067 return E_INVALIDARG
;
1071 if (!GetIntAttribute(
1072 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1074 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1080 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1081 return E_INVALIDARG
;
1083 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1084 ui::AX_ATTR_CELL_IDS
);
1085 DCHECK_EQ(columns
* rows
, static_cast<int>(cell_ids
.size()));
1087 int cell_id
= cell_ids
[row
* columns
+ column
];
1088 BrowserAccessibilityWin
* cell
= GetFromID(cell_id
);
1090 *accessible
= static_cast<IAccessible
*>(cell
->NewReference());
1095 return E_INVALIDARG
;
1098 STDMETHODIMP
BrowserAccessibilityWin::get_caption(IUnknown
** accessible
) {
1099 if (!instance_active())
1103 return E_INVALIDARG
;
1105 // TODO(dmazzoni): implement
1109 STDMETHODIMP
BrowserAccessibilityWin::get_childIndex(long row
,
1112 if (!instance_active())
1116 return E_INVALIDARG
;
1120 if (!GetIntAttribute(
1121 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1123 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1129 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1130 return E_INVALIDARG
;
1132 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1133 ui::AX_ATTR_CELL_IDS
);
1134 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1135 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1136 DCHECK_EQ(columns
* rows
, static_cast<int>(cell_ids
.size()));
1137 int cell_id
= cell_ids
[row
* columns
+ column
];
1138 for (size_t i
= 0; i
< unique_cell_ids
.size(); ++i
) {
1139 if (unique_cell_ids
[i
] == cell_id
) {
1140 *cell_index
= (long)i
;
1148 STDMETHODIMP
BrowserAccessibilityWin::get_columnDescription(long column
,
1149 BSTR
* description
) {
1150 if (!instance_active())
1154 return E_INVALIDARG
;
1158 if (!GetIntAttribute(
1159 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1160 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1166 if (column
< 0 || column
>= columns
)
1167 return E_INVALIDARG
;
1169 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1170 ui::AX_ATTR_CELL_IDS
);
1171 for (int i
= 0; i
< rows
; ++i
) {
1172 int cell_id
= cell_ids
[i
* columns
+ column
];
1173 BrowserAccessibilityWin
* cell
= static_cast<BrowserAccessibilityWin
*>(
1174 manager()->GetFromID(cell_id
));
1175 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
) {
1176 base::string16 cell_name
= cell
->GetString16Attribute(
1178 if (cell_name
.size() > 0) {
1179 *description
= SysAllocString(cell_name
.c_str());
1183 if (cell
->description().size() > 0) {
1184 *description
= SysAllocString(cell
->description().c_str());
1193 STDMETHODIMP
BrowserAccessibilityWin::get_columnExtentAt(
1196 long* n_columns_spanned
) {
1197 if (!instance_active())
1200 if (!n_columns_spanned
)
1201 return E_INVALIDARG
;
1205 if (!GetIntAttribute(
1206 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1207 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1213 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1214 return E_INVALIDARG
;
1216 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1217 ui::AX_ATTR_CELL_IDS
);
1218 int cell_id
= cell_ids
[row
* columns
+ column
];
1219 BrowserAccessibilityWin
* cell
= static_cast<BrowserAccessibilityWin
*>(
1220 manager()->GetFromID(cell_id
));
1223 cell
->GetIntAttribute(
1224 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1226 *n_columns_spanned
= colspan
;
1233 STDMETHODIMP
BrowserAccessibilityWin::get_columnHeader(
1234 IAccessibleTable
** accessible_table
,
1235 long* starting_row_index
) {
1236 // TODO(dmazzoni): implement
1240 STDMETHODIMP
BrowserAccessibilityWin::get_columnIndex(long cell_index
,
1241 long* column_index
) {
1242 if (!instance_active())
1246 return E_INVALIDARG
;
1248 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1249 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1250 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1252 return E_INVALIDARG
;
1253 if (cell_index
>= cell_id_count
)
1256 int cell_id
= unique_cell_ids
[cell_index
];
1257 BrowserAccessibilityWin
* cell
=
1258 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1261 cell
->GetIntAttribute(
1262 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &col_index
)) {
1263 *column_index
= col_index
;
1270 STDMETHODIMP
BrowserAccessibilityWin::get_nColumns(long* column_count
) {
1271 if (!instance_active())
1275 return E_INVALIDARG
;
1278 if (GetIntAttribute(
1279 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
)) {
1280 *column_count
= columns
;
1287 STDMETHODIMP
BrowserAccessibilityWin::get_nRows(long* row_count
) {
1288 if (!instance_active())
1292 return E_INVALIDARG
;
1295 if (GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1303 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedChildren(long* cell_count
) {
1304 if (!instance_active())
1308 return E_INVALIDARG
;
1310 // TODO(dmazzoni): add support for selected cells/rows/columns in tables.
1315 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedColumns(long* column_count
) {
1316 if (!instance_active())
1320 return E_INVALIDARG
;
1326 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedRows(long* row_count
) {
1327 if (!instance_active())
1331 return E_INVALIDARG
;
1337 STDMETHODIMP
BrowserAccessibilityWin::get_rowDescription(long row
,
1338 BSTR
* description
) {
1339 if (!instance_active())
1343 return E_INVALIDARG
;
1347 if (!GetIntAttribute(
1348 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1349 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1355 if (row
< 0 || row
>= rows
)
1356 return E_INVALIDARG
;
1358 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1359 ui::AX_ATTR_CELL_IDS
);
1360 for (int i
= 0; i
< columns
; ++i
) {
1361 int cell_id
= cell_ids
[row
* columns
+ i
];
1362 BrowserAccessibilityWin
* cell
=
1363 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1364 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
) {
1365 base::string16 cell_name
= cell
->GetString16Attribute(
1367 if (cell_name
.size() > 0) {
1368 *description
= SysAllocString(cell_name
.c_str());
1372 if (cell
->description().size() > 0) {
1373 *description
= SysAllocString(cell
->description().c_str());
1382 STDMETHODIMP
BrowserAccessibilityWin::get_rowExtentAt(long row
,
1384 long* n_rows_spanned
) {
1385 if (!instance_active())
1388 if (!n_rows_spanned
)
1389 return E_INVALIDARG
;
1393 if (!GetIntAttribute(
1394 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1395 !GetIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
) ||
1401 if (row
< 0 || row
>= rows
|| column
< 0 || column
>= columns
)
1402 return E_INVALIDARG
;
1404 const std::vector
<int32
>& cell_ids
= GetIntListAttribute(
1405 ui::AX_ATTR_CELL_IDS
);
1406 int cell_id
= cell_ids
[row
* columns
+ column
];
1407 BrowserAccessibilityWin
* cell
=
1408 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1411 cell
->GetIntAttribute(
1412 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1414 *n_rows_spanned
= rowspan
;
1421 STDMETHODIMP
BrowserAccessibilityWin::get_rowHeader(
1422 IAccessibleTable
** accessible_table
,
1423 long* starting_column_index
) {
1424 // TODO(dmazzoni): implement
1428 STDMETHODIMP
BrowserAccessibilityWin::get_rowIndex(long cell_index
,
1430 if (!instance_active())
1434 return E_INVALIDARG
;
1436 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1437 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1438 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1440 return E_INVALIDARG
;
1441 if (cell_index
>= cell_id_count
)
1444 int cell_id
= unique_cell_ids
[cell_index
];
1445 BrowserAccessibilityWin
* cell
=
1446 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1449 cell
->GetIntAttribute(
1450 ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &cell_row_index
)) {
1451 *row_index
= cell_row_index
;
1458 STDMETHODIMP
BrowserAccessibilityWin::get_selectedChildren(long max_children
,
1461 if (!instance_active())
1464 if (!children
|| !n_children
)
1465 return E_INVALIDARG
;
1467 // TODO(dmazzoni): Implement this.
1472 STDMETHODIMP
BrowserAccessibilityWin::get_selectedColumns(long max_columns
,
1475 if (!instance_active())
1478 if (!columns
|| !n_columns
)
1479 return E_INVALIDARG
;
1481 // TODO(dmazzoni): Implement this.
1486 STDMETHODIMP
BrowserAccessibilityWin::get_selectedRows(long max_rows
,
1489 if (!instance_active())
1492 if (!rows
|| !n_rows
)
1493 return E_INVALIDARG
;
1495 // TODO(dmazzoni): Implement this.
1500 STDMETHODIMP
BrowserAccessibilityWin::get_summary(IUnknown
** accessible
) {
1501 if (!instance_active())
1505 return E_INVALIDARG
;
1507 // TODO(dmazzoni): implement
1511 STDMETHODIMP
BrowserAccessibilityWin::get_isColumnSelected(
1513 boolean
* is_selected
) {
1514 if (!instance_active())
1518 return E_INVALIDARG
;
1520 // TODO(dmazzoni): Implement this.
1521 *is_selected
= false;
1525 STDMETHODIMP
BrowserAccessibilityWin::get_isRowSelected(long row
,
1526 boolean
* is_selected
) {
1527 if (!instance_active())
1531 return E_INVALIDARG
;
1533 // TODO(dmazzoni): Implement this.
1534 *is_selected
= false;
1538 STDMETHODIMP
BrowserAccessibilityWin::get_isSelected(long row
,
1540 boolean
* is_selected
) {
1541 if (!instance_active())
1545 return E_INVALIDARG
;
1547 // TODO(dmazzoni): Implement this.
1548 *is_selected
= false;
1552 STDMETHODIMP
BrowserAccessibilityWin::get_rowColumnExtentsAtIndex(
1557 long* column_extents
,
1558 boolean
* is_selected
) {
1559 if (!instance_active())
1562 if (!row
|| !column
|| !row_extents
|| !column_extents
|| !is_selected
)
1563 return E_INVALIDARG
;
1565 const std::vector
<int32
>& unique_cell_ids
= GetIntListAttribute(
1566 ui::AX_ATTR_UNIQUE_CELL_IDS
);
1567 int cell_id_count
= static_cast<int>(unique_cell_ids
.size());
1569 return E_INVALIDARG
;
1570 if (index
>= cell_id_count
)
1573 int cell_id
= unique_cell_ids
[index
];
1574 BrowserAccessibilityWin
* cell
=
1575 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1579 cell
->GetIntAttribute(
1580 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1581 cell
->GetIntAttribute(
1582 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1585 *row_extents
= rowspan
;
1586 *column_extents
= colspan
;
1594 // IAccessibleTable2 methods.
1597 STDMETHODIMP
BrowserAccessibilityWin::get_cellAt(long row
,
1600 return get_accessibleAt(row
, column
, cell
);
1603 STDMETHODIMP
BrowserAccessibilityWin::get_nSelectedCells(long* cell_count
) {
1604 return get_nSelectedChildren(cell_count
);
1607 STDMETHODIMP
BrowserAccessibilityWin::get_selectedCells(
1609 long* n_selected_cells
) {
1610 if (!instance_active())
1613 if (!cells
|| !n_selected_cells
)
1614 return E_INVALIDARG
;
1616 // TODO(dmazzoni): Implement this.
1617 *n_selected_cells
= 0;
1621 STDMETHODIMP
BrowserAccessibilityWin::get_selectedColumns(long** columns
,
1623 if (!instance_active())
1626 if (!columns
|| !n_columns
)
1627 return E_INVALIDARG
;
1629 // TODO(dmazzoni): Implement this.
1634 STDMETHODIMP
BrowserAccessibilityWin::get_selectedRows(long** rows
,
1636 if (!instance_active())
1639 if (!rows
|| !n_rows
)
1640 return E_INVALIDARG
;
1642 // TODO(dmazzoni): Implement this.
1649 // IAccessibleTableCell methods.
1652 STDMETHODIMP
BrowserAccessibilityWin::get_columnExtent(
1653 long* n_columns_spanned
) {
1654 if (!instance_active())
1657 if (!n_columns_spanned
)
1658 return E_INVALIDARG
;
1661 if (GetIntAttribute(
1662 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
) &&
1664 *n_columns_spanned
= colspan
;
1671 STDMETHODIMP
BrowserAccessibilityWin::get_columnHeaderCells(
1672 IUnknown
*** cell_accessibles
,
1673 long* n_column_header_cells
) {
1674 if (!instance_active())
1677 if (!cell_accessibles
|| !n_column_header_cells
)
1678 return E_INVALIDARG
;
1680 *n_column_header_cells
= 0;
1683 if (!GetIntAttribute(
1684 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
)) {
1688 BrowserAccessibility
* table
= GetParent();
1689 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
1690 table
= table
->GetParent();
1698 if (!table
->GetIntAttribute(
1699 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1700 !table
->GetIntAttribute(
1701 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1704 if (columns
<= 0 || rows
<= 0 || column
< 0 || column
>= columns
)
1707 const std::vector
<int32
>& cell_ids
= table
->GetIntListAttribute(
1708 ui::AX_ATTR_CELL_IDS
);
1710 for (int i
= 0; i
< rows
; ++i
) {
1711 int cell_id
= cell_ids
[i
* columns
+ column
];
1712 BrowserAccessibilityWin
* cell
=
1713 manager()->GetFromID(cell_id
)->ToBrowserAccessibilityWin();
1714 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
)
1715 (*n_column_header_cells
)++;
1718 *cell_accessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(
1719 (*n_column_header_cells
) * sizeof(cell_accessibles
[0])));
1721 for (int i
= 0; i
< rows
; ++i
) {
1722 int cell_id
= cell_ids
[i
* columns
+ column
];
1723 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1724 if (cell
&& cell
->GetRole() == ui::AX_ROLE_COLUMN_HEADER
) {
1725 (*cell_accessibles
)[index
] = static_cast<IAccessible
*>(
1726 cell
->ToBrowserAccessibilityWin()->NewReference());
1734 STDMETHODIMP
BrowserAccessibilityWin::get_columnIndex(long* column_index
) {
1735 if (!instance_active())
1739 return E_INVALIDARG
;
1742 if (GetIntAttribute(
1743 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
)) {
1744 *column_index
= column
;
1751 STDMETHODIMP
BrowserAccessibilityWin::get_rowExtent(long* n_rows_spanned
) {
1752 if (!instance_active())
1755 if (!n_rows_spanned
)
1756 return E_INVALIDARG
;
1759 if (GetIntAttribute(
1760 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1762 *n_rows_spanned
= rowspan
;
1769 STDMETHODIMP
BrowserAccessibilityWin::get_rowHeaderCells(
1770 IUnknown
*** cell_accessibles
,
1771 long* n_row_header_cells
) {
1772 if (!instance_active())
1775 if (!cell_accessibles
|| !n_row_header_cells
)
1776 return E_INVALIDARG
;
1778 *n_row_header_cells
= 0;
1781 if (!GetIntAttribute(
1782 ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
)) {
1786 BrowserAccessibility
* table
= GetParent();
1787 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
1788 table
= table
->GetParent();
1796 if (!table
->GetIntAttribute(
1797 ui::AX_ATTR_TABLE_COLUMN_COUNT
, &columns
) ||
1798 !table
->GetIntAttribute(
1799 ui::AX_ATTR_TABLE_ROW_COUNT
, &rows
)) {
1802 if (columns
<= 0 || rows
<= 0 || row
< 0 || row
>= rows
)
1805 const std::vector
<int32
>& cell_ids
= table
->GetIntListAttribute(
1806 ui::AX_ATTR_CELL_IDS
);
1808 for (int i
= 0; i
< columns
; ++i
) {
1809 int cell_id
= cell_ids
[row
* columns
+ i
];
1810 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1811 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
)
1812 (*n_row_header_cells
)++;
1815 *cell_accessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(
1816 (*n_row_header_cells
) * sizeof(cell_accessibles
[0])));
1818 for (int i
= 0; i
< columns
; ++i
) {
1819 int cell_id
= cell_ids
[row
* columns
+ i
];
1820 BrowserAccessibility
* cell
= manager()->GetFromID(cell_id
);
1821 if (cell
&& cell
->GetRole() == ui::AX_ROLE_ROW_HEADER
) {
1822 (*cell_accessibles
)[index
] = static_cast<IAccessible
*>(
1823 cell
->ToBrowserAccessibilityWin()->NewReference());
1831 STDMETHODIMP
BrowserAccessibilityWin::get_rowIndex(long* row_index
) {
1832 if (!instance_active())
1836 return E_INVALIDARG
;
1839 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
)) {
1846 STDMETHODIMP
BrowserAccessibilityWin::get_isSelected(boolean
* is_selected
) {
1847 if (!instance_active())
1851 return E_INVALIDARG
;
1853 *is_selected
= false;
1857 STDMETHODIMP
BrowserAccessibilityWin::get_rowColumnExtents(
1861 long* column_extents
,
1862 boolean
* is_selected
) {
1863 if (!instance_active())
1871 return E_INVALIDARG
;
1878 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
) &&
1880 ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
) &&
1882 ui::AX_ATTR_TABLE_CELL_ROW_SPAN
, &rowspan
) &&
1884 ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN
, &colspan
)) {
1886 *column_index
= column
;
1887 *row_extents
= rowspan
;
1888 *column_extents
= colspan
;
1889 *is_selected
= false;
1896 STDMETHODIMP
BrowserAccessibilityWin::get_table(IUnknown
** table
) {
1897 if (!instance_active())
1901 return E_INVALIDARG
;
1906 GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX
, &row
);
1907 GetIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX
, &column
);
1909 BrowserAccessibility
* find_table
= GetParent();
1910 while (find_table
&& find_table
->GetRole() != ui::AX_ROLE_TABLE
)
1911 find_table
= find_table
->GetParent();
1917 *table
= static_cast<IAccessibleTable
*>(
1918 find_table
->ToBrowserAccessibilityWin()->NewReference());
1924 // IAccessibleText methods.
1927 STDMETHODIMP
BrowserAccessibilityWin::get_nCharacters(LONG
* n_characters
) {
1928 if (!instance_active())
1932 return E_INVALIDARG
;
1934 *n_characters
= TextForIAccessibleText().length();
1938 STDMETHODIMP
BrowserAccessibilityWin::get_caretOffset(LONG
* offset
) {
1939 if (!instance_active())
1943 return E_INVALIDARG
;
1946 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
||
1947 GetRole() == ui::AX_ROLE_TEXT_AREA
) {
1949 if (GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START
,
1951 *offset
= sel_start
;
1957 STDMETHODIMP
BrowserAccessibilityWin::get_characterExtents(
1959 enum IA2CoordinateType coordinate_type
,
1964 if (!instance_active())
1967 if (!out_x
|| !out_y
|| !out_width
|| !out_height
)
1968 return E_INVALIDARG
;
1970 const base::string16
& text_str
= TextForIAccessibleText();
1971 HandleSpecialTextOffset(text_str
, &offset
);
1973 if (offset
< 0 || offset
> static_cast<LONG
>(text_str
.size()))
1974 return E_INVALIDARG
;
1976 gfx::Rect character_bounds
;
1977 if (coordinate_type
== IA2_COORDTYPE_SCREEN_RELATIVE
) {
1978 character_bounds
= GetGlobalBoundsForRange(offset
, 1);
1979 } else if (coordinate_type
== IA2_COORDTYPE_PARENT_RELATIVE
) {
1980 character_bounds
= GetLocalBoundsForRange(offset
, 1);
1981 character_bounds
-= GetLocation().OffsetFromOrigin();
1983 return E_INVALIDARG
;
1986 *out_x
= character_bounds
.x();
1987 *out_y
= character_bounds
.y();
1988 *out_width
= character_bounds
.width();
1989 *out_height
= character_bounds
.height();
1994 STDMETHODIMP
BrowserAccessibilityWin::get_nSelections(LONG
* n_selections
) {
1995 if (!instance_active())
1999 return E_INVALIDARG
;
2002 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
||
2003 GetRole() == ui::AX_ROLE_TEXT_AREA
) {
2006 if (GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START
,
2008 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, &sel_end
) &&
2009 sel_start
!= sel_end
)
2016 STDMETHODIMP
BrowserAccessibilityWin::get_selection(LONG selection_index
,
2019 if (!instance_active())
2022 if (!start_offset
|| !end_offset
|| selection_index
!= 0)
2023 return E_INVALIDARG
;
2027 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
||
2028 GetRole() == ui::AX_ROLE_TEXT_AREA
) {
2031 if (GetIntAttribute(
2032 ui::AX_ATTR_TEXT_SEL_START
, &sel_start
) &&
2033 GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END
, &sel_end
)) {
2034 *start_offset
= sel_start
;
2035 *end_offset
= sel_end
;
2042 STDMETHODIMP
BrowserAccessibilityWin::get_text(LONG start_offset
,
2045 if (!instance_active())
2049 return E_INVALIDARG
;
2051 const base::string16
& text_str
= TextForIAccessibleText();
2053 // Handle special text offsets.
2054 HandleSpecialTextOffset(text_str
, &start_offset
);
2055 HandleSpecialTextOffset(text_str
, &end_offset
);
2057 // The spec allows the arguments to be reversed.
2058 if (start_offset
> end_offset
) {
2059 LONG tmp
= start_offset
;
2060 start_offset
= end_offset
;
2064 // The spec does not allow the start or end offsets to be out or range;
2065 // we must return an error if so.
2066 LONG len
= text_str
.length();
2067 if (start_offset
< 0)
2068 return E_INVALIDARG
;
2069 if (end_offset
> len
)
2070 return E_INVALIDARG
;
2072 base::string16 substr
= text_str
.substr(start_offset
,
2073 end_offset
- start_offset
);
2077 *text
= SysAllocString(substr
.c_str());
2082 STDMETHODIMP
BrowserAccessibilityWin::get_textAtOffset(
2084 enum IA2TextBoundaryType boundary_type
,
2088 if (!instance_active())
2091 if (!start_offset
|| !end_offset
|| !text
)
2092 return E_INVALIDARG
;
2094 const base::string16
& text_str
= TextForIAccessibleText();
2095 HandleSpecialTextOffset(text_str
, &offset
);
2097 return E_INVALIDARG
;
2099 LONG text_len
= text_str
.length();
2100 if (offset
> text_len
)
2101 return E_INVALIDARG
;
2103 // The IAccessible2 spec says we don't have to implement the "sentence"
2104 // boundary type, we can just let the screenreader handle it.
2105 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2112 // According to the IA2 Spec, only line boundaries should succeed when
2113 // the offset is one past the end of the text.
2114 if (offset
== text_len
&& boundary_type
!= IA2_TEXT_BOUNDARY_LINE
) {
2121 *start_offset
= FindBoundary(
2122 text_str
, boundary_type
, offset
, ui::BACKWARDS_DIRECTION
);
2123 *end_offset
= FindBoundary(
2124 text_str
, boundary_type
, offset
, ui::FORWARDS_DIRECTION
);
2125 return get_text(*start_offset
, *end_offset
, text
);
2128 STDMETHODIMP
BrowserAccessibilityWin::get_textBeforeOffset(
2130 enum IA2TextBoundaryType boundary_type
,
2134 if (!instance_active())
2137 if (!start_offset
|| !end_offset
|| !text
)
2138 return E_INVALIDARG
;
2140 // The IAccessible2 spec says we don't have to implement the "sentence"
2141 // boundary type, we can just let the screenreader handle it.
2142 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2149 const base::string16
& text_str
= TextForIAccessibleText();
2151 *start_offset
= FindBoundary(
2152 text_str
, boundary_type
, offset
, ui::BACKWARDS_DIRECTION
);
2153 *end_offset
= offset
;
2154 return get_text(*start_offset
, *end_offset
, text
);
2157 STDMETHODIMP
BrowserAccessibilityWin::get_textAfterOffset(
2159 enum IA2TextBoundaryType boundary_type
,
2163 if (!instance_active())
2166 if (!start_offset
|| !end_offset
|| !text
)
2167 return E_INVALIDARG
;
2169 // The IAccessible2 spec says we don't have to implement the "sentence"
2170 // boundary type, we can just let the screenreader handle it.
2171 if (boundary_type
== IA2_TEXT_BOUNDARY_SENTENCE
) {
2178 const base::string16
& text_str
= TextForIAccessibleText();
2180 *start_offset
= offset
;
2181 *end_offset
= FindBoundary(
2182 text_str
, boundary_type
, offset
, ui::FORWARDS_DIRECTION
);
2183 return get_text(*start_offset
, *end_offset
, text
);
2186 STDMETHODIMP
BrowserAccessibilityWin::get_newText(IA2TextSegment
* new_text
) {
2187 if (!instance_active())
2191 return E_INVALIDARG
;
2193 if (!old_win_attributes_
)
2196 int start
, old_len
, new_len
;
2197 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
2201 base::string16 substr
= hypertext().substr(start
, new_len
);
2202 new_text
->text
= SysAllocString(substr
.c_str());
2203 new_text
->start
= static_cast<long>(start
);
2204 new_text
->end
= static_cast<long>(start
+ new_len
);
2208 STDMETHODIMP
BrowserAccessibilityWin::get_oldText(IA2TextSegment
* old_text
) {
2209 if (!instance_active())
2213 return E_INVALIDARG
;
2215 if (!old_win_attributes_
)
2218 int start
, old_len
, new_len
;
2219 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
2223 base::string16 old_hypertext
= old_win_attributes_
->hypertext
;
2224 base::string16 substr
= old_hypertext
.substr(start
, old_len
);
2225 old_text
->text
= SysAllocString(substr
.c_str());
2226 old_text
->start
= static_cast<long>(start
);
2227 old_text
->end
= static_cast<long>(start
+ old_len
);
2231 STDMETHODIMP
BrowserAccessibilityWin::get_offsetAtPoint(
2234 enum IA2CoordinateType coord_type
,
2236 if (!instance_active())
2240 return E_INVALIDARG
;
2242 // TODO(dmazzoni): implement this. We're returning S_OK for now so that
2243 // screen readers still return partially accurate results rather than
2244 // completely failing.
2249 STDMETHODIMP
BrowserAccessibilityWin::scrollSubstringTo(
2252 enum IA2ScrollType scroll_type
) {
2253 // TODO(dmazzoni): adjust this for the start and end index, too.
2254 return scrollTo(scroll_type
);
2257 STDMETHODIMP
BrowserAccessibilityWin::scrollSubstringToPoint(
2260 enum IA2CoordinateType coordinate_type
,
2262 // TODO(dmazzoni): adjust this for the start and end index, too.
2263 return scrollToPoint(coordinate_type
, x
, y
);
2266 STDMETHODIMP
BrowserAccessibilityWin::addSelection(LONG start_offset
,
2268 if (!instance_active())
2271 const base::string16
& text_str
= TextForIAccessibleText();
2272 HandleSpecialTextOffset(text_str
, &start_offset
);
2273 HandleSpecialTextOffset(text_str
, &end_offset
);
2275 manager()->SetTextSelection(*this, start_offset
, end_offset
);
2279 STDMETHODIMP
BrowserAccessibilityWin::removeSelection(LONG selection_index
) {
2280 if (!instance_active())
2283 if (selection_index
!= 0)
2284 return E_INVALIDARG
;
2286 manager()->SetTextSelection(*this, 0, 0);
2290 STDMETHODIMP
BrowserAccessibilityWin::setCaretOffset(LONG offset
) {
2291 if (!instance_active())
2294 const base::string16
& text_str
= TextForIAccessibleText();
2295 HandleSpecialTextOffset(text_str
, &offset
);
2296 manager()->SetTextSelection(*this, offset
, offset
);
2300 STDMETHODIMP
BrowserAccessibilityWin::setSelection(LONG selection_index
,
2303 if (!instance_active())
2306 if (selection_index
!= 0)
2307 return E_INVALIDARG
;
2309 const base::string16
& text_str
= TextForIAccessibleText();
2310 HandleSpecialTextOffset(text_str
, &start_offset
);
2311 HandleSpecialTextOffset(text_str
, &end_offset
);
2313 manager()->SetTextSelection(*this, start_offset
, end_offset
);
2318 // IAccessibleHypertext methods.
2321 STDMETHODIMP
BrowserAccessibilityWin::get_nHyperlinks(long* hyperlink_count
) {
2322 if (!instance_active())
2325 if (!hyperlink_count
)
2326 return E_INVALIDARG
;
2328 *hyperlink_count
= hyperlink_offset_to_index().size();
2332 STDMETHODIMP
BrowserAccessibilityWin::get_hyperlink(
2334 IAccessibleHyperlink
** hyperlink
) {
2335 if (!instance_active())
2340 index
>= static_cast<long>(hyperlinks().size())) {
2341 return E_INVALIDARG
;
2344 int32 id
= hyperlinks()[index
];
2345 BrowserAccessibilityWin
* child
=
2346 manager()->GetFromID(id
)->ToBrowserAccessibilityWin();
2348 *hyperlink
= static_cast<IAccessibleHyperlink
*>(child
->NewReference());
2355 STDMETHODIMP
BrowserAccessibilityWin::get_hyperlinkIndex(
2357 long* hyperlink_index
) {
2358 if (!instance_active())
2361 if (!hyperlink_index
)
2362 return E_INVALIDARG
;
2364 *hyperlink_index
= -1;
2366 if (char_index
< 0 ||
2367 char_index
>= static_cast<long>(hypertext().size())) {
2368 return E_INVALIDARG
;
2371 std::map
<int32
, int32
>::iterator it
=
2372 hyperlink_offset_to_index().find(char_index
);
2373 if (it
== hyperlink_offset_to_index().end())
2376 *hyperlink_index
= it
->second
;
2381 // IAccessibleValue methods.
2384 STDMETHODIMP
BrowserAccessibilityWin::get_currentValue(VARIANT
* value
) {
2385 if (!instance_active())
2389 return E_INVALIDARG
;
2392 if (GetFloatAttribute(
2393 ui::AX_ATTR_VALUE_FOR_RANGE
, &float_val
)) {
2395 value
->dblVal
= float_val
;
2399 value
->vt
= VT_EMPTY
;
2403 STDMETHODIMP
BrowserAccessibilityWin::get_minimumValue(VARIANT
* value
) {
2404 if (!instance_active())
2408 return E_INVALIDARG
;
2411 if (GetFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE
,
2414 value
->dblVal
= float_val
;
2418 value
->vt
= VT_EMPTY
;
2422 STDMETHODIMP
BrowserAccessibilityWin::get_maximumValue(VARIANT
* value
) {
2423 if (!instance_active())
2427 return E_INVALIDARG
;
2430 if (GetFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE
,
2433 value
->dblVal
= float_val
;
2437 value
->vt
= VT_EMPTY
;
2441 STDMETHODIMP
BrowserAccessibilityWin::setCurrentValue(VARIANT new_value
) {
2442 // TODO(dmazzoni): Implement this.
2447 // ISimpleDOMDocument methods.
2450 STDMETHODIMP
BrowserAccessibilityWin::get_URL(BSTR
* url
) {
2451 if (!instance_active())
2455 return E_INVALIDARG
;
2457 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_URL
, url
);
2460 STDMETHODIMP
BrowserAccessibilityWin::get_title(BSTR
* title
) {
2461 if (!instance_active())
2465 return E_INVALIDARG
;
2467 return GetStringAttributeAsBstr(ui::AX_ATTR_DOC_TITLE
, title
);
2470 STDMETHODIMP
BrowserAccessibilityWin::get_mimeType(BSTR
* mime_type
) {
2471 if (!instance_active())
2475 return E_INVALIDARG
;
2477 return GetStringAttributeAsBstr(
2478 ui::AX_ATTR_DOC_MIMETYPE
, mime_type
);
2481 STDMETHODIMP
BrowserAccessibilityWin::get_docType(BSTR
* doc_type
) {
2482 if (!instance_active())
2486 return E_INVALIDARG
;
2488 return GetStringAttributeAsBstr(
2489 ui::AX_ATTR_DOC_DOCTYPE
, doc_type
);
2493 // ISimpleDOMNode methods.
2496 STDMETHODIMP
BrowserAccessibilityWin::get_nodeInfo(
2498 short* name_space_id
,
2500 unsigned int* num_children
,
2501 unsigned int* unique_id
,
2502 unsigned short* node_type
) {
2503 if (!instance_active())
2506 if (!node_name
|| !name_space_id
|| !node_value
|| !num_children
||
2507 !unique_id
|| !node_type
) {
2508 return E_INVALIDARG
;
2512 if (GetString16Attribute(ui::AX_ATTR_HTML_TAG
, &tag
))
2513 *node_name
= SysAllocString(tag
.c_str());
2518 *node_value
= SysAllocString(value().c_str());
2519 *num_children
= PlatformChildCount();
2520 *unique_id
= unique_id_win_
;
2522 if (ia_role() == ROLE_SYSTEM_DOCUMENT
) {
2523 *node_type
= NODETYPE_DOCUMENT
;
2524 } else if (ia_role() == ROLE_SYSTEM_TEXT
&&
2525 ((ia2_state() & IA2_STATE_EDITABLE
) == 0)) {
2526 *node_type
= NODETYPE_TEXT
;
2528 *node_type
= NODETYPE_ELEMENT
;
2534 STDMETHODIMP
BrowserAccessibilityWin::get_attributes(
2535 unsigned short max_attribs
,
2537 short* name_space_id
,
2538 BSTR
* attrib_values
,
2539 unsigned short* num_attribs
) {
2540 if (!instance_active())
2543 if (!attrib_names
|| !name_space_id
|| !attrib_values
|| !num_attribs
)
2544 return E_INVALIDARG
;
2546 *num_attribs
= max_attribs
;
2547 if (*num_attribs
> GetHtmlAttributes().size())
2548 *num_attribs
= GetHtmlAttributes().size();
2550 for (unsigned short i
= 0; i
< *num_attribs
; ++i
) {
2551 attrib_names
[i
] = SysAllocString(
2552 base::UTF8ToUTF16(GetHtmlAttributes()[i
].first
).c_str());
2553 name_space_id
[i
] = 0;
2554 attrib_values
[i
] = SysAllocString(
2555 base::UTF8ToUTF16(GetHtmlAttributes()[i
].second
).c_str());
2560 STDMETHODIMP
BrowserAccessibilityWin::get_attributesForNames(
2561 unsigned short num_attribs
,
2563 short* name_space_id
,
2564 BSTR
* attrib_values
) {
2565 if (!instance_active())
2568 if (!attrib_names
|| !name_space_id
|| !attrib_values
)
2569 return E_INVALIDARG
;
2571 for (unsigned short i
= 0; i
< num_attribs
; ++i
) {
2572 name_space_id
[i
] = 0;
2574 std::string name
= base::UTF16ToUTF8((LPCWSTR
)attrib_names
[i
]);
2575 for (unsigned int j
= 0; j
< GetHtmlAttributes().size(); ++j
) {
2576 if (GetHtmlAttributes()[j
].first
== name
) {
2577 attrib_values
[i
] = SysAllocString(
2578 base::UTF8ToUTF16(GetHtmlAttributes()[j
].second
).c_str());
2584 attrib_values
[i
] = NULL
;
2590 STDMETHODIMP
BrowserAccessibilityWin::get_computedStyle(
2591 unsigned short max_style_properties
,
2592 boolean use_alternate_view
,
2593 BSTR
* style_properties
,
2595 unsigned short *num_style_properties
) {
2596 if (!instance_active())
2599 if (!style_properties
|| !style_values
)
2600 return E_INVALIDARG
;
2602 // We only cache a single style property for now: DISPLAY
2604 base::string16 display
;
2605 if (max_style_properties
== 0 ||
2606 !GetString16Attribute(ui::AX_ATTR_DISPLAY
, &display
)) {
2607 *num_style_properties
= 0;
2611 *num_style_properties
= 1;
2612 style_properties
[0] = SysAllocString(L
"display");
2613 style_values
[0] = SysAllocString(display
.c_str());
2618 STDMETHODIMP
BrowserAccessibilityWin::get_computedStyleForProperties(
2619 unsigned short num_style_properties
,
2620 boolean use_alternate_view
,
2621 BSTR
* style_properties
,
2622 BSTR
* style_values
) {
2623 if (!instance_active())
2626 if (!style_properties
|| !style_values
)
2627 return E_INVALIDARG
;
2629 // We only cache a single style property for now: DISPLAY
2631 for (unsigned short i
= 0; i
< num_style_properties
; ++i
) {
2632 base::string16 name
= (LPCWSTR
)style_properties
[i
];
2633 base::StringToLowerASCII(&name
);
2634 if (name
== L
"display") {
2635 base::string16 display
= GetString16Attribute(
2636 ui::AX_ATTR_DISPLAY
);
2637 style_values
[i
] = SysAllocString(display
.c_str());
2639 style_values
[i
] = NULL
;
2646 STDMETHODIMP
BrowserAccessibilityWin::scrollTo(boolean placeTopLeft
) {
2647 return scrollTo(placeTopLeft
?
2648 IA2_SCROLL_TYPE_TOP_LEFT
: IA2_SCROLL_TYPE_ANYWHERE
);
2651 STDMETHODIMP
BrowserAccessibilityWin::get_parentNode(ISimpleDOMNode
** node
) {
2652 if (!instance_active())
2656 return E_INVALIDARG
;
2658 *node
= GetParent()->ToBrowserAccessibilityWin()->NewReference();
2662 STDMETHODIMP
BrowserAccessibilityWin::get_firstChild(ISimpleDOMNode
** node
) {
2663 if (!instance_active())
2667 return E_INVALIDARG
;
2669 if (PlatformChildCount() == 0) {
2674 *node
= PlatformGetChild(0)->ToBrowserAccessibilityWin()->NewReference();
2678 STDMETHODIMP
BrowserAccessibilityWin::get_lastChild(ISimpleDOMNode
** node
) {
2679 if (!instance_active())
2683 return E_INVALIDARG
;
2685 if (PlatformChildCount() == 0) {
2690 *node
= PlatformGetChild(PlatformChildCount() - 1)
2691 ->ToBrowserAccessibilityWin()->NewReference();
2695 STDMETHODIMP
BrowserAccessibilityWin::get_previousSibling(
2696 ISimpleDOMNode
** node
) {
2697 if (!instance_active())
2701 return E_INVALIDARG
;
2703 if (!GetParent() || GetIndexInParent() <= 0) {
2708 *node
= GetParent()->InternalGetChild(GetIndexInParent() - 1)->
2709 ToBrowserAccessibilityWin()->NewReference();
2713 STDMETHODIMP
BrowserAccessibilityWin::get_nextSibling(ISimpleDOMNode
** node
) {
2714 if (!instance_active())
2718 return E_INVALIDARG
;
2721 GetIndexInParent() < 0 ||
2722 GetIndexInParent() >= static_cast<int>(
2723 GetParent()->InternalChildCount()) - 1) {
2728 *node
= GetParent()->InternalGetChild(GetIndexInParent() + 1)->
2729 ToBrowserAccessibilityWin()->NewReference();
2733 STDMETHODIMP
BrowserAccessibilityWin::get_childAt(
2734 unsigned int child_index
,
2735 ISimpleDOMNode
** node
) {
2736 if (!instance_active())
2740 return E_INVALIDARG
;
2742 if (child_index
>= PlatformChildCount())
2743 return E_INVALIDARG
;
2745 BrowserAccessibility
* child
= PlatformGetChild(child_index
);
2751 *node
= child
->ToBrowserAccessibilityWin()->NewReference();
2756 // ISimpleDOMText methods.
2759 STDMETHODIMP
BrowserAccessibilityWin::get_domText(BSTR
* dom_text
) {
2760 if (!instance_active())
2764 return E_INVALIDARG
;
2766 return GetStringAttributeAsBstr(
2767 ui::AX_ATTR_NAME
, dom_text
);
2770 STDMETHODIMP
BrowserAccessibilityWin::get_clippedSubstringBounds(
2771 unsigned int start_index
,
2772 unsigned int end_index
,
2777 // TODO(dmazzoni): fully support this API by intersecting the
2778 // rect with the container's rect.
2779 return get_unclippedSubstringBounds(
2780 start_index
, end_index
, out_x
, out_y
, out_width
, out_height
);
2783 STDMETHODIMP
BrowserAccessibilityWin::get_unclippedSubstringBounds(
2784 unsigned int start_index
,
2785 unsigned int end_index
,
2790 if (!instance_active())
2793 if (!out_x
|| !out_y
|| !out_width
|| !out_height
)
2794 return E_INVALIDARG
;
2796 const base::string16
& text_str
= TextForIAccessibleText();
2797 if (start_index
> text_str
.size() ||
2798 end_index
> text_str
.size() ||
2799 start_index
> end_index
) {
2800 return E_INVALIDARG
;
2803 gfx::Rect bounds
= GetGlobalBoundsForRange(
2804 start_index
, end_index
- start_index
);
2805 *out_x
= bounds
.x();
2806 *out_y
= bounds
.y();
2807 *out_width
= bounds
.width();
2808 *out_height
= bounds
.height();
2812 STDMETHODIMP
BrowserAccessibilityWin::scrollToSubstring(
2813 unsigned int start_index
,
2814 unsigned int end_index
) {
2815 if (!instance_active())
2818 const base::string16
& text_str
= TextForIAccessibleText();
2819 if (start_index
> text_str
.size() ||
2820 end_index
> text_str
.size() ||
2821 start_index
> end_index
) {
2822 return E_INVALIDARG
;
2825 manager()->ScrollToMakeVisible(*this, GetLocalBoundsForRange(
2826 start_index
, end_index
- start_index
));
2827 manager()->ToBrowserAccessibilityManagerWin()->TrackScrollingObject(this);
2833 // IServiceProvider methods.
2836 STDMETHODIMP
BrowserAccessibilityWin::QueryService(REFGUID guidService
,
2839 if (!instance_active())
2842 // The system uses IAccessible APIs for many purposes, but only
2843 // assistive technology like screen readers uses IAccessible2.
2844 // Enable full accessibility support when IAccessible2 APIs are queried.
2845 if (riid
== IID_IAccessible2
)
2846 BrowserAccessibilityStateImpl::GetInstance()->EnableAccessibility();
2848 if (guidService
== GUID_IAccessibleContentDocument
) {
2849 // Special Mozilla extension: return the accessible for the root document.
2850 // Screen readers use this to distinguish between a document loaded event
2851 // on the root document vs on an iframe.
2852 return manager()->GetRoot()->ToBrowserAccessibilityWin()->QueryInterface(
2853 IID_IAccessible2
, object
);
2856 if (guidService
== IID_IAccessible
||
2857 guidService
== IID_IAccessible2
||
2858 guidService
== IID_IAccessibleAction
||
2859 guidService
== IID_IAccessibleApplication
||
2860 guidService
== IID_IAccessibleHyperlink
||
2861 guidService
== IID_IAccessibleHypertext
||
2862 guidService
== IID_IAccessibleImage
||
2863 guidService
== IID_IAccessibleTable
||
2864 guidService
== IID_IAccessibleTable2
||
2865 guidService
== IID_IAccessibleTableCell
||
2866 guidService
== IID_IAccessibleText
||
2867 guidService
== IID_IAccessibleValue
||
2868 guidService
== IID_ISimpleDOMDocument
||
2869 guidService
== IID_ISimpleDOMNode
||
2870 guidService
== IID_ISimpleDOMText
||
2871 guidService
== GUID_ISimpleDOM
) {
2872 return QueryInterface(riid
, object
);
2875 // We only support the IAccessibleEx interface on Windows 8 and above. This
2876 // is needed for the on-screen Keyboard to show up in metro mode, when the
2877 // user taps an editable portion on the page.
2878 // All methods in the IAccessibleEx interface are unimplemented.
2879 if (riid
== IID_IAccessibleEx
&&
2880 base::win::GetVersion() >= base::win::VERSION_WIN8
) {
2881 return QueryInterface(riid
, object
);
2888 STDMETHODIMP
BrowserAccessibilityWin::GetPatternProvider(PATTERNID id
,
2889 IUnknown
** provider
) {
2890 DVLOG(1) << "In Function: "
2892 << " for pattern id: "
2894 if (id
== UIA_ValuePatternId
|| id
== UIA_TextPatternId
) {
2895 if (IsEditableText()) {
2896 DVLOG(1) << "Returning UIA text provider";
2897 base::win::UIATextProvider::CreateTextProvider(
2898 GetValueText(), true, provider
);
2905 STDMETHODIMP
BrowserAccessibilityWin::GetPropertyValue(PROPERTYID id
,
2907 DVLOG(1) << "In Function: "
2909 << " for property id: "
2911 V_VT(ret
) = VT_EMPTY
;
2912 if (id
== UIA_ControlTypePropertyId
) {
2913 if (IsEditableText()) {
2915 ret
->lVal
= UIA_EditControlTypeId
;
2916 DVLOG(1) << "Returning Edit control type";
2918 DVLOG(1) << "Returning empty control type";
2925 // CComObjectRootEx methods.
2929 HRESULT WINAPI
BrowserAccessibilityWin::InternalQueryInterface(
2931 const _ATL_INTMAP_ENTRY
* entries
,
2934 BrowserAccessibilityWin
* accessibility
=
2935 reinterpret_cast<BrowserAccessibilityWin
*>(this_ptr
);
2936 int32 ia_role
= accessibility
->ia_role();
2937 if (iid
== IID_IAccessibleImage
) {
2938 if (ia_role
!= ROLE_SYSTEM_GRAPHIC
) {
2940 return E_NOINTERFACE
;
2942 } else if (iid
== IID_IAccessibleTable
|| iid
== IID_IAccessibleTable2
) {
2943 if (ia_role
!= ROLE_SYSTEM_TABLE
) {
2945 return E_NOINTERFACE
;
2947 } else if (iid
== IID_IAccessibleTableCell
) {
2948 if (!accessibility
->IsCellOrTableHeaderRole()) {
2950 return E_NOINTERFACE
;
2952 } else if (iid
== IID_IAccessibleValue
) {
2953 if (ia_role
!= ROLE_SYSTEM_PROGRESSBAR
&&
2954 ia_role
!= ROLE_SYSTEM_SCROLLBAR
&&
2955 ia_role
!= ROLE_SYSTEM_SLIDER
) {
2957 return E_NOINTERFACE
;
2959 } else if (iid
== IID_ISimpleDOMDocument
) {
2960 if (ia_role
!= ROLE_SYSTEM_DOCUMENT
) {
2962 return E_NOINTERFACE
;
2966 return CComObjectRootBase::InternalQueryInterface(
2967 this_ptr
, entries
, iid
, object
);
2974 void BrowserAccessibilityWin::UpdateStep1ComputeWinAttributes() {
2975 // Swap win_attributes_ to old_win_attributes_, allowing us to see
2976 // exactly what changed and fire appropriate events. Note that
2977 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents.
2978 old_win_attributes_
.swap(win_attributes_
);
2979 win_attributes_
.reset(new WinAttributes());
2983 win_attributes_
->ia2_attributes
.clear();
2985 // Expose autocomplete attribute for combobox and textbox.
2986 StringAttributeToIA2(ui::AX_ATTR_AUTO_COMPLETE
, "autocomplete");
2988 // Expose the "display" and "tag" attributes.
2989 StringAttributeToIA2(ui::AX_ATTR_DISPLAY
, "display");
2990 StringAttributeToIA2(ui::AX_ATTR_DROPEFFECT
, "dropeffect");
2991 StringAttributeToIA2(ui::AX_ATTR_TEXT_INPUT_TYPE
, "text-input-type");
2992 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG
, "tag");
2993 StringAttributeToIA2(ui::AX_ATTR_ROLE
, "xml-roles");
2995 // Expose "level" attribute for headings, trees, etc.
2996 IntAttributeToIA2(ui::AX_ATTR_HIERARCHICAL_LEVEL
, "level");
2998 // Expose the set size and position in set for listbox options.
2999 if (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
&&
3001 GetParent()->GetRole() == ui::AX_ROLE_LIST_BOX
) {
3002 win_attributes_
->ia2_attributes
.push_back(
3003 L
"setsize:" + base::IntToString16(GetParent()->PlatformChildCount()));
3004 win_attributes_
->ia2_attributes
.push_back(
3005 L
"setsize:" + base::IntToString16(GetIndexInParent() + 1));
3008 if (ia_role() == ROLE_SYSTEM_CHECKBUTTON
||
3009 ia_role() == ROLE_SYSTEM_RADIOBUTTON
||
3010 ia2_role() == IA2_ROLE_CHECK_MENU_ITEM
||
3011 ia2_role() == IA2_ROLE_RADIO_MENU_ITEM
||
3012 ia2_role() == IA2_ROLE_TOGGLE_BUTTON
) {
3013 win_attributes_
->ia2_attributes
.push_back(L
"checkable:true");
3016 // Expose live region attributes.
3017 StringAttributeToIA2(ui::AX_ATTR_LIVE_STATUS
, "live");
3018 StringAttributeToIA2(ui::AX_ATTR_LIVE_RELEVANT
, "relevant");
3019 BoolAttributeToIA2(ui::AX_ATTR_LIVE_ATOMIC
, "atomic");
3020 BoolAttributeToIA2(ui::AX_ATTR_LIVE_BUSY
, "busy");
3022 // Expose aria-grabbed attributes.
3023 BoolAttributeToIA2(ui::AX_ATTR_GRABBED
, "grabbed");
3025 // Expose container live region attributes.
3026 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_STATUS
,
3028 StringAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT
,
3029 "container-relevant");
3030 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC
,
3031 "container-atomic");
3032 BoolAttributeToIA2(ui::AX_ATTR_CONTAINER_LIVE_BUSY
,
3035 // Expose table cell index.
3036 if (IsCellOrTableHeaderRole()) {
3037 BrowserAccessibility
* table
= GetParent();
3038 while (table
&& table
->GetRole() != ui::AX_ROLE_TABLE
)
3039 table
= table
->GetParent();
3041 const std::vector
<int32
>& unique_cell_ids
= table
->GetIntListAttribute(
3042 ui::AX_ATTR_UNIQUE_CELL_IDS
);
3043 for (size_t i
= 0; i
< unique_cell_ids
.size(); ++i
) {
3044 if (unique_cell_ids
[i
] == GetId()) {
3045 win_attributes_
->ia2_attributes
.push_back(
3046 base::string16(L
"table-cell-index:") + base::IntToString16(i
));
3052 // Expose invalid state for form controls and elements with aria-invalid.
3054 if (GetIntAttribute(ui::AX_ATTR_INVALID_STATE
, &invalid_state
)) {
3055 // TODO(nektar): Handle the possibility of having multiple aria-invalid
3056 // attributes defined, e.g., "invalid:spelling,grammar".
3057 switch (invalid_state
) {
3058 case ui::AX_INVALID_STATE_FALSE
:
3059 win_attributes_
->ia2_attributes
.push_back(L
"invalid:false");
3061 case ui::AX_INVALID_STATE_TRUE
:
3062 win_attributes_
->ia2_attributes
.push_back(L
"invalid:true");
3064 case ui::AX_INVALID_STATE_SPELLING
:
3065 win_attributes_
->ia2_attributes
.push_back(L
"invalid:spelling");
3067 case ui::AX_INVALID_STATE_GRAMMAR
:
3068 win_attributes_
->ia2_attributes
.push_back(L
"invalid:grammar");
3070 case ui::AX_INVALID_STATE_OTHER
:
3072 base::string16 aria_invalid_value
;
3073 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE
,
3074 &aria_invalid_value
)) {
3075 win_attributes_
->ia2_attributes
.push_back(
3076 L
"invalid:" + aria_invalid_value
);
3078 // Set the attribute to L"true", since we cannot be more specific.
3079 win_attributes_
->ia2_attributes
.push_back(L
"invalid:true");
3088 // Expose row or column header sort direction.
3089 int32 sort_direction
;
3090 if ((ia_role() == ROLE_SYSTEM_COLUMNHEADER
||
3091 ia_role() == ROLE_SYSTEM_ROWHEADER
) &&
3092 GetIntAttribute(ui::AX_ATTR_SORT_DIRECTION
, &sort_direction
)) {
3093 switch (sort_direction
) {
3094 case ui::AX_SORT_DIRECTION_UNSORTED
:
3095 win_attributes_
->ia2_attributes
.push_back(L
"sort:none");
3097 case ui::AX_SORT_DIRECTION_ASCENDING
:
3098 win_attributes_
->ia2_attributes
.push_back(L
"sort:ascending");
3100 case ui::AX_SORT_DIRECTION_DESCENDING
:
3101 win_attributes_
->ia2_attributes
.push_back(L
"sort:descending");
3103 case ui::AX_SORT_DIRECTION_OTHER
:
3104 win_attributes_
->ia2_attributes
.push_back(L
"sort:other");
3111 // The calculation of the accessible name of an element has been
3112 // standardized in the HTML to Platform Accessibility APIs Implementation
3113 // Guide (http://www.w3.org/TR/html-aapi/). In order to return the
3114 // appropriate accessible name on Windows, we need to apply some logic
3115 // to the fields we get from WebKit.
3117 // TODO(dmazzoni): move most of this logic into WebKit.
3121 // name: the default name, e.g. inner text
3122 // title ui element: a reference to a <label> element on the same
3123 // page that labels this node.
3124 // description: accessible labels that override the default name:
3125 // aria-label or aria-labelledby or aria-describedby
3126 // help: the value of the "title" attribute
3128 // On Windows, the logic we apply lets some fields take precedence and
3129 // always returns the primary name in "name" and the secondary name,
3130 // if any, in "description".
3132 int title_elem_id
= GetIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT
);
3133 base::string16 name
= GetString16Attribute(ui::AX_ATTR_NAME
);
3134 base::string16 description
= GetString16Attribute(ui::AX_ATTR_DESCRIPTION
);
3135 base::string16 help
= GetString16Attribute(ui::AX_ATTR_HELP
);
3136 base::string16 value
= GetString16Attribute(ui::AX_ATTR_VALUE
);
3138 // WebKit annoyingly puts the title in the description if there's no other
3139 // description, which just confuses the rest of the logic. Put it back.
3140 // Now "help" is always the value of the "title" attribute, if present.
3141 base::string16 title_attr
;
3142 if (GetHtmlAttribute("title", &title_attr
) &&
3143 description
== title_attr
&&
3146 description
.clear();
3149 // Now implement the main logic: the descripion should become the name if
3150 // it's nonempty, and the help should become the description if
3151 // there's no description - or the name if there's no name or description.
3152 if (!description
.empty()) {
3154 description
.clear();
3156 if (!help
.empty() && description
.empty()) {
3160 if (!description
.empty() && name
.empty() && !title_elem_id
) {
3162 description
.clear();
3165 // If it's a text field, also consider the placeholder.
3166 base::string16 placeholder
;
3167 if (GetRole() == ui::AX_ROLE_TEXT_FIELD
&&
3168 HasState(ui::AX_STATE_FOCUSABLE
) &&
3169 GetHtmlAttribute("placeholder", &placeholder
)) {
3170 if (name
.empty() && !title_elem_id
) {
3172 } else if (description
.empty()) {
3173 description
= placeholder
;
3177 // On Windows, the value of a document should be its url.
3178 if (GetRole() == ui::AX_ROLE_ROOT_WEB_AREA
||
3179 GetRole() == ui::AX_ROLE_WEB_AREA
) {
3180 value
= GetString16Attribute(ui::AX_ATTR_DOC_URL
);
3183 // For certain roles (listbox option, static text, and list marker)
3184 // WebKit stores the main accessible text in the "value" - swap it so
3185 // that it's the "name".
3187 (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
||
3188 GetRole() == ui::AX_ROLE_STATIC_TEXT
||
3189 GetRole() == ui::AX_ROLE_LIST_MARKER
)) {
3190 base::string16 tmp
= value
;
3195 // If this doesn't have a value and is linked then set its value to the url
3196 // attribute. This allows screen readers to read an empty link's destination.
3197 if (value
.empty() && (ia_state() & STATE_SYSTEM_LINKED
))
3198 value
= GetString16Attribute(ui::AX_ATTR_URL
);
3200 win_attributes_
->name
= name
;
3201 win_attributes_
->description
= description
;
3202 win_attributes_
->help
= help
;
3203 win_attributes_
->value
= value
;
3205 // Clear any old relationships between this node and other nodes.
3206 for (size_t i
= 0; i
< relations_
.size(); ++i
)
3207 relations_
[i
]->Release();
3210 // Handle title UI element.
3211 if (title_elem_id
) {
3212 // Add a labelled by relationship.
3213 CComObject
<BrowserAccessibilityRelation
>* relation
;
3214 HRESULT hr
= CComObject
<BrowserAccessibilityRelation
>::CreateInstance(
3216 DCHECK(SUCCEEDED(hr
));
3218 relation
->Initialize(this, IA2_RELATION_LABELLED_BY
);
3219 relation
->AddTarget(title_elem_id
);
3220 relations_
.push_back(relation
);
3223 // Expose slider value.
3224 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR
||
3225 ia_role() == ROLE_SYSTEM_SCROLLBAR
||
3226 ia_role() == ROLE_SYSTEM_SLIDER
) {
3227 win_attributes_
->ia2_attributes
.push_back(L
"valuetext:" + GetValueText());
3230 // If this is a web area for a presentational iframe, give it a role of
3231 // something other than DOCUMENT so that the fact that it's a separate doc
3232 // is not exposed to AT.
3233 if (IsWebAreaForPresentationalIframe()) {
3234 win_attributes_
->ia_role
= ROLE_SYSTEM_GROUPING
;
3235 win_attributes_
->ia2_role
= ROLE_SYSTEM_GROUPING
;
3239 void BrowserAccessibilityWin::UpdateStep2ComputeHypertext() {
3240 // Construct the hypertext for this node, which contains the concatenation
3241 // of all of the static text of this node's children and an embedded object
3242 // character for all non-static-text children. Build up a map from the
3243 // character index of each embedded object character to the id of the
3244 // child object it points to.
3245 for (unsigned int i
= 0; i
< PlatformChildCount(); ++i
) {
3246 BrowserAccessibilityWin
* child
=
3247 PlatformGetChild(i
)->ToBrowserAccessibilityWin();
3248 if (child
->GetRole() == ui::AX_ROLE_STATIC_TEXT
) {
3249 win_attributes_
->hypertext
+= child
->name();
3251 int32 char_offset
= hypertext().size();
3252 int32 child_id
= child
->GetId();
3253 int32 index
= hyperlinks().size();
3254 win_attributes_
->hyperlink_offset_to_index
[char_offset
] = index
;
3255 win_attributes_
->hyperlinks
.push_back(child_id
);
3256 win_attributes_
->hypertext
+= kEmbeddedCharacter
;
3261 void BrowserAccessibilityWin::UpdateStep3FireEvents(bool is_subtree_creation
) {
3262 BrowserAccessibilityManagerWin
* manager
=
3263 this->manager()->ToBrowserAccessibilityManagerWin();
3265 // Fire an event when an alert first appears.
3266 if (ia_role() == ROLE_SYSTEM_ALERT
&&
3267 old_win_attributes_
->ia_role
!= ROLE_SYSTEM_ALERT
) {
3268 manager
->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT
, this);
3271 // Fire an event when a new subtree is created.
3272 if (is_subtree_creation
)
3273 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SHOW
, this);
3275 // The rest of the events only fire on changes, not on new objects.
3276 if (old_win_attributes_
->ia_role
!= 0 ||
3277 !old_win_attributes_
->role_name
.empty()) {
3278 // Fire an event if the name, description, help, or value changes.
3279 if (name() != old_win_attributes_
->name
)
3280 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, this);
3281 if (description() != old_win_attributes_
->description
)
3282 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_DESCRIPTIONCHANGE
, this);
3283 if (help() != old_win_attributes_
->help
)
3284 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_HELPCHANGE
, this);
3285 if (value() != old_win_attributes_
->value
)
3286 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_VALUECHANGE
, this);
3287 if (ia_state() != old_win_attributes_
->ia_state
)
3288 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, this);
3290 // Normally focus events are handled elsewhere, however
3291 // focus for managed descendants is platform-specific.
3292 // Fire a focus event if the focused descendant in a multi-select
3293 // list box changes.
3294 if (GetRole() == ui::AX_ROLE_LIST_BOX_OPTION
&&
3295 (ia_state() & STATE_SYSTEM_FOCUSABLE
) &&
3296 (ia_state() & STATE_SYSTEM_SELECTABLE
) &&
3297 (ia_state() & STATE_SYSTEM_FOCUSED
) &&
3298 !(old_win_attributes_
->ia_state
& STATE_SYSTEM_FOCUSED
)) {
3299 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_FOCUS
, this);
3302 // Handle selection being added or removed.
3303 bool is_selected_now
= (ia_state() & STATE_SYSTEM_SELECTED
) != 0;
3304 bool was_selected_before
=
3305 (old_win_attributes_
->ia_state
& STATE_SYSTEM_SELECTED
) != 0;
3306 if (is_selected_now
&& !was_selected_before
) {
3307 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTIONADD
, this);
3308 } else if (!is_selected_now
&& was_selected_before
) {
3309 manager
->MaybeCallNotifyWinEvent(EVENT_OBJECT_SELECTIONREMOVE
, this);
3312 // Fire an event if this container object has scrolled.
3315 if (GetIntAttribute(ui::AX_ATTR_SCROLL_X
, &sx
) &&
3316 GetIntAttribute(ui::AX_ATTR_SCROLL_Y
, &sy
)) {
3317 if (sx
!= previous_scroll_x_
|| sy
!= previous_scroll_y_
)
3318 manager
->MaybeCallNotifyWinEvent(EVENT_SYSTEM_SCROLLINGEND
, this);
3319 previous_scroll_x_
= sx
;
3320 previous_scroll_y_
= sy
;
3323 // Changing a static text node can affect the IAccessibleText hypertext
3324 // of the parent node, so force an update on the parent.
3325 BrowserAccessibilityWin
* parent
= GetParent()->ToBrowserAccessibilityWin();
3327 GetRole() == ui::AX_ROLE_STATIC_TEXT
&&
3328 name() != old_win_attributes_
->name
) {
3329 parent
->UpdateStep1ComputeWinAttributes();
3330 parent
->UpdateStep2ComputeHypertext();
3331 parent
->UpdateStep3FireEvents(false);
3334 // Fire hypertext-related events.
3335 int start
, old_len
, new_len
;
3336 ComputeHypertextRemovedAndInserted(&start
, &old_len
, &new_len
);
3338 // In-process screen readers may call IAccessibleText::get_oldText
3339 // in reaction to this event to retrieve the text that was removed.
3340 manager
->MaybeCallNotifyWinEvent(IA2_EVENT_TEXT_REMOVED
, this);
3343 // In-process screen readers may call IAccessibleText::get_newText
3344 // in reaction to this event to retrieve the text that was inserted.
3345 manager
->MaybeCallNotifyWinEvent(IA2_EVENT_TEXT_INSERTED
, this);
3349 old_win_attributes_
.reset(nullptr);
3352 void BrowserAccessibilityWin::OnSubtreeWillBeDeleted() {
3353 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3354 EVENT_OBJECT_HIDE
, this);
3357 void BrowserAccessibilityWin::NativeAddReference() {
3361 void BrowserAccessibilityWin::NativeReleaseReference() {
3365 bool BrowserAccessibilityWin::IsNative() const {
3369 void BrowserAccessibilityWin::OnLocationChanged() {
3370 manager()->ToBrowserAccessibilityManagerWin()->MaybeCallNotifyWinEvent(
3371 EVENT_OBJECT_LOCATIONCHANGE
, this);
3374 BrowserAccessibilityWin
* BrowserAccessibilityWin::NewReference() {
3379 BrowserAccessibilityWin
* BrowserAccessibilityWin::GetTargetFromChildID(
3380 const VARIANT
& var_id
) {
3381 if (var_id
.vt
!= VT_I4
)
3384 LONG child_id
= var_id
.lVal
;
3385 if (child_id
== CHILDID_SELF
)
3388 if (child_id
>= 1 && child_id
<= static_cast<LONG
>(PlatformChildCount()))
3389 return PlatformGetChild(child_id
- 1)->ToBrowserAccessibilityWin();
3391 return manager()->ToBrowserAccessibilityManagerWin()->
3392 GetFromUniqueIdWin(child_id
);
3395 HRESULT
BrowserAccessibilityWin::GetStringAttributeAsBstr(
3396 ui::AXStringAttribute attribute
,
3400 if (!GetString16Attribute(attribute
, &str
))
3406 *value_bstr
= SysAllocString(str
.c_str());
3407 DCHECK(*value_bstr
);
3412 void BrowserAccessibilityWin::StringAttributeToIA2(
3413 ui::AXStringAttribute attribute
,
3414 const char* ia2_attr
) {
3415 base::string16 value
;
3416 if (GetString16Attribute(attribute
, &value
)) {
3417 win_attributes_
->ia2_attributes
.push_back(
3418 base::ASCIIToUTF16(ia2_attr
) + L
":" + value
);
3422 void BrowserAccessibilityWin::BoolAttributeToIA2(
3423 ui::AXBoolAttribute attribute
,
3424 const char* ia2_attr
) {
3426 if (GetBoolAttribute(attribute
, &value
)) {
3427 win_attributes_
->ia2_attributes
.push_back(
3428 (base::ASCIIToUTF16(ia2_attr
) + L
":") +
3429 (value
? L
"true" : L
"false"));
3433 void BrowserAccessibilityWin::IntAttributeToIA2(
3434 ui::AXIntAttribute attribute
,
3435 const char* ia2_attr
) {
3437 if (GetIntAttribute(attribute
, &value
)) {
3438 win_attributes_
->ia2_attributes
.push_back(
3439 base::ASCIIToUTF16(ia2_attr
) + L
":" +
3440 base::IntToString16(value
));
3444 base::string16
BrowserAccessibilityWin::GetNameRecursive() const {
3445 if (!name().empty()) {
3449 base::string16 result
;
3450 for (uint32 i
= 0; i
< PlatformChildCount(); ++i
) {
3451 result
+= PlatformGetChild(i
)->ToBrowserAccessibilityWin()->
3457 base::string16
BrowserAccessibilityWin::GetValueText() {
3459 base::string16 value
= this->value();
3461 if (value
.empty() &&
3462 GetFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE
, &fval
)) {
3463 value
= base::UTF8ToUTF16(base::DoubleToString(fval
));
3468 base::string16
BrowserAccessibilityWin::TextForIAccessibleText() {
3469 if (IsEditableText())
3471 return (GetRole() == ui::AX_ROLE_STATIC_TEXT
) ? name() : hypertext();
3474 bool BrowserAccessibilityWin::IsSameHypertextCharacter(size_t old_char_index
,
3475 size_t new_char_index
) {
3476 CHECK(old_win_attributes_
);
3478 // For anything other than the "embedded character", we just compare the
3479 // characters directly.
3480 base::char16 old_ch
= old_win_attributes_
->hypertext
[old_char_index
];
3481 base::char16 new_ch
= win_attributes_
->hypertext
[new_char_index
];
3482 if (old_ch
!= new_ch
)
3484 if (old_ch
== new_ch
&& new_ch
!= kEmbeddedCharacter
)
3487 // If it's an embedded character, they're only identical if the child id
3488 // the hyperlink points to is the same.
3489 std::map
<int32
, int32
>& old_offset_to_index
=
3490 old_win_attributes_
->hyperlink_offset_to_index
;
3491 std::vector
<int32
>& old_hyperlinks
= old_win_attributes_
->hyperlinks
;
3492 int32 old_hyperlinks_count
= static_cast<int32
>(old_hyperlinks
.size());
3493 std::map
<int32
, int32
>::iterator iter
;
3494 iter
= old_offset_to_index
.find(old_char_index
);
3495 int old_index
= (iter
!= old_offset_to_index
.end()) ? iter
->second
: -1;
3496 int old_child_id
= (old_index
>= 0 && old_index
< old_hyperlinks_count
) ?
3497 old_hyperlinks
[old_index
] : -1;
3499 std::map
<int32
, int32
>& new_offset_to_index
=
3500 win_attributes_
->hyperlink_offset_to_index
;
3501 std::vector
<int32
>& new_hyperlinks
= win_attributes_
->hyperlinks
;
3502 int32 new_hyperlinks_count
= static_cast<int32
>(new_hyperlinks
.size());
3503 iter
= new_offset_to_index
.find(new_char_index
);
3504 int new_index
= (iter
!= new_offset_to_index
.end()) ? iter
->second
: -1;
3505 int new_child_id
= (new_index
>= 0 && new_index
< new_hyperlinks_count
) ?
3506 new_hyperlinks
[new_index
] : -1;
3508 return old_child_id
== new_child_id
;
3511 void BrowserAccessibilityWin::ComputeHypertextRemovedAndInserted(
3512 int* start
, int* old_len
, int* new_len
) {
3513 CHECK(old_win_attributes_
);
3519 const base::string16
& old_text
= old_win_attributes_
->hypertext
;
3520 const base::string16
& new_text
= hypertext();
3522 size_t common_prefix
= 0;
3523 while (common_prefix
< old_text
.size() &&
3524 common_prefix
< new_text
.size() &&
3525 IsSameHypertextCharacter(common_prefix
, common_prefix
)) {
3529 size_t common_suffix
= 0;
3530 while (common_prefix
+ common_suffix
< old_text
.size() &&
3531 common_prefix
+ common_suffix
< new_text
.size() &&
3532 IsSameHypertextCharacter(
3533 old_text
.size() - common_suffix
- 1,
3534 new_text
.size() - common_suffix
- 1)) {
3538 *start
= common_prefix
;
3539 *old_len
= old_text
.size() - common_prefix
- common_suffix
;
3540 *new_len
= new_text
.size() - common_prefix
- common_suffix
;
3543 void BrowserAccessibilityWin::HandleSpecialTextOffset(
3544 const base::string16
& text
,
3546 if (*offset
== IA2_TEXT_OFFSET_LENGTH
)
3547 *offset
= static_cast<LONG
>(text
.size());
3548 else if (*offset
== IA2_TEXT_OFFSET_CARET
)
3549 get_caretOffset(offset
);
3552 ui::TextBoundaryType
BrowserAccessibilityWin::IA2TextBoundaryToTextBoundary(
3553 IA2TextBoundaryType ia2_boundary
) {
3554 switch(ia2_boundary
) {
3555 case IA2_TEXT_BOUNDARY_CHAR
:
3556 return ui::CHAR_BOUNDARY
;
3557 case IA2_TEXT_BOUNDARY_WORD
:
3558 return ui::WORD_BOUNDARY
;
3559 case IA2_TEXT_BOUNDARY_LINE
:
3560 return ui::LINE_BOUNDARY
;
3561 case IA2_TEXT_BOUNDARY_SENTENCE
:
3562 return ui::SENTENCE_BOUNDARY
;
3563 case IA2_TEXT_BOUNDARY_PARAGRAPH
:
3564 return ui::PARAGRAPH_BOUNDARY
;
3565 case IA2_TEXT_BOUNDARY_ALL
:
3566 return ui::ALL_BOUNDARY
;
3570 return ui::CHAR_BOUNDARY
;
3573 LONG
BrowserAccessibilityWin::FindBoundary(
3574 const base::string16
& text
,
3575 IA2TextBoundaryType ia2_boundary
,
3577 ui::TextBoundaryDirection direction
) {
3578 HandleSpecialTextOffset(text
, &start_offset
);
3579 if (ia2_boundary
== IA2_TEXT_BOUNDARY_WORD
&&
3580 GetRole() == ui::AX_ROLE_TEXT_FIELD
) {
3581 return GetWordStartBoundary(static_cast<int>(start_offset
), direction
);
3584 ui::TextBoundaryType boundary
= IA2TextBoundaryToTextBoundary(ia2_boundary
);
3585 const std::vector
<int32
>& line_breaks
= GetIntListAttribute(
3586 ui::AX_ATTR_LINE_BREAKS
);
3587 return ui::FindAccessibleTextBoundary(
3588 text
, line_breaks
, boundary
, start_offset
, direction
);
3591 BrowserAccessibilityWin
* BrowserAccessibilityWin::GetFromID(int32 id
) {
3592 return manager()->GetFromID(id
)->ToBrowserAccessibilityWin();
3595 void BrowserAccessibilityWin::InitRoleAndState() {
3598 base::string16 role_name
;
3600 int32 ia2_state
= IA2_STATE_OPAQUE
;
3602 if (HasState(ui::AX_STATE_BUSY
))
3603 ia_state
|= STATE_SYSTEM_BUSY
;
3604 if (HasState(ui::AX_STATE_CHECKED
))
3605 ia_state
|= STATE_SYSTEM_CHECKED
;
3606 if (HasState(ui::AX_STATE_COLLAPSED
))
3607 ia_state
|= STATE_SYSTEM_COLLAPSED
;
3608 if (HasState(ui::AX_STATE_EXPANDED
))
3609 ia_state
|= STATE_SYSTEM_EXPANDED
;
3610 if (HasState(ui::AX_STATE_FOCUSABLE
))
3611 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3612 if (HasState(ui::AX_STATE_HASPOPUP
))
3613 ia_state
|= STATE_SYSTEM_HASPOPUP
;
3614 if (HasState(ui::AX_STATE_INDETERMINATE
))
3615 ia_state
|= STATE_SYSTEM_INDETERMINATE
;
3616 if (HasIntAttribute(ui::AX_ATTR_INVALID_STATE
) &&
3617 GetIntAttribute(ui::AX_ATTR_INVALID_STATE
) != ui::AX_INVALID_STATE_FALSE
)
3618 ia2_state
|= IA2_STATE_INVALID_ENTRY
;
3619 if (HasState(ui::AX_STATE_INVISIBLE
))
3620 ia_state
|= STATE_SYSTEM_INVISIBLE
;
3621 if (HasState(ui::AX_STATE_LINKED
))
3622 ia_state
|= STATE_SYSTEM_LINKED
;
3623 if (HasState(ui::AX_STATE_MULTISELECTABLE
)) {
3624 ia_state
|= STATE_SYSTEM_EXTSELECTABLE
;
3625 ia_state
|= STATE_SYSTEM_MULTISELECTABLE
;
3627 // TODO(ctguil): Support STATE_SYSTEM_EXTSELECTABLE/accSelect.
3628 if (HasState(ui::AX_STATE_OFFSCREEN
))
3629 ia_state
|= STATE_SYSTEM_OFFSCREEN
;
3630 if (HasState(ui::AX_STATE_PRESSED
))
3631 ia_state
|= STATE_SYSTEM_PRESSED
;
3632 if (HasState(ui::AX_STATE_PROTECTED
))
3633 ia_state
|= STATE_SYSTEM_PROTECTED
;
3634 if (HasState(ui::AX_STATE_REQUIRED
))
3635 ia2_state
|= IA2_STATE_REQUIRED
;
3636 if (HasState(ui::AX_STATE_SELECTABLE
))
3637 ia_state
|= STATE_SYSTEM_SELECTABLE
;
3638 if (HasState(ui::AX_STATE_SELECTED
))
3639 ia_state
|= STATE_SYSTEM_SELECTED
;
3640 if (HasState(ui::AX_STATE_VISITED
))
3641 ia_state
|= STATE_SYSTEM_TRAVERSED
;
3642 if (!HasState(ui::AX_STATE_ENABLED
))
3643 ia_state
|= STATE_SYSTEM_UNAVAILABLE
;
3644 if (HasState(ui::AX_STATE_VERTICAL
))
3645 ia2_state
|= IA2_STATE_VERTICAL
;
3646 if (HasState(ui::AX_STATE_HORIZONTAL
))
3647 ia2_state
|= IA2_STATE_HORIZONTAL
;
3648 if (HasState(ui::AX_STATE_VISITED
))
3649 ia_state
|= STATE_SYSTEM_TRAVERSED
;
3651 // Expose whether or not the mouse is over an element, but suppress
3652 // this for tests because it can make the test results flaky depending
3653 // on the position of the mouse.
3654 BrowserAccessibilityStateImpl
* accessibility_state
=
3655 BrowserAccessibilityStateImpl::GetInstance();
3656 if (!accessibility_state
->disable_hot_tracking_for_testing()) {
3657 if (HasState(ui::AX_STATE_HOVERED
))
3658 ia_state
|= STATE_SYSTEM_HOTTRACKED
;
3661 // WebKit marks everything as readonly unless it's editable text, so if it's
3662 // not readonly, mark it as editable now. The final computation of the
3663 // READONLY state for MSAA is below, after the switch.
3664 if (!HasState(ui::AX_STATE_READ_ONLY
))
3665 ia2_state
|= IA2_STATE_EDITABLE
;
3667 if (GetBoolAttribute(ui::AX_ATTR_BUTTON_MIXED
))
3668 ia_state
|= STATE_SYSTEM_MIXED
;
3670 if (GetBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE
))
3671 ia2_state
|= IA2_STATE_EDITABLE
;
3673 if (!GetStringAttribute(ui::AX_ATTR_AUTO_COMPLETE
).empty())
3674 ia2_state
|= IA2_STATE_SUPPORTS_AUTOCOMPLETION
;
3676 base::string16 html_tag
= GetString16Attribute(
3677 ui::AX_ATTR_HTML_TAG
);
3678 switch (GetRole()) {
3679 case ui::AX_ROLE_ALERT
:
3680 ia_role
= ROLE_SYSTEM_ALERT
;
3682 case ui::AX_ROLE_ALERT_DIALOG
:
3683 ia_role
= ROLE_SYSTEM_DIALOG
;
3685 case ui::AX_ROLE_APPLICATION
:
3686 ia_role
= ROLE_SYSTEM_APPLICATION
;
3688 case ui::AX_ROLE_ARTICLE
:
3689 ia_role
= ROLE_SYSTEM_DOCUMENT
;
3690 ia_state
|= STATE_SYSTEM_READONLY
;
3692 case ui::AX_ROLE_BANNER
:
3693 ia_role
= ROLE_SYSTEM_GROUPING
;
3694 ia2_role
= IA2_ROLE_HEADER
;
3696 case ui::AX_ROLE_BLOCKQUOTE
:
3697 role_name
= html_tag
;
3698 ia2_role
= IA2_ROLE_SECTION
;
3700 case ui::AX_ROLE_BUSY_INDICATOR
:
3701 ia_role
= ROLE_SYSTEM_ANIMATION
;
3702 ia_state
|= STATE_SYSTEM_READONLY
;
3704 case ui::AX_ROLE_BUTTON
:
3705 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
3707 case ui::AX_ROLE_CANVAS
:
3708 if (GetBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK
)) {
3709 role_name
= L
"canvas";
3710 ia2_role
= IA2_ROLE_CANVAS
;
3712 ia_role
= ROLE_SYSTEM_GRAPHIC
;
3715 case ui::AX_ROLE_CAPTION
:
3716 ia_role
= ROLE_SYSTEM_TEXT
;
3717 ia2_role
= IA2_ROLE_CAPTION
;
3719 case ui::AX_ROLE_CELL
:
3720 ia_role
= ROLE_SYSTEM_CELL
;
3722 case ui::AX_ROLE_CHECK_BOX
:
3723 ia_role
= ROLE_SYSTEM_CHECKBUTTON
;
3724 ia2_state
|= IA2_STATE_CHECKABLE
;
3726 case ui::AX_ROLE_COLOR_WELL
:
3727 ia_role
= ROLE_SYSTEM_TEXT
;
3728 ia2_role
= IA2_ROLE_COLOR_CHOOSER
;
3730 case ui::AX_ROLE_COLUMN
:
3731 ia_role
= ROLE_SYSTEM_COLUMN
;
3733 case ui::AX_ROLE_COLUMN_HEADER
:
3734 ia_role
= ROLE_SYSTEM_COLUMNHEADER
;
3736 case ui::AX_ROLE_COMBO_BOX
:
3737 ia_role
= ROLE_SYSTEM_COMBOBOX
;
3739 case ui::AX_ROLE_COMPLEMENTARY
:
3740 ia_role
= ROLE_SYSTEM_GROUPING
;
3741 ia2_role
= IA2_ROLE_NOTE
;
3743 case ui::AX_ROLE_CONTENT_INFO
:
3744 ia_role
= ROLE_SYSTEM_TEXT
;
3745 ia2_role
= IA2_ROLE_PARAGRAPH
;
3747 case ui::AX_ROLE_DATE
:
3748 case ui::AX_ROLE_DATE_TIME
:
3749 ia_role
= ROLE_SYSTEM_DROPLIST
;
3750 ia2_role
= IA2_ROLE_DATE_EDITOR
;
3752 case ui::AX_ROLE_DIV
:
3754 ia_role
= ROLE_SYSTEM_GROUPING
;
3755 ia2_role
= IA2_ROLE_SECTION
;
3757 case ui::AX_ROLE_DEFINITION
:
3758 role_name
= html_tag
;
3759 ia2_role
= IA2_ROLE_PARAGRAPH
;
3760 ia_state
|= STATE_SYSTEM_READONLY
;
3762 case ui::AX_ROLE_DESCRIPTION_LIST_DETAIL
:
3763 role_name
= html_tag
;
3764 ia_role
= ROLE_SYSTEM_TEXT
;
3765 ia2_role
= IA2_ROLE_PARAGRAPH
;
3767 case ui::AX_ROLE_DESCRIPTION_LIST
:
3768 role_name
= html_tag
;
3769 ia_role
= ROLE_SYSTEM_LIST
;
3770 ia_state
|= STATE_SYSTEM_READONLY
;
3772 case ui::AX_ROLE_DESCRIPTION_LIST_TERM
:
3773 ia_role
= ROLE_SYSTEM_LISTITEM
;
3774 ia_state
|= STATE_SYSTEM_READONLY
;
3776 case ui::AX_ROLE_DETAILS
:
3777 role_name
= html_tag
;
3778 ia_role
= ROLE_SYSTEM_GROUPING
;
3780 case ui::AX_ROLE_DIALOG
:
3781 ia_role
= ROLE_SYSTEM_DIALOG
;
3783 case ui::AX_ROLE_DISCLOSURE_TRIANGLE
:
3784 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
3786 case ui::AX_ROLE_DOCUMENT
:
3787 case ui::AX_ROLE_ROOT_WEB_AREA
:
3788 case ui::AX_ROLE_WEB_AREA
:
3789 ia_role
= ROLE_SYSTEM_DOCUMENT
;
3790 ia_state
|= STATE_SYSTEM_READONLY
;
3791 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3793 case ui::AX_ROLE_EMBEDDED_OBJECT
:
3794 ia_role
= ROLE_SYSTEM_CLIENT
;
3795 ia2_role
= IA2_ROLE_EMBEDDED_OBJECT
;
3797 case ui::AX_ROLE_FIGCAPTION
:
3798 role_name
= html_tag
;
3799 ia2_role
= IA2_ROLE_CAPTION
;
3801 case ui::AX_ROLE_FIGURE
:
3802 ia_role
= ROLE_SYSTEM_GROUPING
;
3804 case ui::AX_ROLE_FORM
:
3805 role_name
= L
"form";
3806 ia2_role
= IA2_ROLE_FORM
;
3808 case ui::AX_ROLE_FOOTER
:
3809 ia_role
= ROLE_SYSTEM_GROUPING
;
3810 ia2_role
= IA2_ROLE_FOOTER
;
3812 case ui::AX_ROLE_GRID
:
3813 ia_role
= ROLE_SYSTEM_TABLE
;
3814 ia_state
|= STATE_SYSTEM_READONLY
;
3816 case ui::AX_ROLE_GROUP
: {
3817 base::string16 aria_role
= GetString16Attribute(
3819 if (aria_role
== L
"group" || html_tag
== L
"fieldset") {
3820 ia_role
= ROLE_SYSTEM_GROUPING
;
3821 } else if (html_tag
== L
"li") {
3822 ia_role
= ROLE_SYSTEM_LISTITEM
;
3823 ia_state
|= STATE_SYSTEM_READONLY
;
3825 if (html_tag
.empty())
3828 role_name
= html_tag
;
3829 ia2_role
= IA2_ROLE_SECTION
;
3833 case ui::AX_ROLE_HEADING
:
3834 role_name
= html_tag
;
3835 ia2_role
= IA2_ROLE_HEADING
;
3837 case ui::AX_ROLE_IFRAME
:
3838 ia_role
= ROLE_SYSTEM_DOCUMENT
;
3839 ia2_role
= IA2_ROLE_INTERNAL_FRAME
;
3840 ia_state
= STATE_SYSTEM_READONLY
;
3842 case ui::AX_ROLE_IFRAME_PRESENTATIONAL
:
3843 ia_role
= ROLE_SYSTEM_GROUPING
;
3845 case ui::AX_ROLE_IMAGE
:
3846 ia_role
= ROLE_SYSTEM_GRAPHIC
;
3847 ia_state
|= STATE_SYSTEM_READONLY
;
3849 case ui::AX_ROLE_IMAGE_MAP
:
3850 role_name
= html_tag
;
3851 ia2_role
= IA2_ROLE_IMAGE_MAP
;
3852 ia_state
|= STATE_SYSTEM_READONLY
;
3854 case ui::AX_ROLE_IMAGE_MAP_LINK
:
3855 ia_role
= ROLE_SYSTEM_LINK
;
3856 ia_state
|= STATE_SYSTEM_LINKED
;
3857 ia_state
|= STATE_SYSTEM_READONLY
;
3859 case ui::AX_ROLE_LABEL_TEXT
:
3860 case ui::AX_ROLE_LEGEND
:
3861 ia_role
= ROLE_SYSTEM_TEXT
;
3862 ia2_role
= IA2_ROLE_LABEL
;
3864 case ui::AX_ROLE_SEARCH
:
3865 ia_role
= ROLE_SYSTEM_GROUPING
;
3866 ia2_role
= IA2_ROLE_SECTION
;
3868 case ui::AX_ROLE_LINK
:
3869 ia_role
= ROLE_SYSTEM_LINK
;
3870 ia_state
|= STATE_SYSTEM_LINKED
;
3872 case ui::AX_ROLE_LIST
:
3873 ia_role
= ROLE_SYSTEM_LIST
;
3874 ia_state
|= STATE_SYSTEM_READONLY
;
3876 case ui::AX_ROLE_LIST_BOX
:
3877 ia_role
= ROLE_SYSTEM_LIST
;
3879 case ui::AX_ROLE_LIST_BOX_OPTION
:
3880 ia_role
= ROLE_SYSTEM_LISTITEM
;
3881 if (ia_state
& STATE_SYSTEM_SELECTABLE
) {
3882 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3883 if (HasState(ui::AX_STATE_FOCUSED
))
3884 ia_state
|= STATE_SYSTEM_FOCUSED
;
3887 case ui::AX_ROLE_LIST_ITEM
:
3888 ia_role
= ROLE_SYSTEM_LISTITEM
;
3889 ia_state
|= STATE_SYSTEM_READONLY
;
3891 case ui::AX_ROLE_MAIN
:
3892 ia_role
= ROLE_SYSTEM_GROUPING
;
3893 ia2_role
= IA2_ROLE_PARAGRAPH
;
3895 case ui::AX_ROLE_MARQUEE
:
3896 ia_role
= ROLE_SYSTEM_ANIMATION
;
3898 case ui::AX_ROLE_MATH
:
3899 ia_role
= ROLE_SYSTEM_EQUATION
;
3901 case ui::AX_ROLE_MENU
:
3902 case ui::AX_ROLE_MENU_BUTTON
:
3903 ia_role
= ROLE_SYSTEM_MENUPOPUP
;
3905 case ui::AX_ROLE_MENU_BAR
:
3906 ia_role
= ROLE_SYSTEM_MENUBAR
;
3908 case ui::AX_ROLE_MENU_ITEM
:
3909 ia_role
= ROLE_SYSTEM_MENUITEM
;
3911 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX
:
3912 ia_role
= ROLE_SYSTEM_MENUITEM
;
3913 ia2_role
= IA2_ROLE_CHECK_MENU_ITEM
;
3914 ia2_state
|= IA2_STATE_CHECKABLE
;
3916 case ui::AX_ROLE_MENU_ITEM_RADIO
:
3917 ia_role
= ROLE_SYSTEM_MENUITEM
;
3918 ia2_role
= IA2_ROLE_RADIO_MENU_ITEM
;
3920 case ui::AX_ROLE_MENU_LIST_POPUP
:
3921 ia_role
= ROLE_SYSTEM_CLIENT
;
3923 case ui::AX_ROLE_MENU_LIST_OPTION
:
3924 ia_role
= ROLE_SYSTEM_LISTITEM
;
3925 if (ia_state
& STATE_SYSTEM_SELECTABLE
) {
3926 ia_state
|= STATE_SYSTEM_FOCUSABLE
;
3927 if (HasState(ui::AX_STATE_FOCUSED
))
3928 ia_state
|= STATE_SYSTEM_FOCUSED
;
3931 case ui::AX_ROLE_METER
:
3932 role_name
= html_tag
;
3933 ia_role
= ROLE_SYSTEM_PROGRESSBAR
;
3935 case ui::AX_ROLE_NAVIGATION
:
3936 ia_role
= ROLE_SYSTEM_GROUPING
;
3937 ia2_role
= IA2_ROLE_SECTION
;
3939 case ui::AX_ROLE_NOTE
:
3940 ia_role
= ROLE_SYSTEM_GROUPING
;
3941 ia2_role
= IA2_ROLE_NOTE
;
3943 case ui::AX_ROLE_OUTLINE
:
3944 ia_role
= ROLE_SYSTEM_OUTLINE
;
3946 case ui::AX_ROLE_PARAGRAPH
:
3948 ia2_role
= IA2_ROLE_PARAGRAPH
;
3950 case ui::AX_ROLE_POP_UP_BUTTON
:
3951 if (html_tag
== L
"select") {
3952 ia_role
= ROLE_SYSTEM_COMBOBOX
;
3954 ia_role
= ROLE_SYSTEM_BUTTONMENU
;
3957 case ui::AX_ROLE_PRE
:
3958 role_name
= html_tag
;
3959 ia_role
= ROLE_SYSTEM_TEXT
;
3960 ia2_role
= IA2_ROLE_PARAGRAPH
;
3962 case ui::AX_ROLE_PROGRESS_INDICATOR
:
3963 ia_role
= ROLE_SYSTEM_PROGRESSBAR
;
3964 ia_state
|= STATE_SYSTEM_READONLY
;
3966 case ui::AX_ROLE_RADIO_BUTTON
:
3967 ia_role
= ROLE_SYSTEM_RADIOBUTTON
;
3968 ia2_state
= IA2_STATE_CHECKABLE
;
3970 case ui::AX_ROLE_RADIO_GROUP
:
3971 ia_role
= ROLE_SYSTEM_GROUPING
;
3973 case ui::AX_ROLE_REGION
:
3974 if (html_tag
== L
"section") {
3975 ia_role
= ROLE_SYSTEM_GROUPING
;
3976 ia2_role
= IA2_ROLE_SECTION
;
3978 ia_role
= ROLE_SYSTEM_PANE
;
3981 case ui::AX_ROLE_ROW
:
3982 ia_role
= ROLE_SYSTEM_ROW
;
3984 case ui::AX_ROLE_ROW_HEADER
:
3985 ia_role
= ROLE_SYSTEM_ROWHEADER
;
3987 case ui::AX_ROLE_RUBY
:
3988 ia_role
= ROLE_SYSTEM_TEXT
;
3989 ia2_role
= IA2_ROLE_TEXT_FRAME
;
3991 case ui::AX_ROLE_RULER
:
3992 ia_role
= ROLE_SYSTEM_CLIENT
;
3993 ia2_role
= IA2_ROLE_RULER
;
3994 ia_state
|= STATE_SYSTEM_READONLY
;
3996 case ui::AX_ROLE_SCROLL_AREA
:
3997 ia_role
= ROLE_SYSTEM_CLIENT
;
3998 ia2_role
= IA2_ROLE_SCROLL_PANE
;
3999 ia_state
|= STATE_SYSTEM_READONLY
;
4000 ia2_state
&= ~(IA2_STATE_EDITABLE
);
4002 case ui::AX_ROLE_SCROLL_BAR
:
4003 ia_role
= ROLE_SYSTEM_SCROLLBAR
;
4005 case ui::AX_ROLE_SLIDER
:
4006 ia_role
= ROLE_SYSTEM_SLIDER
;
4008 case ui::AX_ROLE_SPIN_BUTTON
:
4009 ia_role
= ROLE_SYSTEM_SPINBUTTON
;
4011 case ui::AX_ROLE_SPIN_BUTTON_PART
:
4012 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4014 case ui::AX_ROLE_ANNOTATION
:
4015 case ui::AX_ROLE_LIST_MARKER
:
4016 case ui::AX_ROLE_STATIC_TEXT
:
4017 ia_role
= ROLE_SYSTEM_STATICTEXT
;
4019 case ui::AX_ROLE_STATUS
:
4020 ia_role
= ROLE_SYSTEM_STATUSBAR
;
4022 case ui::AX_ROLE_SPLITTER
:
4023 ia_role
= ROLE_SYSTEM_SEPARATOR
;
4025 case ui::AX_ROLE_SVG_ROOT
:
4026 ia_role
= ROLE_SYSTEM_GRAPHIC
;
4028 case ui::AX_ROLE_TAB
:
4029 ia_role
= ROLE_SYSTEM_PAGETAB
;
4031 case ui::AX_ROLE_TABLE
: {
4032 base::string16 aria_role
= GetString16Attribute(
4034 if (aria_role
== L
"treegrid") {
4035 ia_role
= ROLE_SYSTEM_OUTLINE
;
4037 ia_role
= ROLE_SYSTEM_TABLE
;
4041 case ui::AX_ROLE_TABLE_HEADER_CONTAINER
:
4042 ia_role
= ROLE_SYSTEM_GROUPING
;
4043 ia2_role
= IA2_ROLE_SECTION
;
4044 ia_state
|= STATE_SYSTEM_READONLY
;
4046 case ui::AX_ROLE_TAB_LIST
:
4047 ia_role
= ROLE_SYSTEM_PAGETABLIST
;
4049 case ui::AX_ROLE_TAB_PANEL
:
4050 ia_role
= ROLE_SYSTEM_PROPERTYPAGE
;
4052 case ui::AX_ROLE_TOGGLE_BUTTON
:
4053 ia_role
= ROLE_SYSTEM_PUSHBUTTON
;
4054 ia2_role
= IA2_ROLE_TOGGLE_BUTTON
;
4056 case ui::AX_ROLE_TEXT_AREA
:
4057 ia_role
= ROLE_SYSTEM_TEXT
;
4058 ia2_state
|= IA2_STATE_MULTI_LINE
;
4059 ia2_state
|= IA2_STATE_EDITABLE
;
4060 ia2_state
|= IA2_STATE_SELECTABLE_TEXT
;
4062 case ui::AX_ROLE_TEXT_FIELD
:
4063 ia_role
= ROLE_SYSTEM_TEXT
;
4064 ia2_state
|= IA2_STATE_SINGLE_LINE
;
4065 ia2_state
|= IA2_STATE_EDITABLE
;
4066 ia2_state
|= IA2_STATE_SELECTABLE_TEXT
;
4068 case ui::AX_ROLE_TIME
:
4069 ia_role
= ROLE_SYSTEM_SPINBUTTON
;
4071 case ui::AX_ROLE_TIMER
:
4072 ia_role
= ROLE_SYSTEM_CLOCK
;
4073 ia_state
|= STATE_SYSTEM_READONLY
;
4075 case ui::AX_ROLE_TOOLBAR
:
4076 ia_role
= ROLE_SYSTEM_TOOLBAR
;
4077 ia_state
|= STATE_SYSTEM_READONLY
;
4079 case ui::AX_ROLE_TOOLTIP
:
4080 ia_role
= ROLE_SYSTEM_TOOLTIP
;
4081 ia_state
|= STATE_SYSTEM_READONLY
;
4083 case ui::AX_ROLE_TREE
:
4084 ia_role
= ROLE_SYSTEM_OUTLINE
;
4086 case ui::AX_ROLE_TREE_GRID
:
4087 ia_role
= ROLE_SYSTEM_OUTLINE
;
4089 case ui::AX_ROLE_TREE_ITEM
:
4090 ia_role
= ROLE_SYSTEM_OUTLINEITEM
;
4092 case ui::AX_ROLE_LINE_BREAK
:
4093 ia_role
= ROLE_SYSTEM_WHITESPACE
;
4095 case ui::AX_ROLE_WINDOW
:
4096 ia_role
= ROLE_SYSTEM_WINDOW
;
4099 // TODO(dmazzoni): figure out the proper MSAA role for all of these.
4100 case ui::AX_ROLE_DIRECTORY
:
4101 case ui::AX_ROLE_IGNORED
:
4102 case ui::AX_ROLE_LOG
:
4103 case ui::AX_ROLE_NONE
:
4104 case ui::AX_ROLE_PRESENTATIONAL
:
4105 case ui::AX_ROLE_SLIDER_THUMB
:
4107 ia_role
= ROLE_SYSTEM_CLIENT
;
4111 // Compute the final value of READONLY for MSAA.
4113 // We always set the READONLY state for elements that have the
4114 // aria-readonly attribute and for a few roles (in the switch above).
4115 // We clear the READONLY state on focusable controls and on a document.
4116 // Everything else, the majority of objects, do not have this state set.
4117 if (HasState(ui::AX_STATE_FOCUSABLE
) &&
4118 ia_role
!= ROLE_SYSTEM_DOCUMENT
) {
4119 ia_state
&= ~(STATE_SYSTEM_READONLY
);
4121 if (!HasState(ui::AX_STATE_READ_ONLY
))
4122 ia_state
&= ~(STATE_SYSTEM_READONLY
);
4123 if (GetBoolAttribute(ui::AX_ATTR_ARIA_READONLY
))
4124 ia_state
|= STATE_SYSTEM_READONLY
;
4126 // The role should always be set.
4127 DCHECK(!role_name
.empty() || ia_role
);
4129 // If we didn't explicitly set the IAccessible2 role, make it the same
4130 // as the MSAA role.
4134 win_attributes_
->ia_role
= ia_role
;
4135 win_attributes_
->ia_state
= ia_state
;
4136 win_attributes_
->role_name
= role_name
;
4137 win_attributes_
->ia2_role
= ia2_role
;
4138 win_attributes_
->ia2_state
= ia2_state
;
4141 } // namespace content