diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-28 17:48:11 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-28 17:48:11 +0000 |
commit | bead2c9fb8932fde4bf40a61b9563401d11c69ef (patch) | |
tree | 3253e54b789680322ae26e6eaa9c7af380652af5 /views | |
parent | 805ca7ed20f92d79e02772ab8b28636a863b21bb (diff) | |
download | chromium_src-bead2c9fb8932fde4bf40a61b9563401d11c69ef.zip chromium_src-bead2c9fb8932fde4bf40a61b9563401d11c69ef.tar.gz chromium_src-bead2c9fb8932fde4bf40a61b9563401d11c69ef.tar.bz2 |
Menus in the views desktop. Adds MenuHostViews. This is buggy due to rendering issues I believe.
Moves IsMouseButtonDown to a static method on Widget that is implemented by each platform. It needs to be static as it can be called before the NativeWidget is fully initialized, and does not depend on any NativeWidget state.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7253018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/menu/menu_host_gtk.cc | 6 | ||||
-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 | 6 | ||||
-rw-r--r-- | views/views.gyp | 6 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 25 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 6 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 4 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 18 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 1 | ||||
-rw-r--r-- | views/widget/widget.cc | 6 |
13 files changed, 119 insertions, 34 deletions
diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc index 962d701..c3ff9cd 100644 --- a/views/controls/menu/menu_host_gtk.cc +++ b/views/controls/menu/menu_host_gtk.cc @@ -11,7 +11,9 @@ #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" @@ -132,6 +134,10 @@ void MenuHostGtk::HandleGtkGrabBroke() { // static NativeMenuHost* NativeMenuHost::CreateNativeMenuHost( internal::NativeMenuHostDelegate* delegate) { + if (Widget::IsPureViews() && + ViewsDelegate::views_delegate->GetDefaultParentView()) { + return new MenuHostViews(delegate); + } return new MenuHostGtk(delegate); } diff --git a/views/controls/menu/menu_host_views.cc b/views/controls/menu/menu_host_views.cc new file mode 100644 index 0000000..6896d67 --- /dev/null +++ b/views/controls/menu/menu_host_views.cc @@ -0,0 +1,33 @@ +// 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 new file mode 100644 index 0000000..7ab1729 --- /dev/null +++ b/views/controls/menu/menu_host_views.h @@ -0,0 +1,40 @@ +// 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 index 7e01134..2190b29 100644 --- a/views/controls/menu/menu_host_win.cc +++ b/views/controls/menu/menu_host_win.cc @@ -4,7 +4,9 @@ #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 { @@ -49,6 +51,10 @@ void MenuHostWin::OnCancelMode() { // static NativeMenuHost* NativeMenuHost::CreateNativeMenuHost( internal::NativeMenuHostDelegate* delegate) { + if (Widget::IsPureViews() && + ViewsDelegate::views_delegate->GetDefaultParentView()) { + return new MenuHostViews(delegate); + } return new MenuHostWin(delegate); } diff --git a/views/views.gyp b/views/views.gyp index 9003a44..6efc27f 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -142,12 +142,14 @@ 'controls/menu/menu_gtk.h', 'controls/menu/menu_host.cc', 'controls/menu/menu_host.h', + 'controls/menu/menu_host_gtk.cc', + 'controls/menu/menu_host_gtk.h', 'controls/menu/menu_host_root_view.cc', 'controls/menu/menu_host_root_view.h', + 'controls/menu/menu_host_views.cc', + 'controls/menu/menu_host_views.h', 'controls/menu/menu_host_win.cc', 'controls/menu/menu_host_win.h', - 'controls/menu/menu_host_gtk.cc', - 'controls/menu/menu_host_gtk.h', 'controls/menu/menu_item_view.cc', 'controls/menu/menu_item_view.h', 'controls/menu/menu_item_view_gtk.cc', diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 5fdf830..2b0b135 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -888,18 +888,6 @@ bool NativeWidgetGtk::HasMouseCapture() const { return GTK_WIDGET_HAS_GRAB(window_contents_); } -bool NativeWidgetGtk::IsMouseButtonDown() const { - bool button_pressed = false; - GdkEvent* event = gtk_get_current_event(); - if (event) { - button_pressed = event->type == GDK_BUTTON_PRESS || - event->type == GDK_2BUTTON_PRESS || - event->type == GDK_3BUTTON_PRESS; - gdk_event_free(event); - } - return button_pressed; -} - InputMethod* NativeWidgetGtk::GetInputMethodNative() { if (!input_method_.get()) { // Create input method when it is requested by a child view. @@ -2123,5 +2111,18 @@ void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, } } +// static +bool NativeWidgetPrivate::IsMouseButtonDown() { + bool button_pressed = false; + GdkEvent* event = gtk_get_current_event(); + if (event) { + button_pressed = event->type == GDK_BUTTON_PRESS || + event->type == GDK_2BUTTON_PRESS || + event->type == GDK_3BUTTON_PRESS; + gdk_event_free(event); + } + return button_pressed; +} + } // namespace internal } // namespace views diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index e7e34f33..af0ac49 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -174,7 +174,6 @@ class NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void SetMouseCapture() OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual bool HasMouseCapture() const OVERRIDE; - virtual bool IsMouseButtonDown() 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 91ea7d6..253ca53 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -60,6 +60,9 @@ class NativeWidgetPrivate : public NativeWidget { static void ReparentNativeView(gfx::NativeView native_view, gfx::NativeView new_parent); + // Returns true if any mouse button is currently down. + static bool IsMouseButtonDown(); + // Initializes the NativeWidget. virtual void InitNativeWidget(const Widget::InitParams& params) = 0; @@ -109,9 +112,6 @@ class NativeWidgetPrivate : public NativeWidget { // Returns true if this native widget is capturing all events. virtual bool HasMouseCapture() const = 0; - // Returns true if any mouse button is currently pressed. - virtual bool IsMouseButtonDown() 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 72c251f..9d167b6 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -122,10 +122,6 @@ bool NativeWidgetViews::HasMouseCapture() const { return GetParentNativeWidget()->HasMouseCapture(); } -bool NativeWidgetViews::IsMouseButtonDown() const { - return GetParentNativeWidget()->IsMouseButtonDown(); -} - InputMethod* NativeWidgetViews::GetInputMethodNative() { return GetParentNativeWidget()->GetInputMethodNative(); } diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index 36d65d4..71060d9 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -55,7 +55,6 @@ class NativeWidgetViews : public internal::NativeWidgetPrivate { virtual void SetMouseCapture() OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual bool HasMouseCapture() const OVERRIDE; - virtual bool IsMouseButtonDown() 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 3db46e8..29b3ec6 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -603,14 +603,6 @@ bool NativeWidgetWin::HasMouseCapture() const { return GetCapture() == hwnd(); } -bool NativeWidgetWin::IsMouseButtonDown() const { - return (GetKeyState(VK_LBUTTON) & 0x80) || - (GetKeyState(VK_RBUTTON) & 0x80) || - (GetKeyState(VK_MBUTTON) & 0x80) || - (GetKeyState(VK_XBUTTON1) & 0x80) || - (GetKeyState(VK_XBUTTON2) & 0x80); -} - InputMethod* NativeWidgetWin::GetInputMethodNative() { return input_method_.get(); } @@ -2506,5 +2498,15 @@ void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, } } +// static +bool NativeWidgetPrivate::IsMouseButtonDown() { + return (GetKeyState(VK_LBUTTON) & 0x80) || + (GetKeyState(VK_RBUTTON) & 0x80) || + (GetKeyState(VK_MBUTTON) & 0x80) || + (GetKeyState(VK_XBUTTON1) & 0x80) || + (GetKeyState(VK_XBUTTON2) & 0x80); +} + } // namespace internal + } // namespace views diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index ed40644..b9d3547 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -208,7 +208,6 @@ class NativeWidgetWin : public ui::WindowImpl, virtual void SetMouseCapture() OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual bool HasMouseCapture() const OVERRIDE; - virtual bool IsMouseButtonDown() 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 6f1e5cf..cc60582 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -261,8 +261,10 @@ void Widget::Init(const InitParams& params) { internal::NativeWidgetPrivate::CreateNativeWidget(this); GetRootView(); default_theme_provider_.reset(new DefaultThemeProvider); - if (params.type == InitParams::TYPE_MENU) - is_mouse_button_pressed_ = native_widget_->IsMouseButtonDown(); + if (params.type == InitParams::TYPE_MENU) { + is_mouse_button_pressed_ = + internal::NativeWidgetPrivate::IsMouseButtonDown(); + } native_widget_->InitNativeWidget(params); if (params.type == InitParams::TYPE_WINDOW) { non_client_view_ = new NonClientView; |