| OLD | NEW |
| 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 "views/controls/menu/menu_host_gtk.h" | 5 #include "views/controls/menu/menu_host_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 | 8 |
| 9 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) | 9 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| 11 #include <X11/extensions/XInput2.h> | 11 #include <X11/extensions/XInput2.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "views/controls/menu/native_menu_host_delegate.h" | 14 #include "views/controls/menu/native_menu_host_delegate.h" |
| 15 | 15 |
| 16 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) | 16 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) |
| 17 #include "views/touchui/touch_factory.h" | 17 #include "views/touchui/touch_factory.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 | 21 |
| 22 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
| 23 // MenuHostGtk, public: | 23 // MenuHostGtk, public: |
| 24 | 24 |
| 25 MenuHostGtk::MenuHostGtk(internal::NativeMenuHostDelegate* delegate) | 25 MenuHostGtk::MenuHostGtk(internal::NativeMenuHostDelegate* delegate) |
| 26 : WidgetGtk(WidgetGtk::TYPE_POPUP), | 26 : did_input_grab_(false), |
| 27 did_input_grab_(false), | |
| 28 delegate_(delegate) { | 27 delegate_(delegate) { |
| 29 } | 28 } |
| 30 | 29 |
| 31 MenuHostGtk::~MenuHostGtk() { | 30 MenuHostGtk::~MenuHostGtk() { |
| 32 } | 31 } |
| 33 | 32 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 35 // MenuHostGtk, NativeMenuHost implementation: | 34 // MenuHostGtk, NativeMenuHost implementation: |
| 36 | 35 |
| 37 void MenuHostGtk::InitMenuHost(gfx::NativeWindow parent, | |
| 38 const gfx::Rect& bounds) { | |
| 39 make_transient_to_parent(); | |
| 40 WidgetGtk::Init(GTK_WIDGET(parent), bounds); | |
| 41 // Make sure we get destroyed when the parent is destroyed. | |
| 42 gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE); | |
| 43 gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()), | |
| 44 GDK_WINDOW_TYPE_HINT_MENU); | |
| 45 } | |
| 46 | |
| 47 void MenuHostGtk::StartCapturing() { | 36 void MenuHostGtk::StartCapturing() { |
| 48 DCHECK(!did_input_grab_); | 37 DCHECK(!did_input_grab_); |
| 49 | 38 |
| 50 // Release the current grab. | 39 // Release the current grab. |
| 51 GtkWidget* current_grab_window = gtk_grab_get_current(); | 40 GtkWidget* current_grab_window = gtk_grab_get_current(); |
| 52 if (current_grab_window) | 41 if (current_grab_window) |
| 53 gtk_grab_remove(current_grab_window); | 42 gtk_grab_remove(current_grab_window); |
| 54 | 43 |
| 55 // Make sure all app mouse/keyboard events are targeted at us only. | 44 // Make sure all app mouse/keyboard events are targeted at us only. |
| 56 SetMouseCapture(); | 45 SetMouseCapture(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 85 // need keyboard grab. | 74 // need keyboard grab. |
| 86 } | 75 } |
| 87 | 76 |
| 88 NativeWidget* MenuHostGtk::AsNativeWidget() { | 77 NativeWidget* MenuHostGtk::AsNativeWidget() { |
| 89 return this; | 78 return this; |
| 90 } | 79 } |
| 91 | 80 |
| 92 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
| 93 // MenuHostGtk, WidgetGtk overrides: | 82 // MenuHostGtk, WidgetGtk overrides: |
| 94 | 83 |
| 84 void MenuHostGtk::InitNativeWidget(const Widget::CreateParams& params) { |
| 85 make_transient_to_parent(); |
| 86 WidgetGtk::InitNativeWidget(params); |
| 87 // Make sure we get destroyed when the parent is destroyed. |
| 88 gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE); |
| 89 gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()), |
| 90 GDK_WINDOW_TYPE_HINT_MENU); |
| 91 } |
| 92 |
| 95 // TODO(beng): remove once MenuHost is-a Widget | 93 // TODO(beng): remove once MenuHost is-a Widget |
| 96 RootView* MenuHostGtk::CreateRootView() { | 94 RootView* MenuHostGtk::CreateRootView() { |
| 97 return delegate_->CreateRootView(); | 95 return delegate_->CreateRootView(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 bool MenuHostGtk::ShouldReleaseCaptureOnMouseReleased() const { | 98 bool MenuHostGtk::ShouldReleaseCaptureOnMouseReleased() const { |
| 101 return delegate_->ShouldReleaseCaptureOnMouseRelease(); | 99 return delegate_->ShouldReleaseCaptureOnMouseRelease(); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void MenuHostGtk::ReleaseMouseCapture() { | 102 void MenuHostGtk::ReleaseMouseCapture() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 //////////////////////////////////////////////////////////////////////////////// | 138 //////////////////////////////////////////////////////////////////////////////// |
| 141 // NativeMenuHost, public: | 139 // NativeMenuHost, public: |
| 142 | 140 |
| 143 // static | 141 // static |
| 144 NativeMenuHost* NativeMenuHost::CreateNativeMenuHost( | 142 NativeMenuHost* NativeMenuHost::CreateNativeMenuHost( |
| 145 internal::NativeMenuHostDelegate* delegate) { | 143 internal::NativeMenuHostDelegate* delegate) { |
| 146 return new MenuHostGtk(delegate); | 144 return new MenuHostGtk(delegate); |
| 147 } | 145 } |
| 148 | 146 |
| 149 } // namespace views | 147 } // namespace views |
| OLD | NEW |