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/manage_passwords_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/passwords/manage_passwords_view_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "chrome/browser/ui/chrome_style.h" | 10 #include "chrome/browser/ui/chrome_style.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 IDS_MANAGE_PASSWORDS_NO_PASSWORDS)]; | 29 IDS_MANAGE_PASSWORDS_NO_PASSWORDS)]; |
30 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 30 [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
31 [[self cell] setWraps:YES]; | 31 [[self cell] setWraps:YES]; |
32 [self setFrameSize:NSMakeSize(width, MAXFLOAT)]; | 32 [self setFrameSize:NSMakeSize(width, MAXFLOAT)]; |
33 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:self]; | 33 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:self]; |
34 } | 34 } |
35 return self; | 35 return self; |
36 } | 36 } |
37 @end | 37 @end |
38 | 38 |
39 @interface ManagePasswordsBubbleManageViewController () | 39 @interface ManagePasswordsViewController () |
40 - (void)onDoneClicked:(id)sender; | 40 - (void)onDoneClicked:(id)sender; |
41 - (void)onManageClicked:(id)sender; | 41 - (void)onManageClicked:(id)sender; |
42 @end | 42 @end |
43 | 43 |
44 @implementation ManagePasswordsBubbleManageViewController | 44 @implementation ManagePasswordsViewController |
45 | |
46 - (NSButton*)defaultButton { | |
47 return doneButton_; | |
48 } | |
49 | |
50 - (id)initWithModel:(ManagePasswordsBubbleModel*)model | |
51 delegate:(id<ManagePasswordsBubbleContentViewDelegate>)delegate { | |
52 if (([super initWithDelegate:delegate])) { | |
53 model_ = model; | |
54 } | |
55 return self; | |
56 } | |
57 | 45 |
58 - (void)loadView { | 46 - (void)loadView { |
59 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 47 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
60 | 48 |
61 // ----------------------------------- | 49 // ----------------------------------- |
62 // | Title | | 50 // | Title | |
63 // | | | 51 // | | |
64 // | username password x | | 52 // | username password x | |
65 // | username password x | | 53 // | username password x | |
66 // | username password x | | 54 // | username password x | |
67 // | | | 55 // | | |
68 // | Manage [Done] | | 56 // | Manage [Done] | |
69 // ----------------------------------- | 57 // ----------------------------------- |
70 | 58 |
71 // The bubble should be wide enough to fit the title row, the username and | 59 // The bubble should be wide enough to fit the title row, the username and |
72 // password rows, and the buttons row on one line each, but not smaller than | 60 // password rows, and the buttons row on one line each, but not smaller than |
73 // kDesiredBubbleWidth. | 61 // kDesiredBubbleWidth. |
74 | 62 |
75 // Create the elements and add them to the view. | 63 // Create the elements and add them to the view. |
76 NSTextField* titleLabel = | 64 NSTextField* titleLabel = |
77 [self addTitleLabel:base::SysUTF16ToNSString(model_->title()) | 65 [self addTitleLabel:base::SysUTF16ToNSString(self.model->title()) |
78 toView:view]; | 66 toView:view]; |
79 | 67 |
80 // Content. If we have a list of passwords to store for the current site, we | 68 // Content. If we have a list of passwords to store for the current site, we |
81 // display them to the user for management. Otherwise, we show a "No passwords | 69 // display them to the user for management. Otherwise, we show a "No passwords |
82 // for this site" message. | 70 // for this site" message. |
83 NSView* contentView = nil; | 71 NSView* contentView = nil; |
84 if (model_->local_credentials().empty()) { | 72 if (self.model->local_credentials().empty()) { |
85 const CGFloat noPasswordsWidth = std::max( | 73 const CGFloat noPasswordsWidth = std::max( |
86 kDesiredBubbleWidth - 2 * kFramePadding, NSWidth([titleLabel frame])); | 74 kDesiredBubbleWidth - 2 * kFramePadding, NSWidth([titleLabel frame])); |
87 noPasswordsView_.reset( | 75 noPasswordsView_.reset( |
88 [[NoPasswordsView alloc] initWithWidth:noPasswordsWidth]); | 76 [[NoPasswordsView alloc] initWithWidth:noPasswordsWidth]); |
89 contentView = noPasswordsView_.get(); | 77 contentView = noPasswordsView_.get(); |
90 } else { | 78 } else { |
91 passwordsListController_.reset([[PasswordsListViewController alloc] | 79 passwordsListController_.reset([[PasswordsListViewController alloc] |
92 initWithModel:model_ | 80 initWithModel:self.model |
93 forms:model_->local_credentials().get()]); | 81 forms:self.model->local_credentials().get()]); |
94 contentView = [passwordsListController_ view]; | 82 contentView = [passwordsListController_ view]; |
95 } | 83 } |
96 [view addSubview:contentView]; | 84 [view addSubview:contentView]; |
97 | 85 |
98 // Wrap the title if necessary to match the width of the content view. | 86 // Wrap the title if necessary to match the width of the content view. |
99 if (NSWidth([titleLabel frame]) > NSWidth([contentView frame])) { | 87 if (NSWidth([titleLabel frame]) > NSWidth([contentView frame])) { |
100 [titleLabel setFrameSize:NSMakeSize(NSWidth([contentView frame]), 0)]; | 88 [titleLabel setFrameSize:NSMakeSize(NSWidth([contentView frame]), 0)]; |
101 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; | 89 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; |
102 } | 90 } |
103 | 91 |
104 // Done button. | 92 // Done button. |
105 doneButton_.reset([[self addButton:l10n_util::GetNSString(IDS_DONE) | 93 doneButton_.reset([[self addButton:l10n_util::GetNSString(IDS_DONE) |
106 toView:view | 94 toView:view |
107 target:self | 95 target:self |
108 action:@selector(onDoneClicked:)] retain]); | 96 action:@selector(onDoneClicked:)] retain]); |
109 | 97 |
110 // Manage button. | 98 // Manage button. |
111 manageButton_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); | 99 manageButton_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
112 base::scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc] | 100 base::scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc] |
113 initTextCell:base::SysUTF16ToNSString(model_->manage_link())]); | 101 initTextCell:base::SysUTF16ToNSString(self.model->manage_link())]); |
114 [cell setControlSize:NSSmallControlSize]; | 102 [cell setControlSize:NSSmallControlSize]; |
115 [cell setTextColor:skia::SkColorToCalibratedNSColor( | 103 [cell setTextColor:skia::SkColorToCalibratedNSColor( |
116 chrome_style::GetLinkColor())]; | 104 chrome_style::GetLinkColor())]; |
117 [manageButton_ setCell:cell.get()]; | 105 [manageButton_ setCell:cell.get()]; |
118 [manageButton_ sizeToFit]; | 106 [manageButton_ sizeToFit]; |
119 [manageButton_ setTarget:self]; | 107 [manageButton_ setTarget:self]; |
120 [manageButton_ setAction:@selector(onManageClicked:)]; | 108 [manageButton_ setAction:@selector(onManageClicked:)]; |
121 [view addSubview:manageButton_]; | 109 [view addSubview:manageButton_]; |
122 | 110 |
123 // Layout the elements, starting at the bottom and moving up. | 111 // Layout the elements, starting at the bottom and moving up. |
(...skipping 22 matching lines...) Expand all Loading... |
146 | 134 |
147 curX = NSMaxX([contentView frame]) + kFramePadding; | 135 curX = NSMaxX([contentView frame]) + kFramePadding; |
148 curY = NSMaxY([titleLabel frame]) + kFramePadding; | 136 curY = NSMaxY([titleLabel frame]) + kFramePadding; |
149 DCHECK_EQ(width, curX); | 137 DCHECK_EQ(width, curX); |
150 [view setFrameSize:NSMakeSize(curX, curY)]; | 138 [view setFrameSize:NSMakeSize(curX, curY)]; |
151 | 139 |
152 [self setView:view]; | 140 [self setView:view]; |
153 } | 141 } |
154 | 142 |
155 - (void)onDoneClicked:(id)sender { | 143 - (void)onDoneClicked:(id)sender { |
156 model_->OnDoneClicked(); | 144 if (self.model) |
157 [delegate_ viewShouldDismiss]; | 145 self.model->OnDoneClicked(); |
| 146 [self.delegate viewShouldDismiss]; |
158 } | 147 } |
159 | 148 |
160 - (void)onManageClicked:(id)sender { | 149 - (void)onManageClicked:(id)sender { |
161 model_->OnManageLinkClicked(); | 150 if (self.model) |
162 [delegate_ viewShouldDismiss]; | 151 self.model->OnManageLinkClicked(); |
| 152 [self.delegate viewShouldDismiss]; |
| 153 } |
| 154 |
| 155 - (ManagePasswordsBubbleModel*)model { |
| 156 return [self.delegate model]; |
| 157 } |
| 158 |
| 159 - (NSButton*)defaultButton { |
| 160 return doneButton_; |
163 } | 161 } |
164 | 162 |
165 @end | 163 @end |
166 | 164 |
167 @implementation ManagePasswordsBubbleManageViewController (Testing) | 165 @implementation ManagePasswordsViewController (Testing) |
168 | 166 |
169 - (NSButton*)doneButton { | 167 - (NSButton*)doneButton { |
170 return doneButton_.get(); | 168 return doneButton_.get(); |
171 } | 169 } |
172 | 170 |
173 - (NSButton*)manageButton { | 171 - (NSButton*)manageButton { |
174 return manageButton_.get(); | 172 return manageButton_.get(); |
175 } | 173 } |
176 | 174 |
177 - (NoPasswordsView*)noPasswordsView { | 175 - (NoPasswordsView*)noPasswordsView { |
178 return noPasswordsView_.get(); | 176 return noPasswordsView_.get(); |
179 } | 177 } |
180 | 178 |
181 - (PasswordsListViewController*)passwordsListController { | 179 - (PasswordsListViewController*)passwordsListController { |
182 return passwordsListController_.get(); | 180 return passwordsListController_.get(); |
183 } | 181 } |
184 | 182 |
185 @end | 183 @end |
OLD | NEW |