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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
217 canDragRight_ = (withDelta >= initialDragPoint_.x) && | 223 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
218 (NSWidth(containerFrame) > kMinimumContainerWidth); | 224 |
219 CGFloat maxAllowedWidth = [self maxAllowedWidth]; | 225 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 | 226 |
226 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_)) | 227 const CGFloat maxWidth = std::min(maxAllowedWidth, maxDesiredWidth_); |
| 228 CGFloat newWidth = NSWidth(containerFrame) + (isRTL ? dX : -dX); |
| 229 newWidth = std::min(std::max(newWidth, kMinimumContainerWidth), maxWidth); |
| 230 |
| 231 BOOL canGrow = NSWidth(containerFrame) < maxWidth; |
| 232 BOOL canShrink = NSWidth(containerFrame) > kMinimumContainerWidth; |
| 233 |
| 234 canDragLeft_ = |
| 235 withDelta <= initialDragPoint_.x && (isRTL ? canShrink : canGrow); |
| 236 canDragRight_ = |
| 237 (withDelta >= initialDragPoint_.x) && (isRTL ? canGrow : canShrink); |
| 238 if ((dX < 0.0 && !canDragLeft_) || (dX > 0.0 && !canDragRight_) || |
| 239 fabs(dX) < FLT_EPSILON) |
227 return; | 240 return; |
228 | 241 |
229 if (NSWidth(containerFrame) <= kMinimumContainerWidth) | 242 grippyPinned_ = newWidth >= maxAllowedWidth; |
230 return; | 243 if (!isRTL) |
231 | 244 containerFrame.origin.x += dX; |
232 grippyPinned_ = NSWidth(containerFrame) >= maxAllowedWidth; | 245 containerFrame.size.width = newWidth; |
233 containerFrame.origin.x += dX; | |
234 | 246 |
235 [self setFrame:containerFrame]; | 247 [self setFrame:containerFrame]; |
236 [self setNeedsDisplay:YES]; | 248 [self setNeedsDisplay:YES]; |
237 | 249 |
238 [[NSNotificationCenter defaultCenter] | 250 [[NSNotificationCenter defaultCenter] |
239 postNotificationName:kBrowserActionGrippyDraggingNotification | 251 postNotificationName:kBrowserActionGrippyDraggingNotification |
240 object:self]; | 252 object:self]; |
241 } | 253 } |
242 | 254 |
243 - (void)animationDidEnd:(NSAnimation*)animation { | 255 - (void)animationDidEnd:(NSAnimation*)animation { |
(...skipping 20 matching lines...) Expand all Loading... |
264 | 276 |
265 - (ViewID)viewID { | 277 - (ViewID)viewID { |
266 return VIEW_ID_BROWSER_ACTION_TOOLBAR; | 278 return VIEW_ID_BROWSER_ACTION_TOOLBAR; |
267 } | 279 } |
268 | 280 |
269 #pragma mark - | 281 #pragma mark - |
270 #pragma mark Public Methods | 282 #pragma mark Public Methods |
271 | 283 |
272 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { | 284 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate { |
273 width = std::max(width, kMinimumContainerWidth); | 285 width = std::max(width, kMinimumContainerWidth); |
274 NSRect frame = [self frame]; | 286 NSRect newFrame = [self frame]; |
275 | 287 |
276 CGFloat maxAllowedWidth = [self maxAllowedWidth]; | 288 CGFloat maxAllowedWidth = [self maxAllowedWidth]; |
277 width = std::min(maxAllowedWidth, width); | 289 width = std::min(maxAllowedWidth, width); |
278 | 290 |
279 CGFloat dX = frame.size.width - width; | 291 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { |
280 frame.size.width = width; | 292 newFrame.size.width = width; |
281 NSRect newFrame = NSOffsetRect(frame, dX, 0); | 293 } else { |
| 294 CGFloat dX = NSWidth(newFrame) - width; |
| 295 newFrame.size.width = width; |
| 296 newFrame.origin.x += dX; |
| 297 } |
282 | 298 |
283 grippyPinned_ = width == maxAllowedWidth; | 299 grippyPinned_ = width == maxAllowedWidth; |
284 | 300 |
285 [self stopAnimation]; | 301 [self stopAnimation]; |
286 | 302 |
287 if (animate) { | 303 if (animate) { |
288 NSDictionary* animationDictionary = @{ | 304 NSDictionary* animationDictionary = @{ |
289 NSViewAnimationTargetKey : self, | 305 NSViewAnimationTargetKey : self, |
290 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], | 306 NSViewAnimationStartFrameKey : [NSValue valueWithRect:[self frame]], |
291 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] | 307 NSViewAnimationEndFrameKey : [NSValue valueWithRect:newFrame] |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 retVal = [NSCursor resizeLeftRightCursor]; | 354 retVal = [NSCursor resizeLeftRightCursor]; |
339 } | 355 } |
340 return retVal; | 356 return retVal; |
341 } | 357 } |
342 | 358 |
343 - (CGFloat)maxAllowedWidth { | 359 - (CGFloat)maxAllowedWidth { |
344 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; | 360 return delegate_ ? delegate_->GetMaxAllowedWidth() : CGFLOAT_MAX; |
345 } | 361 } |
346 | 362 |
347 @end | 363 @end |
OLD | NEW |