summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-19 06:11:06 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-19 06:11:06 +0000
commit6ce66267c8511a13c7f7d7a12bae558859d71d93 (patch)
treee42000bf1731158a545229377c8d0c994e9a6181
parent3740cb9b54f6a5d28c3501b650b7c179101568eb (diff)
downloadchromium_src-6ce66267c8511a13c7f7d7a12bae558859d71d93.zip
chromium_src-6ce66267c8511a13c7f7d7a12bae558859d71d93.tar.gz
chromium_src-6ce66267c8511a13c7f7d7a12bae558859d71d93.tar.bz2
Half of CL 481012 (reverted at r35038).
CL 481012 was: Mac: implement DnD of URLs onto Omnibox. This is the half consisting of mild refactoring and no new functionality. BUG=none TEST=Dragging and dropping URLs onto the tab strip should still work as before. More important is whether this regresses the startup tests. TBR=shess@chromium.org Review URL: http://codereview.chromium.org/505057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35044 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/cocoa/browser_window_controller.h18
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm25
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.h9
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm44
-rw-r--r--chrome/browser/cocoa/tab_strip_view.h2
-rw-r--r--chrome/browser/cocoa/tab_strip_view.mm17
-rw-r--r--chrome/browser/cocoa/url_drop_target.h51
-rw-r--r--chrome/browser/cocoa/url_drop_target.mm20
8 files changed, 95 insertions, 91 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h
index a273e8f..5e2014f 100644
--- a/chrome/browser/cocoa/browser_window_controller.h
+++ b/chrome/browser/cocoa/browser_window_controller.h
@@ -47,8 +47,7 @@ class TabStripModelObserverBridge;
BookmarkBarControllerDelegate,
BrowserCommandExecutor,
ViewResizer,
- GTMThemeDelegate,
- URLDropTargetWindowController> {
+ GTMThemeDelegate> {
@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
@@ -164,6 +163,12 @@ 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.
@@ -210,12 +215,6 @@ 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.
@@ -244,9 +243,6 @@ 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 0d13ce1..658b100 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -43,7 +43,6 @@
#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"
@@ -836,10 +835,6 @@ 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
@@ -1011,7 +1006,11 @@ willPositionSheet:(NSWindow*)sheet
}
- (TabStripController*)tabStripController {
- return tabStripController_;
+ return tabStripController_.get();
+}
+
+- (ToolbarController*)toolbarController {
+ return toolbarController_.get();
}
- (void)setIsLoading:(BOOL)isLoading {
@@ -1545,20 +1544,6 @@ 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 2321b7d..838c00a 100644
--- a/chrome/browser/cocoa/tab_strip_controller.h
+++ b/chrome/browser/cocoa/tab_strip_controller.h
@@ -13,6 +13,7 @@
#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;
@@ -38,6 +39,7 @@ class ToolbarModel;
@interface TabStripController :
NSObject<TabControllerTarget,
+ URLDropTargetController,
GTMWindowSheetControllerDelegate> {
@private
TabContents* currentTab_; // weak, tab for which we're showing state
@@ -177,13 +179,6 @@ 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 a468b31..375532d 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)location
+- (void)droppingURLsAt:(NSPoint)point
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 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
+// 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
givesIndex:(NSInteger*)index
disposition:(WindowOpenDisposition*)disposition {
// Proportion of the tab which is considered the "middle" (and causes things
@@ -1455,8 +1455,9 @@ 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|.
- NSRect frame = [tabStripView_ convertRectToBase:[view frame]];
+ // |TabView|'s frame is in the coordinates of the |TabStripView| (which
+ // matches the coordinate system of |point|).
+ NSRect frame = [view frame];
// Modify the frame to make it "unoverlapped".
frame.origin.x += kTabOverlap / 2.0;
@@ -1465,14 +1466,14 @@ private:
frame.size.width = 1.0; // try to avoid complete failure
// Drop in a new tab to the left of tab |i|?
- if (location.x < (frame.origin.x + kLRProportion * frame.size.width)) {
+ if (point.x < (frame.origin.x + kLRProportion * frame.size.width)) {
*index = i;
*disposition = NEW_FOREGROUND_TAB;
return;
}
// Drop on tab |i|?
- if (location.x <= (frame.origin.x +
+ if (point.x <= (frame.origin.x +
(1.0 - kLRProportion) * frame.size.width)) {
*index = i;
*disposition = CURRENT_TAB;
@@ -1489,8 +1490,10 @@ private:
*disposition = NEW_FOREGROUND_TAB;
}
-// Drop URLs at the given location.
-- (void)dropURLs:(NSArray*)urls at:(NSPoint)location {
+// (URLDropTargetController protocol)
+- (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point {
+ DCHECK_EQ(view, tabStripView_.get());
+
if ([urls count] < 1) {
NOTREACHED();
return;
@@ -1507,7 +1510,7 @@ private:
// Get the index and disposition.
NSInteger index;
WindowOpenDisposition disposition;
- [self droppingURLsAt:location
+ [self droppingURLsAt:point
givesIndex:&index
disposition:&disposition];
@@ -1529,15 +1532,16 @@ private:
}
}
-// Update (possibly showing) the indicator which indicates where an URL drop
-// would happen.
-- (void)indicateDropURLsAt:(NSPoint)location {
+// (URLDropTargetController protocol)
+- (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point {
+ DCHECK_EQ(view, tabStripView_.get());
+
// The minimum y-coordinate at which one should consider place the arrow.
const CGFloat arrowBaseY = 25;
NSInteger index;
WindowOpenDisposition disposition;
- [self droppingURLsAt:location
+ [self droppingURLsAt:point
givesIndex:&index
disposition:&disposition];
@@ -1569,8 +1573,10 @@ private:
[tabStripView_ setNeedsDisplay:YES];
}
-// Hide the indicator which indicates where an URL drop would happen.
-- (void)hideDropURLsIndicator {
+// (URLDropTargetController protocol)
+- (void)hideDropURLsIndicatorInView:(NSView*)view {
+ DCHECK_EQ(view, tabStripView_.get());
+
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 454f2a3..6816348 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 {
+@interface TabStripView : NSView<URLDropTarget> {
@private
NSTimeInterval lastMouseUp_;
diff --git a/chrome/browser/cocoa/tab_strip_view.mm b/chrome/browser/cocoa/tab_strip_view.mm
index 3eeef0a..a5435e9 100644
--- a/chrome/browser/cocoa/tab_strip_view.mm
+++ b/chrome/browser/cocoa/tab_strip_view.mm
@@ -4,6 +4,8 @@
#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
@@ -136,22 +138,29 @@
lastMouseUp_ = (clickCount == 1) ? timestamp : -1000.0;
}
-// Required by |URLDropTargetHandler|.
+// (URLDropTarget protocol)
+- (id<URLDropTargetController>)urlDropController {
+ BrowserWindowController* windowController = [[self window] windowController];
+ DCHECK([windowController isKindOfClass:[BrowserWindowController class]]);
+ return [windowController tabStripController];
+}
+
+// (URLDropTarget protocol)
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
return [dropHandler_ draggingEntered:sender];
}
-// Required by |URLDropTargetHandler|.
+// (URLDropTarget protocol)
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
return [dropHandler_ draggingUpdated:sender];
}
-// Required by |URLDropTargetHandler|.
+// (URLDropTarget protocol)
- (void)draggingExited:(id<NSDraggingInfo>)sender {
return [dropHandler_ draggingExited:sender];
}
-// Required by |URLDropTargetHandler|.
+// (URLDropTarget protocol)
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
return [dropHandler_ performDragOperation:sender];
}
diff --git a/chrome/browser/cocoa/url_drop_target.h b/chrome/browser/cocoa/url_drop_target.h
index 2745cef..6b94113 100644
--- a/chrome/browser/cocoa/url_drop_target.h
+++ b/chrome/browser/cocoa/url_drop_target.h
@@ -7,15 +7,19 @@
#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* view_; // weak
+ NSView<URLDropTarget>* view_; // weak
}
-// 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;
+// Initialize the given view, which must implement the |URLDropTarget| (below),
+// to accept drops of URLs.
+- (id)initWithView:(NSView<URLDropTarget>*)view;
// The owner view should implement the following methods by calling the
// |URLDropTargetHandler|'s version, and leave the others to the default
@@ -27,20 +31,37 @@
@end // @interface URLDropTargetHandler
-@protocol URLDropTargetWindowController
+// 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
-// 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;
+// 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;
-// 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 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 over, and any indicator should be hidden.
-- (void)hideDropURLsIndicator;
+- (void)hideDropURLsIndicatorInView:(NSView*)view;
-@end // @protocol URLDropTargetWindowController
+@end // @protocol URLDropTargetController
#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 6a2031d..d21cd67 100644
--- a/chrome/browser/cocoa/url_drop_target.mm
+++ b/chrome/browser/cocoa/url_drop_target.mm
@@ -9,9 +9,6 @@
@interface URLDropTargetHandler(Private)
-// Get the window controller.
-- (id<URLDropTargetWindowController>)windowController;
-
// Gets the appropriate drag operation given the |NSDraggingInfo|.
- (NSDragOperation)getDragOperation:(id<NSDraggingInfo>)sender;
@@ -47,7 +44,8 @@
NSDragOperation dragOp = [self getDragOperation:sender];
if (dragOp == NSDragOperationCopy) {
// Just tell the window controller to update the indicator.
- [[self windowController] indicateDropURLsAt:[sender draggingLocation]];
+ NSPoint hoverPoint = [view_ convertPointFromBase:[sender draggingLocation]];
+ [[view_ urlDropController] indicateDropURLsInView:view_ at:hoverPoint];
}
return dragOp;
}
@@ -67,7 +65,9 @@
if ([urls count]) {
// Tell the window controller about the dropped URL(s).
- [[self windowController] dropURLs:urls at:[sender draggingLocation]];
+ NSPoint dropPoint =
+ [view_ convertPointFromBase:[sender draggingLocation]];
+ [[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint];
return YES;
}
}
@@ -79,21 +79,13 @@
@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 {
- [[self windowController] hideDropURLsIndicator];
+ [[view_ urlDropController] hideDropURLsIndicatorInView:view_];
}
@end // @implementation URLDropTargetHandler(Private)