Fix infinite loop with huge tooltips

* With a tooltip big enough trying to align below or above the mouse, the algorithm would loop endlessly trying to fit it on either side.
 * After trying each side once, set alignment to middle to try to show as much as the tooltip as possible.

A way to trigger this is browsing WebKit github repository in WebPositive. Github will show the full commit message in a tooltip when you hover a file or directory, and some of
their messages are big enough to overflow my desktop.
This commit is contained in:
Adrien Destugues
2013-08-26 22:34:06 +02:00
parent 0edcbd2754
commit 8ce846e2b1
+11 -2
View File
@@ -239,12 +239,19 @@ ToolTipView::ResetWindowFrame(BPoint where)
&& alignment.horizontal == B_ALIGN_CENTER))
alignment.vertical = B_ALIGN_BOTTOM;
// Adjust the tooltip position in cases where it would be partly out of the
// screen frame. Try to fit the tooltip on the requested side of the
// cursor, if that fails, try the opposite side, and if that fails again,
// give up and leave the tooltip under the mouse cursor.
bool firstTry = true;
while (true) {
switch (alignment.vertical) {
case B_ALIGN_TOP:
location.y = where.y - size.height - offset.y;
if (location.y < screenFrame.top) {
alignment.vertical = B_ALIGN_BOTTOM;
alignment.vertical = firstTry ? B_ALIGN_BOTTOM
: B_ALIGN_MIDDLE;
firstTry = false;
continue;
}
break;
@@ -260,7 +267,9 @@ ToolTipView::ResetWindowFrame(BPoint where)
default:
location.y = where.y + offset.y;
if (location.y + size.height > screenFrame.bottom) {
alignment.vertical = B_ALIGN_TOP;
alignment.vertical = firstTry ? B_ALIGN_TOP
: B_ALIGN_MIDDLE;
firstTry = false;
continue;
}
break;