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

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 const ui::OSExchangeData& data = event.data();
sky 2011/02/11 01:06:07 What if the drag originated from this view?
Roger Tawa OOO till Jul 10th 2011/02/11 15:20:17 Good point. This code should be equivalent to the
863 if (data.HasURL()) {
864 GURL url;
865 std::wstring title;
866 if (data.GetURLAndTitle(&url, &title)) {
867 SetUserText(WideToUTF16(UTF8ToWide(url.spec())));
868 model()->AcceptInput(CURRENT_TAB, true);
869 return CopyOrLinkDragOperation(event.source_operations());
870 }
871 } else {
872 std::wstring text;
873 if (data.GetString(&text)) {
874 text = CollapseWhitespace(text, true);
875 if (model()->CanPasteAndGo(WideToUTF16(text))) {
876 model()->PasteAndGo();
877 return CopyOrLinkDragOperation(event.source_operations());
878 }
879 }
880 }
881
882 return ui::DragDropTypes::DRAG_NONE;
883 }
884
848 void AutocompleteEditViewGtk::EnableAccessibility() { 885 void AutocompleteEditViewGtk::EnableAccessibility() {
849 accessible_widget_helper_.reset( 886 accessible_widget_helper_.reset(
850 new AccessibleWidgetHelper(text_view(), model_->profile())); 887 new AccessibleWidgetHelper(text_view(), model_->profile()));
851 accessible_widget_helper_->SetWidgetName( 888 accessible_widget_helper_->SetWidgetName(
852 text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION)); 889 text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION));
853 } 890 }
854 891
855 // static 892 // static
856 AutocompleteEditView* AutocompleteEditViewGtk::Create( 893 AutocompleteEditView* AutocompleteEditViewGtk::Create(
857 AutocompleteEditController* controller, 894 AutocompleteEditController* controller,
(...skipping 1436 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 2331 // baseline, so we need to move the |instant_view_| down to make sure it
2295 // has the same baseline as the |text_view_|. 2332 // has the same baseline as the |text_view_|.
2296 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2333 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2297 int height; 2334 int height;
2298 pango_layout_get_size(layout, NULL, &height); 2335 pango_layout_get_size(layout, NULL, &height);
2299 PangoLayoutIter* iter = pango_layout_get_iter(layout); 2336 PangoLayoutIter* iter = pango_layout_get_iter(layout);
2300 int baseline = pango_layout_iter_get_baseline(iter); 2337 int baseline = pango_layout_iter_get_baseline(iter);
2301 pango_layout_iter_free(iter); 2338 pango_layout_iter_free(iter);
2302 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2339 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2303 } 2340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698