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/card_unmask_prompt_controller.h" | 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
10 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" | 11 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" |
11 #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" |
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
13 #include "chrome/browser/ui/chrome_style.h" | 14 #include "chrome/browser/ui/chrome_style.h" |
14 #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" |
15 #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" |
16 #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" |
17 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 18 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
21 #include "skia/ext/skia_utils_mac.h" | |
20 #include "ui/base/cocoa/window_size_constants.h" | 22 #include "ui/base/cocoa/window_size_constants.h" |
21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const CGFloat kButtonGap = 6.0f; | 27 const CGFloat kButtonGap = 6.0f; |
26 const CGFloat kDialogContentMinWidth = 210.0f; | 28 const CGFloat kDialogContentMinWidth = 210.0f; |
27 const CGFloat kCvcInputWidth = 64.0f; | 29 const CGFloat kCvcInputWidth = 64.0f; |
28 const ui::ResourceBundle::FontStyle kProgressFontStyle = | 30 const ui::ResourceBundle::FontStyle kProgressFontStyle = |
29 chrome_style::kTitleFontStyle; | 31 chrome_style::kTitleFontStyle; |
32 const ui::ResourceBundle::FontStyle kErrorFontStyle = | |
33 chrome_style::kTextFontStyle; | |
30 | 34 |
31 } // namespace | 35 } // namespace |
32 | 36 |
33 namespace autofill { | 37 namespace autofill { |
34 | 38 |
35 // static | 39 // static |
36 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( | 40 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( |
37 CardUnmaskPromptController* controller) { | 41 CardUnmaskPromptController* controller) { |
38 return new CardUnmaskPromptViewBridge(controller); | 42 return new CardUnmaskPromptViewBridge(controller); |
39 } | 43 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 [view_controller_ setProgressOverlayText: | 81 [view_controller_ setProgressOverlayText: |
78 l10n_util::GetStringUTF16( | 82 l10n_util::GetStringUTF16( |
79 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)]; | 83 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)]; |
80 | 84 |
81 base::MessageLoop::current()->PostDelayedTask( | 85 base::MessageLoop::current()->PostDelayedTask( |
82 FROM_HERE, base::Bind(&CardUnmaskPromptViewBridge::PerformClose, | 86 FROM_HERE, base::Bind(&CardUnmaskPromptViewBridge::PerformClose, |
83 weak_ptr_factory_.GetWeakPtr()), | 87 weak_ptr_factory_.GetWeakPtr()), |
84 base::TimeDelta::FromSeconds(1)); | 88 base::TimeDelta::FromSeconds(1)); |
85 } else { | 89 } else { |
86 [view_controller_ setProgressOverlayText:base::string16()]; | 90 [view_controller_ setProgressOverlayText:base::string16()]; |
91 // TODO(bondd): Views version never hides |errorLabel_|. When Views decides | |
92 // when to hide it then do the same thing here. | |
93 [view_controller_ setRetriableErrorMessage:error_message]; | |
bondd
2015/03/23 21:27:55
setRetriableErrorMessage is same method name as in
groby-ooo-7-16
2015/03/24 01:26:49
Can we fix the views version too, then?
bondd
2015/03/24 23:46:47
Leaving shed this color per discussion elsewhere i
| |
87 } | 94 } |
88 } | 95 } |
89 | 96 |
90 void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( | 97 void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( |
91 ConstrainedWindowMac* window) { | 98 ConstrainedWindowMac* window) { |
92 if (controller_) | 99 if (controller_) |
93 controller_->OnUnmaskDialogClosed(); | 100 controller_->OnUnmaskDialogClosed(); |
94 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 101 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
95 } | 102 } |
96 | 103 |
97 CardUnmaskPromptController* CardUnmaskPromptViewBridge::GetController() { | 104 CardUnmaskPromptController* CardUnmaskPromptViewBridge::GetController() { |
98 return controller_; | 105 return controller_; |
99 } | 106 } |
100 | 107 |
101 void CardUnmaskPromptViewBridge::PerformClose() { | 108 void CardUnmaskPromptViewBridge::PerformClose() { |
102 constrained_window_->CloseWebContentsModalDialog(); | 109 constrained_window_->CloseWebContentsModalDialog(); |
103 } | 110 } |
104 | 111 |
105 } // autofill | 112 } // autofill |
106 | 113 |
107 #pragma mark CardUnmaskPromptViewCocoa | 114 #pragma mark CardUnmaskPromptViewCocoa |
108 | 115 |
109 @implementation CardUnmaskPromptViewCocoa { | 116 @implementation CardUnmaskPromptViewCocoa { |
117 base::scoped_nsobject<NSView> expirationView_; | |
groby-ooo-7-16
2015/03/24 01:26:49
This is never used outside -loadView, so no need t
bondd
2015/03/24 23:46:47
Done.
| |
118 base::scoped_nsobject<NSView> inputRowView_; | |
119 base::scoped_nsobject<NSView> storageView_; | |
120 | |
121 base::scoped_nsobject<NSTextField> titleLabel_; | |
122 base::scoped_nsobject<NSTextField> instructionsLabel_; | |
110 base::scoped_nsobject<NSTextField> cvcInput_; | 123 base::scoped_nsobject<NSTextField> cvcInput_; |
111 base::scoped_nsobject<NSPopUpButton> monthPopup_; | 124 base::scoped_nsobject<NSPopUpButton> monthPopup_; |
112 base::scoped_nsobject<NSPopUpButton> yearPopup_; | 125 base::scoped_nsobject<NSPopUpButton> yearPopup_; |
126 base::scoped_nsobject<NSButton> cancelButton_; | |
113 base::scoped_nsobject<NSButton> verifyButton_; | 127 base::scoped_nsobject<NSButton> verifyButton_; |
114 base::scoped_nsobject<NSButton> storageCheckbox_; | 128 base::scoped_nsobject<NSButton> storageCheckbox_; |
115 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; | 129 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; |
116 base::scoped_nsobject<NSView> inputRow_; | 130 base::scoped_nsobject<NSTextField> errorLabel_; |
117 base::scoped_nsobject<NSTextField> progressOverlayText_; | 131 base::scoped_nsobject<NSTextField> progressOverlayLabel_; |
118 | 132 |
119 int monthPopupDefaultIndex_; | 133 int monthPopupDefaultIndex_; |
120 int yearPopupDefaultIndex_; | 134 int yearPopupDefaultIndex_; |
121 | 135 |
122 // Owns |self|. | 136 // Owns |self|. |
123 autofill::CardUnmaskPromptViewBridge* bridge_; | 137 autofill::CardUnmaskPromptViewBridge* bridge_; |
124 } | 138 } |
125 | 139 |
126 + (NSPopUpButton*)buildDatePopupWithModel:(ui::ComboboxModel&)model { | 140 + (NSPopUpButton*)buildDatePopupWithModel:(ui::ComboboxModel&)model { |
127 NSPopUpButton* popup = | 141 NSPopUpButton* popup = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 | 175 |
162 return self; | 176 return self; |
163 } | 177 } |
164 | 178 |
165 - (void)setProgressOverlayText:(const base::string16&)text { | 179 - (void)setProgressOverlayText:(const base::string16&)text { |
166 if (!text.empty()) { | 180 if (!text.empty()) { |
167 NSAttributedString* attributedString = | 181 NSAttributedString* attributedString = |
168 constrained_window::GetAttributedLabelString( | 182 constrained_window::GetAttributedLabelString( |
169 SysUTF16ToNSString(text), kProgressFontStyle, NSCenterTextAlignment, | 183 SysUTF16ToNSString(text), kProgressFontStyle, NSCenterTextAlignment, |
170 NSLineBreakByWordWrapping); | 184 NSLineBreakByWordWrapping); |
171 [progressOverlayText_ setAttributedStringValue:attributedString]; | 185 [progressOverlayLabel_ setAttributedStringValue:attributedString]; |
172 } | 186 } |
173 | 187 |
174 [progressOverlayText_ setHidden:text.empty()]; | 188 [progressOverlayLabel_ setHidden:text.empty()]; |
175 [inputRow_ setHidden:!text.empty()]; | 189 [inputRowView_ setHidden:!text.empty()]; |
176 [self updateVerifyButtonEnabled]; | 190 [self updateVerifyButtonEnabled]; |
177 } | 191 } |
178 | 192 |
193 - (void)setRetriableErrorMessage:(const base::string16&)text { | |
194 NSAttributedString* attributedString = | |
195 constrained_window::GetAttributedLabelString( | |
196 SysUTF16ToNSString(text), kErrorFontStyle, NSNaturalTextAlignment, | |
197 NSLineBreakByWordWrapping); | |
198 [errorLabel_ setAttributedStringValue:attributedString]; | |
199 [self performLayout]; | |
200 } | |
201 | |
179 - (void)updateVerifyButtonEnabled { | 202 - (void)updateVerifyButtonEnabled { |
180 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 203 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); |
181 DCHECK(controller); | 204 DCHECK(controller); |
182 | 205 |
183 BOOL enable = | 206 BOOL enable = |
184 ![inputRow_ isHidden] && | 207 ![inputRowView_ isHidden] && |
185 controller->InputCvcIsValid( | 208 controller->InputCvcIsValid( |
186 base::SysNSStringToUTF16([cvcInput_ stringValue])) && | 209 base::SysNSStringToUTF16([cvcInput_ stringValue])) && |
187 (!monthPopup_ || | 210 (!monthPopup_ || |
188 [monthPopup_ indexOfSelectedItem] != monthPopupDefaultIndex_) && | 211 [monthPopup_ indexOfSelectedItem] != monthPopupDefaultIndex_) && |
189 (!yearPopup_ || | 212 (!yearPopup_ || |
190 [yearPopup_ indexOfSelectedItem] != yearPopupDefaultIndex_); | 213 [yearPopup_ indexOfSelectedItem] != yearPopupDefaultIndex_); |
191 | 214 |
192 [verifyButton_ setEnabled:enable]; | 215 [verifyButton_ setEnabled:enable]; |
193 } | 216 } |
194 | 217 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 // "?" icon with tooltip. | 258 // "?" icon with tooltip. |
236 storageTooltip_.reset([[AutofillTooltipController alloc] | 259 storageTooltip_.reset([[AutofillTooltipController alloc] |
237 initWithArrowLocation:info_bubble::kTopRight]); | 260 initWithArrowLocation:info_bubble::kTopRight]); |
238 [storageTooltip_ setImage:ui::ResourceBundle::GetSharedInstance() | 261 [storageTooltip_ setImage:ui::ResourceBundle::GetSharedInstance() |
239 .GetNativeImageNamed(IDR_AUTOFILL_TOOLTIP_ICON) | 262 .GetNativeImageNamed(IDR_AUTOFILL_TOOLTIP_ICON) |
240 .ToNSImage()]; | 263 .ToNSImage()]; |
241 [storageTooltip_ | 264 [storageTooltip_ |
242 setMessage:base::SysUTF16ToNSString(l10n_util::GetStringUTF16( | 265 setMessage:base::SysUTF16ToNSString(l10n_util::GetStringUTF16( |
243 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLTIP))]; | 266 IDS_AUTOFILL_CARD_UNMASK_PROMPT_STORAGE_TOOLTIP))]; |
244 [view addSubview:[storageTooltip_ view]]; | 267 [view addSubview:[storageTooltip_ view]]; |
245 [[storageTooltip_ view] | 268 [[storageTooltip_ view] setFrameOrigin: |
246 setFrameOrigin:NSMakePoint(NSMaxX([storageCheckbox_ frame]) + kButtonGap, | 269 NSMakePoint(NSMaxX([storageCheckbox_ frame]) + kButtonGap, 0)]; |
247 0)]; | |
248 | 270 |
249 [CardUnmaskPromptViewCocoa sizeToFitView:view]; | 271 [CardUnmaskPromptViewCocoa sizeToFitView:view]; |
250 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:view]; | 272 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:view]; |
251 return view; | 273 return view; |
252 } | 274 } |
253 | 275 |
276 - (void)performLayout { | |
277 // Calculate dialog content width. | |
278 CGFloat contentWidth = | |
279 std::max(NSWidth([titleLabel_ frame]), NSWidth([inputRowView_ frame])); | |
280 contentWidth = std::max(contentWidth, NSWidth([storageView_ frame])); | |
281 contentWidth = std::max(contentWidth, kDialogContentMinWidth); | |
groby-ooo-7-16
2015/03/24 01:26:49
This is weird to me - we only invoke this after in
bondd
2015/03/24 23:46:47
Dialog width stays the same, but dialog height cha
| |
282 | |
283 [storageView_ | |
groby-ooo-7-16
2015/03/24 01:26:49
At this point, the layout is sufficiently complex
bondd
2015/03/24 23:46:47
Done.
| |
284 setFrameOrigin:NSMakePoint(0, chrome_style::kClientBottomPadding)]; | |
285 | |
286 [verifyButton_ setFrameOrigin: | |
287 NSMakePoint(contentWidth - NSWidth([verifyButton_ frame]), | |
288 NSMaxY([storageView_ frame]) + chrome_style::kRowPadding)]; | |
289 | |
290 [cancelButton_ | |
291 setFrameOrigin:NSMakePoint(NSMinX([verifyButton_ frame]) - kButtonGap - | |
292 NSWidth([cancelButton_ frame]), | |
293 NSMinY([verifyButton_ frame]))]; | |
294 | |
295 // Error message label. | |
groby-ooo-7-16
2015/03/24 01:26:49
Please do use a complete sentence, here and elsewh
bondd
2015/03/24 23:46:47
Done. Removed some of these comments because code
| |
296 [errorLabel_ setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton_ frame]) + | |
297 chrome_style::kRowPadding)]; | |
298 NSSize errorSize = [[errorLabel_ cell] | |
299 cellSizeForBounds:NSMakeRect(0, 0, contentWidth, CGFLOAT_MAX)]; | |
groby-ooo-7-16
2015/03/24 01:26:50
We do this in several places - probably worth hois
bondd
2015/03/24 23:46:47
I hoisted it to the top of this class, with a TODO
| |
300 [errorLabel_ setFrameSize:errorSize]; | |
301 | |
302 // Input row. | |
303 [inputRowView_ setFrameOrigin:NSMakePoint(0, NSMaxY([errorLabel_ frame]) + | |
304 chrome_style::kRowPadding)]; | |
305 | |
306 // Instruction label. | |
307 [instructionsLabel_ | |
308 setFrameOrigin:NSMakePoint(0, NSMaxY([inputRowView_ frame]) + | |
309 chrome_style::kRowPadding)]; | |
310 NSSize instructionsSize = [[instructionsLabel_ cell] | |
311 cellSizeForBounds:NSMakeRect(0, 0, contentWidth, CGFLOAT_MAX)]; | |
312 [instructionsLabel_ setFrameSize:instructionsSize]; | |
313 | |
314 // Title label. | |
315 [titleLabel_ | |
316 setFrameOrigin:NSMakePoint(0, NSMaxY([instructionsLabel_ frame]) + | |
317 chrome_style::kRowPadding)]; | |
318 | |
319 // Center progressOverlayLabel_ vertically within inputRowView_ frame. | |
320 CGFloat progressHeight = ui::ResourceBundle::GetSharedInstance() | |
321 .GetFont(kProgressFontStyle) | |
322 .GetHeight(); | |
323 [progressOverlayLabel_ | |
324 setFrame:NSMakeRect(0, ceil(NSMidY([inputRowView_ frame]) - | |
325 progressHeight / 2.0), | |
326 contentWidth, progressHeight)]; | |
327 | |
328 // Dialog size. | |
329 [[self view] | |
330 setFrameSize:NSMakeSize( | |
331 contentWidth + chrome_style::kHorizontalPadding * 2.0, | |
332 NSMaxY([titleLabel_ frame]) + | |
333 chrome_style::kTitleTopPadding)]; | |
334 | |
335 NSRect frameRect = | |
336 [[[self view] window] frameRectForContentRect:[[self view] frame]]; | |
337 [[[self view] window] setFrame:frameRect display:YES]; | |
338 } | |
339 | |
254 - (void)loadView { | 340 - (void)loadView { |
255 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 341 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); |
256 DCHECK(controller); | 342 DCHECK(controller); |
257 | 343 |
258 base::scoped_nsobject<NSBox> mainView( | 344 base::scoped_nsobject<NSBox> mainView( |
259 [[NSBox alloc] initWithFrame:NSZeroRect]); | 345 [[NSBox alloc] initWithFrame:NSZeroRect]); |
260 [mainView setBoxType:NSBoxCustom]; | 346 [mainView setBoxType:NSBoxCustom]; |
261 [mainView setBorderType:NSNoBorder]; | 347 [mainView setBorderType:NSNoBorder]; |
262 [mainView setTitlePosition:NSNoTitle]; | 348 [mainView setTitlePosition:NSNoTitle]; |
263 [mainView | 349 [mainView |
264 setContentViewMargins:NSMakeSize(chrome_style::kHorizontalPadding, 0)]; | 350 setContentViewMargins:NSMakeSize(chrome_style::kHorizontalPadding, 0)]; |
265 | 351 |
266 inputRow_.reset([[NSView alloc] initWithFrame:NSZeroRect]); | 352 inputRowView_.reset([[NSView alloc] initWithFrame:NSZeroRect]); |
267 [mainView addSubview:inputRow_]; | 353 [mainView addSubview:inputRowView_]; |
268 | 354 |
269 base::scoped_nsobject<NSView> storageView( | 355 storageView_ = [self createStorageViewWithController:controller]; |
270 [self createStorageViewWithController:controller]); | 356 [mainView addSubview:storageView_]; |
271 [mainView addSubview:storageView]; | 357 |
358 progressOverlayLabel_.reset([constrained_window::CreateLabel() retain]); | |
359 [progressOverlayLabel_ setHidden:YES]; | |
360 [mainView addSubview:progressOverlayLabel_]; | |
272 | 361 |
273 // Title label. | 362 // Title label. |
274 NSTextField* title = constrained_window::CreateLabel(); | 363 titleLabel_.reset([constrained_window::CreateLabel() retain]); |
275 NSAttributedString* titleString = | 364 NSAttributedString* titleString = |
276 constrained_window::GetAttributedLabelString( | 365 constrained_window::GetAttributedLabelString( |
277 SysUTF16ToNSString(controller->GetWindowTitle()), | 366 SysUTF16ToNSString(controller->GetWindowTitle()), |
278 chrome_style::kTitleFontStyle, NSNaturalTextAlignment, | 367 chrome_style::kTitleFontStyle, NSNaturalTextAlignment, |
279 NSLineBreakByWordWrapping); | 368 NSLineBreakByWordWrapping); |
280 [title setAttributedStringValue:titleString]; | 369 [titleLabel_ setAttributedStringValue:titleString]; |
281 [title sizeToFit]; | 370 [titleLabel_ sizeToFit]; |
282 [mainView addSubview:title]; | 371 [mainView addSubview:titleLabel_]; |
283 | 372 |
284 // Instructions label. | 373 // Instructions label. |
285 NSTextField* instructions = constrained_window::CreateLabel(); | 374 instructionsLabel_.reset([constrained_window::CreateLabel() retain]); |
286 NSAttributedString* instructionsString = | 375 NSAttributedString* instructionsString = |
287 constrained_window::GetAttributedLabelString( | 376 constrained_window::GetAttributedLabelString( |
288 SysUTF16ToNSString(controller->GetInstructionsMessage()), | 377 SysUTF16ToNSString(controller->GetInstructionsMessage()), |
289 chrome_style::kTextFontStyle, NSNaturalTextAlignment, | 378 chrome_style::kTextFontStyle, NSNaturalTextAlignment, |
290 NSLineBreakByWordWrapping); | 379 NSLineBreakByWordWrapping); |
291 [instructions setAttributedStringValue:instructionsString]; | 380 [instructionsLabel_ setAttributedStringValue:instructionsString]; |
292 [mainView addSubview:instructions]; | 381 [mainView addSubview:instructionsLabel_]; |
293 | 382 |
294 // Expiration date. | 383 // Expiration date. |
295 base::scoped_nsobject<NSView> expirationView; | |
296 if (controller->ShouldRequestExpirationDate()) { | 384 if (controller->ShouldRequestExpirationDate()) { |
297 expirationView.reset([[NSView alloc] initWithFrame:NSZeroRect]); | 385 expirationView_.reset([[NSView alloc] initWithFrame:NSZeroRect]); |
298 | 386 |
299 // Month. | 387 // Month. |
300 autofill::MonthComboboxModel monthModel; | 388 autofill::MonthComboboxModel monthModel; |
301 monthPopupDefaultIndex_ = monthModel.GetDefaultIndex(); | 389 monthPopupDefaultIndex_ = monthModel.GetDefaultIndex(); |
302 monthPopup_.reset( | 390 monthPopup_.reset( |
303 [CardUnmaskPromptViewCocoa buildDatePopupWithModel:monthModel]); | 391 [CardUnmaskPromptViewCocoa buildDatePopupWithModel:monthModel]); |
304 [monthPopup_ setTarget:self]; | 392 [monthPopup_ setTarget:self]; |
305 [monthPopup_ setAction:@selector(onExpirationDateChanged:)]; | 393 [monthPopup_ setAction:@selector(onExpirationDateChanged:)]; |
306 [expirationView addSubview:monthPopup_]; | 394 [expirationView_ addSubview:monthPopup_]; |
307 | 395 |
308 // Year. | 396 // Year. |
309 autofill::YearComboboxModel yearModel; | 397 autofill::YearComboboxModel yearModel; |
310 yearPopupDefaultIndex_ = yearModel.GetDefaultIndex(); | 398 yearPopupDefaultIndex_ = yearModel.GetDefaultIndex(); |
311 yearPopup_.reset( | 399 yearPopup_.reset( |
312 [CardUnmaskPromptViewCocoa buildDatePopupWithModel:yearModel]); | 400 [CardUnmaskPromptViewCocoa buildDatePopupWithModel:yearModel]); |
313 [yearPopup_ setTarget:self]; | 401 [yearPopup_ setTarget:self]; |
314 [yearPopup_ setAction:@selector(onExpirationDateChanged:)]; | 402 [yearPopup_ setAction:@selector(onExpirationDateChanged:)]; |
315 [expirationView addSubview:yearPopup_]; | 403 [expirationView_ addSubview:yearPopup_]; |
316 | 404 |
317 // Layout month and year within expirationView. | 405 // Layout month and year within expirationView_. |
318 [yearPopup_ | 406 [yearPopup_ |
319 setFrameOrigin:NSMakePoint(NSMaxX([monthPopup_ frame]) + kButtonGap, | 407 setFrameOrigin:NSMakePoint(NSMaxX([monthPopup_ frame]) + kButtonGap, |
320 0)]; | 408 0)]; |
321 NSRect expirationFrame = | 409 NSRect expirationFrame = |
322 NSUnionRect([monthPopup_ frame], [yearPopup_ frame]); | 410 NSUnionRect([monthPopup_ frame], [yearPopup_ frame]); |
323 expirationFrame.size.width += kButtonGap; | 411 expirationFrame.size.width += kButtonGap; |
324 [expirationView setFrame:expirationFrame]; | 412 [expirationView_ setFrame:expirationFrame]; |
325 [inputRow_ addSubview:expirationView]; | 413 [inputRowView_ addSubview:expirationView_]; |
326 } | 414 } |
327 | 415 |
328 // CVC text input. | 416 // CVC text input. |
329 cvcInput_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | 417 cvcInput_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); |
330 [[cvcInput_ cell] | 418 [[cvcInput_ cell] |
331 setPlaceholderString:l10n_util::GetNSString( | 419 setPlaceholderString:l10n_util::GetNSString( |
332 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)]; | 420 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)]; |
333 [[cvcInput_ cell] setScrollable:YES]; | 421 [[cvcInput_ cell] setScrollable:YES]; |
334 [cvcInput_ setDelegate:self]; | 422 [cvcInput_ setDelegate:self]; |
335 [cvcInput_ sizeToFit]; | 423 [cvcInput_ sizeToFit]; |
336 [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView frame]), 0, | 424 [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView_ frame]), 0, |
337 kCvcInputWidth, NSHeight([cvcInput_ frame]))]; | 425 kCvcInputWidth, NSHeight([cvcInput_ frame]))]; |
338 [inputRow_ addSubview:cvcInput_]; | 426 [inputRowView_ addSubview:cvcInput_]; |
339 | 427 |
340 // CVC image. | 428 // CVC image. |
341 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 429 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
342 NSImage* cvcImage = | 430 NSImage* cvcImage = |
343 rb.GetNativeImageNamed(controller->GetCvcImageRid()).ToNSImage(); | 431 rb.GetNativeImageNamed(controller->GetCvcImageRid()).ToNSImage(); |
344 base::scoped_nsobject<NSImageView> cvcImageView( | 432 base::scoped_nsobject<NSImageView> cvcImageView( |
345 [[NSImageView alloc] initWithFrame:NSZeroRect]); | 433 [[NSImageView alloc] initWithFrame:NSZeroRect]); |
346 [cvcImageView setImage:cvcImage]; | 434 [cvcImageView setImage:cvcImage]; |
347 [cvcImageView setFrameSize:[cvcImage size]]; | 435 [cvcImageView setFrameSize:[cvcImage size]]; |
348 [cvcImageView | 436 [cvcImageView |
349 setFrameOrigin:NSMakePoint(NSMaxX([cvcInput_ frame]) + kButtonGap, 0)]; | 437 setFrameOrigin:NSMakePoint(NSMaxX([cvcInput_ frame]) + kButtonGap, 0)]; |
350 [inputRow_ addSubview:cvcImageView]; | 438 [inputRowView_ addSubview:cvcImageView]; |
439 | |
440 // Error message label. | |
441 errorLabel_.reset([constrained_window::CreateLabel() retain]); | |
442 [errorLabel_ | |
443 setTextColor:gfx::SkColorToCalibratedNSColor(autofill::kWarningColor)]; | |
444 [mainView addSubview:errorLabel_]; | |
351 | 445 |
352 // Cancel button. | 446 // Cancel button. |
353 base::scoped_nsobject<NSButton> cancelButton( | 447 cancelButton_.reset( |
354 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 448 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
355 [cancelButton setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; | 449 [cancelButton_ setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; |
356 [cancelButton setKeyEquivalent:kKeyEquivalentEscape]; | 450 [cancelButton_ setKeyEquivalent:kKeyEquivalentEscape]; |
357 [cancelButton setTarget:self]; | 451 [cancelButton_ setTarget:self]; |
358 [cancelButton setAction:@selector(onCancel:)]; | 452 [cancelButton_ setAction:@selector(onCancel:)]; |
359 [cancelButton sizeToFit]; | 453 [cancelButton_ sizeToFit]; |
360 [mainView addSubview:cancelButton]; | 454 [mainView addSubview:cancelButton_]; |
361 | 455 |
362 // Verify button. | 456 // Verify button. |
363 verifyButton_.reset( | 457 verifyButton_.reset( |
364 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 458 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
365 // TODO(bondd): use l10n string. | 459 // TODO(bondd): use l10n string. |
366 [verifyButton_ setTitle:@"Verify"]; | 460 [verifyButton_ setTitle:@"Verify"]; |
367 [verifyButton_ setKeyEquivalent:kKeyEquivalentReturn]; | 461 [verifyButton_ setKeyEquivalent:kKeyEquivalentReturn]; |
368 [verifyButton_ setTarget:self]; | 462 [verifyButton_ setTarget:self]; |
369 [verifyButton_ setAction:@selector(onVerify:)]; | 463 [verifyButton_ setAction:@selector(onVerify:)]; |
370 [verifyButton_ sizeToFit]; | 464 [verifyButton_ sizeToFit]; |
371 [self updateVerifyButtonEnabled]; | 465 [self updateVerifyButtonEnabled]; |
372 [mainView addSubview:verifyButton_]; | 466 [mainView addSubview:verifyButton_]; |
373 | 467 |
374 // Layout inputRow_. | 468 // Layout inputRowView_. |
375 [CardUnmaskPromptViewCocoa sizeToFitView:inputRow_]; | 469 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView_]; |
376 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRow_]; | 470 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView_]; |
377 | |
378 // Calculate dialog content width. | |
379 CGFloat contentWidth = | |
380 std::max(NSWidth([title frame]), NSWidth([inputRow_ frame])); | |
381 contentWidth = std::max(contentWidth, NSWidth([storageView frame])); | |
382 contentWidth = std::max(contentWidth, kDialogContentMinWidth); | |
383 | |
384 // Layout mainView contents, starting at the bottom and moving up. | |
385 | |
386 [storageView | |
387 setFrameOrigin:NSMakePoint(0, chrome_style::kClientBottomPadding)]; | |
388 | |
389 // Verify and Cancel buttons. | |
390 [verifyButton_ | |
391 setFrameOrigin:NSMakePoint(contentWidth - NSWidth([verifyButton_ frame]), | |
392 NSMaxY([storageView frame]) + | |
393 chrome_style::kRowPadding)]; | |
394 | |
395 [cancelButton | |
396 setFrameOrigin:NSMakePoint(NSMinX([verifyButton_ frame]) - kButtonGap - | |
397 NSWidth([cancelButton frame]), | |
398 NSMinY([verifyButton_ frame]))]; | |
399 | |
400 // Input row. | |
401 [inputRow_ setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton frame]) + | |
402 chrome_style::kRowPadding)]; | |
403 | |
404 // Instruction label. | |
405 [instructions setFrameOrigin:NSMakePoint(0, NSMaxY([inputRow_ frame]) + | |
406 chrome_style::kRowPadding)]; | |
407 NSSize instructionsSize = [[instructions cell] | |
408 cellSizeForBounds:NSMakeRect(0, 0, contentWidth, CGFLOAT_MAX)]; | |
409 [instructions setFrameSize:instructionsSize]; | |
410 | |
411 // Title label. | |
412 [title setFrameOrigin:NSMakePoint(0, NSMaxY([instructions frame]) + | |
413 chrome_style::kRowPadding)]; | |
414 | |
415 // Dialog size. | |
416 [mainView | |
417 setFrameSize:NSMakeSize( | |
418 contentWidth + [mainView contentViewMargins].width * 2.0, | |
419 NSMaxY([title frame]) + chrome_style::kTitleTopPadding)]; | |
420 | |
421 // Add progress overlay. | |
422 progressOverlayText_.reset([constrained_window::CreateLabel() retain]); | |
423 CGFloat progressHeight = ui::ResourceBundle::GetSharedInstance() | |
424 .GetFont(kProgressFontStyle) | |
425 .GetHeight(); | |
426 // Center the text vertically within inputRow_ frame. | |
427 [progressOverlayText_ setFrame:NSMakeRect(0, ceil(NSMidY([inputRow_ frame]) - | |
428 progressHeight / 2.0), | |
429 contentWidth, progressHeight)]; | |
430 [progressOverlayText_ setHidden:YES]; | |
431 [mainView addSubview:progressOverlayText_]; | |
432 | 471 |
433 [self setView:mainView]; | 472 [self setView:mainView]; |
473 [self performLayout]; | |
groby-ooo-7-16
2015/03/24 01:26:49
At this point -loadView will automatically display
bondd
2015/03/24 23:46:46
Done.
| |
434 } | 474 } |
435 | 475 |
436 @end | 476 @end |
OLD | NEW |