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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc

Issue 6462009: Allow dragging and dropping of URLs to any portion of the toolbar view.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
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/autocomplete/autocomplete_edit_view_gtk.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/tab_contents/tab_contents.h" 24 #include "chrome/browser/tab_contents/tab_contents.h"
25 #include "chrome/browser/ui/gtk/gtk_util.h" 25 #include "chrome/browser/ui/gtk/gtk_util.h"
26 #include "chrome/browser/ui/gtk/view_id_util.h" 26 #include "chrome/browser/ui/gtk/view_id_util.h"
27 #include "chrome/browser/ui/toolbar/toolbar_model.h" 27 #include "chrome/browser/ui/toolbar/toolbar_model.h"
28 #include "chrome/common/notification_service.h" 28 #include "chrome/common/notification_service.h"
29 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "net/base/escape.h" 31 #include "net/base/escape.h"
32 #include "third_party/undoview/undo_view.h" 32 #include "third_party/undoview/undo_view.h"
33 #include "ui/base/animation/multi_animation.h" 33 #include "ui/base/animation/multi_animation.h"
34 #include "ui/base/dragdrop/drag_drop_types.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/color_utils.h" 37 #include "ui/gfx/color_utils.h"
37 #include "ui/gfx/font.h" 38 #include "ui/gfx/font.h"
38 #include "ui/gfx/gtk_util.h" 39 #include "ui/gfx/gtk_util.h"
39 #include "ui/gfx/skia_utils_gtk.h" 40 #include "ui/gfx/skia_utils_gtk.h"
40 41
41 #if defined(TOOLKIT_VIEWS) 42 #if defined(TOOLKIT_VIEWS)
42 #include "chrome/browser/autocomplete/autocomplete_edit_view_views.h" 43 #include "chrome/browser/autocomplete/autocomplete_edit_view_views.h"
43 #include "chrome/browser/ui/gtk/accessible_widget_helper_gtk.h" 44 #include "chrome/browser/ui/gtk/accessible_widget_helper_gtk.h"
44 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" 45 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h"
45 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 46 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
46 #include "views/controls/textfield/native_textfield_views.h" 47 #include "views/controls/textfield/native_textfield_views.h"
48 #include "views/events/event.h"
47 #else 49 #else
48 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" 50 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h"
49 #include "chrome/browser/ui/gtk/gtk_theme_provider.h" 51 #include "chrome/browser/ui/gtk/gtk_theme_provider.h"
50 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" 52 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
51 #endif 53 #endif
52 54
53 namespace { 55 namespace {
54 56
55 const gchar* kAutocompleteEditViewGtkKey = "__ACE_VIEW_GTK__"; 57 const gchar* kAutocompleteEditViewGtkKey = "__ACE_VIEW_GTK__";
56 58
57 const char kTextBaseColor[] = "#808080"; 59 const char kTextBaseColor[] = "#808080";
58 const char kSecureSchemeColor[] = "#079500"; 60 const char kSecureSchemeColor[] = "#079500";
59 const char kSecurityErrorSchemeColor[] = "#a20000"; 61 const char kSecurityErrorSchemeColor[] = "#a20000";
60 62
61 const double kStrikethroughStrokeRed = 162.0 / 256.0; 63 const double kStrikethroughStrokeRed = 162.0 / 256.0;
62 const double kStrikethroughStrokeWidth = 2.0; 64 const double kStrikethroughStrokeWidth = 2.0;
63 65
64 size_t GetUTF8Offset(const string16& text, size_t text_offset) { 66 size_t GetUTF8Offset(const string16& text, size_t text_offset) {
65 return UTF16ToUTF8(text.substr(0, text_offset)).size(); 67 return UTF16ToUTF8(text.substr(0, text_offset)).size();
66 } 68 }
67 69
70 // A helper method for determining a valid drag operation given the allowed
71 // operation. We prefer copy over link.
72 int CopyOrLinkDragOperation(int drag_operation) {
73 if (drag_operation & ui::DragDropTypes::DRAG_COPY)
74 return ui::DragDropTypes::DRAG_COPY;
75 if (drag_operation & ui::DragDropTypes::DRAG_LINK)
76 return ui::DragDropTypes::DRAG_LINK;
77 return ui::DragDropTypes::DRAG_NONE;
78 }
79
68 // Stores GTK+-specific state so it can be restored after switching tabs. 80 // Stores GTK+-specific state so it can be restored after switching tabs.
69 struct ViewState { 81 struct ViewState {
70 explicit ViewState(const AutocompleteEditViewGtk::CharRange& selection_range) 82 explicit ViewState(const AutocompleteEditViewGtk::CharRange& selection_range)
71 : selection_range(selection_range) { 83 : selection_range(selection_range) {
72 } 84 }
73 85
74 // Range of selected text. 86 // Range of selected text.
75 AutocompleteEditViewGtk::CharRange selection_range; 87 AutocompleteEditViewGtk::CharRange selection_range;
76 }; 88 };
77 89
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 850
839 #if defined(TOOLKIT_VIEWS) 851 #if defined(TOOLKIT_VIEWS)
840 views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) { 852 views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) {
841 views::NativeViewHost* host = new views::NativeViewHost; 853 views::NativeViewHost* host = new views::NativeViewHost;
842 parent->AddChildView(host); 854 parent->AddChildView(host);
843 host->set_focus_view(parent); 855 host->set_focus_view(parent);
844 host->Attach(GetNativeView()); 856 host->Attach(GetNativeView());
845 return host; 857 return host;
846 } 858 }
847 859
860 int AutocompleteEditViewGtk::OnPerformDrop(
861 const views::DropTargetEvent& event) {
862 std::wstring text;
863 const ui::OSExchangeData& data = event.data();
864 if (data.HasURL()) {
865 GURL url;
866 std::wstring title;
867 if (data.GetURLAndTitle(&url, &title))
868 text = UTF8ToWide(url.spec());
869 } else {
870 std::wstring data_string;
871 if (data.GetString(&data_string))
872 text = CollapseWhitespace(data_string, true);
873 }
874
875 if (!text.empty() && OnPerformDropImpl(WideToUTF16(text)))
876 return CopyOrLinkDragOperation(event.source_operations());
877
878 return ui::DragDropTypes::DRAG_NONE;
879 }
880
848 void AutocompleteEditViewGtk::EnableAccessibility() { 881 void AutocompleteEditViewGtk::EnableAccessibility() {
849 accessible_widget_helper_.reset( 882 accessible_widget_helper_.reset(
850 new AccessibleWidgetHelper(text_view(), model_->profile())); 883 new AccessibleWidgetHelper(text_view(), model_->profile()));
851 accessible_widget_helper_->SetWidgetName( 884 accessible_widget_helper_->SetWidgetName(
852 text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION)); 885 text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION));
853 } 886 }
854 887
855 // static 888 // static
856 AutocompleteEditView* AutocompleteEditViewGtk::Create( 889 AutocompleteEditView* AutocompleteEditViewGtk::Create(
857 AutocompleteEditController* controller, 890 AutocompleteEditController* controller,
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 // allow default behavior for such drags. 1574 // allow default behavior for such drags.
1542 if (context->source_window == text_view_->window) 1575 if (context->source_window == text_view_->window)
1543 return; 1576 return;
1544 1577
1545 guchar* text = gtk_selection_data_get_text(selection_data); 1578 guchar* text = gtk_selection_data_get_text(selection_data);
1546 if (!text) 1579 if (!text)
1547 return; 1580 return;
1548 1581
1549 string16 possible_url = UTF8ToUTF16(reinterpret_cast<char*>(text)); 1582 string16 possible_url = UTF8ToUTF16(reinterpret_cast<char*>(text));
1550 g_free(text); 1583 g_free(text);
1551 if (model_->CanPasteAndGo(CollapseWhitespace(possible_url, true))) { 1584 if (OnPerformDropImpl(possible_url)) {
1552 model_->PasteAndGo();
1553 gtk_drag_finish(context, TRUE, TRUE, time); 1585 gtk_drag_finish(context, TRUE, TRUE, time);
1554 1586
1555 static guint signal_id = 1587 static guint signal_id =
1556 g_signal_lookup("drag-data-received", GTK_TYPE_WIDGET); 1588 g_signal_lookup("drag-data-received", GTK_TYPE_WIDGET);
1557 g_signal_stop_emission(text_view_, signal_id, 0); 1589 g_signal_stop_emission(text_view_, signal_id, 0);
1558 } 1590 }
1559 } 1591 }
1560 1592
1561 void AutocompleteEditViewGtk::HandleDragDataGet( 1593 void AutocompleteEditViewGtk::HandleDragDataGet(
1562 GtkWidget* widget, 1594 GtkWidget* widget,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 copy ? copy_signal_id : cut_signal_id, 1765 copy ? copy_signal_id : cut_signal_id,
1734 0); 1766 0);
1735 1767
1736 if (!copy) 1768 if (!copy)
1737 gtk_text_buffer_delete_selection(text_buffer_, true, true); 1769 gtk_text_buffer_delete_selection(text_buffer_, true, true);
1738 } 1770 }
1739 1771
1740 OwnPrimarySelection(UTF16ToUTF8(text)); 1772 OwnPrimarySelection(UTF16ToUTF8(text));
1741 } 1773 }
1742 1774
1775 bool AutocompleteEditViewGtk::OnPerformDropImpl(const string16& text) {
1776 if (model_->CanPasteAndGo(CollapseWhitespace(text, true))) {
1777 model_->PasteAndGo();
1778 return true;
1779 }
1780
1781 return false;
1782 }
1783
1743 gfx::Font AutocompleteEditViewGtk::GetFont() { 1784 gfx::Font AutocompleteEditViewGtk::GetFont() {
1744 #if defined(TOOLKIT_VIEWS) 1785 #if defined(TOOLKIT_VIEWS)
1745 bool use_gtk = false; 1786 bool use_gtk = false;
1746 #else 1787 #else
1747 bool use_gtk = theme_provider_->UseGtkTheme(); 1788 bool use_gtk = theme_provider_->UseGtkTheme();
1748 #endif 1789 #endif
1749 1790
1750 if (use_gtk) { 1791 if (use_gtk) {
1751 // If we haven't initialized the text view yet, just create a temporary one 1792 // If we haven't initialized the text view yet, just create a temporary one
1752 // whose style we can grab. 1793 // whose style we can grab.
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 // baseline, so we need to move the |instant_view_| down to make sure it 2335 // baseline, so we need to move the |instant_view_| down to make sure it
2295 // has the same baseline as the |text_view_|. 2336 // has the same baseline as the |text_view_|.
2296 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2337 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2297 int height; 2338 int height;
2298 pango_layout_get_size(layout, NULL, &height); 2339 pango_layout_get_size(layout, NULL, &height);
2299 PangoLayoutIter* iter = pango_layout_get_iter(layout); 2340 PangoLayoutIter* iter = pango_layout_get_iter(layout);
2300 int baseline = pango_layout_iter_get_baseline(iter); 2341 int baseline = pango_layout_iter_get_baseline(iter);
2301 pango_layout_iter_free(iter); 2342 pango_layout_iter_free(iter);
2302 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2343 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2303 } 2344 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_gtk.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698