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

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

Issue 1052513002: Autofill OSX: Draw red outline around incorrect CVC input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix include order. Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" 8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h"
9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" 9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h"
11 #include "chrome/browser/ui/chrome_style.h" 11 #include "chrome/browser/ui/chrome_style.h"
12 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h"
12 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" 13 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h"
13 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h" 14 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h"
14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" 15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u tils.h" 16 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u tils.h"
16 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" 17 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
17 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" 18 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h"
18 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" 19 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
19 #import "chrome/browser/ui/cocoa/l10n_util.h" 20 #import "chrome/browser/ui/cocoa/l10n_util.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 #pragma mark CardUnmaskPromptViewCocoa 123 #pragma mark CardUnmaskPromptViewCocoa
123 124
124 @implementation CardUnmaskPromptViewCocoa { 125 @implementation CardUnmaskPromptViewCocoa {
125 base::scoped_nsobject<NSBox> permanentErrorBox_; 126 base::scoped_nsobject<NSBox> permanentErrorBox_;
126 base::scoped_nsobject<NSView> inputRowView_; 127 base::scoped_nsobject<NSView> inputRowView_;
127 base::scoped_nsobject<NSView> storageView_; 128 base::scoped_nsobject<NSView> storageView_;
128 129
129 base::scoped_nsobject<NSTextField> titleLabel_; 130 base::scoped_nsobject<NSTextField> titleLabel_;
130 base::scoped_nsobject<NSTextField> permanentErrorLabel_; 131 base::scoped_nsobject<NSTextField> permanentErrorLabel_;
131 base::scoped_nsobject<NSTextField> instructionsLabel_; 132 base::scoped_nsobject<NSTextField> instructionsLabel_;
132 base::scoped_nsobject<NSTextField> cvcInput_; 133 base::scoped_nsobject<AutofillTextField> cvcInput_;
133 base::scoped_nsobject<NSPopUpButton> monthPopup_; 134 base::scoped_nsobject<NSPopUpButton> monthPopup_;
134 base::scoped_nsobject<NSPopUpButton> yearPopup_; 135 base::scoped_nsobject<NSPopUpButton> yearPopup_;
135 base::scoped_nsobject<NSButton> cancelButton_; 136 base::scoped_nsobject<NSButton> cancelButton_;
136 base::scoped_nsobject<NSButton> verifyButton_; 137 base::scoped_nsobject<NSButton> verifyButton_;
137 base::scoped_nsobject<NSButton> storageCheckbox_; 138 base::scoped_nsobject<NSButton> storageCheckbox_;
138 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; 139 base::scoped_nsobject<AutofillTooltipController> storageTooltip_;
139 base::scoped_nsobject<NSTextField> errorLabel_; 140 base::scoped_nsobject<NSTextField> errorLabel_;
140 base::scoped_nsobject<NSTextField> progressOverlayLabel_; 141 base::scoped_nsobject<NSTextField> progressOverlayLabel_;
141 142
142 int monthPopupDefaultIndex_; 143 int monthPopupDefaultIndex_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 [yearPopup_ setEnabled:enabled]; 207 [yearPopup_ setEnabled:enabled];
207 [storageCheckbox_ setEnabled:enabled]; 208 [storageCheckbox_ setEnabled:enabled];
208 } 209 }
209 210
210 - (void)setRetriableErrorMessage:(const base::string16&)text { 211 - (void)setRetriableErrorMessage:(const base::string16&)text {
211 NSAttributedString* attributedString = 212 NSAttributedString* attributedString =
212 constrained_window::GetAttributedLabelString( 213 constrained_window::GetAttributedLabelString(
213 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, 214 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment,
214 NSLineBreakByWordWrapping); 215 NSLineBreakByWordWrapping);
215 [errorLabel_ setAttributedStringValue:attributedString]; 216 [errorLabel_ setAttributedStringValue:attributedString];
217
218 // If there is more than one input showing, don't mark anything as
219 // invalid since we don't know the location of the problem.
220 if (!text.empty() && !bridge_->GetController()->ShouldRequestExpirationDate())
221 [cvcInput_ setValidityMessage:@"invalid"];
bondd 2015/04/01 18:13:14 AutofillTextField only checks this string for leng
groby-ooo-7-16 2015/04/02 22:32:56 I know :) Check if this is used as a hover messag
222
216 [self performLayoutAndDisplay:YES]; 223 [self performLayoutAndDisplay:YES];
217 } 224 }
218 225
219 - (void)setPermanentErrorMessage:(const base::string16&)text { 226 - (void)setPermanentErrorMessage:(const base::string16&)text {
220 if (!text.empty()) { 227 if (!text.empty()) {
221 if (!permanentErrorBox_) { 228 if (!permanentErrorBox_) {
222 permanentErrorBox_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); 229 permanentErrorBox_.reset([[NSBox alloc] initWithFrame:NSZeroRect]);
223 [permanentErrorBox_ setBoxType:NSBoxCustom]; 230 [permanentErrorBox_ setBoxType:NSBoxCustom];
224 [permanentErrorBox_ setBorderType:NSNoBorder]; 231 [permanentErrorBox_ setBorderType:NSNoBorder];
225 [permanentErrorBox_ setTitlePosition:NSNoTitle]; 232 [permanentErrorBox_ setTitlePosition:NSNoTitle];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 [self setRetriableErrorMessage: 294 [self setRetriableErrorMessage:
288 l10n_util::GetStringUTF16( 295 l10n_util::GetStringUTF16(
289 IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE)]; 296 IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE)];
290 } 297 }
291 298
292 [self updateVerifyButtonEnabled]; 299 [self updateVerifyButtonEnabled];
293 } 300 }
294 301
295 // Called when text in CVC input field changes. 302 // Called when text in CVC input field changes.
296 - (void)controlTextDidChange:(NSNotification*)notification { 303 - (void)controlTextDidChange:(NSNotification*)notification {
304 if (bridge_->GetController()->InputCvcIsValid(
305 base::SysNSStringToUTF16([cvcInput_ stringValue])))
306 [cvcInput_ setValidityMessage:@""];
307
297 [self updateVerifyButtonEnabled]; 308 [self updateVerifyButtonEnabled];
298 } 309 }
299 310
300 - (base::scoped_nsobject<NSView>)createStorageViewWithController: 311 - (base::scoped_nsobject<NSView>)createStorageViewWithController:
301 (autofill::CardUnmaskPromptController*)controller { 312 (autofill::CardUnmaskPromptController*)controller {
302 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); 313 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
303 314
304 // Add "Store card on this device" checkbox. 315 // Add "Store card on this device" checkbox.
305 storageCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); 316 storageCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
306 [storageCheckbox_ setButtonType:NSSwitchButton]; 317 [storageCheckbox_ setButtonType:NSSwitchButton];
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 setFrameOrigin:NSMakePoint(NSMaxX([monthPopup_ frame]) + kButtonGap, 500 setFrameOrigin:NSMakePoint(NSMaxX([monthPopup_ frame]) + kButtonGap,
490 0)]; 501 0)];
491 NSRect expirationFrame = 502 NSRect expirationFrame =
492 NSUnionRect([monthPopup_ frame], [yearPopup_ frame]); 503 NSUnionRect([monthPopup_ frame], [yearPopup_ frame]);
493 expirationFrame.size.width += kButtonGap; 504 expirationFrame.size.width += kButtonGap;
494 [expirationView setFrame:expirationFrame]; 505 [expirationView setFrame:expirationFrame];
495 [inputRowView_ addSubview:expirationView]; 506 [inputRowView_ addSubview:expirationView];
496 } 507 }
497 508
498 // Add CVC text input. 509 // Add CVC text input.
499 cvcInput_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); 510 cvcInput_.reset([[AutofillTextField alloc] initWithFrame:NSZeroRect]);
500 [[cvcInput_ cell] 511 [[cvcInput_ cell]
501 setPlaceholderString:l10n_util::GetNSString( 512 setPlaceholderString:l10n_util::GetNSString(
502 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)]; 513 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)];
503 [[cvcInput_ cell] setScrollable:YES]; 514 [[cvcInput_ cell] setScrollable:YES];
504 [cvcInput_ setDelegate:self]; 515 [cvcInput_ setDelegate:self];
505 [cvcInput_ sizeToFit]; 516 [cvcInput_ sizeToFit];
506 [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView frame]), 0, 517 [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView frame]), 0,
507 kCvcInputWidth, NSHeight([cvcInput_ frame]))]; 518 kCvcInputWidth, NSHeight([cvcInput_ frame]))];
508 [inputRowView_ addSubview:cvcInput_]; 519 [inputRowView_ addSubview:cvcInput_];
509 520
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 560
550 // Layout inputRowView_. 561 // Layout inputRowView_.
551 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_]; 562 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_];
552 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_]; 563 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_];
553 564
554 [self setView:mainView]; 565 [self setView:mainView];
555 [self performLayoutAndDisplay:NO]; 566 [self performLayoutAndDisplay:NO];
556 } 567 }
557 568
558 @end 569 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698