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

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

Issue 62154: Implement stop/go button for Linux (Closed)
Patch Set: Add a small DCHECK => DCHECK_NE change. Created 11 years, 8 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_window_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/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "chrome/common/owned_widget_gtk.h" 13 #include "chrome/common/owned_widget_gtk.h"
14 14
15 class NineBox; 15 class NineBox;
16 16
17 // These classes implement two kinds of custom-drawn buttons. They're 17 // These classes implement two kinds of custom-drawn buttons. They're
18 // used on the toolbar and the bookmarks bar. 18 // used on the toolbar and the bookmarks bar.
19 19
20 // CustomDrawButtonBase provides the base for building a custom drawn button.
21 // It handles managing the pixbufs containing all the static images used to draw
22 // the button. It also manages painting these pixbufs.
23 class CustomDrawButtonBase {
24 public:
25 CustomDrawButtonBase(int normal_id,
26 int active_id,
27 int highlight_id,
28 int depressed_id);
29 ~CustomDrawButtonBase();
30
31 GdkPixbuf* pixbufs(int i) const { return pixbufs_[i]; }
32
33 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e);
34
35 private:
36 // We store one GdkPixbuf* for each possible state of the button;
37 // INSENSITIVE is the last available state;
38 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1];
39
40 DISALLOW_COPY_AND_ASSIGN(CustomDrawButtonBase);
41 };
42
20 // CustomDrawButton is a plain button where all its various states are drawn 43 // CustomDrawButton is a plain button where all its various states are drawn
21 // with static images. 44 // with static images.
22 class CustomDrawButton { 45 class CustomDrawButton {
23 public: 46 public:
24 // The constructor takes 4 resource ids. If a resource doesn't exist for a 47 // The constructor takes 4 resource ids. If a resource doesn't exist for a
25 // button, pass in 0. 48 // button, pass in 0.
26 CustomDrawButton(int normal_id, 49 CustomDrawButton(int normal_id,
27 int active_id, 50 int active_id,
28 int highlight_id, 51 int highlight_id,
29 int depressed_id); 52 int depressed_id);
30 explicit CustomDrawButton(const std::string& filename); 53 explicit CustomDrawButton(const std::string& filename);
31 ~CustomDrawButton(); 54 ~CustomDrawButton();
32 55
33 GtkWidget* widget() const { return widget_.get(); } 56 GtkWidget* widget() const { return widget_.get(); }
34 57
35 // This is a convenience function for creating a widget that closes 58 // This is a convenience function for creating a widget that closes
36 // a bar (find bar, download shelf, info bars). The button will be packed in 59 // a bar (find bar, download shelf, info bars). The button will be packed in
37 // |hbox|. 60 // |hbox|.
38 // The caller is responsible for destroying the returned CustomDrawButton. 61 // The caller is responsible for destroying the returned CustomDrawButton.
39 static CustomDrawButton* AddBarCloseButton(GtkWidget* hbox); 62 static CustomDrawButton* AddBarCloseButton(GtkWidget* hbox);
40 63
41 private: 64 private:
42 // Callback for expose, used to draw the custom graphics. 65 // Callback for expose, used to draw the custom graphics.
43 static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e, 66 static gboolean OnExpose(GtkWidget* widget,
67 GdkEventExpose* e,
44 CustomDrawButton* obj); 68 CustomDrawButton* obj);
45 69
46 // The actual button widget. 70 // The actual button widget.
47 OwnedWidgetGtk widget_; 71 OwnedWidgetGtk widget_;
48 72
49 // We store one GdkPixbuf* for each possible state of the button; 73 CustomDrawButtonBase button_base_;
50 // INSENSITIVE is the last available state; 74
51 GdkPixbuf* pixbufs_[GTK_STATE_INSENSITIVE + 1]; 75 DISALLOW_COPY_AND_ASSIGN(CustomDrawButton);
52 }; 76 };
53 77
54 // CustomContainerButton wraps another widget and uses a NineBox of 78 // CustomContainerButton wraps another widget and uses a NineBox of
55 // images to draw a highlight around the edges when you mouse over it. 79 // images to draw a highlight around the edges when you mouse over it.
56 class CustomContainerButton { 80 class CustomContainerButton {
57 public: 81 public:
58 CustomContainerButton(); 82 CustomContainerButton();
59 ~CustomContainerButton(); 83 ~CustomContainerButton();
60 84
61 GtkWidget* widget() const { return widget_.get(); } 85 GtkWidget* widget() const { return widget_.get(); }
62 86
63 private: 87 private:
64 // Callback for expose, used to draw the custom graphics. 88 // Callback for expose, used to draw the custom graphics.
65 static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e, 89 static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e,
66 CustomContainerButton* obj); 90 CustomContainerButton* obj);
67 91
68 // The button widget. 92 // The button widget.
69 OwnedWidgetGtk widget_; 93 OwnedWidgetGtk widget_;
70 94
71 // The theme graphics for when the mouse is over the button. 95 // The theme graphics for when the mouse is over the button.
72 scoped_ptr<NineBox> nine_box_prelight_; 96 scoped_ptr<NineBox> nine_box_prelight_;
73 // The theme graphics for when the button is clicked. 97 // The theme graphics for when the button is clicked.
74 scoped_ptr<NineBox> nine_box_active_; 98 scoped_ptr<NineBox> nine_box_active_;
75 }; 99 };
76 100
77 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_ 101 #endif // CHROME_BROWSER_GTK_CUSTOM_BUTTON_H_
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_window_gtk.cc ('k') | chrome/browser/gtk/custom_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698