diff options
author | rhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-27 00:11:32 +0000 |
---|---|---|
committer | rhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-27 00:11:32 +0000 |
commit | c30d786aefdd011e76ece42e85ba3976e660c2bf (patch) | |
tree | 4c09a589915787d7fbc193cd746a81a740c31a71 /views | |
parent | 9484a39c1229afbdd7f110ad3ff876acf77e037b (diff) | |
download | chromium_src-c30d786aefdd011e76ece42e85ba3976e660c2bf.zip chromium_src-c30d786aefdd011e76ece42e85ba3976e660c2bf.tar.gz chromium_src-c30d786aefdd011e76ece42e85ba3976e660c2bf.tar.bz2 |
Remove menu keyboard grab and close menu on window manager activation change.
BUG=chromium-os:17013
TEST=Open two windows on device, open wrench menu, use Alt-Tab to switch windows and check that menu closes.
Review URL: http://codereview.chromium.org/7484048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94212 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu_controller.cc | 11 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.h | 4 | ||||
-rw-r--r-- | views/controls/menu/menu_host.cc | 9 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 21 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 3 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 7 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 12 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 3 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 13 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 3 | ||||
-rw-r--r-- | views/widget/widget.cc | 9 |
11 files changed, 24 insertions, 71 deletions
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 429d537..c57ba09 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -366,6 +366,12 @@ MenuItemView* MenuController::Run(Widget* parent, } void MenuController::Cancel(ExitType type) { + // If the menu has already been destroyed, no further cancellation is + // needed. We especially don't want to set the |exit_type_| to a lesser + // value. + if (exit_type_ == EXIT_DESTROYED) + return; + if (!showing_) { // This occurs if we're in the process of notifying the delegate for a drop // and the delegate cancels us. @@ -738,6 +744,11 @@ void MenuController::OnDragExitedScrollButton(SubmenuView* source) { StopScrolling(); } +void MenuController::OnWidgetActivationChanged() { + if (!drag_in_progress_) + Cancel(EXIT_ALL); +} + void MenuController::SetSelection(MenuItemView* menu_item, int selection_types) { size_t paths_differ_at = 0; diff --git a/views/controls/menu/menu_controller.h b/views/controls/menu/menu_controller.h index 83beb17..53887e4 100644 --- a/views/controls/menu/menu_controller.h +++ b/views/controls/menu/menu_controller.h @@ -112,6 +112,10 @@ class MenuController : public MessageLoopForUI::Dispatcher { void OnDragEnteredScrollButton(SubmenuView* source, bool is_up); void OnDragExitedScrollButton(SubmenuView* source); + // Invoked once for any Widget activation change. This allows the menu + // to be canceled if the window manager changes the active window. + void OnWidgetActivationChanged(); + private: class MenuScrollTask; diff --git a/views/controls/menu/menu_host.cc b/views/controls/menu/menu_host.cc index cd6a8ae..512148b 100644 --- a/views/controls/menu/menu_host.cc +++ b/views/controls/menu/menu_host.cc @@ -48,13 +48,8 @@ void MenuHost::ShowMenuHost(bool do_capture) { // process of showing. ignore_capture_lost_ = true; Show(); - if (do_capture) { + if (do_capture) native_widget_private()->SetMouseCapture(); - // We do this to effectively disable window manager keyboard accelerators - // for chromeos. Such accelerators could cause cause another window to - // become active and confuse things. - native_widget_private()->SetKeyboardCapture(); - } ignore_capture_lost_ = false; } @@ -79,8 +74,6 @@ void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) { void MenuHost::ReleaseMenuHostCapture() { if (native_widget_private()->HasMouseCapture()) native_widget_private()->ReleaseMouseCapture(); - if (native_widget_private()->HasKeyboardCapture()) - native_widget_private()->ReleaseKeyboardCapture(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 425600f..133be66 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -959,26 +959,6 @@ bool NativeWidgetGtk::HasMouseCapture() const { return GTK_WIDGET_HAS_GRAB(window_contents_) || has_pointer_grab_; } -void NativeWidgetGtk::SetKeyboardCapture() { - DCHECK(!has_keyboard_grab_); - - GdkGrabStatus keyboard_grab_status = - gdk_keyboard_grab(window_contents()->window, FALSE, GDK_CURRENT_TIME); - has_keyboard_grab_ = keyboard_grab_status == GDK_GRAB_SUCCESS; - DCHECK_EQ(GDK_GRAB_SUCCESS, keyboard_grab_status); -} - -void NativeWidgetGtk::ReleaseKeyboardCapture() { - if (has_keyboard_grab_) { - has_keyboard_grab_ = false; - gdk_keyboard_ungrab(GDK_CURRENT_TIME); - } -} - -bool NativeWidgetGtk::HasKeyboardCapture() const { - return has_keyboard_grab_; -} - InputMethod* NativeWidgetGtk::GetInputMethodNative() { if (!input_method_.get()) { // Create input method when it is requested by a child view. @@ -1816,7 +1796,6 @@ gboolean NativeWidgetGtk::OnConfigureEvent(GtkWidget* widget, void NativeWidgetGtk::HandleGtkGrabBroke() { ReleaseMouseCapture(); - ReleaseKeyboardCapture(); delegate_->OnMouseCaptureLost(); } diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index 2337160..6d94f12 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -166,9 +166,6 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void SetMouseCapture() OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual bool HasMouseCapture() const OVERRIDE; - virtual void SetKeyboardCapture() OVERRIDE; - virtual void ReleaseKeyboardCapture() OVERRIDE; - virtual bool HasKeyboardCapture() const OVERRIDE; virtual InputMethod* GetInputMethodNative() OVERRIDE; virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h index 8062d8f..baf85a4 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -125,13 +125,6 @@ class NativeWidgetPrivate : public NativeWidget { // Returns true if this native widget is capturing mouse events. virtual bool HasMouseCapture() const = 0; - // Sets or release keyboard capture. - virtual void SetKeyboardCapture() = 0; - virtual void ReleaseKeyboardCapture() = 0; - - // Returns true if this native widget is capturing keyboard events. - virtual bool HasKeyboardCapture() const = 0; - // Returns the InputMethod for this native widget. // Note that all widgets in a widget hierarchy share the same input method. // TODO(suzhe): rename to GetInputMethod() when NativeWidget implementation diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index 8c17c57..687fa9d 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -240,18 +240,6 @@ bool NativeWidgetViews::HasMouseCapture() const { view_ == parent_root->capture_view(); } -void NativeWidgetViews::SetKeyboardCapture() { - GetParentNativeWidget()->SetKeyboardCapture(); -} - -void NativeWidgetViews::ReleaseKeyboardCapture() { - GetParentNativeWidget()->ReleaseKeyboardCapture(); -} - -bool NativeWidgetViews::HasKeyboardCapture() const { - return GetParentNativeWidget()->HasKeyboardCapture(); -} - InputMethod* NativeWidgetViews::GetInputMethodNative() { if (!input_method_.get()) { #if defined(HAVE_IBUS) diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index 4ab9ced..4d421a1 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -71,9 +71,6 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate, virtual void SetMouseCapture() OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual bool HasMouseCapture() const OVERRIDE; - virtual void SetKeyboardCapture() OVERRIDE; - virtual void ReleaseKeyboardCapture() OVERRIDE; - virtual bool HasKeyboardCapture() const OVERRIDE; virtual InputMethod* GetInputMethodNative() OVERRIDE; virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index dc90727..36ae766 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -625,19 +625,6 @@ bool NativeWidgetWin::HasMouseCapture() const { return GetCapture() == hwnd(); } -void NativeWidgetWin::SetKeyboardCapture() { - // Windows doesn't really support keyboard grabs. -} - -void NativeWidgetWin::ReleaseKeyboardCapture() { - // Windows doesn't really support keyboard grabs. -} - -bool NativeWidgetWin::HasKeyboardCapture() const { - // Windows doesn't really support keyboard grabs. - return false; -} - InputMethod* NativeWidgetWin::GetInputMethodNative() { return input_method_.get(); } diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index 4298fe5..930536b 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -216,9 +216,6 @@ class NativeWidgetWin : public ui::WindowImpl, virtual void SetMouseCapture() OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual bool HasMouseCapture() const OVERRIDE; - virtual void SetKeyboardCapture() OVERRIDE; - virtual void ReleaseKeyboardCapture() OVERRIDE; - virtual bool HasKeyboardCapture() const OVERRIDE; virtual InputMethod* GetInputMethodNative() OVERRIDE; virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index bfead84..2ab6bd71 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -10,6 +10,7 @@ #include "ui/base/l10n/l10n_font_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/compositor/compositor.h" +#include "views/controls/menu/menu_controller.h" #include "views/focus/view_storage.h" #include "views/ime/input_method.h" #include "views/views_delegate.h" @@ -786,9 +787,15 @@ void Widget::EnableInactiveRendering() { } void Widget::OnNativeWidgetActivationChanged(bool active) { - if (!active) + if (!active) { SaveWindowPosition(); + // Close any open menus. + MenuController* menu_controller = MenuController::GetActiveInstance(); + if (menu_controller) + menu_controller->OnWidgetActivationChanged(); + } + FOR_EACH_OBSERVER(Observer, observers_, OnWidgetActivationChanged(this, active)); } |