OLD | NEW |
---|---|
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 #ifndef UI_GFX_GTK_UTIL_H_ | 5 #ifndef UI_GFX_GTK_UTIL_H_ |
6 #define UI_GFX_GTK_UTIL_H_ | 6 #define UI_GFX_GTK_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <glib-object.h> | 9 #include <glib-object.h> |
10 #include <pango/pango-layout.h> | |
10 #include <stdint.h> | 11 #include <stdint.h> |
11 | 12 |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
16 #include "base/i18n/rtl.h" | |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
16 #include "ui/base/ui_export.h" | 18 #include "ui/base/ui_export.h" |
17 | 19 |
18 typedef struct _GdkPixbuf GdkPixbuf; | 20 typedef struct _GdkPixbuf GdkPixbuf; |
19 typedef struct _GdkRegion GdkRegion; | 21 typedef struct _GdkRegion GdkRegion; |
20 typedef struct _GdkCursor GdkCursor; | 22 typedef struct _GdkCursor GdkCursor; |
21 | 23 |
22 typedef struct _PangoContext PangoContext; | 24 typedef struct _PangoContext PangoContext; |
23 | 25 |
24 class CommandLine; | 26 class CommandLine; |
25 class SkBitmap; | 27 class SkBitmap; |
26 | 28 |
27 namespace gfx { | 29 namespace gfx { |
28 | 30 |
31 class Font; | |
29 class Rect; | 32 class Rect; |
30 | 33 |
31 // Call gtk_init() using the argc and argv from command_line. | 34 // Call gtk_init() using the argc and argv from command_line. |
32 // gtk_init() wants an argc and argv that it can mutate; we provide those, | 35 // gtk_init() wants an argc and argv that it can mutate; we provide those, |
33 // but leave the original CommandLine unaltered. | 36 // but leave the original CommandLine unaltered. |
34 UI_EXPORT void GtkInitFromCommandLine(const CommandLine& command_line); | 37 UI_EXPORT void GtkInitFromCommandLine(const CommandLine& command_line); |
35 | 38 |
36 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so | 39 // Convert and copy a SkBitmap to a GdkPixbuf. NOTE: this uses BGRAToRGBA, so |
37 // it is an expensive operation. The returned GdkPixbuf will have a refcount of | 40 // it is an expensive operation. The returned GdkPixbuf will have a refcount of |
38 // 1, and the caller is responsible for unrefing it when done. | 41 // 1, and the caller is responsible for unrefing it when done. |
39 UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); | 42 UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); |
40 | 43 |
41 // Modify the given region by subtracting the given rectangles. | 44 // Modify the given region by subtracting the given rectangles. |
42 UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region, | 45 UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region, |
43 const std::vector<Rect>& cutouts); | 46 const std::vector<Rect>& cutouts); |
44 | 47 |
48 // Setup pango layout |layout|, including set layout text as |text|, font | |
49 // description based on |font|, width as |width| in PANGO_SCALE for RTL lcoale, | |
50 // and set up whether auto-detect directionality, alignment, ellipsis, word | |
51 // wrapping, resolution etc. | |
52 void SetupPangoLayout(PangoLayout* layout, | |
msw
2011/08/23 08:01:01
Hmm, I didn't suspect that moving the declaration
xji
2011/08/23 23:52:52
Ah, I think I mis-interpreted your previous commen
| |
53 const string16& text, | |
54 const gfx::Font& font, | |
55 int width, | |
56 base::i18n::TextDirection text_direction, | |
57 int flags); | |
58 | |
45 // Creates and returns a PangoContext. The caller owns the context. | 59 // Creates and returns a PangoContext. The caller owns the context. |
46 PangoContext* GetPangoContext(); | 60 PangoContext* GetPangoContext(); |
47 | 61 |
48 // Returns the resolution (DPI) used by pango. A negative values means the | 62 // Returns the resolution (DPI) used by pango. A negative values means the |
49 // resolution hasn't been set. | 63 // resolution hasn't been set. |
50 double GetPangoResolution(); | 64 double GetPangoResolution(); |
51 | 65 |
52 // Returns a static instance of a GdkCursor* object, sharable across the | 66 // Returns a static instance of a GdkCursor* object, sharable across the |
53 // process. Caller must gdk_cursor_ref() it if they want to assume ownership. | 67 // process. Caller must gdk_cursor_ref() it if they want to assume ownership. |
54 UI_EXPORT GdkCursor* GetCursor(int type); | 68 UI_EXPORT GdkCursor* GetCursor(int type); |
55 | 69 |
56 // Change windows accelerator style to GTK style. (GTK uses _ for | 70 // Change windows accelerator style to GTK style. (GTK uses _ for |
57 // accelerators. Windows uses & with && as an escape for &.) | 71 // accelerators. Windows uses & with && as an escape for &.) |
58 UI_EXPORT std::string ConvertAcceleratorsFromWindowsStyle( | 72 UI_EXPORT std::string ConvertAcceleratorsFromWindowsStyle( |
59 const std::string& label); | 73 const std::string& label); |
60 | 74 |
61 // Removes the "&" accelerators from a Windows label. | 75 // Removes the "&" accelerators from a Windows label. |
62 UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label); | 76 UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label); |
63 | 77 |
64 // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. | 78 // Makes a copy of |pixels| with the ordering changed from BGRA to RGBA. |
65 // The caller is responsible for free()ing the data. If |stride| is 0, it's | 79 // The caller is responsible for free()ing the data. If |stride| is 0, it's |
66 // assumed to be 4 * |width|. | 80 // assumed to be 4 * |width|. |
67 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); | 81 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride); |
68 | |
msw
2011/08/23 08:01:01
replace this line. (I think the common/proper styl
| |
69 } // namespace gfx | 82 } // namespace gfx |
70 | 83 |
71 // It's not legal C++ to have a templatized typedefs, so we wrap it in a | 84 // It's not legal C++ to have a templatized typedefs, so we wrap it in a |
72 // struct. When using this, you need to include ::Type. E.g., | 85 // struct. When using this, you need to include ::Type. E.g., |
73 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); | 86 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new()); |
74 template<class T> | 87 template<class T> |
75 struct ScopedGObject { | 88 struct ScopedGObject { |
76 // A helper class that will g_object_unref |p| when it goes out of scope. | 89 // A helper class that will g_object_unref |p| when it goes out of scope. |
77 // This never adds a ref, it only unrefs. | 90 // This never adds a ref, it only unrefs. |
78 template<class U> | 91 template<class U> |
79 struct GObjectUnrefer { | 92 struct GObjectUnrefer { |
80 void operator()(U* ptr) const { | 93 void operator()(U* ptr) const { |
81 if (ptr) | 94 if (ptr) |
82 g_object_unref(ptr); | 95 g_object_unref(ptr); |
83 } | 96 } |
84 }; | 97 }; |
85 | 98 |
86 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; | 99 typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type; |
87 }; | 100 }; |
88 | 101 |
89 #endif // UI_GFX_GTK_UTIL_H_ | 102 #endif // UI_GFX_GTK_UTIL_H_ |
OLD | NEW |