Commit 3e4efae6 authored by msw@chromium.org's avatar msw@chromium.org

LabelButton: SetAccessibleName on SetText; update test.

SetAccessibleName to label text on SetText.
(this matches TextButtonBase::SetText behavior) 
Call SetText from LabelButton's constructor.

Use LabelButton in AccessibilityEventRouterViewsTest like: 
https://codereview.chromium.org/13584010 Patch Set 4. 

Note: This CL depends on https://codereview.chromium.org/13639003/

BUG=155363, 226814
TEST=LabelButtons have accessibility names. Tests pass. 
R=tfarina@chromium.org,sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/13689002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192557 0039d316-1c4b-4281-b951-d872f2087c98
parent 4e91f326
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/accessibility/accessible_view_state.h" #include "ui/base/accessibility/accessible_view_state.h"
#include "ui/views/controls/button/text_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/grid_layout.h" #include "ui/views/layout/grid_layout.h"
#include "ui/views/test/test_views_delegate.h" #include "ui/views/test/test_views_delegate.h"
...@@ -167,14 +167,17 @@ TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) { ...@@ -167,14 +167,17 @@ TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
// Create a contents view with 3 buttons. // Create a contents view with 3 buttons.
views::View* contents = new views::View(); views::View* contents = new views::View();
views::NativeTextButton* button1 = new views::NativeTextButton( views::LabelButton* button1 = new views::LabelButton(
NULL, ASCIIToUTF16(kButton1ASCII)); NULL, ASCIIToUTF16(kButton1ASCII));
button1->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button1); contents->AddChildView(button1);
views::NativeTextButton* button2 = new views::NativeTextButton( views::LabelButton* button2 = new views::LabelButton(
NULL, ASCIIToUTF16(kButton2ASCII)); NULL, ASCIIToUTF16(kButton2ASCII));
button2->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button2); contents->AddChildView(button2);
views::NativeTextButton* button3 = new views::NativeTextButton( views::LabelButton* button3 = new views::LabelButton(
NULL, ASCIIToUTF16(kButton3ASCII)); NULL, ASCIIToUTF16(kButton3ASCII));
button3->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button3); contents->AddChildView(button3);
// Put the view in a window. // Put the view in a window.
...@@ -232,8 +235,9 @@ TEST_F(AccessibilityEventRouterViewsTest, TestToolbarContext) { ...@@ -232,8 +235,9 @@ TEST_F(AccessibilityEventRouterViewsTest, TestToolbarContext) {
views::View* contents = new ViewWithNameAndRole( views::View* contents = new ViewWithNameAndRole(
ASCIIToUTF16(kToolbarNameASCII), ASCIIToUTF16(kToolbarNameASCII),
ui::AccessibilityTypes::ROLE_TOOLBAR); ui::AccessibilityTypes::ROLE_TOOLBAR);
views::NativeTextButton* button = new views::NativeTextButton( views::LabelButton* button = new views::LabelButton(
NULL, ASCIIToUTF16(kButtonNameASCII)); NULL, ASCIIToUTF16(kButtonNameASCII));
button->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button); contents->AddChildView(button);
// Put the view in a window. // Put the view in a window.
...@@ -276,8 +280,9 @@ TEST_F(AccessibilityEventRouterViewsTest, TestAlertContext) { ...@@ -276,8 +280,9 @@ TEST_F(AccessibilityEventRouterViewsTest, TestAlertContext) {
ui::AccessibilityTypes::ROLE_ALERT); ui::AccessibilityTypes::ROLE_ALERT);
views::Label* label = new views::Label(ASCIIToUTF16(kAlertTextASCII)); views::Label* label = new views::Label(ASCIIToUTF16(kAlertTextASCII));
contents->AddChildView(label); contents->AddChildView(label);
views::NativeTextButton* button = new views::NativeTextButton( views::LabelButton* button = new views::LabelButton(
NULL, ASCIIToUTF16(kButtonNameASCII)); NULL, ASCIIToUTF16(kButtonNameASCII));
button->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button); contents->AddChildView(button);
// Put the view in a window. // Put the view in a window.
......
...@@ -35,13 +35,14 @@ const char LabelButton::kViewClassName[] = "views/LabelButton"; ...@@ -35,13 +35,14 @@ const char LabelButton::kViewClassName[] = "views/LabelButton";
LabelButton::LabelButton(ButtonListener* listener, const string16& text) LabelButton::LabelButton(ButtonListener* listener, const string16& text)
: CustomButton(listener), : CustomButton(listener),
image_(new ImageView()), image_(new ImageView()),
label_(new Label(text)), label_(new Label()),
button_state_images_(), button_state_images_(),
button_state_colors_(), button_state_colors_(),
explicitly_set_colors_(), explicitly_set_colors_(),
is_default_(false), is_default_(false),
style_(STYLE_TEXTBUTTON) { style_(STYLE_TEXTBUTTON) {
SetAnimationDuration(kHoverAnimationDurationMs); SetAnimationDuration(kHoverAnimationDurationMs);
SetText(text);
AddChildView(image_); AddChildView(image_);
image_->set_interactive(false); image_->set_interactive(false);
...@@ -74,6 +75,7 @@ const string16& LabelButton::GetText() const { ...@@ -74,6 +75,7 @@ const string16& LabelButton::GetText() const {
} }
void LabelButton::SetText(const string16& text) { void LabelButton::SetText(const string16& text) {
SetAccessibleName(text);
label_->SetText(text); label_->SetText(text);
SetAccessibleName(text); SetAccessibleName(text);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment