Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: chrome/browser/gtk/custom_button.h

Issue 149432: Add button tinting to the toolbar buttons. (Closed)
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/browser_toolbar_gtk.cc ('k') | chrome/browser/gtk/custom_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "chrome/common/owned_widget_gtk.h" 16 #include "chrome/common/owned_widget_gtk.h"
15 17
18 class ThemeProvider;
19
16 // These classes implement two kinds of custom-drawn buttons. They're 20 // These classes implement two kinds of custom-drawn buttons. They're
17 // used on the toolbar and the bookmarks bar. 21 // used on the toolbar and the bookmarks bar.
18 22
19 // CustomDrawButtonBase provides the base for building a custom drawn button. 23 // CustomDrawButtonBase provides the base for building a custom drawn button.
20 // It handles managing the pixbufs containing all the static images used to draw 24 // It handles managing the pixbufs containing all the static images used to draw
21 // the button. It also manages painting these pixbufs. 25 // the button. It also manages painting these pixbufs.
22 class CustomDrawButtonBase { 26 class CustomDrawButtonBase : public NotificationObserver {
23 public: 27 public:
24 CustomDrawButtonBase(int normal_id, 28 // If the images come from ResourceBundle rather than the theme provider,
29 // pass in NULL for |theme_provider|.
30 CustomDrawButtonBase(ThemeProvider* theme_provider,
31 int normal_id,
25 int active_id, 32 int active_id,
26 int highlight_id, 33 int highlight_id,
27 int depressed_id); 34 int depressed_id);
35
28 ~CustomDrawButtonBase(); 36 ~CustomDrawButtonBase();
29 37
30 GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; } 38 GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; }
31 39
32 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e); 40 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e);
33 41
34 void set_paint_override(int state) { paint_override_ = state; } 42 void set_paint_override(int state) { paint_override_ = state; }
35 43
44 // Provide NotificationObserver implementation.
45 virtual void Observe(NotificationType type,
46 const NotificationSource& source,
47 const NotificationDetails& details);
48
36 private: 49 private:
37 // We store one GdkPixbuf* for each possible state of the button; 50 // We store one GdkPixbuf* for each possible state of the button;
38 // INSENSITIVE is the last available state; 51 // INSENSITIVE is the last available state;
39 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1]; 52 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1];
40 53
41 // If non-negative, the state to paint the button. 54 // If non-negative, the state to paint the button.
42 int paint_override_; 55 int paint_override_;
43 56
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
44 DISALLOW_COPY_AND_ASSIGN(CustomDrawButtonBase); 68 DISALLOW_COPY_AND_ASSIGN(CustomDrawButtonBase);
45 }; 69 };
46 70
47 // CustomDrawButton is a plain button where all its various states are drawn 71 // CustomDrawButton is a plain button where all its various states are drawn
48 // with static images. In GTK rendering mode, it will show the standard button 72 // with static images. In GTK rendering mode, it will show the standard button
49 // with GTK |stock_id|. 73 // with GTK |stock_id|.
50 class CustomDrawButton { 74 class CustomDrawButton {
51 public: 75 public:
52 // The constructor takes 4 resource ids. If a resource doesn't exist for a 76 // The constructor takes 4 resource ids. If a resource doesn't exist for a
53 // button, pass in 0. 77 // button, pass in 0.
54 CustomDrawButton(int normal_id, 78 CustomDrawButton(int normal_id,
55 int active_id, 79 int active_id,
56 int highlight_id, 80 int highlight_id,
57 int depressed_id, 81 int depressed_id,
58 const char* stock_id); 82 const char* stock_id);
59 explicit CustomDrawButton(const std::string& filename); 83
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
60 ~CustomDrawButton(); 92 ~CustomDrawButton();
61 93
94 void Init();
95
62 GtkWidget* widget() const { return widget_.get(); } 96 GtkWidget* widget() const { return widget_.get(); }
63 97
64 gfx::Rect bounds() const { 98 gfx::Rect bounds() const {
65 return gfx::Rect(widget_->allocation.x, 99 return gfx::Rect(widget_->allocation.x,
66 widget_->allocation.y, 100 widget_->allocation.y,
67 widget_->allocation.width, 101 widget_->allocation.width,
68 widget_->allocation.height); 102 widget_->allocation.height);
69 } 103 }
70 104
71 int width() const { return widget_->allocation.width; } 105 int width() const { return widget_->allocation.width; }
(...skipping 29 matching lines...) Expand all
101 // The stock icon name. 135 // The stock icon name.
102 const char* gtk_stock_name_; 136 const char* gtk_stock_name_;
103 137
104 // Whether we have an expose signal handler we may need to remove. 138 // Whether we have an expose signal handler we may need to remove.
105 bool has_expose_signal_handler_; 139 bool has_expose_signal_handler_;
106 140
107 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton); 141 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton);
108 }; 142 };
109 143
110 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ 144 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_toolbar_gtk.cc ('k') | chrome/browser/gtk/custom_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698