Chromium Code Reviews| Index: ui/views/controls/button/checkbox.cc |
| diff --git a/ui/views/controls/button/checkbox.cc b/ui/views/controls/button/checkbox.cc |
| index 0bf11ae0b3f6ba1e088aac4cf2e92d0bd3c7c1b3..0f5583c393863e42317451aaee2925cd2c62b2d6 100644 |
| --- a/ui/views/controls/button/checkbox.cc |
| +++ b/ui/views/controls/button/checkbox.cc |
| @@ -4,52 +4,22 @@ |
| #include "ui/views/controls/button/checkbox.h" |
| -#include "base/logging.h" |
| +#include "grit/ui_resources.h" |
| #include "ui/base/accessibility/accessible_view_state.h" |
| -#include "ui/gfx/canvas.h" |
| -#include "ui/views/controls/label.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| namespace views { |
| -namespace { |
| - |
| -const int kCheckboxLabelSpacing = 4; |
| - |
| -const int kFocusBorderWidth = 1; |
| - |
| -} // namespace |
| - |
| // static |
| const char Checkbox::kViewClassName[] = "views/Checkbox"; |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// CheckboxNativeThemeBorder, public: |
| - |
| -gfx::Insets CheckboxNativeThemeBorder::GetInsets() const { |
| - if (use_custom_insets_) |
| - return custom_insets_; |
| - |
| - const gfx::Insets& insets = TextButtonNativeThemeBorder::GetInsets(); |
| - return gfx::Insets(insets.top(), 0, insets.bottom(), 0); |
| -} |
| - |
| -void CheckboxNativeThemeBorder::SetCustomInsets( |
| - const gfx::Insets& custom_insets) { |
| - custom_insets_ = custom_insets; |
| - use_custom_insets_ = true; |
| -} |
| - |
| -void CheckboxNativeThemeBorder::UseDefaultInsets() { |
| - use_custom_insets_ = false; |
| -} |
| - |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// Checkbox, public: |
| - |
| Checkbox::Checkbox(const string16& label) |
| - : TextButtonBase(NULL, label), |
| - checked_(false) { |
| - set_border(new CheckboxNativeThemeBorder(this)); |
| + : LabelButton(NULL, label) { |
|
msw
2013/05/18 01:04:56
Restore the checked_(false) init.
tfarina
2013/05/18 02:30:49
Done.
|
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
|
msw
2013/05/18 01:04:56
nit: move this below SetStyle (just before its use
tfarina
2013/05/18 02:30:49
Done.
tfarina
2013/05/18 02:30:49
Done.
|
| + SetStyle(STYLE_CHECKBOX); |
| + SetImage(STATE_NORMAL, *rb.GetImageSkiaNamed(IDR_CHECKBOX)); |
| + SetImage(STATE_HOVERED, *rb.GetImageSkiaNamed(IDR_CHECKBOX_HOVER)); |
| + SetImage(STATE_PRESSED, *rb.GetImageSkiaNamed(IDR_CHECKBOX_PRESSED)); |
| set_focusable(true); |
| } |
| @@ -61,76 +31,28 @@ void Checkbox::SetChecked(bool checked) { |
| SchedulePaint(); |
| } |
| -gfx::Size Checkbox::GetPreferredSize() { |
| - gfx::Size prefsize(TextButtonBase::GetPreferredSize()); |
| - ui::NativeTheme::ExtraParams extra; |
| - ui::NativeTheme::State state = GetThemeState(&extra); |
| - gfx::Size size = GetNativeTheme()->GetPartSize(GetThemePart(), state, extra); |
| - prefsize.Enlarge(size.width() + kCheckboxLabelSpacing + kFocusBorderWidth, 0); |
| - prefsize.set_height(std::max(prefsize.height(), size.height())); |
| - |
| - if (max_width_ > 0) |
| - prefsize.set_width(std::min(max_width_, prefsize.width())); |
| - |
| - return prefsize; |
| -} |
| - |
| const char* Checkbox::GetClassName() const { |
| return kViewClassName; |
| } |
| void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) { |
| - TextButtonBase::GetAccessibleState(state); |
| + LabelButton::GetAccessibleState(state); |
| state->role = ui::AccessibilityTypes::ROLE_CHECKBUTTON; |
| state->state = checked() ? ui::AccessibilityTypes::STATE_CHECKED : 0; |
| } |
| -void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| - if (HasFocus() && (focusable() || IsAccessibilityFocusable())) { |
| - gfx::Rect bounds(GetTextBounds()); |
| - // Increate the bounding box by one on each side so that that focus border |
| - // does not draw on top of the letters. |
| - bounds.Inset(-kFocusBorderWidth, |
| - -kFocusBorderWidth, |
| - -kFocusBorderWidth, |
| - -kFocusBorderWidth); |
| - canvas->DrawFocusRect(bounds); |
| - } |
| -} |
| - |
| void Checkbox::NotifyClick(const ui::Event& event) { |
| SetChecked(!checked()); |
| - RequestFocus(); |
| - TextButtonBase::NotifyClick(event); |
| + LabelButton::NotifyClick(event); |
| } |
| ui::NativeTheme::Part Checkbox::GetThemePart() const { |
| return ui::NativeTheme::kCheckbox; |
| } |
| -gfx::Rect Checkbox::GetThemePaintRect() const { |
| - ui::NativeTheme::ExtraParams extra; |
| - ui::NativeTheme::State state = GetThemeState(&extra); |
| - gfx::Size size(GetNativeTheme()->GetPartSize(GetThemePart(), state, extra)); |
| - gfx::Insets insets = GetInsets(); |
| - int y_offset = (height() - size.height()) / 2; |
| - gfx::Rect rect(insets.left(), y_offset, size.width(), size.height()); |
| - rect.set_x(GetMirroredXForRect(rect)); |
| - return rect; |
| -} |
| - |
| void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| - TextButtonBase::GetExtraParams(params); |
| + LabelButton::GetExtraParams(params); |
| params->button.checked = checked_; |
| } |
| -gfx::Rect Checkbox::GetTextBounds() const { |
| - gfx::Rect bounds(TextButtonBase::GetTextBounds()); |
| - ui::NativeTheme::ExtraParams extra; |
| - ui::NativeTheme::State state = GetThemeState(&extra); |
| - gfx::Size size(GetNativeTheme()->GetPartSize(GetThemePart(), state, extra)); |
| - bounds.Offset(size.width() + kCheckboxLabelSpacing, 0); |
| - return bounds; |
| -} |
| - |
| } // namespace views |