diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 19:37:29 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-28 19:37:29 +0000 |
commit | 7110c24868971986f9e5cbd22a8dd1e87bda021f (patch) | |
tree | 0d650181d24330c4f72be140224af4a17fed4b51 /chrome | |
parent | cf34891f6a2391419f416356350a542aa4c1cc0f (diff) | |
download | chromium_src-7110c24868971986f9e5cbd22a8dd1e87bda021f.zip chromium_src-7110c24868971986f9e5cbd22a8dd1e87bda021f.tar.gz chromium_src-7110c24868971986f9e5cbd22a8dd1e87bda021f.tar.bz2 |
Cleanup: Get rid of app/gtk_util.h.
* Most functions moved to chrome/browser/gtk/gtk_util.h because they're only
used within chrome/browser.
* BGRAToRGBA() is used within chrome/ and app/ so moved it to base/gtk_util.h.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4170002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64295 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/dom_ui/options/advanced_options_utils_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/extension_install_prompt2_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/first_run_bubble.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_util.cc | 79 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_util.h | 19 | ||||
-rw-r--r-- | chrome/browser/gtk/js_modal_dialog_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/options/advanced_contents_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/options/advanced_page_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/options/content_page_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/options/languages_page_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/options/passwords_page_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/options/url_picker_dialog_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/process_singleton_dialog.cc | 2 | ||||
-rw-r--r-- | chrome/browser/icon_loader_linux.cc | 2 | ||||
-rw-r--r-- | chrome/browser/platform_util_common_linux.cc | 1 |
17 files changed, 97 insertions, 18 deletions
diff --git a/chrome/browser/dom_ui/options/advanced_options_utils_gtk.cc b/chrome/browser/dom_ui/options/advanced_options_utils_gtk.cc index 094701e..66dbe27 100644 --- a/chrome/browser/dom_ui/options/advanced_options_utils_gtk.cc +++ b/chrome/browser/dom_ui/options/advanced_options_utils_gtk.cc @@ -7,7 +7,6 @@ #include "chrome/browser/dom_ui/options/advanced_options_utils.h" #include "app/gtk_signal.h" -#include "app/gtk_util.h" #include "base/file_util.h" #include "base/environment.h" #include "base/process_util.h" diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 2ce9370..c40419f 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -8,7 +8,6 @@ #include <string> -#include "app/gtk_util.h" #include "app/keyboard_codes.h" #include "app/l10n_util.h" #include "base/base_paths.h" diff --git a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc index dbde270..d748622 100644 --- a/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc +++ b/chrome/browser/gtk/create_application_shortcuts_dialog_gtk.cc @@ -6,7 +6,6 @@ #include <string> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/environment.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/gtk/extension_install_prompt2_gtk.cc b/chrome/browser/gtk/extension_install_prompt2_gtk.cc index 6d7008c..9c66c20 100644 --- a/chrome/browser/gtk/extension_install_prompt2_gtk.cc +++ b/chrome/browser/gtk/extension_install_prompt2_gtk.cc @@ -4,7 +4,6 @@ #include <gtk/gtk.h> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/gtk/first_run_bubble.cc b/chrome/browser/gtk/first_run_bubble.cc index fb23e145..6102180 100644 --- a/chrome/browser/gtk/first_run_bubble.cc +++ b/chrome/browser/gtk/first_run_bubble.cc @@ -6,7 +6,6 @@ #include <gtk/gtk.h> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/command_line.h" #include "base/i18n/rtl.h" diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc index c03e5ba..ac45a7d 100644 --- a/chrome/browser/gtk/gtk_util.cc +++ b/chrome/browser/gtk/gtk_util.cc @@ -11,14 +11,16 @@ #include <cstdarg> #include <map> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/x11_util.h" +#include "base/environment.h" #include "base/gtk_util.h" #include "base/i18n/rtl.h" #include "base/linux_util.h" #include "base/logging.h" +#include "base/nix/xdg_util.h" +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_match.h" @@ -81,11 +83,32 @@ gboolean OnMouseButtonReleased(GtkWidget* widget, GdkEventButton* event, return TRUE; } +// Returns the approximate number of characters that can horizontally fit in +// |pixel_width| pixels. +int GetCharacterWidthForPixels(GtkWidget* widget, int pixel_width) { + DCHECK(GTK_WIDGET_REALIZED(widget)) + << " widget must be realized to compute font metrics correctly"; + + PangoContext* context = gtk_widget_create_pango_context(widget); + PangoFontMetrics* metrics = pango_context_get_metrics(context, + widget->style->font_desc, pango_context_get_language(context)); + + // This technique (max of char and digit widths) matches the code in + // gtklabel.c. + int char_width = pixel_width * PANGO_SCALE / + std::max(pango_font_metrics_get_approximate_char_width(metrics), + pango_font_metrics_get_approximate_digit_width(metrics)); + + pango_font_metrics_unref(metrics); + g_object_unref(context); + + return char_width; +} + void OnLabelRealize(GtkWidget* label, gpointer pixel_width) { gtk_label_set_width_chars( GTK_LABEL(label), - gtk_util::GetCharacterWidthForPixels(label, - GPOINTER_TO_INT(pixel_width))); + GetCharacterWidthForPixels(label,GPOINTER_TO_INT(pixel_width))); } // Ownership of |icon_list| is passed to the caller. @@ -225,6 +248,46 @@ GtkWidget* CreateBoldLabel(const std::string& text) { return LeftAlignMisc(label); } +void GetWidgetSizeFromCharacters( + GtkWidget* widget, double width_chars, double height_lines, + int* width, int* height) { + DCHECK(GTK_WIDGET_REALIZED(widget)) + << " widget must be realized to compute font metrics correctly"; + PangoContext* context = gtk_widget_create_pango_context(widget); + PangoFontMetrics* metrics = pango_context_get_metrics(context, + widget->style->font_desc, pango_context_get_language(context)); + if (width) { + *width = static_cast<int>( + pango_font_metrics_get_approximate_char_width(metrics) * + width_chars / PANGO_SCALE); + } + if (height) { + *height = static_cast<int>( + (pango_font_metrics_get_ascent(metrics) + + pango_font_metrics_get_descent(metrics)) * + height_lines / PANGO_SCALE); + } + pango_font_metrics_unref(metrics); + g_object_unref(context); +} + +void GetWidgetSizeFromResources( + GtkWidget* widget, int width_chars, int height_lines, + int* width, int* height) { + DCHECK(GTK_WIDGET_REALIZED(widget)) + << " widget must be realized to compute font metrics correctly"; + + double chars = 0; + if (width) + base::StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars); + + double lines = 0; + if (height) + base::StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines); + + GetWidgetSizeFromCharacters(widget, chars, lines, width, height); +} + void SetWindowSizeFromResources(GtkWindow* window, int width_id, int height_id, bool resizable) { int width = -1; @@ -1137,4 +1200,14 @@ WebDragOperationsMask GdkDragActionToWebDragOp(GdkDragAction action) { return op; } +void ApplyMessageDialogQuirks(GtkWidget* dialog) { + if (gtk_window_get_modal(GTK_WINDOW(dialog))) { + // Work around a KDE 3 window manager bug. + scoped_ptr<base::Environment> env(base::Environment::Create()); + if (base::nix::DESKTOP_ENVIRONMENT_KDE3 == + base::nix::GetDesktopEnvironment(env.get())) + gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); + } +} + } // namespace gtk_util diff --git a/chrome/browser/gtk/gtk_util.h b/chrome/browser/gtk/gtk_util.h index 0ecafee..f7a87e1 100644 --- a/chrome/browser/gtk/gtk_util.h +++ b/chrome/browser/gtk/gtk_util.h @@ -84,6 +84,20 @@ GtkWidget* LeftAlignMisc(GtkWidget* misc); // Create a left-aligned label with the given text in bold. GtkWidget* CreateBoldLabel(const std::string& text); +// As above, but uses number of characters/lines directly rather than looking up +// a resource. +void GetWidgetSizeFromCharacters(GtkWidget* widget, + double width_chars, double height_lines, + int* width, int* height); + +// Calculates the size of given widget based on the size specified in number of +// characters/lines (in locale specific resource file) and font metrics. +// NOTE: Make sure to realize |widget| before using this method, or a default +// font size will be used instead of the actual font size. +void GetWidgetSizeFromResources(GtkWidget* widget, + int width_chars, int height_lines, + int* width, int* height); + // As above, but a convenience method for configuring dialog size. // |width_id| and |height_id| are resource IDs for the size. If either of these // are set to -1, the respective size will be set to the widget default. @@ -341,6 +355,11 @@ void InitLabelSizeRequestAndEllipsizeMode(GtkWidget* label); GdkDragAction WebDragOpToGdkDragAction(WebKit::WebDragOperationsMask op); WebKit::WebDragOperationsMask GdkDragActionToWebDragOp(GdkDragAction action); +// A helper function for gtk_message_dialog_new() to work around a few KDE 3 +// window manager bugs. You should always call it after creating a dialog with +// gtk_message_dialog_new. +void ApplyMessageDialogQuirks(GtkWidget* dialog); + } // namespace gtk_util #endif // CHROME_BROWSER_GTK_GTK_UTIL_H_ diff --git a/chrome/browser/gtk/js_modal_dialog_gtk.cc b/chrome/browser/gtk/js_modal_dialog_gtk.cc index 3689356..b4a0953 100644 --- a/chrome/browser/gtk/js_modal_dialog_gtk.cc +++ b/chrome/browser/gtk/js_modal_dialog_gtk.cc @@ -6,7 +6,6 @@ #include <gtk/gtk.h> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "app/message_box_flags.h" #include "base/logging.h" diff --git a/chrome/browser/gtk/options/advanced_contents_gtk.cc b/chrome/browser/gtk/options/advanced_contents_gtk.cc index fa1c1c9..f98490e 100644 --- a/chrome/browser/gtk/options/advanced_contents_gtk.cc +++ b/chrome/browser/gtk/options/advanced_contents_gtk.cc @@ -11,7 +11,6 @@ #include <vector> #include "app/gtk_signal.h" -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/basictypes.h" #include "base/command_line.h" diff --git a/chrome/browser/gtk/options/advanced_page_gtk.cc b/chrome/browser/gtk/options/advanced_page_gtk.cc index 71c8052..8351322 100644 --- a/chrome/browser/gtk/options/advanced_page_gtk.cc +++ b/chrome/browser/gtk/options/advanced_page_gtk.cc @@ -4,7 +4,6 @@ #include "chrome/browser/gtk/options/advanced_page_gtk.h" -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/options_util.h" diff --git a/chrome/browser/gtk/options/content_page_gtk.cc b/chrome/browser/gtk/options/content_page_gtk.cc index a119904..c75028a 100644 --- a/chrome/browser/gtk/options/content_page_gtk.cc +++ b/chrome/browser/gtk/options/content_page_gtk.cc @@ -6,7 +6,6 @@ #include <string> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/command_line.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/gtk/options/languages_page_gtk.cc b/chrome/browser/gtk/options/languages_page_gtk.cc index 443cca8..eda179f 100644 --- a/chrome/browser/gtk/options/languages_page_gtk.cc +++ b/chrome/browser/gtk/options/languages_page_gtk.cc @@ -9,7 +9,6 @@ #include <vector> #include "app/gtk_signal.h" -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/command_line.h" #include "base/message_loop.h" diff --git a/chrome/browser/gtk/options/passwords_page_gtk.cc b/chrome/browser/gtk/options/passwords_page_gtk.cc index a1aa597..2051eb6 100644 --- a/chrome/browser/gtk/options/passwords_page_gtk.cc +++ b/chrome/browser/gtk/options/passwords_page_gtk.cc @@ -6,7 +6,6 @@ #include <string> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/stl_util-inl.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc index 30059ba..e9cef31 100644 --- a/chrome/browser/gtk/options/url_picker_dialog_gtk.cc +++ b/chrome/browser/gtk/options/url_picker_dialog_gtk.cc @@ -4,7 +4,6 @@ #include <gtk/gtk.h> -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" diff --git a/chrome/browser/gtk/process_singleton_dialog.cc b/chrome/browser/gtk/process_singleton_dialog.cc index cdd4eab..26fc1b4 100644 --- a/chrome/browser/gtk/process_singleton_dialog.cc +++ b/chrome/browser/gtk/process_singleton_dialog.cc @@ -4,9 +4,9 @@ #include "chrome/browser/gtk/process_singleton_dialog.h" -#include "app/gtk_util.h" #include "app/l10n_util.h" #include "base/message_loop.h" +#include "chrome/browser/gtk/gtk_util.h" #include "grit/chromium_strings.h" // static diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index de26857..1f8eff2 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -9,8 +9,8 @@ #include <gtk/gtk.h> #include "base/file_util.h" +#include "base/gtk_util.h" #include "base/logging.h" -#include "app/gtk_util.h" #include "base/message_loop.h" #include "base/mime_util.h" #include "base/thread.h" diff --git a/chrome/browser/platform_util_common_linux.cc b/chrome/browser/platform_util_common_linux.cc index 1f0ea42..61c92eb 100644 --- a/chrome/browser/platform_util_common_linux.cc +++ b/chrome/browser/platform_util_common_linux.cc @@ -6,7 +6,6 @@ #include <gtk/gtk.h> -#include "app/gtk_util.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/process_util.h" |