Index: chrome/browser/ui/cocoa/constrained_window/cw_alert.mm |
diff --git a/chrome/browser/ui/cocoa/constrained_window/cw_alert.mm b/chrome/browser/ui/cocoa/constrained_window/cw_alert.mm |
deleted file mode 100644 |
index f3d3ad67f49c50674653b974ffa366631d058450..0000000000000000000000000000000000000000 |
--- a/chrome/browser/ui/cocoa/constrained_window/cw_alert.mm |
+++ /dev/null |
@@ -1,235 +0,0 @@ |
-// Copyright (c) 2012 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/ui/cocoa/constrained_window/cw_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/hover_close_button.h" |
-#import "chrome/browser/ui/constrained_window.h" |
-#include "skia/ext/skia_utils_mac.h" |
-#include "ui/base/cocoa/window_size_constants.h" |
- |
-namespace { |
- |
-const CGFloat kWindowMinWidth = 500; |
-const CGFloat kButtonGap = 6; |
-const CGFloat kButtonMinWidth = 72; |
-const CGFloat kCloseButtonSize = 16; |
- |
-scoped_nsobject<NSTextField> CreateLabel() { |
- scoped_nsobject<NSTextField> label( |
- [[NSTextField alloc] initWithFrame:NSZeroRect]); |
- [label setEditable:NO]; |
- [label setSelectable:NO]; |
- [label setBezeled:NO]; |
- [label setDrawsBackground:NO]; |
- return label; |
-} |
- |
-NSSize CalculateDesiredSizeForWidth(NSTextField* text_field, CGFloat width) { |
- NSRect rect = NSMakeRect(0, 0, width, 1000); |
- return [[text_field cell] cellSizeForBounds:rect]; |
-} |
- |
-NSAttributedString* GetAttributedLabelString( |
- NSString* string, |
- ui::ResourceBundle::FontStyle font_style) { |
- const gfx::Font& font = |
- ui::ResourceBundle::GetSharedInstance().GetFont(font_style); |
- NSColor* color = |
- gfx::SkColorToCalibratedNSColor(ConstrainedWindow::kTextColor); |
- NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: |
- font.GetNativeFont(), NSFontAttributeName, |
- color, NSForegroundColorAttributeName, |
- nil]; |
- return [[[NSAttributedString alloc] initWithString:string |
- attributes:attributes] autorelease]; |
-} |
- |
-} // namespace |
- |
-@interface CWAlert() |
-- (void)layoutButtonsWithWindowWidth: (CGFloat)windowWidth; |
-- (CGFloat)layoutTextField:(NSTextField*)textField |
- yPos:(CGFloat)yPos |
- windowWidth:(CGFloat)windowWidth; |
-- (CGFloat)layoutAccessoryViewAtYPos:(CGFloat)yPos; |
-- (void)layoutCloseButtonWithWindowWidth:(CGFloat)windowWidth; |
-@end |
- |
-@implementation CWAlert |
- |
-- (NSString*)informativeText { |
- return [informativeTextField_ stringValue]; |
-} |
- |
-- (void)setInformativeText:(NSString*)string { |
- [informativeTextField_ setAttributedStringValue: |
- GetAttributedLabelString(string, ConstrainedWindow::kTextFontStyle)]; |
-} |
- |
-- (NSString*)messageText { |
- return [messageTextField_ stringValue]; |
-} |
- |
-- (void)setMessageText:(NSString*)string { |
- [messageTextField_ setAttributedStringValue: |
- GetAttributedLabelString(string, ConstrainedWindow::kTitleFontStyle)]; |
-} |
- |
-- (NSView*)accessoryView { |
- return accessoryView_; |
-} |
- |
-- (void)setAccessoryView:(NSView*)accessoryView { |
- [accessoryView_ removeFromSuperview]; |
- accessoryView_.reset([accessoryView retain]); |
- [[window_ contentView] addSubview:accessoryView_]; |
-} |
- |
-- (NSArray*)buttons { |
- return buttons_; |
-} |
- |
-- (NSButton*)closeButton { |
- return closeButton_; |
-} |
- |
-- (NSWindow*)window { |
- return window_; |
-} |
- |
-- (id)init { |
- if ((self = [super init])) { |
- window_.reset([[CWWindow alloc] |
- initWithContentRect:ui::kWindowSizeDeterminedLater]); |
- [window_ setReleasedWhenClosed:NO]; |
- NSView* content_view = [window_ contentView]; |
- |
- informativeTextField_ = CreateLabel(); |
- [content_view addSubview:informativeTextField_]; |
- messageTextField_ = CreateLabel(); |
- [content_view addSubview:messageTextField_]; |
- |
- closeButton_.reset([[HoverCloseButton alloc] initWithFrame:NSZeroRect]); |
- [content_view addSubview:closeButton_]; |
- } |
- return self; |
-} |
- |
-- (void)addButtonWithTitle:(NSString*)title |
- keyEquivalent:(NSString*)keyEquivalent { |
- if (!buttons_.get()) |
- buttons_.reset([[NSMutableArray alloc] init]); |
- NSButton* button = [[CWButton alloc] initWithFrame:NSZeroRect]; |
- [button setTitle:title]; |
- [button setKeyEquivalent:keyEquivalent]; |
- [buttons_ addObject:button]; |
- [[window_ contentView] addSubview:button]; |
-} |
- |
-- (void)layout { |
- // Button width |
- CGFloat buttonWidth = 0; |
- for (NSButton* button in buttons_.get()) { |
- [button sizeToFit]; |
- NSSize size = [button frame].size; |
- if (size.width < kButtonMinWidth) { |
- size.width = kButtonMinWidth; |
- [button setFrameSize:size]; |
- } |
- buttonWidth += size.width; |
- } |
- buttonWidth += ([buttons_ count] - 1) * kButtonGap; |
- |
- // Window width. |
- CGFloat windowWidth = buttonWidth; |
- if (accessoryView_.get()) |
- windowWidth = std::max(windowWidth, NSWidth([accessoryView_ frame])); |
- windowWidth += ConstrainedWindow::kHorizontalPadding * 2; |
- windowWidth = std::max(windowWidth, kWindowMinWidth); |
- |
- // Layout controls |
- [self layoutButtonsWithWindowWidth:windowWidth]; |
- CGFloat curY = NSMaxY([[buttons_ lastObject] frame]); |
- curY = [self layoutAccessoryViewAtYPos:curY]; |
- curY = [self layoutTextField:informativeTextField_ |
- yPos:curY |
- windowWidth:windowWidth]; |
- curY = [self layoutTextField:messageTextField_ |
- yPos:curY |
- windowWidth:windowWidth - kCloseButtonSize - kButtonGap]; |
- [self layoutCloseButtonWithWindowWidth:windowWidth]; |
- |
- // Update window frame |
- curY += ConstrainedWindow::kVerticalPadding; |
- [window_ setFrame:NSMakeRect(0, 0, windowWidth, curY) |
- display:NO]; |
-} |
- |
-- (void)layoutButtonsWithWindowWidth: (CGFloat)windowWidth { |
- // Layout first 2 button right to left. |
- CGFloat curX = windowWidth - ConstrainedWindow::kHorizontalPadding; |
- const int buttonCount = [buttons_ count]; |
- DCHECK_GE(buttonCount, 2); |
- for (int i = 0; i < 2; ++i) { |
- NSButton* button = [buttons_ objectAtIndex:i]; |
- NSRect rect = [button frame]; |
- rect.origin.x = curX - NSWidth(rect); |
- rect.origin.y = ConstrainedWindow::kVerticalPadding; |
- [button setFrameOrigin:rect.origin]; |
- curX = NSMinX(rect) - kButtonGap; |
- } |
- |
- // Layout remaining buttons left to right. |
- curX = ConstrainedWindow::kHorizontalPadding; |
- for (int i = buttonCount - 1; i >= 2; --i) { |
- NSButton* button = [buttons_ objectAtIndex:i]; |
- [button setFrameOrigin: |
- NSMakePoint(curX, ConstrainedWindow::kVerticalPadding)]; |
- curX += NSMaxX([button frame]) + kButtonGap; |
- } |
-} |
- |
-- (CGFloat)layoutTextField:(NSTextField*)textField |
- yPos:(CGFloat)yPos |
- windowWidth:(CGFloat)windowWidth { |
- if (![[textField stringValue] length]) { |
- [textField setHidden:YES]; |
- return yPos; |
- } |
- |
- [textField setHidden:NO]; |
- NSRect rect; |
- rect.size = CalculateDesiredSizeForWidth( |
- textField, windowWidth - ConstrainedWindow::kHorizontalPadding * 2); |
- rect.origin.y = yPos + ConstrainedWindow::kRowPadding; |
- rect.origin.x = ConstrainedWindow::kHorizontalPadding; |
- [textField setFrame:rect]; |
- return NSMaxY(rect); |
-} |
- |
-- (CGFloat)layoutAccessoryViewAtYPos:(CGFloat)yPos { |
- if (!accessoryView_.get()) |
- return yPos; |
- NSRect frame = [accessoryView_ frame]; |
- frame.origin.y = yPos + ConstrainedWindow::kRowPadding; |
- frame.origin.x = ConstrainedWindow::kHorizontalPadding; |
- [accessoryView_ setFrameOrigin:frame.origin]; |
- return NSMaxY(frame); |
-} |
- |
-- (void)layoutCloseButtonWithWindowWidth:(CGFloat)windowWidth { |
- NSRect frame; |
- frame.size.width = kCloseButtonSize; |
- frame.size.height = kCloseButtonSize; |
- frame.origin.x = |
- windowWidth - ConstrainedWindow::kHorizontalPadding - NSWidth(frame); |
- frame.origin.y = NSMaxY([messageTextField_ frame]) - NSHeight(frame); |
- [closeButton_ setFrame:frame]; |
-} |
- |
-@end |