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

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

Issue 155108: GTK Themes: Set the text color of bookmark buttons to theme color. (Closed)
Patch Set: Simplify. 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
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 28 matching lines...) Expand all
39 39
40 // The height of the bar. 40 // The height of the bar.
41 const int kBookmarkBarHeight = 29; 41 const int kBookmarkBarHeight = 29;
42 42
43 // Left-padding for the instructional text. 43 // Left-padding for the instructional text.
44 const int kInstructionsPadding = 6; 44 const int kInstructionsPadding = 6;
45 45
46 // Color of the instructional text. 46 // Color of the instructional text.
47 const GdkColor kInstructionsColor = GDK_COLOR_RGB(128, 128, 142); 47 const GdkColor kInstructionsColor = GDK_COLOR_RGB(128, 128, 142);
48 48
49 void SetUseSystemThemeGraphicsOnToolbarItems(GtkToolItem* item, bool use_gtk) {
50 GtkWidget* child = gtk_bin_get_child(GTK_BIN(item));
51 if (GTK_IS_CHROME_BUTTON(child)) {
52 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(child), use_gtk);
53 }
54 }
55
56 } // namespace 49 } // namespace
57 50
58 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser, 51 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser,
59 BrowserWindowGtk* window) 52 BrowserWindowGtk* window)
60 : profile_(NULL), 53 : profile_(NULL),
61 page_navigator_(NULL), 54 page_navigator_(NULL),
62 browser_(browser), 55 browser_(browser),
63 window_(window), 56 window_(window),
64 model_(NULL), 57 model_(NULL),
65 instructions_(NULL), 58 instructions_(NULL),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 99 }
107 100
108 void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) { 101 void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) {
109 page_navigator_ = navigator; 102 page_navigator_ = navigator;
110 } 103 }
111 104
112 void BookmarkBarGtk::Init(Profile* profile) { 105 void BookmarkBarGtk::Init(Profile* profile) {
113 // Load the default images from the resource bundle. 106 // Load the default images from the resource bundle.
114 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 107 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
115 static GdkPixbuf* folder_icon = rb.GetPixbufNamed(IDR_BOOKMARK_BAR_FOLDER); 108 static GdkPixbuf* folder_icon = rb.GetPixbufNamed(IDR_BOOKMARK_BAR_FOLDER);
109 GtkThemeProperties properties(profile);
116 110
117 bookmark_hbox_.Own(gtk_hbox_new(FALSE, 0)); 111 bookmark_hbox_.Own(gtk_hbox_new(FALSE, 0));
118 112
119 instructions_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 113 instructions_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
120 gtk_alignment_set_padding(GTK_ALIGNMENT(instructions_), 0, 0, 114 gtk_alignment_set_padding(GTK_ALIGNMENT(instructions_), 0, 0,
121 kInstructionsPadding, 0); 115 kInstructionsPadding, 0);
122 g_signal_connect(instructions_, "destroy", G_CALLBACK(gtk_widget_destroyed), 116 g_signal_connect(instructions_, "destroy", G_CALLBACK(gtk_widget_destroyed),
123 &instructions_); 117 &instructions_);
124 GtkWidget* instructions_label = gtk_label_new( 118 GtkWidget* instructions_label = gtk_label_new(
125 l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str()); 119 l10n_util::GetStringUTF8(IDS_BOOKMARKS_NO_ITEMS).c_str());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 151
158 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(), 152 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(),
159 FALSE, FALSE, 0); 153 FALSE, FALSE, 0);
160 154
161 // We pack the button manually (rather than using gtk_button_set_*) so that 155 // We pack the button manually (rather than using gtk_button_set_*) so that
162 // we can have finer control over its label. 156 // we can have finer control over its label.
163 other_bookmarks_button_ = gtk_chrome_button_new(); 157 other_bookmarks_button_ = gtk_chrome_button_new();
164 ConnectFolderButtonEvents(other_bookmarks_button_); 158 ConnectFolderButtonEvents(other_bookmarks_button_);
165 159
166 GtkWidget* image = gtk_image_new_from_pixbuf(folder_icon); 160 GtkWidget* image = gtk_image_new_from_pixbuf(folder_icon);
167 GtkWidget* label = gtk_label_new( 161 other_bookmarks_label_ = gtk_label_new(
168 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str()); 162 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str());
169 bookmark_utils::SetButtonTextColors(label); 163 bookmark_utils::SetButtonTextColors(other_bookmarks_label_, &properties);
170 164
171 GtkWidget* box = gtk_hbox_new(FALSE, bookmark_utils::kBarButtonPadding); 165 GtkWidget* box = gtk_hbox_new(FALSE, bookmark_utils::kBarButtonPadding);
172 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); 166 gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
173 gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0); 167 gtk_box_pack_start(GTK_BOX(box), other_bookmarks_label_, FALSE, FALSE, 0);
174 gtk_container_add(GTK_CONTAINER(other_bookmarks_button_), box); 168 gtk_container_add(GTK_CONTAINER(other_bookmarks_button_), box);
175 169
176 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_, 170 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_,
177 FALSE, FALSE, 0); 171 FALSE, FALSE, 0);
178 172
179 // Set the current theme state for all the buttons. 173 // Set the current theme state for all the buttons.
180 UserChangedTheme(profile);
181 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0); 174 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0);
182 175
183 slide_animation_.reset(new SlideAnimation(this)); 176 slide_animation_.reset(new SlideAnimation(this));
184 } 177 }
185 178
186 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { 179 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) {
187 gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0); 180 gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0);
188 } 181 }
189 182
190 void BookmarkBarGtk::Show(bool animate) { 183 void BookmarkBarGtk::Show(bool animate) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 int index) { 260 int index) {
268 if (parent != model_->GetBookmarkBarNode()) { 261 if (parent != model_->GetBookmarkBarNode()) {
269 // We only care about nodes on the bookmark bar. 262 // We only care about nodes on the bookmark bar.
270 return; 263 return;
271 } 264 }
272 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 265 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
273 266
274 GtkToolItem* item = CreateBookmarkToolItem(parent->GetChild(index)); 267 GtkToolItem* item = CreateBookmarkToolItem(parent->GetChild(index));
275 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), 268 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()),
276 item, index); 269 item, index);
277 bool use_gtk = GtkThemeProvider::UseSystemThemeGraphics(profile_);
278 SetUseSystemThemeGraphicsOnToolbarItems(item, use_gtk);
279 270
280 SetInstructionState(parent); 271 SetInstructionState(parent);
281 } 272 }
282 273
283 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, 274 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model,
284 const BookmarkNode* parent, 275 const BookmarkNode* parent,
285 int index) { 276 int index) {
286 if (parent != model_->GetBookmarkBarNode()) { 277 if (parent != model_->GetBookmarkBarNode()) {
287 // We only care about nodes on the bookmark bar. 278 // We only care about nodes on the bookmark bar.
288 return; 279 return;
(...skipping 13 matching lines...) Expand all
302 if (node->GetParent() != model_->GetBookmarkBarNode()) { 293 if (node->GetParent() != model_->GetBookmarkBarNode()) {
303 // We only care about nodes on the bookmark bar. 294 // We only care about nodes on the bookmark bar.
304 return; 295 return;
305 } 296 }
306 int index = model_->GetBookmarkBarNode()->IndexOfChild(node); 297 int index = model_->GetBookmarkBarNode()->IndexOfChild(node);
307 DCHECK(index != -1); 298 DCHECK(index != -1);
308 299
309 GtkToolItem* item = gtk_toolbar_get_nth_item( 300 GtkToolItem* item = gtk_toolbar_get_nth_item(
310 GTK_TOOLBAR(bookmark_toolbar_.get()), index); 301 GTK_TOOLBAR(bookmark_toolbar_.get()), index);
311 GtkWidget* button = gtk_bin_get_child(GTK_BIN(item)); 302 GtkWidget* button = gtk_bin_get_child(GTK_BIN(item));
312 bookmark_utils::ConfigureButtonForNode(node, model, button); 303 GtkThemeProperties properties(profile_);
304 bookmark_utils::ConfigureButtonForNode(node, model, button, &properties);
313 } 305 }
314 306
315 void BookmarkBarGtk::BookmarkNodeFavIconLoaded(BookmarkModel* model, 307 void BookmarkBarGtk::BookmarkNodeFavIconLoaded(BookmarkModel* model,
316 const BookmarkNode* node) { 308 const BookmarkNode* node) {
317 BookmarkNodeChanged(model, node); 309 BookmarkNodeChanged(model, node);
318 } 310 }
319 311
320 void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, 312 void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
321 const BookmarkNode* node) { 313 const BookmarkNode* node) {
322 if (node != model_->GetBookmarkBarNode()) 314 if (node != model_->GetBookmarkBarNode())
323 return; // We only care about reordering of the bookmark bar node. 315 return; // We only care about reordering of the bookmark bar node.
324 316
325 // Purge and rebuild the bar. 317 // Purge and rebuild the bar.
326 RemoveAllBookmarkButtons(); 318 RemoveAllBookmarkButtons();
327 CreateAllBookmarkButtons(node); 319 CreateAllBookmarkButtons(node);
328 } 320 }
329 321
330 void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) { 322 void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) {
331 // Create a button for each of the children on the bookmark bar. 323 // Create a button for each of the children on the bookmark bar.
332 for (int i = 0; i < node->GetChildCount(); ++i) { 324 for (int i = 0; i < node->GetChildCount(); ++i) {
333 GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i)); 325 GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i));
334 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1); 326 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1);
335 } 327 }
336 328
337 // Now that we've made a bunch of toolbar items, we need to make sure they
338 // have the correct theme state.
339 UserChangedTheme(profile_);
340
341 SetInstructionState(node); 329 SetInstructionState(node);
342 } 330 }
343 331
344 void BookmarkBarGtk::SetInstructionState( 332 void BookmarkBarGtk::SetInstructionState(
345 const BookmarkNode* boomarks_bar_node) { 333 const BookmarkNode* boomarks_bar_node) {
346 show_instructions_ = (boomarks_bar_node->GetChildCount() == 0); 334 show_instructions_ = (boomarks_bar_node->GetChildCount() == 0);
347 if (show_instructions_) { 335 if (show_instructions_) {
348 gtk_widget_show_all(instructions_); 336 gtk_widget_show_all(instructions_);
349 } else { 337 } else {
350 gtk_widget_hide(instructions_); 338 gtk_widget_hide(instructions_);
351 } 339 }
352 } 340 }
353 341
354 void BookmarkBarGtk::RemoveAllBookmarkButtons() { 342 void BookmarkBarGtk::RemoveAllBookmarkButtons() {
355 gtk_util::RemoveAllChildren(bookmark_toolbar_.get()); 343 gtk_util::RemoveAllChildren(bookmark_toolbar_.get());
356 } 344 }
357 345
358 int BookmarkBarGtk::GetBookmarkButtonCount() { 346 int BookmarkBarGtk::GetBookmarkButtonCount() {
359 GList* children = gtk_container_get_children( 347 GList* children = gtk_container_get_children(
360 GTK_CONTAINER(bookmark_toolbar_.get())); 348 GTK_CONTAINER(bookmark_toolbar_.get()));
361 int count = g_list_length(children); 349 int count = g_list_length(children);
362 g_list_free(children); 350 g_list_free(children);
363 return count; 351 return count;
364 } 352 }
365 353
366 bool BookmarkBarGtk::IsAlwaysShown() { 354 bool BookmarkBarGtk::IsAlwaysShown() {
367 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 355 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
368 } 356 }
369 357
370 void BookmarkBarGtk::UserChangedTheme(Profile* profile) { 358 void BookmarkBarGtk::UserChangedTheme(GtkThemeProperties* properties) {
371 bool use_gtk = GtkThemeProvider::UseSystemThemeGraphics(profile); 359 gtk_chrome_button_set_use_gtk_rendering(
360 GTK_CHROME_BUTTON(other_bookmarks_button_),
361 properties->use_gtk_rendering);
362 bookmark_utils::SetButtonTextColors(other_bookmarks_label_, properties);
372 363
373 gtk_chrome_button_set_use_gtk_rendering( 364 if (model_) {
374 GTK_CHROME_BUTTON(other_bookmarks_button_), use_gtk); 365 // Regenerate the bookmark bar with all new objects with their theme
366 // properties set correctly for the new theme.
367 RemoveAllBookmarkButtons();
375 368
376 gtk_container_foreach( 369 const BookmarkNode* node = model_->GetBookmarkBarNode();
377 GTK_CONTAINER(bookmark_toolbar_.get()), 370 DCHECK(node && model_->other_node());
378 reinterpret_cast<void (*)(GtkWidget*, void*)>( 371 CreateAllBookmarkButtons(node);
379 SetUseSystemThemeGraphicsOnToolbarItems), 372 } else {
380 reinterpret_cast<void*>(use_gtk)); 373 DLOG(ERROR) << "Received a theme change notification while we don't have a "
374 << "BookmarkModel. Taking no action.";
375 }
381 } 376 }
382 377
383 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) { 378 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) {
384 DCHECK_EQ(animation, slide_animation_.get()); 379 DCHECK_EQ(animation, slide_animation_.get());
385 380
386 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 381 gtk_widget_set_size_request(bookmark_hbox_.get(), -1,
387 animation->GetCurrentValue() * 382 animation->GetCurrentValue() *
388 kBookmarkBarHeight); 383 kBookmarkBarHeight);
389 } 384 }
390 385
391 void BookmarkBarGtk::AnimationEnded(const Animation* animation) { 386 void BookmarkBarGtk::AnimationEnded(const Animation* animation) {
392 DCHECK_EQ(animation, slide_animation_.get()); 387 DCHECK_EQ(animation, slide_animation_.get());
393 388
394 if (!slide_animation_->IsShowing()) 389 if (!slide_animation_->IsShowing())
395 gtk_widget_hide(bookmark_hbox_.get()); 390 gtk_widget_hide(bookmark_hbox_.get());
396 } 391 }
397 392
398 GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) { 393 GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) {
399 GtkWidget* button = gtk_chrome_button_new(); 394 GtkWidget* button = gtk_chrome_button_new();
400 bookmark_utils::ConfigureButtonForNode(node, model_, button); 395 GtkThemeProperties properties(profile_);
396 bookmark_utils::ConfigureButtonForNode(node, model_, button, &properties);
401 397
402 // The tool item is also a source for dragging 398 // The tool item is also a source for dragging
403 gtk_drag_source_set(button, GDK_BUTTON1_MASK, 399 gtk_drag_source_set(button, GDK_BUTTON1_MASK,
404 NULL, 0, GDK_ACTION_MOVE); 400 NULL, 0, GDK_ACTION_MOVE);
405 GtkDndUtil::SetSourceTargetListFromCodeMask( 401 GtkDndUtil::SetSourceTargetListFromCodeMask(
406 button, GtkDndUtil::X_CHROME_BOOKMARK_ITEM); 402 button, GtkDndUtil::X_CHROME_BOOKMARK_ITEM);
407 g_signal_connect(G_OBJECT(button), "drag-begin", 403 g_signal_connect(G_OBJECT(button), "drag-begin",
408 G_CALLBACK(&OnButtonDragBegin), this); 404 G_CALLBACK(&OnButtonDragBegin), this);
409 g_signal_connect(G_OBJECT(button), "drag-end", 405 g_signal_connect(G_OBJECT(button), "drag-end",
410 G_CALLBACK(&OnButtonDragEnd), this); 406 G_CALLBACK(&OnButtonDragEnd), this);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 572
577 // Signal to any future OnButtonReleased calls that we're dragging instead of 573 // Signal to any future OnButtonReleased calls that we're dragging instead of
578 // pressing. 574 // pressing.
579 bar->ignore_button_release_ = true; 575 bar->ignore_button_release_ = true;
580 576
581 const BookmarkNode* node = bar->GetNodeForToolButton(button); 577 const BookmarkNode* node = bar->GetNodeForToolButton(button);
582 DCHECK(!bar->dragged_node_); 578 DCHECK(!bar->dragged_node_);
583 bar->dragged_node_ = node; 579 bar->dragged_node_ = node;
584 DCHECK(bar->dragged_node_); 580 DCHECK(bar->dragged_node_);
585 581
586 GtkWidget* window = bookmark_utils::GetDragRepresentation(node, bar->model_); 582 GtkThemeProperties properties(bar->profile_);
583 GtkWidget* window = bookmark_utils::GetDragRepresentation(node, bar->model_,
584 &properties);
587 gint x, y; 585 gint x, y;
588 gtk_widget_get_pointer(button, &x, &y); 586 gtk_widget_get_pointer(button, &x, &y);
589 gtk_drag_set_icon_widget(drag_context, window, x, y); 587 gtk_drag_set_icon_widget(drag_context, window, x, y);
590 588
591 // Hide our node. 589 // Hide our node.
592 gtk_widget_hide(button); 590 gtk_widget_hide(button);
593 } 591 }
594 592
595 // static 593 // static
596 void BookmarkBarGtk::OnButtonDragEnd(GtkWidget* button, 594 void BookmarkBarGtk::OnButtonDragEnd(GtkWidget* button,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 bar->InitBackground(); 774 bar->InitBackground();
777 gfx::Point tabstrip_origin = 775 gfx::Point tabstrip_origin =
778 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); 776 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget);
779 bar->background_ninebox_->RenderTopCenterStrip( 777 bar->background_ninebox_->RenderTopCenterStrip(
780 cr, tabstrip_origin.x(), tabstrip_origin.y(), 778 cr, tabstrip_origin.x(), tabstrip_origin.y(),
781 event->area.x + event->area.width - tabstrip_origin.x()); 779 event->area.x + event->area.width - tabstrip_origin.x());
782 cairo_destroy(cr); 780 cairo_destroy(cr);
783 781
784 return FALSE; // Propagate expose to children. 782 return FALSE; // Propagate expose to children.
785 } 783 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/bookmark_bar_gtk.h ('k') | chrome/browser/gtk/bookmark_menu_controller_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698