From 4cd44dddcd94e7571e314ebd9c40a5993e8bd8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 16 Apr 2019 00:14:59 -0300 Subject: [PATCH] Minor clean up. --HG-- branch : dev-css --- .hgignore | 2 + include/eepp/ui/uistyle.hpp | 4 +- src/eepp/ui/css/stylesheet.cpp | 38 +++++++------- src/eepp/ui/css/stylesheetselector.cpp | 3 +- src/eepp/ui/css/stylesheetstyle.cpp | 4 +- src/eepp/ui/uistyle.cpp | 68 +++++++++----------------- 6 files changed, 52 insertions(+), 67 deletions(-) diff --git a/.hgignore b/.hgignore index 56dbef0ce..d0e186abb 100644 --- a/.hgignore +++ b/.hgignore @@ -51,3 +51,5 @@ bin/libeepp.dylib .idea eepp.kdev4 bin/eepp-MapEditor* +eepp.tags +eepp.geany diff --git a/include/eepp/ui/uistyle.hpp b/include/eepp/ui/uistyle.hpp index ef51719eb..737fa18f4 100644 --- a/include/eepp/ui/uistyle.hpp +++ b/include/eepp/ui/uistyle.hpp @@ -31,7 +31,7 @@ class EE_API UIStyle : public UIState { Ease::Interpolation getTimingFunction() const { return timingFunction; } - const Time& getDelay() const { return delay; }; + const Time& getDelay() const { return delay; } const Time& getDuration() const { return duration; } @@ -77,6 +77,8 @@ class EE_API UIStyle : public UIState { std::vector mTransitionAttributes; TransitionsMap mTransitions; + void tryApplyStyle( const CSS::StyleSheetStyle& style ); + void updateState(); void parseTransitions(); diff --git a/src/eepp/ui/css/stylesheet.cpp b/src/eepp/ui/css/stylesheet.cpp index 58aca908d..9746e0ade 100644 --- a/src/eepp/ui/css/stylesheet.cpp +++ b/src/eepp/ui/css/stylesheet.cpp @@ -20,8 +20,8 @@ void StyleSheet::combineStyle( const StyleSheetStyle& node ) { auto currentNode = nodeIt->second; if ( node.getSelector().getSpecificity() > currentNode.getSelector().getSpecificity() ) { - for ( auto pit = node.getProperties().begin(); pit != node.getProperties().end(); ++pit ) - currentNode.setProperty( pit->second ); + for ( auto& pit : node.getProperties() ) + currentNode.setProperty( pit.second ); } } } @@ -31,33 +31,35 @@ bool StyleSheet::isEmpty() const { } void StyleSheet::print() { - for ( auto it = mNodes.begin(); it != mNodes.end(); ++it ) { - StyleSheetStyle& style = it->second; + for ( auto& it : mNodes ) { + StyleSheetStyle& style = it.second; style.print(); } } void StyleSheet::combineStyleSheet( const StyleSheet& styleSheet ) { - for ( auto it = styleSheet.getStyles().begin(); it != styleSheet.getStyles().end(); ++it ) { - combineStyle( it->second ); + for ( auto& it : styleSheet.getStyles() ) { + combineStyle( it.second ); } } StyleSheet::StyleSheetPseudoClassProperties StyleSheet::getElementPropertiesByState( StyleSheetElement * element ) { StyleSheetPseudoClassProperties propertiesSelectedByPseudoClass; - for ( auto it = mNodes.begin(); it != mNodes.end(); ++it ) { - StyleSheetStyle& node = it->second; + for ( const auto& it : mNodes ) { + const StyleSheetStyle& node = it.second; const StyleSheetSelector& selector = node.getSelector(); if ( selector.isCacheable() && selector.select( element, false ) ) { - for ( auto pit = node.getProperties().begin(); pit != node.getProperties().end(); ++pit ) { + for ( const auto& pit : node.getProperties() ) { StyleSheetProperties& pseudoClassProperties = propertiesSelectedByPseudoClass[selector.getPseudoClass()]; - auto pcit = pseudoClassProperties.find( pit->second.getName() ); + const StyleSheetProperty& property = pit.second; + const auto& pcit = pseudoClassProperties.find( property.getName() ); + const StyleSheetProperty& propertyRight = pcit->second; - if ( pcit == pseudoClassProperties.end() || pit->second.getSpecificity() >= pcit->second.getSpecificity() ) { - pseudoClassProperties[ pit->second.getName() ] = pit->second; + if ( pcit == pseudoClassProperties.end() || property.getSpecificity() >= propertyRight.getSpecificity() ) { + pseudoClassProperties[ property.getName() ] = property; } } } @@ -69,8 +71,8 @@ StyleSheet::StyleSheetPseudoClassProperties StyleSheet::getElementPropertiesBySt StyleSheetStyleVector StyleSheet::getElementStyles( StyleSheetElement * element , const bool& applyPseudo ) { StyleSheetStyleVector styles; - for ( auto it = mNodes.begin(); it != mNodes.end(); ++it ) { - StyleSheetStyle& node = it->second; + for ( const auto& it : mNodes ) { + const StyleSheetStyle& node = it.second; const StyleSheetSelector& selector = node.getSelector(); if ( selector.select( element, applyPseudo ) ) { @@ -84,8 +86,8 @@ StyleSheetStyleVector StyleSheet::getElementStyles( StyleSheetElement * element StyleSheetStyleVector StyleSheet::getCacheableElementStyles( StyleSheetElement * element, const bool& applyPseudo ) { StyleSheetStyleVector styles; - for ( auto it = mNodes.begin(); it != mNodes.end(); ++it ) { - StyleSheetStyle& node = it->second; + for ( const auto& it : mNodes ) { + const StyleSheetStyle& node = it.second; const StyleSheetSelector& selector = node.getSelector(); if ( selector.isCacheable() && selector.select( element, applyPseudo ) ) { @@ -99,8 +101,8 @@ StyleSheetStyleVector StyleSheet::getCacheableElementStyles( StyleSheetElement * StyleSheetStyleVector StyleSheet::getNoncacheableElementStyles( StyleSheetElement * element, const bool& applyPseudo ) { StyleSheetStyleVector styles; - for ( auto it = mNodes.begin(); it != mNodes.end(); ++it ) { - StyleSheetStyle& node = it->second; + for ( const auto& it : mNodes ) { + const StyleSheetStyle& node = it.second; const StyleSheetSelector& selector = node.getSelector(); if ( !selector.isCacheable() && selector.select( element, applyPseudo ) ) { diff --git a/src/eepp/ui/css/stylesheetselector.cpp b/src/eepp/ui/css/stylesheetselector.cpp index 694148895..8bfbedbf2 100644 --- a/src/eepp/ui/css/stylesheetselector.cpp +++ b/src/eepp/ui/css/stylesheetselector.cpp @@ -25,13 +25,14 @@ const std::string &StyleSheetSelector::getName() const { const std::string& StyleSheetSelector::getPseudoClass() const { return mPseudoClass; -}; +} const Uint32& StyleSheetSelector::getSpecificity() const { return mSpecificity; } void removeExtraSpaces( std::string& string ) { + // @TODO: Optimize this string = String::trim( string ); String::replaceAll( string, " ", " " ); String::replaceAll( string, " ", " " ); diff --git a/src/eepp/ui/css/stylesheetstyle.cpp b/src/eepp/ui/css/stylesheetstyle.cpp index 9d2ce4770..3043bc85f 100644 --- a/src/eepp/ui/css/stylesheetstyle.cpp +++ b/src/eepp/ui/css/stylesheetstyle.cpp @@ -26,11 +26,11 @@ void StyleSheetStyle::print() { std::cout << "}" << std::endl; } -const StyleSheetSelector &StyleSheetStyle::getSelector() const { +const StyleSheetSelector& StyleSheetStyle::getSelector() const { return mSelector; } -const StyleSheetProperties &StyleSheetStyle::getProperties() const { +const StyleSheetProperties& StyleSheetStyle::getProperties() const { return mProperties; } diff --git a/src/eepp/ui/uistyle.cpp b/src/eepp/ui/uistyle.cpp index 286d91e36..379284f28 100644 --- a/src/eepp/ui/uistyle.cpp +++ b/src/eepp/ui/uistyle.cpp @@ -61,10 +61,8 @@ void UIStyle::load() { void UIStyle::addStyleSheetProperties( const CSS::StyleSheetProperties& properties ) { if ( !properties.empty() ) { - for ( auto it = properties.begin(); it != properties.end(); ++it ) { - CSS::StyleSheetProperty property = it->second; - - addStyleSheetProperty( property ); + for ( const auto& it : properties ) { + addStyleSheetProperty( it.second ); } } } @@ -85,63 +83,43 @@ UIStyle::TransitionInfo UIStyle::getTransition( const std::string& propertyName return TransitionInfo(); } +void UIStyle::tryApplyStyle( const StyleSheetStyle& style ) { + if ( style.getSelector().select( mWidget ) ) { + for ( const auto& prop : style.getProperties() ) { + const StyleSheetProperty& property = prop.second; + const auto& it = mProperties.find( property.getName() ); + + if ( it == mProperties.end() || property.getSpecificity() >= it->second.getSpecificity() ) { + mProperties[ property.getName() ] = property; + + if ( String::startsWith( property.getName(), "transition" ) ) + mTransitionAttributes.push_back( property ); + } + } + } +} + void UIStyle::onStateChange() { if ( NULL != mWidget ) { mProperties.clear(); mTransitionAttributes.clear(); - if ( mElementStyle.getSelector().select( mWidget ) ) { - for ( auto& prop : mElementStyle.getProperties() ) { - auto& property = prop.second; - auto it = mProperties.find( property.getName() ); - - if ( it == mProperties.end() || property.getSpecificity() >= it->second.getSpecificity() ) { - mProperties[ property.getName() ] = property; - - if ( String::startsWith( property.getName(), "transition" ) ) - mTransitionAttributes.push_back( property ); - } - } - } + tryApplyStyle( mElementStyle ); for ( auto& style : mCacheableStyles ) { - if ( style.getSelector().select( mWidget ) ) { - for ( auto& prop : style.getProperties() ) { - auto& property = prop.second; - auto it = mProperties.find( property.getName() ); - - if ( it == mProperties.end() || property.getSpecificity() >= it->second.getSpecificity() ) { - mProperties[ property.getName() ] = property; - - if ( String::startsWith( property.getName(), "transition" ) ) - mTransitionAttributes.push_back( property ); - } - } - } + tryApplyStyle( style ); } for ( auto& style : mNoncacheableStyles ) { - if ( style.getSelector().select( mWidget ) ) { - for ( auto& prop : style.getProperties() ) { - auto& property = prop.second; - auto it = mProperties.find( property.getName() ); - - if ( it == mProperties.end() || property.getSpecificity() >= it->second.getSpecificity() ) { - mProperties[ property.getName() ] = property; - - if ( String::startsWith( property.getName(), "transition" ) ) - mTransitionAttributes.push_back( property ); - } - } - } + tryApplyStyle( style ); } parseTransitions(); mWidget->beginAttributesTransaction(); - for ( auto& prop : mProperties ) { - auto& property = prop.second; + for ( const auto& prop : mProperties ) { + const StyleSheetProperty& property = prop.second; mWidget->setAttribute( property.getName(), property.getValue(), mCurrentState ); }