OLD | NEW |
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 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cstdarg> | 10 #include <cstdarg> |
11 #include <map> | 11 #include <map> |
12 | 12 |
13 #include "base/environment.h" | 13 #include "base/environment.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/nix/xdg_util.h" | 16 #include "base/nix/xdg_util.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 19 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
20 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 20 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
21 #include "chrome/browser/autocomplete/autocomplete_match.h" | 21 #include "chrome/browser/autocomplete/autocomplete_match.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_info_cache.h" | 24 #include "chrome/browser/profiles/profile_info_cache.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/browser/ui/browser_tabstrip.h" |
28 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
29 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 30 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
30 #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" |
| 33 #include "content/public/browser/web_contents.h" |
31 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
32 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
33 #include "ui/base/gtk/gtk_compat.h" | 36 #include "ui/base/gtk/gtk_compat.h" |
34 #include "ui/base/gtk/gtk_hig_constants.h" | 37 #include "ui/base/gtk/gtk_hig_constants.h" |
35 #include "ui/base/gtk/gtk_screen_util.h" | 38 #include "ui/base/gtk/gtk_screen_util.h" |
36 #include "ui/base/gtk/menu_label_accelerator_util.h" | 39 #include "ui/base/gtk/menu_label_accelerator_util.h" |
37 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/base/text/text_elider.h" | 42 #include "ui/base/text/text_elider.h" |
40 #include "ui/base/x/x11_util.h" | 43 #include "ui/base/x/x11_util.h" |
41 #include "ui/gfx/image/cairo_cached_surface.h" | 44 #include "ui/gfx/image/cairo_cached_surface.h" |
42 #include "ui/gfx/image/image.h" | 45 #include "ui/gfx/image/image.h" |
43 #include "ui/gfx/pango_util.h" | 46 #include "ui/gfx/pango_util.h" |
44 | 47 |
45 // These conflict with base/tracked_objects.h, so need to come last. | 48 // These conflict with base/tracked_objects.h, so need to come last. |
46 #include <gdk/gdkx.h> // NOLINT | 49 #include <gdk/gdkx.h> // NOLINT |
47 | 50 |
| 51 using content::RenderWidgetHost; |
| 52 using content::WebContents; |
| 53 |
48 namespace { | 54 namespace { |
49 | 55 |
50 #if defined(GOOGLE_CHROME_BUILD) | 56 #if defined(GOOGLE_CHROME_BUILD) |
51 static const char* kIconName = "google-chrome"; | 57 static const char* kIconName = "google-chrome"; |
52 #else | 58 #else |
53 static const char* kIconName = "chromium-browser"; | 59 static const char* kIconName = "chromium-browser"; |
54 #endif | 60 #endif |
55 | 61 |
56 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; | 62 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; |
57 | 63 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 for (GList* item = children; item; item = item->next) { | 271 for (GList* item = children; item; item = item->next) { |
266 gtk_container_propagate_expose(GTK_CONTAINER(widget), | 272 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
267 GTK_WIDGET(item->data), | 273 GTK_WIDGET(item->data), |
268 event); | 274 event); |
269 } | 275 } |
270 g_list_free(children); | 276 g_list_free(children); |
271 | 277 |
272 return TRUE; | 278 return TRUE; |
273 } | 279 } |
274 | 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 |
275 } // namespace | 291 } // namespace |
276 | 292 |
277 namespace gtk_util { | 293 namespace gtk_util { |
278 | 294 |
279 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels, | 295 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels, |
280 const char* text, ...) { | 296 const char* text, ...) { |
281 va_list ap; | 297 va_list ap; |
282 va_start(ap, text); | 298 va_start(ap, text); |
283 GtkWidget* table = gtk_table_new(0, 2, FALSE); | 299 GtkWidget* table = gtk_table_new(0, 2, FALSE); |
284 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); | 300 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 void ApplyMessageDialogQuirks(GtkWidget* dialog) { | 1001 void ApplyMessageDialogQuirks(GtkWidget* dialog) { |
986 if (gtk_window_get_modal(GTK_WINDOW(dialog))) { | 1002 if (gtk_window_get_modal(GTK_WINDOW(dialog))) { |
987 // Work around a KDE 3 window manager bug. | 1003 // Work around a KDE 3 window manager bug. |
988 scoped_ptr<base::Environment> env(base::Environment::Create()); | 1004 scoped_ptr<base::Environment> env(base::Environment::Create()); |
989 if (base::nix::DESKTOP_ENVIRONMENT_KDE3 == | 1005 if (base::nix::DESKTOP_ENVIRONMENT_KDE3 == |
990 base::nix::GetDesktopEnvironment(env.get())) | 1006 base::nix::GetDesktopEnvironment(env.get())) |
991 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); | 1007 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); |
992 } | 1008 } |
993 } | 1009 } |
994 | 1010 |
| 1011 // Performs Cut/Copy/Paste operation on the |window|. |
| 1012 // 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| |
| 1014 // against the focused widget. |
| 1015 // TODO(suzhe): This approach does not work for plugins. |
| 1016 void DoCutCopyPaste(BrowserWindow* window, |
| 1017 void (RenderWidgetHost::*method)(), |
| 1018 const char* signal) { |
| 1019 GtkWidget* widget = GetBrowserWindowFocusedWidget(window); |
| 1020 if (widget == NULL) |
| 1021 return; // Do nothing if no focused widget. |
| 1022 |
| 1023 WebContents* current_tab = GetBrowserWindowSelectedWebContents(window); |
| 1024 if (current_tab && widget == current_tab->GetContentNativeView()) { |
| 1025 (current_tab->GetRenderViewHost()->*method)(); |
| 1026 } else { |
| 1027 guint id; |
| 1028 if ((id = g_signal_lookup(signal, G_OBJECT_TYPE(widget))) != 0) |
| 1029 g_signal_emit(widget, id, 0); |
| 1030 } |
| 1031 } |
| 1032 |
| 1033 void DoCut(BrowserWindow* window) { |
| 1034 DoCutCopyPaste(window, &RenderWidgetHost::Cut, "cut-clipboard"); |
| 1035 } |
| 1036 |
| 1037 void DoCopy(BrowserWindow* window) { |
| 1038 DoCutCopyPaste(window, &RenderWidgetHost::Copy, "copy-clipboard"); |
| 1039 } |
| 1040 |
| 1041 void DoPaste(BrowserWindow* window) { |
| 1042 DoCutCopyPaste(window, &RenderWidgetHost::Paste, "paste-clipboard"); |
| 1043 } |
| 1044 |
995 } // namespace gtk_util | 1045 } // namespace gtk_util |
OLD | NEW |