纠正样式表的匹配逻辑

样式匹配改成从右至左遍历, 成功匹配的条件改为完全遍历样式表的选择器列表(作用域)。
其它地方做了些小调整。
This commit is contained in:
Liu Chao
2015-09-15 22:15:41 +08:00
parent 999c7f9c6a
commit 30008a19df
5 changed files with 21 additions and 14 deletions
+1 -1
View File
@@ -36,7 +36,7 @@
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#define DEBUG
//#define DEBUG
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/misc/parse.h>
+2 -1
View File
@@ -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;
}
+2 -1
View File
@@ -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;
+15 -10
View File
@@ -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 ) {
/* 忽略值没有变化的样式 */
+1 -1
View File
@@ -37,7 +37,7 @@
* 没有,请查看:<http://www.gnu.org/licenses/>.
* ****************************************************************************/
#define DEBUG
//#define DEBUG
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/graph.h>