Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
Avi (use Gerrit)
2012/04/28 16:55:37
year
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h" | |
| 6 | |
| 7 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | |
| 8 #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" | |
| 9 | |
| 10 #pragma mark TranslateInfoBarUtilities helper functions. | |
|
Avi (use Gerrit)
2012/04/28 16:55:37
Useless; remove.
| |
| 11 | |
| 12 namespace InfoBarUtilities { | |
| 13 | |
| 14 // Move the |toMove| view |spacing| pixels before/after the |anchor| view. | |
| 15 // |after| signifies the side of |anchor| on which to place |toMove|. | |
| 16 void MoveControl(NSView* anchor, NSView* toMove, int spacing, bool after) { | |
| 17 NSRect anchorFrame = [anchor frame]; | |
| 18 NSRect toMoveFrame = [toMove frame]; | |
| 19 | |
| 20 // At the time of this writing, OS X doesn't natively support BiDi UIs, but | |
| 21 // it doesn't hurt to be forward looking. | |
| 22 bool toRight = after; | |
| 23 | |
| 24 if (toRight) { | |
| 25 toMoveFrame.origin.x = NSMaxX(anchorFrame) + spacing; | |
| 26 } else { | |
| 27 // Place toMove to theleft of anchor. | |
| 28 toMoveFrame.origin.x = NSMinX(anchorFrame) - | |
| 29 spacing - NSWidth(toMoveFrame); | |
| 30 } | |
| 31 [toMove setFrame:toMoveFrame]; | |
| 32 } | |
| 33 | |
| 34 // Check that the control |before| is ordered visually before the |after| | |
| 35 // control. | |
| 36 // Also, check that there is space between them. | |
| 37 bool VerifyControlOrderAndSpacing(id before, id after) { | |
| 38 NSRect beforeFrame = [before frame]; | |
| 39 NSRect afterFrame = [after frame]; | |
| 40 return NSMinX(afterFrame) >= NSMaxX(beforeFrame); | |
| 41 } | |
| 42 | |
| 43 // Vertically center |toMove| in its container. | |
| 44 void VerticallyCenterView(NSView* toMove) { | |
| 45 NSRect superViewFrame = [[toMove superview] frame]; | |
| 46 NSRect viewFrame = [toMove frame]; | |
| 47 // If the superview is the infobar view, then subtract out the anti-spoof | |
| 48 // height so that the content is centered in the content area of the infobar, | |
| 49 // rather than in the total height (which includes the bulge). | |
| 50 CGFloat superHeight = NSHeight(superViewFrame); | |
| 51 if ([[toMove superview] isKindOfClass:[InfoBarGradientView class]]) | |
| 52 superHeight = infobars::kBaseHeight; | |
| 53 viewFrame.origin.y = | |
| 54 floor((superHeight - NSHeight(viewFrame)) / 2.0); | |
| 55 [toMove setFrame:viewFrame]; | |
| 56 } | |
| 57 | |
| 58 // Creates a label control in the style we need for the infobar's labels | |
| 59 // within |bounds|. | |
| 60 NSTextField* CreateLabel(NSRect bounds) { | |
| 61 NSTextField* ret = [[NSTextField alloc] initWithFrame:bounds]; | |
| 62 [ret setEditable:NO]; | |
| 63 [ret setDrawsBackground:NO]; | |
| 64 [ret setBordered:NO]; | |
| 65 return ret; | |
| 66 } | |
| 67 | |
| 68 // Adds an item with the specified properties to |menu|. | |
| 69 void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title, | |
| 70 int tag, bool enabled, bool checked) { | |
| 71 if (tag == -1) { | |
| 72 [menu addItem:[NSMenuItem separatorItem]]; | |
| 73 } else { | |
| 74 NSMenuItem* item = [[[NSMenuItem alloc] | |
| 75 initWithTitle:title | |
| 76 action:selector | |
| 77 keyEquivalent:@""] autorelease]; | |
|
Avi (use Gerrit)
2012/04/28 16:55:37
scoped_nsobject instead.
| |
| 78 [item setTag:tag]; | |
| 79 [menu addItem:item]; | |
| 80 [item setTarget:target]; | |
| 81 if (checked) | |
| 82 [item setState:NSOnState]; | |
| 83 if (!enabled) | |
| 84 [item setEnabled:NO]; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 } // namespace InfoBarUtilities | |
| OLD | NEW |