Skip to content

Commit

Permalink
[Autofill] Add Details Section
Browse files Browse the repository at this point in the history
Provide UI for details of payment instrument.

R=sail@chromium.org
BUG=157274

Review URL: https://chromiumcodereview.appspot.com/14704004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200338 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
groby@chromium.org committed May 15, 2013
1 parent d95ce52 commit a1dae87
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 16 deletions.
27 changes: 27 additions & 0 deletions chrome/browser/ui/cocoa/autofill/autofill_details_container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

#ifndef CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DETAILS_CONTAINER_H_
#define CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DETAILS_CONTAINER_H_

#import <Cocoa/Cocoa.h>

#include "base/memory/scoped_nsobject.h"

namespace autofill {
class AutofillDialogController;
}

// UI controller for details for current payment instrument.
@interface AutofillDetailsContainer : NSViewController {
@private
scoped_nsobject<NSMutableArray> details_; // The individual detail sections.
autofill::AutofillDialogController* controller_; // Not owned.
}

- (id)initWithController:(autofill::AutofillDialogController*)controller;

@end

#endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DETAILS_CONTAINER_H_
47 changes: 47 additions & 0 deletions chrome/browser/ui/cocoa/autofill/autofill_details_container.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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_details_container.h"

#include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"

@implementation AutofillDetailsContainer

- (id)initWithController:(autofill::AutofillDialogController*)controller {
if (self = [super init]) {
controller_ = controller;
}
return self;
}

- (void)addSection:(autofill::DialogSection)section {
scoped_nsobject<AutofillSectionContainer> sectionContainer(
[[AutofillSectionContainer alloc] initWithController:controller_
forSection:section]);
[details_ addObject:sectionContainer];
}

- (void)loadView {
details_.reset([[NSMutableArray alloc] init]);

[self addSection:autofill::SECTION_EMAIL];
[self addSection:autofill::SECTION_CC];
[self addSection:autofill::SECTION_BILLING];
// TODO(groby): Add SECTION_CC_BILLING once toggling is enabled.
[self addSection:autofill::SECTION_SHIPPING];

[self setView:[[NSView alloc] init]];

NSRect rect = NSZeroRect;
for(AutofillSectionContainer* container in
[details_ reverseObjectEnumerator]) {
[[container view] setFrameOrigin:NSMakePoint(0, NSMaxY(rect))];
rect = NSUnionRect(rect, [[container view] frame]);
[[self view] addSubview:[container view]];
}
[[self view] setFrame:rect];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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_details_container.h"

#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/autofill/mock_autofill_dialog_controller.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/base/test/ui_cocoa_test_helper.h"

namespace {

class AutofillDetailsContainerTest : public ui::CocoaTest {
public:
AutofillDetailsContainerTest() {
container_.reset([[AutofillDetailsContainer alloc] initWithController:
&controller_]);
[[test_window() contentView] addSubview:[container_ view]];
}

protected:
scoped_nsobject<AutofillDetailsContainer> container_;
testing::NiceMock<autofill::MockAutofillDialogController> controller_;
};

} // namespace

TEST_VIEW(AutofillDetailsContainerTest, [container_ view])

TEST_F(AutofillDetailsContainerTest, BasicProperties) {
EXPECT_GT([[[container_ view] subviews] count], 0U);
EXPECT_GT(NSHeight([[container_ view] frame]), 0);
EXPECT_GT(NSWidth([[container_ view] frame]), 0);
}
30 changes: 19 additions & 11 deletions chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"

#include "chrome/browser/ui/chrome_style.h"
#include "base/mac/bundle_locations.h"
#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/chrome_style.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
#include "chrome/browser/ui/chrome_style.h"
#include "chrome/browser/ui/chrome_style.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
#include "ui/base/cocoa/window_size_constants.h"

namespace autofill {

Expand Down Expand Up @@ -112,33 +114,39 @@ - (id)initWithWebContents:(content::WebContents*)webContents
autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog {
DCHECK(webContents);

// TODO(groby): Should be ui::kWindowSizeDeterminedLater
NSRect frame = NSMakeRect(0, 0, 550, 600);
scoped_nsobject<ConstrainedWindowCustomWindow> window(
[[ConstrainedWindowCustomWindow alloc] initWithContentRect:frame]);
[[ConstrainedWindowCustomWindow alloc]
initWithContentRect:ui::kWindowSizeDeterminedLater]);

if ((self = [super initWithWindow:window])) {
webContents_ = webContents;
autofillDialog_ = autofillDialog;

NSRect clientFrame = NSInsetRect(
frame, chrome_style::kHorizontalPadding, 0);
clientFrame.size.height -= chrome_style::kTitleTopPadding +
chrome_style::kClientBottomPadding;
clientFrame.origin.y = chrome_style::kClientBottomPadding;
mainContainer_.reset([[AutofillMainContainer alloc]
initWithController:autofillDialog->controller()]);
[mainContainer_ setTarget:self];
[[mainContainer_ view] setFrame:clientFrame];

signInContainer_.reset(
[[AutofillSignInContainer alloc]
initWithController:autofillDialog->controller()]);
[[signInContainer_ view] setHidden:YES];
[[signInContainer_ view] setFrame:clientFrame];

NSRect clientRect = [[mainContainer_ view] frame];
clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding,
chrome_style::kHorizontalPadding);
[[mainContainer_ view] setFrame:clientRect];
[[signInContainer_ view] setFrame:clientRect];
[[[self window] contentView] setSubviews:
@[[mainContainer_ view], [signInContainer_ view]]];

NSRect contentRect = clientRect;
contentRect.origin = NSMakePoint(0, 0);
contentRect.size.width += 2 * chrome_style::kHorizontalPadding;
contentRect.size.height += chrome_style::kClientBottomPadding +
chrome_style::kTitleTopPadding;
[[[self window] contentView] setFrame:contentRect];
NSRect frame = [[self window] frameRectForContentRect:contentRect];
[[self window] setFrame:frame display:YES];
}
return self;
}
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/cocoa/autofill/autofill_main_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/memory/scoped_nsobject.h"

@class AutofillAccountChooser;
@class AutofillDetailsContainer;
@class AutofillDialogWindowController;
@class GTMWidthBasedTweaker;

Expand All @@ -21,6 +22,7 @@ namespace autofill {
@private
scoped_nsobject<AutofillAccountChooser> accountChooser_;
scoped_nsobject<GTMWidthBasedTweaker> buttonContainer_;
scoped_nsobject<AutofillDetailsContainer> detailsContainer_;
AutofillDialogWindowController* target_;
autofill::AutofillDialogController* controller_; // Not owned.
}
Expand Down
15 changes: 14 additions & 1 deletion chrome/browser/ui/cocoa/autofill/autofill_main_container.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
#import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
#include "grit/generated_resources.h"
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
Expand Down Expand Up @@ -45,9 +46,21 @@ - (void)loadView {
scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
[view setAutoresizesSubviews:YES];
[view setSubviews:@[accountChooser_, buttonContainer_]];
self.view = view;
[self setView:view];

[self layoutButtons];

detailsContainer_.reset(
[[AutofillDetailsContainer alloc] initWithController:controller_]);
NSSize frameSize = [[detailsContainer_ view] frame].size;
[[detailsContainer_ view] setFrameOrigin:
NSMakePoint(0, NSHeight([buttonContainer_ frame]))];
frameSize.height += NSHeight([accountChooser_ frame]);
frameSize.height += NSHeight([buttonContainer_ frame]);
[[detailsContainer_ view] setFrameOrigin:
NSMakePoint(0, NSHeight([buttonContainer_ frame]))];
[[self view] setFrameSize:frameSize];
[[self view] addSubview:[detailsContainer_ view]];
}

- (void)buildWindowButtonsForFrame:(NSRect)frame {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ virtual void SetUp() {

TEST_F(AutofillMainContainerTest, SubViews) {
bool hasAccountChooser = false;
bool hasButtons = false;

// Should have account chooser, button strip, and details section.
EXPECT_EQ(3U, [[[container_ view] subviews] count]);
for (NSView* view in [[container_ view] subviews]) {
if ([view isKindOfClass:[AutofillAccountChooser class]]) {
hasAccountChooser = true;
} else {
NSArray* subviews = [view subviews];
EXPECT_EQ(2U, [subviews count]);
EXPECT_TRUE([[subviews objectAtIndex:0] isKindOfClass:[NSButton class]]);
EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSButton class]]);
if ([subviews count] == 2) {
EXPECT_TRUE(
[[subviews objectAtIndex:0] isKindOfClass:[NSButton class]]);
EXPECT_TRUE(
[[subviews objectAtIndex:1] isKindOfClass:[NSButton class]]);
hasButtons = true;
}
}
}

EXPECT_TRUE(hasAccountChooser);
EXPECT_TRUE(hasAccountChooser && hasButtons);
}
30 changes: 30 additions & 0 deletions chrome/browser/ui/cocoa/autofill/autofill_section_container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

#ifndef CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_SECTION_CONTAINER_H_
#define CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_SECTION_CONTAINER_H_

#import <Cocoa/Cocoa.h>

#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"

namespace autofill {
class AutofillDialogController;
}

@interface AutofillSectionContainer : NSViewController {
@private
autofill::DialogSection section_;
autofill::AutofillDialogController* controller_; // Not owned.
}

@property(readonly, nonatomic) autofill::DialogSection section;

- (id)initWithController:(autofill::AutofillDialogController*)controller
forSection:(autofill::DialogSection)section;

@end

#endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_SECTION_CONTAINER_H_
Loading

0 comments on commit a1dae87

Please sign in to comment.