1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/draggable_button.h"
7 #include "base/logging.h"
9 @implementation DraggableButton
11 - (id)initWithFrame:(NSRect)frame {
12 if ((self = [super initWithFrame:frame])) {
13 draggableButtonImpl_.reset(
14 [[DraggableButtonImpl alloc] initWithButton:self]);
19 - (id)initWithCoder:(NSCoder*)coder {
20 if ((self = [super initWithCoder:coder])) {
21 draggableButtonImpl_.reset(
22 [[DraggableButtonImpl alloc] initWithButton:self]);
27 - (DraggableButtonImpl*)draggableButton {
28 return draggableButtonImpl_.get();
31 - (void)mouseUp:(NSEvent*)theEvent {
32 if ([draggableButtonImpl_ mouseUpImpl:theEvent] ==
33 kDraggableButtonMixinCallSuper) {
34 [super mouseUp:theEvent];
38 - (void)mouseDown:(NSEvent*)theEvent {
39 // The impl spins an event loop to distinguish clicks from drags,
40 // which could result in our destruction. Wire ourselves down for
42 base::scoped_nsobject<DraggableButton> keepAlive([self retain]);
44 if ([draggableButtonImpl_ mouseDownImpl:theEvent] ==
45 kDraggableButtonMixinCallSuper) {
46 [super mouseDown:theEvent];
50 - (void)beginDrag:(NSEvent*)dragEvent {
51 // Must be overridden by subclasses.
55 @end // @interface DraggableButton