Skip to content

Commit

Permalink
[rAc OSX] Simplify the overlay controller.
Browse files Browse the repository at this point in the history
* Remove code handling the case where the overlay doesn't include any text.
* Remove remnants of code handling opacity transitions.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236916 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
isherman@chromium.org committed Nov 23, 2013
1 parent 6d9e62c commit a7e3691
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,17 @@ - (void)requestRelayout {
- (NSSize)preferredSize {
NSSize size;

// Overall size is determined by either main container or sign in view.
if ([[signInContainer_ view] isHidden])
size = [mainContainer_ preferredSize];
else
size = [signInContainer_ preferredSize];

// Always make room for the header.
size.height += kDecorationHeight;

if (![[overlayController_ view] isHidden]) {
CGFloat height = [overlayController_ heightForWidth:size.width];
if (height != 0.0)
size.height = height;
size.height = [overlayController_ heightForWidth:size.width];
} else {
// Overall size is determined by either main container or sign in view.
if ([[signInContainer_ view] isHidden])
size = [mainContainer_ preferredSize];
else
size = [signInContainer_ preferredSize];

// Always make room for the header.
size.height += kDecorationHeight;
}

// Show as much of the main view as is possible without going past the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ struct DialogOverlayState;

@interface AutofillOverlayController : NSViewController<AutofillLayout> {
@private
// |childView_| contains all overlay UI elements. This is used to fade out
// UI elements first, before making the main view transparent to fade out the
// overlay shield.
base::scoped_nsobject<NSView> childView_;
base::scoped_nsobject<NSImageView> imageView_;
base::scoped_nsobject<AutofillMessageView> messageView_;

Expand All @@ -42,4 +38,3 @@ struct DialogOverlayState;
@end

#endif // CHROME_BROWSER_UI_COCOA_AUTOFILL_AUTOFILL_OVERLAY_CONTROLLER_H_

25 changes: 5 additions & 20 deletions chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
[view setContentViewMargins:NSZeroSize];
[view setTitlePosition:NSNoTitle];

childView_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
messageView_.reset([[AutofillMessageView alloc] initWithFrame:NSZeroRect]);
imageView_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]);
[imageView_ setImageAlignment:NSImageAlignCenter];

[childView_ setSubviews:@[messageView_, imageView_]];
[view addSubview:childView_];
[view setSubviews:@[messageView_, imageView_]];
[self setView:view];

[view setFillColor:[[view window] backgroundColor]];
}
return self;
}
Expand All @@ -156,26 +156,16 @@ - (void)updateState {
return;
}

NSBox* view = base::mac::ObjCCastStrict<NSBox>([self view]);
[view setFillColor:[[view window] backgroundColor]];
[view setAlphaValue:1];
[childView_ setAlphaValue:1];
[[self view] setHidden:NO];
[imageView_ setImage:state.image.ToNSImage()];
[messageView_ setMessage:state.string];
[childView_ setHidden:NO];
[view setHidden:NO];

NSWindowController* delegate = [[[self view] window] windowController];
if ([delegate respondsToSelector:@selector(requestRelayout)])
[delegate performSelector:@selector(requestRelayout)];
}

- (CGFloat)heightForWidth:(int) width {
// 0 means "no preference". Image-only overlays fit the container.
if ([messageView_ isHidden])
return 0;

// Overlays with text messages express a size preference.
- (CGFloat)heightForWidth:(int)width {
return 2 * kOverlayImageVerticalPadding +
[messageView_ heightForWidth:width] +
[[imageView_ image] size].height;
Expand All @@ -188,11 +178,6 @@ - (NSSize)preferredSize {

- (void)performLayout {
NSRect bounds = [[self view] bounds];
[childView_ setFrame:bounds];
if ([messageView_ isHidden]) {
[imageView_ setFrame:bounds];
return;
}

int messageHeight = [messageView_ heightForWidth:NSWidth(bounds)];
[messageView_ setFrame:NSMakeRect(0, 0, NSWidth(bounds), messageHeight)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ virtual void SetUp() {

TEST_F(AutofillOverlayControllerTest, Subviews) {
NSView* view = [controller_ view];
ASSERT_EQ(1U, [[view subviews] count]);

EXPECT_TRUE([view isKindOfClass:[NSBox class]]);
EXPECT_TRUE([[[view subviews] objectAtIndex:0] isMemberOfClass:
[NSView class]]);

ASSERT_EQ(2U, [[view subviews] count]);
EXPECT_TRUE(
[[[view subviews] objectAtIndex:0] isKindOfClass:[NSView class]]);
EXPECT_TRUE(
[[[view subviews] objectAtIndex:0] conformsToProtocol:
@protocol(AutofillLayout)]);
EXPECT_TRUE(
[[[view subviews] objectAtIndex:1] isMemberOfClass:[NSImageView class]]);
}

0 comments on commit a7e3691

Please sign in to comment.