summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.cc4
-rw-r--r--chrome/browser/browser.h2
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc211
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.h148
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc58
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h14
-rw-r--r--chrome/browser/gtk/custom_button.cc19
-rw-r--r--chrome/browser/gtk/custom_button.h9
8 files changed, 444 insertions, 21 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 5d2fa70..727d128 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1021,12 +1021,10 @@ void Browser::OpenBugReportDialog() {
#endif // #if defined(OS_WIN)
-#if defined(OS_WIN) || defined(OS_MACOSX)
void Browser::ToggleBookmarkBar() {
UserMetrics::RecordAction(L"ShowBookmarksBar", profile_);
window_->ToggleBookmarkBar();
}
-#endif
#if defined(OS_WIN)
void Browser::OpenBookmarkManager() {
@@ -1271,9 +1269,7 @@ void Browser::ExecuteCommandWithDisposition(
case IDC_REPORT_BUG: OpenBugReportDialog(); break;
#endif
-#if defined(OS_WIN) || defined(OS_MACOSX)
case IDC_SHOW_BOOKMARK_BAR: ToggleBookmarkBar(); break;
-#endif
#if defined(OS_WIN)
case IDC_SHOW_BOOKMARK_MANAGER: OpenBookmarkManager(); break;
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 57e7171..e16a510 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -332,9 +332,7 @@ class Browser : public TabStripModelDelegate,
void OpenBugReportDialog();
#endif // defined(OS_WIN)
-#if defined(OS_WIN) || defined(OS_MACOSX)
void ToggleBookmarkBar();
-#endif
#if defined(OS_WIN)
void OpenBookmarkManager();
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
new file mode 100644
index 0000000..2342416
--- /dev/null
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -0,0 +1,211 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/bookmark_bar_gtk.h"
+
+#include "base/gfx/gtk_util.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/gtk/custom_button.h"
+#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/gfx/text_elider.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4);
+
+// Padding around the container.
+const int kBarPadding = 2;
+
+// Maximum number of characters on a bookmark button.
+const int kMaxCharsOnAButton = 15;
+
+} // namespace
+
+BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser)
+ : profile_(NULL),
+ page_navigator_(NULL),
+ browser_(browser),
+ model_(NULL),
+ instructions_(NULL),
+ show_instructions_(true) {
+ Init(profile);
+ SetProfile(profile);
+}
+
+BookmarkBarGtk::~BookmarkBarGtk() {
+ if (model_)
+ model_->RemoveObserver(this);
+
+ RemoveAllBookmarkButtons();
+ container_.Destroy();
+}
+
+void BookmarkBarGtk::SetProfile(Profile* profile) {
+ DCHECK(profile);
+ if (profile_ == profile)
+ return;
+
+ RemoveAllBookmarkButtons();
+
+ profile_ = profile;
+
+ if (model_)
+ model_->RemoveObserver(this);
+
+ // TODO(erg): Add the other bookmarked button, disabled.
+
+ // TODO(erg): Handle extensions
+
+ model_ = profile_->GetBookmarkModel();
+ model_->AddObserver(this);
+ if (model_->IsLoaded())
+ Loaded(model_);
+
+ // else case: we'll receive notification back from the BookmarkModel when done
+ // loading, then we'll populate the bar.
+}
+
+void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) {
+ page_navigator_ = navigator;
+}
+
+void BookmarkBarGtk::Init(Profile* profile) {
+ bookmark_hbox_ = gtk_hbox_new(FALSE, 0);
+ container_.Own(gfx::CreateGtkBorderBin(bookmark_hbox_, &kBackgroundColor,
+ kBarPadding, kBarPadding, kBarPadding, kBarPadding));
+
+ instructions_ =
+ gtk_label_new(
+ WideToUTF8(l10n_util::GetString(IDS_BOOKMARKS_NO_ITEMS)).c_str());
+ gtk_box_pack_start(GTK_BOX(bookmark_hbox_), instructions_,
+ FALSE, FALSE, 0);
+}
+
+void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) {
+ gtk_box_pack_start(GTK_BOX(box), container_.get(), FALSE, FALSE, 0);
+}
+
+void BookmarkBarGtk::Show() {
+ gtk_widget_show_all(container_.get());
+
+ // Maybe show the instructions
+ if (show_instructions_) {
+ gtk_widget_show(instructions_);
+ } else {
+ gtk_widget_hide(instructions_);
+ }
+}
+
+void BookmarkBarGtk::Hide() {
+ gtk_widget_hide_all(container_.get());
+}
+
+bool BookmarkBarGtk::OnNewTabPage() {
+ return (browser_ && browser_->GetSelectedTabContents() &&
+ browser_->GetSelectedTabContents()->IsBookmarkBarAlwaysVisible());
+}
+
+void BookmarkBarGtk::Loaded(BookmarkModel* model) {
+ RemoveAllBookmarkButtons();
+
+ BookmarkNode* node = model_->GetBookmarkBarNode();
+ DCHECK(node && model_->other_node());
+
+ // Create a button for each of the children on the bookmark bar.
+ for (int i = 0; i < node->GetChildCount(); ++i) {
+ CustomContainerButton* button = CreateBookmarkButton(node->GetChild(i));
+ gtk_box_pack_start(GTK_BOX(bookmark_hbox_), button->widget(),
+ FALSE, FALSE, 0);
+ current_bookmark_buttons_.push_back(button);
+ }
+
+ show_instructions_ = (node->GetChildCount() == 0);
+ if (show_instructions_) {
+ gtk_widget_show(instructions_);
+ } else {
+ gtk_widget_hide(instructions_);
+ }
+
+ // TODO(erg): Reenable the other bookmarks button here once it exists.
+}
+
+void BookmarkBarGtk::RemoveAllBookmarkButtons() {
+ for (std::vector<CustomContainerButton*>::const_iterator it =
+ current_bookmark_buttons_.begin();
+ it != current_bookmark_buttons_.end(); ++it) {
+ delete *it;
+ }
+
+ current_bookmark_buttons_.clear();
+}
+
+bool BookmarkBarGtk::IsAlwaysShown() {
+ return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
+}
+
+CustomContainerButton* BookmarkBarGtk::CreateBookmarkButton(
+ BookmarkNode* node) {
+ if (node->is_url()) {
+ CustomContainerButton* button = new CustomContainerButton;
+
+ gtk_widget_set_tooltip_text(button->widget(), BuildTooltip(node).c_str());
+ gtk_button_set_label(GTK_BUTTON(button->widget()),
+ WideToUTF8(node->GetTitle()).c_str());
+ // TODO(erg): Consider a soft maximum instead of this hard 15.
+ gtk_label_set_max_width_chars(
+ GTK_LABEL(gtk_bin_get_child(GTK_BIN(button->widget()))),
+ kMaxCharsOnAButton);
+
+ // Connect to 'button-release-event' instead of 'clicked' because we need
+ // to access to the modifier keys and we do different things on each
+ // button.
+ g_signal_connect(G_OBJECT(button->widget()), "button-release-event",
+ G_CALLBACK(OnButtonReleased), this);
+ GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS);
+
+ g_object_set_data(G_OBJECT(button->widget()), "bookmark-node", node);
+
+ gtk_widget_show_all(button->widget());
+
+ return button;
+ } else {
+ NOTIMPLEMENTED();
+ return NULL;
+ }
+}
+
+std::string BookmarkBarGtk::BuildTooltip(BookmarkNode* node) {
+ // TODO(erg): Actually build the tooltip. For now, we punt and just return
+ // the URL.
+ return node->GetURL().possibly_invalid_spec();
+}
+
+gboolean BookmarkBarGtk::OnButtonReleased(GtkWidget* sender,
+ GdkEventButton* event,
+ BookmarkBarGtk* bar) {
+ gpointer user_data = g_object_get_data(G_OBJECT(sender), "bookmark-node");
+ BookmarkNode* node = static_cast<BookmarkNode*>(user_data);
+ DCHECK(node);
+ DCHECK(bar->page_navigator_);
+
+ if (node->is_url()) {
+ bar->page_navigator_->OpenURL(
+ node->GetURL(), GURL(),
+ // TODO(erg): Detect the disposition based on the click type.
+ CURRENT_TAB,
+ PageTransition::AUTO_BOOKMARK);
+ } else {
+ // TODO(erg): Handle folders and extensions.
+ }
+
+ UserMetrics::RecordAction(L"ClickedBookmarkBarURLButton", bar->profile_);
+
+ // Allow other handlers to run so the button state is updated correctly.
+ return FALSE;
+}
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h
new file mode 100644
index 0000000..003bf4b
--- /dev/null
+++ b/chrome/browser/gtk/bookmark_bar_gtk.h
@@ -0,0 +1,148 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GTK_BOOKMARK_BAR_GTK_H_
+#define CHROME_BROWSER_GTK_BOOKMARK_BAR_GTK_H_
+
+#include <gtk/gtk.h>
+
+#include <string>
+#include <vector>
+
+#include "chrome/common/owned_widget_gtk.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+
+class Browser;
+class CustomContainerButton;
+class PageNavigator;
+class Profile;
+
+class BookmarkBarGtk : public BookmarkModelObserver {
+ public:
+ explicit BookmarkBarGtk(Profile* proifle, Browser* browser);
+ virtual ~BookmarkBarGtk();
+
+ // Resets the profile. This removes any buttons for the current profile and
+ // recreates the models.
+ void SetProfile(Profile* profile);
+
+ // Returns the current profile.
+ Profile* GetProfile() { return profile_; }
+
+ // Returns the current browser.
+ Browser* browser() const { return browser_; }
+
+ // Sets the PageNavigator that is used when the user selects an entry on
+ // the bookmark bar.
+ void SetPageNavigator(PageNavigator* navigator);
+
+ // Create the contents of the bookmark bar.
+ void Init(Profile* profile);
+
+ // Adds this GTK toolbar into a sizing box.
+ void AddBookmarkbarToBox(GtkWidget* box);
+
+ // Whether the current page is the New Tag Page (which requires different
+ // rendering).
+ bool OnNewTabPage();
+
+ // Change the visibility of the bookmarks bar. (Starts out hidden, per GTK's
+ // default behaviour).
+ void Show();
+ void Hide();
+
+ // Returns true if the bookmarks bar preference is set to 'always show'.
+ bool IsAlwaysShown();
+
+ private:
+ // Helper function which destroys all the bookmark buttons in
+ // |current_bookmark_buttons_|.
+ void RemoveAllBookmarkButtons();
+
+ // Overridden from BookmarkModelObserver:
+
+ // Invoked when the bookmark bar model has finished loading. Creates a button
+ // for each of the children of the root node from the model.
+ virtual void Loaded(BookmarkModel* model);
+
+ // Invoked when the model is being deleted.
+ virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {
+ NOTIMPLEMENTED();
+ }
+
+ // Invoked when a node has moved.
+ virtual void BookmarkNodeMoved(BookmarkModel* model,
+ BookmarkNode* old_parent,
+ int old_index,
+ BookmarkNode* new_parent,
+ int new_index) {
+ NOTIMPLEMENTED();
+ }
+
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index) {
+ NOTIMPLEMENTED();
+ }
+
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ BookmarkNode* parent,
+ int index) {
+ NOTIMPLEMENTED();
+ }
+
+ virtual void BookmarkNodeChanged(BookmarkModel* model,
+ BookmarkNode* node) {
+ NOTIMPLEMENTED();
+ }
+
+ // Invoked when a favicon has finished loading.
+ virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
+ BookmarkNode* node) {
+ NOTIMPLEMENTED();
+ }
+
+ virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
+ BookmarkNode* node) {
+ NOTIMPLEMENTED();
+ }
+
+ private:
+ CustomContainerButton* CreateBookmarkButton(BookmarkNode* node);
+
+ std::string BuildTooltip(BookmarkNode* node);
+
+ static gboolean OnButtonReleased(GtkWidget* sender, GdkEventButton* event,
+ BookmarkBarGtk* bar);
+
+ Profile* profile_;
+
+ // Used for opening urls.
+ PageNavigator* page_navigator_;
+
+ Browser* browser_;
+
+ // Model providing details as to the starred entries/groups that should be
+ // shown. This is owned by the Profile.
+ BookmarkModel* model_;
+
+ // Top level container that contains |bookmark_hbox_| and spacers.
+ OwnedWidgetGtk container_;
+
+ // Container that has all the individual members of
+ // |current_bookmark_buttons_| as children.
+ GtkWidget* bookmark_hbox_;
+
+ // A GtkLabel to display when there are no bookmark buttons to display.
+ GtkWidget* instructions_;
+
+ // Whether we should show the instructional text in the bookmark bar.
+ bool show_instructions_;
+
+ // Bookmark buttons. We keep these references so we can deallocate them
+ // properly.
+ std::vector<CustomContainerButton*> current_bookmark_buttons_;
+};
+
+#endif // CHROME_BROWSER_GTK_BOOKMARK_BAR_GTK_H_
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index e8887a6..478eda4 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -14,9 +14,11 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/find_bar_controller.h"
+#include "chrome/browser/gtk/bookmark_bar_gtk.h"
#include "chrome/browser/gtk/browser_toolbar_gtk.h"
#include "chrome/browser/gtk/find_bar_gtk.h"
#include "chrome/browser/gtk/status_bubble_gtk.h"
@@ -189,6 +191,9 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
toolbar_->Init(browser_->profile(), window_);
toolbar_->AddToolbarToBox(content_vbox_);
+ bookmark_bar_.reset(new BookmarkBarGtk(browser_->profile(), browser_.get()));
+ bookmark_bar_->AddBookmarkbarToBox(content_vbox_);
+
// Insert a border between the toolbar and the web contents.
GtkWidget* border = gtk_event_box_new();
gtk_widget_set_size_request(border, -1, 1);
@@ -217,9 +222,18 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
gtk_widget_show(content_vbox_);
gtk_widget_show(window_vbox_);
browser_->tabstrip_model()->AddObserver(this);
+
+ NotificationService* ns = NotificationService::current();
+ ns->AddObserver(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
+ NotificationService::AllSources());
}
BrowserWindowGtk::~BrowserWindowGtk() {
+ NotificationService* ns = NotificationService::current();
+ ns->RemoveObserver(this,
+ NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
+ NotificationService::AllSources());
+
browser_->tabstrip_model()->RemoveObserver(this);
}
@@ -379,8 +393,8 @@ void BrowserWindowGtk::FocusToolbar() {
}
bool BrowserWindowGtk::IsBookmarkBarVisible() const {
- NOTIMPLEMENTED();
- return false;
+ return browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) &&
+ bookmark_bar_.get();
}
gfx::Rect BrowserWindowGtk::GetRootWindowResizerRect() const {
@@ -388,7 +402,7 @@ gfx::Rect BrowserWindowGtk::GetRootWindowResizerRect() const {
}
void BrowserWindowGtk::ToggleBookmarkBar() {
- NOTIMPLEMENTED();
+ bookmark_utils::ToggleWhenVisible(browser_->profile());
}
void BrowserWindowGtk::ShowFindBar() {
@@ -441,6 +455,16 @@ void BrowserWindowGtk::ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
NOTIMPLEMENTED();
}
+void BrowserWindowGtk::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED) {
+ MaybeShowBookmarkBar(browser_->GetSelectedTabContents());
+ } else {
+ NOTREACHED() << "Got a notification we didn't register for!";
+ }
+}
+
void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) {
// We use index here rather than comparing |contents| because by this time
// the model has already removed |contents| from its list, so
@@ -484,12 +508,40 @@ void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents,
UpdateTitleBar();
toolbar_->SetProfile(new_contents->profile());
UpdateToolbar(new_contents, true);
+ UpdateUIForContents(new_contents);
if (find_bar_controller_.get())
find_bar_controller_->ChangeWebContents(new_contents->AsWebContents());
}
void BrowserWindowGtk::TabStripEmpty() {
+ UpdateUIForContents(NULL);
+}
+
+void BrowserWindowGtk::MaybeShowBookmarkBar(TabContents* contents) {
+ bool show_bar = false;
+
+ if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)
+ && contents) {
+ bookmark_bar_->SetProfile(contents->profile());
+ bookmark_bar_->SetPageNavigator(contents);
+ show_bar = true;
+ }
+
+ if (show_bar) {
+ PrefService* prefs = contents->profile()->GetPrefs();
+ show_bar = prefs->GetBoolean(prefs::kShowBookmarkBar);
+ }
+
+ if (show_bar) {
+ bookmark_bar_->Show();
+ } else {
+ bookmark_bar_->Hide();
+ }
+}
+
+void BrowserWindowGtk::UpdateUIForContents(TabContents* contents) {
+ MaybeShowBookmarkBar(contents);
}
void BrowserWindowGtk::DestroyBrowser() {
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index 4825499..f435202 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -12,8 +12,10 @@
#include "base/task.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/common/notification_observer.h"
#include "chrome/views/widget/widget_gtk.h"
+class BookmarkBarGtk;
class BrowserToolbarGtk;
class FindBarController;
class LocationBar;
@@ -27,6 +29,7 @@ class TabStripGtk;
// it needs to manipulate the window.
class BrowserWindowGtk : public BrowserWindow,
+ public NotificationObserver,
public TabStripModelObserver {
public:
explicit BrowserWindowGtk(Browser* browser);
@@ -76,6 +79,11 @@ class BrowserWindowGtk : public BrowserWindow,
virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
void* parent_window);
+ // Overridden from NotificationObserver:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
// Overridden from TabStripModelObserver:
virtual void TabDetachedAt(TabContents* contents, int index);
virtual void TabSelectedAt(TabContents* old_contents,
@@ -84,6 +92,9 @@ class BrowserWindowGtk : public BrowserWindow,
bool user_gesture);
virtual void TabStripEmpty();
+ void MaybeShowBookmarkBar(TabContents* contents);
+ void UpdateUIForContents(TabContents* contents);
+
void OnBoundsChanged(const gfx::Rect& bounds);
void OnStateChanged(GdkWindowState state);
@@ -133,6 +144,9 @@ class BrowserWindowGtk : public BrowserWindow,
// The object that manages all of the widgets in the toolbar.
scoped_ptr<BrowserToolbarGtk> toolbar_;
+ // The object that manages the bookmark bar.
+ scoped_ptr<BookmarkBarGtk> bookmark_bar_;
+
// The status bubble manager. Always non-NULL.
scoped_ptr<StatusBubbleGtk> status_bubble_;
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc
index 5609937..e3d45d2 100644
--- a/chrome/browser/gtk/custom_button.cc
+++ b/chrome/browser/gtk/custom_button.cc
@@ -12,7 +12,7 @@
CustomDrawButton::CustomDrawButton(int normal_id,
int active_id, int highlight_id, int depressed_id) {
- widget_ = gtk_button_new();
+ widget_.Own(gtk_button_new());
// Load the button images from the resource bundle.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -24,14 +24,14 @@ CustomDrawButton::CustomDrawButton(int normal_id,
pixbufs_[GTK_STATE_INSENSITIVE] =
depressed_id ? rb.LoadPixbuf(depressed_id) : NULL;
- gtk_widget_set_size_request(widget_,
+ gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(pixbufs_[0]),
gdk_pixbuf_get_height(pixbufs_[0]));
- gtk_widget_set_app_paintable(widget_, TRUE);
+ gtk_widget_set_app_paintable(widget_.get(), TRUE);
// We effectively double-buffer by virtue of having only one image...
- gtk_widget_set_double_buffered(widget_, FALSE);
- g_signal_connect(G_OBJECT(widget_), "expose-event",
+ gtk_widget_set_double_buffered(widget_.get(), FALSE);
+ g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
G_CALLBACK(OnExpose), this);
}
@@ -40,6 +40,8 @@ CustomDrawButton::~CustomDrawButton() {
if (pixbufs_[i])
gdk_pixbuf_unref(pixbufs_[i]);
}
+
+ widget_.Destroy();
}
// static
@@ -92,13 +94,14 @@ CustomContainerButton::CustomContainerButton() {
images[i++] = rb.LoadPixbuf(IDR_TEXTBUTTON_BOTTOM_RIGHT_P);
nine_box_active_.reset(new NineBox(images));
- widget_ = gtk_button_new();
- gtk_widget_set_app_paintable(widget_, TRUE);
- g_signal_connect(G_OBJECT(widget_), "expose-event",
+ widget_.Own(gtk_button_new());
+ gtk_widget_set_app_paintable(widget_.get(), TRUE);
+ g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
G_CALLBACK(OnExpose), this);
}
CustomContainerButton::~CustomContainerButton() {
+ widget_.Destroy();
}
// static
diff --git a/chrome/browser/gtk/custom_button.h b/chrome/browser/gtk/custom_button.h
index 8951aaf..2bc6cfc 100644
--- a/chrome/browser/gtk/custom_button.h
+++ b/chrome/browser/gtk/custom_button.h
@@ -10,6 +10,7 @@
#include <string>
#include "base/scoped_ptr.h"
+#include "chrome/common/owned_widget_gtk.h"
class NineBox;
@@ -29,7 +30,7 @@ class CustomDrawButton {
explicit CustomDrawButton(const std::string& filename);
~CustomDrawButton();
- GtkWidget* widget() const { return widget_; }
+ GtkWidget* widget() const { return widget_.get(); }
private:
// Callback for expose, used to draw the custom graphics.
@@ -37,7 +38,7 @@ class CustomDrawButton {
CustomDrawButton* obj);
// The actual button widget.
- GtkWidget* widget_;
+ OwnedWidgetGtk widget_;
// We store one GdkPixbuf* for each possible state of the button;
// INSENSITIVE is the last available state;
@@ -51,7 +52,7 @@ class CustomContainerButton {
CustomContainerButton();
~CustomContainerButton();
- GtkWidget* widget() const { return widget_; }
+ GtkWidget* widget() const { return widget_.get(); }
private:
// Callback for expose, used to draw the custom graphics.
@@ -59,7 +60,7 @@ class CustomContainerButton {
CustomContainerButton* obj);
// The button widget.
- GtkWidget* widget_;
+ OwnedWidgetGtk widget_;
// The theme graphics for when the mouse is over the button.
scoped_ptr<NineBox> nine_box_prelight_;