Index: chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.mm |
diff --git a/chrome/browser/ui/cocoa/constrained_window/cw_alert.mm b/chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.mm |
similarity index 84% |
rename from chrome/browser/ui/cocoa/constrained_window/cw_alert.mm |
rename to chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.mm |
index f3d3ad67f49c50674653b974ffa366631d058450..1a57a3c62c8535494ebb2e6c12f6dab98650eb0a 100644 |
--- a/chrome/browser/ui/cocoa/constrained_window/cw_alert.mm |
+++ b/chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.mm |
@@ -2,11 +2,11 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#import "chrome/browser/ui/cocoa/constrained_window/cw_alert.h" |
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
#import "base/logging.h" |
-#import "chrome/browser/ui/cocoa/constrained_window/cw_button.h" |
-#import "chrome/browser/ui/cocoa/constrained_window/cw_window.h" |
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h" |
#import "chrome/browser/ui/cocoa/hover_close_button.h" |
#import "chrome/browser/ui/constrained_window.h" |
#include "skia/ext/skia_utils_mac.h" |
@@ -19,6 +19,7 @@ const CGFloat kButtonGap = 6; |
const CGFloat kButtonMinWidth = 72; |
const CGFloat kCloseButtonSize = 16; |
+// Creates a label control. |
scoped_nsobject<NSTextField> CreateLabel() { |
scoped_nsobject<NSTextField> label( |
[[NSTextField alloc] initWithFrame:NSZeroRect]); |
@@ -29,11 +30,14 @@ scoped_nsobject<NSTextField> CreateLabel() { |
return label; |
} |
+// Calculates the control size that will fit within the given width. |
NSSize CalculateDesiredSizeForWidth(NSTextField* text_field, CGFloat width) { |
NSRect rect = NSMakeRect(0, 0, width, 1000); |
return [[text_field cell] cellSizeForBounds:rect]; |
} |
+// Helper function to create constrained window label string with the given |
+// font. |
NSAttributedString* GetAttributedLabelString( |
NSString* string, |
ui::ResourceBundle::FontStyle font_style) { |
@@ -51,16 +55,21 @@ NSAttributedString* GetAttributedLabelString( |
} // namespace |
-@interface CWAlert() |
-- (void)layoutButtonsWithWindowWidth: (CGFloat)windowWidth; |
+@interface ConstrainedWindowAlert () |
+// Position the alert buttons within the given window width. |
+- (void)layoutButtonsWithWindowWidth:(CGFloat)windowWidth; |
+// Resize the given text field to fit within the window and position it starting |
+// at |yPos|. Returns the new value of yPos. |
- (CGFloat)layoutTextField:(NSTextField*)textField |
yPos:(CGFloat)yPos |
windowWidth:(CGFloat)windowWidth; |
+// Positions the accessory view starting at yPos. Returns the new value of yPos. |
- (CGFloat)layoutAccessoryViewAtYPos:(CGFloat)yPos; |
+// Update the position of the close button. |
- (void)layoutCloseButtonWithWindowWidth:(CGFloat)windowWidth; |
@end |
-@implementation CWAlert |
+@implementation ConstrainedWindowAlert |
- (NSString*)informativeText { |
return [informativeTextField_ stringValue]; |
@@ -104,7 +113,7 @@ NSAttributedString* GetAttributedLabelString( |
- (id)init { |
if ((self = [super init])) { |
- window_.reset([[CWWindow alloc] |
+ window_.reset([[ConstrainedWindowCustomWindow alloc] |
initWithContentRect:ui::kWindowSizeDeterminedLater]); |
[window_ setReleasedWhenClosed:NO]; |
NSView* content_view = [window_ contentView]; |
@@ -121,12 +130,16 @@ NSAttributedString* GetAttributedLabelString( |
} |
- (void)addButtonWithTitle:(NSString*)title |
- keyEquivalent:(NSString*)keyEquivalent { |
+ keyEquivalent:(NSString*)keyEquivalent |
+ target:(id)target |
+ action:(SEL)action { |
if (!buttons_.get()) |
buttons_.reset([[NSMutableArray alloc] init]); |
- NSButton* button = [[CWButton alloc] initWithFrame:NSZeroRect]; |
+ NSButton* button = [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]; |
[button setTitle:title]; |
[button setKeyEquivalent:keyEquivalent]; |
+ [button setTarget:target]; |
+ [button setAction:action]; |
[buttons_ addObject:button]; |
[[window_ contentView] addSubview:button]; |
} |
@@ -170,7 +183,7 @@ NSAttributedString* GetAttributedLabelString( |
display:NO]; |
} |
-- (void)layoutButtonsWithWindowWidth: (CGFloat)windowWidth { |
+- (void)layoutButtonsWithWindowWidth:(CGFloat)windowWidth { |
// Layout first 2 button right to left. |
CGFloat curX = windowWidth - ConstrainedWindow::kHorizontalPadding; |
const int buttonCount = [buttons_ count]; |