OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/gtk/gtk_window_util.h" | |
6 | |
7 #include <dlfcn.h> | |
8 #include "content/public/browser/render_view_host.h" | |
9 #include "content/public/browser/web_contents.h" | |
10 | |
11 using content::RenderWidgetHost; | |
12 using content::WebContents; | |
13 | |
14 namespace gtk_window_util { | |
15 | |
16 // Performs Cut/Copy/Paste operation on the |window|. | |
17 // If the current render view is focused, then just call the specified |method| | |
18 // against the current render view host, otherwise emit the specified |signal| | |
19 // against the focused widget. | |
20 // TODO(suzhe): This approach does not work for plugins. | |
21 void DoCutCopyPaste(GtkWindow* window, | |
22 WebContents* web_contents, | |
23 void (RenderWidgetHost::*method)(), | |
24 const char* signal) { | |
25 GtkWidget* widget = gtk_window_get_focus(window); | |
26 if (widget == NULL) | |
27 return; // Do nothing if no focused widget. | |
28 | |
29 if (web_contents && widget == web_contents->GetContentNativeView()) { | |
30 (web_contents->GetRenderViewHost()->*method)(); | |
31 } else { | |
32 guint id; | |
33 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) | |
34 g_signal_emit(widget, id, 0); | |
35 } | |
36 } | |
37 | |
38 void DoCut(GtkWindow* window, WebContents* web_contents) { | |
39 DoCutCopyPaste(window, web_contents, | |
40 &RenderWidgetHost::Cut, "cut-clipboard"); | |
41 } | |
42 | |
43 void DoCopy(GtkWindow* window, WebContents* web_contents) { | |
44 DoCutCopyPaste(window, web_contents, | |
45 &RenderWidgetHost::Copy, "copy-clipboard"); | |
46 } | |
47 | |
48 void DoPaste(GtkWindow* window, WebContents* web_contents) { | |
49 DoCutCopyPaste(window, web_contents, | |
50 &RenderWidgetHost::Paste, "paste-clipboard"); | |
51 } | |
52 | |
53 // Ubuntu patches their version of GTK+ so that there is always a | |
54 // gripper in the bottom right corner of the window. We dynamically | |
55 // look up this symbol because it's a non-standard Ubuntu extension to | |
56 // GTK+. We always need to disable this feature since we can't | |
57 // communicate this to WebKit easily. | |
58 typedef void (*gtk_window_set_has_resize_grip_func)(GtkWindow*, gboolean); | |
59 gtk_window_set_has_resize_grip_func gtk_window_set_has_resize_grip_sym; | |
60 | |
61 void DisableResizeGrip(GtkWindow* window) { | |
62 static bool resize_grip_looked_up = false; | |
63 if (!resize_grip_looked_up) { | |
64 resize_grip_looked_up = true; | |
65 gtk_window_set_has_resize_grip_sym = | |
66 reinterpret_cast<gtk_window_set_has_resize_grip_func>( | |
67 dlsym(NULL, "gtk_window_set_has_resize_grip")); | |
68 } | |
69 if (gtk_window_set_has_resize_grip_sym) | |
70 gtk_window_set_has_resize_grip_sym(window, FALSE); | |
71 } | |
72 | |
73 GdkCursorType GdkWindowEdgeToGdkCursorType(GdkWindowEdge edge) { | |
74 switch (edge) { | |
75 case GDK_WINDOW_EDGE_NORTH_WEST: | |
76 return GDK_TOP_LEFT_CORNER; | |
77 case GDK_WINDOW_EDGE_NORTH: | |
78 return GDK_TOP_SIDE; | |
79 case GDK_WINDOW_EDGE_NORTH_EAST: | |
80 return GDK_TOP_RIGHT_CORNER; | |
81 case GDK_WINDOW_EDGE_WEST: | |
82 return GDK_LEFT_SIDE; | |
83 case GDK_WINDOW_EDGE_EAST: | |
84 return GDK_RIGHT_SIDE; | |
85 case GDK_WINDOW_EDGE_SOUTH_WEST: | |
86 return GDK_BOTTOM_LEFT_CORNER; | |
87 case GDK_WINDOW_EDGE_SOUTH: | |
88 return GDK_BOTTOM_SIDE; | |
89 case GDK_WINDOW_EDGE_SOUTH_EAST: | |
90 return GDK_BOTTOM_RIGHT_CORNER; | |
91 default: | |
92 NOTREACHED(); | |
93 } | |
94 return GDK_LAST_CURSOR; | |
95 } | |
96 | |
97 } // namespace gtk_window_util | |
OLD | NEW |