diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-19 03:30:19 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-19 03:30:19 +0000 |
commit | 0ec9512a65f8d7f15dbddd902363994660d85ffb (patch) | |
tree | a075476ee0051162b69ab79308080a1c8ca8c985 | |
parent | 732169bb11fbca6eb6048e37f1d897880771115b (diff) | |
download | chromium_src-0ec9512a65f8d7f15dbddd902363994660d85ffb.zip chromium_src-0ec9512a65f8d7f15dbddd902363994660d85ffb.tar.gz chromium_src-0ec9512a65f8d7f15dbddd902363994660d85ffb.tar.bz2 |
Revert 34998, more stabbing in the dark to find a perf regression - Mac: implement DnD of URLs onto Omnibox.
(DnD of text coming in another patch.)
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.
Review URL: http://codereview.chromium.org/481012
TBR=viettrungluu@chromium.org
Review URL: http://codereview.chromium.org/501135
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35038 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field.mm | 36 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_editor.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 18 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 25 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.h | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 44 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_view.mm | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/toolbar_controller.mm | 35 | ||||
-rw-r--r-- | chrome/browser/cocoa/url_drop_target.h | 51 | ||||
-rw-r--r-- | chrome/browser/cocoa/url_drop_target.mm | 20 |
13 files changed, 95 insertions, 179 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.h b/chrome/browser/cocoa/autocomplete_text_field.h index c343ff0..7336441 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.h +++ b/chrome/browser/cocoa/autocomplete_text_field.h @@ -6,10 +6,9 @@ #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; @@ -76,16 +75,13 @@ class AutocompleteTextFieldObserver { virtual bool OnDoCommandBySelector(SEL cmd) = 0; }; -@interface AutocompleteTextField : StyledTextField<URLDropTarget> { +@interface AutocompleteTextField : StyledTextField { @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 cea5f15..a067fdc 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.mm +++ b/chrome/browser/cocoa/autocomplete_text_field.mm @@ -6,9 +6,6 @@ #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 @@ -25,7 +22,6 @@ - (void)awakeFromNib { DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); - dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); } - (void)flagsChanged:(NSEvent*)theEvent { @@ -256,36 +252,4 @@ } } -// (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 e7d0a1b..f598551 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm @@ -77,10 +77,6 @@ - (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/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 5e2014f..a273e8f 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -47,7 +47,8 @@ class TabStripModelObserverBridge; BookmarkBarControllerDelegate, BrowserCommandExecutor, ViewResizer, - GTMThemeDelegate> { + GTMThemeDelegate, + URLDropTargetWindowController> { @private // The ordering of these members is important as it determines the order in // which they are destroyed. |browser_| needs to be destroyed last as most of @@ -163,12 +164,6 @@ class TabStripModelObserverBridge; // tab/tab contents). - (void)updateBookmarkBarVisibilityWithAnimation:(BOOL)animate; -// Return a weak pointer to the tab strip controller. -- (TabStripController*)tabStripController; - -// Return a weak pointer to the toolbar controller. -- (ToolbarController*)toolbarController; - - (BOOL)isDownloadShelfVisible; // Lazily creates the download shelf in visible state if it doesn't exist yet. @@ -215,6 +210,12 @@ class TabStripModelObserverBridge; // tab's sheet queue. - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window; +// Implementation of the |URLDropTargetWindowController| protocol, which is +// needed for URL dropping on the tab strip. +- (void)dropURLs:(NSArray*)urls at:(NSPoint)location; +- (void)indicateDropURLsAt:(NSPoint)location; +- (void)hideDropURLsIndicator; + @end // Methods which are either only for testing, or only public for testing. @@ -243,6 +244,9 @@ class TabStripModelObserverBridge; // Return a point suitable for the topLeft for a bookmark bubble. - (NSPoint)topLeftForBubble; +// Return a weak pointer to the toolbar controller. +- (ToolbarController*)toolbarController; + // Resets any saved state about window growth (due to showing the bookmark bar // or the download shelf), so that future shrinking will occur from the bottom. - (void)resetWindowGrowthState; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 658b100..0d13ce1 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -43,6 +43,7 @@ #import "chrome/browser/cocoa/tab_strip_controller.h" #import "chrome/browser/cocoa/tab_view.h" #import "chrome/browser/cocoa/toolbar_controller.h" +#include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/sync_ui_util_mac.h" #include "chrome/common/pref_names.h" @@ -835,6 +836,10 @@ willPositionSheet:(NSWindow*)sheet return enable; } +- (ToolbarController*)toolbarController { + return toolbarController_.get(); +} + // Called when the user picks a menu or toolbar item when this window is key. // Calls through to the browser object to execute the command. This assumes that // the command is supported and doesn't check, otherwise it would have been @@ -1006,11 +1011,7 @@ willPositionSheet:(NSWindow*)sheet } - (TabStripController*)tabStripController { - return tabStripController_.get(); -} - -- (ToolbarController*)toolbarController { - return toolbarController_.get(); + return tabStripController_; } - (void)setIsLoading:(BOOL)isLoading { @@ -1544,6 +1545,20 @@ willAnimateFromState:(bookmarks::VisualState)oldState isShrinkingFromZoomed_ = NO; } +// Our implementation of the |URLDropTargetWindowController| protocol just +// reflects everything to the |tabStripController_|. +- (void)dropURLs:(NSArray*)urls at:(NSPoint)location { + [tabStripController_ dropURLs:urls at:location]; +} + +- (void)indicateDropURLsAt:(NSPoint)location { + [tabStripController_ indicateDropURLsAt:location]; +} + +- (void)hideDropURLsIndicator { + [tabStripController_ hideDropURLsIndicator]; +} + @end @implementation BrowserWindowController (Private) diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h index 838c00a..2321b7d 100644 --- a/chrome/browser/cocoa/tab_strip_controller.h +++ b/chrome/browser/cocoa/tab_strip_controller.h @@ -13,7 +13,6 @@ #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" #import "chrome/browser/cocoa/tab_controller_target.h" -#import "chrome/browser/cocoa/url_drop_target.h" #import "third_party/GTM/AppKit/GTMWindowSheetController.h" @class TabView; @@ -39,7 +38,6 @@ class ToolbarModel; @interface TabStripController : NSObject<TabControllerTarget, - URLDropTargetController, GTMWindowSheetControllerDelegate> { @private TabContents* currentTab_; // weak, tab for which we're showing state @@ -179,6 +177,13 @@ class ToolbarModel; // Default height for tabs. + (CGFloat)defaultTabHeight; +// Effectively an implementation of the |URLDropTargetWindowController| +// protocol, which the |BrowserWindowController| just reflects to us. This +// needed for dropping URLs on the tab strip. +- (void)dropURLs:(NSArray*)urls at:(NSPoint)location; +- (void)indicateDropURLsAt:(NSPoint)location; +- (void)hideDropURLsIndicator; + // Returns the (lazily created) window sheet controller of this window. Used // for the per-tab sheets. - (GTMWindowSheetController*)sheetController; diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 375532d..a468b31 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -120,7 +120,7 @@ private: - (NSInteger)numberOfOpenUnpinnedTabs; - (void)mouseMoved:(NSEvent*)event; - (void)setTabTrackingAreasEnabled:(BOOL)enabled; -- (void)droppingURLsAt:(NSPoint)point +- (void)droppingURLsAt:(NSPoint)location givesIndex:(NSInteger*)index disposition:(WindowOpenDisposition*)disposition; @end @@ -1436,11 +1436,11 @@ private: [self setTabTrackingAreasEnabled:mouseInside_]; } -// Get the index and disposition for a potential URL(s) drop given a point (in -// the |TabStripView|'s coordinates). It considers only the x-coordinate of the -// given point. If it's in the "middle" of a tab, it drops on that tab. If it's -// to the left, it inserts to the left, and similarly for the right. -- (void)droppingURLsAt:(NSPoint)point +// Get the index and disposition for a potential URL(s) drop given a location +// (in window base coordinates). It considers x coordinate of the given +// location. If it's in the "middle" of a tab, it drops on that tab. If it's to +// the left, it inserts to the left, and similarly for the right. +- (void)droppingURLsAt:(NSPoint)location givesIndex:(NSInteger*)index disposition:(WindowOpenDisposition*)disposition { // Proportion of the tab which is considered the "middle" (and causes things @@ -1455,9 +1455,8 @@ private: DCHECK([view isKindOfClass:[TabView class]]); // Recall that |-[NSView frame]| is in its superview's coordinates, so a - // |TabView|'s frame is in the coordinates of the |TabStripView| (which - // matches the coordinate system of |point|). - NSRect frame = [view frame]; + // |TabView|'s frame is in the coordinates of the |TabStripView|. + NSRect frame = [tabStripView_ convertRectToBase:[view frame]]; // Modify the frame to make it "unoverlapped". frame.origin.x += kTabOverlap / 2.0; @@ -1466,14 +1465,14 @@ private: frame.size.width = 1.0; // try to avoid complete failure // Drop in a new tab to the left of tab |i|? - if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) { + if (location.x < (frame.origin.x + kLRProportion * frame.size.width)) { *index = i; *disposition = NEW_FOREGROUND_TAB; return; } // Drop on tab |i|? - if (point.x <= (frame.origin.x + + if (location.x <= (frame.origin.x + (1.0 - kLRProportion) * frame.size.width)) { *index = i; *disposition = CURRENT_TAB; @@ -1490,10 +1489,8 @@ private: *disposition = NEW_FOREGROUND_TAB; } -// (URLDropTargetController protocol) -- (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { - DCHECK_EQ(view, tabStripView_.get()); - +// Drop URLs at the given location. +- (void)dropURLs:(NSArray*)urls at:(NSPoint)location { if ([urls count] < 1) { NOTREACHED(); return; @@ -1510,7 +1507,7 @@ private: // Get the index and disposition. NSInteger index; WindowOpenDisposition disposition; - [self droppingURLsAt:point + [self droppingURLsAt:location givesIndex:&index disposition:&disposition]; @@ -1532,16 +1529,15 @@ private: } } -// (URLDropTargetController protocol) -- (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { - DCHECK_EQ(view, tabStripView_.get()); - +// Update (possibly showing) the indicator which indicates where an URL drop +// would happen. +- (void)indicateDropURLsAt:(NSPoint)location { // The minimum y-coordinate at which one should consider place the arrow. const CGFloat arrowBaseY = 25; NSInteger index; WindowOpenDisposition disposition; - [self droppingURLsAt:point + [self droppingURLsAt:location givesIndex:&index disposition:&disposition]; @@ -1573,10 +1569,8 @@ private: [tabStripView_ setNeedsDisplay:YES]; } -// (URLDropTargetController protocol) -- (void)hideDropURLsIndicatorInView:(NSView*)view { - DCHECK_EQ(view, tabStripView_.get()); - +// Hide the indicator which indicates where an URL drop would happen. +- (void)hideDropURLsIndicator { if ([tabStripView_ dropArrowShown]) { [tabStripView_ setDropArrowShown:NO]; [tabStripView_ setNeedsDisplay:YES]; diff --git a/chrome/browser/cocoa/tab_strip_view.h b/chrome/browser/cocoa/tab_strip_view.h index 6816348..454f2a3 100644 --- a/chrome/browser/cocoa/tab_strip_view.h +++ b/chrome/browser/cocoa/tab_strip_view.h @@ -12,7 +12,7 @@ // A view class that handles rendering the tab strip -@interface TabStripView : NSView<URLDropTarget> { +@interface TabStripView : NSView { @private NSTimeInterval lastMouseUp_; diff --git a/chrome/browser/cocoa/tab_strip_view.mm b/chrome/browser/cocoa/tab_strip_view.mm index a5435e9..3eeef0a 100644 --- a/chrome/browser/cocoa/tab_strip_view.mm +++ b/chrome/browser/cocoa/tab_strip_view.mm @@ -4,8 +4,6 @@ #import "chrome/browser/cocoa/tab_strip_view.h" -#import "chrome/browser/cocoa/browser_window_controller.h" -#import "chrome/browser/cocoa/tab_strip_controller.h" #include "base/logging.h" @implementation TabStripView @@ -138,29 +136,22 @@ lastMouseUp_ = (clickCount == 1) ? timestamp : -1000.0; } -// (URLDropTarget protocol) -- (id<URLDropTargetController>)urlDropController { - BrowserWindowController* windowController = [[self window] windowController]; - DCHECK([windowController isKindOfClass:[BrowserWindowController class]]); - return [windowController tabStripController]; -} - -// (URLDropTarget protocol) +// Required by |URLDropTargetHandler|. - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { return [dropHandler_ draggingEntered:sender]; } -// (URLDropTarget protocol) +// Required by |URLDropTargetHandler|. - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { return [dropHandler_ draggingUpdated:sender]; } -// (URLDropTarget protocol) +// Required by |URLDropTargetHandler|. - (void)draggingExited:(id<NSDraggingInfo>)sender { return [dropHandler_ draggingExited:sender]; } -// (URLDropTarget protocol) +// Required by |URLDropTargetHandler|. - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { return [dropHandler_ performDragOperation:sender]; } diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index df922a2..83a1b81 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -11,7 +11,6 @@ #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" @@ -42,8 +41,8 @@ class ToolbarModel; // Manages the bookmark bar and its position in the window relative to // the web content view. -@interface ToolbarController : NSViewController<CommandObserverProtocol, - URLDropTargetController> { +@interface ToolbarController : + NSViewController<CommandObserverProtocol> { @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 93ec18a..cb78971 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -25,11 +25,9 @@ #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" @@ -682,37 +680,4 @@ 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 diff --git a/chrome/browser/cocoa/url_drop_target.h b/chrome/browser/cocoa/url_drop_target.h index 6b94113..2745cef 100644 --- a/chrome/browser/cocoa/url_drop_target.h +++ b/chrome/browser/cocoa/url_drop_target.h @@ -7,19 +7,15 @@ #import <Cocoa/Cocoa.h> -@protocol URLDropTarget; -@protocol URLDropTargetController; - -// Object which coordinates the dropping of URLs on a given view, sending data -// and updates to a controller. @interface URLDropTargetHandler : NSObject { @private - NSView<URLDropTarget>* view_; // weak + NSView* view_; // weak } -// Initialize the given view, which must implement the |URLDropTarget| (below), -// to accept drops of URLs. -- (id)initWithView:(NSView<URLDropTarget>*)view; +// Initialize the given view to accept drops of URLs; this requires the view's +// window's controller to implement the |URLDropTargetWindowController| protocol +// (below). +- (id)initWithView:(NSView*)view; // The owner view should implement the following methods by calling the // |URLDropTargetHandler|'s version, and leave the others to the default @@ -31,37 +27,20 @@ @end // @interface URLDropTargetHandler -// Protocol which views that are URL drop targets and use |URLDropTargetHandler| -// must implement. -@protocol URLDropTarget - -// Returns the controller which handles the drop. -- (id<URLDropTargetController>)urlDropController; - -// The following, which come from |NSDraggingDestination|, must be implemented -// by calling the |URLDropTargetHandler|'s implementations. -- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender; -- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender; -- (void)draggingExited:(id<NSDraggingInfo>)sender; -- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender; - -@end // @protocol URLDropTarget - -// Protocol for the controller which handles the actual drop data/drop updates. -@protocol URLDropTargetController +@protocol URLDropTargetWindowController -// The given URLs (an |NSArray| of |NSString|s) were dropped in the given view -// at the given point (in that view's coordinates). -- (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point; +// The given URLs (an |NSArray| of |NSString|s) were dropped at the given +// location (location in window base coordinates). +- (void)dropURLs:(NSArray*)urls at:(NSPoint)location; -// 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. -- (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point; +// Dragging is in progress over the owner view (at the given location, in window +// base coordinates) and any indicator of location -- e.g., an arrow -- should +// be updated/shown. +- (void)indicateDropURLsAt:(NSPoint)location; // Dragging is over, and any indicator should be hidden. -- (void)hideDropURLsIndicatorInView:(NSView*)view; +- (void)hideDropURLsIndicator; -@end // @protocol URLDropTargetController +@end // @protocol URLDropTargetWindowController #endif // CHROME_BROWSER_COCOA_URL_DROP_TARGET_H_ diff --git a/chrome/browser/cocoa/url_drop_target.mm b/chrome/browser/cocoa/url_drop_target.mm index d21cd67..6a2031d 100644 --- a/chrome/browser/cocoa/url_drop_target.mm +++ b/chrome/browser/cocoa/url_drop_target.mm @@ -9,6 +9,9 @@ @interface URLDropTargetHandler(Private) +// Get the window controller. +- (id<URLDropTargetWindowController>)windowController; + // Gets the appropriate drag operation given the |NSDraggingInfo|. - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender; @@ -44,8 +47,7 @@ NSDragOperation dragOp = [self getDragOperation:sender]; if (dragOp == NSDragOperationCopy) { // Just tell the window controller to update the indicator. - NSPoint hoverPoint = [view_ convertPointFromBase:[sender draggingLocation]]; - [[view_ urlDropController] indicateDropURLsInView:view_ at:hoverPoint]; + [[self windowController] indicateDropURLsAt:[sender draggingLocation]]; } return dragOp; } @@ -65,9 +67,7 @@ if ([urls count]) { // Tell the window controller about the dropped URL(s). - NSPoint dropPoint = - [view_ convertPointFromBase:[sender draggingLocation]]; - [[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint]; + [[self windowController] dropURLs:urls at:[sender draggingLocation]]; return YES; } } @@ -79,13 +79,21 @@ @implementation URLDropTargetHandler(Private) +- (id<URLDropTargetWindowController>)windowController { + id<URLDropTargetWindowController> controller = + [[view_ window] windowController]; + DCHECK([(id)controller conformsToProtocol: + @protocol(URLDropTargetWindowController)]); + return controller; +} + - (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender { // Only allow the copy operation. return [sender draggingSourceOperationMask] & NSDragOperationCopy; } - (void)hideIndicator { - [[view_ urlDropController] hideDropURLsIndicatorInView:view_]; + [[self windowController] hideDropURLsIndicator]; } @end // @implementation URLDropTargetHandler(Private) |