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