From 820e09bcfa7eb447e173ea9ff87d4636c8ff2239 Mon Sep 17 00:00:00 2001 From: "smfr%smfr.org" Date: Sat, 28 May 2005 06:47:57 +0000 Subject: [PATCH] Tweak tooltip sizing to fix a bunch of edge cases. Finally fixes bug 248488. --- camino/src/browser/ToolTip.mm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/camino/src/browser/ToolTip.mm b/camino/src/browser/ToolTip.mm index 5a5c8ba5731..67322847f2c 100644 --- a/camino/src/browser/ToolTip.mm +++ b/camino/src/browser/ToolTip.mm @@ -97,12 +97,30 @@ const float kVOffset = 20.0; if (screen) { NSRect screenFrame = [screen visibleFrame]; NSSize screenSize = screenFrame.size; + + // for some reason, text views suffer from hysteresis; the answer you get this time + // depends on what you had in there before. so clear state first. + [mTextView setString:@""]; + [mTextView setFrame:NSMakeRect(0, kBorderPadding, 0, 0)]; + + // -sizeToFit sucks. For some reason it likes to wrap short words, so + // we measure the text by hand and set that as the min width. + NSSize stringSize = [string sizeWithAttributes:[NSDictionary dictionaryWithObject:[NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttributeName]]; + float textViewWidth = ceil(stringSize.width); + if (textViewWidth > kMaxTextFieldWidth) + textViewWidth = kMaxTextFieldWidth; + + textViewWidth += 2.0 * 5.0; // magic numbers required to make the text not wrap. No, this isn't -textContainerInset. // set up the text view [mTextView setMaxSize:NSMakeSize(kMaxTextFieldWidth, screenSize.height - 2 * kBorderPadding)]; // do this here since we know screen size - [mTextView setString:string]; // do this after setting max size, before setting costrained frame size, + [mTextView setString:string]; // do this after setting max size, before setting constrained frame size, // reset to max width - it will not grow horizontally when resizing, only vertically [mTextView setConstrainedFrameSize:NSMakeSize(kMaxTextFieldWidth, 0.0)]; + // to avoid wrapping when we don't want it, set the min width + [mTextView setMinSize:NSMakeSize(textViewWidth, 0.0)]; + + // finally, do the buggy sizeToFit [mTextView sizeToFit]; // set the origin back where its supposed to be