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

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_section_container.mm

Issue 25358002: [rAC, OSX] Stop suggestions/inputs from flickering (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove bad DCHECK. Created 7 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_section_container.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_section_container.h" 5 #import "chrome/browser/ui/cocoa/autofill/autofill_section_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 "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 [self modelChanged]; 207 [self modelChanged];
208 } 208 }
209 209
210 - (NSSize)preferredSize { 210 - (NSSize)preferredSize {
211 if ([view_ isHidden]) 211 if ([view_ isHidden])
212 return NSZeroSize; 212 return NSZeroSize;
213 213
214 NSSize labelSize = [label_ frame].size; // Assumes sizeToFit was called. 214 NSSize labelSize = [label_ frame].size; // Assumes sizeToFit was called.
215 CGFloat controlHeight = [inputs_ preferredHeightForWidth:kDetailsWidth]; 215 CGFloat controlHeight = [inputs_ preferredHeightForWidth:kDetailsWidth];
216 if ([inputs_ isHidden]) 216 if (showSuggestions_)
217 controlHeight = [suggestContainer_ preferredSize].height; 217 controlHeight = [suggestContainer_ preferredSize].height;
218 218
219 return NSMakeSize(kDetailsWidth, 219 return NSMakeSize(kDetailsWidth,
220 labelSize.height + kVerticalHeaderPadding + 220 labelSize.height + kVerticalHeaderPadding +
221 controlHeight + 2 * kDetailSectionInset); 221 controlHeight + 2 * kDetailSectionInset);
222 } 222 }
223 223
224 - (void)performLayout { 224 - (void)performLayout {
225 if ([view_ isHidden]) 225 if ([view_ isHidden])
226 return; 226 return;
227 227
228 NSSize buttonSize = [suggestButton_ frame].size; // Assume sizeToFit. 228 NSSize buttonSize = [suggestButton_ frame].size; // Assume sizeToFit.
229 NSSize labelSize = [label_ frame].size; // Assumes sizeToFit was called. 229 NSSize labelSize = [label_ frame].size; // Assumes sizeToFit was called.
230 CGFloat controlHeight = [inputs_ preferredHeightForWidth:kDetailsWidth]; 230 CGFloat controlHeight = [inputs_ preferredHeightForWidth:kDetailsWidth];
231 if ([inputs_ isHidden]) 231 if (showSuggestions_)
232 controlHeight = [suggestContainer_ preferredSize].height; 232 controlHeight = [suggestContainer_ preferredSize].height;
233 233
234 NSRect viewFrame = NSZeroRect; 234 NSRect viewFrame = NSZeroRect;
235 viewFrame.size = [self preferredSize]; 235 viewFrame.size = [self preferredSize];
236 236
237 NSRect contentFrame = NSInsetRect(viewFrame, 0, kDetailSectionInset); 237 NSRect contentFrame = NSInsetRect(viewFrame, 0, kDetailSectionInset);
238 NSRect controlFrame, labelFrame, buttonFrame; 238 NSRect controlFrame, labelFrame, buttonFrame;
239 239
240 // Label is top left, suggestion button is top right, controls are below that. 240 // Label is top left, suggestion button is top right, controls are below that.
241 NSDivideRect(contentFrame, &labelFrame, &controlFrame, 241 NSDivideRect(contentFrame, &labelFrame, &controlFrame,
242 kVerticalHeaderPadding + labelSize.height, NSMaxYEdge); 242 kVerticalHeaderPadding + labelSize.height, NSMaxYEdge);
243 NSDivideRect(labelFrame, &buttonFrame, &labelFrame, 243 NSDivideRect(labelFrame, &buttonFrame, &labelFrame,
244 buttonSize.width, NSMaxXEdge); 244 buttonSize.width, NSMaxXEdge);
245 245
246 labelFrame = NSOffsetRect(labelFrame, 0, kVerticalHeaderPadding); 246 labelFrame = NSOffsetRect(labelFrame, 0, kVerticalHeaderPadding);
247 labelFrame.size = labelSize; 247 labelFrame.size = labelSize;
248 248
249 buttonFrame = NSOffsetRect(buttonFrame, 0, 5); 249 buttonFrame = NSOffsetRect(buttonFrame, 0, 5);
250 buttonFrame.size = buttonSize; 250 buttonFrame.size = buttonSize;
251 251
252 if ([inputs_ isHidden]) { 252 if (showSuggestions_) {
253 [[suggestContainer_ view] setFrame:controlFrame]; 253 [[suggestContainer_ view] setFrame:controlFrame];
254 [suggestContainer_ performLayout]; 254 [suggestContainer_ performLayout];
255 } else { 255 } else {
256 [inputs_ setFrame:controlFrame]; 256 [inputs_ setFrame:controlFrame];
257 } 257 }
258 [label_ setFrame:labelFrame]; 258 [label_ setFrame:labelFrame];
259 [suggestButton_ setFrame:buttonFrame]; 259 [suggestButton_ setFrame:buttonFrame];
260 [inputs_ setHidden:showSuggestions_];
261 [[suggestContainer_ view] setHidden:!showSuggestions_];
260 [view_ setFrameSize:viewFrame.size]; 262 [view_ setFrameSize:viewFrame.size];
261 } 263 }
262 264
263 - (void)fieldBecameFirstResponder:(NSControl<AutofillInputField>*)field { 265 - (void)fieldBecameFirstResponder:(NSControl<AutofillInputField>*)field {
264 [self textfieldEditedOrActivated:field edited:NO]; 266 [self textfieldEditedOrActivated:field edited:NO];
265 [validationDelegate_ updateMessageForField:field]; 267 [validationDelegate_ updateMessageForField:field];
266 } 268 }
267 269
268 - (void)didChange:(id)sender { 270 - (void)didChange:(id)sender {
269 [self textfieldEditedOrActivated:sender edited:YES]; 271 [self textfieldEditedOrActivated:sender edited:YES];
270 } 272 }
271 273
272 - (void)didEndEditing:(id)sender { 274 - (void)didEndEditing:(id)sender {
273 [self validateFor:autofill::VALIDATE_EDIT]; 275 [self validateFor:autofill::VALIDATE_EDIT];
274 } 276 }
275 277
276 - (void)updateSuggestionState { 278 - (void)updateSuggestionState {
277 const autofill::SuggestionState& suggestionState = 279 const autofill::SuggestionState& suggestionState =
278 delegate_->SuggestionStateForSection(section_); 280 delegate_->SuggestionStateForSection(section_);
279 // TODO(estade): use |vertically_compact_text| when it fits. 281 // TODO(estade): use |vertically_compact_text| when it fits.
280 const base::string16& text = suggestionState.horizontally_compact_text; 282 const base::string16& text = suggestionState.horizontally_compact_text;
281 bool showSuggestions = suggestionState.visible; 283 showSuggestions_ = suggestionState.visible;
282
283 [[suggestContainer_ view] setHidden:!showSuggestions];
284 [inputs_ setHidden:showSuggestions];
285 284
286 base::string16 line1; 285 base::string16 line1;
287 base::string16 line2; 286 base::string16 line2;
288 BreakSuggestionText(text, &line1, &line2); 287 BreakSuggestionText(text, &line1, &line2);
289 [suggestContainer_ setSuggestionText:base::SysUTF16ToNSString(line1) 288 [suggestContainer_ setSuggestionText:base::SysUTF16ToNSString(line1)
290 line2:base::SysUTF16ToNSString(line2)]; 289 line2:base::SysUTF16ToNSString(line2)];
291 [suggestContainer_ setIcon:suggestionState.icon.AsNSImage()]; 290 [suggestContainer_ setIcon:suggestionState.icon.AsNSImage()];
292 if (!suggestionState.extra_text.empty()) { 291 if (!suggestionState.extra_text.empty()) {
293 NSString* extraText = 292 NSString* extraText =
294 base::SysUTF16ToNSString(suggestionState.extra_text); 293 base::SysUTF16ToNSString(suggestionState.extra_text);
295 NSImage* extraIcon = suggestionState.extra_icon.AsNSImage(); 294 NSImage* extraIcon = suggestionState.extra_icon.AsNSImage();
296 [suggestContainer_ showInputField:extraText withIcon:extraIcon]; 295 [suggestContainer_ showInputField:extraText withIcon:extraIcon];
297 } 296 }
298 [view_ setShouldHighlightOnHover:showSuggestions]; 297 [view_ setShouldHighlightOnHover:showSuggestions_];
299 if (showSuggestions) 298 if (showSuggestions_)
300 [view_ setClickTarget:suggestButton_]; 299 [view_ setClickTarget:suggestButton_];
301 else 300 else
302 [view_ setClickTarget:nil]; 301 [view_ setClickTarget:nil];
303 [view_ setHidden:!delegate_->SectionIsActive(section_)]; 302 [view_ setHidden:!delegate_->SectionIsActive(section_)];
304 } 303 }
305 304
306 - (void)update { 305 - (void)update {
307 [self updateAndClobber:YES]; 306 [self updateAndClobber:YES];
308 } 307 }
309 308
(...skipping 18 matching lines...) Expand all
328 [popup selectItemAtIndex:model->GetDefaultIndex()]; 327 [popup selectItemAtIndex:model->GetDefaultIndex()];
329 } 328 }
330 } 329 }
331 } 330 }
332 } 331 }
333 332
334 [self updateAndClobber:NO]; 333 [self updateAndClobber:NO];
335 } 334 }
336 335
337 - (BOOL)validateFor:(autofill::ValidationType)validationType { 336 - (BOOL)validateFor:(autofill::ValidationType)validationType {
338 DCHECK(![[self view] isHidden]);
339
340 NSArray* fields = nil; 337 NSArray* fields = nil;
341 if (![inputs_ isHidden]) { 338 if (![inputs_ isHidden]) {
342 fields = [inputs_ subviews]; 339 fields = [inputs_ subviews];
343 } else if (section_ == autofill::SECTION_CC) { 340 } else if (section_ == autofill::SECTION_CC) {
344 fields = @[[suggestContainer_ inputField]]; 341 fields = @[[suggestContainer_ inputField]];
345 } 342 }
346 343
347 autofill::DetailOutputMap detailOutputs; 344 autofill::DetailOutputMap detailOutputs;
348 [self fillDetailOutputs:&detailOutputs fromControls:fields]; 345 [self fillDetailOutputs:&detailOutputs fromControls:fields];
349 autofill::ValidityMessages messages = delegate_->InputsAreValid( 346 autofill::ValidityMessages messages = delegate_->InputsAreValid(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 614
618 - (void)activateFieldForInput:(const autofill::DetailInput&)input { 615 - (void)activateFieldForInput:(const autofill::DetailInput&)input {
619 if ([self detailInputForType:input.type] != &input) 616 if ([self detailInputForType:input.type] != &input)
620 return; 617 return;
621 618
622 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type]; 619 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type];
623 [[field window] makeFirstResponder:field]; 620 [[field window] makeFirstResponder:field];
624 } 621 }
625 622
626 @end 623 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_section_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698