OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/autofill/autofill_details_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 93 } |
94 return nil; | 94 return nil; |
95 } | 95 } |
96 | 96 |
97 - (void)modelChanged { | 97 - (void)modelChanged { |
98 for (AutofillSectionContainer* details in details_.get()) | 98 for (AutofillSectionContainer* details in details_.get()) |
99 [details modelChanged]; | 99 [details modelChanged]; |
100 } | 100 } |
101 | 101 |
102 - (BOOL)validate { | 102 - (BOOL)validate { |
103 errorBubbleAnchorView_ = nil; | |
Ilya Sherman
2014/01/08 00:25:37
Hmm, why does this reset the anchor view? Might b
groby-ooo-7-16
2014/01/08 20:15:31
You asked for it. It's long :)
| |
104 | |
103 bool allValid = true; | 105 bool allValid = true; |
104 for (AutofillSectionContainer* details in details_.get()) { | 106 for (AutofillSectionContainer* details in details_.get()) { |
105 if (![[details view] isHidden]) | 107 if (![[details view] isHidden]) |
106 allValid = [details validateFor:autofill::VALIDATE_FINAL] && allValid; | 108 allValid = [details validateFor:autofill::VALIDATE_FINAL] && allValid; |
107 } | 109 } |
108 return allValid; | 110 return allValid; |
109 } | 111 } |
110 | 112 |
111 - (NSView*)firstInvalidField { | 113 - (NSView*)firstInvalidField { |
112 return [self firstEditableFieldMatchingBlock: | 114 return [self firstEditableFieldMatchingBlock: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 } | 151 } |
150 | 152 |
151 - (void)errorBubbleWindowWillClose:(NSNotification*)notification { | 153 - (void)errorBubbleWindowWillClose:(NSNotification*)notification { |
152 DCHECK_EQ([notification object], [errorBubbleController_ window]); | 154 DCHECK_EQ([notification object], [errorBubbleController_ window]); |
153 | 155 |
154 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 156 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
155 [center removeObserver:self | 157 [center removeObserver:self |
156 name:NSWindowWillCloseNotification | 158 name:NSWindowWillCloseNotification |
157 object:[errorBubbleController_ window]]; | 159 object:[errorBubbleController_ window]]; |
158 errorBubbleController_ = nil; | 160 errorBubbleController_ = nil; |
161 errorBubbleAnchorView_ = nil; | |
159 } | 162 } |
160 | 163 |
161 - (void)showErrorBubbleForField:(NSControl<AutofillInputField>*)field { | 164 - (void)showErrorBubbleForField:(NSControl<AutofillInputField>*)field { |
162 if (errorBubbleController_) | 165 // If there is already a bubble controller handling this field, reuse. |
166 if (errorBubbleController_ && errorBubbleAnchorView_ == field) { | |
167 [errorBubbleController_ setMessage:[field validityMessage]]; | |
168 | |
169 return; | |
170 } | |
171 | |
172 if (errorBubbleController_) { | |
163 [errorBubbleController_ close]; | 173 [errorBubbleController_ close]; |
174 } | |
Ilya Sherman
2014/01/08 00:25:37
nit: Why curlies?
groby-ooo-7-16
2014/01/08 20:15:31
Habit. Done.
| |
164 DCHECK(!errorBubbleController_); | 175 DCHECK(!errorBubbleController_); |
165 NSWindow* parentWindow = [field window]; | 176 NSWindow* parentWindow = [field window]; |
166 DCHECK(parentWindow); | 177 DCHECK(parentWindow); |
167 errorBubbleController_ = | 178 errorBubbleController_ = |
168 [[AutofillBubbleController alloc] | 179 [[AutofillBubbleController alloc] |
169 initWithParentWindow:parentWindow | 180 initWithParentWindow:parentWindow |
170 message:[field validityMessage]]; | 181 message:[field validityMessage]]; |
171 | 182 |
172 // Handle bubble self-deleting. | 183 // Handle bubble self-deleting. |
173 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 184 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
(...skipping 22 matching lines...) Expand all Loading... | |
196 | 207 |
197 } else { | 208 } else { |
198 anchorPoint = NSMakePoint(NSMinX(viewRect), NSMinY(viewRect)); | 209 anchorPoint = NSMakePoint(NSMinX(viewRect), NSMinY(viewRect)); |
199 [[errorBubbleController_ bubble] setArrowLocation:info_bubble::kTopLeft]; | 210 [[errorBubbleController_ bubble] setArrowLocation:info_bubble::kTopLeft]; |
200 [[errorBubbleController_ bubble] setAlignment: | 211 [[errorBubbleController_ bubble] setAlignment: |
201 info_bubble::kAlignLeftEdgeToAnchorEdge]; | 212 info_bubble::kAlignLeftEdgeToAnchorEdge]; |
202 } | 213 } |
203 [errorBubbleController_ setAnchorPoint: | 214 [errorBubbleController_ setAnchorPoint: |
204 [parentWindow convertBaseToScreen:anchorPoint]]; | 215 [parentWindow convertBaseToScreen:anchorPoint]]; |
205 | 216 |
217 errorBubbleAnchorView_ = field; | |
206 [errorBubbleController_ showWindow:self]; | 218 [errorBubbleController_ showWindow:self]; |
207 } | 219 } |
208 | 220 |
209 - (void)hideErrorBubble { | 221 - (void)hideErrorBubble { |
210 [errorBubble_ setHidden:YES]; | 222 [errorBubble_ setHidden:YES]; |
211 } | 223 } |
212 | 224 |
213 - (void)updateMessageForField:(NSControl<AutofillInputField>*)field { | 225 - (void)updateMessageForField:(NSControl<AutofillInputField>*)field { |
214 // Ignore fields that are not first responder. Testing this is a bit | 226 // Ignore fields that are not first responder. Testing this is a bit |
215 // convoluted, since for NSTextFields with firstResponder status, the | 227 // convoluted, since for NSTextFields with firstResponder status, the |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 } | 275 } |
264 | 276 |
265 selectedField = field; | 277 selectedField = field; |
266 selectedFieldOrigin = fieldOrigin; | 278 selectedFieldOrigin = fieldOrigin; |
267 } | 279 } |
268 | 280 |
269 return selectedField; | 281 return selectedField; |
270 } | 282 } |
271 | 283 |
272 @end | 284 @end |
OLD | NEW |