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

Side by Side Diff: Source/core/css/StylePropertySerializer.cpp

Issue 341033003: StylePropertySerializer should expand all property if needed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "core/CSSValueKeywords.h" 26 #include "core/CSSValueKeywords.h"
27 #include "core/StylePropertyShorthand.h" 27 #include "core/StylePropertyShorthand.h"
28 #include "core/css/CSSPropertyMetadata.h" 28 #include "core/css/CSSPropertyMetadata.h"
29 #include "core/css/CSSValuePool.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 namespace blink { 33 namespace blink {
33 34
34 static bool isInitialOrInherit(const String& value) 35 static bool isInitialOrInherit(const String& value)
35 { 36 {
36 DEFINE_STATIC_LOCAL(String, initial, ("initial")); 37 DEFINE_STATIC_LOCAL(String, initial, ("initial"));
37 DEFINE_STATIC_LOCAL(String, inherit, ("inherit")); 38 DEFINE_STATIC_LOCAL(String, inherit, ("inherit"));
38 return value.length() == 7 && (value == initial || value == inherit); 39 return value.length() == 7 && (value == initial || value == inherit);
39 } 40 }
40 41
42 StylePropertySetForSerializer::StylePropertySetForSerializer(const StyleProperty Set& properties)
43 : m_propertySet(properties)
44 , m_allIndex(m_propertySet.findPropertyIndex(CSSPropertyAll))
45 , m_needToExpandAll(false)
46 {
47 if (!hasAllProperty())
48 return;
49
50 StylePropertySet::PropertyReference allProperty = m_propertySet.propertyAt(m _allIndex);
51 int numAffectedLonghands = 0;
52 for (unsigned i = 0; i < m_propertySet.propertyCount(); ++i) {
53 StylePropertySet::PropertyReference property = m_propertySet.propertyAt( i);
54 if (CSSProperty::isAffectedByAllProperty(property.id())) {
55 if (allProperty.isImportant() && !property.isImportant())
56 continue;
57 if ((unsigned)m_allIndex >= i)
rune 2014/09/02 20:13:07 Use static_cast instead of C-style cast.
tasak 2014/09/04 06:08:38 Done.
58 continue;
59 if (property.value()->equals(*allProperty.value())
60 && property.isImportant() == allProperty.isImportant())
61 continue;
62 ++numAffectedLonghands;
rune 2014/09/02 20:13:07 Can't you just set m_needToExpandAll here and drop
tasak 2014/09/04 06:08:38 Done.
63 }
64 m_longhandPropertyUsed.set(property.id() - firstCSSProperty);
65 }
66 m_needToExpandAll = numAffectedLonghands > 0;
67 }
68
69 unsigned StylePropertySetForSerializer::propertyCount() const
70 {
71 if (!hasExpandedAllProperty())
72 return m_propertySet.propertyCount();
73 return lastCSSProperty - firstCSSProperty + 1;
74 }
75
76 PropertyValueForSerializer StylePropertySetForSerializer::propertyAt(unsigned in dex) const
77 {
78 if (!hasExpandedAllProperty())
79 return PropertyValueForSerializer(m_propertySet.propertyAt(index));
80
81 CSSPropertyID propertyID = static_cast<CSSPropertyID>(index + firstCSSProper ty);
82 ASSERT(firstCSSProperty <= propertyID && propertyID <= lastCSSProperty);
83 if (m_longhandPropertyUsed.get(index)) {
84 int index = m_propertySet.findPropertyIndex(propertyID);
85 ASSERT(index != -1);
86 return PropertyValueForSerializer(m_propertySet.propertyAt(index));
87 }
88
89 StylePropertySet::PropertyReference property = m_propertySet.propertyAt(m_al lIndex);
90 const CSSValue* value = property.value();
91
92 // FIXME: Firefox shows properties with "unset" when some cssRule has
93 // expanded "all" with "unset". So we should use "unset" here.
94 // After implementing "unset" value correctly, (i.e. StyleBuilder should
95 // support "display: unset", "color: unset", ... and so on),
96 // we should fix the following code.
97 if (!value->isInitialValue() && !value->isInheritedValue()) {
98 if (CSSPropertyMetadata::isInheritedProperty(propertyID))
99 value = cssValuePool().createInheritedValue().get();
100 else
101 value = cssValuePool().createExplicitInitialValue().get();
102 }
103 return PropertyValueForSerializer(propertyID, value, property.isImportant()) ;
104 }
105
106 bool StylePropertySetForSerializer::shouldProcessPropertyAt(unsigned index) cons t
107 {
108 // StylePropertySet has all valid longhands. We should process.
109 if (!hasAllProperty())
110 return true;
111
112 // If all is not expanded, we need to process "all" and properties which
113 // are not overwritten by "all".
114 if (!m_needToExpandAll) {
115 StylePropertySet::PropertyReference property = m_propertySet.propertyAt( index);
116 if (property.id() == CSSPropertyAll || !CSSProperty::isAffectedByAllProp erty(property.id()))
117 return true;
118 return m_longhandPropertyUsed.get(property.id() - firstCSSProperty);
119 }
120
121 CSSPropertyID propertyID = static_cast<CSSPropertyID>(index + firstCSSProper ty);
122 ASSERT(firstCSSProperty <= propertyID && propertyID <= lastCSSProperty);
123
124 // Since "all" is expanded, we don't need to process "all".
125 // We should not process expanded shorthands (e.g. font, background,
126 // and so on) either.
127 if (isExpandedShorthandForAll(propertyID) || propertyID == CSSPropertyAll)
128 return false;
129 // We should not serialize internal properties.
130 if (isInternalProperty(propertyID))
131 return false;
132
133 // The all property is a shorthand that resets all CSS properties except
134 // direction and unicode-bidi. It only accepts the CSS-wide keywords.
135 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand
136 if (!CSSProperty::isAffectedByAllProperty(propertyID))
137 return m_longhandPropertyUsed.get(index);
138
139 return true;
140 }
141
142 int StylePropertySetForSerializer::findPropertyIndex(CSSPropertyID propertyID) c onst
143 {
144 if (!hasExpandedAllProperty())
145 return m_propertySet.findPropertyIndex(propertyID);
146 return propertyID - firstCSSProperty;
147 }
148
149 const CSSValue* StylePropertySetForSerializer::getPropertyCSSValue(CSSPropertyID propertyID) const
150 {
151 int index = findPropertyIndex(propertyID);
152 if (index == -1)
153 return 0;
154 PropertyValueForSerializer value = propertyAt(index);
155 return value.value();
156 }
157
158 String StylePropertySetForSerializer::getPropertyValue(CSSPropertyID propertyID) const
159 {
160 if (!hasExpandedAllProperty())
161 return m_propertySet.getPropertyValue(propertyID);
162
163 const CSSValue* value = getPropertyCSSValue(propertyID);
164 if (!value)
165 return String();
166 return value->cssText();
167 }
168
169 bool StylePropertySetForSerializer::isPropertyImplicit(CSSPropertyID propertyID) const
170 {
171 int index = findPropertyIndex(propertyID);
172 if (index == -1)
173 return false;
174 PropertyValueForSerializer value = propertyAt(index);
175 return value.isImplicit();
176 }
177
178 bool StylePropertySetForSerializer::propertyIsImportant(CSSPropertyID propertyID ) const
179 {
180 int index = findPropertyIndex(propertyID);
181 if (index == -1)
182 return false;
183 PropertyValueForSerializer value = propertyAt(index);
184 return value.isImportant();
185 }
186
41 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies) 187 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies)
42 : m_propertySet(properties) 188 : m_propertySet(properties)
43 { 189 {
44 } 190 }
45 191
46 String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const 192 String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const
47 { 193 {
48 StringBuilder result; 194 StringBuilder result;
49 if (isNotFirstDecl) 195 if (isNotFirstDecl)
50 result.append(' '); 196 result.append(' ');
51 result.append(getPropertyName(propertyID)); 197 result.append(getPropertyName(propertyID));
52 result.appendLiteral(": "); 198 result.appendLiteral(": ");
53 result.append(value); 199 result.append(value);
54 if (isImportant) 200 if (isImportant)
55 result.appendLiteral(" !important"); 201 result.appendLiteral(" !important");
56 result.append(';'); 202 result.append(';');
57 return result.toString(); 203 return result.toString();
58 } 204 }
59 205
60 String StylePropertySerializer::asText() const 206 String StylePropertySerializer::asText() const
61 { 207 {
62 StringBuilder result; 208 StringBuilder result;
63 209
64 BitArray<numCSSProperties> shorthandPropertyUsed; 210 BitArray<numCSSProperties> shorthandPropertyUsed;
65 BitArray<numCSSProperties> shorthandPropertyAppeared; 211 BitArray<numCSSProperties> shorthandPropertyAppeared;
66 212
67 unsigned size = m_propertySet.propertyCount(); 213 unsigned size = m_propertySet.propertyCount();
68 unsigned numDecls = 0; 214 unsigned numDecls = 0;
69 for (unsigned n = 0; n < size; ++n) { 215 for (unsigned n = 0; n < size; ++n) {
70 StylePropertySet::PropertyReference property = m_propertySet.propertyAt( n); 216 if (!m_propertySet.shouldProcessPropertyAt(n))
217 continue;
218
219 PropertyValueForSerializer property = m_propertySet.propertyAt(n);
71 CSSPropertyID propertyID = property.id(); 220 CSSPropertyID propertyID = property.id();
72 // Only enabled or internal properties should be part of the style. 221 // Only enabled or internal properties should be part of the style.
73 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID) || isInternalP roperty(propertyID)); 222 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID) || isInternalP roperty(propertyID));
74 CSSPropertyID shorthandPropertyID = CSSPropertyInvalid; 223 CSSPropertyID shorthandPropertyID = CSSPropertyInvalid;
75 CSSPropertyID borderFallbackShorthandProperty = CSSPropertyInvalid; 224 CSSPropertyID borderFallbackShorthandProperty = CSSPropertyInvalid;
76 String value; 225 String value;
226 ASSERT(!isExpandedShorthandForAll(propertyID));
77 227
78 switch (propertyID) { 228 switch (propertyID) {
79 case CSSPropertyBackgroundAttachment: 229 case CSSPropertyBackgroundAttachment:
80 case CSSPropertyBackgroundClip: 230 case CSSPropertyBackgroundClip:
81 case CSSPropertyBackgroundColor: 231 case CSSPropertyBackgroundColor:
82 case CSSPropertyBackgroundImage: 232 case CSSPropertyBackgroundImage:
83 case CSSPropertyBackgroundOrigin: 233 case CSSPropertyBackgroundOrigin:
84 case CSSPropertyBackgroundPositionX: 234 case CSSPropertyBackgroundPositionX:
85 case CSSPropertyBackgroundPositionY: 235 case CSSPropertyBackgroundPositionY:
86 case CSSPropertyBackgroundSize: 236 case CSSPropertyBackgroundSize:
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 case CSSPropertyWebkitTransformOriginY: 351 case CSSPropertyWebkitTransformOriginY:
202 case CSSPropertyWebkitTransformOriginZ: 352 case CSSPropertyWebkitTransformOriginZ:
203 shorthandPropertyID = CSSPropertyWebkitTransformOrigin; 353 shorthandPropertyID = CSSPropertyWebkitTransformOrigin;
204 break; 354 break;
205 case CSSPropertyWebkitTransitionProperty: 355 case CSSPropertyWebkitTransitionProperty:
206 case CSSPropertyWebkitTransitionDuration: 356 case CSSPropertyWebkitTransitionDuration:
207 case CSSPropertyWebkitTransitionTimingFunction: 357 case CSSPropertyWebkitTransitionTimingFunction:
208 case CSSPropertyWebkitTransitionDelay: 358 case CSSPropertyWebkitTransitionDelay:
209 shorthandPropertyID = CSSPropertyWebkitTransition; 359 shorthandPropertyID = CSSPropertyWebkitTransition;
210 break; 360 break;
361 case CSSPropertyAll:
362 result.append(getPropertyText(propertyID, property.value()->cssText( ), property.isImportant(), numDecls++));
363 continue;
211 default: 364 default:
212 break; 365 break;
213 } 366 }
214 367
215 unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty; 368 unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty;
216 if (shorthandPropertyID) { 369 if (shorthandPropertyID) {
217 if (shorthandPropertyUsed.get(shortPropertyIndex)) 370 if (shorthandPropertyUsed.get(shortPropertyIndex))
218 continue; 371 continue;
219 if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNu ll()) 372 if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNu ll())
220 value = m_propertySet.getPropertyValue(shorthandPropertyID); 373 value = m_propertySet.getPropertyValue(shorthandPropertyID);
221 shorthandPropertyAppeared.set(shortPropertyIndex); 374 shorthandPropertyAppeared.set(shortPropertyIndex);
222 } 375 }
223 376
224 if (!value.isNull()) { 377 if (!value.isNull()) {
225 if (shorthandPropertyID) { 378 if (shorthandPropertyID) {
226 propertyID = shorthandPropertyID; 379 propertyID = shorthandPropertyID;
227 shorthandPropertyUsed.set(shortPropertyIndex); 380 shorthandPropertyUsed.set(shortPropertyIndex);
228 } 381 }
229 } else 382 } else {
383 // We should not show "initial" when the "initial" is implicit.
384 // If explicit "initial", we need to show.
385 if (property.value()->isImplicitInitialValue())
386 continue;
230 value = property.value()->cssText(); 387 value = property.value()->cssText();
231 388 }
232 if (value == "initial" && !CSSPropertyMetadata::isInheritedProperty(prop ertyID))
233 continue;
234 389
235 result.append(getPropertyText(propertyID, value, property.isImportant(), numDecls++)); 390 result.append(getPropertyText(propertyID, value, property.isImportant(), numDecls++));
236 } 391 }
237 392
238 if (shorthandPropertyAppeared.get(CSSPropertyBackground - firstCSSProperty)) 393 if (shorthandPropertyAppeared.get(CSSPropertyBackground - firstCSSProperty))
239 appendBackgroundPropertyAsText(result, numDecls); 394 appendBackgroundPropertyAsText(result, numDecls);
240 395
241 ASSERT(!numDecls ^ !result.isEmpty()); 396 ASSERT(!numDecls ^ !result.isEmpty());
242 return result.toString(); 397 return result.toString();
243 } 398 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 case CSSPropertyWebkitTextStroke: 468 case CSSPropertyWebkitTextStroke:
314 return getShorthandValue(webkitTextStrokeShorthand()); 469 return getShorthandValue(webkitTextStrokeShorthand());
315 case CSSPropertyTransformOrigin: 470 case CSSPropertyTransformOrigin:
316 case CSSPropertyWebkitTransformOrigin: 471 case CSSPropertyWebkitTransformOrigin:
317 return getShorthandValue(webkitTransformOriginShorthand()); 472 return getShorthandValue(webkitTransformOriginShorthand());
318 case CSSPropertyWebkitTransition: 473 case CSSPropertyWebkitTransition:
319 return getLayeredShorthandValue(webkitTransitionShorthand()); 474 return getLayeredShorthandValue(webkitTransitionShorthand());
320 case CSSPropertyWebkitAnimation: 475 case CSSPropertyWebkitAnimation:
321 return getLayeredShorthandValue(webkitAnimationShorthand()); 476 return getLayeredShorthandValue(webkitAnimationShorthand());
322 case CSSPropertyMarker: { 477 case CSSPropertyMarker: {
323 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyMarkerStart); 478 if (const CSSValue* value = m_propertySet.getPropertyCSSValue(CSSPropert yMarkerStart))
324 if (value)
325 return value->cssText(); 479 return value->cssText();
326 return String(); 480 return String();
327 } 481 }
328 case CSSPropertyBorderRadius: 482 case CSSPropertyBorderRadius:
329 return get4Values(borderRadiusShorthand()); 483 return get4Values(borderRadiusShorthand());
330 default: 484 default:
331 return String(); 485 return String();
332 } 486 }
333 } 487 }
334 488
335 String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const 489 String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const
336 { 490 {
337 RefPtrWillBeRawPtr<CSSValue> horizontalValue = m_propertySet.getPropertyCSSV alue(shorthand.properties()[0]); 491 const CSSValue* horizontalValue = m_propertySet.getPropertyCSSValue(shorthan d.properties()[0]);
338 RefPtrWillBeRawPtr<CSSValue> verticalValue = m_propertySet.getPropertyCSSVal ue(shorthand.properties()[1]); 492 const CSSValue* verticalValue = m_propertySet.getPropertyCSSValue(shorthand. properties()[1]);
339 493
340 // While standard border-spacing property does not allow specifying border-s pacing-vertical without 494 // While standard border-spacing property does not allow specifying border-s pacing-vertical without
341 // specifying border-spacing-horizontal <http://www.w3.org/TR/CSS21/tables.h tml#separated-borders>, 495 // specifying border-spacing-horizontal <http://www.w3.org/TR/CSS21/tables.h tml#separated-borders>,
342 // -webkit-border-spacing-vertical can be set without -webkit-border-spacing -horizontal. 496 // -webkit-border-spacing-vertical can be set without -webkit-border-spacing -horizontal.
343 if (!horizontalValue || !verticalValue) 497 if (!horizontalValue || !verticalValue)
344 return String(); 498 return String();
345 499
346 String horizontalValueCSSText = horizontalValue->cssText(); 500 String horizontalValueCSSText = horizontalValue->cssText();
347 String verticalValueCSSText = verticalValue->cssText(); 501 String verticalValueCSSText = verticalValue->cssText();
348 if (horizontalValueCSSText == verticalValueCSSText) 502 if (horizontalValueCSSText == verticalValueCSSText)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 commonValue = String(); 540 commonValue = String();
387 } 541 }
388 542
389 String StylePropertySerializer::fontValue() const 543 String StylePropertySerializer::fontValue() const
390 { 544 {
391 int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontS ize); 545 int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontS ize);
392 int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFon tFamily); 546 int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFon tFamily);
393 if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1) 547 if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1)
394 return emptyString(); 548 return emptyString();
395 549
396 StylePropertySet::PropertyReference fontSizeProperty = m_propertySet.propert yAt(fontSizePropertyIndex); 550 PropertyValueForSerializer fontSizeProperty = m_propertySet.propertyAt(fontS izePropertyIndex);
397 StylePropertySet::PropertyReference fontFamilyProperty = m_propertySet.prope rtyAt(fontFamilyPropertyIndex); 551 PropertyValueForSerializer fontFamilyProperty = m_propertySet.propertyAt(fon tFamilyPropertyIndex);
398 if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit()) 552 if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit())
399 return emptyString(); 553 return emptyString();
400 554
401 String commonValue = fontSizeProperty.value()->cssText(); 555 String commonValue = fontSizeProperty.value()->cssText();
402 StringBuilder result; 556 StringBuilder result;
403 appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue) ; 557 appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue) ;
404 appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValu e); 558 appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValu e);
405 appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue ); 559 appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue );
406 appendFontLonghandValueIfExplicit(CSSPropertyFontStretch, result, commonValu e); 560 appendFontLonghandValueIfExplicit(CSSPropertyFontStretch, result, commonValu e);
407 if (!result.isEmpty()) 561 if (!result.isEmpty())
(...skipping 12 matching lines...) Expand all
420 { 574 {
421 // Assume the properties are in the usual order top, right, bottom, left. 575 // Assume the properties are in the usual order top, right, bottom, left.
422 int topValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[0 ]); 576 int topValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[0 ]);
423 int rightValueIndex = m_propertySet.findPropertyIndex(shorthand.properties() [1]); 577 int rightValueIndex = m_propertySet.findPropertyIndex(shorthand.properties() [1]);
424 int bottomValueIndex = m_propertySet.findPropertyIndex(shorthand.properties( )[2]); 578 int bottomValueIndex = m_propertySet.findPropertyIndex(shorthand.properties( )[2]);
425 int leftValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[ 3]); 579 int leftValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[ 3]);
426 580
427 if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 | | leftValueIndex == -1) 581 if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 | | leftValueIndex == -1)
428 return String(); 582 return String();
429 583
430 StylePropertySet::PropertyReference top = m_propertySet.propertyAt(topValueI ndex); 584 PropertyValueForSerializer top = m_propertySet.propertyAt(topValueIndex);
431 StylePropertySet::PropertyReference right = m_propertySet.propertyAt(rightVa lueIndex); 585 PropertyValueForSerializer right = m_propertySet.propertyAt(rightValueIndex) ;
432 StylePropertySet::PropertyReference bottom = m_propertySet.propertyAt(bottom ValueIndex); 586 PropertyValueForSerializer bottom = m_propertySet.propertyAt(bottomValueInde x);
433 StylePropertySet::PropertyReference left = m_propertySet.propertyAt(leftValu eIndex); 587 PropertyValueForSerializer left = m_propertySet.propertyAt(leftValueIndex);
434 588
435 // All 4 properties must be specified. 589 // All 4 properties must be specified.
436 if (!top.value() || !right.value() || !bottom.value() || !left.value()) 590 if (!top.value() || !right.value() || !bottom.value() || !left.value())
437 return String(); 591 return String();
438 592
439 if (top.isInherited() && right.isInherited() && bottom.isInherited() && left .isInherited()) 593 if (top.isInherited() && right.isInherited() && bottom.isInherited() && left .isInherited())
440 return getValueName(CSSValueInherit); 594 return getValueName(CSSValueInherit);
441 595
442 if (top.value()->isInitialValue() || right.value()->isInitialValue() || bott om.value()->isInitialValue() || left.value()->isInitialValue()) { 596 if (top.value()->isInitialValue() || right.value()->isInitialValue() || bott om.value()->isInitialValue() || left.value()->isInitialValue()) {
443 if (top.value()->isInitialValue() && right.value()->isInitialValue() && bottom.value()->isInitialValue() && left.value()->isInitialValue() && !top.isImp licit()) { 597 if (top.value()->isInitialValue() && right.value()->isInitialValue() && bottom.value()->isInitialValue() && left.value()->isInitialValue() && !top.isImp licit()) {
(...skipping 25 matching lines...) Expand all
469 } 623 }
470 return result.toString(); 624 return result.toString();
471 } 625 }
472 626
473 String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor thand& shorthand) const 627 String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor thand& shorthand) const
474 { 628 {
475 StringBuilder result; 629 StringBuilder result;
476 630
477 const unsigned size = shorthand.length(); 631 const unsigned size = shorthand.length();
478 // Begin by collecting the properties into an array. 632 // Begin by collecting the properties into an array.
479 WillBeHeapVector<RefPtrWillBeMember<CSSValue> > values(size); 633 WillBeHeapVector<const CSSValue*> values(size);
480 size_t numLayers = 0; 634 size_t numLayers = 0;
481 635
482 for (unsigned i = 0; i < size; ++i) { 636 for (unsigned i = 0; i < size; ++i) {
483 values[i] = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]) ; 637 values[i] = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]) ;
484 if (values[i]) { 638 if (values[i]) {
485 if (values[i]->isBaseValueList()) { 639 if (values[i]->isBaseValueList()) {
486 CSSValueList* valueList = toCSSValueList(values[i].get()); 640 const CSSValueList* valueList = toCSSValueList(values[i]);
487 numLayers = std::max(valueList->length(), numLayers); 641 numLayers = std::max(valueList->length(), numLayers);
488 } else { 642 } else {
489 numLayers = std::max<size_t>(1U, numLayers); 643 numLayers = std::max<size_t>(1U, numLayers);
490 } 644 }
491 } 645 }
492 } 646 }
493 647
494 String commonValue; 648 String commonValue;
495 bool commonValueInitialized = false; 649 bool commonValueInitialized = false;
496 650
497 // Now stitch the properties together. Implicit initial values are flagged a s such and 651 // Now stitch the properties together. Implicit initial values are flagged a s such and
498 // can safely be omitted. 652 // can safely be omitted.
499 for (size_t i = 0; i < numLayers; i++) { 653 for (size_t i = 0; i < numLayers; i++) {
500 StringBuilder layerResult; 654 StringBuilder layerResult;
501 bool useRepeatXShorthand = false; 655 bool useRepeatXShorthand = false;
502 bool useRepeatYShorthand = false; 656 bool useRepeatYShorthand = false;
503 bool useSingleWordShorthand = false; 657 bool useSingleWordShorthand = false;
504 bool foundPositionYCSSProperty = false; 658 bool foundPositionYCSSProperty = false;
505 for (unsigned j = 0; j < size; j++) { 659 for (unsigned j = 0; j < size; j++) {
506 RefPtrWillBeRawPtr<CSSValue> value = nullptr; 660 const CSSValue* value = 0;
507 if (values[j]) { 661 if (values[j]) {
508 if (values[j]->isBaseValueList()) { 662 if (values[j]->isBaseValueList()) {
509 value = toCSSValueList(values[j].get())->itemWithBoundsCheck (i); 663 value = toCSSValueList(values[j])->itemWithBoundsCheck(i);
510 } else { 664 } else {
511 value = values[j]; 665 value = values[j];
512 666
513 // Color only belongs in the last layer. 667 // Color only belongs in the last layer.
514 if (shorthand.properties()[j] == CSSPropertyBackgroundColor) { 668 if (shorthand.properties()[j] == CSSPropertyBackgroundColor) {
515 if (i != numLayers - 1) 669 if (i != numLayers - 1)
516 value = nullptr; 670 value = 0;
517 } else if (i) { 671 } else if (i) {
518 // Other singletons only belong in the first layer. 672 // Other singletons only belong in the first layer.
519 value = nullptr; 673 value = 0;
520 } 674 }
521 } 675 }
522 } 676 }
523 677
524 // We need to report background-repeat as it was written in the CSS. If the property is implicit, 678 // We need to report background-repeat as it was written in the CSS. If the property is implicit,
525 // then it was written with only one value. Here we figure out which value that was so we can 679 // then it was written with only one value. Here we figure out which value that was so we can
526 // report back correctly. 680 // report back correctly.
527 if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && m_ propertySet.isPropertyImplicit(shorthand.properties()[j])) 681 if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && m_ propertySet.isPropertyImplicit(shorthand.properties()[j]))
528 || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && m_propertySet.isPropertyImplicit(shorthand.properties()[j]))) { 682 || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && m_propertySet.isPropertyImplicit(shorthand.properties()[j]))) {
529 683
530 // BUG 49055: make sure the value was not reset in the layer che ck just above. 684 // BUG 49055: make sure the value was not reset in the layer che ck just above.
531 if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropert yBackgroundRepeatY && value) 685 if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropert yBackgroundRepeatY && value)
532 || (j < size - 1 && shorthand.properties()[j + 1] == CSSProp ertyWebkitMaskRepeatY && value)) { 686 || (j < size - 1 && shorthand.properties()[j + 1] == CSSProp ertyWebkitMaskRepeatY && value)) {
533 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; 687 const CSSValue* yValue = 0;
534 RefPtrWillBeRawPtr<CSSValue> nextValue = values[j + 1]; 688 const CSSValue* nextValue = values[j + 1];
535 if (nextValue->isValueList()) 689 if (nextValue->isValueList())
536 yValue = toCSSValueList(nextValue.get())->item(i); 690 yValue = toCSSValueList(nextValue)->item(i);
537 else 691 else
538 yValue = nextValue; 692 yValue = nextValue;
539 693
540 // background-repeat-x(y) or mask-repeat-x(y) may be like th is : "initial, repeat". We can omit the implicit initial values 694 // background-repeat-x(y) or mask-repeat-x(y) may be like th is : "initial, repeat". We can omit the implicit initial values
541 // before starting to compare their values. 695 // before starting to compare their values.
542 if (value->isImplicitInitialValue() || yValue->isImplicitIni tialValue()) 696 if (value->isImplicitInitialValue() || yValue->isImplicitIni tialValue())
543 continue; 697 continue;
544 698
545 // FIXME: At some point we need to fix this code to avoid re turning an invalid shorthand, 699 // FIXME: At some point we need to fix this code to avoid re turning an invalid shorthand,
546 // since some longhand combinations are not serializable int o a single shorthand. 700 // since some longhand combinations are not serializable int o a single shorthand.
547 if (!value->isPrimitiveValue() || !yValue->isPrimitiveValue( )) 701 if (!value->isPrimitiveValue() || !yValue->isPrimitiveValue( ))
548 continue; 702 continue;
549 703
550 CSSValueID xId = toCSSPrimitiveValue(value.get())->getValueI D(); 704 CSSValueID xId = toCSSPrimitiveValue(value)->getValueID();
551 CSSValueID yId = toCSSPrimitiveValue(yValue.get())->getValue ID(); 705 CSSValueID yId = toCSSPrimitiveValue(yValue)->getValueID();
552 if (xId != yId) { 706 if (xId != yId) {
553 if (xId == CSSValueRepeat && yId == CSSValueNoRepeat) { 707 if (xId == CSSValueRepeat && yId == CSSValueNoRepeat) {
554 useRepeatXShorthand = true; 708 useRepeatXShorthand = true;
555 ++j; 709 ++j;
556 } else if (xId == CSSValueNoRepeat && yId == CSSValueRep eat) { 710 } else if (xId == CSSValueNoRepeat && yId == CSSValueRep eat) {
557 useRepeatYShorthand = true; 711 useRepeatYShorthand = true;
558 continue; 712 continue;
559 } 713 }
560 } else { 714 } else {
561 useSingleWordShorthand = true; 715 useSingleWordShorthand = true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 return String(); 774 return String();
621 return result.toString(); 775 return result.toString();
622 } 776 }
623 777
624 String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand& shorthand) const 778 String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand& shorthand) const
625 { 779 {
626 String commonValue; 780 String commonValue;
627 StringBuilder result; 781 StringBuilder result;
628 for (unsigned i = 0; i < shorthand.length(); ++i) { 782 for (unsigned i = 0; i < shorthand.length(); ++i) {
629 if (!m_propertySet.isPropertyImplicit(shorthand.properties()[i])) { 783 if (!m_propertySet.isPropertyImplicit(shorthand.properties()[i])) {
630 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(shorthand.properties()[i]); 784 const CSSValue* value = m_propertySet.getPropertyCSSValue(shorthand. properties()[i]);
631 if (!value) 785 if (!value)
632 return String(); 786 return String();
633 String valueText = value->cssText(); 787 String valueText = value->cssText();
634 if (!i) 788 if (!i)
635 commonValue = valueText; 789 commonValue = valueText;
636 else if (!commonValue.isNull() && commonValue != valueText) 790 else if (!commonValue.isNull() && commonValue != valueText)
637 commonValue = String(); 791 commonValue = String();
638 if (value->isInitialValue()) 792 if (value->isInitialValue())
639 continue; 793 continue;
640 if (!result.isEmpty()) 794 if (!result.isEmpty())
641 result.append(' '); 795 result.append(' ');
642 result.append(valueText); 796 result.append(valueText);
643 } else 797 } else
644 commonValue = String(); 798 commonValue = String();
645 } 799 }
646 if (isInitialOrInherit(commonValue)) 800 if (isInitialOrInherit(commonValue))
647 return commonValue; 801 return commonValue;
648 if (result.isEmpty()) 802 if (result.isEmpty())
649 return String(); 803 return String();
650 return result.toString(); 804 return result.toString();
651 } 805 }
652 806
653 // only returns a non-null value if all properties have the same, non-null value 807 // only returns a non-null value if all properties have the same, non-null value
654 String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho rthand) const 808 String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho rthand) const
655 { 809 {
656 String res; 810 String res;
657 bool lastPropertyWasImportant = false; 811 bool lastPropertyWasImportant = false;
658 for (unsigned i = 0; i < shorthand.length(); ++i) { 812 for (unsigned i = 0; i < shorthand.length(); ++i) {
659 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); 813 const CSSValue* value = m_propertySet.getPropertyCSSValue(shorthand.prop erties()[i]);
660 // FIXME: CSSInitialValue::cssText should generate the right value. 814 // FIXME: CSSInitialValue::cssText should generate the right value.
661 if (!value) 815 if (!value)
662 return String(); 816 return String();
663 String text = value->cssText(); 817 String text = value->cssText();
664 if (text.isNull()) 818 if (text.isNull())
665 return String(); 819 return String();
666 if (res.isNull()) 820 if (res.isNull())
667 res = text; 821 res = text;
668 else if (res != text) 822 else if (res != text)
669 return String(); 823 return String();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 builder.appendLiteral("repeat-x"); 874 builder.appendLiteral("repeat-x");
721 } else { 875 } else {
722 builder.append(repeatX.cssText()); 876 builder.append(repeatX.cssText());
723 builder.appendLiteral(" "); 877 builder.appendLiteral(" ");
724 builder.append(repeatY.cssText()); 878 builder.append(repeatY.cssText());
725 } 879 }
726 } 880 }
727 881
728 String StylePropertySerializer::backgroundRepeatPropertyValue() const 882 String StylePropertySerializer::backgroundRepeatPropertyValue() const
729 { 883 {
730 RefPtrWillBeRawPtr<CSSValue> repeatX = m_propertySet.getPropertyCSSValue(CSS PropertyBackgroundRepeatX); 884 const CSSValue* repeatX = m_propertySet.getPropertyCSSValue(CSSPropertyBackg roundRepeatX);
731 RefPtrWillBeRawPtr<CSSValue> repeatY = m_propertySet.getPropertyCSSValue(CSS PropertyBackgroundRepeatY); 885 const CSSValue* repeatY = m_propertySet.getPropertyCSSValue(CSSPropertyBackg roundRepeatY);
732 if (!repeatX || !repeatY) 886 if (!repeatX || !repeatY)
733 return String(); 887 return String();
734 if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_pro pertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY)) 888 if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_pro pertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY))
735 return String(); 889 return String();
736 if (repeatX->cssValueType() == repeatY->cssValueType() 890 if (repeatX->cssValueType() == repeatY->cssValueType()
737 && (repeatX->cssValueType() == CSSValue::CSS_INITIAL || repeatX->cssValu eType() == CSSValue::CSS_INHERIT)) { 891 && (repeatX->cssValueType() == CSSValue::CSS_INITIAL || repeatX->cssValu eType() == CSSValue::CSS_INHERIT)) {
738 return repeatX->cssText(); 892 return repeatX->cssText();
739 } 893 }
740 894
741 RefPtrWillBeRawPtr<CSSValueList> repeatXList; 895 const CSSValueList* repeatXList = 0;
742 if (repeatX->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) { 896 int repeatXLength = 1;
743 repeatXList = CSSValueList::createCommaSeparated(); 897 if (repeatX->cssValueType() == CSSValue::CSS_VALUE_LIST) {
744 repeatXList->append(repeatX); 898 repeatXList = toCSSValueList(repeatX);
745 } else if (repeatX->cssValueType() == CSSValue::CSS_VALUE_LIST) { 899 repeatXLength = repeatXList->length();
746 repeatXList = toCSSValueList(repeatX.get()); 900 } else if (repeatX->cssValueType() != CSSValue::CSS_PRIMITIVE_VALUE) {
747 } else {
748 return String(); 901 return String();
749 } 902 }
750 903
751 RefPtrWillBeRawPtr<CSSValueList> repeatYList; 904 const CSSValueList* repeatYList = 0;
752 if (repeatY->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) { 905 int repeatYLength = 1;
753 repeatYList = CSSValueList::createCommaSeparated(); 906 if (repeatY->cssValueType() == CSSValue::CSS_VALUE_LIST) {
754 repeatYList->append(repeatY); 907 repeatYList = toCSSValueList(repeatY);
755 } else if (repeatY->cssValueType() == CSSValue::CSS_VALUE_LIST) { 908 repeatYLength = repeatYList->length();
756 repeatYList = toCSSValueList(repeatY.get()); 909 } else if (repeatY->cssValueType() != CSSValue::CSS_PRIMITIVE_VALUE) {
757 } else {
758 return String(); 910 return String();
759 } 911 }
760 912
761 size_t shorthandLength = lowestCommonMultiple(repeatXList->length(), repeatY List->length()); 913 size_t shorthandLength = lowestCommonMultiple(repeatXLength, repeatYLength);
762 StringBuilder builder; 914 StringBuilder builder;
763 for (size_t i = 0; i < shorthandLength; ++i) { 915 for (size_t i = 0; i < shorthandLength; ++i) {
764 if (i) 916 if (i)
765 builder.appendLiteral(", "); 917 builder.appendLiteral(", ");
766 appendBackgroundRepeatValue(builder, 918
767 *repeatXList->item(i % repeatXList->length()), 919 const CSSValue* xValue = repeatXList ? repeatXList->item(i % repeatXList ->length()) : repeatX;
768 *repeatYList->item(i % repeatYList->length())); 920 const CSSValue* yValue = repeatYList ? repeatYList->item(i % repeatYList ->length()) : repeatY;
921 appendBackgroundRepeatValue(builder, *xValue, *yValue);
769 } 922 }
770 return builder.toString(); 923 return builder.toString();
771 } 924 }
772 925
773 void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu lt, unsigned& numDecls) const 926 void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu lt, unsigned& numDecls) const
774 { 927 {
775 if (isPropertyShorthandAvailable(backgroundShorthand())) { 928 if (isPropertyShorthandAvailable(backgroundShorthand())) {
776 String backgroundValue = getPropertyValue(CSSPropertyBackground); 929 String backgroundValue = getPropertyValue(CSSPropertyBackground);
777 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage); 930 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage);
778 result.append(getPropertyText(CSSPropertyBackground, backgroundValue, is Important, numDecls++)); 931 result.append(getPropertyText(CSSPropertyBackground, backgroundValue, is Important, numDecls++));
779 return; 932 return;
780 } 933 }
781 if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) { 934 if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) {
782 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyBackgroundImage); 935 const CSSValue* value = m_propertySet.getPropertyCSSValue(CSSPropertyBac kgroundImage);
783 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage); 936 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage);
784 result.append(getPropertyText(CSSPropertyBackground, value->cssText(), i sImportant, numDecls++)); 937 result.append(getPropertyText(CSSPropertyBackground, value->cssText(), i sImportant, numDecls++));
785 return; 938 return;
786 } 939 }
787 940
788 // backgroundShorthandProperty without layered shorhand properties 941 // backgroundShorthandProperty without layered shorhand properties
789 const CSSPropertyID backgroundPropertyIds[] = { 942 const CSSPropertyID backgroundPropertyIds[] = {
790 CSSPropertyBackgroundImage, 943 CSSPropertyBackgroundImage,
791 CSSPropertyBackgroundAttachment, 944 CSSPropertyBackgroundAttachment,
792 CSSPropertyBackgroundColor, 945 CSSPropertyBackgroundColor,
793 CSSPropertyBackgroundSize, 946 CSSPropertyBackgroundSize,
794 CSSPropertyBackgroundOrigin, 947 CSSPropertyBackgroundOrigin,
795 CSSPropertyBackgroundClip 948 CSSPropertyBackgroundClip
796 }; 949 };
797 950
798 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) { 951 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) {
799 CSSPropertyID propertyID = backgroundPropertyIds[i]; 952 CSSPropertyID propertyID = backgroundPropertyIds[i];
800 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(p ropertyID); 953 const CSSValue* value = m_propertySet.getPropertyCSSValue(propertyID);
801 if (!value) 954 if (!value)
802 continue; 955 continue;
803 result.append(getPropertyText(propertyID, value->cssText(), m_propertySe t.propertyIsImportant(propertyID), numDecls++)); 956 result.append(getPropertyText(propertyID, value->cssText(), m_propertySe t.propertyIsImportant(propertyID), numDecls++));
804 } 957 }
805 958
806 // FIXME: This is a not-so-nice way to turn x/y positions into single backgr ound-position in output. 959 // FIXME: This is a not-so-nice way to turn x/y positions into single backgr ound-position in output.
807 // It is required because background-position-x/y are non-standard propertie s and WebKit generated output 960 // It is required because background-position-x/y are non-standard propertie s and WebKit generated output
808 // would not work in Firefox (<rdar://problem/5143183>) 961 // would not work in Firefox (<rdar://problem/5143183>)
809 // It would be a better solution if background-position was CSS_PAIR. 962 // It would be a better solution if background-position was CSS_PAIR.
810 if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) { 963 if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) {
811 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyBackgroundPositionX); 964 const CSSValue* value = m_propertySet.getPropertyCSSValue(CSSPropertyBac kgroundPositionX);
812 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX); 965 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX);
813 result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssT ext(), isImportant, numDecls++)); 966 result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssT ext(), isImportant, numDecls++));
814 } else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) { 967 } else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) {
815 String positionValue = m_propertySet.getPropertyValue(CSSPropertyBackgro undPosition); 968 String positionValue = m_propertySet.getPropertyValue(CSSPropertyBackgro undPosition);
816 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX); 969 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX);
817 if (!positionValue.isNull()) 970 if (!positionValue.isNull())
818 result.append(getPropertyText(CSSPropertyBackgroundPosition, positio nValue, isImportant, numDecls++)); 971 result.append(getPropertyText(CSSPropertyBackgroundPosition, positio nValue, isImportant, numDecls++));
819 } else { 972 } else {
820 // should check background-position-x or background-position-y. 973 // should check background-position-x or background-position-y.
821 if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(CSSPropertyBackgroundPositionX)) { 974 if (const CSSValue* value = m_propertySet.getPropertyCSSValue(CSSPropert yBackgroundPositionX)) {
822 if (!value->isImplicitInitialValue()) { 975 if (!value->isImplicitInitialValue()) {
823 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionX); 976 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionX);
824 result.append(getPropertyText(CSSPropertyBackgroundPositionX, va lue->cssText(), isImportant, numDecls++)); 977 result.append(getPropertyText(CSSPropertyBackgroundPositionX, va lue->cssText(), isImportant, numDecls++));
825 } 978 }
826 } 979 }
827 if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(CSSPropertyBackgroundPositionY)) { 980 if (const CSSValue* value = m_propertySet.getPropertyCSSValue(CSSPropert yBackgroundPositionY)) {
828 if (!value->isImplicitInitialValue()) { 981 if (!value->isImplicitInitialValue()) {
829 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionY); 982 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionY);
830 result.append(getPropertyText(CSSPropertyBackgroundPositionY, va lue->cssText(), isImportant, numDecls++)); 983 result.append(getPropertyText(CSSPropertyBackgroundPositionY, va lue->cssText(), isImportant, numDecls++));
831 } 984 }
832 } 985 }
833 } 986 }
834 987
835 String repeatValue = m_propertySet.getPropertyValue(CSSPropertyBackgroundRep eat); 988 String repeatValue = m_propertySet.getPropertyValue(CSSPropertyBackgroundRep eat);
836 if (!repeatValue.isNull()) 989 if (!repeatValue.isNull())
837 result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++)); 990 result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++));
838 } 991 }
839 992
840 bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh orthand& shorthand) const 993 bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh orthand& shorthand) const
841 { 994 {
842 ASSERT(shorthand.length() > 0); 995 ASSERT(shorthand.length() > 0);
843 996
844 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]); 997 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]);
845 for (unsigned i = 0; i < shorthand.length(); ++i) { 998 for (unsigned i = 0; i < shorthand.length(); ++i) {
846 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); 999 const CSSValue* value = m_propertySet.getPropertyCSSValue(shorthand.prop erties()[i]);
847 if (!value || (value->isInitialValue() && !value->isImplicitInitialValue ()) || value->isInheritedValue()) 1000 if (!value || (value->isInitialValue() && !value->isImplicitInitialValue ()) || value->isInheritedValue())
848 return false; 1001 return false;
849 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i])) 1002 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i]))
850 return false; 1003 return false;
851 } 1004 }
852 return true; 1005 return true;
853 } 1006 }
854 1007
855 bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const Styl ePropertyShorthand& shorthand) const 1008 bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const Styl ePropertyShorthand& shorthand) const
856 { 1009 {
857 ASSERT(shorthand.length() > 0); 1010 ASSERT(shorthand.length() > 0);
858 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]); 1011 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]);
859 bool isInitialValue = true; 1012 bool isInitialValue = true;
860 bool isInheritedValue = true; 1013 bool isInheritedValue = true;
861 for (unsigned i = 0; i < shorthand.length(); ++i) { 1014 for (unsigned i = 0; i < shorthand.length(); ++i) {
862 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); 1015 const CSSValue* value = m_propertySet.getPropertyCSSValue(shorthand.prop erties()[i]);
863 if (!value) 1016 if (!value)
864 return false; 1017 return false;
865 if (!value->isInitialValue()) 1018 if (!value->isInitialValue())
866 isInitialValue = false; 1019 isInitialValue = false;
867 if (!value->isInheritedValue()) 1020 if (!value->isInheritedValue())
868 isInheritedValue = false; 1021 isInheritedValue = false;
869 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i])) 1022 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i]))
870 return false; 1023 return false;
871 } 1024 }
872 return isInitialValue || isInheritedValue; 1025 return isInitialValue || isInheritedValue;
873 } 1026 }
874 1027
875 } 1028 }
OLDNEW
« Source/core/css/StylePropertySerializer.h ('K') | « Source/core/css/StylePropertySerializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698