Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_overlay_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate { | 129 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate { |
| 130 if (self = [super initWithNibName:nil bundle:nil]) { | 130 if (self = [super initWithNibName:nil bundle:nil]) { |
| 131 delegate_ = delegate; | 131 delegate_ = delegate; |
| 132 | 132 |
| 133 base::scoped_nsobject<NSBox> view([[NSBox alloc] initWithFrame:NSZeroRect]); | 133 base::scoped_nsobject<NSBox> view([[NSBox alloc] initWithFrame:NSZeroRect]); |
| 134 [view setBoxType:NSBoxCustom]; | 134 [view setBoxType:NSBoxCustom]; |
| 135 [view setBorderType:NSNoBorder]; | 135 [view setBorderType:NSNoBorder]; |
| 136 [view setContentViewMargins:NSZeroSize]; | 136 [view setContentViewMargins:NSZeroSize]; |
| 137 [view setTitlePosition:NSNoTitle]; | 137 [view setTitlePosition:NSNoTitle]; |
| 138 | 138 |
| 139 childView_.reset([[NSView alloc] initWithFrame:NSZeroRect]); | |
| 140 messageView_.reset([[AutofillMessageView alloc] initWithFrame:NSZeroRect]); | 139 messageView_.reset([[AutofillMessageView alloc] initWithFrame:NSZeroRect]); |
| 141 imageView_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); | 140 imageView_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); |
| 142 [imageView_ setImageAlignment:NSImageAlignCenter]; | 141 [imageView_ setImageAlignment:NSImageAlignCenter]; |
| 143 | 142 |
| 144 [childView_ setSubviews:@[messageView_, imageView_]]; | 143 [view setSubviews:@[messageView_, imageView_]]; |
| 145 [view addSubview:childView_]; | |
| 146 [self setView:view]; | 144 [self setView:view]; |
| 145 | |
| 146 [view setFillColor:[[view window] backgroundColor]]; | |
|
groby-ooo-7-16
2013/11/22 14:24:03
This could also go if we just change contentView..
| |
| 147 } | 147 } |
| 148 return self; | 148 return self; |
| 149 } | 149 } |
| 150 | 150 |
| 151 - (void)updateState { | 151 - (void)updateState { |
| 152 const autofill::DialogOverlayState& state = delegate_->GetDialogOverlay(); | 152 const autofill::DialogOverlayState& state = delegate_->GetDialogOverlay(); |
| 153 | 153 |
| 154 if (state.image.IsEmpty()) { | 154 if (state.image.IsEmpty()) { |
| 155 [[self view] setHidden:YES]; | 155 [[self view] setHidden:YES]; |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 | 158 |
| 159 NSBox* view = base::mac::ObjCCastStrict<NSBox>([self view]); | 159 [[self view] setHidden:NO]; |
| 160 [view setFillColor:[[view window] backgroundColor]]; | |
| 161 [view setAlphaValue:1]; | |
| 162 [childView_ setAlphaValue:1]; | |
| 163 [imageView_ setImage:state.image.ToNSImage()]; | 160 [imageView_ setImage:state.image.ToNSImage()]; |
| 164 [messageView_ setMessage:state.string]; | 161 [messageView_ setMessage:state.string]; |
| 165 [childView_ setHidden:NO]; | |
| 166 [view setHidden:NO]; | |
| 167 | 162 |
| 168 NSWindowController* delegate = [[[self view] window] windowController]; | 163 NSWindowController* delegate = [[[self view] window] windowController]; |
| 169 if ([delegate respondsToSelector:@selector(requestRelayout)]) | 164 if ([delegate respondsToSelector:@selector(requestRelayout)]) |
| 170 [delegate performSelector:@selector(requestRelayout)]; | 165 [delegate performSelector:@selector(requestRelayout)]; |
| 171 } | 166 } |
| 172 | 167 |
| 173 - (CGFloat)heightForWidth:(int) width { | 168 - (CGFloat)heightForWidth:(int)width { |
| 174 // 0 means "no preference". Image-only overlays fit the container. | |
| 175 if ([messageView_ isHidden]) | |
| 176 return 0; | |
| 177 | |
| 178 // Overlays with text messages express a size preference. | |
| 179 return 2 * kOverlayImageVerticalPadding + | 169 return 2 * kOverlayImageVerticalPadding + |
| 180 [messageView_ heightForWidth:width] + | 170 [messageView_ heightForWidth:width] + |
| 181 [[imageView_ image] size].height; | 171 [[imageView_ image] size].height; |
| 182 } | 172 } |
| 183 | 173 |
| 184 - (NSSize)preferredSize { | 174 - (NSSize)preferredSize { |
| 185 NOTREACHED(); // Only implemented as part of AutofillLayout protocol. | 175 NOTREACHED(); // Only implemented as part of AutofillLayout protocol. |
| 186 return NSZeroSize; | 176 return NSZeroSize; |
| 187 } | 177 } |
| 188 | 178 |
| 189 - (void)performLayout { | 179 - (void)performLayout { |
| 190 NSRect bounds = [[self view] bounds]; | 180 NSRect bounds = [[self view] bounds]; |
| 191 [childView_ setFrame:bounds]; | |
| 192 if ([messageView_ isHidden]) { | |
| 193 [imageView_ setFrame:bounds]; | |
| 194 return; | |
| 195 } | |
| 196 | 181 |
| 197 int messageHeight = [messageView_ heightForWidth:NSWidth(bounds)]; | 182 int messageHeight = [messageView_ heightForWidth:NSWidth(bounds)]; |
| 198 [messageView_ setFrame:NSMakeRect(0, 0, NSWidth(bounds), messageHeight)]; | 183 [messageView_ setFrame:NSMakeRect(0, 0, NSWidth(bounds), messageHeight)]; |
| 199 [messageView_ performLayout]; | 184 [messageView_ performLayout]; |
| 200 | 185 |
| 201 NSSize imageSize = [[imageView_ image] size]; | 186 NSSize imageSize = [[imageView_ image] size]; |
| 202 [imageView_ setFrame:NSMakeRect( | 187 [imageView_ setFrame:NSMakeRect( |
| 203 0, NSMaxY([messageView_ frame]) + kOverlayImageVerticalPadding, | 188 0, NSMaxY([messageView_ frame]) + kOverlayImageVerticalPadding, |
| 204 NSWidth(bounds), imageSize.height)]; | 189 NSWidth(bounds), imageSize.height)]; |
| 205 } | 190 } |
| 206 | 191 |
| 207 @end | 192 @end |
| OLD | NEW |