Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(934)

Unified Diff: ui/views/controls/button/checkbox.cc

Issue 15061006: views: Switch Checkbox over to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: almost working - :p Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ea7f9ea887ad17aea15181ad2227f2d11d8d7f1a 100644
--- a/ui/views/controls/button/checkbox.cc
+++ b/ui/views/controls/button/checkbox.cc
@@ -8,6 +8,8 @@
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/gfx/canvas.h"
msw 2013/05/13 01:37:22 nit: remove
tfarina 2013/05/13 01:47:12 Done.
#include "ui/views/controls/label.h"
msw 2013/05/13 01:37:22 nit: remove
tfarina 2013/05/13 01:47:12 Done.
+#include "ui/base/resource/resource_bundle.h"
+#include "grit/ui_resources.h"
namespace views {
@@ -47,9 +49,13 @@ void CheckboxNativeThemeBorder::UseDefaultInsets() {
// Checkbox, public:
Checkbox::Checkbox(const string16& label)
- : TextButtonBase(NULL, label),
+ : LabelButton(NULL, label),
checked_(false) {
- set_border(new CheckboxNativeThemeBorder(this));
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ 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 +67,20 @@ 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();
msw 2013/05/13 01:37:22 nit: try to remove this.
tfarina 2013/05/13 01:47:12 Done.
- TextButtonBase::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);
- 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;
+ LabelButton::NotifyClick(event);
}
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698