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 if (notify_action_ == NOTIFY_ON_PRESS) { |
| 147 if (IsTriggerableEvent(event)) { |
146 NotifyClick(event); | 148 NotifyClick(event); |
147 // NOTE: We may be deleted at this point (by the listener's notification | 149 // NOTE: We may be deleted at this point (by the listener's notification |
148 // handler). | 150 // handler). |
| 151 } else { |
| 152 OnClickCanceled(event); |
149 } | 153 } |
150 } | 154 } |
151 return true; | 155 return true; |
152 } | 156 } |
153 | 157 |
154 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { | 158 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { |
155 if (state_ != STATE_DISABLED) { | 159 if (state_ != STATE_DISABLED) { |
156 if (HitTestPoint(event.location())) | 160 if (HitTestPoint(event.location())) |
157 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); | 161 SetState(ShouldEnterPushedState(event) ? STATE_PRESSED : STATE_HOVERED); |
158 else | 162 else |
159 SetState(STATE_NORMAL); | 163 SetState(STATE_NORMAL); |
160 } | 164 } |
161 return true; | 165 return true; |
162 } | 166 } |
163 | 167 |
164 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { | 168 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { |
165 if (state_ == STATE_DISABLED) | 169 if (state_ != STATE_DISABLED) { |
166 return; | 170 if (!HitTestPoint(event.location())) { |
167 | 171 SetState(STATE_NORMAL); |
168 if (!HitTestPoint(event.location())) { | 172 } else { |
169 SetState(STATE_NORMAL); | 173 SetState(STATE_HOVERED); |
170 return; | 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 return; |
| 179 } |
| 180 } |
171 } | 181 } |
172 | 182 if (notify_action_ == NOTIFY_ON_RELEASE) |
173 SetState(STATE_HOVERED); | 183 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 } | 184 } |
180 | 185 |
181 void CustomButton::OnMouseCaptureLost() { | 186 void CustomButton::OnMouseCaptureLost() { |
182 // Starting a drag results in a MouseCaptureLost, we need to ignore it. | 187 // Starting a drag results in a MouseCaptureLost, we need to ignore it. |
183 if (state_ != STATE_DISABLED && !InDrag()) | 188 if (state_ != STATE_DISABLED && !InDrag()) |
184 SetState(STATE_NORMAL); | 189 SetState(STATE_NORMAL); |
185 } | 190 } |
186 | 191 |
187 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { | 192 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { |
188 if (state_ != STATE_DISABLED) | 193 if (state_ != STATE_DISABLED) |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 412 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
408 } | 413 } |
409 | 414 |
410 bool CustomButton::FocusInChildWidget() const { | 415 bool CustomButton::FocusInChildWidget() const { |
411 return GetWidget() && | 416 return GetWidget() && |
412 GetWidget()->GetRootView()->Contains( | 417 GetWidget()->GetRootView()->Contains( |
413 GetFocusManager()->GetFocusedView()); | 418 GetFocusManager()->GetFocusedView()); |
414 } | 419 } |
415 | 420 |
416 } // namespace views | 421 } // namespace views |
OLD | NEW |