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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
10 #include "base/compiler_specific.h"
11 #include "base/strings/string16.h"
12 #include "ui/views/controls/button/label_button.h"
16 // A native themed class representing a checkbox. This class does not use
17 // platform specific objects to replicate the native platforms looks and feel.
18 class VIEWS_EXPORT Checkbox
: public LabelButton
{
20 static const char kViewClassName
[];
22 explicit Checkbox(const base::string16
& label
);
25 // Sets a listener for this checkbox. Checkboxes aren't required to have them
26 // since their state can be read independently of them being toggled.
27 void set_listener(ButtonListener
* listener
) { listener_
= listener
; }
29 // Sets/Gets whether or not the checkbox is checked.
30 virtual void SetChecked(bool checked
);
31 bool checked() const { return checked_
; }
34 // Overridden from LabelButton:
35 void Layout() override
;
36 const char* GetClassName() const override
;
37 void GetAccessibleState(ui::AXViewState
* state
) override
;
38 void OnFocus() override
;
39 void OnBlur() override
;
40 const gfx::ImageSkia
& GetImage(ButtonState for_state
) override
;
42 // Set the image shown for each button state depending on whether it is
43 // [checked] or [focused].
44 void SetCustomImage(bool checked
,
46 ButtonState for_state
,
47 const gfx::ImageSkia
& image
);
50 // Overridden from Button:
51 void NotifyClick(const ui::Event
& event
) override
;
53 ui::NativeTheme::Part
GetThemePart() const override
;
54 void GetExtraParams(ui::NativeTheme::ExtraParams
* params
) const override
;
56 // True if the checkbox is checked.
59 // The images for each button state.
60 gfx::ImageSkia images_
[2][2][STATE_COUNT
];
62 DISALLOW_COPY_AND_ASSIGN(Checkbox
);
67 #endif // UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_