@@ -666,13 +666,12 @@ int Widget_StopEventPropagation(LCUI_Widget widget)
666
666
static LCUI_Widget GetSameParent (LCUI_Widget a , LCUI_Widget b )
667
667
{
668
668
int depth = 0 , i ;
669
- LCUI_Widget w , root ;
669
+ LCUI_Widget w ;
670
670
671
- root = LCUIWidget_GetRoot ();
672
- for (w = a ; w != root && w ; w = w -> parent ) {
671
+ for (w = a ; w ; w = w -> parent ) {
673
672
++ depth ;
674
673
}
675
- for (w = b ; w != root && w ; w = w -> parent ) {
674
+ for (w = b ; w ; w = w -> parent ) {
676
675
-- depth ;
677
676
}
678
677
if (depth > 0 ) {
@@ -688,7 +687,7 @@ static LCUI_Widget GetSameParent(LCUI_Widget a, LCUI_Widget b)
688
687
a = a -> parent ;
689
688
b = b -> parent ;
690
689
}
691
- if (a && a == b && a != root ) {
690
+ if (a && a == b ) {
692
691
return a ;
693
692
}
694
693
return NULL ;
@@ -762,9 +761,7 @@ static void Widget_OnMouseOverEvent(LCUI_Widget widget)
762
761
if (self .targets [WST_HOVER ] == widget ) {
763
762
return ;
764
763
}
765
- if (widget && self .targets [WST_HOVER ]) {
766
- parent = GetSameParent (widget , self .targets [WST_HOVER ]);
767
- }
764
+ parent = GetSameParent (widget , self .targets [WST_HOVER ]);
768
765
if (widget ) {
769
766
Widget_TriggerMouseOverEvent (widget , parent );
770
767
}
@@ -776,13 +773,14 @@ static void Widget_OnMouseOverEvent(LCUI_Widget widget)
776
773
777
774
static void Widget_OnMouseDownEvent (LCUI_Widget widget )
778
775
{
779
- LCUI_Widget w , parent ;
776
+ LCUI_Widget parent ;
777
+ LCUI_Widget w = self .targets [WST_ACTIVE ];
780
778
781
- if (self . targets [ WST_ACTIVE ] == widget ) {
779
+ if (w == widget ) {
782
780
return ;
783
781
}
784
- parent = GetSameParent (widget , self . targets [ WST_ACTIVE ] );
785
- for (w = self . targets [ WST_ACTIVE ] ; w && w != parent ; w = w -> parent ) {
782
+ parent = GetSameParent (widget , w );
783
+ for (; w && w != parent ; w = w -> parent ) {
786
784
Widget_RemoveStatus (w , "active" );
787
785
}
788
786
for (w = widget ; w && w != parent ; w = w -> parent ) {
@@ -911,42 +909,28 @@ static void OnMouseEvent(LCUI_SysEvent sys_ev, void *arg)
911
909
{
912
910
float scale ;
913
911
LCUI_Pos pos ;
912
+ LCUI_Widget root ;
914
913
LCUI_Widget target , w ;
915
914
LCUI_WidgetEventRec ev = { 0 };
916
915
917
- w = LCUIWidget_GetRoot ();
916
+ root = LCUIWidget_GetRoot ();
918
917
LCUICursor_GetPos (& pos );
919
918
scale = LCUIMetrics_GetScale ();
920
919
pos .x = iround (pos .x / scale );
921
920
pos .y = iround (pos .y / scale );
922
921
if (self .mouse_capturer ) {
923
922
target = self .mouse_capturer ;
924
923
} else {
925
- target = Widget_GetEventTarget (w , ( float ) pos .x , ( float ) pos .y ,
924
+ target = Widget_GetEventTarget (root , 1.f * pos .x , 1.f * pos .y ,
926
925
SV_AUTO );
927
926
}
928
927
for (w = target ; w ; w = w -> parent ) {
929
928
if (w -> event_blocked ) {
930
929
return ;
931
930
}
932
931
}
933
- if (!target || target == LCUIWidget_GetRoot ()) {
934
- Widget_OnMouseOverEvent (NULL );
935
- switch (sys_ev -> type ) {
936
- case LCUI_MOUSEDOWN :
937
- LCUIWidget_SetFocus (NULL );
938
- break ;
939
- case LCUI_MOUSEUP :
940
- if (sys_ev -> button .button == LCUI_KEY_LEFTBUTTON ) {
941
- self .click .x = 0 ;
942
- self .click .y = 0 ;
943
- self .click .time = 0 ;
944
- self .click .widget = NULL ;
945
- Widget_OnMouseDownEvent (NULL );
946
- break ;
947
- }
948
- }
949
- return ;
932
+ if (!target ) {
933
+ target = root ;
950
934
}
951
935
ev .target = target ;
952
936
ev .cancel_bubble = FALSE;
0 commit comments