Skip to content

Commit f9d11c6

Browse files
committedOct 3, 2019
fix(gui): event target selection bug when widget pointer-events is none
1 parent a7d014f commit f9d11c6

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed
 

‎src/gui/widget_event.c

+30-22
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ static int Widget_TriggerEventEx(LCUI_Widget widget, LCUI_WidgetEventPack pack)
528528
break;
529529
}
530530
default:
531-
if (widget->trigger && 0 <
532-
EventTrigger_Trigger(widget->trigger, e->type, pack)) {
531+
if (widget->trigger &&
532+
0 < EventTrigger_Trigger(widget->trigger, e->type, pack)) {
533533
return 0;
534534
}
535535
if (!widget->parent || e->cancel_bubble) {
@@ -694,28 +694,37 @@ static LCUI_Widget GetSameParent(LCUI_Widget a, LCUI_Widget b)
694694
return NULL;
695695
}
696696

697-
static LCUI_Widget Widget_GetActualEventTarget(LCUI_Widget widget)
697+
static LCUI_Widget Widget_GetEventTarget(LCUI_Widget widget, float x, float y,
698+
int inherited_pointer_events)
698699
{
699-
LCUI_BOOL found = FALSE;
700-
LCUI_Widget w = widget;
700+
int pointer_events;
701+
702+
LCUI_Widget child;
701703
LCUI_Widget target = NULL;
702-
LCUI_Widget root = LCUIWidget_GetRoot();
704+
LinkedListNode *node;
703705

704-
while (w && w != root) {
705-
if (w->state == LCUI_WSTATE_DELETED ||
706-
w->computed_style.pointer_events == SV_NONE) {
707-
target = w->parent;
708-
found = TRUE;
709-
} else if (!found &&
710-
w->computed_style.pointer_events == SV_AUTO) {
711-
return widget;
706+
for (LinkedList_Each(node, &widget->children_show)) {
707+
child = node->data;
708+
if (!child->computed_style.visible ||
709+
child->state != LCUI_WSTATE_NORMAL ||
710+
!LCUIRect_HasPoint(&child->box.border, x, y)) {
711+
continue;
712+
}
713+
pointer_events = child->computed_style.pointer_events;
714+
if (pointer_events == SV_INHERIT) {
715+
pointer_events = inherited_pointer_events;
716+
}
717+
target = Widget_GetEventTarget(child, x - child->box.padding.x,
718+
y - child->box.padding.y,
719+
pointer_events);
720+
if (target) {
721+
return target;
722+
}
723+
if (pointer_events == SV_AUTO) {
724+
return child;
712725
}
713-
w = w->parent;
714-
}
715-
if (found) {
716-
return target;
717726
}
718-
return widget;
727+
return target;
719728
}
720729

721730
static void Widget_TriggerMouseOverEvent(LCUI_Widget widget, LCUI_Widget parent)
@@ -913,15 +922,14 @@ static void OnMouseEvent(LCUI_SysEvent sys_ev, void *arg)
913922
if (self.mouse_capturer) {
914923
target = self.mouse_capturer;
915924
} else {
916-
target = Widget_At(w, pos.x, pos.y);
917-
target = Widget_GetActualEventTarget(target);
925+
target = Widget_GetEventTarget(w, pos.x, pos.y, SV_AUTO);
918926
}
919927
for (w = target; w; w = w->parent) {
920928
if (w->event_blocked) {
921929
return;
922930
}
923931
}
924-
if (!target) {
932+
if (!target || target == LCUIWidget_GetRoot()) {
925933
Widget_OnMouseOverEvent(NULL);
926934
switch (sys_ev->type) {
927935
case LCUI_MOUSEDOWN:

‎src/gui/widget_tree.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ LCUI_Widget Widget_At(LCUI_Widget widget, int ix, int iy)
301301
if (!c->computed_style.visible) {
302302
continue;
303303
}
304-
ix = iround(x);
305-
iy = iround(y);
306-
if (LCUIRect_HasPoint(&c->box.border, ix, iy)) {
304+
if (LCUIRect_HasPoint(&c->box.border, x, y)) {
307305
target = c;
308306
x -= c->box.padding.x;
309307
y -= c->box.padding.y;

0 commit comments

Comments
 (0)
Please sign in to comment.