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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && | 239 } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && |
240 ShouldEnterPushedState(*event)) { | 240 ShouldEnterPushedState(*event)) { |
241 SetState(STATE_PRESSED); | 241 SetState(STATE_PRESSED); |
242 if (request_focus_on_press_) | 242 if (request_focus_on_press_) |
243 RequestFocus(); | 243 RequestFocus(); |
244 event->StopPropagation(); | 244 event->StopPropagation(); |
245 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | 245 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || |
246 event->type() == ui::ET_GESTURE_END) { | 246 event->type() == ui::ET_GESTURE_END) { |
247 SetState(STATE_NORMAL); | 247 SetState(STATE_NORMAL); |
248 } | 248 } |
249 if (!event->handled()) | 249 Button::OnGestureEvent(event); |
250 Button::OnGestureEvent(event); | |
251 } | 250 } |
252 | 251 |
253 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 252 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
254 SetState(STATE_NORMAL); | 253 SetState(STATE_NORMAL); |
255 // TODO(beng): remove once NotifyClick takes ui::Event. | 254 // TODO(beng): remove once NotifyClick takes ui::Event. |
256 ui::MouseEvent synthetic_event( | 255 ui::MouseEvent synthetic_event( |
257 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 256 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
258 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 257 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
259 NotifyClick(synthetic_event); | 258 NotifyClick(synthetic_event); |
260 return true; | 259 return true; |
261 } | 260 } |
262 | 261 |
263 void CustomButton::ShowContextMenu(const gfx::Point& p, | 262 void CustomButton::ShowContextMenu(const gfx::Point& p, |
264 ui::MenuSourceType source_type) { | 263 ui::MenuSourceType source_type) { |
265 if (!context_menu_controller()) | 264 if (!context_menu_controller()) |
266 return; | 265 return; |
267 | 266 |
268 // We're about to show the context menu. Showing the context menu likely means | 267 // We're about to show the context menu. Showing the context menu likely means |
269 // we won't get a mouse exited and reset state. Reset it now to be sure. | 268 // we won't get a mouse exited and reset state. Reset it now to be sure. |
270 if (state_ != STATE_DISABLED) | 269 if (state_ != STATE_DISABLED) |
271 SetState(STATE_NORMAL); | 270 SetState(STATE_NORMAL); |
272 View::ShowContextMenu(p, source_type); | 271 View::ShowContextMenu(p, source_type); |
273 } | 272 } |
274 | 273 |
275 void CustomButton::OnDragDone() { | 274 void CustomButton::OnDragDone() { |
276 // Only reset the state to normal if the button isn't currently disabled | 275 // Only reset the state to normal if the button isn't currently disabled |
277 // (since disabled buttons may still be able to be dragged). | 276 // (since disabled buttons may still be able to be dragged). |
278 if (state_ != STATE_DISABLED) | 277 if (state_ != STATE_DISABLED) |
279 SetState(STATE_NORMAL); | 278 SetState(STATE_NORMAL); |
| 279 Button::OnDragDone(); |
280 } | 280 } |
281 | 281 |
282 void CustomButton::GetAccessibleState(ui::AXViewState* state) { | 282 void CustomButton::GetAccessibleState(ui::AXViewState* state) { |
283 Button::GetAccessibleState(state); | 283 Button::GetAccessibleState(state); |
284 switch (state_) { | 284 switch (state_) { |
285 case STATE_HOVERED: | 285 case STATE_HOVERED: |
286 state->AddStateFlag(ui::AX_STATE_HOVERED); | 286 state->AddStateFlag(ui::AX_STATE_HOVERED); |
287 break; | 287 break; |
288 case STATE_PRESSED: | 288 case STATE_PRESSED: |
289 state->AddStateFlag(ui::AX_STATE_PRESSED); | 289 state->AddStateFlag(ui::AX_STATE_PRESSED); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 if (!details.is_add && state_ != STATE_DISABLED) | 372 if (!details.is_add && state_ != STATE_DISABLED) |
373 SetState(STATE_NORMAL); | 373 SetState(STATE_NORMAL); |
374 } | 374 } |
375 | 375 |
376 void CustomButton::OnBlur() { | 376 void CustomButton::OnBlur() { |
377 if (IsHotTracked()) | 377 if (IsHotTracked()) |
378 SetState(STATE_NORMAL); | 378 SetState(STATE_NORMAL); |
379 } | 379 } |
380 | 380 |
381 } // namespace views | 381 } // namespace views |
OLD | NEW |