| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/gtk_util.h" | 5 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 namespace { | 58 namespace { |
| 59 | 59 |
| 60 #if defined(GOOGLE_CHROME_BUILD) | 60 #if defined(GOOGLE_CHROME_BUILD) |
| 61 static const char* kIconName = "google-chrome"; | 61 static const char* kIconName = "google-chrome"; |
| 62 #else | 62 #else |
| 63 static const char* kIconName = "chromium-browser"; | 63 static const char* kIconName = "chromium-browser"; |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; | 66 const char kBoldLabelMarkup[] = "<span weight='bold'>%s</span>"; |
| 67 | 67 |
| 68 // Max size of each component of the button tooltips. |
| 69 const size_t kMaxTooltipTitleLength = 100; |
| 70 const size_t kMaxTooltipURLLength = 400; |
| 71 |
| 68 // Callback used in RemoveAllChildren. | 72 // Callback used in RemoveAllChildren. |
| 69 void RemoveWidget(GtkWidget* widget, gpointer container) { | 73 void RemoveWidget(GtkWidget* widget, gpointer container) { |
| 70 gtk_container_remove(GTK_CONTAINER(container), widget); | 74 gtk_container_remove(GTK_CONTAINER(container), widget); |
| 71 } | 75 } |
| 72 | 76 |
| 73 // These two functions are copped almost directly from gtk core. The only | 77 // These two functions are copped almost directly from gtk core. The only |
| 74 // difference is that they accept middle clicks. | 78 // difference is that they accept middle clicks. |
| 75 gboolean OnMouseButtonPressed(GtkWidget* widget, GdkEventButton* event, | 79 gboolean OnMouseButtonPressed(GtkWidget* widget, GdkEventButton* event, |
| 76 gpointer userdata) { | 80 gpointer userdata) { |
| 77 if (event->type == GDK_BUTTON_PRESS) { | 81 if (event->type == GDK_BUTTON_PRESS) { |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 int x, y; | 767 int x, y; |
| 764 gtk_widget_get_pointer(widget, &x, &y); | 768 gtk_widget_get_pointer(widget, &x, &y); |
| 765 return gfx::Point(x, y); | 769 return gfx::Point(x, y); |
| 766 } | 770 } |
| 767 | 771 |
| 768 GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr) { | 772 GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr) { |
| 769 GdkPoint point = {ltr ? x : width - x, y}; | 773 GdkPoint point = {ltr ? x : width - x, y}; |
| 770 return point; | 774 return point; |
| 771 } | 775 } |
| 772 | 776 |
| 777 std::string BuildTooltipTitleFor(string16 title, GURL url) { |
| 778 const std::string& url_str = url.possibly_invalid_spec(); |
| 779 const std::string& title_str = UTF16ToUTF8(title); |
| 780 |
| 781 std::string truncated_url = UTF16ToUTF8(l10n_util::TruncateString( |
| 782 UTF8ToUTF16(url_str), kMaxTooltipURLLength)); |
| 783 gchar* escaped_url_cstr = g_markup_escape_text(truncated_url.c_str(), |
| 784 truncated_url.size()); |
| 785 std::string escaped_url(escaped_url_cstr); |
| 786 g_free(escaped_url_cstr); |
| 787 |
| 788 std::string tooltip; |
| 789 if (url_str == title_str || title.empty()) { |
| 790 return escaped_url; |
| 791 } else { |
| 792 std::string truncated_title = UTF16ToUTF8(l10n_util::TruncateString( |
| 793 title, kMaxTooltipTitleLength)); |
| 794 gchar* escaped_title_cstr = g_markup_escape_text(truncated_title.c_str(), |
| 795 truncated_title.size()); |
| 796 std::string escaped_title(escaped_title_cstr); |
| 797 g_free(escaped_title_cstr); |
| 798 |
| 799 if (!escaped_url.empty()) |
| 800 return std::string("<b>") + escaped_title + "</b>\n" + escaped_url; |
| 801 else |
| 802 return std::string("<b>") + escaped_title + "</b>"; |
| 803 } |
| 804 } |
| 805 |
| 773 void DrawTextEntryBackground(GtkWidget* offscreen_entry, | 806 void DrawTextEntryBackground(GtkWidget* offscreen_entry, |
| 774 GtkWidget* widget_to_draw_on, | 807 GtkWidget* widget_to_draw_on, |
| 775 GdkRectangle* dirty_rec, | 808 GdkRectangle* dirty_rec, |
| 776 GdkRectangle* rec) { | 809 GdkRectangle* rec) { |
| 777 GtkStyle* gtk_owned_style = gtk_rc_get_style(offscreen_entry); | 810 GtkStyle* gtk_owned_style = gtk_rc_get_style(offscreen_entry); |
| 778 // GTK owns the above and we're going to have to make our own copy of it | 811 // GTK owns the above and we're going to have to make our own copy of it |
| 779 // that we can edit. | 812 // that we can edit. |
| 780 GtkStyle* our_style = gtk_style_copy(gtk_owned_style); | 813 GtkStyle* our_style = gtk_style_copy(gtk_owned_style); |
| 781 our_style = gtk_style_attach(our_style, widget_to_draw_on->window); | 814 our_style = gtk_style_attach(our_style, widget_to_draw_on->window); |
| 782 | 815 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 | 1281 |
| 1249 void DoCopy(BrowserWindow* window) { | 1282 void DoCopy(BrowserWindow* window) { |
| 1250 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); | 1283 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); |
| 1251 } | 1284 } |
| 1252 | 1285 |
| 1253 void DoPaste(BrowserWindow* window) { | 1286 void DoPaste(BrowserWindow* window) { |
| 1254 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); | 1287 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); |
| 1255 } | 1288 } |
| 1256 | 1289 |
| 1257 } // namespace gtk_util | 1290 } // namespace gtk_util |
| OLD | NEW |