Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: chrome/browser/cocoa/extensions/browser_actions_container_view.mm

Issue 2863013: [Mac] UI changes for the Browser Actions toolbar container.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 kGrippyLowerPadding = 4.0; 21 const CGFloat kGrippyWidth = 8.0;
22 const CGFloat kGrippyUpperPadding = 8.0;
23 const CGFloat kGrippyWidth = 10.0;
24 const CGFloat kLowerPadding = 5.0;
25 const CGFloat kMinimumContainerWidth = 10.0; 22 const CGFloat kMinimumContainerWidth = 10.0;
26 const CGFloat kRightBorderXOffset = -1.0;
27 const CGFloat kRightBorderWidth = 1.0;
28 const CGFloat kRightBorderGrayscale = 0.5;
29 const CGFloat kUpperPadding = 9.0;
30 } // namespace 23 } // namespace
31 24
32 @interface BrowserActionsContainerView(Private) 25 @interface BrowserActionsContainerView(Private)
33 // 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
34 // on |canDragLeft_| and |canDragRight_|. 27 // on |canDragLeft_| and |canDragRight_|.
35 - (NSCursor*)appropriateCursorForGrippy; 28 - (NSCursor*)appropriateCursorForGrippy;
36 // Draws the area that the user can use to resize the container. Currently, two
37 // vertical "grip" bars.
38 - (void)drawGrippy;
39 @end 29 @end
40 30
41 @implementation BrowserActionsContainerView 31 @implementation BrowserActionsContainerView
42 32
43 @synthesize animationEndFrame = animationEndFrame_; 33 @synthesize animationEndFrame = animationEndFrame_;
44 @synthesize canDragLeft = canDragLeft_; 34 @synthesize canDragLeft = canDragLeft_;
45 @synthesize canDragRight = canDragRight_; 35 @synthesize canDragRight = canDragRight_;
46 @synthesize grippyPinned = grippyPinned_; 36 @synthesize grippyPinned = grippyPinned_;
47 @synthesize maxWidth = maxWidth_; 37 @synthesize maxWidth = maxWidth_;
48 @synthesize userIsResizing = userIsResizing_; 38 @synthesize userIsResizing = userIsResizing_;
49 @synthesize rightBorderShown = rightBorderShown_;
50 39
51 #pragma mark - 40 #pragma mark -
52 #pragma mark Overridden Class Functions 41 #pragma mark Overridden Class Functions
53 42
54 - (id)initWithFrame:(NSRect)frameRect { 43 - (id)initWithFrame:(NSRect)frameRect {
55 if ((self = [super initWithFrame:frameRect])) { 44 if ((self = [super initWithFrame:frameRect])) {
56 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); 45 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds]));
57 canDragLeft_ = YES; 46 canDragLeft_ = YES;
58 canDragRight_ = YES; 47 canDragRight_ = YES;
59 resizable_ = YES; 48 resizable_ = YES;
60 [self setHidden:YES]; 49 [self setHidden:YES];
61 } 50 }
62 return self; 51 return self;
63 } 52 }
64 53
65 - (void)setResizable:(BOOL)resizable { 54 - (void)setResizable:(BOOL)resizable {
66 if (resizable == resizable_) 55 if (resizable == resizable_)
67 return; 56 return;
68 resizable_ = resizable; 57 resizable_ = resizable;
69 [self setNeedsDisplay:YES]; 58 [self setNeedsDisplay:YES];
70 } 59 }
71 60
72 - (BOOL)isResizable { 61 - (BOOL)isResizable {
73 return resizable_; 62 return resizable_;
74 } 63 }
75 64
76 - (void)drawRect:(NSRect)dirtyRect {
77 if (rightBorderShown_) {
78 NSRect bounds = [self bounds];
79 NSColor* middleColor =
80 [NSColor colorWithCalibratedWhite:kRightBorderGrayscale alpha:1.0];
81 NSColor* endPointColor =
82 [NSColor colorWithCalibratedWhite:kRightBorderGrayscale alpha:0.0];
83 scoped_nsobject<NSGradient> borderGradient([[NSGradient alloc]
84 initWithColorsAndLocations:endPointColor, (CGFloat)0.0,
85 middleColor, (CGFloat)0.5,
86 endPointColor, (CGFloat)1.0,
87 nil]);
88 CGFloat xPos = bounds.origin.x + bounds.size.width - kRightBorderWidth +
89 kRightBorderXOffset;
90 NSRect borderRect = NSMakeRect(xPos, kLowerPadding, kRightBorderWidth,
91 bounds.size.height - kUpperPadding);
92 [borderGradient drawInRect:borderRect angle:90.0];
93 }
94
95 if (resizable_)
96 [self drawGrippy];
97 }
98
99 - (void)resetCursorRects { 65 - (void)resetCursorRects {
100 [self discardCursorRects]; 66 [self discardCursorRects];
101 [self addCursorRect:grippyRect_ cursor:[self appropriateCursorForGrippy]]; 67 [self addCursorRect:grippyRect_ cursor:[self appropriateCursorForGrippy]];
102 } 68 }
103 69
104 - (BOOL)acceptsFirstResponder { 70 - (BOOL)acceptsFirstResponder {
105 return YES; 71 return YES;
106 } 72 }
107 73
108 - (void)mouseDown:(NSEvent*)theEvent { 74 - (void)mouseDown:(NSEvent*)theEvent {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } else if (!canDragLeft_) { 174 } else if (!canDragLeft_) {
209 retVal = [NSCursor resizeRightCursor]; 175 retVal = [NSCursor resizeRightCursor];
210 } else if (!canDragRight_) { 176 } else if (!canDragRight_) {
211 retVal = [NSCursor resizeLeftCursor]; 177 retVal = [NSCursor resizeLeftCursor];
212 } else { 178 } else {
213 retVal = [NSCursor resizeLeftRightCursor]; 179 retVal = [NSCursor resizeLeftRightCursor];
214 } 180 }
215 return retVal; 181 return retVal;
216 } 182 }
217 183
218 - (void)drawGrippy {
219 NSRect grippyRect = NSMakeRect(0.0, kLowerPadding + kGrippyLowerPadding, 1.0,
220 [self bounds].size.height - kUpperPadding - kGrippyUpperPadding);
221 [[NSColor colorWithCalibratedWhite:0.7 alpha:0.5] set];
222 NSRectFill(grippyRect);
223
224 [[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] set];
225 grippyRect.origin.x += 1.0;
226 NSRectFill(grippyRect);
227
228 grippyRect.origin.x += 1.0;
229
230 [[NSColor colorWithCalibratedWhite:0.7 alpha:0.5] set];
231 grippyRect.origin.x += 1.0;
232 NSRectFill(grippyRect);
233
234 [[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] set];
235 grippyRect.origin.x += 1.0;
236 NSRectFill(grippyRect);
237 }
238
239 @end 184 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698