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_cocoa.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 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | |
| 14 #include "ui/base/cocoa/window_size_constants.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 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.
| |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 namespace autofill { | |
| 24 | |
| 25 // static | |
| 26 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( | |
| 27 CardUnmaskPromptController* controller) { | |
| 28 return new CardUnmaskPromptCocoa(controller); | |
| 29 } | |
| 30 | |
| 31 CardUnmaskPromptCocoa::CardUnmaskPromptCocoa( | |
| 32 CardUnmaskPromptController* controller) | |
| 33 : controller_(controller) { | |
| 34 sheet_controller_.reset([[CardUnmaskPromptWindowController alloc] | |
| 35 initWithWebContents:controller_->GetWebContents() | |
| 36 cardUnmaskPrompt:this]); | |
| 37 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | |
| 38 [[CustomConstrainedWindowSheet alloc] | |
| 39 initWithCustomWindow:[sheet_controller_ window]]); | |
| 40 constrained_window_.reset( | |
| 41 new ConstrainedWindowMac(this, controller_->GetWebContents(), sheet)); | |
| 42 } | |
| 43 | |
| 44 CardUnmaskPromptCocoa::~CardUnmaskPromptCocoa() { | |
| 45 } | |
| 46 | |
| 47 void CardUnmaskPromptCocoa::ControllerGone() { | |
| 48 } | |
| 49 | |
| 50 void CardUnmaskPromptCocoa::DisableAndWaitForVerification() { | |
| 51 } | |
| 52 | |
| 53 void CardUnmaskPromptCocoa::GotVerificationResult(bool success) { | |
| 54 } | |
| 55 | |
| 56 void CardUnmaskPromptCocoa::OnConstrainedWindowClosed( | |
| 57 ConstrainedWindowMac* window) { | |
| 58 constrained_window_.reset(); | |
| 59 // |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.
| |
| 60 controller_->OnUnmaskDialogClosed(); | |
| 61 } | |
| 62 | |
| 63 void CardUnmaskPromptCocoa::PerformClose() { | |
| 64 controller_->OnUnmaskDialogClosed(); | |
| 65 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.
| |
| 66 } | |
| 67 | |
| 68 } // autofill | |
| 69 | |
| 70 #pragma mark Window Controller | |
| 71 | |
| 72 @implementation CardUnmaskPromptWindowController | |
| 73 | |
| 74 - (id)initWithWebContents:(content::WebContents*)webContents | |
| 75 cardUnmaskPrompt:(autofill::CardUnmaskPromptCocoa*)cardUnmaskPrompt { | |
| 76 DCHECK(webContents); | |
| 77 | |
| 78 NSRect frame = NSMakeRect(0, 0, 550, 600); | |
| 79 base::scoped_nsobject<ConstrainedWindowCustomWindow> window( | |
| 80 [[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]); | |
| 81 if ((self = [super initWithWindow:window])) { | |
| 82 webContents_ = webContents; | |
| 83 cardUnmaskPrompt_ = cardUnmaskPrompt; | |
| 84 | |
| 85 [self buildWindowButtons]; | |
| 86 [self layoutButtons]; | |
| 87 } | |
| 88 return self; | |
| 89 } | |
| 90 | |
| 91 - (IBAction)closeSheet:(id)sender { | |
| 92 cardUnmaskPrompt_->PerformClose(); | |
| 93 } | |
| 94 | |
| 95 - (void)buildWindowButtons { | |
| 96 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.
| |
| 97 return; | |
| 98 | |
| 99 buttonContainer_.reset([[GTMWidthBasedTweaker alloc] initWithFrame: | |
| 100 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.
| |
| 101 [buttonContainer_ | |
| 102 setAutoresizingMask:(NSViewMinXMargin | NSViewMinYMargin)]; | |
| 103 | |
| 104 base::scoped_nsobject<NSButton> button( | |
| 105 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | |
| 106 [button setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; | |
| 107 [button setKeyEquivalent:kKeyEquivalentEscape]; | |
| 108 [button setTarget:self]; | |
| 109 [button setAction:@selector(closeSheet:)]; | |
| 110 [button sizeToFit]; | |
| 111 [buttonContainer_ addSubview:button]; | |
| 112 | |
| 113 CGFloat nextX = NSMaxX([button frame]) + kButtonGap; | |
| 114 button.reset([[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | |
| 115 [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.
| |
| 116 [button setTitle:l10n_util::GetNSStringWithFixup( | |
| 117 IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON)]; | |
| 118 [button setKeyEquivalent:kKeyEquivalentReturn]; | |
| 119 [button setTarget:self]; | |
| 120 [button setAction:@selector(closeSheet:)]; | |
| 121 [button sizeToFit]; | |
| 122 [buttonContainer_ addSubview:button]; | |
| 123 | |
| 124 const CGFloat dialogOffset = NSWidth([[self window] frame]) - | |
| 125 chrome_style::kHorizontalPadding - NSMaxX([button frame]); | |
| 126 [buttonContainer_ setFrame: | |
| 127 NSMakeRect(dialogOffset, chrome_style::kClientBottomPadding, | |
| 128 NSMaxX([button frame]), NSMaxY([button frame]))]; | |
| 129 | |
| 130 [[[self window] contentView] addSubview:buttonContainer_]; | |
| 131 } | |
| 132 | |
| 133 - (void)layoutButtons { | |
| 134 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.
| |
| 135 [[GTMUILocalizerAndLayoutTweaker alloc] init]); | |
| 136 [layoutTweaker tweakUI:buttonContainer_]; | |
| 137 } | |
| 138 | |
| 139 @end | |
| 140 | |
| OLD | NEW |