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 #ifndef UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "ui/views/controls/button/text_button.h" | 12 #include "ui/views/controls/button/label_button.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 // A border with zero left inset. | |
17 class VIEWS_EXPORT CheckboxNativeThemeBorder | |
18 : public TextButtonNativeThemeBorder { | |
19 public: | |
20 explicit CheckboxNativeThemeBorder(views::NativeThemeDelegate* delegate) | |
21 : TextButtonNativeThemeBorder(delegate), | |
22 use_custom_insets_(false) {} | |
23 virtual ~CheckboxNativeThemeBorder() {} | |
24 | |
25 // The insets apply to the whole view (checkbox + text), not just the square | |
26 // with the checkmark in it. The insets do not visibly affect the checkbox, | |
27 // except to ensure that there is enough padding between this and other | |
28 // elements. | |
29 virtual gfx::Insets GetInsets() const OVERRIDE; | |
30 | |
31 // Use the |custom_insets_| provided instead of those from the theme. | |
32 void SetCustomInsets(const gfx::Insets& custom_insets); | |
33 | |
34 // Use the default insets and ignore any |custom_insets_| that may be set. | |
35 void UseDefaultInsets(); | |
36 | |
37 private: | |
38 // Only used if |use_custom_insets_| is true. | |
39 gfx::Insets custom_insets_; | |
40 | |
41 // Whether |custom_insets_| should be used in |GetInsets()|. | |
42 bool use_custom_insets_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(CheckboxNativeThemeBorder); | |
45 }; | |
46 | |
47 // A native themed class representing a checkbox. This class does not use | 16 // A native themed class representing a checkbox. This class does not use |
48 // platform specific objects to replicate the native platforms looks and feel. | 17 // platform specific objects to replicate the native platforms looks and feel. |
49 class VIEWS_EXPORT Checkbox : public TextButtonBase { | 18 class VIEWS_EXPORT Checkbox : public LabelButton { |
50 public: | 19 public: |
51 static const char kViewClassName[]; | 20 static const char kViewClassName[]; |
52 | 21 |
53 explicit Checkbox(const string16& label); | 22 explicit Checkbox(const string16& label); |
54 virtual ~Checkbox(); | 23 virtual ~Checkbox(); |
55 | 24 |
56 // Sets a listener for this checkbox. Checkboxes aren't required to have them | 25 // Sets a listener for this checkbox. Checkboxes aren't required to have them |
57 // since their state can be read independently of them being toggled. | 26 // since their state can be read independently of them being toggled. |
58 void set_listener(ButtonListener* listener) { listener_ = listener; } | 27 void set_listener(ButtonListener* listener) { listener_ = listener; } |
59 | 28 |
60 // Sets/Gets whether or not the checkbox is checked. | 29 // Sets/Gets whether or not the checkbox is checked. |
61 virtual void SetChecked(bool checked); | 30 virtual void SetChecked(bool checked); |
62 bool checked() const { return checked_; } | 31 bool checked() const { return checked_; } |
63 | 32 |
64 protected: | 33 protected: |
65 // Overridden from View: | 34 // Overridden from LabelButton: |
66 virtual gfx::Size GetPreferredSize() OVERRIDE; | 35 virtual void Layout() OVERRIDE; |
67 virtual const char* GetClassName() const OVERRIDE; | 36 virtual const char* GetClassName() const OVERRIDE; |
68 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 37 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
69 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | 38 virtual void OnFocus() OVERRIDE; |
| 39 virtual void OnBlur() OVERRIDE; |
| 40 virtual const gfx::ImageSkia& GetImage(ButtonState for_state) OVERRIDE; |
| 41 |
| 42 // Set the image shown for each button state depending on whether it is |
| 43 // [checked] or [focused]. |
| 44 void SetCustomImage(bool checked, |
| 45 bool focused, |
| 46 ButtonState for_state, |
| 47 const gfx::ImageSkia& image); |
70 | 48 |
71 private: | 49 private: |
72 // Overridden from Button: | 50 // Overridden from Button: |
73 virtual void NotifyClick(const ui::Event& event) OVERRIDE; | 51 virtual void NotifyClick(const ui::Event& event) OVERRIDE; |
74 | 52 |
75 // Overridden from TextButtonBase: | |
76 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; | 53 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; |
77 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; | |
78 virtual void GetExtraParams( | 54 virtual void GetExtraParams( |
79 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | 55 ui::NativeTheme::ExtraParams* params) const OVERRIDE; |
80 virtual gfx::Rect GetTextBounds() const OVERRIDE; | |
81 | 56 |
82 // True if the checkbox is checked. | 57 // True if the checkbox is checked. |
83 bool checked_; | 58 bool checked_; |
84 | 59 |
| 60 // The images for each button state. |
| 61 gfx::ImageSkia images_[2][2][STATE_COUNT]; |
| 62 |
85 DISALLOW_COPY_AND_ASSIGN(Checkbox); | 63 DISALLOW_COPY_AND_ASSIGN(Checkbox); |
86 }; | 64 }; |
87 | 65 |
88 } // namespace views | 66 } // namespace views |
89 | 67 |
90 #endif // UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_ | 68 #endif // UI_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_ |
OLD | NEW |