Home | History | Annotate | Download | only in cocoa
      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.
      4 
      5 #import "chrome/browser/ui/cocoa/draggable_button.h"
      6 
      7 #include "base/logging.h"
      8 
      9 @implementation DraggableButton
     10 
     11 - (id)initWithFrame:(NSRect)frame {
     12   if ((self = [super initWithFrame:frame])) {
     13     draggableButtonImpl_.reset(
     14         [[DraggableButtonImpl alloc] initWithButton:self]);
     15   }
     16   return self;
     17 }
     18 
     19 - (id)initWithCoder:(NSCoder*)coder {
     20   if ((self = [super initWithCoder:coder])) {
     21     draggableButtonImpl_.reset(
     22         [[DraggableButtonImpl alloc] initWithButton:self]);
     23   }
     24   return self;
     25 }
     26 
     27 - (DraggableButtonImpl*)draggableButton {
     28   return draggableButtonImpl_.get();
     29 }
     30 
     31 - (void)mouseUp:(NSEvent*)theEvent {
     32   if ([draggableButtonImpl_ mouseUpImpl:theEvent] ==
     33           kDraggableButtonMixinCallSuper) {
     34     [super mouseUp:theEvent];
     35   }
     36 }
     37 
     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
     41   // the duration.
     42   base::scoped_nsobject<DraggableButton> keepAlive([self retain]);
     43 
     44   if ([draggableButtonImpl_ mouseDownImpl:theEvent] ==
     45           kDraggableButtonMixinCallSuper) {
     46     [super mouseDown:theEvent];
     47   }
     48 }
     49 
     50 - (void)beginDrag:(NSEvent*)dragEvent {
     51   // Must be overridden by subclasses.
     52   NOTREACHED();
     53 }
     54 
     55 @end  // @interface DraggableButton
     56