| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/css/CSSPropertyEquality.h" | |
| 6 | |
| 7 #include "core/style/ComputedStyle.h" | |
| 8 #include "core/style/DataEquivalency.h" | |
| 9 #include "core/style/ShadowList.h" | |
| 10 | |
| 11 // TODO(ikilpatrick): generate this file. | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 template <CSSPropertyID property> | |
| 18 bool fillLayersEqual(const FillLayer& aLayers, const FillLayer& bLayers) | |
| 19 { | |
| 20 const FillLayer* aLayer = &aLayers; | |
| 21 const FillLayer* bLayer = &bLayers; | |
| 22 while (aLayer && bLayer) { | |
| 23 switch (property) { | |
| 24 case CSSPropertyBackgroundPositionX: | |
| 25 case CSSPropertyWebkitMaskPositionX: | |
| 26 if (aLayer->xPosition() != bLayer->xPosition()) | |
| 27 return false; | |
| 28 break; | |
| 29 case CSSPropertyBackgroundPositionY: | |
| 30 case CSSPropertyWebkitMaskPositionY: | |
| 31 if (aLayer->yPosition() != bLayer->yPosition()) | |
| 32 return false; | |
| 33 break; | |
| 34 case CSSPropertyBackgroundSize: | |
| 35 case CSSPropertyWebkitMaskSize: | |
| 36 if (!(aLayer->sizeLength() == bLayer->sizeLength())) | |
| 37 return false; | |
| 38 break; | |
| 39 case CSSPropertyBackgroundImage: | |
| 40 if (!dataEquivalent(aLayer->image(), bLayer->image())) | |
| 41 return false; | |
| 42 break; | |
| 43 default: | |
| 44 NOTREACHED(); | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 aLayer = aLayer->next(); | |
| 49 bLayer = bLayer->next(); | |
| 50 } | |
| 51 | |
| 52 // FIXME: Shouldn't this be return !aLayer && !bLayer; ? | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 bool CSSPropertyEquality::propertiesEqual(CSSPropertyID prop, const ComputedStyl
e& a, const ComputedStyle& b) | |
| 59 { | |
| 60 switch (prop) { | |
| 61 case CSSPropertyBackgroundColor: | |
| 62 return a.backgroundColor() == b.backgroundColor() | |
| 63 && a.visitedLinkBackgroundColor() == b.visitedLinkBackgroundColor(); | |
| 64 case CSSPropertyBackgroundImage: | |
| 65 return fillLayersEqual<CSSPropertyBackgroundImage>(a.backgroundLayers(),
b.backgroundLayers()); | |
| 66 case CSSPropertyBackgroundPositionX: | |
| 67 return fillLayersEqual<CSSPropertyBackgroundPositionX>(a.backgroundLayer
s(), b.backgroundLayers()); | |
| 68 case CSSPropertyBackgroundPositionY: | |
| 69 return fillLayersEqual<CSSPropertyBackgroundPositionY>(a.backgroundLayer
s(), b.backgroundLayers()); | |
| 70 case CSSPropertyBackgroundSize: | |
| 71 return fillLayersEqual<CSSPropertyBackgroundSize>(a.backgroundLayers(),
b.backgroundLayers()); | |
| 72 case CSSPropertyBaselineShift: | |
| 73 return a.baselineShiftValue() == b.baselineShiftValue(); | |
| 74 case CSSPropertyBorderBottomColor: | |
| 75 return a.borderBottomColor() == b.borderBottomColor() | |
| 76 && a.visitedLinkBorderBottomColor() == b.visitedLinkBorderBottomColo
r(); | |
| 77 case CSSPropertyBorderBottomLeftRadius: | |
| 78 return a.borderBottomLeftRadius() == b.borderBottomLeftRadius(); | |
| 79 case CSSPropertyBorderBottomRightRadius: | |
| 80 return a.borderBottomRightRadius() == b.borderBottomRightRadius(); | |
| 81 case CSSPropertyBorderBottomWidth: | |
| 82 return a.borderBottomWidth() == b.borderBottomWidth(); | |
| 83 case CSSPropertyBorderImageOutset: | |
| 84 return a.borderImageOutset() == b.borderImageOutset(); | |
| 85 case CSSPropertyBorderImageSlice: | |
| 86 return a.borderImageSlices() == b.borderImageSlices(); | |
| 87 case CSSPropertyBorderImageSource: | |
| 88 return dataEquivalent(a.borderImageSource(), b.borderImageSource()); | |
| 89 case CSSPropertyBorderImageWidth: | |
| 90 return a.borderImageWidth() == b.borderImageWidth(); | |
| 91 case CSSPropertyBorderLeftColor: | |
| 92 return a.borderLeftColor() == b.borderLeftColor() | |
| 93 && a.visitedLinkBorderLeftColor() == b.visitedLinkBorderLeftColor(); | |
| 94 case CSSPropertyBorderLeftWidth: | |
| 95 return a.borderLeftWidth() == b.borderLeftWidth(); | |
| 96 case CSSPropertyBorderRightColor: | |
| 97 return a.borderRightColor() == b.borderRightColor() | |
| 98 && a.visitedLinkBorderRightColor() == b.visitedLinkBorderRightColor(
); | |
| 99 case CSSPropertyBorderRightWidth: | |
| 100 return a.borderRightWidth() == b.borderRightWidth(); | |
| 101 case CSSPropertyBorderTopColor: | |
| 102 return a.borderTopColor() == b.borderTopColor() | |
| 103 && a.visitedLinkBorderTopColor() == b.visitedLinkBorderTopColor(); | |
| 104 case CSSPropertyBorderTopLeftRadius: | |
| 105 return a.borderTopLeftRadius() == b.borderTopLeftRadius(); | |
| 106 case CSSPropertyBorderTopRightRadius: | |
| 107 return a.borderTopRightRadius() == b.borderTopRightRadius(); | |
| 108 case CSSPropertyBorderTopWidth: | |
| 109 return a.borderTopWidth() == b.borderTopWidth(); | |
| 110 case CSSPropertyBottom: | |
| 111 return a.bottom() == b.bottom(); | |
| 112 case CSSPropertyBoxShadow: | |
| 113 return dataEquivalent(a.boxShadow(), b.boxShadow()); | |
| 114 case CSSPropertyClip: | |
| 115 return a.clip() == b.clip(); | |
| 116 case CSSPropertyColor: | |
| 117 return a.color() == b.color() && a.visitedLinkColor() == b.visitedLinkCo
lor(); | |
| 118 case CSSPropertyFill: { | |
| 119 const SVGComputedStyle& aSVG = a.svgStyle(); | |
| 120 const SVGComputedStyle& bSVG = b.svgStyle(); | |
| 121 return aSVG.fillPaintType() == bSVG.fillPaintType() | |
| 122 && (aSVG.fillPaintType() != SVG_PAINTTYPE_RGBCOLOR || aSVG.fillPaint
Color() == bSVG.fillPaintColor()) | |
| 123 && aSVG.visitedLinkFillPaintType() == bSVG.visitedLinkFillPaintType(
) | |
| 124 && (aSVG.visitedLinkFillPaintType() != SVG_PAINTTYPE_RGBCOLOR || aSV
G.visitedLinkFillPaintColor() == bSVG.visitedLinkFillPaintColor()); | |
| 125 } | |
| 126 case CSSPropertyFillOpacity: | |
| 127 return a.fillOpacity() == b.fillOpacity(); | |
| 128 case CSSPropertyFlexBasis: | |
| 129 return a.flexBasis() == b.flexBasis(); | |
| 130 case CSSPropertyFlexGrow: | |
| 131 return a.flexGrow() == b.flexGrow(); | |
| 132 case CSSPropertyFlexShrink: | |
| 133 return a.flexShrink() == b.flexShrink(); | |
| 134 case CSSPropertyFloodColor: | |
| 135 return a.floodColor() == b.floodColor(); | |
| 136 case CSSPropertyFloodOpacity: | |
| 137 return a.floodOpacity() == b.floodOpacity(); | |
| 138 case CSSPropertyFontSize: | |
| 139 // CSSPropertyFontSize: Must pass a specified size to setFontSize if Tex
t Autosizing is enabled, but a computed size | |
| 140 // if text zoom is enabled (if neither is enabled it's irrelevant as the
y're probably the same). | |
| 141 // FIXME: Should we introduce an option to pass the computed font size h
ere, allowing consumers to | |
| 142 // enable text zoom rather than Text Autosizing? See http://crbug.com/22
7545. | |
| 143 return a.specifiedFontSize() == b.specifiedFontSize(); | |
| 144 case CSSPropertyFontSizeAdjust: | |
| 145 return a.fontSizeAdjust() == b.fontSizeAdjust(); | |
| 146 case CSSPropertyFontStretch: | |
| 147 return a.fontStretch() == b.fontStretch(); | |
| 148 case CSSPropertyFontWeight: | |
| 149 return a.fontWeight() == b.fontWeight(); | |
| 150 case CSSPropertyHeight: | |
| 151 return a.height() == b.height(); | |
| 152 case CSSPropertyLeft: | |
| 153 return a.left() == b.left(); | |
| 154 case CSSPropertyLetterSpacing: | |
| 155 return a.letterSpacing() == b.letterSpacing(); | |
| 156 case CSSPropertyLightingColor: | |
| 157 return a.lightingColor() == b.lightingColor(); | |
| 158 case CSSPropertyLineHeight: | |
| 159 return a.specifiedLineHeight() == b.specifiedLineHeight(); | |
| 160 case CSSPropertyListStyleImage: | |
| 161 return dataEquivalent(a.listStyleImage(), b.listStyleImage()); | |
| 162 case CSSPropertyMarginBottom: | |
| 163 return a.marginBottom() == b.marginBottom(); | |
| 164 case CSSPropertyMarginLeft: | |
| 165 return a.marginLeft() == b.marginLeft(); | |
| 166 case CSSPropertyMarginRight: | |
| 167 return a.marginRight() == b.marginRight(); | |
| 168 case CSSPropertyMarginTop: | |
| 169 return a.marginTop() == b.marginTop(); | |
| 170 case CSSPropertyMaxHeight: | |
| 171 return a.maxHeight() == b.maxHeight(); | |
| 172 case CSSPropertyMaxWidth: | |
| 173 return a.maxWidth() == b.maxWidth(); | |
| 174 case CSSPropertyMinHeight: | |
| 175 return a.minHeight() == b.minHeight(); | |
| 176 case CSSPropertyMinWidth: | |
| 177 return a.minWidth() == b.minWidth(); | |
| 178 case CSSPropertyMotionOffset: | |
| 179 return a.motionOffset() == b.motionOffset(); | |
| 180 case CSSPropertyMotionRotation: | |
| 181 return a.motionRotation() == b.motionRotation(); | |
| 182 case CSSPropertyObjectPosition: | |
| 183 return a.objectPosition() == b.objectPosition(); | |
| 184 case CSSPropertyOpacity: | |
| 185 return a.opacity() == b.opacity(); | |
| 186 case CSSPropertyOrphans: | |
| 187 return a.orphans() == b.orphans(); | |
| 188 case CSSPropertyOutlineColor: | |
| 189 return a.outlineColor() == b.outlineColor() | |
| 190 && a.visitedLinkOutlineColor() == b.visitedLinkOutlineColor(); | |
| 191 case CSSPropertyOutlineOffset: | |
| 192 return a.outlineOffset() == b.outlineOffset(); | |
| 193 case CSSPropertyOutlineWidth: | |
| 194 return a.outlineWidth() == b.outlineWidth(); | |
| 195 case CSSPropertyPaddingBottom: | |
| 196 return a.paddingBottom() == b.paddingBottom(); | |
| 197 case CSSPropertyPaddingLeft: | |
| 198 return a.paddingLeft() == b.paddingLeft(); | |
| 199 case CSSPropertyPaddingRight: | |
| 200 return a.paddingRight() == b.paddingRight(); | |
| 201 case CSSPropertyPaddingTop: | |
| 202 return a.paddingTop() == b.paddingTop(); | |
| 203 case CSSPropertyRight: | |
| 204 return a.right() == b.right(); | |
| 205 case CSSPropertyShapeImageThreshold: | |
| 206 return a.shapeImageThreshold() == b.shapeImageThreshold(); | |
| 207 case CSSPropertyShapeMargin: | |
| 208 return a.shapeMargin() == b.shapeMargin(); | |
| 209 case CSSPropertyShapeOutside: | |
| 210 return dataEquivalent(a.shapeOutside(), b.shapeOutside()); | |
| 211 case CSSPropertyStopColor: | |
| 212 return a.stopColor() == b.stopColor(); | |
| 213 case CSSPropertyStopOpacity: | |
| 214 return a.stopOpacity() == b.stopOpacity(); | |
| 215 case CSSPropertyStroke: { | |
| 216 const SVGComputedStyle& aSVG = a.svgStyle(); | |
| 217 const SVGComputedStyle& bSVG = b.svgStyle(); | |
| 218 return aSVG.strokePaintType() == bSVG.strokePaintType() | |
| 219 && (aSVG.strokePaintType() != SVG_PAINTTYPE_RGBCOLOR || aSVG.strokeP
aintColor() == bSVG.strokePaintColor()) | |
| 220 && aSVG.visitedLinkStrokePaintType() == bSVG.visitedLinkStrokePaintT
ype() | |
| 221 && (aSVG.visitedLinkStrokePaintType() != SVG_PAINTTYPE_RGBCOLOR || a
SVG.visitedLinkStrokePaintColor() == bSVG.visitedLinkStrokePaintColor()); | |
| 222 } | |
| 223 case CSSPropertyStrokeDasharray: | |
| 224 return a.strokeDashArray() == b.strokeDashArray(); | |
| 225 case CSSPropertyStrokeDashoffset: | |
| 226 return a.strokeDashOffset() == b.strokeDashOffset(); | |
| 227 case CSSPropertyStrokeMiterlimit: | |
| 228 return a.strokeMiterLimit() == b.strokeMiterLimit(); | |
| 229 case CSSPropertyStrokeOpacity: | |
| 230 return a.strokeOpacity() == b.strokeOpacity(); | |
| 231 case CSSPropertyStrokeWidth: | |
| 232 return a.strokeWidth() == b.strokeWidth(); | |
| 233 case CSSPropertyTextDecorationColor: | |
| 234 return a.textDecorationColor() == b.textDecorationColor() | |
| 235 && a.visitedLinkTextDecorationColor() == b.visitedLinkTextDecoration
Color(); | |
| 236 case CSSPropertyTextIndent: | |
| 237 return a.textIndent() == b.textIndent(); | |
| 238 case CSSPropertyTextShadow: | |
| 239 return dataEquivalent(a.textShadow(), b.textShadow()); | |
| 240 case CSSPropertyTop: | |
| 241 return a.top() == b.top(); | |
| 242 case CSSPropertyVerticalAlign: | |
| 243 return a.verticalAlign() == b.verticalAlign() | |
| 244 && (a.verticalAlign() != VerticalAlignLength || a.getVerticalAlignLe
ngth() == b.getVerticalAlignLength()); | |
| 245 case CSSPropertyVisibility: | |
| 246 return a.visibility() == b.visibility(); | |
| 247 case CSSPropertyWebkitBorderHorizontalSpacing: | |
| 248 return a.horizontalBorderSpacing() == b.horizontalBorderSpacing(); | |
| 249 case CSSPropertyWebkitBorderVerticalSpacing: | |
| 250 return a.verticalBorderSpacing() == b.verticalBorderSpacing(); | |
| 251 case CSSPropertyWebkitClipPath: | |
| 252 return dataEquivalent(a.clipPath(), b.clipPath()); | |
| 253 case CSSPropertyColumnCount: | |
| 254 return a.columnCount() == b.columnCount(); | |
| 255 case CSSPropertyColumnGap: | |
| 256 return a.columnGap() == b.columnGap(); | |
| 257 case CSSPropertyColumnRuleColor: | |
| 258 return a.columnRuleColor() == b.columnRuleColor() | |
| 259 && a.visitedLinkColumnRuleColor() == b.visitedLinkColumnRuleColor(); | |
| 260 case CSSPropertyColumnRuleWidth: | |
| 261 return a.columnRuleWidth() == b.columnRuleWidth(); | |
| 262 case CSSPropertyColumnWidth: | |
| 263 return a.columnWidth() == b.columnWidth(); | |
| 264 case CSSPropertyWebkitFilter: | |
| 265 return a.filter() == b.filter(); | |
| 266 case CSSPropertyBackdropFilter: | |
| 267 return a.backdropFilter() == b.backdropFilter(); | |
| 268 case CSSPropertyWebkitMaskBoxImageOutset: | |
| 269 return a.maskBoxImageOutset() == b.maskBoxImageOutset(); | |
| 270 case CSSPropertyWebkitMaskBoxImageSlice: | |
| 271 return a.maskBoxImageSlices() == b.maskBoxImageSlices(); | |
| 272 case CSSPropertyWebkitMaskBoxImageSource: | |
| 273 return dataEquivalent(a.maskBoxImageSource(), b.maskBoxImageSource()); | |
| 274 case CSSPropertyWebkitMaskBoxImageWidth: | |
| 275 return a.maskBoxImageWidth() == b.maskBoxImageWidth(); | |
| 276 case CSSPropertyWebkitMaskImage: | |
| 277 return dataEquivalent(a.maskImage(), b.maskImage()); | |
| 278 case CSSPropertyWebkitMaskPositionX: | |
| 279 return fillLayersEqual<CSSPropertyWebkitMaskPositionX>(a.maskLayers(), b
.maskLayers()); | |
| 280 case CSSPropertyWebkitMaskPositionY: | |
| 281 return fillLayersEqual<CSSPropertyWebkitMaskPositionY>(a.maskLayers(), b
.maskLayers()); | |
| 282 case CSSPropertyWebkitMaskSize: | |
| 283 return fillLayersEqual<CSSPropertyWebkitMaskSize>(a.maskLayers(), b.mask
Layers()); | |
| 284 case CSSPropertyPerspective: | |
| 285 return a.perspective() == b.perspective(); | |
| 286 case CSSPropertyPerspectiveOrigin: | |
| 287 return a.perspectiveOriginX() == b.perspectiveOriginX() && a.perspective
OriginY() == b.perspectiveOriginY(); | |
| 288 case CSSPropertyWebkitTextStrokeColor: | |
| 289 return a.textStrokeColor() == b.textStrokeColor() | |
| 290 && a.visitedLinkTextStrokeColor() == b.visitedLinkTextStrokeColor(); | |
| 291 case CSSPropertyTransform: | |
| 292 return a.transform() == b.transform(); | |
| 293 case CSSPropertyTranslate: | |
| 294 return dataEquivalent<TransformOperation>(a.translate(), b.translate()); | |
| 295 case CSSPropertyRotate: | |
| 296 return dataEquivalent<TransformOperation>(a.rotate(), b.rotate()); | |
| 297 case CSSPropertyScale: | |
| 298 return dataEquivalent<TransformOperation>(a.scale(), b.scale()); | |
| 299 case CSSPropertyTransformOrigin: | |
| 300 return a.transformOriginX() == b.transformOriginX() && a.transformOrigin
Y() == b.transformOriginY() && a.transformOriginZ() == b.transformOriginZ(); | |
| 301 case CSSPropertyWebkitPerspectiveOriginX: | |
| 302 return a.perspectiveOriginX() == b.perspectiveOriginX(); | |
| 303 case CSSPropertyWebkitPerspectiveOriginY: | |
| 304 return a.perspectiveOriginY() == b.perspectiveOriginY(); | |
| 305 case CSSPropertyWebkitTransformOriginX: | |
| 306 return a.transformOriginX() == b.transformOriginX(); | |
| 307 case CSSPropertyWebkitTransformOriginY: | |
| 308 return a.transformOriginY() == b.transformOriginY(); | |
| 309 case CSSPropertyWebkitTransformOriginZ: | |
| 310 return a.transformOriginZ() == b.transformOriginZ(); | |
| 311 case CSSPropertyWidows: | |
| 312 return a.widows() == b.widows(); | |
| 313 case CSSPropertyWidth: | |
| 314 return a.width() == b.width(); | |
| 315 case CSSPropertyWordSpacing: | |
| 316 return a.wordSpacing() == b.wordSpacing(); | |
| 317 case CSSPropertyD: | |
| 318 return dataEquivalent(a.svgStyle().d(), b.svgStyle().d()); | |
| 319 case CSSPropertyCx: | |
| 320 return a.svgStyle().cx() == b.svgStyle().cx(); | |
| 321 case CSSPropertyCy: | |
| 322 return a.svgStyle().cy() == b.svgStyle().cy(); | |
| 323 case CSSPropertyX: | |
| 324 return a.svgStyle().x() == b.svgStyle().x(); | |
| 325 case CSSPropertyY: | |
| 326 return a.svgStyle().y() == b.svgStyle().y(); | |
| 327 case CSSPropertyR: | |
| 328 return a.svgStyle().r() == b.svgStyle().r(); | |
| 329 case CSSPropertyRx: | |
| 330 return a.svgStyle().rx() == b.svgStyle().rx(); | |
| 331 case CSSPropertyRy: | |
| 332 return a.svgStyle().ry() == b.svgStyle().ry(); | |
| 333 case CSSPropertyZIndex: | |
| 334 return a.hasAutoZIndex() == b.hasAutoZIndex() && (a.hasAutoZIndex() || a
.zIndex() == b.zIndex()); | |
| 335 default: | |
| 336 NOTREACHED(); | |
| 337 return true; | |
| 338 } | |
| 339 } | |
| 340 | |
| 341 } // namespace blink | |
| OLD | NEW |