Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #import "chrome/browser/ui/cocoa/l10n_util.h" | |
| 10 #import "chrome/browser/ui/cocoa/view_id_util.h" | 11 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 11 #include "ui/base/cocoa/appkit_utils.h" | 12 #include "ui/base/cocoa/appkit_utils.h" |
| 12 #include "ui/events/keycodes/keyboard_code_conversion_mac.h" | 13 #include "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 13 | 14 |
| 14 NSString* const kBrowserActionGrippyDragStartedNotification = | 15 NSString* const kBrowserActionGrippyDragStartedNotification = |
| 15 @"BrowserActionGrippyDragStartedNotification"; | 16 @"BrowserActionGrippyDragStartedNotification"; |
| 16 NSString* const kBrowserActionGrippyDraggingNotification = | 17 NSString* const kBrowserActionGrippyDraggingNotification = |
| 17 @"BrowserActionGrippyDraggingNotification"; | 18 @"BrowserActionGrippyDraggingNotification"; |
| 18 NSString* const kBrowserActionGrippyDragFinishedNotification = | 19 NSString* const kBrowserActionGrippyDragFinishedNotification = |
| 19 @"BrowserActionGrippyDragFinishedNotification"; | 20 @"BrowserActionGrippyDragFinishedNotification"; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 @synthesize maxDesiredWidth = maxDesiredWidth_; | 52 @synthesize maxDesiredWidth = maxDesiredWidth_; |
| 52 @synthesize userIsResizing = userIsResizing_; | 53 @synthesize userIsResizing = userIsResizing_; |
| 53 @synthesize delegate = delegate_; | 54 @synthesize delegate = delegate_; |
| 54 | 55 |
| 55 #pragma mark - | 56 #pragma mark - |
| 56 #pragma mark Overridden Class Functions | 57 #pragma mark Overridden Class Functions |
| 57 | 58 |
| 58 - (id)initWithFrame:(NSRect)frameRect { | 59 - (id)initWithFrame:(NSRect)frameRect { |
| 59 if ((self = [super initWithFrame:frameRect])) { | 60 if ((self = [super initWithFrame:frameRect])) { |
| 60 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); | 61 grippyRect_ = NSMakeRect(0.0, 0.0, kGrippyWidth, NSHeight([self bounds])); |
| 62 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
| 63 grippyRect_.origin.x = NSWidth(frameRect) - NSWidth(grippyRect_); | |
| 64 | |
| 61 canDragLeft_ = YES; | 65 canDragLeft_ = YES; |
| 62 canDragRight_ = YES; | 66 canDragRight_ = YES; |
| 63 resizable_ = YES; | 67 resizable_ = YES; |
| 64 | 68 |
| 65 resizeAnimation_.reset([[NSViewAnimation alloc] init]); | 69 resizeAnimation_.reset([[NSViewAnimation alloc] init]); |
| 66 [resizeAnimation_ setDuration:kAnimationDuration]; | 70 [resizeAnimation_ setDuration:kAnimationDuration]; |
| 67 [resizeAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 71 [resizeAnimation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 68 [resizeAnimation_ setDelegate:self]; | 72 [resizeAnimation_ setDelegate:self]; |
| 69 | 73 |
| 70 [self setHidden:YES]; | 74 [self setHidden:YES]; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 | 159 |
| 156 - (void)setIsOverflow:(BOOL)isOverflow { | 160 - (void)setIsOverflow:(BOOL)isOverflow { |
| 157 if (isOverflow_ != isOverflow) { | 161 if (isOverflow_ != isOverflow) { |
| 158 isOverflow_ = isOverflow; | 162 isOverflow_ = isOverflow; |
| 159 resizable_ = !isOverflow_; | 163 resizable_ = !isOverflow_; |
| 160 [self setNeedsDisplay:YES]; | 164 [self setNeedsDisplay:YES]; |
| 161 } | 165 } |
| 162 } | 166 } |
| 163 | 167 |
| 164 - (void)resetCursorRects { | 168 - (void)resetCursorRects { |
| 169 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
| 170 grippyRect_.origin.x = NSWidth([self frame]) - NSWidth(grippyRect_); | |
| 165 [self addCursorRect:grippyRect_ cursor:[self appropriateCursorForGrippy]]; | 171 [self addCursorRect:grippyRect_ cursor:[self appropriateCursorForGrippy]]; |
| 166 } | 172 } |
| 167 | 173 |
| 168 - (BOOL)acceptsFirstResponder { | 174 - (BOOL)acceptsFirstResponder { |
| 169 // The overflow container needs to receive key events to handle in-item | 175 // The overflow container needs to receive key events to handle in-item |
| 170 // navigation. The top-level container should not become first responder, | 176 // navigation. The top-level container should not become first responder, |
| 171 // allowing focus travel to proceed to the first action. | 177 // allowing focus travel to proceed to the first action. |
| 172 return isOverflow_; | 178 return isOverflow_; |
| 173 } | 179 } |
| 174 | 180 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 } | 212 } |
| 207 | 213 |
| 208 - (void)mouseDragged:(NSEvent*)theEvent { | 214 - (void)mouseDragged:(NSEvent*)theEvent { |
| 209 if (!userIsResizing_) | 215 if (!userIsResizing_) |
| 210 return; | 216 return; |
| 211 | 217 |
| 212 NSPoint location = [self convertPoint:[theEvent locationInWindow] | 218 NSPoint location = [self convertPoint:[theEvent locationInWindow] |
| 213 fromView:nil]; | 219 fromView:nil]; |
| 214 NSRect containerFrame = [self frame]; | 220 NSRect containerFrame = [self frame]; |
| 215 CGFloat dX = [theEvent deltaX]; | 221 CGFloat dX = [theEvent deltaX]; |
| 216 CGFloat withDelta = location.x - dX; | 222 CGFloat withDelta = location.x - dX; |
|
tapted
2017/01/04 06:08:09
should this be widthDelta?
lgrey
2017/01/04 17:36:38
My understanding is it's "the drag point with the
tapted
2017/01/04 22:57:50
Acknowledged.
| |
| 217 canDragRight_ = (withDelta >= initialDragPoint_.x) && | 223 |
| 218 (NSWidth(containerFrame) > kMinimumContainerWidth); | |
| 219 CGFloat maxAllowedWidth = [self maxAllowedWidth]; | 224 CGFloat maxAllowedWidth = [self maxAllowedWidth]; |
| 220 containerFrame.size.width = | |
| 221 std::max(NSWidth(containerFrame) - dX, kMinimumContainerWidth); | |
| 222 canDragLeft_ = withDelta <= initialDragPoint_.x && | |
| 223 NSWidth(containerFrame) < maxDesiredWidth_ && | |
| 224 NSWidth(containerFrame) < maxAllowedWidth; | |
| 225 | 225 |
| 226 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) | 226 containerFrame.size.width = std::min( |
|
tapted
2017/01/04 06:08:09
does this need to clamp to maxAllowedWidth as well
lgrey
2017/01/04 17:36:38
How's this?
tapted
2017/01/04 22:57:50
nice :)
| |
| 227 maxDesiredWidth_, | |
| 228 std::max( | |
| 229 NSWidth(containerFrame) + | |
| 230 (cocoa_l10n_util::ShouldDoExperimentalRTLLayout() ? dX : -dX), | |
| 231 kMinimumContainerWidth)); | |
| 232 BOOL canGrow = NSWidth(containerFrame) < maxDesiredWidth_ && | |
| 233 NSWidth(containerFrame) < maxAllowedWidth; | |
| 234 BOOL canShrink = NSWidth(containerFrame) > kMinimumContainerWidth; | |
| 235 | |
| 236 canDragLeft_ = | |
| 237 withDelta <= initialDragPoint_.x && | |
| 238 (cocoa_l10n_util::ShouldDoExperimentalRTLLayout() ? canShrink : canGrow); | |
| 239 canDragRight_ = | |
| 240 (withDelta >= initialDragPoint_.x) && | |
| 241 (cocoa_l10n_util::ShouldDoExperimentalRTLLayout() ? canGrow : canShrink); | |
| 242 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_) || | |
| 243 fabs(dX) < FLT_EPSILON) | |
| 227 return; | 244 return; |
| 228 | 245 |
| 229 if (NSWidth(containerFrame) <= kMinimumContainerWidth) | 246 if (NSWidth(containerFrame) <= kMinimumContainerWidth) |
| 230 return; | 247 return; |
| 231 | 248 |
| 232 grippyPinned_ = NSWidth(containerFrame) >= maxAllowedWidth; | 249 grippyPinned_ = NSWidth(containerFrame) >= maxAllowedWidth; |
| 233 containerFrame.origin.x += dX; | 250 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
| 251 containerFrame.origin.x += dX; | |
| 234 | 252 |
| 235 [self setFrame:containerFrame]; | 253 [self setFrame:containerFrame]; |
| 236 [self setNeedsDisplay:YES]; | 254 [self setNeedsDisplay:YES]; |
| 237 | 255 |
| 238 [[NSNotificationCenter defaultCenter] | 256 [[NSNotificationCenter defaultCenter] |
| 239 postNotificationName:kBrowserActionGrippyDraggingNotification | 257 postNotificationName:kBrowserActionGrippyDraggingNotification |
| 240 object:self]; | 258 object:self]; |
| 241 } | 259 } |
| 242 | 260 |
| 243 - (void)animationDidEnd:(NSAnimation*)animation { | 261 - (void)animationDidEnd:(NSAnimation*)animation { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 269 #pragma mark - | 287 #pragma mark - |
| 270 #pragma mark Public Methods | 288 #pragma mark Public Methods |
| 271 | 289 |
| 272 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { | 290 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { |
| 273 width = std::max(width, kMinimumContainerWidth); | 291 width = std::max(width, kMinimumContainerWidth); |
| 274 NSRect frame = [self frame]; | 292 NSRect frame = [self frame]; |
| 275 | 293 |
| 276 CGFloat maxAllowedWidth = [self maxAllowedWidth]; | 294 CGFloat maxAllowedWidth = [self maxAllowedWidth]; |
| 277 width = std::min(maxAllowedWidth, width); | 295 width = std::min(maxAllowedWidth, width); |
| 278 | 296 |
| 279 CGFloat dX = frame.size.width - width; | 297 NSRect newFrame; |
|
tapted
2017/01/04 06:08:09
|newFrame| doesn't really seem to serve a purpose
lgrey
2017/01/04 17:36:38
Had this thought as well, but check the |if (anima
tapted
2017/01/04 22:57:50
I think that's currently using [self frame], not |
lgrey
2017/01/05 20:50:33
Done.
| |
| 280 frame.size.width = width; | 298 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
| 281 NSRect newFrame = NSOffsetRect(frame, dX, 0); | 299 newFrame = frame; |
| 300 newFrame.size.width = width; | |
| 301 } else { | |
| 302 CGFloat dX = frame.size.width - width; | |
| 303 frame.size.width = width; | |
| 304 newFrame = NSOffsetRect(frame, dX, 0); | |
| 305 } | |
| 282 | 306 |
| 283 grippyPinned_ = width == maxAllowedWidth; | 307 grippyPinned_ = width == maxAllowedWidth; |
| 284 | 308 |
| 285 [self stopAnimation]; | 309 [self stopAnimation]; |
| 286 | 310 |
| 287 if (animate) { | 311 if (animate) { |
| 288 NSDictionary* animationDictionary = @{ | 312 NSDictionary* animationDictionary = @{ |
| 289 NSViewAnimationTargetKey : self, | 313 NSViewAnimationTargetKey : self, |
| 290 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], | 314 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], |
| 291 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] | 315 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 retVal = [NSCursor resizeLeftRightCursor]; | 362 retVal = [NSCursor resizeLeftRightCursor]; |
| 339 } | 363 } |
| 340 return retVal; | 364 return retVal; |
| 341 } | 365 } |
| 342 | 366 |
| 343 - (CGFloat)maxAllowedWidth { | 367 - (CGFloat)maxAllowedWidth { |
| 344 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; | 368 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; |
| 345 } | 369 } |
| 346 | 370 |
| 347 @end | 371 @end |
| OLD | NEW |