Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.mm

Issue 15645004: [rAC] Allow sub-views to trigger layout reflow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review issues. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // TODO(groby): Currently, keep size identical to main container.
180 // Change to allow autoresize of web contents.
181 contentSize = [mainContainer_ preferredSize];
182
183 NSSize headerSize = NSMakeSize(contentSize.width, kAccountChooserHeight);
184 NSSize size = NSMakeSize(
185 std::max(contentSize.width, headerSize.width),
186 contentSize.height + headerSize.height + kRelatedControlVerticalSpacing);
187 size.width += 2 * chrome_style::kHorizontalPadding;
188 size.height += chrome_style::kClientBottomPadding +
189 chrome_style::kTitleTopPadding;
190 return size;
191 }
192
193 - (void)performLayout {
194 // Don't animate when we first show the window.
195 BOOL shouldAnimate =
196 !NSEqualRects(ui::kWindowSizeDeterminedLater, [[self window] frame]);
197
198 NSRect contentRect = NSZeroRect;
199 contentRect.size = [self preferredSize];
200 NSRect clientRect = NSInsetRect(
201 contentRect, chrome_style::kHorizontalPadding, 0);
202 clientRect.origin.y += chrome_style::kClientBottomPadding;
203 clientRect.size.height -= chrome_style::kTitleTopPadding +
204 chrome_style::kClientBottomPadding;
205
206 NSRect headerRect, mainRect;
207 NSDivideRect(clientRect, &headerRect, &mainRect,
208 kAccountChooserHeight, NSMaxYEdge);
209
210 [accountChooser_ setFrame:headerRect];
211 if ([[signInContainer_ view] isHidden]) {
212 [[mainContainer_ view] setFrame:mainRect];
213 [mainContainer_ performLayout];
214 } else {
215 [[signInContainer_ view] setFrame:mainRect];
216 }
217
218 NSRect frameRect = [[self window] frameRectForContentRect:contentRect];
219 [[self window] setFrame:frameRect display:YES animate:shouldAnimate];
220 }
221
172 - (IBAction)accept:(id)sender { 222 - (IBAction)accept:(id)sender {
173 // TODO(groby): Validation goes here. 223 // TODO(groby): Validation goes here.
174 autofillDialog_->controller()->OnAccept(); 224 autofillDialog_->controller()->OnAccept();
175 } 225 }
176 226
177 - (IBAction)cancel:(id)sender { 227 - (IBAction)cancel:(id)sender {
178 // TODO(groby): Validation goes here. 228 // TODO(groby): Validation goes here.
179 autofillDialog_->controller()->OnCancel(); 229 autofillDialog_->controller()->OnCancel();
180 autofillDialog_->Hide(); 230 autofillDialog_->Hide();
181 } 231 }
182 232
183 - (void)updateAccountChooser { 233 - (void)updateAccountChooser {
184 [accountChooser_ update]; 234 [accountChooser_ update];
185 } 235 }
186 236
187 - (content::NavigationController*)showSignIn { 237 - (content::NavigationController*)showSignIn {
188 [signInContainer_ loadSignInPage]; 238 [signInContainer_ loadSignInPage];
189 [[mainContainer_ view] setHidden:YES]; 239 [[mainContainer_ view] setHidden:YES];
190 [[signInContainer_ view] setHidden:NO]; 240 [[signInContainer_ view] setHidden:NO];
241 [self performLayout];
191 242
192 return [signInContainer_ navigationController]; 243 return [signInContainer_ navigationController];
193 } 244 }
194 245
195 - (void)getInputs:(autofill::DetailOutputMap*)output 246 - (void)getInputs:(autofill::DetailOutputMap*)output
196 forSection:(autofill::DialogSection)section { 247 forSection:(autofill::DialogSection)section {
197 [[mainContainer_ sectionForId:section] getInputs:output]; 248 [[mainContainer_ sectionForId:section] getInputs:output];
198 } 249 }
199 250
200 - (void)hideSignIn { 251 - (void)hideSignIn {
201 [[signInContainer_ view] setHidden:YES]; 252 [[signInContainer_ view] setHidden:YES];
202 [[mainContainer_ view] setHidden:NO]; 253 [[mainContainer_ view] setHidden:NO];
254 [self performLayout];
203 } 255 }
204 256
205 - (void)modelChanged { 257 - (void)modelChanged {
206 [mainContainer_ modelChanged]; 258 [mainContainer_ modelChanged];
207 } 259 }
208 260
209 @end 261 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h ('k') | chrome/browser/ui/cocoa/autofill/autofill_layout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698