void CSSToStyleMap::mapNinePieceImageSlice(StyleResolverState&, CSSValue* value, NinePieceImage& image) { if (!value || !value->isBorderImageSliceValue()) return; // Retrieve the border image value. CSSBorderImageSliceValue* borderImageSlice = toCSSBorderImageSliceValue(value); // Set up a length box to represent our image slices. LengthBox box; Quad* slices = borderImageSlice->slices(); if (slices->top()->isPercentage()) box.m_top = Length(slices->top()->getDoubleValue(), Percent); else box.m_top = Length(slices->top()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); if (slices->bottom()->isPercentage()) box.m_bottom = Length(slices->bottom()->getDoubleValue(), Percent); else box.m_bottom = Length((int)slices->bottom()->getFloatValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); if (slices->left()->isPercentage()) box.m_left = Length(slices->left()->getDoubleValue(), Percent); else box.m_left = Length(slices->left()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); if (slices->right()->isPercentage()) box.m_right = Length(slices->right()->getDoubleValue(), Percent); else box.m_right = Length(slices->right()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); image.setImageSlices(box); // Set our fill mode. image.setFill(borderImageSlice->m_fill); }
void CSSToStyleMap::mapNinePieceImageSlice(CSSValue& value, NinePieceImage& image) { if (!is<CSSBorderImageSliceValue>(value)) return; // Retrieve the border image value. auto& borderImageSlice = downcast<CSSBorderImageSliceValue>(value); // Set up a length box to represent our image slices. LengthBox box; Quad* slices = borderImageSlice.slices(); if (slices->top()->isPercentage()) box.top() = Length(slices->top()->getDoubleValue(), Percent); else box.top() = Length(slices->top()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); if (slices->bottom()->isPercentage()) box.bottom() = Length(slices->bottom()->getDoubleValue(), Percent); else box.bottom() = Length((int)slices->bottom()->getFloatValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); if (slices->left()->isPercentage()) box.left() = Length(slices->left()->getDoubleValue(), Percent); else box.left() = Length(slices->left()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); if (slices->right()->isPercentage()) box.right() = Length(slices->right()->getDoubleValue(), Percent); else box.right() = Length(slices->right()->getIntValue(CSSPrimitiveValue::CSS_NUMBER), Fixed); image.setImageSlices(box); // Set our fill mode. image.setFill(borderImageSlice.m_fill); }
BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(StyleResolverState& state, CSSValue* value) { if (!value || !value->isPrimitiveValue()) return BorderImageLengthBox(Length(Auto)); Quad* slices = toCSSPrimitiveValue(value)->getQuadValue(); // Set up a border image length box to represent our image slices. return BorderImageLengthBox( toBorderImageLength(*slices->top(), state.cssToLengthConversionData()), toBorderImageLength(*slices->right(), state.cssToLengthConversionData()), toBorderImageLength(*slices->bottom(), state.cssToLengthConversionData()), toBorderImageLength(*slices->left(), state.cssToLengthConversionData())); }
BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) const { if (!value || !value->isPrimitiveValue()) return BorderImageLengthBox(Length(Auto)); float zoom = useSVGZoomRules() ? 1.0f : cssToLengthConversionData().zoom(); Quad* slices = toCSSPrimitiveValue(value)->getQuadValue(); // Set up a border image length box to represent our image slices. const CSSToLengthConversionData& conversionData = cssToLengthConversionData().copyWithAdjustedZoom(zoom); return BorderImageLengthBox( toBorderImageLength(*slices->top(), conversionData), toBorderImageLength(*slices->right(), conversionData), toBorderImageLength(*slices->bottom(), conversionData), toBorderImageLength(*slices->left(), conversionData)); }
LengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) { if (!is<CSSPrimitiveValue>(value)) return LengthBox(); // Get our zoom value. CSSToLengthConversionData conversionData = useSVGZoomRules() ? m_resolver->state().cssToLengthConversionData().copyWithAdjustedZoom(1.0f) : m_resolver->state().cssToLengthConversionData(); // Retrieve the primitive value. CSSPrimitiveValue& borderWidths = downcast<CSSPrimitiveValue>(*value); // Set up a length box to represent our image slices. LengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below. Quad* slices = borderWidths.getQuadValue(); if (slices->top()->isNumber()) box.m_top = Length(slices->top()->getIntValue(), Relative); else if (slices->top()->isPercentage()) box.m_top = Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->top()->getValueID() != CSSValueAuto) box.m_top = slices->top()->computeLength<Length>(conversionData); if (slices->right()->isNumber()) box.m_right = Length(slices->right()->getIntValue(), Relative); else if (slices->right()->isPercentage()) box.m_right = Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->right()->getValueID() != CSSValueAuto) box.m_right = slices->right()->computeLength<Length>(conversionData); if (slices->bottom()->isNumber()) box.m_bottom = Length(slices->bottom()->getIntValue(), Relative); else if (slices->bottom()->isPercentage()) box.m_bottom = Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->bottom()->getValueID() != CSSValueAuto) box.m_bottom = slices->bottom()->computeLength<Length>(conversionData); if (slices->left()->isNumber()) box.m_left = Length(slices->left()->getIntValue(), Relative); else if (slices->left()->isPercentage()) box.m_left = Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->left()->getValueID() != CSSValueAuto) box.m_left = slices->left()->computeLength<Length>(conversionData); return box; }
LengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) { if (!value || !value->isPrimitiveValue()) return LengthBox(); // Get our zoom value. float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom(); // Retrieve the primitive value. CSSPrimitiveValue* borderWidths = static_cast<CSSPrimitiveValue*>(value); // Set up a length box to represent our image slices. LengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below. Quad* slices = borderWidths->getQuadValue(); if (slices->top()->isNumber()) box.m_top = Length(slices->top()->getIntValue(), Relative); else if (slices->top()->isPercentage()) box.m_top = Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->top()->getValueID() != CSSValueAuto) box.m_top = slices->top()->computeLength<Length>(style(), rootElementStyle(), zoom); if (slices->right()->isNumber()) box.m_right = Length(slices->right()->getIntValue(), Relative); else if (slices->right()->isPercentage()) box.m_right = Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->right()->getValueID() != CSSValueAuto) box.m_right = slices->right()->computeLength<Length>(style(), rootElementStyle(), zoom); if (slices->bottom()->isNumber()) box.m_bottom = Length(slices->bottom()->getIntValue(), Relative); else if (slices->bottom()->isPercentage()) box.m_bottom = Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->bottom()->getValueID() != CSSValueAuto) box.m_bottom = slices->bottom()->computeLength<Length>(style(), rootElementStyle(), zoom); if (slices->left()->isNumber()) box.m_left = Length(slices->left()->getIntValue(), Relative); else if (slices->left()->isPercentage()) box.m_left = Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->left()->getValueID() != CSSValueAuto) box.m_left = slices->left()->computeLength<Length>(style(), rootElementStyle(), zoom); return box; }
String CSSPrimitiveValue::customCssText() const { // FIXME: return the original value instead of a generated one (e.g. color // name if it was specified) - check what spec says about this if (m_hasCachedCSSText) { ASSERT(cssTextCache().contains(this)); return cssTextCache().get(this); } String text; switch (m_primitiveUnitType) { case CSS_UNKNOWN: // FIXME break; case CSS_NUMBER: case CSS_PARSER_INTEGER: text = formatNumber(m_value.num); break; case CSS_PERCENTAGE: text = formatNumber(m_value.num) + "%"; break; case CSS_EMS: text = formatNumber(m_value.num) + "em"; break; case CSS_EXS: text = formatNumber(m_value.num) + "ex"; break; case CSS_REMS: text = formatNumber(m_value.num) + "rem"; break; case CSS_PX: text = formatNumber(m_value.num) + "px"; break; case CSS_CM: text = formatNumber(m_value.num) + "cm"; break; #if ENABLE(CSS_IMAGE_RESOLUTION) case CSS_DPPX: text = formatNumber(m_value.num) + "dppx"; break; case CSS_DPI: text = formatNumber(m_value.num) + "dpi"; break; case CSS_DPCM: text = formatNumber(m_value.num) + "dpcm"; break; #endif case CSS_MM: text = formatNumber(m_value.num) + "mm"; break; case CSS_IN: text = formatNumber(m_value.num) + "in"; break; case CSS_PT: text = formatNumber(m_value.num) + "pt"; break; case CSS_PC: text = formatNumber(m_value.num) + "pc"; break; case CSS_DEG: text = formatNumber(m_value.num) + "deg"; break; case CSS_RAD: text = formatNumber(m_value.num) + "rad"; break; case CSS_GRAD: text = formatNumber(m_value.num) + "grad"; break; case CSS_MS: text = formatNumber(m_value.num) + "ms"; break; case CSS_S: text = formatNumber(m_value.num) + "s"; break; case CSS_HZ: text = formatNumber(m_value.num) + "hz"; break; case CSS_KHZ: text = formatNumber(m_value.num) + "khz"; break; case CSS_TURN: text = formatNumber(m_value.num) + "turn"; break; case CSS_DIMENSION: // FIXME break; case CSS_STRING: text = quoteCSSStringIfNeeded(m_value.string); break; case CSS_URI: text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; break; case CSS_IDENT: text = valueOrPropertyName(m_value.ident); break; case CSS_ATTR: { DEFINE_STATIC_LOCAL(const String, attrParen, ("attr(")); StringBuilder result; result.reserveCapacity(6 + m_value.string->length()); result.append(attrParen); result.append(m_value.string); result.append(')'); text = result.toString(); break; } case CSS_COUNTER_NAME: text = "counter("; text += m_value.string; text += ")"; break; case CSS_COUNTER: { DEFINE_STATIC_LOCAL(const String, counterParen, ("counter(")); DEFINE_STATIC_LOCAL(const String, countersParen, ("counters(")); DEFINE_STATIC_LOCAL(const String, commaSpace, (", ")); StringBuilder result; String separator = m_value.counter->separator(); result.append(separator.isEmpty() ? counterParen : countersParen); result.append(m_value.counter->identifier()); if (!separator.isEmpty()) { result.append(commaSpace); result.append(quoteCSSStringIfNeeded(separator)); } String listStyle = m_value.counter->listStyle(); if (!listStyle.isEmpty()) { result.append(commaSpace); result.append(listStyle); } result.append(')'); text = result.toString(); break; } case CSS_RECT: { DEFINE_STATIC_LOCAL(const String, rectParen, ("rect(")); Rect* rectVal = getRectValue(); StringBuilder result; result.reserveCapacity(32); result.append(rectParen); result.append(rectVal->top()->cssText()); result.append(' '); result.append(rectVal->right()->cssText()); result.append(' '); result.append(rectVal->bottom()->cssText()); result.append(' '); result.append(rectVal->left()->cssText()); result.append(')'); text = result.toString(); break; } case CSS_QUAD: { Quad* quadVal = getQuadValue(); Vector<UChar> result; result.reserveInitialCapacity(32); append(result, quadVal->top()->cssText()); if (quadVal->right() != quadVal->top() || quadVal->bottom() != quadVal->top() || quadVal->left() != quadVal->top()) { result.append(' '); append(result, quadVal->right()->cssText()); if (quadVal->bottom() != quadVal->top() || quadVal->right() != quadVal->left()) { result.append(' '); append(result, quadVal->bottom()->cssText()); if (quadVal->left() != quadVal->right()) { result.append(' '); append(result, quadVal->left()->cssText()); } } } text = String::adopt(result); break; } case CSS_RGBCOLOR: case CSS_PARSER_HEXCOLOR: { DEFINE_STATIC_LOCAL(const String, commaSpace, (", ")); DEFINE_STATIC_LOCAL(const String, rgbParen, ("rgb(")); DEFINE_STATIC_LOCAL(const String, rgbaParen, ("rgba(")); RGBA32 rgbColor = m_value.rgbcolor; if (m_primitiveUnitType == CSS_PARSER_HEXCOLOR) Color::parseHexColor(m_value.string, rgbColor); Color color(rgbColor); Vector<UChar> result; result.reserveInitialCapacity(32); if (color.hasAlpha()) append(result, rgbaParen); else append(result, rgbParen); appendNumber(result, static_cast<unsigned char>(color.red())); append(result, commaSpace); appendNumber(result, static_cast<unsigned char>(color.green())); append(result, commaSpace); appendNumber(result, static_cast<unsigned char>(color.blue())); if (color.hasAlpha()) { append(result, commaSpace); append(result, String::number(color.alpha() / 255.0f)); } result.append(')'); text = String::adopt(result); break; } case CSS_PAIR: text = m_value.pair->first()->cssText(); if (m_value.pair->second() != m_value.pair->first()) { text += " "; text += m_value.pair->second()->cssText(); } break; #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(WIDGET_REGION) case CSS_DASHBOARD_REGION: for (DashboardRegion* region = getDashboardRegionValue(); region; region = region->m_next.get()) { if (!text.isEmpty()) text.append(' '); #if ENABLE(DASHBOARD_SUPPORT) && ENABLE(WIDGET_REGION) text += region->m_cssFunctionName; #elif ENABLE(DASHBOARD_SUPPORT) text += "dashboard-region("; #else text += "region("; #endif text += region->m_label; if (region->m_isCircle) text += " circle"; else if (region->m_isRectangle) text += " rectangle"; else break; if (region->top()->m_primitiveUnitType == CSS_IDENT && region->top()->getIdent() == CSSValueInvalid) { ASSERT(region->right()->m_primitiveUnitType == CSS_IDENT); ASSERT(region->bottom()->m_primitiveUnitType == CSS_IDENT); ASSERT(region->left()->m_primitiveUnitType == CSS_IDENT); ASSERT(region->right()->getIdent() == CSSValueInvalid); ASSERT(region->bottom()->getIdent() == CSSValueInvalid); ASSERT(region->left()->getIdent() == CSSValueInvalid); } else { text.append(' '); text += region->top()->cssText() + " "; text += region->right()->cssText() + " "; text += region->bottom()->cssText() + " "; text += region->left()->cssText(); } text += ")"; } break; #endif case CSS_PARSER_OPERATOR: { char c = static_cast<char>(m_value.ident); text = String(&c, 1U); break; } case CSS_PARSER_IDENTIFIER: text = quoteCSSStringIfNeeded(m_value.string); break; case CSS_CALC: text = m_value.calc->cssText(); break; case CSS_SHAPE: text = m_value.shape->cssText(); break; case CSS_VW: text = formatNumber(m_value.num) + "vw"; break; case CSS_VH: text = formatNumber(m_value.num) + "vh"; break; case CSS_VMIN: text = formatNumber(m_value.num) + "vmin"; break; #if ENABLE(CSS_VARIABLES) case CSS_VARIABLE_NAME: text = "-webkit-var("; text += m_value.string; text += ")"; break; #endif } ASSERT(!cssTextCache().contains(this)); cssTextCache().set(this, text); m_hasCachedCSSText = true; return text; }