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

Side by Side Diff: app/gtk_util.cc

Issue 2058004: Move non-linux specific code from base/linux_util to app/gtk_util... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/gtk_util.h" 5 #include "app/gtk_util.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/env_var.h" 10 #include "base/env_var.h"
(...skipping 13 matching lines...) Expand all
24 if (width) 24 if (width)
25 StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars); 25 StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars);
26 26
27 double lines = 0; 27 double lines = 0;
28 if (height) 28 if (height)
29 StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines); 29 StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines);
30 30
31 GetWidgetSizeFromCharacters(widget, chars, lines, width, height); 31 GetWidgetSizeFromCharacters(widget, chars, lines, width, height);
32 } 32 }
33 33
34 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
35 if (stride == 0)
36 stride = width * 4;
37
38 uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride));
39
40 // We have to copy the pixels and swap from BGRA to RGBA.
41 for (int i = 0; i < height; ++i) {
42 for (int j = 0; j < width; ++j) {
43 int idx = i * stride + j * 4;
44 new_pixels[idx] = pixels[idx + 2];
45 new_pixels[idx + 1] = pixels[idx + 1];
46 new_pixels[idx + 2] = pixels[idx];
47 new_pixels[idx + 3] = pixels[idx + 3];
48 }
49 }
50
51 return new_pixels;
52 }
53
34 void GetWidgetSizeFromCharacters( 54 void GetWidgetSizeFromCharacters(
35 GtkWidget* widget, double width_chars, double height_lines, 55 GtkWidget* widget, double width_chars, double height_lines,
36 int* width, int* height) { 56 int* width, int* height) {
37 DCHECK(GTK_WIDGET_REALIZED(widget)) 57 DCHECK(GTK_WIDGET_REALIZED(widget))
38 << " widget must be realized to compute font metrics correctly"; 58 << " widget must be realized to compute font metrics correctly";
39 PangoContext* context = gtk_widget_create_pango_context(widget); 59 PangoContext* context = gtk_widget_create_pango_context(widget);
40 PangoFontMetrics* metrics = pango_context_get_metrics(context, 60 PangoFontMetrics* metrics = pango_context_get_metrics(context,
41 widget->style->font_desc, pango_context_get_language(context)); 61 widget->style->font_desc, pango_context_get_language(context));
42 if (width) { 62 if (width) {
43 *width = static_cast<int>( 63 *width = static_cast<int>(
(...skipping 13 matching lines...) Expand all
57 void ApplyMessageDialogQuirks(GtkWidget* dialog) { 77 void ApplyMessageDialogQuirks(GtkWidget* dialog) {
58 if (gtk_window_get_modal(GTK_WINDOW(dialog))) { 78 if (gtk_window_get_modal(GTK_WINDOW(dialog))) {
59 // Work around a KDE 3 window manager bug. 79 // Work around a KDE 3 window manager bug.
60 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); 80 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
61 if (base::DESKTOP_ENVIRONMENT_KDE3 == GetDesktopEnvironment(env.get())) 81 if (base::DESKTOP_ENVIRONMENT_KDE3 == GetDesktopEnvironment(env.get()))
62 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE); 82 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
63 } 83 }
64 } 84 }
65 85
66 } // namespace gtk_util 86 } // namespace gtk_util
OLDNEW
« app/gtk_util.h ('K') | « app/gtk_util.h ('k') | base/linux_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698