summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-05 12:37:05 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-05 12:37:05 +0000
commitc9f969282a56152ddc0e45522e66fa46d99819d2 (patch)
treee82cd46bba3eaf5e91f025b290adeae233e17728
parent54b0385959ba632179d882d4b4ac8962bf9e705d (diff)
downloadchromium_src-c9f969282a56152ddc0e45522e66fa46d99819d2.zip
chromium_src-c9f969282a56152ddc0e45522e66fa46d99819d2.tar.gz
chromium_src-c9f969282a56152ddc0e45522e66fa46d99819d2.tar.bz2
Infobar l10n pass
- remove the close button outlet (unused) - add a helper to hide the buttons and resize the text field to use the same. - if no image, move the text field - tweak the xib to make it clear the values aren't used - tweak the xib to remove the NSEveryone image - make the link text use the control's font so it matches what's in the xib and other infobar modes (if we ever had to tweak it). - use the GTM helper for autosizing buttons - reflow how we position the buttons/textfield for the button infobars so it updates the textfield once. TEST=if you make the window skinny, any infobars that don't have buttons shouldn't reserve space for them. the the plugin crashed info bar shouldn't show a bogus graphic (currently we have none set). BUG=20535 BUG=19183 Review URL: http://codereview.chromium.org/251075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27983 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/nibs/InfoBar.xib24
-rw-r--r--chrome/browser/cocoa/infobar_controller.h10
-rw-r--r--chrome/browser/cocoa/infobar_controller.mm145
3 files changed, 95 insertions, 84 deletions
diff --git a/chrome/app/nibs/InfoBar.xib b/chrome/app/nibs/InfoBar.xib
index 07f35bb..4f5cb15 100644
--- a/chrome/app/nibs/InfoBar.xib
+++ b/chrome/app/nibs/InfoBar.xib
@@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">9G3553</string>
+ <string key="IBDocument.SystemVersion">9L30</string>
<string key="IBDocument.InterfaceBuilderVersion">677</string>
- <string key="IBDocument.AppKitVersion">949.43</string>
+ <string key="IBDocument.AppKitVersion">949.54</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -96,10 +96,6 @@
<object class="NSImageCell" key="NSCell" id="905047690">
<int key="NSCellFlags">130560</int>
<int key="NSCellFlags2">33554432</int>
- <object class="NSCustomResource" key="NSContents">
- <string key="NSClassName">NSImage</string>
- <string key="NSResourceName">NSEveryone</string>
- </object>
<int key="NSAlign">0</int>
<int key="NSScale">3</int>
<int key="NSStyle">0</int>
@@ -144,7 +140,7 @@
<object class="NSButtonCell" key="NSCell" id="24619168">
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">134217728</int>
- <string key="NSContents">Cancel</string>
+ <string key="NSContents">CancelBtn</string>
<object class="NSFont" key="NSSupport" id="751943183">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">1.100000e+01</double>
@@ -169,7 +165,7 @@
<object class="NSButtonCell" key="NSCell" id="900516520">
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">134217728</int>
- <string key="NSContents">OK</string>
+ <string key="NSContents">OKBtn</string>
<reference key="NSSupport" ref="751943183"/>
<reference key="NSControlView" ref="11488953"/>
<int key="NSButtonFlags">-2038284033</int>
@@ -224,14 +220,6 @@
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
- <string key="label">closeButton_</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="861420161"/>
- </object>
- <int key="connectionID">18</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
<string key="label">delegate</string>
<reference key="source" ref="293244832"/>
<reference key="destination" ref="1001"/>
@@ -413,7 +401,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{75, 275}, {480, 31}}</string>
+ <string>{{91, 327}, {480, 31}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{628, 654}</string>
<string>{{357, 416}, {480, 272}}</string>
@@ -478,7 +466,6 @@
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>cancelButton_</string>
- <string>closeButton_</string>
<string>image_</string>
<string>label_</string>
<string>okButton_</string>
@@ -486,7 +473,6 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSButton</string>
- <string>NSButton</string>
<string>NSImageView</string>
<string>NSTextField</string>
<string>NSButton</string>
diff --git a/chrome/browser/cocoa/infobar_controller.h b/chrome/browser/cocoa/infobar_controller.h
index f037ddf..8015067 100644
--- a/chrome/browser/cocoa/infobar_controller.h
+++ b/chrome/browser/cocoa/infobar_controller.h
@@ -21,7 +21,6 @@ class InfoBarDelegate;
IBOutlet NSTextField* label_;
IBOutlet NSButton* okButton_;
IBOutlet NSButton* cancelButton_;
- IBOutlet NSButton* closeButton_;
};
// Initializes a new InfoBarController.
@@ -51,20 +50,17 @@ class InfoBarDelegate;
// subclass. Each of these subclasses overrides addAdditionalControls to
// configure its view as necessary.
-@interface AlertInfoBarController : InfoBarController {
-}
+@interface AlertInfoBarController : InfoBarController
@end
-@interface LinkInfoBarController : InfoBarController {
-}
+@interface LinkInfoBarController : InfoBarController
// Called when there is a click on the link in the infobar.
- (void)linkClicked;
@end
-@interface ConfirmInfoBarController : InfoBarController {
-}
+@interface ConfirmInfoBarController : InfoBarController
// Called when the ok and cancel buttons are clicked.
- (IBAction)ok:(id)sender;
- (IBAction)cancel:(id)sender;
diff --git a/chrome/browser/cocoa/infobar_controller.mm b/chrome/browser/cocoa/infobar_controller.mm
index 8e4affe..e8b1999 100644
--- a/chrome/browser/cocoa/infobar_controller.mm
+++ b/chrome/browser/cocoa/infobar_controller.mm
@@ -13,6 +13,7 @@
#import "chrome/browser/cocoa/infobar_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "skia/ext/skia_utils_mac.h"
+#include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "webkit/glue/window_open_disposition.h"
@@ -23,6 +24,9 @@
// delegate is removed from the container, it is no longer needed, so
// we ask it to delete itself.
- (void)closeInfoBar;
+// Removes the ok and cancel buttons, and resizes the textfield to use the
+// space.
+- (void)removeButtons;
@end
@implementation InfoBarController
@@ -44,6 +48,15 @@
- (void)awakeFromNib {
if (delegate_->GetIcon()) {
[image_ setImage:gfx::SkBitmapToNSImage(*(delegate_->GetIcon()))];
+ } else {
+ // No icon, remove it from the view and grow the textfield to include the
+ // space.
+ NSRect imageFrame = [image_ frame];
+ NSRect labelFrame = [label_ frame];
+ labelFrame.size.width += NSMinX(imageFrame) - NSMinX(labelFrame);
+ labelFrame.origin.x = imageFrame.origin.x;
+ [image_ removeFromSuperview];
+ [label_ setFrame:labelFrame];
}
[self addAdditionalControls];
@@ -73,6 +86,7 @@
@end
@implementation InfoBarController (PrivateMethods)
+
- (void)closeInfoBar {
// Calling RemoveDelegate() triggers notifications which will remove
// the infobar view from the infobar container. At that point it is
@@ -82,6 +96,17 @@
delegate_->InfoBarClosed();
delegate_ = NULL;
}
+
+- (void)removeButtons {
+ // Extend the label all the way across.
+ // Remove the ok and cancel buttons, since they are not needed.
+ NSRect labelFrame = [label_ frame];
+ labelFrame.size.width = NSMaxX([cancelButton_ frame]) - NSMinX(labelFrame);
+ [okButton_ removeFromSuperview];
+ [cancelButton_ removeFromSuperview];
+ [label_ setFrame:labelFrame];
+}
+
@end
@@ -92,13 +117,12 @@
// Alert infobars have a text message.
- (void)addAdditionalControls {
- AlertInfoBarDelegate* delegate = delegate_->AsAlertInfoBarDelegate();
- [label_ setStringValue:base::SysWideToNSString(
- delegate->GetMessageText())];
+ // No buttons.
+ [self removeButtons];
- // Remove the ok and cancel buttons, since they are not needed.
- [okButton_ removeFromSuperview];
- [cancelButton_ removeFromSuperview];
+ // Insert the text.
+ AlertInfoBarDelegate* delegate = delegate_->AsAlertInfoBarDelegate();
+ [label_ setStringValue:base::SysWideToNSString(delegate->GetMessageText())];
}
@end
@@ -117,21 +141,24 @@
//
// TODO(rohitrao): Using an NSTextField here has some weird UI side
// effects, such as showing the wrong cursor at times. Explore other
-// solutions.
+// solutions. The About box legal block has the same issue, maybe share
+// a solution.
- (void)addAdditionalControls {
+ // No buttons.
+ [self removeButtons];
+
LinkInfoBarDelegate* delegate = delegate_->AsLinkInfoBarDelegate();
size_t offset = std::wstring::npos;
std::wstring message = delegate->GetMessageTextWithOffset(&offset);
// Create an attributes dictionary for the entire message. We have
- // to expicitly set the font to the system font, because
- // NSAttributedString defaults to Helvetica 12. We also override
+ // to expicitly set the font the control's font. We also override
// the cursor to give us the normal cursor rather than the text
// insertion cursor.
NSMutableDictionary* linkAttributes =
[NSMutableDictionary dictionaryWithObject:[NSCursor arrowCursor]
forKey:NSCursorAttributeName];
- [linkAttributes setObject:[NSFont systemFontOfSize:[NSFont systemFontSize]]
+ [linkAttributes setObject:[label_ font]
forKey:NSFontAttributeName];
// Create the attributed string for the main message text.
@@ -164,13 +191,9 @@
// Update the label view with the new text. The view must be
// selectable and allow editing text attributes for the
// linkification to work correctly.
- [label_ setAllowsEditingTextAttributes: YES];
- [label_ setSelectable: YES];
+ [label_ setAllowsEditingTextAttributes:YES];
+ [label_ setSelectable:YES];
[label_ setAttributedStringValue:infoText];
-
- // Remove the ok and cancel buttons, since they are not needed.
- [okButton_ removeFromSuperview];
- [cancelButton_ removeFromSuperview];
}
// Called when someone clicks on the link in the infobar. This method
@@ -209,67 +232,73 @@
- (void)addAdditionalControls {
ConfirmInfoBarDelegate* delegate = delegate_->AsConfirmInfoBarDelegate();
int visibleButtons = delegate->GetButtons();
- [label_ setStringValue:base::SysWideToNSString(delegate->GetMessageText())];
- // Save the margins between the buttons, so we can keep them constant.
- float cancelMargin =
- NSMinX([closeButton_ frame]) - NSMaxX([cancelButton_ frame]);
- float okMargin = NSMinX([cancelButton_ frame]) - NSMaxX([okButton_ frame]);
- float labelMargin = NSMinX([okButton_ frame]) - NSMaxX([label_ frame]);
+ NSRect okButtonFrame = [okButton_ frame];
+ NSRect cancelButtonFrame = [cancelButton_ frame];
+
+ DCHECK(NSMaxX(okButtonFrame) < NSMinX(cancelButtonFrame))
+ << "Cancel button expected to be on the right of the Ok button in nib";
- // Create and position the cancel button if needed. Otherwise, hide it.
+ CGFloat rightEdge = NSMaxX(cancelButtonFrame);
+ CGFloat spaceBetweenButtons =
+ NSMinX(cancelButtonFrame) - NSMaxX(okButtonFrame);
+ CGFloat spaceBeforeButtons =
+ NSMinX(okButtonFrame) - NSMaxX([label_ frame]);
+
+ // Update and position the Cancel button if needed. Otherwise, hide it.
if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
[cancelButton_ setTitle:base::SysWideToNSString(
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL))];
- [cancelButton_ sizeToFit];
-
- NSRect cancelFrame = [cancelButton_ frame];
- float cancelWidth = cancelFrame.size.width + cancelMargin;
-
- // Position the cancel button to the left of the close button.
- // The appropriate margin is already built into cancelWidth.
- cancelFrame.origin.x = NSMinX([closeButton_ frame]) - cancelWidth;
- [cancelButton_ setFrame:cancelFrame];
-
- // Resize the label box to extend all the way to the cancel button,
- // minus the saved margin, but only if we're not also adding an OK button.
- if (!(visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) {
- NSRect labelFrame = [label_ frame];
- labelFrame.size.width =
- NSMinX(cancelFrame) - NSMinX(labelFrame) - labelMargin;
- [label_ setFrame:labelFrame];
- }
+ [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_];
+ cancelButtonFrame = [cancelButton_ frame];
+
+ // Position the cancel button to the left of the Close button.
+ cancelButtonFrame.origin.x = rightEdge - cancelButtonFrame.size.width;
+ [cancelButton_ setFrame:cancelButtonFrame];
+
+ // Update the rightEdge
+ rightEdge = NSMinX(cancelButtonFrame);
} else {
[cancelButton_ removeFromSuperview];
}
- // Create and position the OK button if needed. Otherwise, hide it.
+ // Update and position the OK button if needed. Otherwise, hide it.
if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK) {
[okButton_ setTitle:base::SysWideToNSString(
delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK))];
- [okButton_ sizeToFit];
+ [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_];
+ okButtonFrame = [okButton_ frame];
- NSRect okFrame = [okButton_ frame];
- int okWidth = okFrame.size.width + okMargin;
+ // If we had a Cancel button, leave space between the buttons.
+ if (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
+ rightEdge -= spaceBetweenButtons;
+ }
- // Position the OK button to the left of the cancel button, if
- // present. Otherwise, position it relative to the close button.
- float relativeX = (visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) ?
- NSMinX([cancelButton_ frame]) :
- NSMinX([closeButton_ frame]);
+ // Position the OK button on our current right edge.
+ okButtonFrame.origin.x = rightEdge - okButtonFrame.size.width;
+ [okButton_ setFrame:okButtonFrame];
- // The appropriate margin is already built into okWidth.
- okFrame.origin.x = relativeX - okWidth;
- [okButton_ setFrame:okFrame];
- // Resize the label box to extend all the way to the OK button,
- // minus the saved margin.
- NSRect labelFrame = [label_ frame];
- labelFrame.size.width = NSMinX(okFrame) - NSMinX(labelFrame) - labelMargin;
- [label_ setFrame:labelFrame];
+ // Update the rightEdge
+ rightEdge = NSMinX(okButtonFrame);
} else {
[okButton_ removeFromSuperview];
}
+
+ // If we had either button, leave space before the edge of the textfield.
+ if ((visibleButtons & ConfirmInfoBarDelegate::BUTTON_CANCEL) ||
+ (visibleButtons & ConfirmInfoBarDelegate::BUTTON_OK)) {
+ rightEdge -= spaceBeforeButtons;
+ }
+
+ NSRect frame = [label_ frame];
+ DCHECK(rightEdge > NSMinX(frame))
+ << "Need to make the xib larger to handle buttons with text this long";
+ frame.size.width = rightEdge - NSMinX(frame);
+ [label_ setFrame:frame];
+
+ // Set the text.
+ [label_ setStringValue:base::SysWideToNSString(delegate->GetMessageText())];
}
@end