| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 event->StopPropagation(); | 256 event->StopPropagation(); |
| 257 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | 257 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || |
| 258 event->type() == ui::ET_GESTURE_END) { | 258 event->type() == ui::ET_GESTURE_END) { |
| 259 SetState(STATE_NORMAL); | 259 SetState(STATE_NORMAL); |
| 260 } | 260 } |
| 261 if (!event->handled()) | 261 if (!event->handled()) |
| 262 Button::OnGestureEvent(event); | 262 Button::OnGestureEvent(event); |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 265 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 266 // Should only handle accelerators when active. However, only top level | |
| 267 // widgets can be active, so for child widgets check if they are focused | |
| 268 // instead. | |
| 269 if ((IsChildWidget() && !FocusInChildWidget()) || | |
| 270 (!IsChildWidget() && !GetWidget()->IsActive())) { | |
| 271 return false; | |
| 272 } | |
| 273 SetState(STATE_NORMAL); | 266 SetState(STATE_NORMAL); |
| 274 // TODO(beng): remove once NotifyClick takes ui::Event. | 267 // TODO(beng): remove once NotifyClick takes ui::Event. |
| 275 ui::MouseEvent synthetic_event( | 268 ui::MouseEvent synthetic_event( |
| 276 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 269 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 277 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 270 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 278 NotifyClick(synthetic_event); | 271 NotifyClick(synthetic_event); |
| 279 return true; | 272 return true; |
| 280 } | 273 } |
| 281 | 274 |
| 282 void CustomButton::ShowContextMenu(const gfx::Point& p, | 275 void CustomButton::ShowContextMenu(const gfx::Point& p, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 ink_drop_delegate()->OnAction(ink_drop_action_on_click_); | 426 ink_drop_delegate()->OnAction(ink_drop_action_on_click_); |
| 434 Button::NotifyClick(event); | 427 Button::NotifyClick(event); |
| 435 } | 428 } |
| 436 | 429 |
| 437 void CustomButton::OnClickCanceled(const ui::Event& event) { | 430 void CustomButton::OnClickCanceled(const ui::Event& event) { |
| 438 if (ink_drop_delegate()) | 431 if (ink_drop_delegate()) |
| 439 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); | 432 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); |
| 440 Button::OnClickCanceled(event); | 433 Button::OnClickCanceled(event); |
| 441 } | 434 } |
| 442 | 435 |
| 443 bool CustomButton::IsChildWidget() const { | |
| 444 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | |
| 445 } | |
| 446 | |
| 447 bool CustomButton::FocusInChildWidget() const { | |
| 448 return GetWidget() && | |
| 449 GetWidget()->GetRootView()->Contains( | |
| 450 GetFocusManager()->GetFocusedView()); | |
| 451 } | |
| 452 | |
| 453 } // namespace views | 436 } // namespace views |
| OLD | NEW |