 Chromium Code Reviews
 Chromium Code Reviews Issue 1014683007:
  Autofill OSX: Add "Verifying card" / "Your card is verified" status overlay.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1014683007:
  Autofill OSX: Add "Verifying card" / "Your card is verified" status overlay.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm | 
| diff --git a/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm | 
| index 65d78c8e9492f24121f857dfa37c54ce999c38fc..4c4dba172276458b336ea69d769765c0d64ff7ef 100644 | 
| --- a/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm | 
| +++ b/chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm | 
| @@ -2,6 +2,8 @@ | 
| // Use of this source code is governed by a BSD-style license that can be | 
| // found in the LICENSE file. | 
| +#include "base/bind.h" | 
| +#include "base/message_loop/message_loop.h" | 
| #include "base/strings/sys_string_conversions.h" | 
| #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 
| #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | 
| @@ -21,6 +23,8 @@ namespace { | 
| const CGFloat kButtonGap = 6.0f; | 
| const CGFloat kDialogContentMinWidth = 210.0f; | 
| const CGFloat kCvcInputWidth = 64.0f; | 
| +const ui::ResourceBundle::FontStyle kProgressFontStyle = | 
| + chrome_style::kTitleFontStyle; | 
| } // namespace | 
| @@ -59,15 +63,26 @@ void CardUnmaskPromptViewBridge::ControllerGone() { | 
| } | 
| void CardUnmaskPromptViewBridge::DisableAndWaitForVerification() { | 
| - [view_controller_ setInputsEnabled:false]; | 
| - [view_controller_ updateVerifyButtonEnabled]; | 
| + [view_controller_ setProgressOverlayText: | 
| + l10n_util::GetStringUTF16( | 
| + IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_IN_PROGRESS)]; | 
| } | 
| void CardUnmaskPromptViewBridge::GotVerificationResult( | 
| const base::string16& error_message, | 
| bool allow_retry) { | 
| - [view_controller_ setInputsEnabled:true]; | 
| - [view_controller_ updateVerifyButtonEnabled]; | 
| + if (error_message.empty()) { | 
| + [view_controller_ setProgressOverlayText: | 
| + l10n_util::GetStringUTF16( | 
| + IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)]; | 
| + | 
| + base::MessageLoop::current()->PostDelayedTask( | 
| + FROM_HERE, base::Bind(&CardUnmaskPromptViewBridge::PerformClose, | 
| + base::Unretained(this)), | 
| 
groby-ooo-7-16
2015/03/19 05:15:38
Unretained this? What happens if you close the dia
 
bondd
2015/03/19 21:43:37
Done. Same solution as estade@'s here:
https://cod
 | 
| + base::TimeDelta::FromSeconds(1)); | 
| + } else { | 
| + [view_controller_ setProgressOverlayText:base::string16()]; | 
| + } | 
| } | 
| void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( | 
| @@ -94,6 +109,8 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| base::scoped_nsobject<NSPopUpButton> monthPopup_; | 
| base::scoped_nsobject<NSPopUpButton> yearPopup_; | 
| base::scoped_nsobject<NSButton> verifyButton_; | 
| + base::scoped_nsobject<NSView> inputRow_; | 
| + base::scoped_nsobject<NSTextField> progressOverlayText_; | 
| int monthPopupDefaultIndex_; | 
| int yearPopupDefaultIndex_; | 
| @@ -141,10 +158,18 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| return self; | 
| } | 
| -- (void)setInputsEnabled:(BOOL)enabled { | 
| - [cvcInput_ setEnabled:enabled]; | 
| - [monthPopup_ setEnabled:enabled]; | 
| - [yearPopup_ setEnabled:enabled]; | 
| +- (void)setProgressOverlayText:(const base::string16&)text { | 
| + if (!text.empty()) { | 
| + NSAttributedString* attributedString = | 
| + constrained_window::GetAttributedLabelString( | 
| + SysUTF16ToNSString(text), kProgressFontStyle, NSCenterTextAlignment, | 
| + NSLineBreakByWordWrapping); | 
| + [progressOverlayText_ setAttributedStringValue:attributedString]; | 
| + } | 
| + | 
| + [progressOverlayText_ setHidden:text.empty()]; | 
| + [inputRow_ setHidden:!text.empty()]; | 
| + [self updateVerifyButtonEnabled]; | 
| } | 
| - (void)updateVerifyButtonEnabled { | 
| @@ -152,7 +177,7 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| DCHECK(controller); | 
| BOOL enable = | 
| - [cvcInput_ isEnabled] && | 
| + ![inputRow_ isHidden] && | 
| controller->InputCvcIsValid( | 
| base::SysNSStringToUTF16([cvcInput_ stringValue])) && | 
| (!monthPopup_ || | 
| @@ -198,9 +223,8 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| [mainView | 
| setContentViewMargins:NSMakeSize(chrome_style::kHorizontalPadding, 0)]; | 
| - base::scoped_nsobject<NSView> inputRowView( | 
| - [[NSView alloc] initWithFrame:NSZeroRect]); | 
| - [mainView addSubview:inputRowView]; | 
| + inputRow_.reset([[NSView alloc] initWithFrame:NSZeroRect]); | 
| + [mainView addSubview:inputRow_]; | 
| // Title label. | 
| NSTextField* title = constrained_window::CreateLabel(); | 
| @@ -254,7 +278,7 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| NSUnionRect([monthPopup_ frame], [yearPopup_ frame]); | 
| expirationFrame.size.width += kButtonGap; | 
| [expirationView setFrame:expirationFrame]; | 
| - [inputRowView addSubview:expirationView]; | 
| + [inputRow_ addSubview:expirationView]; | 
| } | 
| // CVC text input. | 
| @@ -267,7 +291,7 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| [cvcInput_ sizeToFit]; | 
| [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView frame]), 0, | 
| kCvcInputWidth, NSHeight([cvcInput_ frame]))]; | 
| - [inputRowView addSubview:cvcInput_]; | 
| + [inputRow_ addSubview:cvcInput_]; | 
| // CVC image. | 
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 
| @@ -279,7 +303,7 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| [cvcImageView setFrameSize:[cvcImage size]]; | 
| [cvcImageView | 
| setFrameOrigin:NSMakePoint(NSMaxX([cvcInput_ frame]) + kButtonGap, 0)]; | 
| - [inputRowView addSubview:cvcImageView]; | 
| + [inputRow_ addSubview:cvcImageView]; | 
| // Cancel button. | 
| base::scoped_nsobject<NSButton> cancelButton( | 
| @@ -303,13 +327,13 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| [self updateVerifyButtonEnabled]; | 
| [mainView addSubview:verifyButton_]; | 
| - // Layout inputRowView. | 
| - [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView]; | 
| - [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView]; | 
| + // Layout inputRow_. | 
| + [CardUnmaskPromptViewCocoa sizeToFitView:inputRow_]; | 
| + [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRow_]; | 
| // Calculate dialog content width. | 
| CGFloat contentWidth = | 
| - std::max(NSWidth([title frame]), NSWidth([inputRowView frame])); | 
| + std::max(NSWidth([title frame]), NSWidth([inputRow_ frame])); | 
| contentWidth = std::max(contentWidth, kDialogContentMinWidth); | 
| // Layout mainView contents, starting at the bottom and moving up. | 
| @@ -325,11 +349,11 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| NSMinY([verifyButton_ frame]))]; | 
| // Input row. | 
| - [inputRowView setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton frame]) + | 
| - chrome_style::kRowPadding)]; | 
| + [inputRow_ setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton frame]) + | 
| + chrome_style::kRowPadding)]; | 
| // Instruction label. | 
| - [instructions setFrameOrigin:NSMakePoint(0, NSMaxY([inputRowView frame]) + | 
| + [instructions setFrameOrigin:NSMakePoint(0, NSMaxY([inputRow_ frame]) + | 
| chrome_style::kRowPadding)]; | 
| NSSize instructionsSize = [[instructions cell] | 
| cellSizeForBounds:NSMakeRect(0, 0, contentWidth, CGFLOAT_MAX)]; | 
| @@ -345,6 +369,20 @@ void CardUnmaskPromptViewBridge::PerformClose() { | 
| contentWidth + [mainView contentViewMargins].width * 2.0, | 
| NSMaxY([title frame]) + chrome_style::kTitleTopPadding)]; | 
| + // Add progress overlay. | 
| + progressOverlayText_.reset([constrained_window::CreateLabel() retain]); | 
| + const gfx::Font& progressFont = | 
| + ui::ResourceBundle::GetSharedInstance().GetFont(kProgressFontStyle); | 
| + base::scoped_nsobject<NSLayoutManager> layoutManager( | 
| 
groby-ooo-7-16
2015/03/19 05:15:38
Whoa, that's a lot of code :)
Why not progressFon
 
bondd
2015/03/19 21:43:37
Done.
 | 
| + [[NSLayoutManager alloc] init]); | 
| + CGFloat progressHeight = | 
| + [layoutManager defaultLineHeightForFont:progressFont.GetNativeFont()]; | 
| + [progressOverlayText_ setFrame:NSMakeRect(0, ceil(NSMidY([inputRow_ frame]) - | 
| 
groby-ooo-7-16
2015/03/19 05:15:38
That's an interesting calculation... I'm not sure
 
bondd
2015/03/19 21:43:37
Done. Answered in comment.
Is there an easier way
 | 
| + progressHeight * 0.5), | 
| + contentWidth, progressHeight)]; | 
| + [progressOverlayText_ setHidden:YES]; | 
| + [mainView addSubview:progressOverlayText_]; | 
| + | 
| [self setView:mainView]; | 
| } |