BListView: do not spawn a thread on every mouse click.

That's a bad idea. The drag and drop tracking could get confused enough
to crash app_server (possibly because of calling InitiateDrag multiple
times?)

Fixes #14983.
This commit is contained in:
Adrien Destugues 2020-04-04 11:45:24 +02:00
parent 1e4cb11ffd
commit 61557c8240
2 changed files with 20 additions and 29 deletions

View File

@ -189,9 +189,6 @@ private:
bool _ReplaceItem(int32 index, BListItem* item);
void _RescanSelection(int32 from, int32 to);
void _DoneTracking(BPoint where);
void _Track(BPoint where, uint32);
private:
BList fList;
list_view_type fListType;

View File

@ -588,8 +588,7 @@ BListView::MouseDown(BPoint where)
fTrack->was_selected = index >= 0 ? ItemAt(index)->IsSelected() : false;
fTrack->try_drag = true;
MouseDownThread<BListView>::TrackMouse(this,
&BListView::_DoneTracking, &BListView::_Track);
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
}
if (index >= 0) {
@ -636,6 +635,14 @@ void
BListView::MouseUp(BPoint where)
{
BView::MouseUp(where);
uint32* buttons = 0;
GetMouse(&where, buttons);
if (buttons == 0) {
fTrack->try_drag = false;
fTrack->is_dragging = false;
}
}
@ -643,6 +650,17 @@ void
BListView::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
{
BView::MouseMoved(where, code, dragMessage);
if (fTrack->item_index >= 0 && fTrack->try_drag) {
// initiate a drag if the mouse was moved far enough
BPoint offset = where - fTrack->drag_start;
float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y);
if (dragDistance >= 5.0f) {
fTrack->try_drag = false;
fTrack->is_dragging = InitiateDrag(fTrack->drag_start,
fTrack->item_index, fTrack->was_selected);
}
}
}
@ -1966,27 +1984,3 @@ BListView::_RecalcItemTops(int32 start, int32 end)
top += ceilf(item->Height());
}
}
void
BListView::_DoneTracking(BPoint where)
{
fTrack->try_drag = false;
fTrack->is_dragging = false;
}
void
BListView::_Track(BPoint where, uint32)
{
if (fTrack->item_index >= 0 && fTrack->try_drag) {
// initiate a drag if the mouse was moved far enough
BPoint offset = where - fTrack->drag_start;
float dragDistance = sqrtf(offset.x * offset.x + offset.y * offset.y);
if (dragDistance >= 5.0f) {
fTrack->try_drag = false;
fTrack->is_dragging = InitiateDrag(fTrack->drag_start,
fTrack->item_index, fTrack->was_selected);
}
}
}