Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. |
| 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. | 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. |
| 5 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 5 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/css/StylePropertySerializer.h" | 24 #include "core/css/StylePropertySerializer.h" |
| 25 | 25 |
| 26 #include "CSSValueKeywords.h" | 26 #include "CSSValueKeywords.h" |
| 27 #include "StylePropertyShorthand.h" | 27 #include "StylePropertyShorthand.h" |
| 28 #include "core/css/CSSValuePool.h" | |
| 28 #include "core/css/RuntimeCSSEnabled.h" | 29 #include "core/css/RuntimeCSSEnabled.h" |
| 29 #include "wtf/BitArray.h" | 30 #include "wtf/BitArray.h" |
| 30 #include "wtf/text/StringBuilder.h" | 31 #include "wtf/text/StringBuilder.h" |
| 31 | 32 |
| 32 using namespace std; | 33 using namespace std; |
| 33 | 34 |
| 34 namespace WebCore { | 35 namespace WebCore { |
| 35 | 36 |
| 36 static bool isInitialOrInherit(const String& value) | 37 static bool isInitialOrInherit(const String& value) |
| 37 { | 38 { |
| 38 DEFINE_STATIC_LOCAL(String, initial, ("initial")); | 39 DEFINE_STATIC_LOCAL(String, initial, ("initial")); |
| 39 DEFINE_STATIC_LOCAL(String, inherit, ("inherit")); | 40 DEFINE_STATIC_LOCAL(String, inherit, ("inherit")); |
| 40 return value.length() == 7 && (value == initial || value == inherit); | 41 return value.length() == 7 && (value == initial || value == inherit); |
| 41 } | 42 } |
| 42 | 43 |
| 44 static bool isAffectedByAllProperty(CSSPropertyID propertyID) | |
| 45 { | |
| 46 return propertyID != CSSPropertyUnicodeBidi && propertyID != CSSPropertyDire ction; | |
| 47 } | |
| 48 | |
| 49 static bool shouldExpandAll(const StylePropertySet& properties) | |
| 50 { | |
| 51 int allIndex = properties.findPropertyIndex(CSSPropertyAll); | |
| 52 if (allIndex == -1) | |
| 53 return false; | |
| 54 | |
| 55 for (unsigned i = 0; i < properties.propertyCount(); ++i) { | |
| 56 StylePropertySet::PropertyReference property = properties.propertyAt(i); | |
| 57 if (isAffectedByAllProperty(property.id()) && property.id() != CSSProper tyAll) | |
| 58 return true; | |
| 59 } | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 static bool canAllOverwriteProperty(StylePropertySet::PropertyReference all, uns igned allIndex, StylePropertySet::PropertyReference property, unsigned propertyI ndex) | |
|
esprehn
2014/05/30 00:59:22
const StylePropertySet::PropertyReference&
tasak
2014/06/04 09:37:41
Done.
| |
| 64 { | |
| 65 if (allIndex == propertyIndex) | |
| 66 return true; | |
| 67 if (!isAffectedByAllProperty(property.id())) | |
| 68 return false; | |
| 69 if (all.isImportant() != property.isImportant()) | |
| 70 return all.isImportant(); | |
| 71 return propertyIndex < allIndex; | |
| 72 } | |
| 73 | |
| 43 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies) | 74 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies) |
| 44 : m_propertySet(properties) | 75 : m_propertySet(properties) |
| 45 { | 76 { |
| 77 if (!shouldExpandAll(properties)) | |
| 78 return; | |
| 79 | |
| 80 unsigned allIndex = properties.findPropertyIndex(CSSPropertyAll); | |
| 81 StylePropertySet::PropertyReference all = properties.propertyAt(allIndex); | |
| 82 BitArray<numCSSProperties> shorthandPropertyAppeared; | |
| 83 | |
| 84 m_propertyVector = adoptPtr(new Vector<CSSPropertyInternal>()); | |
|
esprehn
2014/05/30 00:59:22
Why heap allocate this if the constructor is alway
tasak
2014/06/04 09:37:40
I changed m_propertyVector, from OwnPtr<Vector..>
| |
| 85 | |
| 86 unsigned position = 0; | |
| 87 for (unsigned i = 0; i < properties.propertyCount(); ++i) { | |
|
esprehn
2014/05/30 00:59:22
All of this needs to be in a method.
the early re
tasak
2014/06/04 09:37:40
Done.
| |
| 88 StylePropertySet::PropertyReference property = properties.propertyAt(i); | |
| 89 CSSPropertyID propertyId = property.id(); | |
| 90 | |
| 91 if (propertyId == CSSPropertyAll) | |
| 92 position = m_propertyVector->size(); | |
| 93 | |
| 94 if (!canAllOverwriteProperty(all, allIndex, property, i)) { | |
| 95 m_propertyVector->append(CSSPropertyInternal(property)); | |
| 96 | |
| 97 unsigned shortPropertyIndex = property.id() - firstCSSProperty; | |
| 98 shorthandPropertyAppeared.set(shortPropertyIndex); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 bool allIsUnset = !all.value()->isInitialValue() && !all.value()->isInherite dValue(); | |
| 103 CSSValue* value = all.value(); | |
| 104 | |
| 105 for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) { | |
| 106 CSSPropertyID propertyId = static_cast<CSSPropertyID>(i); | |
| 107 | |
| 108 if (isExpandedShorthandForAll(propertyId)) | |
| 109 continue; | |
| 110 if (propertyId == CSSPropertyAll || !isAffectedByAllProperty(propertyId) ) | |
| 111 continue; | |
| 112 if (shorthandPropertyAppeared.get(i - firstCSSProperty)) | |
| 113 continue; | |
| 114 | |
| 115 if (allIsUnset) { | |
| 116 if (CSSProperty::isInheritedProperty(propertyId)) | |
| 117 value = cssValuePool().createInheritedValue().get(); | |
| 118 else | |
| 119 value = cssValuePool().createExplicitInitialValue().get(); | |
| 120 } | |
| 121 m_propertyVector->insert(position++, CSSPropertyInternal(propertyId, val ue, all.isImportant(), value->isInheritedValue(), all.isImplicit())); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 unsigned StylePropertySerializer::propertyCount() const | |
| 126 { | |
| 127 if (!m_propertyVector) | |
| 128 return m_propertySet.propertyCount(); | |
| 129 | |
| 130 return m_propertyVector->size(); | |
| 131 } | |
| 132 | |
| 133 StylePropertySerializer::CSSPropertyInternal StylePropertySerializer::propertyAt (unsigned index) const | |
|
esprehn
2014/05/30 00:59:22
Is this private? PropertyInternal doesn't seem lik
tasak
2014/06/04 09:37:41
Yes, this is private.
| |
| 134 { | |
| 135 if (!m_propertyVector) | |
| 136 return CSSPropertyInternal(m_propertySet.propertyAt(index)); | |
| 137 | |
| 138 return m_propertyVector->at(index); | |
| 139 } | |
| 140 | |
| 141 String StylePropertySerializer::getPropertyValueInternal(CSSPropertyID propertyI d) const | |
|
esprehn
2014/05/30 00:59:22
these are all named wrong. propertyValue() and suc
tasak
2014/06/04 09:37:40
Done.
Now propertyValue().
| |
| 142 { | |
| 143 if (!m_propertyVector) | |
| 144 return m_propertySet.getPropertyValue(propertyId); | |
| 145 | |
| 146 int index = findPropertyIndex(propertyId); | |
| 147 if (index == -1) | |
| 148 return String(); | |
| 149 if (CSSValue* value = m_propertyVector->at(index).value()) | |
| 150 return value->cssText(); | |
| 151 return String(); | |
| 152 } | |
| 153 | |
| 154 CSSValue* StylePropertySerializer::getPropertyCSSValue(CSSPropertyID propertyId) const | |
| 155 { | |
| 156 if (!m_propertyVector) | |
| 157 return m_propertySet.getPropertyCSSValue(propertyId).get(); | |
| 158 | |
| 159 int index = findPropertyIndex(propertyId); | |
| 160 if (index == -1) | |
| 161 return 0; | |
| 162 return m_propertyVector->at(index).value(); | |
| 163 } | |
| 164 | |
| 165 int StylePropertySerializer::findPropertyIndex(CSSPropertyID propertyId) const | |
| 166 { | |
| 167 if (!m_propertyVector) | |
| 168 return m_propertySet.findPropertyIndex(propertyId); | |
| 169 | |
| 170 for (unsigned i = 0; i < m_propertyVector->size(); ++i) { | |
| 171 if (m_propertyVector->at(i).id() == propertyId) | |
| 172 return i; | |
| 173 } | |
| 174 return -1; | |
| 175 } | |
| 176 | |
| 177 bool StylePropertySerializer::isPropertyImplicit(CSSPropertyID propertyId) const | |
| 178 { | |
| 179 if (!m_propertyVector) | |
| 180 return m_propertySet.isPropertyImplicit(propertyId); | |
| 181 | |
| 182 int index = findPropertyIndex(propertyId); | |
| 183 if (index == -1) | |
| 184 return false; | |
| 185 return m_propertyVector->at(index).isImplicit(); | |
| 186 } | |
| 187 | |
| 188 bool StylePropertySerializer::propertyIsImportant(CSSPropertyID propertyId) cons t | |
| 189 { | |
| 190 if (!m_propertyVector) | |
| 191 return m_propertySet.propertyIsImportant(propertyId); | |
| 192 | |
| 193 int index = findPropertyIndex(propertyId); | |
| 194 if (index == -1) | |
| 195 return false; | |
| 196 return m_propertyVector->at(index).isImportant(); | |
| 46 } | 197 } |
| 47 | 198 |
| 48 String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const | 199 String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const |
| 49 { | 200 { |
| 50 StringBuilder result; | 201 StringBuilder result; |
| 51 if (isNotFirstDecl) | 202 if (isNotFirstDecl) |
| 52 result.append(' '); | 203 result.append(' '); |
| 53 result.append(getPropertyName(propertyID)); | 204 result.append(getPropertyName(propertyID)); |
| 54 result.appendLiteral(": "); | 205 result.appendLiteral(": "); |
| 55 result.append(value); | 206 result.append(value); |
| 56 if (isImportant) | 207 if (isImportant) |
| 57 result.appendLiteral(" !important"); | 208 result.appendLiteral(" !important"); |
| 58 result.append(';'); | 209 result.append(';'); |
| 59 return result.toString(); | 210 return result.toString(); |
| 60 } | 211 } |
| 61 | 212 |
| 62 String StylePropertySerializer::asText() const | 213 String StylePropertySerializer::asText() const |
| 63 { | 214 { |
| 64 StringBuilder result; | 215 StringBuilder result; |
| 65 | 216 |
| 217 String allValue; | |
| 218 if (hasAllShorthand(allValue)) | |
| 219 return allValue; | |
| 220 | |
| 66 BitArray<numCSSProperties> shorthandPropertyUsed; | 221 BitArray<numCSSProperties> shorthandPropertyUsed; |
| 67 BitArray<numCSSProperties> shorthandPropertyAppeared; | 222 BitArray<numCSSProperties> shorthandPropertyAppeared; |
| 68 | 223 |
| 69 unsigned size = m_propertySet.propertyCount(); | 224 unsigned size = propertyCount(); |
| 70 unsigned numDecls = 0; | 225 unsigned numDecls = 0; |
| 71 for (unsigned n = 0; n < size; ++n) { | 226 for (unsigned n = 0; n < size; ++n) { |
| 72 StylePropertySet::PropertyReference property = m_propertySet.propertyAt( n); | 227 CSSPropertyInternal property = propertyAt(n); |
| 73 CSSPropertyID propertyID = property.id(); | 228 CSSPropertyID propertyID = property.id(); |
| 74 // Only enabled or internal properties should be part of the style. | 229 // Only enabled or internal properties should be part of the style. |
| 75 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternal Property(propertyID)); | 230 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternal Property(propertyID)); |
| 76 CSSPropertyID shorthandPropertyID = CSSPropertyInvalid; | 231 CSSPropertyID shorthandPropertyID = CSSPropertyInvalid; |
| 77 CSSPropertyID borderFallbackShorthandProperty = CSSPropertyInvalid; | 232 CSSPropertyID borderFallbackShorthandProperty = CSSPropertyInvalid; |
| 78 String value; | 233 String value; |
| 79 | 234 |
| 80 switch (propertyID) { | 235 switch (propertyID) { |
| 81 case CSSPropertyBackgroundAttachment: | 236 case CSSPropertyBackgroundAttachment: |
| 82 case CSSPropertyBackgroundClip: | 237 case CSSPropertyBackgroundClip: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 case CSSPropertyWebkitTransformOriginY: | 357 case CSSPropertyWebkitTransformOriginY: |
| 203 case CSSPropertyWebkitTransformOriginZ: | 358 case CSSPropertyWebkitTransformOriginZ: |
| 204 shorthandPropertyID = CSSPropertyWebkitTransformOrigin; | 359 shorthandPropertyID = CSSPropertyWebkitTransformOrigin; |
| 205 break; | 360 break; |
| 206 case CSSPropertyWebkitTransitionProperty: | 361 case CSSPropertyWebkitTransitionProperty: |
| 207 case CSSPropertyWebkitTransitionDuration: | 362 case CSSPropertyWebkitTransitionDuration: |
| 208 case CSSPropertyWebkitTransitionTimingFunction: | 363 case CSSPropertyWebkitTransitionTimingFunction: |
| 209 case CSSPropertyWebkitTransitionDelay: | 364 case CSSPropertyWebkitTransitionDelay: |
| 210 shorthandPropertyID = CSSPropertyWebkitTransition; | 365 shorthandPropertyID = CSSPropertyWebkitTransition; |
| 211 break; | 366 break; |
| 367 case CSSPropertyAll: | |
| 368 result.append(getPropertyText(propertyID, property.value()->cssText( ), property.isImportant(), numDecls++)); | |
| 369 continue; | |
| 212 default: | 370 default: |
| 213 break; | 371 break; |
| 214 } | 372 } |
| 215 | 373 |
| 216 unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty; | 374 unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty; |
| 217 if (shorthandPropertyID) { | 375 if (shorthandPropertyID) { |
| 218 if (shorthandPropertyUsed.get(shortPropertyIndex)) | 376 if (shorthandPropertyUsed.get(shortPropertyIndex)) |
| 219 continue; | 377 continue; |
| 220 if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNu ll()) | 378 if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNu ll()) |
| 221 value = m_propertySet.getPropertyValue(shorthandPropertyID); | 379 value = getPropertyValueInternal(shorthandPropertyID); |
| 222 shorthandPropertyAppeared.set(shortPropertyIndex); | 380 shorthandPropertyAppeared.set(shortPropertyIndex); |
| 223 } | 381 } |
| 224 | 382 |
| 225 if (!value.isNull()) { | 383 if (!value.isNull()) { |
| 226 if (shorthandPropertyID) { | 384 if (shorthandPropertyID) { |
| 227 propertyID = shorthandPropertyID; | 385 propertyID = shorthandPropertyID; |
| 228 shorthandPropertyUsed.set(shortPropertyIndex); | 386 shorthandPropertyUsed.set(shortPropertyIndex); |
| 229 } | 387 } |
| 230 } else | 388 } else |
| 231 value = property.value()->cssText(); | 389 value = property.value()->cssText(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 case CSSPropertyWebkitTextStroke: | 472 case CSSPropertyWebkitTextStroke: |
| 315 return getShorthandValue(webkitTextStrokeShorthand()); | 473 return getShorthandValue(webkitTextStrokeShorthand()); |
| 316 case CSSPropertyTransformOrigin: | 474 case CSSPropertyTransformOrigin: |
| 317 case CSSPropertyWebkitTransformOrigin: | 475 case CSSPropertyWebkitTransformOrigin: |
| 318 return getShorthandValue(webkitTransformOriginShorthand()); | 476 return getShorthandValue(webkitTransformOriginShorthand()); |
| 319 case CSSPropertyWebkitTransition: | 477 case CSSPropertyWebkitTransition: |
| 320 return getLayeredShorthandValue(webkitTransitionShorthand()); | 478 return getLayeredShorthandValue(webkitTransitionShorthand()); |
| 321 case CSSPropertyWebkitAnimation: | 479 case CSSPropertyWebkitAnimation: |
| 322 return getLayeredShorthandValue(webkitAnimationShorthand()); | 480 return getLayeredShorthandValue(webkitAnimationShorthand()); |
| 323 case CSSPropertyMarker: { | 481 case CSSPropertyMarker: { |
| 324 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyMarkerStart); | 482 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyMark erStart); |
| 325 if (value) | 483 if (value) |
| 326 return value->cssText(); | 484 return value->cssText(); |
| 327 return String(); | 485 return String(); |
| 328 } | 486 } |
| 329 case CSSPropertyBorderRadius: | 487 case CSSPropertyBorderRadius: |
| 330 return get4Values(borderRadiusShorthand()); | 488 return get4Values(borderRadiusShorthand()); |
| 331 default: | 489 default: |
| 332 return String(); | 490 return String(); |
| 333 } | 491 } |
| 334 } | 492 } |
| 335 | 493 |
| 336 String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const | 494 String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const |
| 337 { | 495 { |
| 338 RefPtrWillBeRawPtr<CSSValue> horizontalValue = m_propertySet.getPropertyCSSV alue(shorthand.properties()[0]); | 496 RefPtrWillBeRawPtr<CSSValue> horizontalValue = getPropertyCSSValue(shorthand .properties()[0]); |
| 339 RefPtrWillBeRawPtr<CSSValue> verticalValue = m_propertySet.getPropertyCSSVal ue(shorthand.properties()[1]); | 497 RefPtrWillBeRawPtr<CSSValue> verticalValue = getPropertyCSSValue(shorthand.p roperties()[1]); |
| 340 | 498 |
| 341 // While standard border-spacing property does not allow specifying border-s pacing-vertical without | 499 // While standard border-spacing property does not allow specifying border-s pacing-vertical without |
| 342 // specifying border-spacing-horizontal <http://www.w3.org/TR/CSS21/tables.h tml#separated-borders>, | 500 // specifying border-spacing-horizontal <http://www.w3.org/TR/CSS21/tables.h tml#separated-borders>, |
| 343 // -webkit-border-spacing-vertical can be set without -webkit-border-spacing -horizontal. | 501 // -webkit-border-spacing-vertical can be set without -webkit-border-spacing -horizontal. |
| 344 if (!horizontalValue || !verticalValue) | 502 if (!horizontalValue || !verticalValue) |
| 345 return String(); | 503 return String(); |
| 346 | 504 |
| 347 String horizontalValueCSSText = horizontalValue->cssText(); | 505 String horizontalValueCSSText = horizontalValue->cssText(); |
| 348 String verticalValueCSSText = verticalValue->cssText(); | 506 String verticalValueCSSText = verticalValue->cssText(); |
| 349 if (horizontalValueCSSText == verticalValueCSSText) | 507 if (horizontalValueCSSText == verticalValueCSSText) |
| 350 return horizontalValueCSSText; | 508 return horizontalValueCSSText; |
| 351 return horizontalValueCSSText + ' ' + verticalValueCSSText; | 509 return horizontalValueCSSText + ' ' + verticalValueCSSText; |
| 352 } | 510 } |
| 353 | 511 |
| 354 void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID pr opertyID, StringBuilder& result, String& commonValue) const | 512 void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID pr opertyID, StringBuilder& result, String& commonValue) const |
| 355 { | 513 { |
| 356 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); | 514 int foundPropertyIndex = findPropertyIndex(propertyID); |
| 357 if (foundPropertyIndex == -1) | 515 if (foundPropertyIndex == -1) |
| 358 return; // All longhands must have at least implicit values if "font" is specified. | 516 return; // All longhands must have at least implicit values if "font" is specified. |
| 359 | 517 |
| 360 if (m_propertySet.propertyAt(foundPropertyIndex).isImplicit()) { | 518 if (propertyAt(foundPropertyIndex).isImplicit()) { |
| 361 commonValue = String(); | 519 commonValue = String(); |
| 362 return; | 520 return; |
| 363 } | 521 } |
| 364 | 522 |
| 365 char prefix = '\0'; | 523 char prefix = '\0'; |
| 366 switch (propertyID) { | 524 switch (propertyID) { |
| 367 case CSSPropertyFontStyle: | 525 case CSSPropertyFontStyle: |
| 368 break; // No prefix. | 526 break; // No prefix. |
| 369 case CSSPropertyFontFamily: | 527 case CSSPropertyFontFamily: |
| 370 case CSSPropertyFontVariant: | 528 case CSSPropertyFontVariant: |
| 371 case CSSPropertyFontWeight: | 529 case CSSPropertyFontWeight: |
| 372 prefix = ' '; | 530 prefix = ' '; |
| 373 break; | 531 break; |
| 374 case CSSPropertyLineHeight: | 532 case CSSPropertyLineHeight: |
| 375 prefix = '/'; | 533 prefix = '/'; |
| 376 break; | 534 break; |
| 377 default: | 535 default: |
| 378 ASSERT_NOT_REACHED(); | 536 ASSERT_NOT_REACHED(); |
| 379 } | 537 } |
| 380 | 538 |
| 381 if (prefix && !result.isEmpty()) | 539 if (prefix && !result.isEmpty()) |
| 382 result.append(prefix); | 540 result.append(prefix); |
| 383 String value = m_propertySet.propertyAt(foundPropertyIndex).value()->cssText (); | 541 String value = propertyAt(foundPropertyIndex).value()->cssText(); |
| 384 result.append(value); | 542 result.append(value); |
| 385 if (!commonValue.isNull() && commonValue != value) | 543 if (!commonValue.isNull() && commonValue != value) |
| 386 commonValue = String(); | 544 commonValue = String(); |
| 387 } | 545 } |
| 388 | 546 |
| 389 String StylePropertySerializer::fontValue() const | 547 String StylePropertySerializer::fontValue() const |
| 390 { | 548 { |
| 391 int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontS ize); | 549 int fontSizePropertyIndex = findPropertyIndex(CSSPropertyFontSize); |
| 392 int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFon tFamily); | 550 int fontFamilyPropertyIndex = findPropertyIndex(CSSPropertyFontFamily); |
| 393 if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1) | 551 if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1) |
| 394 return emptyString(); | 552 return emptyString(); |
| 395 | 553 |
| 396 StylePropertySet::PropertyReference fontSizeProperty = m_propertySet.propert yAt(fontSizePropertyIndex); | 554 CSSPropertyInternal fontSizeProperty = propertyAt(fontSizePropertyIndex); |
|
esprehn
2014/05/30 00:59:22
This needs a different name. Internal usually mean
tasak
2014/06/04 09:37:40
Yes, I would like to make CSSPropertyInternal priv
| |
| 397 StylePropertySet::PropertyReference fontFamilyProperty = m_propertySet.prope rtyAt(fontFamilyPropertyIndex); | 555 CSSPropertyInternal fontFamilyProperty = propertyAt(fontFamilyPropertyIndex) ; |
| 398 if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit()) | 556 if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit()) |
| 399 return emptyString(); | 557 return emptyString(); |
| 400 | 558 |
| 401 String commonValue = fontSizeProperty.value()->cssText(); | 559 String commonValue = fontSizeProperty.value()->cssText(); |
| 402 StringBuilder result; | 560 StringBuilder result; |
| 403 appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue) ; | 561 appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue) ; |
| 404 appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValu e); | 562 appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValu e); |
| 405 appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue ); | 563 appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue ); |
| 406 if (!result.isEmpty()) | 564 if (!result.isEmpty()) |
| 407 result.append(' '); | 565 result.append(' '); |
| 408 result.append(fontSizeProperty.value()->cssText()); | 566 result.append(fontSizeProperty.value()->cssText()); |
| 409 appendFontLonghandValueIfExplicit(CSSPropertyLineHeight, result, commonValue ); | 567 appendFontLonghandValueIfExplicit(CSSPropertyLineHeight, result, commonValue ); |
| 410 if (!result.isEmpty()) | 568 if (!result.isEmpty()) |
| 411 result.append(' '); | 569 result.append(' '); |
| 412 result.append(fontFamilyProperty.value()->cssText()); | 570 result.append(fontFamilyProperty.value()->cssText()); |
| 413 if (isInitialOrInherit(commonValue)) | 571 if (isInitialOrInherit(commonValue)) |
| 414 return commonValue; | 572 return commonValue; |
| 415 return result.toString(); | 573 return result.toString(); |
| 416 } | 574 } |
| 417 | 575 |
| 418 String StylePropertySerializer::get4Values(const StylePropertyShorthand& shortha nd) const | 576 String StylePropertySerializer::get4Values(const StylePropertyShorthand& shortha nd) const |
| 419 { | 577 { |
| 420 // Assume the properties are in the usual order top, right, bottom, left. | 578 // Assume the properties are in the usual order top, right, bottom, left. |
| 421 int topValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[0 ]); | 579 int topValueIndex = findPropertyIndex(shorthand.properties()[0]); |
| 422 int rightValueIndex = m_propertySet.findPropertyIndex(shorthand.properties() [1]); | 580 int rightValueIndex = findPropertyIndex(shorthand.properties()[1]); |
| 423 int bottomValueIndex = m_propertySet.findPropertyIndex(shorthand.properties( )[2]); | 581 int bottomValueIndex = findPropertyIndex(shorthand.properties()[2]); |
| 424 int leftValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[ 3]); | 582 int leftValueIndex = findPropertyIndex(shorthand.properties()[3]); |
| 425 | 583 |
| 426 if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 | | leftValueIndex == -1) | 584 if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 | | leftValueIndex == -1) |
| 427 return String(); | 585 return String(); |
| 428 | 586 |
| 429 StylePropertySet::PropertyReference top = m_propertySet.propertyAt(topValueI ndex); | 587 CSSPropertyInternal top = propertyAt(topValueIndex); |
| 430 StylePropertySet::PropertyReference right = m_propertySet.propertyAt(rightVa lueIndex); | 588 CSSPropertyInternal right = propertyAt(rightValueIndex); |
| 431 StylePropertySet::PropertyReference bottom = m_propertySet.propertyAt(bottom ValueIndex); | 589 CSSPropertyInternal bottom = propertyAt(bottomValueIndex); |
| 432 StylePropertySet::PropertyReference left = m_propertySet.propertyAt(leftValu eIndex); | 590 CSSPropertyInternal left = propertyAt(leftValueIndex); |
| 433 | 591 |
| 434 // All 4 properties must be specified. | 592 // All 4 properties must be specified. |
| 435 if (!top.value() || !right.value() || !bottom.value() || !left.value()) | 593 if (!top.value() || !right.value() || !bottom.value() || !left.value()) |
| 436 return String(); | 594 return String(); |
| 437 | 595 |
| 438 if (top.isInherited() && right.isInherited() && bottom.isInherited() && left .isInherited()) | 596 if (top.isInherited() && right.isInherited() && bottom.isInherited() && left .isInherited()) |
| 439 return getValueName(CSSValueInherit); | 597 return getValueName(CSSValueInherit); |
| 440 | 598 |
| 441 if (top.value()->isInitialValue() || right.value()->isInitialValue() || bott om.value()->isInitialValue() || left.value()->isInitialValue()) { | 599 if (top.value()->isInitialValue() || right.value()->isInitialValue() || bott om.value()->isInitialValue() || left.value()->isInitialValue()) { |
| 442 if (top.value()->isInitialValue() && right.value()->isInitialValue() && bottom.value()->isInitialValue() && left.value()->isInitialValue() && !top.isImp licit()) { | 600 if (top.value()->isInitialValue() && right.value()->isInitialValue() && bottom.value()->isInitialValue() && left.value()->isInitialValue() && !top.isImp licit()) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 472 String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor thand& shorthand) const | 630 String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor thand& shorthand) const |
| 473 { | 631 { |
| 474 StringBuilder result; | 632 StringBuilder result; |
| 475 | 633 |
| 476 const unsigned size = shorthand.length(); | 634 const unsigned size = shorthand.length(); |
| 477 // Begin by collecting the properties into an array. | 635 // Begin by collecting the properties into an array. |
| 478 WillBeHeapVector<RefPtrWillBeMember<CSSValue> > values(size); | 636 WillBeHeapVector<RefPtrWillBeMember<CSSValue> > values(size); |
| 479 size_t numLayers = 0; | 637 size_t numLayers = 0; |
| 480 | 638 |
| 481 for (unsigned i = 0; i < size; ++i) { | 639 for (unsigned i = 0; i < size; ++i) { |
| 482 values[i] = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]) ; | 640 values[i] = getPropertyCSSValue(shorthand.properties()[i]); |
| 483 if (values[i]) { | 641 if (values[i]) { |
| 484 if (values[i]->isBaseValueList()) { | 642 if (values[i]->isBaseValueList()) { |
| 485 CSSValueList* valueList = toCSSValueList(values[i].get()); | 643 CSSValueList* valueList = toCSSValueList(values[i].get()); |
| 486 numLayers = max(valueList->length(), numLayers); | 644 numLayers = max(valueList->length(), numLayers); |
| 487 } else | 645 } else |
| 488 numLayers = max<size_t>(1U, numLayers); | 646 numLayers = max<size_t>(1U, numLayers); |
| 489 } | 647 } |
| 490 } | 648 } |
| 491 | 649 |
| 492 String commonValue; | 650 String commonValue; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 515 } else if (i) { | 673 } else if (i) { |
| 516 // Other singletons only belong in the first layer. | 674 // Other singletons only belong in the first layer. |
| 517 value = nullptr; | 675 value = nullptr; |
| 518 } | 676 } |
| 519 } | 677 } |
| 520 } | 678 } |
| 521 | 679 |
| 522 // We need to report background-repeat as it was written in the CSS. If the property is implicit, | 680 // We need to report background-repeat as it was written in the CSS. If the property is implicit, |
| 523 // then it was written with only one value. Here we figure out which value that was so we can | 681 // then it was written with only one value. Here we figure out which value that was so we can |
| 524 // report back correctly. | 682 // report back correctly. |
| 525 if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && m_ propertySet.isPropertyImplicit(shorthand.properties()[j])) | 683 if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && is PropertyImplicit(shorthand.properties()[j])) |
| 526 || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && m_propertySet.isPropertyImplicit(shorthand.properties()[j]))) { | 684 || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && isPropertyImplicit(shorthand.properties()[j]))) { |
| 527 | 685 |
| 528 // BUG 49055: make sure the value was not reset in the layer che ck just above. | 686 // BUG 49055: make sure the value was not reset in the layer che ck just above. |
| 529 if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropert yBackgroundRepeatY && value) | 687 if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropert yBackgroundRepeatY && value) |
| 530 || (j < size - 1 && shorthand.properties()[j + 1] == CSSProp ertyWebkitMaskRepeatY && value)) { | 688 || (j < size - 1 && shorthand.properties()[j + 1] == CSSProp ertyWebkitMaskRepeatY && value)) { |
| 531 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; | 689 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; |
| 532 RefPtrWillBeRawPtr<CSSValue> nextValue = values[j + 1]; | 690 RefPtrWillBeRawPtr<CSSValue> nextValue = values[j + 1]; |
| 533 if (nextValue->isValueList()) | 691 if (nextValue->isValueList()) |
| 534 yValue = toCSSValueList(nextValue.get())->itemWithoutBou ndsCheck(i); | 692 yValue = toCSSValueList(nextValue.get())->itemWithoutBou ndsCheck(i); |
| 535 else | 693 else |
| 536 yValue = nextValue; | 694 yValue = nextValue; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 if (result.isEmpty()) | 775 if (result.isEmpty()) |
| 618 return String(); | 776 return String(); |
| 619 return result.toString(); | 777 return result.toString(); |
| 620 } | 778 } |
| 621 | 779 |
| 622 String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand& shorthand) const | 780 String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand& shorthand) const |
| 623 { | 781 { |
| 624 String commonValue; | 782 String commonValue; |
| 625 StringBuilder result; | 783 StringBuilder result; |
| 626 for (unsigned i = 0; i < shorthand.length(); ++i) { | 784 for (unsigned i = 0; i < shorthand.length(); ++i) { |
| 627 if (!m_propertySet.isPropertyImplicit(shorthand.properties()[i])) { | 785 if (!isPropertyImplicit(shorthand.properties()[i])) { |
| 628 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(shorthand.properties()[i]); | 786 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.p roperties()[i]); |
| 629 if (!value) | 787 if (!value) |
| 630 return String(); | 788 return String(); |
| 631 String valueText = value->cssText(); | 789 String valueText = value->cssText(); |
| 632 if (!i) | 790 if (!i) |
| 633 commonValue = valueText; | 791 commonValue = valueText; |
| 634 else if (!commonValue.isNull() && commonValue != valueText) | 792 else if (!commonValue.isNull() && commonValue != valueText) |
| 635 commonValue = String(); | 793 commonValue = String(); |
| 636 if (value->isInitialValue()) | 794 if (value->isInitialValue()) |
| 637 continue; | 795 continue; |
| 638 if (!result.isEmpty()) | 796 if (!result.isEmpty()) |
| 639 result.append(' '); | 797 result.append(' '); |
| 640 result.append(valueText); | 798 result.append(valueText); |
| 641 } else | 799 } else |
| 642 commonValue = String(); | 800 commonValue = String(); |
| 643 } | 801 } |
| 644 if (isInitialOrInherit(commonValue)) | 802 if (isInitialOrInherit(commonValue)) |
| 645 return commonValue; | 803 return commonValue; |
| 646 if (result.isEmpty()) | 804 if (result.isEmpty()) |
| 647 return String(); | 805 return String(); |
| 648 return result.toString(); | 806 return result.toString(); |
| 649 } | 807 } |
| 650 | 808 |
| 651 // only returns a non-null value if all properties have the same, non-null value | 809 // only returns a non-null value if all properties have the same, non-null value |
| 652 String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho rthand) const | 810 String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho rthand) const |
| 653 { | 811 { |
| 654 String res; | 812 String res; |
| 655 bool lastPropertyWasImportant = false; | 813 bool lastPropertyWasImportant = false; |
| 656 for (unsigned i = 0; i < shorthand.length(); ++i) { | 814 for (unsigned i = 0; i < shorthand.length(); ++i) { |
| 657 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); | 815 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.prope rties()[i]); |
| 658 // FIXME: CSSInitialValue::cssText should generate the right value. | 816 // FIXME: CSSInitialValue::cssText should generate the right value. |
| 659 if (!value) | 817 if (!value) |
| 660 return String(); | 818 return String(); |
| 661 String text = value->cssText(); | 819 String text = value->cssText(); |
| 662 if (text.isNull()) | 820 if (text.isNull()) |
| 663 return String(); | 821 return String(); |
| 664 if (res.isNull()) | 822 if (res.isNull()) |
| 665 res = text; | 823 res = text; |
| 666 else if (res != text) | 824 else if (res != text) |
| 667 return String(); | 825 return String(); |
| 668 | 826 |
| 669 bool currentPropertyIsImportant = m_propertySet.propertyIsImportant(shor thand.properties()[i]); | 827 bool currentPropertyIsImportant = propertyIsImportant(shorthand.properti es()[i]); |
| 670 if (i && lastPropertyWasImportant != currentPropertyIsImportant) | 828 if (i && lastPropertyWasImportant != currentPropertyIsImportant) |
| 671 return String(); | 829 return String(); |
| 672 lastPropertyWasImportant = currentPropertyIsImportant; | 830 lastPropertyWasImportant = currentPropertyIsImportant; |
| 673 } | 831 } |
| 674 return res; | 832 return res; |
| 675 } | 833 } |
| 676 | 834 |
| 677 String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c onst | 835 String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c onst |
| 678 { | 836 { |
| 679 const StylePropertyShorthand properties[3] = { borderWidthShorthand(), borde rStyleShorthand(), borderColorShorthand() }; | 837 const StylePropertyShorthand properties[3] = { borderWidthShorthand(), borde rStyleShorthand(), borderColorShorthand() }; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 697 result.append(' '); | 855 result.append(' '); |
| 698 result.append(value); | 856 result.append(value); |
| 699 } | 857 } |
| 700 if (isInitialOrInherit(commonValue)) | 858 if (isInitialOrInherit(commonValue)) |
| 701 return commonValue; | 859 return commonValue; |
| 702 return result.isEmpty() ? String() : result.toString(); | 860 return result.isEmpty() ? String() : result.toString(); |
| 703 } | 861 } |
| 704 | 862 |
| 705 String StylePropertySerializer::backgroundRepeatPropertyValue() const | 863 String StylePropertySerializer::backgroundRepeatPropertyValue() const |
| 706 { | 864 { |
| 707 RefPtrWillBeRawPtr<CSSValue> repeatX = m_propertySet.getPropertyCSSValue(CSS PropertyBackgroundRepeatX); | 865 RefPtrWillBeRawPtr<CSSValue> repeatX = getPropertyCSSValue(CSSPropertyBackgr oundRepeatX); |
| 708 RefPtrWillBeRawPtr<CSSValue> repeatY = m_propertySet.getPropertyCSSValue(CSS PropertyBackgroundRepeatY); | 866 RefPtrWillBeRawPtr<CSSValue> repeatY = getPropertyCSSValue(CSSPropertyBackgr oundRepeatY); |
| 709 if (!repeatX || !repeatY) | 867 if (!repeatX || !repeatY) |
| 710 return String(); | 868 return String(); |
| 711 if (repeatX->cssValueType() != repeatY->cssValueType()) | 869 if (repeatX->cssValueType() != repeatY->cssValueType()) |
| 712 return String(); | 870 return String(); |
| 713 if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_pro pertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY)) | 871 if (propertyIsImportant(CSSPropertyBackgroundRepeatX) != propertyIsImportant (CSSPropertyBackgroundRepeatY)) |
| 714 return String(); | 872 return String(); |
| 715 | 873 |
| 716 StringBuilder builder; | 874 StringBuilder builder; |
| 717 switch (repeatX->cssValueType()) { | 875 switch (repeatX->cssValueType()) { |
| 718 case CSSValue::CSS_INHERIT: | 876 case CSSValue::CSS_INHERIT: |
| 719 case CSSValue::CSS_INITIAL: | 877 case CSSValue::CSS_INITIAL: |
| 720 return repeatX->cssText(); | 878 return repeatX->cssText(); |
| 721 | 879 |
| 722 case CSSValue::CSS_PRIMITIVE_VALUE: | 880 case CSSValue::CSS_PRIMITIVE_VALUE: |
| 723 { | 881 { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 744 builder.append(repeatY->cssText()); | 902 builder.append(repeatY->cssText()); |
| 745 break; | 903 break; |
| 746 } | 904 } |
| 747 return builder.toString(); | 905 return builder.toString(); |
| 748 } | 906 } |
| 749 | 907 |
| 750 void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu lt, unsigned& numDecls) const | 908 void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu lt, unsigned& numDecls) const |
| 751 { | 909 { |
| 752 if (isPropertyShorthandAvailable(backgroundShorthand())) { | 910 if (isPropertyShorthandAvailable(backgroundShorthand())) { |
| 753 String backgroundValue = getPropertyValue(CSSPropertyBackground); | 911 String backgroundValue = getPropertyValue(CSSPropertyBackground); |
| 754 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage); | 912 bool isImportant = propertyIsImportant(CSSPropertyBackgroundImage); |
| 755 result.append(getPropertyText(CSSPropertyBackground, backgroundValue, is Important, numDecls++)); | 913 result.append(getPropertyText(CSSPropertyBackground, backgroundValue, is Important, numDecls++)); |
| 756 return; | 914 return; |
| 757 } | 915 } |
| 758 if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) { | 916 if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) { |
| 759 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyBackgroundImage); | 917 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBack groundImage); |
| 760 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage); | 918 bool isImportant = propertyIsImportant(CSSPropertyBackgroundImage); |
| 761 result.append(getPropertyText(CSSPropertyBackground, value->cssText(), i sImportant, numDecls++)); | 919 result.append(getPropertyText(CSSPropertyBackground, value->cssText(), i sImportant, numDecls++)); |
| 762 return; | 920 return; |
| 763 } | 921 } |
| 764 | 922 |
| 765 // backgroundShorthandProperty without layered shorhand properties | 923 // backgroundShorthandProperty without layered shorhand properties |
| 766 const CSSPropertyID backgroundPropertyIds[] = { | 924 const CSSPropertyID backgroundPropertyIds[] = { |
| 767 CSSPropertyBackgroundImage, | 925 CSSPropertyBackgroundImage, |
| 768 CSSPropertyBackgroundAttachment, | 926 CSSPropertyBackgroundAttachment, |
| 769 CSSPropertyBackgroundColor, | 927 CSSPropertyBackgroundColor, |
| 770 CSSPropertyBackgroundSize, | 928 CSSPropertyBackgroundSize, |
| 771 CSSPropertyBackgroundOrigin, | 929 CSSPropertyBackgroundOrigin, |
| 772 CSSPropertyBackgroundClip | 930 CSSPropertyBackgroundClip |
| 773 }; | 931 }; |
| 774 | 932 |
| 775 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) { | 933 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) { |
| 776 CSSPropertyID propertyID = backgroundPropertyIds[i]; | 934 CSSPropertyID propertyID = backgroundPropertyIds[i]; |
| 777 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(p ropertyID); | 935 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); |
| 778 if (!value) | 936 if (!value) |
| 779 continue; | 937 continue; |
| 780 result.append(getPropertyText(propertyID, value->cssText(), m_propertySe t.propertyIsImportant(propertyID), numDecls++)); | 938 result.append(getPropertyText(propertyID, value->cssText(), propertyIsIm portant(propertyID), numDecls++)); |
| 781 } | 939 } |
| 782 | 940 |
| 783 // FIXME: This is a not-so-nice way to turn x/y positions into single backgr ound-position in output. | 941 // FIXME: This is a not-so-nice way to turn x/y positions into single backgr ound-position in output. |
| 784 // It is required because background-position-x/y are non-standard propertie s and WebKit generated output | 942 // It is required because background-position-x/y are non-standard propertie s and WebKit generated output |
| 785 // would not work in Firefox (<rdar://problem/5143183>) | 943 // would not work in Firefox (<rdar://problem/5143183>) |
| 786 // It would be a better solution if background-position was CSS_PAIR. | 944 // It would be a better solution if background-position was CSS_PAIR. |
| 787 if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) { | 945 if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) { |
| 788 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyBackgroundPositionX); | 946 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBack groundPositionX); |
| 789 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX); | 947 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX); |
| 790 result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssT ext(), isImportant, numDecls++)); | 948 result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssT ext(), isImportant, numDecls++)); |
| 791 } else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) { | 949 } else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) { |
| 792 String positionValue = m_propertySet.getPropertyValue(CSSPropertyBackgro undPosition); | 950 String positionValue = getPropertyValueInternal(CSSPropertyBackgroundPos ition); |
| 793 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX); | 951 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX); |
| 794 if (!positionValue.isNull()) | 952 if (!positionValue.isNull()) |
| 795 result.append(getPropertyText(CSSPropertyBackgroundPosition, positio nValue, isImportant, numDecls++)); | 953 result.append(getPropertyText(CSSPropertyBackgroundPosition, positio nValue, isImportant, numDecls++)); |
| 796 } else { | 954 } else { |
| 797 // should check background-position-x or background-position-y. | 955 // should check background-position-x or background-position-y. |
| 798 if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(CSSPropertyBackgroundPositionX)) { | 956 if (RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSProperty BackgroundPositionX)) { |
| 799 if (!value->isImplicitInitialValue()) { | 957 if (!value->isImplicitInitialValue()) { |
| 800 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionX); | 958 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPosi tionX); |
| 801 result.append(getPropertyText(CSSPropertyBackgroundPositionX, va lue->cssText(), isImportant, numDecls++)); | 959 result.append(getPropertyText(CSSPropertyBackgroundPositionX, va lue->cssText(), isImportant, numDecls++)); |
| 802 } | 960 } |
| 803 } | 961 } |
| 804 if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(CSSPropertyBackgroundPositionY)) { | 962 if (RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSProperty BackgroundPositionY)) { |
| 805 if (!value->isImplicitInitialValue()) { | 963 if (!value->isImplicitInitialValue()) { |
| 806 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionY); | 964 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPosi tionY); |
| 807 result.append(getPropertyText(CSSPropertyBackgroundPositionY, va lue->cssText(), isImportant, numDecls++)); | 965 result.append(getPropertyText(CSSPropertyBackgroundPositionY, va lue->cssText(), isImportant, numDecls++)); |
| 808 } | 966 } |
| 809 } | 967 } |
| 810 } | 968 } |
| 811 | 969 |
| 812 String repeatValue = m_propertySet.getPropertyValue(CSSPropertyBackgroundRep eat); | 970 String repeatValue = getPropertyValueInternal(CSSPropertyBackgroundRepeat); |
| 813 if (!repeatValue.isNull()) | 971 if (!repeatValue.isNull()) |
| 814 result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++)); | 972 result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++)); |
| 815 } | 973 } |
| 816 | 974 |
| 817 bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh orthand& shorthand) const | 975 bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh orthand& shorthand) const |
| 818 { | 976 { |
| 819 ASSERT(shorthand.length() > 0); | 977 ASSERT(shorthand.length() > 0); |
| 820 | 978 |
| 821 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]); | 979 bool isImportant = propertyIsImportant(shorthand.properties()[0]); |
| 822 for (unsigned i = 0; i < shorthand.length(); ++i) { | 980 for (unsigned i = 0; i < shorthand.length(); ++i) { |
| 823 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); | 981 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.prope rties()[i]); |
| 824 if (!value || (value->isInitialValue() && !value->isImplicitInitialValue ()) || value->isInheritedValue()) | 982 if (!value || (value->isInitialValue() && !value->isImplicitInitialValue ()) || value->isInheritedValue()) |
| 825 return false; | 983 return false; |
| 826 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i])) | 984 if (isImportant != propertyIsImportant(shorthand.properties()[i])) |
| 827 return false; | 985 return false; |
| 828 } | 986 } |
| 829 return true; | 987 return true; |
| 830 } | 988 } |
| 831 | 989 |
| 832 bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const Styl ePropertyShorthand& shorthand) const | 990 bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const Styl ePropertyShorthand& shorthand) const |
| 833 { | 991 { |
| 834 ASSERT(shorthand.length() > 0); | 992 ASSERT(shorthand.length() > 0); |
| 835 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]); | 993 bool isImportant = propertyIsImportant(shorthand.properties()[0]); |
| 836 bool isInitialValue = true; | 994 bool isInitialValue = true; |
| 837 bool isInheritedValue = true; | 995 bool isInheritedValue = true; |
| 838 for (unsigned i = 0; i < shorthand.length(); ++i) { | 996 for (unsigned i = 0; i < shorthand.length(); ++i) { |
| 839 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); | 997 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.prope rties()[i]); |
| 840 if (!value) | 998 if (!value) |
| 841 return false; | 999 return false; |
| 842 if (!value->isInitialValue()) | 1000 if (!value->isInitialValue()) |
| 843 isInitialValue = false; | 1001 isInitialValue = false; |
| 844 if (!value->isInheritedValue()) | 1002 if (!value->isInheritedValue()) |
| 845 isInheritedValue = false; | 1003 isInheritedValue = false; |
| 846 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i])) | 1004 if (isImportant != propertyIsImportant(shorthand.properties()[i])) |
| 847 return false; | 1005 return false; |
| 848 } | 1006 } |
| 849 return isInitialValue || isInheritedValue; | 1007 return isInitialValue || isInheritedValue; |
| 850 } | 1008 } |
| 851 | 1009 |
| 1010 bool StylePropertySerializer::hasAllShorthand(String& result) const | |
| 1011 { | |
| 1012 if (!propertyCount()) | |
| 1013 return false; | |
| 1014 | |
| 1015 bool isImportant = propertyAt(0).isImportant(); | |
|
esprehn
2014/05/30 00:59:22
why is it okay to only check 0?
tasak
2014/06/04 09:37:40
I'm trying to see if all properties' isImportant a
| |
| 1016 bool isInitialValue = true; | |
| 1017 bool isInheritedValue = true; | |
| 1018 bool isUnsetValue = true; | |
| 1019 | |
| 1020 BitArray<numCSSProperties> shorthandPropertyAppeared; | |
| 1021 | |
| 1022 for (unsigned i = 0; i < propertyCount(); ++i) { | |
| 1023 CSSPropertyInternal property = propertyAt(i); | |
| 1024 | |
| 1025 unsigned shorthandIndex = property.id() - firstCSSProperty; | |
| 1026 shorthandPropertyAppeared.set(shorthandIndex); | |
| 1027 | |
| 1028 if (!property.value()->isInitialValue()) | |
| 1029 isInitialValue = false; | |
| 1030 if (!property.value()->isInheritedValue()) | |
| 1031 isInheritedValue = false; | |
| 1032 if ((CSSProperty::isInheritedProperty(property.id()) && !property.value( )->isInheritedValue()) || (!CSSProperty::isInheritedProperty(property.id()) && ! property.value()->isInitialValue())) | |
| 1033 isUnsetValue = false; | |
| 1034 | |
| 1035 if (isImportant != property.isImportant()) | |
| 1036 return false; | |
| 1037 } | |
| 1038 if (!isInitialValue && !isInheritedValue && !isUnsetValue) | |
| 1039 return false; | |
| 1040 | |
| 1041 for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) { | |
|
esprehn
2014/05/30 00:59:22
I think you can just loop over CSSPropertyID and c
tasak
2014/06/04 09:37:40
Because I have the following error:
"error: cannot
| |
| 1042 CSSPropertyID propertyId = static_cast<CSSPropertyID>(i); | |
| 1043 | |
| 1044 if (isExpandedShorthandForAll(propertyId)) | |
| 1045 continue; | |
| 1046 if (propertyId == CSSPropertyAll || !isAffectedByAllProperty(propertyId) ) | |
| 1047 continue; | |
| 1048 | |
| 1049 unsigned shorthandIndex = i - firstCSSProperty; | |
| 1050 if (!shorthandPropertyAppeared.get(shorthandIndex)) | |
| 1051 return false; | |
| 1052 } | |
| 1053 | |
| 1054 String value = isInitialValue ? "initial" : (isInheritedValue ? "inherit" : "unset"); | |
|
esprehn
2014/05/30 00:59:22
don't nest ternaries
tasak
2014/06/04 09:37:40
Done.
| |
| 1055 result = getPropertyText(CSSPropertyAll, value, isImportant, false); | |
| 1056 return true; | |
| 852 } | 1057 } |
| 1058 | |
| 1059 } | |
| OLD | NEW |