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 | |
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
-rw-r--r-- | chrome/browser/views/bookmark_editor_view.cc | 19 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_editor_view.h | 9 | ||||
-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 |
7 files changed, 82 insertions, 16 deletions
diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index fb2d072..34f8e91 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -44,7 +44,7 @@ static const SkColor kErrorColor = SkColorSetRGB(0xFF, 0xBC, 0xBC); static const int kTreeWidth = 300; // ID for various children. -static const int kNewGroupButtonID = 1002; +static const int kNewGroupButtonID = 1002; // static void BookmarkEditor::Show(HWND parent_hwnd, @@ -68,6 +68,8 @@ BookmarkEditorView::BookmarkEditorView( : profile_(profile), tree_view_(NULL), new_group_button_(NULL), + url_label_(NULL), + title_label_(NULL), parent_(parent), details_(details), running_menu_for_root_(false), @@ -271,6 +273,10 @@ void BookmarkEditorView::Init() { title_tf_.SetText(title); title_tf_.SetController(this); + title_label_ = new views::Label( + l10n_util::GetString(IDS_BOOMARK_EDITOR_NAME_LABEL)); + title_tf_.SetAccessibleName(title_label_->GetText()); + std::wstring url_text; if (details_.type == EditDetails::EXISTING_NODE) { std::wstring languages = profile_ @@ -284,6 +290,10 @@ void BookmarkEditorView::Init() { url_tf_.SetText(url_text); url_tf_.SetController(this); + url_label_ = new views::Label( + l10n_util::GetString(IDS_BOOMARK_EDITOR_URL_LABEL)); + url_tf_.SetAccessibleName(url_label_->GetText()); + if (show_tree_) { tree_view_ = new views::TreeView(); new_group_button_.reset(new views::NativeButton( @@ -327,16 +337,15 @@ void BookmarkEditorView::Init() { column_set->LinkColumnSizes(0, 2, 4, -1); layout->StartRow(0, labels_column_set_id); - layout->AddView( - new Label(l10n_util::GetString(IDS_BOOMARK_EDITOR_NAME_LABEL))); + + layout->AddView(title_label_); layout->AddView(&title_tf_); if (details_.type != EditDetails::NEW_FOLDER) { layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); layout->StartRow(0, labels_column_set_id); - layout->AddView( - new Label(l10n_util::GetString(IDS_BOOMARK_EDITOR_URL_LABEL))); + layout->AddView(url_label_); layout->AddView(&url_tf_); } diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h index 575b726..84fccf6 100644 --- a/chrome/browser/views/bookmark_editor_view.h +++ b/chrome/browser/views/bookmark_editor_view.h @@ -18,9 +18,10 @@ #include "testing/gtest/include/gtest/gtest_prod.h" namespace views { +class Label; +class Menu2; class NativeButton; class Window; -class Menu2; } class BookmarkEditorViewTest; @@ -227,9 +228,15 @@ class BookmarkEditorView : public BookmarkEditor, // Used to create a new group. scoped_ptr<views::NativeButton> new_group_button_; + // The label for the url text field. + views::Label* url_label_; + // Used for editing the URL. views::Textfield url_tf_; + // The label for the title text field. + views::Label* title_label_; + // Used for editing the title. views::Textfield title_tf_; 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. |