Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Unified Diff: Source/core/css/resolver/CSSAnimatableValueFactory.cpp

Issue 19744002: Web Animations: Add CSSAnimatableValueFactory API (partial implementation) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/resolver/CSSAnimatableValueFactory.cpp
diff --git a/Source/core/css/resolver/CSSAnimatableValueFactory.cpp b/Source/core/css/resolver/CSSAnimatableValueFactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a82db144f4e293a08682fdcc5f190061bd165bb5
--- /dev/null
+++ b/Source/core/css/resolver/CSSAnimatableValueFactory.cpp
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "core/css/resolver/CSSAnimatableValueFactory.h"
+
+#include "CSSValueKeywords.h"
+#include "core/animation/AnimatableNumber.h"
+#include "core/animation/AnimatableUnknown.h"
+#include "core/rendering/style/RenderStyle.h"
+
+
+namespace WebCore {
dstockwell 2013/07/18 07:43:12 Fixme, generate this file?
+
+// FIXME: Handle remaining animatable properties:
+// CSSPropertyBackgroundColor
+// CSSPropertyBackgroundPosition
+// CSSPropertyBorderBottomColor
+// CSSPropertyBorderBottomWidth
+// CSSPropertyBorderLeftColor
+// CSSPropertyBorderLeftWidth
+// CSSPropertyBorderRightColor
+// CSSPropertyBorderRightWidth
+// CSSPropertyBorderSpacing
+// CSSPropertyBorderTopColor
+// CSSPropertyBorderTopWidth
+// CSSPropertyBottom
+// CSSPropertyClip
+// CSSPropertyColor
+// CSSPropertyFontSize
+// CSSPropertyFontWeight
+// CSSPropertyLetterSpacing
+// CSSPropertyLineHeight
+// CSSPropertyOpacity
+// CSSPropertyOutlineColor
+// CSSPropertyOutlineOffset
+// CSSPropertyOutlineWidth
+// CSSPropertyTextIndent
+// CSSPropertyTextShadow
+// CSSPropertyVerticalAlign
+// CSSPropertyVisibility
+// CSSPropertyWebkitTransform
+// CSSPropertyWordSpacing
+// CSSPropertyZIndex
+
+PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromCSSValue(CSSValue* value, CSSPropertyID property)
+{
+ switch (property) {
+ case CSSPropertyBottom:
+ case CSSPropertyHeight:
+ case CSSPropertyLeft:
+ case CSSPropertyMarginBottom:
+ case CSSPropertyMarginLeft:
+ case CSSPropertyMarginRight:
+ case CSSPropertyMarginTop:
+ case CSSPropertyMaxHeight:
+ case CSSPropertyMaxWidth:
+ case CSSPropertyMinHeight:
+ case CSSPropertyMinWidth:
+ case CSSPropertyPaddingBottom:
+ case CSSPropertyPaddingLeft:
+ case CSSPropertyPaddingRight:
+ case CSSPropertyPaddingTop:
+ case CSSPropertyRight:
+ case CSSPropertyTop:
+ case CSSPropertyWebkitPerspectiveOriginX:
+ case CSSPropertyWebkitPerspectiveOriginY:
+ case CSSPropertyWebkitTransformOriginX:
+ case CSSPropertyWebkitTransformOriginY:
+ case CSSPropertyWidth:
+ if (AnimatableNumber::canCreateFrom(value))
+ return AnimatableNumber::create(value);
+ default:
+ return AnimatableUnknown::create(value);
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromRenderStyle(RenderStyle* style, CSSPropertyID property)
+{
+ switch (property) {
+ case CSSPropertyBottom:
+ return createFromLength(style->bottom(), style);
+ case CSSPropertyHeight:
+ return createFromLength(style->height(), style);
+ case CSSPropertyLeft:
+ return createFromLength(style->left(), style);
+ case CSSPropertyMarginBottom:
+ return createFromLength(style->marginBottom(), style);
+ case CSSPropertyMarginLeft:
+ return createFromLength(style->marginLeft(), style);
+ case CSSPropertyMarginRight:
+ return createFromLength(style->marginRight(), style);
+ case CSSPropertyMarginTop:
+ return createFromLength(style->marginTop(), style);
+ case CSSPropertyMaxHeight:
+ return createFromLength(style->maxHeight(), style);
+ case CSSPropertyMaxWidth:
+ return createFromLength(style->maxWidth(), style);
+ case CSSPropertyMinHeight:
+ return createFromLength(style->minHeight(), style);
+ case CSSPropertyMinWidth:
+ return createFromLength(style->minWidth(), style);
+ case CSSPropertyPaddingBottom:
+ return createFromLength(style->paddingBottom(), style);
+ case CSSPropertyPaddingLeft:
+ return createFromLength(style->paddingLeft(), style);
+ case CSSPropertyPaddingRight:
+ return createFromLength(style->paddingRight(), style);
+ case CSSPropertyPaddingTop:
+ return createFromLength(style->paddingTop(), style);
+ case CSSPropertyRight:
+ return createFromLength(style->right(), style);
+ case CSSPropertyTop:
+ return createFromLength(style->top(), style);
+ case CSSPropertyWebkitPerspectiveOriginX:
+ return createFromLength(style->perspectiveOriginX(), style);
+ case CSSPropertyWebkitPerspectiveOriginY:
+ return createFromLength(style->perspectiveOriginY(), style);
+ case CSSPropertyWebkitTransformOriginX:
+ return createFromLength(style->transformOriginX(), style);
+ case CSSPropertyWebkitTransformOriginY:
+ return createFromLength(style->transformOriginY(), style);
+ case CSSPropertyWidth:
+ return createFromLength(style->width(), style);
+ default:
+ // FIXME: Generate CSS values for all non-animatable properties and create AnimatableUnknown values out of them.
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::createFromLength(const Length& length, RenderStyle* style)
+{
+ switch (length.type()) {
+ case Relative:
+ return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeNumber);
+ case Fixed:
+ return AnimatableNumber::create(adjustFloatForAbsoluteZoom(length.value(), style), AnimatableNumber::UnitTypeLength);
+ case Percent:
+ return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypePercentage);
+ case ViewportPercentageWidth:
+ return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportWidth);
+ case ViewportPercentageHeight:
+ return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportHeight);
+ case ViewportPercentageMin:
+ return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportMin);
+ case ViewportPercentageMax:
+ return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportMax);
+ case Calculated:
+ // FIXME: Convert platform calcs to CSS calcs.
+ ASSERT_NOT_REACHED();
+ return 0;
+ case Auto:
+ case Intrinsic:
+ case MinIntrinsic:
+ case MinContent:
+ case MaxContent:
+ case FillAvailable:
+ case FitContent:
+ return AnimatableUnknown::create(CSSPrimitiveValue::create(length));
+ case Undefined:
+ return AnimatableUnknown::create(CSSPrimitiveValue::create(CSSValueNone));
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698