| 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 #include "ui/views/controls/button/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
| 6 | 6 |
| 7 #include "ui/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
| 9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
| 10 #include "ui/gfx/animation/throb_animation.h" | 10 #include "ui/gfx/animation/throb_animation.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 else | 120 else |
| 121 SetState(STATE_DISABLED); | 121 SetState(STATE_DISABLED); |
| 122 } | 122 } |
| 123 | 123 |
| 124 const char* CustomButton::GetClassName() const { | 124 const char* CustomButton::GetClassName() const { |
| 125 return kViewClassName; | 125 return kViewClassName; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { | 128 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { |
| 129 if (state_ != STATE_DISABLED) { | 129 if (state_ != STATE_DISABLED) { |
| 130 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) | 130 if (ShouldEnterPushedState(event) && |
| 131 HitTestPoint(gfx::ToFlooredPoint(event.location()))) |
| 131 SetState(STATE_PRESSED); | 132 SetState(STATE_PRESSED); |
| 132 if (request_focus_on_press_) | 133 if (request_focus_on_press_) |
| 133 RequestFocus(); | 134 RequestFocus(); |
| 134 } | 135 } |
| 135 return true; | 136 return true; |
| 136 } | 137 } |
| 137 | 138 |
| 138 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { | 139 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 139 if (state_ != STATE_DISABLED) { | 140 if (state_ != STATE_DISABLED) { |
| 140 if (HitTestPoint(event.location())) | 141 if (HitTestPoint(gfx::ToFlooredPoint(event.location()))) |
| 141 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); | 142 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); |
| 142 else | 143 else |
| 143 SetState(STATE_NORMAL); | 144 SetState(STATE_NORMAL); |
| 144 } | 145 } |
| 145 return true; | 146 return true; |
| 146 } | 147 } |
| 147 | 148 |
| 148 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { | 149 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 149 if (state_ == STATE_DISABLED) | 150 if (state_ == STATE_DISABLED) |
| 150 return; | 151 return; |
| 151 | 152 |
| 152 if (!HitTestPoint(event.location())) { | 153 if (!HitTestPoint(gfx::ToFlooredPoint(event.location()))) { |
| 153 SetState(STATE_NORMAL); | 154 SetState(STATE_NORMAL); |
| 154 return; | 155 return; |
| 155 } | 156 } |
| 156 | 157 |
| 157 SetState(STATE_HOVERED); | 158 SetState(STATE_HOVERED); |
| 158 if (IsTriggerableEvent(event)) { | 159 if (IsTriggerableEvent(event)) { |
| 159 NotifyClick(event); | 160 NotifyClick(event); |
| 160 // NOTE: We may be deleted at this point (by the listener's notification | 161 // NOTE: We may be deleted at this point (by the listener's notification |
| 161 // handler). | 162 // handler). |
| 162 } | 163 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 } | 175 } |
| 175 | 176 |
| 176 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { | 177 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { |
| 177 // Starting a drag results in a MouseExited, we need to ignore it. | 178 // Starting a drag results in a MouseExited, we need to ignore it. |
| 178 if (state_ != STATE_DISABLED && !InDrag()) | 179 if (state_ != STATE_DISABLED && !InDrag()) |
| 179 SetState(STATE_NORMAL); | 180 SetState(STATE_NORMAL); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) { | 183 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) { |
| 183 if (state_ != STATE_DISABLED) | 184 if (state_ != STATE_DISABLED) |
| 184 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL); | 185 SetState(HitTestPoint(gfx::ToFlooredPoint(event.location())) |
| 186 ? STATE_HOVERED |
| 187 : STATE_NORMAL); |
| 185 } | 188 } |
| 186 | 189 |
| 187 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { | 190 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { |
| 188 if (state_ == STATE_DISABLED) | 191 if (state_ == STATE_DISABLED) |
| 189 return false; | 192 return false; |
| 190 | 193 |
| 191 // Space sets button state to pushed. Enter clicks the button. This matches | 194 // Space sets button state to pushed. Enter clicks the button. This matches |
| 192 // the Windows native behavior of buttons, where Space clicks the button on | 195 // the Windows native behavior of buttons, where Space clicks the button on |
| 193 // KeyRelease and Enter clicks the button on KeyPressed. | 196 // KeyRelease and Enter clicks the button on KeyPressed. |
| 194 if (event.key_code() == ui::VKEY_SPACE) { | 197 if (event.key_code() == ui::VKEY_SPACE) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 if (!details.is_add && state_ != STATE_DISABLED) | 355 if (!details.is_add && state_ != STATE_DISABLED) |
| 353 SetState(STATE_NORMAL); | 356 SetState(STATE_NORMAL); |
| 354 } | 357 } |
| 355 | 358 |
| 356 void CustomButton::OnBlur() { | 359 void CustomButton::OnBlur() { |
| 357 if (IsHotTracked()) | 360 if (IsHotTracked()) |
| 358 SetState(STATE_NORMAL); | 361 SetState(STATE_NORMAL); |
| 359 } | 362 } |
| 360 | 363 |
| 361 } // namespace views | 364 } // namespace views |
| OLD | NEW |