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