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

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

Issue 216803002: Implement all shorthand property. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 "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 shouldExpandAll(const StylePropertySet& properties)
45 {
46 int allIndex = properties.findPropertyIndex(CSSPropertyAll);
47 if (allIndex == -1)
48 return false;
49
50 for (unsigned i = 0; i < properties.propertyCount(); ++i) {
51 StylePropertySet::PropertyReference property = properties.propertyAt(i);
52 if (CSSProperty::isAffectedByAllProperty(property.id()))
53 return true;
54 }
55 return false;
56 }
57
58 static bool canAllOverwriteProperty(const StylePropertySet::PropertyReference& a ll, unsigned allIndex, const StylePropertySet::PropertyReference& property, unsi gned propertyIndex)
esprehn 2014/06/12 00:36:45 Can you explain the purpose of this?
59 {
60 if (allIndex == propertyIndex)
61 return true;
62 if (!CSSProperty::isAffectedByAllProperty(property.id()))
63 return false;
64 if (all.isImportant() != property.isImportant())
65 return all.isImportant();
66 return propertyIndex < allIndex;
67 }
68
69 void StylePropertySerializer::expandAll()
70 {
71 unsigned allIndex = m_propertySet.findPropertyIndex(CSSPropertyAll);
72 StylePropertySet::PropertyReference all = m_propertySet.propertyAt(allIndex) ;
73 BitArray<numCSSProperties> shorthandPropertyAppeared;
74
75 unsigned position = 0;
76 for (unsigned i = 0; i < m_propertySet.propertyCount(); ++i) {
77 StylePropertySet::PropertyReference property = m_propertySet.propertyAt( i);
78 CSSPropertyID propertyId = property.id();
79
80 if (propertyId == CSSPropertyAll)
81 position = m_propertyVector.size();
82
83 if (!canAllOverwriteProperty(all, allIndex, property, i)) {
84 m_propertyVector.append(CSSPropertyInternal(property));
85
86 unsigned shortPropertyIndex = property.id() - firstCSSProperty;
87 shorthandPropertyAppeared.set(shortPropertyIndex);
88 }
89 }
90
91 bool allIsUnset = !all.value()->isInitialValue() && !all.value()->isInherite dValue();
92 CSSValue* value = all.value();
93
94 for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
95 CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
96
97 if (isExpandedShorthandForAll(propertyId))
98 continue;
99 if (!CSSProperty::isAffectedByAllProperty(propertyId))
100 continue;
101 if (shorthandPropertyAppeared.get(i - firstCSSProperty))
102 continue;
103
104 if (allIsUnset) {
105 if (CSSProperty::isInheritedProperty(propertyId))
106 value = cssValuePool().createInheritedValue().get();
107 else
108 value = cssValuePool().createExplicitInitialValue().get();
109 }
110 m_propertyVector.insert(position++, CSSPropertyInternal(propertyId, valu e, all.isImportant(), value->isInheritedValue(), all.isImplicit()));
esprehn 2014/06/12 00:36:44 All these vector inserts are going to be really ex
111 }
112 }
113
43 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies) 114 StylePropertySerializer::StylePropertySerializer(const StylePropertySet& propert ies)
44 : m_propertySet(properties) 115 : m_propertySet(properties)
45 { 116 {
117 if (shouldExpandAll(properties))
118 expandAll();
119 }
120
121 unsigned StylePropertySerializer::propertyCount() const
122 {
123 if (m_propertyVector.isEmpty())
124 return m_propertySet.propertyCount();
125
126 return m_propertyVector.size();
127 }
128
129 StylePropertySerializer::CSSPropertyInternal StylePropertySerializer::propertyAt (unsigned index) const
130 {
131 if (m_propertyVector.isEmpty())
132 return CSSPropertyInternal(m_propertySet.propertyAt(index));
133
134 return m_propertyVector.at(index);
esprehn 2014/06/12 00:36:45 m_propertyVector[index] ?
135 }
136
137 String StylePropertySerializer::propertyValue(CSSPropertyID propertyId) const
138 {
139 if (m_propertyVector.isEmpty())
140 return m_propertySet.getPropertyValue(propertyId);
141
142 int index = findPropertyIndex(propertyId);
143 if (index == -1)
144 return String();
145 if (CSSValue* value = m_propertyVector.at(index).value())
esprehn 2014/06/12 00:36:45 ditto
146 return value->cssText();
147 return String();
148 }
149
150 CSSValue* StylePropertySerializer::getPropertyCSSValue(CSSPropertyID propertyId) const
151 {
152 if (m_propertyVector.isEmpty())
153 return m_propertySet.getPropertyCSSValue(propertyId).get();
154
155 int index = findPropertyIndex(propertyId);
156 if (index == -1)
157 return 0;
158 return m_propertyVector.at(index).value();
esprehn 2014/06/12 00:36:45 ditto
159 }
160
161 int StylePropertySerializer::findPropertyIndex(CSSPropertyID propertyId) const
162 {
163 if (m_propertyVector.isEmpty())
164 return m_propertySet.findPropertyIndex(propertyId);
165
166 for (unsigned i = 0; i < m_propertyVector.size(); ++i) {
167 if (m_propertyVector.at(i).id() == propertyId)
esprehn 2014/06/12 00:36:45 m_propertyVector[i].id()
168 return i;
169 }
170 return -1;
171 }
172
173 bool StylePropertySerializer::isPropertyImplicit(CSSPropertyID propertyId) const
174 {
175 if (m_propertyVector.isEmpty())
176 return m_propertySet.isPropertyImplicit(propertyId);
177
178 int index = findPropertyIndex(propertyId);
179 if (index == -1)
180 return false;
181 return m_propertyVector.at(index).isImplicit();
182 }
183
184 bool StylePropertySerializer::propertyIsImportant(CSSPropertyID propertyId) cons t
185 {
186 if (m_propertyVector.isEmpty())
187 return m_propertySet.propertyIsImportant(propertyId);
188
189 int index = findPropertyIndex(propertyId);
190 if (index == -1)
191 return false;
192 return m_propertyVector.at(index).isImportant();
46 } 193 }
47 194
48 String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const 195 String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isImportant, bool isNotFirstDecl) const
49 { 196 {
50 StringBuilder result; 197 StringBuilder result;
51 if (isNotFirstDecl) 198 if (isNotFirstDecl)
52 result.append(' '); 199 result.append(' ');
53 result.append(getPropertyName(propertyID)); 200 result.append(getPropertyName(propertyID));
54 result.appendLiteral(": "); 201 result.appendLiteral(": ");
55 result.append(value); 202 result.append(value);
56 if (isImportant) 203 if (isImportant)
57 result.appendLiteral(" !important"); 204 result.appendLiteral(" !important");
58 result.append(';'); 205 result.append(';');
59 return result.toString(); 206 return result.toString();
60 } 207 }
61 208
62 String StylePropertySerializer::asText() const 209 String StylePropertySerializer::asText() const
63 { 210 {
64 StringBuilder result; 211 StringBuilder result;
65 212
213 String allValue;
214 if (hasAllShorthand(allValue))
215 return allValue;
216
66 BitArray<numCSSProperties> shorthandPropertyUsed; 217 BitArray<numCSSProperties> shorthandPropertyUsed;
67 BitArray<numCSSProperties> shorthandPropertyAppeared; 218 BitArray<numCSSProperties> shorthandPropertyAppeared;
68 219
69 unsigned size = m_propertySet.propertyCount(); 220 unsigned size = propertyCount();
70 unsigned numDecls = 0; 221 unsigned numDecls = 0;
71 for (unsigned n = 0; n < size; ++n) { 222 for (unsigned n = 0; n < size; ++n) {
72 StylePropertySet::PropertyReference property = m_propertySet.propertyAt( n); 223 CSSPropertyInternal property = propertyAt(n);
73 CSSPropertyID propertyID = property.id(); 224 CSSPropertyID propertyID = property.id();
74 // Only enabled or internal properties should be part of the style. 225 // Only enabled or internal properties should be part of the style.
75 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternal Property(propertyID)); 226 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID) || isInternal Property(propertyID));
76 CSSPropertyID shorthandPropertyID = CSSPropertyInvalid; 227 CSSPropertyID shorthandPropertyID = CSSPropertyInvalid;
77 CSSPropertyID borderFallbackShorthandProperty = CSSPropertyInvalid; 228 CSSPropertyID borderFallbackShorthandProperty = CSSPropertyInvalid;
78 String value; 229 String value;
79 230
80 switch (propertyID) { 231 switch (propertyID) {
81 case CSSPropertyBackgroundAttachment: 232 case CSSPropertyBackgroundAttachment:
82 case CSSPropertyBackgroundClip: 233 case CSSPropertyBackgroundClip:
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 case CSSPropertyWebkitTransformOriginY: 353 case CSSPropertyWebkitTransformOriginY:
203 case CSSPropertyWebkitTransformOriginZ: 354 case CSSPropertyWebkitTransformOriginZ:
204 shorthandPropertyID = CSSPropertyWebkitTransformOrigin; 355 shorthandPropertyID = CSSPropertyWebkitTransformOrigin;
205 break; 356 break;
206 case CSSPropertyWebkitTransitionProperty: 357 case CSSPropertyWebkitTransitionProperty:
207 case CSSPropertyWebkitTransitionDuration: 358 case CSSPropertyWebkitTransitionDuration:
208 case CSSPropertyWebkitTransitionTimingFunction: 359 case CSSPropertyWebkitTransitionTimingFunction:
209 case CSSPropertyWebkitTransitionDelay: 360 case CSSPropertyWebkitTransitionDelay:
210 shorthandPropertyID = CSSPropertyWebkitTransition; 361 shorthandPropertyID = CSSPropertyWebkitTransition;
211 break; 362 break;
363 case CSSPropertyAll:
364 result.append(getPropertyText(propertyID, property.value()->cssText( ), property.isImportant(), numDecls++));
365 continue;
212 default: 366 default:
213 break; 367 break;
214 } 368 }
215 369
216 unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty; 370 unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty;
217 if (shorthandPropertyID) { 371 if (shorthandPropertyID) {
218 if (shorthandPropertyUsed.get(shortPropertyIndex)) 372 if (shorthandPropertyUsed.get(shortPropertyIndex))
219 continue; 373 continue;
220 if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNu ll()) 374 if (!shorthandPropertyAppeared.get(shortPropertyIndex) && value.isNu ll())
221 value = m_propertySet.getPropertyValue(shorthandPropertyID); 375 value = propertyValue(shorthandPropertyID);
222 shorthandPropertyAppeared.set(shortPropertyIndex); 376 shorthandPropertyAppeared.set(shortPropertyIndex);
223 } 377 }
224 378
225 if (!value.isNull()) { 379 if (!value.isNull()) {
226 if (shorthandPropertyID) { 380 if (shorthandPropertyID) {
227 propertyID = shorthandPropertyID; 381 propertyID = shorthandPropertyID;
228 shorthandPropertyUsed.set(shortPropertyIndex); 382 shorthandPropertyUsed.set(shortPropertyIndex);
229 } 383 }
230 } else 384 } else {
385 // We should not show "initial" when the "initial" is implicit.
386 // If explicit "initial", we need to show.
387 if (property.value()->isImplicitInitialValue())
388 continue;
231 value = property.value()->cssText(); 389 value = property.value()->cssText();
232 390 }
233 if (value == "initial" && !CSSProperty::isInheritedProperty(propertyID))
234 continue;
235 391
236 result.append(getPropertyText(propertyID, value, property.isImportant(), numDecls++)); 392 result.append(getPropertyText(propertyID, value, property.isImportant(), numDecls++));
237 } 393 }
238 394
239 if (shorthandPropertyAppeared.get(CSSPropertyBackground - firstCSSProperty)) 395 if (shorthandPropertyAppeared.get(CSSPropertyBackground - firstCSSProperty))
240 appendBackgroundPropertyAsText(result, numDecls); 396 appendBackgroundPropertyAsText(result, numDecls);
241 397
242 ASSERT(!numDecls ^ !result.isEmpty()); 398 ASSERT(!numDecls ^ !result.isEmpty());
243 return result.toString(); 399 return result.toString();
244 } 400 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 case CSSPropertyWebkitTextStroke: 470 case CSSPropertyWebkitTextStroke:
315 return getShorthandValue(webkitTextStrokeShorthand()); 471 return getShorthandValue(webkitTextStrokeShorthand());
316 case CSSPropertyTransformOrigin: 472 case CSSPropertyTransformOrigin:
317 case CSSPropertyWebkitTransformOrigin: 473 case CSSPropertyWebkitTransformOrigin:
318 return getShorthandValue(webkitTransformOriginShorthand()); 474 return getShorthandValue(webkitTransformOriginShorthand());
319 case CSSPropertyWebkitTransition: 475 case CSSPropertyWebkitTransition:
320 return getLayeredShorthandValue(webkitTransitionShorthand()); 476 return getLayeredShorthandValue(webkitTransitionShorthand());
321 case CSSPropertyWebkitAnimation: 477 case CSSPropertyWebkitAnimation:
322 return getLayeredShorthandValue(webkitAnimationShorthand()); 478 return getLayeredShorthandValue(webkitAnimationShorthand());
323 case CSSPropertyMarker: { 479 case CSSPropertyMarker: {
324 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyMarkerStart); 480 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyMark erStart);
325 if (value) 481 if (value)
326 return value->cssText(); 482 return value->cssText();
327 return String(); 483 return String();
328 } 484 }
329 case CSSPropertyBorderRadius: 485 case CSSPropertyBorderRadius:
330 return get4Values(borderRadiusShorthand()); 486 return get4Values(borderRadiusShorthand());
331 default: 487 default:
332 return String(); 488 return String();
333 } 489 }
334 } 490 }
335 491
336 String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const 492 String StylePropertySerializer::borderSpacingValue(const StylePropertyShorthand& shorthand) const
337 { 493 {
338 RefPtrWillBeRawPtr<CSSValue> horizontalValue = m_propertySet.getPropertyCSSV alue(shorthand.properties()[0]); 494 RefPtrWillBeRawPtr<CSSValue> horizontalValue = getPropertyCSSValue(shorthand .properties()[0]);
339 RefPtrWillBeRawPtr<CSSValue> verticalValue = m_propertySet.getPropertyCSSVal ue(shorthand.properties()[1]); 495 RefPtrWillBeRawPtr<CSSValue> verticalValue = getPropertyCSSValue(shorthand.p roperties()[1]);
340 496
341 // While standard border-spacing property does not allow specifying border-s pacing-vertical without 497 // 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>, 498 // 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. 499 // -webkit-border-spacing-vertical can be set without -webkit-border-spacing -horizontal.
344 if (!horizontalValue || !verticalValue) 500 if (!horizontalValue || !verticalValue)
345 return String(); 501 return String();
346 502
347 String horizontalValueCSSText = horizontalValue->cssText(); 503 String horizontalValueCSSText = horizontalValue->cssText();
348 String verticalValueCSSText = verticalValue->cssText(); 504 String verticalValueCSSText = verticalValue->cssText();
349 if (horizontalValueCSSText == verticalValueCSSText) 505 if (horizontalValueCSSText == verticalValueCSSText)
350 return horizontalValueCSSText; 506 return horizontalValueCSSText;
351 return horizontalValueCSSText + ' ' + verticalValueCSSText; 507 return horizontalValueCSSText + ' ' + verticalValueCSSText;
352 } 508 }
353 509
354 void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID pr opertyID, StringBuilder& result, String& commonValue) const 510 void StylePropertySerializer::appendFontLonghandValueIfExplicit(CSSPropertyID pr opertyID, StringBuilder& result, String& commonValue) const
355 { 511 {
356 int foundPropertyIndex = m_propertySet.findPropertyIndex(propertyID); 512 int foundPropertyIndex = findPropertyIndex(propertyID);
357 if (foundPropertyIndex == -1) 513 if (foundPropertyIndex == -1)
358 return; // All longhands must have at least implicit values if "font" is specified. 514 return; // All longhands must have at least implicit values if "font" is specified.
359 515
360 if (m_propertySet.propertyAt(foundPropertyIndex).isImplicit()) { 516 if (propertyAt(foundPropertyIndex).isImplicit()) {
361 commonValue = String(); 517 commonValue = String();
362 return; 518 return;
363 } 519 }
364 520
365 char prefix = '\0'; 521 char prefix = '\0';
366 switch (propertyID) { 522 switch (propertyID) {
367 case CSSPropertyFontStyle: 523 case CSSPropertyFontStyle:
368 break; // No prefix. 524 break; // No prefix.
369 case CSSPropertyFontFamily: 525 case CSSPropertyFontFamily:
370 case CSSPropertyFontVariant: 526 case CSSPropertyFontVariant:
371 case CSSPropertyFontWeight: 527 case CSSPropertyFontWeight:
372 prefix = ' '; 528 prefix = ' ';
373 break; 529 break;
374 case CSSPropertyLineHeight: 530 case CSSPropertyLineHeight:
375 prefix = '/'; 531 prefix = '/';
376 break; 532 break;
377 default: 533 default:
378 ASSERT_NOT_REACHED(); 534 ASSERT_NOT_REACHED();
379 } 535 }
380 536
381 if (prefix && !result.isEmpty()) 537 if (prefix && !result.isEmpty())
382 result.append(prefix); 538 result.append(prefix);
383 String value = m_propertySet.propertyAt(foundPropertyIndex).value()->cssText (); 539 String value = propertyAt(foundPropertyIndex).value()->cssText();
384 result.append(value); 540 result.append(value);
385 if (!commonValue.isNull() && commonValue != value) 541 if (!commonValue.isNull() && commonValue != value)
386 commonValue = String(); 542 commonValue = String();
387 } 543 }
388 544
389 String StylePropertySerializer::fontValue() const 545 String StylePropertySerializer::fontValue() const
390 { 546 {
391 int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontS ize); 547 int fontSizePropertyIndex = findPropertyIndex(CSSPropertyFontSize);
392 int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFon tFamily); 548 int fontFamilyPropertyIndex = findPropertyIndex(CSSPropertyFontFamily);
393 if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1) 549 if (fontSizePropertyIndex == -1 || fontFamilyPropertyIndex == -1)
394 return emptyString(); 550 return emptyString();
395 551
396 StylePropertySet::PropertyReference fontSizeProperty = m_propertySet.propert yAt(fontSizePropertyIndex); 552 CSSPropertyInternal fontSizeProperty = propertyAt(fontSizePropertyIndex);
397 StylePropertySet::PropertyReference fontFamilyProperty = m_propertySet.prope rtyAt(fontFamilyPropertyIndex); 553 CSSPropertyInternal fontFamilyProperty = propertyAt(fontFamilyPropertyIndex) ;
398 if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit()) 554 if (fontSizeProperty.isImplicit() || fontFamilyProperty.isImplicit())
399 return emptyString(); 555 return emptyString();
400 556
401 String commonValue = fontSizeProperty.value()->cssText(); 557 String commonValue = fontSizeProperty.value()->cssText();
402 StringBuilder result; 558 StringBuilder result;
403 appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue) ; 559 appendFontLonghandValueIfExplicit(CSSPropertyFontStyle, result, commonValue) ;
404 appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValu e); 560 appendFontLonghandValueIfExplicit(CSSPropertyFontVariant, result, commonValu e);
405 appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue ); 561 appendFontLonghandValueIfExplicit(CSSPropertyFontWeight, result, commonValue );
406 if (!result.isEmpty()) 562 if (!result.isEmpty())
407 result.append(' '); 563 result.append(' ');
408 result.append(fontSizeProperty.value()->cssText()); 564 result.append(fontSizeProperty.value()->cssText());
409 appendFontLonghandValueIfExplicit(CSSPropertyLineHeight, result, commonValue ); 565 appendFontLonghandValueIfExplicit(CSSPropertyLineHeight, result, commonValue );
410 if (!result.isEmpty()) 566 if (!result.isEmpty())
411 result.append(' '); 567 result.append(' ');
412 result.append(fontFamilyProperty.value()->cssText()); 568 result.append(fontFamilyProperty.value()->cssText());
413 if (isInitialOrInherit(commonValue)) 569 if (isInitialOrInherit(commonValue))
414 return commonValue; 570 return commonValue;
415 return result.toString(); 571 return result.toString();
416 } 572 }
417 573
418 String StylePropertySerializer::get4Values(const StylePropertyShorthand& shortha nd) const 574 String StylePropertySerializer::get4Values(const StylePropertyShorthand& shortha nd) const
419 { 575 {
420 // Assume the properties are in the usual order top, right, bottom, left. 576 // Assume the properties are in the usual order top, right, bottom, left.
421 int topValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[0 ]); 577 int topValueIndex = findPropertyIndex(shorthand.properties()[0]);
422 int rightValueIndex = m_propertySet.findPropertyIndex(shorthand.properties() [1]); 578 int rightValueIndex = findPropertyIndex(shorthand.properties()[1]);
423 int bottomValueIndex = m_propertySet.findPropertyIndex(shorthand.properties( )[2]); 579 int bottomValueIndex = findPropertyIndex(shorthand.properties()[2]);
424 int leftValueIndex = m_propertySet.findPropertyIndex(shorthand.properties()[ 3]); 580 int leftValueIndex = findPropertyIndex(shorthand.properties()[3]);
425 581
426 if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 | | leftValueIndex == -1) 582 if (topValueIndex == -1 || rightValueIndex == -1 || bottomValueIndex == -1 | | leftValueIndex == -1)
427 return String(); 583 return String();
428 584
429 StylePropertySet::PropertyReference top = m_propertySet.propertyAt(topValueI ndex); 585 CSSPropertyInternal top = propertyAt(topValueIndex);
430 StylePropertySet::PropertyReference right = m_propertySet.propertyAt(rightVa lueIndex); 586 CSSPropertyInternal right = propertyAt(rightValueIndex);
431 StylePropertySet::PropertyReference bottom = m_propertySet.propertyAt(bottom ValueIndex); 587 CSSPropertyInternal bottom = propertyAt(bottomValueIndex);
432 StylePropertySet::PropertyReference left = m_propertySet.propertyAt(leftValu eIndex); 588 CSSPropertyInternal left = propertyAt(leftValueIndex);
433 589
434 // All 4 properties must be specified. 590 // All 4 properties must be specified.
435 if (!top.value() || !right.value() || !bottom.value() || !left.value()) 591 if (!top.value() || !right.value() || !bottom.value() || !left.value())
436 return String(); 592 return String();
437 593
438 if (top.isInherited() && right.isInherited() && bottom.isInherited() && left .isInherited()) 594 if (top.isInherited() && right.isInherited() && bottom.isInherited() && left .isInherited())
439 return getValueName(CSSValueInherit); 595 return getValueName(CSSValueInherit);
440 596
441 if (top.value()->isInitialValue() || right.value()->isInitialValue() || bott om.value()->isInitialValue() || left.value()->isInitialValue()) { 597 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()) { 598 if (top.value()->isInitialValue() && right.value()->isInitialValue() && bottom.value()->isInitialValue() && left.value()->isInitialValue() && !top.isImp licit()) {
(...skipping 29 matching lines...) Expand all
472 String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor thand& shorthand) const 628 String StylePropertySerializer::getLayeredShorthandValue(const StylePropertyShor thand& shorthand) const
473 { 629 {
474 StringBuilder result; 630 StringBuilder result;
475 631
476 const unsigned size = shorthand.length(); 632 const unsigned size = shorthand.length();
477 // Begin by collecting the properties into an array. 633 // Begin by collecting the properties into an array.
478 WillBeHeapVector<RefPtrWillBeMember<CSSValue> > values(size); 634 WillBeHeapVector<RefPtrWillBeMember<CSSValue> > values(size);
479 size_t numLayers = 0; 635 size_t numLayers = 0;
480 636
481 for (unsigned i = 0; i < size; ++i) { 637 for (unsigned i = 0; i < size; ++i) {
482 values[i] = m_propertySet.getPropertyCSSValue(shorthand.properties()[i]) ; 638 values[i] = getPropertyCSSValue(shorthand.properties()[i]);
483 if (values[i]) { 639 if (values[i]) {
484 if (values[i]->isBaseValueList()) { 640 if (values[i]->isBaseValueList()) {
485 CSSValueList* valueList = toCSSValueList(values[i].get()); 641 CSSValueList* valueList = toCSSValueList(values[i].get());
486 numLayers = max(valueList->length(), numLayers); 642 numLayers = max(valueList->length(), numLayers);
487 } else 643 } else
488 numLayers = max<size_t>(1U, numLayers); 644 numLayers = max<size_t>(1U, numLayers);
489 } 645 }
490 } 646 }
491 647
492 String commonValue; 648 String commonValue;
(...skipping 22 matching lines...) Expand all
515 } else if (i) { 671 } else if (i) {
516 // Other singletons only belong in the first layer. 672 // Other singletons only belong in the first layer.
517 value = nullptr; 673 value = nullptr;
518 } 674 }
519 } 675 }
520 } 676 }
521 677
522 // 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,
523 // 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
524 // report back correctly. 680 // report back correctly.
525 if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && m_ propertySet.isPropertyImplicit(shorthand.properties()[j])) 681 if ((shorthand.properties()[j] == CSSPropertyBackgroundRepeatX && is PropertyImplicit(shorthand.properties()[j]))
526 || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && m_propertySet.isPropertyImplicit(shorthand.properties()[j]))) { 682 || (shorthand.properties()[j] == CSSPropertyWebkitMaskRepeatX && isPropertyImplicit(shorthand.properties()[j]))) {
527 683
528 // 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.
529 if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropert yBackgroundRepeatY && value) 685 if ((j < size - 1 && shorthand.properties()[j + 1] == CSSPropert yBackgroundRepeatY && value)
530 || (j < size - 1 && shorthand.properties()[j + 1] == CSSProp ertyWebkitMaskRepeatY && value)) { 686 || (j < size - 1 && shorthand.properties()[j + 1] == CSSProp ertyWebkitMaskRepeatY && value)) {
531 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr; 687 RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
532 RefPtrWillBeRawPtr<CSSValue> nextValue = values[j + 1]; 688 RefPtrWillBeRawPtr<CSSValue> nextValue = values[j + 1];
533 if (nextValue->isValueList()) 689 if (nextValue->isValueList())
534 yValue = toCSSValueList(nextValue.get())->itemWithoutBou ndsCheck(i); 690 yValue = toCSSValueList(nextValue.get())->itemWithoutBou ndsCheck(i);
535 else 691 else
536 yValue = nextValue; 692 yValue = nextValue;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (result.isEmpty()) 773 if (result.isEmpty())
618 return String(); 774 return String();
619 return result.toString(); 775 return result.toString();
620 } 776 }
621 777
622 String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand& shorthand) const 778 String StylePropertySerializer::getShorthandValue(const StylePropertyShorthand& shorthand) const
623 { 779 {
624 String commonValue; 780 String commonValue;
625 StringBuilder result; 781 StringBuilder result;
626 for (unsigned i = 0; i < shorthand.length(); ++i) { 782 for (unsigned i = 0; i < shorthand.length(); ++i) {
627 if (!m_propertySet.isPropertyImplicit(shorthand.properties()[i])) { 783 if (!isPropertyImplicit(shorthand.properties()[i])) {
628 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(shorthand.properties()[i]); 784 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.p roperties()[i]);
629 if (!value) 785 if (!value)
630 return String(); 786 return String();
631 String valueText = value->cssText(); 787 String valueText = value->cssText();
632 if (!i) 788 if (!i)
633 commonValue = valueText; 789 commonValue = valueText;
634 else if (!commonValue.isNull() && commonValue != valueText) 790 else if (!commonValue.isNull() && commonValue != valueText)
635 commonValue = String(); 791 commonValue = String();
636 if (value->isInitialValue()) 792 if (value->isInitialValue())
637 continue; 793 continue;
638 if (!result.isEmpty()) 794 if (!result.isEmpty())
639 result.append(' '); 795 result.append(' ');
640 result.append(valueText); 796 result.append(valueText);
641 } else 797 } else
642 commonValue = String(); 798 commonValue = String();
643 } 799 }
644 if (isInitialOrInherit(commonValue)) 800 if (isInitialOrInherit(commonValue))
645 return commonValue; 801 return commonValue;
646 if (result.isEmpty()) 802 if (result.isEmpty())
647 return String(); 803 return String();
648 return result.toString(); 804 return result.toString();
649 } 805 }
650 806
651 // 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
652 String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho rthand) const 808 String StylePropertySerializer::getCommonValue(const StylePropertyShorthand& sho rthand) const
653 { 809 {
654 String res; 810 String res;
655 bool lastPropertyWasImportant = false; 811 bool lastPropertyWasImportant = false;
656 for (unsigned i = 0; i < shorthand.length(); ++i) { 812 for (unsigned i = 0; i < shorthand.length(); ++i) {
657 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); 813 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.prope rties()[i]);
658 // FIXME: CSSInitialValue::cssText should generate the right value. 814 // FIXME: CSSInitialValue::cssText should generate the right value.
659 if (!value) 815 if (!value)
660 return String(); 816 return String();
661 String text = value->cssText(); 817 String text = value->cssText();
662 if (text.isNull()) 818 if (text.isNull())
663 return String(); 819 return String();
664 if (res.isNull()) 820 if (res.isNull())
665 res = text; 821 res = text;
666 else if (res != text) 822 else if (res != text)
667 return String(); 823 return String();
668 824
669 bool currentPropertyIsImportant = m_propertySet.propertyIsImportant(shor thand.properties()[i]); 825 bool currentPropertyIsImportant = propertyIsImportant(shorthand.properti es()[i]);
670 if (i && lastPropertyWasImportant != currentPropertyIsImportant) 826 if (i && lastPropertyWasImportant != currentPropertyIsImportant)
671 return String(); 827 return String();
672 lastPropertyWasImportant = currentPropertyIsImportant; 828 lastPropertyWasImportant = currentPropertyIsImportant;
673 } 829 }
674 return res; 830 return res;
675 } 831 }
676 832
677 String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c onst 833 String StylePropertySerializer::borderPropertyValue(CommonValueMode valueMode) c onst
678 { 834 {
679 const StylePropertyShorthand properties[3] = { borderWidthShorthand(), borde rStyleShorthand(), borderColorShorthand() }; 835 const StylePropertyShorthand properties[3] = { borderWidthShorthand(), borde rStyleShorthand(), borderColorShorthand() };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 builder.append("repeat-x"); 874 builder.append("repeat-x");
719 } else { 875 } else {
720 builder.append(repeatX.cssText()); 876 builder.append(repeatX.cssText());
721 builder.append(" "); 877 builder.append(" ");
722 builder.append(repeatY.cssText()); 878 builder.append(repeatY.cssText());
723 } 879 }
724 } 880 }
725 881
726 String StylePropertySerializer::backgroundRepeatPropertyValue() const 882 String StylePropertySerializer::backgroundRepeatPropertyValue() const
727 { 883 {
728 RefPtrWillBeRawPtr<CSSValue> repeatX = m_propertySet.getPropertyCSSValue(CSS PropertyBackgroundRepeatX); 884 RefPtrWillBeRawPtr<CSSValue> repeatX = getPropertyCSSValue(CSSPropertyBackgr oundRepeatX);
729 RefPtrWillBeRawPtr<CSSValue> repeatY = m_propertySet.getPropertyCSSValue(CSS PropertyBackgroundRepeatY); 885 RefPtrWillBeRawPtr<CSSValue> repeatY = getPropertyCSSValue(CSSPropertyBackgr oundRepeatY);
730 if (!repeatX || !repeatY) 886 if (!repeatX || !repeatY)
731 return String(); 887 return String();
732 if (m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX) != m_pro pertySet.propertyIsImportant(CSSPropertyBackgroundRepeatY)) 888 if (propertyIsImportant(CSSPropertyBackgroundRepeatX) != propertyIsImportant (CSSPropertyBackgroundRepeatY))
733 return String(); 889 return String();
734 if (repeatX->cssValueType() == repeatY->cssValueType() 890 if (repeatX->cssValueType() == repeatY->cssValueType()
735 && (repeatX->cssValueType() == CSSValue::CSS_INITIAL || repeatX->cssValu eType() == CSSValue::CSS_INHERIT)) { 891 && (repeatX->cssValueType() == CSSValue::CSS_INITIAL || repeatX->cssValu eType() == CSSValue::CSS_INHERIT)) {
736 return repeatX->cssText(); 892 return repeatX->cssText();
737 } 893 }
738 894
739 RefPtrWillBeRawPtr<CSSValueList> repeatXList; 895 RefPtrWillBeRawPtr<CSSValueList> repeatXList;
740 if (repeatX->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) { 896 if (repeatX->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
741 repeatXList = CSSValueList::createCommaSeparated(); 897 repeatXList = CSSValueList::createCommaSeparated();
742 repeatXList->append(repeatX); 898 repeatXList->append(repeatX);
(...skipping 22 matching lines...) Expand all
765 *repeatXList->item(i % repeatXList->length()), 921 *repeatXList->item(i % repeatXList->length()),
766 *repeatYList->item(i % repeatYList->length())); 922 *repeatYList->item(i % repeatYList->length()));
767 } 923 }
768 return builder.toString(); 924 return builder.toString();
769 } 925 }
770 926
771 void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu lt, unsigned& numDecls) const 927 void StylePropertySerializer::appendBackgroundPropertyAsText(StringBuilder& resu lt, unsigned& numDecls) const
772 { 928 {
773 if (isPropertyShorthandAvailable(backgroundShorthand())) { 929 if (isPropertyShorthandAvailable(backgroundShorthand())) {
774 String backgroundValue = getPropertyValue(CSSPropertyBackground); 930 String backgroundValue = getPropertyValue(CSSPropertyBackground);
775 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage); 931 bool isImportant = propertyIsImportant(CSSPropertyBackgroundImage);
776 result.append(getPropertyText(CSSPropertyBackground, backgroundValue, is Important, numDecls++)); 932 result.append(getPropertyText(CSSPropertyBackground, backgroundValue, is Important, numDecls++));
777 return; 933 return;
778 } 934 }
779 if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) { 935 if (shorthandHasOnlyInitialOrInheritedValue(backgroundShorthand())) {
780 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyBackgroundImage); 936 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBack groundImage);
781 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndImage); 937 bool isImportant = propertyIsImportant(CSSPropertyBackgroundImage);
782 result.append(getPropertyText(CSSPropertyBackground, value->cssText(), i sImportant, numDecls++)); 938 result.append(getPropertyText(CSSPropertyBackground, value->cssText(), i sImportant, numDecls++));
783 return; 939 return;
784 } 940 }
785 941
786 // backgroundShorthandProperty without layered shorhand properties 942 // backgroundShorthandProperty without layered shorhand properties
787 const CSSPropertyID backgroundPropertyIds[] = { 943 const CSSPropertyID backgroundPropertyIds[] = {
788 CSSPropertyBackgroundImage, 944 CSSPropertyBackgroundImage,
789 CSSPropertyBackgroundAttachment, 945 CSSPropertyBackgroundAttachment,
790 CSSPropertyBackgroundColor, 946 CSSPropertyBackgroundColor,
791 CSSPropertyBackgroundSize, 947 CSSPropertyBackgroundSize,
792 CSSPropertyBackgroundOrigin, 948 CSSPropertyBackgroundOrigin,
793 CSSPropertyBackgroundClip 949 CSSPropertyBackgroundClip
794 }; 950 };
795 951
796 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) { 952 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(backgroundPropertyIds); ++i) {
797 CSSPropertyID propertyID = backgroundPropertyIds[i]; 953 CSSPropertyID propertyID = backgroundPropertyIds[i];
798 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(p ropertyID); 954 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID);
799 if (!value) 955 if (!value)
800 continue; 956 continue;
801 result.append(getPropertyText(propertyID, value->cssText(), m_propertySe t.propertyIsImportant(propertyID), numDecls++)); 957 result.append(getPropertyText(propertyID, value->cssText(), propertyIsIm portant(propertyID), numDecls++));
802 } 958 }
803 959
804 // FIXME: This is a not-so-nice way to turn x/y positions into single backgr ound-position in output. 960 // FIXME: This is a not-so-nice way to turn x/y positions into single backgr ound-position in output.
805 // It is required because background-position-x/y are non-standard propertie s and WebKit generated output 961 // It is required because background-position-x/y are non-standard propertie s and WebKit generated output
806 // would not work in Firefox (<rdar://problem/5143183>) 962 // would not work in Firefox (<rdar://problem/5143183>)
807 // It would be a better solution if background-position was CSS_PAIR. 963 // It would be a better solution if background-position was CSS_PAIR.
808 if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) { 964 if (shorthandHasOnlyInitialOrInheritedValue(backgroundPositionShorthand())) {
809 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(C SSPropertyBackgroundPositionX); 965 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBack groundPositionX);
810 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX); 966 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX);
811 result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssT ext(), isImportant, numDecls++)); 967 result.append(getPropertyText(CSSPropertyBackgroundPosition, value->cssT ext(), isImportant, numDecls++));
812 } else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) { 968 } else if (isPropertyShorthandAvailable(backgroundPositionShorthand())) {
813 String positionValue = m_propertySet.getPropertyValue(CSSPropertyBackgro undPosition); 969 String positionValue = propertyValue(CSSPropertyBackgroundPosition);
814 bool isImportant = m_propertySet.propertyIsImportant(CSSPropertyBackgrou ndPositionX); 970 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPositionX);
815 if (!positionValue.isNull()) 971 if (!positionValue.isNull())
816 result.append(getPropertyText(CSSPropertyBackgroundPosition, positio nValue, isImportant, numDecls++)); 972 result.append(getPropertyText(CSSPropertyBackgroundPosition, positio nValue, isImportant, numDecls++));
817 } else { 973 } else {
818 // should check background-position-x or background-position-y. 974 // should check background-position-x or background-position-y.
819 if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(CSSPropertyBackgroundPositionX)) { 975 if (RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSProperty BackgroundPositionX)) {
820 if (!value->isImplicitInitialValue()) { 976 if (!value->isImplicitInitialValue()) {
821 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionX); 977 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPosi tionX);
822 result.append(getPropertyText(CSSPropertyBackgroundPositionX, va lue->cssText(), isImportant, numDecls++)); 978 result.append(getPropertyText(CSSPropertyBackgroundPositionX, va lue->cssText(), isImportant, numDecls++));
823 } 979 }
824 } 980 }
825 if (RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSVal ue(CSSPropertyBackgroundPositionY)) { 981 if (RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSProperty BackgroundPositionY)) {
826 if (!value->isImplicitInitialValue()) { 982 if (!value->isImplicitInitialValue()) {
827 bool isImportant = m_propertySet.propertyIsImportant(CSSProperty BackgroundPositionY); 983 bool isImportant = propertyIsImportant(CSSPropertyBackgroundPosi tionY);
828 result.append(getPropertyText(CSSPropertyBackgroundPositionY, va lue->cssText(), isImportant, numDecls++)); 984 result.append(getPropertyText(CSSPropertyBackgroundPositionY, va lue->cssText(), isImportant, numDecls++));
829 } 985 }
830 } 986 }
831 } 987 }
832 988
833 String repeatValue = m_propertySet.getPropertyValue(CSSPropertyBackgroundRep eat); 989 String repeatValue = propertyValue(CSSPropertyBackgroundRepeat);
834 if (!repeatValue.isNull()) 990 if (!repeatValue.isNull())
835 result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, m_propertySet.propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++)); 991 result.append(getPropertyText(CSSPropertyBackgroundRepeat, repeatValue, propertyIsImportant(CSSPropertyBackgroundRepeatX), numDecls++));
836 } 992 }
837 993
838 bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh orthand& shorthand) const 994 bool StylePropertySerializer::isPropertyShorthandAvailable(const StylePropertySh orthand& shorthand) const
839 { 995 {
840 ASSERT(shorthand.length() > 0); 996 ASSERT(shorthand.length() > 0);
841 997
842 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]); 998 bool isImportant = propertyIsImportant(shorthand.properties()[0]);
843 for (unsigned i = 0; i < shorthand.length(); ++i) { 999 for (unsigned i = 0; i < shorthand.length(); ++i) {
844 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); 1000 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.prope rties()[i]);
845 if (!value || (value->isInitialValue() && !value->isImplicitInitialValue ()) || value->isInheritedValue()) 1001 if (!value || (value->isInitialValue() && !value->isImplicitInitialValue ()) || value->isInheritedValue())
846 return false; 1002 return false;
847 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i])) 1003 if (isImportant != propertyIsImportant(shorthand.properties()[i]))
848 return false; 1004 return false;
849 } 1005 }
850 return true; 1006 return true;
851 } 1007 }
852 1008
853 bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const Styl ePropertyShorthand& shorthand) const 1009 bool StylePropertySerializer::shorthandHasOnlyInitialOrInheritedValue(const Styl ePropertyShorthand& shorthand) const
854 { 1010 {
855 ASSERT(shorthand.length() > 0); 1011 ASSERT(shorthand.length() > 0);
856 bool isImportant = m_propertySet.propertyIsImportant(shorthand.properties()[ 0]); 1012 bool isImportant = propertyIsImportant(shorthand.properties()[0]);
857 bool isInitialValue = true; 1013 bool isInitialValue = true;
858 bool isInheritedValue = true; 1014 bool isInheritedValue = true;
859 for (unsigned i = 0; i < shorthand.length(); ++i) { 1015 for (unsigned i = 0; i < shorthand.length(); ++i) {
860 RefPtrWillBeRawPtr<CSSValue> value = m_propertySet.getPropertyCSSValue(s horthand.properties()[i]); 1016 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.prope rties()[i]);
861 if (!value) 1017 if (!value)
862 return false; 1018 return false;
863 if (!value->isInitialValue()) 1019 if (!value->isInitialValue())
864 isInitialValue = false; 1020 isInitialValue = false;
865 if (!value->isInheritedValue()) 1021 if (!value->isInheritedValue())
866 isInheritedValue = false; 1022 isInheritedValue = false;
867 if (isImportant != m_propertySet.propertyIsImportant(shorthand.propertie s()[i])) 1023 if (isImportant != propertyIsImportant(shorthand.properties()[i]))
868 return false; 1024 return false;
869 } 1025 }
870 return isInitialValue || isInheritedValue; 1026 return isInitialValue || isInheritedValue;
871 } 1027 }
872 1028
1029 bool StylePropertySerializer::hasAllShorthand(String& result) const
esprehn 2014/06/12 00:36:44 has*() methods shouldn't really reaturn stuff like
1030 {
1031 if (!propertyCount())
1032 return false;
1033
1034 bool firstPropertyIsImportant = propertyAt(0).isImportant();
1035 bool isInitialValue = true;
1036 bool isInheritedValue = true;
1037 bool isUnsetValue = true;
1038
1039 BitArray<numCSSProperties> shorthandPropertyAppeared;
1040
1041 for (unsigned i = 0; i < propertyCount(); ++i) {
1042 CSSPropertyInternal property = propertyAt(i);
1043
1044 unsigned shorthandIndex = property.id() - firstCSSProperty;
1045 shorthandPropertyAppeared.set(shorthandIndex);
1046
1047 if (!property.value()->isInitialValue())
1048 isInitialValue = false;
1049 if (!property.value()->isInheritedValue())
1050 isInheritedValue = false;
1051 if ((CSSProperty::isInheritedProperty(property.id()) && !property.value( )->isInheritedValue()) || (!CSSProperty::isInheritedProperty(property.id()) && ! property.value()->isInitialValue()))
1052 isUnsetValue = false;
1053
1054 if (firstPropertyIsImportant != property.isImportant())
1055 return false;
1056 }
1057 if (!isInitialValue && !isInheritedValue && !isUnsetValue)
1058 return false;
1059
1060 for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
1061 CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
1062
1063 if (isExpandedShorthandForAll(propertyId))
1064 continue;
1065 if (!CSSProperty::isAffectedByAllProperty(propertyId))
1066 continue;
1067
1068 unsigned shorthandIndex = i - firstCSSProperty;
1069 if (!shorthandPropertyAppeared.get(shorthandIndex))
1070 return false;
1071 }
1072
1073 String value;
1074 if (isInitialValue)
1075 value = "initial";
1076 else if (isInheritedValue)
1077 value = "inherit";
1078 else
1079 value = "unset";
1080 result = getPropertyText(CSSPropertyAll, value, firstPropertyIsImportant, fa lse);
1081 return true;
873 } 1082 }
1083
1084 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698