Chromium Code Reviews| 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/location_bar/manage_passwords_decoration.h" | |
| 13 #import "chrome/browser/ui/cocoa/passwords/auto_signin_view_controller.h" | 14 #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" | 15 #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" | 16 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_view_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/passwords/save_pending_password_view_controller .h" | 17 #import "chrome/browser/ui/cocoa/passwords/save_pending_password_view_controller .h" |
| 17 #import "chrome/browser/ui/cocoa/passwords/signin_promo_view_controller.h" | 18 #import "chrome/browser/ui/cocoa/passwords/signin_promo_view_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/passwords/update_pending_password_view_controll er.h" | 19 #import "chrome/browser/ui/cocoa/passwords/update_pending_password_view_controll er.h" |
| 19 #include "ui/base/cocoa/cocoa_base_utils.h" | 20 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 20 #include "ui/base/cocoa/window_size_constants.h" | 21 #include "ui/base/cocoa/window_size_constants.h" |
| 21 | 22 |
| 22 @interface ManagePasswordsBubbleController () | 23 @interface ManagePasswordsBubbleController () |
| 23 // Updates the content view controller according to the current state. | 24 // Updates the content view controller according to the current state. |
| 24 - (void)updateState; | 25 - (void)updateState; |
| 25 @end | 26 @end |
| 26 | 27 |
| 27 @implementation ManagePasswordsBubbleController | 28 @implementation ManagePasswordsBubbleController |
| 28 - (id)initWithParentWindow:(NSWindow*)parentWindow | 29 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 29 model:(ManagePasswordsBubbleModel*)model { | 30 model:(ManagePasswordsBubbleModel*)model { |
| 30 NSRect contentRect = ui::kWindowSizeDeterminedLater; | 31 NSRect contentRect = ui::kWindowSizeDeterminedLater; |
| 31 base::scoped_nsobject<InfoBubbleWindow> window( | 32 base::scoped_nsobject<InfoBubbleWindow> window( |
| 32 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 33 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
| 33 styleMask:NSBorderlessWindowMask | 34 styleMask:NSBorderlessWindowMask |
| 34 backing:NSBackingStoreBuffered | 35 backing:NSBackingStoreBuffered |
| 35 defer:NO]); | 36 defer:NO]); |
| 36 if ((self = [super initWithWindow:window | 37 if ((self = [super initWithWindow:window |
| 37 parentWindow:parentWindow | 38 parentWindow:parentWindow |
| 38 anchoredAt:NSZeroPoint])) { | 39 anchoredAt:NSZeroPoint])) { |
| 39 model_ = model; | 40 model_ = model; |
| 41 Browser* browser = chrome::FindBrowserWithWindow([self parentWindow]); | |
| 42 | |
| 43 bool hasLocationBar = | |
| 44 browser && browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); | |
| 45 | |
| 46 if (hasLocationBar) { | |
| 47 BrowserWindowController* controller = [BrowserWindowController | |
| 48 browserWindowControllerForWindow:parentWindow]; | |
| 49 decoration_ = | |
| 50 [controller locationBarBridge]->manage_passwords_decoration(); | |
| 51 } | |
| 52 | |
| 40 [self updateState]; | 53 [self updateState]; |
| 41 } | 54 } |
| 42 return self; | 55 return self; |
| 43 } | 56 } |
| 44 | 57 |
| 45 - (void)dealloc { | 58 - (void)dealloc { |
| 46 [currentController_ setDelegate:nil]; | 59 [currentController_ setDelegate:nil]; |
| 47 [super dealloc]; | 60 [super dealloc]; |
| 48 } | 61 } |
| 49 | 62 |
| 50 - (void)showWindow:(id)sender { | 63 - (void)showWindow:(id)sender { |
| 51 [self performLayout]; | 64 [self performLayout]; |
| 52 [super showWindow:sender]; | 65 [super showWindow:sender]; |
| 53 } | 66 } |
| 54 | 67 |
| 55 - (void)close { | 68 - (void)close { |
| 56 // The bubble is about to be closed. It destroys the model. | 69 // The bubble is about to be closed. It destroys the model. |
| 57 model_ = nil; | 70 model_ = nil; |
| 58 [super close]; | 71 [super close]; |
| 59 } | 72 } |
| 60 | 73 |
| 74 - (LocationBarDecoration*)decorationForBubble { | |
| 75 return decoration_; | |
|
Robert Sesek
2016/11/28 22:46:59
In all the other DecorationControllers, you don't
spqchan
2016/11/29 17:34:49
Done.
| |
| 76 } | |
| 77 | |
| 61 - (void)updateState { | 78 - (void)updateState { |
| 62 // Find the next view controller. | 79 // Find the next view controller. |
| 63 [currentController_ setDelegate:nil]; | 80 [currentController_ setDelegate:nil]; |
| 64 currentController_.reset(); | 81 currentController_.reset(); |
| 65 if (model_->state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 82 if (model_->state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 66 currentController_.reset([[SavePendingPasswordViewController alloc] | 83 currentController_.reset([[SavePendingPasswordViewController alloc] |
| 67 initWithDelegate:self]); | 84 initWithDelegate:self]); |
| 68 } else if (model_->state() == | 85 } else if (model_->state() == |
| 69 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { | 86 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
| 70 currentController_.reset([[UpdatePendingPasswordViewController alloc] | 87 currentController_.reset([[UpdatePendingPasswordViewController alloc] |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 101 | 118 |
| 102 NSPoint anchorPoint; | 119 NSPoint anchorPoint; |
| 103 info_bubble::BubbleArrowLocation arrow; | 120 info_bubble::BubbleArrowLocation arrow; |
| 104 Browser* browser = chrome::FindBrowserWithWindow([self parentWindow]); | 121 Browser* browser = chrome::FindBrowserWithWindow([self parentWindow]); |
| 105 bool hasLocationBar = | 122 bool hasLocationBar = |
| 106 browser && browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); | 123 browser && browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); |
| 107 | 124 |
| 108 if (hasLocationBar) { | 125 if (hasLocationBar) { |
| 109 BrowserWindowController* controller = [BrowserWindowController | 126 BrowserWindowController* controller = [BrowserWindowController |
| 110 browserWindowControllerForWindow:[self parentWindow]]; | 127 browserWindowControllerForWindow:[self parentWindow]]; |
| 111 anchorPoint = | 128 anchorPoint = [controller locationBarBridge]->GetBubblePointForDecoration( |
| 112 [controller locationBarBridge]->GetManagePasswordsBubblePoint(); | 129 decoration_); |
| 113 arrow = info_bubble::kTopRight; | 130 arrow = info_bubble::kTopRight; |
| 114 } else { | 131 } else { |
| 115 // Center the bubble if there's no location bar. | 132 // Center the bubble if there's no location bar. |
| 116 NSRect contentFrame = [[[self parentWindow] contentView] frame]; | 133 NSRect contentFrame = [[[self parentWindow] contentView] frame]; |
| 117 anchorPoint = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); | 134 anchorPoint = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); |
| 118 arrow = info_bubble::kNoArrow; | 135 arrow = info_bubble::kNoArrow; |
| 119 } | 136 } |
| 120 | 137 |
| 121 // Update the anchor arrow. | 138 // Update the anchor arrow. |
| 122 [[self bubble] setArrowLocation:arrow]; | 139 [[self bubble] setArrowLocation:arrow]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 190 |
| 174 @end | 191 @end |
| 175 | 192 |
| 176 @implementation ManagePasswordsBubbleController (Testing) | 193 @implementation ManagePasswordsBubbleController (Testing) |
| 177 | 194 |
| 178 - (NSViewController*)currentController { | 195 - (NSViewController*)currentController { |
| 179 return currentController_.get(); | 196 return currentController_.get(); |
| 180 } | 197 } |
| 181 | 198 |
| 182 @end | 199 @end |
| OLD | NEW |