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/base/accessibility/accessible_view_state.h" | 7 #include "ui/base/accessibility/accessible_view_state.h" |
8 #include "ui/base/animation/throb_animation.h" | 8 #include "ui/base/animation/throb_animation.h" |
9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
10 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 bool CustomButton::IsMouseHovered() const { | 68 bool CustomButton::IsMouseHovered() const { |
69 // If we haven't yet been placed in an onscreen view hierarchy, we can't be | 69 // If we haven't yet been placed in an onscreen view hierarchy, we can't be |
70 // hovered. | 70 // hovered. |
71 if (!GetWidget()) | 71 if (!GetWidget()) |
72 return false; | 72 return false; |
73 | 73 |
74 gfx::Point cursor_pos(gfx::Screen::GetCursorScreenPoint()); | 74 gfx::Point cursor_pos(gfx::Screen::GetCursorScreenPoint()); |
75 ConvertPointToView(NULL, this, &cursor_pos); | 75 ConvertPointToView(NULL, this, &cursor_pos); |
76 return HitTest(cursor_pos); | 76 return HitTestPoint(cursor_pos); |
77 } | 77 } |
78 | 78 |
79 void CustomButton::SetHotTracked(bool is_hot_tracked) { | 79 void CustomButton::SetHotTracked(bool is_hot_tracked) { |
80 if (state_ != BS_DISABLED) | 80 if (state_ != BS_DISABLED) |
81 SetState(is_hot_tracked ? BS_HOT : BS_NORMAL); | 81 SetState(is_hot_tracked ? BS_HOT : BS_NORMAL); |
82 | 82 |
83 if (is_hot_tracked && GetWidget()) { | 83 if (is_hot_tracked && GetWidget()) { |
84 GetWidget()->NotifyAccessibilityEvent( | 84 GetWidget()->NotifyAccessibilityEvent( |
85 this, ui::AccessibilityTypes::EVENT_FOCUS, true); | 85 this, ui::AccessibilityTypes::EVENT_FOCUS, true); |
86 } | 86 } |
(...skipping 15 matching lines...) Expand all Loading... |
102 else | 102 else |
103 SetState(BS_DISABLED); | 103 SetState(BS_DISABLED); |
104 } | 104 } |
105 | 105 |
106 std::string CustomButton::GetClassName() const { | 106 std::string CustomButton::GetClassName() const { |
107 return kViewClassName; | 107 return kViewClassName; |
108 } | 108 } |
109 | 109 |
110 bool CustomButton::OnMousePressed(const MouseEvent& event) { | 110 bool CustomButton::OnMousePressed(const MouseEvent& event) { |
111 if (state_ != BS_DISABLED) { | 111 if (state_ != BS_DISABLED) { |
112 if (ShouldEnterPushedState(event) && HitTest(event.location())) | 112 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) |
113 SetState(BS_PUSHED); | 113 SetState(BS_PUSHED); |
114 if (request_focus_on_press_) | 114 if (request_focus_on_press_) |
115 RequestFocus(); | 115 RequestFocus(); |
116 } | 116 } |
117 return true; | 117 return true; |
118 } | 118 } |
119 | 119 |
120 bool CustomButton::OnMouseDragged(const MouseEvent& event) { | 120 bool CustomButton::OnMouseDragged(const MouseEvent& event) { |
121 if (state_ != BS_DISABLED) { | 121 if (state_ != BS_DISABLED) { |
122 if (HitTest(event.location())) | 122 if (HitTestPoint(event.location())) |
123 SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT); | 123 SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT); |
124 else | 124 else |
125 SetState(BS_NORMAL); | 125 SetState(BS_NORMAL); |
126 } | 126 } |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 void CustomButton::OnMouseReleased(const MouseEvent& event) { | 130 void CustomButton::OnMouseReleased(const MouseEvent& event) { |
131 if (state_ == BS_DISABLED) | 131 if (state_ == BS_DISABLED) |
132 return; | 132 return; |
133 | 133 |
134 if (!HitTest(event.location())) { | 134 if (!HitTestPoint(event.location())) { |
135 SetState(BS_NORMAL); | 135 SetState(BS_NORMAL); |
136 return; | 136 return; |
137 } | 137 } |
138 | 138 |
139 SetState(BS_HOT); | 139 SetState(BS_HOT); |
140 if (IsTriggerableEvent(event)) { | 140 if (IsTriggerableEvent(event)) { |
141 NotifyClick(event); | 141 NotifyClick(event); |
142 // NOTE: We may be deleted at this point (by the listener's notification | 142 // NOTE: We may be deleted at this point (by the listener's notification |
143 // handler). | 143 // handler). |
144 } | 144 } |
(...skipping 11 matching lines...) Expand all Loading... |
156 } | 156 } |
157 | 157 |
158 void CustomButton::OnMouseExited(const MouseEvent& event) { | 158 void CustomButton::OnMouseExited(const MouseEvent& event) { |
159 // Starting a drag results in a MouseExited, we need to ignore it. | 159 // Starting a drag results in a MouseExited, we need to ignore it. |
160 if (state_ != BS_DISABLED && !InDrag()) | 160 if (state_ != BS_DISABLED && !InDrag()) |
161 SetState(BS_NORMAL); | 161 SetState(BS_NORMAL); |
162 } | 162 } |
163 | 163 |
164 void CustomButton::OnMouseMoved(const MouseEvent& event) { | 164 void CustomButton::OnMouseMoved(const MouseEvent& event) { |
165 if (state_ != BS_DISABLED) | 165 if (state_ != BS_DISABLED) |
166 SetState(HitTest(event.location()) ? BS_HOT : BS_NORMAL); | 166 SetState(HitTestPoint(event.location()) ? BS_HOT : BS_NORMAL); |
167 } | 167 } |
168 | 168 |
169 bool CustomButton::OnKeyPressed(const KeyEvent& event) { | 169 bool CustomButton::OnKeyPressed(const KeyEvent& event) { |
170 if (state_ == BS_DISABLED) | 170 if (state_ == BS_DISABLED) |
171 return false; | 171 return false; |
172 | 172 |
173 // Space sets button state to pushed. Enter clicks the button. This matches | 173 // Space sets button state to pushed. Enter clicks the button. This matches |
174 // the Windows native behavior of buttons, where Space clicks the button on | 174 // the Windows native behavior of buttons, where Space clicks the button on |
175 // KeyRelease and Enter clicks the button on KeyPressed. | 175 // KeyRelease and Enter clicks the button on KeyPressed. |
176 if (event.key_code() == ui::VKEY_SPACE) { | 176 if (event.key_code() == ui::VKEY_SPACE) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (!is_add && state_ != BS_DISABLED) | 302 if (!is_add && state_ != BS_DISABLED) |
303 SetState(BS_NORMAL); | 303 SetState(BS_NORMAL); |
304 } | 304 } |
305 | 305 |
306 void CustomButton::OnBlur() { | 306 void CustomButton::OnBlur() { |
307 if (IsHotTracked()) | 307 if (IsHotTracked()) |
308 SetState(BS_NORMAL); | 308 SetState(BS_NORMAL); |
309 } | 309 } |
310 | 310 |
311 } // namespace views | 311 } // namespace views |
OLD | NEW |