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

Unified Diff: chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.mm

Issue 115753002: [rAc] [OSX] Use vertically compact text to show suggestions, when it fits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix wording a bit Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.mm b/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.mm
index e854cd2d1667e6a4645975d42ff2894b3586e154..337154e88387f11450aea353c33c6560b9d1d539 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.mm
@@ -82,6 +82,17 @@ const CGFloat kLabelTopPadding = 5.0;
@end
+@interface AutofillSuggestionContainer (Private)
+
+// Set the main suggestion text and the corresponding |icon|.
+// Attempts to wrap the text if |wrapText| is set.
+- (void)setSuggestionText:(NSString*)line
+ icon:(NSImage*)icon
+ wrapText:(BOOL)wrapText;
+
+@end
+
+
@implementation AutofillSuggestionContainer
- (AutofillTextField*)inputField {
@@ -125,7 +136,9 @@ const CGFloat kLabelTopPadding = 5.0;
[self setView:view];
}
-- (void)setSuggestionText:(NSString*)line icon:(NSImage*)icon {
+- (void)setSuggestionText:(NSString*)line
+ icon:(NSImage*)icon
+ wrapText:(BOOL)wrapText {
[label_ setString:@""];
if ([icon size].width) {
@@ -151,11 +164,31 @@ const CGFloat kLabelTopPadding = 5.0;
[[label_ textStorage] appendAttributedString:str1];
[label_ setVerticallyResizable:YES];
- [label_ setHorizontallyResizable:NO];
- [label_ setFrameSize:NSMakeSize(2 * autofill::kFieldWidth, kInfiniteSize)];
+ [label_ setHorizontallyResizable:!wrapText];
+ if (wrapText) {
+ CGFloat availableWidth =
+ 4 * autofill::kFieldWidth - [inputField_ frame].size.width;
+ [label_ setFrameSize:NSMakeSize(availableWidth, kInfiniteSize)];
+ } else {
+ [label_ setFrameSize:NSMakeSize(kInfiniteSize, kInfiniteSize)];
+ }
+ [[label_ layoutManager] ensureLayoutForTextContainer:[label_ textContainer]];
[label_ sizeToFit];
}
+- (void)
+ setSuggestionWithVerticallyCompactText:(NSString*)verticallyCompactText
+ horizontallyCompactText:(NSString*)horizontallyCompactText
+ icon:(NSImage*)icon
+ maxWidth:(CGFloat)maxWidth {
+ // Prefer the vertically compact text when it fits. If it doesn't fit, fall
+ // back to the horizontally compact text.
+ [self setSuggestionText:verticallyCompactText icon:icon wrapText:NO];
+ if ([self preferredSize].width > maxWidth)
+ [self setSuggestionText:horizontallyCompactText icon:icon wrapText:YES];
+}
+
+
- (void)showInputField:(NSString*)text withIcon:(NSImage*)icon {
[[inputField_ cell] setPlaceholderString:text];
[[inputField_ cell] setIcon:icon];
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/autofill_suggestion_container.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698