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

Side by Side Diff: chrome/browser/gtk/bookmark_bar_gtk.cc

Issue 155342: A little bit of bookmark bar cleanup, a little bit of padding improvement.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/bookmark_bar_gtk.h ('k') | chrome/browser/gtk/bookmark_utils_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/text_elider.h" 9 #include "app/gfx/text_elider.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (profile_ == profile) 78 if (profile_ == profile)
79 return; 79 return;
80 80
81 RemoveAllBookmarkButtons(); 81 RemoveAllBookmarkButtons();
82 82
83 profile_ = profile; 83 profile_ = profile;
84 84
85 if (model_) 85 if (model_)
86 model_->RemoveObserver(this); 86 model_->RemoveObserver(this);
87 87
88 gtk_widget_set_sensitive(other_bookmarks_button_, false);
89
90 // TODO(erg): Handle extensions 88 // TODO(erg): Handle extensions
91 89
92 model_ = profile_->GetBookmarkModel(); 90 model_ = profile_->GetBookmarkModel();
93 model_->AddObserver(this); 91 model_->AddObserver(this);
94 if (model_->IsLoaded()) 92 if (model_->IsLoaded())
95 Loaded(model_); 93 Loaded(model_);
96 94
97 // else case: we'll receive notification back from the BookmarkModel when done 95 // else case: we'll receive notification back from the BookmarkModel when done
98 // loading, then we'll populate the bar. 96 // loading, then we'll populate the bar.
99 } 97 }
100 98
101 void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) { 99 void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) {
102 page_navigator_ = navigator; 100 page_navigator_ = navigator;
103 } 101 }
104 102
105 void BookmarkBarGtk::Init(Profile* profile) { 103 void BookmarkBarGtk::Init(Profile* profile) {
106 // Load the default images from the resource bundle.
107 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
108 static GdkPixbuf* folder_icon = rb.GetPixbufNamed(IDR_BOOKMARK_BAR_FOLDER);
109
110 bookmark_hbox_.Own(gtk_hbox_new(FALSE, 0)); 104 bookmark_hbox_.Own(gtk_hbox_new(FALSE, 0));
111 105
112 instructions_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 106 instructions_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
113 gtk_alignment_set_padding(GTK_ALIGNMENT(instructions_), 0, 0, 107 gtk_alignment_set_padding(GTK_ALIGNMENT(instructions_), 0, 0,
114 kInstructionsPadding, 0); 108 kInstructionsPadding, 0);
115 g_signal_connect(instructions_, "destroy", G_CALLBACK(gtk_widget_destroyed), 109 g_signal_connect(instructions_, "destroy", G_CALLBACK(gtk_widget_destroyed),
116 &instructions_); 110 &instructions_);
117 GtkWidget* instructions_label = gtk_label_new( 111 GtkWidget* instructions_label = gtk_label_new(
118 l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str()); 112 l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str());
119 gtk_widget_modify_fg(instructions_label, GTK_STATE_NORMAL, 113 gtk_widget_modify_fg(instructions_label, GTK_STATE_NORMAL,
(...skipping 28 matching lines...) Expand all
148 g_signal_connect(bookmark_toolbar_.get(), "button-press-event", 142 g_signal_connect(bookmark_toolbar_.get(), "button-press-event",
149 G_CALLBACK(&OnButtonPressed), this); 143 G_CALLBACK(&OnButtonPressed), this);
150 144
151 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(), 145 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(),
152 FALSE, FALSE, 0); 146 FALSE, FALSE, 0);
153 147
154 // We pack the button manually (rather than using gtk_button_set_*) so that 148 // We pack the button manually (rather than using gtk_button_set_*) so that
155 // we can have finer control over its label. 149 // we can have finer control over its label.
156 other_bookmarks_button_ = gtk_chrome_button_new(); 150 other_bookmarks_button_ = gtk_chrome_button_new();
157 ConnectFolderButtonEvents(other_bookmarks_button_); 151 ConnectFolderButtonEvents(other_bookmarks_button_);
158 gtk_chrome_button_set_use_gtk_rendering(
159 GTK_CHROME_BUTTON(other_bookmarks_button_),
160 GtkThemeProvider::UseSystemThemeGraphics(profile));
161
162 GtkWidget* image = gtk_image_new_from_pixbuf(folder_icon);
163 other_bookmarks_label_ = gtk_label_new(
164 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str());
165 GtkThemeProperties properties(profile);
166 bookmark_utils::SetButtonTextColors(other_bookmarks_label_, &properties);
167
168 GtkWidget* box = gtk_hbox_new(FALSE, bookmark_utils::kBarButtonPadding);
169 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
170 gtk_box_pack_start(GTK_BOX(box), other_bookmarks_label_, FALSE, FALSE, 0);
171 gtk_container_add(GTK_CONTAINER(other_bookmarks_button_), box);
172
173 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_, 152 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_,
174 FALSE, FALSE, 0); 153 FALSE, FALSE, 0);
175 154
176 // Set the current theme state for all the buttons. 155 // Set the current theme state for all the buttons.
177 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0); 156 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0);
178 157
179 slide_animation_.reset(new SlideAnimation(this)); 158 slide_animation_.reset(new SlideAnimation(this));
180 } 159 }
181 160
182 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { 161 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 bool BookmarkBarGtk::OnNewTabPage() { 202 bool BookmarkBarGtk::OnNewTabPage() {
224 return (browser_ && browser_->GetSelectedTabContents() && 203 return (browser_ && browser_->GetSelectedTabContents() &&
225 browser_->GetSelectedTabContents()->IsBookmarkBarAlwaysVisible()); 204 browser_->GetSelectedTabContents()->IsBookmarkBarAlwaysVisible());
226 } 205 }
227 206
228 void BookmarkBarGtk::Loaded(BookmarkModel* model) { 207 void BookmarkBarGtk::Loaded(BookmarkModel* model) {
229 // If |instructions_| has been nulled, we are in the middle of browser 208 // If |instructions_| has been nulled, we are in the middle of browser
230 // shutdown. Do nothing. 209 // shutdown. Do nothing.
231 if (!instructions_) 210 if (!instructions_)
232 return; 211 return;
212
233 RemoveAllBookmarkButtons(); 213 RemoveAllBookmarkButtons();
234 214 CreateAllBookmarkButtons();
235 const BookmarkNode* node = model_->GetBookmarkBarNode();
236 DCHECK(node && model_->other_node());
237 CreateAllBookmarkButtons(node);
238
239 gtk_widget_set_sensitive(other_bookmarks_button_, true);
240 } 215 }
241 216
242 void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { 217 void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) {
243 // The bookmark model should never be deleted before us. This code exists 218 // The bookmark model should never be deleted before us. This code exists
244 // to check for regressions in shutdown code and not crash. 219 // to check for regressions in shutdown code and not crash.
245 NOTREACHED(); 220 NOTREACHED();
246 221
247 // Do minimal cleanup, presumably we'll be deleted shortly. 222 // Do minimal cleanup, presumably we'll be deleted shortly.
248 model_->RemoveObserver(this); 223 model_->RemoveObserver(this);
249 model_ = NULL; 224 model_ = NULL;
(...skipping 14 matching lines...) Expand all
264 if (parent != model_->GetBookmarkBarNode()) { 239 if (parent != model_->GetBookmarkBarNode()) {
265 // We only care about nodes on the bookmark bar. 240 // We only care about nodes on the bookmark bar.
266 return; 241 return;
267 } 242 }
268 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 243 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
269 244
270 GtkToolItem* item = CreateBookmarkToolItem(parent->GetChild(index)); 245 GtkToolItem* item = CreateBookmarkToolItem(parent->GetChild(index));
271 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), 246 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()),
272 item, index); 247 item, index);
273 248
274 SetInstructionState(parent); 249 SetInstructionState();
275 } 250 }
276 251
277 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, 252 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model,
278 const BookmarkNode* parent, 253 const BookmarkNode* parent,
279 int index) { 254 int index) {
280 if (parent != model_->GetBookmarkBarNode()) { 255 if (parent != model_->GetBookmarkBarNode()) {
281 // We only care about nodes on the bookmark bar. 256 // We only care about nodes on the bookmark bar.
282 return; 257 return;
283 } 258 }
284 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 259 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
285 260
286 GtkWidget* to_remove = GTK_WIDGET(gtk_toolbar_get_nth_item( 261 GtkWidget* to_remove = GTK_WIDGET(gtk_toolbar_get_nth_item(
287 GTK_TOOLBAR(bookmark_toolbar_.get()), index)); 262 GTK_TOOLBAR(bookmark_toolbar_.get()), index));
288 gtk_container_remove(GTK_CONTAINER(bookmark_toolbar_.get()), 263 gtk_container_remove(GTK_CONTAINER(bookmark_toolbar_.get()),
289 to_remove); 264 to_remove);
290 265
291 SetInstructionState(parent); 266 SetInstructionState();
292 } 267 }
293 268
294 void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model, 269 void BookmarkBarGtk::BookmarkNodeChanged(BookmarkModel* model,
295 const BookmarkNode* node) { 270 const BookmarkNode* node) {
296 if (node->GetParent() != model_->GetBookmarkBarNode()) { 271 if (node->GetParent() != model_->GetBookmarkBarNode()) {
297 // We only care about nodes on the bookmark bar. 272 // We only care about nodes on the bookmark bar.
298 return; 273 return;
299 } 274 }
300 int index = model_->GetBookmarkBarNode()->IndexOfChild(node); 275 int index = model_->GetBookmarkBarNode()->IndexOfChild(node);
301 DCHECK(index != -1); 276 DCHECK(index != -1);
(...skipping 10 matching lines...) Expand all
312 BookmarkNodeChanged(model, node); 287 BookmarkNodeChanged(model, node);
313 } 288 }
314 289
315 void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, 290 void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
316 const BookmarkNode* node) { 291 const BookmarkNode* node) {
317 if (node != model_->GetBookmarkBarNode()) 292 if (node != model_->GetBookmarkBarNode())
318 return; // We only care about reordering of the bookmark bar node. 293 return; // We only care about reordering of the bookmark bar node.
319 294
320 // Purge and rebuild the bar. 295 // Purge and rebuild the bar.
321 RemoveAllBookmarkButtons(); 296 RemoveAllBookmarkButtons();
322 CreateAllBookmarkButtons(node); 297 CreateAllBookmarkButtons();
323 } 298 }
324 299
325 void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) { 300 void BookmarkBarGtk::CreateAllBookmarkButtons() {
301 const BookmarkNode* node = model_->GetBookmarkBarNode();
302 DCHECK(node && model_->other_node());
303
326 // Create a button for each of the children on the bookmark bar. 304 // Create a button for each of the children on the bookmark bar.
327 for (int i = 0; i < node->GetChildCount(); ++i) { 305 for (int i = 0; i < node->GetChildCount(); ++i) {
328 GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i)); 306 GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i));
329 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1); 307 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1);
330 } 308 }
331 309
332 SetInstructionState(node); 310 GtkThemeProperties properties(profile_);
311 bookmark_utils::ConfigureButtonForNode(model_->other_node(),
312 model_, other_bookmarks_button_, &properties);
313
314 SetInstructionState();
333 } 315 }
334 316
335 void BookmarkBarGtk::SetInstructionState( 317 void BookmarkBarGtk::SetInstructionState() {
336 const BookmarkNode* boomarks_bar_node) { 318 show_instructions_ = (model_->GetBookmarkBarNode()->GetChildCount() == 0);
337 show_instructions_ = (boomarks_bar_node->GetChildCount() == 0);
338 if (show_instructions_) { 319 if (show_instructions_) {
339 gtk_widget_show_all(instructions_); 320 gtk_widget_show_all(instructions_);
340 } else { 321 } else {
341 gtk_widget_hide(instructions_); 322 gtk_widget_hide(instructions_);
342 } 323 }
343 } 324 }
344 325
345 void BookmarkBarGtk::RemoveAllBookmarkButtons() { 326 void BookmarkBarGtk::RemoveAllBookmarkButtons() {
346 gtk_util::RemoveAllChildren(bookmark_toolbar_.get()); 327 gtk_util::RemoveAllChildren(bookmark_toolbar_.get());
347 } 328 }
348 329
349 int BookmarkBarGtk::GetBookmarkButtonCount() { 330 int BookmarkBarGtk::GetBookmarkButtonCount() {
350 GList* children = gtk_container_get_children( 331 GList* children = gtk_container_get_children(
351 GTK_CONTAINER(bookmark_toolbar_.get())); 332 GTK_CONTAINER(bookmark_toolbar_.get()));
352 int count = g_list_length(children); 333 int count = g_list_length(children);
353 g_list_free(children); 334 g_list_free(children);
354 return count; 335 return count;
355 } 336 }
356 337
357 bool BookmarkBarGtk::IsAlwaysShown() { 338 bool BookmarkBarGtk::IsAlwaysShown() {
358 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 339 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
359 } 340 }
360 341
361 void BookmarkBarGtk::UserChangedTheme(GtkThemeProperties* properties) { 342 void BookmarkBarGtk::UserChangedTheme(GtkThemeProperties* properties) {
362 gtk_chrome_button_set_use_gtk_rendering(
363 GTK_CHROME_BUTTON(other_bookmarks_button_),
364 properties->use_gtk_rendering);
365 bookmark_utils::SetButtonTextColors(other_bookmarks_label_, properties);
366
367 if (model_) { 343 if (model_) {
368 // Regenerate the bookmark bar with all new objects with their theme 344 // Regenerate the bookmark bar with all new objects with their theme
369 // properties set correctly for the new theme. 345 // properties set correctly for the new theme.
370 RemoveAllBookmarkButtons(); 346 RemoveAllBookmarkButtons();
371 347 CreateAllBookmarkButtons();
372 const BookmarkNode* node = model_->GetBookmarkBarNode();
373 DCHECK(node && model_->other_node());
374 CreateAllBookmarkButtons(node);
375 } else { 348 } else {
376 DLOG(ERROR) << "Received a theme change notification while we don't have a " 349 DLOG(ERROR) << "Received a theme change notification while we don't have a "
377 << "BookmarkModel. Taking no action."; 350 << "BookmarkModel. Taking no action.";
378 } 351 }
379 } 352 }
380 353
381 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) { 354 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) {
382 DCHECK_EQ(animation, slide_animation_.get()); 355 DCHECK_EQ(animation, slide_animation_.get());
383 356
384 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 357 gtk_widget_set_size_request(bookmark_hbox_.get(), -1,
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 bar->InitBackground(); 782 bar->InitBackground();
810 gfx::Point tabstrip_origin = 783 gfx::Point tabstrip_origin =
811 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); 784 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget);
812 bar->background_ninebox_->RenderTopCenterStrip( 785 bar->background_ninebox_->RenderTopCenterStrip(
813 cr, tabstrip_origin.x(), tabstrip_origin.y(), 786 cr, tabstrip_origin.x(), tabstrip_origin.y(),
814 event->area.x + event->area.width - tabstrip_origin.x()); 787 event->area.x + event->area.width - tabstrip_origin.x());
815 cairo_destroy(cr); 788 cairo_destroy(cr);
816 789
817 return FALSE; // Propagate expose to children. 790 return FALSE; // Propagate expose to children.
818 } 791 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/bookmark_bar_gtk.h ('k') | chrome/browser/gtk/bookmark_utils_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698