| 118 | } |
| 119 | |
| 120 | bool StyleSheetSelector::select( UIWidget* element, const bool& applyPseudo ) const { |
| 121 | if ( mSelectorRules.empty() ) |
| 122 | return false; |
| 123 | |
| 124 | UIWidget* curElement = element; |
| 125 | |
| 126 | for ( size_t i = 0; i < mSelectorRules.size(); i++ ) { |
| 127 | const StyleSheetSelectorRule& selectorRule = mSelectorRules[i]; |
| 128 | |
| 129 | switch ( selectorRule.getPatternMatch() ) { |
| 130 | case StyleSheetSelectorRule::ANY: { |
| 131 | if ( !selectorRule.matches( curElement, applyPseudo ) ) |
| 132 | return false; |
| 133 | |
| 134 | break; // continue evaluating |
| 135 | } |
| 136 | case StyleSheetSelectorRule::DESCENDANT: { |
| 137 | bool foundDescendant = false; |
| 138 | |
| 139 | curElement = curElement->getStyleSheetParentElement(); |
| 140 | |
| 141 | while ( NULL != curElement && !foundDescendant ) { |
| 142 | if ( selectorRule.matches( curElement, applyPseudo ) ) { |
| 143 | foundDescendant = true; |
| 144 | } else { |
| 145 | curElement = curElement->getStyleSheetParentElement(); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if ( !foundDescendant ) |
| 150 | return false; |
| 151 | |
| 152 | break; // continue evaluating |
| 153 | } |
| 154 | case StyleSheetSelectorRule::CHILD: { |
| 155 | curElement = curElement->getStyleSheetParentElement(); |
| 156 | |
| 157 | if ( NULL == curElement || !selectorRule.matches( curElement, applyPseudo ) ) |
| 158 | return false; |
| 159 | |
| 160 | break; // continue evaluating |
| 161 | } |
| 162 | case StyleSheetSelectorRule::PREVIOUS_SIBLING: { |
| 163 | curElement = curElement->getStyleSheetPreviousSiblingElement(); |
| 164 | |
| 165 | if ( NULL == curElement || !selectorRule.matches( curElement, applyPseudo ) ) |
| 166 | return false; |
| 167 | |
| 168 | break; // continue evaluating |
| 169 | } |
| 170 | case StyleSheetSelectorRule::DIRECT_SIBLING: { |
| 171 | curElement = curElement->getStyleSheetNextSiblingElement(); |
| 172 | |
| 173 | if ( NULL == curElement || !selectorRule.matches( curElement, applyPseudo ) ) |
| 174 | return false; |
| 175 | |
| 176 | break; // continue evaluating |
| 177 | } |
no test coverage detected