Chromium Code Reviews| Index: chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm |
| diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm |
| index cef8922a99346c86f774063d5656190433dc4343..625c28f59a5d92cc581b0bb90ede7e8a5ab4595a 100644 |
| --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm |
| +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm |
| @@ -4,8 +4,6 @@ |
| #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" |
|
Avi (use Gerrit)
2012/04/28 16:55:37
You sure we don't need this any more?
|
| -#import <Cocoa/Cocoa.h> |
| - |
| #include "base/logging.h" |
| #include "base/metrics/histogram.h" |
| #include "base/sys_string_conversions.h" |
| @@ -18,121 +16,42 @@ |
| #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" |
| #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" |
| +#import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h" |
| #include "chrome/browser/ui/cocoa/infobars/translate_message_infobar_controller.h" |
| #include "grit/generated_resources.h" |
| #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| #include "ui/base/l10n/l10n_util.h" |
| -using TranslateInfoBarUtilities::MoveControl; |
| -using TranslateInfoBarUtilities::VerticallyCenterView; |
| -using TranslateInfoBarUtilities::VerifyControlOrderAndSpacing; |
| -using TranslateInfoBarUtilities::CreateLabel; |
| -using TranslateInfoBarUtilities::AddMenuItem; |
| - |
| -#pragma mark TranslateInfoBarUtilities helper functions. |
| - |
| -namespace TranslateInfoBarUtilities { |
| - |
| -// Move the |toMove| view |spacing| pixels before/after the |anchor| view. |
| -// |after| signifies the side of |anchor| on which to place |toMove|. |
| -void MoveControl(NSView* anchor, NSView* toMove, int spacing, bool after) { |
| - NSRect anchorFrame = [anchor frame]; |
| - NSRect toMoveFrame = [toMove frame]; |
| - |
| - // At the time of this writing, OS X doesn't natively support BiDi UIs, but |
| - // it doesn't hurt to be forward looking. |
| - bool toRight = after; |
| - |
| - if (toRight) { |
| - toMoveFrame.origin.x = NSMaxX(anchorFrame) + spacing; |
| - } else { |
| - // Place toMove to theleft of anchor. |
| - toMoveFrame.origin.x = NSMinX(anchorFrame) - |
| - spacing - NSWidth(toMoveFrame); |
| - } |
| - [toMove setFrame:toMoveFrame]; |
| -} |
| - |
| -// Check that the control |before| is ordered visually before the |after| |
| -// control. |
| -// Also, check that there is space between them. |
| -bool VerifyControlOrderAndSpacing(id before, id after) { |
| - NSRect beforeFrame = [before frame]; |
| - NSRect afterFrame = [after frame]; |
| - return NSMinX(afterFrame) >= NSMaxX(beforeFrame); |
| -} |
| - |
| -// Vertically center |toMove| in its container. |
| -void VerticallyCenterView(NSView* toMove) { |
| - NSRect superViewFrame = [[toMove superview] frame]; |
| - NSRect viewFrame = [toMove frame]; |
| - // If the superview is the infobar view, then subtract out the anti-spoof |
| - // height so that the content is centered in the content area of the infobar, |
| - // rather than in the total height (which includes the bulge). |
| - CGFloat superHeight = NSHeight(superViewFrame); |
| - if ([[toMove superview] isKindOfClass:[InfoBarGradientView class]]) |
| - superHeight = infobars::kBaseHeight; |
| - viewFrame.origin.y = |
| - floor((superHeight - NSHeight(viewFrame)) / 2.0); |
| - [toMove setFrame:viewFrame]; |
| -} |
| - |
| -// Creates a label control in the style we need for the translate infobar's |
| -// labels within |bounds|. |
| -NSTextField* CreateLabel(NSRect bounds) { |
| - NSTextField* ret = [[NSTextField alloc] initWithFrame:bounds]; |
| - [ret setEditable:NO]; |
| - [ret setDrawsBackground:NO]; |
| - [ret setBordered:NO]; |
| - return ret; |
| -} |
| - |
| -// Adds an item with the specified properties to |menu|. |
| -void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title, |
| - int tag, bool enabled, bool checked) { |
| - if (tag == -1) { |
| - [menu addItem:[NSMenuItem separatorItem]]; |
| - } else { |
| - NSMenuItem* item = [[[NSMenuItem alloc] |
| - initWithTitle:title |
| - action:selector |
| - keyEquivalent:@""] autorelease]; |
| - [item setTag:tag]; |
| - [menu addItem:item]; |
| - [item setTarget:target]; |
| - if (checked) |
| - [item setState:NSOnState]; |
| - if (!enabled) |
| - [item setEnabled:NO]; |
| - } |
| -} |
| - |
| -} // namespace TranslateInfoBarUtilities |
| +using InfoBarUtilities::MoveControl; |
| +using InfoBarUtilities::VerticallyCenterView; |
| +using InfoBarUtilities::VerifyControlOrderAndSpacing; |
| +using InfoBarUtilities::CreateLabel; |
| +using InfoBarUtilities::AddMenuItem; |
| // TranslateInfoBarDelegate views specific method: |
| InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* owner) { |
| - TranslateInfoBarControllerBase* infobar_controller = NULL; |
| + TranslateInfoBarControllerBase* infobarController = NULL; |
|
Avi (use Gerrit)
2012/04/28 16:55:37
No. Variable styles are set by the type of code th
|
| switch (type_) { |
| case BEFORE_TRANSLATE: |
| - infobar_controller = |
| + infobarController = |
| [[BeforeTranslateInfobarController alloc] initWithDelegate:this |
| owner:owner]; |
| break; |
| case AFTER_TRANSLATE: |
| - infobar_controller = |
| + infobarController = |
| [[AfterTranslateInfobarController alloc] initWithDelegate:this |
| owner:owner]; |
| break; |
| case TRANSLATING: |
| case TRANSLATION_ERROR: |
| - infobar_controller = |
| + infobarController = |
| [[TranslateMessageInfobarController alloc] initWithDelegate:this |
| owner:owner]; |
| break; |
| default: |
| NOTREACHED(); |
| } |
| - return new InfoBar(infobar_controller, this); |
| + return new InfoBar(infobarController, this); |
| } |
| @implementation TranslateInfoBarControllerBase (FrameChangeObserver) |