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

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

Issue 21692002: Rename AutofillDialogController to AutofillDialogViewDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 4 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
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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
13 #import "chrome/browser/ui/cocoa/autofill/autofill_pop_up_button.h" 13 #import "chrome/browser/ui/cocoa/autofill/autofill_pop_up_button.h"
14 #import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h" 14 #import "chrome/browser/ui/cocoa/autofill/autofill_section_view.h"
15 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" 15 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h"
16 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" 16 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h"
17 #import "chrome/browser/ui/cocoa/autofill/layout_view.h" 17 #import "chrome/browser/ui/cocoa/autofill/layout_view.h"
18 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h" 18 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h"
19 #import "chrome/browser/ui/cocoa/image_button_cell.h" 19 #import "chrome/browser/ui/cocoa/image_button_cell.h"
20 #import "chrome/browser/ui/cocoa/menu_button.h" 20 #import "chrome/browser/ui/cocoa/menu_button.h"
21 #include "components/autofill/core/browser/autofill_type.h" 21 #include "components/autofill/core/browser/autofill_type.h"
22 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
(...skipping 21 matching lines...) Expand all
44 44
45 // Padding between section label and section input. 45 // Padding between section label and section input.
46 const int kPadding = 30; 46 const int kPadding = 30;
47 47
48 // Fixed width for the details section. 48 // Fixed width for the details section.
49 const int kDetailsWidth = 300; 49 const int kDetailsWidth = 300;
50 50
51 // Top/bottom inset for contents of a detail section. 51 // Top/bottom inset for contents of a detail section.
52 const size_t kDetailSectionInset = 10; 52 const size_t kDetailSectionInset = 10;
53 53
54 // Break suggestion text into two lines. TODO(groby): Should be on controller. 54 // Break suggestion text into two lines. TODO(groby): Should be on delegate.
55 void BreakSuggestionText(const string16& text, 55 void BreakSuggestionText(const string16& text,
56 string16* line1, 56 string16* line1,
57 string16* line2) { 57 string16* line2) {
58 // TODO(estade): does this localize well? 58 // TODO(estade): does this localize well?
59 string16 line_return(base::ASCIIToUTF16("\n")); 59 string16 line_return(base::ASCIIToUTF16("\n"));
60 size_t position = text.find(line_return); 60 size_t position = text.find(line_return);
61 if (position == string16::npos) { 61 if (position == string16::npos) {
62 *line1 = text; 62 *line1 = text;
63 line2->clear(); 63 line2->clear();
64 } else { 64 } else {
65 *line1 = text.substr(0, position); 65 *line1 = text.substr(0, position);
66 *line2 = text.substr(position + line_return.length()); 66 *line2 = text.substr(position + line_return.length());
67 } 67 }
68 } 68 }
69 69
70 // If the Autofill data comes from a credit card, make sure to overwrite the 70 // If the Autofill data comes from a credit card, make sure to overwrite the
71 // CC comboboxes (even if they already have something in them). If the 71 // CC comboboxes (even if they already have something in them). If the
72 // Autofill data comes from an AutofillProfile, leave the comboboxes alone. 72 // Autofill data comes from an AutofillProfile, leave the comboboxes alone.
73 // TODO(groby): This kind of logic should _really_ live on the controller. 73 // TODO(groby): This kind of logic should _really_ live on the delegate.
74 bool ShouldOverwriteComboboxes(autofill::DialogSection section, 74 bool ShouldOverwriteComboboxes(autofill::DialogSection section,
75 autofill::AutofillFieldType type) { 75 autofill::AutofillFieldType type) {
76 if (autofill::AutofillType(type).group() != autofill::CREDIT_CARD) { 76 if (autofill::AutofillType(type).group() != autofill::CREDIT_CARD) {
77 return false; 77 return false;
78 } 78 }
79 79
80 if (section == autofill::SECTION_CC) { 80 if (section == autofill::SECTION_CC) {
81 return true; 81 return true;
82 } 82 }
83 83
84 return section == autofill::SECTION_CC_BILLING; 84 return section == autofill::SECTION_CC_BILLING;
85 } 85 }
86 86
87 bool CompareInputRows(const autofill::DetailInput* input1, 87 bool CompareInputRows(const autofill::DetailInput* input1,
88 const autofill::DetailInput* input2) { 88 const autofill::DetailInput* input2) {
89 // Row ID -1 is sorted to the end of rows. 89 // Row ID -1 is sorted to the end of rows.
90 if (input2->row_id == -1) 90 if (input2->row_id == -1)
91 return false; 91 return false;
92 return input2->row_id < input1->row_id; 92 return input2->row_id < input1->row_id;
93 } 93 }
94 94
95 } 95 }
96 96
97 @interface AutofillSectionContainer () 97 @interface AutofillSectionContainer ()
98 98
99 // A text field has been edited or activated - inform the controller that it's 99 // A text field has been edited or activated - inform the delegate that it's
100 // time to show a suggestion popup & possibly reset the validity of the input. 100 // time to show a suggestion popup & possibly reset the validity of the input.
101 - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field 101 - (void)textfieldEditedOrActivated:(NSControl<AutofillInputField>*)field
102 edited:(BOOL)edited; 102 edited:(BOOL)edited;
103 103
104 // Convenience method to retrieve a field type via the control's tag. 104 // Convenience method to retrieve a field type via the control's tag.
105 - (autofill::AutofillFieldType)fieldTypeForControl:(NSControl*)control; 105 - (autofill::AutofillFieldType)fieldTypeForControl:(NSControl*)control;
106 106
107 // Find the DetailInput* associated with a field type. 107 // Find the DetailInput* associated with a field type.
108 - (const autofill::DetailInput*)detailInputForType: 108 - (const autofill::DetailInput*)detailInputForType:
109 (autofill::AutofillFieldType)type; 109 (autofill::AutofillFieldType)type;
110 110
111 // Takes an NSArray of controls and builds a DetailOutputMap from them. 111 // Takes an NSArray of controls and builds a DetailOutputMap from them.
112 // Translates between Cocoa code and controller, essentially. 112 // Translates between Cocoa code and delegate, essentially.
113 // All controls must inherit from NSControl and conform to AutofillInputView. 113 // All controls must inherit from NSControl and conform to AutofillInputView.
114 - (void)fillDetailOutputs:(autofill::DetailOutputMap*)outputs 114 - (void)fillDetailOutputs:(autofill::DetailOutputMap*)outputs
115 fromControls:(NSArray*)controls; 115 fromControls:(NSArray*)controls;
116 116
117 // Updates input fields based on controller status. If |shouldClobber| is YES, 117 // Updates input fields based on delegate status. If |shouldClobber| is YES,
118 // will clobber existing data and reset fields to the initial values. 118 // will clobber existing data and reset fields to the initial values.
119 - (void)updateAndClobber:(BOOL)shouldClobber; 119 - (void)updateAndClobber:(BOOL)shouldClobber;
120 120
121 // Create properly styled label for section. Autoreleased. 121 // Create properly styled label for section. Autoreleased.
122 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText; 122 - (NSTextField*)makeDetailSectionLabel:(NSString*)labelText;
123 123
124 // Create a button offering input suggestions. 124 // Create a button offering input suggestions.
125 - (MenuButton*)makeSuggestionButton; 125 - (MenuButton*)makeSuggestionButton;
126 126
127 // Create a view with all inputs requested by |controller_|. Autoreleased. 127 // Create a view with all inputs requested by |delegate_|. Autoreleased.
128 - (LayoutView*)makeInputControls; 128 - (LayoutView*)makeInputControls;
129 129
130 @end 130 @end
131 131
132 @implementation AutofillSectionContainer 132 @implementation AutofillSectionContainer
133 133
134 @synthesize section = section_; 134 @synthesize section = section_;
135 @synthesize validationDelegate = validationDelegate_; 135 @synthesize validationDelegate = validationDelegate_;
136 136
137 - (id)initWithController:(autofill::AutofillDialogController*)controller 137 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate
138 forSection:(autofill::DialogSection)section { 138 forSection:(autofill::DialogSection)section {
139 if (self = [super init]) { 139 if (self = [super init]) {
140 section_ = section; 140 section_ = section;
141 controller_ = controller; 141 delegate_ = delegate;
142 } 142 }
143 return self; 143 return self;
144 } 144 }
145 145
146 - (void)getInputs:(autofill::DetailOutputMap*)output { 146 - (void)getInputs:(autofill::DetailOutputMap*)output {
147 [self fillDetailOutputs:output fromControls:[inputs_ subviews]]; 147 [self fillDetailOutputs:output fromControls:[inputs_ subviews]];
148 } 148 }
149 149
150 // Note: This corresponds to Views' "UpdateDetailsGroupState". 150 // Note: This corresponds to Views' "UpdateDetailsGroupState".
151 - (void)modelChanged { 151 - (void)modelChanged {
152 ui::MenuModel* suggestionModel = controller_->MenuModelForSection(section_); 152 ui::MenuModel* suggestionModel = delegate_->MenuModelForSection(section_);
153 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel 153 menuController_.reset([[MenuController alloc] initWithModel:suggestionModel
154 useWithPopUpButtonCell:YES]); 154 useWithPopUpButtonCell:YES]);
155 NSMenu* menu = [menuController_ menu]; 155 NSMenu* menu = [menuController_ menu];
156 156
157 const BOOL hasSuggestions = [menu numberOfItems] > 0; 157 const BOOL hasSuggestions = [menu numberOfItems] > 0;
158 [suggestButton_ setHidden:!hasSuggestions]; 158 [suggestButton_ setHidden:!hasSuggestions];
159 159
160 [suggestButton_ setAttachedMenu:menu]; 160 [suggestButton_ setAttachedMenu:menu];
161 161
162 [self updateSuggestionState]; 162 [self updateSuggestionState];
163 163
164 // TODO(groby): "Save in Chrome" handling. 164 // TODO(groby): "Save in Chrome" handling.
165 165
166 if (![[self view] isHidden]) 166 if (![[self view] isHidden])
167 [self validateFor:autofill::VALIDATE_EDIT]; 167 [self validateFor:autofill::VALIDATE_EDIT];
168 168
169 // Always request re-layout on state change. 169 // Always request re-layout on state change.
170 id controller = [[view_ window] windowController]; 170 id delegate = [[view_ window] windowController];
171 if ([controller respondsToSelector:@selector(requestRelayout)]) 171 if ([delegate respondsToSelector:@selector(requestRelayout)])
172 [controller performSelector:@selector(requestRelayout)]; 172 [delegate performSelector:@selector(requestRelayout)];
173 } 173 }
174 174
175 - (void)loadView { 175 - (void)loadView {
176 // Keep a list of weak pointers to DetailInputs. 176 // Keep a list of weak pointers to DetailInputs.
177 const autofill::DetailInputs& inputs = 177 const autofill::DetailInputs& inputs =
178 controller_->RequestedFieldsForSection(section_); 178 delegate_->RequestedFieldsForSection(section_);
179 for (size_t i = 0; i < inputs.size(); ++i) { 179 for (size_t i = 0; i < inputs.size(); ++i) {
180 detailInputs_.push_back(&(inputs[i])); 180 detailInputs_.push_back(&(inputs[i]));
181 } 181 }
182 182
183 inputs_.reset([[self makeInputControls] retain]); 183 inputs_.reset([[self makeInputControls] retain]);
184 string16 labelText = controller_->LabelForSection(section_); 184 string16 labelText = delegate_->LabelForSection(section_);
185 label_.reset([[self makeDetailSectionLabel: 185 label_.reset([[self makeDetailSectionLabel:
186 base::SysUTF16ToNSString(labelText)] retain]); 186 base::SysUTF16ToNSString(labelText)] retain]);
187 187
188 suggestButton_.reset([[self makeSuggestionButton] retain]); 188 suggestButton_.reset([[self makeSuggestionButton] retain]);
189 suggestContainer_.reset([[AutofillSuggestionContainer alloc] init]); 189 suggestContainer_.reset([[AutofillSuggestionContainer alloc] init]);
190 190
191 view_.reset([[AutofillSectionView alloc] initWithFrame:NSZeroRect]); 191 view_.reset([[AutofillSectionView alloc] initWithFrame:NSZeroRect]);
192 [self setView:view_]; 192 [self setView:view_];
193 [[self view] setSubviews: 193 [[self view] setSubviews:
194 @[label_, inputs_, [suggestContainer_ view], suggestButton_]]; 194 @[label_, inputs_, [suggestContainer_ view], suggestButton_]];
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 - (void)didChange:(id)sender { 275 - (void)didChange:(id)sender {
276 [self textfieldEditedOrActivated:sender edited:YES]; 276 [self textfieldEditedOrActivated:sender edited:YES];
277 } 277 }
278 278
279 - (void)didEndEditing:(id)sender { 279 - (void)didEndEditing:(id)sender {
280 [self validateFor:autofill::VALIDATE_EDIT]; 280 [self validateFor:autofill::VALIDATE_EDIT];
281 } 281 }
282 282
283 - (void)updateSuggestionState { 283 - (void)updateSuggestionState {
284 const autofill::SuggestionState& suggestionState = 284 const autofill::SuggestionState& suggestionState =
285 controller_->SuggestionStateForSection(section_); 285 delegate_->SuggestionStateForSection(section_);
286 bool showSuggestions = !suggestionState.text.empty(); 286 bool showSuggestions = !suggestionState.text.empty();
287 287
288 [[suggestContainer_ view] setHidden:!showSuggestions]; 288 [[suggestContainer_ view] setHidden:!showSuggestions];
289 [inputs_ setHidden:showSuggestions]; 289 [inputs_ setHidden:showSuggestions];
290 290
291 string16 line1; 291 string16 line1;
292 string16 line2; 292 string16 line2;
293 BreakSuggestionText(suggestionState.text, &line1, &line2); 293 BreakSuggestionText(suggestionState.text, &line1, &line2);
294 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 294 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
295 gfx::Font font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont( 295 gfx::Font font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(
296 0, suggestionState.text_style); 296 0, suggestionState.text_style);
297 [suggestContainer_ setSuggestionText:base::SysUTF16ToNSString(line1) 297 [suggestContainer_ setSuggestionText:base::SysUTF16ToNSString(line1)
298 line2:base::SysUTF16ToNSString(line2) 298 line2:base::SysUTF16ToNSString(line2)
299 withFont:font.GetNativeFont()]; 299 withFont:font.GetNativeFont()];
300 [suggestContainer_ setIcon:suggestionState.icon.AsNSImage()]; 300 [suggestContainer_ setIcon:suggestionState.icon.AsNSImage()];
301 if (!suggestionState.extra_text.empty()) { 301 if (!suggestionState.extra_text.empty()) {
302 NSString* extraText = 302 NSString* extraText =
303 base::SysUTF16ToNSString(suggestionState.extra_text); 303 base::SysUTF16ToNSString(suggestionState.extra_text);
304 NSImage* extraIcon = suggestionState.extra_icon.AsNSImage(); 304 NSImage* extraIcon = suggestionState.extra_icon.AsNSImage();
305 [suggestContainer_ showInputField:extraText withIcon:extraIcon]; 305 [suggestContainer_ showInputField:extraText withIcon:extraIcon];
306 } 306 }
307 [view_ setShouldHighlightOnHover:showSuggestions]; 307 [view_ setShouldHighlightOnHover:showSuggestions];
308 [view_ setHidden:!controller_->SectionIsActive(section_)]; 308 [view_ setHidden:!delegate_->SectionIsActive(section_)];
309 } 309 }
310 310
311 - (void)update { 311 - (void)update {
312 [self updateAndClobber:YES]; 312 [self updateAndClobber:YES];
313 } 313 }
314 314
315 - (void)fillForInput:(const autofill::DetailInput&)input { 315 - (void)fillForInput:(const autofill::DetailInput&)input {
316 // Make sure to overwrite the originating input if it is a text field. 316 // Make sure to overwrite the originating input if it is a text field.
317 AutofillTextField* field = 317 AutofillTextField* field =
318 base::mac::ObjCCast<AutofillTextField>([inputs_ viewWithTag:input.type]); 318 base::mac::ObjCCast<AutofillTextField>([inputs_ viewWithTag:input.type]);
319 [field setFieldValue:@""]; 319 [field setFieldValue:@""];
320 320
321 if (ShouldOverwriteComboboxes(section_, input.type)) { 321 if (ShouldOverwriteComboboxes(section_, input.type)) {
322 for (NSControl* control in [inputs_ subviews]) { 322 for (NSControl* control in [inputs_ subviews]) {
323 AutofillPopUpButton* popup = 323 AutofillPopUpButton* popup =
324 base::mac::ObjCCast<AutofillPopUpButton>(control); 324 base::mac::ObjCCast<AutofillPopUpButton>(control);
325 if (popup) { 325 if (popup) {
326 autofill::AutofillFieldType fieldType = 326 autofill::AutofillFieldType fieldType =
327 [self fieldTypeForControl:popup]; 327 [self fieldTypeForControl:popup];
328 if (autofill::AutofillType(fieldType).group() == 328 if (autofill::AutofillType(fieldType).group() ==
329 autofill::CREDIT_CARD) { 329 autofill::CREDIT_CARD) {
330 ui::ComboboxModel* model = 330 ui::ComboboxModel* model =
331 controller_->ComboboxModelForAutofillType(fieldType); 331 delegate_->ComboboxModelForAutofillType(fieldType);
332 DCHECK(model); 332 DCHECK(model);
333 [popup selectItemAtIndex:model->GetDefaultIndex()]; 333 [popup selectItemAtIndex:model->GetDefaultIndex()];
334 } 334 }
335 } 335 }
336 } 336 }
337 } 337 }
338 338
339 [self updateAndClobber:NO]; 339 [self updateAndClobber:NO];
340 } 340 }
341 341
342 - (void)editLinkClicked { 342 - (void)editLinkClicked {
343 controller_->EditClickedForSection(section_); 343 delegate_->EditClickedForSection(section_);
344 } 344 }
345 345
346 - (NSString*)editLinkTitle { 346 - (NSString*)editLinkTitle {
347 return base::SysUTF16ToNSString(controller_->EditSuggestionText()); 347 return base::SysUTF16ToNSString(delegate_->EditSuggestionText());
348 } 348 }
349 349
350 - (BOOL)validateFor:(autofill::ValidationType)validationType { 350 - (BOOL)validateFor:(autofill::ValidationType)validationType {
351 DCHECK(![[self view] isHidden]); 351 DCHECK(![[self view] isHidden]);
352 352
353 NSArray* fields = nil; 353 NSArray* fields = nil;
354 if (![inputs_ isHidden]) { 354 if (![inputs_ isHidden]) {
355 fields = [inputs_ subviews]; 355 fields = [inputs_ subviews];
356 } else if (section_ == autofill::SECTION_CC) { 356 } else if (section_ == autofill::SECTION_CC) {
357 fields = @[[suggestContainer_ inputField]]; 357 fields = @[[suggestContainer_ inputField]];
358 } 358 }
359 359
360 autofill::DetailOutputMap detailOutputs; 360 autofill::DetailOutputMap detailOutputs;
361 [self fillDetailOutputs:&detailOutputs fromControls:fields]; 361 [self fillDetailOutputs:&detailOutputs fromControls:fields];
362 autofill::ValidityData invalidInputs = controller_->InputsAreValid( 362 autofill::ValidityData invalidInputs = delegate_->InputsAreValid(
363 section_, detailOutputs, validationType); 363 section_, detailOutputs, validationType);
364 364
365 for (NSControl<AutofillInputField>* input in fields) { 365 for (NSControl<AutofillInputField>* input in fields) {
366 const autofill::AutofillFieldType type = [self fieldTypeForControl:input]; 366 const autofill::AutofillFieldType type = [self fieldTypeForControl:input];
367 if (invalidInputs.count(type)) 367 if (invalidInputs.count(type))
368 [input setValidityMessage:base::SysUTF16ToNSString(invalidInputs[type])]; 368 [input setValidityMessage:base::SysUTF16ToNSString(invalidInputs[type])];
369 else 369 else
370 [input setValidityMessage:@""]; 370 [input setValidityMessage:@""];
371 [validationDelegate_ updateMessageForField:input]; 371 [validationDelegate_ updateMessageForField:input];
372 } 372 }
(...skipping 19 matching lines...) Expand all
392 NSRect textFrameInScreen = [field convertRect:[field frame] toView:nil]; 392 NSRect textFrameInScreen = [field convertRect:[field frame] toView:nil];
393 textFrameInScreen.origin = 393 textFrameInScreen.origin =
394 [[field window] convertBaseToScreen:textFrameInScreen.origin]; 394 [[field window] convertBaseToScreen:textFrameInScreen.origin];
395 395
396 // And adjust for gfx::Rect being flipped compared to OSX coordinates. 396 // And adjust for gfx::Rect being flipped compared to OSX coordinates.
397 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 397 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
398 textFrameInScreen.origin.y = 398 textFrameInScreen.origin.y =
399 NSMaxY([screen frame]) - NSMaxY(textFrameInScreen); 399 NSMaxY([screen frame]) - NSMaxY(textFrameInScreen);
400 gfx::Rect textFrameRect(NSRectToCGRect(textFrameInScreen)); 400 gfx::Rect textFrameRect(NSRectToCGRect(textFrameInScreen));
401 401
402 controller_->UserEditedOrActivatedInput(section_, 402 delegate_->UserEditedOrActivatedInput(section_,
403 [self detailInputForType:type], 403 [self detailInputForType:type],
404 [self view], 404 [self view],
405 textFrameRect, 405 textFrameRect,
406 fieldValue, 406 fieldValue,
407 edited); 407 edited);
408 408
409 // If the field is marked as invalid, check if the text is now valid. 409 // If the field is marked as invalid, check if the text is now valid.
410 // Many fields (i.e. CC#) are invalid for most of the duration of editing, 410 // Many fields (i.e. CC#) are invalid for most of the duration of editing,
411 // so flagging them as invalid prematurely is not helpful. However, 411 // so flagging them as invalid prematurely is not helpful. However,
412 // correcting a minor mistake (i.e. a wrong CC digit) should immediately 412 // correcting a minor mistake (i.e. a wrong CC digit) should immediately
413 // result in validation - positive user feedback. 413 // result in validation - positive user feedback.
414 if ([textfield invalid]) { 414 if ([textfield invalid]) {
415 string16 message = controller_->InputValidityMessage(section_, 415 string16 message = delegate_->InputValidityMessage(section_,
416 type, 416 type,
417 fieldValue); 417 fieldValue);
418 [textfield setValidityMessage:base::SysUTF16ToNSString(message)]; 418 [textfield setValidityMessage:base::SysUTF16ToNSString(message)];
419 [validationDelegate_ updateMessageForField:textfield]; 419 [validationDelegate_ updateMessageForField:textfield];
420 420
421 // If the field transitioned from invalid to valid, re-validate the group, 421 // If the field transitioned from invalid to valid, re-validate the group,
422 // since inter-field checks become meaningful with valid fields. 422 // since inter-field checks become meaningful with valid fields.
423 if (![textfield invalid]) 423 if (![textfield invalid])
424 [self validateFor:autofill::VALIDATE_EDIT]; 424 [self validateFor:autofill::VALIDATE_EDIT];
425 } 425 }
426 426
427 // Update the icon for the textfield. 427 // Update the icon for the textfield.
428 gfx::Image icon = controller_->IconForField(type, fieldValue); 428 gfx::Image icon = delegate_->IconForField(type, fieldValue);
429 if (!icon.IsEmpty()) { 429 if (!icon.IsEmpty()) {
430 [[textfield cell] setIcon:icon.ToNSImage()]; 430 [[textfield cell] setIcon:icon.ToNSImage()];
431 } 431 }
432 } 432 }
433 433
434 - (autofill::AutofillFieldType)fieldTypeForControl:(NSControl*)control { 434 - (autofill::AutofillFieldType)fieldTypeForControl:(NSControl*)control {
435 DCHECK([control tag]); 435 DCHECK([control tag]);
436 return static_cast<autofill::AutofillFieldType>([control tag]); 436 return static_cast<autofill::AutofillFieldType>([control tag]);
437 } 437 }
438 438
(...skipping 28 matching lines...) Expand all
467 toHaveTrait:NSBoldFontMask]]; 467 toHaveTrait:NSBoldFontMask]];
468 [label setStringValue:labelText]; 468 [label setStringValue:labelText];
469 [label setEditable:NO]; 469 [label setEditable:NO];
470 [label setBordered:NO]; 470 [label setBordered:NO];
471 [label sizeToFit]; 471 [label sizeToFit];
472 return label.autorelease(); 472 return label.autorelease();
473 } 473 }
474 474
475 - (void)updateAndClobber:(BOOL)shouldClobber { 475 - (void)updateAndClobber:(BOOL)shouldClobber {
476 const autofill::DetailInputs& updatedInputs = 476 const autofill::DetailInputs& updatedInputs =
477 controller_->RequestedFieldsForSection(section_); 477 delegate_->RequestedFieldsForSection(section_);
478 478
479 for (autofill::DetailInputs::const_iterator iter = updatedInputs.begin(); 479 for (autofill::DetailInputs::const_iterator iter = updatedInputs.begin();
480 iter != updatedInputs.end(); 480 iter != updatedInputs.end();
481 ++iter) { 481 ++iter) {
482 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:iter->type]; 482 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:iter->type];
483 DCHECK(field); 483 DCHECK(field);
484 484
485 [field setEnabled:iter->editable]; 485 [field setEnabled:iter->editable];
486 486
487 // TODO(groby): For comboboxes, "empty" means "set to default index" 487 // TODO(groby): For comboboxes, "empty" means "set to default index"
488 if (shouldClobber || [[field fieldValue] length] == 0) { 488 if (shouldClobber || [[field fieldValue] length] == 0) {
489 [field setFieldValue:base::SysUTF16ToNSString(iter->initial_value)]; 489 [field setFieldValue:base::SysUTF16ToNSString(iter->initial_value)];
490 AutofillTextField* textField = 490 AutofillTextField* textField =
491 base::mac::ObjCCast<AutofillTextField>(field); 491 base::mac::ObjCCast<AutofillTextField>(field);
492 if (textField) { 492 if (textField) {
493 gfx::Image icon = 493 gfx::Image icon =
494 controller_->IconForField(iter->type, iter->initial_value); 494 delegate_->IconForField(iter->type, iter->initial_value);
495 if (!icon.IsEmpty()) { 495 if (!icon.IsEmpty()) {
496 [[textField cell] setIcon:icon.ToNSImage()]; 496 [[textField cell] setIcon:icon.ToNSImage()];
497 } 497 }
498 } 498 }
499 } 499 }
500 } 500 }
501 [self modelChanged]; 501 [self modelChanged];
502 } 502 }
503 503
504 - (MenuButton*)makeSuggestionButton { 504 - (MenuButton*)makeSuggestionButton {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // Add a new column to existing row. 557 // Add a new column to existing row.
558 column_set->AddPaddingColumn(kRelatedControlHorizontalSpacing); 558 column_set->AddPaddingColumn(kRelatedControlHorizontalSpacing);
559 // Must explicitly skip the padding column since we've already started 559 // Must explicitly skip the padding column since we've already started
560 // adding views. 560 // adding views.
561 layout->SkipColumns(1); 561 layout->SkipColumns(1);
562 } 562 }
563 563
564 column_set->AddColumn(input.expand_weight ? input.expand_weight : 1.0f); 564 column_set->AddColumn(input.expand_weight ? input.expand_weight : 1.0f);
565 565
566 ui::ComboboxModel* input_model = 566 ui::ComboboxModel* input_model =
567 controller_->ComboboxModelForAutofillType(input.type); 567 delegate_->ComboboxModelForAutofillType(input.type);
568 base::scoped_nsprotocol<NSControl<AutofillInputField>*> control; 568 base::scoped_nsprotocol<NSControl<AutofillInputField>*> control;
569 if (input_model) { 569 if (input_model) {
570 base::scoped_nsobject<AutofillPopUpButton> popup( 570 base::scoped_nsobject<AutofillPopUpButton> popup(
571 [[AutofillPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]); 571 [[AutofillPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]);
572 for (int i = 0; i < input_model->GetItemCount(); ++i) { 572 for (int i = 0; i < input_model->GetItemCount(); ++i) {
573 [popup addItemWithTitle: 573 [popup addItemWithTitle:
574 base::SysUTF16ToNSString(input_model->GetItemAt(i))]; 574 base::SysUTF16ToNSString(input_model->GetItemAt(i))];
575 } 575 }
576 control.reset(popup.release()); 576 control.reset(popup.release());
577 } else { 577 } else {
578 base::scoped_nsobject<AutofillTextField> field( 578 base::scoped_nsobject<AutofillTextField> field(
579 [[AutofillTextField alloc] init]); 579 [[AutofillTextField alloc] init]);
580 [[field cell] setPlaceholderString: 580 [[field cell] setPlaceholderString:
581 l10n_util::GetNSStringWithFixup(input.placeholder_text_rid)]; 581 l10n_util::GetNSStringWithFixup(input.placeholder_text_rid)];
582 [[field cell] setIcon: 582 [[field cell] setIcon:
583 controller_->IconForField( 583 delegate_->IconForField(
584 input.type, input.initial_value).AsNSImage()]; 584 input.type, input.initial_value).AsNSImage()];
585 control.reset(field.release()); 585 control.reset(field.release());
586 } 586 }
587 [control setFieldValue:base::SysUTF16ToNSString(input.initial_value)]; 587 [control setFieldValue:base::SysUTF16ToNSString(input.initial_value)];
588 [control sizeToFit]; 588 [control sizeToFit];
589 [control setTag:input.type]; 589 [control setTag:input.type];
590 [control setDelegate:self]; 590 [control setDelegate:self];
591 // Hide away fields that cannot be edited. 591 // Hide away fields that cannot be edited.
592 if (kColumnSetId == -1) { 592 if (kColumnSetId == -1) {
593 [control setFrame:NSZeroRect]; 593 [control setFrame:NSZeroRect];
(...skipping 29 matching lines...) Expand all
623 623
624 - (void)activateFieldForInput:(const autofill::DetailInput&)input { 624 - (void)activateFieldForInput:(const autofill::DetailInput&)input {
625 if ([self detailInputForType:input.type] != &input) 625 if ([self detailInputForType:input.type] != &input)
626 return; 626 return;
627 627
628 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type]; 628 NSControl<AutofillInputField>* field = [inputs_ viewWithTag:input.type];
629 [[field window] makeFirstResponder:field]; 629 [[field window] makeFirstResponder:field];
630 } 630 }
631 631
632 @end 632 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698