Pass Aspect Ratio to RenderStyle
authorfsamuel@chromium.org <fsamuel@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 20:09:34 +0000 (20:09 +0000)
committerfsamuel@chromium.org <fsamuel@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 20:09:34 +0000 (20:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72350

Reviewed by Ojan Vafai.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyAspectRatio::applyInheritValue):
(WebCore::ApplyPropertyAspectRatio::applyInitialValue):
(WebCore::ApplyPropertyAspectRatio::applyValue):
(WebCore::ApplyPropertyAspectRatio::createHandler):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
* css/CSSValue.h:
(WebCore::CSSValue::isAspectRatioValue):
* rendering/style/RenderStyle.h:
(WebCore::InheritedFlags::hasAspectRatio):
(WebCore::InheritedFlags::aspectRatio):
(WebCore::InheritedFlags::aspectRatioDenominator):
(WebCore::InheritedFlags::aspectRatioNumerator):
(WebCore::InheritedFlags::setHasAspectRatio):
(WebCore::InheritedFlags::setAspectRatioDenominator):
(WebCore::InheritedFlags::setAspectRatioNumerator):
(WebCore::InheritedFlags::initialHasAspectRatio):
(WebCore::InheritedFlags::initialAspectRatioDenominator):
(WebCore::InheritedFlags::initialAspectRatioNumerator):
* rendering/style/StyleRareNonInheritedData.cpp:
(WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
(WebCore::StyleRareNonInheritedData::operator==):
* rendering/style/StyleRareNonInheritedData.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@100656 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSStyleApplyProperty.cpp
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/css/CSSValue.h
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp
Source/WebCore/rendering/style/StyleRareNonInheritedData.h

index f05a0cf54f6a06e90fe4af58efc57b1d81471310..49a07820927fa10f6eec6bd9e7cff490aea6b3ac 100755 (executable)
@@ -1,3 +1,38 @@
+2011-11-17  Fady Samuel  <fsamuel@chromium.org>
+
+        Pass Aspect Ratio to RenderStyle
+        https://bugs.webkit.org/show_bug.cgi?id=72350
+
+        Reviewed by Ojan Vafai.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyAspectRatio::applyInheritValue):
+        (WebCore::ApplyPropertyAspectRatio::applyInitialValue):
+        (WebCore::ApplyPropertyAspectRatio::applyValue):
+        (WebCore::ApplyPropertyAspectRatio::createHandler):
+        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        * css/CSSValue.h:
+        (WebCore::CSSValue::isAspectRatioValue):
+        * rendering/style/RenderStyle.h:
+        (WebCore::InheritedFlags::hasAspectRatio):
+        (WebCore::InheritedFlags::aspectRatio):
+        (WebCore::InheritedFlags::aspectRatioDenominator):
+        (WebCore::InheritedFlags::aspectRatioNumerator):
+        (WebCore::InheritedFlags::setHasAspectRatio):
+        (WebCore::InheritedFlags::setAspectRatioDenominator):
+        (WebCore::InheritedFlags::setAspectRatioNumerator):
+        (WebCore::InheritedFlags::initialHasAspectRatio):
+        (WebCore::InheritedFlags::initialAspectRatioDenominator):
+        (WebCore::InheritedFlags::initialAspectRatioNumerator):
+        * rendering/style/StyleRareNonInheritedData.cpp:
+        (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
+        (WebCore::StyleRareNonInheritedData::operator==):
+        * rendering/style/StyleRareNonInheritedData.h:
+
 2011-11-09  Robert Hogan  <robert@webkit.org>
 
         CSS 2.1 failure: outline-color-* tests fail
index f0383bdb62e8fbab87284b229e490dfc50aa8766..af94688e30675740f5c4160b7b676ef47e2d6445 100644 (file)
@@ -1876,6 +1876,10 @@ PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int proper
             return getTimingFunctionValue(style->animations());
         case CSSPropertyWebkitAppearance:
             return primitiveValueCache->createValue(style->appearance());
+        case CSSPropertyWebkitAspectRatio:
+            if (!style->hasAspectRatio())
+                return primitiveValueCache->createIdentifierValue(CSSValueNone);
+            return primitiveValueCache->createValue(style->aspectRatio(), CSSPrimitiveValue::CSS_NUMBER);
         case CSSPropertyWebkitBackfaceVisibility:
             return primitiveValueCache->createIdentifierValue((style->backfaceVisibility() == BackfaceVisibilityHidden) ? CSSValueHidden : CSSValueVisible);
         case CSSPropertyWebkitBorderImage:
@@ -2070,7 +2074,6 @@ PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(int proper
             break;
 
         /* Unimplemented CSS 3 properties (including CSS3 shorthand properties) */
-        case CSSPropertyWebkitAspectRatio:
         case CSSPropertyWebkitTextEmphasis:
         case CSSPropertyTextLineThrough:
         case CSSPropertyTextLineThroughColor:
index 7daf3d0a2b6a9495132c2831296ebbe31c023cb8..5a6a72f38472ec37dc3b7f0269bed747c05d6ce9 100644 (file)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "CSSStyleApplyProperty.h"
 
+#include "CSSAspectRatioValue.h"
 #include "CSSCursorImageValue.h"
 #include "CSSFlexValue.h"
 #include "CSSPrimitiveValueMappings.h"
@@ -831,6 +832,41 @@ public:
     static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
 };
 
+class ApplyPropertyAspectRatio {
+public:
+    static void applyInheritValue(CSSStyleSelector* selector)
+    {
+        if (!selector->parentStyle()->hasAspectRatio())
+            return;
+        selector->style()->setAspectRatioDenominator(selector->parentStyle()->aspectRatioDenominator());
+        selector->style()->setAspectRatioNumerator(selector->parentStyle()->aspectRatioNumerator());
+    }
+
+    static void applyInitialValue(CSSStyleSelector* selector)
+    {
+        selector->style()->setHasAspectRatio(RenderStyle::initialHasAspectRatio());
+        selector->style()->setAspectRatioDenominator(RenderStyle::initialAspectRatioDenominator());
+        selector->style()->setAspectRatioNumerator(RenderStyle::initialAspectRatioNumerator());
+    }
+
+    static void applyValue(CSSStyleSelector* selector, CSSValue* value)
+    {
+        if (!value->isAspectRatioValue()) {
+            selector->style()->setHasAspectRatio(false);
+            return;
+        }
+        CSSAspectRatioValue* aspectRatioValue = static_cast<CSSAspectRatioValue*>(value);
+        selector->style()->setHasAspectRatio(true);
+        selector->style()->setAspectRatioDenominator(aspectRatioValue->denominatorValue());
+        selector->style()->setAspectRatioNumerator(aspectRatioValue->numeratorValue());
+    }
+
+    static PropertyHandler createHandler()
+    {
+        return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue);
+    }
+};
+
 const CSSStyleApplyProperty& CSSStyleApplyProperty::sharedCSSStyleApplyProperty()
 {
     DEFINE_STATIC_LOCAL(CSSStyleApplyProperty, cssStyleApplyPropertyInstance, ());
@@ -842,6 +878,8 @@ CSSStyleApplyProperty::CSSStyleApplyProperty()
     for (int i = 0; i < numCSSProperties; ++i)
         m_propertyMap[i] = PropertyHandler();
 
+    setPropertyHandler(CSSPropertyWebkitAspectRatio, ApplyPropertyAspectRatio::createHandler());
+
     setPropertyHandler(CSSPropertyColor, ApplyPropertyColor<InheritFromParent, &RenderStyle::color, &RenderStyle::setColor, &RenderStyle::setVisitedLinkColor, &RenderStyle::invalidColor, RenderStyle::initialColor>::createHandler());
     setPropertyHandler(CSSPropertyDirection, ApplyPropertyDirection<&RenderStyle::direction, &RenderStyle::setDirection, RenderStyle::initialDirection>::createHandler());
 
index 02ed22d1cfea79e6aba4055fa02637c33cb351ae..295f5c7e7c7ad1a24740674fd00bb36a6c996bb0 100644 (file)
 #include "CSSStyleSelector.h"
 
 #include "Attribute.h"
+#include "CachedImage.h"
 #include "ContentData.h"
+#include "Counter.h"
 #include "CounterContent.h"
-#include "CursorList.h"
 #include "CSSBorderImageValue.h"
 #include "CSSCursorImageValue.h"
 #include "CSSFontFaceRule.h"
@@ -53,8 +54,7 @@
 #include "CSSStyleSheet.h"
 #include "CSSTimingFunctionValue.h"
 #include "CSSValueList.h"
-#include "CachedImage.h"
-#include "Counter.h"
+#include "CursorList.h"
 #if ENABLE(CSS_FILTERS)
 #include "FilterOperation.h"
 #endif
@@ -3822,7 +3822,6 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
     case CSSPropertyTextUnderlineMode:
     case CSSPropertyTextUnderlineStyle:
     case CSSPropertyTextUnderlineWidth:
-    case CSSPropertyWebkitAspectRatio:
     case CSSPropertyWebkitFontSizeDelta:
     case CSSPropertyWebkitTextDecorationsInEffect:
     case CSSPropertyWebkitTextStroke:
@@ -3925,6 +3924,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
     case CSSPropertyBackgroundOrigin:
     case CSSPropertyWebkitBackgroundOrigin:
     case CSSPropertyBackgroundImage:
+    case CSSPropertyWebkitAspectRatio:
     case CSSPropertyBackgroundSize:
     case CSSPropertyWebkitBackgroundSize:
     case CSSPropertyWebkitMaskAttachment:
index 63b16ea18bbc4570e524b9c5e0317eef4b10c553..90b8aef290320586c4c7be112c6c07466ef2f1f8 100644 (file)
@@ -59,6 +59,7 @@ public:
     bool isPrimitiveValue() const { return m_isPrimitive; }
     bool isValueList() const { return m_isList; }
 
+    bool isAspectRatioValue() const { return m_classType == AspectRatioClass; }
     bool isBorderImageValue() const { return m_classType == BorderImageClass; }
     bool isBorderImageSliceValue() const { return m_classType == BorderImageSliceClass; }
     bool isCursorImageValue() const { return m_classType == CursorImageClass; }
index 047d82dde59c01ae412a11ff13f94bdeffaf78b9..d5397c6f4d97e87475d1ef0ef9a0f05e3c2b9302 100644 (file)
@@ -701,6 +701,11 @@ public:
     ColorSpace colorSpace() const { return static_cast<ColorSpace>(rareInheritedData->colorSpace); }
     float opacity() const { return rareNonInheritedData->opacity; }
     ControlPart appearance() const { return static_cast<ControlPart>(rareNonInheritedData->m_appearance); }
+    // aspect ratio convenience method
+    bool hasAspectRatio() const { return rareNonInheritedData->m_hasAspectRatio; }
+    float aspectRatio() const { return aspectRatioNumerator() / aspectRatioDenominator(); }
+    float aspectRatioDenominator() const { return rareNonInheritedData->m_aspectRatioDenominator; }
+    float aspectRatioNumerator() const { return rareNonInheritedData->m_aspectRatioNumerator; }
     EBoxAlignment boxAlign() const { return static_cast<EBoxAlignment>(rareNonInheritedData->m_deprecatedFlexibleBox->align); }
     EBoxDirection boxDirection() const { return static_cast<EBoxDirection>(inherited_flags._box_direction); }
     float boxFlex() { return rareNonInheritedData->m_deprecatedFlexibleBox->flex; }
@@ -1054,6 +1059,9 @@ public:
     void setEmptyCells(EEmptyCell v) { inherited_flags._empty_cells = v; }
     void setCaptionSide(ECaptionSide v) { inherited_flags._caption_side = v; }
 
+    void setHasAspectRatio(bool b) { SET_VAR(rareNonInheritedData, m_hasAspectRatio, b); }
+    void setAspectRatioDenominator(float v) { SET_VAR(rareNonInheritedData, m_aspectRatioDenominator, v); }
+    void setAspectRatioNumerator(float v) { SET_VAR(rareNonInheritedData, m_aspectRatioNumerator, v); }
     void setCounterIncrement(short v) { SET_VAR(rareNonInheritedData, m_counterIncrement, v) }
     void setCounterReset(short v) { SET_VAR(rareNonInheritedData, m_counterReset, v) }
 
@@ -1463,6 +1471,9 @@ public:
     static EBorderFit initialBorderFit() { return BorderFitBorder; }
     static EResize initialResize() { return RESIZE_NONE; }
     static ControlPart initialAppearance() { return NoControlPart; }
+    static bool initialHasAspectRatio() { return false; }
+    static float initialAspectRatioDenominator() { return 1; }
+    static float initialAspectRatioNumerator() { return 1; }
     static Order initialRTLOrdering() { return LogicalOrder; }
     static float initialTextStrokeWidth() { return 0; }
     static unsigned short initialColumnCount() { return 1; }
index fc139d1e278ecf7164354169684cfce2b47cd27c..788a488d8e6df79a758dd6d9790ce23dec142479 100644 (file)
@@ -35,6 +35,8 @@ namespace WebCore {
 
 StyleRareNonInheritedData::StyleRareNonInheritedData()
     : opacity(RenderStyle::initialOpacity())
+    , m_aspectRatioDenominator(RenderStyle::initialAspectRatioDenominator())
+    , m_aspectRatioNumerator(RenderStyle::initialAspectRatioNumerator())
     , m_counterIncrement(0)
     , m_counterReset(0)
     , m_perspective(RenderStyle::initialPerspective())
@@ -66,6 +68,7 @@ StyleRareNonInheritedData::StyleRareNonInheritedData()
     , m_textCombine(RenderStyle::initialTextCombine())
     , m_wrapFlow(RenderStyle::initialWrapFlow())
     , m_wrapThrough(RenderStyle::initialWrapThrough())
+    , m_hasAspectRatio(false)
 #if USE(ACCELERATED_COMPOSITING)
     , m_runningAcceleratedAnimation(false)
 #endif
@@ -76,6 +79,8 @@ StyleRareNonInheritedData::StyleRareNonInheritedData()
 StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInheritedData& o)
     : RefCounted<StyleRareNonInheritedData>()
     , opacity(o.opacity)
+    , m_aspectRatioDenominator(o.m_aspectRatioDenominator)
+    , m_aspectRatioNumerator(o.m_aspectRatioNumerator)
     , m_counterIncrement(o.m_counterIncrement)
     , m_counterReset(o.m_counterReset)
     , m_perspective(o.m_perspective)
@@ -127,6 +132,7 @@ StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInherited
     , m_textCombine(o.m_textCombine)
     , m_wrapFlow(o.m_wrapFlow)
     , m_wrapThrough(o.m_wrapThrough)
+    , m_hasAspectRatio(o.m_hasAspectRatio)
 #if USE(ACCELERATED_COMPOSITING)
     , m_runningAcceleratedAnimation(o.m_runningAcceleratedAnimation)
 #endif
@@ -162,8 +168,11 @@ bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) c
         && m_appearance == o.m_appearance
         && m_borderFit == o.m_borderFit
         && m_textCombine == o.m_textCombine
+        && m_aspectRatioDenominator == o.m_aspectRatioDenominator
+        && m_aspectRatioNumerator == o.m_aspectRatioNumerator
         && m_counterIncrement == o.m_counterIncrement
         && m_counterReset == o.m_counterReset
+        && m_hasAspectRatio == o.m_hasAspectRatio
 #if USE(ACCELERATED_COMPOSITING)
         && !m_runningAcceleratedAnimation && !o.m_runningAcceleratedAnimation
 #endif
index 0023e74e7f2675fd236c0a3549fac9e3a50c645c..e2c62bc7365b249d755ab006e0f64280dff0ad17 100644 (file)
@@ -89,6 +89,9 @@ public:
 
     float opacity; // Whether or not we're transparent.
 
+    float m_aspectRatioDenominator;
+    float m_aspectRatioNumerator;
+
     short m_counterIncrement;
     short m_counterReset;
 
@@ -161,6 +164,7 @@ public:
     unsigned m_wrapFlow: 3; // WrapFlow
     unsigned m_wrapThrough: 1; // WrapThrough
 
+    bool m_hasAspectRatio : 1; // Whether or not an aspect ratio has been specified.
 #if USE(ACCELERATED_COMPOSITING)
     bool m_runningAcceleratedAnimation : 1;
 #endif