summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 16:43:15 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 16:43:15 +0000
commit4f26826dc91e9aa41f3adbda05f94c44581eddd8 (patch)
treef5de5a1b868c8b8d1cfc22c9e44dc77da23ccbae /chrome/common
parent88efb7ec99239eeecaa17d21f8635be1bce29cca (diff)
downloadchromium_src-4f26826dc91e9aa41f3adbda05f94c44581eddd8.zip
chromium_src-4f26826dc91e9aa41f3adbda05f94c44581eddd8.tar.gz
chromium_src-4f26826dc91e9aa41f3adbda05f94c44581eddd8.tar.bz2
Linux: Add first run search bubble.
Review URL: http://codereview.chromium.org/149501 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/gtk_util.cc21
-rw-r--r--chrome/common/gtk_util.h6
2 files changed, 27 insertions, 0 deletions
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index e985bf6..8b7dfd8 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -178,6 +178,27 @@ GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
return ebox;
}
+bool GetWidgetSizeFromResources(GtkWidget* widget, int width_chars,
+ int height_lines, int* width, int* height) {
+ PangoContext* context = gtk_widget_create_pango_context(widget);
+ PangoFontMetrics* metrics = pango_context_get_metrics(context,
+ widget->style->font_desc, pango_context_get_language(context));
+ double chars = 0;
+ StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars);
+ *width =
+ pango_font_metrics_get_approximate_char_width(metrics) *
+ static_cast<int>(chars) / PANGO_SCALE;
+ double lines = 0;
+ StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines);
+ *height =
+ (pango_font_metrics_get_ascent(metrics) +
+ pango_font_metrics_get_descent(metrics)) *
+ static_cast<int>(lines) / PANGO_SCALE;
+ pango_font_metrics_unref(metrics);
+ g_object_unref(context);
+ return true;
+}
+
void RemoveAllChildren(GtkWidget* container) {
gtk_container_foreach(GTK_CONTAINER(container), RemoveWidget, container);
}
diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h
index 983cf4a..85bcc4b 100644
--- a/chrome/common/gtk_util.h
+++ b/chrome/common/gtk_util.h
@@ -62,6 +62,12 @@ GtkWidget* CreateLabeledControlsGroup(const char* text, ...);
GtkWidget* CreateGtkBorderBin(GtkWidget* child, const GdkColor* color,
int top, int bottom, int left, int right);
+// Calculates the size of given widget based on the size specified in
+// number of characters/lines (in locale specific resource file) and
+// font metrics.
+bool GetWidgetSizeFromResources(GtkWidget* widget, int width_chars,
+ int height_lines, int* width, int* height);
+
// Remove all children from this container.
void RemoveAllChildren(GtkWidget* container);