diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-20 07:42:23 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-20 07:42:23 +0000 |
commit | de32974398386af30f54ac81098b32965c8ccd7e (patch) | |
tree | 8c679fe39cdd635a45b8ae4ee0be481c679bf579 /chrome | |
parent | 36fcda6c03115d0247178adf2513babc12eaf195 (diff) | |
download | chromium_src-de32974398386af30f54ac81098b32965c8ccd7e.zip chromium_src-de32974398386af30f54ac81098b32965c8ccd7e.tar.gz chromium_src-de32974398386af30f54ac81098b32965c8ccd7e.tar.bz2 |
Mac: Fourth half of CL 481012 (reverted at r35038).
This introduces code to properly enable DnD to the Omnibox without adding a
trivial |-updateDragTypeRegistration| to |AutocompleteTextFieldEditor| (so that
it falls through to the text field), but rather letting the field editor accept
DnD directly.
We'll see whether or not it turns Mac Perf(2) red (by regressing startup times).
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/500157
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_editor.h | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_editor.mm | 48 |
2 files changed, 48 insertions, 10 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.h b/chrome/browser/cocoa/autocomplete_text_field_editor.h index e7e586f..b7f0457 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_editor.h +++ b/chrome/browser/cocoa/autocomplete_text_field_editor.h @@ -4,6 +4,9 @@ #import <Cocoa/Cocoa.h> +#include "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/url_drop_target.h" + class AutocompleteTextFieldObserver; // AutocompleteTextFieldEditor customized the AutocompletTextField @@ -14,7 +17,12 @@ class AutocompleteTextFieldObserver; // pasteboard). // Field editor used for the autocomplete field. -@interface AutocompleteTextFieldEditor : NSTextView { +@interface AutocompleteTextFieldEditor : NSTextView<URLDropTarget> { + // Handles being a drag-and-drop target. We handle DnD directly instead + // allowing the |AutocompletTextField| to handle it (by making an empty + // |-updateDragTypeRegistration|), since the latter results in a weird + // start-up time regression. + scoped_nsobject<URLDropTargetHandler> dropHandler_; } // Copy contents of the TextView to the designated clipboard as plain diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/autocomplete_text_field_editor.mm index ceaacd4..54a866e 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm @@ -10,9 +10,17 @@ #include "base/sys_string_conversions.h" #include "chrome/app/chrome_dll_resource.h" // IDC_* #import "chrome/browser/cocoa/autocomplete_text_field.h" +#import "chrome/browser/cocoa/browser_window_controller.h" +#import "chrome/browser/cocoa/toolbar_controller.h" @implementation AutocompleteTextFieldEditor +- (id)initWithFrame:(NSRect)frameRect { + if ((self = [super initWithFrame:frameRect])) + dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); + return self; +} + - (void)copy:(id)sender { NSPasteboard* pb = [NSPasteboard generalPasteboard]; [self performCopy:pb]; @@ -77,15 +85,6 @@ - (void)updateRuler { } -#if 0 -// TODO(viettrungluu): This is causing a regression somehow. So let's disable it -// and work from there. See also corresponding comment in -// autocomplete_text_field.mm. -// Let the |AutocompleteTextField| handle drops. -- (void)updateDragTypeRegistration { -} -#endif - - (NSMenu*)menuForEvent:(NSEvent*)event { NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease]; [menu addItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT) @@ -131,4 +130,35 @@ return menu; } +// (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 (even though we're presumably already the + // first responder), which will select the text to indicate that our contents + // would be replaced by a drop. + [[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 |