summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_button.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/bookmark_button.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_button.mm86
1 files changed, 5 insertions, 81 deletions
diff --git a/chrome/browser/cocoa/bookmark_button.mm b/chrome/browser/cocoa/bookmark_button.mm
index 55c95f6..b0b6ecd 100644
--- a/chrome/browser/cocoa/bookmark_button.mm
+++ b/chrome/browser/cocoa/bookmark_button.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,19 +6,9 @@
#import "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/bookmark_button.h"
#import "chrome/browser/cocoa/bookmark_button_cell.h"
-#import "third_party/GTM/AppKit/GTMTheme.h"
-
-namespace {
-
-// Code taken from <http://codereview.chromium.org/180036/diff/3001/3004>.
-// TODO(viettrungluu): Do we want common, standard code for drag hysteresis?
-const CGFloat kWebDragStartHysteresisX = 5.0;
-const CGFloat kWebDragStartHysteresisY = 5.0;
// The opacity of the bookmark button drag image.
-const CGFloat kDragImageOpacity = 0.7;
-
-}
+static const CGFloat kDragImageOpacity = 0.7;
@interface BookmarkButton(Private)
@@ -29,25 +19,15 @@ const CGFloat kDragImageOpacity = 0.7;
@implementation BookmarkButton
-@synthesize draggable = draggable_;
@synthesize delegate = delegate_;
-- (id)initWithFrame:(NSRect)frame {
- if ((self = [super initWithFrame:frame])) {
- draggable_ = YES;
- }
- return self;
-}
-
// By default, NSButton ignores middle-clicks.
- (void)otherMouseUp:(NSEvent*)event {
[self performClick:self];
}
+// Overridden from DraggableButton.
- (void)beginDrag:(NSEvent*)event {
- // Starting drag. Never start another drag until another mouse down.
- mayDragStart_ = NO;
-
if (delegate_) {
// Ask our delegate to fill the pasteboard for us.
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
@@ -64,7 +44,7 @@ const CGFloat kDragImageOpacity = 0.7;
[self dragImage:[self dragImage] at:NSMakePoint(0, yAt) offset:dragOffset
event:event pasteboard:pboard source:self slideBack:YES];
- // And we're done.
+ // And we're done.
[self autorelease];
} else {
// Avoid blowing up, but we really shouldn't get here.
@@ -75,8 +55,7 @@ const CGFloat kDragImageOpacity = 0.7;
- (void)draggedImage:(NSImage*)anImage
endedAt:(NSPoint)aPoint
operation:(NSDragOperation)operation {
- beingDragged_ = NO;
- [[self cell] setHighlighted:NO];
+ [super endDrag];
}
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
@@ -84,61 +63,6 @@ const CGFloat kDragImageOpacity = 0.7;
: NSDragOperationCopy;
}
-- (void)mouseUp:(NSEvent*)theEvent {
- // Make sure that we can't start a drag until we see a mouse down again.
- mayDragStart_ = NO;
-
- // This conditional is never true (DnD loops in Cocoa eat the mouse
- // up) but I added it in case future versions of Cocoa do unexpected
- // things.
- if (beingDragged_) {
- NOTREACHED();
- return [super mouseUp:theEvent];
- }
-
- // There are non-drag cases where a mouseUp: may happen
- // (e.g. mouse-down, cmd-tab to another application, move mouse,
- // mouse-up). So we check.
- NSPoint viewLocal = [self convertPoint:[theEvent locationInWindow]
- fromView:[[self window] contentView]];
- if (NSPointInRect(viewLocal, [self bounds])) {
- [self performClick:self];
- } else {
- [[self cell] setHighlighted:NO];
- }
-}
-
-// Mimic "begin a click" operation visually. Do NOT follow through
-// with normal button event handling.
-- (void)mouseDown:(NSEvent*)theEvent {
- mayDragStart_ = YES;
- [[self cell] setHighlighted:YES];
- initialMouseDownLocation_ = [theEvent locationInWindow];
-}
-
-// Return YES if we have crossed a threshold of movement after
-// mouse-down when we should begin a drag. Else NO.
-- (BOOL)hasCrossedDragThreshold:(NSEvent*)theEvent {
- NSPoint currentLocation = [theEvent locationInWindow];
- if ((abs(currentLocation.x - initialMouseDownLocation_.x) >
- kWebDragStartHysteresisX) ||
- (abs(currentLocation.y - initialMouseDownLocation_.y) >
- kWebDragStartHysteresisY)) {
- return YES;
- } else {
- return NO;
- }
-}
-
-- (void)mouseDragged:(NSEvent*)theEvent {
- if (beingDragged_) {
- [super mouseDragged:theEvent];
- } else if (draggable_ && mayDragStart_ &&
- [self hasCrossedDragThreshold:theEvent]) {
- [self beginDrag:theEvent];
- }
-}
-
@end
@implementation BookmarkButton(Private)