From 23bebc9a8b14dc3becb3de4c9a44663750a7f029 Mon Sep 17 00:00:00 2001 From: "eric@webkit.org" Date: Mon, 25 Jun 2012 17:36:38 +0000 Subject: [PATCH] Split map* functions out of StyleResolver into a helper object https://bugs.webkit.org/show_bug.cgi?id=89881 Reviewed by Daniel Bates. These map* functions are completely independent of the rest of StyleResolver and only exist to serve StyleBuilder. CSSToStyleMap doesn't even want to have a StyleResolver pointer, but currently needs one to access the resolve-lifetime caches for the current resolve. Once we split out that per-resolve state into some sort of ResolveState/ResolveInfo object (akin to PaintInfo/LayoutState) then this object will be even simpler. No behavioral change, thus no tests. * CMakeLists.txt: * GNUmakefile.list.am: * WebCore.gypi: * WebCore.vcproj/WebCore.vcproj: * WebCore.xcodeproj/project.pbxproj: * css/CSSToStyleMap.cpp: Added. (WebCore): (WebCore::CSSToStyleMap::style): (WebCore::CSSToStyleMap::rootElementStyle): (WebCore::CSSToStyleMap::useSVGZoomRules): (WebCore::CSSToStyleMap::styleImage): (WebCore::CSSToStyleMap::mapFillAttachment): (WebCore::CSSToStyleMap::mapFillClip): (WebCore::CSSToStyleMap::mapFillComposite): (WebCore::CSSToStyleMap::mapFillOrigin): (WebCore::CSSToStyleMap::mapFillImage): (WebCore::CSSToStyleMap::mapFillRepeatX): (WebCore::CSSToStyleMap::mapFillRepeatY): (WebCore::CSSToStyleMap::mapFillSize): (WebCore::CSSToStyleMap::mapFillXPosition): (WebCore::CSSToStyleMap::mapFillYPosition): (WebCore::CSSToStyleMap::mapAnimationDelay): (WebCore::CSSToStyleMap::mapAnimationDirection): (WebCore::CSSToStyleMap::mapAnimationDuration): (WebCore::CSSToStyleMap::mapAnimationFillMode): (WebCore::CSSToStyleMap::mapAnimationIterationCount): (WebCore::CSSToStyleMap::mapAnimationName): (WebCore::CSSToStyleMap::mapAnimationPlayState): (WebCore::CSSToStyleMap::mapAnimationProperty): (WebCore::CSSToStyleMap::mapAnimationTimingFunction): (WebCore::CSSToStyleMap::mapNinePieceImage): (WebCore::CSSToStyleMap::mapNinePieceImageSlice): (WebCore::CSSToStyleMap::mapNinePieceImageQuad): (WebCore::CSSToStyleMap::mapNinePieceImageRepeat): * css/CSSToStyleMap.h: Added. (WebCore): (CSSToStyleMap): (WebCore::CSSToStyleMap::CSSToStyleMap): * css/StyleBuilder.cpp: (WebCore::ApplyPropertyFillLayer::applyValue): (WebCore::ApplyPropertyBorderImage::applyValue): (WebCore::ApplyPropertyBorderImageModifier::applyValue): (WebCore): (WebCore::ApplyPropertyAnimation::map): (WebCore::StyleBuilder::StyleBuilder): * css/StyleResolver.cpp: (WebCore::StyleResolver::StyleResolver): (WebCore::StyleResolver::collectMatchingRulesForList): * css/StyleResolver.h: (WebCore::StyleResolver::styleMap): (StyleResolver): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121164 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/CMakeLists.txt | 1 + Source/WebCore/ChangeLog | 69 +++ Source/WebCore/GNUmakefile.list.am | 2 + Source/WebCore/Target.pri | 2 + Source/WebCore/WebCore.gypi | 2 + Source/WebCore/WebCore.vcproj/WebCore.vcproj | 8 + Source/WebCore/WebCore.xcodeproj/project.pbxproj | 8 + Source/WebCore/css/CSSToStyleMap.cpp | 659 +++++++++++++++++++++++ Source/WebCore/css/CSSToStyleMap.h | 88 +++ Source/WebCore/css/StyleBuilder.cpp | 85 +-- Source/WebCore/css/StyleResolver.cpp | 598 +------------------- Source/WebCore/css/StyleResolver.h | 31 +- 12 files changed, 890 insertions(+), 663 deletions(-) create mode 100644 Source/WebCore/css/CSSToStyleMap.cpp create mode 100644 Source/WebCore/css/CSSToStyleMap.h diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index fcdeaba..6d3da7f 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -503,6 +503,7 @@ SET(WebCore_SOURCES css/CSSStyleRule.cpp css/CSSStyleSheet.cpp css/CSSTimingFunctionValue.cpp + css/CSSToStyleMap.cpp css/CSSUnicodeRangeValue.cpp css/CSSValue.cpp css/CSSValueList.cpp diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 72ec3dc..0054b30 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,72 @@ +2012-06-25 Eric Seidel + + Split map* functions out of StyleResolver into a helper object + https://bugs.webkit.org/show_bug.cgi?id=89881 + + Reviewed by Daniel Bates. + + These map* functions are completely independent of the rest of StyleResolver + and only exist to serve StyleBuilder. + CSSToStyleMap doesn't even want to have a StyleResolver pointer, but + currently needs one to access the resolve-lifetime caches for the + current resolve. Once we split out that per-resolve state into + some sort of ResolveState/ResolveInfo object (akin to PaintInfo/LayoutState) + then this object will be even simpler. + + No behavioral change, thus no tests. + + * CMakeLists.txt: + * GNUmakefile.list.am: + * WebCore.gypi: + * WebCore.vcproj/WebCore.vcproj: + * WebCore.xcodeproj/project.pbxproj: + * css/CSSToStyleMap.cpp: Added. + (WebCore): + (WebCore::CSSToStyleMap::style): + (WebCore::CSSToStyleMap::rootElementStyle): + (WebCore::CSSToStyleMap::useSVGZoomRules): + (WebCore::CSSToStyleMap::styleImage): + (WebCore::CSSToStyleMap::mapFillAttachment): + (WebCore::CSSToStyleMap::mapFillClip): + (WebCore::CSSToStyleMap::mapFillComposite): + (WebCore::CSSToStyleMap::mapFillOrigin): + (WebCore::CSSToStyleMap::mapFillImage): + (WebCore::CSSToStyleMap::mapFillRepeatX): + (WebCore::CSSToStyleMap::mapFillRepeatY): + (WebCore::CSSToStyleMap::mapFillSize): + (WebCore::CSSToStyleMap::mapFillXPosition): + (WebCore::CSSToStyleMap::mapFillYPosition): + (WebCore::CSSToStyleMap::mapAnimationDelay): + (WebCore::CSSToStyleMap::mapAnimationDirection): + (WebCore::CSSToStyleMap::mapAnimationDuration): + (WebCore::CSSToStyleMap::mapAnimationFillMode): + (WebCore::CSSToStyleMap::mapAnimationIterationCount): + (WebCore::CSSToStyleMap::mapAnimationName): + (WebCore::CSSToStyleMap::mapAnimationPlayState): + (WebCore::CSSToStyleMap::mapAnimationProperty): + (WebCore::CSSToStyleMap::mapAnimationTimingFunction): + (WebCore::CSSToStyleMap::mapNinePieceImage): + (WebCore::CSSToStyleMap::mapNinePieceImageSlice): + (WebCore::CSSToStyleMap::mapNinePieceImageQuad): + (WebCore::CSSToStyleMap::mapNinePieceImageRepeat): + * css/CSSToStyleMap.h: Added. + (WebCore): + (CSSToStyleMap): + (WebCore::CSSToStyleMap::CSSToStyleMap): + * css/StyleBuilder.cpp: + (WebCore::ApplyPropertyFillLayer::applyValue): + (WebCore::ApplyPropertyBorderImage::applyValue): + (WebCore::ApplyPropertyBorderImageModifier::applyValue): + (WebCore): + (WebCore::ApplyPropertyAnimation::map): + (WebCore::StyleBuilder::StyleBuilder): + * css/StyleResolver.cpp: + (WebCore::StyleResolver::StyleResolver): + (WebCore::StyleResolver::collectMatchingRulesForList): + * css/StyleResolver.h: + (WebCore::StyleResolver::styleMap): + (StyleResolver): + 2012-06-25 Gyuyoung Kim [EFL] Support screenDepth() functionality. diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am index 4861f82..2a14316 100644 --- a/Source/WebCore/GNUmakefile.list.am +++ b/Source/WebCore/GNUmakefile.list.am @@ -1679,6 +1679,8 @@ webcore_sources += \ Source/WebCore/css/CSSStyleSheet.h \ Source/WebCore/css/CSSTimingFunctionValue.cpp \ Source/WebCore/css/CSSTimingFunctionValue.h \ + Source/WebCore/css/CSSToStyleMap.cpp \ + Source/WebCore/css/CSSToStyleMap.h \ Source/WebCore/css/CSSWrapShapes.cpp \ Source/WebCore/css/CSSWrapShapes.h \ Source/WebCore/css/CSSUnicodeRangeValue.cpp \ diff --git a/Source/WebCore/Target.pri b/Source/WebCore/Target.pri index 67fedd6..60ba3df9 100644 --- a/Source/WebCore/Target.pri +++ b/Source/WebCore/Target.pri @@ -466,6 +466,7 @@ SOURCES += \ css/CSSStyleRule.cpp \ css/CSSStyleSheet.cpp \ css/CSSTimingFunctionValue.cpp \ + css/CSSToStyleMap.cpp \ css/CSSUnicodeRangeValue.cpp \ css/CSSValue.cpp \ css/CSSValueList.cpp \ @@ -1648,6 +1649,7 @@ HEADERS += \ css/CSSStyleRule.h \ css/CSSStyleSheet.h \ css/CSSTimingFunctionValue.h \ + css/CSSToStyleMap.h \ css/CSSUnicodeRangeValue.h \ css/CSSValue.cpp \ css/CSSValue.h \ diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi index d73e670..e9ebd6c 100644 --- a/Source/WebCore/WebCore.gypi +++ b/Source/WebCore/WebCore.gypi @@ -2505,6 +2505,8 @@ 'css/CSSStyleSheet.h', 'css/CSSTimingFunctionValue.cpp', 'css/CSSTimingFunctionValue.h', + 'css/CSSToStyleMap.cpp', + 'css/CSSToStyleMap.h', 'css/CSSUnicodeRangeValue.cpp', 'css/CSSUnicodeRangeValue.h', 'css/CSSUnknownRule.h', diff --git a/Source/WebCore/WebCore.vcproj/WebCore.vcproj b/Source/WebCore/WebCore.vcproj/WebCore.vcproj index a002e29..d12db56 100755 --- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj +++ b/Source/WebCore/WebCore.vcproj/WebCore.vcproj @@ -36635,6 +36635,14 @@ > + + + + + * Copyright (C) 2007, 2008 Eric Seidel + * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * Copyright (c) 2011, Code Aurora Forum. All rights reserved. + * Copyright (C) Research In Motion Limited 2011. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "CSSToStyleMap.h" + +#include "Animation.h" +#include "CSSBorderImageSliceValue.h" +#include "CSSPrimitiveValue.h" +#include "CSSPrimitiveValueMappings.h" +#include "CSSTimingFunctionValue.h" +#include "CSSValueKeywords.h" +#include "FillLayer.h" +#include "Pair.h" +#include "Rect.h" +#include "StyleResolver.h" + +namespace WebCore { + +RenderStyle* CSSToStyleMap::style() const +{ + return m_resolver->style(); +} + +RenderStyle* CSSToStyleMap::rootElementStyle() const +{ + return m_resolver->rootElementStyle(); +} + +bool CSSToStyleMap::useSVGZoomRules() const +{ + return m_resolver->useSVGZoomRules(); +} + +PassRefPtr CSSToStyleMap::styleImage(CSSPropertyID propertyId, CSSValue* value) +{ + return m_resolver->styleImage(propertyId, value); +} + +void CSSToStyleMap::mapFillAttachment(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setAttachment(FillLayer::initialFillAttachment(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + switch (primitiveValue->getIdent()) { + case CSSValueFixed: + layer->setAttachment(FixedBackgroundAttachment); + break; + case CSSValueScroll: + layer->setAttachment(ScrollBackgroundAttachment); + break; + case CSSValueLocal: + layer->setAttachment(LocalBackgroundAttachment); + break; + default: + return; + } +} + +void CSSToStyleMap::mapFillClip(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setClip(FillLayer::initialFillClip(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + layer->setClip(*primitiveValue); +} + +void CSSToStyleMap::mapFillComposite(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setComposite(FillLayer::initialFillComposite(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + layer->setComposite(*primitiveValue); +} + +void CSSToStyleMap::mapFillOrigin(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setOrigin(FillLayer::initialFillOrigin(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + layer->setOrigin(*primitiveValue); +} + + +void CSSToStyleMap::mapFillImage(CSSPropertyID property, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setImage(FillLayer::initialFillImage(layer->type())); + return; + } + + layer->setImage(styleImage(property, value)); +} + +void CSSToStyleMap::mapFillRepeatX(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setRepeatX(FillLayer::initialFillRepeatX(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + layer->setRepeatX(*primitiveValue); +} + +void CSSToStyleMap::mapFillRepeatY(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setRepeatY(FillLayer::initialFillRepeatY(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + layer->setRepeatY(*primitiveValue); +} + +void CSSToStyleMap::mapFillSize(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (!value->isPrimitiveValue()) { + layer->setSizeType(SizeNone); + return; + } + + CSSPrimitiveValue* primitiveValue = static_cast(value); + if (primitiveValue->getIdent() == CSSValueContain) + layer->setSizeType(Contain); + else if (primitiveValue->getIdent() == CSSValueCover) + layer->setSizeType(Cover); + else + layer->setSizeType(SizeLength); + + LengthSize b = FillLayer::initialFillSizeLength(layer->type()); + + if (value->isInitialValue() || primitiveValue->getIdent() == CSSValueContain || primitiveValue->getIdent() == CSSValueCover) { + layer->setSizeLength(b); + return; + } + + float zoomFactor = style()->effectiveZoom(); + + Length firstLength; + Length secondLength; + + if (Pair* pair = primitiveValue->getPairValue()) { + CSSPrimitiveValue* first = static_cast(pair->first()); + CSSPrimitiveValue* second = static_cast(pair->second()); + firstLength = first->convertToLength(style(), rootElementStyle(), zoomFactor); + secondLength = second->convertToLength(style(), rootElementStyle(), zoomFactor); + } else { + firstLength = primitiveValue->convertToLength(style(), rootElementStyle(), zoomFactor); + secondLength = Length(); + } + + if (firstLength.isUndefined() || secondLength.isUndefined()) + return; + + b.setWidth(firstLength); + b.setHeight(secondLength); + layer->setSizeLength(b); +} + +void CSSToStyleMap::mapFillXPosition(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setXPosition(FillLayer::initialFillXPosition(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + float zoomFactor = style()->effectiveZoom(); + + CSSPrimitiveValue* primitiveValue = static_cast(value); + Length length; + if (primitiveValue->isLength()) + length = primitiveValue->computeLength(style(), rootElementStyle(), zoomFactor); + else if (primitiveValue->isPercentage()) + length = Length(primitiveValue->getDoubleValue(), Percent); + else if (primitiveValue->isCalculatedPercentageWithLength()) + length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), rootElementStyle(), zoomFactor)); + else if (primitiveValue->isViewportPercentageLength()) + length = primitiveValue->viewportPercentageLength(); + else + return; + layer->setXPosition(length); +} + +void CSSToStyleMap::mapFillYPosition(CSSPropertyID, FillLayer* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); + return; + } + + if (!value->isPrimitiveValue()) + return; + + float zoomFactor = style()->effectiveZoom(); + + CSSPrimitiveValue* primitiveValue = static_cast(value); + Length length; + if (primitiveValue->isLength()) + length = primitiveValue->computeLength(style(), rootElementStyle(), zoomFactor); + else if (primitiveValue->isPercentage()) + length = Length(primitiveValue->getDoubleValue(), Percent); + else if (primitiveValue->isCalculatedPercentageWithLength()) + length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), rootElementStyle(), zoomFactor)); + else if (primitiveValue->isViewportPercentageLength()) + length = primitiveValue->viewportPercentageLength(); + else + return; + layer->setYPosition(length); +} + +void CSSToStyleMap::mapAnimationDelay(Animation* animation, CSSValue* value) +{ + if (value->isInitialValue()) { + animation->setDelay(Animation::initialAnimationDelay()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + animation->setDelay(primitiveValue->computeTime()); +} + +void CSSToStyleMap::mapAnimationDirection(Animation* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setDirection(Animation::initialAnimationDirection()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + switch (primitiveValue->getIdent()) { + case CSSValueNormal: + layer->setDirection(Animation::AnimationDirectionNormal); + break; + case CSSValueAlternate: + layer->setDirection(Animation::AnimationDirectionAlternate); + break; + case CSSValueReverse: + layer->setDirection(Animation::AnimationDirectionReverse); + break; + case CSSValueAlternateReverse: + layer->setDirection(Animation::AnimationDirectionAlternateReverse); + break; + } +} + +void CSSToStyleMap::mapAnimationDuration(Animation* animation, CSSValue* value) +{ + if (value->isInitialValue()) { + animation->setDuration(Animation::initialAnimationDuration()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + animation->setDuration(primitiveValue->computeTime()); +} + +void CSSToStyleMap::mapAnimationFillMode(Animation* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setFillMode(Animation::initialAnimationFillMode()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + switch (primitiveValue->getIdent()) { + case CSSValueNone: + layer->setFillMode(AnimationFillModeNone); + break; + case CSSValueForwards: + layer->setFillMode(AnimationFillModeForwards); + break; + case CSSValueBackwards: + layer->setFillMode(AnimationFillModeBackwards); + break; + case CSSValueBoth: + layer->setFillMode(AnimationFillModeBoth); + break; + } +} + +void CSSToStyleMap::mapAnimationIterationCount(Animation* animation, CSSValue* value) +{ + if (value->isInitialValue()) { + animation->setIterationCount(Animation::initialAnimationIterationCount()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + if (primitiveValue->getIdent() == CSSValueInfinite) + animation->setIterationCount(-1); + else + animation->setIterationCount(primitiveValue->getFloatValue()); +} + +void CSSToStyleMap::mapAnimationName(Animation* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setName(Animation::initialAnimationName()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + if (primitiveValue->getIdent() == CSSValueNone) + layer->setIsNoneAnimation(true); + else + layer->setName(primitiveValue->getStringValue()); +} + +void CSSToStyleMap::mapAnimationPlayState(Animation* layer, CSSValue* value) +{ + if (value->isInitialValue()) { + layer->setPlayState(Animation::initialAnimationPlayState()); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + EAnimPlayState playState = (primitiveValue->getIdent() == CSSValuePaused) ? AnimPlayStatePaused : AnimPlayStatePlaying; + layer->setPlayState(playState); +} + +void CSSToStyleMap::mapAnimationProperty(Animation* animation, CSSValue* value) +{ + if (value->isInitialValue()) { + animation->setAnimationMode(Animation::AnimateAll); + animation->setProperty(CSSPropertyInvalid); + return; + } + + if (!value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + if (primitiveValue->getIdent() == CSSValueAll) { + animation->setAnimationMode(Animation::AnimateAll); + animation->setProperty(CSSPropertyInvalid); + } else if (primitiveValue->getIdent() == CSSValueNone) { + animation->setAnimationMode(Animation::AnimateNone); + animation->setProperty(CSSPropertyInvalid); + } else { + animation->setAnimationMode(Animation::AnimateSingleProperty); + animation->setProperty(static_cast(primitiveValue->getIdent())); + } +} + +void CSSToStyleMap::mapAnimationTimingFunction(Animation* animation, CSSValue* value) +{ + if (value->isInitialValue()) { + animation->setTimingFunction(Animation::initialAnimationTimingFunction()); + return; + } + + if (value->isPrimitiveValue()) { + CSSPrimitiveValue* primitiveValue = static_cast(value); + switch (primitiveValue->getIdent()) { + case CSSValueLinear: + animation->setTimingFunction(LinearTimingFunction::create()); + break; + case CSSValueEase: + animation->setTimingFunction(CubicBezierTimingFunction::create()); + break; + case CSSValueEaseIn: + animation->setTimingFunction(CubicBezierTimingFunction::create(0.42, 0.0, 1.0, 1.0)); + break; + case CSSValueEaseOut: + animation->setTimingFunction(CubicBezierTimingFunction::create(0.0, 0.0, 0.58, 1.0)); + break; + case CSSValueEaseInOut: + animation->setTimingFunction(CubicBezierTimingFunction::create(0.42, 0.0, 0.58, 1.0)); + break; + case CSSValueStepStart: + animation->setTimingFunction(StepsTimingFunction::create(1, true)); + break; + case CSSValueStepEnd: + animation->setTimingFunction(StepsTimingFunction::create(1, false)); + break; + } + return; + } + + if (value->isCubicBezierTimingFunctionValue()) { + CSSCubicBezierTimingFunctionValue* cubicTimingFunction = static_cast(value); + animation->setTimingFunction(CubicBezierTimingFunction::create(cubicTimingFunction->x1(), cubicTimingFunction->y1(), cubicTimingFunction->x2(), cubicTimingFunction->y2())); + } else if (value->isStepsTimingFunctionValue()) { + CSSStepsTimingFunctionValue* stepsTimingFunction = static_cast(value); + animation->setTimingFunction(StepsTimingFunction::create(stepsTimingFunction->numberOfSteps(), stepsTimingFunction->stepAtStart())); + } else if (value->isLinearTimingFunctionValue()) + animation->setTimingFunction(LinearTimingFunction::create()); +} + +void CSSToStyleMap::mapNinePieceImage(CSSPropertyID property, CSSValue* value, NinePieceImage& image) +{ + // If we're not a value list, then we are "none" and don't need to alter the empty image at all. + if (!value || !value->isValueList()) + return; + + // Retrieve the border image value. + CSSValueList* borderImage = static_cast(value); + + // Set the image (this kicks off the load). + CSSPropertyID imageProperty; + if (property == CSSPropertyWebkitBorderImage) + imageProperty = CSSPropertyBorderImageSource; + else if (property == CSSPropertyWebkitMaskBoxImage) + imageProperty = CSSPropertyWebkitMaskBoxImageSource; + else + imageProperty = property; + + for (unsigned i = 0 ; i < borderImage->length() ; ++i) { + CSSValue* current = borderImage->item(i); + + if (current->isImageValue() || current->isImageGeneratorValue() +#if ENABLE(CSS_IMAGE_SET) + || current->isImageSetValue() +#endif + ) + image.setImage(styleImage(imageProperty, current)); + else if (current->isBorderImageSliceValue()) + mapNinePieceImageSlice(current, image); + else if (current->isValueList()) { + CSSValueList* slashList = static_cast(current); + // Map in the image slices. + if (slashList->item(0) && slashList->item(0)->isBorderImageSliceValue()) + mapNinePieceImageSlice(slashList->item(0), image); + + // Map in the border slices. + if (slashList->item(1)) + image.setBorderSlices(mapNinePieceImageQuad(slashList->item(1))); + + // Map in the outset. + if (slashList->item(2)) + image.setOutset(mapNinePieceImageQuad(slashList->item(2))); + } else if (current->isPrimitiveValue()) { + // Set the appropriate rules for stretch/round/repeat of the slices. + mapNinePieceImageRepeat(current, image); + } + } + + if (property == CSSPropertyWebkitBorderImage) { + // We have to preserve the legacy behavior of -webkit-border-image and make the border slices + // also set the border widths. We don't need to worry about percentages, since we don't even support + // those on real borders yet. + if (image.borderSlices().top().isFixed()) + style()->setBorderTopWidth(image.borderSlices().top().value()); + if (image.borderSlices().right().isFixed()) + style()->setBorderRightWidth(image.borderSlices().right().value()); + if (image.borderSlices().bottom().isFixed()) + style()->setBorderBottomWidth(image.borderSlices().bottom().value()); + if (image.borderSlices().left().isFixed()) + style()->setBorderLeftWidth(image.borderSlices().left().value()); + } +} + +void CSSToStyleMap::mapNinePieceImageSlice(CSSValue* value, NinePieceImage& image) +{ + if (!value || !value->isBorderImageSliceValue()) + return; + + // Retrieve the border image value. + CSSBorderImageSliceValue* borderImageSlice = static_cast(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); +} + +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(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()->getIdent() != CSSValueAuto) + box.m_top = slices->top()->computeLength(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()->getIdent() != CSSValueAuto) + box.m_right = slices->right()->computeLength(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()->getIdent() != CSSValueAuto) + box.m_bottom = slices->bottom()->computeLength(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()->getIdent() != CSSValueAuto) + box.m_left = slices->left()->computeLength(style(), rootElementStyle(), zoom); + + return box; +} + +void CSSToStyleMap::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& image) +{ + if (!value || !value->isPrimitiveValue()) + return; + + CSSPrimitiveValue* primitiveValue = static_cast(value); + Pair* pair = primitiveValue->getPairValue(); + if (!pair || !pair->first() || !pair->second()) + return; + + int firstIdentifier = pair->first()->getIdent(); + int secondIdentifier = pair->second()->getIdent(); + + ENinePieceImageRule horizontalRule; + switch (firstIdentifier) { + case CSSValueStretch: + horizontalRule = StretchImageRule; + break; + case CSSValueRound: + horizontalRule = RoundImageRule; + break; + case CSSValueSpace: + horizontalRule = SpaceImageRule; + break; + default: // CSSValueRepeat + horizontalRule = RepeatImageRule; + break; + } + image.setHorizontalRule(horizontalRule); + + ENinePieceImageRule verticalRule; + switch (secondIdentifier) { + case CSSValueStretch: + verticalRule = StretchImageRule; + break; + case CSSValueRound: + verticalRule = RoundImageRule; + break; + case CSSValueSpace: + verticalRule = SpaceImageRule; + break; + default: // CSSValueRepeat + verticalRule = RepeatImageRule; + break; + } + image.setVerticalRule(verticalRule); +} + +}; diff --git a/Source/WebCore/css/CSSToStyleMap.h b/Source/WebCore/css/CSSToStyleMap.h new file mode 100644 index 0000000..8e0fc95 --- /dev/null +++ b/Source/WebCore/css/CSSToStyleMap.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef CSSToStyleMap_h +#define CSSToStyleMap_h + +#include "CSSPropertyNames.h" +#include "LengthBox.h" + +namespace WebCore { + +class FillLayer; +class CSSValue; +class Animation; +class StyleImage; +class StyleResolver; +class NinePieceImage; + +class CSSToStyleMap { + WTF_MAKE_NONCOPYABLE(CSSToStyleMap); + WTF_MAKE_FAST_ALLOCATED; + +public: + CSSToStyleMap(StyleResolver* resolver) : m_resolver(resolver) { } + + void mapFillAttachment(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillClip(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillComposite(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillOrigin(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillImage(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillRepeatX(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillRepeatY(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillSize(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillXPosition(CSSPropertyID, FillLayer*, CSSValue*); + void mapFillYPosition(CSSPropertyID, FillLayer*, CSSValue*); + + void mapAnimationDelay(Animation*, CSSValue*); + void mapAnimationDirection(Animation*, CSSValue*); + void mapAnimationDuration(Animation*, CSSValue*); + void mapAnimationFillMode(Animation*, CSSValue*); + void mapAnimationIterationCount(Animation*, CSSValue*); + void mapAnimationName(Animation*, CSSValue*); + void mapAnimationPlayState(Animation*, CSSValue*); + void mapAnimationProperty(Animation*, CSSValue*); + void mapAnimationTimingFunction(Animation*, CSSValue*); + + void mapNinePieceImage(CSSPropertyID, CSSValue*, NinePieceImage&); + void mapNinePieceImageSlice(CSSValue*, NinePieceImage&); + LengthBox mapNinePieceImageQuad(CSSValue*); + void mapNinePieceImageRepeat(CSSValue*, NinePieceImage&); + +private: + // FIXME: These accessors should be replaced by a ResolveState object + // similar to how PaintInfo/LayoutState cache values needed for + // the current paint/layout. + RenderStyle* style() const; + RenderStyle* rootElementStyle() const; + bool useSVGZoomRules() const; + + // FIXME: This should be part of some sort of StyleImageCache object which + // is held by the StyleResolver, and likely provided to this object + // during the resolve. + PassRefPtr styleImage(CSSPropertyID, CSSValue*); + + StyleResolver* m_resolver; +}; + +} + +#endif diff --git a/Source/WebCore/css/StyleBuilder.cpp b/Source/WebCore/css/StyleBuilder.cpp index 2139996..20d02cc 100644 --- a/Source/WebCore/css/StyleBuilder.cpp +++ b/Source/WebCore/css/StyleBuilder.cpp @@ -29,6 +29,7 @@ #include "CSSCalculationValue.h" #include "CSSCursorImageValue.h" #include "CSSPrimitiveValueMappings.h" +#include "CSSToStyleMap.h" #include "CSSValueList.h" #include "CursorList.h" #include "Document.h" @@ -496,7 +497,7 @@ template ::Setter), void (FillLayer::*clearFunction)(), typename FillLayerAccessorTypes::Getter (*initialFunction)(EFillLayerType), - void (StyleResolver::*mapFillFunction)(CSSPropertyID, FillLayer*, CSSValue*)> + void (CSSToStyleMap::*mapFillFunction)(CSSPropertyID, FillLayer*, CSSValue*)> class ApplyPropertyFillLayer { public: static void applyInheritValue(StyleResolver* styleResolver) @@ -548,12 +549,12 @@ public: currChild = new FillLayer(fillLayerType); prevChild->setNext(currChild); } - (styleResolver->*mapFillFunction)(propertyId, currChild, valueList->itemWithoutBoundsCheck(i)); + (styleResolver->styleMap()->*mapFillFunction)(propertyId, currChild, valueList->itemWithoutBoundsCheck(i)); prevChild = currChild; currChild = currChild->next(); } } else { - (styleResolver->*mapFillFunction)(propertyId, currChild, value); + (styleResolver->styleMap()->*mapFillFunction)(propertyId, currChild, value); currChild = currChild->next(); } while (currChild) { @@ -886,7 +887,7 @@ public: NinePieceImage image; if (borderImageType == Mask) image.setMaskDefaults(); - styleResolver->mapNinePieceImage(property, value, image); + styleResolver->styleMap()->mapNinePieceImage(property, value, image); (styleResolver->style()->*setterFunction)(image); } @@ -953,16 +954,16 @@ public: NinePieceImage image(getValue(styleResolver->style())); switch (modifier) { case Outset: - image.setOutset(styleResolver->mapNinePieceImageQuad(value)); + image.setOutset(styleResolver->styleMap()->mapNinePieceImageQuad(value)); break; case Repeat: - styleResolver->mapNinePieceImageRepeat(value, image); + styleResolver->styleMap()->mapNinePieceImageRepeat(value, image); break; case Slice: - styleResolver->mapNinePieceImageSlice(value, image); + styleResolver->styleMap()->mapNinePieceImageSlice(value, image); break; case Width: - image.setBorderSlices(styleResolver->mapNinePieceImageQuad(value)); + image.setBorderSlices(styleResolver->styleMap()->mapNinePieceImageQuad(value)); break; } setValue(styleResolver->style(), image); @@ -1437,7 +1438,7 @@ template class ApplyPropertyAnimation { @@ -1447,7 +1448,7 @@ public: static bool test(const Animation* animation) { return (animation->*testFunction)(); } static void clear(Animation* animation) { (animation->*clearFunction)(); } static T initial() { return (*initialFunction)(); } - static void map(StyleResolver* styleResolver, Animation* animation, CSSValue* value) { (styleResolver->*mapFunction)(animation, value); } + static void map(StyleResolver* styleResolver, Animation* animation, CSSValue* value) { (styleResolver->styleMap()->*mapFunction)(animation, value); } static AnimationList* accessAnimations(RenderStyle* style) { return (style->*animationGetterFunction)(); } static const AnimationList* animations(RenderStyle* style) { return (style->*immutableAnimationGetterFunction)(); } @@ -1840,18 +1841,18 @@ StyleBuilder::StyleBuilder() m_propertyMap[i] = PropertyHandler(); // Please keep CSS property list in alphabetical order. - setPropertyHandler(CSSPropertyBackgroundAttachment, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyBackgroundClip, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundAttachment, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundClip, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyBackgroundColor, ApplyPropertyColor::createHandler()); - setPropertyHandler(CSSPropertyBackgroundImage, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyBackgroundOrigin, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundImage, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundOrigin, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyBackgroundPosition, ApplyPropertyExpanding::createHandler()); - setPropertyHandler(CSSPropertyBackgroundPositionX, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyBackgroundPositionY, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundPositionX, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundPositionY, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyBackgroundRepeat, ApplyPropertyExpanding::createHandler()); - setPropertyHandler(CSSPropertyBackgroundRepeatX, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyBackgroundRepeatY, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyBackgroundSize, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundRepeatX, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundRepeatY, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyBackgroundSize, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyBorder, ApplyPropertyExpanding::createHandler()); setPropertyHandler(CSSPropertyBorderBottom, ApplyPropertyExpanding::createHandler()); setPropertyHandler(CSSPropertyBorderBottomColor, ApplyPropertyColor::createHandler()); @@ -1957,19 +1958,19 @@ StyleBuilder::StyleBuilder() setPropertyHandler(CSSPropertyUnicodeBidi, ApplyPropertyUnicodeBidi::createHandler()); setPropertyHandler(CSSPropertyVerticalAlign, ApplyPropertyVerticalAlign::createHandler()); setPropertyHandler(CSSPropertyVisibility, ApplyPropertyDefault::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationDelay, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationDirection, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationDuration, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationFillMode, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationIterationCount, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationName, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationPlayState, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitAnimationTimingFunction, ApplyPropertyAnimation, &Animation::timingFunction, &Animation::setTimingFunction, &Animation::isTimingFunctionSet, &Animation::clearTimingFunction, &Animation::initialAnimationTimingFunction, &StyleResolver::mapAnimationTimingFunction, &RenderStyle::accessAnimations, &RenderStyle::animations>::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationDelay, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationDirection, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationDuration, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationFillMode, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationIterationCount, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationName, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationPlayState, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitAnimationTimingFunction, ApplyPropertyAnimation, &Animation::timingFunction, &Animation::setTimingFunction, &Animation::isTimingFunctionSet, &Animation::clearTimingFunction, &Animation::initialAnimationTimingFunction, &CSSToStyleMap::mapAnimationTimingFunction, &RenderStyle::accessAnimations, &RenderStyle::animations>::createHandler()); setPropertyHandler(CSSPropertyWebkitAppearance, ApplyPropertyDefault::createHandler()); setPropertyHandler(CSSPropertyWebkitAspectRatio, ApplyPropertyAspectRatio::createHandler()); setPropertyHandler(CSSPropertyWebkitBackfaceVisibility, ApplyPropertyDefault::createHandler()); setPropertyHandler(CSSPropertyWebkitBackgroundClip, CSSPropertyBackgroundClip); - setPropertyHandler(CSSPropertyWebkitBackgroundComposite, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitBackgroundComposite, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyWebkitBackgroundOrigin, CSSPropertyBackgroundOrigin); setPropertyHandler(CSSPropertyWebkitBackgroundSize, CSSPropertyBackgroundSize); setPropertyHandler(CSSPropertyWebkitBorderFit, ApplyPropertyDefault::createHandler()); @@ -2037,24 +2038,24 @@ StyleBuilder::StyleBuilder() setPropertyHandler(CSSPropertyWebkitMarginTopCollapse, CSSPropertyWebkitMarginBeforeCollapse); setPropertyHandler(CSSPropertyWebkitMarqueeDirection, ApplyPropertyDefault::createHandler()); setPropertyHandler(CSSPropertyWebkitMarqueeStyle, ApplyPropertyDefault::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskAttachment, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskAttachment, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskBoxImage, ApplyPropertyBorderImage::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskBoxImageOutset, ApplyPropertyBorderImageModifier::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskBoxImageRepeat, ApplyPropertyBorderImageModifier::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskBoxImageSlice, ApplyPropertyBorderImageModifier::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskBoxImageSource, ApplyPropertyBorderImageSource::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskBoxImageWidth, ApplyPropertyBorderImageModifier::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskClip, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskComposite, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskImage, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskOrigin, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskClip, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskComposite, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskImage, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskOrigin, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskPosition, ApplyPropertyExpanding::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskPositionX, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskPositionY, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskPositionX, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskPositionY, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyWebkitMaskRepeat, ApplyPropertyExpanding::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskRepeatX, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskRepeatY, ApplyPropertyFillLayer::createHandler()); - setPropertyHandler(CSSPropertyWebkitMaskSize, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskRepeatX, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskRepeatY, ApplyPropertyFillLayer::createHandler()); + setPropertyHandler(CSSPropertyWebkitMaskSize, ApplyPropertyFillLayer::createHandler()); setPropertyHandler(CSSPropertyWebkitNbspMode, ApplyPropertyDefault::createHandler()); setPropertyHandler(CSSPropertyWebkitPerspectiveOrigin, ApplyPropertyExpanding::createHandler()); setPropertyHandler(CSSPropertyWebkitPerspectiveOriginX, ApplyPropertyLength<&RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX, &RenderStyle::initialPerspectiveOriginX>::createHandler()); @@ -2080,10 +2081,10 @@ StyleBuilder::StyleBuilder() setPropertyHandler(CSSPropertyWebkitTransformOriginY, ApplyPropertyLength<&RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY, &RenderStyle::initialTransformOriginY>::createHandler()); setPropertyHandler(CSSPropertyWebkitTransformOriginZ, ApplyPropertyComputeLength::createHandler()); setPropertyHandler(CSSPropertyWebkitTransformStyle, ApplyPropertyDefault::createHandler()); - setPropertyHandler(CSSPropertyWebkitTransitionDelay, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitTransitionDuration, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitTransitionProperty, ApplyPropertyAnimation::createHandler()); - setPropertyHandler(CSSPropertyWebkitTransitionTimingFunction, ApplyPropertyAnimation, &Animation::timingFunction, &Animation::setTimingFunction, &Animation::isTimingFunctionSet, &Animation::clearTimingFunction, &Animation::initialAnimationTimingFunction, &StyleResolver::mapAnimationTimingFunction, &RenderStyle::accessTransitions, &RenderStyle::transitions>::createHandler()); + setPropertyHandler(CSSPropertyWebkitTransitionDelay, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitTransitionDuration, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitTransitionProperty, ApplyPropertyAnimation::createHandler()); + setPropertyHandler(CSSPropertyWebkitTransitionTimingFunction, ApplyPropertyAnimation, &Animation::timingFunction, &Animation::setTimingFunction, &Animation::isTimingFunctionSet, &Animation::clearTimingFunction, &Animation::initialAnimationTimingFunction, &CSSToStyleMap::mapAnimationTimingFunction, &RenderStyle::accessTransitions, &RenderStyle::transitions>::createHandler()); setPropertyHandler(CSSPropertyWebkitUserDrag, ApplyPropertyDefault::createHandler()); setPropertyHandler(CSSPropertyWebkitUserModify, ApplyPropertyDefault::createHandler()); setPropertyHandler(CSSPropertyWebkitUserSelect, ApplyPropertyDefault::createHandler()); diff --git a/Source/WebCore/css/StyleResolver.cpp b/Source/WebCore/css/StyleResolver.cpp index 252298f..55dbfe9 100644 --- a/Source/WebCore/css/StyleResolver.cpp +++ b/Source/WebCore/css/StyleResolver.cpp @@ -8,6 +8,7 @@ * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * Copyright (c) 2011, Code Aurora Forum. All rights reserved. * Copyright (C) Research In Motion Limited 2011. All rights reserved. + * Copyright (C) 2012 Google Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -374,6 +375,7 @@ StyleResolver::StyleResolver(Document* document, bool matchAuthorAndUserStyles) , m_scopeStackParent(0) , m_scopeStackParentBoundsIndex(0) #endif + , m_styleMap(this) { Element* root = document->documentElement(); @@ -3740,7 +3742,7 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value) reflection->setOffset(reflectValue->offset()->convertToLength(style(), m_rootElementStyle, zoomFactor)); NinePieceImage mask; mask.setMaskDefaults(); - mapNinePieceImage(id, reflectValue->mask(), mask); + m_styleMap.mapNinePieceImage(id, reflectValue->mask(), mask); reflection->setMask(mask); m_style->setBoxReflect(reflection.release()); @@ -4428,74 +4430,6 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value) } } -void StyleResolver::mapFillAttachment(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setAttachment(FillLayer::initialFillAttachment(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - switch (primitiveValue->getIdent()) { - case CSSValueFixed: - layer->setAttachment(FixedBackgroundAttachment); - break; - case CSSValueScroll: - layer->setAttachment(ScrollBackgroundAttachment); - break; - case CSSValueLocal: - layer->setAttachment(LocalBackgroundAttachment); - break; - default: - return; - } -} - -void StyleResolver::mapFillClip(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setClip(FillLayer::initialFillClip(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - layer->setClip(*primitiveValue); -} - -void StyleResolver::mapFillComposite(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setComposite(FillLayer::initialFillComposite(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - layer->setComposite(*primitiveValue); -} - -void StyleResolver::mapFillOrigin(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setOrigin(FillLayer::initialFillOrigin(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - layer->setOrigin(*primitiveValue); -} - PassRefPtr StyleResolver::styleImage(CSSPropertyID property, CSSValue* value) { if (value->isImageValue()) @@ -4539,532 +4473,6 @@ PassRefPtr StyleResolver::setOrPendingFromValue(CSSPropertyID proper } #endif -void StyleResolver::mapFillImage(CSSPropertyID property, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setImage(FillLayer::initialFillImage(layer->type())); - return; - } - - layer->setImage(styleImage(property, value)); -} - -void StyleResolver::mapFillRepeatX(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setRepeatX(FillLayer::initialFillRepeatX(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - layer->setRepeatX(*primitiveValue); -} - -void StyleResolver::mapFillRepeatY(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setRepeatY(FillLayer::initialFillRepeatY(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - layer->setRepeatY(*primitiveValue); -} - -void StyleResolver::mapFillSize(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (!value->isPrimitiveValue()) { - layer->setSizeType(SizeNone); - return; - } - - CSSPrimitiveValue* primitiveValue = static_cast(value); - if (primitiveValue->getIdent() == CSSValueContain) - layer->setSizeType(Contain); - else if (primitiveValue->getIdent() == CSSValueCover) - layer->setSizeType(Cover); - else - layer->setSizeType(SizeLength); - - LengthSize b = FillLayer::initialFillSizeLength(layer->type()); - - if (value->isInitialValue() || primitiveValue->getIdent() == CSSValueContain || primitiveValue->getIdent() == CSSValueCover) { - layer->setSizeLength(b); - return; - } - - float zoomFactor = m_style->effectiveZoom(); - - Length firstLength; - Length secondLength; - - if (Pair* pair = primitiveValue->getPairValue()) { - CSSPrimitiveValue* first = static_cast(pair->first()); - CSSPrimitiveValue* second = static_cast(pair->second()); - firstLength = first->convertToLength(style(), m_rootElementStyle, zoomFactor); - secondLength = second->convertToLength(style(), m_rootElementStyle, zoomFactor); - } else { - firstLength = primitiveValue->convertToLength(style(), m_rootElementStyle, zoomFactor); - secondLength = Length(); - } - - if (firstLength.isUndefined() || secondLength.isUndefined()) - return; - - b.setWidth(firstLength); - b.setHeight(secondLength); - layer->setSizeLength(b); -} - -void StyleResolver::mapFillXPosition(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setXPosition(FillLayer::initialFillXPosition(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - float zoomFactor = m_style->effectiveZoom(); - - CSSPrimitiveValue* primitiveValue = static_cast(value); - Length length; - if (primitiveValue->isLength()) - length = primitiveValue->computeLength(style(), m_rootElementStyle, zoomFactor); - else if (primitiveValue->isPercentage()) - length = Length(primitiveValue->getDoubleValue(), Percent); - else if (primitiveValue->isCalculatedPercentageWithLength()) - length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), m_rootElementStyle, zoomFactor)); - else if (primitiveValue->isViewportPercentageLength()) - length = primitiveValue->viewportPercentageLength(); - else - return; - layer->setXPosition(length); -} - -void StyleResolver::mapFillYPosition(CSSPropertyID, FillLayer* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); - return; - } - - if (!value->isPrimitiveValue()) - return; - - float zoomFactor = m_style->effectiveZoom(); - - CSSPrimitiveValue* primitiveValue = static_cast(value); - Length length; - if (primitiveValue->isLength()) - length = primitiveValue->computeLength(style(), m_rootElementStyle, zoomFactor); - else if (primitiveValue->isPercentage()) - length = Length(primitiveValue->getDoubleValue(), Percent); - else if (primitiveValue->isCalculatedPercentageWithLength()) - length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), m_rootElementStyle, zoomFactor)); - else if (primitiveValue->isViewportPercentageLength()) - length = primitiveValue->viewportPercentageLength(); - else - return; - layer->setYPosition(length); -} - -void StyleResolver::mapAnimationDelay(Animation* animation, CSSValue* value) -{ - if (value->isInitialValue()) { - animation->setDelay(Animation::initialAnimationDelay()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - animation->setDelay(primitiveValue->computeTime()); -} - -void StyleResolver::mapAnimationDirection(Animation* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setDirection(Animation::initialAnimationDirection()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - switch (primitiveValue->getIdent()) { - case CSSValueNormal: - layer->setDirection(Animation::AnimationDirectionNormal); - break; - case CSSValueAlternate: - layer->setDirection(Animation::AnimationDirectionAlternate); - break; - case CSSValueReverse: - layer->setDirection(Animation::AnimationDirectionReverse); - break; - case CSSValueAlternateReverse: - layer->setDirection(Animation::AnimationDirectionAlternateReverse); - break; - } -} - -void StyleResolver::mapAnimationDuration(Animation* animation, CSSValue* value) -{ - if (value->isInitialValue()) { - animation->setDuration(Animation::initialAnimationDuration()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - animation->setDuration(primitiveValue->computeTime()); -} - -void StyleResolver::mapAnimationFillMode(Animation* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setFillMode(Animation::initialAnimationFillMode()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - switch (primitiveValue->getIdent()) { - case CSSValueNone: - layer->setFillMode(AnimationFillModeNone); - break; - case CSSValueForwards: - layer->setFillMode(AnimationFillModeForwards); - break; - case CSSValueBackwards: - layer->setFillMode(AnimationFillModeBackwards); - break; - case CSSValueBoth: - layer->setFillMode(AnimationFillModeBoth); - break; - } -} - -void StyleResolver::mapAnimationIterationCount(Animation* animation, CSSValue* value) -{ - if (value->isInitialValue()) { - animation->setIterationCount(Animation::initialAnimationIterationCount()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - if (primitiveValue->getIdent() == CSSValueInfinite) - animation->setIterationCount(-1); - else - animation->setIterationCount(primitiveValue->getFloatValue()); -} - -void StyleResolver::mapAnimationName(Animation* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setName(Animation::initialAnimationName()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - if (primitiveValue->getIdent() == CSSValueNone) - layer->setIsNoneAnimation(true); - else - layer->setName(primitiveValue->getStringValue()); -} - -void StyleResolver::mapAnimationPlayState(Animation* layer, CSSValue* value) -{ - if (value->isInitialValue()) { - layer->setPlayState(Animation::initialAnimationPlayState()); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - EAnimPlayState playState = (primitiveValue->getIdent() == CSSValuePaused) ? AnimPlayStatePaused : AnimPlayStatePlaying; - layer->setPlayState(playState); -} - -void StyleResolver::mapAnimationProperty(Animation* animation, CSSValue* value) -{ - if (value->isInitialValue()) { - animation->setAnimationMode(Animation::AnimateAll); - animation->setProperty(CSSPropertyInvalid); - return; - } - - if (!value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - if (primitiveValue->getIdent() == CSSValueAll) { - animation->setAnimationMode(Animation::AnimateAll); - animation->setProperty(CSSPropertyInvalid); - } else if (primitiveValue->getIdent() == CSSValueNone) { - animation->setAnimationMode(Animation::AnimateNone); - animation->setProperty(CSSPropertyInvalid); - } else { - animation->setAnimationMode(Animation::AnimateSingleProperty); - animation->setProperty(static_cast(primitiveValue->getIdent())); - } -} - -void StyleResolver::mapAnimationTimingFunction(Animation* animation, CSSValue* value) -{ - if (value->isInitialValue()) { - animation->setTimingFunction(Animation::initialAnimationTimingFunction()); - return; - } - - if (value->isPrimitiveValue()) { - CSSPrimitiveValue* primitiveValue = static_cast(value); - switch (primitiveValue->getIdent()) { - case CSSValueLinear: - animation->setTimingFunction(LinearTimingFunction::create()); - break; - case CSSValueEase: - animation->setTimingFunction(CubicBezierTimingFunction::create()); - break; - case CSSValueEaseIn: - animation->setTimingFunction(CubicBezierTimingFunction::create(0.42, 0.0, 1.0, 1.0)); - break; - case CSSValueEaseOut: - animation->setTimingFunction(CubicBezierTimingFunction::create(0.0, 0.0, 0.58, 1.0)); - break; - case CSSValueEaseInOut: - animation->setTimingFunction(CubicBezierTimingFunction::create(0.42, 0.0, 0.58, 1.0)); - break; - case CSSValueStepStart: - animation->setTimingFunction(StepsTimingFunction::create(1, true)); - break; - case CSSValueStepEnd: - animation->setTimingFunction(StepsTimingFunction::create(1, false)); - break; - } - return; - } - - if (value->isCubicBezierTimingFunctionValue()) { - CSSCubicBezierTimingFunctionValue* cubicTimingFunction = static_cast(value); - animation->setTimingFunction(CubicBezierTimingFunction::create(cubicTimingFunction->x1(), cubicTimingFunction->y1(), cubicTimingFunction->x2(), cubicTimingFunction->y2())); - } else if (value->isStepsTimingFunctionValue()) { - CSSStepsTimingFunctionValue* stepsTimingFunction = static_cast(value); - animation->setTimingFunction(StepsTimingFunction::create(stepsTimingFunction->numberOfSteps(), stepsTimingFunction->stepAtStart())); - } else if (value->isLinearTimingFunctionValue()) - animation->setTimingFunction(LinearTimingFunction::create()); -} - -void StyleResolver::mapNinePieceImage(CSSPropertyID property, CSSValue* value, NinePieceImage& image) -{ - // If we're not a value list, then we are "none" and don't need to alter the empty image at all. - if (!value || !value->isValueList()) - return; - - // Retrieve the border image value. - CSSValueList* borderImage = static_cast(value); - - // Set the image (this kicks off the load). - CSSPropertyID imageProperty; - if (property == CSSPropertyWebkitBorderImage) - imageProperty = CSSPropertyBorderImageSource; - else if (property == CSSPropertyWebkitMaskBoxImage) - imageProperty = CSSPropertyWebkitMaskBoxImageSource; - else - imageProperty = property; - - for (unsigned i = 0 ; i < borderImage->length() ; ++i) { - CSSValue* current = borderImage->item(i); - - if (current->isImageValue() || current->isImageGeneratorValue() -#if ENABLE(CSS_IMAGE_SET) - || current->isImageSetValue() -#endif - ) - image.setImage(styleImage(imageProperty, current)); - else if (current->isBorderImageSliceValue()) - mapNinePieceImageSlice(current, image); - else if (current->isValueList()) { - CSSValueList* slashList = static_cast(current); - // Map in the image slices. - if (slashList->item(0) && slashList->item(0)->isBorderImageSliceValue()) - mapNinePieceImageSlice(slashList->item(0), image); - - // Map in the border slices. - if (slashList->item(1)) - image.setBorderSlices(mapNinePieceImageQuad(slashList->item(1))); - - // Map in the outset. - if (slashList->item(2)) - image.setOutset(mapNinePieceImageQuad(slashList->item(2))); - } else if (current->isPrimitiveValue()) { - // Set the appropriate rules for stretch/round/repeat of the slices. - mapNinePieceImageRepeat(current, image); - } - } - - if (property == CSSPropertyWebkitBorderImage) { - // We have to preserve the legacy behavior of -webkit-border-image and make the border slices - // also set the border widths. We don't need to worry about percentages, since we don't even support - // those on real borders yet. - if (image.borderSlices().top().isFixed()) - style()->setBorderTopWidth(image.borderSlices().top().value()); - if (image.borderSlices().right().isFixed()) - style()->setBorderRightWidth(image.borderSlices().right().value()); - if (image.borderSlices().bottom().isFixed()) - style()->setBorderBottomWidth(image.borderSlices().bottom().value()); - if (image.borderSlices().left().isFixed()) - style()->setBorderLeftWidth(image.borderSlices().left().value()); - } -} - -void StyleResolver::mapNinePieceImageSlice(CSSValue* value, NinePieceImage& image) -{ - if (!value || !value->isBorderImageSliceValue()) - return; - - // Retrieve the border image value. - CSSBorderImageSliceValue* borderImageSlice = static_cast(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); -} - -LengthBox StyleResolver::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(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()->getIdent() != CSSValueAuto) - box.m_top = slices->top()->computeLength(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()->getIdent() != CSSValueAuto) - box.m_right = slices->right()->computeLength(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()->getIdent() != CSSValueAuto) - box.m_bottom = slices->bottom()->computeLength(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()->getIdent() != CSSValueAuto) - box.m_left = slices->left()->computeLength(style(), rootElementStyle(), zoom); - - return box; -} - -void StyleResolver::mapNinePieceImageRepeat(CSSValue* value, NinePieceImage& image) -{ - if (!value || !value->isPrimitiveValue()) - return; - - CSSPrimitiveValue* primitiveValue = static_cast(value); - Pair* pair = primitiveValue->getPairValue(); - if (!pair || !pair->first() || !pair->second()) - return; - - int firstIdentifier = pair->first()->getIdent(); - int secondIdentifier = pair->second()->getIdent(); - - ENinePieceImageRule horizontalRule; - switch (firstIdentifier) { - case CSSValueStretch: - horizontalRule = StretchImageRule; - break; - case CSSValueRound: - horizontalRule = RoundImageRule; - break; - case CSSValueSpace: - horizontalRule = SpaceImageRule; - break; - default: // CSSValueRepeat - horizontalRule = RepeatImageRule; - break; - } - image.setHorizontalRule(horizontalRule); - - ENinePieceImageRule verticalRule; - switch (secondIdentifier) { - case CSSValueStretch: - verticalRule = StretchImageRule; - break; - case CSSValueRound: - verticalRule = RoundImageRule; - break; - case CSSValueSpace: - verticalRule = SpaceImageRule; - break; - default: // CSSValueRepeat - verticalRule = RepeatImageRule; - break; - } - image.setVerticalRule(verticalRule); -} - void StyleResolver::checkForTextSizeAdjust() { if (m_style->textSizeAdjust()) diff --git a/Source/WebCore/css/StyleResolver.h b/Source/WebCore/css/StyleResolver.h index 29f800e..4843eb5 100644 --- a/Source/WebCore/css/StyleResolver.h +++ b/Source/WebCore/css/StyleResolver.h @@ -23,6 +23,7 @@ #define StyleResolver_h #include "CSSRule.h" +#include "CSSToStyleMap.h" #include "CSSValueList.h" #include "LinkHash.h" #include "MediaQueryExp.h" @@ -411,6 +412,8 @@ public: static Length convertToIntLength(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, double multiplier = 1); static Length convertToFloatLength(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, double multiplier = 1); + CSSToStyleMap* styleMap() { return &m_styleMap; } + private: static RenderStyle* s_styleNotYetAvailable; @@ -419,32 +422,6 @@ private: void cacheBorderAndBackground(); - void mapFillAttachment(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillClip(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillComposite(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillOrigin(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillImage(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillRepeatX(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillRepeatY(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillSize(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillXPosition(CSSPropertyID, FillLayer*, CSSValue*); - void mapFillYPosition(CSSPropertyID, FillLayer*, CSSValue*); - - void mapAnimationDelay(Animation*, CSSValue*); - void mapAnimationDirection(Animation*, CSSValue*); - void mapAnimationDuration(Animation*, CSSValue*); - void mapAnimationFillMode(Animation*, CSSValue*); - void mapAnimationIterationCount(Animation*, CSSValue*); - void mapAnimationName(Animation*, CSSValue*); - void mapAnimationPlayState(Animation*, CSSValue*); - void mapAnimationProperty(Animation*, CSSValue*); - void mapAnimationTimingFunction(Animation*, CSSValue*); - -public: - void mapNinePieceImage(CSSPropertyID, CSSValue*, NinePieceImage&); - void mapNinePieceImageSlice(CSSValue*, NinePieceImage&); - LengthBox mapNinePieceImageQuad(CSSValue*); - void mapNinePieceImageRepeat(CSSValue*, NinePieceImage&); private: bool canShareStyleWithControl(StyledElement*) const; @@ -546,6 +523,8 @@ private: int m_scopeStackParentBoundsIndex; #endif + CSSToStyleMap m_styleMap; + friend class StyleBuilder; friend bool operator==(const MatchedProperties&, const MatchedProperties&); friend bool operator!=(const MatchedProperties&, const MatchedProperties&); -- 2.7.4