summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 23:57:13 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-07 23:57:13 +0000
commitb9293ff66e688d5ff2239b8984588f501fbbfe4b (patch)
tree61cfbfbcf6dbdf19a4482189c9fa8ec14b77ce7f /chrome/browser/gtk
parent4cf2e5c49c739753ac2aa8049ec515f0a2e36186 (diff)
downloadchromium_src-b9293ff66e688d5ff2239b8984588f501fbbfe4b.zip
chromium_src-b9293ff66e688d5ff2239b8984588f501fbbfe4b.tar.gz
chromium_src-b9293ff66e688d5ff2239b8984588f501fbbfe4b.tar.bz2
Fix the findbar crash.
FindBarController is no longer owned by the BrowserWindow, it is owned by Browser. So we can remove the FindBarController code in BrowserWindowGtk. Also, go ahead and implement BrowserWindow::CreateFindBar (which creates the gtk widget and adds it to the gtk widget hierarchy) and enable the code on linux. Since the widgets are created and added to the hierarchy later, we attach the signals after the widgets have been "realized". Review URL: http://codereview.chromium.org/62126 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13310 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/browser_window_factory_gtk.cc6
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc25
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h10
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc20
-rw-r--r--chrome/browser/gtk/find_bar_gtk.h3
-rw-r--r--chrome/browser/gtk/tab_contents_container_gtk.cc8
-rw-r--r--chrome/browser/gtk/tab_contents_container_gtk.h8
7 files changed, 39 insertions, 41 deletions
diff --git a/chrome/browser/gtk/browser_window_factory_gtk.cc b/chrome/browser/gtk/browser_window_factory_gtk.cc
index 6766943..4cd7d2d5d 100644
--- a/chrome/browser/gtk/browser_window_factory_gtk.cc
+++ b/chrome/browser/gtk/browser_window_factory_gtk.cc
@@ -4,8 +4,14 @@
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/browser.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
+#include "chrome/browser/gtk/find_bar_gtk.h"
BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
return new BrowserWindowGtk(browser);
}
+
+FindBar* BrowserWindow::CreateFindBar(Browser* browser) {
+ return new FindBarGtk(static_cast<BrowserWindowGtk*>(browser->window()));
+}
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index cd7c805..031d626 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -18,7 +18,6 @@
#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/infobar_container_gtk.h"
@@ -213,13 +212,7 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
gtk_box_pack_start(GTK_BOX(content_vbox_), border, FALSE, FALSE, 0);
gtk_widget_show(border);
- FindBarGtk* find_bar_gtk = new FindBarGtk();
- find_bar_controller_.reset(new FindBarController(find_bar_gtk));
- find_bar_gtk->SetFindBarController(find_bar_controller_.get());
-
- contents_container_.reset(
- new TabContentsContainerGtk(find_bar_gtk->widget()));
-
+ contents_container_.reset(new TabContentsContainerGtk());
contents_container_->AddContainerToBox(content_vbox_);
// Note that calling this the first time is necessary to get the
@@ -444,10 +437,6 @@ void BrowserWindowGtk::ToggleBookmarkBar() {
bookmark_utils::ToggleWhenVisible(browser_->profile());
}
-void BrowserWindowGtk::ShowFindBar() {
- find_bar_controller_->Show();
-}
-
void BrowserWindowGtk::ShowAboutChromeDialog() {
NOTIMPLEMENTED();
}
@@ -511,11 +500,6 @@ void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) {
if (index == browser_->tabstrip_model()->selected_index()) {
infobar_container_->ChangeTabContents(NULL);
contents_container_->SetTabContents(NULL);
-
- // When dragging the last TabContents out of a window there is no selection
- // notification that causes the find bar for that window to be un-registered
- // for notifications from this TabContents.
- find_bar_controller_->ChangeWebContents(NULL);
}
}
@@ -546,9 +530,6 @@ void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents,
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() {
@@ -626,6 +607,10 @@ bool BrowserWindowGtk::ShouldShowWindowIcon() const {
return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
}
+void BrowserWindowGtk::AddFindBar(GtkWidget* findbar) {
+ contents_container_->AddFindBar(findbar);
+}
+
void BrowserWindowGtk::ConnectAccelerators() {
GtkAccelGroup* accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(window_, accel_group);
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index bc9f697..2629fb1 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -18,7 +18,6 @@
class BookmarkBarGtk;
class BrowserToolbarGtk;
-class FindBarController;
class InfoBarContainerGtk;
class LocationBar;
class NineBox;
@@ -67,7 +66,6 @@ class BrowserWindowGtk : public BrowserWindow,
virtual bool IsBookmarkBarVisible() const;
virtual gfx::Rect GetRootWindowResizerRect() const;
virtual void ToggleBookmarkBar();
- virtual void ShowFindBar();
virtual void ShowAboutChromeDialog();
virtual void ShowBookmarkManager();
virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked);
@@ -106,6 +104,9 @@ class BrowserWindowGtk : public BrowserWindow,
bool ShouldShowWindowIcon() const;
+ // Add the find bar widget to the window hierarchy.
+ void AddFindBar(GtkWidget* findbar);
+
protected:
virtual void DestroyBrowser();
GtkWindow* window_;
@@ -162,11 +163,6 @@ class BrowserWindowGtk : public BrowserWindow,
// of the content area).
scoped_ptr<TabContentsContainerGtk> contents_container_;
- // The Find Bar. This may be NULL if there is no Find Bar, and if it is
- // non-NULL, it may or may not be visible. It is possible for the Find Bar
- // to move among windows as tabs are dragged around.
- scoped_ptr<FindBarController> find_bar_controller_;
-
// The tab strip. Always non-NULL.
scoped_ptr<TabStripGtk> tabstrip_;
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index 890d838..67d9d07 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -9,6 +9,7 @@
#include "base/gfx/gtk_util.h"
#include "base/string_util.h"
#include "chrome/browser/find_bar_controller.h"
+#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/tab_contents_container_gtk.h"
#include "chrome/browser/tab_contents/web_contents.h"
@@ -37,8 +38,18 @@ gboolean KeyPressEvent(GtkWindow* window, GdkEventKey* event,
}
-FindBarGtk::FindBarGtk() {
+FindBarGtk::FindBarGtk(BrowserWindowGtk* browser) {
InitWidgets();
+
+ // Insert the widget into the browser gtk hierarchy.
+ browser->AddFindBar(container_.get());
+
+ // Hook up signals after the widget has been added to the hierarchy so the
+ // widget will be realized.
+ g_signal_connect(G_OBJECT(find_text_), "changed",
+ G_CALLBACK(EntryContentsChanged), this);
+ g_signal_connect(G_OBJECT(find_text_), "key-press-event",
+ G_CALLBACK(KeyPressEvent), this);
}
FindBarGtk::~FindBarGtk() {
@@ -91,11 +102,6 @@ void FindBarGtk::InitWidgets() {
gtk_box_pack_start(GTK_BOX(centering_vbox), border_bin, TRUE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0);
-
- g_signal_connect(G_OBJECT(find_text_), "changed",
- G_CALLBACK(EntryContentsChanged), this);
- g_signal_connect(G_OBJECT(find_text_), "key-press-event",
- G_CALLBACK(KeyPressEvent), this);
}
void FindBarGtk::Show() {
@@ -141,6 +147,8 @@ gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
}
void FindBarGtk::SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) {
+ if (!IsFindBarVisible())
+ Show(); // TODO(tc): This should be a no animation show.
}
bool FindBarGtk::IsFindBarVisible() {
diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h
index 1dba7fb..07aa76f 100644
--- a/chrome/browser/gtk/find_bar_gtk.h
+++ b/chrome/browser/gtk/find_bar_gtk.h
@@ -12,6 +12,7 @@
#include "chrome/browser/find_bar.h"
#include "chrome/common/owned_widget_gtk.h"
+class BrowserWindowGtk;
class CustomDrawButton;
class FindBarController;
class TabContentsContainerGtk;
@@ -22,7 +23,7 @@ class WebContents;
class FindBarGtk : public FindBar,
public FindBarTesting {
public:
- FindBarGtk();
+ FindBarGtk(BrowserWindowGtk* browser);
virtual ~FindBarGtk();
// Callback when the text in the find box changes.
diff --git a/chrome/browser/gtk/tab_contents_container_gtk.cc b/chrome/browser/gtk/tab_contents_container_gtk.cc
index 0b38c76..9e73389 100644
--- a/chrome/browser/gtk/tab_contents_container_gtk.cc
+++ b/chrome/browser/gtk/tab_contents_container_gtk.cc
@@ -10,11 +10,9 @@
#include "chrome/common/notification_service.h"
-TabContentsContainerGtk::TabContentsContainerGtk(GtkWidget* findbar)
+TabContentsContainerGtk::TabContentsContainerGtk()
: tab_contents_(NULL),
vbox_(gtk_vbox_new(FALSE, 0)) {
- DCHECK(findbar);
- gtk_box_pack_start(GTK_BOX(vbox_), findbar, FALSE, FALSE, 0);
gtk_widget_show(vbox_);
}
@@ -27,6 +25,10 @@ void TabContentsContainerGtk::AddContainerToBox(GtkWidget* box) {
gtk_box_pack_start(GTK_BOX(box), vbox_, TRUE, TRUE, 0);
}
+void TabContentsContainerGtk::AddFindBar(GtkWidget* findbar) {
+ gtk_box_pack_start(GTK_BOX(vbox_), findbar, FALSE, FALSE, 0);
+}
+
void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) {
if (tab_contents_) {
gfx::NativeView widget = tab_contents_->GetNativeView();
diff --git a/chrome/browser/gtk/tab_contents_container_gtk.h b/chrome/browser/gtk/tab_contents_container_gtk.h
index 19e8c92..6bef9a4 100644
--- a/chrome/browser/gtk/tab_contents_container_gtk.h
+++ b/chrome/browser/gtk/tab_contents_container_gtk.h
@@ -15,15 +15,15 @@ class TabContents;
class TabContentsContainerGtk : public NotificationObserver {
public:
- // |findbar| is a pointer to the find bar container widget. Since the
- // position is relative to the tab contents, we position the find bar using
- // the tab contents container.
- explicit TabContentsContainerGtk(GtkWidget* findbar);
+ TabContentsContainerGtk();
~TabContentsContainerGtk();
// Inserts our GtkWidget* hierarchy into a GtkBox managed by our owner.
void AddContainerToBox(GtkWidget* widget);
+ // Add the findbar to the top of the tab contents container.
+ void AddFindBar(GtkWidget* widget);
+
// Make the specified tab visible.
void SetTabContents(TabContents* tab_contents);
TabContents* GetTabContents() const { return tab_contents_; }