Welcome to mirror list, hosted at ThFree Co, Russian Federation.

type.c « finder « modest « source - github.com/lexborisov/Modest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6db405e33369374dd9fa563faf8de9087ab488bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 Copyright (C) 2016-2017 Alexander Borisov
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 Author: lex.borisov@gmail.com (Alexander Borisov)
*/

#include "modest/finder/type.h"
#include "modest/finder/resource.h"

bool modest_finder_selector_type_undef(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    return false;
}

bool modest_finder_selector_type_element(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    /* namespace */
    if(selector->ns_entry) {
        if(selector->ns_entry->ns_id != MyHTML_NAMESPACE_ANY && selector->ns_entry->ns_id != node->ns)
            return false;
    }
    
    /* tag match */
    mycore_string_t *str = selector->key;
    if(str->length == 1 && *str->data == '*')
        return true;
    
    if(node->tree) {
        myhtml_tag_id_t tag_id = myhtml_tag_id_by_name(node->tree, str->data, str->length);
        
        if(tag_id == node->tag_id)
            return true;
    }
    
    return false;
}

bool modest_finder_selector_type_id(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    if(node->token == NULL)
        return false;
    
    if(node->tree) {
        return modest_finder_match_attribute_eq(node->token->attr_first,
                                                "id", 2,
                                                selector->key->data, selector->key->length,
                                                (node->tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS));
    }
    
    return false;
}

bool modest_finder_selector_type_class(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    if(node->token == NULL)
        return false;
    
    if(node->tree) {
        return modest_finder_match_attribute_ws(node->token->attr_first,
                                                "class", 5,
                                                selector->key->data, selector->key->length,
                                                (node->tree->compat_mode != MyHTML_TREE_COMPAT_MODE_QUIRKS));
    }
    
    return false;
}

bool modest_finder_selector_type_attribute(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    /* namespace */
    if(selector->ns_entry) {
        if(selector->ns_entry->ns_id != MyHTML_NAMESPACE_ANY && selector->ns_entry->ns_id != node->ns)
            return false;
    }
    
    if(node->token == NULL)
        return false;
    
    mycss_selectors_object_attribute_t *sel_attr = mycss_selector_value_attribute(selector->value);
    
    if(sel_attr) {
        if(sel_attr->value == NULL)
            return false;
        
        if(sel_attr->match < MyCSS_SELECTORS_MATCH_LAST_ENTRY)
            return modest_finder_static_selector_match_map[sel_attr->match](node->token->attr_first,
                                                                            selector->key->data, selector->key->length,
                                                                            sel_attr->value->data, sel_attr->value->length,
                                                                            (sel_attr->mod & MyCSS_SELECTORS_MOD_I));
    }
    else {
        return modest_finder_match_attribute_only_key(node->token->attr_first,
                                                      selector->key->data, selector->key->length);
    }
    
    return false;
}

bool modest_finder_selector_type_pseudo_class_function(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    if(selector->sub_type < MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LAST_ENTRY)
        return modest_finder_static_selector_sub_type_pseudo_class_function_map[selector->sub_type](finder, node, selector, spec);
    
    return false;
}

bool modest_finder_selector_type_pseudo_class(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    if(selector->sub_type < MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_LAST_ENTRY)
        return modest_finder_static_selector_sub_type_pseudo_class_map[selector->sub_type](finder, node, selector, spec);
    
    return false;
}

bool modest_finder_selector_type_pseudo_element_function(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    return false;
}

bool modest_finder_selector_type_pseudo_element(modest_finder_t* finder, myhtml_tree_node_t* node, mycss_selectors_entry_t* selector, mycss_selectors_specificity_t* spec)
{
    return false;
}