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" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 object:self]; | 113 object:self]; |
114 } | 114 } |
115 | 115 |
116 - (void)mouseDown:(NSEvent*)theEvent { | 116 - (void)mouseDown:(NSEvent*)theEvent { |
117 initialDragPoint_ = [self convertPoint:[theEvent locationInWindow] | 117 initialDragPoint_ = [self convertPoint:[theEvent locationInWindow] |
118 fromView:nil]; | 118 fromView:nil]; |
119 if (!resizable_ || | 119 if (!resizable_ || |
120 !NSMouseInRect(initialDragPoint_, grippyRect_, [self isFlipped])) | 120 !NSMouseInRect(initialDragPoint_, grippyRect_, [self isFlipped])) |
121 return; | 121 return; |
122 | 122 |
123 lastXPos_ = [self frame].origin.x; | |
124 userIsResizing_ = YES; | 123 userIsResizing_ = YES; |
125 | 124 |
126 [[self appropriateCursorForGrippy] push]; | 125 [[self appropriateCursorForGrippy] push]; |
127 // Disable cursor rects so that the Omnibox and other UI elements don't push | 126 // Disable cursor rects so that the Omnibox and other UI elements don't push |
128 // cursors while the user is dragging. The cursor should be grippy until | 127 // cursors while the user is dragging. The cursor should be grippy until |
129 // the |-mouseUp:| message is received. | 128 // the |-mouseUp:| message is received. |
130 [[self window] disableCursorRects]; | 129 [[self window] disableCursorRects]; |
131 | 130 |
132 [[NSNotificationCenter defaultCenter] | 131 [[NSNotificationCenter defaultCenter] |
133 postNotificationName:kBrowserActionGrippyDragStartedNotification | 132 postNotificationName:kBrowserActionGrippyDragStartedNotification |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 grippyPinned_ = NSWidth(containerFrame) >= maxAllowedWidth; | 173 grippyPinned_ = NSWidth(containerFrame) >= maxAllowedWidth; |
175 containerFrame.origin.x += dX; | 174 containerFrame.origin.x += dX; |
176 | 175 |
177 [self setFrame:containerFrame]; | 176 [self setFrame:containerFrame]; |
178 [self setNeedsDisplay:YES]; | 177 [self setNeedsDisplay:YES]; |
179 | 178 |
180 [[NSNotificationCenter defaultCenter] | 179 [[NSNotificationCenter defaultCenter] |
181 postNotificationName:kBrowserActionGrippyDraggingNotification | 180 postNotificationName:kBrowserActionGrippyDraggingNotification |
182 object:self]; | 181 object:self]; |
183 | |
184 lastXPos_ += dX; | |
185 } | 182 } |
186 | 183 |
187 - (ViewID)viewID { | 184 - (ViewID)viewID { |
188 return VIEW_ID_BROWSER_ACTION_TOOLBAR; | 185 return VIEW_ID_BROWSER_ACTION_TOOLBAR; |
189 } | 186 } |
190 | 187 |
191 #pragma mark - | 188 #pragma mark - |
192 #pragma mark Public Methods | 189 #pragma mark Public Methods |
193 | 190 |
194 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { | 191 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { |
195 width = std::max(width, kMinimumContainerWidth); | 192 width = std::max(width, kMinimumContainerWidth); |
196 NSRect frame = [self frame]; | 193 NSRect frame = [self frame]; |
197 | 194 |
198 CGFloat maxAllowedWidth = [self maxAllowedWidth]; | 195 CGFloat maxAllowedWidth = [self maxAllowedWidth]; |
199 width = std::min(maxAllowedWidth, width); | 196 width = std::min(maxAllowedWidth, width); |
200 | 197 |
201 lastXPos_ = frame.origin.x; | |
202 CGFloat dX = frame.size.width - width; | 198 CGFloat dX = frame.size.width - width; |
203 frame.size.width = width; | 199 frame.size.width = width; |
204 NSRect newFrame = NSOffsetRect(frame, dX, 0); | 200 NSRect newFrame = NSOffsetRect(frame, dX, 0); |
205 | 201 |
206 grippyPinned_ = width == maxAllowedWidth; | 202 grippyPinned_ = width == maxAllowedWidth; |
207 | 203 |
208 [self stopAnimation]; | 204 [self stopAnimation]; |
209 | 205 |
210 if (animate) { | 206 if (animate) { |
211 NSDictionary* animationDictionary = @{ | 207 NSDictionary* animationDictionary = @{ |
212 NSViewAnimationTargetKey : self, | 208 NSViewAnimationTargetKey : self, |
213 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], | 209 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], |
214 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] | 210 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] |
215 }; | 211 }; |
216 [resizeAnimation_ setViewAnimations:@[ animationDictionary ]]; | 212 [resizeAnimation_ setViewAnimations:@[ animationDictionary ]]; |
217 [resizeAnimation_ startAnimation]; | 213 [resizeAnimation_ startAnimation]; |
218 | 214 |
219 [[NSNotificationCenter defaultCenter] | 215 [[NSNotificationCenter defaultCenter] |
220 postNotificationName:kBrowserActionsContainerWillAnimate | 216 postNotificationName:kBrowserActionsContainerWillAnimate |
221 object:self]; | 217 object:self]; |
222 } else { | 218 } else { |
223 [self setFrame:newFrame]; | 219 [self setFrame:newFrame]; |
224 [self setNeedsDisplay:YES]; | 220 [self setNeedsDisplay:YES]; |
225 } | 221 } |
226 } | 222 } |
227 | 223 |
228 - (CGFloat)resizeDeltaX { | |
229 return [self frame].origin.x - lastXPos_; | |
230 } | |
231 | |
232 - (NSRect)animationEndFrame { | 224 - (NSRect)animationEndFrame { |
233 if ([resizeAnimation_ isAnimating]) { | 225 if ([resizeAnimation_ isAnimating]) { |
234 NSRect endFrame = [[[[resizeAnimation_ viewAnimations] objectAtIndex:0] | 226 NSRect endFrame = [[[[resizeAnimation_ viewAnimations] objectAtIndex:0] |
235 valueForKey:NSViewAnimationEndFrameKey] rectValue]; | 227 valueForKey:NSViewAnimationEndFrameKey] rectValue]; |
236 return endFrame; | 228 return endFrame; |
237 } else { | 229 } else { |
238 return [self frame]; | 230 return [self frame]; |
239 } | 231 } |
240 } | 232 } |
241 | 233 |
(...skipping 23 matching lines...) Expand all Loading... |
265 retVal = [NSCursor resizeLeftRightCursor]; | 257 retVal = [NSCursor resizeLeftRightCursor]; |
266 } | 258 } |
267 return retVal; | 259 return retVal; |
268 } | 260 } |
269 | 261 |
270 - (CGFloat)maxAllowedWidth { | 262 - (CGFloat)maxAllowedWidth { |
271 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; | 263 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; |
272 } | 264 } |
273 | 265 |
274 @end | 266 @end |
OLD | NEW |