Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | |
| 6 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.h" | |
| 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | |
| 8 #include "chrome/browser/ui/chrome_style.h" | |
| 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" | |
| 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" | |
| 11 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | |
| 12 #include "grit/generated_resources.h" | |
| 13 #include "ui/base/cocoa/window_size_constants.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const CGFloat kButtonGap = 6.0f; | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 namespace autofill { | |
| 23 | |
| 24 // static | |
| 25 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( | |
| 26 CardUnmaskPromptController* controller) { | |
| 27 return new CardUnmaskPromptBridge(controller); | |
| 28 } | |
| 29 | |
| 30 CardUnmaskPromptBridge::CardUnmaskPromptBridge( | |
| 31 CardUnmaskPromptController* controller) | |
| 32 : controller_(controller) { | |
| 33 sheet_controller_.reset([[CardUnmaskPromptCocoa alloc] | |
| 34 initWithWebContents:controller_->GetWebContents() | |
| 35 bridge:this]); | |
| 36 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | |
| 37 [[CustomConstrainedWindowSheet alloc] | |
| 38 initWithCustomWindow:[sheet_controller_ window]]); | |
| 39 constrained_window_.reset( | |
| 40 new ConstrainedWindowMac(this, controller_->GetWebContents(), sheet)); | |
| 41 } | |
| 42 | |
| 43 CardUnmaskPromptBridge::~CardUnmaskPromptBridge() { | |
| 44 } | |
| 45 | |
| 46 void CardUnmaskPromptBridge::ControllerGone() { | |
| 47 } | |
| 48 | |
| 49 void CardUnmaskPromptBridge::DisableAndWaitForVerification() { | |
| 50 } | |
| 51 | |
| 52 void CardUnmaskPromptBridge::GotVerificationResult(bool success) { | |
| 53 } | |
| 54 | |
| 55 void CardUnmaskPromptBridge::CancelForTesting() { | |
| 56 PerformClose(); | |
| 57 } | |
| 58 | |
| 59 void CardUnmaskPromptBridge::OnConstrainedWindowClosed( | |
| 60 ConstrainedWindowMac* window) { | |
| 61 constrained_window_.reset(); | |
| 62 controller_->OnUnmaskDialogClosed(); | |
| 63 } | |
| 64 | |
| 65 void CardUnmaskPromptBridge::PerformClose() { | |
| 66 constrained_window_->CloseWebContentsModalDialog(); | |
| 67 } | |
| 68 | |
| 69 } // autofill | |
| 70 | |
| 71 #pragma mark CardUnmaskPromptCocoa | |
| 72 | |
| 73 @implementation CardUnmaskPromptCocoa | |
| 74 | |
| 75 - (id)initWithWebContents:(content::WebContents*)webContents | |
| 76 bridge:(autofill::CardUnmaskPromptBridge*)bridge { | |
| 77 DCHECK(webContents); | |
| 78 | |
| 79 NSRect frame = NSMakeRect(0, 0, 550, 600); | |
| 80 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( | |
| 81 [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]); | |
| 82 if ((self = [super initWithWindow:window])) { | |
| 83 webContents_ = webContents; | |
| 84 cardUnmaskPromptBridge_ = bridge; | |
| 85 | |
| 86 [self buildWindowButtons]; | |
| 87 } | |
| 88 return self; | |
| 89 } | |
| 90 | |
| 91 - (IBAction)closeSheet:(id)sender { | |
| 92 cardUnmaskPromptBridge_->PerformClose(); | |
| 93 } | |
| 94 | |
| 95 - (void)buildWindowButtons { | |
| 96 buttonContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); | |
| 97 [buttonContainer_ setAutoresizingMask:(NSViewMinXMargin | NSViewMinYMargin)]; | |
|
groby-ooo-7-16
2015/02/12 00:51:55
N.B: You only need autoresizingmask if you plan to
bondd
2015/02/12 19:07:22
Done.
| |
| 98 | |
| 99 base::scoped_nsobject<NSButton> button( | |
| 100 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | |
| 101 [button setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; | |
| 102 [button setKeyEquivalent:kKeyEquivalentEscape]; | |
| 103 [button setTarget:self]; | |
| 104 [button setAction:@selector(closeSheet:)]; | |
| 105 [button sizeToFit]; | |
| 106 [buttonContainer_ addSubview:button]; | |
| 107 | |
| 108 CGFloat nextX = NSMaxX([button frame]) + kButtonGap; | |
| 109 button.reset([[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | |
| 110 [button setFrameOrigin:NSMakePoint(nextX, 0)]; | |
| 111 [button setTitle:l10n_util::GetNSStringWithFixup( | |
| 112 IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON)]; | |
| 113 [button setKeyEquivalent:kKeyEquivalentReturn]; | |
| 114 [button setTarget:self]; | |
| 115 [button setAction:@selector(closeSheet:)]; | |
| 116 [button sizeToFit]; | |
| 117 [buttonContainer_ addSubview:button]; | |
| 118 | |
| 119 const CGFloat dialogOffset = NSWidth([[self window] frame]) - | |
| 120 chrome_style::kHorizontalPadding - | |
| 121 NSMaxX([button frame]); | |
| 122 [buttonContainer_ | |
| 123 setFrame:NSMakeRect(dialogOffset, chrome_style::kClientBottomPadding, | |
| 124 NSMaxX([button frame]), NSMaxY([button frame]))]; | |
| 125 | |
| 126 [[[self window] contentView] addSubview:buttonContainer_]; | |
| 127 } | |
| 128 | |
| 129 @end | |
| OLD | NEW |