diff options
author | klink@chromium.org <klink@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-16 00:24:30 +0000 |
---|---|---|
committer | klink@chromium.org <klink@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-16 00:24:30 +0000 |
commit | 4e6b02f23537a91bd1990900ff0ffb5001d5b74d (patch) | |
tree | cb2e64f0f9c22303758934d3ccd129201f8589fd /chrome/browser/autocomplete | |
parent | 75f208729c0811751c9f9c54f6cf27f7869d3330 (diff) | |
download | chromium_src-4e6b02f23537a91bd1990900ff0ffb5001d5b74d.zip chromium_src-4e6b02f23537a91bd1990900ff0ffb5001d5b74d.tar.gz chromium_src-4e6b02f23537a91bd1990900ff0ffb5001d5b74d.tar.bz2 |
Eliminates the dependencies between views and browser, and also does some other minor cleanups. The special casing for the OmniBox that used to live in the ViewAccessibility code could be removed due to the fact that the only assistive technologies depending on this case are now testing tools. The end-user tools will see no difference, and the testing tools can access the OmniBox IAccessible by directly giving it keyboard/mouse focus.
BUG=2237
Review URL: http://codereview.chromium.org/14036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
3 files changed, 383 insertions, 1 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_accessibility.cc b/chrome/browser/autocomplete/autocomplete_accessibility.cc new file mode 100644 index 0000000..76eddca --- /dev/null +++ b/chrome/browser/autocomplete/autocomplete_accessibility.cc @@ -0,0 +1,268 @@ +// 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/browser/autocomplete/autocomplete_accessibility.h" + +#include "chrome/common/l10n_util.h" +#include "chrome/views/accessibility/accessible_wrapper.h" +#include "chrome/views/view.h" + +#include "generated_resources.h" + +HRESULT AutocompleteAccessibility::Initialize( + const AutocompleteEditView* 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/browser/autocomplete/autocomplete_accessibility.h b/chrome/browser/autocomplete/autocomplete_accessibility.h new file mode 100644 index 0000000..3bddf15 --- /dev/null +++ b/chrome/browser/autocomplete/autocomplete_accessibility.h @@ -0,0 +1,114 @@ +// 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_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_ACCESSIBILITY_H_ +#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_ACCESSIBILITY_H_ + +#include <atlbase.h> +#include <atlcom.h> + +#include <oleacc.h> + +#include "chrome/browser/autocomplete/autocomplete_edit.h" + +//////////////////////////////////////////////////////////////////////////////// +// +// AutocompleteAccessibility +// +// Class implementing the MSAA IAccessible COM interface for +// AutocompleteEditView, 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 AutocompleteEditView* 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 AutocompleteEditView* edit_box_; + + DISALLOW_EVIL_CONSTRUCTORS(AutocompleteAccessibility); +}; +#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_ACCESSIBILITY_H_ + + diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 6fb50f1..994315e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -13,6 +13,7 @@ #include "base/scoped_clipboard_writer.h" #include "base/string_util.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/autocomplete/autocomplete_accessibility.h" #include "chrome/browser/autocomplete/autocomplete_popup.h" #include "chrome/browser/autocomplete/edit_drop_target.h" #include "chrome/browser/autocomplete/keyword_provider.h" @@ -32,7 +33,6 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/os_exchange_data.h" #include "chrome/common/win_util.h" -#include "chrome/views/accessibility/autocomplete_accessibility.h" #include "googleurl/src/url_util.h" #include "skia/ext/skia_utils_win.h" |