diff options
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/menu/menu_host.cc | 50 | ||||
-rw-r--r-- | views/controls/menu/menu_host.h | 19 | ||||
-rw-r--r-- | views/controls/menu/menu_host_gtk.cc | 144 | ||||
-rw-r--r-- | views/controls/menu/menu_host_gtk.h | 47 | ||||
-rw-r--r-- | views/controls/menu/menu_host_views.cc | 33 | ||||
-rw-r--r-- | views/controls/menu/menu_host_views.h | 40 | ||||
-rw-r--r-- | views/controls/menu/menu_host_win.cc | 61 | ||||
-rw-r--r-- | views/controls/menu/menu_host_win.h | 40 |
8 files changed, 34 insertions, 400 deletions
diff --git a/views/controls/menu/menu_host.cc b/views/controls/menu/menu_host.cc index 57f7707..b767feb 100644 --- a/views/controls/menu/menu_host.cc +++ b/views/controls/menu/menu_host.cc @@ -18,10 +18,9 @@ namespace views { // MenuHost, public: MenuHost::MenuHost(SubmenuView* submenu) - : ALLOW_THIS_IN_INITIALIZER_LIST(native_menu_host_( - NativeMenuHost::CreateNativeMenuHost(this))), - submenu_(submenu), - destroying_(false) { + : submenu_(submenu), + destroying_(false), + showing_(false) { } MenuHost::~MenuHost() { @@ -39,7 +38,6 @@ void MenuHost::InitMenuHost(gfx::NativeWindow parent, params.parent = GTK_WIDGET(parent); #endif params.bounds = bounds; - params.native_widget = native_menu_host_->AsNativeWidget(); Init(params); SetContentsView(contents_view); ShowMenuHost(do_capture); @@ -50,9 +48,18 @@ bool MenuHost::IsMenuHostVisible() { } void MenuHost::ShowMenuHost(bool do_capture) { + // Doing a capture may make us get capture lost. Ignore it while we're in the + // process of showing. + showing_ = true; Show(); - if (do_capture) - native_menu_host_->StartCapturing(); + 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(); + } + showing_ = false; } void MenuHost::HideMenuHost() { @@ -74,6 +81,8 @@ 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(); } //////////////////////////////////////////////////////////////////////////////// @@ -87,29 +96,24 @@ bool MenuHost::ShouldReleaseCaptureOnMouseReleased() const { return false; } -//////////////////////////////////////////////////////////////////////////////// -// MenuHost, internal::NativeMenuHostDelegate implementation: - -void MenuHost::OnNativeMenuHostDestroy() { - if (!destroying_) { - // We weren't explicitly told to destroy ourselves, which means the menu was - // deleted out from under us (the window we're parented to was closed). Tell - // the SubmenuView to drop references to us. - submenu_->MenuHostDestroyed(); - } -} - -void MenuHost::OnNativeMenuHostCancelCapture() { - if (destroying_) +void MenuHost::OnMouseCaptureLost() { + if (destroying_ || showing_) return; MenuController* menu_controller = submenu_->GetMenuItem()->GetMenuController(); if (menu_controller && !menu_controller->drag_in_progress()) menu_controller->CancelAll(); + Widget::OnMouseCaptureLost(); } -internal::NativeWidgetDelegate* MenuHost::AsNativeWidgetDelegate() { - return this; +void MenuHost::OnNativeWidgetDestroyed() { + if (!destroying_) { + // We weren't explicitly told to destroy ourselves, which means the menu was + // deleted out from under us (the window we're parented to was closed). Tell + // the SubmenuView to drop references to us. + submenu_->MenuHostDestroyed(); + } + Widget::OnNativeWidgetDestroyed(); } } // namespace views diff --git a/views/controls/menu/menu_host.h b/views/controls/menu/menu_host.h index a33f445..0b5417b 100644 --- a/views/controls/menu/menu_host.h +++ b/views/controls/menu/menu_host.h @@ -20,17 +20,14 @@ class SubmenuView; class View; class Widget; -// SubmenuView uses a MenuHost to house the SubmenuView. MenuHost typically -// extends the native Widget type, but is defined here for clarity of what -// methods SubmenuView uses. +// SubmenuView uses a MenuHost to house the SubmenuView. // // SubmenuView owns the MenuHost. When SubmenuView is done with the MenuHost // |DestroyMenuHost| is invoked. The one exception to this is if the native // OS destroys the widget out from under us, in which case |MenuHostDestroyed| // is invoked back on the SubmenuView and the SubmenuView then drops references // to the MenuHost. -class MenuHost : public Widget, - public internal::NativeMenuHostDelegate { +class MenuHost : public Widget { public: explicit MenuHost(SubmenuView* submenu); virtual ~MenuHost(); @@ -67,13 +64,8 @@ class MenuHost : public Widget, // Overridden from Widget: virtual internal::RootView* CreateRootView() OVERRIDE; virtual bool ShouldReleaseCaptureOnMouseReleased() const OVERRIDE; - - // Overridden from NativeMenuHostDelegate: - virtual void OnNativeMenuHostDestroy() OVERRIDE; - virtual void OnNativeMenuHostCancelCapture() OVERRIDE; - virtual internal::NativeWidgetDelegate* AsNativeWidgetDelegate() OVERRIDE; - - NativeMenuHost* native_menu_host_; + virtual void OnMouseCaptureLost() OVERRIDE; + virtual void OnNativeWidgetDestroyed() OVERRIDE; // The view we contain. SubmenuView* submenu_; @@ -81,6 +73,9 @@ class MenuHost : public Widget, // If true, DestroyMenuHost has been invoked. bool destroying_; + // If true, we're attempting to Show. + bool showing_; + DISALLOW_COPY_AND_ASSIGN(MenuHost); }; diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc deleted file mode 100644 index c3ff9cd..0000000 --- a/views/controls/menu/menu_host_gtk.cc +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/controls/menu/menu_host_gtk.h" - -#include <gdk/gdk.h> - -#if defined(HAVE_XINPUT2) && defined(TOUCH_UI) -#include <gdk/gdkx.h> -#include <X11/extensions/XInput2.h> -#endif - -#include "views/controls/menu/menu_host_views.h" -#include "views/controls/menu/native_menu_host_delegate.h" -#include "views/views_delegate.h" - -#if defined(HAVE_XINPUT2) && defined(TOUCH_UI) -#include "views/touchui/touch_factory.h" -#endif - -namespace views { - -//////////////////////////////////////////////////////////////////////////////// -// MenuHostGtk, public: - -MenuHostGtk::MenuHostGtk(internal::NativeMenuHostDelegate* delegate) - : NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), - did_input_grab_(false), - delegate_(delegate) { -} - -MenuHostGtk::~MenuHostGtk() { -} - -//////////////////////////////////////////////////////////////////////////////// -// MenuHostGtk, NativeMenuHost implementation: - -void MenuHostGtk::StartCapturing() { - DCHECK(!did_input_grab_); - - // Release the current grab. - GtkWidget* current_grab_window = gtk_grab_get_current(); - if (current_grab_window) - gtk_grab_remove(current_grab_window); - - // Make sure all app mouse/keyboard events are targeted at us only. - SetMouseCapture(); - - // And do a grab. NOTE: we do this to ensure we get mouse/keyboard - // events from other apps, a grab done with gtk_grab_add doesn't get - // events from other apps. - GdkGrabStatus pointer_grab_status = - gdk_pointer_grab(window_contents()->window, FALSE, - static_cast<GdkEventMask>( - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK), - NULL, NULL, GDK_CURRENT_TIME); - GdkGrabStatus keyboard_grab_status = - gdk_keyboard_grab(window_contents()->window, FALSE, - GDK_CURRENT_TIME); - - did_input_grab_ = pointer_grab_status == GDK_GRAB_SUCCESS && - keyboard_grab_status == GDK_GRAB_SUCCESS; - - DCHECK_EQ(GDK_GRAB_SUCCESS, pointer_grab_status); - DCHECK_EQ(GDK_GRAB_SUCCESS, keyboard_grab_status); - -#if defined(HAVE_XINPUT2) && defined(TOUCH_UI) - ::Window window = GDK_WINDOW_XID(window_contents()->window); - Display* display = GDK_WINDOW_XDISPLAY(window_contents()->window); - bool xi2grab = TouchFactory::GetInstance()->GrabTouchDevices(display, window); - did_input_grab_ = did_input_grab_ && xi2grab; -#endif - - DCHECK(did_input_grab_); - // need keyboard grab. -} - -NativeWidget* MenuHostGtk::AsNativeWidget() { - return this; -} - -//////////////////////////////////////////////////////////////////////////////// -// MenuHostGtk, NativeWidgetGtk overrides: - -void MenuHostGtk::InitNativeWidget(const Widget::InitParams& params) { - NativeWidgetGtk::InitNativeWidget(params); - // Make sure we get destroyed when the parent is destroyed. - gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE); - gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()), - GDK_WINDOW_TYPE_HINT_MENU); -} - -void MenuHostGtk::ReleaseMouseCapture() { - NativeWidgetGtk::ReleaseMouseCapture(); - if (did_input_grab_) { - did_input_grab_ = false; - gdk_pointer_ungrab(GDK_CURRENT_TIME); - gdk_keyboard_ungrab(GDK_CURRENT_TIME); -#if defined(HAVE_XINPUT2) && defined(TOUCH_UI) - TouchFactory::GetInstance()->UngrabTouchDevices( - GDK_WINDOW_XDISPLAY(window_contents()->window)); -#endif - } -} - -void MenuHostGtk::OnDestroy(GtkWidget* object) { - delegate_->OnNativeMenuHostDestroy(); - NativeWidgetGtk::OnDestroy(object); -} - -void MenuHostGtk::HandleXGrabBroke() { - // Grab may already be release in ReleaseGrab. - if (did_input_grab_) { - did_input_grab_ = false; - delegate_->OnNativeMenuHostCancelCapture(); - } - NativeWidgetGtk::HandleXGrabBroke(); -} - -void MenuHostGtk::HandleGtkGrabBroke() { - // Grab can be broken by drag & drop, other menu or screen locker. - if (did_input_grab_) { - ReleaseMouseCapture(); - delegate_->OnNativeMenuHostCancelCapture(); - } - NativeWidgetGtk::HandleGtkGrabBroke(); -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeMenuHost, public: - -// static -NativeMenuHost* NativeMenuHost::CreateNativeMenuHost( - internal::NativeMenuHostDelegate* delegate) { - if (Widget::IsPureViews() && - ViewsDelegate::views_delegate->GetDefaultParentView()) { - return new MenuHostViews(delegate); - } - return new MenuHostGtk(delegate); -} - -} // namespace views diff --git a/views/controls/menu/menu_host_gtk.h b/views/controls/menu/menu_host_gtk.h deleted file mode 100644 index e49064e..0000000 --- a/views/controls/menu/menu_host_gtk.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - - -#ifndef VIEWS_CONTROLS_MENU_MENU_HOST_GTK_H_ -#define VIEWS_CONTROLS_MENU_MENU_HOST_GTK_H_ -#pragma once - -#include "views/controls/menu/native_menu_host.h" -#include "views/widget/native_widget_gtk.h" - -namespace views { -namespace internal { -class NativeMenuHostDelegate; -} - -// NativeMenuHost implementation for Gtk. -class MenuHostGtk : public NativeWidgetGtk, - public NativeMenuHost { - public: - explicit MenuHostGtk(internal::NativeMenuHostDelegate* delegate); - virtual ~MenuHostGtk(); - - private: - // Overridden from NativeMenuHost: - virtual void StartCapturing() OVERRIDE; - virtual NativeWidget* AsNativeWidget() OVERRIDE; - - // Overridden from NativeWidgetGtk: - virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; - virtual void ReleaseMouseCapture() OVERRIDE; - virtual void OnDestroy(GtkWidget* object) OVERRIDE; - virtual void HandleGtkGrabBroke() OVERRIDE; - virtual void HandleXGrabBroke() OVERRIDE; - - // Have we done input grab? - bool did_input_grab_; - - internal::NativeMenuHostDelegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(MenuHostGtk); -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_MENU_MENU_HOST_GTK_H_ diff --git a/views/controls/menu/menu_host_views.cc b/views/controls/menu/menu_host_views.cc deleted file mode 100644 index 6896d67..0000000 --- a/views/controls/menu/menu_host_views.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/controls/menu/menu_host_views.h" - -#include "views/controls/menu/native_menu_host_delegate.h" - -namespace views { - -MenuHostViews::MenuHostViews(internal::NativeMenuHostDelegate* delegate) - : NativeWidgetViews(delegate->AsNativeWidgetDelegate()), - delegate_(delegate) { -} - -MenuHostViews::~MenuHostViews() { -} - -void MenuHostViews::StartCapturing() { - SetMouseCapture(); -} - -NativeWidget* MenuHostViews::AsNativeWidget() { - return this; -} - -void MenuHostViews::InitNativeWidget(const Widget::InitParams& params) { - NativeWidgetViews::InitNativeWidget(params); - GetView()->SetVisible(false); -} - -} // namespace views - diff --git a/views/controls/menu/menu_host_views.h b/views/controls/menu/menu_host_views.h deleted file mode 100644 index 7ab1729..0000000 --- a/views/controls/menu/menu_host_views.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_CONTROLS_MENU_MENU_HOST_VIEWS_H_ -#define VIEWS_CONTROLS_MENU_MENU_HOST_VIEWS_H_ -#pragma once - -#include "views/controls/menu/native_menu_host.h" -#include "views/widget/native_widget_views.h" - -namespace views { -namespace internal { -class NativeMenuHostDelegate; -} - -// MenuHost implementation for views. -class MenuHostViews : public NativeWidgetViews, - public NativeMenuHost { - public: - explicit MenuHostViews(internal::NativeMenuHostDelegate* delegate); - virtual ~MenuHostViews(); - - private: - // Overridden from NativeMenuHost: - virtual void StartCapturing() OVERRIDE; - virtual NativeWidget* AsNativeWidget() OVERRIDE; - - // Overridden from NativeWidgetViews: - virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; - - internal::NativeMenuHostDelegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(MenuHostViews); -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_MENU_MENU_HOST_VIEWS_H_ - diff --git a/views/controls/menu/menu_host_win.cc b/views/controls/menu/menu_host_win.cc deleted file mode 100644 index 2190b29..0000000 --- a/views/controls/menu/menu_host_win.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/controls/menu/menu_host_win.h" - -#include "views/controls/menu/menu_host_views.h" -#include "views/controls/menu/native_menu_host_delegate.h" -#include "views/views_delegate.h" - -namespace views { - -//////////////////////////////////////////////////////////////////////////////// -// MenuHostWin, public: - -MenuHostWin::MenuHostWin(internal::NativeMenuHostDelegate* delegate) - : NativeWidgetWin(delegate->AsNativeWidgetDelegate()), - delegate_(delegate) { -} - -MenuHostWin::~MenuHostWin() { -} - -//////////////////////////////////////////////////////////////////////////////// -// MenuHostWin, NativeMenuHost implementation: - -void MenuHostWin::StartCapturing() { - SetMouseCapture(); -} - -NativeWidget* MenuHostWin::AsNativeWidget() { - return this; -} - -//////////////////////////////////////////////////////////////////////////////// -// MenuHostWin, NativeWidgetWin overrides: - -void MenuHostWin::OnDestroy() { - delegate_->OnNativeMenuHostDestroy(); - NativeWidgetWin::OnDestroy(); -} - -void MenuHostWin::OnCancelMode() { - delegate_->OnNativeMenuHostCancelCapture(); - NativeWidgetWin::OnCancelMode(); -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeMenuHost, public: - -// static -NativeMenuHost* NativeMenuHost::CreateNativeMenuHost( - internal::NativeMenuHostDelegate* delegate) { - if (Widget::IsPureViews() && - ViewsDelegate::views_delegate->GetDefaultParentView()) { - return new MenuHostViews(delegate); - } - return new MenuHostWin(delegate); -} - -} // namespace views diff --git a/views/controls/menu/menu_host_win.h b/views/controls/menu/menu_host_win.h deleted file mode 100644 index 9c9f8f8..0000000 --- a/views/controls/menu/menu_host_win.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_CONTROLS_MENU_MENU_HOST_WIN_H_ -#define VIEWS_CONTROLS_MENU_MENU_HOST_WIN_H_ -#pragma once - -#include "views/controls/menu/native_menu_host.h" -#include "views/widget/native_widget_win.h" - -namespace views { -namespace internal { -class NativeMenuHostDelegate; -} - -// MenuHost implementation for windows. -class MenuHostWin : public NativeWidgetWin, - public NativeMenuHost { - public: - explicit MenuHostWin(internal::NativeMenuHostDelegate* delegate); - virtual ~MenuHostWin(); - - private: - // Overridden from NativeMenuHost: - virtual void StartCapturing() OVERRIDE; - virtual NativeWidget* AsNativeWidget() OVERRIDE; - - // Overridden from NativeWidgetWin: - virtual void OnDestroy() OVERRIDE; - virtual void OnCancelMode() OVERRIDE; - - internal::NativeMenuHostDelegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(MenuHostWin); -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_MENU_MENU_HOST_WIN_H_ |