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/touch/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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 // 3) If it's never painted before. The first expose event will | 1303 // 3) If it's never painted before. The first expose event will |
1304 // paint the area that has to be painted. | 1304 // paint the area that has to be painted. |
1305 if (widget_ && GTK_WIDGET_DRAWABLE(widget_) && painted_) { | 1305 if (widget_ && GTK_WIDGET_DRAWABLE(widget_) && painted_) { |
1306 gtk_widget_queue_draw_area(widget_, rect.x(), rect.y(), rect.width(), | 1306 gtk_widget_queue_draw_area(widget_, rect.x(), rect.y(), rect.width(), |
1307 rect.height()); | 1307 rect.height()); |
1308 } | 1308 } |
1309 } | 1309 } |
1310 | 1310 |
1311 void NativeWidgetGtk::SetCursor(gfx::NativeCursor cursor) { | 1311 void NativeWidgetGtk::SetCursor(gfx::NativeCursor cursor) { |
1312 #if defined(TOUCH_UI) | 1312 #if defined(TOUCH_UI) |
1313 if (TouchFactory::GetInstance()->keep_mouse_cursor()) | 1313 if (ui::TouchFactory::GetInstance()->keep_mouse_cursor()) |
1314 cursor = gfx::GetCursor(GDK_ARROW); | 1314 cursor = gfx::GetCursor(GDK_ARROW); |
1315 else if (!TouchFactory::GetInstance()->is_cursor_visible()) | 1315 else if (!ui::TouchFactory::GetInstance()->is_cursor_visible()) |
1316 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); | 1316 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); |
1317 #endif | 1317 #endif |
1318 // |window_contents_| is placed on top of |widget_|. So the cursor needs to be | 1318 // |window_contents_| is placed on top of |widget_|. So the cursor needs to be |
1319 // set on |window_contents_| instead of |widget_|. | 1319 // set on |window_contents_| instead of |widget_|. |
1320 if (window_contents_) | 1320 if (window_contents_) |
1321 gdk_window_set_cursor(window_contents_->window, cursor); | 1321 gdk_window_set_cursor(window_contents_->window, cursor); |
1322 } | 1322 } |
1323 | 1323 |
1324 void NativeWidgetGtk::ClearNativeFocus() { | 1324 void NativeWidgetGtk::ClearNativeFocus() { |
1325 DCHECK(!child_); | 1325 DCHECK(!child_); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 return false; | 1687 return false; |
1688 | 1688 |
1689 // Only top-level Widget should have an InputMethod instance. | 1689 // Only top-level Widget should have an InputMethod instance. |
1690 InputMethod* input_method = GetWidget()->GetInputMethod(); | 1690 InputMethod* input_method = GetWidget()->GetInputMethod(); |
1691 if (input_method) | 1691 if (input_method) |
1692 input_method->OnBlur(); | 1692 input_method->OnBlur(); |
1693 return false; | 1693 return false; |
1694 } | 1694 } |
1695 | 1695 |
1696 gboolean NativeWidgetGtk::OnEventKey(GtkWidget* widget, GdkEventKey* event) { | 1696 gboolean NativeWidgetGtk::OnEventKey(GtkWidget* widget, GdkEventKey* event) { |
1697 KeyEvent key(reinterpret_cast<NativeEvent>(event)); | 1697 KeyEvent key(reinterpret_cast<GdkEvent*>(event)); |
1698 InputMethod* input_method = GetWidget()->GetInputMethod(); | 1698 InputMethod* input_method = GetWidget()->GetInputMethod(); |
1699 if (input_method) | 1699 if (input_method) |
1700 input_method->DispatchKeyEvent(key); | 1700 input_method->DispatchKeyEvent(key); |
1701 else | 1701 else |
1702 DispatchKeyEventPostIME(key); | 1702 DispatchKeyEventPostIME(key); |
1703 | 1703 |
1704 // Returns true to prevent GtkWindow's default key event handler. | 1704 // Returns true to prevent GtkWindow's default key event handler. |
1705 return true; | 1705 return true; |
1706 } | 1706 } |
1707 | 1707 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 has_pointer_grab_ = false; | 1744 has_pointer_grab_ = false; |
1745 if (has_keyboard_grab_) { | 1745 if (has_keyboard_grab_) { |
1746 has_keyboard_grab_ = false; | 1746 has_keyboard_grab_ = false; |
1747 gdk_keyboard_ungrab(GDK_CURRENT_TIME); | 1747 gdk_keyboard_ungrab(GDK_CURRENT_TIME); |
1748 } | 1748 } |
1749 delegate_->OnMouseCaptureLost(); | 1749 delegate_->OnMouseCaptureLost(); |
1750 } | 1750 } |
1751 ReleaseMouseCapture(); | 1751 ReleaseMouseCapture(); |
1752 | 1752 |
1753 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) | 1753 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) |
1754 TouchFactory::GetInstance()->UngrabTouchDevices( | 1754 ui::TouchFactory::GetInstance()->UngrabTouchDevices( |
1755 GDK_WINDOW_XDISPLAY(window_contents()->window)); | 1755 GDK_WINDOW_XDISPLAY(window_contents()->window)); |
1756 #endif | 1756 #endif |
1757 return false; // To let other widgets get the event. | 1757 return false; // To let other widgets get the event. |
1758 } | 1758 } |
1759 | 1759 |
1760 void NativeWidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { | 1760 void NativeWidgetGtk::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { |
1761 // Sent when gtk_grab_add changes. | 1761 // Sent when gtk_grab_add changes. |
1762 if (!window_contents_) | 1762 if (!window_contents_) |
1763 return; // Grab broke after window destroyed, don't try processing it. | 1763 return; // Grab broke after window destroyed, don't try processing it. |
1764 if (!was_grabbed) // Indicates we've been shadowed (lost grab). | 1764 if (!was_grabbed) // Indicates we've been shadowed (lost grab). |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1839 // Send the key event to View hierarchy first. | 1839 // Send the key event to View hierarchy first. |
1840 bool handled = delegate_->OnKeyEvent(key); | 1840 bool handled = delegate_->OnKeyEvent(key); |
1841 | 1841 |
1842 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) | 1842 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) |
1843 return; | 1843 return; |
1844 | 1844 |
1845 // Dispatch the key event to native GtkWidget hierarchy. | 1845 // Dispatch the key event to native GtkWidget hierarchy. |
1846 // To prevent GtkWindow from handling the key event as a keybinding, we need | 1846 // To prevent GtkWindow from handling the key event as a keybinding, we need |
1847 // to bypass GtkWindow's default key event handler and dispatch the event | 1847 // to bypass GtkWindow's default key event handler and dispatch the event |
1848 // here. | 1848 // here. |
1849 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); | 1849 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.gdk_event()); |
1850 if (!handled && event && GTK_IS_WINDOW(widget_)) | 1850 if (!handled && event && GTK_IS_WINDOW(widget_)) |
1851 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event); | 1851 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event); |
1852 | 1852 |
1853 // On Linux, in order to handle VKEY_MENU (Alt) accelerator key correctly and | 1853 // On Linux, in order to handle VKEY_MENU (Alt) accelerator key correctly and |
1854 // avoid issues like: http://crbug.com/40966 and http://crbug.com/49701, we | 1854 // avoid issues like: http://crbug.com/40966 and http://crbug.com/49701, we |
1855 // should only send the key event to the focus manager if it's not handled by | 1855 // should only send the key event to the focus manager if it's not handled by |
1856 // any View or native GtkWidget. | 1856 // any View or native GtkWidget. |
1857 // The flow is different when the focus is in a RenderWidgetHostViewGtk, which | 1857 // The flow is different when the focus is in a RenderWidgetHostViewGtk, which |
1858 // always consumes the key event and send it back to us later by calling | 1858 // always consumes the key event and send it back to us later by calling |
1859 // HandleKeyboardEvent() directly, if it's not handled by webkit. | 1859 // HandleKeyboardEvent() directly, if it's not handled by webkit. |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2271 button_pressed = event->type == GDK_BUTTON_PRESS || | 2271 button_pressed = event->type == GDK_BUTTON_PRESS || |
2272 event->type == GDK_2BUTTON_PRESS || | 2272 event->type == GDK_2BUTTON_PRESS || |
2273 event->type == GDK_3BUTTON_PRESS; | 2273 event->type == GDK_3BUTTON_PRESS; |
2274 gdk_event_free(event); | 2274 gdk_event_free(event); |
2275 } | 2275 } |
2276 return button_pressed; | 2276 return button_pressed; |
2277 } | 2277 } |
2278 | 2278 |
2279 } // namespace internal | 2279 } // namespace internal |
2280 } // namespace views | 2280 } // namespace views |
OLD | NEW |