summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-23 13:14:58 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-23 13:14:58 +0000
commitbf9940639b4a942b18837f532d71bf4e0855a39e (patch)
tree9ce2a7675ea516c4a3a0787824d19f7d61c3875c /views
parentf34fc289bcfff2304a854b2d8bf29a78979c75c3 (diff)
downloadchromium_src-bf9940639b4a942b18837f532d71bf4e0855a39e.zip
chromium_src-bf9940639b4a942b18837f532d71bf4e0855a39e.tar.gz
chromium_src-bf9940639b4a942b18837f532d71bf4e0855a39e.tar.bz2
Change chrome to use the new native themed radio button.
While testing the chromeos password changed dialog, I noticed that the dialog was clipped at the bottom, so that the text field to enter the old password was not fully visible. This was with and without my change. To fix, I increase the height of the dialog, hence the locale_settings.grd change. BUG=None TEST=Make sure all uses of radio buttons in chrome, on all platforms including chromeos, work as expected. The look may be slightly different, but the behaviour should be the same. To test the password changed dialog on chromeos, login and then logout with a given account. Change the password of that account (with another computer for example) and then log back in using the new password. The text field at the bottom should not be clipped. Review URL: http://codereview.chromium.org/6955002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/button/native_button_gtk.cc12
-rw-r--r--views/controls/button/native_button_gtk.h4
-rw-r--r--views/controls/button/native_button_win.cc4
-rw-r--r--views/controls/button/native_button_win.h2
-rw-r--r--views/controls/button/native_button_wrapper.h4
-rw-r--r--views/controls/button/radio_button.cc73
-rw-r--r--views/controls/button/radio_button.h20
-rw-r--r--views/examples/radio_button_example.cc36
-rw-r--r--views/examples/radio_button_example.h10
-rw-r--r--views/focus/focus_manager_unittest.cc7
10 files changed, 95 insertions, 77 deletions
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
index 2114553..58d221a 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -184,15 +184,15 @@ void NativeCheckboxGtk::UpdateChecked() {
}
////////////////////////////////////////////////////////////////////////////////
-NativeRadioButtonGtk::NativeRadioButtonGtk(RadioButton* radio_button)
+NativeRadioButtonGtk::NativeRadioButtonGtk(NativeRadioButton* radio_button)
: NativeCheckboxGtk(radio_button) {
}
NativeRadioButtonGtk::~NativeRadioButtonGtk() {
}
-RadioButton* NativeRadioButtonGtk::radio_button() {
- return static_cast<RadioButton*>(native_button_);
+NativeRadioButton* NativeRadioButtonGtk::radio_button() {
+ return static_cast<NativeRadioButton*>(native_button_);
}
////////////////////////////////////////////////////////////////////////////////
@@ -256,7 +256,7 @@ void NativeRadioButtonGtk::ViewHierarchyChanged(bool is_add,
i != other.end();
++i) {
if (*i != native_button_) {
- if ((*i)->GetClassName() != RadioButton::kViewClassName) {
+ if ((*i)->GetClassName() != NativeRadioButton::kViewClassName) {
NOTREACHED() << "radio-button has same group as other non "
"radio-button views.";
continue;
@@ -265,7 +265,7 @@ void NativeRadioButtonGtk::ViewHierarchyChanged(bool is_add,
// A button without wrapper will be added to the group in
// its own ViewHierachyChanged.
NativeButtonWrapper* wrapper =
- static_cast<RadioButton*>(*i)->native_wrapper();
+ static_cast<NativeRadioButton*>(*i)->native_wrapper();
if (wrapper) {
SetGroupFrom(wrapper);
break;
@@ -303,7 +303,7 @@ NativeButtonWrapper* NativeButtonWrapper::CreateCheckboxWrapper(
// static
NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper(
- RadioButton* radio_button) {
+ NativeRadioButton* radio_button) {
return new NativeRadioButtonGtk(radio_button);
}
diff --git a/views/controls/button/native_button_gtk.h b/views/controls/button/native_button_gtk.h
index 91a1ce1..2b1b8926 100644
--- a/views/controls/button/native_button_gtk.h
+++ b/views/controls/button/native_button_gtk.h
@@ -86,7 +86,7 @@ class NativeCheckboxGtk : public NativeButtonGtk {
// A View that hosts a native Gtk radio button.
class NativeRadioButtonGtk : public NativeCheckboxGtk {
public:
- explicit NativeRadioButtonGtk(RadioButton* radio_button);
+ explicit NativeRadioButtonGtk(NativeRadioButton* radio_button);
virtual ~NativeRadioButtonGtk();
protected:
@@ -100,7 +100,7 @@ class NativeRadioButtonGtk : public NativeCheckboxGtk {
static void CallToggled(GtkButton* widget, NativeRadioButtonGtk* button);
// Return RadioButton we are bound to.
- RadioButton* radio_button();
+ NativeRadioButton* radio_button();
// Set the gtk radio button's group to that of given wrapper's gruop.
void SetGroupFrom(NativeButtonWrapper* wrapper);
// Invoked when the radio button's state is changed.
diff --git a/views/controls/button/native_button_win.cc b/views/controls/button/native_button_win.cc
index 66a96d9..03a1144 100644
--- a/views/controls/button/native_button_win.cc
+++ b/views/controls/button/native_button_win.cc
@@ -242,7 +242,7 @@ void NativeCheckboxWin::NativeControlCreated(HWND control_hwnd) {
////////////////////////////////////////////////////////////////////////////////
// NativeRadioButtonWin, public:
-NativeRadioButtonWin::NativeRadioButtonWin(RadioButton* radio_button)
+NativeRadioButtonWin::NativeRadioButtonWin(NativeRadioButton* radio_button)
: NativeCheckboxWin(radio_button) {
}
@@ -283,7 +283,7 @@ NativeButtonWrapper* NativeButtonWrapper::CreateCheckboxWrapper(
// static
NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper(
- RadioButton* radio_button) {
+ NativeRadioButton* radio_button) {
return new NativeRadioButtonWin(radio_button);
}
diff --git a/views/controls/button/native_button_win.h b/views/controls/button/native_button_win.h
index 3061353..97acc3e 100644
--- a/views/controls/button/native_button_win.h
+++ b/views/controls/button/native_button_win.h
@@ -97,7 +97,7 @@ class NativeCheckboxWin : public NativeButtonWin {
// A View that hosts a native Windows radio button.
class NativeRadioButtonWin : public NativeCheckboxWin {
public:
- explicit NativeRadioButtonWin(RadioButton* radio_button);
+ explicit NativeRadioButtonWin(NativeRadioButton* radio_button);
virtual ~NativeRadioButtonWin();
protected:
diff --git a/views/controls/button/native_button_wrapper.h b/views/controls/button/native_button_wrapper.h
index 37968c0..8bb5bb2 100644
--- a/views/controls/button/native_button_wrapper.h
+++ b/views/controls/button/native_button_wrapper.h
@@ -12,7 +12,7 @@ namespace views {
class Checkbox;
class NativeButtonBase;
-class RadioButton;
+class NativeRadioButton;
class View;
// A specialization of NativeControlWrapper that hosts a platform-native button.
@@ -71,7 +71,7 @@ class NativeButtonWrapper {
NativeButtonBase* button);
static NativeButtonWrapper* CreateCheckboxWrapper(Checkbox* checkbox);
static NativeButtonWrapper* CreateRadioButtonWrapper(
- RadioButton* radio_button);
+ NativeRadioButton* radio_button);
protected:
virtual ~NativeButtonWrapper() {}
diff --git a/views/controls/button/radio_button.cc b/views/controls/button/radio_button.cc
index 249cba2..f49f70e 100644
--- a/views/controls/button/radio_button.cc
+++ b/views/controls/button/radio_button.cc
@@ -11,27 +11,27 @@
namespace views {
// static
-const char RadioButton::kViewClassName[] = "views/RadioButton";
+const char NativeRadioButton::kViewClassName[] = "views/NativeRadioButton";
// static
-const char RadioButtonNt::kViewClassName[] = "views/RadioButtonNt";
+const char RadioButton::kViewClassName[] = "views/RadioButton";
////////////////////////////////////////////////////////////////////////////////
-// RadioButton, public:
+// NativeRadioButton, public:
-RadioButton::RadioButton(const std::wstring& label, int group_id)
+NativeRadioButton::NativeRadioButton(const std::wstring& label, int group_id)
: Checkbox(label) {
SetGroup(group_id);
}
-RadioButton::~RadioButton() {
+NativeRadioButton::~NativeRadioButton() {
}
////////////////////////////////////////////////////////////////////////////////
-// RadioButton, Checkbox overrides:
+// NativeRadioButton, Checkbox overrides:
-void RadioButton::SetChecked(bool checked) {
- if (checked == RadioButton::checked())
+void NativeRadioButton::SetChecked(bool checked) {
+ if (checked == NativeRadioButton::checked())
return;
if (native_wrapper_ &&
!native_wrapper_->UsesNativeRadioButtonGroup() && checked) {
@@ -52,7 +52,7 @@ void RadioButton::SetChecked(bool checked) {
"radio-button views.";
continue;
}
- RadioButton* peer = static_cast<RadioButton*>(*i);
+ NativeRadioButton* peer = static_cast<NativeRadioButton*>(*i);
peer->SetChecked(false);
}
}
@@ -62,14 +62,14 @@ void RadioButton::SetChecked(bool checked) {
}
////////////////////////////////////////////////////////////////////////////////
-// RadioButton, View overrides:
+// NativeRadioButton, View overrides:
-void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
+void NativeRadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
Checkbox::GetAccessibleState(state);
state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
}
-View* RadioButton::GetSelectedViewForGroup(int group_id) {
+View* NativeRadioButton::GetSelectedViewForGroup(int group_id) {
std::vector<View*> views;
GetWidget()->GetRootView()->GetViewsWithGroup(group_id, &views);
if (views.empty())
@@ -77,20 +77,20 @@ View* RadioButton::GetSelectedViewForGroup(int group_id) {
for (std::vector<View*>::const_iterator iter = views.begin();
iter != views.end(); ++iter) {
- RadioButton* radio_button = static_cast<RadioButton*>(*iter);
+ NativeRadioButton* radio_button = static_cast<NativeRadioButton*>(*iter);
if (radio_button->checked())
return radio_button;
}
return NULL;
}
-bool RadioButton::IsGroupFocusTraversable() const {
+bool NativeRadioButton::IsGroupFocusTraversable() const {
// When focusing a radio button with tab/shift+tab, only the selected button
// from the group should be focused.
return false;
}
-void RadioButton::OnMouseReleased(const MouseEvent& event) {
+void NativeRadioButton::OnMouseReleased(const MouseEvent& event) {
// Set the checked state to true only if we are unchecked, since we can't
// be toggled on and off like a checkbox.
if (!checked() && HitTestLabel(event))
@@ -99,38 +99,39 @@ void RadioButton::OnMouseReleased(const MouseEvent& event) {
OnMouseCaptureLost();
}
-void RadioButton::OnMouseCaptureLost() {
+void NativeRadioButton::OnMouseCaptureLost() {
native_wrapper_->SetPushed(false);
ButtonPressed();
}
-std::string RadioButton::GetClassName() const {
+std::string NativeRadioButton::GetClassName() const {
return kViewClassName;
}
////////////////////////////////////////////////////////////////////////////////
-// RadioButton, NativeButton overrides:
+// NativeRadioButton, NativeButton overrides:
-NativeButtonWrapper* RadioButton::CreateWrapper() {
+NativeButtonWrapper* NativeRadioButton::CreateWrapper() {
return NativeButtonWrapper::CreateRadioButtonWrapper(this);
}
////////////////////////////////////////////////////////////////////////////////
//
-// RadioButtonNt
+// RadioButton
//
////////////////////////////////////////////////////////////////////////////////
-RadioButtonNt::RadioButtonNt(const std::wstring& label, int group_id)
+RadioButton::RadioButton(const std::wstring& label, int group_id)
: CheckboxNt(label) {
SetGroup(group_id);
+ focusable_ = true;
}
-RadioButtonNt::~RadioButtonNt() {
+RadioButton::~RadioButton() {
}
-void RadioButtonNt::SetChecked(bool checked) {
- if (checked == RadioButtonNt::checked())
+void RadioButton::SetChecked(bool checked) {
+ if (checked == RadioButton::checked())
return;
if (checked) {
// We can't just get the root view here because sometimes the radio
@@ -150,7 +151,7 @@ void RadioButtonNt::SetChecked(bool checked) {
"radio-button-nt views.";
continue;
}
- RadioButtonNt* peer = static_cast<RadioButtonNt*>(*i);
+ RadioButton* peer = static_cast<RadioButton*>(*i);
peer->SetChecked(false);
}
}
@@ -159,16 +160,16 @@ void RadioButtonNt::SetChecked(bool checked) {
CheckboxNt::SetChecked(checked);
}
-std::string RadioButtonNt::GetClassName() const {
+std::string RadioButton::GetClassName() const {
return kViewClassName;
}
-void RadioButtonNt::GetAccessibleState(ui::AccessibleViewState* state) {
+void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
CheckboxNt::GetAccessibleState(state);
state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
}
-View* RadioButtonNt::GetSelectedViewForGroup(int group_id) {
+View* RadioButton::GetSelectedViewForGroup(int group_id) {
std::vector<View*> views;
GetWidget()->GetRootView()->GetViewsWithGroup(group_id, &views);
if (views.empty())
@@ -177,28 +178,36 @@ View* RadioButtonNt::GetSelectedViewForGroup(int group_id) {
for (std::vector<View*>::const_iterator iter = views.begin();
iter != views.end(); ++iter) {
// REVIEW: why don't we check the runtime type like is done above?
- RadioButtonNt* radio_button = static_cast<RadioButtonNt*>(*iter);
+ RadioButton* radio_button = static_cast<RadioButton*>(*iter);
if (radio_button->checked())
return radio_button;
}
return NULL;
}
-bool RadioButtonNt::IsGroupFocusTraversable() const {
+bool RadioButton::IsGroupFocusTraversable() const {
// When focusing a radio button with tab/shift+tab, only the selected button
// from the group should be focused.
return false;
}
-void RadioButtonNt::NotifyClick(const views::Event& event) {
+void RadioButton::OnFocus() {
+ CheckboxNt::OnFocus();
+ SetChecked(true);
+ views::MouseEvent event(ui::ET_MOUSE_PRESSED, 0, 0, 0);
+ TextButtonBase::NotifyClick(event);
+}
+
+void RadioButton::NotifyClick(const views::Event& event) {
// Set the checked state to true only if we are unchecked, since we can't
// be toggled on and off like a checkbox.
if (!checked())
SetChecked(true);
RequestFocus();
+ TextButtonBase::NotifyClick(event);
}
-gfx::NativeTheme::Part RadioButtonNt::GetThemePart() const {
+gfx::NativeTheme::Part RadioButton::GetThemePart() const {
return gfx::NativeTheme::kRadio;
}
diff --git a/views/controls/button/radio_button.h b/views/controls/button/radio_button.h
index c922558..bd34394 100644
--- a/views/controls/button/radio_button.h
+++ b/views/controls/button/radio_button.h
@@ -13,13 +13,13 @@ namespace views {
class NativeRadioButtonGtk;
// A Checkbox subclass representing a radio button.
-class RadioButton : public Checkbox {
+class NativeRadioButton : public Checkbox {
public:
// The button's class name.
static const char kViewClassName[];
- RadioButton(const std::wstring& label, int group_id);
- virtual ~RadioButton();
+ NativeRadioButton(const std::wstring& label, int group_id);
+ virtual ~NativeRadioButton();
// Overridden from Checkbox:
virtual void SetChecked(bool checked) OVERRIDE;
@@ -43,27 +43,25 @@ class RadioButton : public Checkbox {
NativeButtonWrapper* native_wrapper() { return native_wrapper_; }
- DISALLOW_COPY_AND_ASSIGN(RadioButton);
+ DISALLOW_COPY_AND_ASSIGN(NativeRadioButton);
};
// A native themed class representing a radio button. This class does not use
// platform specific objects to replicate the native platforms looks and feel.
-//
-// This class will eventually be renamed to RadioButton to replace the class
-// above.
-class RadioButtonNt : public CheckboxNt {
+class RadioButton : public CheckboxNt {
public:
// The button's class name.
static const char kViewClassName[];
- RadioButtonNt(const std::wstring& label, int group_id);
- virtual ~RadioButtonNt();
+ RadioButton(const std::wstring& label, int group_id);
+ virtual ~RadioButton();
// Overridden from View:
virtual std::string GetClassName() const OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual View* GetSelectedViewForGroup(int group_id) OVERRIDE;
virtual bool IsGroupFocusTraversable() const OVERRIDE;
+ virtual void OnFocus() OVERRIDE;
// Overridden from Button:
virtual void NotifyClick(const views::Event& event) OVERRIDE;
@@ -74,7 +72,7 @@ class RadioButtonNt : public CheckboxNt {
// Overridden from CheckboxNt:
virtual void SetChecked(bool checked) OVERRIDE;
- DISALLOW_COPY_AND_ASSIGN(RadioButtonNt);
+ DISALLOW_COPY_AND_ASSIGN(RadioButton);
};
} // namespace views
diff --git a/views/examples/radio_button_example.cc b/views/examples/radio_button_example.cc
index c61eef5..252a25a 100644
--- a/views/examples/radio_button_example.cc
+++ b/views/examples/radio_button_example.cc
@@ -5,13 +5,14 @@
#include "views/examples/radio_button_example.h"
#include "base/stringprintf.h"
+#include "views/controls/button/text_button.h"
#include "views/layout/grid_layout.h"
#include "views/view.h"
namespace examples {
RadioButtonExample::RadioButtonExample(ExamplesMain* main)
- : ExampleBase(main) {
+ : ExampleBase(main), count_(0) {
}
RadioButtonExample::~RadioButtonExample() {
@@ -26,16 +27,17 @@ void RadioButtonExample::CreateExampleView(views::View* container) {
status_ = new views::TextButton(this, L"Show Status");
int group = 1;
- for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
- radio_buttons_[i] = new views::RadioButton(
+ for (size_t i = 0; i < arraysize(native_radio_buttons_); ++i) {
+ native_radio_buttons_[i] = new views::NativeRadioButton(
base::StringPrintf( L"Radio %d in group %d", i + 1, group), group);
+ native_radio_buttons_[i]->set_listener(this);
}
++group;
- for (size_t i = 0; i < arraysize(radio_buttons_nt_); ++i) {
- radio_buttons_nt_[i] = new views::RadioButtonNt(
+ for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
+ radio_buttons_[i] = new views::RadioButton(
base::StringPrintf( L"Radio %d in group %d", i + 1, group), group);
- radio_buttons_nt_[i]->SetFocusable(true);
+ radio_buttons_[i]->set_listener(this);
}
views::GridLayout* layout = new views::GridLayout(container);
@@ -44,13 +46,13 @@ void RadioButtonExample::CreateExampleView(views::View* container) {
views::ColumnSet* column_set = layout->AddColumnSet(0);
column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
1.0f, views::GridLayout::USE_PREF, 0, 0);
- for (size_t i = 0; i < arraysize(radio_buttons_); i++) {
+ for (size_t i = 0; i < arraysize(native_radio_buttons_); ++i) {
layout->StartRow(0, 0);
- layout->AddView(radio_buttons_[i]);
+ layout->AddView(native_radio_buttons_[i]);
}
- for (size_t i = 0; i < arraysize(radio_buttons_nt_); i++) {
+ for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
layout->StartRow(0, 0);
- layout->AddView(radio_buttons_nt_[i]);
+ layout->AddView(radio_buttons_[i]);
}
layout->StartRow(0, 0);
layout->AddView(select_);
@@ -61,17 +63,19 @@ void RadioButtonExample::CreateExampleView(views::View* container) {
void RadioButtonExample::ButtonPressed(views::Button* sender,
const views::Event& event) {
if (sender == select_) {
- radio_buttons_[0]->SetChecked(true);
- radio_buttons_nt_[2]->SetChecked(true);
+ native_radio_buttons_[0]->SetChecked(true);
+ radio_buttons_[2]->SetChecked(true);
} else if (sender == status_) {
// Show the state of radio buttons.
PrintStatus(L"Group1: 1:%ls, 2:%ls, 3:%ls Group2: 1:%ls, 2:%ls, 3:%ls",
+ IntToOnOff(native_radio_buttons_[0]->checked()),
+ IntToOnOff(native_radio_buttons_[1]->checked()),
+ IntToOnOff(native_radio_buttons_[2]->checked()),
IntToOnOff(radio_buttons_[0]->checked()),
IntToOnOff(radio_buttons_[1]->checked()),
- IntToOnOff(radio_buttons_[2]->checked()),
- IntToOnOff(radio_buttons_nt_[0]->checked()),
- IntToOnOff(radio_buttons_nt_[1]->checked()),
- IntToOnOff(radio_buttons_nt_[2]->checked()));
+ IntToOnOff(radio_buttons_[2]->checked()));
+ } else {
+ PrintStatus(L"Pressed! count:%d", ++count_);
}
}
diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h
index 72217e2..4af37af 100644
--- a/views/examples/radio_button_example.h
+++ b/views/examples/radio_button_example.h
@@ -11,9 +11,12 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "views/controls/button/radio_button.h"
-#include "views/controls/button/text_button.h"
#include "views/examples/example_base.h"
+namespace events {
+class TextButton;
+}
+
namespace examples {
class RadioButtonExample : public ExampleBase,
@@ -32,13 +35,16 @@ class RadioButtonExample : public ExampleBase,
const views::Event& event) OVERRIDE;
// Two groups of 3 radio buttons.
+ views::NativeRadioButton* native_radio_buttons_[3];
views::RadioButton* radio_buttons_[3];
- views::RadioButtonNt* radio_buttons_nt_[3];
// Control button to select radio buttons, and show the status of buttons.
views::TextButton* select_;
views::TextButton* status_;
+ // The number of times the button is pressed.
+ int count_;
+
DISALLOW_COPY_AND_ASSIGN(RadioButtonExample);
};
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index b891cae..4f59eaa 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -874,10 +874,11 @@ class TestCheckbox : public Checkbox {
}
};
-class TestRadioButton : public RadioButton {
+class TestRadioButton : public NativeRadioButton {
public:
- explicit TestRadioButton(const std::wstring& text) : RadioButton(text, 1) {
- };
+ explicit TestRadioButton(const std::wstring& text)
+ : NativeRadioButton(text, 1) {
+ }
virtual gfx::NativeView TestGetNativeControlView() {
return native_wrapper_->GetTestingHandle();
}