| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 spacer_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); | 118 spacer_.reset([[NSBox alloc] initWithFrame:NSZeroRect]); |
| 119 [spacer_ setBoxType:NSBoxSeparator]; | 119 [spacer_ setBoxType:NSBoxSeparator]; |
| 120 [spacer_ setBorderType:NSLineBorder]; | 120 [spacer_ setBorderType:NSLineBorder]; |
| 121 | 121 |
| 122 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 122 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 123 [view setSubviews: | 123 [view setSubviews: |
| 124 @[ label_, inputField_, spacer_ ]]; | 124 @[ label_, inputField_, spacer_ ]]; |
| 125 [self setView:view]; | 125 [self setView:view]; |
| 126 } | 126 } |
| 127 | 127 |
| 128 - (void)setSuggestionText:(NSString*)line icon:(NSImage*)icon { | 128 - (void)setSuggestionText:(NSString*)line |
| 129 icon:(NSImage*)icon |
| 130 wrapText:(BOOL)wrapText { |
| 129 [label_ setString:@""]; | 131 [label_ setString:@""]; |
| 130 | 132 |
| 131 if ([icon size].width) { | 133 if ([icon size].width) { |
| 132 base::scoped_nsobject<IconAttachmentCell> cell( | 134 base::scoped_nsobject<IconAttachmentCell> cell( |
| 133 [[IconAttachmentCell alloc] initImageCell:icon]); | 135 [[IconAttachmentCell alloc] initImageCell:icon]); |
| 134 base::scoped_nsobject<NSTextAttachment> attachment( | 136 base::scoped_nsobject<NSTextAttachment> attachment( |
| 135 [[NSTextAttachment alloc] init]); | 137 [[NSTextAttachment alloc] init]); |
| 136 [cell adjustBaselineForFont:[NSFont controlContentFontOfSize:0]]; | 138 [cell adjustBaselineForFont:[NSFont controlContentFontOfSize:0]]; |
| 137 [cell setAlignment:NSLeftTextAlignment]; | 139 [cell setAlignment:NSLeftTextAlignment]; |
| 138 [attachment setAttachmentCell:cell]; | 140 [attachment setAttachmentCell:cell]; |
| 139 [[label_ textStorage] setAttributedString: | 141 [[label_ textStorage] setAttributedString: |
| 140 [NSAttributedString attributedStringWithAttachment:attachment]]; | 142 [NSAttributedString attributedStringWithAttachment:attachment]]; |
| 141 } | 143 } |
| 142 | 144 |
| 143 NSDictionary* attributes = @{ | 145 NSDictionary* attributes = @{ |
| 144 NSParagraphStyleAttributeName : [label_ defaultParagraphStyle], | 146 NSParagraphStyleAttributeName : [label_ defaultParagraphStyle], |
| 145 NSCursorAttributeName : [NSCursor arrowCursor], | 147 NSCursorAttributeName : [NSCursor arrowCursor], |
| 146 NSFontAttributeName : [NSFont controlContentFontOfSize:0] | 148 NSFontAttributeName : [NSFont controlContentFontOfSize:0] |
| 147 }; | 149 }; |
| 148 base::scoped_nsobject<NSAttributedString> str1( | 150 base::scoped_nsobject<NSAttributedString> str1( |
| 149 [[NSAttributedString alloc] initWithString:line | 151 [[NSAttributedString alloc] initWithString:line |
| 150 attributes:attributes]); | 152 attributes:attributes]); |
| 151 [[label_ textStorage] appendAttributedString:str1]; | 153 [[label_ textStorage] appendAttributedString:str1]; |
| 152 | 154 |
| 153 [label_ setVerticallyResizable:YES]; | 155 [label_ setVerticallyResizable:YES]; |
| 154 [label_ setHorizontallyResizable:NO]; | 156 [label_ setHorizontallyResizable:!wrapText]; |
| 155 [label_ setFrameSize:NSMakeSize(2 * autofill::kFieldWidth, kInfiniteSize)]; | 157 if (wrapText) |
| 158 [label_ setFrameSize:NSMakeSize(4 * autofill::kFieldWidth, kInfiniteSize)]; |
| 159 else |
| 160 [label_ setFrameSize:NSMakeSize(kInfiniteSize, kInfiniteSize)]; |
| 161 [[label_ layoutManager] ensureLayoutForTextContainer:[label_ textContainer]]; |
| 156 [label_ sizeToFit]; | 162 [label_ sizeToFit]; |
| 157 } | 163 } |
| 158 | 164 |
| 159 - (void)showInputField:(NSString*)text withIcon:(NSImage*)icon { | 165 - (void)showInputField:(NSString*)text withIcon:(NSImage*)icon { |
| 160 [[inputField_ cell] setPlaceholderString:text]; | 166 [[inputField_ cell] setPlaceholderString:text]; |
| 161 [[inputField_ cell] setIcon:icon]; | 167 [[inputField_ cell] setIcon:icon]; |
| 162 [inputField_ setHidden:NO]; | 168 [inputField_ setHidden:NO]; |
| 163 [inputField_ sizeToFit]; | 169 [inputField_ sizeToFit]; |
| 164 | 170 |
| 165 // Enforce fixed width. | 171 // Enforce fixed width. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // Due to fixed width, fields are guaranteed to not overlap. | 215 // Due to fixed width, fields are guaranteed to not overlap. |
| 210 DCHECK_LE(NSMaxX(labelFrame), NSMinX(inputfieldFrame)); | 216 DCHECK_LE(NSMaxX(labelFrame), NSMinX(inputfieldFrame)); |
| 211 } | 217 } |
| 212 | 218 |
| 213 [spacer_ setFrame:spacerFrame]; | 219 [spacer_ setFrame:spacerFrame]; |
| 214 [label_ setFrame:labelFrame]; | 220 [label_ setFrame:labelFrame]; |
| 215 [[self view] setFrameSize:preferredContainerSize]; | 221 [[self view] setFrameSize:preferredContainerSize]; |
| 216 } | 222 } |
| 217 | 223 |
| 218 @end | 224 @end |
| OLD | NEW |