| 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/event_utils.h" | 9 #include "ui/events/event_utils.h" |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); | 130 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); |
| 131 else | 131 else |
| 132 SetState(STATE_DISABLED); | 132 SetState(STATE_DISABLED); |
| 133 } | 133 } |
| 134 | 134 |
| 135 const char* CustomButton::GetClassName() const { | 135 const char* CustomButton::GetClassName() const { |
| 136 return kViewClassName; | 136 return kViewClassName; |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { | 139 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { |
| 140 if (state_ != STATE_DISABLED) { | 140 if (state_ == STATE_DISABLED) |
| 141 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) | 141 return true; |
| 142 SetState(STATE_PRESSED); | 142 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) |
| 143 if (request_focus_on_press_) | 143 SetState(STATE_PRESSED); |
| 144 RequestFocus(); | 144 if (request_focus_on_press_) |
| 145 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { | 145 RequestFocus(); |
| 146 NotifyClick(event); | 146 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { |
| 147 // NOTE: We may be deleted at this point (by the listener's notification | 147 NotifyClick(event); |
| 148 // handler). | 148 // NOTE: We may be deleted at this point (by the listener's notification |
| 149 } | 149 // handler). |
| 150 } | 150 } |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { | 154 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 155 if (state_ != STATE_DISABLED) { | 155 if (state_ != STATE_DISABLED) { |
| 156 if (HitTestPoint(event.location())) | 156 if (HitTestPoint(event.location())) |
| 157 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); | 157 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); |
| 158 else | 158 else |
| 159 SetState(STATE_NORMAL); | 159 SetState(STATE_NORMAL); |
| 160 } | 160 } |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { | 164 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 165 if (state_ == STATE_DISABLED) | 165 if (state_ != STATE_DISABLED) { |
| 166 return; | 166 if (!HitTestPoint(event.location())) { |
| 167 | 167 SetState(STATE_NORMAL); |
| 168 if (!HitTestPoint(event.location())) { | 168 } else { |
| 169 SetState(STATE_NORMAL); | 169 SetState(STATE_HOVERED); |
| 170 return; | 170 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_RELEASE) { |
| 171 NotifyClick(event); |
| 172 // NOTE: We may be deleted at this point (by the listener's notification |
| 173 // handler). |
| 174 return; |
| 175 } |
| 176 } |
| 171 } | 177 } |
| 172 | 178 if (notify_action_ == NOTIFY_ON_RELEASE) |
| 173 SetState(STATE_HOVERED); | 179 OnClickCanceled(event); |
| 174 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_RELEASE) { | |
| 175 NotifyClick(event); | |
| 176 // NOTE: We may be deleted at this point (by the listener's notification | |
| 177 // handler). | |
| 178 } | |
| 179 } | 180 } |
| 180 | 181 |
| 181 void CustomButton::OnMouseCaptureLost() { | 182 void CustomButton::OnMouseCaptureLost() { |
| 182 // Starting a drag results in a MouseCaptureLost, we need to ignore it. | 183 // Starting a drag results in a MouseCaptureLost, we need to ignore it. |
| 183 if (state_ != STATE_DISABLED && !InDrag()) | 184 if (state_ != STATE_DISABLED && !InDrag()) |
| 184 SetState(STATE_NORMAL); | 185 SetState(STATE_NORMAL); |
| 185 } | 186 } |
| 186 | 187 |
| 187 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { | 188 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { |
| 188 if (state_ != STATE_DISABLED) | 189 if (state_ != STATE_DISABLED) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 408 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
| 408 } | 409 } |
| 409 | 410 |
| 410 bool CustomButton::FocusInChildWidget() const { | 411 bool CustomButton::FocusInChildWidget() const { |
| 411 return GetWidget() && | 412 return GetWidget() && |
| 412 GetWidget()->GetRootView()->Contains( | 413 GetWidget()->GetRootView()->Contains( |
| 413 GetFocusManager()->GetFocusedView()); | 414 GetFocusManager()->GetFocusedView()); |
| 414 } | 415 } |
| 415 | 416 |
| 416 } // namespace views | 417 } // namespace views |
| OLD | NEW |