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

Side by Side Diff: ui/views/widget/native_widget_aura.cc

Issue 8907029: AURA/X11: Handle VKEY_MENU accelerator on content area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/widget/native_widget_aura.h" 5 #include "ui/views/widget/native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "ui/aura/client/activation_client.h" 9 #include "ui/aura/client/activation_client.h"
10 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
110 // NativeWidgetAura, public: 110 // NativeWidgetAura, public:
111 111
112 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) 112 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
113 : delegate_(delegate), 113 : delegate_(delegate),
114 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 114 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
115 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 115 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
116 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), 116 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
117 can_activate_(true), 117 can_activate_(true),
118 #if defined(USE_X11)
119 should_handle_menu_key_release_(false),
120 #endif
121 cursor_(gfx::kNullCursor) { 118 cursor_(gfx::kNullCursor) {
122 } 119 }
123 120
124 NativeWidgetAura::~NativeWidgetAura() { 121 NativeWidgetAura::~NativeWidgetAura() {
125 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 122 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
126 delete delegate_; 123 delete delegate_;
127 else 124 else
128 CloseNow(); 125 CloseNow();
129 } 126 }
130 127
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 if (!value) 538 if (!value)
542 active_window_observer_.reset(); 539 active_window_observer_.reset();
543 else 540 else
544 active_window_observer_.reset(new ActiveWindowObserver(this)); 541 active_window_observer_.reset(new ActiveWindowObserver(this));
545 } 542 }
546 543
547 //////////////////////////////////////////////////////////////////////////////// 544 ////////////////////////////////////////////////////////////////////////////////
548 // NativeWidgetAura, views::InputMethodDelegate implementation: 545 // NativeWidgetAura, views::InputMethodDelegate implementation:
549 546
550 void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) { 547 void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) {
551 if (delegate_->OnKeyEvent(key) || !GetWidget()->GetFocusManager()) 548 FocusManager* focus_manager = GetWidget()->GetFocusManager();
549 if (focus_manager)
550 focus_manager->MaybeResetMenuKeyState(key);
551 if (delegate_->OnKeyEvent(key) || !focus_manager)
552 return; 552 return;
553 553 focus_manager->OnKeyEvent(key);
554 #if defined(USE_X11)
555 // TODO(oshima): This is copied from native_widget_gtk for now.
556 // RenderWidgetHostViewAura doesn't work and needs more work.
557 // oshima thinks this should be moved to focus manager (see
558 // crbug.com/106998), but beng believes that this should be done
559 // in RootWindowHosLinux for aura/linux.
560 const int key_code = key.key_code();
561
562 // Always reset |should_handle_menu_key_release_| unless we are handling a
563 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only
564 // be activated when handling a VKEY_MENU key release event which is preceded
565 // by an un-handled VKEY_MENU key press event.
566 if (key_code != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED)
567 should_handle_menu_key_release_ = false;
568
569 if (key.type() == ui::ET_KEY_PRESSED) {
570 // VKEY_MENU is triggered by key release event.
571 // FocusManager::OnKeyEvent() returns false when the key has been consumed.
572 if (key_code != ui::VKEY_MENU)
573 GetWidget()->GetFocusManager()->OnKeyEvent(key);
574 else
575 should_handle_menu_key_release_ = true;
576 } else if (key_code == ui::VKEY_MENU && should_handle_menu_key_release_ &&
577 (key.flags() & ~ui::EF_ALT_DOWN) == 0) {
578 // Trigger VKEY_MENU when only this key is pressed and released, and both
579 // press and release events are not handled by others.
580 ui::Accelerator accelerator(ui::VKEY_MENU, false, false, false);
581 GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator);
582 }
583 #else
584 if (key.type() == ui::ET_KEY_PRESSED)
585 GetWidget()->GetFocusManager()->OnKeyEvent(key);
586 #endif
587 } 554 }
588 555
589 //////////////////////////////////////////////////////////////////////////////// 556 ////////////////////////////////////////////////////////////////////////////////
590 // NativeWidgetAura, aura::WindowDelegate implementation: 557 // NativeWidgetAura, aura::WindowDelegate implementation:
591 558
592 gfx::Size NativeWidgetAura::GetMinimumSize() const { 559 gfx::Size NativeWidgetAura::GetMinimumSize() const {
593 return delegate_->GetMinimumSize(); 560 return delegate_->GetMinimumSize();
594 } 561 }
595 562
596 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, 563 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
597 const gfx::Rect& new_bounds) { 564 const gfx::Rect& new_bounds) {
598 if (old_bounds.origin() != new_bounds.origin()) 565 if (old_bounds.origin() != new_bounds.origin())
599 GetWidget()->widget_delegate()->OnWidgetMove(); 566 GetWidget()->widget_delegate()->OnWidgetMove();
600 if (old_bounds.size() != new_bounds.size()) 567 if (old_bounds.size() != new_bounds.size())
601 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); 568 delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
602 } 569 }
603 570
604 void NativeWidgetAura::OnFocus() { 571 void NativeWidgetAura::OnFocus() {
605 #if defined(USE_X11)
606 should_handle_menu_key_release_ = false;
607 #endif
608 Widget* widget = GetWidget(); 572 Widget* widget = GetWidget();
609 if (widget->is_top_level()) { 573 if (widget->is_top_level()) {
610 InputMethod* input_method = widget->GetInputMethod(); 574 InputMethod* input_method = widget->GetInputMethod();
611 input_method->OnFocus(); 575 input_method->OnFocus();
612 } 576 }
613 delegate_->OnNativeFocus(window_); 577 delegate_->OnNativeFocus(window_);
614 } 578 }
615 579
616 void NativeWidgetAura::OnBlur() { 580 void NativeWidgetAura::OnBlur() {
617 Widget* widget = GetWidget(); 581 Widget* widget = GetWidget();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 } 815 }
852 } 816 }
853 817
854 // static 818 // static
855 bool NativeWidgetPrivate::IsMouseButtonDown() { 819 bool NativeWidgetPrivate::IsMouseButtonDown() {
856 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); 820 return aura::RootWindow::GetInstance()->IsMouseButtonDown();
857 } 821 }
858 822
859 } // namespace internal 823 } // namespace internal
860 } // namespace views 824 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698