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

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

Issue 1038503003: Autofill OSX: Add PermanentErrorMessage box and label. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace +sizeTextField with WrapOrSizeToFit() and make label autoresize. 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
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e461ce6a2b07992e0b7aa569b08c7c2ec3dce90d..7c0468023fc1183f8859901f23f1ee84117cf2bf 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
@@ -8,14 +8,15 @@
#include "chrome/browser/ui/autofill/autofill_dialog_models.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h"
+#include "chrome/browser/ui/chrome_style.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h"
#include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
-#include "chrome/browser/ui/chrome_style.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_utils.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
#import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
+#import "chrome/browser/ui/cocoa/l10n_util.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
@@ -27,6 +28,8 @@ namespace {
const CGFloat kButtonGap = 6.0f;
const CGFloat kDialogContentMinWidth = 210.0f;
const CGFloat kCvcInputWidth = 64.0f;
+const SkColor kPermanentErrorTextColor = 0xffffffff;
groby-ooo-7-16 2015/03/26 01:35:27 SkColor_WHITE;
bondd 2015/03/26 02:54:29 Done.
+const SkColor kPermanentErrorBackgroundColor = 0xffd32f2f;
groby-ooo-7-16 2015/03/26 01:35:27 SkColorSetRGB(0xd3, 0x2f, 0x2f)
bondd 2015/03/26 02:54:29 Done.
const ui::ResourceBundle::FontStyle kProgressFontStyle =
chrome_style::kTitleFontStyle;
const ui::ResourceBundle::FontStyle kErrorFontStyle =
@@ -88,9 +91,16 @@ void CardUnmaskPromptViewBridge::GotVerificationResult(
base::TimeDelta::FromSeconds(1));
} else {
[view_controller_ setProgressOverlayText:base::string16()];
- // TODO(bondd): Views version never hides |errorLabel_|. When Views decides
- // when to hide it then do the same thing here.
- [view_controller_ setRetriableErrorMessage:error_message];
+
+ if (allow_retry) {
+ // TODO(bondd): Views version never hides |errorLabel_|. When Views
+ // decides when to hide it then do the same thing here.
+ [view_controller_ setRetriableErrorMessage:error_message];
+ } else {
+ [view_controller_ setPermanentErrorMessage:error_message];
+ [view_controller_ setRetriableErrorMessage:base::string16()];
groby-ooo-7-16 2015/03/26 01:35:27 Shouldn't -setPermanentErrorMessage automatically
bondd 2015/03/26 02:54:28 Done. This gets rid of the -performLayout call too
+ }
+ [view_controller_ performLayout];
}
}
@@ -114,10 +124,12 @@ void CardUnmaskPromptViewBridge::PerformClose() {
#pragma mark CardUnmaskPromptViewCocoa
@implementation CardUnmaskPromptViewCocoa {
+ base::scoped_nsobject<NSBox> permanentErrorBox_;
base::scoped_nsobject<NSView> inputRowView_;
base::scoped_nsobject<NSView> storageView_;
base::scoped_nsobject<NSTextField> titleLabel_;
+ base::scoped_nsobject<NSTextField> permanentErrorLabel_;
base::scoped_nsobject<NSTextField> instructionsLabel_;
base::scoped_nsobject<NSTextField> cvcInput_;
base::scoped_nsobject<NSPopUpButton> monthPopup_;
@@ -147,16 +159,6 @@ void CardUnmaskPromptViewBridge::PerformClose() {
return popup;
}
-// Sets |textField|'s frame size to minimum dimensions needed to display its
-// text without exceeding |width|. Text will wrap onto multiple lines if
-// necessary. Frame width may end up being less than |width| if the text fits
-// in a smaller area.
-+ (void)sizeTextField:(NSTextField*)textField toFitWidth:(CGFloat)width {
- NSSize frameSize =
- [[textField cell] cellSizeForBounds:NSMakeRect(0, 0, width, CGFLOAT_MAX)];
- [textField setFrameSize:frameSize];
-}
-
// Set |view|'s frame to the minimum dimensions required to contain all of its
// subviews.
+ (void)sizeToFitView:(NSView*)view {
@@ -205,7 +207,35 @@ void CardUnmaskPromptViewBridge::PerformClose() {
SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment,
NSLineBreakByWordWrapping);
[errorLabel_ setAttributedStringValue:attributedString];
- [self performLayoutAndDisplay:YES];
+}
+
+- (void)setPermanentErrorMessage:(const base::string16&)text {
+ if (!text.empty()) {
+ if (!permanentErrorBox_) {
+ permanentErrorBox_.reset([[NSBox alloc] initWithFrame:NSZeroRect]);
+ [permanentErrorBox_ setBoxType:NSBoxCustom];
+ [permanentErrorBox_ setBorderType:NSNoBorder];
+ [permanentErrorBox_ setTitlePosition:NSNoTitle];
+ [permanentErrorBox_ setFillColor:gfx::SkColorToCalibratedNSColor(
+ kPermanentErrorBackgroundColor)];
+
+ permanentErrorLabel_.reset([constrained_window::CreateLabel() retain]);
+ [permanentErrorLabel_ setAutoresizingMask:NSViewWidthSizable];
+ [permanentErrorLabel_ setTextColor:gfx::SkColorToCalibratedNSColor(
+ kPermanentErrorTextColor)];
+
+ [permanentErrorBox_ addSubview:permanentErrorLabel_];
+ [[self view] addSubview:permanentErrorBox_];
+ }
+
+ NSAttributedString* attributedString =
+ constrained_window::GetAttributedLabelString(
+ SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment,
+ NSLineBreakByWordWrapping);
+ [permanentErrorLabel_ setAttributedStringValue:attributedString];
+ }
+
+ [permanentErrorBox_ setHidden:text.empty()];
}
- (void)updateVerifyButtonEnabled {
@@ -282,7 +312,25 @@ void CardUnmaskPromptViewBridge::PerformClose() {
return view;
}
-// TODO(bondd): Add an ASCII diagram of the layout.
+// +------------------------------------------------+
+// | titleLabel_ (Single line.) |
+// |------------------------------------------------|
+// | permanentErrorBox_ (Multiline, may be hidden.) |
+// |------------------------------------------------|
+// | instructionsLabel_ (Multiline.) |
+// |------------------------------------------------|
+// | monthPopup_ yearPopup_ cvcInput_ cvcImage |
+// | (All enclosed in inputRowView_. Month and |
+// | year may be hidden.) |
+// |------------------------------------------------|
+// | errorLabel_ (Multiline. Always takes up space |
+// | for one line even if empty.) |
+// |------------------------------------------------|
+// | [Cancel] [Verify] |
+// |------------------------------------------------|
+// | storageCheckbox_ storageTooltip_ |
+// | (Both enclosed in storageView_.) |
+// +------------------------------------------------+
- (void)performLayoutAndDisplay:(BOOL)display {
// Calculate dialog content width.
CGFloat contentWidth =
@@ -302,22 +350,29 @@ void CardUnmaskPromptViewBridge::PerformClose() {
NSWidth([cancelButton_ frame]),
NSMinY([verifyButton_ frame]))];
- [errorLabel_ setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton_ frame]) +
- chrome_style::kRowPadding)];
- [CardUnmaskPromptViewCocoa sizeTextField:errorLabel_ toFitWidth:contentWidth];
+ [errorLabel_ setFrame:NSMakeRect(0, NSMaxY([cancelButton_ frame]) +
+ chrome_style::kRowPadding,
+ contentWidth, 0)];
+ cocoa_l10n_util::WrapOrSizeToFit(errorLabel_);
[inputRowView_ setFrameOrigin:NSMakePoint(0, NSMaxY([errorLabel_ frame]) +
chrome_style::kRowPadding)];
- [instructionsLabel_
- setFrameOrigin:NSMakePoint(0, NSMaxY([inputRowView_ frame]) +
- chrome_style::kRowPadding)];
- [CardUnmaskPromptViewCocoa sizeTextField:instructionsLabel_
- toFitWidth:contentWidth];
+ [instructionsLabel_ setFrame:NSMakeRect(0, NSMaxY([inputRowView_ frame]) +
+ chrome_style::kRowPadding,
+ contentWidth, 0)];
+ cocoa_l10n_util::WrapOrSizeToFit(instructionsLabel_);
+
+ // Layout permanent error box.
+ CGFloat minY = NSMaxY([instructionsLabel_ frame]) + chrome_style::kRowPadding;
+ if (permanentErrorBox_ && ![permanentErrorBox_ isHidden]) {
+ [permanentErrorBox_ setFrame:NSMakeRect(0, minY, contentWidth, 0)];
+ cocoa_l10n_util::WrapOrSizeToFit(permanentErrorLabel_);
+ [permanentErrorBox_ sizeToFit];
+ minY = NSMaxY([permanentErrorBox_ frame]) + chrome_style::kRowPadding;
+ }
- [titleLabel_
- setFrameOrigin:NSMakePoint(0, NSMaxY([instructionsLabel_ frame]) +
- chrome_style::kRowPadding)];
+ [titleLabel_ setFrameOrigin:NSMakePoint(0, minY)];
// Center progressOverlayLabel_ vertically within inputRowView_ frame.
CGFloat progressHeight = ui::ResourceBundle::GetSharedInstance()
@@ -340,6 +395,10 @@ void CardUnmaskPromptViewBridge::PerformClose() {
[[[self view] window] setFrame:frameRect display:display];
}
+- (void)performLayout {
+ [self performLayoutAndDisplay:YES];
groby-ooo-7-16 2015/03/26 01:35:27 You call this only once - can you just inline?
bondd 2015/03/26 02:54:29 Done.
+}
+
- (void)loadView {
autofill::CardUnmaskPromptController* controller = bridge_->GetController();
DCHECK(controller);
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698