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> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return TRUE; | 101 return TRUE; |
102 } | 102 } |
103 | 103 |
104 // Returns the approximate number of characters that can horizontally fit in | 104 // Returns the approximate number of characters that can horizontally fit in |
105 // |pixel_width| pixels. | 105 // |pixel_width| pixels. |
106 int GetCharacterWidthForPixels(GtkWidget* widget, int pixel_width) { | 106 int GetCharacterWidthForPixels(GtkWidget* widget, int pixel_width) { |
107 DCHECK(gtk_widget_get_realized(widget)) | 107 DCHECK(gtk_widget_get_realized(widget)) |
108 << " widget must be realized to compute font metrics correctly"; | 108 << " widget must be realized to compute font metrics correctly"; |
109 | 109 |
110 PangoContext* context = gtk_widget_create_pango_context(widget); | 110 PangoContext* context = gtk_widget_create_pango_context(widget); |
| 111 GtkStyle* style = gtk_widget_get_style(widget); |
111 PangoFontMetrics* metrics = pango_context_get_metrics(context, | 112 PangoFontMetrics* metrics = pango_context_get_metrics(context, |
112 widget->style->font_desc, pango_context_get_language(context)); | 113 style->font_desc, pango_context_get_language(context)); |
113 | 114 |
114 // This technique (max of char and digit widths) matches the code in | 115 // This technique (max of char and digit widths) matches the code in |
115 // gtklabel.c. | 116 // gtklabel.c. |
116 int char_width = pixel_width * PANGO_SCALE / | 117 int char_width = pixel_width * PANGO_SCALE / |
117 std::max(pango_font_metrics_get_approximate_char_width(metrics), | 118 std::max(pango_font_metrics_get_approximate_char_width(metrics), |
118 pango_font_metrics_get_approximate_digit_width(metrics)); | 119 pango_font_metrics_get_approximate_digit_width(metrics)); |
119 | 120 |
120 pango_font_metrics_unref(metrics); | 121 pango_font_metrics_unref(metrics); |
121 g_object_unref(context); | 122 g_object_unref(context); |
122 | 123 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 274 |
274 return LeftAlignMisc(label); | 275 return LeftAlignMisc(label); |
275 } | 276 } |
276 | 277 |
277 void GetWidgetSizeFromCharacters( | 278 void GetWidgetSizeFromCharacters( |
278 GtkWidget* widget, double width_chars, double height_lines, | 279 GtkWidget* widget, double width_chars, double height_lines, |
279 int* width, int* height) { | 280 int* width, int* height) { |
280 DCHECK(gtk_widget_get_realized(widget)) | 281 DCHECK(gtk_widget_get_realized(widget)) |
281 << " widget must be realized to compute font metrics correctly"; | 282 << " widget must be realized to compute font metrics correctly"; |
282 PangoContext* context = gtk_widget_create_pango_context(widget); | 283 PangoContext* context = gtk_widget_create_pango_context(widget); |
| 284 GtkStyle* style = gtk_widget_get_style(widget); |
283 PangoFontMetrics* metrics = pango_context_get_metrics(context, | 285 PangoFontMetrics* metrics = pango_context_get_metrics(context, |
284 widget->style->font_desc, pango_context_get_language(context)); | 286 style->font_desc, pango_context_get_language(context)); |
285 if (width) { | 287 if (width) { |
286 *width = static_cast<int>( | 288 *width = static_cast<int>( |
287 pango_font_metrics_get_approximate_char_width(metrics) * | 289 pango_font_metrics_get_approximate_char_width(metrics) * |
288 width_chars / PANGO_SCALE); | 290 width_chars / PANGO_SCALE); |
289 } | 291 } |
290 if (height) { | 292 if (height) { |
291 *height = static_cast<int>( | 293 *height = static_cast<int>( |
292 (pango_font_metrics_get_ascent(metrics) + | 294 (pango_font_metrics_get_ascent(metrics) + |
293 pango_font_metrics_get_descent(metrics)) * | 295 pango_font_metrics_get_descent(metrics)) * |
294 height_lines / PANGO_SCALE); | 296 height_lines / PANGO_SCALE); |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 | 1175 |
1174 void DoCopy(BrowserWindow* window) { | 1176 void DoCopy(BrowserWindow* window) { |
1175 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); | 1177 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); |
1176 } | 1178 } |
1177 | 1179 |
1178 void DoPaste(BrowserWindow* window) { | 1180 void DoPaste(BrowserWindow* window) { |
1179 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); | 1181 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); |
1180 } | 1182 } |
1181 | 1183 |
1182 } // namespace gtk_util | 1184 } // namespace gtk_util |
OLD | NEW |