| 293 | } |
| 294 | |
| 295 | std::shared_ptr<StyleSheetStyle> |
| 296 | StyleSheet::getStyleFromSelector( const std::string& selector, bool searchBySpecificity ) const { |
| 297 | if ( !searchBySpecificity ) { |
| 298 | for ( const auto& node : mNodes ) |
| 299 | if ( node->getSelector().getName() == selector ) |
| 300 | return node; |
| 301 | } else { |
| 302 | std::vector<std::shared_ptr<StyleSheetStyle>> found; |
| 303 | for ( const auto& node : mNodes ) |
| 304 | if ( node->isMediaValid() && node->getSelector().getName() == selector ) |
| 305 | found.push_back( node ); |
| 306 | if ( !found.empty() ) { |
| 307 | std::sort( found.begin(), found.end(), |
| 308 | []( const std::shared_ptr<StyleSheetStyle>& lhs, |
| 309 | const std::shared_ptr<StyleSheetStyle>& rhs ) { |
| 310 | if ( ( lhs->getMediaQueryList() == nullptr ) != |
| 311 | ( rhs->getMediaQueryList() == nullptr ) ) { |
| 312 | return ( lhs->getMediaQueryList() == nullptr ) > |
| 313 | ( rhs->getMediaQueryList() == nullptr ); |
| 314 | } |
| 315 | return lhs->getSelector().getSpecificity() < |
| 316 | rhs->getSelector().getSpecificity(); |
| 317 | } ); |
| 318 | return found.back(); |
| 319 | } |
| 320 | } |
| 321 | return {}; |
| 322 | } |
| 323 | |
| 324 | bool StyleSheet::updateMediaLists( const MediaFeatures& features ) { |
| 325 | if ( mMediaQueryList.empty() ) |