diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-29 01:08:24 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-29 01:08:24 +0000 |
commit | 0996997dcdeb39892665ce5ee7ae773ab2e729e3 (patch) | |
tree | 42cb5670877914ba66115fcd31ae42e57c9cd686 /gfx | |
parent | 4346168703bc2f3879669e1b969628ed62a266d2 (diff) | |
download | chromium_src-0996997dcdeb39892665ce5ee7ae773ab2e729e3.zip chromium_src-0996997dcdeb39892665ce5ee7ae773ab2e729e3.tar.gz chromium_src-0996997dcdeb39892665ce5ee7ae773ab2e729e3.tar.bz2 |
Cleanup: Remove base/gtk_util.h by moving its methods to
gfx/gtk_util.h
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/4150006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64348 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/canvas_skia_linux.cc | 3 | ||||
-rw-r--r-- | gfx/gtk_util.cc | 61 | ||||
-rw-r--r-- | gfx/gtk_util.h | 31 |
3 files changed, 72 insertions, 23 deletions
diff --git a/gfx/canvas_skia_linux.cc b/gfx/canvas_skia_linux.cc index 6d675ad..57705a6 100644 --- a/gfx/canvas_skia_linux.cc +++ b/gfx/canvas_skia_linux.cc @@ -10,7 +10,6 @@ #include <pango/pangocairo.h> #include "base/logging.h" -#include "base/gtk_util.h" #include "base/utf_string_conversions.h" #include "gfx/font.h" #include "gfx/gtk_util.h" @@ -166,7 +165,7 @@ static void SetupPangoLayout(PangoLayout* layout, g_free(escaped_text); } else if (flags & gfx::Canvas::HIDE_PREFIX) { // Remove the ampersand character. - utf8 = gtk_util::RemoveWindowsStyleAccelerators(utf8); + utf8 = gfx::RemoveWindowsStyleAccelerators(utf8); pango_layout_set_text(layout, utf8.data(), utf8.size()); } else { pango_layout_set_text(layout, utf8.data(), utf8.size()); diff --git a/gfx/gtk_util.cc b/gfx/gtk_util.cc index bbed191..c45e133 100644 --- a/gfx/gtk_util.cc +++ b/gfx/gtk_util.cc @@ -20,15 +20,38 @@ void FreePixels(guchar* pixels, gpointer data) { free(data); } +// Common implementation of ConvertAcceleratorsFromWindowsStyle() and +// RemoveWindowsStyleAccelerators(). +// Replaces all ampersands (as used in our grd files to indicate mnemonics) +// to |target|. Similarly any underscores get replaced with two underscores as +// is needed by pango. +std::string ConvertAmperstandsTo(const std::string& label, + const std::string& target) { + std::string ret; + ret.reserve(label.length() * 2); + for (size_t i = 0; i < label.length(); ++i) { + if ('_' == label[i]) { + ret.push_back('_'); + ret.push_back('_'); + } else if ('&' == label[i]) { + if (i + 1 < label.length() && '&' == label[i + 1]) { + ret.push_back('&'); + ++i; + } else { + ret.append(target); + } + } else { + ret.push_back(label[i]); + } + } + + return ret; +} + } // namespace namespace gfx { -const GdkColor kGdkWhite = GDK_COLOR_RGB(0xff, 0xff, 0xff); -const GdkColor kGdkGray = GDK_COLOR_RGB(0x7f, 0x7f, 0x7f); -const GdkColor kGdkBlack = GDK_COLOR_RGB(0x00, 0x00, 0x00); -const GdkColor kGdkGreen = GDK_COLOR_RGB(0x00, 0xff, 0x00); - GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { if (bitmap->isNull()) return NULL; @@ -104,4 +127,32 @@ double GetPangoResolution() { return resolution; } +std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) { + return ConvertAmperstandsTo(label, "_"); +} + +std::string RemoveWindowsStyleAccelerators(const std::string& label) { + return ConvertAmperstandsTo(label, ""); +} + +uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) { + if (stride == 0) + stride = width * 4; + + uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride)); + + // We have to copy the pixels and swap from BGRA to RGBA. + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int idx = i * stride + j * 4; + new_pixels[idx] = pixels[idx + 2]; + new_pixels[idx + 1] = pixels[idx + 1]; + new_pixels[idx + 2] = pixels[idx]; + new_pixels[idx + 3] = pixels[idx + 3]; + } + } + + return new_pixels; +} + } // namespace gfx diff --git a/gfx/gtk_util.h b/gfx/gtk_util.h index 3f8fc0c..5c4ad94 100644 --- a/gfx/gtk_util.h +++ b/gfx/gtk_util.h @@ -6,36 +6,23 @@ #define GFX_GTK_UTIL_H_ #pragma once +#include <glib-object.h> #include <stdint.h> -#include <vector> -#include <glib-object.h> +#include <string> +#include <vector> #include "base/scoped_ptr.h" -typedef struct _GdkColor GdkColor; typedef struct _GdkPixbuf GdkPixbuf; typedef struct _GdkRegion GdkRegion; class SkBitmap; -const int kSkiaToGDKMultiplier = 257; - -// Define a macro for creating GdkColors from RGB values. This is a macro to -// allow static construction of literals, etc. Use this like: -// GdkColor white = GDK_COLOR_RGB(0xff, 0xff, 0xff); -#define GDK_COLOR_RGB(r, g, b) {0, r * kSkiaToGDKMultiplier, \ - g * kSkiaToGDKMultiplier, b * kSkiaToGDKMultiplier} - namespace gfx { class Rect; -extern const GdkColor kGdkWhite; -extern const GdkColor kGdkGray; -extern const GdkColor kGdkBlack; -extern const GdkColor kGdkGreen; - // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so // it is an expensive operation. The returned GdkPixbuf will have a refcount of // 1, and the caller is responsible for unrefing it when done. @@ -49,6 +36,18 @@ void SubtractRectanglesFromRegion(GdkRegion* region, // resolution hasn't been set. double GetPangoResolution(); +// Change windows accelerator style to GTK style. (GTK uses _ for +// accelerators. Windows uses & with && as an escape for &.) +std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label); + +// Removes the "&" accelerators from a Windows label. +std::string RemoveWindowsStyleAccelerators(const std::string& label); + +// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. +// The caller is responsible for free()ing the data. If |stride| is 0, it's +// assumed to be 4 * |width|. +uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); + } // namespace gfx namespace { |