| 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_actions_container_view.h" | 5 #import "chrome/browser/cocoa/extensions/browser_actions_container_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/scoped_nsobject.h" | 10 #import "base/scoped_nsobject.h" |
| 11 | 11 |
| 12 NSString* const kBrowserActionGrippyDragStartedNotification = | 12 NSString* const kBrowserActionGrippyDragStartedNotification = |
| 13 @"BrowserActionGrippyDragStartedNotification"; | 13 @"BrowserActionGrippyDragStartedNotification"; |
| 14 NSString* const kBrowserActionGrippyDraggingNotification = | 14 NSString* const kBrowserActionGrippyDraggingNotification = |
| 15 @"BrowserActionGrippyDraggingNotification"; | 15 @"BrowserActionGrippyDraggingNotification"; |
| 16 NSString* const kBrowserActionGrippyDragFinishedNotification = | 16 NSString* const kBrowserActionGrippyDragFinishedNotification = |
| 17 @"BrowserActionGrippyDragFinishedNotification"; | 17 @"BrowserActionGrippyDragFinishedNotification"; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 const CGFloat kAnimationDuration = 0.2; | 20 const CGFloat kAnimationDuration = 0.2; |
| 21 const CGFloat kGrippyWidth = 8.0; | 21 const CGFloat kGrippyWidth = 4.0; |
| 22 const CGFloat kLowerPadding = 6.0; | |
| 23 const CGFloat kMinimumContainerWidth = 10.0; | 22 const CGFloat kMinimumContainerWidth = 10.0; |
| 24 const CGFloat kRightBorderXOffset = -1.0; | |
| 25 const CGFloat kRightBorderWidth = 1.0; | |
| 26 const CGFloat kRightBorderGrayscale = 0.5; | |
| 27 const CGFloat kUpperPadding = 9.0; | |
| 28 } // namespace | 23 } // namespace |
| 29 | 24 |
| 30 @interface BrowserActionsContainerView(Private) | 25 @interface BrowserActionsContainerView(Private) |
| 31 // Returns the cursor that should be shown when hovering over the grippy based | 26 // Returns the cursor that should be shown when hovering over the grippy based |
| 32 // on |canDragLeft_| and |canDragRight_|. | 27 // on |canDragLeft_| and |canDragRight_|. |
| 33 - (NSCursor*)appropriateCursorForGrippy; | 28 - (NSCursor*)appropriateCursorForGrippy; |
| 34 @end | 29 @end |
| 35 | 30 |
| 36 @implementation BrowserActionsContainerView | 31 @implementation BrowserActionsContainerView |
| 37 | 32 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 if ((self = [super initWithFrame:frameRect])) { | 44 if ((self = [super initWithFrame:frameRect])) { |
| 50 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); | 45 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); |
| 51 canDragLeft_ = YES; | 46 canDragLeft_ = YES; |
| 52 canDragRight_ = YES; | 47 canDragRight_ = YES; |
| 53 resizable_ = YES; | 48 resizable_ = YES; |
| 54 [self setHidden:YES]; | 49 [self setHidden:YES]; |
| 55 } | 50 } |
| 56 return self; | 51 return self; |
| 57 } | 52 } |
| 58 | 53 |
| 59 - (void)drawRect:(NSRect)dirtyRect { | |
| 60 NSRect bounds = [self bounds]; | |
| 61 NSColor* middleColor = | |
| 62 [NSColor colorWithCalibratedWhite:kRightBorderGrayscale alpha:1.0]; | |
| 63 NSColor* endPointColor = | |
| 64 [NSColor colorWithCalibratedWhite:kRightBorderGrayscale alpha:0.0]; | |
| 65 scoped_nsobject<NSGradient> borderGradient([[NSGradient alloc] | |
| 66 initWithColorsAndLocations:endPointColor, (CGFloat)0.0, | |
| 67 middleColor, (CGFloat)0.5, | |
| 68 endPointColor, (CGFloat)1.0, | |
| 69 nil]); | |
| 70 CGFloat xPos = bounds.origin.x + bounds.size.width - kRightBorderWidth + | |
| 71 kRightBorderXOffset; | |
| 72 NSRect borderRect = NSMakeRect(xPos, kLowerPadding, kRightBorderWidth, | |
| 73 bounds.size.height - kUpperPadding); | |
| 74 [borderGradient drawInRect:borderRect angle:90.0]; | |
| 75 } | |
| 76 | |
| 77 - (void)setResizable:(BOOL)resizable { | 54 - (void)setResizable:(BOOL)resizable { |
| 78 if (resizable == resizable_) | 55 if (resizable == resizable_) |
| 79 return; | 56 return; |
| 80 resizable_ = resizable; | 57 resizable_ = resizable; |
| 81 [self setNeedsDisplay:YES]; | 58 [self setNeedsDisplay:YES]; |
| 82 } | 59 } |
| 83 | 60 |
| 84 - (BOOL)isResizable { | 61 - (BOOL)isResizable { |
| 85 return resizable_; | 62 return resizable_; |
| 86 } | 63 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 retVal = [NSCursor resizeRightCursor]; | 175 retVal = [NSCursor resizeRightCursor]; |
| 199 } else if (!canDragRight_) { | 176 } else if (!canDragRight_) { |
| 200 retVal = [NSCursor resizeLeftCursor]; | 177 retVal = [NSCursor resizeLeftCursor]; |
| 201 } else { | 178 } else { |
| 202 retVal = [NSCursor resizeLeftRightCursor]; | 179 retVal = [NSCursor resizeLeftRightCursor]; |
| 203 } | 180 } |
| 204 return retVal; | 181 return retVal; |
| 205 } | 182 } |
| 206 | 183 |
| 207 @end | 184 @end |
| OLD | NEW |