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/tab_contents/tab_contents_view_gtk.h" | 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
11 #include "app/l10n_util.h" | |
11 #include "base/mime_util.h" | 12 #include "base/mime_util.h" |
12 #include "base/gfx/point.h" | 13 #include "base/gfx/point.h" |
13 #include "base/gfx/rect.h" | 14 #include "base/gfx/rect.h" |
14 #include "base/gfx/size.h" | 15 #include "base/gfx/size.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
17 #include "chrome/browser/download/download_shelf.h" | 18 #include "chrome/browser/download/download_shelf.h" |
18 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" | 19 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" |
19 #include "chrome/browser/gtk/browser_window_gtk.h" | 20 #include "chrome/browser/gtk/browser_window_gtk.h" |
20 #include "chrome/browser/gtk/constrained_window_gtk.h" | 21 #include "chrome/browser/gtk/constrained_window_gtk.h" |
21 #include "chrome/browser/gtk/gtk_dnd_util.h" | 22 #include "chrome/browser/gtk/gtk_dnd_util.h" |
22 #include "chrome/browser/gtk/gtk_floating_container.h" | 23 #include "chrome/browser/gtk/gtk_floating_container.h" |
23 #include "chrome/browser/gtk/gtk_theme_provider.h" | 24 #include "chrome/browser/gtk/gtk_theme_provider.h" |
24 #include "chrome/browser/gtk/sad_tab_gtk.h" | 25 #include "chrome/browser/gtk/sad_tab_gtk.h" |
25 #include "chrome/browser/renderer_host/render_view_host.h" | 26 #include "chrome/browser/renderer_host/render_view_host.h" |
26 #include "chrome/browser/renderer_host/render_view_host_factory.h" | 27 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
27 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 28 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
28 #include "chrome/browser/tab_contents/interstitial_page.h" | 29 #include "chrome/browser/tab_contents/interstitial_page.h" |
29 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" | 30 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" |
30 #include "chrome/browser/tab_contents/tab_contents.h" | 31 #include "chrome/browser/tab_contents/tab_contents.h" |
31 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 32 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
32 #include "chrome/common/gtk_util.h" | 33 #include "chrome/common/gtk_util.h" |
33 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
34 #include "chrome/common/notification_source.h" | 35 #include "chrome/common/notification_source.h" |
35 #include "chrome/common/notification_type.h" | 36 #include "chrome/common/notification_type.h" |
37 #include "grit/app_strings.h" | |
38 #include "net/base/net_util.h" | |
36 #include "webkit/glue/webdropdata.h" | 39 #include "webkit/glue/webdropdata.h" |
37 | 40 |
38 namespace { | 41 namespace { |
39 | 42 |
40 // TODO(erg): I have no idea how to progromatically figure out how wide the | 43 // TODO(erg): I have no idea how to progromatically figure out how wide the |
41 // vertical scrollbar is. Hack it with a hardcoded value for now. | 44 // vertical scrollbar is. Hack it with a hardcoded value for now. |
42 const int kScrollbarWidthHack = 25; | 45 const int kScrollbarWidthHack = 25; |
43 | 46 |
44 // Called when the content view gtk widget is tabbed to, or after the call to | 47 // Called when the content view gtk widget is tabbed to, or after the call to |
45 // gtk_widget_child_focus() in TakeFocus(). We return true | 48 // gtk_widget_child_focus() in TakeFocus(). We return true |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
783 // static | 786 // static |
784 void TabContentsViewGtk::OnDragDataGet( | 787 void TabContentsViewGtk::OnDragDataGet( |
785 GtkWidget* drag_widget, | 788 GtkWidget* drag_widget, |
786 GdkDragContext* context, GtkSelectionData* selection_data, | 789 GdkDragContext* context, GtkSelectionData* selection_data, |
787 guint target_type, guint time, TabContentsViewGtk* view) { | 790 guint target_type, guint time, TabContentsViewGtk* view) { |
788 const int bits_per_byte = 8; | 791 const int bits_per_byte = 8; |
789 // We must make these initializations here or gcc complains about jumping past | 792 // We must make these initializations here or gcc complains about jumping past |
790 // it in the switch statement. | 793 // it in the switch statement. |
791 std::string utf8_text; | 794 std::string utf8_text; |
792 Pickle pickle; | 795 Pickle pickle; |
796 std::string name; | |
tony
2009/07/22 00:51:08
Nit: If you add {} around the case block, you can
Evan Stade
2009/07/22 00:54:55
oh, sweet. This has rather annoyed me.
| |
797 const GURL& url = view->drop_data_->url; | |
793 | 798 |
794 switch (target_type) { | 799 switch (target_type) { |
795 case GtkDndUtil::TEXT_PLAIN: | 800 case GtkDndUtil::TEXT_PLAIN: |
796 utf8_text = UTF16ToUTF8(view->drop_data_->plain_text); | 801 utf8_text = UTF16ToUTF8(view->drop_data_->plain_text); |
797 gtk_selection_data_set_text(selection_data, utf8_text.c_str(), | 802 gtk_selection_data_set_text(selection_data, utf8_text.c_str(), |
798 utf8_text.length()); | 803 utf8_text.length()); |
799 break; | 804 break; |
800 | 805 |
801 case GtkDndUtil::TEXT_URI_LIST: | 806 case GtkDndUtil::TEXT_URI_LIST: |
802 gchar* uri_array[2]; | 807 gchar* uri_array[2]; |
803 uri_array[0] = strdup(view->drop_data_->url.spec().c_str()); | 808 uri_array[0] = strdup(view->drop_data_->url.spec().c_str()); |
804 uri_array[1] = NULL; | 809 uri_array[1] = NULL; |
805 gtk_selection_data_set_uris(selection_data, uri_array); | 810 gtk_selection_data_set_uris(selection_data, uri_array); |
806 free(uri_array[0]); | 811 free(uri_array[0]); |
807 break; | 812 break; |
808 | 813 |
809 case GtkDndUtil::TEXT_HTML: | 814 case GtkDndUtil::TEXT_HTML: |
810 // TODO(estade): change relative links to be absolute using | 815 // TODO(estade): change relative links to be absolute using |
811 // |html_base_url|. | 816 // |html_base_url|. |
812 utf8_text = UTF16ToUTF8(view->drop_data_->text_html); | 817 utf8_text = UTF16ToUTF8(view->drop_data_->text_html); |
813 gtk_selection_data_set(selection_data, | 818 gtk_selection_data_set(selection_data, |
814 GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_HTML), | 819 GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_HTML), |
815 bits_per_byte, | 820 bits_per_byte, |
816 reinterpret_cast<const guchar*>(utf8_text.c_str()), | 821 reinterpret_cast<const guchar*>(utf8_text.c_str()), |
817 utf8_text.length()); | 822 utf8_text.length()); |
818 break; | 823 break; |
819 | 824 |
820 case GtkDndUtil::CHROME_NAMED_URL: | 825 case GtkDndUtil::CHROME_NAMED_URL: |
821 pickle.WriteString(UTF16ToUTF8(view->drop_data_->url_title)); | 826 if (!view->drop_data_->url_title.empty()) { |
822 pickle.WriteString(view->drop_data_->url.spec()); | 827 name = UTF16ToUTF8(view->drop_data_->url_title); |
828 } else if (url.is_valid()) { | |
829 name = WideToUTF8(net::GetSuggestedFilename( | |
830 url, std::string(), std::string(), std::wstring())); | |
831 } else { | |
832 // Nothing else can be done, just use a default. | |
833 name = l10n_util::GetStringUTF8(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME); | |
834 } | |
835 pickle.WriteString(name); | |
836 pickle.WriteString(url.spec()); | |
823 gtk_selection_data_set(selection_data, | 837 gtk_selection_data_set(selection_data, |
824 GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), | 838 GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL), |
825 bits_per_byte, | 839 bits_per_byte, |
826 reinterpret_cast<const guchar*>(pickle.data()), | 840 reinterpret_cast<const guchar*>(pickle.data()), |
827 pickle.size()); | 841 pickle.size()); |
828 break; | 842 break; |
829 | 843 |
830 case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS: | 844 case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS: |
831 gtk_selection_data_set(selection_data, | 845 gtk_selection_data_set(selection_data, |
832 view->drag_file_mime_type_, bits_per_byte, | 846 view->drag_file_mime_type_, bits_per_byte, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 939 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
926 widget, "x", &value); | 940 widget, "x", &value); |
927 | 941 |
928 int child_y = std::max(half_view_height - (requisition.height / 2), 0); | 942 int child_y = std::max(half_view_height - (requisition.height / 2), 0); |
929 g_value_set_int(&value, child_y); | 943 g_value_set_int(&value, child_y); |
930 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 944 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
931 widget, "y", &value); | 945 widget, "y", &value); |
932 g_value_unset(&value); | 946 g_value_unset(&value); |
933 } | 947 } |
934 } | 948 } |
OLD | NEW |