Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.mm

Issue 904613006: Autofill: First step toward CVC unmask prompt dialog on OSX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address groby@ comments for patch set 8. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 const CGFloat kButtonGap = 6.0f;
18 } // namespace
19
20 namespace autofill {
21
22 // static
23 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow(
24 CardUnmaskPromptController* controller) {
25 return new CardUnmaskPromptBridge(controller);
26 }
27
28 #pragma mark CardUnmaskPromptBridge
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 DCHECK(bridge);
79
80 NSRect frame = NSMakeRect(0, 0, 550, 600);
81 base::scoped_nsobject<ConstrainedWindowCustomWindow> window(
82 [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]);
83 if ((self = [super initWithWindow:window])) {
84 webContents_ = webContents;
85 cardUnmaskPromptBridge_ = bridge;
86
87 [self buildWindowButtons];
88 }
89 return self;
90 }
91
92 - (IBAction)closeSheet:(id)sender {
93 cardUnmaskPromptBridge_->PerformClose();
94 }
95
96 - (void)buildWindowButtons {
97 base::scoped_nsobject<NSView> buttonContainer(
98 [[NSView alloc] initWithFrame:NSZeroRect]);
99
100 base::scoped_nsobject<NSButton> button(
101 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]);
102 [button setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)];
103 [button setKeyEquivalent:kKeyEquivalentEscape];
104 [button setTarget:self];
105 [button setAction:@selector(closeSheet:)];
106 [button sizeToFit];
107 [buttonContainer addSubview:button];
108
109 CGFloat nextX = NSMaxX([button frame]) + kButtonGap;
110 button.reset([[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]);
111 [button setFrameOrigin:NSMakePoint(nextX, 0)];
112 [button setTitle:l10n_util::GetNSStringWithFixup(
113 IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON)];
114 [button setKeyEquivalent:kKeyEquivalentReturn];
115 [button setTarget:self];
116 [button setAction:@selector(closeSheet:)];
117 [button sizeToFit];
118 [buttonContainer addSubview:button];
119
120 const CGFloat dialogOffset = NSWidth([[self window] frame]) -
121 chrome_style::kHorizontalPadding -
122 NSMaxX([button frame]);
123 [buttonContainer
124 setFrame:NSMakeRect(dialogOffset, chrome_style::kClientBottomPadding,
125 NSMaxX([button frame]), NSMaxY([button frame]))];
126
127 [[[self window] contentView] addSubview:buttonContainer];
128 }
129
130 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698