Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/ui/gtk/gtk_util.cc

Issue 8588068: GTK: Create the start of a compatibility header wrapping deprecated methods. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase to ToT and remove views/ cleanups. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "content/browser/disposition_utils.h" 30 #include "content/browser/disposition_utils.h"
31 #include "content/browser/renderer_host/render_view_host.h" 31 #include "content/browser/renderer_host/render_view_host.h"
32 #include "content/browser/tab_contents/tab_contents.h" 32 #include "content/browser/tab_contents/tab_contents.h"
33 #include "content/public/common/renderer_preferences.h" 33 #include "content/public/common/renderer_preferences.h"
34 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
35 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
36 #include "grit/theme_resources_standard.h" 36 #include "grit/theme_resources_standard.h"
37 #include "third_party/skia/include/core/SkBitmap.h" 37 #include "third_party/skia/include/core/SkBitmap.h"
38 #include "third_party/skia/include/core/SkColor.h" 38 #include "third_party/skia/include/core/SkColor.h"
39 #include "ui/base/events.h" 39 #include "ui/base/events.h"
40 #include "ui/base/gtk/gtk_compat.h"
40 #include "ui/base/gtk/gtk_hig_constants.h" 41 #include "ui/base/gtk/gtk_hig_constants.h"
41 #include "ui/base/l10n/l10n_util.h" 42 #include "ui/base/l10n/l10n_util.h"
42 #include "ui/base/resource/resource_bundle.h" 43 #include "ui/base/resource/resource_bundle.h"
43 #include "ui/base/text/text_elider.h" 44 #include "ui/base/text/text_elider.h"
44 #include "ui/base/x/x11_util.h" 45 #include "ui/base/x/x11_util.h"
45 #include "ui/gfx/gtk_util.h" 46 #include "ui/gfx/gtk_util.h"
46 #include "ui/gfx/image/image.h" 47 #include "ui/gfx/image/image.h"
47 48
48 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS)
49 #include "chrome/browser/chromeos/frame/browser_view.h" 50 #include "chrome/browser/chromeos/frame/browser_view.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 gint button_mask = GPOINTER_TO_INT(userdata); 95 gint button_mask = GPOINTER_TO_INT(userdata);
95 if (button_mask && (1 << event->button)) 96 if (button_mask && (1 << event->button))
96 gtk_button_released(GTK_BUTTON(widget)); 97 gtk_button_released(GTK_BUTTON(widget));
97 98
98 return TRUE; 99 return TRUE;
99 } 100 }
100 101
101 // Returns the approximate number of characters that can horizontally fit in 102 // Returns the approximate number of characters that can horizontally fit in
102 // |pixel_width| pixels. 103 // |pixel_width| pixels.
103 int GetCharacterWidthForPixels(GtkWidget* widget, int pixel_width) { 104 int GetCharacterWidthForPixels(GtkWidget* widget, int pixel_width) {
104 DCHECK(GTK_WIDGET_REALIZED(widget)) 105 DCHECK(gtk_widget_get_realized(widget))
105 << " widget must be realized to compute font metrics correctly"; 106 << " widget must be realized to compute font metrics correctly";
106 107
107 PangoContext* context = gtk_widget_create_pango_context(widget); 108 PangoContext* context = gtk_widget_create_pango_context(widget);
108 PangoFontMetrics* metrics = pango_context_get_metrics(context, 109 PangoFontMetrics* metrics = pango_context_get_metrics(context,
109 widget->style->font_desc, pango_context_get_language(context)); 110 widget->style->font_desc, pango_context_get_language(context));
110 111
111 // This technique (max of char and digit widths) matches the code in 112 // This technique (max of char and digit widths) matches the code in
112 // gtklabel.c. 113 // gtklabel.c.
113 int char_width = pixel_width * PANGO_SCALE / 114 int char_width = pixel_width * PANGO_SCALE /
114 std::max(pango_font_metrics_get_approximate_char_width(metrics), 115 std::max(pango_font_metrics_get_approximate_char_width(metrics),
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 char* markup = g_markup_printf_escaped(kBoldLabelMarkup, text.c_str()); 268 char* markup = g_markup_printf_escaped(kBoldLabelMarkup, text.c_str());
268 gtk_label_set_markup(GTK_LABEL(label), markup); 269 gtk_label_set_markup(GTK_LABEL(label), markup);
269 g_free(markup); 270 g_free(markup);
270 271
271 return LeftAlignMisc(label); 272 return LeftAlignMisc(label);
272 } 273 }
273 274
274 void GetWidgetSizeFromCharacters( 275 void GetWidgetSizeFromCharacters(
275 GtkWidget* widget, double width_chars, double height_lines, 276 GtkWidget* widget, double width_chars, double height_lines,
276 int* width, int* height) { 277 int* width, int* height) {
277 DCHECK(GTK_WIDGET_REALIZED(widget)) 278 DCHECK(gtk_widget_get_realized(widget))
278 << " widget must be realized to compute font metrics correctly"; 279 << " widget must be realized to compute font metrics correctly";
279 PangoContext* context = gtk_widget_create_pango_context(widget); 280 PangoContext* context = gtk_widget_create_pango_context(widget);
280 PangoFontMetrics* metrics = pango_context_get_metrics(context, 281 PangoFontMetrics* metrics = pango_context_get_metrics(context,
281 widget->style->font_desc, pango_context_get_language(context)); 282 widget->style->font_desc, pango_context_get_language(context));
282 if (width) { 283 if (width) {
283 *width = static_cast<int>( 284 *width = static_cast<int>(
284 pango_font_metrics_get_approximate_char_width(metrics) * 285 pango_font_metrics_get_approximate_char_width(metrics) *
285 width_chars / PANGO_SCALE); 286 width_chars / PANGO_SCALE);
286 } 287 }
287 if (height) { 288 if (height) {
288 *height = static_cast<int>( 289 *height = static_cast<int>(
289 (pango_font_metrics_get_ascent(metrics) + 290 (pango_font_metrics_get_ascent(metrics) +
290 pango_font_metrics_get_descent(metrics)) * 291 pango_font_metrics_get_descent(metrics)) *
291 height_lines / PANGO_SCALE); 292 height_lines / PANGO_SCALE);
292 } 293 }
293 pango_font_metrics_unref(metrics); 294 pango_font_metrics_unref(metrics);
294 g_object_unref(context); 295 g_object_unref(context);
295 } 296 }
296 297
297 void GetWidgetSizeFromResources( 298 void GetWidgetSizeFromResources(
298 GtkWidget* widget, int width_chars, int height_lines, 299 GtkWidget* widget, int width_chars, int height_lines,
299 int* width, int* height) { 300 int* width, int* height) {
300 DCHECK(GTK_WIDGET_REALIZED(widget)) 301 DCHECK(gtk_widget_get_realized(widget))
301 << " widget must be realized to compute font metrics correctly"; 302 << " widget must be realized to compute font metrics correctly";
302 303
303 double chars = 0; 304 double chars = 0;
304 if (width) 305 if (width)
305 base::StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars); 306 base::StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars);
306 307
307 double lines = 0; 308 double lines = 0;
308 if (height) 309 if (height)
309 base::StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines); 310 base::StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines);
310 311
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 GValue true_value = { 0 }; 835 GValue true_value = { 0 };
835 g_value_init(&true_value, G_TYPE_BOOLEAN); 836 g_value_init(&true_value, G_TYPE_BOOLEAN);
836 g_value_set_boolean(&true_value, TRUE); 837 g_value_set_boolean(&true_value, TRUE);
837 g_object_set_property(G_OBJECT(image_menu_item), "always-show-image", 838 g_object_set_property(G_OBJECT(image_menu_item), "always-show-image",
838 &true_value); 839 &true_value);
839 } 840 }
840 #endif 841 #endif
841 } 842 }
842 843
843 gfx::Rect GetWidgetRectRelativeToToplevel(GtkWidget* widget) { 844 gfx::Rect GetWidgetRectRelativeToToplevel(GtkWidget* widget) {
844 DCHECK(GTK_WIDGET_REALIZED(widget)); 845 DCHECK(gtk_widget_get_realized(widget));
845 846
846 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); 847 GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
847 DCHECK(toplevel); 848 DCHECK(toplevel);
848 DCHECK(GTK_WIDGET_REALIZED(toplevel)); 849 DCHECK(gtk_widget_get_realized(toplevel));
849 850
850 gint x = 0, y = 0; 851 gint x = 0, y = 0;
851 gtk_widget_translate_coordinates(widget, 852 gtk_widget_translate_coordinates(widget,
852 toplevel, 853 toplevel,
853 0, 0, 854 0, 0,
854 &x, &y); 855 &x, &y);
855 return gfx::Rect(x, y, widget->allocation.width, widget->allocation.height); 856 return gfx::Rect(x, y, widget->allocation.width, widget->allocation.height);
856 } 857 }
857 858
858 void SuppressDefaultPainting(GtkWidget* container) { 859 void SuppressDefaultPainting(GtkWidget* container) {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); 1139 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
1139 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 1140 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1140 1141
1141 // Do the simple thing in LTR because the bug only affects right-aligned 1142 // Do the simple thing in LTR because the bug only affects right-aligned
1142 // text. Also, when using the workaround, the label tries to maintain 1143 // text. Also, when using the workaround, the label tries to maintain
1143 // uniform line-length, which we don't really want. 1144 // uniform line-length, which we don't really want.
1144 if (gtk_widget_get_direction(label) == GTK_TEXT_DIR_LTR) { 1145 if (gtk_widget_get_direction(label) == GTK_TEXT_DIR_LTR) {
1145 gtk_widget_set_size_request(label, pixel_width, -1); 1146 gtk_widget_set_size_request(label, pixel_width, -1);
1146 } else { 1147 } else {
1147 // The label has to be realized before we can adjust its width. 1148 // The label has to be realized before we can adjust its width.
1148 if (GTK_WIDGET_REALIZED(label)) { 1149 if (gtk_widget_get_realized(label)) {
1149 OnLabelRealize(label, GINT_TO_POINTER(pixel_width)); 1150 OnLabelRealize(label, GINT_TO_POINTER(pixel_width));
1150 } else { 1151 } else {
1151 g_signal_connect(label, "realize", G_CALLBACK(OnLabelRealize), 1152 g_signal_connect(label, "realize", G_CALLBACK(OnLabelRealize),
1152 GINT_TO_POINTER(pixel_width)); 1153 GINT_TO_POINTER(pixel_width));
1153 } 1154 }
1154 } 1155 }
1155 } 1156 }
1156 1157
1157 void InitLabelSizeRequestAndEllipsizeMode(GtkWidget* label) { 1158 void InitLabelSizeRequestAndEllipsizeMode(GtkWidget* label) {
1158 GtkRequisition size; 1159 GtkRequisition size;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 1202
1202 void DoCopy(BrowserWindow* window) { 1203 void DoCopy(BrowserWindow* window) {
1203 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); 1204 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard");
1204 } 1205 }
1205 1206
1206 void DoPaste(BrowserWindow* window) { 1207 void DoPaste(BrowserWindow* window) {
1207 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); 1208 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard");
1208 } 1209 }
1209 1210
1210 } // namespace gtk_util 1211 } // namespace gtk_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/gtk_chrome_link_button.cc ('k') | chrome/browser/ui/gtk/hover_controller_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698