コード例 #1
0
 private function _mergeValues($sShorthand, $aValues, $aOldProperties, $bImportant)
 {
     $this->styleDeclaration->remove($aOldProperties);
     $oNewValueList = new PropertyValueList($aValues, ' ');
     $oNewProperty = new Property($sShorthand, $oNewValueList);
     $oNewProperty->setIsImportant($bImportant);
     $this->styleDeclaration->append($oNewProperty);
 }
コード例 #2
0
 private function _expandBackgroundShorthand($iPos, $oProperty)
 {
     /*{{{*/
     $oValueList = $oProperty->getValueList();
     // Get a normalized array
     if ($oValueList->getSeparator() === ',' && count($oValueList) > 1) {
         // we have multiple layers
         $aValueList = $oValueList->getItems();
     } else {
         // we have only one value or a space separated list of values
         $aValueList = array($oValueList->getItems());
     }
     $iNumLayers = count($aValueList);
     $aUnfoldedResults = array();
     // background-color only allowed on final layer;
     $color = null;
     foreach ($aValueList as $iLayerIndex => $aValues) {
         // if we have multiple layers, get the values for this layer
         if ($aValues instanceof PropertyValueList) {
             $aValues = $aValues->getItems();
         } else {
             if (!is_array($aValues)) {
                 $aValues = array($aValues);
             }
         }
         $aBgProperties = array();
         $iNumBgPos = 0;
         $iNumBoxValues = 0;
         foreach ($aValues as $mValue) {
             $mValue = Object::getClone($mValue);
             if ($mValue instanceof Value\Url || $mValue instanceof Value\Func || $mValue == "none") {
                 $aBgProperties['background-image'] = $mValue;
             } else {
                 if ($mValue instanceof PropertyValueList) {
                     // bg-pos bg-pos? / bg-size bg-size?
                     $oBgPosValues = $mValue->getFirst();
                     if ($oBgPosValues instanceof PropertyValueList) {
                         $aBgPosValues = $oBgPosValues->getItems();
                     } else {
                         $aBgPosValues = array($oBgPosValues);
                     }
                     $bgpos_valuelist = new PropertyValueList(array($aBgPosValues[0], 'center'), ' ');
                     if (count($aBgPosValues) > 1) {
                         $bgpos_valuelist->replace(1, $aBgPosValues[1]);
                     }
                     $aBgProperties['background-position'] = $bgpos_valuelist;
                     //
                     $oBgSizeValues = $mValue->getLast();
                     if ($oBgSizeValues instanceof PropertyValueList) {
                         $aBgSizeValues = $oBgSizeValues->getItems();
                     } else {
                         $aBgSizeValues = array($oBgSizeValues);
                     }
                     $bgsize_valuelist = new PropertyValueList(array($aBgSizeValues[0], $aBgSizeValues[0]), ' ');
                     if (count($aBgSizeValues) > 1) {
                         $bgsize_valuelist->replace(1, $aBgSizeValues[1]);
                     }
                     $aBgProperties['background-size'] = $bgsize_valuelist;
                 } else {
                     if (in_array($mValue, array('left', 'center', 'right', 'top', 'bottom')) || $mValue instanceof Value\Dimension) {
                         //if ($mValue instanceof Value\Dimension) $mValue = clone $mValue;
                         if ($iNumBgPos === 0) {
                             $aBgProperties['background-position'] = new PropertyValueList(array($mValue, 'center'), ' ');
                         } else {
                             $aBgProperties['background-position']->replace(1, $mValue);
                         }
                         $iNumBgPos++;
                     } else {
                         if (in_array($mValue, array('repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'space', 'round'))) {
                             $aBgProperties['background-repeat'] = $mValue;
                         } else {
                             if (in_array($mValue, array('scroll', 'fixed', 'local'))) {
                                 $aBgProperties['background-attachment'] = $mValue;
                             } else {
                                 if (in_array($mValue, array('border-box', 'padding-box', 'content-box'))) {
                                     if ($iNumBoxValues === 0) {
                                         $aBgProperties['background-origin'] = $mValue;
                                         $aBgProperties['background-clip'] = $mValue;
                                     } else {
                                         $aBgProperties['background-clip'] = $mValue;
                                     }
                                     $iNumBoxValues++;
                                 } else {
                                     if ($mValue instanceof Value\Color) {
                                         if ($iLayerIndex == $iNumLayers - 1) {
                                             $color = $mValue;
                                         } else {
                                             if (empty($aBgProperties)) {
                                                 $aBgProperties['background-image'] = "none";
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $aUnfoldedResults[] = $aBgProperties;
     }
     if ($color) {
         $aUnfoldedResults[$iNumLayers - 1]['background-color'] = $color;
     }
     $aFoldedResults = array();
     foreach ($aUnfoldedResults as $i => $result) {
         foreach ($result as $propname => $propval) {
             $aFoldedResults[$propname][$i] = $propval;
         }
     }
     foreach ($aFoldedResults as $propname => $aValues) {
         if ($this->_canAddShorthandExpansion($oProperty, $propname)) {
             $separator = count($aValues) === 0 ? ' ' : ',';
             $oValueList = new PropertyValueList($aValues, $separator);
             $oNewProp = new Property($propname, $oValueList);
             $oNewProp->setIsImportant($oProperty->getIsImportant());
             $this->styleDeclaration->insertAfter($oNewProp, $oProperty);
         }
     }
     $this->styleDeclaration->remove($oProperty);
 }