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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/autofill_section_container.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm b/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm
new file mode 100644
index 0000000000000000000000000000000000000000..06df18262f6f54cf97ba033b54d200339185b3c2
--- /dev/null
+++ b/chrome/browser/ui/cocoa/autofill/autofill_section_container.mm
@@ -0,0 +1,168 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
+
+#include "base/strings/sys_string_conversions.h"
+#include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
+#import "chrome/browser/ui/cocoa/autofill/autofill_layout_view.h"
+#import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h"
+#include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+#include "ui/base/models/combobox_model.h"
+
+namespace {
+
+// Constants used for layouting controls. These variables are copied from
+// "ui/views/layout/layout_constants.h".
+
+// Horizontal spacing between controls that are logically related.
+const int kRelatedControlHorizontalSpacing = 8;
+
+// Vertical spacing between controls that are logically related.
+const int kRelatedControlVerticalSpacing = 8;
+
+}
+
+@interface AutofillSectionContainer (Internal)
+
+- (NSTextField*)newDetailSectionLabel:(NSString*)labelText;
+- (NSView*)newSectionView:(NSString*)labelText
+ withControls:(AutofillLayoutView*)controls;
+- (AutofillLayoutView*)newInputControls;
+
+@end
+
+@implementation AutofillSectionContainer
+
+@synthesize section = section_;
+
+- (id)initWithController:(autofill::AutofillDialogController*)controller
+ forSection:(autofill::DialogSection)section {
+ if (self = [super init]) {
+ section_ = section;
+ controller_ = controller;
+ }
+ return self;
+}
+
+- (void)loadView {
+ scoped_nsobject<AutofillLayoutView> inputs([self newInputControls]);
+ string16 labelText = controller_->LabelForSection(section_);
+ 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.
+ withControls:inputs];
+}
+
+- (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
+ NSTextField* label([[NSTextField alloc] init]);
+ [label setFont:
+ [[NSFontManager sharedFontManager] convertFont:[label font]
+ toHaveTrait:NSBoldFontMask]];
+ [label setStringValue:labelText];
+ [label sizeToFit];
+ [label setEditable:NO];
+ [label setBordered:NO];
+ [label sizeToFit];
+ return label;
+}
+
+- (NSView*)newSectionView:(NSString*)labelText
+ withControls:(AutofillLayoutView*)controls {
+ // TODO(estade): pull out these constants, and figure out better values
+ // for them. Note: These are duplicated from Views code.
+ const int kLabelWidth = 180;
+ const int kPadding = 30;
+ const int kDetailsWidth = 300;
+ const size_t kDetailSectionInset = 10;
+
+ scoped_nsobject<NSTextField> label([self newDetailSectionLabel:labelText]);
+
+ CGFloat controlHeight = [controls preferredHeightForWidth:kDetailsWidth];
+ 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.
+ 0, 0,
+ kLabelWidth + kPadding + kDetailsWidth,
+ std::max(NSHeight([label frame]), controlHeight) +
+ 2 * kDetailSectionInset);
+ scoped_nsobject<NSView> section_container(
+ [[NSView alloc] initWithFrame:frame]);
+
+ NSPoint labelOrigin = NSMakePoint(
+ kLabelWidth - NSWidth([label frame]),
+ NSHeight(frame) - NSHeight([label frame]) - kDetailSectionInset);
+ [label setFrameOrigin:labelOrigin];
+ [label setAutoresizingMask:(NSViewMinYMargin | NSViewMinYMargin)];
+
+ NSRect dummyFrame;
+ NSRect controlFrame = [controls frame];
+ NSDivideRect(NSInsetRect(frame, 0, kDetailSectionInset),
+ &controlFrame, &dummyFrame, kDetailsWidth, NSMaxXEdge);
+ controlFrame.size.height = controlHeight;
+ [controls setFrame:controlFrame];
+ [controls setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)];
+
+ [section_container setSubviews:@[label, controls]];
+ return [section_container retain];
+}
+
+// TODO(estade): we should be using Chrome-style constrained window padding
+// values.
+- (AutofillLayoutView*)newInputControls {
+ const autofill::DetailInputs& inputs =
+ controller_->RequestedFieldsForSection(section_);
+
+ AutofillLayoutView* view = [[AutofillLayoutView alloc] init];
+ SimpleGridLayout* layout = new SimpleGridLayout(view);
+ [view setLayoutManager:layout];
+
+ for (autofill::DetailInputs::const_iterator it = inputs.begin();
+ it != inputs.end(); ++it) {
+ const autofill::DetailInput& input = *it;
+ int kColumnSetId = input.row_id;
+ ColumnSet* column_set = layout->GetColumnSet(kColumnSetId);
+ if (!column_set) {
+ // Create a new column set and row.
+ column_set = layout->AddColumnSet(kColumnSetId);
+ if (it != inputs.begin())
+ layout->AddPaddingRow(kRelatedControlVerticalSpacing);
+ layout->StartRow(0, kColumnSetId);
+ } else {
+ // Add a new column to existing row.
+ column_set->AddPaddingColumn(kRelatedControlHorizontalSpacing);
+ // Must explicitly skip the padding column since we've already started
+ // adding views.
+ layout->SkipColumns(1);
+ }
+
+ column_set->AddColumn(input.expand_weight ? input.expand_weight : 1.0f);
+
+ ui::ComboboxModel* input_model =
+ controller_->ComboboxModelForAutofillType(input.type);
+ if (input_model) {
+ scoped_nsobject<NSPopUpButton> popup(
+ [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:YES]);
+ for (int i = 0; i < input_model->GetItemCount(); ++i) {
+ [popup addItemWithTitle:
+ base::SysUTF16ToNSString(input_model->GetItemAt(i))];
+ }
+ [popup selectItemWithTitle:base::SysUTF16ToNSString(input.initial_value)];
+ [popup sizeToFit];
+ layout->AddView(popup);
+ } else {
+ scoped_nsobject<AutofillTextField> field(
+ [[AutofillTextField alloc] init]);
+ [[field cell] setPlaceholderString:
+ l10n_util::GetNSStringWithFixup(input.placeholder_text_rid)];
+ [[field cell] setIcon:
+ controller_->IconForField(
+ input.type, input.initial_value).AsNSImage()];
+ [[field cell] setInvalid:YES];
+ [field sizeToFit];
+ layout->AddView(field);
+ }
+ }
+
+ return view;
+}
+
+ @end

Powered by Google App Engine
This is Rietveld 408576698