mirror of
https://github.com/lvgl/lvgl.git
synced 2024-12-02 22:24:02 +08:00
fix(event): stop event event processing when requested (#6113)
This commit is contained in:
parent
29d8a4d509
commit
33c6ec90f3
@ -356,19 +356,19 @@ static lv_result_t event_send_core(lv_event_t * e)
|
||||
lv_event_list_t * list = target->spec_attr ? &target->spec_attr->event_list : NULL;
|
||||
|
||||
res = lv_event_send(list, e, true);
|
||||
if(res != LV_RESULT_OK) return res;
|
||||
if(res != LV_RESULT_OK || e->stop_processing) return res;
|
||||
|
||||
res = lv_obj_event_base(NULL, e);
|
||||
if(res != LV_RESULT_OK) return res;
|
||||
if(res != LV_RESULT_OK || e->stop_processing) return res;
|
||||
|
||||
res = lv_event_send(list, e, false);
|
||||
if(res != LV_RESULT_OK) return res;
|
||||
if(res != LV_RESULT_OK || e->stop_processing) return res;
|
||||
|
||||
lv_obj_t * parent = lv_obj_get_parent(e->current_target);
|
||||
if(parent && event_is_bubbled(e)) {
|
||||
e->current_target = parent;
|
||||
res = event_send_core(e);
|
||||
if(res != LV_RESULT_OK) return res;
|
||||
if(res != LV_RESULT_OK || e->stop_processing || e->stop_bubbling) return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
#include "lv_test_indev.h"
|
||||
|
||||
static void event_object_deletion_cb(const lv_obj_class_t * cls, lv_event_t * e)
|
||||
{
|
||||
@ -42,4 +43,82 @@ void test_event_should_not_memory_lean(void)
|
||||
TEST_ASSERT_LESS_OR_EQUAL_CHAR(initial_free_size, m2.free_size);
|
||||
}
|
||||
|
||||
static uint32_t pre_cnt_1;
|
||||
static uint32_t pre_cnt_2;
|
||||
static uint32_t post_cnt_1;
|
||||
static uint32_t post_cnt_2;
|
||||
static bool pre_stop_1;
|
||||
static bool post_stop_1;
|
||||
|
||||
static void event_pre_1_cb(lv_event_t * e)
|
||||
{
|
||||
pre_cnt_1++;
|
||||
if(pre_stop_1) lv_event_stop_processing(e);
|
||||
}
|
||||
|
||||
static void event_pre_2_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
pre_cnt_2++;
|
||||
}
|
||||
|
||||
static void event_post_1_cb(lv_event_t * e)
|
||||
{
|
||||
post_cnt_1++;
|
||||
if(post_stop_1) lv_event_stop_processing(e);
|
||||
}
|
||||
|
||||
static void event_post_2_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
post_cnt_2++;
|
||||
}
|
||||
|
||||
/* Add and then remove event should not memory leak */
|
||||
void test_event_stop_processing(void)
|
||||
{
|
||||
lv_obj_t * btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 200, 100);
|
||||
lv_obj_add_event_cb(btn, event_pre_1_cb, LV_EVENT_CLICKED | LV_EVENT_PREPROCESS, NULL);
|
||||
lv_obj_add_event_cb(btn, event_pre_2_cb, LV_EVENT_CLICKED | LV_EVENT_PREPROCESS, NULL);
|
||||
lv_obj_add_event_cb(btn, event_post_1_cb, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_add_event_cb(btn, event_post_2_cb, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
pre_cnt_1 = 0;
|
||||
pre_cnt_2 = 0;
|
||||
post_cnt_1 = 0;
|
||||
post_cnt_2 = 0;
|
||||
pre_stop_1 = false;
|
||||
post_stop_1 = false;
|
||||
lv_test_mouse_click_at(30, 30);
|
||||
TEST_ASSERT_EQUAL(pre_cnt_1, 1);
|
||||
TEST_ASSERT_EQUAL(pre_cnt_2, 1);
|
||||
TEST_ASSERT_EQUAL(post_cnt_1, 1);
|
||||
TEST_ASSERT_EQUAL(post_cnt_2, 1);
|
||||
|
||||
pre_cnt_1 = 0;
|
||||
pre_cnt_2 = 0;
|
||||
post_cnt_1 = 0;
|
||||
post_cnt_2 = 0;
|
||||
pre_stop_1 = true;
|
||||
post_stop_1 = false;
|
||||
lv_test_mouse_click_at(30, 30);
|
||||
TEST_ASSERT_EQUAL(pre_cnt_1, 1);
|
||||
TEST_ASSERT_EQUAL(pre_cnt_2, 0);
|
||||
TEST_ASSERT_EQUAL(post_cnt_1, 0);
|
||||
TEST_ASSERT_EQUAL(post_cnt_2, 0);
|
||||
|
||||
pre_cnt_1 = 0;
|
||||
pre_cnt_2 = 0;
|
||||
post_cnt_1 = 0;
|
||||
post_cnt_2 = 0;
|
||||
pre_stop_1 = false;
|
||||
post_stop_1 = true;
|
||||
lv_test_mouse_click_at(30, 30);
|
||||
TEST_ASSERT_EQUAL(pre_cnt_1, 1);
|
||||
TEST_ASSERT_EQUAL(pre_cnt_2, 1);
|
||||
TEST_ASSERT_EQUAL(post_cnt_1, 1);
|
||||
TEST_ASSERT_EQUAL(post_cnt_2, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user