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] init]); |
357 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 339 [[loadingShieldController_ view] setHidden:YES]; |
358 NSFont* loadingFont = rb.GetFont( | |
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 | 340 |
370 overlayController_.reset( | 341 overlayController_.reset( |
371 [[AutofillOverlayController alloc] initWithDelegate: | 342 [[AutofillOverlayController alloc] initWithDelegate: |
372 autofillDialog->delegate()]); | 343 autofillDialog->delegate()]); |
373 [[overlayController_ view] setHidden:YES]; | 344 [[overlayController_ view] setHidden:YES]; |
374 | 345 |
375 // This needs a flipped content view because otherwise the size | 346 // This needs a flipped content view because otherwise the size |
376 // animation looks odd. However, replacing the contentView for constrained | 347 // animation looks odd. However, replacing the contentView for constrained |
377 // windows does not work - it does custom rendering. | 348 // windows does not work - it does custom rendering. |
378 base::scoped_nsobject<NSView> flippedContentView( | 349 base::scoped_nsobject<NSView> flippedContentView( |
379 [[FlippedView alloc] initWithFrame: | 350 [[FlippedView alloc] initWithFrame: |
380 [[[self window] contentView] frame]]); | 351 [[[self window] contentView] frame]]); |
381 [flippedContentView setSubviews: | 352 [flippedContentView setSubviews: |
382 @[accountChooser_, | 353 @[accountChooser_, |
383 titleTextField_, | 354 titleTextField_, |
384 [mainContainer_ view], | 355 [mainContainer_ view], |
385 [signInContainer_ view], | 356 [signInContainer_ view], |
386 loadingShieldView, | 357 [loadingShieldController_ view], |
387 [overlayController_ view]]]; | 358 [overlayController_ view]]]; |
388 [flippedContentView setAutoresizingMask: | 359 [flippedContentView setAutoresizingMask: |
389 (NSViewWidthSizable | NSViewHeightSizable)]; | 360 (NSViewWidthSizable | NSViewHeightSizable)]; |
390 [[[self window] contentView] addSubview:flippedContentView]; | 361 [[[self window] contentView] addSubview:flippedContentView]; |
391 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; | 362 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; |
392 } | 363 } |
393 return self; | 364 return self; |
394 } | 365 } |
395 | 366 |
396 - (void)dealloc { | 367 - (void)dealloc { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 | 463 |
493 [accountChooser_ setFrame:headerRect]; | 464 [accountChooser_ setFrame:headerRect]; |
494 [accountChooser_ performLayout]; | 465 [accountChooser_ performLayout]; |
495 if ([[signInContainer_ view] isHidden]) { | 466 if ([[signInContainer_ view] isHidden]) { |
496 [[mainContainer_ view] setFrame:mainRect]; | 467 [[mainContainer_ view] setFrame:mainRect]; |
497 [mainContainer_ performLayout]; | 468 [mainContainer_ performLayout]; |
498 } else { | 469 } else { |
499 [[signInContainer_ view] setFrame:mainRect]; | 470 [[signInContainer_ view] setFrame:mainRect]; |
500 } | 471 } |
501 | 472 |
502 // Loading shield has text centered in the content rect. | 473 [[loadingShieldController_ view] setFrame:contentRect]; |
503 NSRect textFrame = [loadingShieldTextField_ frame]; | 474 [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 | 475 |
511 [[overlayController_ view] setFrame:contentRect]; | 476 [[overlayController_ view] setFrame:contentRect]; |
512 [overlayController_ performLayout]; | 477 [overlayController_ performLayout]; |
513 | 478 |
514 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; | 479 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; |
515 [[self window] setFrame:frameRect display:YES]; | 480 [[self window] setFrame:frameRect display:YES]; |
516 [[self window] recalculateKeyViewLoop]; | 481 [[self window] recalculateKeyViewLoop]; |
517 } | 482 } |
518 | 483 |
519 - (IBAction)accept:(id)sender { | 484 - (IBAction)accept:(id)sender { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 } | 516 } |
552 | 517 |
553 - (void)updateNotificationArea { | 518 - (void)updateNotificationArea { |
554 [mainContainer_ updateNotificationArea]; | 519 [mainContainer_ updateNotificationArea]; |
555 } | 520 } |
556 | 521 |
557 - (void)updateAccountChooser { | 522 - (void)updateAccountChooser { |
558 [accountChooser_ update]; | 523 [accountChooser_ update]; |
559 [mainContainer_ updateLegalDocuments]; | 524 [mainContainer_ updateLegalDocuments]; |
560 | 525 |
526 autofill::AutofillDialogViewDelegate* delegate = autofillDialog_->delegate(); | |
561 NSString* newLoadingMessage = @""; | 527 NSString* newLoadingMessage = @""; |
562 if (autofillDialog_->delegate()->ShouldShowSpinner()) | 528 if (delegate->ShouldShowSpinner()) |
563 newLoadingMessage = l10n_util::GetNSStringWithFixup(IDS_TAB_LOADING_TITLE); | 529 newLoadingMessage = base::SysUTF16ToNSString(delegate->SpinnerText()); |
564 if (![newLoadingMessage isEqualToString: | 530 if (![newLoadingMessage isEqualToString:[loadingShieldController_ message]]) { |
565 [loadingShieldTextField_ stringValue]]) { | 531 [loadingShieldController_ setMessage:newLoadingMessage]; |
groby-ooo-7-16
2013/11/15 23:03:38
Should that just move into the setMessage: call?
Ilya Sherman
2013/11/16 00:31:13
Restructured this so that most of this logic is no
| |
566 NSView* loadingShieldView = [loadingShieldTextField_ superview]; | |
567 [loadingShieldTextField_ setStringValue:newLoadingMessage]; | |
568 [loadingShieldTextField_ sizeToFit]; | |
569 | 532 |
570 BOOL showShield = ([newLoadingMessage length] != 0); | 533 BOOL showShield = ([newLoadingMessage length] != 0); |
571 | 534 |
572 // For the duration of the loading shield, hide the main contents. | 535 // For the duration of the loading shield, hide the main contents. |
573 // This prevents the currently focused text field "shining through". | 536 // This prevents the currently focused text field "shining through". |
574 // No need to remember previous state, because the loading shield | 537 // No need to remember previous state, because the loading shield |
575 // always flows through to the main container. | 538 // always flows through to the main container. |
576 [[mainContainer_ view] setHidden:showShield]; | 539 [[mainContainer_ view] setHidden:showShield]; |
577 [loadingShieldView setHidden:!showShield]; | 540 [[loadingShieldController_ view] setHidden:!showShield]; |
578 [self requestRelayout]; | 541 [self requestRelayout]; |
579 } | 542 } |
580 } | 543 } |
581 | 544 |
582 - (void)updateButtonStrip { | 545 - (void)updateButtonStrip { |
583 [overlayController_ updateState]; | 546 [overlayController_ updateState]; |
584 } | 547 } |
585 | 548 |
586 - (void)updateSection:(autofill::DialogSection)section { | 549 - (void)updateSection:(autofill::DialogSection)section { |
587 [[mainContainer_ sectionForId:section] update]; | 550 [[mainContainer_ sectionForId:section] update]; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 | 633 |
671 - (content::WebContents*)getSignInWebContents { | 634 - (content::WebContents*)getSignInWebContents { |
672 return [signInContainer_ webContents]; | 635 return [signInContainer_ webContents]; |
673 } | 636 } |
674 | 637 |
675 - (BOOL)IsShowingOverlay { | 638 - (BOOL)IsShowingOverlay { |
676 return ![[overlayController_ view] isHidden]; | 639 return ![[overlayController_ view] isHidden]; |
677 } | 640 } |
678 | 641 |
679 @end | 642 @end |
OLD | NEW |