| 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/widget/native_widget_gtk.h" | 5 #include "views/widget/native_widget_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 #include <X11/extensions/shape.h> | 9 #include <X11/extensions/shape.h> |
| 10 #include <X11/Xatom.h> | 10 #include <X11/Xatom.h> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "views/views_delegate.h" | 35 #include "views/views_delegate.h" |
| 36 #include "views/widget/drop_target_gtk.h" | 36 #include "views/widget/drop_target_gtk.h" |
| 37 #include "views/widget/gtk_views_fixed.h" | 37 #include "views/widget/gtk_views_fixed.h" |
| 38 #include "views/widget/gtk_views_window.h" | 38 #include "views/widget/gtk_views_window.h" |
| 39 #include "views/widget/native_widget_views.h" | 39 #include "views/widget/native_widget_views.h" |
| 40 #include "views/widget/root_view.h" | 40 #include "views/widget/root_view.h" |
| 41 #include "views/widget/widget_delegate.h" | 41 #include "views/widget/widget_delegate.h" |
| 42 #include "views/window/hit_test.h" | 42 #include "views/window/hit_test.h" |
| 43 | 43 |
| 44 #if defined(TOUCH_UI) | 44 #if defined(TOUCH_UI) |
| 45 #include "ui/base/touchui/touch_factory.h" |
| 45 #include "views/widget/tooltip_manager_views.h" | 46 #include "views/widget/tooltip_manager_views.h" |
| 46 #include "views/touchui/touch_factory.h" | |
| 47 #else | 47 #else |
| 48 #include "views/widget/tooltip_manager_gtk.h" | 48 #include "views/widget/tooltip_manager_gtk.h" |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 #if defined(HAVE_IBUS) | 51 #if defined(HAVE_IBUS) |
| 52 #include "views/ime/input_method_ibus.h" | 52 #include "views/ime/input_method_ibus.h" |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 using ui::OSExchangeData; | 55 using ui::OSExchangeData; |
| 56 using ui::OSExchangeDataProviderGtk; | 56 using ui::OSExchangeDataProviderGtk; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 should_handle_menu_key_release_(false), | 373 should_handle_menu_key_release_(false), |
| 374 dragged_view_(NULL), | 374 dragged_view_(NULL), |
| 375 painted_(false), | 375 painted_(false), |
| 376 has_pointer_grab_(false), | 376 has_pointer_grab_(false), |
| 377 has_keyboard_grab_(false), | 377 has_keyboard_grab_(false), |
| 378 grab_notify_signal_id_(0), | 378 grab_notify_signal_id_(0), |
| 379 is_menu_(false) { | 379 is_menu_(false) { |
| 380 #if defined(TOUCH_UI) | 380 #if defined(TOUCH_UI) |
| 381 // Make sure the touch factory is initialized so that it can setup XInput2 for | 381 // Make sure the touch factory is initialized so that it can setup XInput2 for |
| 382 // the widget. | 382 // the widget. |
| 383 TouchFactory::GetInstance(); | 383 ui::TouchFactory::GetInstance(); |
| 384 #endif | 384 #endif |
| 385 static bool installed_message_loop_observer = false; | 385 static bool installed_message_loop_observer = false; |
| 386 if (!installed_message_loop_observer) { | 386 if (!installed_message_loop_observer) { |
| 387 installed_message_loop_observer = true; | 387 installed_message_loop_observer = true; |
| 388 MessageLoopForUI* loop = MessageLoopForUI::current(); | 388 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 389 if (loop) | 389 if (loop) |
| 390 loop->AddObserver(DropObserver::GetInstance()); | 390 loop->AddObserver(DropObserver::GetInstance()); |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 | 393 |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 NULL, NULL, GDK_CURRENT_TIME); | 919 NULL, NULL, GDK_CURRENT_TIME); |
| 920 // NOTE: technically grab may fail. We may want to try and continue on in | 920 // NOTE: technically grab may fail. We may want to try and continue on in |
| 921 // that case. | 921 // that case. |
| 922 DCHECK_EQ(GDK_GRAB_SUCCESS, pointer_grab_status); | 922 DCHECK_EQ(GDK_GRAB_SUCCESS, pointer_grab_status); |
| 923 has_pointer_grab_ = pointer_grab_status == GDK_GRAB_SUCCESS; | 923 has_pointer_grab_ = pointer_grab_status == GDK_GRAB_SUCCESS; |
| 924 | 924 |
| 925 #if defined(TOUCH_UI) | 925 #if defined(TOUCH_UI) |
| 926 ::Window window = GDK_WINDOW_XID(window_contents()->window); | 926 ::Window window = GDK_WINDOW_XID(window_contents()->window); |
| 927 Display* display = GDK_WINDOW_XDISPLAY(window_contents()->window); | 927 Display* display = GDK_WINDOW_XDISPLAY(window_contents()->window); |
| 928 bool xi2grab = | 928 bool xi2grab = |
| 929 TouchFactory::GetInstance()->GrabTouchDevices(display, window); | 929 ui::TouchFactory::GetInstance()->GrabTouchDevices(display, window); |
| 930 // xi2grab should always succeed if has_pointer_grab_ succeeded. | 930 // xi2grab should always succeed if has_pointer_grab_ succeeded. |
| 931 DCHECK(xi2grab); | 931 DCHECK(xi2grab); |
| 932 has_pointer_grab_ = has_pointer_grab_ && xi2grab; | 932 has_pointer_grab_ = has_pointer_grab_ && xi2grab; |
| 933 #endif | 933 #endif |
| 934 } | 934 } |
| 935 } | 935 } |
| 936 | 936 |
| 937 void NativeWidgetGtk::ReleaseMouseCapture() { | 937 void NativeWidgetGtk::ReleaseMouseCapture() { |
| 938 bool delegate_lost_capture = HasMouseCapture(); | 938 bool delegate_lost_capture = HasMouseCapture(); |
| 939 if (GTK_WIDGET_HAS_GRAB(window_contents_)) | 939 if (GTK_WIDGET_HAS_GRAB(window_contents_)) |
| 940 gtk_grab_remove(window_contents_); | 940 gtk_grab_remove(window_contents_); |
| 941 if (grab_notify_signal_id_) { | 941 if (grab_notify_signal_id_) { |
| 942 g_signal_handler_disconnect(window_contents_, grab_notify_signal_id_); | 942 g_signal_handler_disconnect(window_contents_, grab_notify_signal_id_); |
| 943 grab_notify_signal_id_ = 0; | 943 grab_notify_signal_id_ = 0; |
| 944 } | 944 } |
| 945 if (has_pointer_grab_) { | 945 if (has_pointer_grab_) { |
| 946 has_pointer_grab_ = false; | 946 has_pointer_grab_ = false; |
| 947 gdk_pointer_ungrab(GDK_CURRENT_TIME); | 947 gdk_pointer_ungrab(GDK_CURRENT_TIME); |
| 948 #if defined(TOUCH_UI) | 948 #if defined(TOUCH_UI) |
| 949 TouchFactory::GetInstance()->UngrabTouchDevices( | 949 ui::TouchFactory::GetInstance()->UngrabTouchDevices( |
| 950 GDK_WINDOW_XDISPLAY(window_contents()->window)); | 950 GDK_WINDOW_XDISPLAY(window_contents()->window)); |
| 951 #endif | 951 #endif |
| 952 } | 952 } |
| 953 if (delegate_lost_capture) | 953 if (delegate_lost_capture) |
| 954 delegate_->OnMouseCaptureLost(); | 954 delegate_->OnMouseCaptureLost(); |
| 955 } | 955 } |
| 956 | 956 |
| 957 bool NativeWidgetGtk::HasMouseCapture() const { | 957 bool NativeWidgetGtk::HasMouseCapture() const { |
| 958 return GTK_WIDGET_HAS_GRAB(window_contents_) || has_pointer_grab_; | 958 return GTK_WIDGET_HAS_GRAB(window_contents_) || has_pointer_grab_; |
| 959 } | 959 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 // 3) If it's never painted before. The first expose event will | 1294 // 3) If it's never painted before. The first expose event will |
| 1295 // paint the area that has to be painted. | 1295 // paint the area that has to be painted. |
| 1296 if (widget_ && GTK_WIDGET_DRAWABLE(widget_) && painted_) { | 1296 if (widget_ && GTK_WIDGET_DRAWABLE(widget_) && painted_) { |
| 1297 gtk_widget_queue_draw_area(widget_, rect.x(), rect.y(), rect.width(), | 1297 gtk_widget_queue_draw_area(widget_, rect.x(), rect.y(), rect.width(), |
| 1298 rect.height()); | 1298 rect.height()); |
| 1299 } | 1299 } |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 void NativeWidgetGtk::SetCursor(gfx::NativeCursor cursor) { | 1302 void NativeWidgetGtk::SetCursor(gfx::NativeCursor cursor) { |
| 1303 #if defined(TOUCH_UI) | 1303 #if defined(TOUCH_UI) |
| 1304 if (TouchFactory::GetInstance()->keep_mouse_cursor()) | 1304 if (ui::TouchFactory::GetInstance()->keep_mouse_cursor()) |
| 1305 cursor = gfx::GetCursor(GDK_ARROW); | 1305 cursor = gfx::GetCursor(GDK_ARROW); |
| 1306 else if (!TouchFactory::GetInstance()->is_cursor_visible()) | 1306 else if (!ui::TouchFactory::GetInstance()->is_cursor_visible()) |
| 1307 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); | 1307 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); |
| 1308 #endif | 1308 #endif |
| 1309 // |window_contents_| is placed on top of |widget_|. So the cursor needs to be | 1309 // |window_contents_| is placed on top of |widget_|. So the cursor needs to be |
| 1310 // set on |window_contents_| instead of |widget_|. | 1310 // set on |window_contents_| instead of |widget_|. |
| 1311 if (window_contents_) | 1311 if (window_contents_) |
| 1312 gdk_window_set_cursor(window_contents_->window, cursor); | 1312 gdk_window_set_cursor(window_contents_->window, cursor); |
| 1313 } | 1313 } |
| 1314 | 1314 |
| 1315 void NativeWidgetGtk::ClearNativeFocus() { | 1315 void NativeWidgetGtk::ClearNativeFocus() { |
| 1316 DCHECK(!child_); | 1316 DCHECK(!child_); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 has_pointer_grab_ = false; | 1735 has_pointer_grab_ = false; |
| 1736 if (has_keyboard_grab_) { | 1736 if (has_keyboard_grab_) { |
| 1737 has_keyboard_grab_ = false; | 1737 has_keyboard_grab_ = false; |
| 1738 gdk_keyboard_ungrab(GDK_CURRENT_TIME); | 1738 gdk_keyboard_ungrab(GDK_CURRENT_TIME); |
| 1739 } | 1739 } |
| 1740 delegate_->OnMouseCaptureLost(); | 1740 delegate_->OnMouseCaptureLost(); |
| 1741 } | 1741 } |
| 1742 ReleaseMouseCapture(); | 1742 ReleaseMouseCapture(); |
| 1743 | 1743 |
| 1744 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) | 1744 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) |
| 1745 TouchFactory::GetInstance()->UngrabTouchDevices( | 1745 ui::TouchFactory::GetInstance()->UngrabTouchDevices( |
| 1746 GDK_WINDOW_XDISPLAY(window_contents()->window)); | 1746 GDK_WINDOW_XDISPLAY(window_contents()->window)); |
| 1747 #endif | 1747 #endif |
| 1748 return false; // To let other widgets get the event. | 1748 return false; // To let other widgets get the event. |
| 1749 } | 1749 } |
| 1750 | 1750 |
| 1751 void NativeWidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { | 1751 void NativeWidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { |
| 1752 // Sent when gtk_grab_add changes. | 1752 // Sent when gtk_grab_add changes. |
| 1753 if (!window_contents_) | 1753 if (!window_contents_) |
| 1754 return; // Grab broke after window destroyed, don't try processing it. | 1754 return; // Grab broke after window destroyed, don't try processing it. |
| 1755 if (!was_grabbed) // Indicates we've been shadowed (lost grab). | 1755 if (!was_grabbed) // Indicates we've been shadowed (lost grab). |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2262 button_pressed = event->type == GDK_BUTTON_PRESS || | 2262 button_pressed = event->type == GDK_BUTTON_PRESS || |
| 2263 event->type == GDK_2BUTTON_PRESS || | 2263 event->type == GDK_2BUTTON_PRESS || |
| 2264 event->type == GDK_3BUTTON_PRESS; | 2264 event->type == GDK_3BUTTON_PRESS; |
| 2265 gdk_event_free(event); | 2265 gdk_event_free(event); |
| 2266 } | 2266 } |
| 2267 return button_pressed; | 2267 return button_pressed; |
| 2268 } | 2268 } |
| 2269 | 2269 |
| 2270 } // namespace internal | 2270 } // namespace internal |
| 2271 } // namespace views | 2271 } // namespace views |
| OLD | NEW |