| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/button/radio_button.h" | 5 #include "ui/views/controls/button/radio_button.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "grit/ui_resources.h" |
| 8 #include "ui/base/accessibility/accessible_view_state.h" | 9 #include "ui/base/accessibility/accessible_view_state.h" |
| 10 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
| 10 | 12 |
| 11 namespace views { | 13 namespace views { |
| 12 | 14 |
| 13 // static | 15 // static |
| 14 const char RadioButton::kViewClassName[] = "views/RadioButton"; | 16 const char RadioButton::kViewClassName[] = "views/RadioButton"; |
| 15 | 17 |
| 16 RadioButton::RadioButton(const string16& label, int group_id) | 18 RadioButton::RadioButton(const string16& label, int group_id) |
| 17 : Checkbox(label) { | 19 : Checkbox(label) { |
| 18 SetGroup(group_id); | 20 SetGroup(group_id); |
| 19 set_focusable(true); | 21 |
| 22 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 23 |
| 24 // Unchecked/Unfocused images. |
| 25 SetCustomImage(false, false, STATE_NORMAL, |
| 26 *rb.GetImageSkiaNamed(IDR_RADIO)); |
| 27 SetCustomImage(false, false, STATE_HOVERED, |
| 28 *rb.GetImageSkiaNamed(IDR_RADIO_HOVER)); |
| 29 SetCustomImage(false, false, STATE_PRESSED, |
| 30 *rb.GetImageSkiaNamed(IDR_RADIO_PRESSED)); |
| 31 SetCustomImage(false, false, STATE_DISABLED, |
| 32 *rb.GetImageSkiaNamed(IDR_RADIO_DISABLED)); |
| 33 |
| 34 // Checked/Unfocused images. |
| 35 SetCustomImage(true, false, STATE_NORMAL, |
| 36 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED)); |
| 37 SetCustomImage(true, false, STATE_HOVERED, |
| 38 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_HOVER)); |
| 39 SetCustomImage(true, false, STATE_PRESSED, |
| 40 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_PRESSED)); |
| 41 SetCustomImage(true, false, STATE_DISABLED, |
| 42 *rb.GetImageSkiaNamed(IDR_RADIO_CHECKED_DISABLED)); |
| 43 |
| 44 // Unchecked/Focused images. |
| 45 SetCustomImage(false, true, STATE_NORMAL, |
| 46 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED)); |
| 47 SetCustomImage(false, true, STATE_HOVERED, |
| 48 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_HOVER)); |
| 49 SetCustomImage(false, true, STATE_PRESSED, |
| 50 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_PRESSED)); |
| 51 |
| 52 // Checked/Focused images. |
| 53 SetCustomImage(true, true, STATE_NORMAL, |
| 54 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED)); |
| 55 SetCustomImage(true, true, STATE_HOVERED, |
| 56 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_HOVER)); |
| 57 SetCustomImage(true, true, STATE_PRESSED, |
| 58 *rb.GetImageSkiaNamed(IDR_RADIO_FOCUSED_CHECKED_PRESSED)); |
| 20 } | 59 } |
| 21 | 60 |
| 22 RadioButton::~RadioButton() { | 61 RadioButton::~RadioButton() { |
| 23 } | 62 } |
| 24 | 63 |
| 25 void RadioButton::SetChecked(bool checked) { | 64 void RadioButton::SetChecked(bool checked) { |
| 26 if (checked == RadioButton::checked()) | 65 if (checked == RadioButton::checked()) |
| 27 return; | 66 return; |
| 28 if (checked) { | 67 if (checked) { |
| 29 // We can't just get the root view here because sometimes the radio | 68 // We can't just get the root view here because sometimes the radio |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 bool RadioButton::IsGroupFocusTraversable() const { | 117 bool RadioButton::IsGroupFocusTraversable() const { |
| 79 // When focusing a radio button with tab/shift+tab, only the selected button | 118 // When focusing a radio button with tab/shift+tab, only the selected button |
| 80 // from the group should be focused. | 119 // from the group should be focused. |
| 81 return false; | 120 return false; |
| 82 } | 121 } |
| 83 | 122 |
| 84 void RadioButton::OnFocus() { | 123 void RadioButton::OnFocus() { |
| 85 Checkbox::OnFocus(); | 124 Checkbox::OnFocus(); |
| 86 SetChecked(true); | 125 SetChecked(true); |
| 87 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); | 126 ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); |
| 88 TextButtonBase::NotifyClick(event); | 127 LabelButton::NotifyClick(event); |
| 89 } | 128 } |
| 90 | 129 |
| 91 void RadioButton::NotifyClick(const ui::Event& event) { | 130 void RadioButton::NotifyClick(const ui::Event& event) { |
| 92 // Set the checked state to true only if we are unchecked, since we can't | 131 // Set the checked state to true only if we are unchecked, since we can't |
| 93 // be toggled on and off like a checkbox. | 132 // be toggled on and off like a checkbox. |
| 94 if (!checked()) | 133 if (!checked()) |
| 95 SetChecked(true); | 134 SetChecked(true); |
| 96 RequestFocus(); | 135 RequestFocus(); |
| 97 TextButtonBase::NotifyClick(event); | 136 LabelButton::NotifyClick(event); |
| 98 } | 137 } |
| 99 | 138 |
| 100 ui::NativeTheme::Part RadioButton::GetThemePart() const { | 139 ui::NativeTheme::Part RadioButton::GetThemePart() const { |
| 101 return ui::NativeTheme::kRadio; | 140 return ui::NativeTheme::kRadio; |
| 102 } | 141 } |
| 103 | 142 |
| 104 } // namespace views | 143 } // namespace views |
| OLD | NEW |