From 30008a19dfe665b4e85f3d8c16035fbbeaa08d67 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 15 Sep 2015 22:15:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E6=A0=B7=E5=BC=8F=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E5=8C=B9=E9=85=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 样式匹配改成从右至左遍历, 成功匹配的条件改为完全遍历样式表的选择器列表(作用域)。 其它地方做了些小调整。 --- src/gui/css_parser.c | 2 +- src/gui/widget/sidebar.c | 3 ++- src/gui/widget_base.c | 3 ++- src/gui/widget_style.c | 25 +++++++++++++++---------- src/output/graph_display.c | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 7f893eea..517d93c6 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -36,7 +36,7 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#define DEBUG +//#define DEBUG #include #include #include diff --git a/src/gui/widget/sidebar.c b/src/gui/widget/sidebar.c index 21d92db6..f5ac8fa2 100644 --- a/src/gui/widget/sidebar.c +++ b/src/gui/widget/sidebar.c @@ -66,7 +66,6 @@ sidebar { sidebar sidebar-item { width: 100%; height: 38px; - background-color: rgba(255,255,255,0); padding: 0 16px 0 7px; border-top: 1px solid #f3f3f3; } @@ -119,6 +118,8 @@ LCUI_Widget SideBar_AppendItem( LCUI_Widget sidebar, const wchar_t *id, TextView_SetTextW( sbi->icon, icon ); TextView_SetTextW( sbi->text, text ); Widget_Show( w ); + Widget_Show( sbi->icon ); + Widget_Show( sbi->text ); LinkedList_Append( &sb->items, sbi ); return w; } diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 1bc26d23..e023f9fb 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -517,7 +517,8 @@ void Widget_ComputeSize( LCUI_Widget w ) w->height = 0; break; } - if( w->computed_style.height.type == SVT_AUTO || w->computed_style.width.type == SVT_AUTO ) { + if( w->computed_style.height.type == SVT_AUTO + || w->computed_style.width.type == SVT_AUTO ) { LCUI_WidgetClass *wc; int width, height; diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 9c4751fe..75601c9c 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -453,16 +453,20 @@ LCUI_BOOL IsMatchPath( LCUI_Widget *wlist, LCUI_Selector selector ) int i, n; LCUI_SelectorNode *sn_ptr = selector; LCUI_Widget *obj_ptr = wlist, w; - - for( ; *obj_ptr && *sn_ptr; ++obj_ptr ) { + /* 定位到最后一个元素 */ + for( ;*sn_ptr; ++sn_ptr ); + for( ;*obj_ptr; ++obj_ptr ); + --sn_ptr; + --obj_ptr; + /* 从右到左遍历,进行匹配 */ + for( ; obj_ptr >= wlist && sn_ptr >= selector; --obj_ptr ) { w = *obj_ptr; if( (*sn_ptr)->id ) { - if( strcmp("*", (*sn_ptr)->id) - && strcmp( w->id, (*sn_ptr)->id ) ) { + if( strcmp( w->id, (*sn_ptr)->id ) ) { continue; } } - if( (*sn_ptr)->type ) { + if( (*sn_ptr)->type && strcmp("*", (*sn_ptr)->type) ) { if( strcmp(w->type, (*sn_ptr)->type) ) { continue; } @@ -491,9 +495,10 @@ LCUI_BOOL IsMatchPath( LCUI_Widget *wlist, LCUI_Selector selector ) continue; } } - ++sn_ptr; + --sn_ptr; } - if( *obj_ptr == NULL && *sn_ptr == NULL ) { + /* 匹配成功的标志是遍历完选择器列表 */ + if( sn_ptr < selector ) { return TRUE; } return FALSE; @@ -541,8 +546,7 @@ static int FindStyleNode( LCUI_Widget w, LinkedList *list ) { int i, count = 0; char fullname[MAX_NAME_LEN]; - /* 记录作用于全局元素的样式表 */ - count += FindStyleNodeByName( "*", w, list ); + i = ptrslen( w->classes ); /* 记录类选择器匹配的样式表 */ while( --i >= 0 ) { @@ -567,6 +571,8 @@ static int FindStyleNode( LCUI_Widget w, LinkedList *list ) if( w->type ) { count += FindStyleNodeByName( w->type, w, list ); } + /* 记录作用于全局元素的样式表 */ + count += FindStyleNodeByName( "*", w, list ); return count; } @@ -691,7 +697,6 @@ void Widget_Update( LCUI_Widget w, LCUI_BOOL is_update_all ) Widget_ComputeInheritStyle( w, w->inherited_style ); } ReplaceStyleSheet( w->style, w->inherited_style, w->custom_style ); - DEBUG_MSG("widget: %s, background-color: 0x%08x, is_valid: %d\n", w->type, w->css[key_background_color].value_color.value, w->type, w->css[key_background_color].is_valid); /* 对比两张样式表,确定哪些需要更新 */ for( key = 0; key < STYLE_KEY_TOTAL; ++key ) { /* 忽略值没有变化的样式 */ diff --git a/src/output/graph_display.c b/src/output/graph_display.c index 4f26cdb7..25c2ca98 100755 --- a/src/output/graph_display.c +++ b/src/output/graph_display.c @@ -37,7 +37,7 @@ * 没有,请查看:. * ****************************************************************************/ -#define DEBUG +//#define DEBUG #include #include #include