summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-16 18:30:47 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-16 18:30:47 +0000
commitc0b99038c58d79f7c1032f35dfb0eb62279a2d0d (patch)
tree92fbe908e564e72c45d206298a80236340a1034a /chrome/browser
parent027ec5f2dc1e9a26aea297623f1784592de7d562 (diff)
downloadchromium_src-c0b99038c58d79f7c1032f35dfb0eb62279a2d0d.zip
chromium_src-c0b99038c58d79f7c1032f35dfb0eb62279a2d0d.tar.gz
chromium_src-c0b99038c58d79f7c1032f35dfb0eb62279a2d0d.tar.bz2
Move a bunch of our GTK code that was previous manually handling references (and often doing it incorrect / leaking) to use an OwnedWidgetGtk.
Review URL: http://codereview.chromium.org/48007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc54
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h5
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc13
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc15
-rw-r--r--chrome/browser/gtk/find_bar_gtk.h13
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc15
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h5
-rw-r--r--chrome/browser/gtk/menu_gtk.cc17
-rw-r--r--chrome/browser/gtk/menu_gtk.h6
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_gtk.cc26
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_gtk.h5
-rw-r--r--chrome/browser/tab_contents/web_contents_view_gtk.cc15
-rw-r--r--chrome/browser/tab_contents/web_contents_view_gtk.h3
13 files changed, 97 insertions, 95 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index d957f47..4a3a486 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -33,8 +33,7 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
ToolbarModel* toolbar_model,
Profile* profile,
CommandUpdater* command_updater)
- : text_view_(NULL),
- tag_table_(NULL),
+ : tag_table_(NULL),
text_buffer_(NULL),
base_tag_(NULL),
secure_scheme_tag_(NULL),
@@ -61,8 +60,8 @@ AutocompleteEditViewGtk::~AutocompleteEditViewGtk() {
model_.release();
// We own our widget and TextView related objects.
- if (text_view_) { // Init() has been called.
- gtk_widget_destroy(text_view_);
+ if (text_view_.get()) { // Init() has been called.
+ text_view_.Destroy();
g_object_unref(text_buffer_);
g_object_unref(tag_table_);
// The tags we created are owned by the tag_table, and should be destroyed
@@ -76,20 +75,19 @@ void AutocompleteEditViewGtk::Init() {
// the other objects adds a reference; it doesn't adopt them.
tag_table_ = gtk_text_tag_table_new();
text_buffer_ = gtk_text_buffer_new(tag_table_);
- text_view_ = gtk_text_view_new_with_buffer(text_buffer_);
- g_object_ref_sink(text_view_); // We want to own the widget.
+ text_view_.Own(gtk_text_view_new_with_buffer(text_buffer_));
- gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_view_), 4);
- gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_view_), 4);
+ gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_view_.get()), 4);
+ gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_view_.get()), 4);
// TODO(deanm): This is a super lame attempt to vertically center our single
// line of text in a multiline edit control. Mannnn.
- gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(text_view_), 4);
+ gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(text_view_.get()), 4);
// TODO(deanm): This will probably have to be handled differently with the
// tab to search business. Maybe we should just eat the tab characters.
// We want the tab key to move focus, not insert a tab.
- gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(text_view_), false);
+ gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(text_view_.get()), false);
base_tag_ = gtk_text_buffer_create_tag(text_buffer_,
NULL, "foreground", kTextBaseColor, NULL);
@@ -107,26 +105,26 @@ void AutocompleteEditViewGtk::Init() {
g_signal_connect(text_buffer_, "end-user-action",
G_CALLBACK(&HandleEndUserActionThunk), this);
// We connect to key press and release for special handling of a few keys.
- g_signal_connect(text_view_, "key-press-event",
+ g_signal_connect(text_view_.get(), "key-press-event",
G_CALLBACK(&HandleKeyPressThunk), this);
- g_signal_connect(text_view_, "key-release-event",
+ g_signal_connect(text_view_.get(), "key-release-event",
G_CALLBACK(&HandleKeyReleaseThunk), this);
- g_signal_connect(text_view_, "size-request",
+ g_signal_connect(text_view_.get(), "size-request",
G_CALLBACK(&HandleViewSizeRequest), this);
- g_signal_connect(text_view_, "button-press-event",
+ g_signal_connect(text_view_.get(), "button-press-event",
G_CALLBACK(&HandleViewButtonPressThunk), this);
- g_signal_connect(text_view_, "focus-in-event",
+ g_signal_connect(text_view_.get(), "focus-in-event",
G_CALLBACK(&HandleViewFocusInThunk), this);
- g_signal_connect(text_view_, "focus-out-event",
+ g_signal_connect(text_view_.get(), "focus-out-event",
G_CALLBACK(&HandleViewFocusOutThunk), this);
// NOTE: The GtkTextView documentation asks you not to connect to this
// signal, but it is very convenient and clean for catching up/down.
- g_signal_connect(text_view_, "move-cursor",
+ g_signal_connect(text_view_.get(), "move-cursor",
G_CALLBACK(&HandleViewMoveCursorThunk), this);
}
void AutocompleteEditViewGtk::SetFocus() {
- gtk_widget_grab_focus(text_view_);
+ gtk_widget_grab_focus(text_view_.get());
}
void AutocompleteEditViewGtk::SaveStateToTab(TabContents* tab) {
@@ -308,9 +306,9 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() {
}
void AutocompleteEditViewGtk::BottomLeftPosWidth(int* x, int* y, int* width) {
- gdk_window_get_origin(text_view_->window, x, y);
- *y += text_view_->allocation.height;
- *width = text_view_->allocation.width;
+ gdk_window_get_origin(text_view_.get()->window, x, y);
+ *y += text_view_.get()->allocation.height;
+ *width = text_view_.get()->allocation.width;
}
void AutocompleteEditViewGtk::HandleBeginUserAction() {
@@ -353,7 +351,7 @@ gboolean AutocompleteEditViewGtk::HandleKeyPress(GtkWidget* widget,
(event->keyval == GDK_Escape && event->state == 0)) {
// Handle IME. This is basically taken from GtkTextView and reworked a bit.
GtkTextIter iter;
- GtkTextView* text_view = GTK_TEXT_VIEW(text_view_);
+ GtkTextView* text_view = GTK_TEXT_VIEW(text_view_.get());
GtkTextMark* insert = gtk_text_buffer_get_insert(text_buffer_);
gtk_text_buffer_get_iter_at_mark(text_buffer_, &iter, insert);
gboolean can_insert = gtk_text_iter_can_insert(&iter, text_view->editable);
@@ -405,13 +403,13 @@ gboolean AutocompleteEditViewGtk::HandleViewButtonPress(GdkEventButton* event) {
// will cause us to become focused. We call GtkTextView's default handler
// and then stop propagation. This allows us to run our code after the
// default handler, even if that handler stopped propagation.
- if (GTK_WIDGET_HAS_FOCUS(text_view_))
+ if (GTK_WIDGET_HAS_FOCUS(text_view_.get()))
return FALSE; // Continue to propagate into the GtkTextView handler.
// Call the GtkTextView default handler, ignoring the fact that it will
// likely have told us to stop propagating. We want to handle selection.
- GtkWidgetClass* klass = GTK_WIDGET_GET_CLASS(text_view_);
- klass->button_press_event(text_view_, event);
+ GtkWidgetClass* klass = GTK_WIDGET_GET_CLASS(text_view_.get());
+ klass->button_press_event(text_view_.get(), event);
// Select the full input when we get focus.
SelectAll(false);
@@ -421,7 +419,7 @@ gboolean AutocompleteEditViewGtk::HandleViewButtonPress(GdkEventButton* event) {
// code it will skip an important loop. Use -1 to achieve the same.
GtkTextIter start, end;
gtk_text_buffer_get_bounds(text_buffer_, &start, &end);
- gtk_text_view_move_visually(GTK_TEXT_VIEW(text_view_), &start, -1);
+ gtk_text_view_move_visually(GTK_TEXT_VIEW(text_view_.get()), &start, -1);
return TRUE; // Don't continue, we called the default handler already.
}
@@ -450,7 +448,7 @@ void AutocompleteEditViewGtk::HandleViewMoveCursor(
model_->OnUpOrDownKeyPressed(count);
// move-cursor doesn't use a signal accumulator on the return value (it
// just ignores them), so we have to stop the propagation.
- g_signal_stop_emission_by_name(text_view_, "move-cursor");
+ g_signal_stop_emission_by_name(text_view_.get(), "move-cursor");
return;
}
// Propagate into GtkTextView.
@@ -530,7 +528,7 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() {
gtk_text_buffer_apply_tag(text_buffer_, insecure_scheme_tag_,
&start, &end);
}
- gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, background);
+ gtk_widget_modify_base(text_view_.get(), GTK_STATE_NORMAL, background);
}
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 6f14da9..833f579 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -12,6 +12,7 @@
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/toolbar_model.h"
+#include "chrome/common/owned_widget_gtk.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/window_open_disposition.h"
@@ -34,7 +35,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
// Initialize, create the underlying widgets, etc.
void Init();
- GtkWidget* widget() { return text_view_; }
+ GtkWidget* widget() { return text_view_.get(); }
// Grab keyboard input focus, putting focus on the location widget.
void SetFocus();
@@ -182,7 +183,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
// Internally invoked whenever the text changes in some way.
void TextChanged();
- GtkWidget* text_view_;
+ OwnedWidgetGtk text_view_;
GtkTextTagTable* tag_table_;
GtkTextBuffer* text_buffer_;
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 59bd60c..56745bd 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -170,8 +170,8 @@ void BrowserWindowGtk::Init() {
find_bar_controller_.reset(new FindBarController(find_bar_gtk));
find_bar_gtk->set_find_bar_controller(find_bar_controller_.get());
- contents_container_.reset(new TabContentsContainerGtk(
- find_bar_gtk->gtk_widget()));
+ contents_container_.reset(
+ new TabContentsContainerGtk(find_bar_gtk->widget()));
contents_container_->AddContainerToBox(vbox_);
@@ -201,14 +201,14 @@ void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) {
}
void BrowserWindowGtk::Close() {
- if (!window_)
- return;
-
// TODO(tc): Once the tab strip model is hooked up, this call can be removed.
// It should get called by TabDetachedAt when the window is being closed, but
// we don't have a TabStripModel yet.
find_bar_controller_->ChangeWebContents(NULL);
+ if (!window_)
+ return;
+
GtkWidget* window = GTK_WIDGET(window_);
// To help catch bugs in any event handlers that might get fired during the
// destruction, set window_ to NULL before any handlers will run.
@@ -248,6 +248,9 @@ void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) {
}
void BrowserWindowGtk::UpdateTitleBar() {
+ if (!window_)
+ return;
+
std::wstring title = browser_->GetCurrentPageTitle();
gtk_window_set_title(window_, WideToUTF8(title).c_str());
if (browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) {
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index 2398770..f4dc247 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -28,11 +28,12 @@ gboolean KeyPressEvent(GtkWindow* window, GdkEventKey* event,
}
FindBarGtk::FindBarGtk() {
+ // TODO(tc): Pull out widget creation into an Init() method.
find_text_ = gtk_entry_new();
gtk_widget_show(find_text_);
- container_ = gtk_hbox_new(false, 2);
- gtk_box_pack_end(GTK_BOX(container_), find_text_, FALSE, FALSE, 0);
+ container_.Own(gtk_hbox_new(false, 2));
+ gtk_box_pack_end(GTK_BOX(container_.get()), find_text_, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(find_text_), "changed",
G_CALLBACK(EntryContentsChanged), this);
@@ -40,15 +41,19 @@ FindBarGtk::FindBarGtk() {
G_CALLBACK(KeyPressEvent), this);
}
+FindBarGtk::~FindBarGtk() {
+ container_.Destroy();
+}
+
void FindBarGtk::Show() {
// TODO(tc): This should be an animated slide in.
- gtk_widget_show(container_);
+ gtk_widget_show(container_.get());
gtk_widget_grab_focus(find_text_);
}
void FindBarGtk::Hide(bool animate) {
// TODO(tc): Animated slide away.
- gtk_widget_hide(container_);
+ gtk_widget_hide(container_.get());
}
void FindBarGtk::SetFocusAndSelection() {
@@ -76,7 +81,7 @@ void FindBarGtk::SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) {
}
bool FindBarGtk::IsFindBarVisible() {
- return true;
+ return GTK_WIDGET_VISIBLE(container_.get());
}
void FindBarGtk::RestoreSavedFocus() {
diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h
index 11439fb..a9f0ca7 100644
--- a/chrome/browser/gtk/find_bar_gtk.h
+++ b/chrome/browser/gtk/find_bar_gtk.h
@@ -5,13 +5,14 @@
#ifndef CHROME_BROWSER_GTK_FIND_BAR_GTK_H_
#define CHROME_BROWSER_GTK_FIND_BAR_GTK_H_
-#include "base/basictypes.h"
-#include "chrome/browser/find_bar.h"
-
#include <gtk/gtk.h>
#include <string>
+#include "base/basictypes.h"
+#include "chrome/browser/find_bar.h"
+#include "chrome/common/owned_widget_gtk.h"
+
class FindBarController;
class TabContentsContainerGtk;
class WebContents;
@@ -21,7 +22,7 @@ class WebContents;
class FindBarGtk : public FindBar {
public:
FindBarGtk();
- virtual ~FindBarGtk() { }
+ virtual ~FindBarGtk();
void set_find_bar_controller(FindBarController* find_bar_controller) {
find_bar_controller_ = find_bar_controller;
@@ -33,7 +34,7 @@ class FindBarGtk : public FindBar {
// Callback when Escape is pressed.
void EscapePressed();
- GtkWidget* gtk_widget() const { return container_; }
+ GtkWidget* widget() const { return container_.get(); }
// Methods from FindBar.
virtual void Show();
@@ -51,7 +52,7 @@ class FindBarGtk : public FindBar {
private:
// GtkHBox containing the find bar widgets.
- GtkWidget* container_;
+ OwnedWidgetGtk container_;
// The widget where text is entered.
GtkWidget* find_text_;
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 4f6d623..9aa1bb6 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -33,8 +33,7 @@ const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4);
LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
ToolbarModel* toolbar_model)
- : outer_bin_(NULL),
- inner_vbox_(NULL),
+ : inner_vbox_(NULL),
profile_(NULL),
command_updater_(command_updater),
toolbar_model_(toolbar_model),
@@ -43,7 +42,8 @@ LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
}
LocationBarViewGtk::~LocationBarViewGtk() {
- gtk_widget_destroy(outer_bin_);
+ // All of our widgets should have be children of / owned by the outer bin.
+ outer_bin_.Destroy();
}
void LocationBarViewGtk::Init() {
@@ -62,15 +62,12 @@ void LocationBarViewGtk::Init() {
TRUE, TRUE, 0);
// Use an alignment to position our bordered location entry exactly.
- outer_bin_ = gtk_alignment_new(0, 0, 1, 1);
- gtk_alignment_set_padding(GTK_ALIGNMENT(outer_bin_),
+ outer_bin_.Own(gtk_alignment_new(0, 0, 1, 1));
+ gtk_alignment_set_padding(GTK_ALIGNMENT(outer_bin_.get()),
kTopPadding, kBottomPadding, 0, 0);
gtk_container_add(
- GTK_CONTAINER(outer_bin_),
+ GTK_CONTAINER(outer_bin_.get()),
gfx::CreateGtkBorderBin(inner_vbox_, &kBorderColor, 1, 1, 0, 0));
-
- // Sink the ref so that we own the widget, and will destroy on destruction.
- g_object_ref_sink(outer_bin_);
}
void LocationBarViewGtk::SetProfile(Profile* profile) {
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index eb7bbf2..2fc5b0b 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -13,6 +13,7 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/location_bar.h"
+#include "chrome/common/owned_widget_gtk.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/window_open_disposition.h"
@@ -35,7 +36,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
void SetProfile(Profile* profile);
// Returns the widget the caller should host. You must call Init() first.
- GtkWidget* widget() { return outer_bin_; }
+ GtkWidget* widget() { return outer_bin_.get(); }
// Updates the location bar. We also reset the bar's permanent text and
// security style, and, if |tab_for_state_restoring| is non-NULL, also
@@ -65,7 +66,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
private:
// The outermost widget we want to be hosted.
- GtkWidget* outer_bin_;
+ OwnedWidgetGtk outer_bin_;
// This is the widget you probably care about, our inner vbox (inside the
// the border) which holds the elements inside the location bar.
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc
index 3f8f7a9..fc349cd 100644
--- a/chrome/browser/gtk/menu_gtk.cc
+++ b/chrome/browser/gtk/menu_gtk.cc
@@ -40,19 +40,17 @@ MenuGtk::MenuGtk(MenuGtk::Delegate* delegate,
: delegate_(delegate),
accel_group_(accel_group),
menu_(gtk_menu_new()) {
- g_object_ref_sink(menu_);
- BuildMenuIn(menu_, menu_data);
+ BuildMenuIn(menu_.get(), menu_data);
}
MenuGtk::MenuGtk(MenuGtk::Delegate* delegate)
: delegate_(delegate),
menu_(gtk_menu_new()) {
- g_object_ref_sink(menu_);
BuildMenuFromDelegate();
}
MenuGtk::~MenuGtk() {
- g_object_unref(menu_);
+ menu_.Destroy();
}
void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) {
@@ -64,20 +62,20 @@ void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) {
}
void MenuGtk::Popup(GtkWidget* widget, gint button_type, guint32 timestamp) {
- gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this);
+ gtk_container_foreach(GTK_CONTAINER(menu_.get()), SetMenuItemInfo, this);
- gtk_menu_popup(GTK_MENU(menu_), NULL, NULL,
+ gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL,
MenuPositionFunc,
widget,
button_type, timestamp);
}
void MenuGtk::PopupAsContext() {
- gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this);
+ gtk_container_foreach(GTK_CONTAINER(menu_.get()), SetMenuItemInfo, this);
// TODO(estade): |button| value of 0 (6th argument) is not strictly true,
// but does it matter?
- gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, NULL, NULL, 0,
+ gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, NULL, NULL, 0,
gtk_get_current_event_time());
}
@@ -180,7 +178,8 @@ void MenuGtk::BuildMenuFromDelegate() {
G_CALLBACK(OnMenuItemActivatedById), this);
gtk_widget_show(menu_item);
- gtk_menu_append(menu_, menu_item);
+ // TODO(estade): gtk_menu_append is deprecated.
+ gtk_menu_append(menu_.get(), menu_item);
}
}
diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h
index 01bdc78..216478a 100644
--- a/chrome/browser/gtk/menu_gtk.h
+++ b/chrome/browser/gtk/menu_gtk.h
@@ -9,6 +9,7 @@
#include <string>
#include "chrome/browser/gtk/standard_menus.h"
+#include "chrome/common/owned_widget_gtk.h"
class SkBitmap;
@@ -93,12 +94,9 @@ class MenuGtk {
// Accelerator group to add keyboard accelerators to.
GtkAccelGroup* accel_group_;
- // The window this menu is attached to.
- GtkWindow* window_;
-
// gtk_menu_popup() does not appear to take ownership of popup menus, so
// MenuGtk explicitly manages the lifetime of the menu.
- GtkWidget* menu_;
+ OwnedWidgetGtk menu_;
};
#endif // CHROME_BROWSER_GTK_MENU_GTK_H_
diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc
index ad9ffdf..c0f8b27 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc
@@ -135,12 +135,11 @@ RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host)
: host_(widget_host) {
host_->set_view(this);
- view_ = RenderWidgetHostViewGtkWidget::CreateNewWidget(this);
// BUG 8707: We will live in some container (in this case in WebContents).
// We want to destroy during Destroy(), independent of how we are managed in
// any containers. We need to sink the reference here to "own" the widget so
// it can be added and removed from containers without being destroyed.
- g_object_ref_sink(view_);
+ view_.Own(RenderWidgetHostViewGtkWidget::CreateNewWidget(this));
}
RenderWidgetHostViewGtk::~RenderWidgetHostViewGtk() {
@@ -162,7 +161,7 @@ gfx::NativeView RenderWidgetHostViewGtk::GetPluginNativeView() {
// TODO(port): We need to pass some widget pointer out here because the
// renderer echos it back to us when it asks for GetScreenInfo. However, we
// should probably be passing the top-level window or some such instead.
- return view_;
+ return view_.get();
}
void RenderWidgetHostViewGtk::MovePluginWindows(
@@ -195,8 +194,8 @@ void RenderWidgetHostViewGtk::Hide() {
}
gfx::Rect RenderWidgetHostViewGtk::GetViewBounds() const {
- return gfx::Rect(view_->allocation.x, view_->allocation.y,
- view_->allocation.width, view_->allocation.height);
+ GtkAllocation* alloc = &view_.get()->allocation;
+ return gfx::Rect(alloc->x, alloc->y, alloc->width, alloc->height);
}
void RenderWidgetHostViewGtk::UpdateCursor(const WebCursor& cursor) {
@@ -219,7 +218,7 @@ void RenderWidgetHostViewGtk::UpdateCursor(const WebCursor& cursor) {
return;
gdk_cursor = gdk_cursor_new(new_cursor_type);
}
- gdk_window_set_cursor(view_->window, gdk_cursor);
+ gdk_window_set_cursor(view_.get()->window, gdk_cursor);
// The window now owns the cursor.
gdk_cursor_unref(gdk_cursor);
}
@@ -258,26 +257,25 @@ void RenderWidgetHostViewGtk::Destroy() {
// We need to disconnect ourselves from our parent widget at this time; this
// does the right thing, automatically removing ourselves from our parent
// container.
- gtk_widget_destroy(view_);
- view_ = NULL;
+ view_.Destroy();
}
void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) {
if (tooltip_text.empty()) {
- gtk_widget_set_has_tooltip(view_, FALSE);
+ gtk_widget_set_has_tooltip(view_.get(), FALSE);
} else {
- gtk_widget_set_tooltip_text(view_, WideToUTF8(tooltip_text).c_str());
+ gtk_widget_set_tooltip_text(view_.get(), WideToUTF8(tooltip_text).c_str());
}
}
BackingStore* RenderWidgetHostViewGtk::AllocBackingStore(
const gfx::Size& size) {
Display* display = x11_util::GetXDisplay();
- void* visual = x11_util::GetVisualFromGtkWidget(view_);
+ void* visual = x11_util::GetVisualFromGtkWidget(view_.get());
XID root_window = x11_util::GetX11RootWindow();
bool use_render = x11_util::QueryRenderSupport(display);
bool use_shared_memory = x11_util::QuerySharedMemorySupport(display);
- int depth = gtk_widget_get_visual(view_)->depth;
+ int depth = gtk_widget_get_visual(view_.get())->depth;
return new BackingStore(size, display, depth, visual, root_window,
use_render, use_shared_memory);
@@ -290,10 +288,10 @@ void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) {
// Only render the widget if it is attached to a window; there's a short
// period where this object isn't attached to a window but hasn't been
// Destroy()ed yet and it receives paint messages...
- GdkWindow* window = view_->window;
+ GdkWindow* window = view_.get()->window;
if (window) {
backing_store->ShowRect(
- damage_rect, x11_util::GetX11WindowFromGtkWidget(view_));
+ damage_rect, x11_util::GetX11WindowFromGtkWidget(view_.get()));
}
} else {
NOTIMPLEMENTED();
diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h
index 9c74172..3cf06b1 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h
@@ -9,6 +9,7 @@
#include "base/gfx/native_widget_types.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
+#include "chrome/common/owned_widget_gtk.h"
#include "webkit/glue/webcursor.h"
class RenderWidgetHost;
@@ -50,7 +51,7 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView {
BackingStore* AllocBackingStore(const gfx::Size& size);
// ---------------------------------------------------------------------------
- gfx::NativeView native_view() const { return view_; }
+ gfx::NativeView native_view() const { return view_.get(); }
void Paint(const gfx::Rect&);
@@ -58,7 +59,7 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView {
// The model object.
RenderWidgetHost *const host_;
// The native UI widget.
- gfx::NativeView view_;
+ OwnedWidgetGtk view_;
// The cursor for the page. This is passed up from the renderer.
WebCursor current_cursor_;
diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc
index 7b6cf18..72da1e5 100644
--- a/chrome/browser/tab_contents/web_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc
@@ -44,7 +44,7 @@ gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* event, void*) {
}
// Callback used in WebContentsViewGtk::CreateViewForWidget().
-void RemoveWidget(GtkWidget* widget, void* container) {
+void RemoveWidget(GtkWidget* widget, gpointer container) {
gtk_container_remove(GTK_CONTAINER(container), widget);
}
@@ -58,11 +58,10 @@ WebContentsView* WebContentsView::Create(WebContents* web_contents) {
WebContentsViewGtk::WebContentsViewGtk(WebContents* web_contents)
: web_contents_(web_contents),
vbox_(gtk_vbox_new(FALSE, 0)) {
- g_object_ref_sink(vbox_);
}
WebContentsViewGtk::~WebContentsViewGtk() {
- gtk_widget_destroy(vbox_);
+ vbox_.Destroy();
}
WebContents* WebContentsViewGtk::GetWebContents() {
@@ -83,13 +82,13 @@ RenderWidgetHostView* WebContentsViewGtk::CreateViewForWidget(
G_CALLBACK(OnFocus), web_contents_);
g_signal_connect(view->native_view(), "focus-out-event",
G_CALLBACK(OnFocusOut), NULL);
- gtk_container_foreach(GTK_CONTAINER(vbox_), RemoveWidget, vbox_);
- gtk_box_pack_start(GTK_BOX(vbox_), view->native_view(), TRUE, TRUE, 0);
+ gtk_container_foreach(GTK_CONTAINER(vbox_.get()), RemoveWidget, vbox_.get());
+ gtk_box_pack_start(GTK_BOX(vbox_.get()), view->native_view(), TRUE, TRUE, 0);
return view;
}
gfx::NativeView WebContentsViewGtk::GetNativeView() const {
- return vbox_;
+ return vbox_.get();
}
gfx::NativeView WebContentsViewGtk::GetContentNativeView() const {
@@ -98,7 +97,7 @@ gfx::NativeView WebContentsViewGtk::GetContentNativeView() const {
}
gfx::NativeWindow WebContentsViewGtk::GetTopLevelNativeView() const {
- return GTK_WINDOW(gtk_widget_get_toplevel(vbox_));
+ return GTK_WINDOW(gtk_widget_get_toplevel(vbox_.get()));
}
void WebContentsViewGtk::GetContainerBounds(gfx::Rect* out) const {
@@ -180,7 +179,7 @@ void WebContentsViewGtk::HandleKeyboardEvent(
break;
default:
// This may be an accelerator. Pass it on to GTK.
- gtk_accel_groups_activate(G_OBJECT(vbox_->window),
+ gtk_accel_groups_activate(G_OBJECT(vbox_.get()->window),
event.os_event->keyval,
GdkModifierType(event.os_event->state));
}
diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.h b/chrome/browser/tab_contents/web_contents_view_gtk.h
index f218fee..d389865 100644
--- a/chrome/browser/tab_contents/web_contents_view_gtk.h
+++ b/chrome/browser/tab_contents/web_contents_view_gtk.h
@@ -7,6 +7,7 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/tab_contents/web_contents_view.h"
+#include "chrome/common/owned_widget_gtk.h"
class RenderViewContextMenuGtk;
@@ -67,7 +68,7 @@ class WebContentsViewGtk : public WebContentsView {
private:
WebContents* web_contents_;
- GtkWidget* vbox_;
+ OwnedWidgetGtk vbox_;
// The context menu is reset every time we show it, but we keep a pointer to
// between uses so that it won't go out of scope before we're done with it.