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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if (!event->handled()) |
250 Button::OnGestureEvent(event); | 250 Button::OnGestureEvent(event); |
251 } | 251 } |
252 | 252 |
253 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { | 253 bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { |
254 if ((IsChildWidget() && !FocusInChildWidget()) || | |
sky
2015/11/17 14:22:39
This is subtle enough that it is worth a comment.
meacer
2015/11/17 18:56:26
Done.
| |
255 (!IsChildWidget() && !GetWidget()->IsActive())) { | |
256 return false; | |
257 } | |
254 SetState(STATE_NORMAL); | 258 SetState(STATE_NORMAL); |
255 // TODO(beng): remove once NotifyClick takes ui::Event. | 259 // TODO(beng): remove once NotifyClick takes ui::Event. |
256 ui::MouseEvent synthetic_event( | 260 ui::MouseEvent synthetic_event( |
257 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 261 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
258 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 262 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
259 NotifyClick(synthetic_event); | 263 NotifyClick(synthetic_event); |
260 return true; | 264 return true; |
261 } | 265 } |
262 | 266 |
263 void CustomButton::ShowContextMenu(const gfx::Point& p, | 267 void CustomButton::ShowContextMenu(const gfx::Point& p, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 const ViewHierarchyChangedDetails& details) { | 375 const ViewHierarchyChangedDetails& details) { |
372 if (!details.is_add && state_ != STATE_DISABLED) | 376 if (!details.is_add && state_ != STATE_DISABLED) |
373 SetState(STATE_NORMAL); | 377 SetState(STATE_NORMAL); |
374 } | 378 } |
375 | 379 |
376 void CustomButton::OnBlur() { | 380 void CustomButton::OnBlur() { |
377 if (IsHotTracked()) | 381 if (IsHotTracked()) |
378 SetState(STATE_NORMAL); | 382 SetState(STATE_NORMAL); |
379 } | 383 } |
380 | 384 |
385 bool CustomButton::IsChildWidget() const { | |
386 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget(); | |
387 } | |
388 | |
389 bool CustomButton::FocusInChildWidget() const { | |
390 return GetWidget() && | |
391 GetWidget()->GetRootView()->Contains( | |
392 GetFocusManager()->GetFocusedView()); | |
393 } | |
394 | |
381 } // namespace views | 395 } // namespace views |
OLD | NEW |