summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/gtk/tabs/tab_strip_gtk.cc24
-rw-r--r--chrome/browser/gtk/tabs/tab_strip_gtk.h2
-rw-r--r--chrome/browser/ui/cocoa/tab_strip_controller.mm59
-rw-r--r--chrome/browser/ui/cocoa/toolbar_controller.mm20
-rw-r--r--chrome/browser/ui/cocoa/url_drop_target.h4
-rw-r--r--chrome/browser/ui/cocoa/url_drop_target.mm19
6 files changed, 99 insertions, 29 deletions
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc
index 594f6f9..597c9d7 100644
--- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc
@@ -12,7 +12,10 @@
#include "app/slide_animation.h"
#include "base/i18n/rtl.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
@@ -737,6 +740,7 @@ void TabStripGtk::Init() {
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
static const int targets[] = { gtk_dnd_util::TEXT_URI_LIST,
gtk_dnd_util::NETSCAPE_URL,
+ gtk_dnd_util::TEXT_PLAIN,
-1 };
gtk_dnd_util::SetDestTargetList(tabstrip_.get(), targets);
@@ -1603,7 +1607,7 @@ void TabStripGtk::SetDropIndex(int index, bool drop_before) {
drop_bounds.width(), drop_bounds.height());
}
-bool TabStripGtk::CompleteDrop(guchar* data) {
+bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) {
if (!drop_info_.get())
return false;
@@ -1613,8 +1617,17 @@ bool TabStripGtk::CompleteDrop(guchar* data) {
// Destroy the drop indicator.
drop_info_.reset();
- std::string url_string(reinterpret_cast<char*>(data));
- GURL url(url_string.substr(0, url_string.find_first_of('\n')));
+ GURL url;
+ if (is_plain_text) {
+ AutocompleteMatch match;
+ model_->profile()->GetAutocompleteClassifier()->Classify(
+ UTF8ToWide(reinterpret_cast<char*>(data)), std::wstring(), false,
+ &match, NULL);
+ url = match.destination_url;
+ } else {
+ std::string url_string(reinterpret_cast<char*>(data));
+ url = GURL(url_string.substr(0, url_string.find_first_of('\n')));
+ }
if (!url.is_valid())
return false;
@@ -1954,8 +1967,9 @@ gboolean TabStripGtk::OnDragDataReceived(GtkWidget* widget,
bool success = false;
if (info == gtk_dnd_util::TEXT_URI_LIST ||
- info == gtk_dnd_util::NETSCAPE_URL) {
- success = CompleteDrop(data->data);
+ info == gtk_dnd_util::NETSCAPE_URL ||
+ info == gtk_dnd_util::TEXT_PLAIN) {
+ success = CompleteDrop(data->data, info == gtk_dnd_util::TEXT_PLAIN);
}
gtk_drag_finish(context, success, success, time);
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h
index 0095ebe5b..d7a2a4c 100644
--- a/chrome/browser/gtk/tabs/tab_strip_gtk.h
+++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h
@@ -363,7 +363,7 @@ class TabStripGtk : public TabStripModelObserver,
// Determines whether the data is acceptable by the tabstrip and opens a new
// tab with the data as URL if it is. Returns true if the drop was
// successful.
- bool CompleteDrop(guchar* data);
+ bool CompleteDrop(guchar* data, bool is_plain_text);
// Returns the image to use for indicating a drop on a tab. If is_down is
// true, this returns an arrow pointing down.
diff --git a/chrome/browser/ui/cocoa/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tab_strip_controller.mm
index 7d4a5d9..a1fc5af 100644
--- a/chrome/browser/ui/cocoa/tab_strip_controller.mm
+++ b/chrome/browser/ui/cocoa/tab_strip_controller.mm
@@ -15,6 +15,9 @@
#include "base/nsimage_cache_mac.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/debugger/devtools_window.h"
@@ -1686,23 +1689,7 @@ private:
*disposition = NEW_FOREGROUND_TAB;
}
-// (URLDropTargetController protocol)
-- (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point {
- DCHECK_EQ(view, tabStripView_.get());
-
- if ([urls count] < 1) {
- NOTREACHED();
- return;
- }
-
- //TODO(viettrungluu): dropping multiple URLs.
- if ([urls count] > 1)
- NOTIMPLEMENTED();
-
- // Get the first URL and fix it up.
- GURL url(URLFixerUpper::FixupURL(
- base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string()));
-
+- (void)openURL:(GURL*)url inView:(NSView*)view at:(NSPoint)point {
// Get the index and disposition.
NSInteger index;
WindowOpenDisposition disposition;
@@ -1715,7 +1702,7 @@ private:
case NEW_FOREGROUND_TAB: {
UserMetrics::RecordAction(UserMetricsAction("Tab_DropURLBetweenTabs"),
browser_->profile());
- browser::NavigateParams params(browser_, url, PageTransition::TYPED);
+ browser::NavigateParams params(browser_, *url, PageTransition::TYPED);
params.disposition = disposition;
params.tabstrip_index = index;
params.tabstrip_add_types =
@@ -1727,7 +1714,7 @@ private:
UserMetrics::RecordAction(UserMetricsAction("Tab_DropURLOnTab"),
browser_->profile());
tabStripModel_->GetTabContentsAt(index)
- ->tab_contents()->OpenURL(url, GURL(), CURRENT_TAB,
+ ->tab_contents()->OpenURL(*url, GURL(), CURRENT_TAB,
PageTransition::TYPED);
tabStripModel_->SelectTabContentsAt(index, true);
break;
@@ -1737,6 +1724,40 @@ private:
}
// (URLDropTargetController protocol)
+- (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point {
+ DCHECK_EQ(view, tabStripView_.get());
+
+ if ([urls count] < 1) {
+ NOTREACHED();
+ return;
+ }
+
+ //TODO(viettrungluu): dropping multiple URLs.
+ if ([urls count] > 1)
+ NOTIMPLEMENTED();
+
+ // Get the first URL and fix it up.
+ GURL url(GURL(URLFixerUpper::FixupURL(
+ base::SysNSStringToUTF8([urls objectAtIndex:0]), std::string())));
+
+ [self openURL:&url inView:view at:point];
+}
+
+// (URLDropTargetController protocol)
+- (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point {
+ DCHECK_EQ(view, tabStripView_.get());
+
+ // If the input is plain text, classify the input and make the URL.
+ AutocompleteMatch match;
+ browser_->profile()->GetAutocompleteClassifier()->Classify(
+ base::SysNSStringToWide(text),
+ std::wstring(), false, &match, NULL);
+ GURL url(match.destination_url);
+
+ [self openURL:&url inView:view at:point];
+}
+
+// (URLDropTargetController protocol)
- (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point {
DCHECK_EQ(view, tabStripView_.get());
diff --git a/chrome/browser/ui/cocoa/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar_controller.mm
index bb6f433..586bf784 100644
--- a/chrome/browser/ui/cocoa/toolbar_controller.mm
+++ b/chrome/browser/ui/cocoa/toolbar_controller.mm
@@ -15,7 +15,10 @@
#include "base/singleton.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -741,6 +744,23 @@ class NotificationBridge : public NotificationObserver {
}
// (URLDropTargetController protocol)
+- (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point {
+ // TODO(viettrungluu): This code is more or less copied from the code in
+ // |TabStripController|. I'll refactor this soon to make it common and expand
+ // its capabilities (e.g., allow text DnD).
+
+ // If the input is plain text, classify the input and make the URL.
+ AutocompleteMatch match;
+ browser_->profile()->GetAutocompleteClassifier()->Classify(
+ base::SysNSStringToWide(text),
+ std::wstring(), false, &match, NULL);
+ GURL url(match.destination_url);
+
+ browser_->GetSelectedTabContents()->OpenURL(url, GURL(), CURRENT_TAB,
+ PageTransition::TYPED);
+}
+
+// (URLDropTargetController protocol)
- (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point {
// Do nothing.
}
diff --git a/chrome/browser/ui/cocoa/url_drop_target.h b/chrome/browser/ui/cocoa/url_drop_target.h
index abfefb3..ea57026 100644
--- a/chrome/browser/ui/cocoa/url_drop_target.h
+++ b/chrome/browser/ui/cocoa/url_drop_target.h
@@ -58,6 +58,10 @@
// at the given point (in that view's coordinates).
- (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point;
+// The given text was dropped in the given view at the given point (in that
+// view's coordinates).
+- (void)dropText:(NSString*)text inView:(NSView*)view at:(NSPoint)point;
+
// Dragging is in progress over the owner view (at the given point, in view
// coordinates) and any indicator of location -- e.g., an arrow -- should be
// updated/shown.
diff --git a/chrome/browser/ui/cocoa/url_drop_target.mm b/chrome/browser/ui/cocoa/url_drop_target.mm
index d854775..ceca7d2 100644
--- a/chrome/browser/ui/cocoa/url_drop_target.mm
+++ b/chrome/browser/ui/cocoa/url_drop_target.mm
@@ -62,18 +62,26 @@
[self hideIndicator];
NSPasteboard* pboard = [sender draggingPasteboard];
+ NSArray* supportedTypes = [NSArray arrayWithObjects:NSStringPboardType, nil];
+ NSString* bestType = [pboard availableTypeFromArray:supportedTypes];
+
+ NSPoint dropPoint =
+ [view_ convertPoint:[sender draggingLocation] fromView:nil];
+ // Tell the window controller about the dropped URL(s).
if ([pboard containsURLData]) {
NSArray* urls = nil;
NSArray* titles; // discarded
[pboard getURLs:&urls andTitles:&titles convertingFilenames:YES];
if ([urls count]) {
- // Tell the window controller about the dropped URL(s).
- NSPoint dropPoint =
- [view_ convertPoint:[sender draggingLocation] fromView:nil];
[[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint];
return YES;
}
+ } else if (NSString* text = [pboard stringForType:bestType]) {
+ // This does not include any URLs, so treat it as plain text if we can
+ // get NSString.
+ [[view_ urlDropController] dropText:text inView:view_ at:dropPoint];
+ return YES;
}
return NO;
@@ -84,7 +92,10 @@
@implementation URLDropTargetHandler(Private)
- (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender {
- if (![[sender draggingPasteboard] containsURLData])
+ NSPasteboard* pboard = [sender draggingPasteboard];
+ NSArray *supportedTypes = [NSArray arrayWithObjects:NSStringPboardType, nil];
+ NSString *bestType = [pboard availableTypeFromArray:supportedTypes];
+ if (![pboard containsURLData] && ![pboard stringForType:bestType])
return NSDragOperationNone;
// Only allow the copy operation.