Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h" | |
| 6 | |
| 7 #include "base/mac/scoped_nsobject.h" | |
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
| 9 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | |
| 10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | |
| 11 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | |
| 12 #include "ui/base/cocoa/window_size_constants.h" | |
| 13 | |
| 14 @interface ManagePasswordsBubbleController () | |
| 15 // Updates the content view controller according to the current state. | |
| 16 - (void)updateState; | |
| 17 // Updates the content view controller and lays out the window. | |
| 18 - (void)refresh; | |
| 19 @end | |
| 20 | |
| 21 @implementation ManagePasswordsBubbleController | |
| 22 - (id)initWithParentWindow:(NSWindow*)parentWindow | |
| 23 model:(ManagePasswordsBubbleModel*)model { | |
| 24 NSRect contentRect = ui::kWindowSizeDeterminedLater; | |
| 25 base::scoped_nsobject<InfoBubbleWindow> window( | |
| 26 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | |
| 27 styleMask:NSBorderlessWindowMask | |
| 28 backing:NSBackingStoreBuffered | |
| 29 defer:NO]); | |
| 30 if ((self = [super initWithWindow:window | |
| 31 parentWindow:parentWindow | |
| 32 anchoredAt:NSZeroPoint])) { | |
| 33 model_ = model; | |
| 34 neverSave_ = NO; | |
| 35 [self refresh]; | |
| 36 } | |
| 37 return self; | |
| 38 } | |
| 39 | |
| 40 - (void)showWindow:(id)sender { | |
| 41 [self performLayout]; | |
| 42 [super showWindow:sender]; | |
| 43 } | |
| 44 | |
| 45 - (void)updateState { | |
| 46 // Find the next view controller. | |
| 47 // TODO(dconnelly): Handle other states once they're implemented. | |
| 48 currentController_.reset(); | |
| 49 if (password_manager::ui::IsPendingState(model_->state()) && !neverSave_) { | |
|
Scott Hess - ex-Googler
2014/08/20 20:04:40
I have had complaints in the past about things lik
dconnelly
2014/08/21 08:47:59
Nope. And to address that and the first comment I'
| |
| 50 currentController_.reset([[ManagePasswordsBubblePendingViewController alloc] | |
| 51 initWithModel:model_ | |
| 52 delegate:self]); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 - (void)performLayout { | |
| 57 if (!currentController_) | |
| 58 return; | |
| 59 | |
| 60 // Update the window. | |
| 61 NSWindow* window = [self window]; | |
| 62 [[window contentView] setSubviews:@[ [currentController_ view] ]]; | |
| 63 | |
| 64 // Update the anchor. | |
| 65 BrowserWindowController* controller = [BrowserWindowController | |
| 66 browserWindowControllerForWindow:[self parentWindow]]; | |
| 67 NSPoint anchorPoint = | |
| 68 [controller locationBarBridge]->GetManagePasswordsBubblePoint(); | |
| 69 anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint]; | |
| 70 [self setAnchorPoint:anchorPoint]; | |
| 71 | |
| 72 // Update the frame. | |
| 73 CGFloat height = NSHeight([[currentController_ view] frame]) + | |
| 74 info_bubble::kBubbleArrowHeight; | |
| 75 CGFloat width = NSWidth([[currentController_ view] frame]); | |
| 76 CGFloat x = anchorPoint.x - width + | |
| 77 info_bubble::kBubbleArrowXOffset + | |
| 78 (0.5 * info_bubble::kBubbleArrowWidth); | |
| 79 CGFloat y = anchorPoint.y - height; | |
| 80 [window setFrame:NSMakeRect(x, y, width, height) | |
| 81 display:YES | |
| 82 animate:[window isVisible]]; | |
| 83 } | |
| 84 | |
| 85 - (void)refresh { | |
| 86 [self updateState]; | |
| 87 [self performLayout]; | |
|
Scott Hess - ex-Googler
2014/08/20 20:04:40
Is there a case where -updateState shouldn't lead
dconnelly
2014/08/21 08:47:59
Nope. Removed.
| |
| 88 } | |
| 89 | |
| 90 // ManagePasswordsBubbleContentViewDelegate | |
|
Scott Hess - ex-Googler
2014/08/20 20:04:40
Generally this is indicated by:
#pragma mark Mana
dconnelly
2014/08/21 08:47:59
Done.
| |
| 91 | |
| 92 - (void)viewShouldDismiss { | |
| 93 [self close]; | |
| 94 } | |
| 95 | |
| 96 // ManagePasswordsBubblePendingViewDelegate | |
| 97 | |
| 98 - (void)passwordShouldNeverBeSavedOnSiteWithExistingPasswords { | |
| 99 neverSave_ = YES; | |
| 100 [self performLayout]; | |
| 101 } | |
| 102 | |
| 103 @end | |
| 104 | |
| 105 @implementation ManagePasswordsBubbleController (Testing) | |
| 106 | |
| 107 - (NSViewController*)currentController { | |
| 108 return currentController_.get(); | |
| 109 } | |
| 110 | |
| 111 @end | |
| OLD | NEW |