diff options
author | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 21:51:04 +0000 |
---|---|---|
committer | ctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 21:51:04 +0000 |
commit | a9d59460c07913177e8bf149276a433403783c88 (patch) | |
tree | e661ac21a58003c4e5a1ddd0afb550258ace59ee /views | |
parent | 78d36a2f101aaa7dea9820b7001672c8f5f78f4f (diff) | |
download | chromium_src-a9d59460c07913177e8bf149276a433403783c88.zip chromium_src-a9d59460c07913177e8bf149276a433403783c88.tar.gz chromium_src-a9d59460c07913177e8bf149276a433403783c88.tar.bz2 |
views: [accessibility] Add support for Accessibility Value.
BUG=9604
TEST=point AccExplorer to Edit Bookmark dialog, see if everything has a MSAA information, like: Name, Role, State, Value.
Patch from Thiago Farina <thiago.farina@gmail.com>
Review URL: http://codereview.chromium.org/928001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/accessibility/view_accessibility.cc | 41 | ||||
-rw-r--r-- | views/accessibility/view_accessibility.h | 6 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 13 | ||||
-rw-r--r-- | views/controls/textfield/textfield.h | 1 | ||||
-rw-r--r-- | views/view.h | 9 |
5 files changed, 60 insertions, 10 deletions
diff --git a/views/accessibility/view_accessibility.cc b/views/accessibility/view_accessibility.cc index f8bf516..32239d1 100644 --- a/views/accessibility/view_accessibility.cc +++ b/views/accessibility/view_accessibility.cc @@ -479,7 +479,7 @@ STDMETHODIMP ViewAccessibility::get_accName(VARIANT var_id, BSTR* name) { std::wstring temp_name; if (var_id.lVal == CHILDID_SELF) { - // Retrieve the parent view's name. + // Retrieve the current view's name. view_->GetAccessibleName(&temp_name); } else { if (!IsValidChild((var_id.lVal - 1), view_)) { @@ -600,6 +600,39 @@ STDMETHODIMP ViewAccessibility::get_accState(VARIANT var_id, VARIANT* state) { return S_OK; } +STDMETHODIMP ViewAccessibility::get_accValue(VARIANT var_id, BSTR* value) { + if (var_id.vt != VT_I4 || !value) { + return E_INVALIDARG; + } + + if (!view_) { + return E_FAIL; + } + + std::wstring temp_value; + + if (var_id.lVal == CHILDID_SELF) { + // Retrieve the current view's value. + view_->GetAccessibleValue(&temp_value); + } else { + if (!IsValidChild((var_id.lVal - 1), view_)) { + return E_INVALIDARG; + } + // Retrieve the child view's value. + view_->GetChildViewAt(var_id.lVal - 1)->GetAccessibleValue(&temp_value); + } + if (!temp_value.empty()) { + // Return value retrieved. + *value = SysAllocString(temp_value.c_str()); + } else { + // If view has no value, fall back into the default implementation. + *value = NULL; + return E_NOTIMPL; + } + + return S_OK; +} + // Helper functions. bool ViewAccessibility::IsValidChild(int child_id, views::View* view) const { @@ -725,12 +758,6 @@ HRESULT ViewAccessibility::accDoDefaultAction(VARIANT var_id) { return E_NOTIMPL; } -STDMETHODIMP ViewAccessibility::get_accValue(VARIANT var_id, BSTR* value) { - if (value) - *value = NULL; - return E_NOTIMPL; -} - STDMETHODIMP ViewAccessibility::get_accSelection(VARIANT* selected) { if (selected) selected->vt = VT_EMPTY; diff --git a/views/accessibility/view_accessibility.h b/views/accessibility/view_accessibility.h index 003ce7a..7d95794 100644 --- a/views/accessibility/view_accessibility.h +++ b/views/accessibility/view_accessibility.h @@ -81,14 +81,14 @@ class ATL_NO_VTABLE ViewAccessibility // Retrieves the current state of the specified object. STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state); + // Retrieves the current value associated with the specified object. + STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value); + // 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); diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index d2e2fae..71f66b4 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -12,6 +12,7 @@ #include "base/keyboard_codes.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "gfx/insets.h" #include "views/controls/native/native_view_host.h" #include "views/controls/textfield/native_textfield_wrapper.h" @@ -284,6 +285,18 @@ void Textfield::SetAccessibleName(const std::wstring& name) { accessible_name_.assign(name); } +bool Textfield::GetAccessibleValue(std::wstring* value) { + DCHECK(value); + if (!value) + return false; + + if (!text_.empty()) { + *value = UTF16ToWide(text_); + return true; + } + return false; +} + void Textfield::SetEnabled(bool enabled) { View::SetEnabled(enabled); if (native_wrapper_) diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h index 4b8076c..7b36547 100644 --- a/views/controls/textfield/textfield.h +++ b/views/controls/textfield/textfield.h @@ -226,6 +226,7 @@ class Textfield : public View { virtual bool GetAccessibleName(std::wstring* name); virtual bool GetAccessibleState(AccessibilityTypes::State* state); virtual void SetAccessibleName(const std::wstring& name); + virtual bool GetAccessibleValue(std::wstring* value); protected: virtual void Focus(); diff --git a/views/view.h b/views/view.h index b226c82..0c047d3 100644 --- a/views/view.h +++ b/views/view.h @@ -589,6 +589,10 @@ class View : public AcceleratorTarget { return false; } + // Returns the current value associated with a view. Sets the input string + // appropriately, and returns true if successful. + virtual bool GetAccessibleValue(std::wstring* value) { return false; } + // Assigns a keyboard shortcut string description to the given control. Needed // as a View does not know which shortcut will be associated with it until it // is created to be a certain type. @@ -599,6 +603,11 @@ class View : public AcceleratorTarget { // certain type. virtual void SetAccessibleName(const std::wstring& name) {} + // Assigns a string value to the given control. Needed as a View does not know + // which value will be associated with it until it is created to be a + // certain type. + virtual void SetAccessibleValue(const std::wstring& value) {} + // Returns an instance of a wrapper class implementing the (platform-specific) // accessibility interface for a given View. If one exists, it will be // re-used, otherwise a new instance will be created. |