diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 00:34:05 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 00:34:05 +0000 |
commit | 2362e4fe2905ab75d3230ebc3e307ae53e2b8362 (patch) | |
tree | e6d88357a2021811e0e354f618247217be8bb3da /views/controls/button/radio_button.cc | |
parent | db23ac3e713dc17509b2b15d3ee634968da45715 (diff) | |
download | chromium_src-2362e4fe2905ab75d3230ebc3e307ae53e2b8362.zip chromium_src-2362e4fe2905ab75d3230ebc3e307ae53e2b8362.tar.gz chromium_src-2362e4fe2905ab75d3230ebc3e307ae53e2b8362.tar.bz2 |
Move src/chrome/views to src/views. RS=darin http://crbug.com/11387
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/button/radio_button.cc')
-rw-r--r-- | views/controls/button/radio_button.cc | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/views/controls/button/radio_button.cc b/views/controls/button/radio_button.cc new file mode 100644 index 0000000..3f4820d --- /dev/null +++ b/views/controls/button/radio_button.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#include "views/controls/button/radio_button.h" + +#include "views/widget/root_view.h" + +namespace views { + +// static +const char RadioButton::kViewClassName[] = "views/RadioButton"; + +//////////////////////////////////////////////////////////////////////////////// +// RadioButton, public: + +RadioButton::RadioButton() : Checkbox() { +} + +RadioButton::RadioButton(const std::wstring& label) : Checkbox(label) { +} + +RadioButton::RadioButton(const std::wstring& label, int group_id) + : Checkbox(label) { + SetGroup(group_id); +} + +RadioButton::~RadioButton() { +} + +//////////////////////////////////////////////////////////////////////////////// +// RadioButton, Checkbox overrides: + +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 + // button isn't attached to a root view (e.g., if it's part of a tab page + // that is currently not active). + View* container = GetParent(); + while (container && container->GetParent()) + container = container->GetParent(); + if (container) { + std::vector<View*> other; + container->GetViewsWithGroup(GetGroup(), &other); + std::vector<View*>::iterator i; + for (i = other.begin(); i != other.end(); ++i) { + if (*i != this) { + RadioButton* peer = static_cast<RadioButton*>(*i); + peer->SetChecked(false); + } + } + } + } + Checkbox::SetChecked(checked); + +} + +//////////////////////////////////////////////////////////////////////////////// +// RadioButton, View overrides: + +View* RadioButton::GetSelectedViewForGroup(int group_id) { + std::vector<View*> views; + GetRootView()->GetViewsWithGroup(group_id, &views); + if (views.empty()) + return NULL; + + for (std::vector<View*>::const_iterator iter = views.begin(); + iter != views.end(); ++iter) { + RadioButton* radio_button = static_cast<RadioButton*>(*iter); + if (radio_button->checked()) + return radio_button; + } + return NULL; +} + +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 RadioButton::OnMouseReleased(const MouseEvent& event, bool canceled) { + native_wrapper_->SetPushed(false); + // 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() && !canceled && HitTestLabel(event)) + SetChecked(true); + + ButtonPressed(); +} + +std::string RadioButton::GetClassName() const { + return kViewClassName; +} + +//////////////////////////////////////////////////////////////////////////////// +// RadioButton, NativeButton overrides: + +void RadioButton::CreateWrapper() { + native_wrapper_ = NativeButtonWrapper::CreateRadioButtonWrapper(this); + native_wrapper_->UpdateLabel(); + native_wrapper_->UpdateChecked(); +} + +} // namespace views |