summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/translate
diff options
context:
space:
mode:
authorfeldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-13 18:06:46 +0000
committerfeldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-13 18:06:46 +0000
commitfae0c716da991395bc240cf871a3540e19efceb6 (patch)
treea1d4e8e079efb91dc0bfd5ac944a4d2d29193c8f /chrome/browser/cocoa/translate
parent0c95205965366d9acbc0cef488b5c197ddad2708 (diff)
downloadchromium_src-fae0c716da991395bc240cf871a3540e19efceb6.zip
chromium_src-fae0c716da991395bc240cf871a3540e19efceb6.tar.gz
chromium_src-fae0c716da991395bc240cf871a3540e19efceb6.tar.bz2
Clean up mac translate bars.
Switch buttons to use the metal style, and fix up spacing a bit. BUG=40425 TEST=none Review URL: http://codereview.chromium.org/2804035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/translate')
-rw-r--r--chrome/browser/cocoa/translate/after_translate_infobar_controller.mm7
-rw-r--r--chrome/browser/cocoa/translate/before_translate_infobar_controller.mm7
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_base.h17
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_base.mm93
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_unittest.mm7
-rw-r--r--chrome/browser/cocoa/translate/translate_message_infobar_controller.mm4
6 files changed, 112 insertions, 23 deletions
diff --git a/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm b/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm
index f263c70..7e01146 100644
--- a/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm
+++ b/chrome/browser/cocoa/translate/after_translate_infobar_controller.mm
@@ -6,6 +6,7 @@
#include "base/sys_string_conversions.h"
using TranslateInfoBarUtilities::MoveControl;
+using TranslateInfoBarUtilities::VerifyControlOrderAndSpacing;
@implementation AfterTranslateInfobarController
@@ -34,9 +35,9 @@ using TranslateInfoBarUtilities::MoveControl;
}
NSView* lastControl = lastPopup;
- MoveControl(label1_, firstPopup, 0, true);
- MoveControl(firstPopup, label2_, 0, true);
- MoveControl(label2_, lastPopup, 0, true);
+ 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_;
diff --git a/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm b/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm
index d2d418d..bcae753 100644
--- a/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm
+++ b/chrome/browser/cocoa/translate/before_translate_infobar_controller.mm
@@ -9,13 +9,13 @@
#include "grit/generated_resources.h"
using TranslateInfoBarUtilities::MoveControl;
+using TranslateInfoBarUtilities::VerifyControlOrderAndSpacing;
@implementation BeforeTranslateInfobarController
- (void)layout {
- [optionsPopUp_ setHidden:NO];
- MoveControl(label1_, fromLanguagePopUp_, 0, true);
- MoveControl(fromLanguagePopUp_, label2_, 0, true);
+ MoveControl(label1_, fromLanguagePopUp_, spaceBetweenControls_ / 2, true);
+ MoveControl(fromLanguagePopUp_, label2_, spaceBetweenControls_, true);
MoveControl(label2_, okButton_, spaceBetweenControls_, true);
MoveControl(okButton_, cancelButton_, spaceBetweenControls_, true);
}
@@ -35,7 +35,6 @@ using TranslateInfoBarUtilities::MoveControl;
- (NSArray*)visibleControls {
return [NSArray arrayWithObjects:label1_.get(), fromLanguagePopUp_.get(),
label2_.get(), okButton_, cancelButton_, nil];
-
}
- (bool)verifyLayout {
diff --git a/chrome/browser/cocoa/translate/translate_infobar_base.h b/chrome/browser/cocoa/translate/translate_infobar_base.h
index 8d15e38..befa37c 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_base.h
+++ b/chrome/browser/cocoa/translate/translate_infobar_base.h
@@ -83,6 +83,12 @@ void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title,
@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.
@@ -118,8 +124,10 @@ void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title,
- (void)languageMenuChanged:(id)item;
- (void)optionsMenuChanged:(id)item;
-// Teardown and rebuild the options menu.
-- (void)rebuildOptionsMenu;
+// 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;
@end // TranslateInfoBarControllerBase (ProtectedAPI)
@@ -127,6 +135,11 @@ void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title,
@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;
diff --git a/chrome/browser/cocoa/translate/translate_infobar_base.mm b/chrome/browser/cocoa/translate/translate_infobar_base.mm
index 0da7ca8..bf2b631 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_base.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_base.mm
@@ -122,6 +122,18 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
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
@@ -224,6 +236,8 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
[self clearAllControls];
[self showVisibleControls:[self visibleControls]];
[self layout];
+ [self adjustOptionsButtonSizeAndVisibilityForView:
+ [[self visibleControls] lastObject]];
}
- (void)setInfoBarGradientColor {
@@ -250,9 +264,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
- (void)clearAllControls {
// Step 1: remove all controls from the infobar so we have a clean slate.
- NSArray *allControls = [NSArray arrayWithObjects:label2_.get(), label3_.get(),
- fromLanguagePopUp_.get(), toLanguagePopUp_.get(),
- showOriginalButton_.get(), tryAgainButton_.get(), nil];
+ NSArray *allControls = [self allControls];
for (NSControl* control in allControls) {
if ([control superview])
@@ -292,7 +304,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
return [NSArray array];
}
-- (void) rebuildOptionsMenu {
+- (void)rebuildOptionsMenu:(BOOL)hideTitle {
// The options model doesn't know how to handle state transitions, so rebuild
// it each time through here.
optionsMenuModel_.reset(
@@ -300,7 +312,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
[optionsPopUp_ removeAllItems];
// Set title.
- NSString* optionsLabel =
+ NSString* optionsLabel = hideTitle ? @"" :
l10n_util::GetNSString(IDS_TRANSLATE_INFOBAR_OPTIONS);
[optionsPopUp_ addItemWithTitle:optionsLabel];
@@ -395,7 +407,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
label_.reset(); // Now released.
// Populate contextual menus.
- [self rebuildOptionsMenu];
+ [self rebuildOptionsMenu:NO];
[self populateLanguageMenus];
// Set OK & Cancel text.
@@ -403,11 +415,26 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
[cancelButton_ setTitle:GetNSStringWithFixup(IDS_TRANSLATE_INFOBAR_DENY)];
// Set up "Show original" and "Try again" buttons.
- [showOriginalButton_ setBezelStyle:NSRoundRectBezelStyle];
[showOriginalButton_ setFrame:okButtonFrame];
- [tryAgainButton_ setBezelStyle:NSRoundRectBezelStyle];
[tryAgainButton_ 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:)];
[tryAgainButton_ setTarget:self];
@@ -430,10 +457,36 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
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];
@@ -487,17 +540,30 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
}
}
+- (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 rebuildOptionsMenu];
+ [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(), tryAgainButton_.get(),
+ nil];
+}
+
- (NSMenu*)optionsMenu {
return [optionsPopUp_ menu];
}
@@ -510,9 +576,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
// 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 = [NSArray arrayWithObjects:label1_.get(),
- fromLanguagePopUp_.get(), label2_.get(), toLanguagePopUp_.get(),
- label3_.get(), showOriginalButton_.get(), tryAgainButton_.get(), nil];
+ NSArray* allControls = [self allControls];
NSArray* visibleControls = [self visibleControls];
// Step 1: Make sure control visibility is what we expect.
@@ -540,6 +604,11 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
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 = @"";
diff --git a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
index 646039f3..3b8ee65 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
@@ -103,7 +103,10 @@ class TranslationInfoBarTest : public CocoaTest {
infobar_controller.reset(
reinterpret_cast<TranslateInfoBarControllerBase*>(
infobar->controller()));
- // Need to call this to get the view to load from nib.
+ // 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]];
}
};
@@ -145,7 +148,7 @@ TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) {
EXPECT_CALL(*infobar_delegate, Translate())
.Times(0);
- [infobar_controller rebuildOptionsMenu];
+ [infobar_controller rebuildOptionsMenu:NO];
NSMenu* optionsMenu = [infobar_controller optionsMenu];
NSArray* optionsMenuItems = [optionsMenu itemArray];
diff --git a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
index 65d92bb..db2f46f 100644
--- a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
+++ b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
@@ -30,6 +30,10 @@ using TranslateInfoBarUtilities::MoveControl;
MoveControl(label1_, tryAgainButton_, spaceBetweenControls_ * 2, true);
}
+- (void)adjustOptionsButtonSizeAndVisibilityForView:(NSView*)lastView {
+ // Do nothing, but stop the options button from showing up.
+}
+
- (NSArray*)visibleControls {
NSMutableArray* visibleControls =
[NSMutableArray arrayWithObjects:label1_.get(), nil];