| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | 13 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
| 14 #include "chrome/browser/ui/chrome_style.h" | 14 #include "chrome/browser/ui/chrome_style.h" |
| 15 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" | 15 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" |
| 16 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" | 16 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" |
| 17 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 17 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
| 18 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" | 18 #import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h" |
| 19 #import "chrome/browser/ui/cocoa/autofill/autofill_loading_shield_controller.h" |
| 19 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" | 20 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
| 20 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" | 21 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" |
| 21 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | 22 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
| 22 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" | 23 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" |
| 23 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" | 24 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
| 24 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 25 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
| 25 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" | 26 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi
ndow.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_contents_view.h" | 28 #include "content/public/browser/web_contents_view.h" |
| 28 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 227 |
| 227 void AutofillDialogCocoa::OnConstrainedWindowClosed( | 228 void AutofillDialogCocoa::OnConstrainedWindowClosed( |
| 228 ConstrainedWindowMac* window) { | 229 ConstrainedWindowMac* window) { |
| 229 constrained_window_.reset(); | 230 constrained_window_.reset(); |
| 230 // |this| belongs to |delegate_|, so no self-destruction here. | 231 // |this| belongs to |delegate_|, so no self-destruction here. |
| 231 delegate_->ViewClosed(); | 232 delegate_->ViewClosed(); |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // autofill | 235 } // autofill |
| 235 | 236 |
| 236 #pragma mark "Loading" Shield | |
| 237 | |
| 238 @interface AutofillOpaqueView : NSView | |
| 239 @end | |
| 240 | |
| 241 @implementation AutofillOpaqueView | |
| 242 | |
| 243 - (BOOL)isOpaque { | |
| 244 return YES; | |
| 245 } | |
| 246 | |
| 247 - (void)drawRect:(NSRect)dirtyRect { | |
| 248 [[[self window] backgroundColor] setFill]; | |
| 249 [NSBezierPath fillRect:[self bounds]]; | |
| 250 } | |
| 251 | |
| 252 @end | |
| 253 | |
| 254 | |
| 255 #pragma mark Field Editor | 237 #pragma mark Field Editor |
| 256 | 238 |
| 257 @interface AutofillDialogFieldEditor : NSTextView | 239 @interface AutofillDialogFieldEditor : NSTextView |
| 258 @end | 240 @end |
| 259 | 241 |
| 260 | 242 |
| 261 @implementation AutofillDialogFieldEditor | 243 @implementation AutofillDialogFieldEditor |
| 262 | 244 |
| 263 - (void)mouseDown:(NSEvent*)event { | 245 - (void)mouseDown:(NSEvent*)event { |
| 264 // Delegate _must_ be notified before mouseDown is complete, since it needs | 246 // Delegate _must_ be notified before mouseDown is complete, since it needs |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 [titleTextField_ setDrawsBackground:NO]; | 318 [titleTextField_ setDrawsBackground:NO]; |
| 337 [titleTextField_ setFont:[NSFont systemFontOfSize:15.0]]; | 319 [titleTextField_ setFont:[NSFont systemFontOfSize:15.0]]; |
| 338 [titleTextField_ setStringValue: | 320 [titleTextField_ setStringValue: |
| 339 base::SysUTF16ToNSString(autofillDialog->delegate()->DialogTitle())]; | 321 base::SysUTF16ToNSString(autofillDialog->delegate()->DialogTitle())]; |
| 340 [titleTextField_ sizeToFit]; | 322 [titleTextField_ sizeToFit]; |
| 341 | 323 |
| 342 accountChooser_.reset([[AutofillAccountChooser alloc] | 324 accountChooser_.reset([[AutofillAccountChooser alloc] |
| 343 initWithFrame:NSZeroRect | 325 initWithFrame:NSZeroRect |
| 344 delegate:autofillDialog->delegate()]); | 326 delegate:autofillDialog->delegate()]); |
| 345 | 327 |
| 346 loadingShieldTextField_.reset( | 328 loadingShieldController_.reset( |
| 347 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 329 [[AutofillLoadingShieldController alloc] |
| 348 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 330 initWithDelegate:autofillDialog->delegate()]); |
| 349 NSFont* loadingFont = rb.GetFont( | 331 [[loadingShieldController_ view] setHidden:YES]; |
| 350 ui::ResourceBundle::BaseFont).DeriveFont(15).GetNativeFont(); | |
| 351 [loadingShieldTextField_ setFont:loadingFont]; | |
| 352 [loadingShieldTextField_ setEditable:NO]; | |
| 353 [loadingShieldTextField_ setBordered:NO]; | |
| 354 [loadingShieldTextField_ setDrawsBackground:NO]; | |
| 355 | |
| 356 base::scoped_nsobject<AutofillOpaqueView> loadingShieldView( | |
| 357 [[AutofillOpaqueView alloc] initWithFrame:NSZeroRect]); | |
| 358 [loadingShieldView setHidden:YES]; | |
| 359 [loadingShieldView addSubview:loadingShieldTextField_]; | |
| 360 | 332 |
| 361 overlayController_.reset( | 333 overlayController_.reset( |
| 362 [[AutofillOverlayController alloc] initWithDelegate: | 334 [[AutofillOverlayController alloc] initWithDelegate: |
| 363 autofillDialog->delegate()]); | 335 autofillDialog->delegate()]); |
| 364 [[overlayController_ view] setHidden:YES]; | 336 [[overlayController_ view] setHidden:YES]; |
| 365 | 337 |
| 366 // This needs a flipped content view because otherwise the size | 338 // This needs a flipped content view because otherwise the size |
| 367 // animation looks odd. However, replacing the contentView for constrained | 339 // animation looks odd. However, replacing the contentView for constrained |
| 368 // windows does not work - it does custom rendering. | 340 // windows does not work - it does custom rendering. |
| 369 base::scoped_nsobject<NSView> flippedContentView( | 341 base::scoped_nsobject<NSView> flippedContentView( |
| 370 [[FlippedView alloc] initWithFrame: | 342 [[FlippedView alloc] initWithFrame: |
| 371 [[[self window] contentView] frame]]); | 343 [[[self window] contentView] frame]]); |
| 372 [flippedContentView setSubviews: | 344 [flippedContentView setSubviews: |
| 373 @[accountChooser_, | 345 @[accountChooser_, |
| 374 titleTextField_, | 346 titleTextField_, |
| 375 [mainContainer_ view], | 347 [mainContainer_ view], |
| 376 [signInContainer_ view], | 348 [signInContainer_ view], |
| 377 loadingShieldView, | 349 [loadingShieldController_ view], |
| 378 [overlayController_ view]]]; | 350 [overlayController_ view]]]; |
| 379 [flippedContentView setAutoresizingMask: | 351 [flippedContentView setAutoresizingMask: |
| 380 (NSViewWidthSizable | NSViewHeightSizable)]; | 352 (NSViewWidthSizable | NSViewHeightSizable)]; |
| 381 [[[self window] contentView] addSubview:flippedContentView]; | 353 [[[self window] contentView] addSubview:flippedContentView]; |
| 382 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; | 354 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; |
| 383 } | 355 } |
| 384 return self; | 356 return self; |
| 385 } | 357 } |
| 386 | 358 |
| 387 - (void)dealloc { | 359 - (void)dealloc { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 454 |
| 483 [accountChooser_ setFrame:headerRect]; | 455 [accountChooser_ setFrame:headerRect]; |
| 484 [accountChooser_ performLayout]; | 456 [accountChooser_ performLayout]; |
| 485 if ([[signInContainer_ view] isHidden]) { | 457 if ([[signInContainer_ view] isHidden]) { |
| 486 [[mainContainer_ view] setFrame:mainRect]; | 458 [[mainContainer_ view] setFrame:mainRect]; |
| 487 [mainContainer_ performLayout]; | 459 [mainContainer_ performLayout]; |
| 488 } else { | 460 } else { |
| 489 [[signInContainer_ view] setFrame:mainRect]; | 461 [[signInContainer_ view] setFrame:mainRect]; |
| 490 } | 462 } |
| 491 | 463 |
| 492 // Loading shield has text centered in the content rect. | 464 [[loadingShieldController_ view] setFrame:contentRect]; |
| 493 NSRect textFrame = [loadingShieldTextField_ frame]; | 465 [loadingShieldController_ performLayout]; |
| 494 textFrame.origin.x = | |
| 495 std::ceil((NSWidth(contentRect) - NSWidth(textFrame)) / 2.0); | |
| 496 textFrame.origin.y = | |
| 497 std::ceil((NSHeight(contentRect) - NSHeight(textFrame)) / 2.0); | |
| 498 [loadingShieldTextField_ setFrame:textFrame]; | |
| 499 [[loadingShieldTextField_ superview] setFrame:contentRect]; | |
| 500 | 466 |
| 501 [[overlayController_ view] setFrame:contentRect]; | 467 [[overlayController_ view] setFrame:contentRect]; |
| 502 [overlayController_ performLayout]; | 468 [overlayController_ performLayout]; |
| 503 | 469 |
| 504 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; | 470 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; |
| 505 [[self window] setFrame:frameRect display:YES]; | 471 [[self window] setFrame:frameRect display:YES]; |
| 506 [[self window] recalculateKeyViewLoop]; | 472 [[self window] recalculateKeyViewLoop]; |
| 507 } | 473 } |
| 508 | 474 |
| 509 - (IBAction)accept:(id)sender { | 475 - (IBAction)accept:(id)sender { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 507 } |
| 542 | 508 |
| 543 - (void)updateNotificationArea { | 509 - (void)updateNotificationArea { |
| 544 [mainContainer_ updateNotificationArea]; | 510 [mainContainer_ updateNotificationArea]; |
| 545 } | 511 } |
| 546 | 512 |
| 547 - (void)updateAccountChooser { | 513 - (void)updateAccountChooser { |
| 548 [accountChooser_ update]; | 514 [accountChooser_ update]; |
| 549 [mainContainer_ updateLegalDocuments]; | 515 [mainContainer_ updateLegalDocuments]; |
| 550 | 516 |
| 551 NSString* newLoadingMessage = @""; | 517 // For the duration of the loading shield, hide the main contents. |
| 552 if (autofillDialog_->delegate()->ShouldShowSpinner()) | 518 // This prevents the currently focused text field "shining through". |
| 553 newLoadingMessage = l10n_util::GetNSStringWithFixup(IDS_TAB_LOADING_TITLE); | 519 // No need to remember previous state, because the loading shield |
| 554 if (![newLoadingMessage isEqualToString: | 520 // always flows through to the main container. |
| 555 [loadingShieldTextField_ stringValue]]) { | 521 [loadingShieldController_ update]; |
| 556 NSView* loadingShieldView = [loadingShieldTextField_ superview]; | 522 [[mainContainer_ view] setHidden:![[loadingShieldController_ view] isHidden]]; |
| 557 [loadingShieldTextField_ setStringValue:newLoadingMessage]; | |
| 558 [loadingShieldTextField_ sizeToFit]; | |
| 559 | |
| 560 BOOL showShield = ([newLoadingMessage length] != 0); | |
| 561 | |
| 562 // For the duration of the loading shield, hide the main contents. | |
| 563 // This prevents the currently focused text field "shining through". | |
| 564 // No need to remember previous state, because the loading shield | |
| 565 // always flows through to the main container. | |
| 566 [[mainContainer_ view] setHidden:showShield]; | |
| 567 [loadingShieldView setHidden:!showShield]; | |
| 568 [self requestRelayout]; | |
| 569 } | |
| 570 } | 523 } |
| 571 | 524 |
| 572 - (void)updateButtonStrip { | 525 - (void)updateButtonStrip { |
| 573 [overlayController_ updateState]; | 526 [overlayController_ updateState]; |
| 574 } | 527 } |
| 575 | 528 |
| 576 - (void)updateSection:(autofill::DialogSection)section { | 529 - (void)updateSection:(autofill::DialogSection)section { |
| 577 [[mainContainer_ sectionForId:section] update]; | 530 [[mainContainer_ sectionForId:section] update]; |
| 578 [mainContainer_ updateSaveInChrome]; | 531 [mainContainer_ updateSaveInChrome]; |
| 579 } | 532 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 613 |
| 661 - (content::WebContents*)getSignInWebContents { | 614 - (content::WebContents*)getSignInWebContents { |
| 662 return [signInContainer_ webContents]; | 615 return [signInContainer_ webContents]; |
| 663 } | 616 } |
| 664 | 617 |
| 665 - (BOOL)IsShowingOverlay { | 618 - (BOOL)IsShowingOverlay { |
| 666 return ![[overlayController_ view] isHidden]; | 619 return ![[overlayController_ view] isHidden]; |
| 667 } | 620 } |
| 668 | 621 |
| 669 @end | 622 @end |
| OLD | NEW |