summaryrefslogtreecommitdiffstats
path: root/views/controls/button
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 23:13:49 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 23:13:49 +0000
commitc45dde3c15cddbca7795cab1c28fa472148b01b1 (patch)
tree74f32f6537b87946703839e7e2dfde2f2a2f9063 /views/controls/button
parent7c8f18ab4383e497f0ba3663156abf81ea5af3e6 (diff)
downloadchromium_src-c45dde3c15cddbca7795cab1c28fa472148b01b1.zip
chromium_src-c45dde3c15cddbca7795cab1c28fa472148b01b1.tar.gz
chromium_src-c45dde3c15cddbca7795cab1c28fa472148b01b1.tar.bz2
Refactor Views accessibility.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6581010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/button')
-rw-r--r--views/controls/button/button.cc20
-rw-r--r--views/controls/button/button.h7
-rw-r--r--views/controls/button/button_dropdown.cc16
-rw-r--r--views/controls/button/button_dropdown.h4
-rw-r--r--views/controls/button/checkbox.cc11
-rw-r--r--views/controls/button/checkbox.h3
-rw-r--r--views/controls/button/custom_button.cc19
-rw-r--r--views/controls/button/custom_button.h2
-rw-r--r--views/controls/button/menu_button.cc16
-rw-r--r--views/controls/button/menu_button.h4
-rw-r--r--views/controls/button/native_button_win.cc26
-rw-r--r--views/controls/button/radio_button.cc6
-rw-r--r--views/controls/button/radio_button.h14
13 files changed, 74 insertions, 74 deletions
diff --git a/views/controls/button/button.cc b/views/controls/button/button.cc
index 7b6cc75..6d18204 100644
--- a/views/controls/button/button.cc
+++ b/views/controls/button/button.cc
@@ -3,7 +3,9 @@
// found in the LICENSE file.
#include "views/controls/button/button.h"
+
#include "base/utf_string_conversions.h"
+#include "ui/base/accessibility/accessible_view_state.h"
namespace views {
@@ -18,8 +20,12 @@ void Button::SetTooltipText(const std::wstring& tooltip_text) {
TooltipTextChanged();
}
-void Button::SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {
- accessible_shortcut_ = WideToUTF16Hack(shortcut);
+void Button::SetAccessibleName(const string16& name) {
+ accessible_name_ = name;
+}
+
+void Button::SetAccessibleKeyboardShortcut(const string16& shortcut) {
+ accessible_shortcut_ = shortcut;
}
////////////////////////////////////////////////////////////////////////////////
@@ -33,12 +39,10 @@ bool Button::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
return true;
}
-string16 Button::GetAccessibleKeyboardShortcut() {
- return accessible_shortcut_;
-}
-
-AccessibilityTypes::Role Button::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_PUSHBUTTON;
+void Button::GetAccessibleState(ui::AccessibleViewState* state) {
+ state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
+ state->name = accessible_name_;
+ state->keyboard_shortcut = accessible_shortcut_;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/views/controls/button/button.h b/views/controls/button/button.h
index 263e45f..0c9c6c7 100644
--- a/views/controls/button/button.h
+++ b/views/controls/button/button.h
@@ -36,13 +36,13 @@ class Button : public View {
int mouse_event_flags() const { return mouse_event_flags_; }
- void SetAccessibleKeyboardShortcut(const std::wstring& shortcut);
+ void SetAccessibleName(const string16& name);
+ void SetAccessibleKeyboardShortcut(const string16& shortcut);
// Overridden from View:
virtual bool GetTooltipText(const gfx::Point& p,
std::wstring* tooltip) OVERRIDE;
- virtual string16 GetAccessibleKeyboardShortcut() OVERRIDE;
- virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
protected:
// Construct the Button with a Listener. The listener can be NULL. This can be
@@ -61,6 +61,7 @@ class Button : public View {
string16 tooltip_text_;
// Accessibility data.
+ string16 accessible_name_;
string16 accessible_shortcut_;
// The id tag associated with this button. Used to disambiguate buttons in
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc
index d2f69e2..a5f7ab1 100644
--- a/views/controls/button/button_dropdown.cc
+++ b/views/controls/button/button_dropdown.cc
@@ -8,6 +8,7 @@
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "grit/app_strings.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/l10n/l10n_util.h"
#include "views/controls/menu/view_menu_delegate.h"
#include "views/widget/widget.h"
@@ -165,16 +166,11 @@ void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) {
//
////////////////////////////////////////////////////////////////////////////////
-string16 ButtonDropDown::GetAccessibleDefaultAction() {
- return l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
-}
-
-AccessibilityTypes::Role ButtonDropDown::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_BUTTONDROPDOWN;
-}
-
-AccessibilityTypes::State ButtonDropDown::GetAccessibleState() {
- return AccessibilityTypes::STATE_HASPOPUP;
+void ButtonDropDown::GetAccessibleState(ui::AccessibleViewState* state) {
+ CustomButton::GetAccessibleState(state);
+ state->role = ui::AccessibilityTypes::ROLE_BUTTONDROPDOWN;
+ state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
+ state->state = ui::AccessibilityTypes::STATE_HASPOPUP;
}
} // namespace views
diff --git a/views/controls/button/button_dropdown.h b/views/controls/button/button_dropdown.h
index 07b8276..32f2c5c 100644
--- a/views/controls/button/button_dropdown.h
+++ b/views/controls/button/button_dropdown.h
@@ -26,9 +26,7 @@ class ButtonDropDown : public ImageButton {
virtual ~ButtonDropDown();
// Accessibility accessors, overridden from View.
- virtual string16 GetAccessibleDefaultAction() OVERRIDE;
- virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
- virtual AccessibilityTypes::State GetAccessibleState() OVERRIDE;
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
private:
// Overridden from CustomButton
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
index 719dfd8..2a34cc5 100644
--- a/views/controls/button/checkbox.cc
+++ b/views/controls/button/checkbox.cc
@@ -5,6 +5,7 @@
#include "views/controls/button/checkbox.h"
#include "base/logging.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/gfx/canvas.h"
#include "views/controls/label.h"
@@ -158,12 +159,10 @@ void Checkbox::OnBlur() {
label_->set_paint_as_focused(false);
}
-AccessibilityTypes::Role Checkbox::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_CHECKBUTTON;
-}
-
-AccessibilityTypes::State Checkbox::GetAccessibleState() {
- return checked() ? AccessibilityTypes::STATE_CHECKED : 0;
+void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) {
+ Button::GetAccessibleState(state);
+ state->role = ui::AccessibilityTypes::ROLE_CHECKBUTTON;
+ state->state = checked() ? ui::AccessibilityTypes::STATE_CHECKED : 0;
}
std::string Checkbox::GetClassName() const {
diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h
index 71d218d..801b0fd 100644
--- a/views/controls/button/checkbox.h
+++ b/views/controls/button/checkbox.h
@@ -57,8 +57,7 @@ class Checkbox : public NativeButton {
virtual void OnBlur() OVERRIDE;
// Accessibility accessors, overridden from View.
- virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
- virtual AccessibilityTypes::State GetAccessibleState() OVERRIDE;
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
// Overridden from NativeButton:
virtual void SetLabel(const std::wstring& label) OVERRIDE;
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc
index 1696d14..fc349a2 100644
--- a/views/controls/button/custom_button.cc
+++ b/views/controls/button/custom_button.cc
@@ -4,9 +4,11 @@
#include "views/controls/button/custom_button.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/animation/throb_animation.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "views/screen.h"
+#include "views/widget/widget.h"
namespace views {
@@ -57,24 +59,23 @@ void CustomButton::SetAnimationDuration(int duration) {
////////////////////////////////////////////////////////////////////////////////
// CustomButton, View overrides:
-AccessibilityTypes::State CustomButton::GetAccessibleState() {
- int state = 0;
+void CustomButton::GetAccessibleState(ui::AccessibleViewState* state) {
+ Button::GetAccessibleState(state);
switch (state_) {
case BS_HOT:
- state = AccessibilityTypes::STATE_HOTTRACKED;
+ state->state = ui::AccessibilityTypes::STATE_HOTTRACKED;
break;
case BS_PUSHED:
- state = AccessibilityTypes::STATE_PRESSED;
+ state->state = ui::AccessibilityTypes::STATE_PRESSED;
break;
case BS_DISABLED:
- state = AccessibilityTypes::STATE_UNAVAILABLE;
+ state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE;
break;
case BS_NORMAL:
case BS_COUNT:
// No additional accessibility state set for this button state.
break;
}
- return state;
}
void CustomButton::SetEnabled(bool enabled) {
@@ -248,8 +249,10 @@ void CustomButton::SetHotTracked(bool flag) {
if (state_ != BS_DISABLED)
SetState(flag ? BS_HOT : BS_NORMAL);
- if (flag)
- NotifyAccessibilityEvent(AccessibilityTypes::EVENT_FOCUS);
+ if (flag) {
+ GetWidget()->NotifyAccessibilityEvent(
+ this, ui::AccessibilityTypes::EVENT_FOCUS, true);
+ }
}
bool CustomButton::IsHotTracked() const {
diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h
index 17dafbf..1a0f75e 100644
--- a/views/controls/button/custom_button.h
+++ b/views/controls/button/custom_button.h
@@ -48,7 +48,7 @@ class CustomButton : public Button,
void SetAnimationDuration(int duration);
// Overridden from View:
- virtual AccessibilityTypes::State GetAccessibleState() OVERRIDE;
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual void SetEnabled(bool enabled) OVERRIDE;
virtual bool IsEnabled() const OVERRIDE;
virtual bool IsFocusable() const OVERRIDE;
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc
index f88b106..db138bb 100644
--- a/views/controls/button/menu_button.cc
+++ b/views/controls/button/menu_button.cc
@@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "grit/app_strings.h"
#include "grit/app_resources.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -260,16 +261,11 @@ void MenuButton::OnMouseExited(const MouseEvent& event) {
//
////////////////////////////////////////////////////////////////////////////////
-string16 MenuButton::GetAccessibleDefaultAction() {
- return l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
-}
-
-AccessibilityTypes::Role MenuButton::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_BUTTONMENU;
-}
-
-AccessibilityTypes::State MenuButton::GetAccessibleState() {
- return AccessibilityTypes::STATE_HASPOPUP;
+void MenuButton::GetAccessibleState(ui::AccessibleViewState* state) {
+ CustomButton::GetAccessibleState(state);
+ state->role = ui::AccessibilityTypes::ROLE_BUTTONMENU;
+ state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
+ state->state = ui::AccessibilityTypes::STATE_HASPOPUP;
}
std::string MenuButton::GetClassName() const {
diff --git a/views/controls/button/menu_button.h b/views/controls/button/menu_button.h
index 55f5a89..c6f3092 100644
--- a/views/controls/button/menu_button.h
+++ b/views/controls/button/menu_button.h
@@ -58,9 +58,7 @@ class MenuButton : public TextButton {
virtual bool OnKeyReleased(const KeyEvent& e);
// Accessibility accessors, overridden from View.
- virtual string16 GetAccessibleDefaultAction() OVERRIDE;
- virtual AccessibilityTypes::Role GetAccessibleRole() OVERRIDE;
- virtual AccessibilityTypes::State GetAccessibleState() OVERRIDE;
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
// Returns views/MenuButton.
virtual std::string GetClassName() const;
diff --git a/views/controls/button/native_button_win.cc b/views/controls/button/native_button_win.cc
index fbba56a..2783c84 100644
--- a/views/controls/button/native_button_win.cc
+++ b/views/controls/button/native_button_win.cc
@@ -11,6 +11,7 @@
#include "base/win/scoped_comptr.h"
#include "base/win/win_util.h"
#include "base/win/windows_version.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "views/controls/button/checkbox.h"
#include "views/controls/button/native_button.h"
#include "views/controls/button/radio_button.h"
@@ -71,18 +72,19 @@ void NativeButtonWin::UpdateDefault() {
}
void NativeButtonWin::UpdateAccessibleName() {
- string16 name;
- if (native_button_->GetAccessibleName(&name)) {
- base::win::ScopedComPtr<IAccPropServices> pAccPropServices;
- HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER,
- IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices));
- if (SUCCEEDED(hr)) {
- VARIANT var;
- var.vt = VT_BSTR;
- var.bstrVal = SysAllocString(name.c_str());
- hr = pAccPropServices->SetHwndProp(native_view(), OBJID_WINDOW,
- CHILDID_SELF, PROPID_ACC_NAME, var);
- }
+ ui::AccessibleViewState state;
+ native_button_->GetAccessibleState(&state);
+ string16 name = state.name;
+ base::win::ScopedComPtr<IAccPropServices> pAccPropServices;
+ HRESULT hr = CoCreateInstance(
+ CLSID_AccPropServices, NULL, CLSCTX_SERVER,
+ IID_IAccPropServices, reinterpret_cast<void**>(&pAccPropServices));
+ if (SUCCEEDED(hr)) {
+ VARIANT var;
+ var.vt = VT_BSTR;
+ var.bstrVal = SysAllocString(name.c_str());
+ hr = pAccPropServices->SetHwndProp(native_view(), OBJID_WINDOW,
+ CHILDID_SELF, PROPID_ACC_NAME, var);
}
}
diff --git a/views/controls/button/radio_button.cc b/views/controls/button/radio_button.cc
index 4074da4..f162f2c 100644
--- a/views/controls/button/radio_button.cc
+++ b/views/controls/button/radio_button.cc
@@ -5,6 +5,7 @@
#include "views/controls/button/radio_button.h"
#include "base/logging.h"
+#include "ui/base/accessibility/accessible_view_state.h"
#include "views/widget/root_view.h"
namespace views {
@@ -60,8 +61,9 @@ void RadioButton::SetChecked(bool checked) {
////////////////////////////////////////////////////////////////////////////////
// RadioButton, View overrides:
-AccessibilityTypes::Role RadioButton::GetAccessibleRole() {
- return AccessibilityTypes::ROLE_RADIOBUTTON;
+void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
+ Checkbox::GetAccessibleState(state);
+ state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
}
View* RadioButton::GetSelectedViewForGroup(int group_id) {
diff --git a/views/controls/button/radio_button.h b/views/controls/button/radio_button.h
index 7ea35f5..5ff6f76 100644
--- a/views/controls/button/radio_button.h
+++ b/views/controls/button/radio_button.h
@@ -22,16 +22,18 @@ class RadioButton : public Checkbox {
virtual ~RadioButton();
// Overridden from Checkbox:
- virtual void SetChecked(bool checked);
+ virtual void SetChecked(bool checked) OVERRIDE;
// Overridden from View:
- virtual AccessibilityTypes::Role GetAccessibleRole();
- virtual View* GetSelectedViewForGroup(int group_id);
- virtual bool IsGroupFocusTraversable() const;
- virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
+ virtual View* GetSelectedViewForGroup(int group_id) OVERRIDE;
+ virtual bool IsGroupFocusTraversable() const OVERRIDE;
+ virtual void OnMouseReleased(const MouseEvent& event, bool canceled)
+ OVERRIDE;
protected:
- virtual std::string GetClassName() const;
+ // Overridden from View:
+ virtual std::string GetClassName() const OVERRIDE;
// Overridden from NativeButton:
virtual NativeButtonWrapper* CreateWrapper();