Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm

Issue 23674004: [rAC, OSX] Add overlay shield for interstitials/waits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final tweaks. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
13 #include "chrome/browser/ui/chrome_style.h" 13 #include "chrome/browser/ui/chrome_style.h"
14 #include "chrome/browser/ui/chrome_style.h" 14 #include "chrome/browser/ui/chrome_style.h"
15 #include "chrome/browser/ui/chrome_style.h" 15 #include "chrome/browser/ui/chrome_style.h"
16 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" 16 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
17 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" 17 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
18 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" 18 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
19 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" 19 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
20 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h"
20 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" 21 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
21 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" 22 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
22 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" 23 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
23 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" 24 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_view.h" 26 #include "content/public/browser/web_contents_view.h"
26 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
27 #import "ui/base/cocoa/flipped_view.h" 28 #import "ui/base/cocoa/flipped_view.h"
28 #include "ui/base/cocoa/window_size_constants.h" 29 #include "ui/base/cocoa/window_size_constants.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
(...skipping 26 matching lines...) Expand all
56 // This should only be called once. 57 // This should only be called once.
57 DCHECK(!sheet_delegate_.get()); 58 DCHECK(!sheet_delegate_.get());
58 sheet_delegate_.reset([[AutofillDialogWindowController alloc] 59 sheet_delegate_.reset([[AutofillDialogWindowController alloc]
59 initWithWebContents:delegate_->GetWebContents() 60 initWithWebContents:delegate_->GetWebContents()
60 autofillDialog:this]); 61 autofillDialog:this]);
61 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( 62 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
62 [[CustomConstrainedWindowSheet alloc] 63 [[CustomConstrainedWindowSheet alloc]
63 initWithCustomWindow:[sheet_delegate_ window]]); 64 initWithCustomWindow:[sheet_delegate_ window]]);
64 constrained_window_.reset( 65 constrained_window_.reset(
65 new ConstrainedWindowMac(this, delegate_->GetWebContents(), sheet)); 66 new ConstrainedWindowMac(this, delegate_->GetWebContents(), sheet));
67 [sheet_delegate_ show];
66 } 68 }
67 69
68 void AutofillDialogCocoa::Hide() { 70 void AutofillDialogCocoa::Hide() {
69 [sheet_delegate_ hide]; 71 [sheet_delegate_ hide];
70 } 72 }
71 73
72 void AutofillDialogCocoa::PerformClose() { 74 void AutofillDialogCocoa::PerformClose() {
73 if (!close_weak_ptr_factory_.HasWeakPtrs()) { 75 if (!close_weak_ptr_factory_.HasWeakPtrs()) {
74 base::MessageLoop::current()->PostTask( 76 base::MessageLoop::current()->PostTask(
75 FROM_HERE, 77 FROM_HERE,
(...skipping 12 matching lines...) Expand all
88 90
89 void AutofillDialogCocoa::UpdatesFinished() { 91 void AutofillDialogCocoa::UpdatesFinished() {
90 // TODO(estade): implement if it makes sense to. 92 // TODO(estade): implement if it makes sense to.
91 } 93 }
92 94
93 void AutofillDialogCocoa::UpdateAccountChooser() { 95 void AutofillDialogCocoa::UpdateAccountChooser() {
94 [sheet_delegate_ updateAccountChooser]; 96 [sheet_delegate_ updateAccountChooser];
95 } 97 }
96 98
97 void AutofillDialogCocoa::UpdateButtonStrip() { 99 void AutofillDialogCocoa::UpdateButtonStrip() {
100 [sheet_delegate_ updateButtonStrip];
98 } 101 }
99 102
100 void AutofillDialogCocoa::UpdateDetailArea() { 103 void AutofillDialogCocoa::UpdateDetailArea() {
101 } 104 }
102 105
103 void AutofillDialogCocoa::UpdateForErrors() { 106 void AutofillDialogCocoa::UpdateForErrors() {
104 } 107 }
105 108
106 void AutofillDialogCocoa::UpdateNotificationArea() { 109 void AutofillDialogCocoa::UpdateNotificationArea() {
107 [sheet_delegate_ updateNotificationArea]; 110 [sheet_delegate_ updateNotificationArea];
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 [loadingShieldTextField_ setFont:loadingFont]; 281 [loadingShieldTextField_ setFont:loadingFont];
279 [loadingShieldTextField_ setEditable:NO]; 282 [loadingShieldTextField_ setEditable:NO];
280 [loadingShieldTextField_ setBordered:NO]; 283 [loadingShieldTextField_ setBordered:NO];
281 [loadingShieldTextField_ setDrawsBackground:NO]; 284 [loadingShieldTextField_ setDrawsBackground:NO];
282 285
283 base::scoped_nsobject<AutofillOpaqueView> loadingShieldView( 286 base::scoped_nsobject<AutofillOpaqueView> loadingShieldView(
284 [[AutofillOpaqueView alloc] initWithFrame:NSZeroRect]); 287 [[AutofillOpaqueView alloc] initWithFrame:NSZeroRect]);
285 [loadingShieldView setHidden:YES]; 288 [loadingShieldView setHidden:YES];
286 [loadingShieldView addSubview:loadingShieldTextField_]; 289 [loadingShieldView addSubview:loadingShieldTextField_];
287 290
291 overlayController_.reset(
292 [[AutofillOverlayController alloc] initWithDelegate:
293 autofillDialog->delegate()]);
294 [[overlayController_ view] setHidden:YES];
295
288 // This needs a flipped content view because otherwise the size 296 // This needs a flipped content view because otherwise the size
289 // animation looks odd. However, replacing the contentView for constrained 297 // animation looks odd. However, replacing the contentView for constrained
290 // windows does not work - it does custom rendering. 298 // windows does not work - it does custom rendering.
291 base::scoped_nsobject<NSView> flippedContentView( 299 base::scoped_nsobject<NSView> flippedContentView(
292 [[FlippedView alloc] initWithFrame:NSZeroRect]); 300 [[FlippedView alloc] initWithFrame:NSZeroRect]);
293 [flippedContentView setSubviews: 301 [flippedContentView setSubviews:
294 @[accountChooser_, 302 @[accountChooser_,
295 [mainContainer_ view], 303 [mainContainer_ view],
296 [signInContainer_ view], 304 [signInContainer_ view],
297 loadingShieldView]]; 305 loadingShieldView,
306 [overlayController_ view]]];
298 [flippedContentView setAutoresizingMask: 307 [flippedContentView setAutoresizingMask:
299 (NSViewWidthSizable | NSViewHeightSizable)]; 308 (NSViewWidthSizable | NSViewHeightSizable)];
300 [[[self window] contentView] addSubview:flippedContentView]; 309 [[[self window] contentView] addSubview:flippedContentView];
301 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]]; 310 [mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]];
302 311
303 NSRect contentRect = clientRect; 312 NSRect contentRect = clientRect;
304 contentRect.origin = NSZeroPoint; 313 contentRect.origin = NSZeroPoint;
305 contentRect.size.width += 2 * chrome_style::kHorizontalPadding; 314 contentRect.size.width += 2 * chrome_style::kHorizontalPadding;
306 contentRect.size.height += NSHeight(headerRect) + 315 contentRect.size.height += NSHeight(headerRect) +
307 chrome_style::kClientBottomPadding + 316 chrome_style::kClientBottomPadding +
308 chrome_style::kTitleTopPadding; 317 chrome_style::kTitleTopPadding;
309 [self performLayout];
310
311 // Resizing the browser causes the ConstrainedWindow to move.
312 // Observe that to allow resizes based on browser size.
313 NSView* contentView = [[self window] contentView];
314 [contentView setPostsFrameChangedNotifications:YES];
315 [[NSNotificationCenter defaultCenter]
316 addObserver:self
317 selector:@selector(onContentViewFrameDidChange:)
318 name:NSWindowDidMoveNotification
319 object:[self window]];
320 } 318 }
321 return self; 319 return self;
322 } 320 }
323 321
324 - (void)dealloc { 322 - (void)dealloc {
325 [[NSNotificationCenter defaultCenter] removeObserver:self]; 323 [[NSNotificationCenter defaultCenter] removeObserver:self];
326 [super dealloc]; 324 [super dealloc];
327 } 325 }
328 326
329 - (void)onContentViewFrameDidChange:(NSNotification*)notification { 327 - (void)onContentViewFrameDidChange:(NSNotification*)notification {
(...skipping 21 matching lines...) Expand all
351 // Show as much of the main view as is possible without going past the 349 // Show as much of the main view as is possible without going past the
352 // bottom of the browser window. 350 // bottom of the browser window.
353 NSRect dialogFrameRect = [[self window] frame]; 351 NSRect dialogFrameRect = [[self window] frame];
354 NSRect browserFrameRect = 352 NSRect browserFrameRect =
355 [webContents_->GetView()->GetTopLevelNativeWindow() frame]; 353 [webContents_->GetView()->GetTopLevelNativeWindow() frame];
356 dialogFrameRect.size.height = 354 dialogFrameRect.size.height =
357 NSMaxY(dialogFrameRect) - NSMinY(browserFrameRect); 355 NSMaxY(dialogFrameRect) - NSMinY(browserFrameRect);
358 dialogFrameRect = [[self window] contentRectForFrameRect:dialogFrameRect]; 356 dialogFrameRect = [[self window] contentRectForFrameRect:dialogFrameRect];
359 size.height = std::min(NSHeight(dialogFrameRect), size.height); 357 size.height = std::min(NSHeight(dialogFrameRect), size.height);
360 358
359 if (![[overlayController_ view] isHidden]) {
360 CGFloat height = [overlayController_ heightForWidth:size.width];
361 // TODO(groby): This currently reserves size on top of the overlay image
362 // equivalent to the height of the header. Clarify with UX what the final
363 // padding will be.
364 if (height != 0.0) {
365 size.height = height + headerSize.height + kDetailTopPadding;
366 }
367 }
368
361 return size; 369 return size;
362 } 370 }
363 371
364 - (void)performLayout { 372 - (void)performLayout {
365 NSRect contentRect = NSZeroRect; 373 NSRect contentRect = NSZeroRect;
366 contentRect.size = [self preferredSize]; 374 contentRect.size = [self preferredSize];
367 NSRect clientRect = NSInsetRect( 375 NSRect clientRect = NSInsetRect(
368 contentRect, chrome_style::kHorizontalPadding, 0); 376 contentRect, chrome_style::kHorizontalPadding, 0);
369 clientRect.origin.y = chrome_style::kClientBottomPadding; 377 clientRect.origin.y = chrome_style::kClientBottomPadding;
370 clientRect.size.height -= chrome_style::kTitleTopPadding + 378 clientRect.size.height -= chrome_style::kTitleTopPadding +
(...skipping 15 matching lines...) Expand all
386 394
387 // Loading shield has text centered in the content rect. 395 // Loading shield has text centered in the content rect.
388 NSRect textFrame = [loadingShieldTextField_ frame]; 396 NSRect textFrame = [loadingShieldTextField_ frame];
389 textFrame.origin.x = 397 textFrame.origin.x =
390 std::ceil((NSWidth(contentRect) - NSWidth(textFrame)) / 2.0); 398 std::ceil((NSWidth(contentRect) - NSWidth(textFrame)) / 2.0);
391 textFrame.origin.y = 399 textFrame.origin.y =
392 std::ceil((NSHeight(contentRect) - NSHeight(textFrame)) / 2.0); 400 std::ceil((NSHeight(contentRect) - NSHeight(textFrame)) / 2.0);
393 [loadingShieldTextField_ setFrame:textFrame]; 401 [loadingShieldTextField_ setFrame:textFrame];
394 [[loadingShieldTextField_ superview] setFrame:contentRect]; 402 [[loadingShieldTextField_ superview] setFrame:contentRect];
395 403
404 [[overlayController_ view] setFrame:contentRect];
405 [overlayController_ performLayout];
406
396 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; 407 NSRect frameRect = [[self window] frameRectForContentRect:contentRect];
397 [[self window] setFrame:frameRect display:YES]; 408 [[self window] setFrame:frameRect display:YES];
398 } 409 }
399 410
400 - (IBAction)accept:(id)sender { 411 - (IBAction)accept:(id)sender {
401 if ([mainContainer_ validate]) 412 if ([mainContainer_ validate])
402 autofillDialog_->delegate()->OnAccept(); 413 autofillDialog_->delegate()->OnAccept();
403 } 414 }
404 415
405 - (IBAction)cancel:(id)sender { 416 - (IBAction)cancel:(id)sender {
406 autofillDialog_->delegate()->OnCancel(); 417 autofillDialog_->delegate()->OnCancel();
407 autofillDialog_->PerformClose(); 418 autofillDialog_->PerformClose();
408 } 419 }
409 420
421 - (void)show {
422 gfx::Image splashImage = autofillDialog_->delegate()->SplashPageImage();
423 if (!splashImage.IsEmpty()) {
424 autofill::DialogOverlayState state;
425 state.image = splashImage;
426 [overlayController_ setState:state];
427 [overlayController_ beginFadeOut];
428 }
429
430 // Resizing the browser causes the ConstrainedWindow to move.
431 // Observe that to allow resizes based on browser size.
432 // NOTE: This MUST come last after all initial setup is done, because there
433 // is an immediate notification post registration.
434 DCHECK([self window]);
435 [[NSNotificationCenter defaultCenter]
436 addObserver:self
437 selector:@selector(onContentViewFrameDidChange:)
438 name:NSWindowDidMoveNotification
439 object:[self window]];
440
441 [self requestRelayout];
442 }
443
410 - (void)hide { 444 - (void)hide {
411 autofillDialog_->delegate()->OnCancel(); 445 autofillDialog_->delegate()->OnCancel();
412 autofillDialog_->PerformClose(); 446 autofillDialog_->PerformClose();
413 } 447 }
414 448
415 - (void)updateNotificationArea { 449 - (void)updateNotificationArea {
416 [mainContainer_ updateNotificationArea]; 450 [mainContainer_ updateNotificationArea];
417 } 451 }
418 452
419 - (void)updateAccountChooser { 453 - (void)updateAccountChooser {
420 [accountChooser_ update]; 454 [accountChooser_ update];
421 [mainContainer_ updateLegalDocuments]; 455 [mainContainer_ updateLegalDocuments];
422 // TODO(estade): replace this with a better loading image/animation. 456 // TODO(estade): replace this with a better loading image/animation.
423 // See http://crbug.com/230932 457 // See http://crbug.com/230932
424 NSString* newLoadingMessage = @""; 458 NSString* newLoadingMessage = @"";
425 if (autofillDialog_->delegate()->ShouldShowSpinner()) 459 if (autofillDialog_->delegate()->ShouldShowSpinner())
426 newLoadingMessage = l10n_util::GetNSStringWithFixup(IDS_TAB_LOADING_TITLE); 460 newLoadingMessage = l10n_util::GetNSStringWithFixup(IDS_TAB_LOADING_TITLE);
427 if (![newLoadingMessage isEqualToString: 461 if (![newLoadingMessage isEqualToString:
428 [loadingShieldTextField_ stringValue]]) { 462 [loadingShieldTextField_ stringValue]]) {
429 [loadingShieldTextField_ setStringValue:newLoadingMessage]; 463 [loadingShieldTextField_ setStringValue:newLoadingMessage];
430 [loadingShieldTextField_ sizeToFit]; 464 [loadingShieldTextField_ sizeToFit];
431 [[loadingShieldTextField_ superview] setHidden: 465 [[loadingShieldTextField_ superview] setHidden:
432 [newLoadingMessage length] == 0]; 466 [newLoadingMessage length] == 0];
433 [self requestRelayout]; 467 [self requestRelayout];
434 } 468 }
435 } 469 }
436 470
471 - (void)updateButtonStrip {
472 [overlayController_ updateState];
473 }
474
437 - (void)updateSection:(autofill::DialogSection)section { 475 - (void)updateSection:(autofill::DialogSection)section {
438 [[mainContainer_ sectionForId:section] update]; 476 [[mainContainer_ sectionForId:section] update];
439 } 477 }
440 478
441 - (void)fillSection:(autofill::DialogSection)section 479 - (void)fillSection:(autofill::DialogSection)section
442 forInput:(const autofill::DetailInput&)input { 480 forInput:(const autofill::DetailInput&)input {
443 [[mainContainer_ sectionForId:section] fillForInput:input]; 481 [[mainContainer_ sectionForId:section] fillForInput:input];
444 } 482 }
445 483
446 - (content::NavigationController*)showSignIn { 484 - (content::NavigationController*)showSignIn {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 529 }
492 530
493 - (void)activateFieldForInput:(const autofill::DetailInput&)input { 531 - (void)activateFieldForInput:(const autofill::DetailInput&)input {
494 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) { 532 for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
495 autofill::DialogSection section = static_cast<autofill::DialogSection>(i); 533 autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
496 [[mainContainer_ sectionForId:section] activateFieldForInput:input]; 534 [[mainContainer_ sectionForId:section] activateFieldForInput:input];
497 } 535 }
498 } 536 }
499 537
500 @end 538 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698