| 1756 | } |
| 1757 | |
| 1758 | void UIWidget::propagateInheritedProperty( const CSS::StyleSheetProperty& property ) { |
| 1759 | CSS::StyleSheetProperty propToPropagate = property; |
| 1760 | |
| 1761 | if ( property.getPropertyDefinition() && |
| 1762 | property.getPropertyDefinition()->getPropertyId() == PropertyId::FontSize ) { |
| 1763 | StyleSheetLength length( property.value() ); |
| 1764 | Float pxSize = 0; |
| 1765 | |
| 1766 | if ( length.getUnit() == StyleSheetLength::Unit::Rem ) { |
| 1767 | Float rootFontSize = 12.f; |
| 1768 | if ( getUISceneNode() != NULL ) { |
| 1769 | UIWidget* docRoot = this; |
| 1770 | while ( docRoot->getParent() && docRoot->getParent()->isWidget() ) |
| 1771 | docRoot = docRoot->getParent()->asType<UIWidget>(); |
| 1772 | rootFontSize = getAbsoluteFontSize( docRoot ); |
| 1773 | } |
| 1774 | pxSize = length.getValue() * rootFontSize; |
| 1775 | } else if ( length.getUnit() == StyleSheetLength::Unit::Em || |
| 1776 | length.getUnit() == StyleSheetLength::Unit::Percentage ) { |
| 1777 | Float parentFontSize = 12.f; |
| 1778 | Node* parentNode = getParent(); |
| 1779 | while ( parentNode ) { |
| 1780 | if ( parentNode->isWidget() ) { |
| 1781 | parentFontSize = getAbsoluteFontSize( parentNode->asType<UIWidget>() ); |
| 1782 | break; |
| 1783 | } |
| 1784 | parentNode = parentNode->getParent(); |
| 1785 | } |
| 1786 | if ( length.getUnit() == StyleSheetLength::Unit::Em ) |
| 1787 | pxSize = length.getValue() * parentFontSize; |
| 1788 | else |
| 1789 | pxSize = ( length.getValue() / 100.f ) * parentFontSize; |
| 1790 | } else { |
| 1791 | pxSize = lengthFromValue( property ); |
| 1792 | } |
| 1793 | |
| 1794 | propToPropagate = CSS::StyleSheetProperty( |
| 1795 | property.getName(), String::fromFloat( PixelDensity::pxToDp( pxSize ), "dp" ), |
| 1796 | property.getSpecificity() ); |
| 1797 | } |
| 1798 | |
| 1799 | Node* child = getFirstChild(); |
| 1800 | while ( child ) { |
| 1801 | if ( child->isWidget() ) { |
| 1802 | UIWidget* childWidget = child->asType<UIWidget>(); |
| 1803 | UIStyle* childStyle = childWidget->getUIStyle(); |
| 1804 | // Only propagate if the child doesn't explicitly override it |
| 1805 | if ( childStyle && !childStyle->hasLocalProperty( |
| 1806 | property.getPropertyDefinition()->getPropertyId() ) ) { |
| 1807 | childWidget->applyProperty( propToPropagate ); |
| 1808 | childWidget->propagateInheritedProperty( propToPropagate ); |
| 1809 | } |
| 1810 | } |
| 1811 | child = child->getNextNode(); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { |
no test coverage detected