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

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

Issue 14704004: [Autofill] Add Details Section (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
9 #import "chrome/browser/ui/cocoa/autofill/autofill_layout_view.h"
10 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h"
11 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
13 #include "ui/base/models/combobox_model.h"
14
15 namespace {
16
17 // Constants used for layouting controls. These variables are copied from
18 // "ui/views/layout/layout_constants.h".
19
20 // Horizontal spacing between controls that are logically related.
21 const int kRelatedControlHorizontalSpacing = 8;
22
23 // Vertical spacing between controls that are logically related.
24 const int kRelatedControlVerticalSpacing = 8;
25
26 }
27
28 @interface AutofillSectionContainer (Internal)
29
30 - (NSTextField*)newDetailSectionLabel:(NSString*)labelText;
31 - (NSView*)newSectionView:(NSString*)labelText
32 withControls:(AutofillLayoutView*)controls;
33 - (AutofillLayoutView*)newInputControls;
34
35 @end
36
37 @implementation AutofillSectionContainer
38
39 @synthesize section = section_;
40
41 - (id)initWithController:(autofill::AutofillDialogController*)controller
42 forSection:(autofill::DialogSection)section {
43 if (self = [super init]) {
44 section_ = section;
45 controller_ = controller;
46 }
47 return self;
48 }
49
50 - (void)loadView {
51 scoped_nsobject<AutofillLayoutView> inputs([self newInputControls]);
52 string16 labelText = controller_->LabelForSection(section_);
53 self.view = [self newSectionView:base::SysUTF16ToNSString(labelText)
sail 2013/05/01 17:12:36 no dot notation
groby-ooo-7-16 2013/05/01 20:37:44 Done.
54 withControls:inputs];
55 }
56
57 - (NSTextField*)newDetailSectionLabel:(NSString*)labelText {
sail 2013/05/01 17:12:36 My personal preference is to have things autorelea
groby-ooo-7-16 2013/05/01 20:37:44 Done.
sail 2013/05/01 21:38:38 Didn't see this change in the latest patch.
groby-ooo-7-16 2013/05/01 22:36:41 Ah, was talking about newSectionView - missed this
58 NSTextField* label([[NSTextField alloc] init]);
59 [label setFont:
60 [[NSFontManager sharedFontManager] convertFont:[label font]
61 toHaveTrait:NSBoldFontMask]];
62 [label setStringValue:labelText];
63 [label sizeToFit];
64 [label setEditable:NO];
65 [label setBordered:NO];
66 [label sizeToFit];
67 return label;
68 }
69
70 - (NSView*)newSectionView:(NSString*)labelText
71 withControls:(AutofillLayoutView*)controls {
72 // TODO(estade): pull out these constants, and figure out better values
73 // for them. Note: These are duplicated from Views code.
74 const int kLabelWidth = 180;
75 const int kPadding = 30;
76 const int kDetailsWidth = 300;
77 const size_t kDetailSectionInset = 10;
78
79 scoped_nsobject<NSTextField> label([self newDetailSectionLabel:labelText]);
80
81 CGFloat controlHeight = [controls preferredHeightForWidth:kDetailsWidth];
82 NSRect frame = NSMakeRect(
sail 2013/05/01 17:12:36 this would be easier to read as: NSRect frame =
groby-ooo-7-16 2013/05/01 20:37:44 Done.
83 0, 0,
84 kLabelWidth + kPadding + kDetailsWidth,
85 std::max(NSHeight([label frame]), controlHeight) +
86 2 * kDetailSectionInset);
87 scoped_nsobject<NSView> section_container(
88 [[NSView alloc] initWithFrame:frame]);
89
90 NSPoint labelOrigin = NSMakePoint(
91 kLabelWidth - NSWidth([label frame]),
92 NSHeight(frame) - NSHeight([label frame]) - kDetailSectionInset);
93 [label setFrameOrigin:labelOrigin];
94 [label setAutoresizingMask:(NSViewMinYMargin | NSViewMinYMargin)];
95
96 NSRect dummyFrame;
97 NSRect controlFrame = [controls frame];
98 NSDivideRect(NSInsetRect(frame, 0, kDetailSectionInset),
99 &controlFrame, &dummyFrame, kDetailsWidth, NSMaxXEdge);
100 controlFrame.size.height = controlHeight;
101 [controls setFrame:controlFrame];
102 [controls setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)];
103
104 [section_container setSubviews:@[label, controls]];
105 return [section_container retain];
106 }
107
108 // TODO(estade): we should be using Chrome-style constrained window padding
109 // values.
110 - (AutofillLayoutView*)newInputControls {
111 const autofill::DetailInputs& inputs =
112 controller_->RequestedFieldsForSection(section_);
113
114 AutofillLayoutView* view = [[AutofillLayoutView alloc] init];
115 SimpleGridLayout* layout = new SimpleGridLayout(view);
116 [view setLayoutManager:layout];
117
118 for (autofill::DetailInputs::const_iterator it = inputs.begin();
119 it != inputs.end(); ++it) {
120 const autofill::DetailInput& input = *it;
121 int kColumnSetId = input.row_id;
122 ColumnSet* column_set = layout->GetColumnSet(kColumnSetId);
123 if (!column_set) {
124 // Create a new column set and row.
125 column_set = layout->AddColumnSet(kColumnSetId);
126 if (it != inputs.begin())
127 layout->AddPaddingRow(kRelatedControlVerticalSpacing);
128 layout->StartRow(0, kColumnSetId);
129 } else {
130 // Add a new column to existing row.
131 column_set->AddPaddingColumn(kRelatedControlHorizontalSpacing);
132 // Must explicitly skip the padding column since we've already started
133 // adding views.
134 layout->SkipColumns(1);
135 }
136
137 column_set->AddColumn(input.expand_weight ? input.expand_weight : 1.0f);
138
139 ui::ComboboxModel* input_model =
140 controller_->ComboboxModelForAutofillType(input.type);
141 if (input_model) {
142 scoped_nsobject<NSPopUpButton> popup(
143 [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:YES]);
144 for (int i = 0; i < input_model->GetItemCount(); ++i) {
145 [popup addItemWithTitle:
146 base::SysUTF16ToNSString(input_model->GetItemAt(i))];
147 }
148 [popup selectItemWithTitle:base::SysUTF16ToNSString(input.initial_value)];
149 [popup sizeToFit];
150 layout->AddView(popup);
151 } else {
152 scoped_nsobject<AutofillTextField> field(
153 [[AutofillTextField alloc] init]);
154 [[field cell] setPlaceholderString:
155 l10n_util::GetNSStringWithFixup(input.placeholder_text_rid)];
156 [[field cell] setIcon:
157 controller_->IconForField(
158 input.type, input.initial_value).AsNSImage()];
159 [[field cell] setInvalid:YES];
160 [field sizeToFit];
161 layout->AddView(field);
162 }
163 }
164
165 return view;
166 }
167
168 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698