OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ |
6 #define CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ | 6 #define CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/gfx/rect.h" | 12 #include "base/gfx/rect.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "chrome/common/notification_observer.h" | 14 #include "chrome/common/notification_observer.h" |
15 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
16 #include "chrome/common/owned_widget_gtk.h" | 16 #include "chrome/common/owned_widget_gtk.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
18 | 18 |
| 19 class CairoCachedSurface; |
19 class GtkThemeProvider; | 20 class GtkThemeProvider; |
20 | 21 |
21 // These classes implement two kinds of custom-drawn buttons. They're | 22 // These classes implement two kinds of custom-drawn buttons. They're |
22 // used on the toolbar and the bookmarks bar. | 23 // used on the toolbar and the bookmarks bar. |
23 | 24 |
24 // CustomDrawButtonBase provides the base for building a custom drawn button. | 25 // CustomDrawButtonBase provides the base for building a custom drawn button. |
25 // It handles managing the pixbufs containing all the static images used to draw | 26 // It handles managing the pixbufs containing all the static images used to draw |
26 // the button. It also manages painting these pixbufs. | 27 // the button. It also manages painting these pixbufs. |
27 class CustomDrawButtonBase : public NotificationObserver { | 28 class CustomDrawButtonBase : public NotificationObserver { |
28 public: | 29 public: |
29 // If the images come from ResourceBundle rather than the theme provider, | 30 // If the images come from ResourceBundle rather than the theme provider, |
30 // pass in NULL for |theme_provider|. | 31 // pass in NULL for |theme_provider|. |
31 CustomDrawButtonBase(GtkThemeProvider* theme_provider, | 32 CustomDrawButtonBase(GtkThemeProvider* theme_provider, |
32 int normal_id, | 33 int normal_id, |
33 int active_id, | 34 int active_id, |
34 int highlight_id, | 35 int highlight_id, |
35 int depressed_id); | 36 int depressed_id); |
36 | 37 |
37 ~CustomDrawButtonBase(); | 38 ~CustomDrawButtonBase(); |
38 | 39 |
39 GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; } | 40 // Returns the dimensions of the first surface. |
| 41 int Width() const; |
| 42 int Height() const; |
40 | 43 |
41 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e); | 44 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e); |
42 | 45 |
43 void set_paint_override(int state) { paint_override_ = state; } | 46 void set_paint_override(int state) { paint_override_ = state; } |
44 int paint_override() const { return paint_override_; } | 47 int paint_override() const { return paint_override_; } |
45 | 48 |
46 // Set the background details. | 49 // Set the background details. |
47 void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask); | 50 void SetBackground(SkColor color, SkBitmap* image, SkBitmap* mask); |
48 | 51 |
49 // Provide NotificationObserver implementation. | 52 // Provide NotificationObserver implementation. |
50 virtual void Observe(NotificationType type, | 53 virtual void Observe(NotificationType type, |
51 const NotificationSource& source, | 54 const NotificationSource& source, |
52 const NotificationDetails& details); | 55 const NotificationDetails& details); |
53 | 56 |
54 private: | 57 private: |
55 // We store one GdkPixbuf* for each possible state of the button; | 58 // We store one surface for each possible state of the button; |
56 // INSENSITIVE is the last available state; | 59 // INSENSITIVE is the last available state; |
57 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1]; | 60 scoped_ptr<CairoCachedSurface> surfaces_[GTK_STATE_INSENSITIVE + 1]; |
58 | 61 |
59 // The background image. | 62 // The background image. |
60 GdkPixbuf* background_image_; | 63 scoped_ptr<CairoCachedSurface> background_image_; |
61 | 64 |
62 // If non-negative, the state to paint the button. | 65 // If non-negative, the state to paint the button. |
63 int paint_override_; | 66 int paint_override_; |
64 | 67 |
65 // We need to remember the image ids that the user passes in and the theme | 68 // We need to remember the image ids that the user passes in and the theme |
66 // provider so we can reload images if the user changes theme. | 69 // provider so we can reload images if the user changes theme. |
67 int normal_id_; | 70 int normal_id_; |
68 int active_id_; | 71 int active_id_; |
69 int highlight_id_; | 72 int highlight_id_; |
70 int depressed_id_; | 73 int depressed_id_; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 const char* gtk_stock_name_; | 156 const char* gtk_stock_name_; |
154 GtkIconSize icon_size_; | 157 GtkIconSize icon_size_; |
155 | 158 |
156 // Used to listen for theme change notifications. | 159 // Used to listen for theme change notifications. |
157 NotificationRegistrar registrar_; | 160 NotificationRegistrar registrar_; |
158 | 161 |
159 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton); | 162 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton); |
160 }; | 163 }; |
161 | 164 |
162 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ | 165 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ |
OLD | NEW |