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 @end |
| 18 |
| 19 @implementation ManagePasswordsBubbleController |
| 20 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 21 model:(ManagePasswordsBubbleModel*)model { |
| 22 NSRect contentRect = ui::kWindowSizeDeterminedLater; |
| 23 base::scoped_nsobject<InfoBubbleWindow> window( |
| 24 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
| 25 styleMask:NSBorderlessWindowMask |
| 26 backing:NSBackingStoreBuffered |
| 27 defer:NO]); |
| 28 if ((self = [super initWithWindow:window |
| 29 parentWindow:parentWindow |
| 30 anchoredAt:NSZeroPoint])) { |
| 31 model_ = model; |
| 32 [self updateState]; |
| 33 } |
| 34 return self; |
| 35 } |
| 36 |
| 37 - (void)showWindow:(id)sender { |
| 38 [self performLayout]; |
| 39 [super showWindow:sender]; |
| 40 } |
| 41 |
| 42 - (void)updateState { |
| 43 // Find the next view controller. |
| 44 // TODO(dconnelly): Handle other states once they're implemented. |
| 45 currentController_.reset(); |
| 46 if (password_manager::ui::IsPendingState(model_->state())) { |
| 47 currentController_.reset( |
| 48 [[ManagePasswordsBubblePendingViewController alloc] |
| 49 initWithModel:model_ |
| 50 delegate:self]); |
| 51 } |
| 52 [self performLayout]; |
| 53 } |
| 54 |
| 55 - (void)performLayout { |
| 56 if (!currentController_) |
| 57 return; |
| 58 |
| 59 // Update the window. |
| 60 NSWindow* window = [self window]; |
| 61 [[window contentView] setSubviews:@[ [currentController_ view] ]]; |
| 62 |
| 63 // Update the anchor. |
| 64 BrowserWindowController* controller = [BrowserWindowController |
| 65 browserWindowControllerForWindow:[self parentWindow]]; |
| 66 NSPoint anchorPoint = |
| 67 [controller locationBarBridge]->GetManagePasswordsBubblePoint(); |
| 68 anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint]; |
| 69 [self setAnchorPoint:anchorPoint]; |
| 70 |
| 71 // Update the frame. |
| 72 CGFloat height = NSHeight([[currentController_ view] frame]) + |
| 73 info_bubble::kBubbleArrowHeight; |
| 74 CGFloat width = NSWidth([[currentController_ view] frame]); |
| 75 CGFloat x = anchorPoint.x - width + |
| 76 info_bubble::kBubbleArrowXOffset + |
| 77 (0.5 * info_bubble::kBubbleArrowWidth); |
| 78 CGFloat y = anchorPoint.y - height; |
| 79 [window setFrame:NSMakeRect(x, y, width, height) |
| 80 display:YES |
| 81 animate:[window isVisible]]; |
| 82 } |
| 83 |
| 84 #pragma mark ManagePasswordsBubbleContentViewDelegate |
| 85 |
| 86 - (void)viewShouldDismiss { |
| 87 [self close]; |
| 88 } |
| 89 |
| 90 #pragma mark ManagePasswordsBubblePendingViewDelegate |
| 91 |
| 92 - (void)passwordShouldNeverBeSavedOnSiteWithExistingPasswords { |
| 93 // TODO(dconnelly): Set the NeverSaveViewController once it's implemented. |
| 94 [self performLayout]; |
| 95 } |
| 96 |
| 97 @end |
| 98 |
| 99 @implementation ManagePasswordsBubbleController (Testing) |
| 100 |
| 101 - (NSViewController*)currentController { |
| 102 return currentController_.get(); |
| 103 } |
| 104 |
| 105 @end |
OLD | NEW |