Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.mm |
| diff --git a/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.mm b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..242e1f6717b8fa94462afbd925ad678ceda36ec9 |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.mm |
| @@ -0,0 +1,128 @@ |
| +// 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_bridge.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" |
| +#include "ui/base/cocoa/window_size_constants.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +namespace { |
| + |
|
groby-ooo-7-16
2015/02/13 01:53:40
Kill a newline, save a whitespace;) (Here and at e
bondd
2015/02/13 02:37:13
Done.
|
| +const CGFloat kButtonGap = 6.0f; |
| + |
| +} // namespace |
| + |
| +namespace autofill { |
| + |
| +// static |
| +CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( |
| + CardUnmaskPromptController* controller) { |
| + return new CardUnmaskPromptBridge(controller); |
| +} |
| + |
| +CardUnmaskPromptBridge::CardUnmaskPromptBridge( |
| + CardUnmaskPromptController* controller) |
| + : controller_(controller) { |
| + sheet_controller_.reset([[CardUnmaskPromptCocoa alloc] |
| + initWithWebContents:controller_->GetWebContents() |
| + bridge:this]); |
| + base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| + [[CustomConstrainedWindowSheet alloc] |
| + initWithCustomWindow:[sheet_controller_ window]]); |
| + constrained_window_.reset( |
| + new ConstrainedWindowMac(this, controller_->GetWebContents(), sheet)); |
| +} |
| + |
| +CardUnmaskPromptBridge::~CardUnmaskPromptBridge() { |
| +} |
| + |
| +void CardUnmaskPromptBridge::ControllerGone() { |
| +} |
| + |
| +void CardUnmaskPromptBridge::DisableAndWaitForVerification() { |
| +} |
| + |
| +void CardUnmaskPromptBridge::GotVerificationResult(bool success) { |
| +} |
| + |
| +void CardUnmaskPromptBridge::CancelForTesting() { |
| + PerformClose(); |
| +} |
| + |
| +void CardUnmaskPromptBridge::OnConstrainedWindowClosed( |
| + ConstrainedWindowMac* window) { |
| + constrained_window_.reset(); |
| + controller_->OnUnmaskDialogClosed(); |
| +} |
| + |
| +void CardUnmaskPromptBridge::PerformClose() { |
| + constrained_window_->CloseWebContentsModalDialog(); |
| +} |
| + |
| +} // autofill |
| + |
| +#pragma mark CardUnmaskPromptCocoa |
|
groby-ooo-7-16
2015/02/13 01:53:40
Only #pragma mark if it actually helps you editing
bondd
2015/02/13 02:37:13
Done. Added #pragma CardUnmaskPromptBridge as well
|
| + |
| +@implementation CardUnmaskPromptCocoa |
| + |
| +- (id)initWithWebContents:(content::WebContents*)webContents |
| + bridge:(autofill::CardUnmaskPromptBridge*)bridge { |
| + 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; |
| + cardUnmaskPromptBridge_ = bridge; |
| + |
| + [self buildWindowButtons]; |
| + } |
| + return self; |
| +} |
| + |
| +- (IBAction)closeSheet:(id)sender { |
| + cardUnmaskPromptBridge_->PerformClose(); |
| +} |
| + |
| +- (void)buildWindowButtons { |
| + buttonContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); |
| + |
| + 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)]; |
| + [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_]; |
| +} |
| + |
| +@end |