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

Side by Side Diff: chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.mm

Issue 1411733009: Bulk rename files in chrome/browser/ui/cocoa/passwords/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-federation
Patch Set: Created 5 years, 1 month 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
OLDNEW
(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 #include "chrome/browser/ui/browser_finder.h"
9 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
10 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
11 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
12 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
13 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_account_choos er_view_controller.h"
14 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_auto_signin_v iew_controller.h"
15 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_confirmation_ view_controller.h"
16 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_manage_view_c ontroller.h"
17 #include "ui/base/cocoa/window_size_constants.h"
18
19 @interface ManagePasswordsBubbleController ()
20 // Updates the content view controller according to the current state.
21 - (void)updateState;
22 @end
23
24 @implementation ManagePasswordsBubbleController
25 - (id)initWithParentWindow:(NSWindow*)parentWindow
26 model:(ManagePasswordsBubbleModel*)model {
27 NSRect contentRect = ui::kWindowSizeDeterminedLater;
28 base::scoped_nsobject<InfoBubbleWindow> window(
29 [[InfoBubbleWindow alloc] initWithContentRect:contentRect
30 styleMask:NSBorderlessWindowMask
31 backing:NSBackingStoreBuffered
32 defer:NO]);
33 if ((self = [super initWithWindow:window
34 parentWindow:parentWindow
35 anchoredAt:NSZeroPoint])) {
36 model_ = model;
37 [self updateState];
38 }
39 return self;
40 }
41
42 - (void)dealloc {
43 [currentController_ setDelegate:nil];
44 [super dealloc];
45 }
46
47 - (void)showWindow:(id)sender {
48 [self performLayout];
49 [super showWindow:sender];
50 }
51
52 - (void)close {
53 [currentController_ bubbleWillDisappear];
54 [super close];
55 }
56
57 - (void)updateState {
58 // Find the next view controller.
59 currentController_.reset();
60 if (model_->state() == password_manager::ui::PENDING_PASSWORD_STATE) {
61 currentController_.reset(
62 [[ManagePasswordsBubblePendingViewController alloc]
63 initWithModel:model_
64 delegate:self]);
65 } else if (model_->state() == password_manager::ui::CONFIRMATION_STATE) {
66 currentController_.reset(
67 [[ManagePasswordsBubbleConfirmationViewController alloc]
68 initWithModel:model_
69 delegate:self]);
70 } else if (model_->state() == password_manager::ui::MANAGE_STATE) {
71 currentController_.reset(
72 [[ManagePasswordsBubbleManageViewController alloc]
73 initWithModel:model_
74 delegate:self]);
75 } else if (model_->state() == password_manager::ui::AUTO_SIGNIN_STATE) {
76 currentController_.reset(
77 [[ManagePasswordsBubbleAutoSigninViewController alloc]
78 initWithModel:model_
79 delegate:self]);
80 } else if (model_->state() ==
81 password_manager::ui::CREDENTIAL_REQUEST_STATE) {
82 currentController_.reset(
83 [[ManagePasswordsBubbleAccountChooserViewController alloc]
84 initWithModel:model_
85 delegate:self]);
86 } else {
87 NOTREACHED();
88 }
89 [self performLayout];
90 }
91
92 - (void)performLayout {
93 if (!currentController_)
94 return;
95
96 // Update the window.
97 NSWindow* window = [self window];
98 [[window contentView] setSubviews:@[ [currentController_ view] ]];
99 NSButton* button = [currentController_ defaultButton];
100 if (button)
101 [window setDefaultButtonCell:[button cell]];
102
103 NSPoint anchorPoint;
104 info_bubble::BubbleArrowLocation arrow;
105 Browser* browser = chrome::FindBrowserWithWindow([self parentWindow]);
106 bool hasLocationBar =
107 browser && browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
108
109 if (hasLocationBar) {
110 BrowserWindowController* controller = [BrowserWindowController
111 browserWindowControllerForWindow:[self parentWindow]];
112 anchorPoint =
113 [controller locationBarBridge]->GetManagePasswordsBubblePoint();
114 arrow = info_bubble::kTopRight;
115 } else {
116 // Center the bubble if there's no location bar.
117 NSRect contentFrame = [[[self parentWindow] contentView] frame];
118 anchorPoint = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame));
119 arrow = info_bubble::kNoArrow;
120 }
121
122 // Update the anchor arrow.
123 [[self bubble] setArrowLocation:arrow];
124
125 // Update the anchor point.
126 anchorPoint = [[self parentWindow] convertBaseToScreen:anchorPoint];
127 [self setAnchorPoint:anchorPoint];
128
129 // Update the frame.
130 CGFloat height = NSHeight([[currentController_ view] frame]);
131 CGFloat width = NSWidth([[currentController_ view] frame]);
132 CGFloat x = anchorPoint.x - width;
133 CGFloat y = anchorPoint.y - height;
134
135 // Make the frame large enough for the arrow.
136 if (hasLocationBar) {
137 height += info_bubble::kBubbleArrowHeight;
138 x += info_bubble::kBubbleArrowXOffset +
139 (0.5 * info_bubble::kBubbleArrowWidth);
140 }
141
142 [window setFrame:NSMakeRect(x, y, width, height)
143 display:YES
144 animate:[window isVisible]];
145 }
146
147 #pragma mark ManagePasswordsBubbleContentViewDelegate
148
149 - (void)viewShouldDismiss {
150 [self close];
151 }
152
153 @end
154
155 @implementation ManagePasswordsBubbleController (Testing)
156
157 - (NSViewController*)currentController {
158 return currentController_.get();
159 }
160
161 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698