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

Unified Diff: chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.mm

Issue 1014683007: Autofill OSX: Add "Verifying card" / "Your card is verified" status overlay. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
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..8e872003df430fbafdbbdf76d6b8d4e89830d926 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"
@@ -59,15 +61,32 @@ void CardUnmaskPromptViewBridge::ControllerGone() {
}
void CardUnmaskPromptViewBridge::DisableAndWaitForVerification() {
- [view_controller_ setInputsEnabled:false];
+ [view_controller_ setInputRowHidden:YES];
[view_controller_ updateVerifyButtonEnabled];
+
+ [view_controller_ setProgressOverlayText:
+ l10n_util::GetStringUTF16(
+ IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_IN_PROGRESS)];
+ [view_controller_ setProgressOverlayHidden:NO];
}
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)),
+ base::TimeDelta::FromSeconds(1));
bondd 2015/03/18 02:48:37 This call to PostDelayedTask is copied from the Vi
+ } else {
+ [view_controller_ setInputRowHidden:NO];
+ [view_controller_ setProgressOverlayHidden:YES];
+ [view_controller_ updateVerifyButtonEnabled];
+ }
}
void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed(
@@ -94,6 +113,9 @@ 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<NSView> progressOverlay_;
groby-ooo-7-16 2015/03/18 07:10:05 Why a separate view and not just a text field?
bondd 2015/03/18 22:01:40 Done.
+ base::scoped_nsobject<NSTextField> progressOverlayText_;
int monthPopupDefaultIndex_;
int yearPopupDefaultIndex_;
@@ -141,10 +163,26 @@ void CardUnmaskPromptViewBridge::PerformClose() {
return self;
}
-- (void)setInputsEnabled:(BOOL)enabled {
- [cvcInput_ setEnabled:enabled];
- [monthPopup_ setEnabled:enabled];
- [yearPopup_ setEnabled:enabled];
+- (void)setInputRowHidden:(BOOL)hidden {
+ [inputRow_ setHidden:hidden];
+}
+
+- (void)setProgressOverlayHidden:(BOOL)hidden {
+ [progressOverlay_ setHidden:hidden];
+}
+
+- (void)setProgressOverlayText:(const base::string16&)text {
+ NSAttributedString* attributedString =
+ constrained_window::GetAttributedLabelString(
+ SysUTF16ToNSString(text), chrome_style::kTitleFontStyle,
+ NSCenterTextAlignment, NSLineBreakByWordWrapping);
+ [progressOverlayText_ setAttributedStringValue:attributedString];
+
+ [progressOverlayText_ sizeToFit];
+ [progressOverlayText_
+ setFrameSize:NSMakeSize(NSWidth([progressOverlay_ frame]),
+ NSHeight([progressOverlayText_ frame]))];
+ [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:progressOverlay_];
}
- (void)updateVerifyButtonEnabled {
@@ -152,7 +190,7 @@ void CardUnmaskPromptViewBridge::PerformClose() {
DCHECK(controller);
BOOL enable =
- [cvcInput_ isEnabled] &&
+ ![inputRow_ isHidden] &&
controller->InputCvcIsValid(
base::SysNSStringToUTF16([cvcInput_ stringValue])) &&
(!monthPopup_ ||
@@ -186,6 +224,13 @@ void CardUnmaskPromptViewBridge::PerformClose() {
[self updateVerifyButtonEnabled];
}
+- (void)createProgressOverlay {
+ progressOverlay_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
+ progressOverlayText_.reset([constrained_window::CreateLabel() retain]);
+ [progressOverlay_ addSubview:progressOverlayText_];
+ [progressOverlay_ setHidden:YES];
+}
+
- (void)loadView {
autofill::CardUnmaskPromptController* controller = bridge_->GetController();
DCHECK(controller);
@@ -198,9 +243,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 +298,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 +311,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 +323,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 +347,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 +369,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 +389,13 @@ void CardUnmaskPromptViewBridge::PerformClose() {
contentWidth + [mainView contentViewMargins].width * 2.0,
NSMaxY([title frame]) + chrome_style::kTitleTopPadding)];
+ // Add progress overlay.
+ [self createProgressOverlay];
groby-ooo-7-16 2015/03/18 07:10:05 In case it becomes a single view, doing this inlin
bondd 2015/03/18 22:01:40 Done. I also did an alternate implementation where
+ [progressOverlay_
+ setFrame:NSMakeRect(0, NSMinY([inputRow_ frame]), contentWidth,
+ NSHeight([inputRow_ frame]))];
+ [mainView addSubview:progressOverlay_];
+
[self setView:mainView];
}

Powered by Google App Engine
This is Rietveld 408576698