MCPcopy Create free account
hub / github.com/SpartanJ/eepp / getElementStyles

Method getElementStyles

src/eepp/ui/css/stylesheet.cpp:231–280  ·  view source on GitHub ↗

This is based on the RmlUi implementation.

Source from the content-addressed store, hash-verified

229
230// This is based on the RmlUi implementation.
231std::shared_ptr<ElementDefinition> StyleSheet::getElementStyles( UIWidget* element,
232 const bool& applyPseudo ) const {
233 static StyleSheetStyleVector applicableNodes;
234 applicableNodes.clear();
235
236 const std::string& tag = element->getElementTag();
237 const std::string& id = element->getId();
238
239 std::array<size_t, 4> nodeHash;
240 int numHashes = 2;
241
242 nodeHash[0] = 0;
243 nodeHash[1] = this->nodeHash( tag, "" );
244
245 if ( !id.empty() ) {
246 numHashes = 4;
247 nodeHash[2] = this->nodeHash( "", id );
248 nodeHash[3] = this->nodeHash( tag, id );
249 }
250
251 for ( int i = 0; i < numHashes; i++ ) {
252 auto itNodes = mNodeIndex.find( nodeHash[i] );
253 if ( itNodes != mNodeIndex.end() ) {
254 const StyleSheetStyleVector& nodes = itNodes->second;
255 for ( StyleSheetStyle* node : nodes ) {
256 if ( node->isMediaValid() && node->getSelector().select( element, applyPseudo ) ) {
257 applicableNodes.push_back( node );
258 }
259 }
260 }
261 }
262
263 std::sort( applicableNodes.begin(), applicableNodes.end(), StyleSheetNodeSort );
264
265 if ( applicableNodes.empty() )
266 return nullptr;
267
268 size_t seed = 0;
269 for ( const StyleSheetStyle* node : applicableNodes )
270 HashCombine( seed, node );
271
272 auto cacheIterator = mNodeCache.find( seed );
273 if ( cacheIterator != mNodeCache.end() )
274 return cacheIterator->second;
275
276 auto newDefinition = std::make_shared<ElementDefinition>( applicableNodes );
277 mNodeCache[seed] = newDefinition;
278
279 return newDefinition;
280}
281
282const std::vector<std::shared_ptr<StyleSheetStyle>>& StyleSheet::getStyles() const {
283 return mNodes;

Callers 2

resetGlobalDefinitionMethod · 0.80
onStateChangeMethod · 0.80

Calls 12

nodeHashMethod · 0.95
sortFunction · 0.85
HashCombineFunction · 0.85
isMediaValidMethod · 0.80
push_backMethod · 0.80
getIdMethod · 0.65
clearMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
selectMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected