| 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" | |
| 15 #include "chrome/common/notification_registrar.h" | |
| 16 #include "chrome/common/owned_widget_gtk.h" | 14 #include "chrome/common/owned_widget_gtk.h" |
| 17 | 15 |
| 18 class ThemeProvider; | |
| 19 | |
| 20 // These classes implement two kinds of custom-drawn buttons. They're | 16 // These classes implement two kinds of custom-drawn buttons. They're |
| 21 // used on the toolbar and the bookmarks bar. | 17 // used on the toolbar and the bookmarks bar. |
| 22 | 18 |
| 23 // CustomDrawButtonBase provides the base for building a custom drawn button. | 19 // CustomDrawButtonBase provides the base for building a custom drawn button. |
| 24 // It handles managing the pixbufs containing all the static images used to draw | 20 // It handles managing the pixbufs containing all the static images used to draw |
| 25 // the button. It also manages painting these pixbufs. | 21 // the button. It also manages painting these pixbufs. |
| 26 class CustomDrawButtonBase : public NotificationObserver { | 22 class CustomDrawButtonBase { |
| 27 public: | 23 public: |
| 28 // If the images come from ResourceBundle rather than the theme provider, | 24 CustomDrawButtonBase(int normal_id, |
| 29 // pass in NULL for |theme_provider|. | |
| 30 CustomDrawButtonBase(ThemeProvider* theme_provider, | |
| 31 int normal_id, | |
| 32 int active_id, | 25 int active_id, |
| 33 int highlight_id, | 26 int highlight_id, |
| 34 int depressed_id); | 27 int depressed_id); |
| 35 | |
| 36 ~CustomDrawButtonBase(); | 28 ~CustomDrawButtonBase(); |
| 37 | 29 |
| 38 GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; } | 30 GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; } |
| 39 | 31 |
| 40 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e); | 32 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e); |
| 41 | 33 |
| 42 void set_paint_override(int state) { paint_override_ = state; } | 34 void set_paint_override(int state) { paint_override_ = state; } |
| 43 | 35 |
| 44 // Provide NotificationObserver implementation. | |
| 45 virtual void Observe(NotificationType type, | |
| 46 const NotificationSource& source, | |
| 47 const NotificationDetails& details); | |
| 48 | |
| 49 private: | 36 private: |
| 50 // We store one GdkPixbuf* for each possible state of the button; | 37 // We store one GdkPixbuf* for each possible state of the button; |
| 51 // INSENSITIVE is the last available state; | 38 // INSENSITIVE is the last available state; |
| 52 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1]; | 39 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1]; |
| 53 | 40 |
| 54 // If non-negative, the state to paint the button. | 41 // If non-negative, the state to paint the button. |
| 55 int paint_override_; | 42 int paint_override_; |
| 56 | 43 |
| 57 // We need to remember the image ids that the user passes in and the theme | |
| 58 // provider so we can reload images if the user changes theme. | |
| 59 int normal_id_; | |
| 60 int active_id_; | |
| 61 int highlight_id_; | |
| 62 int depressed_id_; | |
| 63 ThemeProvider* theme_provider_; | |
| 64 | |
| 65 // Used to listen for theme change notifications. | |
| 66 NotificationRegistrar registrar_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(CustomDrawButtonBase); | 44 DISALLOW_COPY_AND_ASSIGN(CustomDrawButtonBase); |
| 69 }; | 45 }; |
| 70 | 46 |
| 71 // CustomDrawButton is a plain button where all its various states are drawn | 47 // CustomDrawButton is a plain button where all its various states are drawn |
| 72 // with static images. In GTK rendering mode, it will show the standard button | 48 // with static images. In GTK rendering mode, it will show the standard button |
| 73 // with GTK |stock_id|. | 49 // with GTK |stock_id|. |
| 74 class CustomDrawButton { | 50 class CustomDrawButton { |
| 75 public: | 51 public: |
| 76 // The constructor takes 4 resource ids. If a resource doesn't exist for a | 52 // The constructor takes 4 resource ids. If a resource doesn't exist for a |
| 77 // button, pass in 0. | 53 // button, pass in 0. |
| 78 CustomDrawButton(int normal_id, | 54 CustomDrawButton(int normal_id, |
| 79 int active_id, | 55 int active_id, |
| 80 int highlight_id, | 56 int highlight_id, |
| 81 int depressed_id, | 57 int depressed_id, |
| 82 const char* stock_id); | 58 const char* stock_id); |
| 83 | 59 explicit CustomDrawButton(const std::string& filename); |
| 84 // Same as above, but uses themed (and possibly tinted) images. | |
| 85 CustomDrawButton(ThemeProvider* theme_provider, | |
| 86 int normal_id, | |
| 87 int active_id, | |
| 88 int highlight_id, | |
| 89 int depressed_id, | |
| 90 const char* stock_id); | |
| 91 | |
| 92 ~CustomDrawButton(); | 60 ~CustomDrawButton(); |
| 93 | 61 |
| 94 void Init(); | |
| 95 | |
| 96 GtkWidget* widget() const { return widget_.get(); } | 62 GtkWidget* widget() const { return widget_.get(); } |
| 97 | 63 |
| 98 gfx::Rect bounds() const { | 64 gfx::Rect bounds() const { |
| 99 return gfx::Rect(widget_->allocation.x, | 65 return gfx::Rect(widget_->allocation.x, |
| 100 widget_->allocation.y, | 66 widget_->allocation.y, |
| 101 widget_->allocation.width, | 67 widget_->allocation.width, |
| 102 widget_->allocation.height); | 68 widget_->allocation.height); |
| 103 } | 69 } |
| 104 | 70 |
| 105 int width() const { return widget_->allocation.width; } | 71 int width() const { return widget_->allocation.width; } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 135 // The stock icon name. | 101 // The stock icon name. |
| 136 const char* gtk_stock_name_; | 102 const char* gtk_stock_name_; |
| 137 | 103 |
| 138 // Whether we have an expose signal handler we may need to remove. | 104 // Whether we have an expose signal handler we may need to remove. |
| 139 bool has_expose_signal_handler_; | 105 bool has_expose_signal_handler_; |
| 140 | 106 |
| 141 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton); | 107 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton); |
| 142 }; | 108 }; |
| 143 | 109 |
| 144 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ | 110 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ |
| OLD | NEW |