/** * Transforms "white-space: pre-wrap" into browser specific counterparts. */ private static function whiteSpace(css_property $property, css_prefixer $prefixer) { if (strtolower($property->value) === "pre-wrap") { // Firefox < 3 if ($prefixer->mozilla) { $property->insert_after("white-space", "-moz-pre-wrap"); } // Webkit if ($prefixer->webkit) { $property->insert_after("white-space", "-webkit-pre-wrap"); } if ($prefixer->opera) { // Opera >= 4 <= 6 $property->insert_after("white-space", "-pre-wrap"); // Opera >= 7 $property->insert_after("white-space", "-o-pre-wrap"); } // Internet Explorer >= 5.5 if ($prefixer->msie) { $property->insert_after("word-wrap", "break-word"); } } }
private function _shorthand(css_property $property) { $shorthands = array('background' => array('background-color', 'background-image', 'background-repeat', 'background-position', 'background-attachment'), 'font' => array('font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', 'font-family'), 'margin' => array('margin-top', 'margin-right', 'margin-bottom', 'margin-left'), 'padding' => array('padding-top', 'padding-right', 'padding-bottom', 'padding-left'), 'list-style' => array('list-style-type', 'list-style-position', 'list-style-image'), 'border-width' => array('border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width'), 'border-radius' => array('border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius')); foreach ($shorthands as $shorthand => $shorthand_properties) { if (in_array($property->name, $shorthand_properties)) { //All properties must be defined in order to use the shorthand version $properties = array(); $siblings = $property->siblings('css_property', true); foreach ($shorthand_properties as $name) { $found = false; foreach ($siblings as $sibling) { if ($sibling->name == $name) { $properties[] = $sibling; $found = true; break; } } if (!$found) { break; } } if ($found && count($properties) == count($shorthand_properties)) { //Replace with shorthand $values = array(); foreach ($properties as $p) { $values[] = $p->value; if ($p != $property) { $p->remove(); } } $property->name = $shorthand; $property->value = implode(' ', $values); } } } }