| 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" |
| 6 #include "base/message_loop/message_loop.h" |
| 5 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 6 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 7 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | 9 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
| 8 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" | 10 #import "chrome/browser/ui/cocoa/autofill/autofill_tooltip_controller.h" |
| 9 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h" | 11 #include "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_view_bridge.h" |
| 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 11 #include "chrome/browser/ui/chrome_style.h" | 13 #include "chrome/browser/ui/chrome_style.h" |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u
tils.h" | 14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u
tils.h" |
| 13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 15 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
| 14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 16 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
| 15 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 17 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 16 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 17 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 18 #include "ui/base/cocoa/window_size_constants.h" | 20 #include "ui/base/cocoa/window_size_constants.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 const CGFloat kButtonGap = 6.0f; | 25 const CGFloat kButtonGap = 6.0f; |
| 24 const CGFloat kDialogContentMinWidth = 210.0f; | 26 const CGFloat kDialogContentMinWidth = 210.0f; |
| 25 const CGFloat kCvcInputWidth = 64.0f; | 27 const CGFloat kCvcInputWidth = 64.0f; |
| 28 const ui::ResourceBundle::FontStyle kProgressFontStyle = |
| 29 chrome_style::kTitleFontStyle; |
| 26 | 30 |
| 27 } // namespace | 31 } // namespace |
| 28 | 32 |
| 29 namespace autofill { | 33 namespace autofill { |
| 30 | 34 |
| 31 // static | 35 // static |
| 32 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( | 36 CardUnmaskPromptView* CardUnmaskPromptView::CreateAndShow( |
| 33 CardUnmaskPromptController* controller) { | 37 CardUnmaskPromptController* controller) { |
| 34 return new CardUnmaskPromptViewBridge(controller); | 38 return new CardUnmaskPromptViewBridge(controller); |
| 35 } | 39 } |
| 36 | 40 |
| 37 #pragma mark CardUnmaskPromptViewBridge | 41 #pragma mark CardUnmaskPromptViewBridge |
| 38 | 42 |
| 39 CardUnmaskPromptViewBridge::CardUnmaskPromptViewBridge( | 43 CardUnmaskPromptViewBridge::CardUnmaskPromptViewBridge( |
| 40 CardUnmaskPromptController* controller) | 44 CardUnmaskPromptController* controller) |
| 41 : controller_(controller) { | 45 : controller_(controller), weak_ptr_factory_(this) { |
| 42 view_controller_.reset( | 46 view_controller_.reset( |
| 43 [[CardUnmaskPromptViewCocoa alloc] initWithBridge:this]); | 47 [[CardUnmaskPromptViewCocoa alloc] initWithBridge:this]); |
| 44 | 48 |
| 45 // Setup the constrained window that will show the view. | 49 // Setup the constrained window that will show the view. |
| 46 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] | 50 base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc] |
| 47 initWithContentRect:[[view_controller_ view] bounds]]); | 51 initWithContentRect:[[view_controller_ view] bounds]]); |
| 48 [window setContentView:[view_controller_ view]]; | 52 [window setContentView:[view_controller_ view]]; |
| 49 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 53 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| 50 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]); | 54 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]); |
| 51 constrained_window_.reset( | 55 constrained_window_.reset( |
| 52 new ConstrainedWindowMac(this, controller_->GetWebContents(), sheet)); | 56 new ConstrainedWindowMac(this, controller_->GetWebContents(), sheet)); |
| 53 } | 57 } |
| 54 | 58 |
| 55 CardUnmaskPromptViewBridge::~CardUnmaskPromptViewBridge() { | 59 CardUnmaskPromptViewBridge::~CardUnmaskPromptViewBridge() { |
| 56 } | 60 } |
| 57 | 61 |
| 58 void CardUnmaskPromptViewBridge::ControllerGone() { | 62 void CardUnmaskPromptViewBridge::ControllerGone() { |
| 59 controller_ = nullptr; | 63 controller_ = nullptr; |
| 60 PerformClose(); | 64 PerformClose(); |
| 61 } | 65 } |
| 62 | 66 |
| 63 void CardUnmaskPromptViewBridge::DisableAndWaitForVerification() { | 67 void CardUnmaskPromptViewBridge::DisableAndWaitForVerification() { |
| 64 [view_controller_ setInputsEnabled:false]; | 68 [view_controller_ setProgressOverlayText: |
| 65 [view_controller_ updateVerifyButtonEnabled]; | 69 l10n_util::GetStringUTF16( |
| 70 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_IN_PROGRESS)]; |
| 66 } | 71 } |
| 67 | 72 |
| 68 void CardUnmaskPromptViewBridge::GotVerificationResult( | 73 void CardUnmaskPromptViewBridge::GotVerificationResult( |
| 69 const base::string16& error_message, | 74 const base::string16& error_message, |
| 70 bool allow_retry) { | 75 bool allow_retry) { |
| 71 [view_controller_ setInputsEnabled:true]; | 76 if (error_message.empty()) { |
| 72 [view_controller_ updateVerifyButtonEnabled]; | 77 [view_controller_ setProgressOverlayText: |
| 78 l10n_util::GetStringUTF16( |
| 79 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)]; |
| 80 |
| 81 base::MessageLoop::current()->PostDelayedTask( |
| 82 FROM_HERE, base::Bind(&CardUnmaskPromptViewBridge::PerformClose, |
| 83 weak_ptr_factory_.GetWeakPtr()), |
| 84 base::TimeDelta::FromSeconds(1)); |
| 85 } else { |
| 86 [view_controller_ setProgressOverlayText:base::string16()]; |
| 87 } |
| 73 } | 88 } |
| 74 | 89 |
| 75 void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( | 90 void CardUnmaskPromptViewBridge::OnConstrainedWindowClosed( |
| 76 ConstrainedWindowMac* window) { | 91 ConstrainedWindowMac* window) { |
| 77 constrained_window_.reset(); | |
| 78 if (controller_) | 92 if (controller_) |
| 79 controller_->OnUnmaskDialogClosed(); | 93 controller_->OnUnmaskDialogClosed(); |
| 94 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 80 } | 95 } |
| 81 | 96 |
| 82 CardUnmaskPromptController* CardUnmaskPromptViewBridge::GetController() { | 97 CardUnmaskPromptController* CardUnmaskPromptViewBridge::GetController() { |
| 83 return controller_; | 98 return controller_; |
| 84 } | 99 } |
| 85 | 100 |
| 86 void CardUnmaskPromptViewBridge::PerformClose() { | 101 void CardUnmaskPromptViewBridge::PerformClose() { |
| 87 constrained_window_->CloseWebContentsModalDialog(); | 102 constrained_window_->CloseWebContentsModalDialog(); |
| 88 } | 103 } |
| 89 | 104 |
| 90 } // autofill | 105 } // autofill |
| 91 | 106 |
| 92 #pragma mark CardUnmaskPromptViewCocoa | 107 #pragma mark CardUnmaskPromptViewCocoa |
| 93 | 108 |
| 94 @implementation CardUnmaskPromptViewCocoa { | 109 @implementation CardUnmaskPromptViewCocoa { |
| 95 base::scoped_nsobject<NSTextField> cvcInput_; | 110 base::scoped_nsobject<NSTextField> cvcInput_; |
| 96 base::scoped_nsobject<NSPopUpButton> monthPopup_; | 111 base::scoped_nsobject<NSPopUpButton> monthPopup_; |
| 97 base::scoped_nsobject<NSPopUpButton> yearPopup_; | 112 base::scoped_nsobject<NSPopUpButton> yearPopup_; |
| 98 base::scoped_nsobject<NSButton> verifyButton_; | 113 base::scoped_nsobject<NSButton> verifyButton_; |
| 99 base::scoped_nsobject<NSButton> storageCheckbox_; | 114 base::scoped_nsobject<NSButton> storageCheckbox_; |
| 100 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; | 115 base::scoped_nsobject<AutofillTooltipController> storageTooltip_; |
| 116 base::scoped_nsobject<NSView> inputRow_; |
| 117 base::scoped_nsobject<NSTextField> progressOverlayText_; |
| 101 | 118 |
| 102 int monthPopupDefaultIndex_; | 119 int monthPopupDefaultIndex_; |
| 103 int yearPopupDefaultIndex_; | 120 int yearPopupDefaultIndex_; |
| 104 | 121 |
| 105 // Owns |self|. | 122 // Owns |self|. |
| 106 autofill::CardUnmaskPromptViewBridge* bridge_; | 123 autofill::CardUnmaskPromptViewBridge* bridge_; |
| 107 } | 124 } |
| 108 | 125 |
| 109 + (NSPopUpButton*)buildDatePopupWithModel:(ui::ComboboxModel&)model { | 126 + (NSPopUpButton*)buildDatePopupWithModel:(ui::ComboboxModel&)model { |
| 110 NSPopUpButton* popup = | 127 NSPopUpButton* popup = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 138 | 155 |
| 139 - (id)initWithBridge:(autofill::CardUnmaskPromptViewBridge*)bridge { | 156 - (id)initWithBridge:(autofill::CardUnmaskPromptViewBridge*)bridge { |
| 140 DCHECK(bridge); | 157 DCHECK(bridge); |
| 141 | 158 |
| 142 if ((self = [super initWithNibName:nil bundle:nil])) | 159 if ((self = [super initWithNibName:nil bundle:nil])) |
| 143 bridge_ = bridge; | 160 bridge_ = bridge; |
| 144 | 161 |
| 145 return self; | 162 return self; |
| 146 } | 163 } |
| 147 | 164 |
| 148 - (void)setInputsEnabled:(BOOL)enabled { | 165 - (void)setProgressOverlayText:(const base::string16&)text { |
| 149 [cvcInput_ setEnabled:enabled]; | 166 if (!text.empty()) { |
| 150 [monthPopup_ setEnabled:enabled]; | 167 NSAttributedString* attributedString = |
| 151 [yearPopup_ setEnabled:enabled]; | 168 constrained_window::GetAttributedLabelString( |
| 169 SysUTF16ToNSString(text), kProgressFontStyle, NSCenterTextAlignment, |
| 170 NSLineBreakByWordWrapping); |
| 171 [progressOverlayText_ setAttributedStringValue:attributedString]; |
| 172 } |
| 173 |
| 174 [progressOverlayText_ setHidden:text.empty()]; |
| 175 [inputRow_ setHidden:!text.empty()]; |
| 176 [self updateVerifyButtonEnabled]; |
| 152 } | 177 } |
| 153 | 178 |
| 154 - (void)updateVerifyButtonEnabled { | 179 - (void)updateVerifyButtonEnabled { |
| 155 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); | 180 autofill::CardUnmaskPromptController* controller = bridge_->GetController(); |
| 156 DCHECK(controller); | 181 DCHECK(controller); |
| 157 | 182 |
| 158 BOOL enable = | 183 BOOL enable = |
| 159 [cvcInput_ isEnabled] && | 184 ![inputRow_ isHidden] && |
| 160 controller->InputCvcIsValid( | 185 controller->InputCvcIsValid( |
| 161 base::SysNSStringToUTF16([cvcInput_ stringValue])) && | 186 base::SysNSStringToUTF16([cvcInput_ stringValue])) && |
| 162 (!monthPopup_ || | 187 (!monthPopup_ || |
| 163 [monthPopup_ indexOfSelectedItem] != monthPopupDefaultIndex_) && | 188 [monthPopup_ indexOfSelectedItem] != monthPopupDefaultIndex_) && |
| 164 (!yearPopup_ || | 189 (!yearPopup_ || |
| 165 [yearPopup_ indexOfSelectedItem] != yearPopupDefaultIndex_); | 190 [yearPopup_ indexOfSelectedItem] != yearPopupDefaultIndex_); |
| 166 | 191 |
| 167 [verifyButton_ setEnabled:enable]; | 192 [verifyButton_ setEnabled:enable]; |
| 168 } | 193 } |
| 169 | 194 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 DCHECK(controller); | 256 DCHECK(controller); |
| 232 | 257 |
| 233 base::scoped_nsobject<NSBox> mainView( | 258 base::scoped_nsobject<NSBox> mainView( |
| 234 [[NSBox alloc] initWithFrame:NSZeroRect]); | 259 [[NSBox alloc] initWithFrame:NSZeroRect]); |
| 235 [mainView setBoxType:NSBoxCustom]; | 260 [mainView setBoxType:NSBoxCustom]; |
| 236 [mainView setBorderType:NSNoBorder]; | 261 [mainView setBorderType:NSNoBorder]; |
| 237 [mainView setTitlePosition:NSNoTitle]; | 262 [mainView setTitlePosition:NSNoTitle]; |
| 238 [mainView | 263 [mainView |
| 239 setContentViewMargins:NSMakeSize(chrome_style::kHorizontalPadding, 0)]; | 264 setContentViewMargins:NSMakeSize(chrome_style::kHorizontalPadding, 0)]; |
| 240 | 265 |
| 241 base::scoped_nsobject<NSView> inputRowView( | 266 inputRow_.reset([[NSView alloc] initWithFrame:NSZeroRect]); |
| 242 [[NSView alloc] initWithFrame:NSZeroRect]); | 267 [mainView addSubview:inputRow_]; |
| 243 [mainView addSubview:inputRowView]; | |
| 244 | 268 |
| 245 base::scoped_nsobject<NSView> storageView( | 269 base::scoped_nsobject<NSView> storageView( |
| 246 [self createStorageViewWithController:controller]); | 270 [self createStorageViewWithController:controller]); |
| 247 [mainView addSubview:storageView]; | 271 [mainView addSubview:storageView]; |
| 248 | 272 |
| 249 // Title label. | 273 // Title label. |
| 250 NSTextField* title = constrained_window::CreateLabel(); | 274 NSTextField* title = constrained_window::CreateLabel(); |
| 251 NSAttributedString* titleString = | 275 NSAttributedString* titleString = |
| 252 constrained_window::GetAttributedLabelString( | 276 constrained_window::GetAttributedLabelString( |
| 253 SysUTF16ToNSString(controller->GetWindowTitle()), | 277 SysUTF16ToNSString(controller->GetWindowTitle()), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 [expirationView addSubview:yearPopup_]; | 315 [expirationView addSubview:yearPopup_]; |
| 292 | 316 |
| 293 // Layout month and year within expirationView. | 317 // Layout month and year within expirationView. |
| 294 [yearPopup_ | 318 [yearPopup_ |
| 295 setFrameOrigin:NSMakePoint(NSMaxX([monthPopup_ frame]) + kButtonGap, | 319 setFrameOrigin:NSMakePoint(NSMaxX([monthPopup_ frame]) + kButtonGap, |
| 296 0)]; | 320 0)]; |
| 297 NSRect expirationFrame = | 321 NSRect expirationFrame = |
| 298 NSUnionRect([monthPopup_ frame], [yearPopup_ frame]); | 322 NSUnionRect([monthPopup_ frame], [yearPopup_ frame]); |
| 299 expirationFrame.size.width += kButtonGap; | 323 expirationFrame.size.width += kButtonGap; |
| 300 [expirationView setFrame:expirationFrame]; | 324 [expirationView setFrame:expirationFrame]; |
| 301 [inputRowView addSubview:expirationView]; | 325 [inputRow_ addSubview:expirationView]; |
| 302 } | 326 } |
| 303 | 327 |
| 304 // CVC text input. | 328 // CVC text input. |
| 305 cvcInput_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | 329 cvcInput_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); |
| 306 [[cvcInput_ cell] | 330 [[cvcInput_ cell] |
| 307 setPlaceholderString:l10n_util::GetNSString( | 331 setPlaceholderString:l10n_util::GetNSString( |
| 308 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)]; | 332 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)]; |
| 309 [[cvcInput_ cell] setScrollable:YES]; | 333 [[cvcInput_ cell] setScrollable:YES]; |
| 310 [cvcInput_ setDelegate:self]; | 334 [cvcInput_ setDelegate:self]; |
| 311 [cvcInput_ sizeToFit]; | 335 [cvcInput_ sizeToFit]; |
| 312 [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView frame]), 0, | 336 [cvcInput_ setFrame:NSMakeRect(NSMaxX([expirationView frame]), 0, |
| 313 kCvcInputWidth, NSHeight([cvcInput_ frame]))]; | 337 kCvcInputWidth, NSHeight([cvcInput_ frame]))]; |
| 314 [inputRowView addSubview:cvcInput_]; | 338 [inputRow_ addSubview:cvcInput_]; |
| 315 | 339 |
| 316 // CVC image. | 340 // CVC image. |
| 317 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 341 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 318 NSImage* cvcImage = | 342 NSImage* cvcImage = |
| 319 rb.GetNativeImageNamed(controller->GetCvcImageRid()).ToNSImage(); | 343 rb.GetNativeImageNamed(controller->GetCvcImageRid()).ToNSImage(); |
| 320 base::scoped_nsobject<NSImageView> cvcImageView( | 344 base::scoped_nsobject<NSImageView> cvcImageView( |
| 321 [[NSImageView alloc] initWithFrame:NSZeroRect]); | 345 [[NSImageView alloc] initWithFrame:NSZeroRect]); |
| 322 [cvcImageView setImage:cvcImage]; | 346 [cvcImageView setImage:cvcImage]; |
| 323 [cvcImageView setFrameSize:[cvcImage size]]; | 347 [cvcImageView setFrameSize:[cvcImage size]]; |
| 324 [cvcImageView | 348 [cvcImageView |
| 325 setFrameOrigin:NSMakePoint(NSMaxX([cvcInput_ frame]) + kButtonGap, 0)]; | 349 setFrameOrigin:NSMakePoint(NSMaxX([cvcInput_ frame]) + kButtonGap, 0)]; |
| 326 [inputRowView addSubview:cvcImageView]; | 350 [inputRow_ addSubview:cvcImageView]; |
| 327 | 351 |
| 328 // Cancel button. | 352 // Cancel button. |
| 329 base::scoped_nsobject<NSButton> cancelButton( | 353 base::scoped_nsobject<NSButton> cancelButton( |
| 330 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 354 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
| 331 [cancelButton setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; | 355 [cancelButton setTitle:l10n_util::GetNSStringWithFixup(IDS_CANCEL)]; |
| 332 [cancelButton setKeyEquivalent:kKeyEquivalentEscape]; | 356 [cancelButton setKeyEquivalent:kKeyEquivalentEscape]; |
| 333 [cancelButton setTarget:self]; | 357 [cancelButton setTarget:self]; |
| 334 [cancelButton setAction:@selector(onCancel:)]; | 358 [cancelButton setAction:@selector(onCancel:)]; |
| 335 [cancelButton sizeToFit]; | 359 [cancelButton sizeToFit]; |
| 336 [mainView addSubview:cancelButton]; | 360 [mainView addSubview:cancelButton]; |
| 337 | 361 |
| 338 // Verify button. | 362 // Verify button. |
| 339 verifyButton_.reset( | 363 verifyButton_.reset( |
| 340 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 364 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
| 341 // TODO(bondd): use l10n string. | 365 // TODO(bondd): use l10n string. |
| 342 [verifyButton_ setTitle:@"Verify"]; | 366 [verifyButton_ setTitle:@"Verify"]; |
| 343 [verifyButton_ setKeyEquivalent:kKeyEquivalentReturn]; | 367 [verifyButton_ setKeyEquivalent:kKeyEquivalentReturn]; |
| 344 [verifyButton_ setTarget:self]; | 368 [verifyButton_ setTarget:self]; |
| 345 [verifyButton_ setAction:@selector(onVerify:)]; | 369 [verifyButton_ setAction:@selector(onVerify:)]; |
| 346 [verifyButton_ sizeToFit]; | 370 [verifyButton_ sizeToFit]; |
| 347 [self updateVerifyButtonEnabled]; | 371 [self updateVerifyButtonEnabled]; |
| 348 [mainView addSubview:verifyButton_]; | 372 [mainView addSubview:verifyButton_]; |
| 349 | 373 |
| 350 // Layout inputRowView. | 374 // Layout inputRow_. |
| 351 [CardUnmaskPromptViewCocoa sizeToFitView:inputRowView]; | 375 [CardUnmaskPromptViewCocoa sizeToFitView:inputRow_]; |
| 352 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRowView]; | 376 [CardUnmaskPromptViewCocoa verticallyCenterSubviewsInView:inputRow_]; |
| 353 | 377 |
| 354 // Calculate dialog content width. | 378 // Calculate dialog content width. |
| 355 CGFloat contentWidth = | 379 CGFloat contentWidth = |
| 356 std::max(NSWidth([title frame]), NSWidth([inputRowView frame])); | 380 std::max(NSWidth([title frame]), NSWidth([inputRow_ frame])); |
| 357 contentWidth = std::max(contentWidth, NSWidth([storageView frame])); | 381 contentWidth = std::max(contentWidth, NSWidth([storageView frame])); |
| 358 contentWidth = std::max(contentWidth, kDialogContentMinWidth); | 382 contentWidth = std::max(contentWidth, kDialogContentMinWidth); |
| 359 | 383 |
| 360 // Layout mainView contents, starting at the bottom and moving up. | 384 // Layout mainView contents, starting at the bottom and moving up. |
| 361 | 385 |
| 362 [storageView | 386 [storageView |
| 363 setFrameOrigin:NSMakePoint(0, chrome_style::kClientBottomPadding)]; | 387 setFrameOrigin:NSMakePoint(0, chrome_style::kClientBottomPadding)]; |
| 364 | 388 |
| 365 // Verify and Cancel buttons. | 389 // Verify and Cancel buttons. |
| 366 [verifyButton_ | 390 [verifyButton_ |
| 367 setFrameOrigin:NSMakePoint(contentWidth - NSWidth([verifyButton_ frame]), | 391 setFrameOrigin:NSMakePoint(contentWidth - NSWidth([verifyButton_ frame]), |
| 368 NSMaxY([storageView frame]) + | 392 NSMaxY([storageView frame]) + |
| 369 chrome_style::kRowPadding)]; | 393 chrome_style::kRowPadding)]; |
| 370 | 394 |
| 371 [cancelButton | 395 [cancelButton |
| 372 setFrameOrigin:NSMakePoint(NSMinX([verifyButton_ frame]) - kButtonGap - | 396 setFrameOrigin:NSMakePoint(NSMinX([verifyButton_ frame]) - kButtonGap - |
| 373 NSWidth([cancelButton frame]), | 397 NSWidth([cancelButton frame]), |
| 374 NSMinY([verifyButton_ frame]))]; | 398 NSMinY([verifyButton_ frame]))]; |
| 375 | 399 |
| 376 // Input row. | 400 // Input row. |
| 377 [inputRowView setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton frame]) + | 401 [inputRow_ setFrameOrigin:NSMakePoint(0, NSMaxY([cancelButton frame]) + |
| 378 chrome_style::kRowPadding)]; | 402 chrome_style::kRowPadding)]; |
| 379 | 403 |
| 380 // Instruction label. | 404 // Instruction label. |
| 381 [instructions setFrameOrigin:NSMakePoint(0, NSMaxY([inputRowView frame]) + | 405 [instructions setFrameOrigin:NSMakePoint(0, NSMaxY([inputRow_ frame]) + |
| 382 chrome_style::kRowPadding)]; | 406 chrome_style::kRowPadding)]; |
| 383 NSSize instructionsSize = [[instructions cell] | 407 NSSize instructionsSize = [[instructions cell] |
| 384 cellSizeForBounds:NSMakeRect(0, 0, contentWidth, CGFLOAT_MAX)]; | 408 cellSizeForBounds:NSMakeRect(0, 0, contentWidth, CGFLOAT_MAX)]; |
| 385 [instructions setFrameSize:instructionsSize]; | 409 [instructions setFrameSize:instructionsSize]; |
| 386 | 410 |
| 387 // Title label. | 411 // Title label. |
| 388 [title setFrameOrigin:NSMakePoint(0, NSMaxY([instructions frame]) + | 412 [title setFrameOrigin:NSMakePoint(0, NSMaxY([instructions frame]) + |
| 389 chrome_style::kRowPadding)]; | 413 chrome_style::kRowPadding)]; |
| 390 | 414 |
| 391 // Dialog size. | 415 // Dialog size. |
| 392 [mainView | 416 [mainView |
| 393 setFrameSize:NSMakeSize( | 417 setFrameSize:NSMakeSize( |
| 394 contentWidth + [mainView contentViewMargins].width * 2.0, | 418 contentWidth + [mainView contentViewMargins].width * 2.0, |
| 395 NSMaxY([title frame]) + chrome_style::kTitleTopPadding)]; | 419 NSMaxY([title frame]) + chrome_style::kTitleTopPadding)]; |
| 396 | 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 |
| 397 [self setView:mainView]; | 433 [self setView:mainView]; |
| 398 } | 434 } |
| 399 | 435 |
| 400 @end | 436 @end |
| OLD | NEW |