Commit 0e1b12f2 authored by isherman@chromium.org's avatar isherman@chromium.org

[rAc] [OSX] Use vertically compact text to show suggestions, when it fits.

BUG=279563
TEST=Shorter addresses should fit on a single line; longer addresses should
     still span many lines.
R=groby@chromium.org

Review URL: https://codereview.chromium.org/115753002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241110 0039d316-1c4b-4281-b951-d872f2087c98
parent 78ce8755
...@@ -310,19 +310,29 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section, ...@@ -310,19 +310,29 @@ bool ShouldOverwriteComboboxes(autofill::DialogSection section,
- (void)updateSuggestionState { - (void)updateSuggestionState {
const autofill::SuggestionState& suggestionState = const autofill::SuggestionState& suggestionState =
delegate_->SuggestionStateForSection(section_); delegate_->SuggestionStateForSection(section_);
// TODO(estade): use |vertically_compact_text| when it fits.
const base::string16& text = suggestionState.horizontally_compact_text;
showSuggestions_ = suggestionState.visible; showSuggestions_ = suggestionState.visible;
[suggestContainer_ setSuggestionText:base::SysUTF16ToNSString(text)
icon:suggestionState.icon.AsNSImage()];
if (!suggestionState.extra_text.empty()) { if (!suggestionState.extra_text.empty()) {
NSString* extraText = NSString* extraText =
base::SysUTF16ToNSString(suggestionState.extra_text); base::SysUTF16ToNSString(suggestionState.extra_text);
NSImage* extraIcon = suggestionState.extra_icon.AsNSImage(); NSImage* extraIcon = suggestionState.extra_icon.AsNSImage();
[suggestContainer_ showInputField:extraText withIcon:extraIcon]; [suggestContainer_ showInputField:extraText withIcon:extraIcon];
} }
// NOTE: It's important to set the input field, if there is one, _before_
// setting the suggestion text, since the suggestion container needs to
// account for the input field's width when deciding which of the two string
// representations to use.
NSString* verticallyCompactText =
base::SysUTF16ToNSString(suggestionState.vertically_compact_text);
NSString* horizontallyCompactText =
base::SysUTF16ToNSString(suggestionState.horizontally_compact_text);
[suggestContainer_
setSuggestionWithVerticallyCompactText:verticallyCompactText
horizontallyCompactText:horizontallyCompactText
icon:suggestionState.icon.AsNSImage()
maxWidth:kDetailsWidth];
[view_ setShouldHighlightOnHover:showSuggestions_]; [view_ setShouldHighlightOnHover:showSuggestions_];
if (showSuggestions_) if (showSuggestions_)
[view_ setClickTarget:suggestButton_]; [view_ setClickTarget:suggestButton_];
......
...@@ -34,8 +34,18 @@ namespace autofill { ...@@ -34,8 +34,18 @@ namespace autofill {
// Auxiliary textfield. See showInputField: for details. // Auxiliary textfield. See showInputField: for details.
@property (readonly, nonatomic) AutofillTextField* inputField; @property (readonly, nonatomic) AutofillTextField* inputField;
// Set the main suggestion text and the corresponding |icon|. // Set the main suggestion text and the corresponding |icon|. The text is set to
- (void)setSuggestionText:(NSString*)line icon:(NSImage*)icon; // |verticallyCompactText| if that can fit without wrapping. Otherwise, the text
// is set to |horizontallyCompactText|, with possibly additional wrapping
// imposed by the dialog's size constraints.
// NOTE: The implementation assumes that all other elements' sizes are already
// known. Hence, -showInputField:withIcon: should be called prior to calling
// this method, if it is going to be called at all.
- (void)
setSuggestionWithVerticallyCompactText:(NSString*)verticallyCompactText
horizontallyCompactText:(NSString*)horizontallyCompactText
icon:(NSImage*)icon
maxWidth:(CGFloat)maxWidth;
// Shows an auxiliary textfield to the right of the suggestion icon and // Shows an auxiliary textfield to the right of the suggestion icon and
// text. This is currently only used to show a CVC field for the CC section. // text. This is currently only used to show a CVC field for the CC section.
......
...@@ -82,6 +82,17 @@ const CGFloat kLabelWithInputTopPadding = 5.0; ...@@ -82,6 +82,17 @@ const CGFloat kLabelWithInputTopPadding = 5.0;
@end @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 @implementation AutofillSuggestionContainer
- (AutofillTextField*)inputField { - (AutofillTextField*)inputField {
...@@ -125,7 +136,9 @@ const CGFloat kLabelWithInputTopPadding = 5.0; ...@@ -125,7 +136,9 @@ const CGFloat kLabelWithInputTopPadding = 5.0;
[self setView:view]; [self setView:view];
} }
- (void)setSuggestionText:(NSString*)line icon:(NSImage*)icon { - (void)setSuggestionText:(NSString*)line
icon:(NSImage*)icon
wrapText:(BOOL)wrapText {
[label_ setString:@""]; [label_ setString:@""];
if ([icon size].width) { if ([icon size].width) {
...@@ -151,11 +164,31 @@ const CGFloat kLabelWithInputTopPadding = 5.0; ...@@ -151,11 +164,31 @@ const CGFloat kLabelWithInputTopPadding = 5.0;
[[label_ textStorage] appendAttributedString:str1]; [[label_ textStorage] appendAttributedString:str1];
[label_ setVerticallyResizable:YES]; [label_ setVerticallyResizable:YES];
[label_ setHorizontallyResizable:NO]; [label_ setHorizontallyResizable:!wrapText];
[label_ setFrameSize:NSMakeSize(2 * autofill::kFieldWidth, kInfiniteSize)]; 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]; [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 { - (void)showInputField:(NSString*)text withIcon:(NSImage*)icon {
[[inputField_ cell] setPlaceholderString:text]; [[inputField_ cell] setPlaceholderString:text];
[[inputField_ cell] setIcon:icon]; [[inputField_ cell] setIcon:icon];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment