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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 base::SysUTF16ToNSString(autofillDialog->delegate()->DialogTitle())]; | 327 base::SysUTF16ToNSString(autofillDialog->delegate()->DialogTitle())]; |
346 [titleTextField_ sizeToFit]; | 328 [titleTextField_ sizeToFit]; |
347 | 329 |
348 NSRect headerRect = clientRect; | 330 NSRect headerRect = clientRect; |
349 headerRect.size.height = kAccountChooserHeight; | 331 headerRect.size.height = kAccountChooserHeight; |
350 headerRect.origin.y = NSMaxY(clientRect); | 332 headerRect.origin.y = NSMaxY(clientRect); |
351 accountChooser_.reset([[AutofillAccountChooser alloc] | 333 accountChooser_.reset([[AutofillAccountChooser alloc] |
352 initWithFrame:headerRect | 334 initWithFrame:headerRect |
353 delegate:autofillDialog->delegate()]); | 335 delegate:autofillDialog->delegate()]); |
354 | 336 |
355 loadingShieldTextField_.reset( | 337 loadingShieldController_.reset( |
356 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 338 [[AutofillLoadingShieldController alloc] |
357 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 339 initWithDelegate:autofillDialog->delegate()]); |
358 NSFont* loadingFont = rb.GetFont( | 340 [[loadingShieldController_ view] setHidden:YES]; |
359 ui::ResourceBundle::BaseFont).DeriveFont(15).GetNativeFont(); | |
360 [loadingShieldTextField_ setFont:loadingFont]; | |
361 [loadingShieldTextField_ setEditable:NO]; | |
362 [loadingShieldTextField_ setBordered:NO]; | |
363 [loadingShieldTextField_ setDrawsBackground:NO]; | |
364 | |
365 base::scoped_nsobject<AutofillOpaqueView> loadingShieldView( | |
366 [[AutofillOpaqueView alloc] initWithFrame:NSZeroRect]); | |
367 [loadingShieldView setHidden:YES]; | |
368 [loadingShieldView addSubview:loadingShieldTextField_]; | |
369 | 341 |
370 overlayController_.reset( | 342 overlayController_.reset( |
371 [[AutofillOverlayController alloc] initWithDelegate: | 343 [[AutofillOverlayController alloc] initWithDelegate: |
372 autofillDialog->delegate()]); | 344 autofillDialog->delegate()]); |
373 [[overlayController_ view] setHidden:YES]; | 345 [[overlayController_ view] setHidden:YES]; |
374 | 346 |
375 // This needs a flipped content view because otherwise the size | 347 // This needs a flipped content view because otherwise the size |
376 // animation looks odd. However, replacing the contentView for constrained | 348 // animation looks odd. However, replacing the contentView for constrained |
377 // windows does not work - it does custom rendering. | 349 // windows does not work - it does custom rendering. |
378 base::scoped_nsobject<NSView> flippedContentView( | 350 base::scoped_nsobject<NSView> flippedContentView( |
379 [[FlippedView alloc] initWithFrame: | 351 [[FlippedView alloc] initWithFrame: |
380 [[[self window] contentView] frame]]); | 352 [[[self window] contentView] frame]]); |
381 [flippedContentView setSubviews: | 353 [flippedContentView setSubviews: |
382 @[accountChooser_, | 354 @[accountChooser_, |
383 titleTextField_, | 355 titleTextField_, |
384 [mainContainer_ view], | 356 [mainContainer_ view], |
385 [signInContainer_ view], | 357 [signInContainer_ view], |
386 loadingShieldView, | 358 [loadingShieldController_ view], |
387 [overlayController_ view]]]; | 359 [overlayController_ view]]]; |
388 [flippedContentView setAutoresizingMask: | 360 [flippedContentView setAutoresizingMask: |
389 (NSViewWidthSizable | NSViewHeightSizable)]; | 361 (NSViewWidthSizable | NSViewHeightSizable)]; |
390 [[[self window] contentView] addSubview:flippedContentView]; | 362 [[[self window] contentView] addSubview:flippedContentView]; |
391 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; | 363 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; |
392 } | 364 } |
393 return self; | 365 return self; |
394 } | 366 } |
395 | 367 |
396 - (void)dealloc { | 368 - (void)dealloc { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 464 |
493 [accountChooser_ setFrame:headerRect]; | 465 [accountChooser_ setFrame:headerRect]; |
494 [accountChooser_ performLayout]; | 466 [accountChooser_ performLayout]; |
495 if ([[signInContainer_ view] isHidden]) { | 467 if ([[signInContainer_ view] isHidden]) { |
496 [[mainContainer_ view] setFrame:mainRect]; | 468 [[mainContainer_ view] setFrame:mainRect]; |
497 [mainContainer_ performLayout]; | 469 [mainContainer_ performLayout]; |
498 } else { | 470 } else { |
499 [[signInContainer_ view] setFrame:mainRect]; | 471 [[signInContainer_ view] setFrame:mainRect]; |
500 } | 472 } |
501 | 473 |
502 // Loading shield has text centered in the content rect. | 474 [[loadingShieldController_ view] setFrame:contentRect]; |
503 NSRect textFrame = [loadingShieldTextField_ frame]; | 475 [loadingShieldController_ performLayout]; |
504 textFrame.origin.x = | |
505 std::ceil((NSWidth(contentRect) - NSWidth(textFrame)) / 2.0); | |
506 textFrame.origin.y = | |
507 std::ceil((NSHeight(contentRect) - NSHeight(textFrame)) / 2.0); | |
508 [loadingShieldTextField_ setFrame:textFrame]; | |
509 [[loadingShieldTextField_ superview] setFrame:contentRect]; | |
510 | 476 |
511 [[overlayController_ view] setFrame:contentRect]; | 477 [[overlayController_ view] setFrame:contentRect]; |
512 [overlayController_ performLayout]; | 478 [overlayController_ performLayout]; |
513 | 479 |
514 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; | 480 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; |
515 [[self window] setFrame:frameRect display:YES]; | 481 [[self window] setFrame:frameRect display:YES]; |
516 [[self window] recalculateKeyViewLoop]; | 482 [[self window] recalculateKeyViewLoop]; |
517 } | 483 } |
518 | 484 |
519 - (IBAction)accept:(id)sender { | 485 - (IBAction)accept:(id)sender { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 } | 517 } |
552 | 518 |
553 - (void)updateNotificationArea { | 519 - (void)updateNotificationArea { |
554 [mainContainer_ updateNotificationArea]; | 520 [mainContainer_ updateNotificationArea]; |
555 } | 521 } |
556 | 522 |
557 - (void)updateAccountChooser { | 523 - (void)updateAccountChooser { |
558 [accountChooser_ update]; | 524 [accountChooser_ update]; |
559 [mainContainer_ updateLegalDocuments]; | 525 [mainContainer_ updateLegalDocuments]; |
560 | 526 |
561 NSString* newLoadingMessage = @""; | 527 // For the duration of the loading shield, hide the main contents. |
562 if (autofillDialog_->delegate()->ShouldShowSpinner()) | 528 // This prevents the currently focused text field "shining through". |
563 newLoadingMessage = l10n_util::GetNSStringWithFixup(IDS_TAB_LOADING_TITLE); | 529 // No need to remember previous state, because the loading shield |
564 if (![newLoadingMessage isEqualToString: | 530 // always flows through to the main container. |
565 [loadingShieldTextField_ stringValue]]) { | 531 [loadingShieldController_ update]; |
566 NSView* loadingShieldView = [loadingShieldTextField_ superview]; | 532 [[mainContainer_ view] setHidden:![[loadingShieldController_ view] isHidden]]; |
567 [loadingShieldTextField_ setStringValue:newLoadingMessage]; | |
568 [loadingShieldTextField_ sizeToFit]; | |
569 | |
570 BOOL showShield = ([newLoadingMessage length] != 0); | |
571 | |
572 // For the duration of the loading shield, hide the main contents. | |
573 // This prevents the currently focused text field "shining through". | |
574 // No need to remember previous state, because the loading shield | |
575 // always flows through to the main container. | |
576 [[mainContainer_ view] setHidden:showShield]; | |
577 [loadingShieldView setHidden:!showShield]; | |
578 [self requestRelayout]; | |
579 } | |
580 } | 533 } |
581 | 534 |
582 - (void)updateButtonStrip { | 535 - (void)updateButtonStrip { |
583 [overlayController_ updateState]; | 536 [overlayController_ updateState]; |
584 } | 537 } |
585 | 538 |
586 - (void)updateSection:(autofill::DialogSection)section { | 539 - (void)updateSection:(autofill::DialogSection)section { |
587 [[mainContainer_ sectionForId:section] update]; | 540 [[mainContainer_ sectionForId:section] update]; |
588 [mainContainer_ updateSaveInChrome]; | 541 [mainContainer_ updateSaveInChrome]; |
589 } | 542 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 | 623 |
671 - (content::WebContents*)getSignInWebContents { | 624 - (content::WebContents*)getSignInWebContents { |
672 return [signInContainer_ webContents]; | 625 return [signInContainer_ webContents]; |
673 } | 626 } |
674 | 627 |
675 - (BOOL)IsShowingOverlay { | 628 - (BOOL)IsShowingOverlay { |
676 return ![[overlayController_ view] isHidden]; | 629 return ![[overlayController_ view] isHidden]; |
677 } | 630 } |
678 | 631 |
679 @end | 632 @end |
OLD | NEW |