diff options
Diffstat (limited to 'views/controls/button/checkbox.cc')
-rw-r--r-- | views/controls/button/checkbox.cc | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index 45aea1c..693e282 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -34,6 +34,11 @@ Checkbox::Checkbox(const std::wstring& label) Checkbox::~Checkbox() { } +// static +int Checkbox::GetTextIndent() { + return NativeButtonWrapper::GetFixedWidth() + kCheckboxLabelSpacing; +} + void Checkbox::SetMultiLine(bool multiline) { label_->SetMultiLine(multiline); PreferredSizeChanged(); @@ -47,11 +52,6 @@ void Checkbox::SetChecked(bool checked) { native_wrapper_->UpdateChecked(); } -// static -int Checkbox::GetTextIndent() { - return NativeButtonWrapper::GetFixedWidth() + kCheckboxLabelSpacing; -} - //////////////////////////////////////////////////////////////////////////////// // Checkbox, View overrides: @@ -87,6 +87,12 @@ int Checkbox::GetHeightForWidth(int w) { return label_->GetHeightForWidth(std::max(prefsize.height(), w - width)); } +void Checkbox::SetEnabled(bool enabled) { + NativeButton::SetEnabled(enabled); + if (label_) + label_->SetEnabled(enabled); +} + void Checkbox::Layout() { if (!native_wrapper_) return; @@ -112,26 +118,8 @@ void Checkbox::Layout() { native_wrapper_->GetView()->Layout(); } -void Checkbox::SetEnabled(bool enabled) { - NativeButton::SetEnabled(enabled); - if (label_) - label_->SetEnabled(enabled); -} - -void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) { - // Our focus border is rendered by the label, so we don't do anything here. -} - -void Checkbox::OnMouseEntered(const MouseEvent& event) { - native_wrapper_->SetPushed(HitTestLabel(event)); -} - -void Checkbox::OnMouseMoved(const MouseEvent& event) { - native_wrapper_->SetPushed(HitTestLabel(event)); -} - -void Checkbox::OnMouseExited(const MouseEvent& event) { - native_wrapper_->SetPushed(false); +std::string Checkbox::GetClassName() const { + return kViewClassName; } bool Checkbox::OnMousePressed(const MouseEvent& event) { @@ -139,6 +127,10 @@ bool Checkbox::OnMousePressed(const MouseEvent& event) { return true; } +bool Checkbox::OnMouseDragged(const MouseEvent& event) { + return false; +} + void Checkbox::OnMouseReleased(const MouseEvent& event, bool canceled) { native_wrapper_->SetPushed(false); if (!canceled && HitTestLabel(event)) { @@ -147,16 +139,16 @@ void Checkbox::OnMouseReleased(const MouseEvent& event, bool canceled) { } } -bool Checkbox::OnMouseDragged(const MouseEvent& event) { - return false; +void Checkbox::OnMouseMoved(const MouseEvent& event) { + native_wrapper_->SetPushed(HitTestLabel(event)); } -void Checkbox::OnFocus() { - label_->set_paint_as_focused(true); +void Checkbox::OnMouseEntered(const MouseEvent& event) { + native_wrapper_->SetPushed(HitTestLabel(event)); } -void Checkbox::OnBlur() { - label_->set_paint_as_focused(false); +void Checkbox::OnMouseExited(const MouseEvent& event) { + native_wrapper_->SetPushed(false); } void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) { @@ -165,25 +157,9 @@ void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) { state->state = checked() ? ui::AccessibilityTypes::STATE_CHECKED : 0; } -std::string Checkbox::GetClassName() const { - return kViewClassName; -} - //////////////////////////////////////////////////////////////////////////////// // Checkbox, NativeButton overrides: -NativeButtonWrapper* Checkbox::CreateWrapper() { - NativeButtonWrapper* native_wrapper = - NativeButtonWrapper::CreateCheckboxWrapper(this); - native_wrapper->UpdateLabel(); - native_wrapper->UpdateChecked(); - return native_wrapper; -} - -void Checkbox::InitBorder() { - // No border, so we do nothing. -} - void Checkbox::SetLabel(const std::wstring& label) { NativeButton::SetLabel(label); if (!native_wrapper_->UsesNativeLabel()) @@ -200,6 +176,36 @@ bool Checkbox::HitTestLabel(const MouseEvent& event) { } //////////////////////////////////////////////////////////////////////////////// +// Checkbox, View overrides, protected: + +void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) { + // Our focus border is rendered by the label, so we don't do anything here. +} +void Checkbox::OnFocus() { + label_->set_paint_as_focused(true); +} + +void Checkbox::OnBlur() { + label_->set_paint_as_focused(false); +} + + +//////////////////////////////////////////////////////////////////////////////// +// Checkbox, NativeButton overrides, protected: + +NativeButtonWrapper* Checkbox::CreateWrapper() { + NativeButtonWrapper* native_wrapper = + NativeButtonWrapper::CreateCheckboxWrapper(this); + native_wrapper->UpdateLabel(); + native_wrapper->UpdateChecked(); + return native_wrapper; +} + +void Checkbox::InitBorder() { + // No border, so we do nothing. +} + +//////////////////////////////////////////////////////////////////////////////// // Checkbox, private: void Checkbox::Init(const std::wstring& label_text) { |