Index: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa.mm |
diff --git a/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa.mm b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..968eb8fdb474b2a5fe45d73ba69c3de2ea971a9e |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa.mm |
@@ -0,0 +1,140 @@ |
+// Copyright (c) 2015 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. |
+ |
+#include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
+#include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_cocoa.h" |
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
+#include "chrome/browser/ui/chrome_style.h" |
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h" |
+#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h" |
+#import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
+#include "grit/generated_resources.h" |
+#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
+#include "ui/base/cocoa/window_size_constants.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+namespace { |
+ |
+const CGFloat kButtonGap = 6; |
groby-ooo-7-16
2015/02/06 03:06:19
nit: 6.0f - it's a float :)
bondd
2015/02/09 19:21:00
Done.
|
+ |
+} // namespace |
+ |
+namespace autofill { |
+ |
+// static |
+CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( |
+ CardUnmaskPromptController* controller) { |
+ return new CardUnmaskPromptCocoa(controller); |
+} |
+ |
+CardUnmaskPromptCocoa::CardUnmaskPromptCocoa( |
+ CardUnmaskPromptController* controller) |
+ : controller_(controller) { |
+ sheet_controller_.reset([[CardUnmaskPromptWindowController alloc] |
+ initWithWebContents:controller_->GetWebContents() |
+ cardUnmaskPrompt:this]); |
+ base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
+ [[CustomConstrainedWindowSheet alloc] |
+ initWithCustomWindow:[sheet_controller_ window]]); |
+ constrained_window_.reset( |
+ new ConstrainedWindowMac(this, controller_->GetWebContents(), sheet)); |
+} |
+ |
+CardUnmaskPromptCocoa::~CardUnmaskPromptCocoa() { |
+} |
+ |
+void CardUnmaskPromptCocoa::ControllerGone() { |
+} |
+ |
+void CardUnmaskPromptCocoa::DisableAndWaitForVerification() { |
+} |
+ |
+void CardUnmaskPromptCocoa::GotVerificationResult(bool success) { |
+} |
+ |
+void CardUnmaskPromptCocoa::OnConstrainedWindowClosed( |
+ ConstrainedWindowMac* window) { |
+ constrained_window_.reset(); |
+ // |this| belongs to |controller_|, so no self-destruction here. |
groby-ooo-7-16
2015/02/06 03:06:19
You can probably skip this comment
bondd
2015/02/09 19:21:00
Done.
|
+ controller_->OnUnmaskDialogClosed(); |
+} |
+ |
+void CardUnmaskPromptCocoa::PerformClose() { |
+ controller_->OnUnmaskDialogClosed(); |
+ constrained_window_->CloseWebContentsModalDialog(); |
groby-ooo-7-16
2015/02/06 03:06:19
This seems odd - CloseWebContentsModalDialog shoul
bondd
2015/02/09 19:21:00
Done.
|
+} |
+ |
+} // autofill |
+ |
+#pragma mark Window Controller |
+ |
+@implementation CardUnmaskPromptWindowController |
+ |
+- (id)initWithWebContents:(content::WebContents*)webContents |
+ cardUnmaskPrompt:(autofill::CardUnmaskPromptCocoa*)cardUnmaskPrompt { |
+ DCHECK(webContents); |
+ |
+ NSRect frame = NSMakeRect(0, 0, 550, 600); |
+ base::scoped_nsobject<ConstrainedWindowCustomWindow> window( |
+ [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]); |
+ if ((self = [super initWithWindow:window])) { |
+ webContents_ = webContents; |
+ cardUnmaskPrompt_ = cardUnmaskPrompt; |
+ |
+ [self buildWindowButtons]; |
+ [self layoutButtons]; |
+ } |
+ return self; |
+} |
+ |
+- (IBAction)closeSheet:(id)sender { |
+ cardUnmaskPrompt_->PerformClose(); |
+} |
+ |
+- (void)buildWindowButtons { |
+ if (buttonContainer_.get()) |
groby-ooo-7-16
2015/02/06 03:06:19
Is that called repeatedly? Otherwise, why check |b
bondd
2015/02/09 19:21:00
Done.
|
+ return; |
+ |
+ buttonContainer_.reset([[GTMWidthBasedTweaker alloc] initWithFrame: |
+ ui::kWindowSizeDeterminedLater]); |
groby-ooo-7-16
2015/02/06 03:06:19
NSZeroRect is fine. ui::kWindowSizeDeterminedLater
bondd
2015/02/09 19:21:00
Done.
|
+ [buttonContainer_ |
+ setAutoresizingMask:(NSViewMinXMargin | NSViewMinYMargin)]; |
+ |
+ base::scoped_nsobject<NSButton> button( |
+ [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
+ [button setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; |
+ [button setKeyEquivalent:kKeyEquivalentEscape]; |
+ [button setTarget:self]; |
+ [button setAction:@selector(closeSheet:)]; |
+ [button sizeToFit]; |
+ [buttonContainer_ addSubview:button]; |
+ |
+ CGFloat nextX = NSMaxX([button frame]) + kButtonGap; |
+ button.reset([[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
+ [button setFrameOrigin:NSMakePoint(nextX, 0)]; |
groby-ooo-7-16
2015/02/09 20:25:02
That's what I meant when talking about the tweaker
bondd
2015/02/09 23:07:32
Done.
|
+ [button setTitle:l10n_util::GetNSStringWithFixup( |
+ IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON)]; |
+ [button setKeyEquivalent:kKeyEquivalentReturn]; |
+ [button setTarget:self]; |
+ [button setAction:@selector(closeSheet:)]; |
+ [button sizeToFit]; |
+ [buttonContainer_ addSubview:button]; |
+ |
+ const CGFloat dialogOffset = NSWidth([[self window] frame]) - |
+ chrome_style::kHorizontalPadding - NSMaxX([button frame]); |
+ [buttonContainer_ setFrame: |
+ NSMakeRect(dialogOffset, chrome_style::kClientBottomPadding, |
+ NSMaxX([button frame]), NSMaxY([button frame]))]; |
+ |
+ [[[self window] contentView] addSubview:buttonContainer_]; |
+} |
+ |
+- (void)layoutButtons { |
+ base::scoped_nsobject<GTMUILocalizerAndLayoutTweaker> layoutTweaker( |
groby-ooo-7-16
2015/02/06 03:06:19
-buildButtons already lays things out - I don't th
bondd
2015/02/09 19:21:00
Done.
|
+ [[GTMUILocalizerAndLayoutTweaker alloc] init]); |
+ [layoutTweaker tweakUI:buttonContainer_]; |
+} |
+ |
+@end |
+ |