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_suggestion_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 // Technically, CGFLOAT_MAX should do. Practically, it runs into several issues. | 28 // Technically, CGFLOAT_MAX should do. Practically, it runs into several issues. |
29 // #1) Many computations on Retina devices overflow with that value. | 29 // #1) Many computations on Retina devices overflow with that value. |
30 // #2) In this particular use case, it results in the message | 30 // #2) In this particular use case, it results in the message |
31 // "CGAffineTransformInvert: singular matrix." | 31 // "CGAffineTransformInvert: singular matrix." |
32 const CGFloat kInfiniteSize = 1.0e6; | 32 const CGFloat kInfiniteSize = 1.0e6; |
33 | 33 |
34 // A line fragment padding that creates the same visual look as text layout in | 34 // A line fragment padding that creates the same visual look as text layout in |
35 // an NSTextField does. (Which UX feedback was based on) | 35 // an NSTextField does. (Which UX feedback was based on) |
36 const CGFloat kLineFragmentPadding = 2.0; | 36 const CGFloat kLineFragmentPadding = 2.0; |
37 | 37 |
38 // Padding added on top of the label so its first line looks centered with | |
39 // respect to the input field. | |
40 const CGFloat kLabelTopPadding = 5.0; | |
groby-ooo-7-16
2013/12/13 07:19:39
So, what happens with a CVV input? Is that not cen
Ilya Sherman
2013/12/13 07:48:11
Good call, that was very broken. Fixed.
| |
41 | |
42 } | 38 } |
43 | 39 |
44 // An attachment cell for a single icon - takes care of proper alignment of | 40 // An attachment cell for a single icon - takes care of proper alignment of |
45 // text and icon. | 41 // text and icon. |
46 @interface IconAttachmentCell : NSTextAttachmentCell { | 42 @interface IconAttachmentCell : NSTextAttachmentCell { |
47 CGFloat baseline_; // The cell's baseline adjustment. | 43 CGFloat baseline_; // The cell's baseline adjustment. |
48 } | 44 } |
49 | 45 |
50 // Adjust the cell's baseline so that the lower edge of the image aligns with | 46 // Adjust the cell's baseline so that the lower edge of the image aligns with |
51 // the longest descender, not the font baseline | 47 // the longest descender, not the font baseline |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 | 98 |
103 - (void)loadView { | 99 - (void)loadView { |
104 label_.reset([[NSTextView alloc] initWithFrame:NSZeroRect]); | 100 label_.reset([[NSTextView alloc] initWithFrame:NSZeroRect]); |
105 [[label_ textContainer] setLineFragmentPadding:kLineFragmentPadding]; | 101 [[label_ textContainer] setLineFragmentPadding:kLineFragmentPadding]; |
106 [label_ setEditable:NO]; | 102 [label_ setEditable:NO]; |
107 [label_ setSelectable:NO]; | 103 [label_ setSelectable:NO]; |
108 [label_ setDrawsBackground:NO]; | 104 [label_ setDrawsBackground:NO]; |
109 | 105 |
110 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 106 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
111 [[NSMutableParagraphStyle alloc] init]); | 107 [[NSMutableParagraphStyle alloc] init]); |
112 [paragraphStyle setLineHeightMultiple:1.5]; | 108 [paragraphStyle setLineSpacing:0.5 * [[label_ font] pointSize]]; |
groby-ooo-7-16
2013/12/13 07:19:39
Why the change from lineHeightMultiple to lineSpac
Ilya Sherman
2013/12/13 07:48:11
Because lineHeightMultiple reserves space above th
| |
113 [label_ setDefaultParagraphStyle:paragraphStyle]; | 109 [label_ setDefaultParagraphStyle:paragraphStyle]; |
114 | 110 |
115 inputField_.reset([[AutofillTextField alloc] initWithFrame:NSZeroRect]); | 111 inputField_.reset([[AutofillTextField alloc] initWithFrame:NSZeroRect]); |
116 [inputField_ setHidden:YES]; | 112 [inputField_ setHidden:YES]; |
117 | 113 |
118 spacer_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); | 114 spacer_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); |
119 [spacer_ setBoxType:NSBoxSeparator]; | 115 [spacer_ setBoxType:NSBoxSeparator]; |
120 [spacer_ setBorderType:NSLineBorder]; | 116 [spacer_ setBorderType:NSLineBorder]; |
121 | 117 |
122 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 118 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 160 |
165 // Enforce fixed width. | 161 // Enforce fixed width. |
166 NSSize frameSize = NSMakeSize(autofill::kFieldWidth, | 162 NSSize frameSize = NSMakeSize(autofill::kFieldWidth, |
167 NSHeight([inputField_ frame])); | 163 NSHeight([inputField_ frame])); |
168 [inputField_ setFrameSize:frameSize]; | 164 [inputField_ setFrameSize:frameSize]; |
169 } | 165 } |
170 | 166 |
171 | 167 |
172 - (NSSize)preferredSize { | 168 - (NSSize)preferredSize { |
173 NSSize size = [label_ bounds].size; | 169 NSSize size = [label_ bounds].size; |
174 size.height += kLabelTopPadding; | |
175 | 170 |
176 // Final inputField_ sizing/spacing depends on a TODO(estade) in Views code. | 171 // Final inputField_ sizing/spacing depends on a TODO(estade) in Views code. |
177 if (![inputField_ isHidden]) { | 172 if (![inputField_ isHidden]) { |
178 size.height = std::max(size.height, NSHeight([inputField_ frame])); | 173 size.height = std::max(size.height, NSHeight([inputField_ frame])); |
179 size.width += NSWidth([inputField_ frame]) + kAroundTextPadding; | 174 size.width += NSWidth([inputField_ frame]) + kAroundTextPadding; |
180 } | 175 } |
181 | 176 |
182 size.height += kTopPadding; | 177 size.height += kTopPadding; |
183 | 178 |
184 return size; | 179 return size; |
185 } | 180 } |
186 | 181 |
187 - (void)performLayout { | 182 - (void)performLayout { |
188 NSRect bounds = [[self view] bounds]; | 183 NSRect bounds = [[self view] bounds]; |
189 NSSize preferredContainerSize = [self preferredSize]; | 184 NSSize preferredContainerSize = [self preferredSize]; |
190 // width is externally determined. | 185 // width is externally determined. |
191 preferredContainerSize.width = NSWidth(bounds); | 186 preferredContainerSize.width = NSWidth(bounds); |
192 | 187 |
193 NSRect spacerFrame = NSMakeRect(0, preferredContainerSize.height - 1, | 188 NSRect spacerFrame = NSMakeRect(0, preferredContainerSize.height - 1, |
194 preferredContainerSize.width, 1); | 189 preferredContainerSize.width, 1); |
195 | 190 |
196 NSRect labelFrame = [label_ bounds]; | 191 NSRect labelFrame = [label_ bounds]; |
197 labelFrame.origin.x = NSMinX(bounds); | 192 labelFrame.origin.x = NSMinX(bounds); |
198 labelFrame.origin.y = | 193 labelFrame.origin.y = NSMaxY(bounds) - NSHeight(labelFrame) - kTopPadding; |
199 NSMaxY(bounds) - kLabelTopPadding - NSHeight(labelFrame) - kTopPadding; | |
200 | 194 |
201 // Position input field - top is aligned to top of label field. | 195 // Position input field - top is aligned to top of label field. |
202 if (![inputField_ isHidden]) { | 196 if (![inputField_ isHidden]) { |
203 NSRect inputfieldFrame = [inputField_ frame]; | 197 NSRect inputfieldFrame = [inputField_ frame]; |
204 inputfieldFrame.origin.x = NSMaxX(bounds) - NSWidth(inputfieldFrame); | 198 inputfieldFrame.origin.x = NSMaxX(bounds) - NSWidth(inputfieldFrame); |
205 inputfieldFrame.origin.y = | 199 inputfieldFrame.origin.y = NSMaxY(labelFrame) + NSHeight(inputfieldFrame); |
206 NSMaxY(labelFrame) + kLabelTopPadding - NSHeight(inputfieldFrame); | |
207 [inputField_ setFrameOrigin:inputfieldFrame.origin]; | 200 [inputField_ setFrameOrigin:inputfieldFrame.origin]; |
208 | 201 |
209 // Due to fixed width, fields are guaranteed to not overlap. | 202 // Due to fixed width, fields are guaranteed to not overlap. |
210 DCHECK_LE(NSMaxX(labelFrame), NSMinX(inputfieldFrame)); | 203 DCHECK_LE(NSMaxX(labelFrame), NSMinX(inputfieldFrame)); |
211 } | 204 } |
212 | 205 |
213 [spacer_ setFrame:spacerFrame]; | 206 [spacer_ setFrame:spacerFrame]; |
214 [label_ setFrame:labelFrame]; | 207 [label_ setFrame:labelFrame]; |
215 [[self view] setFrameSize:preferredContainerSize]; | 208 [[self view] setFrameSize:preferredContainerSize]; |
216 } | 209 } |
217 | 210 |
218 @end | 211 @end |
OLD | NEW |