OLD | NEW |
---|---|
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 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" | 11 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" |
12 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h" | 12 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h" |
13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
14 #include "chrome/browser/ui/chrome_style.h" | 14 #include "chrome/browser/ui/chrome_style.h" |
15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u tils.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_custom_sh eet.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_wi ndow.h" | 17 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" |
18 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 18 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
21 #include "skia/ext/skia_utils_mac.h" | 21 #include "skia/ext/skia_utils_mac.h" |
22 #include "ui/base/cocoa/window_size_constants.h" | 22 #include "ui/base/cocoa/window_size_constants.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 const CGFloat kButtonGap = 6.0f; | 27 const CGFloat kButtonGap = 6.0f; |
28 const CGFloat kDialogContentMinWidth = 210.0f; | 28 const CGFloat kDialogContentMinWidth = 210.0f; |
29 const CGFloat kCvcInputWidth = 64.0f; | 29 const CGFloat kCvcInputWidth = 64.0f; |
30 const SkColor kPermanentErrorTextColor = 0xffffffff; | |
31 const SkColor kPermanentErrorBackgroundColor = 0xffd32f2f; | |
30 const ui::ResourceBundle::FontStyle kProgressFontStyle = | 32 const ui::ResourceBundle::FontStyle kProgressFontStyle = |
31 chrome_style::kTitleFontStyle; | 33 chrome_style::kTitleFontStyle; |
32 const ui::ResourceBundle::FontStyle kErrorFontStyle = | 34 const ui::ResourceBundle::FontStyle kErrorFontStyle = |
33 chrome_style::kTextFontStyle; | 35 chrome_style::kTextFontStyle; |
34 | 36 |
35 } // namespace | 37 } // namespace |
36 | 38 |
37 namespace autofill { | 39 namespace autofill { |
38 | 40 |
39 // static | 41 // static |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 [view_controller_ setProgressOverlayText: | 83 [view_controller_ setProgressOverlayText: |
82 l10n_util::GetStringUTF16( | 84 l10n_util::GetStringUTF16( |
83 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)]; | 85 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)]; |
84 | 86 |
85 base::MessageLoop::current()->PostDelayedTask( | 87 base::MessageLoop::current()->PostDelayedTask( |
86 FROM_HERE, base::Bind(&CardUnmaskPromptViewBridge::PerformClose, | 88 FROM_HERE, base::Bind(&CardUnmaskPromptViewBridge::PerformClose, |
87 weak_ptr_factory_.GetWeakPtr()), | 89 weak_ptr_factory_.GetWeakPtr()), |
88 base::TimeDelta::FromSeconds(1)); | 90 base::TimeDelta::FromSeconds(1)); |
89 } else { | 91 } else { |
90 [view_controller_ setProgressOverlayText:base::string16()]; | 92 [view_controller_ setProgressOverlayText:base::string16()]; |
91 // TODO(bondd): Views version never hides |errorLabel_|. When Views decides | 93 |
92 // when to hide it then do the same thing here. | 94 if (allow_retry) { |
93 [view_controller_ setRetriableErrorMessage:error_message]; | 95 // TODO(bondd): Views version never hides |errorLabel_|. When Views |
96 // decides when to hide it then do the same thing here. | |
97 [view_controller_ setRetriableErrorMessage:error_message]; | |
98 } else { | |
99 [view_controller_ setPermanentErrorMessage:error_message]; | |
100 [view_controller_ setRetriableErrorMessage:base::string16()]; | |
101 } | |
102 [view_controller_ performLayout]; | |
94 } | 103 } |
95 } | 104 } |
96 | 105 |
97 void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( | 106 void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( |
98 ConstrainedWindowMac* window) { | 107 ConstrainedWindowMac* window) { |
99 if (controller_) | 108 if (controller_) |
100 controller_->OnUnmaskDialogClosed(); | 109 controller_->OnUnmaskDialogClosed(); |
101 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 110 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
102 } | 111 } |
103 | 112 |
104 CardUnmaskPromptController* CardUnmaskPromptViewBridge::GetController() { | 113 CardUnmaskPromptController* CardUnmaskPromptViewBridge::GetController() { |
105 return controller_; | 114 return controller_; |
106 } | 115 } |
107 | 116 |
108 void CardUnmaskPromptViewBridge::PerformClose() { | 117 void CardUnmaskPromptViewBridge::PerformClose() { |
109 constrained_window_->CloseWebContentsModalDialog(); | 118 constrained_window_->CloseWebContentsModalDialog(); |
110 } | 119 } |
111 | 120 |
112 } // autofill | 121 } // autofill |
113 | 122 |
114 #pragma mark CardUnmaskPromptViewCocoa | 123 #pragma mark CardUnmaskPromptViewCocoa |
115 | 124 |
116 @implementation CardUnmaskPromptViewCocoa { | 125 @implementation CardUnmaskPromptViewCocoa { |
126 base::scoped_nsobject<NSBox> permanentErrorBox_; | |
117 base::scoped_nsobject<NSView> inputRowView_; | 127 base::scoped_nsobject<NSView> inputRowView_; |
118 base::scoped_nsobject<NSView> storageView_; | 128 base::scoped_nsobject<NSView> storageView_; |
119 | 129 |
120 base::scoped_nsobject<NSTextField> titleLabel_; | 130 base::scoped_nsobject<NSTextField> titleLabel_; |
131 base::scoped_nsobject<NSTextField> permanentErrorLabel_; | |
121 base::scoped_nsobject<NSTextField> instructionsLabel_; | 132 base::scoped_nsobject<NSTextField> instructionsLabel_; |
122 base::scoped_nsobject<NSTextField> cvcInput_; | 133 base::scoped_nsobject<NSTextField> cvcInput_; |
123 base::scoped_nsobject<NSPopUpButton> monthPopup_; | 134 base::scoped_nsobject<NSPopUpButton> monthPopup_; |
124 base::scoped_nsobject<NSPopUpButton> yearPopup_; | 135 base::scoped_nsobject<NSPopUpButton> yearPopup_; |
125 base::scoped_nsobject<NSButton> cancelButton_; | 136 base::scoped_nsobject<NSButton> cancelButton_; |
126 base::scoped_nsobject<NSButton> verifyButton_; | 137 base::scoped_nsobject<NSButton> verifyButton_; |
127 base::scoped_nsobject<NSButton> storageCheckbox_; | 138 base::scoped_nsobject<NSButton> storageCheckbox_; |
128 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; | 139 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; |
129 base::scoped_nsobject<NSTextField> errorLabel_; | 140 base::scoped_nsobject<NSTextField> errorLabel_; |
130 base::scoped_nsobject<NSTextField> progressOverlayLabel_; | 141 base::scoped_nsobject<NSTextField> progressOverlayLabel_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 [inputRowView_ setHidden:!text.empty()]; | 210 [inputRowView_ setHidden:!text.empty()]; |
200 [self updateVerifyButtonEnabled]; | 211 [self updateVerifyButtonEnabled]; |
201 } | 212 } |
202 | 213 |
203 - (void)setRetriableErrorMessage:(const base::string16&)text { | 214 - (void)setRetriableErrorMessage:(const base::string16&)text { |
204 NSAttributedString* attributedString = | 215 NSAttributedString* attributedString = |
205 constrained_window::GetAttributedLabelString( | 216 constrained_window::GetAttributedLabelString( |
206 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, | 217 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, |
207 NSLineBreakByWordWrapping); | 218 NSLineBreakByWordWrapping); |
208 [errorLabel_ setAttributedStringValue:attributedString]; | 219 [errorLabel_ setAttributedStringValue:attributedString]; |
209 [self performLayoutAndDisplay:YES]; | 220 } |
221 | |
222 - (void)setPermanentErrorMessage:(const base::string16&)text { | |
groby-ooo-7-16
2015/03/25 19:32:35
OK, I still have to harp on the naming. setRetriab
bondd
2015/03/26 00:17:59
Acknowledged.
| |
223 if (!text.empty()) { | |
224 if (!permanentErrorBox_) { | |
225 permanentErrorBox_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); | |
226 [permanentErrorBox_ setBoxType:NSBoxCustom]; | |
227 [permanentErrorBox_ setBorderType:NSNoBorder]; | |
228 [permanentErrorBox_ setTitlePosition:NSNoTitle]; | |
229 [permanentErrorBox_ setFillColor:gfx::SkColorToCalibratedNSColor( | |
230 kPermanentErrorBackgroundColor)]; | |
231 | |
232 permanentErrorLabel_.reset([constrained_window::CreateLabel() retain]); | |
233 [permanentErrorLabel_ setTextColor:gfx::SkColorToCalibratedNSColor( | |
234 kPermanentErrorTextColor)]; | |
235 | |
236 [permanentErrorBox_ addSubview:permanentErrorLabel_]; | |
237 [[self view] addSubview:permanentErrorBox_]; | |
238 } | |
239 | |
240 NSAttributedString* attributedString = | |
241 constrained_window::GetAttributedLabelString( | |
242 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, | |
243 NSLineBreakByWordWrapping); | |
244 [permanentErrorLabel_ setAttributedStringValue:attributedString]; | |
245 } | |
246 | |
247 [permanentErrorBox_ setHidden:text.empty()]; | |
210 } | 248 } |
211 | 249 |
212 - (void)updateVerifyButtonEnabled { | 250 - (void)updateVerifyButtonEnabled { |
213 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 251 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); |
214 DCHECK(controller); | 252 DCHECK(controller); |
215 | 253 |
216 BOOL enable = | 254 BOOL enable = |
217 ![inputRowView_ isHidden] && | 255 ![inputRowView_ isHidden] && |
218 controller->InputCvcIsValid( | 256 controller->InputCvcIsValid( |
219 base::SysNSStringToUTF16([cvcInput_ stringValue])) && | 257 base::SysNSStringToUTF16([cvcInput_ stringValue])) && |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLTIP))]; | 314 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLTIP))]; |
277 [view addSubview:[storageTooltip_ view]]; | 315 [view addSubview:[storageTooltip_ view]]; |
278 [[storageTooltip_ view] setFrameOrigin: | 316 [[storageTooltip_ view] setFrameOrigin: |
279 NSMakePoint(NSMaxX([storageCheckbox_ frame]) + kButtonGap, 0)]; | 317 NSMakePoint(NSMaxX([storageCheckbox_ frame]) + kButtonGap, 0)]; |
280 | 318 |
281 [CardUnmaskPromptViewCocoa sizeToFitView:view]; | 319 [CardUnmaskPromptViewCocoa sizeToFitView:view]; |
282 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:view]; | 320 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:view]; |
283 return view; | 321 return view; |
284 } | 322 } |
285 | 323 |
286 // TODO(bondd): Add an ASCII diagram of the layout. | 324 // +------------------------------------------------+ |
325 // | titleLabel_ (Single line.) | | |
326 // |------------------------------------------------| | |
327 // | permanentErrorBox_ (Multiline, may be hidden.) | | |
328 // |------------------------------------------------| | |
329 // | instructionsLabel_ (Multiline.) | | |
330 // |------------------------------------------------| | |
331 // | monthPopup_ yearPopup_ cvcInput_ cvcImage | | |
332 // | (All enclosed in inputRowView_. Month and | | |
333 // | year may be hidden.) | | |
334 // |------------------------------------------------| | |
335 // | errorLabel_ (Multiline. Always takes up space | | |
336 // | for one line even if empty.) | | |
337 // |------------------------------------------------| | |
338 // | [Cancel] [Verify] | | |
339 // |------------------------------------------------| | |
340 // | storageCheckbox_ storageTooltip_ | | |
341 // | (Both enclosed in storageView_.) | | |
groby-ooo-7-16
2015/03/25 19:32:35
Yay! +1 for ASCII diagrams! (No, really - this is
bondd
2015/03/26 00:17:59
Woo!
| |
342 // +------------------------------------------------+ | |
287 - (void)performLayoutAndDisplay:(BOOL)display { | 343 - (void)performLayoutAndDisplay:(BOOL)display { |
288 // Calculate dialog content width. | 344 // Calculate dialog content width. |
289 CGFloat contentWidth = | 345 CGFloat contentWidth = |
290 std::max(NSWidth([titleLabel_ frame]), NSWidth([inputRowView_ frame])); | 346 std::max(NSWidth([titleLabel_ frame]), NSWidth([inputRowView_ frame])); |
291 contentWidth = std::max(contentWidth, NSWidth([storageView_ frame])); | 347 contentWidth = std::max(contentWidth, NSWidth([storageView_ frame])); |
292 contentWidth = std::max(contentWidth, kDialogContentMinWidth); | 348 contentWidth = std::max(contentWidth, kDialogContentMinWidth); |
293 | 349 |
294 [storageView_ | 350 [storageView_ |
295 setFrameOrigin:NSMakePoint(0, chrome_style::kClientBottomPadding)]; | 351 setFrameOrigin:NSMakePoint(0, chrome_style::kClientBottomPadding)]; |
296 | 352 |
(...skipping 12 matching lines...) Expand all Loading... | |
309 | 365 |
310 [inputRowView_ setFrameOrigin:NSMakePoint(0, NSMaxY([errorLabel_ frame]) + | 366 [inputRowView_ setFrameOrigin:NSMakePoint(0, NSMaxY([errorLabel_ frame]) + |
311 chrome_style::kRowPadding)]; | 367 chrome_style::kRowPadding)]; |
312 | 368 |
313 [instructionsLabel_ | 369 [instructionsLabel_ |
314 setFrameOrigin:NSMakePoint(0, NSMaxY([inputRowView_ frame]) + | 370 setFrameOrigin:NSMakePoint(0, NSMaxY([inputRowView_ frame]) + |
315 chrome_style::kRowPadding)]; | 371 chrome_style::kRowPadding)]; |
316 [CardUnmaskPromptViewCocoa sizeTextField:instructionsLabel_ | 372 [CardUnmaskPromptViewCocoa sizeTextField:instructionsLabel_ |
317 toFitWidth:contentWidth]; | 373 toFitWidth:contentWidth]; |
318 | 374 |
319 [titleLabel_ | 375 // Layout permanent error box. |
320 setFrameOrigin:NSMakePoint(0, NSMaxY([instructionsLabel_ frame]) + | 376 CGFloat minY = NSMaxY([instructionsLabel_ frame]) + chrome_style::kRowPadding; |
groby-ooo-7-16
2015/03/25 19:32:35
[permanentErrorBox_ setFrame:NSMakeRect(0, minY, c
bondd
2015/03/26 00:17:59
Nice! Done.
| |
321 chrome_style::kRowPadding)]; | 377 if (permanentErrorBox_ && ![permanentErrorBox_ isHidden]) { |
378 CGFloat errorBoxContentWidth = | |
379 contentWidth - [permanentErrorBox_ contentViewMargins].width * 2.0; | |
380 [CardUnmaskPromptViewCocoa sizeTextField:permanentErrorLabel_ | |
groby-ooo-7-16
2015/03/25 19:32:35
Sorry. My brain was stuck. This functionality exis
bondd
2015/03/26 00:17:59
Done.
| |
381 toFitWidth:errorBoxContentWidth]; | |
382 | |
383 [permanentErrorBox_ sizeToFit]; | |
384 [permanentErrorBox_ | |
385 setFrame:NSMakeRect(0, minY, contentWidth, | |
386 NSHeight([permanentErrorBox_ frame]))]; | |
387 minY = NSMaxY([permanentErrorBox_ frame]) + chrome_style::kRowPadding; | |
groby-ooo-7-16
2015/03/25 19:32:35
I'm tempted to suggest a "NextRow" helper.
bondd
2015/03/26 00:17:59
Acknowledged. This layout code is in flux right no
| |
388 } | |
389 | |
390 [titleLabel_ setFrameOrigin:NSMakePoint(0, minY)]; | |
322 | 391 |
323 // Center progressOverlayLabel_ vertically within inputRowView_ frame. | 392 // Center progressOverlayLabel_ vertically within inputRowView_ frame. |
324 CGFloat progressHeight = ui::ResourceBundle::GetSharedInstance() | 393 CGFloat progressHeight = ui::ResourceBundle::GetSharedInstance() |
325 .GetFont(kProgressFontStyle) | 394 .GetFont(kProgressFontStyle) |
326 .GetHeight(); | 395 .GetHeight(); |
327 [progressOverlayLabel_ | 396 [progressOverlayLabel_ |
328 setFrame:NSMakeRect(0, ceil(NSMidY([inputRowView_ frame]) - | 397 setFrame:NSMakeRect(0, ceil(NSMidY([inputRowView_ frame]) - |
329 progressHeight / 2.0), | 398 progressHeight / 2.0), |
330 contentWidth, progressHeight)]; | 399 contentWidth, progressHeight)]; |
331 | 400 |
332 // Set dialog size. | 401 // Set dialog size. |
333 [[self view] | 402 [[self view] |
334 setFrameSize:NSMakeSize( | 403 setFrameSize:NSMakeSize( |
335 contentWidth + chrome_style::kHorizontalPadding * 2.0, | 404 contentWidth + chrome_style::kHorizontalPadding * 2.0, |
336 NSMaxY([titleLabel_ frame]) + | 405 NSMaxY([titleLabel_ frame]) + |
337 chrome_style::kTitleTopPadding)]; | 406 chrome_style::kTitleTopPadding)]; |
338 | 407 |
339 NSRect frameRect = | 408 NSRect frameRect = |
340 [[[self view] window] frameRectForContentRect:[[self view] frame]]; | 409 [[[self view] window] frameRectForContentRect:[[self view] frame]]; |
341 [[[self view] window] setFrame:frameRect display:display]; | 410 [[[self view] window] setFrame:frameRect display:display]; |
342 } | 411 } |
343 | 412 |
413 - (void)performLayout { | |
414 [self performLayoutAndDisplay:YES]; | |
415 } | |
416 | |
344 - (void)loadView { | 417 - (void)loadView { |
345 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 418 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); |
346 DCHECK(controller); | 419 DCHECK(controller); |
347 | 420 |
348 base::scoped_nsobject<NSBox> mainView( | 421 base::scoped_nsobject<NSBox> mainView( |
349 [[NSBox alloc] initWithFrame:NSZeroRect]); | 422 [[NSBox alloc] initWithFrame:NSZeroRect]); |
350 [mainView setBoxType:NSBoxCustom]; | 423 [mainView setBoxType:NSBoxCustom]; |
351 [mainView setBorderType:NSNoBorder]; | 424 [mainView setBorderType:NSNoBorder]; |
352 [mainView setTitlePosition:NSNoTitle]; | 425 [mainView setTitlePosition:NSNoTitle]; |
353 [mainView | 426 [mainView |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 | 545 |
473 // Layout inputRowView_. | 546 // Layout inputRowView_. |
474 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_]; | 547 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_]; |
475 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_]; | 548 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_]; |
476 | 549 |
477 [self setView:mainView]; | 550 [self setView:mainView]; |
478 [self performLayoutAndDisplay:NO]; | 551 [self performLayoutAndDisplay:NO]; |
479 } | 552 } |
480 | 553 |
481 @end | 554 @end |
OLD | NEW |