| OLD | NEW |
| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 GtkWidget* label; | 82 GtkWidget* label; |
| 83 gtk_container_foreach(GTK_CONTAINER(button), SearchForLabel, &label); | 83 gtk_container_foreach(GTK_CONTAINER(button), SearchForLabel, &label); |
| 84 if (label) { | 84 if (label) { |
| 85 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &kEnabledColor); | 85 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &kEnabledColor); |
| 86 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, &kEnabledColor); | 86 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, &kEnabledColor); |
| 87 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &kHighlightColor); | 87 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &kHighlightColor); |
| 88 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, &kDisabledColor); | 88 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, &kDisabledColor); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 std::string DoubleUnderscores(const std::string& text) { |
| 93 std::string ret; |
| 94 ret.reserve(text.length() * 2); |
| 95 for (size_t i = 0; i < text.length(); ++i) { |
| 96 if ('_' == text[i]) { |
| 97 ret.push_back('_'); |
| 98 ret.push_back('_'); |
| 99 } else { |
| 100 ret.push_back(text[i]); |
| 101 } |
| 102 } |
| 103 |
| 104 return ret; |
| 105 } |
| 106 |
| 92 } // namespace | 107 } // namespace |
| 93 | 108 |
| 94 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser, | 109 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser, |
| 95 BrowserWindowGtk* window) | 110 BrowserWindowGtk* window) |
| 96 : profile_(NULL), | 111 : profile_(NULL), |
| 97 page_navigator_(NULL), | 112 page_navigator_(NULL), |
| 98 browser_(browser), | 113 browser_(browser), |
| 99 window_(window), | 114 window_(window), |
| 100 model_(NULL), | 115 model_(NULL), |
| 101 instructions_(NULL), | 116 instructions_(NULL), |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 419 } |
| 405 | 420 |
| 406 void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node, | 421 void BookmarkBarGtk::ConfigureButtonForNode(BookmarkNode* node, |
| 407 GtkWidget* button) { | 422 GtkWidget* button) { |
| 408 std::string tooltip = BuildTooltip(node); | 423 std::string tooltip = BuildTooltip(node); |
| 409 if (!tooltip.empty()) | 424 if (!tooltip.empty()) |
| 410 gtk_widget_set_tooltip_text(button, tooltip.c_str()); | 425 gtk_widget_set_tooltip_text(button, tooltip.c_str()); |
| 411 | 426 |
| 412 // TODO(erg): Consider a soft maximum instead of this hard 15. | 427 // TODO(erg): Consider a soft maximum instead of this hard 15. |
| 413 std::wstring title = node->GetTitle(); | 428 std::wstring title = node->GetTitle(); |
| 414 title = title.substr(0, std::min(title.size(), kMaxCharsOnAButton)); | 429 // Don't treat underscores as mnemonics. |
| 415 gtk_button_set_label(GTK_BUTTON(button), WideToUTF8(title).c_str()); | 430 // O, that we could just use gtk_button_set_use_underline()! |
| 431 // See http://bugzilla.gnome.org/show_bug.cgi?id=586330 |
| 432 std::string text = DoubleUnderscores(WideToUTF8(title)); |
| 433 text = text.substr(0, std::min(text.size(), kMaxCharsOnAButton)); |
| 434 gtk_button_set_label(GTK_BUTTON(button), text.c_str()); |
| 416 | 435 |
| 417 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model_); | 436 GdkPixbuf* pixbuf = bookmark_utils::GetPixbufForNode(node, model_); |
| 418 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf)); | 437 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf)); |
| 419 g_object_unref(pixbuf); | 438 g_object_unref(pixbuf); |
| 420 | 439 |
| 421 SetButtonTextColors(button); | 440 SetButtonTextColors(button); |
| 422 g_object_set_data(G_OBJECT(button), kBookmarkNode, | 441 g_object_set_data(G_OBJECT(button), kBookmarkNode, |
| 423 reinterpret_cast<void*>(node)); | 442 reinterpret_cast<void*>(node)); |
| 424 } | 443 } |
| 425 | 444 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 bar->InitBackground(); | 836 bar->InitBackground(); |
| 818 gfx::Point tabstrip_origin = | 837 gfx::Point tabstrip_origin = |
| 819 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); | 838 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); |
| 820 bar->background_ninebox_->RenderTopCenterStrip( | 839 bar->background_ninebox_->RenderTopCenterStrip( |
| 821 cr, tabstrip_origin.x(), tabstrip_origin.y(), | 840 cr, tabstrip_origin.x(), tabstrip_origin.y(), |
| 822 event->area.x + event->area.width - tabstrip_origin.x()); | 841 event->area.x + event->area.width - tabstrip_origin.x()); |
| 823 cairo_destroy(cr); | 842 cairo_destroy(cr); |
| 824 | 843 |
| 825 return FALSE; // Propagate expose to children. | 844 return FALSE; // Propagate expose to children. |
| 826 } | 845 } |
| OLD | NEW |