| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/cocoa/extensions/browser_action_button.h" | 5 #import "chrome/browser/cocoa/extensions/browser_action_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; | 36 static const CGFloat kBrowserActionBadgeOriginYOffset = 5; |
| 37 | 37 |
| 38 // Since the container is the maximum height of the toolbar, we have to move the | 38 // Since the container is the maximum height of the toolbar, we have to move the |
| 39 // buttons up by this amount in order to have them look vertically centered | 39 // buttons up by this amount in order to have them look vertically centered |
| 40 // within the toolbar. | 40 // within the toolbar. |
| 41 static const CGFloat kBrowserActionOriginYOffset = 5; | 41 static const CGFloat kBrowserActionOriginYOffset = 5; |
| 42 | 42 |
| 43 // The size of each button on the toolbar. | 43 // The size of each button on the toolbar. |
| 44 static const CGFloat kBrowserActionHeight = 27; | 44 static const CGFloat kBrowserActionHeight = 27; |
| 45 extern const CGFloat kBrowserActionWidth = 29; | 45 const CGFloat kBrowserActionWidth = 29; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 const CGFloat kAnimationDuration = 0.2; | 48 const CGFloat kAnimationDuration = 0.2; |
| 49 const CGFloat kShadowOffset = 2.0; | 49 const CGFloat kShadowOffset = 2.0; |
| 50 } // anonymous namespace | 50 } // anonymous namespace |
| 51 | 51 |
| 52 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to | 52 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to |
| 53 // the extension's button. | 53 // the extension's button. |
| 54 class ExtensionImageTrackerBridge : public NotificationObserver, | 54 class ExtensionImageTrackerBridge : public NotificationObserver, |
| 55 public ImageLoadingTracker::Observer { | 55 public ImageLoadingTracker::Observer { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 174 |
| 175 - (void)mouseDragged:(NSEvent*)theEvent { | 175 - (void)mouseDragged:(NSEvent*)theEvent { |
| 176 if (!dragCouldStart_) | 176 if (!dragCouldStart_) |
| 177 return; | 177 return; |
| 178 | 178 |
| 179 if (!isBeingDragged_) { | 179 if (!isBeingDragged_) { |
| 180 // The start of a drag. Position the button above all others. | 180 // The start of a drag. Position the button above all others. |
| 181 [[self superview] addSubview:self positioned:NSWindowAbove relativeTo:nil]; | 181 [[self superview] addSubview:self positioned:NSWindowAbove relativeTo:nil]; |
| 182 } | 182 } |
| 183 isBeingDragged_ = YES; | 183 isBeingDragged_ = YES; |
| 184 NSPoint location = [self convertPoint:[theEvent locationInWindow] | |
| 185 fromView:nil]; | |
| 186 NSRect buttonFrame = [self frame]; | 184 NSRect buttonFrame = [self frame]; |
| 187 // TODO(andybons): Constrain the buttons to be within the container. | 185 // TODO(andybons): Constrain the buttons to be within the container. |
| 188 // Clamp the button to be within its superview along the X-axis. | 186 // Clamp the button to be within its superview along the X-axis. |
| 189 buttonFrame.origin.x += [theEvent deltaX]; | 187 buttonFrame.origin.x += [theEvent deltaX]; |
| 190 [self setFrame:buttonFrame]; | 188 [self setFrame:buttonFrame]; |
| 191 [self setNeedsDisplay:YES]; | 189 [self setNeedsDisplay:YES]; |
| 192 [[NSNotificationCenter defaultCenter] | 190 [[NSNotificationCenter defaultCenter] |
| 193 postNotificationName:kBrowserActionButtonDraggingNotification | 191 postNotificationName:kBrowserActionButtonDraggingNotification |
| 194 object:self]; | 192 object:self]; |
| 195 } | 193 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 335 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 338 [NSGraphicsContext saveGraphicsState]; | 336 [NSGraphicsContext saveGraphicsState]; |
| 339 [self setIconShadow]; | 337 [self setIconShadow]; |
| 340 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 338 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 341 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 339 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
| 342 [self drawBadgeWithinFrame:cellFrame]; | 340 [self drawBadgeWithinFrame:cellFrame]; |
| 343 [NSGraphicsContext restoreGraphicsState]; | 341 [NSGraphicsContext restoreGraphicsState]; |
| 344 } | 342 } |
| 345 | 343 |
| 346 @end | 344 @end |
| OLD | NEW |