OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history_overlay_controller.h" | 5 #import "chrome/browser/ui/cocoa/history_overlay_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
9 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 - (id)initForMode:(HistoryOverlayMode)mode { | 83 - (id)initForMode:(HistoryOverlayMode)mode { |
84 if ((self = [super init])) { | 84 if ((self = [super init])) { |
85 mode_ = mode; | 85 mode_ = mode; |
86 DCHECK(mode == kHistoryOverlayModeBack || | 86 DCHECK(mode == kHistoryOverlayModeBack || |
87 mode == kHistoryOverlayModeForward); | 87 mode == kHistoryOverlayModeForward); |
88 } | 88 } |
89 return self; | 89 return self; |
90 } | 90 } |
91 | 91 |
92 - (void)dealloc { | |
93 [[BrowserWindowController | |
94 browserWindowControllerForView:[self view]] onOverlappedViewHidden]; | |
95 [self.view removeFromSuperview]; | |
96 [super dealloc]; | |
97 } | |
98 | |
99 - (void)loadView { | 92 - (void)loadView { |
100 const gfx::Image& image = | 93 const gfx::Image& image = |
101 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 94 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
102 mode_ == kHistoryOverlayModeBack ? IDR_SWIPE_BACK | 95 mode_ == kHistoryOverlayModeBack ? IDR_SWIPE_BACK |
103 : IDR_SWIPE_FORWARD); | 96 : IDR_SWIPE_FORWARD); |
104 contentView_.reset( | 97 contentView_.reset( |
105 [[HistoryOverlayView alloc] initWithMode:mode_ | 98 [[HistoryOverlayView alloc] initWithMode:mode_ |
106 image:image.ToNSImage()]); | 99 image:image.ToNSImage()]); |
107 self.view = contentView_; | 100 self.view = contentView_; |
108 } | 101 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 [[parent_ superview] addSubview:self.view | 138 [[parent_ superview] addSubview:self.view |
146 positioned:NSWindowAbove | 139 positioned:NSWindowAbove |
147 relativeTo:parent_]; | 140 relativeTo:parent_]; |
148 [[BrowserWindowController | 141 [[BrowserWindowController |
149 browserWindowControllerForView:[self view]] onOverlappedViewShown]; | 142 browserWindowControllerForView:[self view]] onOverlappedViewShown]; |
150 } | 143 } |
151 | 144 |
152 - (void)dismiss { | 145 - (void)dismiss { |
153 const CGFloat kFadeOutDurationSeconds = 0.4; | 146 const CGFloat kFadeOutDurationSeconds = 0.4; |
154 | 147 |
| 148 [NSAnimationContext beginGrouping]; |
| 149 [NSAnimationContext currentContext].duration = kFadeOutDurationSeconds; |
155 NSView* overlay = self.view; | 150 NSView* overlay = self.view; |
156 | 151 |
157 base::scoped_nsobject<CAAnimation> animation( | 152 base::scoped_nsobject<CAAnimation> animation( |
158 [[overlay animationForKey:@"alphaValue"] copy]); | 153 [[overlay animationForKey:@"alphaValue"] copy]); |
159 [animation setDelegate:self]; | 154 [animation setDelegate:self]; |
160 [animation setDuration:kFadeOutDurationSeconds]; | 155 [animation setDuration:kFadeOutDurationSeconds]; |
161 NSMutableDictionary* dictionary = | 156 NSMutableDictionary* dictionary = |
162 [NSMutableDictionary dictionaryWithCapacity:1]; | 157 [NSMutableDictionary dictionaryWithCapacity:1]; |
163 [dictionary setObject:animation forKey:@"alphaValue"]; | 158 [dictionary setObject:animation forKey:@"alphaValue"]; |
164 [overlay setAnimations:dictionary]; | 159 [overlay setAnimations:dictionary]; |
165 [[overlay animator] setAlphaValue:0.0]; | 160 [[overlay animator] setAlphaValue:0.0]; |
| 161 [NSAnimationContext endGrouping]; |
166 } | 162 } |
167 | 163 |
168 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { | 164 - (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { |
| 165 [[BrowserWindowController |
| 166 browserWindowControllerForView:[self view]] onOverlappedViewHidden]; |
| 167 [self.view removeFromSuperview]; |
169 // Destroy the CAAnimation and its strong reference to its delegate (this | 168 // Destroy the CAAnimation and its strong reference to its delegate (this |
170 // class). | 169 // class). |
171 [self.view setAnimations:nil]; | 170 [self.view setAnimations:nil]; |
172 } | 171 } |
173 | 172 |
174 @end | 173 @end |
OLD | NEW |