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

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

Issue 1437523005: Custom buttons should only handle accelerators when focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment Created 5 years, 1 month 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
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/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
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 // Should only handle accelerators when active. However, only top level
255 // widgets can be active, so for child widgets check if they are focused
256 // instead.
257 if ((IsChildWidget() && !FocusInChildWidget()) ||
258 (!IsChildWidget() && !GetWidget()->IsActive())) {
259 return false;
260 }
254 SetState(STATE_NORMAL); 261 SetState(STATE_NORMAL);
255 // TODO(beng): remove once NotifyClick takes ui::Event. 262 // TODO(beng): remove once NotifyClick takes ui::Event.
256 ui::MouseEvent synthetic_event( 263 ui::MouseEvent synthetic_event(
257 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), 264 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
258 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 265 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
259 NotifyClick(synthetic_event); 266 NotifyClick(synthetic_event);
260 return true; 267 return true;
261 } 268 }
262 269
263 void CustomButton::ShowContextMenu(const gfx::Point& p, 270 void CustomButton::ShowContextMenu(const gfx::Point& p,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 const ViewHierarchyChangedDetails& details) { 378 const ViewHierarchyChangedDetails& details) {
372 if (!details.is_add && state_ != STATE_DISABLED) 379 if (!details.is_add && state_ != STATE_DISABLED)
373 SetState(STATE_NORMAL); 380 SetState(STATE_NORMAL);
374 } 381 }
375 382
376 void CustomButton::OnBlur() { 383 void CustomButton::OnBlur() {
377 if (IsHotTracked()) 384 if (IsHotTracked())
378 SetState(STATE_NORMAL); 385 SetState(STATE_NORMAL);
379 } 386 }
380 387
388 bool CustomButton::IsChildWidget() const {
389 return GetWidget() && GetWidget()->GetTopLevelWidget() != GetWidget();
390 }
391
392 bool CustomButton::FocusInChildWidget() const {
393 return GetWidget() &&
394 GetWidget()->GetRootView()->Contains(
395 GetFocusManager()->GetFocusedView());
396 }
397
381 } // namespace views 398 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/custom_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698