summaryrefslogtreecommitdiffstats
path: root/chrome/views/accessibility
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/views/accessibility')
-rw-r--r--chrome/views/accessibility/accessible_wrapper.cc105
-rw-r--r--chrome/views/accessibility/accessible_wrapper.h80
-rw-r--r--chrome/views/accessibility/autocomplete_accessibility.cc291
-rw-r--r--chrome/views/accessibility/autocomplete_accessibility.h139
-rw-r--r--chrome/views/accessibility/view_accessibility.cc703
-rw-r--r--chrome/views/accessibility/view_accessibility.h155
6 files changed, 1473 insertions, 0 deletions
diff --git a/chrome/views/accessibility/accessible_wrapper.cc b/chrome/views/accessibility/accessible_wrapper.cc
new file mode 100644
index 0000000..481e6b2
--- /dev/null
+++ b/chrome/views/accessibility/accessible_wrapper.cc
@@ -0,0 +1,105 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "chrome/views/accessibility/accessible_wrapper.h"
+
+#include "base/logging.h"
+#include "chrome/views/accessibility/view_accessibility.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// AccessibleWrapper - constructors, destructors
+//
+////////////////////////////////////////////////////////////////////////////////
+
+AccessibleWrapper::AccessibleWrapper(ChromeViews::View* view) :
+ accessibility_info_(NULL),
+ view_(view) {
+}
+
+STDMETHODIMP AccessibleWrapper::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);
+ DCHECK(SUCCEEDED(hr));
+
+ if (!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 AccessibleWrapper::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 AccessibleWrapper::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/accessible_wrapper.h b/chrome/views/accessibility/accessible_wrapper.h
new file mode 100644
index 0000000..05a4d6a
--- /dev/null
+++ b/chrome/views/accessibility/accessible_wrapper.h
@@ -0,0 +1,80 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CHROME_VIEWS_ACCESSIBILITY_ACCESSIBLE_WRAPPER_H__
+#define CHROME_VIEWS_ACCESSIBILITY_ACCESSIBLE_WRAPPER_H__
+
+#include <atlcomcli.h>
+#include <oleacc.h>
+#include <windows.h>
+
+#include "base/basictypes.h"
+
+namespace ChromeViews {
+ class View;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// AccessibleWrapper
+//
+// 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 AccessibleWrapper {
+ public:
+ explicit AccessibleWrapper(ChromeViews::View* view);
+ ~AccessibleWrapper() {}
+
+ 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.
+ ChromeViews::View* view_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(AccessibleWrapper);
+};
+#endif // CHROME_VIEWS_ACCESSIBILITY_ACCESSIBLE_WRAPPER_H__
diff --git a/chrome/views/accessibility/autocomplete_accessibility.cc b/chrome/views/accessibility/autocomplete_accessibility.cc
new file mode 100644
index 0000000..cb88ff6
--- /dev/null
+++ b/chrome/views/accessibility/autocomplete_accessibility.cc
@@ -0,0 +1,291 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "chrome/views/accessibility/autocomplete_accessibility.h"
+
+#include "base/logging.h"
+#include "chrome/common/l10n_util.h"
+
+#include "generated_resources.h"
+
+HRESULT AutocompleteAccessibility::Initialize(
+ const AutocompleteEdit* edit_box) {
+ if (edit_box == NULL) {
+ return E_INVALIDARG;
+ }
+
+ edit_box_ = edit_box;
+
+ // Create a default accessible object for this instance.
+ return CreateStdAccessibleObject(edit_box_->m_hWnd, OBJID_CLIENT,
+ IID_IAccessible, reinterpret_cast<void **>
+ (&default_accessibility_server_));
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accChildCount(LONG* child_count) {
+ if (!child_count) {
+ return E_INVALIDARG;
+ }
+
+ DCHECK(default_accessibility_server_);
+ return default_accessibility_server_->get_accChildCount(child_count);
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accChild(VARIANT var_child,
+ IDispatch** disp_child) {
+ if (var_child.vt != VT_I4 || !disp_child) {
+ return E_INVALIDARG;
+ }
+
+ // If var_child is the parent, remain with the same IDispatch
+ if (var_child.lVal == CHILDID_SELF)
+ return S_OK;
+
+ *disp_child = NULL;
+ return S_FALSE;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accParent(IDispatch** disp_parent) {
+ if (!disp_parent) {
+ return E_INVALIDARG;
+ }
+
+ if (edit_box_->parent_view() == NULL) {
+ *disp_parent = NULL;
+ return S_FALSE;
+ }
+
+ // Retrieve the IUnknown interface for the parent view, and assign the
+ // IDispatch returned.
+ if (edit_box_->parent_view()->GetAccessibleWrapper()->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_NOINTERFACE;
+ }
+}
+
+STDMETHODIMP AutocompleteAccessibility::accNavigate(LONG nav_dir, VARIANT start,
+ VARIANT* end) {
+ if (start.vt != VT_I4 || !end) {
+ return E_INVALIDARG;
+ }
+
+ DCHECK(default_accessibility_server_);
+ return default_accessibility_server_->accNavigate(nav_dir, start, end);
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accFocus(VARIANT* focus_child) {
+ if (!focus_child) {
+ return E_INVALIDARG;
+ }
+
+ DCHECK(default_accessibility_server_);
+ return default_accessibility_server_->get_accFocus(focus_child);
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accName(VARIANT var_id,
+ BSTR* name) {
+ if (var_id.vt != VT_I4 || !name) {
+ return E_INVALIDARG;
+ }
+
+ std::wstring temp_name = l10n_util::GetString(IDS_ACCNAME_LOCATION);
+
+ if (!temp_name.empty()) {
+ // Return name retrieved.
+ *name = CComBSTR(temp_name.c_str()).Detach();
+ } else {
+ // If no name is found, return S_FALSE.
+ return S_FALSE;
+ }
+ DCHECK(*name);
+
+ return S_OK;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accDescription(VARIANT var_id,
+ BSTR* desc) {
+ if (var_id.vt != VT_I4 || !desc) {
+ return E_INVALIDARG;
+ }
+
+ return S_FALSE;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accValue(VARIANT var_id,
+ BSTR* value) {
+ if (var_id.vt != VT_I4 || !value) {
+ return E_INVALIDARG;
+ }
+
+ std::wstring temp_value;
+
+ if (var_id.lVal != CHILDID_SELF)
+ return E_INVALIDARG;
+
+ // Edit box has no children, only handle self.
+ temp_value = edit_box_->GetText();
+ if (temp_value.empty())
+ return S_FALSE;
+
+ // Return value retrieved.
+ *value = CComBSTR(temp_value.c_str()).Detach();
+
+ DCHECK(*value);
+
+ return S_OK;
+
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accState(VARIANT var_id,
+ VARIANT* state) {
+ if (var_id.vt != VT_I4 || !state) {
+ return E_INVALIDARG;
+ }
+
+ DCHECK(default_accessibility_server_);
+ HRESULT hr = default_accessibility_server_->get_accState(var_id, state);
+
+ if (hr != S_OK)
+ return hr;
+
+ // Adding on state to convey the fact that there is a dropdown.
+ state->lVal |= STATE_SYSTEM_HASPOPUP;
+ return S_OK;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accRole(VARIANT var_id,
+ VARIANT* role) {
+ if (var_id.vt != VT_I4 || !role) {
+ return E_INVALIDARG;
+ }
+
+ role->vt = VT_I4;
+
+ // Need to override the default role, which is ROLE_SYSTEM_CLIENT.
+ if (var_id.lVal == CHILDID_SELF) {
+ role->lVal = ROLE_SYSTEM_TEXT;
+ } else {
+ return S_FALSE;
+ }
+
+ return S_OK;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accDefaultAction(VARIANT var_id,
+ BSTR* def_action) {
+ if (var_id.vt != VT_I4 || !def_action) {
+ return E_INVALIDARG;
+ }
+
+ return S_FALSE;
+}
+
+STDMETHODIMP AutocompleteAccessibility::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;
+ }
+
+ DCHECK(default_accessibility_server_);
+ return default_accessibility_server_->accLocation(x_left, y_top, width,
+ height, var_id);
+}
+
+STDMETHODIMP AutocompleteAccessibility::accHitTest(LONG x_left, LONG y_top,
+ VARIANT* child) {
+ if (!child) {
+ return E_INVALIDARG;
+ }
+
+ DCHECK(default_accessibility_server_);
+ return default_accessibility_server_->accHitTest(x_left, y_top, child);
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accKeyboardShortcut(VARIANT var_id,
+ BSTR* acc_key) {
+ if (var_id.vt != VT_I4 || !acc_key) {
+ return E_INVALIDARG;
+ }
+
+ return S_FALSE;
+}
+
+// IAccessible functions not supported.
+
+HRESULT AutocompleteAccessibility::accDoDefaultAction(VARIANT var_id) {
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accSelection(VARIANT* selected) {
+ if (selected)
+ selected->vt = VT_EMPTY;
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP AutocompleteAccessibility::accSelect(LONG flagsSelect,
+ VARIANT var_id) {
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accHelp(VARIANT var_id,
+ BSTR* help) {
+ if (help)
+ *help = NULL;
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP AutocompleteAccessibility::get_accHelpTopic(BSTR* help_file,
+ VARIANT var_id,
+ LONG* topic_id) {
+ if (help_file) {
+ *help_file = NULL;
+ }
+ if (topic_id) {
+ *topic_id = static_cast<LONG>(-1);
+ }
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP AutocompleteAccessibility::put_accName(VARIANT var_id,
+ BSTR put_name) {
+ // Deprecated.
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP AutocompleteAccessibility::put_accValue(VARIANT var_id,
+ BSTR put_val) {
+ // Deprecated.
+ return DISP_E_MEMBERNOTFOUND;
+}
+
diff --git a/chrome/views/accessibility/autocomplete_accessibility.h b/chrome/views/accessibility/autocomplete_accessibility.h
new file mode 100644
index 0000000..218dd0a
--- /dev/null
+++ b/chrome/views/accessibility/autocomplete_accessibility.h
@@ -0,0 +1,139 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CHROME_BROWSER_ACCESSIBILITY_AUTOCOMPLETE_ACCESSIBILITY_H__
+#define CHROME_BROWSER_ACCESSIBILITY_AUTOCOMPLETE_ACCESSIBILITY_H__
+
+#include <atlbase.h>
+#include <atlcom.h>
+
+#include <oleacc.h>
+
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/views/view.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// AutocompleteAccessibility
+//
+// Class implementing the MSAA IAccessible COM interface for AutocompleteEdit,
+// providing accessibility to be used by screen readers and other assistive
+// technology (AT).
+//
+////////////////////////////////////////////////////////////////////////////////
+class ATL_NO_VTABLE AutocompleteAccessibility
+ : public CComObjectRootEx<CComMultiThreadModel>,
+ public IDispatchImpl<IAccessible, &IID_IAccessible, &LIBID_Accessibility> {
+ public:
+ BEGIN_COM_MAP(AutocompleteAccessibility)
+ COM_INTERFACE_ENTRY2(IDispatch, IAccessible)
+ COM_INTERFACE_ENTRY(IAccessible)
+ END_COM_MAP()
+
+ AutocompleteAccessibility() {}
+ ~AutocompleteAccessibility() {}
+
+ HRESULT Initialize(const AutocompleteEdit* edit_box);
+
+ // Supported IAccessible methods.
+
+ // Retrieves the number of accessible children.
+ STDMETHODIMP get_accChildCount(LONG* child_count);
+
+ // 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);
+
+ // Traverses to another UI element and retrieves the object.
+ STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);
+
+ // Retrieves the object that has the keyboard focus.
+ STDMETHODIMP get_accFocus(VARIANT* focus_child);
+
+ // 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);
+
+ // Returns the current value of the edit box.
+ STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value);
+
+ // Retrieves the current state of the specified object.
+ STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state);
+
+ // 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);
+
+ // Non-supported IAccessible methods.
+
+ // Out-dated and can be safely said to be very rarely used.
+ STDMETHODIMP accDoDefaultAction(VARIANT var_id);
+
+ // Selections not applicable to views.
+ STDMETHODIMP get_accSelection(VARIANT* selected);
+ STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id);
+
+ // Help functions not supported.
+ STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help);
+ STDMETHODIMP get_accHelpTopic(BSTR* help_file, VARIANT var_id,
+ LONG* topic_id);
+
+ // Deprecated functions, not implemented here.
+ STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name);
+ STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val);
+
+ protected:
+ // A pointer containing the Windows' default IAccessible implementation for
+ // this object. Used where it is acceptable to return default MSAA
+ // information.
+ CComPtr<IAccessible> default_accessibility_server_;
+
+ private:
+ const AutocompleteEdit* edit_box_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(AutocompleteAccessibility);
+};
+#endif // CHROME_BROWSER_ACCESSIBILITY_AUTOCOMPLETE_ACCESSIBILITY_H__
+
diff --git a/chrome/views/accessibility/view_accessibility.cc b/chrome/views/accessibility/view_accessibility.cc
new file mode 100644
index 0000000..c435f1e
--- /dev/null
+++ b/chrome/views/accessibility/view_accessibility.cc
@@ -0,0 +1,703 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "chrome/views/accessibility/view_accessibility.h"
+
+#include "base/logging.h"
+#include "chrome/browser/view_ids.h"
+#include "chrome/browser/views/location_bar_view.h"
+
+HRESULT ViewAccessibility::Initialize(ChromeViews::View* view) {
+ if (!view) {
+ return E_INVALIDARG;
+ }
+
+ view_ = view;
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accChildCount(LONG* child_count) {
+ if (!child_count) {
+ return E_INVALIDARG;
+ }
+
+ DCHECK(view_);
+ *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;
+ }
+
+ // If var_child is the parent, remain with the same IDispatch.
+ if (var_child.lVal == CHILDID_SELF) {
+ return S_OK;
+ }
+
+ ChromeViews::View* child = NULL;
+ bool get_iaccessible = false;
+
+ // Check to see if child is out-of-bounds.
+ if (IsValidChild((var_child.lVal - 1), view_)) {
+ child = view_->GetChildViewAt(var_child.lVal - 1);
+ } else {
+ // Child is further down the hierarchy, get ID and adjust for MSAA.
+ child = view_->GetViewByID(static_cast<int>(var_child.lVal));
+ get_iaccessible = true;
+ }
+ // TODO(klink): Add bounds checking for View IDs and an else for OOB error.
+
+ if (!child) {
+ // No child found.
+ *disp_child = NULL;
+ return E_FAIL;
+ }
+
+ // Sprecial case to handle the AutocompleteEdit MSAA.
+ if (child->GetID() == VIEW_ID_AUTOCOMPLETE) {
+ ChromeViews::View* parent = child->GetParent();
+
+ // Paranoia check, to make sure we are making a correct cast.
+ if (parent->GetID() == VIEW_ID_LOCATION_BAR) {
+ LocationBarView* location_bar =
+ static_cast<LocationBarView*>(parent);
+
+ // Set the custom IAccessible for the HWNDView containing
+ // AutocompleteEdit.
+ IAccessible* location_entry_accessibility =
+ location_bar->location_entry()->GetIAccessible();
+ if (!location_entry_accessibility)
+ return E_NOINTERFACE;
+
+ GetAccessibleWrapper(child)->SetInstance(location_entry_accessibility);
+ // Setting bool to be true, as we have inserted an IAccessible on a
+ // leaf, and we need ref counting to happen properly.
+ get_iaccessible = true;
+ }
+ }
+
+ if (get_iaccessible || child->GetChildViewCount() != 0) {
+ // Retrieve the IUnknown interface for the requested child view, and
+ // assign the IDispatch returned.
+ if ((GetAccessibleWrapper(child))->
+ 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_accParent(IDispatch** disp_parent) {
+ if (!disp_parent) {
+ return E_INVALIDARG;
+ }
+
+ ChromeViews::View* parent = view_->GetParent();
+
+ if (!parent) {
+ // 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_->GetViewContainer()->GetHWND(),
+ OBJID_WINDOW, IID_IAccessible,
+ reinterpret_cast<void**>(disp_parent));
+
+ if (!SUCCEEDED(hr)) {
+ *disp_parent = NULL;
+ return S_FALSE;
+ }
+
+ return S_OK;
+ }
+
+ // Retrieve the IUnknown interface for the parent view, and assign the
+ // IDispatch returned.
+ if ((GetAccessibleWrapper(parent))->
+ 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_NOINTERFACE;
+ }
+}
+
+STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start,
+ VARIANT* end) {
+ if (start.vt != VT_I4 || !end) {
+ return E_INVALIDARG;
+ }
+
+ switch (nav_dir) {
+ case NAVDIR_FIRSTCHILD:
+ case NAVDIR_LASTCHILD: {
+ if (start.lVal != CHILDID_SELF) {
+ // Start of navigation must be on the View itself.
+ return E_INVALIDARG;
+ } else if (view_->GetChildViewCount() == 0) {
+ // No children found.
+ return S_FALSE;
+ }
+
+ // Set child_id based on first or last child.
+ int child_id = 0;
+ if (nav_dir == NAVDIR_LASTCHILD) {
+ child_id = view_->GetChildViewCount() - 1;
+ }
+
+ ChromeViews::View* child = view_->GetChildViewAt(child_id);
+
+ if (child->GetChildViewCount() != 0) {
+ end->vt = VT_DISPATCH;
+ if ((GetAccessibleWrapper(child))->
+ GetInstance(IID_IAccessible,
+ reinterpret_cast<void**>(&end->pdispVal)) == S_OK) {
+ // Increment the reference count for the retrieved interface.
+ end->pdispVal->AddRef();
+ return S_OK;
+ } else {
+ return E_NOINTERFACE;
+ }
+ } else {
+ end->vt = VT_I4;
+ // Set return child lVal, adjusted for MSAA indexing. (MSAA
+ // child indexing starts with 1, whereas View indexing starts with 0).
+ end->lVal = child_id + 1;
+ }
+ break;
+ }
+ case NAVDIR_LEFT:
+ case NAVDIR_UP:
+ case NAVDIR_PREVIOUS:
+ case NAVDIR_RIGHT:
+ case NAVDIR_DOWN:
+ case NAVDIR_NEXT: {
+ // Retrieve parent to access view index and perform bounds checking.
+ ChromeViews::View* parent = view_->GetParent();
+ if (!parent) {
+ return E_FAIL;
+ }
+
+ if (start.lVal == CHILDID_SELF) {
+ int view_index = parent->GetChildIndex(view_);
+ // Check navigation bounds, adjusting for View child indexing (MSAA
+ // child indexing starts with 1, whereas View indexing starts with 0).
+ if (!IsValidNav(nav_dir, view_index, -1,
+ parent->GetChildViewCount())) {
+ // Navigation attempted to go out-of-bounds.
+ end->vt = VT_EMPTY;
+ return S_FALSE;
+ } else {
+ if (IsNavDirNext(nav_dir)) {
+ view_index += 1;
+ } else {
+ view_index -=1;
+ }
+ }
+
+ ChromeViews::View* child = parent->GetChildViewAt(view_index);
+ if (child->GetChildViewCount() != 0) {
+ end->vt = VT_DISPATCH;
+ // Retrieve IDispatch for non-leaf child.
+ if ((GetAccessibleWrapper(child))->
+ GetInstance(IID_IAccessible,
+ reinterpret_cast<void**>(&end->pdispVal)) == S_OK) {
+ // Increment the reference count for the retrieved interface.
+ end->pdispVal->AddRef();
+ return S_OK;
+ } else {
+ return E_NOINTERFACE;
+ }
+ } else {
+ end->vt = VT_I4;
+ // Modifying view_index to give lVal correct MSAA-based value. (MSAA
+ // child indexing starts with 1, whereas View indexing starts with 0).
+ end->lVal = view_index + 1;
+ }
+ } else {
+ // Check navigation bounds, adjusting for MSAA child indexing (MSAA
+ // child indexing starts with 1, whereas View indexing starts with 0).
+ if (!IsValidNav(nav_dir, start.lVal, 0,
+ parent->GetChildViewCount() + 1)) {
+ // Navigation attempted to go out-of-bounds.
+ end->vt = VT_EMPTY;
+ return S_FALSE;
+ } else {
+ if (IsNavDirNext(nav_dir)) {
+ start.lVal += 1;
+ } else {
+ start.lVal -= 1;
+ }
+ }
+
+ HRESULT result = this->get_accChild(start, &end->pdispVal);
+ if (result == S_FALSE) {
+ // Child is a leaf.
+ end->vt = VT_I4;
+ end->lVal = start.lVal;
+ } else if (result == E_INVALIDARG) {
+ return E_INVALIDARG;
+ } else {
+ // Child is not a leaf.
+ end->vt = VT_DISPATCH;
+ }
+ }
+ break;
+ }
+ default:
+ return E_INVALIDARG;
+ }
+ // Navigation performed correctly. Global return for this function, if no
+ // error triggered an escape earlier.
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accFocus(VARIANT* focus_child) {
+ if (!focus_child) {
+ return E_INVALIDARG;
+ }
+
+ if (view_->GetChildViewCount() == 0 && view_->HasFocus()) {
+ // Parent view has focus.
+ focus_child->vt = VT_I4;
+ focus_child->lVal = CHILDID_SELF;
+ } 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;
+
+ // 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;
+ }
+ }
+
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accName(VARIANT var_id, BSTR* name) {
+ if (var_id.vt != VT_I4 || !name) {
+ return E_INVALIDARG;
+ }
+
+ std::wstring temp_name;
+
+ if (var_id.lVal == CHILDID_SELF) {
+ // Retrieve the parent view's name.
+ view_->GetAccessibleName(&temp_name);
+ } 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);
+ }
+ 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;
+ }
+ DCHECK(*name);
+
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accDescription(VARIANT var_id, BSTR* desc) {
+ if (var_id.vt != VT_I4 || !desc) {
+ return E_INVALIDARG;
+ }
+
+ std::wstring temp_desc;
+
+ if (var_id.lVal == CHILDID_SELF) {
+ view_->GetTooltipText(0, 0, &temp_desc);
+ } else {
+ if (!IsValidChild((var_id.lVal - 1), view_)) {
+ return E_INVALIDARG;
+ }
+ view_->GetChildViewAt(var_id.lVal - 1)->GetTooltipText(0, 0, &temp_desc);
+ }
+ if (!temp_desc.empty()) {
+ *desc = CComBSTR(temp_desc.c_str()).Detach();
+ } else {
+ return S_FALSE;
+ }
+ DCHECK(*desc);
+
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accState(VARIANT var_id, VARIANT* state) {
+ if (var_id.vt != VT_I4 || !state) {
+ 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_);
+ } else {
+ if (!IsValidChild((var_id.lVal - 1), view_)) {
+ return E_INVALIDARG;
+ }
+ // Retrieve all currently applicable states of the child.
+ this->SetState(state, view_->GetChildViewAt(var_id.lVal - 1));
+ }
+ DCHECK((*state).vt != VT_EMPTY);
+
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accRole(VARIANT var_id, VARIANT* role) {
+ if (var_id.vt != VT_I4 || !role) {
+ return E_INVALIDARG;
+ }
+
+ if (var_id.lVal == CHILDID_SELF) {
+ // Retrieve parent role.
+ if (!view_->GetAccessibleRole(role)) {
+ return E_FAIL;
+ }
+ } 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;
+ }
+ }
+ DCHECK((*role).vt != VT_EMPTY);
+
+ return S_OK;
+}
+
+STDMETHODIMP ViewAccessibility::get_accDefaultAction(VARIANT var_id,
+ BSTR* def_action) {
+ if (var_id.vt != VT_I4 || !def_action) {
+ return E_INVALIDARG;
+ }
+
+ std::wstring temp_action;
+
+ if (var_id.lVal == CHILDID_SELF) {
+ view_->GetAccessibleDefaultAction(&temp_action);
+ } else {
+ if (!IsValidChild((var_id.lVal - 1), view_)) {
+ return E_INVALIDARG;
+ }
+ view_->GetChildViewAt(var_id.lVal - 1)->
+ GetAccessibleDefaultAction(&temp_action);
+ }
+ if (!temp_action.empty()) {
+ *def_action = CComBSTR(temp_action.c_str()).Detach();
+ } else {
+ return S_FALSE;
+ }
+ DCHECK(*def_action);
+
+ 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) {
+ return E_INVALIDARG;
+ }
+
+ CRect view_bounds(0, 0, 0, 0);
+ // Retrieving the parent View to be used for converting from view-to-screen
+ // coordinates.
+ ChromeViews::View* parent = view_->GetParent();
+
+ if (parent == NULL) {
+ // If no parent, remain within the same View.
+ parent = view_;
+ }
+
+ if (var_id.lVal == CHILDID_SELF) {
+ // Retrieve active View's bounds.
+ view_->GetBounds(&view_bounds);
+ } else {
+ // Check to see if child is out-of-bounds.
+ if (!IsValidChild((var_id.lVal - 1), view_)) {
+ return E_INVALIDARG;
+ }
+ // Retrieve child bounds.
+ view_->GetChildViewAt(var_id.lVal - 1)->GetBounds(&view_bounds);
+ // Parent View is current View.
+ parent = view_;
+ }
+
+ if (!view_bounds.IsRectNull()) {
+ *width = view_bounds.Width();
+ *height = view_bounds.Height();
+
+ ChromeViews::View::ConvertPointToScreen(parent, &view_bounds.TopLeft());
+ *x_left = view_bounds.left;
+ *y_top = view_bounds.top;
+ } else {
+ return E_FAIL;
+ }
+ 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) {
+ return E_INVALIDARG;
+ }
+
+ CPoint pt(x_left, y_top);
+ ChromeViews::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;
+ ChromeViews::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);
+ ChromeViews::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.
+ ChromeViews::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) {
+ 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;
+ }
+ }
+ }
+
+ return S_OK;
+}
+
+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) {
+ view_->GetAccessibleKeyboardShortcut(&temp_key);
+ } 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;
+ }
+ DCHECK(*acc_key);
+
+ return S_OK;
+}
+
+// Helper functions.
+
+bool ViewAccessibility::IsValidChild(int child_id,
+ ChromeViews::View* view) const {
+ if (((child_id) < 0) ||
+ ((child_id) >= view->GetChildViewCount())) {
+ return false;
+ }
+ return true;
+}
+
+bool ViewAccessibility::IsNavDirNext(int nav_dir) const {
+ if (nav_dir == NAVDIR_RIGHT || nav_dir == NAVDIR_DOWN ||
+ nav_dir == NAVDIR_NEXT) {
+ return true;
+ }
+ return false;
+}
+
+bool ViewAccessibility::IsValidNav(int nav_dir, int start_id, int lower_bound,
+ int upper_bound) const {
+ if (IsNavDirNext(nav_dir)) {
+ if ((start_id + 1) > upper_bound) {
+ return false;
+ }
+ } else {
+ if ((start_id - 1) <= lower_bound) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void ViewAccessibility::SetState(VARIANT* state, ChromeViews::View* view) {
+ // Default state; all views can have accessibility focus.
+ state->lVal |= STATE_SYSTEM_FOCUSABLE;
+
+ if (!view)
+ return;
+
+ if (!view->IsEnabled()) {
+ state->lVal |= STATE_SYSTEM_UNAVAILABLE;
+ }
+ if (!view->IsVisible()) {
+ state->lVal |= STATE_SYSTEM_INVISIBLE;
+ }
+ if (view->IsHotTracked()) {
+ state->lVal |= STATE_SYSTEM_HOTTRACKED;
+ }
+ if (view->IsPushed()) {
+ state->lVal |= STATE_SYSTEM_PRESSED;
+ }
+ // Check both for actual View focus, as well as accessibility focus.
+ ChromeViews::View* parent = view->GetParent();
+
+ if (view->HasFocus() ||
+ (parent && parent->GetAccFocusedChildView() == view)) {
+ state->lVal |= STATE_SYSTEM_FOCUSED;
+ }
+
+ // Add on any view-specific states.
+ view->GetAccessibleState(state);
+}
+
+// IAccessible functions not supported.
+
+HRESULT ViewAccessibility::accDoDefaultAction(VARIANT var_id) {
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::get_accValue(VARIANT var_id, BSTR* value) {
+ if (value)
+ *value = NULL;
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::get_accSelection(VARIANT* selected) {
+ if (selected)
+ selected->vt = VT_EMPTY;
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::accSelect(LONG flagsSelect, VARIANT var_id) {
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::get_accHelp(VARIANT var_id, BSTR* help) {
+ if (help)
+ *help = NULL;
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::get_accHelpTopic(BSTR* help_file,
+ VARIANT var_id,
+ LONG* topic_id) {
+ if (help_file) {
+ *help_file = NULL;
+ }
+ if (topic_id) {
+ *topic_id = static_cast<LONG>(-1);
+ }
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::put_accName(VARIANT var_id, BSTR put_name) {
+ // Deprecated.
+ return DISP_E_MEMBERNOTFOUND;
+}
+
+STDMETHODIMP ViewAccessibility::put_accValue(VARIANT var_id, BSTR put_val) {
+ // Deprecated.
+ return DISP_E_MEMBERNOTFOUND;
+}
+
diff --git a/chrome/views/accessibility/view_accessibility.h b/chrome/views/accessibility/view_accessibility.h
new file mode 100644
index 0000000..6dcf9dcb
--- /dev/null
+++ b/chrome/views/accessibility/view_accessibility.h
@@ -0,0 +1,155 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CHROME_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H__
+#define CHROME_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H__
+
+#include <atlbase.h>
+#include <atlcom.h>
+
+#include <oleacc.h>
+
+#include "chrome/views/view.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// ViewAccessibility
+//
+// Class implementing the MSAA IAccessible COM interface for a generic View,
+// providing accessibility to be used by screen readers and other assistive
+// technology (AT).
+//
+////////////////////////////////////////////////////////////////////////////////
+class ATL_NO_VTABLE ViewAccessibility
+ : public CComObjectRootEx<CComMultiThreadModel>,
+ public IDispatchImpl<IAccessible, &IID_IAccessible, &LIBID_Accessibility> {
+ public:
+ BEGIN_COM_MAP(ViewAccessibility)
+ COM_INTERFACE_ENTRY2(IDispatch, IAccessible)
+ COM_INTERFACE_ENTRY(IAccessible)
+ END_COM_MAP()
+
+ ViewAccessibility() {}
+ ~ViewAccessibility() {}
+
+ HRESULT Initialize(ChromeViews::View* view);
+
+ // Supported IAccessible methods.
+
+ // Retrieves the number of accessible children.
+ STDMETHODIMP get_accChildCount(LONG* child_count);
+
+ // 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);
+
+ // Traverses to another UI element and retrieves the object.
+ STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);
+
+ // Retrieves the object that has the keyboard focus.
+ STDMETHODIMP get_accFocus(VARIANT* focus_child);
+
+ // 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 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);
+
+ // Non-supported IAccessible methods.
+
+ // Out-dated and can be safely said to be very rarely used.
+ STDMETHODIMP accDoDefaultAction(VARIANT var_id);
+
+ // No value associated with views.
+ STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value);
+
+ // Selections not applicable to views.
+ STDMETHODIMP get_accSelection(VARIANT* selected);
+ STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id);
+
+ // Help functions not supported.
+ STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help);
+ STDMETHODIMP get_accHelpTopic(BSTR* help_file, VARIANT var_id,
+ LONG* topic_id);
+
+ // Deprecated functions, not implemented here.
+ STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name);
+ STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val);
+
+ private:
+ // Checks to see if child_id is within the child bounds of view. Returns true
+ // if the child is within the bounds, false otherwise.
+ bool IsValidChild(int child_id, ChromeViews::View* view) const;
+
+ // Determines navigation direction for accNavigate, based on left, up and
+ // previous being mapped all to previous and right, down, next being mapped
+ // to next. Returns true if navigation direction is next, false otherwise.
+ bool IsNavDirNext(int nav_dir) const;
+
+ // 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,
+ int upper_bound) const;
+
+ // Wrapper to retrieve the view's instance of IAccessible.
+ AccessibleWrapper* GetAccessibleWrapper(ChromeViews::View* view) const {
+ return view->GetAccessibleWrapper();
+ }
+
+ // Helper function which sets applicable states of view.
+ void SetState(VARIANT* state, ChromeViews::View* view);
+
+ // Member View needed for view-specific calls.
+ ChromeViews::View* view_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(ViewAccessibility);
+};
+#endif // CHROME_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H__
+