Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ui/views/controls/button/custom_button.cc

Issue 10832282: Replace views::MouseEvent with ui::MouseEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/menu_button.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/event.h" 9 #include "ui/base/event.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (enabled()) 101 if (enabled())
102 SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL); 102 SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL);
103 else 103 else
104 SetState(BS_DISABLED); 104 SetState(BS_DISABLED);
105 } 105 }
106 106
107 std::string CustomButton::GetClassName() const { 107 std::string CustomButton::GetClassName() const {
108 return kViewClassName; 108 return kViewClassName;
109 } 109 }
110 110
111 bool CustomButton::OnMousePressed(const MouseEvent& event) { 111 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) {
112 if (state_ != BS_DISABLED) { 112 if (state_ != BS_DISABLED) {
113 if (ShouldEnterPushedState(event) && HitTestPoint(event.location())) 113 if (ShouldEnterPushedState(event) && HitTestPoint(event.location()))
114 SetState(BS_PUSHED); 114 SetState(BS_PUSHED);
115 if (request_focus_on_press_) 115 if (request_focus_on_press_)
116 RequestFocus(); 116 RequestFocus();
117 } 117 }
118 return true; 118 return true;
119 } 119 }
120 120
121 bool CustomButton::OnMouseDragged(const MouseEvent& event) { 121 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) {
122 if (state_ != BS_DISABLED) { 122 if (state_ != BS_DISABLED) {
123 if (HitTestPoint(event.location())) 123 if (HitTestPoint(event.location()))
124 SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT); 124 SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT);
125 else 125 else
126 SetState(BS_NORMAL); 126 SetState(BS_NORMAL);
127 } 127 }
128 return true; 128 return true;
129 } 129 }
130 130
131 void CustomButton::OnMouseReleased(const MouseEvent& event) { 131 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) {
132 if (state_ == BS_DISABLED) 132 if (state_ == BS_DISABLED)
133 return; 133 return;
134 134
135 if (!HitTestPoint(event.location())) { 135 if (!HitTestPoint(event.location())) {
136 SetState(BS_NORMAL); 136 SetState(BS_NORMAL);
137 return; 137 return;
138 } 138 }
139 139
140 SetState(BS_HOT); 140 SetState(BS_HOT);
141 if (IsTriggerableEvent(event)) { 141 if (IsTriggerableEvent(event)) {
142 NotifyClick(event); 142 NotifyClick(event);
143 // NOTE: We may be deleted at this point (by the listener's notification 143 // NOTE: We may be deleted at this point (by the listener's notification
144 // handler). 144 // handler).
145 } 145 }
146 } 146 }
147 147
148 void CustomButton::OnMouseCaptureLost() { 148 void CustomButton::OnMouseCaptureLost() {
149 // Starting a drag results in a MouseCaptureLost, we need to ignore it. 149 // Starting a drag results in a MouseCaptureLost, we need to ignore it.
150 if (state_ != BS_DISABLED && !InDrag()) 150 if (state_ != BS_DISABLED && !InDrag())
151 SetState(BS_NORMAL); 151 SetState(BS_NORMAL);
152 } 152 }
153 153
154 void CustomButton::OnMouseEntered(const MouseEvent& event) { 154 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) {
155 if (state_ != BS_DISABLED) 155 if (state_ != BS_DISABLED)
156 SetState(BS_HOT); 156 SetState(BS_HOT);
157 } 157 }
158 158
159 void CustomButton::OnMouseExited(const MouseEvent& event) { 159 void CustomButton::OnMouseExited(const ui::MouseEvent& event) {
160 // Starting a drag results in a MouseExited, we need to ignore it. 160 // Starting a drag results in a MouseExited, we need to ignore it.
161 if (state_ != BS_DISABLED && !InDrag()) 161 if (state_ != BS_DISABLED && !InDrag())
162 SetState(BS_NORMAL); 162 SetState(BS_NORMAL);
163 } 163 }
164 164
165 void CustomButton::OnMouseMoved(const MouseEvent& event) { 165 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) {
166 if (state_ != BS_DISABLED) 166 if (state_ != BS_DISABLED)
167 SetState(HitTestPoint(event.location()) ? BS_HOT : BS_NORMAL); 167 SetState(HitTestPoint(event.location()) ? BS_HOT : BS_NORMAL);
168 } 168 }
169 169
170 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { 170 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) {
171 if (state_ == BS_DISABLED) 171 if (state_ == BS_DISABLED)
172 return false; 172 return false;
173 173
174 // Space sets button state to pushed. Enter clicks the button. This matches 174 // Space sets button state to pushed. Enter clicks the button. This matches
175 // the Windows native behavior of buttons, where Space clicks the button on 175 // the Windows native behavior of buttons, where Space clicks the button on
176 // KeyRelease and Enter clicks the button on KeyPressed. 176 // KeyRelease and Enter clicks the button on KeyPressed.
177 if (event.key_code() == ui::VKEY_SPACE) { 177 if (event.key_code() == ui::VKEY_SPACE) {
178 SetState(BS_PUSHED); 178 SetState(BS_PUSHED);
179 } else if (event.key_code() == ui::VKEY_RETURN) { 179 } else if (event.key_code() == ui::VKEY_RETURN) {
180 SetState(BS_NORMAL); 180 SetState(BS_NORMAL);
181 // TODO(beng): remove once NotifyClick takes ui::Event. 181 // TODO(beng): remove once NotifyClick takes ui::Event.
182 views::MouseEvent synthetic_event( 182 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED,
183 ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON); 183 gfx::Point(),
184 gfx::Point(),
185 ui::EF_LEFT_MOUSE_BUTTON);
184 NotifyClick(synthetic_event); 186 NotifyClick(synthetic_event);
185 } else { 187 } else {
186 return false; 188 return false;
187 } 189 }
188 return true; 190 return true;
189 } 191 }
190 192
191 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { 193 bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) {
192 if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE)) 194 if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE))
193 return false; 195 return false;
194 196
195 SetState(BS_NORMAL); 197 SetState(BS_NORMAL);
196 // TODO(beng): remove once NotifyClick takes ui::Event. 198 // TODO(beng): remove once NotifyClick takes ui::Event.
197 views::MouseEvent synthetic_event( 199 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED,
198 ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON); 200 gfx::Point(),
201 gfx::Point(),
202 ui::EF_LEFT_MOUSE_BUTTON);
199 NotifyClick(synthetic_event); 203 NotifyClick(synthetic_event);
200 return true; 204 return true;
201 } 205 }
202 206
203 ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) { 207 ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) {
204 if (state_ == BS_DISABLED) 208 if (state_ == BS_DISABLED)
205 return Button::OnGestureEvent(event); 209 return Button::OnGestureEvent(event);
206 210
207 if (event.type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(event)) { 211 if (event.type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(event)) {
208 // Set the button state to hot and start the animation fully faded in. The 212 // Set the button state to hot and start the animation fully faded in. The
(...skipping 15 matching lines...) Expand all
224 return Button::OnGestureEvent(event); 228 return Button::OnGestureEvent(event);
225 } 229 }
226 230
227 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { 231 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) {
228 SetState(BS_NORMAL); 232 SetState(BS_NORMAL);
229 /* 233 /*
230 ui::KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), 234 ui::KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(),
231 accelerator.modifiers()); 235 accelerator.modifiers());
232 */ 236 */
233 // TODO(beng): remove once NotifyClick takes ui::Event. 237 // TODO(beng): remove once NotifyClick takes ui::Event.
234 views::MouseEvent synthetic_event( 238 ui::MouseEvent synthetic_event(ui::ET_MOUSE_RELEASED,
235 ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_MOUSE_BUTTON); 239 gfx::Point(),
240 gfx::Point(),
241 ui::EF_LEFT_MOUSE_BUTTON);
236 NotifyClick(synthetic_event); 242 NotifyClick(synthetic_event);
237 return true; 243 return true;
238 } 244 }
239 245
240 void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { 246 void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
241 if (!context_menu_controller()) 247 if (!context_menu_controller())
242 return; 248 return;
243 249
244 // We're about to show the context menu. Showing the context menu likely means 250 // We're about to show the context menu. Showing the context menu likely means
245 // we won't get a mouse exited and reset state. Reset it now to be sure. 251 // we won't get a mouse exited and reset state. Reset it now to be sure.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 if (!is_add && state_ != BS_DISABLED) 320 if (!is_add && state_ != BS_DISABLED)
315 SetState(BS_NORMAL); 321 SetState(BS_NORMAL);
316 } 322 }
317 323
318 void CustomButton::OnBlur() { 324 void CustomButton::OnBlur() {
319 if (IsHotTracked()) 325 if (IsHotTracked())
320 SetState(BS_NORMAL); 326 SetState(BS_NORMAL);
321 } 327 }
322 328
323 } // namespace views 329 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698