Commit 540f2134 authored by isherman@chromium.org's avatar isherman@chromium.org

[rAc OSX] Factor out AutofillHeader class to contain dialog header elements.

Currently contains the title and the account chooser.  In the next CL, I'm
planning to move notifications into the header as well.

BUG=315977
TEST=none
R=groby@chromium.org

Review URL: https://codereview.chromium.org/77283002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236997 0039d316-1c4b-4281-b951-d872f2087c98
parent c3156488
......@@ -11,24 +11,18 @@
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
#include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_layout.h"
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
#include "ui/gfx/size.h"
namespace content {
class NavigationController;
class NavigationController;
}
namespace autofill {
class AutofillDialogViewDelegate;
class AutofillDialogViewDelegate;
}
@class AutofillAccountChooser;
@class AutofillDialogWindowController;
@class AutofillLoadingShieldController;
@class AutofillMainContainer;
@class AutofillOverlayController;
@class AutofillSignInContainer;
namespace autofill {
......
......@@ -37,7 +37,7 @@ void AutofillDialogCocoa::Show() {
DCHECK(!sheet_delegate_.get());
sheet_delegate_.reset([[AutofillDialogWindowController alloc]
initWithWebContents:delegate_->GetWebContents()
autofillDialog:this]);
dialog:this]);
base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
[[CustomConstrainedWindowSheet alloc]
initWithCustomWindow:[sheet_delegate_ window]]);
......
......@@ -11,8 +11,8 @@
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_layout.h"
@class AutofillAccountChooser;
@class AutofillDialogWindowController;
@class AutofillHeader;
@class AutofillLoadingShieldController;
@class AutofillMainContainer;
@class AutofillOverlayController;
......@@ -57,22 +57,20 @@ class AutofillDialogCocoa;
NSWindowController<NSWindowDelegate, AutofillLayout, AutofillDialogBridge> {
@private
content::WebContents* webContents_; // weak.
autofill::AutofillDialogCocoa* autofillDialog_; // weak.
autofill::AutofillDialogCocoa* dialog_; // weak.
base::scoped_nsobject<AutofillHeader> header_;
base::scoped_nsobject<AutofillMainContainer> mainContainer_;
base::scoped_nsobject<AutofillSignInContainer> signInContainer_;
base::scoped_nsobject<AutofillAccountChooser> accountChooser_;
base::scoped_nsobject<AutofillOverlayController> overlayController_;
base::scoped_nsobject<AutofillLoadingShieldController>
loadingShieldController_;
base::scoped_nsobject<NSTextField> loadingShieldTextField_;
base::scoped_nsobject<NSTextField> titleTextField_;
base::scoped_nsobject<NSTextView> fieldEditor_;
}
// Designated initializer. The WebContents cannot be NULL.
- (id)initWithWebContents:(content::WebContents*)webContents
autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog;
dialog:(autofill::AutofillDialogCocoa*)dialog;
// Requests a re-layout for the entire dialog. The layout will be postponed
// until the next cycle of the runloop.
......
......@@ -9,9 +9,9 @@
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
#include "chrome/browser/ui/chrome_style.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_header.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_input_field.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_loading_shield_controller.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
......@@ -28,14 +28,9 @@
#include "ui/base/l10n/l10n_util.h"
namespace {
const CGFloat kAccountChooserHeight = 20.0;
const CGFloat kMinimumContentsHeight = 101;
// Height of all decorations & paddings on main dialog together.
const CGFloat kDecorationHeight = kAccountChooserHeight +
autofill::kDetailVerticalPadding +
chrome_style::kClientBottomPadding +
chrome_style::kTitleTopPadding;
} // namespace
#pragma mark Field Editor
......@@ -107,7 +102,7 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
@implementation AutofillDialogWindowController
- (id)initWithWebContents:(content::WebContents*)webContents
autofillDialog:(autofill::AutofillDialogCocoa*)autofillDialog {
dialog:(autofill::AutofillDialogCocoa*)dialog {
DCHECK(webContents);
base::scoped_nsobject<ConstrainedWindowCustomWindow> window(
......@@ -117,38 +112,26 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
if ((self = [super initWithWindow:window])) {
[window setDelegate:self];
webContents_ = webContents;
autofillDialog_ = autofillDialog;
dialog_ = dialog;
header_.reset([[AutofillHeader alloc] initWithDelegate:dialog->delegate()]);
mainContainer_.reset([[AutofillMainContainer alloc]
initWithDelegate:autofillDialog->delegate()]);
initWithDelegate:dialog->delegate()]);
[mainContainer_ setTarget:self];
signInContainer_.reset(
[[AutofillSignInContainer alloc] initWithDialog:autofillDialog]);
[[AutofillSignInContainer alloc] initWithDialog:dialog]);
[[signInContainer_ view] setHidden:YES];
// Set dialog title.
titleTextField_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
[titleTextField_ setEditable:NO];
[titleTextField_ setBordered:NO];
[titleTextField_ setDrawsBackground:NO];
[titleTextField_ setFont:[NSFont systemFontOfSize:15.0]];
[titleTextField_ setStringValue:
base::SysUTF16ToNSString(autofillDialog->delegate()->DialogTitle())];
[titleTextField_ sizeToFit];
accountChooser_.reset([[AutofillAccountChooser alloc]
initWithFrame:NSZeroRect
delegate:autofillDialog->delegate()]);
loadingShieldController_.reset(
[[AutofillLoadingShieldController alloc]
initWithDelegate:autofillDialog->delegate()]);
[[AutofillLoadingShieldController alloc] initWithDelegate:
dialog->delegate()]);
[[loadingShieldController_ view] setHidden:YES];
overlayController_.reset(
[[AutofillOverlayController alloc] initWithDelegate:
autofillDialog->delegate()]);
dialog->delegate()]);
[[overlayController_ view] setHidden:YES];
// This needs a flipped content view because otherwise the size
......@@ -158,8 +141,7 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
[[FlippedView alloc] initWithFrame:
[[[self window] contentView] frame]]);
[flippedContentView setSubviews:
@[accountChooser_,
titleTextField_,
@[[header_ view],
[mainContainer_ view],
[signInContainer_ view],
[loadingShieldController_ view],
......@@ -167,7 +149,7 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
[flippedContentView setAutoresizingMask:
(NSViewWidthSizable | NSViewHeightSizable)];
[[[self window] contentView] addSubview:flippedContentView];
[mainContainer_ setAnchorView:[[accountChooser_ subviews] objectAtIndex:1]];
[mainContainer_ setAnchorView:[header_ anchorView]];
}
return self;
}
......@@ -189,8 +171,10 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
- (void)updateSignInSizeConstraints {
// Adjust for the size of all decorations and paddings outside main content.
CGFloat minHeight = kMinimumContentsHeight - kDecorationHeight;
CGFloat maxHeight = std::max([self maxHeight] - kDecorationHeight, minHeight);
CGFloat decorationHeight =
[[header_ view] frame].size.height + chrome_style::kClientBottomPadding;
CGFloat minHeight = kMinimumContentsHeight - decorationHeight;
CGFloat maxHeight = std::max([self maxHeight] - decorationHeight, minHeight);
CGFloat width = NSWidth([[[self window] contentView] frame]);
[signInContainer_ constrainSizeToMinimum:NSMakeSize(width, minHeight)
......@@ -226,8 +210,10 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
else
size = [signInContainer_ preferredSize];
// Always make room for the header.
size.height += kDecorationHeight;
// Always make room for the header and bottom padding.
size.height +=
[header_ heightForWidth:size.width] +
chrome_style::kClientBottomPadding;
}
// Show as much of the main view as is possible without going past the
......@@ -241,33 +227,15 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
NSRect contentRect = NSZeroRect;
contentRect.size = [self preferredSize];
NSRect clientRect = contentRect;
clientRect.origin.y = chrome_style::kTitleTopPadding;
clientRect.size.height -= chrome_style::kTitleTopPadding +
chrome_style::kClientBottomPadding;
[titleTextField_ setStringValue:
base::SysUTF16ToNSString(autofillDialog_->delegate()->DialogTitle())];
[titleTextField_ sizeToFit];
NSRect headerRect, mainRect, titleRect, dummyRect;
NSDivideRect(clientRect, &headerRect, &mainRect,
kAccountChooserHeight, NSMinYEdge);
NSDivideRect(mainRect, &dummyRect, &mainRect,
autofill::kDetailVerticalPadding, NSMinYEdge);
headerRect = NSInsetRect(headerRect, chrome_style::kHorizontalPadding, 0);
NSDivideRect(headerRect, &titleRect, &headerRect,
NSWidth([titleTextField_ frame]), NSMinXEdge);
// Align baseline of title with bottom of accountChooser.
base::scoped_nsobject<NSLayoutManager> layout_manager(
[[NSLayoutManager alloc] init]);
NSFont* titleFont = [titleTextField_ font];
titleRect.origin.y += NSHeight(titleRect) -
[layout_manager defaultBaselineOffsetForFont:titleFont];
[titleTextField_ setFrame:titleRect];
[accountChooser_ setFrame:headerRect];
[accountChooser_ performLayout];
clientRect.size.height -= chrome_style::kClientBottomPadding;
CGFloat headerHeight = [header_ heightForWidth:NSWidth(clientRect)];
NSRect headerRect, mainRect;
NSDivideRect(clientRect, &headerRect, &mainRect, headerHeight, NSMinYEdge);
[[header_ view] setFrame:headerRect];
[header_ performLayout];
if ([[signInContainer_ view] isHidden]) {
[[mainContainer_ view] setFrame:mainRect];
[mainContainer_ performLayout];
......@@ -288,14 +256,14 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
- (IBAction)accept:(id)sender {
if ([mainContainer_ validate])
autofillDialog_->delegate()->OnAccept();
dialog_->delegate()->OnAccept();
else
[mainContainer_ makeFirstInvalidInputFirstResponder];
}
- (IBAction)cancel:(id)sender {
autofillDialog_->delegate()->OnCancel();
autofillDialog_->PerformClose();
dialog_->delegate()->OnCancel();
dialog_->PerformClose();
}
- (void)show {
......@@ -316,8 +284,8 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
}
- (void)hide {
autofillDialog_->delegate()->OnCancel();
autofillDialog_->PerformClose();
dialog_->delegate()->OnCancel();
dialog_->PerformClose();
}
- (void)updateNotificationArea {
......@@ -325,7 +293,7 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
}
- (void)updateAccountChooser {
[accountChooser_ update];
[header_ update];
[mainContainer_ updateLegalDocuments];
// For the duration of the loading shield, hide the main contents.
......@@ -342,7 +310,7 @@ const CGFloat kDecorationHeight = kAccountChooserHeight +
// to remember previous state, because the overlay view is always the last
// state of the dialog.
[overlayController_ updateState];
[accountChooser_ setHidden:![[overlayController_ view] isHidden]];
[[header_ view] setHidden:![[overlayController_ view] isHidden]];
[[mainContainer_ view] setHidden:![[overlayController_ view] isHidden]];
}
......
// Copyright 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_HEADER_H_
#define CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_HEADER_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_layout.h"
namespace autofill {
class AutofillDialogViewDelegate;
} // autofill
@class AutofillAccountChooser;
@interface AutofillHeader : NSViewController<AutofillLayout> {
@private
base::scoped_nsobject<AutofillAccountChooser> accountChooser_;
base::scoped_nsobject<NSTextField> title_;
// TODO(isherman): Include notifications in the header.
autofill::AutofillDialogViewDelegate* delegate_; // not owned, owns dialog.
}
// Designated initializer.
- (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate;
// Returns the anchor view for notifications, which is the middle of the account
// chooser view.
- (NSView*)anchorView;
// Updates the header's state from the dialog controller.
- (void)update;
// Get the preferred view height for a given width.
- (CGFloat)heightForWidth:(int)width;
@end
#endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_DIALOG_HEADER_H_
// Copyright 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_header.h"
#import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
#include "chrome/browser/ui/chrome_style.h"
#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
namespace {
// Height of the account chooser.
const CGFloat kAccountChooserHeight = 20.0;
} // namespace
@implementation AutofillHeader
- (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
if (self = [super initWithNibName:nil bundle:nil]) {
delegate_ = delegate;
accountChooser_.reset(
[[AutofillAccountChooser alloc] initWithFrame:NSZeroRect
delegate:delegate]);
// Set dialog title.
title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
[title_ setEditable:NO];
[title_ setBordered:NO];
[title_ setDrawsBackground:NO];
[title_ setFont:[NSFont systemFontOfSize:15.0]];
[title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())];
[title_ sizeToFit];
base::scoped_nsobject<NSView> view(
[[NSView alloc] initWithFrame:NSZeroRect]);
[view setSubviews:@[accountChooser_, title_]];
[self setView:view];
}
return self;
}
- (NSView*)anchorView {
return [[accountChooser_ subviews] objectAtIndex:1];
}
- (void)update {
[accountChooser_ update];
[title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())];
[title_ sizeToFit];
}
- (CGFloat)heightForWidth:(int)width {
return chrome_style::kTitleTopPadding +
kAccountChooserHeight +
autofill::kDetailVerticalPadding;
}
- (NSSize)preferredSize {
NOTREACHED(); // Only implemented as part of AutofillLayout protocol.
return NSZeroSize;
}
- (void)performLayout {
NSRect bounds = [[self view] bounds];
[title_ setFrameOrigin:NSMakePoint(chrome_style::kHorizontalPadding,
autofill::kDetailVerticalPadding)];
CGFloat accountChooserLeftX =
NSMaxX([title_ frame]) + chrome_style::kHorizontalPadding;
CGFloat accountChooserWidth =
NSMaxX(bounds) - chrome_style::kHorizontalPadding - accountChooserLeftX;
NSRect accountChooserFrame =
NSMakeRect(accountChooserLeftX, autofill::kDetailVerticalPadding,
accountChooserWidth, kAccountChooserHeight);
[accountChooser_ setFrame:accountChooserFrame];
[accountChooser_ performLayout];
}
@end
......@@ -523,15 +523,17 @@
'browser/ui/cocoa/autofill/autofill_bubble_controller.mm',
'browser/ui/cocoa/autofill/autofill_dialog_window_controller.h',
'browser/ui/cocoa/autofill/autofill_dialog_window_controller.mm',
'browser/ui/cocoa/autofill/autofill_header.h',
'browser/ui/cocoa/autofill/autofill_header.mm',
'browser/ui/cocoa/autofill/autofill_layout.h',
'browser/ui/cocoa/autofill/autofill_notification_container.h',
'browser/ui/cocoa/autofill/autofill_notification_container.mm',
'browser/ui/cocoa/autofill/autofill_notification_controller.h',
'browser/ui/cocoa/autofill/autofill_notification_controller.mm',
'browser/ui/cocoa/autofill/autofill_loading_shield_controller.h',
'browser/ui/cocoa/autofill/autofill_loading_shield_controller.mm',
'browser/ui/cocoa/autofill/autofill_main_container.h',
'browser/ui/cocoa/autofill/autofill_main_container.mm',
'browser/ui/cocoa/autofill/autofill_notification_container.h',
'browser/ui/cocoa/autofill/autofill_notification_container.mm',
'browser/ui/cocoa/autofill/autofill_notification_controller.h',
'browser/ui/cocoa/autofill/autofill_notification_controller.mm',
'browser/ui/cocoa/autofill/autofill_overlay_controller.h',
'browser/ui/cocoa/autofill/autofill_overlay_controller.mm',
'browser/ui/cocoa/autofill/autofill_popup_view_bridge.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment