| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 SetState(STATE_NORMAL); | 258 SetState(STATE_NORMAL); |
| 259 } | 259 } |
| 260 if (!event->handled()) | 260 if (!event->handled()) |
| 261 Button::OnGestureEvent(event); | 261 Button::OnGestureEvent(event); |
| 262 } | 262 } |
| 263 | 263 |
| 264 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 264 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 265 // Should only handle accelerators when active. However, only top level | 265 // Should only handle accelerators when active. However, only top level |
| 266 // widgets can be active, so for child widgets check if they are focused | 266 // widgets can be active, so for child widgets check if they are focused |
| 267 // instead. | 267 // instead. |
| 268 if ((IsChildWidget() && !FocusInChildWidget()) || | 268 if (!ShouldHandleAcceleratorWhenInactive() && |
| 269 (!IsChildWidget() && !GetWidget()->IsActive())) { | 269 ((IsChildWidget() && !FocusInChildWidget()) || |
| 270 (!IsChildWidget() && !GetWidget()->IsActive()))) { |
| 270 return false; | 271 return false; |
| 271 } | 272 } |
| 272 SetState(STATE_NORMAL); | 273 SetState(STATE_NORMAL); |
| 273 // TODO(beng): remove once NotifyClick takes ui::Event. | 274 // TODO(beng): remove once NotifyClick takes ui::Event. |
| 274 ui::MouseEvent synthetic_event( | 275 ui::MouseEvent synthetic_event( |
| 275 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 276 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 276 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 277 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 277 NotifyClick(synthetic_event); | 278 NotifyClick(synthetic_event); |
| 278 return true; | 279 return true; |
| 279 } | 280 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 return event.type() == ui::ET_GESTURE_TAP_DOWN || | 355 return event.type() == ui::ET_GESTURE_TAP_DOWN || |
| 355 event.type() == ui::ET_GESTURE_TAP || | 356 event.type() == ui::ET_GESTURE_TAP || |
| 356 (event.IsMouseEvent() && | 357 (event.IsMouseEvent() && |
| 357 (triggerable_event_flags_ & event.flags()) != 0); | 358 (triggerable_event_flags_ & event.flags()) != 0); |
| 358 } | 359 } |
| 359 | 360 |
| 360 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { | 361 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { |
| 361 return IsTriggerableEvent(event); | 362 return IsTriggerableEvent(event); |
| 362 } | 363 } |
| 363 | 364 |
| 365 bool CustomButton::ShouldHandleAcceleratorWhenInactive() { |
| 366 return false; |
| 367 } |
| 368 |
| 364 bool CustomButton::ShouldEnterHoveredState() { | 369 bool CustomButton::ShouldEnterHoveredState() { |
| 365 if (!visible()) | 370 if (!visible()) |
| 366 return false; | 371 return false; |
| 367 | 372 |
| 368 bool check_mouse_position = true; | 373 bool check_mouse_position = true; |
| 369 #if defined(USE_AURA) | 374 #if defined(USE_AURA) |
| 370 // If another window has capture, we shouldn't check the current mouse | 375 // If another window has capture, we shouldn't check the current mouse |
| 371 // position because the button won't receive any mouse events - so if the | 376 // position because the button won't receive any mouse events - so if the |
| 372 // mouse was hovered, the button would be stuck in a hovered state (since it | 377 // mouse was hovered, the button would be stuck in a hovered state (since it |
| 373 // would never receive OnMouseExited). | 378 // would never receive OnMouseExited). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | 414 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); |
| 410 } | 415 } |
| 411 | 416 |
| 412 bool CustomButton::FocusInChildWidget() const { | 417 bool CustomButton::FocusInChildWidget() const { |
| 413 return GetWidget() && | 418 return GetWidget() && |
| 414 GetWidget()->GetRootView()->Contains( | 419 GetWidget()->GetRootView()->Contains( |
| 415 GetFocusManager()->GetFocusedView()); | 420 GetFocusManager()->GetFocusedView()); |
| 416 } | 421 } |
| 417 | 422 |
| 418 } // namespace views | 423 } // namespace views |
| OLD | NEW |