Diff
Modified: trunk/Source/WebCore/ChangeLog (105692 => 105693)
--- trunk/Source/WebCore/ChangeLog 2012-01-24 05:19:25 UTC (rev 105692)
+++ trunk/Source/WebCore/ChangeLog 2012-01-24 05:44:22 UTC (rev 105693)
@@ -1,3 +1,28 @@
+2012-01-23 Luke Macpherson <macpher...@chromium.org>
+
+ Implement CSS clip property in CSSStyleApplyProperty.
+ https://bugs.webkit.org/show_bug.cgi?id=74913
+
+ Reviewed by Andreas Kling.
+
+ No new tests / refactoring only.
+
+ * css/CSSPrimitiveValue.h:
+ * css/CSSPrimitiveValueMappings.h:
+ (WebCore::CSSPrimitiveValue::convertToLength):
+ This new function aims to provide a single call for converting many CSSPrimitiveValue
+ values to Lengths. It is templated to allow the caller to specify which conversions
+ are appropriate depending on the context in which the value is used.
+ * css/CSSStyleApplyProperty.cpp:
+ (WebCore::ApplyPropertyClip::convertToLength):
+ (WebCore::ApplyPropertyClip::applyInheritValue):
+ (WebCore::ApplyPropertyClip::applyInitialValue):
+ (WebCore::ApplyPropertyClip::applyValue):
+ (WebCore::ApplyPropertyClip::createHandler):
+ (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
+ * css/CSSStyleSelector.cpp:
+ (WebCore::CSSStyleSelector::applyProperty):
+
2012-01-23 Tom Sepez <tse...@chromium.org>
decodeEscapeSequences() not correct for some encodings (GBK, Big5, ...).
Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (105692 => 105693)
--- trunk/Source/WebCore/css/CSSPrimitiveValue.h 2012-01-24 05:19:25 UTC (rev 105692)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h 2012-01-24 05:44:22 UTC (rev 105693)
@@ -203,6 +203,9 @@
*/
template<typename T> T computeLength(RenderStyle* currStyle, RenderStyle* rootStyle, float multiplier = 1.0f, bool computingFontSize = false);
+ // Converts to a Length, mapping various unit types appropriately.
+ template<int> Length convertToLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
+
// use with care!!!
void setPrimitiveType(unsigned short type) { m_primitiveUnitType = type; }
Modified: trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h (105692 => 105693)
--- trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h 2012-01-24 05:19:25 UTC (rev 105692)
+++ trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h 2012-01-24 05:44:22 UTC (rev 105693)
@@ -36,6 +36,7 @@
#include "FontDescription.h"
#include "FontSmoothingMode.h"
#include "GraphicsTypes.h"
+#include "Length.h"
#include "Path.h"
#include "RenderStyleConstants.h"
#include "SVGRenderStyleDefs.h"
@@ -3673,6 +3674,21 @@
}
}
+enum LengthConversion { UnsupportedConversion = 0, FixedConversion = 1, AutoConversion = 2, PercentConversion = 4, FractionConversion = 8};
+template<int supported> Length CSSPrimitiveValue::convertToLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
+{
+ if ((supported & FixedConversion) && isLength())
+ return computeLength<Length>(style, rootStyle, multiplier, computingFontSize);
+ if ((supported & PercentConversion) && isPercentage())
+ return Length(getDoubleValue(), Percent);
+ if ((supported & FractionConversion) && isNumber())
+ return Length(getDoubleValue() * 100.0, Percent);
+ if ((supported & AutoConversion) && getIdent() == CSSValueAuto)
+ return Length(Auto);
+ ASSERT_NOT_REACHED();
+ return Length(Undefined);
+}
+
#if ENABLE(SVG)
template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EColorInterpolation e)
Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (105692 => 105693)
--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp 2012-01-24 05:19:25 UTC (rev 105692)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp 2012-01-24 05:44:22 UTC (rev 105693)
@@ -35,6 +35,7 @@
#include "Document.h"
#include "Element.h"
#include "Pair.h"
+#include "Rect.h"
#include "RenderObject.h"
#include "RenderStyle.h"
#include "Settings.h"
@@ -212,6 +213,51 @@
static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
};
+class ApplyPropertyClip {
+private:
+ static Length convertToLength(CSSStyleSelector* selector, CSSPrimitiveValue* value)
+ {
+ return value->convertToLength<FixedConversion | PercentConversion | FractionConversion | AutoConversion>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
+ }
+public:
+ static void applyInheritValue(CSSStyleSelector* selector)
+ {
+ RenderStyle* parentStyle = selector->parentStyle();
+ if (!parentStyle->hasClip())
+ return applyInitialValue(selector);
+ selector->style()->setClip(parentStyle->clipTop(), parentStyle->clipRight(), parentStyle->clipBottom(), parentStyle->clipLeft());
+ selector->style()->setHasClip(true);
+ }
+
+ static void applyInitialValue(CSSStyleSelector* selector)
+ {
+ selector->style()->setClip(Length(), Length(), Length(), Length());
+ selector->style()->setHasClip(false);
+ }
+
+ static void applyValue(CSSStyleSelector* selector, CSSValue* value)
+ {
+ if (!value->isPrimitiveValue())
+ return;
+
+ CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
+
+ if (Rect* rect = primitiveValue->getRectValue()) {
+ Length top = convertToLength(selector, rect->top());
+ Length right = convertToLength(selector, rect->right());
+ Length bottom = convertToLength(selector, rect->bottom());
+ Length left = convertToLength(selector, rect->left());
+ selector->style()->setClip(top, right, bottom, left);
+ selector->style()->setHasClip(true);
+ } else if (primitiveValue->getIdent() == CSSValueAuto) {
+ selector->style()->setClip(Length(), Length(), Length(), Length());
+ selector->style()->setHasClip(true);
+ }
+ }
+
+ static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
+};
+
enum ColorInherit {NoInheritFromParent = 0, InheritFromParent};
Color defaultInitialColor();
Color defaultInitialColor() { return Color(); }
@@ -1745,6 +1791,8 @@
setPropertyHandler(CSSPropertyLetterSpacing, ApplyPropertyComputeLength<int, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing, &RenderStyle::initialLetterWordSpacing, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>::createHandler());
setPropertyHandler(CSSPropertyWordSpacing, ApplyPropertyComputeLength<int, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing, &RenderStyle::initialLetterWordSpacing, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>::createHandler());
+ setPropertyHandler(CSSPropertyClip, ApplyPropertyClip::createHandler());
+
setPropertyHandler(CSSPropertyCursor, ApplyPropertyCursor::createHandler());
setPropertyHandler(CSSPropertyCounterIncrement, ApplyPropertyCounter<Increment>::createHandler());
Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (105692 => 105693)
--- trunk/Source/WebCore/css/CSSStyleSelector.cpp 2012-01-24 05:19:25 UTC (rev 105692)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp 2012-01-24 05:44:22 UTC (rev 105693)
@@ -2791,47 +2791,7 @@
case CSSPropertyOrphans:
HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(orphans, Orphans)
return;
-// rect
- case CSSPropertyClip:
- {
- Length top;
- Length right;
- Length bottom;
- Length left;
- bool hasClip = true;
- if (isInherit) {
- if (m_parentStyle->hasClip()) {
- top = m_parentStyle->clipTop();
- right = m_parentStyle->clipRight();
- bottom = m_parentStyle->clipBottom();
- left = m_parentStyle->clipLeft();
- } else {
- hasClip = false;
- top = right = bottom = left = Length();
- }
- } else if (isInitial) {
- hasClip = false;
- top = right = bottom = left = Length();
- } else if (!primitiveValue) {
- return;
- } else if (primitiveValue->isRect()) {
- Rect* rect = primitiveValue->getRectValue();
- if (!rect)
- return;
- top = convertToIntLength(rect->top(), style(), m_rootElementStyle, zoomFactor);
- right = convertToIntLength(rect->right(), style(), m_rootElementStyle, zoomFactor);
- bottom = convertToIntLength(rect->bottom(), style(), m_rootElementStyle, zoomFactor);
- left = convertToIntLength(rect->left(), style(), m_rootElementStyle, zoomFactor);
- } else if (primitiveValue->getIdent() != CSSValueAuto) {
- return;
- }
- m_style->setClip(top, right, bottom, left);
- m_style->setHasClip(hasClip);
- // rect, ident
- return;
- }
-
// lists
case CSSPropertyContent:
// list of string, uri, counter, attr, i
@@ -3767,6 +3727,7 @@
case CSSPropertyBorderSpacing:
case CSSPropertyWebkitBorderHorizontalSpacing:
case CSSPropertyWebkitBorderVerticalSpacing:
+ case CSSPropertyClip:
case CSSPropertyCounterIncrement:
case CSSPropertyCounterReset:
case CSSPropertyLetterSpacing: