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

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: Now using proper patch base. 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 [[AutofillSignInContainer alloc] 139 [[AutofillSignInContainer alloc]
133 initWithController:autofillDialog->controller()]); 140 initWithController:autofillDialog->controller()]);
134 [[signInContainer_ view] setHidden:YES]; 141 [[signInContainer_ view] setHidden:YES];
135 142
136 NSRect clientRect = [[mainContainer_ view] frame]; 143 NSRect clientRect = [[mainContainer_ view] frame];
137 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding, 144 clientRect.origin = NSMakePoint(chrome_style::kClientBottomPadding,
138 chrome_style::kHorizontalPadding); 145 chrome_style::kHorizontalPadding);
139 [[mainContainer_ view] setFrame:clientRect]; 146 [[mainContainer_ view] setFrame:clientRect];
140 [[signInContainer_ view] setFrame:clientRect]; 147 [[signInContainer_ view] setFrame:clientRect];
141 148
142 const CGFloat kAccountChooserHeight = 20.0;
143 NSRect headerRect = clientRect; 149 NSRect headerRect = clientRect;
144 headerRect.size.height = kAccountChooserHeight; 150 headerRect.size.height = kAccountChooserHeight;
145 headerRect.origin.y = NSMaxY(clientRect); 151 headerRect.origin.y = NSMaxY(clientRect);
146 accountChooser_.reset([[AutofillAccountChooser alloc] 152 accountChooser_.reset([[AutofillAccountChooser alloc]
147 initWithFrame:headerRect 153 initWithFrame:headerRect
148 controller:autofillDialog->controller()]); 154 controller:autofillDialog->controller()]);
149 [[[self window] contentView] setSubviews: 155 [[[self window] contentView] setSubviews:
150 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]]; 156 @[accountChooser_, [mainContainer_ view], [signInContainer_ view]]];
151 157
152 NSRect contentRect = clientRect; 158 NSRect contentRect = clientRect;
153 contentRect.origin = NSMakePoint(0, 0); 159 contentRect.origin = NSMakePoint(0, 0);
154 contentRect.size.width += 2 * chrome_style::kHorizontalPadding; 160 contentRect.size.width += 2 * chrome_style::kHorizontalPadding;
155 contentRect.size.height += NSHeight(headerRect) + 161 contentRect.size.height += NSHeight(headerRect) +
156 chrome_style::kClientBottomPadding + 162 chrome_style::kClientBottomPadding +
157 chrome_style::kTitleTopPadding; 163 chrome_style::kTitleTopPadding;
158 [[[self window] contentView] setFrame:contentRect]; 164 [self performLayout];
159 NSRect frame = [[self window] frameRectForContentRect:contentRect];
160 [[self window] setFrame:frame display:YES];
161
162 [accountChooser_
163 setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
164 } 165 }
165 return self; 166 return self;
166 } 167 }
167 168
169 - (void)requestRelayout {
170 [self performLayout];
171 }
172
173 - (NSSize)preferredSize {
174 NSSize contentSize;
175 if ([[signInContainer_ view] isHidden])
176 contentSize = [mainContainer_ preferredSize];
177 else {
Robert Sesek 2013/05/23 15:30:16 If any branch has braces, all branches need braces
groby-ooo-7-16 2013/05/24 20:36:14 Done.
178 // TODO(groby): SignInContainer needs preferredSize, too.
179 NOTREACHED();
180 }
181
182 NSSize headerSize = NSMakeSize(contentSize.width, kAccountChooserHeight);
183 NSSize size = NSMakeSize(
184 std::max(contentSize.width, headerSize.width),
185 contentSize.height + headerSize.height + kRelatedControlVerticalSpacing);
186 size.width += 2 * chrome_style::kHorizontalPadding;
187 size.height += chrome_style::kClientBottomPadding +
188 chrome_style::kTitleTopPadding;
189 return size;
190 }
191
192 - (void)performLayout {
193 // Don't animate when we first show the window.
194 BOOL shouldAnimate =
195 !NSEqualRects(ui::kWindowSizeDeterminedLater, [[self window] frame]);
196
197 NSRect contentRect = NSZeroRect;
198 contentRect.size = [self preferredSize];
199 NSRect clientRect = NSInsetRect(
200 contentRect, chrome_style::kHorizontalPadding, 0);
201 clientRect.origin.y += chrome_style::kClientBottomPadding;
202 clientRect.size.height -= chrome_style::kTitleTopPadding +
203 chrome_style::kClientBottomPadding;
204
205 NSRect headerRect, mainRect;
206 NSDivideRect(clientRect, &headerRect, &mainRect,
207 kAccountChooserHeight, NSMaxYEdge);
208
209 [accountChooser_ setFrame:headerRect];
210 [[mainContainer_ view] setFrame:mainRect];
211 [mainContainer_ performLayout];
212 [[signInContainer_ view] setFrame:mainRect];
213 // TODO(groby): Perform layout for signInContainer.
214
215 NSRect frameRect = [[self window] frameRectForContentRect:contentRect];
216 [[self window] setFrame:frameRect display:YES animate:shouldAnimate];
217 }
218
168 - (IBAction)accept:(id)sender { 219 - (IBAction)accept:(id)sender {
169 // TODO(groby): Validation goes here. 220 // TODO(groby): Validation goes here.
170 autofillDialog_->controller()->OnAccept(); 221 autofillDialog_->controller()->OnAccept();
171 } 222 }
172 223
173 - (IBAction)cancel:(id)sender { 224 - (IBAction)cancel:(id)sender {
174 // TODO(groby): Validation goes here. 225 // TODO(groby): Validation goes here.
175 autofillDialog_->controller()->OnCancel(); 226 autofillDialog_->controller()->OnCancel();
176 autofillDialog_->Hide(); 227 autofillDialog_->Hide();
177 } 228 }
(...skipping 18 matching lines...) Expand all
196 - (void)hideSignIn { 247 - (void)hideSignIn {
197 [[signInContainer_ view] setHidden:YES]; 248 [[signInContainer_ view] setHidden:YES];
198 [[mainContainer_ view] setHidden:NO]; 249 [[mainContainer_ view] setHidden:NO];
199 } 250 }
200 251
201 - (void)modelChanged { 252 - (void)modelChanged {
202 [mainContainer_ modelChanged]; 253 [mainContainer_ modelChanged];
203 } 254 }
204 255
205 @end 256 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698