summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/translate
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 16:34:49 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 16:34:49 +0000
commit7d791652c7ede4209a2014d885148e2713f49bce (patch)
treec26baf12593bed381c631b81c736106809d46b44 /chrome/browser/cocoa/translate
parent3b94427c99bdf12836fd455eeb1499fdde511e26 (diff)
downloadchromium_src-7d791652c7ede4209a2014d885148e2713f49bce.zip
chromium_src-7d791652c7ede4209a2014d885148e2713f49bce.tar.gz
chromium_src-7d791652c7ede4209a2014d885148e2713f49bce.tar.bz2
Move browser/cocoa to browser/ui/cocoa
BUG=none TEST=none TBR=brettw git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/translate')
-rw-r--r--chrome/browser/cocoa/translate/after_translate_infobar_controller.h11
-rw-r--r--chrome/browser/cocoa/translate/after_translate_infobar_controller.mm60
-rw-r--r--chrome/browser/cocoa/translate/before_translate_infobar_controller.h23
-rw-r--r--chrome/browser/cocoa/translate/before_translate_infobar_controller.mm123
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_base.h163
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_base.mm642
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_unittest.mm254
-rw-r--r--chrome/browser/cocoa/translate/translate_message_infobar_controller.h10
-rw-r--r--chrome/browser/cocoa/translate/translate_message_infobar_controller.mm53
9 files changed, 0 insertions, 1339 deletions
diff --git a/chrome/browser/cocoa/translate/after_translate_infobar_controller.h b/chrome/browser/cocoa/translate/after_translate_infobar_controller.h
deleted file mode 100644
index ba946c9..0000000
--- a/chrome/browser/cocoa/translate/after_translate_infobar_controller.h
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "chrome/browser/cocoa/translate/translate_infobar_base.h"
-
-@interface AfterTranslateInfobarController : TranslateInfoBarControllerBase {
- bool swappedLanugageButtons_;
-}
-
-@end
diff --git a/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm b/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm
deleted file mode 100644
index 7e01146..0000000
--- a/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/cocoa/translate/after_translate_infobar_controller.h"
-#include "base/sys_string_conversions.h"
-
-using TranslateInfoBarUtilities::MoveControl;
-using TranslateInfoBarUtilities::VerifyControlOrderAndSpacing;
-
-@implementation AfterTranslateInfobarController
-
-- (void)loadLabelText {
- std::vector<string16> strings;
- TranslateInfoBarDelegate::GetAfterTranslateStrings(
- &strings, &swappedLanugageButtons_);
- DCHECK(strings.size() == 3U);
- NSString* string1 = base::SysUTF16ToNSString(strings[0]);
- NSString* string2 = base::SysUTF16ToNSString(strings[1]);
- NSString* string3 = base::SysUTF16ToNSString(strings[2]);
-
- [label1_ setStringValue:string1];
- [label2_ setStringValue:string2];
- [label3_ setStringValue:string3];
-}
-
-- (void)layout {
- [self removeOkCancelButtons];
- [optionsPopUp_ setHidden:NO];
- NSView* firstPopup = fromLanguagePopUp_;
- NSView* lastPopup = toLanguagePopUp_;
- if (swappedLanugageButtons_) {
- firstPopup = toLanguagePopUp_;
- lastPopup = fromLanguagePopUp_;
- }
- NSView* lastControl = lastPopup;
-
- MoveControl(label1_, firstPopup, spaceBetweenControls_ / 2, true);
- MoveControl(firstPopup, label2_, spaceBetweenControls_ / 2, true);
- MoveControl(label2_, lastPopup, spaceBetweenControls_ / 2, true);
- MoveControl(lastPopup, label3_, 0, true);
- lastControl = label3_;
-
- MoveControl(lastControl, showOriginalButton_, spaceBetweenControls_ * 2,
- true);
-}
-
-- (NSArray*)visibleControls {
- return [NSArray arrayWithObjects:label1_.get(), fromLanguagePopUp_.get(),
- label2_.get(), toLanguagePopUp_.get(), label3_.get(),
- showOriginalButton_.get(), nil];
-}
-
-- (bool)verifyLayout {
- if ([optionsPopUp_ isHidden])
- return false;
- return [super verifyLayout];
-}
-
-@end
diff --git a/chrome/browser/cocoa/translate/before_translate_infobar_controller.h b/chrome/browser/cocoa/translate/before_translate_infobar_controller.h
deleted file mode 100644
index ff54daa..0000000
--- a/chrome/browser/cocoa/translate/before_translate_infobar_controller.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "chrome/browser/cocoa/translate/translate_infobar_base.h"
-
-@interface BeforeTranslateInfobarController : TranslateInfoBarControllerBase {
- scoped_nsobject<NSButton> alwaysTranslateButton_;
- scoped_nsobject<NSButton> neverTranslateButton_;
-}
-
-// Creates and initializes the alwaysTranslate and neverTranslate buttons.
-- (void)initializeExtraControls;
-
-@end
-
-@interface BeforeTranslateInfobarController (TestingAPI)
-
-- (NSButton*)alwaysTranslateButton;
-- (NSButton*)neverTranslateButton;
-
-@end
-
diff --git a/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm b/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm
deleted file mode 100644
index baa0eef..0000000
--- a/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/cocoa/translate/before_translate_infobar_controller.h"
-
-#include "app/l10n_util.h"
-#include "base/sys_string_conversions.h"
-#include "grit/generated_resources.h"
-
-using TranslateInfoBarUtilities::MoveControl;
-using TranslateInfoBarUtilities::VerifyControlOrderAndSpacing;
-
-namespace {
-
-NSButton* CreateNSButtonWithResourceIDAndParameter(
- int resourceId, const string16& param) {
- string16 title = l10n_util::GetStringFUTF16(resourceId, param);
- NSButton* button = [[NSButton alloc] init];
- [button setTitle:base::SysUTF16ToNSString(title)];
- [button setBezelStyle:NSTexturedRoundedBezelStyle];
- return button;
-}
-
-} // namespace
-
-@implementation BeforeTranslateInfobarController
-
-- (id) initWithDelegate:(InfoBarDelegate *)delegate {
- if ((self = [super initWithDelegate:delegate])) {
- [self initializeExtraControls];
- }
- return self;
-}
-
-- (void)initializeExtraControls {
- TranslateInfoBarDelegate* delegate = [self delegate];
- const string16& language = delegate->GetLanguageDisplayableNameAt(
- delegate->original_language_index());
- neverTranslateButton_.reset(
- CreateNSButtonWithResourceIDAndParameter(
- IDS_TRANSLATE_INFOBAR_NEVER_TRANSLATE, language));
- [neverTranslateButton_ setTarget:self];
- [neverTranslateButton_ setAction:@selector(neverTranslate:)];
-
- alwaysTranslateButton_.reset(
- CreateNSButtonWithResourceIDAndParameter(
- IDS_TRANSLATE_INFOBAR_ALWAYS_TRANSLATE, language));
- [alwaysTranslateButton_ setTarget:self];
- [alwaysTranslateButton_ setAction:@selector(alwaysTranslate:)];
-}
-
-- (void)layout {
- MoveControl(label1_, fromLanguagePopUp_, spaceBetweenControls_ / 2, true);
- MoveControl(fromLanguagePopUp_, label2_, spaceBetweenControls_, true);
- MoveControl(label2_, okButton_, spaceBetweenControls_, true);
- MoveControl(okButton_, cancelButton_, spaceBetweenControls_, true);
- NSView* lastControl = cancelButton_;
- if (neverTranslateButton_.get()) {
- MoveControl(lastControl, neverTranslateButton_.get(),
- spaceBetweenControls_, true);
- lastControl = neverTranslateButton_.get();
- }
- if (alwaysTranslateButton_.get()) {
- MoveControl(lastControl, alwaysTranslateButton_.get(),
- spaceBetweenControls_, true);
- }
-}
-
-- (void)loadLabelText {
- size_t offset = 0;
- string16 text =
- l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE,
- string16(), &offset);
- NSString* string1 = base::SysUTF16ToNSString(text.substr(0, offset));
- NSString* string2 = base::SysUTF16ToNSString(text.substr(offset));
- [label1_ setStringValue:string1];
- [label2_ setStringValue:string2];
- [label3_ setStringValue:@""];
-}
-
-- (NSArray*)visibleControls {
- NSMutableArray* visibleControls = [NSMutableArray arrayWithObjects:
- label1_.get(), fromLanguagePopUp_.get(), label2_.get(),
- okButton_, cancelButton_, nil];
-
- if ([self delegate]->ShouldShowNeverTranslateButton())
- [visibleControls addObject:neverTranslateButton_.get()];
-
- if ([self delegate]->ShouldShowAlwaysTranslateButton())
- [visibleControls addObject:alwaysTranslateButton_.get()];
-
- return visibleControls;
-}
-
-// This is called when the "Never Translate [language]" button is pressed.
-- (void)neverTranslate:(id)sender {
- [self delegate]->NeverTranslatePageLanguage();
-}
-
-// This is called when the "Always Translate [language]" button is pressed.
-- (void)alwaysTranslate:(id)sender {
- [self delegate]->AlwaysTranslatePageLanguage();
-}
-
-- (bool)verifyLayout {
- if ([optionsPopUp_ isHidden])
- return false;
- return [super verifyLayout];
-}
-
-@end
-
-@implementation BeforeTranslateInfobarController (TestingAPI)
-
-- (NSButton*)alwaysTranslateButton {
- return alwaysTranslateButton_.get();
-}
-- (NSButton*)neverTranslateButton {
- return neverTranslateButton_.get();
-}
-
-@end
diff --git a/chrome/browser/cocoa/translate/translate_infobar_base.h b/chrome/browser/cocoa/translate/translate_infobar_base.h
deleted file mode 100644
index b23250f..0000000
--- a/chrome/browser/cocoa/translate/translate_infobar_base.h
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_COCOA_TRANSLATE_INFOBAR_BASE_H_
-#define CHROME_BROWSER_COCOA_TRANSLATE_INFOBAR_BASE_H_
-#pragma once
-
-#import <Cocoa/Cocoa.h>
-#import "chrome/browser/cocoa/infobar_controller.h"
-
-#import "base/cocoa_protocols_mac.h"
-#import "base/scoped_nsobject.h"
-#include "base/scoped_ptr.h"
-#include "chrome/browser/translate/languages_menu_model.h"
-#include "chrome/browser/translate/options_menu_model.h"
-#include "chrome/browser/translate/translate_infobar_delegate.h"
-#include "chrome/common/translate_errors.h"
-
-class TranslateInfoBarMenuModel;
-
-#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);
-
-// Vertically center |toMove| in its container.
-void VerticallyCenterView(NSView *toMove);
-// 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);
-
-// Creates a label control in the style we need for the translate infobar's
-// labels within |bounds|.
-NSTextField* CreateLabel(NSRect bounds);
-
-// 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);
-
-} // namespace
-
-// The base class for the three translate infobars. This class does all of the
-// heavy UI lifting, while deferring to the subclass to tell it what views
-// should be shown and where. Subclasses need to implement:
-// - (void)layout;
-// - (void)loadLabelText;
-// - (void)visibleControls;
-// - (bool)verifyLayout; // For testing.
-@interface TranslateInfoBarControllerBase : InfoBarController<NSMenuDelegate> {
- @protected
- scoped_nsobject<NSTextField> label1_;
- scoped_nsobject<NSTextField> label2_;
- scoped_nsobject<NSTextField> label3_;
- scoped_nsobject<NSPopUpButton> fromLanguagePopUp_;
- scoped_nsobject<NSPopUpButton> toLanguagePopUp_;
- scoped_nsobject<NSPopUpButton> optionsPopUp_;
- scoped_nsobject<NSButton> showOriginalButton_;
- // This is the button used in the translate message infobar. It can either be
- // a "Try Again" button, or a "Show Original" button in the case that the
- // page was translated from an unknown language.
- scoped_nsobject<NSButton> translateMessageButton_;
-
- // In the current locale, are the "from" and "to" language popup menu
- // flipped from what they'd appear in English.
- bool swappedLanguagePlaceholders_;
-
- // Space between controls in pixels - read from the NIB.
- CGFloat spaceBetweenControls_;
-
- scoped_ptr<LanguagesMenuModel> originalLanguageMenuModel_;
- scoped_ptr<LanguagesMenuModel> targetLanguageMenuModel_;
- scoped_ptr<OptionsMenuModel> optionsMenuModel_;
-}
-
-// Returns the delegate as a TranslateInfoBarDelegate.
-- (TranslateInfoBarDelegate*)delegate;
-
-// Called when the "Show Original" button is pressed.
-- (IBAction)showOriginal:(id)sender;
-
-@end
-
-@interface TranslateInfoBarControllerBase (ProtectedAPI)
-
-// Resizes or hides the options button based on how much space is available
-// so that it doesn't overlap other buttons.
-// lastView is the rightmost view, the first one that the options button
-// would overlap with.
-- (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView;
-
-// Move all the currently visible views into the correct place for the
-// current mode.
-// Must be implemented by the subclass.
-- (void)layout;
-
-// Loads the text for the 3 labels. There is only one message, but since
-// it has controls separating parts of it, it is separated into 3 separate
-// labels.
-// Must be implemented by the subclass.
-- (void)loadLabelText;
-
-// Returns the controls that are visible in the subclasses infobar. The
-// default implementation returns an empty array. The controls should
-// be returned in the order they are displayed, otherwise the layout test
-// will fail.
-// Must be implemented by the subclass.
-- (NSArray*)visibleControls;
-
-// Shows the array of controls provided by the subclass.
-- (void)showVisibleControls:(NSArray*)visibleControls;
-
-// Hides the OK and Cancel buttons.
-- (void)removeOkCancelButtons;
-
-// Called when the source or target language selection changes in a menu.
-// |newLanguageIdx| is the index of the newly selected item in the appropriate
-// menu.
-- (void)sourceLanguageModified:(NSInteger)newLanguageIdx;
-- (void)targetLanguageModified:(NSInteger)newLanguageIdx;
-
-// Called when an item in one of the toolbar's language or options
-// menus is selected.
-- (void)languageMenuChanged:(id)item;
-- (void)optionsMenuChanged:(id)item;
-
-// Teardown and rebuild the options menu. When the infobar is small, the
-// options menu is shrunk to just a drop down arrow, so the title needs
-// to be empty.
-- (void)rebuildOptionsMenu:(BOOL)hideTitle;
-
-// Whether or not this infobar should show the options popup.
-- (BOOL)shouldShowOptionsPopUp;
-
-@end // TranslateInfoBarControllerBase (ProtectedAPI)
-
-#pragma mark TestingAPI
-
-@interface TranslateInfoBarControllerBase (TestingAPI)
-
-// All the controls used in any of the translate states.
-// This is used for verifying layout and for setting the
-// correct styles on each button.
-- (NSArray*)allControls;
-
-// Verifies that the layout of the infobar is correct.
-// Must be implmented by the subclass.
-- (bool)verifyLayout;
-
-// Returns the underlying options menu.
-- (NSMenu*)optionsMenu;
-
-// Returns |translateMessageButton_|, see declaration of member
-// variable for a full description.
-- (NSButton*)translateMessageButton;
-
-@end // TranslateInfoBarControllerBase (TestingAPI)
-
-
-#endif // CHROME_BROWSER_COCOA_TRANSLATE_INFOBAR_BASE_H_
diff --git a/chrome/browser/cocoa/translate/translate_infobar_base.mm b/chrome/browser/cocoa/translate/translate_infobar_base.mm
deleted file mode 100644
index 48ce514..0000000
--- a/chrome/browser/cocoa/translate/translate_infobar_base.mm
+++ /dev/null
@@ -1,642 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import <Cocoa/Cocoa.h>
-#import "chrome/browser/cocoa/translate/translate_infobar_base.h"
-
-#include "app/l10n_util.h"
-#include "base/logging.h"
-#include "base/mac_util.h"
-#include "base/metrics/histogram.h"
-#include "base/sys_string_conversions.h"
-#include "chrome/app/chrome_command_ids.h"
-#import "chrome/browser/cocoa/hover_close_button.h"
-#include "chrome/browser/cocoa/infobar.h"
-#import "chrome/browser/cocoa/infobar_controller.h"
-#import "chrome/browser/cocoa/infobar_gradient_view.h"
-#include "chrome/browser/cocoa/translate/after_translate_infobar_controller.h"
-#import "chrome/browser/cocoa/translate/before_translate_infobar_controller.h"
-#include "chrome/browser/cocoa/translate/translate_message_infobar_controller.h"
-#include "chrome/browser/translate/translate_infobar_delegate.h"
-#include "grit/generated_resources.h"
-#include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.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];
- viewFrame.origin.y =
- floor((NSHeight(superViewFrame) - 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
-
-// TranslateInfoBarDelegate views specific method:
-InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
- TranslateInfoBarControllerBase* infobar_controller = NULL;
- switch (type_) {
- case BEFORE_TRANSLATE:
- infobar_controller =
- [[BeforeTranslateInfobarController alloc] initWithDelegate:this];
- break;
- case AFTER_TRANSLATE:
- infobar_controller =
- [[AfterTranslateInfobarController alloc] initWithDelegate:this];
- break;
- case TRANSLATING:
- case TRANSLATION_ERROR:
- infobar_controller =
- [[TranslateMessageInfobarController alloc] initWithDelegate:this];
- break;
- default:
- NOTREACHED();
- }
- return new InfoBar(infobar_controller);
-}
-
-@implementation TranslateInfoBarControllerBase (FrameChangeObserver)
-
-// Triggered when the frame changes. This will figure out what size and
-// visibility the options popup should be.
-- (void)didChangeFrame:(NSNotification*)notification {
- [self adjustOptionsButtonSizeAndVisibilityForView:
- [[self visibleControls] lastObject]];
-}
-
-@end
-
-
-@interface TranslateInfoBarControllerBase (Private)
-
-// Removes all controls so that layout can add in only the controls
-// required.
-- (void)clearAllControls;
-
-// Create all the various controls we need for the toolbar.
-- (void)constructViews;
-
-// Reloads text for all labels for the current state.
-- (void)loadLabelText:(TranslateErrors::Type)error;
-
-// Set the infobar background gradient.
-- (void)setInfoBarGradientColor;
-
-// Main function to update the toolbar graphic state and data model after
-// the state has changed.
-// Controls are moved around as needed and visibility changed to match the
-// current state.
-- (void)updateState;
-
-// Called when the source or target language selection changes in a menu.
-// |newLanguageIdx| is the index of the newly selected item in the appropriate
-// menu.
-- (void)sourceLanguageModified:(NSInteger)newLanguageIdx;
-- (void)targetLanguageModified:(NSInteger)newLanguageIdx;
-
-// Completely rebuild "from" and "to" language menus from the data model.
-- (void)populateLanguageMenus;
-
-@end
-
-#pragma mark TranslateInfoBarController class
-
-@implementation TranslateInfoBarControllerBase
-
-- (id)initWithDelegate:(InfoBarDelegate*)delegate {
- if ((self = [super initWithDelegate:delegate])) {
- originalLanguageMenuModel_.reset(
- new LanguagesMenuModel([self delegate],
- LanguagesMenuModel::ORIGINAL));
-
- targetLanguageMenuModel_.reset(
- new LanguagesMenuModel([self delegate],
- LanguagesMenuModel::TARGET));
- }
- return self;
-}
-
-- (TranslateInfoBarDelegate*)delegate {
- return reinterpret_cast<TranslateInfoBarDelegate*>(delegate_);
-}
-
-- (void)constructViews {
- // Using a zero or very large frame causes GTMUILocalizerAndLayoutTweaker
- // to not resize the view properly so we take the bounds of the first label
- // which is contained in the nib.
- NSRect bogusFrame = [label_ frame];
- label1_.reset(CreateLabel(bogusFrame));
- label2_.reset(CreateLabel(bogusFrame));
- label3_.reset(CreateLabel(bogusFrame));
-
- optionsPopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame
- pullsDown:YES]);
- fromLanguagePopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame
- pullsDown:NO]);
- toLanguagePopUp_.reset([[NSPopUpButton alloc] initWithFrame:bogusFrame
- pullsDown:NO]);
- showOriginalButton_.reset([[NSButton alloc] init]);
- translateMessageButton_.reset([[NSButton alloc] init]);
-}
-
-- (void)sourceLanguageModified:(NSInteger)newLanguageIdx {
- DCHECK_GT(newLanguageIdx, -1);
- if (newLanguageIdx == [self delegate]->original_language_index())
- return;
- [self delegate]->SetOriginalLanguage(newLanguageIdx);
- int commandId = IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE + newLanguageIdx;
- int newMenuIdx = [fromLanguagePopUp_ indexOfItemWithTag:commandId];
- [fromLanguagePopUp_ selectItemAtIndex:newMenuIdx];
-}
-
-- (void)targetLanguageModified:(NSInteger)newLanguageIdx {
- DCHECK_GT(newLanguageIdx, -1);
- if (newLanguageIdx == [self delegate]->target_language_index())
- return;
- [self delegate]->SetTargetLanguage(newLanguageIdx);
- int commandId = IDC_TRANSLATE_TARGET_LANGUAGE_BASE + newLanguageIdx;
- int newMenuIdx = [toLanguagePopUp_ indexOfItemWithTag:commandId];
- [toLanguagePopUp_ selectItemAtIndex:newMenuIdx];
-}
-
-- (void)loadLabelText {
- // Do nothing by default, should be implemented by subclasses.
-}
-
-- (void)updateState {
- [self loadLabelText];
- [self clearAllControls];
- [self showVisibleControls:[self visibleControls]];
- [optionsPopUp_ setHidden:![self shouldShowOptionsPopUp]];
- [self layout];
- [self adjustOptionsButtonSizeAndVisibilityForView:
- [[self visibleControls] lastObject]];
-}
-
-- (void)setInfoBarGradientColor {
- NSColor* startingColor = [NSColor colorWithCalibratedWhite:0.93 alpha:1.0];
- NSColor* endingColor = [NSColor colorWithCalibratedWhite:0.85 alpha:1.0];
- NSGradient* translateInfoBarGradient =
- [[[NSGradient alloc] initWithStartingColor:startingColor
- endingColor:endingColor] autorelease];
-
- [infoBarView_ setGradient:translateInfoBarGradient];
- [infoBarView_
- setStrokeColor:[NSColor colorWithCalibratedWhite:0.75 alpha:1.0]];
-}
-
-- (void)removeOkCancelButtons {
- // Removing okButton_ & cancelButton_ from the view may cause them
- // to be released and since we can still access them from other areas
- // in the code later, we need them to be nil when this happens.
- [okButton_ removeFromSuperview];
- okButton_ = nil;
- [cancelButton_ removeFromSuperview];
- cancelButton_ = nil;
-}
-
-- (void)clearAllControls {
- // Step 1: remove all controls from the infobar so we have a clean slate.
- NSArray *allControls = [self allControls];
-
- for (NSControl* control in allControls) {
- if ([control superview])
- [control removeFromSuperview];
- }
-}
-
-- (void)showVisibleControls:(NSArray*)visibleControls {
- NSRect optionsFrame = [optionsPopUp_ frame];
- for (NSControl* control in visibleControls) {
- [GTMUILocalizerAndLayoutTweaker sizeToFitView:control];
- [control setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin |
- NSViewMaxYMargin];
-
- // Need to check if a view is already attached since |label1_| is always
- // parented and we don't want to add it again.
- if (![control superview])
- [infoBarView_ addSubview:control];
-
- if ([control isKindOfClass:[NSButton class]])
- VerticallyCenterView(control);
-
- // Make "from" and "to" language popup menus the same size as the options
- // menu.
- // We don't autosize since some languages names are really long causing
- // the toolbar to overflow.
- if ([control isKindOfClass:[NSPopUpButton class]])
- [control setFrame:optionsFrame];
- }
-}
-
-- (void)layout {
-
-}
-
-- (NSArray*)visibleControls {
- return [NSArray array];
-}
-
-- (void)rebuildOptionsMenu:(BOOL)hideTitle {
- if (![self shouldShowOptionsPopUp])
- return;
-
- // The options model doesn't know how to handle state transitions, so rebuild
- // it each time through here.
- optionsMenuModel_.reset(
- new OptionsMenuModel([self delegate]));
-
- [optionsPopUp_ removeAllItems];
- // Set title.
- NSString* optionsLabel = hideTitle ? @"" :
- l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_OPTIONS);
- [optionsPopUp_ addItemWithTitle:optionsLabel];
-
- // Populate options menu.
- NSMenu* optionsMenu = [optionsPopUp_ menu];
- [optionsMenu setAutoenablesItems:NO];
- for (int i = 0; i < optionsMenuModel_->GetItemCount(); ++i) {
- NSString* title = base::SysUTF16ToNSString(
- optionsMenuModel_->GetLabelAt(i));
- int cmd = optionsMenuModel_->GetCommandIdAt(i);
- bool checked = optionsMenuModel_->IsItemCheckedAt(i);
- bool enabled = optionsMenuModel_->IsEnabledAt(i);
- AddMenuItem(optionsMenu,
- self,
- @selector(optionsMenuChanged:),
- title,
- cmd,
- enabled,
- checked);
- }
-}
-
-- (BOOL)shouldShowOptionsPopUp {
- return YES;
-}
-
-- (void)populateLanguageMenus {
- NSMenu* originalLanguageMenu = [fromLanguagePopUp_ menu];
- [originalLanguageMenu setAutoenablesItems:NO];
- int selectedMenuIndex = 0;
- int selectedLangIndex = [self delegate]->original_language_index();
- for (int i = 0; i < originalLanguageMenuModel_->GetItemCount(); ++i) {
- NSString* title = base::SysUTF16ToNSString(
- originalLanguageMenuModel_->GetLabelAt(i));
- int cmd = originalLanguageMenuModel_->GetCommandIdAt(i);
- bool checked = (cmd == selectedLangIndex);
- if (checked)
- selectedMenuIndex = i;
- bool enabled = originalLanguageMenuModel_->IsEnabledAt(i);
- cmd += IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE;
- AddMenuItem(originalLanguageMenu,
- self,
- @selector(languageMenuChanged:),
- title,
- cmd,
- enabled,
- checked);
- }
- [fromLanguagePopUp_ selectItemAtIndex:selectedMenuIndex];
-
- NSMenu* targetLanguageMenu = [toLanguagePopUp_ menu];
- [targetLanguageMenu setAutoenablesItems:NO];
- selectedLangIndex = [self delegate]->target_language_index();
- for (int i = 0; i < targetLanguageMenuModel_->GetItemCount(); ++i) {
- NSString* title = base::SysUTF16ToNSString(
- targetLanguageMenuModel_->GetLabelAt(i));
- int cmd = targetLanguageMenuModel_->GetCommandIdAt(i);
- bool checked = (cmd == selectedLangIndex);
- if (checked)
- selectedMenuIndex = i;
- bool enabled = targetLanguageMenuModel_->IsEnabledAt(i);
- cmd += IDC_TRANSLATE_TARGET_LANGUAGE_BASE;
- AddMenuItem(targetLanguageMenu,
- self,
- @selector(languageMenuChanged:),
- title,
- cmd,
- enabled,
- checked);
- }
- [toLanguagePopUp_ selectItemAtIndex:selectedMenuIndex];
-}
-
-- (void)addAdditionalControls {
- using l10n_util::GetNSString;
- using l10n_util::GetNSStringWithFixup;
-
- // Get layout information from the NIB.
- NSRect okButtonFrame = [okButton_ frame];
- NSRect cancelButtonFrame = [cancelButton_ frame];
- spaceBetweenControls_ = NSMinX(cancelButtonFrame) - NSMaxX(okButtonFrame);
-
- // Set infobar background color.
- [self setInfoBarGradientColor];
-
- // Instantiate additional controls.
- [self constructViews];
-
- // Set ourselves as the delegate for the options menu so we can populate it
- // dynamically.
- [[optionsPopUp_ menu] setDelegate:self];
-
- // Replace label_ with label1_ so we get a consistent look between all the
- // labels we display in the translate view.
- [[label_ superview] replaceSubview:label_ with:label1_.get()];
- label_.reset(); // Now released.
-
- // Populate contextual menus.
- [self rebuildOptionsMenu:NO];
- [self populateLanguageMenus];
-
- // Set OK & Cancel text.
- [okButton_ setTitle:GetNSStringWithFixup(IDS_TRANSLATE_INFOBAR_ACCEPT)];
- [cancelButton_ setTitle:GetNSStringWithFixup(IDS_TRANSLATE_INFOBAR_DENY)];
-
- // Set up "Show original" and "Try again" buttons.
- [showOriginalButton_ setFrame:okButtonFrame];
-
- // Set each of the buttons and popups to the NSTexturedRoundedBezelStyle
- // (metal-looking) style.
- NSArray* allControls = [self allControls];
- for (NSControl* control in allControls) {
- if (![control isKindOfClass:[NSButton class]])
- continue;
- NSButton* button = (NSButton*)control;
- [button setBezelStyle:NSTexturedRoundedBezelStyle];
- if ([button isKindOfClass:[NSPopUpButton class]]) {
- [[button cell] setArrowPosition:NSPopUpArrowAtBottom];
- }
- }
- // The options button is handled differently than the rest as it floats
- // to the right.
- [optionsPopUp_ setBezelStyle:NSTexturedRoundedBezelStyle];
- [[optionsPopUp_ cell] setArrowPosition:NSPopUpArrowAtBottom];
-
- [showOriginalButton_ setTarget:self];
- [showOriginalButton_ setAction:@selector(showOriginal:)];
- [translateMessageButton_ setTarget:self];
- [translateMessageButton_ setAction:@selector(messageButtonPressed:)];
-
- [showOriginalButton_
- setTitle:GetNSStringWithFixup(IDS_TRANSLATE_INFOBAR_REVERT)];
-
- // Add and configure controls that are visible in all modes.
- [optionsPopUp_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin |
- NSViewMaxYMargin];
- // Add "options" popup z-ordered below all other controls so when we
- // resize the toolbar it doesn't hide them.
- [infoBarView_ addSubview:optionsPopUp_
- positioned:NSWindowBelow
- relativeTo:nil];
- [GTMUILocalizerAndLayoutTweaker sizeToFitView:optionsPopUp_];
- MoveControl(closeButton_, optionsPopUp_, spaceBetweenControls_, false);
- VerticallyCenterView(optionsPopUp_);
-
- [infoBarView_ setPostsFrameChangedNotifications:YES];
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(didChangeFrame:)
- name:NSViewFrameDidChangeNotification
- object:infoBarView_];
- // Show and place GUI elements.
- [self updateState];
-}
-
-- (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView {
- [optionsPopUp_ setHidden:NO];
- [self rebuildOptionsMenu:NO];
- [[optionsPopUp_ cell] setArrowPosition:NSPopUpArrowAtBottom];
- [optionsPopUp_ sizeToFit];
-
- MoveControl(closeButton_, optionsPopUp_, spaceBetweenControls_, false);
- if (!VerifyControlOrderAndSpacing(lastView, optionsPopUp_)) {
- [self rebuildOptionsMenu:YES];
- NSRect oldFrame = [optionsPopUp_ frame];
- oldFrame.size.width = NSHeight(oldFrame);
- [optionsPopUp_ setFrame:oldFrame];
- [[optionsPopUp_ cell] setArrowPosition:NSPopUpArrowAtCenter];
- MoveControl(closeButton_, optionsPopUp_, spaceBetweenControls_, false);
- if (!VerifyControlOrderAndSpacing(lastView, optionsPopUp_)) {
- [optionsPopUp_ setHidden:YES];
- }
- }
-}
-
-// Called when "Translate" button is clicked.
-- (IBAction)ok:(id)sender {
- TranslateInfoBarDelegate* delegate = [self delegate];
- TranslateInfoBarDelegate::Type state = delegate->type();
- DCHECK(state == TranslateInfoBarDelegate::BEFORE_TRANSLATE ||
- state == TranslateInfoBarDelegate::TRANSLATION_ERROR);
- delegate->Translate();
- UMA_HISTOGRAM_COUNTS("Translate.Translate", 1);
-}
-
-// Called when someone clicks on the "Nope" button.
-- (IBAction)cancel:(id)sender {
- DCHECK(
- [self delegate]->type() == TranslateInfoBarDelegate::BEFORE_TRANSLATE);
- [self delegate]->TranslationDeclined();
- UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslate", 1);
- [super dismiss:nil];
-}
-
-- (void)messageButtonPressed:(id)sender {
- [self delegate]->MessageInfoBarButtonPressed();
-}
-
-- (IBAction)showOriginal:(id)sender {
- [self delegate]->RevertTranslation();
-}
-
-// Called when any of the language drop down menus are changed.
-- (void)languageMenuChanged:(id)item {
- if ([item respondsToSelector:@selector(tag)]) {
- int cmd = [item tag];
- if (cmd >= IDC_TRANSLATE_TARGET_LANGUAGE_BASE) {
- cmd -= IDC_TRANSLATE_TARGET_LANGUAGE_BASE;
- [self targetLanguageModified:cmd];
- return;
- } else if (cmd >= IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE) {
- cmd -= IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE;
- [self sourceLanguageModified:cmd];
- return;
- }
- }
- NOTREACHED() << "Language menu was changed with a bad language ID";
-}
-
-// Called when the options menu is changed.
-- (void)optionsMenuChanged:(id)item {
- if ([item respondsToSelector:@selector(tag)]) {
- int cmd = [item tag];
- // Danger Will Robinson! : This call can release the infobar (e.g. invoking
- // "About Translate" can open a new tab).
- // Do not access member variables after this line!
- optionsMenuModel_->ExecuteCommand(cmd);
- } else {
- NOTREACHED();
- }
-}
-
-- (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [super dealloc];
-}
-
-#pragma mark NSMenuDelegate
-
-// Invoked by virtue of us being set as the delegate for the options menu.
-- (void)menuNeedsUpdate:(NSMenu *)menu {
- [self adjustOptionsButtonSizeAndVisibilityForView:
- [[self visibleControls] lastObject]];
-}
-
-@end
-
-@implementation TranslateInfoBarControllerBase (TestingAPI)
-
-- (NSArray*)allControls {
- return [NSArray arrayWithObjects:label1_.get(),fromLanguagePopUp_.get(),
- label2_.get(), toLanguagePopUp_.get(), label3_.get(), okButton_,
- cancelButton_, showOriginalButton_.get(), translateMessageButton_.get(),
- nil];
-}
-
-- (NSMenu*)optionsMenu {
- return [optionsPopUp_ menu];
-}
-
-- (NSButton*)translateMessageButton {
- return translateMessageButton_.get();
-}
-
-- (bool)verifyLayout {
- // All the controls available to translate infobars, except the options popup.
- // The options popup is shown/hidden instead of actually removed. This gets
- // checked in the subclasses.
- NSArray* allControls = [self allControls];
- NSArray* visibleControls = [self visibleControls];
-
- // Step 1: Make sure control visibility is what we expect.
- for (NSUInteger i = 0; i < [allControls count]; ++i) {
- id control = [allControls objectAtIndex:i];
- bool hasSuperView = [control superview];
- bool expectedVisibility = [visibleControls containsObject:control];
-
- if (expectedVisibility != hasSuperView) {
- NSString *title = @"";
- if ([control isKindOfClass:[NSPopUpButton class]]) {
- title = [[[control menu] itemAtIndex:0] title];
- }
-
- LOG(ERROR) <<
- "State: " << [self description] <<
- " Control @" << i << (hasSuperView ? " has" : " doesn't have") <<
- " a superview" << [[control description] UTF8String] <<
- " Title=" << [title UTF8String];
- return false;
- }
- }
-
- // Step 2: Check that controls are ordered correctly with no overlap.
- id previousControl = nil;
- for (NSUInteger i = 0; i < [visibleControls count]; ++i) {
- id control = [visibleControls objectAtIndex:i];
- // The options pop up doesn't lay out like the rest of the controls as
- // it floats to the right. It has some known issues shown in
- // http://crbug.com/47941.
- if (control == optionsPopUp_.get())
- continue;
- if (previousControl &&
- !VerifyControlOrderAndSpacing(previousControl, control)) {
- NSString *title = @"";
- if ([control isKindOfClass:[NSPopUpButton class]]) {
- title = [[[control menu] itemAtIndex:0] title];
- }
- LOG(ERROR) <<
- "State: " << [self description] <<
- " Control @" << i << " not ordered correctly: " <<
- [[control description] UTF8String] <<[title UTF8String];
- return false;
- }
- previousControl = control;
- }
-
- return true;
-}
-
-@end // TranslateInfoBarControllerBase (TestingAPI)
-
diff --git a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
deleted file mode 100644
index fbe85b0..0000000
--- a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
+++ /dev/null
@@ -1,254 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import <Cocoa/Cocoa.h>
-
-#import "base/scoped_nsobject.h"
-#import "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#import "chrome/app/chrome_command_ids.h" // For translate menu command ids.
-#import "chrome/browser/cocoa/browser_test_helper.h"
-#import "chrome/browser/cocoa/cocoa_test_helper.h"
-#import "chrome/browser/cocoa/infobar.h"
-#import "chrome/browser/cocoa/translate/translate_infobar_base.h"
-#import "chrome/browser/cocoa/translate/before_translate_infobar_controller.h"
-#import "chrome/browser/renderer_host/site_instance.h"
-#import "chrome/browser/tab_contents/tab_contents.h"
-#import "chrome/browser/translate/translate_infobar_delegate.h"
-#import "testing/gmock/include/gmock/gmock.h"
-#import "testing/gtest/include/gtest/gtest.h"
-#import "testing/platform_test.h"
-
-namespace {
-
-// All states the translate toolbar can assume.
-TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = {
- TranslateInfoBarDelegate::BEFORE_TRANSLATE,
- TranslateInfoBarDelegate::AFTER_TRANSLATE,
- TranslateInfoBarDelegate::TRANSLATING,
- TranslateInfoBarDelegate::TRANSLATION_ERROR
-};
-
-class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate {
- public:
- MockTranslateInfoBarDelegate(TranslateInfoBarDelegate::Type type,
- TranslateErrors::Type error,
- TabContents* contents)
- : TranslateInfoBarDelegate(type, error, contents, "en", "es"){
- // Start out in the "Before Translate" state.
- type_ = type;
-
- }
-
- virtual string16 GetDisplayNameForLocale(const std::string& language_code) {
- return ASCIIToUTF16("Foo");
- }
-
- virtual bool IsLanguageBlacklisted() {
- return false;
- }
-
- virtual bool IsSiteBlacklisted() {
- return false;
- }
-
- virtual bool ShouldAlwaysTranslate() {
- return false;
- }
-
- MOCK_METHOD0(Translate, void());
- MOCK_METHOD0(RevertTranslation, void());
- MOCK_METHOD0(TranslationDeclined, void());
- MOCK_METHOD0(ToggleLanguageBlacklist, void());
- MOCK_METHOD0(ToggleSiteBlacklist, void());
- MOCK_METHOD0(ToggleAlwaysTranslate, void());
-};
-
-class TranslationInfoBarTest : public CocoaTest {
- public:
- BrowserTestHelper browser_helper_;
- scoped_ptr<TabContents> tab_contents;
- scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate;
- scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller;
-
- public:
- // Each test gets a single Mock translate delegate for the lifetime of
- // the test.
- virtual void SetUp() {
- CocoaTest::SetUp();
- tab_contents.reset(
- new TabContents(browser_helper_.profile(),
- NULL,
- MSG_ROUTING_NONE,
- NULL,
- NULL));
- CreateInfoBar();
- }
-
- void CreateInfoBar() {
- CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE);
- }
-
- void CreateInfoBar(TranslateInfoBarDelegate::Type type) {
- TranslateErrors::Type error = TranslateErrors::NONE;
- if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR)
- error = TranslateErrors::NETWORK;
- infobar_delegate.reset(
- new MockTranslateInfoBarDelegate(type, error, tab_contents.get()));
- [[infobar_controller view] removeFromSuperview];
- scoped_ptr<InfoBar> infobar(infobar_delegate->CreateInfoBar());
- infobar_controller.reset(
- reinterpret_cast<TranslateInfoBarControllerBase*>(
- infobar->controller()));
- // We need to set the window to be wide so that the options button
- // doesn't overlap the other buttons.
- [test_window() setContentSize:NSMakeSize(2000, 500)];
- [[infobar_controller view] setFrame:NSMakeRect(0, 0, 2000, 500)];
- [[test_window() contentView] addSubview:[infobar_controller view]];
- }
-};
-
-// Check that we can instantiate a Translate Infobar correctly.
-TEST_F(TranslationInfoBarTest, Instantiate) {
- CreateInfoBar();
- ASSERT_TRUE(infobar_controller.get());
-}
-
-// Check that clicking the Translate button calls Translate().
-TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) {
- CreateInfoBar();
-
- EXPECT_CALL(*infobar_delegate, Translate()).Times(1);
- [infobar_controller ok:nil];
-}
-
-// Check that clicking the "Retry" button calls Translate() when we're
-// in the error mode - http://crbug.com/41315 .
-TEST_F(TranslationInfoBarTest, TranslateCalledInErrorMode) {
- CreateInfoBar(TranslateInfoBarDelegate::TRANSLATION_ERROR);
-
- EXPECT_CALL(*infobar_delegate, Translate()).Times(1);
-
- [infobar_controller ok:nil];
-}
-
-// Check that clicking the "Show Original button calls RevertTranslation().
-TEST_F(TranslationInfoBarTest, RevertCalledOnButtonPress) {
- CreateInfoBar();
-
- EXPECT_CALL(*infobar_delegate, RevertTranslation()).Times(1);
- [infobar_controller showOriginal:nil];
-}
-
-// Check that items in the options menu are hooked up correctly.
-TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) {
- EXPECT_CALL(*infobar_delegate, Translate())
- .Times(0);
-
- [infobar_controller rebuildOptionsMenu:NO];
- NSMenu* optionsMenu = [infobar_controller optionsMenu];
- NSArray* optionsMenuItems = [optionsMenu itemArray];
-
- EXPECT_EQ(7U, [optionsMenuItems count]);
-
- // First item is the options menu button's title, so there's no need to test
- // that the target on that is setup correctly.
- for (NSUInteger i = 1; i < [optionsMenuItems count]; ++i) {
- NSMenuItem* item = [optionsMenuItems objectAtIndex:i];
- if (![item isSeparatorItem])
- EXPECT_EQ([item target], infobar_controller.get());
- }
- NSMenuItem* alwaysTranslateLanguateItem = [optionsMenuItems objectAtIndex:1];
- NSMenuItem* neverTranslateLanguateItem = [optionsMenuItems objectAtIndex:2];
- NSMenuItem* neverTranslateSiteItem = [optionsMenuItems objectAtIndex:3];
- // Separator at 4.
- NSMenuItem* reportBadLanguageItem = [optionsMenuItems objectAtIndex:5];
- NSMenuItem* aboutTranslateItem = [optionsMenuItems objectAtIndex:6];
-
- {
- EXPECT_CALL(*infobar_delegate, ToggleAlwaysTranslate())
- .Times(1);
- [infobar_controller optionsMenuChanged:alwaysTranslateLanguateItem];
- }
-
- {
- EXPECT_CALL(*infobar_delegate, ToggleLanguageBlacklist())
- .Times(1);
- [infobar_controller optionsMenuChanged:neverTranslateLanguateItem];
- }
-
- {
- EXPECT_CALL(*infobar_delegate, ToggleSiteBlacklist())
- .Times(1);
- [infobar_controller optionsMenuChanged:neverTranslateSiteItem];
- }
-
- {
- // Can't mock these effectively, so just check that the tag is set
- // correctly.
- EXPECT_EQ(IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION,
- [reportBadLanguageItem tag]);
- EXPECT_EQ(IDC_TRANSLATE_OPTIONS_ABOUT, [aboutTranslateItem tag]);
- }
-}
-
-// Check that selecting a new item from the "Source Language" popup in "before
-// translate" mode doesn't trigger a translation or change state.
-// http://crbug.com/36666
-TEST_F(TranslationInfoBarTest, Bug36666) {
- EXPECT_CALL(*infobar_delegate, Translate())
- .Times(0);
-
- CreateInfoBar();
- int arbitrary_index = 2;
- [infobar_controller sourceLanguageModified:arbitrary_index];
- EXPECT_CALL(*infobar_delegate, Translate())
- .Times(0);
-}
-
-// Check that the infobar lays itself out correctly when instantiated in
-// each of the states.
-// http://crbug.com/36895
-TEST_F(TranslationInfoBarTest, Bug36895) {
- EXPECT_CALL(*infobar_delegate, Translate())
- .Times(0);
-
- for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) {
- CreateInfoBar(kTranslateToolbarStates[i]);
- EXPECT_TRUE(
- [infobar_controller verifyLayout]) << "Layout wrong, for state #" << i;
- }
-}
-
-// Verify that the infobar shows the "Always translate this language" button
-// after doing 3 translations.
-TEST_F(TranslationInfoBarTest, TriggerShowAlwaysTranslateButton) {
- TranslatePrefs translate_prefs(browser_helper_.profile()->GetPrefs());
- translate_prefs.ResetTranslationAcceptedCount("en");
- for (int i = 0; i < 4; ++i) {
- translate_prefs.IncrementTranslationAcceptedCount("en");
- }
- CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE);
- BeforeTranslateInfobarController* controller =
- (BeforeTranslateInfobarController*)infobar_controller.get();
- EXPECT_TRUE([[controller alwaysTranslateButton] superview] != nil);
- EXPECT_TRUE([[controller neverTranslateButton] superview] == nil);
-}
-
-// Verify that the infobar shows the "Never translate this language" button
-// after denying 3 translations.
-TEST_F(TranslationInfoBarTest, TriggerShowNeverTranslateButton) {
- TranslatePrefs translate_prefs(browser_helper_.profile()->GetPrefs());
- translate_prefs.ResetTranslationDeniedCount("en");
- for (int i = 0; i < 4; ++i) {
- translate_prefs.IncrementTranslationDeniedCount("en");
- }
- CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE);
- BeforeTranslateInfobarController* controller =
- (BeforeTranslateInfobarController*)infobar_controller.get();
- EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil);
- EXPECT_TRUE([[controller neverTranslateButton] superview] != nil);
-}
-
-} // namespace
diff --git a/chrome/browser/cocoa/translate/translate_message_infobar_controller.h b/chrome/browser/cocoa/translate/translate_message_infobar_controller.h
deleted file mode 100644
index 985bf2a..0000000
--- a/chrome/browser/cocoa/translate/translate_message_infobar_controller.h
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "chrome/browser/cocoa/translate/translate_infobar_base.h"
-
-@interface TranslateMessageInfobarController : TranslateInfoBarControllerBase {
-}
-
-@end
diff --git a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
deleted file mode 100644
index 1146fdc..0000000
--- a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/cocoa/translate/translate_message_infobar_controller.h"
-
-#include "base/sys_string_conversions.h"
-
-using TranslateInfoBarUtilities::MoveControl;
-
-@implementation TranslateMessageInfobarController
-
-- (void)layout {
- [self removeOkCancelButtons];
- MoveControl(label1_, translateMessageButton_, spaceBetweenControls_ * 2, true);
- TranslateInfoBarDelegate* delegate = [self delegate];
- if ([self delegate]->ShouldShowMessageInfoBarButton()) {
- string16 buttonText = delegate->GetMessageInfoBarButtonText();
- [translateMessageButton_ setTitle:base::SysUTF16ToNSString(buttonText)];
- [translateMessageButton_ sizeToFit];
- }
-}
-
-- (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView {
- // Do nothing, but stop the options button from showing up.
-}
-
-- (NSArray*)visibleControls {
- NSMutableArray* visibleControls =
- [NSMutableArray arrayWithObjects:label1_.get(), nil];
- if ([self delegate]->ShouldShowMessageInfoBarButton())
- [visibleControls addObject:translateMessageButton_];
- return visibleControls;
-}
-
-- (void)loadLabelText {
- TranslateInfoBarDelegate* delegate = [self delegate];
- string16 messageText = delegate->GetMessageInfoBarText();
- NSString* string1 = base::SysUTF16ToNSString(messageText);
- [label1_ setStringValue:string1];
-}
-
-- (bool)verifyLayout {
- if (![optionsPopUp_ isHidden])
- return false;
- return [super verifyLayout];
-}
-
-- (BOOL)shouldShowOptionsPopUp {
- return NO;
-}
-
-@end