Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
| 9 #include "chrome/browser/ui/chrome_style.h" | 9 #include "chrome/browser/ui/chrome_style.h" |
| 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 11 #include "chrome/browser/ui/chrome_style.h" | 11 #include "chrome/browser/ui/chrome_style.h" |
| 12 #include "chrome/browser/ui/chrome_style.h" | 12 #include "chrome/browser/ui/chrome_style.h" |
| 13 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" | 13 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" |
| 14 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" | 14 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" |
| 15 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" | 15 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
| 16 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | 16 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
| 17 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" | 17 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" |
| 18 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" | 18 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h" |
| 19 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" | 19 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_wi ndow.h" |
| 20 #include "ui/base/cocoa/window_size_constants.h" | 20 #include "ui/base/cocoa/window_size_constants.h" |
| 21 | 21 |
| 22 namespace { | |
| 23 | |
| 24 const CGFloat kAccountChooserHeight = 20.0; | |
| 25 const CGFloat kRelatedControlVerticalSpacing = 8.0; | |
| 26 | |
| 27 } // namespace; | |
| 28 | |
| 22 namespace autofill { | 29 namespace autofill { |
| 23 | 30 |
| 24 // static | 31 // static |
| 25 AutofillDialogView* AutofillDialogView::Create( | 32 AutofillDialogView* AutofillDialogView::Create( |
| 26 AutofillDialogController* controller) { | 33 AutofillDialogController* controller) { |
| 27 return new AutofillDialogCocoa(controller); | 34 return new AutofillDialogCocoa(controller); |
| 28 } | 35 } |
| 29 | 36 |
| 30 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogController* controller) | 37 AutofillDialogCocoa::AutofillDialogCocoa(AutofillDialogController* controller) |
| 31 : controller_(controller) { | 38 : controller_(controller) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 [[AutofillSignInContainer alloc] | 143 [[AutofillSignInContainer alloc] |
| 137 initWithController:autofillDialog->controller()]); | 144 initWithController:autofillDialog->controller()]); |
| 138 [[signInContainer_ view] setHidden:YES]; | 145 [[signInContainer_ view] setHidden:YES]; |
| 139 | 146 |
| 140 NSRect clientRect = [[mainContainer_ view] frame]; | 147 NSRect clientRect = [[mainContainer_ view] frame]; |
| 141 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding, | 148 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding, |
| 142 chrome_style::kHorizontalPadding); | 149 chrome_style::kHorizontalPadding); |
| 143 [[mainContainer_ view] setFrame:clientRect]; | 150 [[mainContainer_ view] setFrame:clientRect]; |
| 144 [[signInContainer_ view] setFrame:clientRect]; | 151 [[signInContainer_ view] setFrame:clientRect]; |
| 145 | 152 |
| 146 const CGFloat kAccountChooserHeight = 20.0; | |
| 147 NSRect headerRect = clientRect; | 153 NSRect headerRect = clientRect; |
| 148 headerRect.size.height = kAccountChooserHeight; | 154 headerRect.size.height = kAccountChooserHeight; |
| 149 headerRect.origin.y = NSMaxY(clientRect); | 155 headerRect.origin.y = NSMaxY(clientRect); |
| 150 accountChooser_.reset([[AutofillAccountChooser alloc] | 156 accountChooser_.reset([[AutofillAccountChooser alloc] |
| 151 initWithFrame:headerRect | 157 initWithFrame:headerRect |
| 152 controller:autofillDialog->controller()]); | 158 controller:autofillDialog->controller()]); |
| 153 [[[self window] contentView] setSubviews: | 159 [[[self window] contentView] setSubviews: |
| 154 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]]; | 160 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]]; |
| 155 | 161 |
| 156 NSRect contentRect = clientRect; | 162 NSRect contentRect = clientRect; |
| 157 contentRect.origin = NSMakePoint(0, 0); | 163 contentRect.origin = NSMakePoint(0, 0); |
| 158 contentRect.size.width += 2 * chrome_style::kHorizontalPadding; | 164 contentRect.size.width += 2 * chrome_style::kHorizontalPadding; |
| 159 contentRect.size.height += NSHeight(headerRect) + | 165 contentRect.size.height += NSHeight(headerRect) + |
| 160 chrome_style::kClientBottomPadding + | 166 chrome_style::kClientBottomPadding + |
| 161 chrome_style::kTitleTopPadding; | 167 chrome_style::kTitleTopPadding; |
| 162 [[[self window] contentView] setFrame:contentRect]; | 168 [self performLayout]; |
| 163 NSRect frame = [[self window] frameRectForContentRect:contentRect]; | |
| 164 [[self window] setFrame:frame display:YES]; | |
| 165 | |
| 166 [accountChooser_ | |
| 167 setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; | |
| 168 } | 169 } |
| 169 return self; | 170 return self; |
| 170 } | 171 } |
| 171 | 172 |
| 173 - (void)requestRelayout { | |
| 174 [self performLayout]; | |
| 175 } | |
| 176 | |
| 177 - (NSSize)preferredSize { | |
| 178 NSSize contentSize; | |
| 179 if ([[signInContainer_ view] isHidden]) { | |
| 180 contentSize = [mainContainer_ preferredSize]; | |
| 181 } else { | |
| 182 // TODO(groby): Currently, keep size identical to main container. | |
| 183 // Change to allow autoresize of web contents. | |
| 184 contentSize = [mainContainer_ preferredSize]; | |
|
Robert Sesek
2013/05/24 20:49:23
These two if-branches are the same.
groby-ooo-7-16
2013/05/24 23:53:35
Done.
| |
| 185 } | |
| 186 | |
| 187 NSSize headerSize = NSMakeSize(contentSize.width, kAccountChooserHeight); | |
| 188 NSSize size = NSMakeSize( | |
| 189 std::max(contentSize.width, headerSize.width), | |
| 190 contentSize.height + headerSize.height + kRelatedControlVerticalSpacing); | |
| 191 size.width += 2 * chrome_style::kHorizontalPadding; | |
| 192 size.height += chrome_style::kClientBottomPadding + | |
| 193 chrome_style::kTitleTopPadding; | |
| 194 return size; | |
| 195 } | |
| 196 | |
| 197 - (void)performLayout { | |
| 198 // Don't animate when we first show the window. | |
| 199 BOOL shouldAnimate = | |
| 200 !NSEqualRects(ui::kWindowSizeDeterminedLater, [[self window] frame]); | |
|
Robert Sesek
2013/05/24 20:49:23
nit: continuation -> indent 4
groby-ooo-7-16
2013/05/24 23:53:35
Done.
| |
| 201 | |
| 202 NSRect contentRect = NSZeroRect; | |
| 203 contentRect.size = [self preferredSize]; | |
| 204 NSRect clientRect = NSInsetRect( | |
| 205 contentRect, chrome_style::kHorizontalPadding, 0); | |
| 206 clientRect.origin.y += chrome_style::kClientBottomPadding; | |
| 207 clientRect.size.height -= chrome_style::kTitleTopPadding + | |
| 208 chrome_style::kClientBottomPadding; | |
| 209 | |
| 210 NSRect headerRect, mainRect; | |
| 211 NSDivideRect(clientRect, &headerRect, &mainRect, | |
| 212 kAccountChooserHeight, NSMaxYEdge); | |
| 213 | |
| 214 [accountChooser_ setFrame:headerRect]; | |
| 215 if ([[signInContainer_ view] isHidden]) { | |
| 216 [[mainContainer_ view] setFrame:mainRect]; | |
| 217 [mainContainer_ performLayout]; | |
| 218 } else { | |
| 219 [[signInContainer_ view] setFrame:mainRect]; | |
| 220 } | |
| 221 | |
| 222 NSRect frameRect = [[self window] frameRectForContentRect:contentRect]; | |
| 223 [[self window] setFrame:frameRect display:YES animate:shouldAnimate]; | |
| 224 } | |
| 225 | |
| 172 - (IBAction)accept:(id)sender { | 226 - (IBAction)accept:(id)sender { |
| 173 // TODO(groby): Validation goes here. | 227 // TODO(groby): Validation goes here. |
| 174 autofillDialog_->controller()->OnAccept(); | 228 autofillDialog_->controller()->OnAccept(); |
| 175 } | 229 } |
| 176 | 230 |
| 177 - (IBAction)cancel:(id)sender { | 231 - (IBAction)cancel:(id)sender { |
| 178 // TODO(groby): Validation goes here. | 232 // TODO(groby): Validation goes here. |
| 179 autofillDialog_->controller()->OnCancel(); | 233 autofillDialog_->controller()->OnCancel(); |
| 180 autofillDialog_->Hide(); | 234 autofillDialog_->Hide(); |
| 181 } | 235 } |
| 182 | 236 |
| 183 - (void)updateAccountChooser { | 237 - (void)updateAccountChooser { |
| 184 [accountChooser_ update]; | 238 [accountChooser_ update]; |
| 185 } | 239 } |
| 186 | 240 |
| 187 - (content::NavigationController*)showSignIn { | 241 - (content::NavigationController*)showSignIn { |
| 188 [signInContainer_ loadSignInPage]; | 242 [signInContainer_ loadSignInPage]; |
| 189 [[mainContainer_ view] setHidden:YES]; | 243 [[mainContainer_ view] setHidden:YES]; |
| 190 [[signInContainer_ view] setHidden:NO]; | 244 [[signInContainer_ view] setHidden:NO]; |
| 245 [self performLayout]; | |
| 191 | 246 |
| 192 return [signInContainer_ navigationController]; | 247 return [signInContainer_ navigationController]; |
| 193 } | 248 } |
| 194 | 249 |
| 195 - (void)getInputs:(autofill::DetailOutputMap*)output | 250 - (void)getInputs:(autofill::DetailOutputMap*)output |
| 196 forSection:(autofill::DialogSection)section { | 251 forSection:(autofill::DialogSection)section { |
| 197 [[mainContainer_ sectionForId:section] getInputs:output]; | 252 [[mainContainer_ sectionForId:section] getInputs:output]; |
| 198 } | 253 } |
| 199 | 254 |
| 200 - (void)hideSignIn { | 255 - (void)hideSignIn { |
| 201 [[signInContainer_ view] setHidden:YES]; | 256 [[signInContainer_ view] setHidden:YES]; |
| 202 [[mainContainer_ view] setHidden:NO]; | 257 [[mainContainer_ view] setHidden:NO]; |
| 258 [self performLayout]; | |
| 203 } | 259 } |
| 204 | 260 |
| 205 - (void)modelChanged { | 261 - (void)modelChanged { |
| 206 [mainContainer_ modelChanged]; | 262 [mainContainer_ modelChanged]; |
| 207 } | 263 } |
| 208 | 264 |
| 209 @end | 265 @end |
| OLD | NEW |