OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/ui/cocoa/extensions/browser_actions_container_view.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #import "chrome/browser/ui/cocoa/view_id_util.h" | 10 #import "chrome/browser/ui/cocoa/view_id_util.h" |
11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
12 #include "ui/base/cocoa/appkit_utils.h" | 12 #include "ui/base/cocoa/appkit_utils.h" |
13 | 13 |
14 NSString* const kBrowserActionGrippyDragStartedNotification = | 14 NSString* const kBrowserActionGrippyDragStartedNotification = |
15 @"BrowserActionGrippyDragStartedNotification"; | 15 @"BrowserActionGrippyDragStartedNotification"; |
16 NSString* const kBrowserActionGrippyDraggingNotification = | 16 NSString* const kBrowserActionGrippyDraggingNotification = |
17 @"BrowserActionGrippyDraggingNotification"; | 17 @"BrowserActionGrippyDraggingNotification"; |
18 NSString* const kBrowserActionGrippyDragFinishedNotification = | 18 NSString* const kBrowserActionGrippyDragFinishedNotification = |
19 @"BrowserActionGrippyDragFinishedNotification"; | 19 @"BrowserActionGrippyDragFinishedNotification"; |
20 NSString* const kBrowserActionsContainerWillAnimate = | 20 NSString* const kBrowserActionsContainerWillAnimate = |
21 @"BrowserActionsContainerWillAnimate"; | 21 @"BrowserActionsContainerWillAnimate"; |
22 NSString* const kBrowserActionsContainerMouseEntered = | 22 NSString* const kBrowserActionsContainerMouseEntered = |
23 @"BrowserActionsContainerMouseEntered"; | 23 @"BrowserActionsContainerMouseEntered"; |
| 24 NSString* const kBrowserActionsContainerAnimationEnded = |
| 25 @"BrowserActionsContainerAnimationEnded"; |
24 NSString* const kTranslationWithDelta = | 26 NSString* const kTranslationWithDelta = |
25 @"TranslationWithDelta"; | 27 @"TranslationWithDelta"; |
26 | 28 |
27 namespace { | 29 namespace { |
28 const CGFloat kAnimationDuration = 0.2; | 30 const CGFloat kAnimationDuration = 0.2; |
29 const CGFloat kGrippyWidth = 3.0; | 31 const CGFloat kGrippyWidth = 3.0; |
30 const CGFloat kMinimumContainerWidth = 3.0; | 32 const CGFloat kMinimumContainerWidth = 3.0; |
31 } // namespace | 33 } // namespace |
32 | 34 |
33 @interface BrowserActionsContainerView(Private) | 35 @interface BrowserActionsContainerView(Private) |
(...skipping 20 matching lines...) Expand all Loading... |
54 - (id)initWithFrame:(NSRect)frameRect { | 56 - (id)initWithFrame:(NSRect)frameRect { |
55 if ((self = [super initWithFrame:frameRect])) { | 57 if ((self = [super initWithFrame:frameRect])) { |
56 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); | 58 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); |
57 canDragLeft_ = YES; | 59 canDragLeft_ = YES; |
58 canDragRight_ = YES; | 60 canDragRight_ = YES; |
59 resizable_ = YES; | 61 resizable_ = YES; |
60 | 62 |
61 resizeAnimation_.reset([[NSViewAnimation alloc] init]); | 63 resizeAnimation_.reset([[NSViewAnimation alloc] init]); |
62 [resizeAnimation_ setDuration:kAnimationDuration]; | 64 [resizeAnimation_ setDuration:kAnimationDuration]; |
63 [resizeAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 65 [resizeAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 66 [resizeAnimation_ setDelegate:self]; |
64 | 67 |
65 [self setHidden:YES]; | 68 [self setHidden:YES]; |
66 } | 69 } |
67 return self; | 70 return self; |
68 } | 71 } |
69 | 72 |
70 - (void)dealloc { | 73 - (void)dealloc { |
71 if (trackingArea_.get()) | 74 if (trackingArea_.get()) |
72 [self removeTrackingArea:trackingArea_.get()]; | 75 [self removeTrackingArea:trackingArea_.get()]; |
73 [super dealloc]; | 76 [super dealloc]; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 containerFrame.origin.x += dX; | 195 containerFrame.origin.x += dX; |
193 | 196 |
194 [self setFrame:containerFrame]; | 197 [self setFrame:containerFrame]; |
195 [self setNeedsDisplay:YES]; | 198 [self setNeedsDisplay:YES]; |
196 | 199 |
197 [[NSNotificationCenter defaultCenter] | 200 [[NSNotificationCenter defaultCenter] |
198 postNotificationName:kBrowserActionGrippyDraggingNotification | 201 postNotificationName:kBrowserActionGrippyDraggingNotification |
199 object:self]; | 202 object:self]; |
200 } | 203 } |
201 | 204 |
| 205 - (void)animationDidEnd:(NSAnimation*)animation { |
| 206 // We notify asynchronously so that the animation fully finishes before any |
| 207 // listeners do work. |
| 208 [self performSelector:@selector(notifyAnimationEnded) |
| 209 withObject:self |
| 210 afterDelay:0]; |
| 211 } |
| 212 |
| 213 - (void)animationDidStop:(NSAnimation*)animation { |
| 214 // We notify asynchronously so that the animation fully finishes before any |
| 215 // listeners do work. |
| 216 [self performSelector:@selector(notifyAnimationEnded) |
| 217 withObject:self |
| 218 afterDelay:0]; |
| 219 } |
| 220 |
| 221 - (void)notifyAnimationEnded { |
| 222 [[NSNotificationCenter defaultCenter] |
| 223 postNotificationName:kBrowserActionsContainerAnimationEnded |
| 224 object:self]; |
| 225 } |
| 226 |
202 - (ViewID)viewID { | 227 - (ViewID)viewID { |
203 return VIEW_ID_BROWSER_ACTION_TOOLBAR; | 228 return VIEW_ID_BROWSER_ACTION_TOOLBAR; |
204 } | 229 } |
205 | 230 |
206 #pragma mark - | 231 #pragma mark - |
207 #pragma mark Public Methods | 232 #pragma mark Public Methods |
208 | 233 |
209 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { | 234 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { |
210 width = std::max(width, kMinimumContainerWidth); | 235 width = std::max(width, kMinimumContainerWidth); |
211 NSRect frame = [self frame]; | 236 NSRect frame = [self frame]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 retVal = [NSCursor resizeLeftRightCursor]; | 300 retVal = [NSCursor resizeLeftRightCursor]; |
276 } | 301 } |
277 return retVal; | 302 return retVal; |
278 } | 303 } |
279 | 304 |
280 - (CGFloat)maxAllowedWidth { | 305 - (CGFloat)maxAllowedWidth { |
281 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; | 306 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; |
282 } | 307 } |
283 | 308 |
284 @end | 309 @end |
OLD | NEW |