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