Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: chrome/browser/ui/gtk/gtk_util.cc

Issue 10831226: Panels refactor: Support browserless panels on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ui/gtk/gtk_util.h" 5 #include "chrome/browser/ui/gtk/gtk_util.h"
6 6
7 #include <cairo/cairo.h> 7 #include <cairo/cairo.h>
8 #include <dlfcn.h>
8 9
9 #include <algorithm> 10 #include <algorithm>
10 #include <cstdarg> 11 #include <cstdarg>
11 #include <map> 12 #include <map>
12 13
13 #include "base/environment.h" 14 #include "base/environment.h"
14 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/nix/xdg_util.h" 17 #include "base/nix/xdg_util.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 20 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
20 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 21 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
21 #include "chrome/browser/autocomplete/autocomplete_match.h" 22 #include "chrome/browser/autocomplete/autocomplete_match.h"
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_info_cache.h" 25 #include "chrome/browser/profiles/profile_info_cache.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_list.h" 28 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/gtk/browser_window_gtk.h" 30 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
31 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 31 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
32 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
35 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
36 #include "ui/base/gtk/gtk_compat.h" 36 #include "ui/base/gtk/gtk_compat.h"
37 #include "ui/base/gtk/gtk_hig_constants.h" 37 #include "ui/base/gtk/gtk_hig_constants.h"
38 #include "ui/base/gtk/gtk_screen_util.h" 38 #include "ui/base/gtk/gtk_screen_util.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 for (GList* item = children; item; item = item->next) { 271 for (GList* item = children; item; item = item->next) {
272 gtk_container_propagate_expose(GTK_CONTAINER(widget), 272 gtk_container_propagate_expose(GTK_CONTAINER(widget),
273 GTK_WIDGET(item->data), 273 GTK_WIDGET(item->data),
274 event); 274 event);
275 } 275 }
276 g_list_free(children); 276 g_list_free(children);
277 277
278 return TRUE; 278 return TRUE;
279 } 279 }
280 280
281 WebContents* GetBrowserWindowSelectedWebContents(BrowserWindow* window) {
282 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>(
283 window);
284 return chrome::GetActiveWebContents(browser_window->browser());
285 }
286
287 GtkWidget* GetBrowserWindowFocusedWidget(BrowserWindow* window) {
288 return gtk_window_get_focus(window->GetNativeWindow());
289 }
290
291 } // namespace 281 } // namespace
292 282
293 namespace gtk_util { 283 namespace gtk_util {
294 284
295 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels, 285 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels,
296 const char* text, ...) { 286 const char* text, ...) {
297 va_list ap; 287 va_list ap;
298 va_start(ap, text); 288 va_start(ap, text);
299 GtkWidget* table = gtk_table_new(0, 2, FALSE); 289 GtkWidget* table = gtk_table_new(0, 2, FALSE);
300 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); 290 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing);
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 base::nix::GetDesktopEnvironment(env.get())) 996 base::nix::GetDesktopEnvironment(env.get()))
1007 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); 997 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
1008 } 998 }
1009 } 999 }
1010 1000
1011 // Performs Cut/Copy/Paste operation on the |window|. 1001 // Performs Cut/Copy/Paste operation on the |window|.
1012 // If the current render view is focused, then just call the specified |method| 1002 // If the current render view is focused, then just call the specified |method|
1013 // against the current render view host, otherwise emit the specified |signal| 1003 // against the current render view host, otherwise emit the specified |signal|
1014 // against the focused widget. 1004 // against the focused widget.
1015 // TODO(suzhe): This approach does not work for plugins. 1005 // TODO(suzhe): This approach does not work for plugins.
1016 void DoCutCopyPaste(BrowserWindow* window, 1006 void DoCutCopyPaste(GtkWindow* window,
1007 WebContents* web_contents,
1017 void (RenderWidgetHost::*method)(), 1008 void (RenderWidgetHost::*method)(),
1018 const char* signal) { 1009 const char* signal) {
1019 GtkWidget* widget = GetBrowserWindowFocusedWidget(window); 1010 GtkWidget* widget = gtk_window_get_focus(window);
1020 if (widget == NULL) 1011 if (widget == NULL)
1021 return; // Do nothing if no focused widget. 1012 return; // Do nothing if no focused widget.
1022 1013
1023 WebContents* current_tab = GetBrowserWindowSelectedWebContents(window); 1014 if (web_contents && widget == web_contents->GetContentNativeView()) {
1024 if (current_tab && widget == current_tab->GetContentNativeView()) { 1015 (web_contents->GetRenderViewHost()->*method)();
1025 (current_tab->GetRenderViewHost()->*method)();
1026 } else { 1016 } else {
1027 guint id; 1017 guint id;
1028 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) 1018 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0)
1029 g_signal_emit(widget, id, 0); 1019 g_signal_emit(widget, id, 0);
1030 } 1020 }
1031 } 1021 }
1032 1022
1033 void DoCut(BrowserWindow* window) { 1023 void DoCut(GtkWindow* window, WebContents* web_contents) {
1034 DoCutCopyPaste(window, &RenderWidgetHost::Cut, "cut-clipboard"); 1024 DoCutCopyPaste(window, web_contents,
1025 &RenderWidgetHost::Cut, "cut-clipboard");
1035 } 1026 }
1036 1027
1037 void DoCopy(BrowserWindow* window) { 1028 void DoCopy(GtkWindow* window, WebContents* web_contents) {
1038 DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard"); 1029 DoCutCopyPaste(window, web_contents,
1030 &RenderWidgetHost::Copy, "copy-clipboard");
1039 } 1031 }
1040 1032
1041 void DoPaste(BrowserWindow* window) { 1033 void DoPaste(GtkWindow* window, WebContents* web_contents) {
1042 DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard"); 1034 DoCutCopyPaste(window, web_contents,
1035 &RenderWidgetHost::Paste, "paste-clipboard");
1036 }
1037
1038 // Ubuntu patches their verrsion of GTK+ so that there is always a
Evan Stade 2012/08/10 01:52:30 sp: verrsion
jennb 2012/08/10 18:45:42 Done.
1039 // gripper in the bottom right corner of the window. We dynamically
1040 // look up this symbol because it's a non-standard Ubuntu extension to
1041 // GTK+. We always need to disable this feature since we can't
1042 // communicate this to WebKit easily.
1043 typedef void (*gtk_window_set_has_resize_grip_func)(GtkWindow*, gboolean);
1044 gtk_window_set_has_resize_grip_func gtk_window_set_has_resize_grip_sym;
1045
1046 void DisableResizeGrip(GtkWindow* window) {
1047 static bool resize_grip_looked_up = false;
1048 if (!resize_grip_looked_up) {
1049 resize_grip_looked_up = true;
1050 gtk_window_set_has_resize_grip_sym =
1051 reinterpret_cast<gtk_window_set_has_resize_grip_func>(
1052 dlsym(NULL, "gtk_window_set_has_resize_grip"));
1053 }
1054 if (gtk_window_set_has_resize_grip_sym)
1055 gtk_window_set_has_resize_grip_sym(window, FALSE);
1056 }
1057
1058 GdkCursorType GdkWindowEdgeToGdkCursorType(GdkWindowEdge edge) {
1059 switch (edge) {
1060 case GDK_WINDOW_EDGE_NORTH_WEST:
1061 return GDK_TOP_LEFT_CORNER;
1062 case GDK_WINDOW_EDGE_NORTH:
1063 return GDK_TOP_SIDE;
1064 case GDK_WINDOW_EDGE_NORTH_EAST:
1065 return GDK_TOP_RIGHT_CORNER;
1066 case GDK_WINDOW_EDGE_WEST:
1067 return GDK_LEFT_SIDE;
1068 case GDK_WINDOW_EDGE_EAST:
1069 return GDK_RIGHT_SIDE;
1070 case GDK_WINDOW_EDGE_SOUTH_WEST:
1071 return GDK_BOTTOM_LEFT_CORNER;
1072 case GDK_WINDOW_EDGE_SOUTH:
1073 return GDK_BOTTOM_SIDE;
1074 case GDK_WINDOW_EDGE_SOUTH_EAST:
1075 return GDK_BOTTOM_RIGHT_CORNER;
1076 default:
1077 NOTREACHED();
1078 }
1079 return GDK_LAST_CURSOR;
1043 } 1080 }
1044 1081
1045 } // namespace gtk_util 1082 } // namespace gtk_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698