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

Side by Side 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, 1 month 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 | Annotate | Revision Log
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 #include "chrome/browser/gtk/bookmark_bar_gtk.h" 5 #include "chrome/browser/gtk/bookmark_bar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/gfx/gtk_util.h" 9 #include "app/gfx/gtk_util.h"
10 #include "app/gfx/canvas_paint.h" 10 #include "app/gfx/canvas_paint.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 #if defined(BROWSER_SYNC) 121 #if defined(BROWSER_SYNC)
122 sync_error_button_(NULL), 122 sync_error_button_(NULL),
123 sync_service_(NULL), 123 sync_service_(NULL),
124 #endif 124 #endif
125 dragged_node_(NULL), 125 dragged_node_(NULL),
126 toolbar_drop_item_(NULL), 126 toolbar_drop_item_(NULL),
127 theme_provider_(GtkThemeProvider::GetFrom(profile)), 127 theme_provider_(GtkThemeProvider::GetFrom(profile)),
128 show_instructions_(true), 128 show_instructions_(true),
129 menu_bar_helper_(this), 129 menu_bar_helper_(this),
130 floating_(false), 130 floating_(false),
131 last_allocation_width_(-1) { 131 last_allocation_width_(-1),
132 event_box_paint_factory_(this) {
132 #if defined(BROWSER_SYNC) 133 #if defined(BROWSER_SYNC)
133 if (profile->GetProfileSyncService()) { 134 if (profile->GetProfileSyncService()) {
134 // Obtain a pointer to the profile sync service and add our instance as an 135 // Obtain a pointer to the profile sync service and add our instance as an
135 // observer. 136 // observer.
136 sync_service_ = profile->GetProfileSyncService(); 137 sync_service_ = profile->GetProfileSyncService();
137 sync_service_->AddObserver(this); 138 sync_service_->AddObserver(this);
138 } 139 }
139 #endif 140 #endif
140 141
141 Init(profile); 142 Init(profile);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), instructions_, 221 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), instructions_,
221 FALSE, FALSE, 0); 222 FALSE, FALSE, 0);
222 223
223 gtk_drag_dest_set(instructions_, 224 gtk_drag_dest_set(instructions_,
224 GtkDestDefaults(GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION), 225 GtkDestDefaults(GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION),
225 NULL, 0, kDragAction); 226 NULL, 0, kDragAction);
226 GtkDndUtil::SetDestTargetList(instructions_, kDestTargetList); 227 GtkDndUtil::SetDestTargetList(instructions_, kDestTargetList);
227 g_signal_connect(instructions_, "drag-data-received", 228 g_signal_connect(instructions_, "drag-data-received",
228 G_CALLBACK(&OnDragReceived), this); 229 G_CALLBACK(&OnDragReceived), this);
229 230
230 g_signal_connect(G_OBJECT(event_box_.get()), "expose-event", 231 g_signal_connect(event_box_.get(), "expose-event",
231 G_CALLBACK(&OnEventBoxExpose), this); 232 G_CALLBACK(&OnEventBoxExpose), this);
232 UpdateEventBoxPaintability(); 233 UpdateEventBoxPaintability();
233 234
234 bookmark_toolbar_.Own(gtk_toolbar_new()); 235 bookmark_toolbar_.Own(gtk_toolbar_new());
235 SetToolBarStyle(); 236 SetToolBarStyle();
236 gtk_widget_set_name(bookmark_toolbar_.get(), "chrome-bookmark-toolbar"); 237 gtk_widget_set_name(bookmark_toolbar_.get(), "chrome-bookmark-toolbar");
237 gtk_widget_set_app_paintable(bookmark_toolbar_.get(), TRUE); 238 gtk_widget_set_app_paintable(bookmark_toolbar_.get(), TRUE);
238 g_signal_connect(bookmark_toolbar_.get(), "expose-event", 239 g_signal_connect(bookmark_toolbar_.get(), "expose-event",
239 G_CALLBACK(&OnToolbarExpose), this); 240 G_CALLBACK(&OnToolbarExpose), this);
240 g_signal_connect(bookmark_toolbar_.get(), "size-allocate", 241 g_signal_connect(bookmark_toolbar_.get(), "size-allocate",
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 gtk_container_set_border_width(GTK_CONTAINER(bookmark_hbox_), kNTPPadding); 609 gtk_container_set_border_width(GTK_CONTAINER(bookmark_hbox_), kNTPPadding);
609 } else { 610 } else {
610 gtk_util::StopActingAsRoundedWindow(paint_box_); 611 gtk_util::StopActingAsRoundedWindow(paint_box_);
611 gtk_event_box_set_visible_window(GTK_EVENT_BOX(paint_box_), FALSE); 612 gtk_event_box_set_visible_window(GTK_EVENT_BOX(paint_box_), FALSE);
612 gtk_alignment_set_padding(GTK_ALIGNMENT(ntp_padding_box_), 0, 0, 0, 0); 613 gtk_alignment_set_padding(GTK_ALIGNMENT(ntp_padding_box_), 0, 0, 0, 0);
613 gtk_container_set_border_width(GTK_CONTAINER(bookmark_hbox_), 0); 614 gtk_container_set_border_width(GTK_CONTAINER(bookmark_hbox_), 0);
614 } 615 }
615 616
616 UpdateEventBoxPaintability(); 617 UpdateEventBoxPaintability();
617 // |window_| can be NULL during testing. 618 // |window_| can be NULL during testing.
618 if (window_) 619 if (window_) {
619 window_->BookmarkBarIsFloating(floating_); 620 window_->BookmarkBarIsFloating(floating_);
621 // Listen for parent size allocations.
622 if (floating_ && widget()->parent) {
623 // Only connect once.
624 if (g_signal_handler_find(widget()->parent, G_SIGNAL_MATCH_FUNC,
625 0, NULL, NULL, reinterpret_cast<gpointer>(OnParentSizeAllocate),
626 NULL) == 0) {
627 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
628 G_CALLBACK(OnParentSizeAllocate), this);
629 }
630 }
631 }
620 } 632 }
621 633
622 void BookmarkBarGtk::UpdateEventBoxPaintability() { 634 void BookmarkBarGtk::UpdateEventBoxPaintability() {
623 gtk_widget_set_app_paintable(event_box_.get(), 635 gtk_widget_set_app_paintable(event_box_.get(),
624 !theme_provider_->UseGtkTheme() || floating_); 636 !theme_provider_->UseGtkTheme() || floating_);
625 // When using the GTK+ theme, we need to have the event box be visible so 637 // When using the GTK+ theme, we need to have the event box be visible so
626 // buttons don't get a halo color from the background. When using Chromium 638 // buttons don't get a halo color from the background. When using Chromium
627 // themes, we want to let the background show through the toolbar. 639 // themes, we want to let the background show through the toolbar.
628 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), 640 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()),
629 theme_provider_->UseGtkTheme()); 641 theme_provider_->UseGtkTheme());
630 } 642 }
631 643
644 void BookmarkBarGtk::PaintEventBox() {
645 gfx::Size tab_contents_size;
646 if (GetTabContentsSize(&tab_contents_size) &&
647 tab_contents_size != last_tab_contents_size_) {
648 last_tab_contents_size_ = tab_contents_size;
649 gtk_widget_queue_draw(event_box_.get());
650 }
651 }
652
653 bool BookmarkBarGtk::GetTabContentsSize(gfx::Size* size) {
654 Browser* browser = browser_;
655 if (!browser) {
656 NOTREACHED();
657 return false;
658 }
659 TabContents* tab_contents = browser->GetSelectedTabContents();
660 if (!tab_contents) {
661 NOTREACHED();
662 return false;
663 }
664 if (!tab_contents->view()) {
665 NOTREACHED();
666 return false;
667 }
668 *size = tab_contents->view()->GetContainerSize();
669 return true;
670 }
671
632 bool BookmarkBarGtk::IsAlwaysShown() { 672 bool BookmarkBarGtk::IsAlwaysShown() {
633 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 673 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
634 } 674 }
635 675
636 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) { 676 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) {
637 DCHECK_EQ(animation, slide_animation_.get()); 677 DCHECK_EQ(animation, slide_animation_.get());
638 678
639 int max_height = ShouldBeFloating() ? 679 int max_height = ShouldBeFloating() ?
640 kBookmarkBarNTPHeight : kBookmarkBarHeight; 680 kBookmarkBarNTPHeight : kBookmarkBarHeight;
641 gint height = 681 gint height =
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 cairo_rectangle(cr, 1133 cairo_rectangle(cr,
1094 tabstrip_origin.x(), 1134 tabstrip_origin.x(),
1095 tabstrip_origin.y(), 1135 tabstrip_origin.y(),
1096 event->area.x + event->area.width - tabstrip_origin.x(), 1136 event->area.x + event->area.width - tabstrip_origin.x(),
1097 event->area.y + event->area.height - tabstrip_origin.y()); 1137 event->area.y + event->area.height - tabstrip_origin.y());
1098 cairo_fill(cr); 1138 cairo_fill(cr);
1099 1139
1100 cairo_destroy(cr); 1140 cairo_destroy(cr);
1101 } else { 1141 } else {
1102 gfx::Size tab_contents_size; 1142 gfx::Size tab_contents_size;
1103 Browser* browser = bar->browser_; 1143 if (!bar->GetTabContentsSize(&tab_contents_size))
1104 if (!browser) {
1105 NOTREACHED();
1106 return FALSE; 1144 return FALSE;
1107 }
1108 TabContents* tab_contents = browser->GetSelectedTabContents();
1109 if (!tab_contents) {
1110 NOTREACHED();
1111 return FALSE;
1112 }
1113 if (!tab_contents->view()) {
1114 NOTREACHED();
1115 return FALSE;
1116 }
1117 tab_contents_size = tab_contents->view()->GetContainerSize();
1118 gfx::CanvasPaint canvas(event, true); 1145 gfx::CanvasPaint canvas(event, true);
1119 NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas, 1146 NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas,
1120 gfx::Rect(widget->allocation), tab_contents_size.height()); 1147 gfx::Rect(widget->allocation), tab_contents_size.height());
1121 } 1148 }
1122 1149
1123 return FALSE; // Propagate expose to children. 1150 return FALSE; // Propagate expose to children.
1124 } 1151 }
1125 1152
1126 // static 1153 // static
1154 void BookmarkBarGtk::OnParentSizeAllocate(GtkWidget* widget,
1155 GtkAllocation* allocation,
1156 BookmarkBarGtk* bar) {
1157 // In floating mode, our layout depends on the size of the tab contents.
1158 // We get the size-allocate signal before the tab contents does, hence we
1159 // need to post a delayed task so we will paint correctly. Note that
1160 // gtk_widget_queue_draw by itself does not work, despite that it claims to
1161 // be asynchronous.
1162 if (bar->floating_) {
1163 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,
1164 bar->event_box_paint_factory_.NewRunnableMethod(
1165 &BookmarkBarGtk::PaintEventBox));
1166 }
1167 }
1168
1169 // static
1127 gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget, 1170 gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget,
1128 GdkEventExpose* event, 1171 GdkEventExpose* event,
1129 BookmarkBarGtk* bar) { 1172 BookmarkBarGtk* bar) {
1130 if (bar->theme_provider_->UseGtkTheme()) 1173 if (bar->theme_provider_->UseGtkTheme())
1131 return FALSE; 1174 return FALSE;
1132 1175
1133 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); 1176 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
1134 cairo_rectangle(cr, event->area.x, event->area.y, 1177 cairo_rectangle(cr, event->area.x, event->area.y,
1135 event->area.width, event->area.height); 1178 event->area.width, event->area.height);
1136 cairo_clip(cr); 1179 cairo_clip(cr);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 break; 1267 break;
1225 } 1268 }
1226 } 1269 }
1227 DCHECK_NE(button_idx, -1); 1270 DCHECK_NE(button_idx, -1);
1228 1271
1229 // Find the GtkWidget* for the actual target button. 1272 // Find the GtkWidget* for the actual target button.
1230 int shift = dir == GTK_MENU_DIR_PARENT ? -1 : 1; 1273 int shift = dir == GTK_MENU_DIR_PARENT ? -1 : 1;
1231 button_idx = (button_idx + shift + folder_list.size()) % folder_list.size(); 1274 button_idx = (button_idx + shift + folder_list.size()) % folder_list.size();
1232 PopupForButton(folder_list[button_idx]); 1275 PopupForButton(folder_list[button_idx]);
1233 } 1276 }
OLDNEW
« 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