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

Unified Diff: chrome/browser/gtk/bookmark_bar_gtk.cc

Issue 329022: GTK: Draw floating bookmark bar correctly during resizes.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/gtk/bookmark_bar_gtk.cc
===================================================================
--- chrome/browser/gtk/bookmark_bar_gtk.cc (revision 30061)
+++ chrome/browser/gtk/bookmark_bar_gtk.cc (working copy)
@@ -128,7 +128,8 @@
show_instructions_(true),
menu_bar_helper_(this),
floating_(false),
- last_allocation_width_(-1) {
+ last_allocation_width_(-1),
+ event_box_paint_factory_(this) {
#if defined(BROWSER_SYNC)
if (profile->GetProfileSyncService()) {
// Obtain a pointer to the profile sync service and add our instance as an
@@ -227,7 +228,7 @@
g_signal_connect(instructions_, "drag-data-received",
G_CALLBACK(&OnDragReceived), this);
- g_signal_connect(G_OBJECT(event_box_.get()), "expose-event",
+ g_signal_connect(event_box_.get(), "expose-event",
G_CALLBACK(&OnEventBoxExpose), this);
UpdateEventBoxPaintability();
@@ -615,8 +616,19 @@
UpdateEventBoxPaintability();
// |window_| can be NULL during testing.
- if (window_)
+ if (window_) {
window_->BookmarkBarIsFloating(floating_);
+ // Listen for parent size allocations.
+ if (floating_ && widget()->parent) {
+ // Only connect once.
+ if (g_signal_handler_find(widget()->parent, G_SIGNAL_MATCH_FUNC,
+ 0, NULL, NULL, reinterpret_cast<gpointer>(OnParentSizeAllocate),
+ NULL) == 0) {
+ g_signal_connect(widget()->parent, "size-allocate",
tony 2009/10/26 23:55:30 What happens if you drag a tab from one window to
Evan Stade 2009/10/27 00:11:12 the bookmark bar and the tab contents container sh
tony 2009/10/27 00:34:19 I see, it's the container. The g_signal_handler_f
Evan Stade 2009/10/27 00:37:48 it's because we don't want to connect mroe than on
+ G_CALLBACK(OnParentSizeAllocate), this);
+ }
+ }
+ }
}
void BookmarkBarGtk::UpdateEventBoxPaintability() {
@@ -629,6 +641,34 @@
theme_provider_->UseGtkTheme());
}
+void BookmarkBarGtk::PaintEventBox() {
+ gfx::Size tab_contents_size;
+ if (GetTabContentsSize(&tab_contents_size) &&
+ tab_contents_size != last_tab_contents_size_) {
+ last_tab_contents_size_ = tab_contents_size;
+ gtk_widget_queue_draw(event_box_.get());
+ }
+}
+
+bool BookmarkBarGtk::GetTabContentsSize(gfx::Size* size) {
+ Browser* browser = browser_;
+ if (!browser) {
+ NOTREACHED();
+ return false;
+ }
+ TabContents* tab_contents = browser->GetSelectedTabContents();
+ if (!tab_contents) {
+ NOTREACHED();
+ return false;
+ }
+ if (!tab_contents->view()) {
+ NOTREACHED();
+ return false;
+ }
+ *size = tab_contents->view()->GetContainerSize();
+ return true;
+}
+
bool BookmarkBarGtk::IsAlwaysShown() {
return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
}
@@ -1100,21 +1140,8 @@
cairo_destroy(cr);
} else {
gfx::Size tab_contents_size;
- Browser* browser = bar->browser_;
- if (!browser) {
- NOTREACHED();
+ if (!bar->GetTabContentsSize(&tab_contents_size))
return FALSE;
- }
- TabContents* tab_contents = browser->GetSelectedTabContents();
- if (!tab_contents) {
- NOTREACHED();
- return FALSE;
- }
- if (!tab_contents->view()) {
- NOTREACHED();
- return FALSE;
- }
- tab_contents_size = tab_contents->view()->GetContainerSize();
gfx::CanvasPaint canvas(event, true);
NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas,
gfx::Rect(widget->allocation), tab_contents_size.height());
@@ -1124,6 +1151,22 @@
}
// static
+void BookmarkBarGtk::OnParentSizeAllocate(GtkWidget* widget,
+ GtkAllocation* allocation,
+ BookmarkBarGtk* bar) {
+ // In floating mode, our layout depends on the size of the tab contents.
+ // We get the size-allocate signal before the tab contents does, hence we
+ // need to post a delayed task so we will paint correctly. Note that
+ // gtk_widget_queue_draw by itself does not work, despite that it claims to
+ // be asynchronous.
+ if (bar->floating_) {
+ MessageLoop::current()->PostTask(FROM_HERE,
tony 2009/10/26 23:55:30 Is this still necessary since we're getting the si
Evan Stade 2009/10/27 00:11:12 we are getting it from the tab contents container,
+ bar->event_box_paint_factory_.NewRunnableMethod(
+ &BookmarkBarGtk::PaintEventBox));
+ }
+}
+
+// static
gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget,
GdkEventExpose* event,
BookmarkBarGtk* bar) {
« chrome/browser/gtk/bookmark_bar_gtk.h ('K') | « chrome/browser/gtk/bookmark_bar_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698