Chromium Code Reviews| Index: chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.mm b/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..97575a94be87b51de4cb3e81594043b49e45f690 |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_never_save_view_controller.mm |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2014 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/passwords/manage_passwords_bubble_never_save_view_controller.h" |
| + |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| +#include "grit/generated_resources.h" |
| +#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +@interface ManagePasswordsBubbleNeverSaveViewController () |
| +- (void)onConfirmClicked; |
| +- (void)onUndoClicked; |
| +@end |
| + |
| +@implementation ManagePasswordsBubbleNeverSaveViewController |
| + |
| +- (id)initWithModel:(ManagePasswordsBubbleModel*)model |
| + delegate:(id<ManagePasswordsBubbleNeverSaveViewDelegate>)delegate { |
| + if ((self = [super initWithNibName:nil bundle:nil])) { |
| + model_ = model; |
| + delegate_ = delegate; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)onConfirmClicked { |
|
Scott Hess - ex-Googler
2014/08/22 21:45:35
-(void)actionName:(id)sender;
dconnelly
2014/08/25 11:44:20
Done.
|
| + model_->OnNeverForThisSiteClicked(); |
| + [delegate_ viewShouldDismiss]; |
| +} |
| + |
| +- (void)onUndoClicked { |
|
Scott Hess - ex-Googler
2014/08/22 21:45:35
here too.
dconnelly
2014/08/25 11:44:20
Done.
|
| + [delegate_ neverSavePasswordCancelled]; |
| +} |
| + |
| +- (void)loadView { |
| + self.view = [[[NSView alloc] initWithFrame:NSZeroRect] autorelease]; |
| + |
| + // ----------------------------------- |
| + // | Title | |
| + // | | |
| + // | Confirmation! | |
| + // | | |
| + // | [Undo] [Confirm] | |
| + // ----------------------------------- |
| + |
| + // Create the elements and add them to the view. |
| + |
| + // Title. |
| + NSTextField* titleLabel = [self |
| + addTitleLabel:l10n_util::GetNSString( |
| + IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE)]; |
| + |
| + // Blacklist confirmation. |
| + NSTextField* confirmationLabel = [self |
| + addLabel:l10n_util::GetNSString( |
| + IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TEXT)]; |
| + |
| + // Undo button. |
| + undoButton_.reset([[self addButton:l10n_util::GetNSString(IDS_CANCEL) |
| + target:self |
| + action:@selector(onUndoClicked)] retain]); |
| + |
| + // Confirm button. |
| + confirmButton_.reset( |
| + [[self addButton:l10n_util::GetNSString( |
| + IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_BUTTON) |
| + target:self |
| + action:@selector(onConfirmClicked)] retain]); |
| + |
| + // Compute the bubble width using the title and confirmation labels. |
| + // The explanation label can wrap to multiple lines. |
| + const CGFloat minContentWidth = |
| + password_manager::mac::ui::kDesiredBubbleWidth - |
| + 2 * password_manager::mac::ui::kFramePadding; |
|
Scott Hess - ex-Googler
2014/08/22 21:45:35
using namespace password_manager::mac::ui;
dconnelly
2014/08/25 11:44:20
Done.
|
| + const CGFloat contentWidth = |
| + std::max(NSWidth(titleLabel.frame), minContentWidth); |
| + NSSize confirmationSize = confirmationLabel.frame.size; |
| + confirmationSize.width = contentWidth; |
| + [confirmationLabel setFrameSize:confirmationSize]; |
| + [GTMUILocalizerAndLayoutTweaker |
| + sizeToFitFixedWidthTextField:confirmationLabel]; |
| + const CGFloat width = password_manager::mac::ui::kFramePadding + |
| + contentWidth + password_manager::mac::ui::kFramePadding; |
| + |
| + // Layout the elements, starting at the bottom and moving up. |
| + |
| + // Buttons go on the bottom row and are right-aligned. |
| + // Start with [Confirm]. |
| + CGFloat curX = width - password_manager::mac::ui::kFramePadding - |
| + NSWidth([confirmButton_ frame]); |
| + CGFloat curY = password_manager::mac::ui::kFramePadding; |
| + [confirmButton_ setFrameOrigin:NSMakePoint(curX, curY)]; |
| + |
| + // [Undo] goes to the left of [Confirm]. |
| + curX = NSMinX([confirmButton_ frame]) - |
| + password_manager::mac::ui::kRelatedControlHorizontalPadding - |
| + NSWidth([undoButton_ frame]); |
| + [undoButton_ setFrameOrigin:NSMakePoint(curX, curY)]; |
| + |
| + // Confirmation label goes on the next row and is shifted right. |
| + curX = password_manager::mac::ui::kFramePadding; |
| + curY = NSMaxY([undoButton_ frame]) + |
| + password_manager::mac::ui::kUnrelatedControlVerticalPadding; |
| + [confirmationLabel setFrameOrigin:NSMakePoint(curX, curY)]; |
| + |
| + // Title goes at the top after some padding. |
| + curY = NSMaxY(confirmationLabel.frame) + |
| + password_manager::mac::ui::kUnrelatedControlVerticalPadding; |
| + [titleLabel setFrameOrigin:NSMakePoint(curX, curY)]; |
| + |
| + // Update the bubble size. |
| + const CGFloat height = |
| + NSMaxY([titleLabel frame]) + password_manager::mac::ui::kFramePadding; |
| + [self.view setFrame:NSMakeRect(0, 0, width, height)]; |
| +} |
| + |
| +@end |
| + |
| +@implementation ManagePasswordsBubbleNeverSaveViewController (Testing) |
| + |
| +- (NSButton*)undoButton { |
| + return undoButton_.get(); |
| +} |
| + |
| +- (NSButton*)confirmButton { |
| + return confirmButton_.get(); |
| +} |
| + |
| +@end |