| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 11 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 11 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 13 #import "chrome/browser/ui/cocoa/passwords/auto_signin_view_controller.h" | 13 #import "chrome/browser/ui/cocoa/passwords/auto_signin_view_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/passwords/confirmation_password_saved_view_cont
roller.h" | 14 #import "chrome/browser/ui/cocoa/passwords/confirmation_password_saved_view_cont
roller.h" |
| 15 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_view_controller.h" | 15 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_view_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/passwords/save_pending_password_view_controller
.h" | 16 #import "chrome/browser/ui/cocoa/passwords/save_pending_password_view_controller
.h" |
| 17 #import "chrome/browser/ui/cocoa/passwords/signin_promo_view_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/passwords/update_pending_password_view_controll
er.h" | 18 #import "chrome/browser/ui/cocoa/passwords/update_pending_password_view_controll
er.h" |
| 18 #include "ui/base/cocoa/cocoa_base_utils.h" | 19 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 19 #include "ui/base/cocoa/window_size_constants.h" | 20 #include "ui/base/cocoa/window_size_constants.h" |
| 20 | 21 |
| 21 @interface ManagePasswordsBubbleController () | 22 @interface ManagePasswordsBubbleController () |
| 22 // Updates the content view controller according to the current state. | 23 // Updates the content view controller according to the current state. |
| 23 - (void)updateState; | 24 - (void)updateState; |
| 24 @end | 25 @end |
| 25 | 26 |
| 26 @implementation ManagePasswordsBubbleController | 27 @implementation ManagePasswordsBubbleController |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 [currentController_ setDelegate:nil]; | 46 [currentController_ setDelegate:nil]; |
| 46 [super dealloc]; | 47 [super dealloc]; |
| 47 } | 48 } |
| 48 | 49 |
| 49 - (void)showWindow:(id)sender { | 50 - (void)showWindow:(id)sender { |
| 50 [self performLayout]; | 51 [self performLayout]; |
| 51 [super showWindow:sender]; | 52 [super showWindow:sender]; |
| 52 } | 53 } |
| 53 | 54 |
| 54 - (void)close { | 55 - (void)close { |
| 55 [currentController_ bubbleWillDisappear]; | |
| 56 // The bubble is about to be closed. It destroys the model. | 56 // The bubble is about to be closed. It destroys the model. |
| 57 model_ = nil; | 57 model_ = nil; |
| 58 [super close]; | 58 [super close]; |
| 59 } | 59 } |
| 60 | 60 |
| 61 - (void)updateState { | 61 - (void)updateState { |
| 62 // Find the next view controller. | 62 // Find the next view controller. |
| 63 [currentController_ setDelegate:nil]; |
| 63 currentController_.reset(); | 64 currentController_.reset(); |
| 64 if (model_->state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 65 if (model_->state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 65 currentController_.reset([[SavePendingPasswordViewController alloc] | 66 currentController_.reset([[SavePendingPasswordViewController alloc] |
| 66 initWithDelegate:self]); | 67 initWithDelegate:self]); |
| 67 } else if (model_->state() == | 68 } else if (model_->state() == |
| 68 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { | 69 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
| 69 currentController_.reset([[UpdatePendingPasswordViewController alloc] | 70 currentController_.reset([[UpdatePendingPasswordViewController alloc] |
| 70 initWithDelegate:self]); | 71 initWithDelegate:self]); |
| 71 } else if (model_->state() == password_manager::ui::CONFIRMATION_STATE) { | 72 } else if (model_->state() == password_manager::ui::CONFIRMATION_STATE) { |
| 72 currentController_.reset([[ConfirmationPasswordSavedViewController alloc] | 73 currentController_.reset([[ConfirmationPasswordSavedViewController alloc] |
| 73 initWithDelegate:self]); | 74 initWithDelegate:self]); |
| 74 } else if (model_->state() == password_manager::ui::MANAGE_STATE) { | 75 } else if (model_->state() == password_manager::ui::MANAGE_STATE) { |
| 75 currentController_.reset( | 76 currentController_.reset( |
| 76 [[ManagePasswordsViewController alloc] initWithDelegate:self]); | 77 [[ManagePasswordsViewController alloc] initWithDelegate:self]); |
| 77 } else if (model_->state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 78 } else if (model_->state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 78 currentController_.reset( | 79 currentController_.reset( |
| 79 [[AutoSigninViewController alloc] initWithDelegate:self]); | 80 [[AutoSigninViewController alloc] initWithDelegate:self]); |
| 81 } else if (model_->state() == |
| 82 password_manager::ui::CHROME_SIGN_IN_PROMO_STATE) { |
| 83 currentController_.reset( |
| 84 [[SignInPromoViewController alloc] initWithDelegate:self]); |
| 80 } else { | 85 } else { |
| 81 NOTREACHED(); | 86 NOTREACHED(); |
| 82 } | 87 } |
| 83 } | 88 } |
| 84 | 89 |
| 85 - (void)performLayout { | 90 - (void)performLayout { |
| 86 if (!currentController_) | 91 if (!currentController_) |
| 87 return; | 92 return; |
| 88 | 93 |
| 89 // Update the window. | 94 // Update the window. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 (0.5 * info_bubble::kBubbleArrowWidth); | 139 (0.5 * info_bubble::kBubbleArrowWidth); |
| 135 } | 140 } |
| 136 | 141 |
| 137 [window setFrame:NSMakeRect(x, y, width, height) | 142 [window setFrame:NSMakeRect(x, y, width, height) |
| 138 display:YES | 143 display:YES |
| 139 animate:[window isVisible]]; | 144 animate:[window isVisible]]; |
| 140 } | 145 } |
| 141 | 146 |
| 142 #pragma mark BasePasswordsContentViewDelegate | 147 #pragma mark BasePasswordsContentViewDelegate |
| 143 | 148 |
| 149 - (ManagePasswordsBubbleModel*)model { |
| 150 return model_; |
| 151 } |
| 152 |
| 144 - (void)viewShouldDismiss { | 153 - (void)viewShouldDismiss { |
| 145 [self close]; | 154 [self close]; |
| 146 } | 155 } |
| 147 | 156 |
| 148 - (ManagePasswordsBubbleModel*)model { | 157 - (void)refreshBubble { |
| 149 return model_; | 158 NSWindow* window = [self window]; |
| 159 NSRect currentFrame = [window frame]; |
| 160 CGFloat contentHeight = NSHeight([[currentController_ view] frame]); |
| 161 [self updateState]; |
| 162 [[window contentView] setSubviews:@[ [currentController_ view] ]]; |
| 163 [window setDefaultButtonCell:[[currentController_ defaultButton] cell]]; |
| 164 |
| 165 // Set new position. |
| 166 CGFloat delta = NSHeight([[currentController_ view] frame]) - contentHeight; |
| 167 currentFrame.size.height += delta; |
| 168 currentFrame.origin.y -= delta; |
| 169 [window setFrame:currentFrame |
| 170 display:YES |
| 171 animate:YES]; |
| 150 } | 172 } |
| 151 | 173 |
| 152 @end | 174 @end |
| 153 | 175 |
| 154 @implementation ManagePasswordsBubbleController (Testing) | 176 @implementation ManagePasswordsBubbleController (Testing) |
| 155 | 177 |
| 156 - (NSViewController*)currentController { | 178 - (NSViewController*)currentController { |
| 157 return currentController_.get(); | 179 return currentController_.get(); |
| 158 } | 180 } |
| 159 | 181 |
| 160 @end | 182 @end |
| OLD | NEW |