summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-19 17:20:30 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-19 17:20:30 +0000
commit05f53d7aa8d698bc62126d4fd79a7e398a377443 (patch)
tree95631049e23a842c157b2a04cce1b7d49f0e2b6f /chrome
parentb13c94927b0e2747ddc9289ae21207c8b296b157 (diff)
downloadchromium_src-05f53d7aa8d698bc62126d4fd79a7e398a377443.zip
chromium_src-05f53d7aa8d698bc62126d4fd79a7e398a377443.tar.gz
chromium_src-05f53d7aa8d698bc62126d4fd79a7e398a377443.tar.bz2
Second half of CL 481012 (reverted at r35038). Will revert if Mac perf turns red.
CL 481012 was: Mac: implement DnD of URLs onto Omnibox. It was reverted due to a startup (perf) regression. The first half was re-committed at r35044. I can't for the life of me reproduce the regression locally, so I'm re-committing and watching the bots. BUG=24631 TEST=Select a URL/link/file from somewhere (a link in a browser, a URL in text, a file from the desktop, etc.) and drag it to the Omnibox in a Chromium browser window; the contents of the Omnibox should be selected to indicate that a drop would replace its contents; dropping should navigate to the appropriate location. TBR=shess@chromium.org Review URL: http://codereview.chromium.org/500153 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35053 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.h8
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.mm36
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor.mm4
-rw-r--r--chrome/browser/cocoa/toolbar_controller.h5
-rw-r--r--chrome/browser/cocoa/toolbar_controller.mm35
5 files changed, 84 insertions, 4 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.h b/chrome/browser/cocoa/autocomplete_text_field.h
index 7336441..c343ff0 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.h
+++ b/chrome/browser/cocoa/autocomplete_text_field.h
@@ -6,9 +6,10 @@
#define CHROME_BROWSER_COCOA_AUTOCOMPLETE_TEXT_FIELD_H_
#import <Cocoa/Cocoa.h>
-#import "chrome/browser/cocoa/styled_text_field.h"
#include "base/scoped_nsobject.h"
+#import "chrome/browser/cocoa/styled_text_field.h"
+#import "chrome/browser/cocoa/url_drop_target.h"
@class AutocompleteTextFieldCell;
@@ -75,13 +76,16 @@ class AutocompleteTextFieldObserver {
virtual bool OnDoCommandBySelector(SEL cmd) = 0;
};
-@interface AutocompleteTextField : StyledTextField {
+@interface AutocompleteTextField : StyledTextField<URLDropTarget> {
@private
// Undo manager for this text field. We use a specific instance rather than
// the standard undo manager in order to let us clear the undo stack at will.
scoped_nsobject<NSUndoManager> undoManager_;
AutocompleteTextFieldObserver* observer_; // weak, owned by location bar.
+
+ // Handles being a drag-and-drop target.
+ scoped_nsobject<URLDropTargetHandler> dropHandler_;
}
@property AutocompleteTextFieldObserver* observer;
diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm
index a067fdc..cea5f15 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field.mm
@@ -6,6 +6,9 @@
#include "base/logging.h"
#import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
+#import "chrome/browser/cocoa/browser_window_controller.h"
+#import "chrome/browser/cocoa/toolbar_controller.h"
+#import "chrome/browser/cocoa/url_drop_target.h"
@implementation AutocompleteTextField
@@ -22,6 +25,7 @@
- (void)awakeFromNib {
DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]);
+ dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]);
}
- (void)flagsChanged:(NSEvent*)theEvent {
@@ -252,4 +256,36 @@
}
}
+// (URLDropTarget protocol)
+- (id<URLDropTargetController>)urlDropController {
+ BrowserWindowController* windowController = [[self window] windowController];
+ DCHECK([windowController isKindOfClass:[BrowserWindowController class]]);
+ return [windowController toolbarController];
+}
+
+// (URLDropTarget protocol)
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
+ // Make ourself the first responder, which will select the text to indicate
+ // that our contents would be replaced by a drop.
+ // TODO(viettrungluu): crbug.com/30809 -- this is a hack since it steals focus
+ // and doesn't return it.
+ [[self window] makeFirstResponder:self];
+ return [dropHandler_ draggingEntered:sender];
+}
+
+// (URLDropTarget protocol)
+- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
+ return [dropHandler_ draggingUpdated:sender];
+}
+
+// (URLDropTarget protocol)
+- (void)draggingExited:(id<NSDraggingInfo>)sender {
+ return [dropHandler_ draggingExited:sender];
+}
+
+// (URLDropTarget protocol)
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
+ return [dropHandler_ performDragOperation:sender];
+}
+
@end
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
index f598551..e7d0a1b 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
@@ -77,6 +77,10 @@
- (void)updateRuler {
}
+// Let the |AutocompleteTextField| handle drops.
+- (void)updateDragTypeRegistration {
+}
+
- (NSMenu*)menuForEvent:(NSEvent*)event {
NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease];
[menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT)
diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h
index 83a1b81..df922a2 100644
--- a/chrome/browser/cocoa/toolbar_controller.h
+++ b/chrome/browser/cocoa/toolbar_controller.h
@@ -11,6 +11,7 @@
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/command_observer_bridge.h"
#import "chrome/browser/cocoa/delayedmenu_button.h"
+#import "chrome/browser/cocoa/url_drop_target.h"
#import "chrome/browser/cocoa/view_resizer.h"
#include "chrome/common/pref_member.h"
@@ -41,8 +42,8 @@ class ToolbarModel;
// Manages the bookmark bar and its position in the window relative to
// the web content view.
-@interface ToolbarController :
- NSViewController<CommandObserverProtocol> {
+@interface ToolbarController : NSViewController<CommandObserverProtocol,
+ URLDropTargetController> {
@private
ToolbarModel* toolbarModel_; // weak, one per window
CommandUpdater* commands_; // weak, one per window
diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm
index cb78971..93ec18a 100644
--- a/chrome/browser/cocoa/toolbar_controller.mm
+++ b/chrome/browser/cocoa/toolbar_controller.mm
@@ -25,9 +25,11 @@
#import "chrome/browser/cocoa/menu_button.h"
#import "chrome/browser/cocoa/menu_controller.h"
#import "chrome/browser/cocoa/toolbar_view.h"
+#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/browser/page_menu_model.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/toolbar_model.h"
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_observer.h"
@@ -680,4 +682,37 @@ class PrefObserverBridge : public NotificationObserver {
stack_bounds.Inset(kLocationStackEdgeWidth, 0);
return stack_bounds;
}
+
+// (URLDropTargetController protocol)
+- (void)dropURLs:(NSArray*)urls 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 ([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()));
+
+ browser_->GetSelectedTabContents()->OpenURL(url, GURL(), CURRENT_TAB,
+ PageTransition::TYPED);
+}
+
+// (URLDropTargetController protocol)
+- (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point {
+ // Do nothing.
+}
+
+// (URLDropTargetController protocol)
+- (void)hideDropURLsIndicatorInView:(NSView*)view {
+ // Do nothing.
+}
+
@end