| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/checkbox.h" | 5 #include "ui/views/controls/button/checkbox.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/base/accessibility/accessible_view_state.h" | 8 #include "ui/base/accessibility/accessible_view_state.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/views/controls/label.h" | 10 #include "ui/views/controls/label.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 Checkbox::~Checkbox() { | 29 Checkbox::~Checkbox() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 void Checkbox::SetChecked(bool checked) { | 32 void Checkbox::SetChecked(bool checked) { |
| 33 checked_ = checked; | 33 checked_ = checked; |
| 34 SchedulePaint(); | 34 SchedulePaint(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 gfx::Size Checkbox::GetPreferredSize() { | 37 gfx::Size Checkbox::GetPreferredSize() { |
| 38 gfx::Size prefsize(TextButtonBase::GetPreferredSize()); | 38 gfx::Size prefsize(TextButtonBase::GetPreferredSize()); |
| 39 gfx::NativeTheme::ExtraParams extra; | 39 ui::NativeTheme::ExtraParams extra; |
| 40 gfx::NativeTheme::State state = GetThemeState(&extra); | 40 ui::NativeTheme::State state = GetThemeState(&extra); |
| 41 gfx::Size size = gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), | 41 gfx::Size size = ui::NativeTheme::instance()->GetPartSize(GetThemePart(), |
| 42 state, | 42 state, extra); |
| 43 extra); | |
| 44 prefsize.Enlarge(size.width(), 0); | 43 prefsize.Enlarge(size.width(), 0); |
| 45 prefsize.set_height(std::max(prefsize.height(), size.height())); | 44 prefsize.set_height(std::max(prefsize.height(), size.height())); |
| 46 | 45 |
| 47 if (max_width_ > 0) | 46 if (max_width_ > 0) |
| 48 prefsize.set_width(std::min(max_width_, prefsize.width())); | 47 prefsize.set_width(std::min(max_width_, prefsize.width())); |
| 49 | 48 |
| 50 return prefsize; | 49 return prefsize; |
| 51 } | 50 } |
| 52 | 51 |
| 53 std::string Checkbox::GetClassName() const { | 52 std::string Checkbox::GetClassName() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 canvas->DrawFocusRect(bounds); | 68 canvas->DrawFocusRect(bounds); |
| 70 } | 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 void Checkbox::NotifyClick(const views::Event& event) { | 72 void Checkbox::NotifyClick(const views::Event& event) { |
| 74 SetChecked(!checked()); | 73 SetChecked(!checked()); |
| 75 RequestFocus(); | 74 RequestFocus(); |
| 76 TextButtonBase::NotifyClick(event); | 75 TextButtonBase::NotifyClick(event); |
| 77 } | 76 } |
| 78 | 77 |
| 79 gfx::NativeTheme::Part Checkbox::GetThemePart() const { | 78 ui::NativeTheme::Part Checkbox::GetThemePart() const { |
| 80 return gfx::NativeTheme::kCheckbox; | 79 return ui::NativeTheme::kCheckbox; |
| 81 } | 80 } |
| 82 | 81 |
| 83 gfx::Rect Checkbox::GetThemePaintRect() const { | 82 gfx::Rect Checkbox::GetThemePaintRect() const { |
| 84 gfx::NativeTheme::ExtraParams extra; | 83 ui::NativeTheme::ExtraParams extra; |
| 85 gfx::NativeTheme::State state = GetThemeState(&extra); | 84 ui::NativeTheme::State state = GetThemeState(&extra); |
| 86 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), | 85 gfx::Size size(ui::NativeTheme::instance()->GetPartSize(GetThemePart(), state, |
| 87 state, | 86 extra)); |
| 88 extra)); | |
| 89 gfx::Insets insets = GetInsets(); | 87 gfx::Insets insets = GetInsets(); |
| 90 int y_offset = (height() - size.height()) / 2; | 88 int y_offset = (height() - size.height()) / 2; |
| 91 gfx::Rect rect(insets.left(), y_offset, size.width(), size.height()); | 89 gfx::Rect rect(insets.left(), y_offset, size.width(), size.height()); |
| 92 rect.set_x(GetMirroredXForRect(rect)); | 90 rect.set_x(GetMirroredXForRect(rect)); |
| 93 return rect; | 91 return rect; |
| 94 } | 92 } |
| 95 | 93 |
| 96 void Checkbox::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { | 94 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| 97 TextButtonBase::GetExtraParams(params); | 95 TextButtonBase::GetExtraParams(params); |
| 98 params->button.checked = checked_; | 96 params->button.checked = checked_; |
| 99 } | 97 } |
| 100 | 98 |
| 101 gfx::Rect Checkbox::GetTextBounds() const { | 99 gfx::Rect Checkbox::GetTextBounds() const { |
| 102 gfx::Rect bounds(TextButtonBase::GetTextBounds()); | 100 gfx::Rect bounds(TextButtonBase::GetTextBounds()); |
| 103 gfx::NativeTheme::ExtraParams extra; | 101 ui::NativeTheme::ExtraParams extra; |
| 104 gfx::NativeTheme::State state = GetThemeState(&extra); | 102 ui::NativeTheme::State state = GetThemeState(&extra); |
| 105 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), | 103 gfx::Size size(ui::NativeTheme::instance()->GetPartSize(GetThemePart(), state, |
| 106 state, | 104 extra)); |
| 107 extra)); | |
| 108 bounds.Offset(size.width() + kCheckboxLabelSpacing, 0); | 105 bounds.Offset(size.width() + kCheckboxLabelSpacing, 0); |
| 109 return bounds; | 106 return bounds; |
| 110 } | 107 } |
| 111 | 108 |
| 112 } // namespace views | 109 } // namespace views |
| OLD | NEW |