summaryrefslogtreecommitdiffstats
path: root/chrome/views/accessibility
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/views/accessibility')
-rw-r--r--chrome/views/accessibility/view_accessibility.cc509
-rw-r--r--chrome/views/accessibility/view_accessibility.h60
-rw-r--r--chrome/views/accessibility/view_accessibility_wrapper.cc79
-rw-r--r--chrome/views/accessibility/view_accessibility_wrapper.h55
4 files changed, 421 insertions, 282 deletions
diff --git a/chrome/views/accessibility/view_accessibility.cc b/chrome/views/accessibility/view_accessibility.cc
index 5991218..4ba7d54 100644
--- a/chrome/views/accessibility/view_accessibility.cc
+++ b/chrome/views/accessibility/view_accessibility.cc
@@ -4,7 +4,7 @@
#include "chrome/views/accessibility/view_accessibility.h"
-#include "chrome/views/accessibility/accessible_wrapper.h"
+#include "chrome/views/accessibility/view_accessibility_wrapper.h"
#include "chrome/views/widget/widget.h"
HRESULT ViewAccessibility::Initialize(views::View* view) {
@@ -16,106 +16,108 @@ HRESULT ViewAccessibility::Initialize(views::View* view) {
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accChildCount(LONG* child_count) {
- if (!child_count || !view_) {
+// TODO(klink): Handle case where child View is not contained by parent.
+STDMETHODIMP ViewAccessibility::accHitTest(LONG x_left, LONG y_top,
+ VARIANT* child) {
+ if (!child) {
return E_INVALIDARG;
}
- *child_count = view_->GetChildViewCount();
- return S_OK;
-}
-
-STDMETHODIMP ViewAccessibility::get_accChild(VARIANT var_child,
- IDispatch** disp_child) {
- if (var_child.vt != VT_I4 || !disp_child) {
- return E_INVALIDARG;
- }
+ gfx::Point pt(x_left, y_top);
+ views::View::ConvertPointToView(NULL, view_, &pt);
- // If var_child is the parent, remain with the same IDispatch.
- if (var_child.lVal == CHILDID_SELF) {
- return S_OK;
+ if (!view_->HitTest(pt)) {
+ // If containing parent is not hit, return with failure.
+ child->vt = VT_EMPTY;
+ return S_FALSE;
}
+ int child_count = view_->GetChildViewCount();
+ bool child_hit = false;
views::View* child_view = NULL;
- bool get_iaccessible = false;
-
- // Check to see if child is out-of-bounds.
- if (IsValidChild((var_child.lVal - 1), view_)) {
- child_view = view_->GetChildViewAt(var_child.lVal - 1);
- } else {
- // Child is located elsewhere in the hierarchy, get ID and adjust for MSAA.
- child_view = view_->GetViewByID(static_cast<int>(var_child.lVal));
- get_iaccessible = true;
+ for (int child_id = 0; child_id < child_count; ++child_id) {
+ // Search for hit within any of the children.
+ child_view = view_->GetChildViewAt(child_id);
+ views::View::ConvertPointToView(view_, child_view, &pt);
+ if (child_view->HitTest(pt)) {
+ // Store child_id (adjusted with +1 to convert to MSAA indexing).
+ child->lVal = child_id + 1;
+ child_hit = true;
+ break;
+ }
+ // Convert point back to parent view to test next child.
+ views::View::ConvertPointToView(child_view, view_, &pt);
}
- if (!child_view) {
- // No child found.
- *disp_child = NULL;
- return E_FAIL;
- }
+ child->vt = VT_I4;
- if (get_iaccessible || child_view->GetChildViewCount() != 0) {
- // Retrieve the IUnknown interface for the requested child view, and
- // assign the IDispatch returned.
- if ((GetAccessibleWrapper(child_view))->
- GetInstance(IID_IAccessible,
- reinterpret_cast<void**>(disp_child)) == S_OK) {
- // Increment the reference count for the retrieved interface.
- (*disp_child)->AddRef();
- return S_OK;
- } else {
- // No interface, return failure.
- return E_NOINTERFACE;
- }
+ if (!child_hit) {
+ // No child hit, return parent id.
+ child->lVal = CHILDID_SELF;
} else {
- // When at a leaf, children are handled by the parent object.
- *disp_child = NULL;
- return S_FALSE;
+ if (child_view == NULL) {
+ return E_FAIL;
+ } else if (child_view->GetChildViewCount() != 0) {
+ // Retrieve IDispatch for child, if it is not a leaf.
+ child->vt = VT_DISPATCH;
+ if ((GetViewAccessibilityWrapper(child_view))->
+ GetInstance(IID_IAccessible,
+ reinterpret_cast<void**>(&child->pdispVal)) == S_OK) {
+ // Increment the reference count for the retrieved interface.
+ child->pdispVal->AddRef();
+ return S_OK;
+ } else {
+ return E_NOINTERFACE;
+ }
+ }
}
+
+ return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) {
- if (!disp_parent) {
+STDMETHODIMP ViewAccessibility::accLocation(LONG* x_left, LONG* y_top,
+ LONG* width, LONG* height,
+ VARIANT var_id) {
+ if (var_id.vt != VT_I4 || !x_left || !y_top || !width || !height) {
return E_INVALIDARG;
}
- views::View* parent_view = view_->GetParent();
-
- if (!parent_view) {
- // This function can get called during teardown of WidetWin so we
- // should bail out if we fail to get the HWND.
- if (!view_->GetWidget() || !view_->GetWidget()->GetNativeView()) {
- *disp_parent = NULL;
- return S_FALSE;
- }
+ gfx::Rect view_bounds;
+ // Retrieving the parent View to be used for converting from view-to-screen
+ // coordinates.
+ views::View* parent = view_->GetParent();
- // For a View that has no parent (e.g. root), point the accessible parent to
- // the default implementation, to interface with Windows' hierarchy and to
- // support calls from e.g. WindowFromAccessibleObject.
- HRESULT hr =
- ::AccessibleObjectFromWindow(view_->GetWidget()->GetNativeView(),
- OBJID_WINDOW, IID_IAccessible,
- reinterpret_cast<void**>(disp_parent));
+ if (parent == NULL) {
+ // If no parent, remain within the same View.
+ parent = view_;
+ }
- if (!SUCCEEDED(hr)) {
- *disp_parent = NULL;
- return S_FALSE;
+ if (var_id.lVal == CHILDID_SELF) {
+ // Retrieve active View's bounds.
+ view_bounds = view_->bounds();
+ } else {
+ // Check to see if child is out-of-bounds.
+ if (!IsValidChild((var_id.lVal - 1), view_)) {
+ return E_INVALIDARG;
}
-
- return S_OK;
+ // Retrieve child bounds.
+ view_bounds = view_->GetChildViewAt(var_id.lVal - 1)->bounds();
+ // Parent View is current View.
+ parent = view_;
}
- // Retrieve the IUnknown interface for the parent view, and assign the
- // IDispatch returned.
- if ((GetAccessibleWrapper(parent_view))->
- GetInstance(IID_IAccessible,
- reinterpret_cast<void**>(disp_parent)) == S_OK) {
- // Increment the reference count for the retrieved interface.
- (*disp_parent)->AddRef();
- return S_OK;
+ if (!view_bounds.IsEmpty()) {
+ *width = view_bounds.width();
+ *height = view_bounds.height();
+
+ gfx::Point topleft(view_bounds.origin());
+ views::View::ConvertPointToScreen(parent, &topleft);
+ *x_left = topleft.x();
+ *y_top = topleft.y();
} else {
- return E_NOINTERFACE;
+ return E_FAIL;
}
+ return S_OK;
}
STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start,
@@ -145,7 +147,7 @@ STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start,
if (child->GetChildViewCount() != 0) {
end->vt = VT_DISPATCH;
- if ((GetAccessibleWrapper(child))->
+ if ((GetViewAccessibilityWrapper(child))->
GetInstance(IID_IAccessible,
reinterpret_cast<void**>(&end->pdispVal)) == S_OK) {
// Increment the reference count for the retrieved interface.
@@ -195,7 +197,7 @@ STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start,
if (child->GetChildViewCount() != 0) {
end->vt = VT_DISPATCH;
// Retrieve IDispatch for non-leaf child.
- if ((GetAccessibleWrapper(child))->
+ if ((GetViewAccessibilityWrapper(child))->
GetInstance(IID_IAccessible,
reinterpret_cast<void**>(&end->pdispVal)) == S_OK) {
// Increment the reference count for the retrieved interface.
@@ -248,65 +250,84 @@ STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start,
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accFocus(VARIANT* focus_child) {
- if (!focus_child) {
+STDMETHODIMP ViewAccessibility::get_accChild(VARIANT var_child,
+ IDispatch** disp_child) {
+ if (var_child.vt != VT_I4 || !disp_child) {
return E_INVALIDARG;
}
- if (view_->GetChildViewCount() == 0 && view_->HasFocus()) {
- // Parent view has focus.
- focus_child->vt = VT_I4;
- focus_child->lVal = CHILDID_SELF;
+ // If var_child is the parent, remain with the same IDispatch.
+ if (var_child.lVal == CHILDID_SELF) {
+ return S_OK;
+ }
+
+ views::View* child_view = NULL;
+ bool get_iaccessible = false;
+
+ // Check to see if child is out-of-bounds.
+ if (IsValidChild((var_child.lVal - 1), view_)) {
+ child_view = view_->GetChildViewAt(var_child.lVal - 1);
} else {
- bool has_focus = false;
- int child_count = view_->GetChildViewCount();
- // Search for child view with focus.
- for (int child_id = 0; child_id < child_count; ++child_id) {
- if (view_->GetChildViewAt(child_id)->HasFocus()) {
- focus_child->vt = VT_I4;
- focus_child->lVal = child_id + 1;
+ // Child is located elsewhere in the hierarchy, get ID and adjust for MSAA.
+ child_view = view_->GetViewByID(static_cast<int>(var_child.lVal));
+ get_iaccessible = true;
+ }
- // If child view is no leaf, retrieve IDispatch.
- if (view_->GetChildViewAt(child_id)->GetChildViewCount() != 0) {
- focus_child->vt = VT_DISPATCH;
- this->get_accChild(*focus_child, &focus_child->pdispVal);
- }
- has_focus = true;
- break;
- }
- }
- // No current focus on any of the children.
- if (!has_focus) {
- focus_child->vt = VT_EMPTY;
- return S_FALSE;
+ if (!child_view) {
+ // No child found.
+ *disp_child = NULL;
+ return E_FAIL;
+ }
+
+ if (get_iaccessible || child_view->GetChildViewCount() != 0) {
+ // Retrieve the IUnknown interface for the requested child view, and
+ // assign the IDispatch returned.
+ if ((GetViewAccessibilityWrapper(child_view))->
+ GetInstance(IID_IAccessible,
+ reinterpret_cast<void**>(disp_child)) == S_OK) {
+ // Increment the reference count for the retrieved interface.
+ (*disp_child)->AddRef();
+ return S_OK;
+ } else {
+ // No interface, return failure.
+ return E_NOINTERFACE;
}
+ } else {
+ // When at a leaf, children are handled by the parent object.
+ *disp_child = NULL;
+ return S_FALSE;
}
+}
+STDMETHODIMP ViewAccessibility::get_accChildCount(LONG* child_count) {
+ if (!child_count || !view_) {
+ return E_INVALIDARG;
+ }
+
+ *child_count = view_->GetChildViewCount();
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accName(VARIANT var_id, BSTR* name) {
- if (var_id.vt != VT_I4 || !name) {
+STDMETHODIMP ViewAccessibility::get_accDefaultAction(VARIANT var_id,
+ BSTR* def_action) {
+ if (var_id.vt != VT_I4 || !def_action) {
return E_INVALIDARG;
}
- std::wstring temp_name;
+ std::wstring temp_action;
if (var_id.lVal == CHILDID_SELF) {
- // Retrieve the parent view's name.
- view_->GetAccessibleName(&temp_name);
+ view_->GetAccessibleDefaultAction(&temp_action);
} else {
if (!IsValidChild((var_id.lVal - 1), view_)) {
return E_INVALIDARG;
}
- // Retrieve the child view's name.
- view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleName(&temp_name);
+ view_->GetChildViewAt(var_id.lVal - 1)->
+ GetAccessibleDefaultAction(&temp_action);
}
- if (!temp_name.empty()) {
- // Return name retrieved.
- *name = CComBSTR(temp_name.c_str()).Detach();
+ if (!temp_action.empty()) {
+ *def_action = CComBSTR(temp_action.c_str()).Detach();
} else {
- // If view has no name, return S_FALSE.
return S_FALSE;
}
@@ -337,212 +358,190 @@ STDMETHODIMP ViewAccessibility::get_accDescription(VARIANT var_id, BSTR* desc) {
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accState(VARIANT var_id, VARIANT* state) {
- if (var_id.vt != VT_I4 || !state) {
+STDMETHODIMP ViewAccessibility::get_accFocus(VARIANT* focus_child) {
+ if (!focus_child) {
return E_INVALIDARG;
}
- state->vt = VT_I4;
-
- if (var_id.lVal == CHILDID_SELF) {
- // Retrieve all currently applicable states of the parent.
- this->SetState(state, view_);
+ if (view_->GetChildViewCount() == 0 && view_->HasFocus()) {
+ // Parent view has focus.
+ focus_child->vt = VT_I4;
+ focus_child->lVal = CHILDID_SELF;
} else {
- if (!IsValidChild((var_id.lVal - 1), view_)) {
- return E_INVALIDARG;
+ bool has_focus = false;
+ int child_count = view_->GetChildViewCount();
+ // Search for child view with focus.
+ for (int child_id = 0; child_id < child_count; ++child_id) {
+ if (view_->GetChildViewAt(child_id)->HasFocus()) {
+ focus_child->vt = VT_I4;
+ focus_child->lVal = child_id + 1;
+
+ // If child view is no leaf, retrieve IDispatch.
+ if (view_->GetChildViewAt(child_id)->GetChildViewCount() != 0) {
+ focus_child->vt = VT_DISPATCH;
+ this->get_accChild(*focus_child, &focus_child->pdispVal);
+ }
+ has_focus = true;
+ break;
+ }
+ }
+ // No current focus on any of the children.
+ if (!has_focus) {
+ focus_child->vt = VT_EMPTY;
+ return S_FALSE;
}
- // Retrieve all currently applicable states of the child.
- this->SetState(state, view_->GetChildViewAt(var_id.lVal - 1));
}
- // Make sure that state is not empty, and has the proper type.
- if (state->vt == VT_EMPTY)
- return E_FAIL;
-
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accRole(VARIANT var_id, VARIANT* role) {
- if (var_id.vt != VT_I4 || !role) {
+STDMETHODIMP ViewAccessibility::get_accKeyboardShortcut(VARIANT var_id,
+ BSTR* acc_key) {
+ if (var_id.vt != VT_I4 || !acc_key) {
return E_INVALIDARG;
}
+ std::wstring temp_key;
+
if (var_id.lVal == CHILDID_SELF) {
- // Retrieve parent role.
- if (!view_->GetAccessibleRole(role)) {
- return E_FAIL;
- }
+ view_->GetAccessibleKeyboardShortcut(&temp_key);
} else {
if (!IsValidChild((var_id.lVal - 1), view_)) {
return E_INVALIDARG;
}
- // Retrieve child role.
- if (!view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleRole(role)) {
- return E_FAIL;
- }
+ view_->GetChildViewAt(var_id.lVal - 1)->
+ GetAccessibleKeyboardShortcut(&temp_key);
+ }
+ if (!temp_key.empty()) {
+ *acc_key = CComBSTR(temp_key.c_str()).Detach();
+ } else {
+ return S_FALSE;
}
-
- // Make sure that role is not empty, and has the proper type.
- if (role->vt == VT_EMPTY)
- return E_FAIL;
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accDefaultAction(VARIANT var_id,
- BSTR* def_action) {
- if (var_id.vt != VT_I4 || !def_action) {
+STDMETHODIMP ViewAccessibility::get_accName(VARIANT var_id, BSTR* name) {
+ if (var_id.vt != VT_I4 || !name) {
return E_INVALIDARG;
}
- std::wstring temp_action;
+ std::wstring temp_name;
if (var_id.lVal == CHILDID_SELF) {
- view_->GetAccessibleDefaultAction(&temp_action);
+ // Retrieve the parent view's name.
+ view_->GetAccessibleName(&temp_name);
} else {
if (!IsValidChild((var_id.lVal - 1), view_)) {
return E_INVALIDARG;
}
- view_->GetChildViewAt(var_id.lVal - 1)->
- GetAccessibleDefaultAction(&temp_action);
+ // Retrieve the child view's name.
+ view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleName(&temp_name);
}
- if (!temp_action.empty()) {
- *def_action = CComBSTR(temp_action.c_str()).Detach();
+ if (!temp_name.empty()) {
+ // Return name retrieved.
+ *name = CComBSTR(temp_name.c_str()).Detach();
} else {
+ // If view has no name, return S_FALSE.
return S_FALSE;
}
return S_OK;
}
-STDMETHODIMP ViewAccessibility::accLocation(LONG* x_left, LONG* y_top,
- LONG* width, LONG* height,
- VARIANT var_id) {
- if (var_id.vt != VT_I4 || !x_left || !y_top || !width || !height) {
+STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) {
+ if (!disp_parent) {
return E_INVALIDARG;
}
- gfx::Rect view_bounds;
- // Retrieving the parent View to be used for converting from view-to-screen
- // coordinates.
- views::View* parent = view_->GetParent();
+ views::View* parent_view = view_->GetParent();
- if (parent == NULL) {
- // If no parent, remain within the same View.
- parent = view_;
- }
+ if (!parent_view) {
+ // This function can get called during teardown of WidetWin so we
+ // should bail out if we fail to get the HWND.
+ if (!view_->GetWidget() || !view_->GetWidget()->GetNativeView()) {
+ *disp_parent = NULL;
+ return S_FALSE;
+ }
- if (var_id.lVal == CHILDID_SELF) {
- // Retrieve active View's bounds.
- view_bounds = view_->bounds();
- } else {
- // Check to see if child is out-of-bounds.
- if (!IsValidChild((var_id.lVal - 1), view_)) {
- return E_INVALIDARG;
+ // For a View that has no parent (e.g. root), point the accessible parent to
+ // the default implementation, to interface with Windows' hierarchy and to
+ // support calls from e.g. WindowFromAccessibleObject.
+ HRESULT hr =
+ ::AccessibleObjectFromWindow(view_->GetWidget()->GetNativeView(),
+ OBJID_WINDOW, IID_IAccessible,
+ reinterpret_cast<void**>(disp_parent));
+
+ if (!SUCCEEDED(hr)) {
+ *disp_parent = NULL;
+ return S_FALSE;
}
- // Retrieve child bounds.
- view_bounds = view_->GetChildViewAt(var_id.lVal - 1)->bounds();
- // Parent View is current View.
- parent = view_;
- }
- if (!view_bounds.IsEmpty()) {
- *width = view_bounds.width();
- *height = view_bounds.height();
+ return S_OK;
+ }
- gfx::Point topleft(view_bounds.origin());
- views::View::ConvertPointToScreen(parent, &topleft);
- *x_left = topleft.x();
- *y_top = topleft.y();
+ // Retrieve the IUnknown interface for the parent view, and assign the
+ // IDispatch returned.
+ if ((GetViewAccessibilityWrapper(parent_view))->
+ GetInstance(IID_IAccessible,
+ reinterpret_cast<void**>(disp_parent)) == S_OK) {
+ // Increment the reference count for the retrieved interface.
+ (*disp_parent)->AddRef();
+ return S_OK;
} else {
- return E_FAIL;
+ return E_NOINTERFACE;
}
- return S_OK;
}
-
-// TODO(klink): Handle case where child View is not contained by parent.
-STDMETHODIMP ViewAccessibility::accHitTest(LONG x_left, LONG y_top,
- VARIANT* child) {
- if (!child) {
+STDMETHODIMP ViewAccessibility::get_accRole(VARIANT var_id, VARIANT* role) {
+ if (var_id.vt != VT_I4 || !role) {
return E_INVALIDARG;
}
- gfx::Point pt(x_left, y_top);
- views::View::ConvertPointToView(NULL, view_, &pt);
-
- if (!view_->HitTest(pt)) {
- // If containing parent is not hit, return with failure.
- child->vt = VT_EMPTY;
- return S_FALSE;
- }
-
- int child_count = view_->GetChildViewCount();
- bool child_hit = false;
- views::View* child_view = NULL;
- for (int child_id = 0; child_id < child_count; ++child_id) {
- // Search for hit within any of the children.
- child_view = view_->GetChildViewAt(child_id);
- views::View::ConvertPointToView(view_, child_view, &pt);
- if (child_view->HitTest(pt)) {
- // Store child_id (adjusted with +1 to convert to MSAA indexing).
- child->lVal = child_id + 1;
- child_hit = true;
- break;
+ if (var_id.lVal == CHILDID_SELF) {
+ // Retrieve parent role.
+ if (!view_->GetAccessibleRole(role)) {
+ return E_FAIL;
}
- // Convert point back to parent view to test next child.
- views::View::ConvertPointToView(child_view, view_, &pt);
- }
-
- child->vt = VT_I4;
-
- if (!child_hit) {
- // No child hit, return parent id.
- child->lVal = CHILDID_SELF;
} else {
- if (child_view == NULL) {
+ if (!IsValidChild((var_id.lVal - 1), view_)) {
+ return E_INVALIDARG;
+ }
+ // Retrieve child role.
+ if (!view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleRole(role)) {
return E_FAIL;
- } else if (child_view->GetChildViewCount() != 0) {
- // Retrieve IDispatch for child, if it is not a leaf.
- child->vt = VT_DISPATCH;
- if ((GetAccessibleWrapper(child_view))->
- GetInstance(IID_IAccessible,
- reinterpret_cast<void**>(&child->pdispVal)) == S_OK) {
- // Increment the reference count for the retrieved interface.
- child->pdispVal->AddRef();
- return S_OK;
- } else {
- return E_NOINTERFACE;
- }
}
}
+ // Make sure that role is not empty, and has the proper type.
+ if (role->vt == VT_EMPTY)
+ return E_FAIL;
+
return S_OK;
}
-STDMETHODIMP ViewAccessibility::get_accKeyboardShortcut(VARIANT var_id,
- BSTR* acc_key) {
- if (var_id.vt != VT_I4 || !acc_key) {
+STDMETHODIMP ViewAccessibility::get_accState(VARIANT var_id, VARIANT* state) {
+ if (var_id.vt != VT_I4 || !state) {
return E_INVALIDARG;
}
- std::wstring temp_key;
+ state->vt = VT_I4;
if (var_id.lVal == CHILDID_SELF) {
- view_->GetAccessibleKeyboardShortcut(&temp_key);
+ // Retrieve all currently applicable states of the parent.
+ this->SetState(state, view_);
} else {
if (!IsValidChild((var_id.lVal - 1), view_)) {
return E_INVALIDARG;
}
- view_->GetChildViewAt(var_id.lVal - 1)->
- GetAccessibleKeyboardShortcut(&temp_key);
- }
- if (!temp_key.empty()) {
- *acc_key = CComBSTR(temp_key.c_str()).Detach();
- } else {
- return S_FALSE;
+ // Retrieve all currently applicable states of the child.
+ this->SetState(state, view_->GetChildViewAt(var_id.lVal - 1));
}
+ // Make sure that state is not empty, and has the proper type.
+ if (state->vt == VT_EMPTY)
+ return E_FAIL;
+
return S_OK;
}
@@ -612,29 +611,29 @@ void ViewAccessibility::SetState(VARIANT* state, views::View* view) {
// IAccessible functions not supported.
HRESULT ViewAccessibility::accDoDefaultAction(VARIANT var_id) {
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::get_accValue(VARIANT var_id, BSTR* value) {
if (value)
*value = NULL;
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::get_accSelection(VARIANT* selected) {
if (selected)
selected->vt = VT_EMPTY;
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::accSelect(LONG flagsSelect, VARIANT var_id) {
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::get_accHelp(VARIANT var_id, BSTR* help) {
if (help)
*help = NULL;
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::get_accHelpTopic(BSTR* help_file,
@@ -646,15 +645,15 @@ STDMETHODIMP ViewAccessibility::get_accHelpTopic(BSTR* help_file,
if (topic_id) {
*topic_id = static_cast<LONG>(-1);
}
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::put_accName(VARIANT var_id, BSTR put_name) {
// Deprecated.
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
STDMETHODIMP ViewAccessibility::put_accValue(VARIANT var_id, BSTR put_val) {
// Deprecated.
- return DISP_E_MEMBERNOTFOUND;
+ return E_NOTIMPL;
}
diff --git a/chrome/views/accessibility/view_accessibility.h b/chrome/views/accessibility/view_accessibility.h
index c94054f..c541a04 100644
--- a/chrome/views/accessibility/view_accessibility.h
+++ b/chrome/views/accessibility/view_accessibility.h
@@ -37,45 +37,48 @@ class ATL_NO_VTABLE ViewAccessibility
// Supported IAccessible methods.
- // Retrieves the number of accessible children.
- STDMETHODIMP get_accChildCount(LONG* child_count);
+ // Retrieves the child element or child object at a given point on the screen.
+ STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child);
+
+ // Retrieves the specified object's current screen location.
+ STDMETHODIMP accLocation(LONG* x_left,
+ LONG* y_top,
+ LONG* width,
+ LONG* height,
+ VARIANT var_id);
+
+ // Traverses to another UI element and retrieves the object.
+ STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);
// Retrieves an IDispatch interface pointer for the specified child.
STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child);
- // Retrieves the IDispatch interface of the object's parent.
- STDMETHODIMP get_accParent(IDispatch** disp_parent);
+ // Retrieves the number of accessible children.
+ STDMETHODIMP get_accChildCount(LONG* child_count);
- // Traverses to another UI element and retrieves the object.
- STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);
+ // Retrieves a string that describes the object's default action.
+ STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action);
+
+ // Retrieves the tooltip description.
+ STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc);
// Retrieves the object that has the keyboard focus.
STDMETHODIMP get_accFocus(VARIANT* focus_child);
+ // Retrieves the specified object's shortcut.
+ STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key);
+
// Retrieves the name of the specified object.
STDMETHODIMP get_accName(VARIANT var_id, BSTR* name);
- // Retrieves the tooltip description.
- STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc);
-
- // Retrieves the current state of the specified object.
- STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state);
+ // Retrieves the IDispatch interface of the object's parent.
+ STDMETHODIMP get_accParent(IDispatch** disp_parent);
// Retrieves information describing the role of the specified object.
STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role);
- // Retrieves a string that describes the object's default action.
- STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action);
-
- // Retrieves the specified object's current screen location.
- STDMETHODIMP accLocation(LONG* x_left, LONG* y_top, LONG* width, LONG* height,
- VARIANT var_id);
-
- // Retrieves the child element or child object at a given point on the screen.
- STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child);
-
- // Retrieves the specified object's shortcut.
- STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key);
+ // Retrieves the current state of the specified object.
+ STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state);
// Non-supported IAccessible methods.
@@ -91,7 +94,8 @@ class ATL_NO_VTABLE ViewAccessibility
// Help functions not supported.
STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help);
- STDMETHODIMP get_accHelpTopic(BSTR* help_file, VARIANT var_id,
+ STDMETHODIMP get_accHelpTopic(BSTR* help_file,
+ VARIANT var_id,
LONG* topic_id);
// Deprecated functions, not implemented here.
@@ -110,12 +114,14 @@ class ATL_NO_VTABLE ViewAccessibility
// Determines if the navigation target is within the allowed bounds. Returns
// true if it is, false otherwise.
- bool IsValidNav(int nav_dir, int start_id, int lower_bound,
+ bool IsValidNav(int nav_dir,
+ int start_id,
+ int lower_bound,
int upper_bound) const;
// Wrapper to retrieve the view's instance of IAccessible.
- AccessibleWrapper* GetAccessibleWrapper(views::View* view) const {
- return view->GetAccessibleWrapper();
+ ViewAccessibilityWrapper* GetViewAccessibilityWrapper(views::View* v) const {
+ return v->GetViewAccessibilityWrapper();
}
// Helper function which sets applicable states of view.
diff --git a/chrome/views/accessibility/view_accessibility_wrapper.cc b/chrome/views/accessibility/view_accessibility_wrapper.cc
new file mode 100644
index 0000000..c52c42d
--- /dev/null
+++ b/chrome/views/accessibility/view_accessibility_wrapper.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/views/accessibility/view_accessibility_wrapper.h"
+
+#include "chrome/views/accessibility/view_accessibility.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// ViewAccessibilityWrapper - constructors, destructors
+//
+////////////////////////////////////////////////////////////////////////////////
+
+ViewAccessibilityWrapper::ViewAccessibilityWrapper(views::View* view)
+ : accessibility_info_(NULL),
+ view_(view) {
+}
+
+STDMETHODIMP ViewAccessibilityWrapper::CreateDefaultInstance(REFIID iid) {
+ if (IID_IUnknown == iid || IID_IDispatch == iid || IID_IAccessible == iid) {
+ // If there is no instance of ViewAccessibility created, create it
+ // now. Otherwise reuse previous instance.
+ if (!accessibility_info_) {
+ CComObject<ViewAccessibility>* instance = NULL;
+
+ HRESULT hr = CComObject<ViewAccessibility>::CreateInstance(&instance);
+
+ if (!SUCCEEDED(hr) || !instance)
+ return E_FAIL;
+
+ CComPtr<IAccessible> accessibility_instance(instance);
+
+ if (!SUCCEEDED(instance->Initialize(view_)))
+ return E_FAIL;
+
+ // All is well, assign the temp instance to the class smart pointer.
+ accessibility_info_.Attach(accessibility_instance.Detach());
+ }
+ return S_OK;
+ }
+ // Interface not supported.
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP ViewAccessibilityWrapper::GetInstance(REFIID iid,
+ void** interface_ptr) {
+ if (IID_IUnknown == iid || IID_IDispatch == iid || IID_IAccessible == iid) {
+ // If there is no accessibility instance created, create a default now.
+ // Otherwise reuse previous instance.
+ if (!accessibility_info_) {
+ HRESULT hr = CreateDefaultInstance(iid);
+
+ if (hr != S_OK) {
+ // Interface creation failed.
+ *interface_ptr = NULL;
+ return E_NOINTERFACE;
+ }
+ }
+ *interface_ptr = static_cast<IAccessible*>(accessibility_info_);
+ return S_OK;
+ }
+ // No supported interface found, return error.
+ *interface_ptr = NULL;
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP ViewAccessibilityWrapper::SetInstance(IAccessible* interface_ptr) {
+ if (!interface_ptr)
+ return E_NOINTERFACE;
+
+ accessibility_info_.Attach(interface_ptr);
+
+ // Paranoia check, to make sure we do have a valid IAccessible pointer stored.
+ if (!accessibility_info_)
+ return E_FAIL;
+
+ return S_OK;
+}
diff --git a/chrome/views/accessibility/view_accessibility_wrapper.h b/chrome/views/accessibility/view_accessibility_wrapper.h
new file mode 100644
index 0000000..6d4a842
--- /dev/null
+++ b/chrome/views/accessibility/view_accessibility_wrapper.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_WRAPPER_H_
+#define CHROME_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_WRAPPER_H_
+
+#include <atlcomcli.h>
+#include <oleacc.h>
+
+#include "base/basictypes.h"
+
+namespace views {
+class View;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// ViewAccessibilityWrapper
+//
+// Wrapper class for returning a pointer to the appropriate (platform-specific)
+// accessibility interface for a given View. Needed to keep platform-specific
+// code out of the View class, when answering calls for child/parent IAccessible
+// implementations, for instance.
+//
+////////////////////////////////////////////////////////////////////////////////
+class ViewAccessibilityWrapper {
+ public:
+ explicit ViewAccessibilityWrapper(views::View* view);
+ ~ViewAccessibilityWrapper() {}
+
+ STDMETHODIMP CreateDefaultInstance(REFIID iid);
+
+ // Returns a pointer to a specified interface on an object to which a client
+ // currently holds an interface pointer. If pointer exists, it is reused,
+ // otherwise a new pointer is created. Used by accessibility implementation to
+ // retrieve MSAA implementation for child or parent, when navigating MSAA
+ // hierarchy.
+ STDMETHODIMP GetInstance(REFIID iid, void** interface_ptr);
+
+ // Sets the accessibility interface implementation of this wrapper to be
+ // anything the user specifies.
+ STDMETHODIMP SetInstance(IAccessible* interface_ptr);
+
+ private:
+ // Instance of accessibility information and handling for a View.
+ CComPtr<IAccessible> accessibility_info_;
+
+ // View needed to initialize IAccessible.
+ views::View* view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ViewAccessibilityWrapper);
+};
+
+#endif // CHROME_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_WRAPPER_H_