| 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" | |
| 29 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 30 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 29 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 31 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 30 #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" | |
| 34 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| 35 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 36 #include "ui/base/gtk/gtk_compat.h" | 33 #include "ui/base/gtk/gtk_compat.h" |
| 37 #include "ui/base/gtk/gtk_hig_constants.h" | 34 #include "ui/base/gtk/gtk_hig_constants.h" |
| 38 #include "ui/base/gtk/gtk_screen_util.h" | 35 #include "ui/base/gtk/gtk_screen_util.h" |
| 39 #include "ui/base/gtk/menu_label_accelerator_util.h" | 36 #include "ui/base/gtk/menu_label_accelerator_util.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 42 #include "ui/base/text/text_elider.h" | 39 #include "ui/base/text/text_elider.h" |
| 43 #include "ui/base/x/x11_util.h" | 40 #include "ui/base/x/x11_util.h" |
| 44 #include "ui/gfx/image/cairo_cached_surface.h" | 41 #include "ui/gfx/image/cairo_cached_surface.h" |
| 45 #include "ui/gfx/image/image.h" | 42 #include "ui/gfx/image/image.h" |
| 46 #include "ui/gfx/pango_util.h" | 43 #include "ui/gfx/pango_util.h" |
| 47 | 44 |
| 48 // These conflict with base/tracked_objects.h, so need to come last. | 45 // These conflict with base/tracked_objects.h, so need to come last. |
| 49 #include <gdk/gdkx.h> // NOLINT | 46 #include <gdk/gdkx.h> // NOLINT |
| 50 | 47 |
| 51 using content::RenderWidgetHost; | |
| 52 using content::WebContents; | |
| 53 | |
| 54 namespace { | 48 namespace { |
| 55 | 49 |
| 56 #if defined(GOOGLE_CHROME_BUILD) | 50 #if defined(GOOGLE_CHROME_BUILD) |
| 57 static const char* kIconName = "google-chrome"; | 51 static const char* kIconName = "google-chrome"; |
| 58 #else | 52 #else |
| 59 static const char* kIconName = "chromium-browser"; | 53 static const char* kIconName = "chromium-browser"; |
| 60 #endif | 54 #endif |
| 61 | 55 |
| 62 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; | 56 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; |
| 63 | 57 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 for (GList* item = children; item; item = item->next) { | 265 for (GList* item = children; item; item = item->next) { |
| 272 gtk_container_propagate_expose(GTK_CONTAINER(widget), | 266 gtk_container_propagate_expose(GTK_CONTAINER(widget), |
| 273 GTK_WIDGET(item->data), | 267 GTK_WIDGET(item->data), |
| 274 event); | 268 event); |
| 275 } | 269 } |
| 276 g_list_free(children); | 270 g_list_free(children); |
| 277 | 271 |
| 278 return TRUE; | 272 return TRUE; |
| 279 } | 273 } |
| 280 | 274 |
| 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 | 275 } // namespace |
| 292 | 276 |
| 293 namespace gtk_util { | 277 namespace gtk_util { |
| 294 | 278 |
| 295 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels, | 279 GtkWidget* CreateLabeledControlsGroup(std::vector<GtkWidget*>* labels, |
| 296 const char* text, ...) { | 280 const char* text, ...) { |
| 297 va_list ap; | 281 va_list ap; |
| 298 va_start(ap, text); | 282 va_start(ap, text); |
| 299 GtkWidget* table = gtk_table_new(0, 2, FALSE); | 283 GtkWidget* table = gtk_table_new(0, 2, FALSE); |
| 300 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); | 284 gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing); |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 void ApplyMessageDialogQuirks(GtkWidget* dialog) { | 985 void ApplyMessageDialogQuirks(GtkWidget* dialog) { |
| 1002 if (gtk_window_get_modal(GTK_WINDOW(dialog))) { | 986 if (gtk_window_get_modal(GTK_WINDOW(dialog))) { |
| 1003 // Work around a KDE 3 window manager bug. | 987 // Work around a KDE 3 window manager bug. |
| 1004 scoped_ptr<base::Environment> env(base::Environment::Create()); | 988 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 1005 if (base::nix::DESKTOP_ENVIRONMENT_KDE3 == | 989 if (base::nix::DESKTOP_ENVIRONMENT_KDE3 == |
| 1006 base::nix::GetDesktopEnvironment(env.get())) | 990 base::nix::GetDesktopEnvironment(env.get())) |
| 1007 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); | 991 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); |
| 1008 } | 992 } |
| 1009 } | 993 } |
| 1010 | 994 |
| 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 | |
| 1045 } // namespace gtk_util | 995 } // namespace gtk_util |
| OLD | NEW |