Commit df798cbf authored by msw@chromium.org's avatar msw@chromium.org

Make LabelButton STYLE_NATIVE_TEXTBUTTON focusable; etc.

Make LabelButton focusable on set_style(STYLE_NATIVE_TEXTBUTTON).
(this matches NativeTextButton::Init behavior)

Change NativeTextButton to LabelButton in FocusTraversalTest like:
https://codereview.chromium.org/13584010 Patch Set 4.

Update MessageLoopForUI...RunWithDispatcher() test comments.

BUG=155363,226814
TEST=native style LabelButtons are focusable by default. Tests pass.
R=tfarina@chromium.org,sky@chromium.org
TBR=sky@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192519 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d0a3e0c
...@@ -126,8 +126,10 @@ void LabelButton::SetStyle(ButtonStyle style) { ...@@ -126,8 +126,10 @@ void LabelButton::SetStyle(ButtonStyle style) {
// Inset the button focus rect from the actual border; roughly match Windows. // Inset the button focus rect from the actual border; roughly match Windows.
if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON) if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON)
set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3)); set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3));
if (style == STYLE_BUTTON || style_ == STYLE_NATIVE_TEXTBUTTON) if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON)
label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
if (style == STYLE_NATIVE_TEXTBUTTON)
set_focusable(true);
if (style == STYLE_BUTTON) { if (style == STYLE_BUTTON) {
set_min_size(gfx::Size(70, 31)); set_min_size(gfx::Size(70, 31));
const SkColor color = GetNativeTheme()->GetSystemColor( const SkColor color = GetNativeTheme()->GetSystemColor(
......
...@@ -85,7 +85,6 @@ TEST_F(FocusManagerTest, FocusStoreRestore) { ...@@ -85,7 +85,6 @@ TEST_F(FocusManagerTest, FocusStoreRestore) {
view->RequestFocus(); view->RequestFocus();
RunPendingMessages(); RunPendingMessages();
// MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler());
// Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/details/520043/error-converting-from-null-to-a-pointer-type-in-std-pair // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/details/520043/error-converting-from-null-to-a-pointer-type-in-std-pair
views::View* null_view = NULL; views::View* null_view = NULL;
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
#include "ui/views/focus/focus_manager.h" #include "ui/views/focus/focus_manager.h"
#include "base/run_loop.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "ui/base/models/combobox_model.h" #include "ui/base/models/combobox_model.h"
#include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/radio_button.h" #include "ui/views/controls/button/radio_button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/link.h" #include "ui/views/controls/link.h"
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
#include "ui/views/controls/scroll_view.h" #include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane.h" #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/views/focus/accelerator_handler.h"
#include "ui/views/focus/focus_manager_test.h" #include "ui/views/focus/focus_manager_test.h"
#include "ui/views/widget/root_view.h" #include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -102,7 +104,7 @@ class PaneView : public View, public FocusTraversable { ...@@ -102,7 +104,7 @@ class PaneView : public View, public FocusTraversable {
focus_search_ = focus_search; focus_search_ = focus_search;
} }
// Overridden from views::View: // Overridden from View:
virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE { virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE {
if (focus_search_) if (focus_search_)
return this; return this;
...@@ -110,8 +112,8 @@ class PaneView : public View, public FocusTraversable { ...@@ -110,8 +112,8 @@ class PaneView : public View, public FocusTraversable {
return NULL; return NULL;
} }
// Overridden from views::FocusTraversable: // Overridden from FocusTraversable:
virtual views::FocusSearch* GetFocusSearch() OVERRIDE { virtual FocusSearch* GetFocusSearch() OVERRIDE {
return focus_search_; return focus_search_;
} }
virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE { virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE {
...@@ -357,8 +359,8 @@ void FocusTraversalTest::InitContentView() { ...@@ -357,8 +359,8 @@ void FocusTraversalTest::InitContentView() {
y += label_height + gap_between_labels; y += label_height + gap_between_labels;
NativeTextButton* button = new NativeTextButton(NULL, LabelButton* button = new LabelButton(NULL, ASCIIToUTF16("Click me"));
ASCIIToUTF16("Click me")); button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
button->SetBounds(label_x, y + 10, 80, 30); button->SetBounds(label_x, y + 10, 80, 30);
button->set_id(kFruitButtonID); button->set_id(kFruitButtonID);
left_container_->AddChildView(button); left_container_->AddChildView(button);
...@@ -453,19 +455,22 @@ void FocusTraversalTest::InitContentView() { ...@@ -453,19 +455,22 @@ void FocusTraversalTest::InitContentView() {
y = 250; y = 250;
int width = 60; int width = 60;
button = new NativeTextButton(NULL, ASCIIToUTF16("OK")); button = new LabelButton(NULL, ASCIIToUTF16("OK"));
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
button->set_id(kOKButtonID); button->set_id(kOKButtonID);
button->SetIsDefault(true); button->SetIsDefault(true);
GetContentsView()->AddChildView(button); GetContentsView()->AddChildView(button);
button->SetBounds(150, y, width, 30); button->SetBounds(150, y, width, 30);
button = new NativeTextButton(NULL, ASCIIToUTF16("Cancel")); button = new LabelButton(NULL, ASCIIToUTF16("Cancel"));
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
button->set_id(kCancelButtonID); button->set_id(kCancelButtonID);
GetContentsView()->AddChildView(button); GetContentsView()->AddChildView(button);
button->SetBounds(220, y, width, 30); button->SetBounds(220, y, width, 30);
button = new NativeTextButton(NULL, ASCIIToUTF16("Help")); button = new LabelButton(NULL, ASCIIToUTF16("Help"));
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
button->set_id(kHelpButtonID); button->set_id(kHelpButtonID);
GetContentsView()->AddChildView(button); GetContentsView()->AddChildView(button);
button->SetBounds(290, y, width, 30); button->SetBounds(290, y, width, 30);
...@@ -518,7 +523,8 @@ void FocusTraversalTest::InitContentView() { ...@@ -518,7 +523,8 @@ void FocusTraversalTest::InitContentView() {
text_field->SetBounds(10, 10, 100, 20); text_field->SetBounds(10, 10, 100, 20);
text_field->set_id(kSearchTextfieldID); text_field->set_id(kSearchTextfieldID);
button = new NativeTextButton(NULL, ASCIIToUTF16("Search")); button = new LabelButton(NULL, ASCIIToUTF16("Search"));
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button); contents->AddChildView(button);
button->SetBounds(112, 5, 60, 30); button->SetBounds(112, 5, 60, 30);
button->set_id(kSearchButtonID); button->set_id(kSearchButtonID);
...@@ -541,11 +547,13 @@ void FocusTraversalTest::InitContentView() { ...@@ -541,11 +547,13 @@ void FocusTraversalTest::InitContentView() {
contents->set_focusable(true); contents->set_focusable(true);
contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE)); contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE));
contents->set_id(kThumbnailContainerID); contents->set_id(kThumbnailContainerID);
button = new NativeTextButton(NULL, ASCIIToUTF16("Star")); button = new LabelButton(NULL, ASCIIToUTF16("Star"));
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button); contents->AddChildView(button);
button->SetBounds(5, 5, 50, 30); button->SetBounds(5, 5, 50, 30);
button->set_id(kThumbnailStarID); button->set_id(kThumbnailStarID);
button = new NativeTextButton(NULL, ASCIIToUTF16("SuperStar")); button = new LabelButton(NULL, ASCIIToUTF16("SuperStar"));
button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON);
contents->AddChildView(button); contents->AddChildView(button);
button->SetBounds(60, 5, 100, 30); button->SetBounds(60, 5, 100, 30);
button->set_id(kThumbnailSuperStarID); button->set_id(kThumbnailSuperStarID);
...@@ -570,9 +578,8 @@ TEST_F(FocusTraversalTest, NormalTraversal) { ...@@ -570,9 +578,8 @@ TEST_F(FocusTraversalTest, NormalTraversal) {
kSearchTextfieldID, kSearchButtonID, kHelpLinkID, kSearchTextfieldID, kSearchButtonID, kHelpLinkID,
kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID }; kThumbnailContainerID, kThumbnailStarID, kThumbnailSuperStarID };
// Uncomment the following line if you want to test manually the UI of this // Uncomment the following line to manually test the UI of this test.
// test. // base::RunLoop(new AcceleratorHandler()).Run();
// MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler());
// Let's traverse the whole focus hierarchy (several times, to make sure it // Let's traverse the whole focus hierarchy (several times, to make sure it
// loops OK). // loops OK).
...@@ -623,9 +630,8 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { ...@@ -623,9 +630,8 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) {
v->SetEnabled(false); v->SetEnabled(false);
} }
// Uncomment the following line if you want to test manually the UI of this // Uncomment the following line to manually test the UI of this test.
// test. // base::RunLoop(new AcceleratorHandler()).Run();
// MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler());
View* focused_view; View* focused_view;
// Let's do one traversal (several times, to make sure it loops ok). // Let's do one traversal (several times, to make sure it loops ok).
...@@ -675,9 +681,8 @@ TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) { ...@@ -675,9 +681,8 @@ TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) {
v->SetVisible(false); v->SetVisible(false);
} }
// Uncomment the following line if you want to test manually the UI of this // Uncomment the following line to manually test the UI of this test.
// test. // base::RunLoop(new AcceleratorHandler()).Run();
// MessageLoopForUI::current()->RunWithDispatcher(new AcceleratorHandler());
View* focused_view; View* focused_view;
// Let's do one traversal (several times, to make sure it loops ok). // Let's do one traversal (several times, to make sure it loops ok).
......
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